1 //  This may look like C code, but it is really -*- C++ -*-
2 
3 //  ------------------------------------------------------------------
4 //  The Goldware Library
5 //  Copyright (C) 1990-1999 Odinn Sorensen
6 //  Copyright (C) 1999-2000 Alexander S. Aganichev
7 //  Copyright (C) 2000 Jacobo Tarrio
8 //  ------------------------------------------------------------------
9 //  This library is free software; you can redistribute it and/or
10 //  modify it under the terms of the GNU Library General Public
11 //  License as published by the Free Software Foundation; either
12 //  version 2 of the License, or (at your option) any later version.
13 //
14 //  This library is distributed in the hope that it will be useful,
15 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 //  Library General Public License for more details.
18 //
19 //  You should have received a copy of the GNU Library General Public
20 //  License along with this program; if not, write to the Free
21 //  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 //  MA 02111-1307, USA
23 //  ------------------------------------------------------------------
24 //  $Id: gwinall.h,v 1.1 2011/02/18 19:46:02 stas_degteff Exp $
25 //  ------------------------------------------------------------------
26 //  GCUI: Golded+ Character-oriented User Interface.
27 //  Windowing functions.
28 //  Based on CXL by Mike Smedley.
29 //  ------------------------------------------------------------------
30 
31 #ifndef __gwinall_h
32 #define __gwinall_h
33 
34 
35 //  ------------------------------------------------------------------
36 
37 #include <gdefs.h>
38 #include <gstrall.h>
39 #include <gkbdbase.h>
40 #include <gvidall.h>
41 
42 
43 //  ------------------------------------------------------------------
44 //  Error codes returned from windowing functions
45 
46 #define W_NOERROR   0       // no error
47 #define W_ESCPRESS  1       // Escape key was pressed
48 #define W_ALLOCERR  2       // memory allocation error
49 #define W_NOTFOUND  3       // record not found
50 #define W_NOACTIVE  4       // no active window
51 #define W_INVCOORD  5       // invalid coordinates
52 #define W_INVFORMT  6       // invalid format string
53 #define W_NOINPDEF  7       // no input fields defined
54 #define W_STRLONG   8       // string too long for window
55 #define W_INVBTYPE  9       // invalid box type
56 #define W_NOBORDER  10      // no window border
57 #define W_NOHIDDEN  11      // no hidden windows
58 #define W_NOTHIDD   12      // window is not hidden
59 #define W_NOSELECT  13      // no selectable menu items
60 #define W_NOITMDEF  14      // no menu items defined
61 #define W_NOMNUEND  15      // no end of menu specified
62 #define W_NOMNUDEF  16      // no menu defined
63 #define W_NOMNUBEG  17      // no begin of menu specified
64 #define W_NOFRMDEF  18      // no form defined
65 #define W_NOFRMBEG  19      // no begin of form specified
66 #define W_NOHLPDEF  20      // no help record defined
67 #define W_HLPSTKOV  21      // help stack overflow
68 #define W_HLPSTKUN  22      // help stack underflow
69 #define W_DOSERROR  23      // DOS error
70 #define W_NOMATCH   24      // no files matched input filespec
71 #define W_INVTAGID  25      // invalid tag identifier
72 
73 
74 //  ------------------------------------------------------------------
75 //  Window border identifiers
76 
77 #define TP_BORD  0      // top border
78 #define BT_BORD  1      // bottom border
79 #define LT_BORD  2      // left border
80 #define RT_BORD  3      // right border
81 
82 
83 //  ------------------------------------------------------------------
84 //  Direction codes
85 
86 #define D_DOWN    0
87 #define D_UP      1
88 #define D_LEFT    2
89 #define D_RIGHT   3
90 #define SDOWN     D_DOWN    // scroll down
91 #define SUP       D_UP      // scroll up
92 
93 
94 //  ------------------------------------------------------------------
95 //  Scrollbar orientation
96 
97 const int W_HORZ = 1;
98 const int W_VERT = 2;
99 
100 
101 //  ------------------------------------------------------------------
102 //  Menu item record definition
103 
104 struct _item_t {
105   _item_t*  prev;       // pointer to previous record
106   _item_t*  next;       // pointer to next record
107   void*     child;      // pointer to submenu's record
108   const char* str;      // address of selection string
109   const char* desc;     // text description of menu option
110   VfvCP     select;     // address of selection function
111   VfvCP     before;     // address of "before" function
112   VfvCP     after;      // address of "after"  function
113   gkey      hotkey;     // hot key to select function
114   int       tagid;      // tag identifier
115   int       help;       // help category number
116   int       wrow;       // start of text - window row
117   int       wcol;       // start of text - window column
118   char      schar;      // quick selection character
119   int       fmask;      // special feature mask
120   int       dwhdl;      // description window handle
121   int       dwrow;      // description window row
122   int       dwcol;      // description window column
123   vattr     dattr;      // description attribute
124   int       redisp;     // redisplay flag
125 };
126 
127 
128 //  ------------------------------------------------------------------
129 //  Window menu record definition
130 
131 struct _menu_t {
132   _menu_t*  prev;       // pointer to prev menu structure
133   _menu_t*  next;       // pointer to next menu structure
134   _menu_t*  parent;     // pointer to parent menu
135   _item_t*  item;       // pointer to head menu item
136   _item_t*  citem;      // pointer to current menu item
137   VfvCP     open;       // address of post-opening function
138   int       tagcurr;    // tag ID of item selection bar on
139   int       usecurr;    // will menu use current window?
140   int       srow;       // starting row of menu window
141   int       scol;       // starting column of menu window
142   int       erow;       // ending row of menu window
143   int       ecol;       // ending column of menu window
144   int       btype;      // menu window border type
145   vattr     battr;      // menu window "hi" border attribute
146   vattr     loattr;     // menu window "lo" border attribute
147   vattr     sbattr;     // menu window scrollbar attribute
148   vattr     wattr;      // menu window attribute
149   int       menutype;   // menu type mask
150   int       barwidth;   // width of menu bar or zero
151   int       textpos;    // offset of text from start of bar
152   vattr     textattr;   // attribute of menu text
153   vattr     scharattr;  // attribute of selection character
154   vattr     noselattr;  // non-selectable text attribute
155   vattr     barattr;    // attribute of selection bar
156   const char* title;    // menu title string or NULL if no title
157   int       titlepos;   // position of menu title (TLEFT,TCENTER,TRIGHT)
158   vattr     titleattr;  // attribute of menu title
159   vattr     shadattr;   // shadow attribute or -1 if no shadow
160   int       items;      // number of items in menu
161   bool      hotkey;
162 };
163 
164 
165 //  ------------------------------------------------------------------
166 //  Window input field definition
167 
168 struct _field_t {
169   _field_t*  prev;       // pointer to previous field
170   _field_t*  next;       // pointer to next field
171   char*      str;        // address of receiving string
172   char*      buf;        // address of temp receive string
173   const char* format;    // input field format string
174   IfcpCP     validate;   // address of validation function
175   VfvCP      before;     // address of "before" function
176   VfvCP      after;      // address of "after"  function
177   int        help;       // help category number
178   int        lenbuf;     // length of buffer
179   int        lenfld;     // length of screen input field
180   int        lenfmt;     // length of format string
181   int        wrow;       // start of input - window row
182   int        wcol;       // start of input - window column
183   int        mode;       // 0=init, 1=update, 2=cond update
184   int        decpos;     // decimal position (numeric)
185   int        redisp;     // redisplay flag
186   char       fconv;      // field conversion character
187 };
188 
189 
190 //  ------------------------------------------------------------------
191 //  Window data entry form definition
192 
193 typedef gkey (*KfipCP)(int*);
194 
195 struct _form_t {
196   KfipCP    getkey;     // pointer to alternate get func
197   _form_t*  prev;       // pointer to previous form record
198   _form_t*  next;       // pointer to next form record
199   _field_t* field;      // pointer to head field record
200   _field_t* cfield;     // pointer to current field record
201   gkey*     termkey;    // addr of int for terminating key
202   const char* pformat;  // format string pointer
203   char*     pbuf;       // buffer string pointer
204   int       cwrow;      // current window row
205   int       cwcol;      // current window column
206   int       decimal;    // decimal field flag
207   int       insert;     // insert mode flag
208   int       fieldattr;  // field attribute
209   int       textattr;   // text attribute
210 };
211 
212 
213 //  ------------------------------------------------------------------
214 //  Structure of window records
215 
216 struct _wrec_t {
217   _wrec_t* prev;       // pointer to previous window record
218   _wrec_t* next;       // pointer to next window record
219   _form_t* form;       // pointer to head form record
220   vsavebuf* wbuf;      // address of window's buffer
221   vatch*   wsbuf;      // address of window shadow's buffer
222   const char* title;   // address of window's title string
223   int      whandle;    // window's handle
224   int      help;       // help category number
225   int      srow;       // start row of window
226   int      scol;       // start column of window
227   int      erow;       // end row of window
228   int      ecol;       // end column of window
229   int      btype;      // window's box type
230   vattr    wattr;      // window's initial text attribute
231   vattr    battr;      // attribute of window's border
232   vattr    loattr;     // attribute of window's border
233   vattr    sbattr;     // attribute of window's scrollbar
234   int      border;     // has border?  0 = no, 1 = yes
235   int      row;        // window's current cursor row
236   int      column;     // window's current cursor column
237   vattr    attr;       // window's current text attribute
238   int      tpos;       // position of window's title
239   vattr    tattr;      // attribute of window's title
240   vattr    wsattr;     // attribute of window's shadow
241 };
242 
243 
244 //  ------------------------------------------------------------------
245 
246 class _help_t;
247 
248 
249 //  ------------------------------------------------------------------
250 //  Window information record
251 
252 class GWin {
253 
254 public:
255 
256   _wrec_t* active;     // pointer to active window
257   _wrec_t* hidden;     // pointer to head hidden window
258   _menu_t* menu;       // pointer to head menu record
259   _menu_t* cmenu;      // pointer to current menu record
260   _help_t* helptr;     // pointer to help info record
261   int      handle;     // last handle given to a window
262   int      help;       // current help category
263   int      werrno;     // error num from last window func
264   int      total;      // total number of open windows
265   int      mlevel;     // system variable used in menus
266   int      ilevel;     // system variable used in menus
267   int      esc;        // check for Esc in input funcions?
268   int      tabwidth;   // window TTY output tab width
269   vchar    fillch;     // character to fill windows with
270   int      style;      // how to open the windows
271 
272 public:
273 
274   GWin();
275   ~GWin();
276 
277 };
278 
279 extern GWin gwin;
280 
281 
282 //  ------------------------------------------------------------------
283 //  Window open styles
284 
285 #define STYLE_NORMAL        0
286 #define STYLE_EXPLODE       1
287 #define STYLE_EXPLODENOISY  2
288 
289 
290 //  ------------------------------------------------------------------
291 //  Fmask definitions for wmenuitem()
292 
293 #define M_HASPD     1   // has pull-down menu attached
294 #define M_NOSEL     2   // is not selectable
295 #define M_CLOSE     4   // close menu after select func
296 #define M_CLALL     8   // close all menus when selected
297 #define M_CLOSB    16   // close menu before select func
298 #define M_SEPAR    (32 + M_NOSEL) // item is separator
299 
300 //  ------------------------------------------------------------------
301 //  Menutype definitions for wmenuend()
302 
303 #define M_HORZ      1   // horizontal menu
304 #define M_VERT      2   // vertical menu
305 #define M_OMNI      7   // omnidirectional menu
306 #define M_PD        8   // pull-down menu
307 #define M_NOQS      16  // disable quick selection
308 #define M_SAVE      32  // save last bar position
309 
310 
311 //  ------------------------------------------------------------------
312 //  Special return codes from wmenuget()
313 
314 #define M_EXIT      32764   // exit menu
315 #define M_EXITALL   32765   // exit all menus
316 #define M_PREVPD    32766   // previous pull-down menu
317 #define M_NEXTPD    32767   // next pull-down menu
318 
319 
320 //  ------------------------------------------------------------------
321 //  Window title position definitions for wtitle()
322 
323 #define TTOP        0   // Top border
324 #define TLEFT       1   // Left justified
325 #define TCENTER     2   // Centered
326 #define TRIGHT      3   // Right justified
327 #define TBOTTOM     4   // Bottom border
328 
329 
330 //  ------------------------------------------------------------------
331 //  Values for the Proportional Bar
332 
333 #define PROP_PAGE      1
334 #define PROP_BARGRAPH  2
335 
336 
337 //  ------------------------------------------------------------------
338 
339 extern int wpickstr_tag;
340 
341 
342 //  ------------------------------------------------------------------
343 //  Function prototypes
344 
345 int       wactiv      (int whandle);
346 int       wactiv_     (int whandle);
347 int       wborder     (int btype);
348 int       wbox        (int wsrow, int wscol, int werow, int wecol, int btype, int attr);
349 int       wcclear     (vattr attr);
350 int       wcenters    (int wrow, vattr attr, const char* str);
351 int       wchkbox     (int wsrow, int wscol, int werow, int wecol);
352 int       wchkcol     (int wcol);
353 int       wchkcoord   (int wrow, int wcol);
354 int       wchkrow     (int wrow);
355 int       wclose      ();
356 int       wcloseall   ();
357 int       wclreol     ();
358 int       wclreos     ();
359 int       wcopy       (int nsrow, int nscol);
360 int       wdelline    (int wrow, int direc);
361 int       wdrag       (int direction);
362 int       wdupc       (char ch, int count);
363 int       wfill       (int wsrow, int wscol, int werow, int wecol, vchar ch, vattr attr);
364 _wrec_t*  wfindrec    (int whandle);
365 int       wgotoxy     (int wrow, int wcol);
366 int       whandle     ();
367 int       whide       ();
368 int       whline      (int wsrow, int wscol, int count, int btype, vattr attr);
369 int       wmessage    (const char* str, int border, int leftofs, vattr attr);
370 int       wmove       (int nsrow, int nscol);
371 int       wopen       (int srow, int scol, int erow, int ecol, int btype, vattr battr, vattr wattr, vattr sbattr = DEFATTR, vattr loattr = DEFATTR);
372 inline int wopen_     (int srow, int scol, int vlen, int hlen, int btype, vattr battr, vattr wattr, vattr sbattr = DEFATTR, vattr loattr = DEFATTR) { return wopen(srow, scol, srow+vlen-1, scol+hlen-1, btype, battr, wattr, sbattr, loattr); }
373 int       wperror     (const char* message);
374 bool      wpickfile   (int srow, int scol, int erow, int ecol, int btype, vattr bordattr, vattr winattr, vattr barattr, bool title, std::string &filespec, IfcpCP open, bool casesens=false);
375 int       wpickstr    (int srow, int scol, int erow, int ecol, int btype, vattr bordattr, vattr winattr, vattr barattr, gstrarray &strarr, int initelem, VfvCP open);
376 int       wprintc     (int wrow, int wcol, vattr attr, vchar ch);
377 int       wprintf     (const char* format, ...) __attribute__ ((format (printf, 1, 2)));
378 int       wprintaf    (int attr, const char* format, ...) __attribute__ ((format (printf, 2, 3)));
379 int       wprintfs    (int wrow, int wcol, vattr attr, const char* format, ...) __attribute__ ((format (printf, 4, 5)));
380 int       wprints     (int wrow, int wcol, vattr attr, const char* str);
381 int       wprints_box (int wrow, int wcol, vattr attr, const char* str);
382 int       wprintvs    (int wrow, int wcol, vattr attr, const vchar* str);
383 int       wprintns    (int wrow, int wcol, vattr attr, const std::string &str, uint len, vchar fill=' ', vattr fill_attr = DEFATTR);
384 int       wprintsf    (int wrow, int wcol, vattr attr, const char* format, const char* str);
385 int       wprintws    (int wrow, int wcol, vatch* buf, uint len);
386 void      wpropbar    (int xx, int yy, long len, vattr attr, long pos, long size);
387 int       wputc       (vchar ch);
388 int       wputs       (const char* str);
389 int       wputx       (int wrow, int wcol, vattr attr, vchar chr, uint len);
390 int       wputy       (int wrow, int wcol, vattr attr, vchar chr, uint len);
391 int       wreadcur    (int* wrow, int* wcol);
392 int       wscroll     (int count, int direc);
393 void      wscrollbar  (int orientation, uint total, uint maxpos, uint pos, int sadd=0);
394 int       wscrollbox  (int wsrow, int wscol, int werow, int wecol, int count, int direction);
395 int       wshadoff    ();
396 int       wshadow     (vattr attr);
397 int       wsize       (int nerow, int necol);
398 int       wslide      (int nsrow, int nscol);
399 void      wtextattr   (vattr attr);
400 int       wtitle      (const char* str, int tpos, vattr tattr);
401 int       wunhide     (int whandle);
402 int       wunlink     (int w);
403 int       wvline      (int wsrow, int wscol, int count, int btype, vattr attr);
404 int       wwprintc    (int whandle, int wrow, int wcol, vattr attr, const vchar chr);
405 int       wwprints    (int whandle, int wrow, int wcol, vattr attr, const char* str);
406 int       wwprintstr  (int whandle, int wrow, int wcol, vattr attr, const char* str);
407 
408 int       wmenubeg    (int srow, int scol, int erow, int ecol, int btype, vattr battr, vattr wattr, VfvCP open, int menutype=M_VERT);
409 inline int wmenubeg_  (int srow, int scol, int vlen, int hlen, int btype, vattr battr, vattr wattr, VfvCP open, int menutype=M_VERT) { return wmenubeg(srow, scol, srow+vlen-1, scol+hlen-1, btype, battr, wattr, open, menutype); }
410 int       wmenubegc   ();
411 int       wmenuend    (int taginit, int menutype, int barwidth, int textpos, vattr textattr, vattr scharattr, vattr noselattr, vattr barattr);
412 int       wmenuget    ();
413 int       wmenuiba    (VfvCP before, VfvCP after);
414 int       wmenuidsab  (int tagid);
415 int       wmenuienab  (int tagid);
416 _item_t*  wmenuifind  (int tagid);
417 int       wmenuinext  (int tagid);
418 int       wmenuitem   (int wrow, int wcol, const char* str, char schar, int tagid, int fmask, VfvCP select, gkey hotkey, int help);
419 int       wmenuitxt   (int whdl, int wrow, int wcol, vattr attr, const char* str);
420 
421 
422 //  ------------------------------------------------------------------
423 //  Inline functions
424 
wtextattr(vattr attr)425 inline void wtextattr(vattr attr) { gwin.active->attr = attr; }
426 
wclear()427 inline int       wclear      ()       { return wcclear(gwin.active->wattr); }
wfillch(vchar a)428 inline void      wfillch     (vchar a) { gwin.fillch=a; }
wgetc(int wrow,int wcol)429 inline vchar     wgetc       (int wrow, int wcol) { return vgetc(gwin.active->srow+wrow+gwin.active->border,gwin.active->scol+wcol+gwin.active->border); }
wisactiv(int a)430 inline int       wisactiv    (int a)  { return a == gwin.active->whandle; }
wsetesc(int a)431 inline int       wsetesc     (int a)  { int t=gwin.esc; gwin.esc=a; return t; }
wsetstyle(int a)432 inline void      wsetstyle   (int a)  { gwin.style = a; }
wstyle()433 inline int       wstyle      ()       { return gwin.style; }
wtabwidth(int a)434 inline void      wtabwidth   (int a)  { gwin.tabwidth = (a==0) ? 1 : a; }
435 
winpfcurr()436 inline _field_t* winpfcurr   ()       { return gwin.active->form->cfield; }
437 
wmenumcurr()438 inline _menu_t*  wmenumcurr  ()       { return gwin.cmenu; }
wmenuicurr()439 inline _item_t*  wmenuicurr  ()       { return wmenumcurr()->citem; }
440 
wmenutitshad(const char * title,int pos,vattr attr,vattr shadattr)441 inline int       wmenutitshad(const char* title, int pos, vattr attr, vattr shadattr) { gwin.cmenu->title=title; gwin.cmenu->titlepos=pos; gwin.cmenu->titleattr=attr; gwin.cmenu->shadattr=shadattr; return W_NOERROR; }
442 
443 
444 //  ------------------------------------------------------------------
445 
446 #endif
447 
448 //  ------------------------------------------------------------------
449