]> ncurses.scripts.mit.edu Git - ncurses.git/blob - c++/cursesw.h
ncurses 4.2
[ncurses.git] / c++ / cursesw.h
1 // * This makes emacs happy -*-Mode: C++;-*-
2 #ifndef _CURSESW_H
3 #define _CURSESW_H
4
5 // $Id: cursesw.h,v 1.13 1998/01/20 16:53:50 Fred.Fish Exp $
6
7 #include <etip.h>
8 #include <stdio.h>
9 #include <stdarg.h>
10 #ifdef __MWERKS__
11 /* This is a bogus check, stringstream is actually ANSI C++ standard,
12  * but old compilers like GCC don't have it, and new compilers like Metrowerks
13  * don't have strstream
14  */
15 #include <sstream>
16 #else
17 #include <strstream.h>
18 #endif
19
20 extern "C" {
21 #  include   <curses.h>
22 }
23
24 /* SCO 3.2v4 curses.h includes term.h, which defines lines as a macro.
25    Undefine it here, because NCursesWindow uses lines as a method.  */
26 #undef lines
27
28 /* "Convert" macros to inlines. We'll define it as another symbol to avoid
29  * conflict with library symbols.
30  */
31 #undef UNDEF
32 #define UNDEF(name) CUR_ ##name
33
34 #ifdef addch
35 inline int UNDEF(addch)(chtype ch)  { return addch(ch); }
36 #undef addch
37 #define addch UNDEF(addch)
38 #endif
39
40 #ifdef echochar
41 inline int UNDEF(echochar)(chtype ch)  { return echochar(ch); }
42 #undef echochar
43 #define echochar UNDEF(echochar)
44 #endif
45
46 #ifdef insdelln
47 inline int UNDEF(insdelln)(int n)  { return insdelln(n); }
48 #undef insdelln
49 #define insdelln UNDEF(insdelln)
50 #endif
51
52 #ifdef addstr
53 /* The (char*) cast is to hack around missing const's */
54 inline int UNDEF(addstr)(const char * str)  { return addstr((char*)str); }
55 #undef addstr
56 #define addstr UNDEF(addstr)
57 #endif
58
59 #ifdef attron
60 inline int UNDEF(attron)(chtype at) { return attron(at); }
61 #undef attron
62 #define attron UNDEF(attron)
63 #endif
64
65 #ifdef attroff
66 inline int UNDEF(attroff)(chtype at) { return attroff(at); }
67 #undef attroff
68 #define attroff UNDEF(attroff)
69 #endif
70
71 #ifdef attrset
72 inline chtype UNDEF(attrset)(chtype at) { return attrset(at); }
73 #undef attrset
74 #define attrset UNDEF(attrset)
75 #endif
76
77 #ifdef border
78 inline int UNDEF(border)(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, chtype tr, chtype bl, chtype br)
79 { return border(ls,rs,ts,bs,tl,tr,bl,br); }
80 #undef border
81 #define border UNDEF(border)
82 #endif
83
84 #ifdef box
85 inline int UNDEF(box)(WINDOW *win, int v, int h) { return box(win, v, h); }
86 #undef box
87 #define box UNDEF(box)
88 #endif
89
90 #ifdef mvwhline
91 inline int UNDEF(mvwhline)(WINDOW *win,int y,int x,chtype c,int n) {
92   return mvwhline(win,y,x,c,n); }
93 #undef mvwhline
94 #define mvwhline UNDEF(mvwhline)
95 #endif
96
97 #ifdef mvwvline
98 inline int UNDEF(mvwvline)(WINDOW *win,int y,int x,chtype c,int n) {
99   return mvwvline(win,y,x,c,n); }
100 #undef mvwvline
101 #define mvwvline UNDEF(mvwvline)
102 #endif
103
104 #ifdef clear
105 inline int UNDEF(clear)()  { return clear(); }
106 #undef clear
107 #define clear UNDEF(clear)
108 #endif
109
110 #ifdef clearok
111 inline int UNDEF(clearok)(WINDOW* win, bool bf)  { return clearok(win, bf); }
112 #undef clearok
113 #define clearok UNDEF(clearok)
114 #else
115 extern "C" int clearok(WINDOW*, bool);
116 #endif
117
118 #ifdef clrtobot
119 inline int UNDEF(clrtobot)()  { return clrtobot(); }
120 #undef clrtobot
121 #define clrtobot UNDEF(clrtobot)
122 #endif
123
124 #ifdef clrtoeol
125 inline int UNDEF(clrtoeol)()  { return clrtoeol(); }
126 #undef clrtoeol
127 #define clrtoeol UNDEF(clrtoeol)
128 #endif
129
130 #ifdef delch
131 inline int UNDEF(delch)()  { return delch(); }
132 #undef delch
133 #define delch UNDEF(delch)
134 #endif
135
136 #ifdef deleteln
137 inline int UNDEF(deleteln)()  { return deleteln(); }
138 #undef deleteln
139 #define deleteln UNDEF(deleteln)
140 #endif
141
142 #ifdef erase
143 inline int UNDEF(erase)()  { return erase(); }
144 #undef erase
145 #define erase UNDEF(erase)
146 #endif
147
148 #ifdef flushok
149 inline int UNDEF(flushok)(WINDOW* _win, bool _bf)  { 
150   return flushok(_win, _bf); }
151 #undef flushok
152 #define flushok UNDEF(flushok)
153 #else
154 #define _no_flushok
155 #endif
156
157 #ifdef getch
158 inline int UNDEF(getch)()  { return getch(); }
159 #undef getch
160 #define getch UNDEF(getch)
161 #endif
162
163 #ifdef getstr
164 inline int UNDEF(getstr)(char *_str)  { return getstr(_str); }
165 #undef getstr
166 #define getstr UNDEF(getstr)
167 #endif
168
169 #ifdef instr
170 inline int UNDEF(instr)(char *_str)  { return instr(_str); }
171 #undef instr
172 #define instr UNDEF(instr)
173 #endif
174
175 #ifdef innstr
176 inline int UNDEF(innstr)(char *_str, int n)  { return innstr(_str,n); }
177 #undef innstr
178 #define innstr UNDEF(innstr)
179 #endif
180
181 #ifdef mvwinnstr
182 inline int UNDEF(mvwinnstr)(WINDOW *win, int y, int x, char *_str, int n) { 
183   return mvwinnstr(win,y,x,_str,n); }
184 #undef mvwinnstr
185 #define mvwinnstr UNDEF(mvwinnstr)
186 #endif
187
188 #ifdef mvinnstr
189 inline int UNDEF(mvinnstr)(int y, int x, char *_str, int n) { 
190   return mvinnstr(y,x,_str,n); }
191 #undef mvinnstr
192 #define mvinnstr UNDEF(mvinnstr)
193 #endif
194
195 #ifdef winsstr
196 inline int UNDEF(winsstr)(WINDOW *w, const char *_str)  { 
197   return winsstr(w,_str); }
198 #undef winsstr
199 #define winsstr UNDEF(winsstr)
200 #endif
201
202 #ifdef mvwinsstr
203 inline int UNDEF(mvwinsstr)(WINDOW *w, int y, int x,  const char *_str)  { 
204   return mvwinsstr(w,y,x,_str); }
205 #undef mvwinsstr
206 #define mvwinsstr UNDEF(mvwinsstr)
207 #endif
208
209 #ifdef insstr
210 inline int UNDEF(insstr)(const char *_str)  { 
211   return insstr(_str); }
212 #undef insstr
213 #define insstr UNDEF(insstr)
214 #endif
215
216 #ifdef mvinsstr
217 inline int UNDEF(mvinsstr)(int y, int x,const char *_str)  { 
218   return mvinsstr(y,x,_str); }
219 #undef mvinsstr
220 #define mvinsstr UNDEF(mvinsstr)
221 #endif
222
223 #ifdef insnstr
224 inline int UNDEF(insnstr)(const char *_str, int n)  { 
225   return insnstr(_str,n); }
226 #undef insnstr
227 #define insnstr UNDEF(insnstr)
228 #endif
229
230 #ifdef mvwinsnstr
231 inline int UNDEF(mvwinsnstr)(WINDOW *w, int y, int x,const char *_str, int n) {
232   return mvwinsnstr(w,y,x,_str,n); }
233 #undef mvwinsnstr
234 #define mvwinsnstr UNDEF(mvwinsnstr)
235 #endif
236
237 #ifdef mvinsnstr
238 inline int UNDEF(mvinsnstr)(int y, int x,const char *_str, int n) {
239   return mvinsnstr(y,x,_str,n); }
240 #undef mvinsnstr
241 #define mvinsnstr UNDEF(mvinsnstr)
242 #endif
243
244 #ifdef getnstr
245 inline int UNDEF(getnstr)(char *_str, int n)  { return getnstr(_str,n); }
246 #undef getnstr
247 #define getnstr UNDEF(getnstr)
248 #endif
249
250 #ifdef getyx
251 inline void UNDEF(getyx)(const WINDOW* win, int& y, int& x) { 
252   getyx(win, y, x); }
253 #undef getyx
254 #define getyx UNDEF(getyx)
255 #endif
256
257 #ifdef getbegyx
258 inline void UNDEF(getbegyx)(WINDOW* win, int& y, int& x) { getbegyx(win, y, x); }
259 #undef getbegyx
260 #define getbegyx UNDEF(getbegyx)
261 #endif
262
263 #ifdef getmaxyx
264 inline void UNDEF(getmaxyx)(WINDOW* win, int& y, int& x) { getmaxyx(win, y, x); }
265 #undef getmaxyx
266 #define getmaxyx UNDEF(getmaxyx)
267 #endif
268
269 #ifdef hline
270 inline int UNDEF(hline)(chtype ch, int n) { return hline(ch, n); }
271 #undef hline
272 #define hline UNDEF(hline)
273 #endif
274
275 #ifdef inch
276 inline chtype UNDEF(inch)()  { return inch(); }
277 #undef inch
278 #define inch UNDEF(inch)
279 #endif
280
281 #ifdef insch
282 inline int UNDEF(insch)(char c)  { return insch(c); }
283 #undef insch
284 #define insch UNDEF(insch)
285 #endif
286
287 #ifdef insertln
288 inline int UNDEF(insertln)()  { return insertln(); }
289 #undef insertln
290 #define insertln UNDEF(insertln)
291 #endif
292
293 #ifdef leaveok
294 inline int UNDEF(leaveok)(WINDOW* win, bool bf)  { return leaveok(win, bf); }
295 #undef leaveok
296 #define leaveok UNDEF(leaveok)
297 #else
298 extern "C" int leaveok(WINDOW* win, bool bf);
299 #endif
300
301 #ifdef move
302 inline int UNDEF(move)(int x, int y)  { return move(x, y); }
303 #undef move
304 #define move UNDEF(move)
305 #endif
306
307 #ifdef refresh
308 inline int UNDEF(refresh)()  { return refresh(); }
309 #undef refresh
310 #define refresh UNDEF(refresh)
311 #endif
312
313 #ifdef redrawwin
314 inline int UNDEF(redrawwin)(WINDOW *win)  { return redrawwin(win); }
315 #undef redrawwin
316 #define redrawwin UNDEF(redrawwin)
317 #endif
318
319 #ifdef scrl
320 inline int UNDEF(scrl)(int l) { return scrl(l); }
321 #undef scrl
322 #define scrl UNDEF(scrl)
323 #endif
324
325 #ifdef scroll
326 inline int UNDEF(scroll)(WINDOW *win) { return scroll(win); }
327 #undef scroll
328 #define scroll UNDEF(scroll)
329 #endif
330
331 #ifdef scrollok
332 inline int UNDEF(scrollok)(WINDOW* win, bool bf)  { return scrollok(win, bf); }
333 #undef scrollok
334 #define scrollok UNDEF(scrollok)
335 #else
336 #if     defined(__NCURSES_H)
337 extern "C" int scrollok(WINDOW*, bool);
338 #else
339 extern "C" int scrollok(WINDOW*, char);
340 #endif
341 #endif
342
343 #ifdef setscrreg
344 inline int UNDEF(setscrreg)(int t, int b) { return setscrreg(t, b); }
345 #undef setscrreg
346 #define setscrreg UNDEF(setscrreg)
347 #endif
348
349 #ifdef standend
350 inline int UNDEF(standend)()  { return standend(); }
351 #undef standend
352 #define standend UNDEF(standend)
353 #endif
354
355 #ifdef standout
356 inline int UNDEF(standout)()  { return standout(); }
357 #undef standout
358 #define standout UNDEF(standout)
359 #endif
360
361 #ifdef subpad
362 inline WINDOW *UNDEF(subpad)(WINDOW *p, int l, int c, int y, int x) 
363 { return derwin(p,l,c,y,x); }
364 #undef subpad
365 #define subpad UNDEF(subpad)
366 #endif
367
368 #ifdef timeout
369 inline int UNDEF(timeout)(int delay) { return timeout(delay); }
370 #undef timeout
371 #define timeout UNDEF(timeout)
372 #endif
373
374 #ifdef touchline
375 inline int UNDEF(touchline)(WINDOW *win, int s, int c)
376 { return touchline(win,s,c); }
377 #undef touchline
378 #define touchline UNDEF(touchline)
379 #endif
380
381 #ifdef touchwin
382 inline int UNDEF(touchwin)(WINDOW *win) { return touchwin(win); }
383 #undef touchwin
384 #define touchwin UNDEF(touchwin)
385 #endif
386
387 #ifdef untouchwin
388 inline int UNDEF(untouchwin)(WINDOW *win) { return untouchwin(win); }
389 #undef untouchwin
390 #define untouchwin UNDEF(untouchwin)
391 #endif
392
393 #ifdef vline
394 inline int UNDEF(vline)(chtype ch, int n) { return vline(ch, n); }
395 #undef vline
396 #define vline UNDEF(vline)
397 #endif
398
399 #ifdef waddstr
400 inline int UNDEF(waddstr)(WINDOW *win, char *str) { return waddstr(win, str); }
401 #undef waddstr
402 #define waddstr UNDEF(waddstr)
403 #endif
404
405 #ifdef waddchstr
406 inline int UNDEF(waddchstr)(WINDOW *win, chtype *at) { return waddchstr(win, at); }
407 #undef waddchstr
408 #define waddchstr UNDEF(waddchstr)
409 #endif
410
411 #ifdef wstandend
412 inline int UNDEF(wstandend)(WINDOW *win)  { return wstandend(win); }
413 #undef wstandend
414 #define wstandend UNDEF(wstandend)
415 #endif
416
417 #ifdef wstandout
418 inline int UNDEF(wstandout)(WINDOW *win)  { return wstandout(win); }
419 #undef wstandout
420 #define wstandout UNDEF(wstandout)
421 #endif
422
423
424 #ifdef wattroff
425 inline int UNDEF(wattroff)(WINDOW *win, int att) { return wattroff(win, att); }
426 #undef wattroff
427 #define wattroff UNDEF(wattroff)
428 #endif
429
430 #ifdef chgat
431 inline int UNDEF(chgat)(int n,attr_t attr, short color, const void *opts) { 
432   return chgat(n,attr,color,opts); }
433 #undef chgat
434 #define chgat UNDEF(chgat)
435 #endif
436
437 #ifdef mvchgat
438 inline int UNDEF(mvchgat)(int y, int x, int n,
439                           attr_t attr, short color, const void *opts) { 
440   return mvchgat(y,x,n,attr,color,opts); }
441 #undef mvchgat
442 #define mvchgat UNDEF(mvchgat)
443 #endif
444
445 #ifdef mvwchgat
446 inline int UNDEF(mvwchgat)(WINDOW *win, int y, int x, int n,
447                            attr_t attr, short color, const void *opts) { 
448   return mvwchgat(win,y,x,n,attr,color,opts); }
449 #undef mvwchgat
450 #define mvwchgat UNDEF(mvwchgat)
451 #endif
452
453 #ifdef wattrset
454 inline int UNDEF(wattrset)(WINDOW *win, int att) { return wattrset(win, att); }
455 #undef wattrset
456 #define wattrset UNDEF(wattrset)
457 #endif
458
459 #ifdef winch
460 inline chtype UNDEF(winch)(const WINDOW* win) { return winch(win); }
461 #undef winch
462 #define winch UNDEF(winch)
463 #endif
464
465 #ifdef mvwaddch
466 inline int UNDEF(mvwaddch)(WINDOW *win, int y, int x, const chtype ch)
467 { return mvwaddch(win, y, x, ch); }
468 #undef mvwaddch
469 #define mvwaddch UNDEF(mvwaddch)
470 #endif
471
472 #ifdef mvwaddchnstr
473 inline int UNDEF(mvwaddchnstr)(WINDOW *win, int y, int x, chtype *str, int n)
474 { return mvwaddchnstr(win, y, x, str, n); }
475 #undef mvwaddchnstr
476 #define mvwaddchnstr UNDEF(mvwaddchnstr)
477 #endif
478
479 #ifdef mvwaddchstr
480 inline int UNDEF(mvwaddchstr)(WINDOW *win, int y, int x, chtype *str)
481 { return mvwaddchstr(win, y, x, str); }
482 #undef mvwaddchstr
483 #define mvwaddchstr UNDEF(mvwaddchstr)
484 #endif
485
486 #ifdef addnstr
487 inline int UNDEF(addnstr)(const char *str, int n)
488 { return addnstr((char*)str, n); }
489 #undef addnstr
490 #define addnstr UNDEF(addnstr)
491 #endif
492
493 #ifdef mvwaddnstr
494 inline int UNDEF(mvwaddnstr)(WINDOW *win, int y, int x, const char *str, int n)
495 { return mvwaddnstr(win, y, x, (char*)str, n); }
496 #undef mvwaddnstr
497 #define mvwaddnstr UNDEF(mvwaddnstr)
498 #endif
499
500 #ifdef mvwaddstr
501 inline int UNDEF(mvwaddstr)(WINDOW *win, int y, int x, const char * str)
502 { return mvwaddstr(win, y, x, (char*)str); }
503 #undef mvwaddstr
504 #define mvwaddstr UNDEF(mvwaddstr)
505 #endif
506
507 #ifdef mvwdelch
508 inline int UNDEF(mvwdelch)(WINDOW *win, int y, int x)
509 { return mvwdelch(win, y, x); }
510 #undef mvwdelch
511 #define mvwdelch UNDEF(mvwdelch)
512 #endif
513
514 #ifdef mvwgetch
515 inline int UNDEF(mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
516 #undef mvwgetch
517 #define mvwgetch UNDEF(mvwgetch)
518 #endif
519
520 #ifdef mvwgetstr
521 inline int UNDEF(mvwgetstr)(WINDOW *win, int y, int x, char *str)
522 {return mvwgetstr(win,y,x, str);}
523 #undef mvwgetstr
524 #define mvwgetstr UNDEF(mvwgetstr)
525 #endif
526
527 #ifdef mvwgetnstr
528 inline int UNDEF(mvwgetnstr)(WINDOW *win, int y, int x, char *str, int n)
529 {return mvwgetnstr(win,y,x, str,n);}
530 #undef mvwgetnstr
531 #define mvwgetnstr UNDEF(mvwgetnstr)
532 #endif
533
534 #ifdef mvwinch
535 inline chtype UNDEF(mvwinch)(WINDOW *win, int y, int x) { 
536   return mvwinch(win, y, x);}
537 #undef mvwinch
538 #define mvwinch UNDEF(mvwinch)
539 #endif
540
541 #ifdef mvwinsch
542 inline int UNDEF(mvwinsch)(WINDOW *win, int y, int x, char c)
543 { return mvwinsch(win, y, x, c); }
544 #undef mvwinsch
545 #define mvwinsch UNDEF(mvwinsch)
546 #endif
547
548 #ifdef mvaddch
549 inline int UNDEF(mvaddch)(int y, int x, chtype ch)
550 { return mvaddch(y, x, ch); }
551 #undef mvaddch
552 #define mvaddch UNDEF(mvaddch)
553 #endif
554
555 #ifdef mvaddnstr
556 inline int UNDEF(mvaddnstr)(int y, int x, const char *str, int n)
557 { return mvaddnstr(y, x, (char*)str, n); }
558 #undef mvaddnstr
559 #define mvaddnstr UNDEF(mvaddnstr)
560 #endif
561
562 #ifdef mvaddstr
563 inline int UNDEF(mvaddstr)(int y, int x, const char * str)
564 { return mvaddstr(y, x, (char*)str); }
565 #undef mvaddstr
566 #define mvaddstr UNDEF(mvaddstr)
567 #endif
568
569 #ifdef mvdelch
570 inline int UNDEF(mvdelch)(int y, int x) { return mvdelch(y, x);}
571 #undef mvdelch
572 #define mvdelch UNDEF(mvdelch)
573 #endif
574
575 #ifdef mvgetch
576 inline int UNDEF(mvgetch)(int y, int x) { return mvgetch(y, x);}
577 #undef mvgetch
578 #define mvgetch UNDEF(mvgetch)
579 #endif
580
581 #ifdef mvgetstr
582 inline int UNDEF(mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
583 #undef mvgetstr
584 #define mvgetstr UNDEF(mvgetstr)
585 #endif
586
587 #ifdef mvgetnstr
588 inline int UNDEF(mvgetnstr)(int y, int x, char *str, int n) {
589   return mvgetnstr(y, x, str,n);}
590 #undef mvgetnstr
591 #define mvgetnstr UNDEF(mvgetnstr)
592 #endif
593
594 #ifdef mvinch
595 inline chtype UNDEF(mvinch)(int y, int x) { return mvinch(y, x);}
596 #undef mvinch
597 #define mvinch UNDEF(mvinch)
598 #endif
599
600 #ifdef mvinsch
601 inline int UNDEF(mvinsch)(int y, int x, char c)
602 { return mvinsch(y, x, c); }
603 #undef mvinsch
604 #define mvinsch UNDEF(mvinsch)
605 #endif
606
607 #ifdef napms
608 inline void UNDEF(napms)(unsigned long x) { napms(x); }
609 #undef napms
610 #define napms UNDEF(napms)
611 #endif
612
613 #ifdef fixterm
614 inline int UNDEF(fixterm)(void) { return fixterm(); }
615 #undef fixterm
616 #define fixterm UNDEF(fixterm)
617 #endif
618
619 #ifdef resetterm
620 inline int UNDEF(resetterm)(void) { return resetterm(); }
621 #undef resetterm
622 #define resetterm UNDEF(resetterm)
623 #endif
624
625 #ifdef saveterm
626 inline int UNDEF(saveterm)(void) { return saveterm(); }
627 #undef saveterm
628 #define saveterm UNDEF(saveterm)
629 #endif
630
631 #ifdef crmode
632 inline int UNDEF(crmode)(void) { return crmode(); }
633 #undef crmode
634 #define crmode UNDEF(crmode)
635 #endif
636
637 #ifdef nocrmode
638 inline int UNDEF(nocrmode)(void) { return nocrmode(); }
639 #undef nocrmode
640 #define nocrmode UNDEF(nocrmode)
641 #endif
642
643 #ifdef getbkgd
644 inline chtype UNDEF(getbkgd)(const WINDOW *win) { return getbkgd(win); }
645 #undef getbkgd
646 #define getbkgd UNDEF(getbkgd)
647 #endif
648
649 #ifdef bkgd
650 inline int UNDEF(bkgd)(chtype ch) { return bkgd(ch); }
651 #undef bkgd
652 #define bkgd UNDEF(bkgd)
653 #endif
654
655 #ifdef bkgdset
656 inline void UNDEF(bkgdset)(chtype ch) { bkgdset(ch); }
657 #undef bkgdset
658 #define bkgdset UNDEF(bkgdset)
659 #endif
660
661 /*
662  *
663  * C++ class for windows.
664  *
665  *
666  */
667
668 class NCursesWindow
669 {
670   friend class NCursesMenu;
671   friend class NCursesForm;
672   
673 private:
674   static bool    b_initialized;
675   static void    initialize();
676   static int     ripoff_init(WINDOW *,int);
677
678   void           init(); 
679   
680   short          getcolor(int getback) const;
681
682   static int     setpalette(short fore, short back, short pair);
683   static int     colorInitialized;
684
685   // This private constructor is only used during the initialization
686   // of windows generated by ripoffline() calls.
687   NCursesWindow(WINDOW* win, int cols);
688
689 protected:
690   void           err_handler(const char *) const THROWS(NCursesException);
691   // Signal an error with the given message text.
692
693   static long count;        // count of all active windows:
694   //   We rely on the c++ promise that
695   //   all otherwise uninitialized
696   //   static class vars are set to 0
697   
698   WINDOW*        w;                // the curses WINDOW
699   
700   bool           alloced;          // TRUE if we own the WINDOW
701   
702   NCursesWindow* par;              // parent, if subwindow
703   NCursesWindow* subwins;          // head of subwindows list
704   NCursesWindow* sib;              // next subwindow of parent
705   
706   void           kill_subwindows(); // disable all subwindows
707   // Destroy all subwindows.
708
709   /* Only for use by derived classes. They are then in charge to
710      fill the member variables correctly. */
711   NCursesWindow();
712
713 public:
714   NCursesWindow(WINDOW* &window);  // useful only for stdscr
715   
716   NCursesWindow(int lines,         // number of lines
717                 int cols,          // number of columns
718                 int begin_y,       // line origin
719                 int begin_x);      // col origin
720   
721   NCursesWindow(NCursesWindow& par,// parent window
722                 int lines,         // number of lines
723                 int cols,          // number of columns
724                 int begin_y,       // absolute or relative
725                 int begin_x,       //   origins:
726                 char absrel = 'a');// if `a', by & bx are
727   // absolute screen pos, else if `r', they are relative to par origin
728
729   virtual ~NCursesWindow();
730
731   NCursesWindow Clone();
732   // Make an exact copy of the window.
733
734   // Initialization.
735   static void    useColors(void);
736   // Call this routine very early if you want to have colors.
737
738   static int ripoffline(int ripoff_lines,
739                         int (*init)(NCursesWindow& win));
740   // This function is used to generate a window of ripped-of lines.
741   // If the argument is positive, lines are removed from the top, if it
742   // is negative lines are removed from the bottom. This enhances the 
743   // lowlevel ripoffline() function because it uses the internal 
744   // implementation that allows to remove more than just a single line. 
745   // This function must be called before any other ncurses function. The
746   // creation of the window is defered until ncurses gets initialized.
747   // The initialization function is then called.
748
749   // -------------------------------------------------------------------------
750   // terminal status
751   // -------------------------------------------------------------------------
752   int            lines() const { return LINES; }
753   // Number of lines on terminal, *not* window
754
755   int            cols() const { return COLS; }
756   // Number of cols  on terminal, *not* window
757
758   int            tabsize() const { return TABSIZE; }
759   // Size of a tab on terminal, *not* window
760
761   static int     NumberOfColors();
762   // Number of available colors
763
764   int     colors() const { return NumberOfColors(); }
765   // Number of available colors
766   
767   // -------------------------------------------------------------------------
768   // window status
769   // -------------------------------------------------------------------------
770   int            height() const { return maxy() + 1; }
771   // Number of lines in this window
772
773   int            width() const { return maxx() + 1; }
774   // Number of columns in this window
775
776   int            begx() const { return w->_begx; }
777   // Column of top left corner relative to stdscr
778
779   int            begy() const { return w->_begy; }
780   // Line of top left corner relative to stdscr
781
782   int            maxx() const { return w->_maxx; }
783   // Largest x coord in window
784
785   int            maxy() const { return w->_maxy; }
786   // Largest y coord in window
787
788   short  getcolor() const;
789   // Actual color pair
790
791   short  foreground() const { return getcolor(0); }
792   // Actual foreground color
793
794   short  background() const { return getcolor(1); }
795   // Actual background color
796
797   int    setpalette(short fore, short back);
798   // Set color palette entry
799
800   int    setcolor(short pair);
801   // Set actually used palette entry
802   
803   // -------------------------------------------------------------------------
804   // window positioning
805   // -------------------------------------------------------------------------
806   virtual int  mvwin(int begin_y, int begin_x) {
807     return ::mvwin(w,begin_y,begin_x); }
808   // Move window to new position with the new position as top left corner.
809   // This is virtual because it is redefined in NCursesPanel.
810
811   // -------------------------------------------------------------------------
812   // coordinate positioning
813   // -------------------------------------------------------------------------
814   int            move(int y, int x) { return ::wmove(w, y, x); }
815   // Move cursor the this position
816
817   void           getyx(int& y, int& x) const { ::getyx(w, y, x); }
818   // Get current position of the cursor 
819
820   int            mvcur(int oldrow, int oldcol, int newrow, int newcol) const { 
821     return ::mvcur(oldrow, oldcol, newrow, newcol); }
822   // Perform lowlevel cursor motion that takes effect immediately.
823   
824   // -------------------------------------------------------------------------
825   // input
826   // -------------------------------------------------------------------------
827   int            getch() { return ::wgetch(w); }
828   // Get a keystroke from the window.
829
830   int            getch(int y, int x) { return ::mvwgetch(w,y,x); }
831   // Move cursor to position and get a keystroke from the window
832
833   int            getstr(char* str, int n=-1) { 
834     return ::wgetnstr(w, str,n); }
835   // Read a series of characters into str until a newline or carriage return
836   // is received. Read at most n characters. If n is negative, the limit is
837   // ignored.
838
839   int            getstr(int y, int x, char* str, int n=-1) { 
840     return ::mvwgetnstr(w,y,x,str,n); }
841   // Move the cursor to the requested position and then perform the getstr()
842   // as described above.
843
844   int            instr(char *s, int n=-1) { return ::winnstr(w,s,n); }
845   // Get a string of characters from the window into the buffer s. Retrieve
846   // at most n characters, if n is negative retrieve all characters up to the
847   // end of the current line. Attributes are stripped from the characters.
848
849   int            instr(int y, int x, char *s, int n=-1) {
850     return ::mvwinnstr(w,y,x,s,n); }
851   // Move the cursor to the requested position and then perform the instr()
852   // as described above.
853
854   int            scanw(const char* fmt, ...)
855     // Perform a scanw function from the window. This only works if you're
856     // using the GNU C++ compiler.
857 #if __GNUG__ >= 2
858     __attribute__ ((format (scanf, 2, 3)));
859 #else
860   ;
861 #endif
862
863   int            scanw(int y, int x, const char* fmt, ...)
864     // Move the cursor to the requested position and then perform a scanw
865     // from the window. This nly works if you're using the GNU C++ compiler.
866 #if __GNUG__ >= 2
867     __attribute__ ((format (scanf, 4, 5)));
868 #else
869   ;
870 #endif
871   
872   // -------------------------------------------------------------------------
873   // output
874   // -------------------------------------------------------------------------
875   int            addch(const chtype ch) { return ::waddch(w, ch); }
876   // Put attributed character to the window. 
877
878   int            addch(int y, int x, const chtype ch) {
879     return ::mvwaddch(w,y,x,ch); }
880   // Move cursor to the requested position and then put attributed character
881   // to the window.
882
883   int            echochar(const chtype ch) { return ::wechochar(w,ch); }
884   // Put attributed character to the window and refresh it immediately.
885
886   int            addstr(const char* str, int n=-1) { 
887     return ::waddnstr(w, (char*)str,n); }
888   // Write the string str to the window, stop writing if the terminating
889   // NUL or the limit n is reached. If n is negative, it is ignored. 
890
891   int            addstr(int y, int x, const char * str, int n=-1) {
892     return ::mvwaddnstr(w,y,x,(char*)str,n); }
893   // Move the cursor to the requested position and then perform the addstr
894   // as described above.
895
896   int            printw(const char* fmt, ...)
897     // Do a formatted print to the window.
898 #if __GNUG__ >= 2
899     __attribute__ ((format (printf, 2, 3)));
900 #else
901   ;
902 #endif
903
904   int            printw(int y, int x, const char * fmt, ...)
905     // Move the cursor and then do a formatted print to the window.
906 #if __GNUG__ >= 2
907     __attribute__ ((format (printf, 4, 5)));
908 #else
909   ;
910 #endif
911
912   chtype         inch() const { return ::winch(w); }
913   // Retrieve attributed character under the current cursor position.
914
915   chtype         inch(int y, int x) { return ::mvwinch(w,y,x); }
916   // Move cursor to requested position and then retrieve attributed character
917   // at this position.
918
919   int            insch(chtype ch) { return ::winsch(w, ch); }
920   // Insert attributed character into the window before current cursor
921   // position.
922
923   int            insch(int y, int x, chtype ch) {
924     return ::mvwinsch(w,y,x,ch); }
925   // Move cursor to requested position and then insert the attributed
926   // character before that position.
927
928   int            insertln() { return ::winsdelln(w,1); }
929   // Insert an empty line above the current line.
930   
931   int            insdelln(int n=1) { return ::winsdelln(w,n); }
932   // If n>0 insert that many lines above the current line. If n<0 delete
933   // that many lines beginning with the current line.
934
935   int            insstr(const char *s, int n=-1) {
936     return ::winsnstr(w,s,n); }
937   // Insert the string into the window before the current cursor position.
938   // Insert stops at end of string or when the limit n is reached. If n is
939   // negative, it is ignored.
940   
941   int            insstr(int y, int x, const char *s, int n=-1) {
942     return ::mvwinsnstr(w,y,x,s,n); }
943   // Move the cursor to the requested position and then perform the insstr()
944   // as described above.
945
946   int            attron (chtype at) { return ::wattron (w, at); }
947   // Switch on the window attributes;
948   
949   int            attroff(chtype at) { return ::wattroff(w, at); }
950   // Switch off the window attributes;
951
952   int            attrset(chtype at) { return ::wattrset(w, at); }
953   // Set the window attributes;
954
955   int            chgat(int n,attr_t attr, short color, const void *opts=NULL) {
956     return ::wchgat(w,n,attr,color,opts); }
957   // Change the attributes of the next n characters in the current line. If
958   // n is negative or greater than the number of remaining characters in the
959   // line, the attributes will be changed up to the end of the line.
960
961   int            chgat(int y, int x,
962                        int n,attr_t attr, short color, const void *opts=NULL) {
963     return ::mvwchgat(w,y,x,n,attr,color,opts); }
964   // Move the cursor to the requested position and then perform chgat() as
965   // described above.
966
967   // -------------------------------------------------------------------------
968   // background
969   // -------------------------------------------------------------------------
970   chtype         getbkgd() const { return ::getbkgd(w); }
971   // Get current background setting.
972
973   int            bkgd(const chtype ch) { return ::wbkgd(w,ch); }
974   // Set the background property and apply it to the window.
975
976   void           bkgdset(chtype ch) { ::wbkgdset(w,ch); }
977   // Set the background property.
978
979   // -------------------------------------------------------------------------
980   // borders
981   // -------------------------------------------------------------------------
982   int            box(chtype vert=0, chtype  hor=0) { 
983     return ::wborder(w, vert, vert, hor, hor, 0, 0 ,0, 0); }
984   // Draw a box around the window with the given vertical and horizontal
985   // drawing characters. If you specifiy a zero as character, curses will try
986   // to find a "nice" character.
987
988   int            border(chtype left=0, chtype right=0,
989                         chtype top =0, chtype bottom=0,
990                         chtype top_left =0, chtype top_right=0,
991                         chtype bottom_left =0, chtype bottom_right=0) {
992     return ::wborder(w,left,right,top,bottom,top_left,top_right,
993                      bottom_left,bottom_right); }
994   // Draw a border around the window with the given characters for the
995   // various parts of the border. If you pass zero for a character, curses
996   // will try to find "nice" characters.
997
998   // -------------------------------------------------------------------------
999   // lines and boxes
1000   // -------------------------------------------------------------------------
1001   int            hline(int len, chtype ch=0) { return ::whline(w, ch, len); }
1002   // Draw a horizontal line of len characters with the given character. If
1003   // you pass zero for the character, curses will try to find a "nice" one. 
1004
1005   int            hline(int y, int x, int len, chtype ch=0) {
1006     return ::mvwhline(w,y,x,ch,len); }
1007   // Move the cursor to the requested position and then draw a horizontal line.
1008
1009   int            vline(int len, chtype ch=0) { return ::wvline(w, ch, len); }
1010   // Draw a vertical line of len characters with the given character. If
1011   // you pass zero for the character, curses will try to find a "nice" one.
1012
1013   int            vline(int y, int x, int len, chtype ch=0) {
1014     return ::mvwvline(w,y,x,ch,len); }
1015   // Move the cursor to the requested position and then draw a vertical line.
1016   
1017   // -------------------------------------------------------------------------
1018   // erasure
1019   // -------------------------------------------------------------------------
1020   int            erase() { return ::werase(w); }
1021   // Erase the window.
1022
1023   int            clear() { return ::wclear(w); }
1024   // Clear the window.
1025
1026   int            clearok(bool bf) { return ::clearok(w, bf); }
1027   // Set/Reset the clear flag. If set, the next refresh() will clear the
1028   // screen.
1029
1030   int            clrtobot() { return ::wclrtobot(w); }
1031   // Clear to the end of the window.
1032
1033   int            clrtoeol() { return ::wclrtoeol(w); }
1034   // Clear to the end of the line.
1035
1036   int            delch() { return ::wdelch(w); }
1037   // Delete character under the cursor. 
1038
1039   int            delch(int y, int x) { return ::mvwdelch(w,y,x); }
1040   // Move cursor to requested position and delete the character under the
1041   // cursor.
1042
1043   int            deleteln() { return ::winsdelln(w,-1); }
1044   // Delete the current line.
1045
1046   // -------------------------------------------------------------------------
1047   // screen control
1048   // -------------------------------------------------------------------------
1049   int            scroll(int amount=1) { return ::wscrl(w,amount); }
1050   // Scroll amount lines. If amount is positive, scroll up, otherwise
1051   // scroll down.
1052
1053   int            scrollok(bool bf) { return ::scrollok(w, bf); }
1054   // If bf is TRUE, window scrolls if cursor is moved off the bottom
1055   // edge of the window or a scrolling region, otherwise the cursor is left
1056   // at the bottom line.
1057
1058   int            setscrreg(int from, int to) {
1059     return ::wsetscrreg(w,from,to); }
1060   // Define a soft scrolling region.
1061
1062   int            idlok(bool bf) { return ::idlok(w, bf); }
1063   // If bf is TRUE, use insert/delete line hardware support if possible.
1064   // Otherwise do it in software.
1065
1066
1067   void           idcok(bool bf) { ::idcok(w, bf); }
1068   // If bf is TRUE, use insert/delete character hardware support if possible.
1069   // Otherwise do it in software.
1070
1071   int            touchwin()   { return ::wtouchln(w,0,height(),1); }
1072   // Mark the whole window as modified.
1073
1074   int            untouchwin() { return ::wtouchln(w,0,height(),0); }
1075   // Mark the whole window as unmodified.
1076
1077   int            touchln(int s, int cnt, bool changed=TRUE) { 
1078     return ::wtouchln(w,s,cnt,(int)(changed?1:0)); }
1079   // Mark cnt lines beginning from line s as changed or unchanged, depending
1080   // on the value of the changed flag.
1081
1082   bool           is_linetouched(int line) const { 
1083     return (::is_linetouched(w,line) ? TRUE:FALSE); }
1084   // Return TRUE if line is marked as changed, FALSE otherwise 
1085
1086   bool           is_wintouched() const { 
1087     return (::is_wintouched(w) ? TRUE:FALSE); }
1088   // Return TRUE if window is marked as changed, FALSE otherwise 
1089
1090   int            leaveok(bool bf) { return ::leaveok(w, bf); }
1091   // If bf is TRUE, curses will leave the cursor after an update whereever
1092   // it is after the update.
1093
1094   int            redrawln(int from, int n) { return ::wredrawln(w,from,n); }
1095   // Redraw n lines starting from the requested line
1096
1097   int            redrawwin() { return ::wredrawln(w,0,height()); }
1098   // Redraw the whole window
1099
1100   int            doupdate()  { return ::doupdate(); }
1101   // Do all outputs to make the physical screen looking like the virtual one
1102
1103   void           syncdown()  { ::wsyncdown(w); }
1104   // Propagate the changes down to all descendant windows
1105
1106   void           syncup()    { ::wsyncup(w); }
1107   // Propagate the changes up in the hierarchy
1108
1109   void           cursyncup() { ::wcursyncup(w); }
1110   // Position the cursor in all ancestor windows corresponding to our setting
1111
1112   int            syncok(bool bf) { return ::syncok(w,bf); }
1113   // If called with bf=TRUE, syncup() is called whenever the window is changed
1114
1115 #ifndef _no_flushok
1116   int            flushok(bool bf) { return ::flushok(w, bf); }
1117 #endif
1118
1119   void           immedok(bool bf) { ::immedok(w,bf); }
1120   // If called with bf=TRUE, any change in the window will cause an
1121   // automatic immediate refresh()
1122
1123   int            keypad(bool bf) { return ::keypad(w, bf); }
1124   // If called with bf=TRUE, the application will interpret function keys.
1125
1126   int            meta(bool bf) { return ::meta(w,bf); }
1127   // If called with bf=TRUE, keys may generate 8-Bit characters. Otherwise
1128   // 7-Bit characters are generated. 
1129
1130   int            standout() { return ::wstandout(w); }
1131   // Enable "standout" attributes
1132
1133   int            standend() { return ::wstandend(w); }
1134   // Disable "standout" attributes
1135
1136   // -------------------------------------------------------------------------
1137   // The next two are virtual, because we redefine them in the
1138   // NCursesPanel class.
1139   // -------------------------------------------------------------------------
1140   virtual int    refresh() { return ::wrefresh(w); }
1141   // Propagate the changes in this window to the virtual screen and call
1142   // doupdate(). This is redefined in NCursesPanel.
1143
1144   virtual int    noutrefresh() { return ::wnoutrefresh(w); }
1145   // Propagate the changes in this window to the virtual screen. This is 
1146   // redefined in NCursesPanel.
1147   
1148   // -------------------------------------------------------------------------
1149   // multiple window control
1150   // -------------------------------------------------------------------------
1151   int            overlay(NCursesWindow& win) {
1152     return ::overlay(w, win.w); }
1153   // Overlay this window over win.
1154
1155   int            overwrite(NCursesWindow& win) {
1156     return ::overwrite(w, win.w); }
1157   // Overwrite win with this window.
1158
1159   int            copywin(NCursesWindow& win,
1160                          int sminrow, int smincol,
1161                          int dminrow, int dmincol,
1162                          int dmaxrow, int dmaxcol, bool overlay=TRUE) {
1163     return ::copywin(w,win.w,sminrow,smincol,dminrow,dmincol,
1164                      dmaxrow,dmaxcol,(int)(overlay?1:0)); }
1165   // Overlay or overwrite the rectangle in win given by dminrow,dmincol,
1166   // dmaxrow,dmaxcol with the rectangle in this window beginning at
1167   // sminrow,smincol.
1168
1169   // -------------------------------------------------------------------------
1170   // Mouse related
1171   // -------------------------------------------------------------------------
1172   bool has_mouse() const;
1173   // Return TRUE if terminal supports a mouse, FALSE otherwise
1174
1175   // -------------------------------------------------------------------------
1176   // traversal support
1177   // -------------------------------------------------------------------------
1178   NCursesWindow*  child() { return subwins; }
1179   // Get the first child window.
1180
1181   NCursesWindow*  sibling() { return sib; }
1182   // Get the next child of my parent.
1183
1184   NCursesWindow*  parent() { return par; }
1185   // Get my parent.
1186
1187   bool isDescendant(NCursesWindow& win);
1188   // Return TRUE if win is a descendant of this.
1189 };
1190
1191 // -------------------------------------------------------------------------
1192 // We leave this here for compatibility reasons.
1193 // -------------------------------------------------------------------------
1194 class NCursesColorWindow : public NCursesWindow {
1195 public:
1196   NCursesColorWindow(WINDOW* &window)   // useful only for stdscr
1197     : NCursesWindow(window) {
1198       useColors(); }
1199
1200   NCursesColorWindow(int lines,         // number of lines
1201                      int cols,          // number of columns
1202                      int begin_y,       // line origin
1203                      int begin_x)       // col origin
1204     : NCursesWindow(lines,cols,begin_y,begin_x) {
1205       useColors(); }
1206
1207   NCursesColorWindow(NCursesWindow& par,// parent window
1208                      int lines,         // number of lines
1209                      int cols,          // number of columns
1210                      int begin_y,       // absolute or relative
1211                      int begin_x,       //   origins:
1212                      char absrel = 'a') // if `a', by & bx are
1213     : NCursesWindow(par,lines,cols,     // absolute screen pos,
1214                     begin_y,begin_x,    // else if `r', they are
1215                     absrel ) {          // relative to par origin  
1216       useColors(); }                      
1217 };
1218
1219 class NCursesPad : public NCursesWindow {
1220 public:
1221   NCursesPad(int lines, int cols);
1222
1223   int echochar(const chtype ch) { return ::pechochar(w,ch); }
1224   // Put the attributed character onto the pad and immediately do a
1225   // prefresh().
1226   
1227   // For Pad's we reimplement refresh() and noutrefresh() to do nothing.
1228   // You should call the versions with the argument list that are specific
1229   // for Pad's.
1230   int refresh() { return OK; };
1231   int noutrefresh() { return OK; };
1232
1233   int refresh(int pminrow, int pmincol,
1234               int sminrow, int smincol,
1235               int smaxrow, int smaxcol) {
1236     return ::prefresh(w,pminrow,pmincol,
1237                       sminrow,smincol,smaxrow,smaxcol);
1238   }
1239   // The coordinates sminrow,smincol,smaxrow,smaxcol describe a rectangle
1240   // on the screen. <b>refresh</b> copies a rectangle of this size beginning
1241   // with top left corner pminrow,pmincol onto the screen and calls doupdate().
1242
1243   int noutrefresh(int pminrow, int pmincol,
1244                   int sminrow, int smincol,
1245                   int smaxrow, int smaxcol) {
1246     return ::pnoutrefresh(w,pminrow,pmincol,
1247                           sminrow,smincol,smaxrow,smaxcol);
1248   }
1249   // Does the same like refresh() but without calling doupdate().
1250 };
1251
1252 #endif // _CURSESW_H