/*===========================================================================*/
/*                                                                           */
/* File    : WINDOW.H                                                        */
/*                                                                           */
/* Purpose : Main header file for the window manager                         */
/*                                                                           */
/* History :                                                                 */
/*                                                                           */
/* (C) Copyright 1989 Marc Adler/Magma Systems     All Rights Reserved       */
/*===========================================================================*/

#define NO      0
#define YES     1
#define FALSE   0
#define TRUE    1
#ifndef NULL
#define NULL    (char *) 0
#endif

#ifndef max
#define max(a,b)        ( ((a) > (b)) ? (a) : (b) )
#endif
#ifndef min
#define min(a,b)        ( ((a) < (b)) ? (a) : (b) )
#endif

#ifdef OS2
#define BOOL          char
#else
typedef char          BOOL;
#endif
typedef unsigned char BYTE;
typedef unsigned int  WORD;
#ifdef OS2
#define LONG          long
#else
typedef long          LONG;
#endif
typedef unsigned long DWORD;
typedef BYTE far      *LPSTR;
typedef int (far pascal *FARPROC)();

typedef WORD     HANDLE;
#ifdef OS2
#define HWND     HANDLE
#else
typedef HANDLE   HWND;
#endif
typedef HWND     HMENU;
typedef HWND     HDLG;
typedef HANDLE   HACCEL;
#define NULLHWND  ((HWND)  0)
#define NULLHMENU ((HMENU) 0)

#ifndef MAKELONG
#define MAKELONG(lo,hi) ((long)(((WORD)(lo)) | ((DWORD)((WORD)(hi))) << 16))
#endif
#define LOWORD(l)       ((WORD) (l))
#define HIWORD(l)       ((WORD)(((DWORD)(l) >> 16) & 0xFFFF))


typedef struct point
{
  int   x, y;
} POINT;

typedef struct rectangle
{
  int   left,
        right,
        top,
        bottom;
} RECT;
#define RECTGEN(r, row1, col1, row2, col2) \
        {\
          r.top    = row1;\
          r.left   = col1;\
          r.bottom = row2;\
          r.right  = col2;\
        }

typedef struct wndClass
{
  struct wndClass *next;
  DWORD dwStyle;
  int   (pascal *pfnWndProc)();
  int   (pascal *pfnDefWndProc)();
  int   cbClsExtra;                /* # of extra bytes for the class */
  int   cbWndExtra;
  char  *szClassName;
  char  *szBaseClass;
  WORD  idClass;
} WNDCLASS;


typedef struct window
{
  struct window *next;		/* hook onto WindowList */
  struct window *parent;
  struct window *children;
  struct window *sibling;
  HWND     win_id;      /* window handle */
  WORD     idCtrl;      /* control ID for control windows */
  HWND     hMenu;       /* handle to a menubar */
  RECT     rect;        /* window dimensions */
  RECT     rClient;     /* client area dimensions */
  unsigned attr;        /* color attribute */
  int      fillchar;    /* char to draw window background with */
  int      row;         /* cursor row */
  int      col;         /* cursor col */
  int      iMonitor;		/* in case of multiple monitors, the monitor id */
  char     *title;      /* title in border */
  int      class;       /* class id */
#define NORMAL_CLASS      0
#define BUTTON_CLASS      1
#define EDIT_CLASS        2
#define LISTBOX_CLASS     3
#define SCROLLBAR_CLASS   4
#define STATIC_CLASS      5
#define PUSHBUTTON_CLASS  6
#define CHECKBOX_CLASS    7
#define RADIOBUTTON_CLASS 8
#define TEXT_CLASS        9
#define FRAME_CLASS       10
#define BOX_CLASS         11
#define USER_CLASS        20
  int      (pascal *winproc)();    /* ptr to the window procedure */
  DWORD    flags;
#define WIN_HAS_BORDER  0x00000001L
#define WIN_ZOOMED      0x00000002L
#define WIN_HIDDEN      0x00000004L
#define WIN_DISABLED    0x00000008L
#define SHADOW_TOPLEFT  0x00000010L
#define SHADOW_BOTLEFT  0x00000020L
#define SHADOW_TOPRIGHT 0x00000040L
#define SHADOW_BOTRIGHT 0x00000080L
#define WIN_CHECKBOX    0x00000100L
#define WIN_RADIOBUTTON 0x00000200L
#define WIN_PUSHBUTTON  0x00000400L
#define WIN_VSCROLL     0x00001000L
#define WIN_HSCROLL     0x00002000L
#define WIN_HAS_SHADOW  0x00004000L
#define WIN_STTEXT      0x00010000L
#define WIN_STFRAME     0x00020000L
#define WIN_STBOX       0x00040000L
#define WIN_SIZEBOX     0x00100000L
#define WIN_MOVEBOX     0x00200000L
#define WIN_BIT_RESERVED 0x80000000L  /* reserved for use by misc functions */
/* edit styles */
#define ES_MULTILINE    0x00010000L
#define ES_AUTOVSCROLL  0x00020000L
#define ES_AUTOHSCROLL  0x00040000L
/* dialog item styles */
#define WS_TABSTOP      0x00400000L
#define WS_GROUP        0x00800000L
#define WS_CLIP         0x01000000L
#define WS_SAVEBITS     0x02000000L

  DWORD      ulStyle;

#ifndef cwExtra
#define cwExtra 32
#endif
  char     szClassExtra[cwExtra];
  char     *pWinExtra;
  char     *pSavedRect;  /* for WS_SAVEBITS */
} WINDOW;


/*
  Private global variables
*/
extern WINDOW *WindowList;
extern HWND   CurrFocusWnd;
extern HWND   CaptureWnd;

/*
  Height and Width macros
*/
#define RECT_HEIGHT(r)          ((r).bottom - (r).top + 1)
#define RECT_WIDTH(r)           ((r).right - (r).left + 1)
#define WIN_HEIGHT(w)           ((w)->rect.bottom-(w)->rect.top+1)
#define WIN_WIDTH(w)            ((w)->rect.right-(w)->rect.left+1)
#define WIN_CLIENT_HEIGHT(w)    ((w)->rClient.bottom-(w)->rClient.top+1)
#define WIN_CLIENT_WIDTH(w)     ((w)->rClient.right-(w)->rClient.left+1)

/*
  Border Styles for WinDrawBorder()
*/
#define BORDER_SINGLE   0
#define BORDER_DOUBLE   1
#define BORDER_DASHED   2


/*===========================================================================*/
/*                                                                           */
/*                          MICROSOFT WINDOWS compatability                  */
/*                                                                           */
/*===========================================================================*/

#define ChildWindowFromPoint(hWnd,pt)  WinChildWindowFromPoint(hWnd,pt.y,pt.x)
#define CloseWindow(hWnd)       WinCloseWindow(hWnd)
#define DestroyWindow(hWnd)     WinDestroy(hWnd)
#define EnableWindow(hWnd,f)    WinEnable(hWnd,f)
#define GetCapture()						(CaptureWnd)
#define GetClientRect(hWnd,r)   (*(r) = WinGetClient(hWnd))
#define GetDlgItemText(h,id,s,n) GetDialogText(h,id,s,n)
#define GetFocus()	  					(CurrFocusWnd)
#define GetNextWindow(hWnd,f)	  WinGetNextWindow(hWnd, f)
#define GW_HWNDNEXT							1
#define GW_HWNDPREV							2
#define GetParent(hWnd)     		WinGetParent(hWnd)
#define GetTopWindow(hWnd)      WinGetFirstChild(hWnd)
#define GetWindowRect(hWnd,r)   (*(r) = WinGetRect(hWnd))
#define GetWindowText(hWnd,s,n) WinGetText(hWnd,s,n)
#define GetWindowTextLength(hWnd) WinGetTextLength(hWnd)
#define IsWindow(hWnd)					WinIsWindow(hWnd)
#define IsWindowEnabled(hWnd)   (!(WinGetFlags(hWnd) & WIN_DISABLED))
#define IsWindowVisible(hWnd)   (!(WinGetFlags(hWnd) & WIN_HIDDEN))
#define PostMessage(h,m,w,l)    PostWinMessage(h,m,w,l)
#define SendMessage(h,m,w,l)    SendWinMessage(h,m,w,l)
#define SetDlgItemText(h,id,s)  SetDialogText(h,id,s)
#define SetParent(hWnd,hParent) WinSetParent(hWnd, hParent)
#define SetWindowText(hWnd,s)   WinSetText(hWnd,s)
#define ShowWindow(hWnd,bVis)   WinShowWindow(hWnd, bVis)
#define WindowFromPoint(pt)     WinPointToID(pt.y, pt.x)


/*===========================================================================*/
/*                                                                           */
/*                          MESSAGES                                         */
/*                                                                           */
/*===========================================================================*/

#define WM_NULL        0
#define WM_CREATE      1
#define WM_ACTIVATE    2
#define WM_SETFOCUS    3
#define WM_KILLFOCUS   4
#define WM_PAINT       5
#define WM_QUIT        6
#define WM_HIDE        7
#define WM_UNHIDE      8
#define WM_SHOW        9
#define WM_GETTEXT     10
#define WM_SETTEXT     11
#define WM_GETTEXTLENGTH 12
#define WM_ERASEBKGND  13
#define WM_CLOSE       14
#define WM_SIZE        15
#define WM_MOVE        16
#define WM_BORDER      17
#define WM_GETID       18
#define WM_SETID       19
#define WM_HELP        80
#define WM_DESTROY     99

#define WM_KEYFIRST    0x0100
#define WM_KEYLAST     0x0107

#define WM_KEYDOWN     0x0100
#define WM_KEYUP       0x0101
#define WM_CHAR        0x0102

#define WM_CUT         0x0103
#define WM_PASTE       0x0104
#define WM_COPY        0x0105

#define WM_COMMAND     0x0111
#define WM_MENUSELECT  0x0112          /* selecting a menu item */
#define WM_MENUSTART   0x0113          /* starting a menu action */
#define WM_HSCROLL     0x0114
#define WM_VSCROLL     0x0115
#define WM_INITMENUPOPUP  0x0116
#define WM_INITDIALOG  0x0117
#define WM_TIMER       0x0120

#define WM_MOUSEFIRST  0x0200
#define WM_LMOUSELAST  0x0203  /* last of Left mouse actions */
#define WM_MOUSELAST   0x0210

#define WM_MOUSEMOVE            0x0200
#define WM_LBUTTONDOWN          0x0201
#define WM_LBUTTONUP            0x0202
#define WM_LBUTTONDBLCLK        0x0203
#define WM_RBUTTONDOWN          0x0204
#define WM_RBUTTONUP            0x0205
#define WM_RBUTTONDBLCLK        0x0206
#define WM_MBUTTONDOWN          0x0207
#define WM_MBUTTONUP            0x0208
#define WM_MBUTTONDBLCLK        0x0209
#define WM_MOUSEREPEAT          0x0210

/* Edit box messages */
#define EM_SETSEL               0x0300
#define EM_GETSEL               0x0301
#define EM_LIMITTEXT            0x0302
#define EM_GETMODIFY            0x0303
#define EM_CANUNDO              0x0304
#define EM_GETHANDLE            0x0305
#define EM_GETLINE              0x0306
#define EM_GETLINECOUNT         0x0307
#define EM_LINEFROMCHAR         0x0308
#define EM_LINEINDEX            0x0309
#define EM_LINELENGTH           0x030A
#define EM_LINESCROLL           0x030B
#define EM_REPLACESEL           0x030C
#define EM_SETHANDLE            0x030D
#define EM_SETMODIFY            0x030E

/* Edit notification messages */
#define EN_CHANGE								0x0310
#define EN_SETFOCUS						  0x0311
#define EN_KILLFOCUS						0x0312
#define EN_HSCROLL  						0x0313
#define EN_VSCROLL  						0x0314
#define EN_ERRSPACE 						0x0315

/* ListBox messages */
#define LB_ADDSTRING            0x0400
#define LB_INSERTSTRING         0x0401
#define LB_DELETESTRING         0x0402
#define LB_SELECTSTRING         0x0403
#define LB_SETCURSEL            0x0404
#define LB_SETSEL               0x0405
#define LB_GETCOUNT             0x0406
#define LB_GETCURSEL            0x0407
#define LB_GETSEL               0x0408
#define LB_GETTEXT              0x0409
#define LB_GETTEXTLEN           0x040A
#define LB_DIR                  0x040B
#define LB_RESETCONTENT         0x040C

/* Listbox Notification messages */
#define LBN_DBLCLK              0x040C
#define LBN_ERRSPACE            0x040D
#define LBN_SELCHANGE           0x040E

/* Error messages */
#define WM_OUTOFMEMORY          0x1000

#define WM_USER                 0x7000


/*===========================================================================*/
/*                                                                           */
/*                SYSTEM COLOR INFORMATION                                   */
/*                                                                           */
/*===========================================================================*/

extern BOOL bUseSysColors;  /* TRUE if using system colors */

#define SYSCLR_FIRST              0

#define SYSCLR_BACKGROUND         0
#define SYSCLR_SHADOW             1
#define SYSCLR_MENUTEXT           2
#define SYSCLR_MENU               3
#define SYSCLR_MENUGRAYEDTEXT     4
#define SYSCLR_MENUHILITETEXT     5
#define SYSCLR_MENUHILITESEL      6
#define SYSCLR_WINDOWTEXT         7
#define SYSCLR_WINDOWSTATICTEXT   8
#define SYSCLR_WINDOW             9
#define SYSCLR_SCROLLBAR          10
#define SYSCLR_SCROLLBARARROWS    11
#define SYSCLR_SCROLLBARTHUMB     12
#define SYSCLR_ACTIVEBORDER       13
#define SYSCLR_INACTIVEBORDER     14
#define SYSCLR_HELPTEXT           15
#define SYSCLR_HELPHILITE         16
#define SYSCLR_HELPBACKGROUND     17
#define SYSCLR_MESSAGEBOX         18
#define SYSCLR_DLGBOX             19
#define SYSCLR_DLGACCEL           20
#define SYSCLR_BUTTON             21
#define SYSCLR_BUTTONDOWN         22
#define SYSCLR_LAST               22


/*===========================================================================*/
/*                                                                           */
/*                       EVENT INFORMATION                                   */
/*                                                                           */
/*===========================================================================*/

#define MAXEVENTS    256       /* Length of the message queue */

typedef struct event
{
  HWND   hWnd;
  WORD   message;
  WORD   wParam;
  DWORD  lParam;
} EVENT;


/*===========================================================================*/
/*                                                                           */
/*                       MESSAGE BOX INFORMATION                             */
/*                                                                           */
/*===========================================================================*/

#define IDOK         1
#define IDCANCEL     2
#define IDNO         3
#define IDYES        4

#define MB_OK         0
#define MB_OKCANCEL   1
#define MB_YESNO      2
#define MB_BUTTON1DEF 0x0100
#define MB_BUTTON2DEF 0x0200
#define MB_BUTTON3DEF 0x0300
#define MB_DEFMASK    0x0700


/*===========================================================================*/
/*                                                                           */
/*                       BUTTON INFORMATION                                  */
/*                                                                           */
/*===========================================================================*/

typedef struct pushbutton
{
  char     *button_text;
  unsigned flags;
#define BUTTON_DISMISS  0x0001       /* TRUE if this dismisses the msgbox  */
#define BUTTON_DEFAULT  0x0002       /* TRUE if this is the default button */
#define BUTTON_INVERTED 0x0004       /* TRUE if it is inverted */
#define BUTTON_HELP     0x0008       /* TRUE if it generates WM_HELP */
} PUSHBUTTON;

typedef struct checkboxinfo
{
  int  state;
  int  checkchar;
} CHECKBOXINFO;

typedef struct radiogroup
{
  int  numbuttons;
  int  hButton[32];
} RADIOGROUP;


/* Button messages */
#define BM_GETCHECK		0x500
#define BM_GETSTATE		0x501
#define BM_SETCHECK		0x502
#define BM_SETSTATE		0x503
#define BM_SETSTYLE 	0x504

/* Button Notification Messages */
#define BN_CLICKED 		0x510
#define BN_DISABLE 		0x511
#define BN_DOUBLECLICKED 0x512
#define BN_HILITE  		0x513
#define BN_PAINT   		0x514
#define BN_UNHILITE 	0x515

/* Dialog-Button messages */
#define DM_GETDEFID		0x530
#define DM_SETDEFID		0x531


/*===========================================================================*/
/*                                                                           */
/*                       LISTBOX INFORMATION                                 */
/*                                                                           */
/*===========================================================================*/

#include "list.h"

#define ATEND		-1
#define ATSTART  0

typedef struct listbox
{
  int  nStrings;		/* number of strings in the listbox */
  int  iTopLine;		/* index of string currently at the top of the box */
  int  iCurrSel;    /* index of currently selected item */
  WORD flags;		    /* status info */
  int  (*pfSort)(); /* ptr to a sorting proc to be used for LB_SORT */
  LIST *strList;		/* linked list of strings */
  HWND hListBox;    /* back reference to listbox window handle */
} LISTBOX;


/* ListBox styles */
#define LBS_MULTIPLESEL	0x0001
#define LBS_NOREDRAW   	0x0002
#define LBS_NOTIFY     	0x0004
#define LBS_SORT       	0x0008
#define LBS_STANDARD   	(LBS_NOTIFY | LBS_SORT)

#define LB_ERR       (-2)
#define LB_ERRSPACE  (-3)


/*===========================================================================*/
/*                                                                           */
/*                       SCROLLBAR INFORMATION                               */
/*                                                                           */
/*===========================================================================*/

typedef struct scrollbar
{
  int    minpos, maxpos, currpos;
  int    thumbpos;   /* offset of thumb position from window top-left */
  unsigned sb_flags;
#define SB_VERT		0x0001
#define SB_HORIZ	0x0002
#define SB_HIDDEN 0x0004
} SCROLLBARINFO;


/* ScrollBar Messages */
#define SB_BOTTOM           1
#define SB_ENDSCROLL        2
#define SB_LINEDOWN         3
#define SB_LINEUP           4
#define SB_PAGEDOWN         5
#define SB_PAGEUP           6
#define SB_THUMBPOSITION    7
#define SB_THUMBTRACK       8
#define SB_TOP              9


/*===========================================================================*/
/*                                                                           */
/*                       STATIC INFORMATION                                  */
/*                                                                           */
/*===========================================================================*/

/* values for STATICINFO.flags */
#define STATIC_TEXT     0x0001
#define STATIC_FRAME    0x0002
#define STATIC_BOX      0x0004


/*===========================================================================*/
/*                                                                           */
/*                       MENU  INFORMATION                                   */
/*                                                                           */
/*===========================================================================*/

/* ChangeMenu flags */
#define MF_APPEND		  0x0001
#define MF_CHANGE		  0x0002
#define MF_INSERT		  0x0004
#define MF_DELETE		  0x0008

#define MF_BYPOSITION 0x0010
#define MF_BYCOMMAND  0x0020
#define MF_POPUP      0x0040
#define MF_STRING     0x0080

#define ATTR_MASK     0xFFC0

#define MF_CHECKED		0x0100
#define MF_UNCHECKED	0x0200
#define MF_DISABLED 	0x0400
#define MF_ENABLED 	  0x0800

#define MF_SEPARATOR  0x1000
#define MF_MENUBREAK  0x2000
#define MF_MENUBARBREAK 0x4000
#define MF_SHADOW     0x4000
#define MF_HELP       0x8000

/*===========================================================================*/
/*                                                                           */
/*                       VIDEO INFORMATION                                   */
/*                                                                           */
/*===========================================================================*/

#pragma pack(1)

typedef struct video
{
  unsigned char crt_mode;
  int      crt_cols;
  int      crt_len;
  unsigned crt_start;
  int      cursor_pos[8];
  unsigned cursor_mode;
  char     active_page;
  unsigned addr_6845;
  unsigned char crt_mode_set;
  unsigned char crt_pallette;
} BIOSVIDEOINFO;


extern struct videoinfo
{
  int       length,
            width;
  unsigned  segment;
  unsigned  starting_mode;
  unsigned  flags;
#define VIDEO_EGA       0x0001
#define VIDEO_NOSNOW    0x0002
} VideoInfo;


/*
  Color info
*/
#define INTENSE(color)          ( (color) | 0x08 )

#define BLACK           0
#define BLUE            1
#define GREEN           2
#define CYAN            3
#define RED             4
#define MAGENTA         5
#define YELLOW          6
#define WHITE           7
#define INTENSE_BLACK   INTENSE(BLACK)
#define INTENSE_BLUE    INTENSE(BLUE)
#define INTENSE_GREEN   INTENSE(GREEN)
#define INTENSE_CYAN    INTENSE(CYAN)
#define INTENSE_RED     INTENSE(RED)
#define INTENSE_MAGENTA INTENSE(MAGENTA)
#define INTENSE_YELLOW  INTENSE(YELLOW)
#define INTENSE_WHITE   INTENSE(WHITE)

#define MAKE_ATTR(fg, bg)       ( ((bg) << 4) | (fg) )
#define MAKE_HIGHLITE(attr)     ( (((attr) << 4) | ((attr) >> 4)) & 0x007F )

extern BOOL  NoSnow;
extern BOOL  ClrToEOL;
extern BYTE  ClrFillChar;
extern BYTE  HilitePrefix;
extern BYTE  Color;
extern WORD  Scr_Base;
extern BYTE  bUseMonoMap;
/* Monitor switching flags */
#define SAVE    0
#define RESTORE 1
extern int   CurrMonitor;
extern int   MaxDisplays;


/*===========================================================================*/
/*                                                                           */
/*                       CRITICAL INFORMATION                                */
/*                                                                           */
/*===========================================================================*/

#define WRITE_PROTECT_ERR  0x0
#define UNKNOWN_UNIT       0x1
#define DRIVE_NOT_READY    0x2
#define UNKNOWN_CMD        0x3
#define CRC_ERR            0x4
#define BAD_DRV_REQUEST    0x5
#define SEEK_ERR           0x6
#define UNKNOWN_MEDIA      0x7
#define SECTOR_NOT_FOUND   0x8
#define OUT_OF_PAPER       0x9
#define WRITE_FAULT        0xA
#define READ_FAULT         0xB
#define GENERAL_FAILURE    0xC

extern  unsigned Int24Err;
extern  char    *Int24ErrMsg;
#define SET_INT24_ERR(code)     Int24Err = ((1 << 8) | (code))
#define GET_INT24_ERR()         (Int24Err & 0x00FF)
#define CLR_INT24_ERR()         Int24Err = 0
#define IS_INT24_ERR()          (Int24Err)


/*---------------------------- MISC INFO --------------------------------*/

#include "sound.h"
#include "decls.h"
