#ifndef BOOLEAN
#define BOOLEAN short
#endif
#ifndef FALSE
#define FALSE 0
#define TRUE 1
#endif

#ifdef LINUX
#define _MAX_PATH 512
#define _MAX_EXT 6
#define _MAX_DRIVE 6
#define _MAX_DIR 512
#define _MAX_FNAME 512
#endif

typedef unsigned long WINDOW;
typedef unsigned int UNIT_TYPE;
typedef unsigned long ULONG;
typedef unsigned long XVT_ERRMSG;
typedef unsigned long XVT_ODBC;

typedef wchar_t XVT_WCHAR;
typedef short MENU_TAG;
typedef short CURSOR;
typedef char* DATA_PTR;

#define EOL_SEQ "\015\012"

typedef struct
{
	short top, left, bottom, right;
} RCT;

typedef long XVT_HELP_TID;
typedef unsigned long COLOR;
typedef unsigned long XVT_COLOR_TYPE;
typedef unsigned long XVT_FONT_ATTR_MASK;
typedef unsigned long XVT_FONT_STYLE_MASK;
typedef long PICTURE;
typedef void* XVT_IMAGE;

typedef enum {
XVT_IMAGE_NONE,
XVT_IMAGE_CL8,
XVT_IMAGE_RGB,
XVT_IMAGE_MONO,
} XVT_IMAGE_FORMAT;

#define XVT_FNTID void*
typedef void* XVT_PALETTE;
typedef unsigned long XVT_PALETTE_ATTR;

#define XVT_ESC_GET_PRINTER_INFO 883
#define XVT_ESC_SET_PRINTER_INFO 884

typedef enum e_display_type {
    XVT_DISPLAY_MONO,           /* monochromatic display */
    XVT_DISPLAY_GRAY_16,        /* 16-entry grayscale */
    XVT_DISPLAY_GRAY_256,       /* 256-entry grayscale */
    XVT_DISPLAY_COLOR_16,       /* 16-entry color */
    XVT_DISPLAY_COLOR_256,      /* 256-entry color */
    XVT_DISPLAY_DIRECT_COLOR,   /* full color capabilities */
} XVT_DISPLAY_TYPE;

typedef enum {

XVT_PALETTE_NONE,
XVT_PALETTE_STOCK,
XVT_PALETTE_CURRENT,
XVT_PALETTE_CUBE16,
XVT_PALETTE_CUBE256,
XVT_PALETTE_USER
} XVT_PALETTE_TYPE;

typedef enum {                  /* response from ask fcn */
    RESP_DEFAULT,               /* default button */
    RESP_2,                     /* second button */
    RESP_3,                     /* third button */
} ASK_RESPONSE;

typedef enum {                  /* result from file open & save dialogs */
    FL_BAD,                     /* error occurred */
    FL_CANCEL,                  /* cancel button clicked */
    FL_OK,                      /* OK button clicked */
} FL_STATUS;

typedef struct
{
	char path[_MAX_DIR];
} DIRECTORY;

typedef struct s_mitem {

MENU_TAG tag;	/* menu tag */
char *text;	/* text to appear in menu */
short mkey;	/* mnemonic */
unsigned enabled: 1;	/* enabled? */
unsigned checked: 1;	/* checked? */
unsigned checkable: 1;	/* checkable? */
unsigned separator: 1;	/* separator? */
struct s_mitem *child;	/* pointer to submenu */
} MENU_ITEM;

typedef enum e_popup_alignment { 
XVT_POPUP_CENTER, 
XVT_POPUP_LEFT_ALIGN, 
XVT_POPUP_RIGHT_ALIGN, 
XVT_POPUP_OVER_ITEM 
} XVT_POPUP_ALIGNMENT;

#define SZ_FNAME _MAX_FNAME

typedef struct {	/* file specification */
DIRECTORY dir;	/* directory */
char type[6];	/* file type/extension */
char name[SZ_FNAME];	/* filename */
char creator[6];	/* file creator */
} FILE_SPEC;

typedef struct
{
	void* pr;
} PRINT_RCD;

typedef struct
{
	short v, h;
} PNT;

typedef struct { char* str; long data; void* next; } SLIST_ITEM;
typedef SLIST_ITEM* SLIST_ELT;

typedef struct { SLIST_ELT head; long count; } xvtList;
typedef xvtList* SLIST;

typedef enum {	/* drawing (transfer) mode */
M_COPY,
M_OR,
M_XOR,
M_CLEAR,
M_NOT_COPY,
M_NOT_OR,
M_NOT_XOR,
M_NOT_CLEAR
} DRAW_MODE;

typedef enum e_pen_style {	/* pen style */
P_SOLID,	/* solid */
P_DOT,	/* dotted line */
P_DASH	/* dashed line */
} PEN_STYLE;

typedef enum {
PAT_NONE,	/* no pattern */
PAT_HOLLOW,	/* hollow */
PAT_SOLID,	/* solid fill */
PAT_HORZ,	/* horizontal lines */
PAT_VERT,	/* vertical lines */
PAT_FDIAG,	/* diagonal lines -- top-left to bottom-right */
PAT_BDIAG,	/* diagonal lines -- top-right to bottom-left */
PAT_CROSS,	/* horizontal and vertical crossing lines */
PAT_DIAGCROSS,	/* diagonal crossing lines */
PAT_RUBBER,	/* rubber banding */
PAT_SPECIAL
} PAT_STYLE;

typedef struct {	/* color pen tool */
short width;	/* width */
PAT_STYLE pat;	/* pattern */
PEN_STYLE style;	/* style */
COLOR color;	/* color */
} CPEN;

typedef struct
{
	PAT_STYLE pat;
	COLOR color;
}	CBRUSH;

typedef struct {	/* color drawing tools */
CPEN pen;	/* color pen */
CBRUSH brush;	/* color brush */
DRAW_MODE mode;	/* drawing mode */
COLOR fore_color;	/* foreground color */
COLOR back_color;	/* background color */
BOOLEAN opaque_text;	/* is text opaque*/
} DRAW_CTOOLS;

typedef enum {	/* scrollbar activity */
SC_NONE,	/* nowhere (ignore) */
SC_LINE_UP,	/* one line up */
SC_LINE_DOWN,	/* one line down */
SC_PAGE_UP,	/* previous page */
SC_PAGE_DOWN,	/* next page */
SC_THUMB,	/* thumb repositioning */
SC_THUMBTRACK	/* thumb tracking */
} SCROLL_CONTROL;

typedef enum {	/* type of window */

W_NONE,		      /* marker for end of WIN_DEF array */
W_DOC,	        /* document window */
W_PLAIN,	      /* window with plain border */
W_DBL,	        /* window with double border */
W_PRINT,	      /* XVT internal use only */
W_TASK,	        /* task window */
W_SCREEN,	      /* screen window */
W_NO_BORDER,	  /* no border */
W_PIXMAP,	      /* pixmap */
W_MODAL,	      /* modal window */
WD_MODAL,	      /* modal dialog */
WD_MODELESS,	  /* modeless dialog */
WC_PUSHBUTTON,	/* button control */
WC_RADIOBUTTON,	/* radio button control */
WC_CHECKBOX,	  /* check box control */
WC_HSCROLL,	    /* horizontal scrollbar control */
WC_VSCROLL,	    /* vertical scrollbar control */
//WC_EDIT,	/* edit control */              commentato perche' rompe le scatole
WC_TEXT,	      /* static text control */
WC_LBOX,	      /* list box control */
WC_LISTBUTTON,	/* button with list */
WC_CHECKBUTTON, /* check button control */
WC_LISTEDIT,	  /* edit with field list */
WC_GROUPBOX,	  /* group box */
WC_TEXTEDIT,	  /* text edit object */
WC_ICON,	      /* icon control */
WO_TE,          /* text edit */
WC_HGAUGE,      /* horizontal progress bar */
WC_VGAUGE,      /* vertical progress bar */
WC_NOTEBK,      /* notebook control */
WC_HTML,        /* HTML control */
WC_TREE,        /* tree view */
WC_OUTLOOKBAR,  /* Barra di outlook */
WC_HSLIDER,     /* horizontal slider control */
WC_VSLIDER,     /* vertical slider control */
WC_POPUP,       /* list of listedit control or popup menu */
WC_PROPGRID,    /* property grid */
WC_MVC,         /* model view controller */
WC_TREELIST,    /* tree list */
} WIN_TYPE;

typedef enum {
SEV_NONE,
SEV_WARNING,
SEV_ERROR,
SEV_FATAL,
} XVT_ERRSEV;

typedef enum {	/* type of scrollbar */

HSCROLL,	/* horizontal */
VSCROLL,	/* vertical */
HVSCROLL,	/* either */
HVGAUGE,  /* progress bar */
HVSLIDER, /* slider */

} SCROLL_TYPE;

/* Treeview - Types */

typedef void * XVT_TREEVIEW_NODE;

typedef enum e_treeview_node_type {
    XVT_TREEVIEW_NODE_TERMINAL,           /* leaf - no children */
    XVT_TREEVIEW_NODE_NONTERMINAL,        /* branch - may have children */
    XVT_ENUM_DUMMY26 = XVT_CC_ENUM_END
} XVT_TREEVIEW_NODE_TYPE;

typedef XVT_CALLCONV_TYPEDEF( BOOLEAN, XVT_TREEVIEW_CALLBACK,
         (WINDOW ctl_win, XVT_TREEVIEW_NODE node) );

typedef struct s_ctlinfo {

WIN_TYPE type;
WINDOW win;		
union {

struct s_scroll {

SCROLL_CONTROL what;
short pos;

} scroll;
struct s_edit {

BOOLEAN focus_change;
BOOLEAN active;

} edit;
struct s_lbox {

BOOLEAN dbl_click;

} lbox;
struct s_listedit {

BOOLEAN focus_change;
BOOLEAN active;

} listedit;
struct s_notebk {

    WINDOW page;
    short  page_new;
    short  page_old;

} notebk;
struct s_html {

    int reserved;            /* Reserved...no usage yet.*/

} html;
struct s_treeview {

    XVT_TREEVIEW_NODE node;  /* Node */
    BOOLEAN sgl_click;       /* Single click */
    BOOLEAN dbl_click;       /* Double click */
    BOOLEAN expanded;        /* Node was expanded */
    BOOLEAN collapsed;       /* Node was collapsed */

} treeview;

} v;

} CONTROL_INFO;

typedef struct s_xvt_color_component {
XVT_COLOR_TYPE type;	/* color component being defined */
COLOR color;	/* RGB color value */
} XVT_COLOR_COMPONENT;

typedef enum s_xvt_color_action {
XVT_COLOR_ACTION_SET,/* set the colors */
XVT_COLOR_ACTION_UNSET/* unset the colors */
} XVT_COLOR_ACTION;

typedef struct s_win_def {
  WIN_TYPE wtype;	/* WC_* or WO_* type */
  RCT rct;
  char *text;
  UNIT_TYPE units;
  XVT_COLOR_COMPONENT * ctlcolors;
  union {
    struct s_win_def_win {	/* WINDOW's */
      short int menu_rid;	/* menu resource id */
      MENU_ITEM *menu_p;	/* pointer to menu tree */
      long flags;	/* WSF_* flags */
      XVT_FNTID ctl_font_id;	/* control font id */
    } win;
    struct s_win_def_dlg {	/* DIALOG's */
      long flags;	/* WSF_* flags */
      XVT_FNTID ctl_font_id;	/* control font id */
    } dlg;
    struct s_win_def_ctl {	/* CONTROL's */
      short int ctrl_id;
      short int icon_id;	/* for icons only */
      long flags;	/* CTL_* flags */
      XVT_FNTID font_id;	/* logical font */
    } ctl;
    struct s_win_def_tx {	/* text edit objects */
      unsigned short attrib;	/* TX_* flags */
      XVT_FNTID font_id;	/* logical font */
      short margin;	/* right margin */
      short limit;	/* max chars */
      short int tx_id;	/* text ID */
    } tx;
  } v;
} WIN_DEF;

typedef enum {
E_CREATE,	/* creation */
E_DESTROY,	/* destruction */
E_FOCUS,	/* window focus gain/loss */
E_SIZE,	/* resize */
E_UPDATE,	/* update */
E_CLOSE,	/* close window request */
E_MOUSE_DOWN,	/* mouse down */
E_MOUSE_UP,	/* mouse up */
E_MOUSE_MOVE,	/* mouse move */
E_MOUSE_DBL,	/* mouse double click */
E_CHAR,	/* character typed */
E_VSCROLL,	/* vert. window scrollbar activity */
E_HSCROLL,	/* horz. window scrollbar activity */
E_COMMAND,	/* menu command */
E_FONT,	/* font menu selection */
E_CONTROL,	/* control activity */
E_TIMER,	/* timer */
E_QUIT,	/* application shutdown request */
E_HELP,	/* help invoked */
E_USER,	/* user defined */
E_CXO,	/* cxo event */
E_PROCESS, /* child process terminated */
} EVENT_TYPE;


typedef struct s_event {
  EVENT_TYPE type;
  union _v {
    struct s_mouse {        /* E_MOUSE_DOWN, E_MOUSE_UP, E_MOUSE_MOVE, E_MOUSE_DBL */
      PNT where;            /* location of event (window relative) */
      BOOLEAN shift;        /* shift key down? */
      BOOLEAN control;      /* control or option key down? */
      short button;         /* button number */
    } mouse;
    struct s_char {         /* E_CHAR */
      XVT_WCHAR ch;         /* wide character */
      BOOLEAN shift;        /* shift key down? */
      BOOLEAN control;      /* control or option key down? */
      BOOLEAN virtual_key;  /* ch contains virtual key or not? */
      unsigned long modifiers; /* bit field of key modifiers */
    } chr;
    BOOLEAN active;         /* E_FOCUS: activation? (vs. deactivation) */
    BOOLEAN query;          /* E_QUIT: query only? (app calls quit_OK) */
    struct s_scroll_info {  /* E_VSCROLL, E_HSCROLL */
      SCROLL_CONTROL what;  /* site of activity */
      short pos;            /* thumb position, if SC_THUMB */
    } scroll;
    struct s_cmd {          /* E_COMMAND */
      MENU_TAG tag;         /* menu item tag */
      BOOLEAN shift;        /* shift key? */
      BOOLEAN control;      /* control or option key? */
    } cmd;
    struct s_size {         /* E_SIZE */
      short height;         /* new height */
      short width;          /* new width */
    } size;
    struct s_efont {        /* E_FONT */
      XVT_FNTID font_id;    /* R4 font id of selected font */
   } font;
    struct s_ctl {          /* E_CONTROL */
      short id;             /* control's ID */
      CONTROL_INFO ci;      /* control info */
    } ctl;
    struct s_update {       /* E_UPDATE */
      RCT rct;              /* update rectangle */
    } update;
    struct s_timer {        /* E_TIMER */
      long id;              /* timer ID */
    } timer;
    struct s_user {         /* E_USER */
      long id;              /* application ID */
      void *ptr;            /* application pointer */
    } user;
    struct s_help {         /* E_HELP */
      WINDOW obj;           /* help for control, window, dialog */
      MENU_TAG tag;         /* help for menu item */
      XVT_HELP_TID  tid;    /* predefined help topic */
    } help;
    struct s_cxo {          /* E_CXO */
      long msg_id;          /* CXO message id - Unique to each CXO */
      void * ptr;           /* message data pointer */
    } cxo;
    struct s_process {      /* E_PROCESS */
      long pid;             /* PID of started/terminated process */
      int msg_id;           /* 0=started; 1=stopped */
      int exit_code;
    } process;
  } v;
} EVENT, *EVENT_PTR;

typedef unsigned long EVENT_MASK;
typedef long (* EVENT_HANDLER) (WINDOW win, EVENT *ep);
typedef BOOLEAN (* XVT_ERRMSG_HANDLER) (XVT_ERRMSG err, DATA_PTR context);
typedef BOOLEAN (* XVT_ENUM_CHILDREN)(WINDOW child, long data);

typedef enum {	/* std. clipboard format */
CB_TEXT,	/* ASCII text */
CB_PICT,	/* encapsulated picture */
CB_APPL	/* app's own (must have name) */
} CB_FORMAT;

typedef struct s_xvt_config 
{
  short menu_bar_ID;	        /* task menubar ResID */
  short about_box_ID;	        /* default aboutbox ResID */
  const char* base_appl_name;	/* application's "filename" */
  const char* appl_name;	    /* application's name */
  const char* taskwin_title;	/* title for task window */
} XVT_CONFIG;