1 /*
2  *  WINSYS.H
3  *
4  *  Written on 10-Jul-94 by John Dennis and released to the public domain.
5  *
6  *  Header file for a system-independant windowing system.
7  */
8 
9 #ifndef __WINSYS_H__
10 #define __WINSYS_H__
11 
12 #ifndef TRUE
13 #define TRUE 1
14 #endif
15 
16 #ifndef FALSE
17 #define FALSE 0
18 #endif
19 
20 #define WND_ERROR         -1
21 #define WND_NOERR         1
22 #define NBDR              0x01     /* No Border             */
23 #define SBDR              0x02     /* Single border         */
24 #define DBDR              0x04     /* Double Border         */
25 #define SHADOW            0x08     /* We have a shadow      */
26 #define INSBDR            0x10     /* Inset border          */
27 #define NOSAVE            0x20     /* don't save background */
28 #define NOMOUSE           0x40     /* we don't want a mouse */
29 
30 #define MOUSE_EVT         0xff     /* Undefined event       */
31 #define RMOU_CLCK         0xfe     /* Right button clicked  */
32 #define LMOU_CLCK         0xfd     /* Left button clicked   */
33 #define LMOU_RPT          0xfc     /* Button repeating   */
34 #define RMOU_RPT          0xf7     /* Button repeating   */
35 #define MOU_LBTDN         0xfb     /* Left button pressed   */
36 #define MOU_RBTDN         0xfa     /* Right button pressed  */
37 #define MOU_LBTUP         0xf9     /* Left button released  */
38 #define MOU_RBTUP         0xf8     /* Right button released */
39 
40 #define VERT_SCRL         0xf7     /* not used yet.. urk... */
41 #define HORZ_SCRL         0xf6
42 #define WM_SCRLFT         0xf5
43 #define WM_SCRRGT         0xf4
44 #define WM_SCRLUP         0xf3
45 #define WM_SCRLDN         0xf2
46 #define WM_SPGDN          0xf1
47 #define WM_SPGUP          0xef
48 
49 /* colours */
50 
51 #define BLACK             0x00     /* Black                 */
52 #define BLUE              0x01     /* Blue                  */
53 #define GREEN             0x02     /* Green                 */
54 #define CYAN              0x03     /* Cyan                  */
55 #define RED               0x04     /* Red                   */
56 #define MAGENTA           0x05     /* Magenta               */
57 #define BROWN             0x06     /* Brown                 */
58 #define LGREY             0x07     /* Light grey (white)    */
59 #define DGREY             0x08     /* Dark grey             */
60 #define LBLUE             0x09     /* Light blue            */
61 #define LGREEN            0x0A     /* Light green           */
62 #define LCYAN             0x0B     /* Light cyan            */
63 #define LRED              0x0C     /* Light red             */
64 #define LMAGENTA          0x0D     /* Light magenta         */
65 #define YELLOW            0x0E     /* Yellow                */
66 #define WHITE             0x0F     /* Intense white         */
67 #define INTENSE           0x08     /* Intensity bit         */
68 
69 #define _BLACK            0x00     /* Black                 */
70 #define _BLUE             0x10     /* Blue                  */
71 #define _GREEN            0x20     /* Green                 */
72 #define _CYAN             0x30     /* Cyan                  */
73 #define _RED              0x40     /* Red                   */
74 #define _MAGENTA          0x50     /* Magenta               */
75 #define _BROWN            0x60     /* Brown                 */
76 #define _LGREY            0x70     /* White                 */
77 #define _DGREY            0x80     /* Blink/dark grey       */
78 #define _LBLUE            0x90     /* Blink/light blue      */
79 #define _LGREEN           0xA0     /* Blink/light green     */
80 #define _LCYAN            0xB0     /* Blink/light cyan      */
81 #define _LRED             0xC0     /* Blink/light red       */
82 #define _LMAGENTA         0xD0     /* Blink/light magenta   */
83 #define _YELLOW           0xE0     /* Blink/light yellow    */
84 #define _WHITE            0xF0     /* Blink/light white     */
85 #define _BLINK            0x80     /* Blink/intensity bit   */
86 #define _TRANSPARENT      0x100    /* transparent background, for Unix */
87 
88 #define F_NORMAL         0x000     /* Normal Font    */
89 #define F_ALTERNATE      0x100     /* Alternate Font */
90 
91 #define MAKECELL(ch, at) ((unsigned long)(((unsigned long)((unsigned char)(ch))) | \
92                                           (((unsigned long)(at)) << 16)))
93 
94 
95 /* hotspot related stuff */
96 
97 #define MAX_HOTS          30       /* max # of hot spots per group */
98 #define MAX_HOT_GROUP     40       /* max # of HotGroups */
99 #define WND_WM_MOUSE      0x01     /* we got a Mouse Message */
100 #define WND_WM_CHAR       0x02     /* we got a keyboard message */
101 #define WND_WM_RESIZE     0x03     /* the window has been resized */
102 #define WND_WM_COMMAND    0x0020   /* we got a recognized id (was 0x04) */
103 
104 /* these are wid's reserved for useage - wids start at 20 */
105 
106 #define WND_WN_MENU       1L
107 #define WND_WN_WIND       2L
108 
109 /* kludge time! :-) */
110 
111 /* defines local terminal characteristics */
112 
113 typedef struct _term
114 {
115     short NCol;                 /* Number Rows  0 org */
116     short NRow;                 /* Number Columns 0 org */
117     unsigned char Abil;         /* Abilities of Terminal */
118 }
119 TERM;
120 
121 #ifdef UNIX     /* prevent a name clash with term.h */
122 #define term msged_term
123 #endif
124 
125 
126 #ifndef TERMDEF
127 #if defined(UNIX) || defined(Cygwin)
128 volatile
129 #endif
130 extern TERM term;
131 #endif
132 
133 typedef struct _window
134 {
135     unsigned long wid;
136     unsigned char x1;           /* screen coordinates (no shadow) */
137     unsigned char y1;
138     unsigned char x2;
139     unsigned char y2;
140     unsigned char wattr;        /* window forground attribute */
141     unsigned char battr;        /* border background attr */
142     unsigned char flags;        /* SHADOW DBDR SBDR IBDR TITLE */
143     char *title;                /* pointer to title memory */
144     unsigned long **buffer;    /* screen save buffer (screen behind) */
145     struct _window *next;       /* pointer to window above this one */
146     struct _window *prev;       /* pointer to window below this one */
147 }
148 WND;
149 
150 /* Mouse event structure */
151 /* not used much now */
152 
153 typedef struct _mou
154 {
155     unsigned int event;         /* event number */
156     int x;                      /* location x,y */
157     int y;
158     int lbutton;                /* left button down */
159     int rbutton;                /* left button down */
160     int lrelease;               /* left button has been released */
161     int rrelease;               /* right button has been released */
162     int repeat;                 /* repeat? */
163 }
164 MOU;
165 
166 /* An input event */
167 
168 typedef struct _event
169 {
170     int x, y;                   /* location */
171     int msgtype;                /* message type */
172     int msg;                    /* message */
173     int id;
174 }
175 EVT;
176 
177 /*
178  *  This is a group of hot-spots - they're usually pushed onto the
179  *  global stack.  id MUST be unique for it to be effective.  Currently,
180  *  the ID must be manually added; this may change in the future.
181  */
182 
183 typedef struct _hotgrp
184 {
185     unsigned long wid;          /* window ID for this group.  0 = ignored */
186     int num;                    /* number of hotspots in this group */
187     struct
188     {                           /* individual hotspots */
189         int id;                 /* identifier for item */
190         int x1;                 /* coordinates */
191         int y1;
192         int x2;
193         int y2;
194         void *ctl;              /* pointer to structure containing item */
195     }
196     harr[MAX_HOTS];
197 }
198 HotGroup;
199 
200 /*
201  *  Window terminal functions for use by higher modules.  Each
202  *  system-dependant module should provide these functions.
203  */
204 
205 int  TTScolor(unsigned int Attr);
206 int  TTopen(void);
207 int  TTclose(void);
208 int  TTkopen(void);
209 int  TTkclose(void);
210 int  TTCurSet(int);
211 int  TTgotoxy(int row, int col);
212 int  TTgetxy(int *row, int *col);
213 int  TTconfigure(const char *, const char *);
214 int  TTGetChr(void);
215 int  TTPutChr(unsigned int Ch);
216 int  TTWriteStr(unsigned long *b, int len, int row, int col);
217 int  TTStrWr(unsigned char *s, int row, int col, int len);
218 int  TTReadStr(unsigned long *b, int len, int row, int col);
219 int  TTClear(int x1, int y1, int x2, int y2);
220 int  TTScroll(int x1, int y1, int x2, int y2, int lines, int Dir);
221 int  TTEeol(void);
222 int  TTdelay(int mil);
223 int  TTGetMsg(EVT * event);
224 unsigned int TTGetKey(void);
225 void  MouseOFF(void);
226 void  MouseON(void);
227 void  MouseInit(void);
228 void  MouseClose(void);
229 int  GetMouInfo(int *x, int *y);
230 void TTClearQue(void);
231 int  TTPeekQue(void);
232 void TTBeginOutput(void); /* suppresses screen drawing until ... */
233 void TTEndOutput(void);   /* .. ttendoutput is called. This improves speed! */
234 
235 /* routines from the window module (system independant) */
236 
237 WND *WndOpen(int x1, int y1, int x2, int y2, int Bdr, int BAttr, int Attr);
238 WND *WndPopUp(int wid, int dep, int Bdr, int BAttr, int NAttr);
239 void WndClose(WND * w);
240 void WndBox(int x1, int y1, int x2, int y2, int Attr, int type);
241 void WndTitle(const char *Str, int Attr);
242 void WndWriteStr(int x, int y, int Attr, char *Str);
243 void WndPutsCen(int y, int Attr, char *Str);
244 int WndPrintf(int x, int y, int Attr, char *Str, ...);
245 void WndPutsn(int x, int y, int len, int Attr, char *Str);
246 void WndScroll(int x1, int y1, int x2, int y2, int dir);
247 void WndCurr(WND * hWnd);
248 WND *WndTop(void);
249 void WndPutc(int Ch, int Attr);
250 void WndGotoXY(int x, int y);
251 void WndClear(int x1, int y1, int x2, int y2, int attr);
252 int WndGetLine(int x, int y, int len, char *buf, int Attr, int *pos, int nokeys, int fil, int disp, EVT * ev);
253 void WndClearLine(int y, int Att);
254 void WndFillField(int x, int y, int len, unsigned char ch, int Attr);
255 void WndGetRel(int x, int y, int *wx, int *wy);
256 
257 /* Routines from system module (system independent) */
258 
259 void PushHotGroup(HotGroup * New);
260 void PopHotGroup(void);
261 int LocateHotItem(int x, int y, unsigned long wid);
262 unsigned int MnuGetMsg(EVT * event, unsigned long wid);
263 
264 extern int wnd_suppress_shadows;
265 extern int wnd_force_monochrome;
266 extern int wnd_bs_127;
267 
268 extern int window_resized;
269 
270 
271 #endif
272