1 // * This makes emacs happy -*-Mode: C++;-*-
5 #include <ncurses_cfg.h>
14 # define exception builtin_exception
18 #else // #elif defined (__SUNPRO_CC)
21 extern "C" { unsigned sleep(int); }
28 #include <strstream.h>
35 /* SCO 3.2v4 curses.h includes term.h, which defines lines as a macro.
36 Undefine it here, because NCursesWindow uses lines as a method. */
39 /* "Convert" macros to inlines. We'll define it as another symbol to avoid
40 * conflict with library symbols.
43 #define UNDEF(name) CUR_ ##name
46 inline int UNDEF(addch)(chtype ch) { return addch(ch); }
48 #define addch UNDEF(addch)
52 /* The (char*) cast is to hack around missing const's */
53 inline int UNDEF(addstr)(const char * str) { return addstr((char*)str); }
55 #define addstr UNDEF(addstr)
59 inline int UNDEF(attron)(chtype at) { return attron(at); }
61 #define attron UNDEF(attron)
65 inline int UNDEF(attroff)(chtype at) { return attroff(at); }
67 #define attroff UNDEF(attroff)
71 inline chtype UNDEF(attrset)(chtype at) { return attrset(at); }
73 #define attrset UNDEF(attrset)
77 inline int UNDEF(border)(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, chtype tr, chtype bl, chtype br)
78 { return border(ls,rs,ts,bs,tl,tr,bl,br); }
80 #define border UNDEF(border)
84 inline int UNDEF(box)(WINDOW *win, int v, int h) { return box(win, v, h); }
86 #define box UNDEF(box)
90 inline int UNDEF(clear)() { return clear(); }
92 #define clear UNDEF(clear)
96 inline int UNDEF(clearok)(WINDOW* win, int bf) { return clearok(win, bf); }
98 #define clearok UNDEF(clearok)
100 extern "C" int clearok(WINDOW*, bool);
104 inline int UNDEF(clrtobot)() { return clrtobot(); }
106 #define clrtobot UNDEF(clrtobot)
110 inline int UNDEF(clrtoeol)() { return clrtoeol(); }
112 #define clrtoeol UNDEF(clrtoeol)
116 inline int UNDEF(delch)() { return delch(); }
118 #define delch UNDEF(delch)
122 inline int UNDEF(deleteln)() { return deleteln(); }
124 #define deleteln UNDEF(deleteln)
128 inline int UNDEF(erase)() { return erase(); }
130 #define erase UNDEF(erase)
134 inline int UNDEF(flushok)(WINDOW* _win, int _bf) { return flushok(_win, _bf); }
136 #define flushok UNDEF(flushok)
142 inline int UNDEF(getch)() { return getch(); }
144 #define getch UNDEF(getch)
148 inline int UNDEF(getstr)(char *_str) { return getstr(_str); }
150 #define getstr UNDEF(getstr)
154 inline void UNDEF(getyx)(WINDOW* win, int& y, int& x) { getyx(win, y, x); }
156 #define getyx UNDEF(getyx)
160 inline void UNDEF(getbegyx)(WINDOW* win, int& y, int& x) { getbegyx(win, y, x); }
162 #define getbegyx UNDEF(getbegyx)
166 inline void UNDEF(getmaxyx)(WINDOW* win, int& y, int& x) { getmaxyx(win, y, x); }
168 #define getmaxyx UNDEF(getmaxyx)
172 inline int UNDEF(hline)(chtype ch, int n) { return hline(ch, n); }
174 #define hline UNDEF(hline)
178 inline int UNDEF(inch)() { return inch(); }
180 #define inch UNDEF(inch)
184 inline int UNDEF(insch)(char c) { return insch(c); }
186 #define insch UNDEF(insch)
190 inline int UNDEF(insertln)() { return insertln(); }
192 #define insertln UNDEF(insertln)
196 inline int UNDEF(leaveok)(WINDOW* win, int bf) { return leaveok(win, bf); }
198 #define leaveok UNDEF(leaveok)
200 extern "C" int leaveok(WINDOW* win, bool bf);
204 inline int UNDEF(move)(int x, int y) { return move(x, y); }
206 #define move UNDEF(move)
210 inline int UNDEF(refresh)() { return refresh(); }
212 #define refresh UNDEF(refresh)
216 inline int UNDEF(scrl)(int l) { return scrl(l); }
218 #define scrl UNDEF(scrl)
222 inline int UNDEF(scroll)(WINDOW *win) { return scroll(win); }
224 #define scroll UNDEF(scroll)
228 inline int UNDEF(scrollok)(WINDOW* win, int bf) { return scrollok(win, bf); }
230 #define scrollok UNDEF(scrollok)
232 #if defined(__NCURSES_H)
233 extern "C" int scrollok(WINDOW*, bool);
235 extern "C" int scrollok(WINDOW*, char);
240 inline int UNDEF(setscrreg)(int t, int b) { return setscrreg(t, b); }
242 #define setscrreg UNDEF(setscrreg)
246 inline int UNDEF(standend)() { return standend(); }
248 #define standend UNDEF(standend)
252 inline int UNDEF(standout)() { return standout(); }
254 #define standout UNDEF(standout)
258 inline WINDOW *UNDEF(subpad)(WINDOW *p, int l, int c, int y, int x)
259 { return derwin(p,l,c,y,x); }
261 #define subpad UNDEF(subpad)
265 inline int UNDEF(timeout)(int delay) { return timeout(delay); }
267 #define timeout UNDEF(timeout)
271 inline int UNDEF(touchline)(WINDOW *win, int s, int c)
272 { return touchline(win,s,c); }
274 #define touchline UNDEF(touchline)
278 inline int UNDEF(touchwin)(WINDOW *win) { return touchwin(win); }
280 #define touchwin UNDEF(touchwin)
284 inline int UNDEF(untouchwin)(WINDOW *win) { return untouchwin(win); }
286 #define untouchwin UNDEF(untouchwin)
290 inline int UNDEF(vline)(chtype ch, int n) { return vline(ch, n); }
292 #define vline UNDEF(vline)
296 inline int UNDEF(waddstr)(WINDOW *win, char *str) { return waddstr(win, str); }
298 #define waddstr UNDEF(waddstr)
302 inline int UNDEF(waddchstr)(WINDOW *win, chtype *at) { return waddchstr(win, at); }
304 #define waddchstr UNDEF(waddchstr)
308 inline int UNDEF(wstandend)(WINDOW *win) { return wstandend(win); }
310 #define wstandend UNDEF(wstandend)
314 inline int UNDEF(wstandout)(WINDOW *win) { return wstandout(win); }
316 #define wstandout UNDEF(wstandout)
320 inline int UNDEF(wattroff)(WINDOW *win, int att) { return wattroff(win, att); }
322 #define wattroff UNDEF(wattroff)
326 inline int UNDEF(wattrset)(WINDOW *win, int att) { return wattrset(win, att); }
328 #define wattrset UNDEF(wattrset)
332 inline chtype UNDEF(winch)(WINDOW* win) { return winch(win); }
334 #define winch UNDEF(winch)
338 inline int UNDEF(mvwaddch)(WINDOW *win, int y, int x, chtype ch)
339 { return mvwaddch(win, y, x, ch); }
341 #define mvwaddch UNDEF(mvwaddch)
345 inline int UNDEF(mvwaddchnstr)(WINDOW *win, int y, int x, chtype *str, int n)
346 { return mvwaddchnstr(win, y, x, str, n); }
348 #define mvwaddchnstr UNDEF(mvwaddchnstr)
352 inline int UNDEF(mvwaddchstr)(WINDOW *win, int y, int x, chtype *str)
353 { return mvwaddchstr(win, y, x, str); }
355 #define mvwaddchstr UNDEF(mvwaddchstr)
359 inline int UNDEF(mvwaddnstr)(WINDOW *win, int y, int x, const char *str, int n)
360 { return mvwaddnstr(win, y, x, (char*)str, n); }
362 #define mvwaddnstr UNDEF(mvwaddnstr)
366 inline int UNDEF(mvwaddstr)(WINDOW *win, int y, int x, const char * str)
367 { return mvwaddstr(win, y, x, (char*)str); }
369 #define mvwaddstr UNDEF(mvwaddstr)
373 inline int UNDEF(mvwdelch)(WINDOW *win, int y, int x)
374 { return mvwdelch(win, y, x); }
376 #define mvwdelch UNDEF(mvwdelch)
380 inline int UNDEF(mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
382 #define mvwgetch UNDEF(mvwgetch)
386 inline int UNDEF(mvwgetstr)(WINDOW *win, int y, int x, char *str)
387 {return mvwgetstr(win,y,x, str);}
389 #define mvwgetstr UNDEF(mvwgetstr)
393 inline int UNDEF(mvwinch)(WINDOW *win, int y, int x) { return mvwinch(win, y, x);}
395 #define mvwinch UNDEF(mvwinch)
399 inline int UNDEF(mvwinsch)(WINDOW *win, int y, int x, char c)
400 { return mvwinsch(win, y, x, c); }
402 #define mvwinsch UNDEF(mvwinsch)
406 inline int UNDEF(mvaddch)(int y, int x, chtype ch)
407 { return mvaddch(y, x, ch); }
409 #define mvaddch UNDEF(mvaddch)
413 inline int UNDEF(mvaddnstr)(int y, int x, const char *str, int n)
414 { return mvaddnstr(y, x, (char*)str, n); }
416 #define mvaddnstr UNDEF(mvaddnstr)
420 inline int UNDEF(mvaddstr)(int y, int x, const char * str)
421 { return mvaddstr(y, x, (char*)str); }
423 #define mvaddstr UNDEF(mvaddstr)
427 inline int UNDEF(mvdelch)(int y, int x) { return mvdelch(y, x);}
429 #define mvdelch UNDEF(mvdelch)
433 inline int UNDEF(mvgetch)(int y, int x) { return mvgetch(y, x);}
435 #define mvgetch UNDEF(mvgetch)
439 inline int UNDEF(mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
441 #define mvgetstr UNDEF(mvgetstr)
445 inline int UNDEF(mvinch)(int y, int x) { return mvinch(y, x);}
447 #define mvinch UNDEF(mvinch)
451 inline int UNDEF(mvinsch)(int y, int x, char c)
452 { return mvinsch(y, x, c); }
454 #define mvinsch UNDEF(mvinsch)
458 inline void UNDEF(napms)(unsigned long x) { napms(x); }
460 #define napms UNDEF(napms)
464 inline int UNDEF(fixterm)(void) { return fixterm(); }
466 #define fixterm UNDEF(fixterm)
470 inline int UNDEF(resetterm)(void) { return resetterm(); }
472 #define resetterm UNDEF(resetterm)
476 inline int UNDEF(saveterm)(void) { return saveterm(); }
478 #define saveterm UNDEF(saveterm)
482 inline int UNDEF(crmode)(void) { return crmode(); }
484 #define crmode UNDEF(crmode)
488 inline int UNDEF(nocrmode)(void) { return nocrmode(); }
490 #define nocrmode UNDEF(nocrmode)
495 * C++ class for windows.
502 friend class NCursesMenu; friend class NCursesForm;
505 static void initialize();
507 void err_handler(const char *) const THROWS(NCursesException);
509 short getcolor(int getback) const;
511 static int setpalette(short fore, short back, short pair);
512 static int colorInitialized;
515 static int count; // count of all active windows:
516 // We rely on the c++ promise that
517 // all otherwise uninitialized
518 // static class vars are set to 0
520 WINDOW * w; // the curses WINDOW
522 int alloced; // true if we own the WINDOW
524 NCursesWindow* par; // parent, if subwindow
525 NCursesWindow* subwins; // head of subwindows list
526 NCursesWindow* sib; // next subwindow of parent
528 void kill_subwindows(); // disable all subwindows
531 NCursesWindow(WINDOW* &window); // useful only for stdscr
533 NCursesWindow(int lines, // number of lines
534 int cols, // number of columns
535 int begin_y, // line origin
536 int begin_x); // col origin
538 NCursesWindow(NCursesWindow& par,// parent window
539 int lines, // number of lines
540 int cols, // number of columns
541 int by, // absolute or relative
543 char absrel = 'a');// if `a', by & bx are
544 // absolute screen pos,
545 // else if `r', they are
546 // relative to par origin
547 virtual ~NCursesWindow();
549 static void useColors(void);
550 // Call this routine very early if you want to have colors.
553 int lines() const { return LINES; }
554 // number of lines on terminal, *not* window
555 int cols() const { return COLS; }
556 // number of cols on terminal, *not* window
557 static int NumberOfColors();
558 // number of available colors
559 int colors() const { return NumberOfColors(); }
560 // number of available colors
563 int height() const { return maxy() + 1; }
564 // number of lines in this window
565 int width() const { return maxx() + 1; }
566 // number of cols in this window
567 int begx() const { return w->_begx; }
568 // smallest x coord in window
569 int begy() const { return w->_begy; }
570 // smallest y coord in window
571 int maxx() const { return w->_maxx; }
572 // largest x coord in window
573 int maxy() const { return w->_maxy; }
574 // largest x coord in window
575 short getcolor() const;
577 short foreground() const { return getcolor(0); }
578 // actual foreground color
579 short background() const { return getcolor(1); }
580 // actual background color
581 int setpalette(short fore, short back);
582 // set color palette entry
583 int setcolor(short pair);
584 // set actually used palette entry
586 // window positioning
587 int move(int y, int x) { return ::wmove(w, y, x); }
589 // coordinate positioning
590 void getyx(int& y, int& x) { ::getyx(w, y, x); }
591 int mvcur(int sy, int ey, int sx, int ex) {
592 return ::mvcur(sy, ey, sx, ex); }
595 int getch() { return ::wgetch(w); }
596 int getch(int y, int x) {
597 return (::wmove(w, y, x)==ERR) ? ERR : ::wgetch(w); }
598 int getstr(char* str) { return ::wgetstr(w, str); }
599 int getstr(int y, int x, char* str) {
600 return (::wmove(w, y, x)==ERR) ? ERR : ::wgetstr(w, str); }
601 int scanw(const char*, ...)
603 __attribute__ ((format (scanf, 2, 3)));
607 int scanw(int, int, const char*, ...)
609 __attribute__ ((format (scanf, 4, 5)));
615 int addch(const chtype ch) { return ::waddch(w, ch); }
616 int addch(int y, int x, chtype ch) {
617 return (::wmove(w, y, x)==ERR) ? ERR : ::waddch(w, ch); }
618 int addstr(const char* str) { return ::waddstr(w, (char*)str); }
619 int addstr(int y, int x, const char * str) {
620 return (::wmove(w, y, x)==ERR) ? ERR : ::waddstr(w, (char*)str); }
621 int printw(const char* fmt, ...)
623 __attribute__ ((format (printf, 2, 3)));
627 int printw(int y, int x, const char * fmt, ...)
629 __attribute__ ((format (printf, 4, 5)));
633 int inch() { return ::winch(w); }
634 int inch(int y, int x) {
635 return (::wmove(w, y, x)==ERR) ? ERR : (int) ::winch(w); }
636 int insch(chtype ch) { return ::winsch(w, ch); }
637 int insch(int y, int x, chtype ch) {
638 return (::wmove(w, y, x)==ERR) ? ERR : ::winsch(w, ch); }
639 int insertln() { return ::winsertln(w); }
640 int attron(chtype at) { return ::wattron(w, at); }
641 int attroff(chtype at) { return ::wattroff(w, at); }
642 int attrset(chtype at) { return ::wattrset(w, at); }
645 int box(chtype vert=0, chtype hor=0) { return ::box(w, vert, hor); }
648 int hline(int y, int x, chtype ch, int len) {
649 return (::wmove(w, y, x)==ERR) ? ERR: ::whline(w, ch, len); }
650 int hline(int y, int x, int len) {
651 return (::wmove(w, y, x)==ERR) ? ERR: ::whline(w, 0, len); }
652 int hline(chtype ch, int len) { return ::whline(w, ch, len); }
653 int hline(int len) { return ::whline(w, 0, len); }
654 int vline(int y, int x, chtype ch, int len) {
655 return (::wmove(w, y, x)==ERR) ? ERR: ::wvline(w, ch, len); }
656 int vline(int y, int x, int len) {
657 return (::wmove(w, y, x)==ERR) ? ERR: ::wvline(w, 0, len); }
658 int vline(chtype ch, int len) { return ::wvline(w, ch, len); }
659 int vline(int len) { return ::wvline(w, 0, len); }
662 int erase() { return ::werase(w); }
663 int clear() { return ::wclear(w); }
664 int clearok(int bf) { return ::clearok(w, bf); }
665 int clrtobot() { return ::wclrtobot(w); }
666 int clrtoeol() { return ::wclrtoeol(w); }
667 int delch() { return ::wdelch(w); }
668 int delch(int y, int x) {
669 return (::wmove(w, y, x)==ERR) ? ERR : ::wdelch(w); }
670 int deleteln() { return ::wdeleteln(w); }
673 int scroll() { return ::scroll(w); }
674 int scrollok(int bf) { return ::scrollok(w, bf); }
675 int idlok(int bf) { return ::idlok(w, bf); }
676 int touchwin() { return ::touchwin(w); }
677 int refresh() { return ::wrefresh(w); }
678 int leaveok(int bf) { return ::leaveok(w, bf); }
679 int noutrefresh() { return ::wnoutrefresh(w); }
680 int doupdate() { return ::doupdate(); }
682 int flushok(int bf) { return ::flushok(w, bf); }
684 int keypad(int bf) { return ::keypad(w, bf); }
685 int standout() { return ::wstandout(w); }
686 int standend() { return ::wstandend(w); }
688 // multiple window control
689 int overlay(NCursesWindow &win) {
690 return ::overlay(w, win.w); }
691 int overwrite(NCursesWindow &win) {
692 return ::overwrite(w, win.w); }
696 NCursesWindow* child() { return subwins; }
697 NCursesWindow* sibling() { return sib; }
698 NCursesWindow* parent() { return par; }
700 // True if win is a child of this window.
701 bool isDescendant(NCursesWindow& win);
705 // We leave this here for compatibility reasons.
706 class NCursesColorWindow : public NCursesWindow {
708 NCursesColorWindow(WINDOW* &window) // useful only for stdscr
709 : NCursesWindow(window) {
712 NCursesColorWindow(int lines, // number of lines
713 int cols, // number of columns
714 int begin_y, // line origin
715 int begin_x) // col origin
716 : NCursesWindow(lines,cols,begin_y,begin_x) {
719 NCursesColorWindow(NCursesWindow& par,// parent window
720 int lines, // number of lines
721 int cols, // number of columns
722 int by, // absolute or relative
724 char absrel = 'a') // if `a', by & bx are
725 : NCursesWindow(par,lines,cols, // absolute screen pos,
726 by,bx) { // else if `r', they are
727 useColors(); } // relative to par origin