1 // * This makes emacs happy -*-Mode: C++;-*-
5 // $Id: cursesw.h,v 1.13 1998/01/20 16:53:50 Fred.Fish Exp $
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
17 #include <strstream.h>
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. */
28 /* "Convert" macros to inlines. We'll define it as another symbol to avoid
29 * conflict with library symbols.
32 #define UNDEF(name) CUR_ ##name
35 inline int UNDEF(addch)(chtype ch) { return addch(ch); }
37 #define addch UNDEF(addch)
41 inline int UNDEF(echochar)(chtype ch) { return echochar(ch); }
43 #define echochar UNDEF(echochar)
47 inline int UNDEF(insdelln)(int n) { return insdelln(n); }
49 #define insdelln UNDEF(insdelln)
53 /* The (char*) cast is to hack around missing const's */
54 inline int UNDEF(addstr)(const char * str) { return addstr((char*)str); }
56 #define addstr UNDEF(addstr)
60 inline int UNDEF(attron)(chtype at) { return attron(at); }
62 #define attron UNDEF(attron)
66 inline int UNDEF(attroff)(chtype at) { return attroff(at); }
68 #define attroff UNDEF(attroff)
72 inline chtype UNDEF(attrset)(chtype at) { return attrset(at); }
74 #define attrset UNDEF(attrset)
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); }
81 #define border UNDEF(border)
85 inline int UNDEF(box)(WINDOW *win, int v, int h) { return box(win, v, h); }
87 #define box UNDEF(box)
91 inline int UNDEF(mvwhline)(WINDOW *win,int y,int x,chtype c,int n) {
92 return mvwhline(win,y,x,c,n); }
94 #define mvwhline UNDEF(mvwhline)
98 inline int UNDEF(mvwvline)(WINDOW *win,int y,int x,chtype c,int n) {
99 return mvwvline(win,y,x,c,n); }
101 #define mvwvline UNDEF(mvwvline)
105 inline int UNDEF(clear)() { return clear(); }
107 #define clear UNDEF(clear)
111 inline int UNDEF(clearok)(WINDOW* win, bool bf) { return clearok(win, bf); }
113 #define clearok UNDEF(clearok)
115 extern "C" int clearok(WINDOW*, bool);
119 inline int UNDEF(clrtobot)() { return clrtobot(); }
121 #define clrtobot UNDEF(clrtobot)
125 inline int UNDEF(clrtoeol)() { return clrtoeol(); }
127 #define clrtoeol UNDEF(clrtoeol)
131 inline int UNDEF(delch)() { return delch(); }
133 #define delch UNDEF(delch)
137 inline int UNDEF(deleteln)() { return deleteln(); }
139 #define deleteln UNDEF(deleteln)
143 inline int UNDEF(erase)() { return erase(); }
145 #define erase UNDEF(erase)
149 inline int UNDEF(flushok)(WINDOW* _win, bool _bf) {
150 return flushok(_win, _bf); }
152 #define flushok UNDEF(flushok)
158 inline int UNDEF(getch)() { return getch(); }
160 #define getch UNDEF(getch)
164 inline int UNDEF(getstr)(char *_str) { return getstr(_str); }
166 #define getstr UNDEF(getstr)
170 inline int UNDEF(instr)(char *_str) { return instr(_str); }
172 #define instr UNDEF(instr)
176 inline int UNDEF(innstr)(char *_str, int n) { return innstr(_str,n); }
178 #define innstr UNDEF(innstr)
182 inline int UNDEF(mvwinnstr)(WINDOW *win, int y, int x, char *_str, int n) {
183 return mvwinnstr(win,y,x,_str,n); }
185 #define mvwinnstr UNDEF(mvwinnstr)
189 inline int UNDEF(mvinnstr)(int y, int x, char *_str, int n) {
190 return mvinnstr(y,x,_str,n); }
192 #define mvinnstr UNDEF(mvinnstr)
196 inline int UNDEF(winsstr)(WINDOW *w, const char *_str) {
197 return winsstr(w,_str); }
199 #define winsstr UNDEF(winsstr)
203 inline int UNDEF(mvwinsstr)(WINDOW *w, int y, int x, const char *_str) {
204 return mvwinsstr(w,y,x,_str); }
206 #define mvwinsstr UNDEF(mvwinsstr)
210 inline int UNDEF(insstr)(const char *_str) {
211 return insstr(_str); }
213 #define insstr UNDEF(insstr)
217 inline int UNDEF(mvinsstr)(int y, int x,const char *_str) {
218 return mvinsstr(y,x,_str); }
220 #define mvinsstr UNDEF(mvinsstr)
224 inline int UNDEF(insnstr)(const char *_str, int n) {
225 return insnstr(_str,n); }
227 #define insnstr UNDEF(insnstr)
231 inline int UNDEF(mvwinsnstr)(WINDOW *w, int y, int x,const char *_str, int n) {
232 return mvwinsnstr(w,y,x,_str,n); }
234 #define mvwinsnstr UNDEF(mvwinsnstr)
238 inline int UNDEF(mvinsnstr)(int y, int x,const char *_str, int n) {
239 return mvinsnstr(y,x,_str,n); }
241 #define mvinsnstr UNDEF(mvinsnstr)
245 inline int UNDEF(getnstr)(char *_str, int n) { return getnstr(_str,n); }
247 #define getnstr UNDEF(getnstr)
251 inline void UNDEF(getyx)(const WINDOW* win, int& y, int& x) {
254 #define getyx UNDEF(getyx)
258 inline void UNDEF(getbegyx)(WINDOW* win, int& y, int& x) { getbegyx(win, y, x); }
260 #define getbegyx UNDEF(getbegyx)
264 inline void UNDEF(getmaxyx)(WINDOW* win, int& y, int& x) { getmaxyx(win, y, x); }
266 #define getmaxyx UNDEF(getmaxyx)
270 inline int UNDEF(hline)(chtype ch, int n) { return hline(ch, n); }
272 #define hline UNDEF(hline)
276 inline chtype UNDEF(inch)() { return inch(); }
278 #define inch UNDEF(inch)
282 inline int UNDEF(insch)(char c) { return insch(c); }
284 #define insch UNDEF(insch)
288 inline int UNDEF(insertln)() { return insertln(); }
290 #define insertln UNDEF(insertln)
294 inline int UNDEF(leaveok)(WINDOW* win, bool bf) { return leaveok(win, bf); }
296 #define leaveok UNDEF(leaveok)
298 extern "C" int leaveok(WINDOW* win, bool bf);
302 inline int UNDEF(move)(int x, int y) { return move(x, y); }
304 #define move UNDEF(move)
308 inline int UNDEF(refresh)() { return refresh(); }
310 #define refresh UNDEF(refresh)
314 inline int UNDEF(redrawwin)(WINDOW *win) { return redrawwin(win); }
316 #define redrawwin UNDEF(redrawwin)
320 inline int UNDEF(scrl)(int l) { return scrl(l); }
322 #define scrl UNDEF(scrl)
326 inline int UNDEF(scroll)(WINDOW *win) { return scroll(win); }
328 #define scroll UNDEF(scroll)
332 inline int UNDEF(scrollok)(WINDOW* win, bool bf) { return scrollok(win, bf); }
334 #define scrollok UNDEF(scrollok)
336 #if defined(__NCURSES_H)
337 extern "C" int scrollok(WINDOW*, bool);
339 extern "C" int scrollok(WINDOW*, char);
344 inline int UNDEF(setscrreg)(int t, int b) { return setscrreg(t, b); }
346 #define setscrreg UNDEF(setscrreg)
350 inline int UNDEF(standend)() { return standend(); }
352 #define standend UNDEF(standend)
356 inline int UNDEF(standout)() { return standout(); }
358 #define standout UNDEF(standout)
362 inline WINDOW *UNDEF(subpad)(WINDOW *p, int l, int c, int y, int x)
363 { return derwin(p,l,c,y,x); }
365 #define subpad UNDEF(subpad)
369 inline int UNDEF(timeout)(int delay) { return timeout(delay); }
371 #define timeout UNDEF(timeout)
375 inline int UNDEF(touchline)(WINDOW *win, int s, int c)
376 { return touchline(win,s,c); }
378 #define touchline UNDEF(touchline)
382 inline int UNDEF(touchwin)(WINDOW *win) { return touchwin(win); }
384 #define touchwin UNDEF(touchwin)
388 inline int UNDEF(untouchwin)(WINDOW *win) { return untouchwin(win); }
390 #define untouchwin UNDEF(untouchwin)
394 inline int UNDEF(vline)(chtype ch, int n) { return vline(ch, n); }
396 #define vline UNDEF(vline)
400 inline int UNDEF(waddstr)(WINDOW *win, char *str) { return waddstr(win, str); }
402 #define waddstr UNDEF(waddstr)
406 inline int UNDEF(waddchstr)(WINDOW *win, chtype *at) { return waddchstr(win, at); }
408 #define waddchstr UNDEF(waddchstr)
412 inline int UNDEF(wstandend)(WINDOW *win) { return wstandend(win); }
414 #define wstandend UNDEF(wstandend)
418 inline int UNDEF(wstandout)(WINDOW *win) { return wstandout(win); }
420 #define wstandout UNDEF(wstandout)
425 inline int UNDEF(wattroff)(WINDOW *win, int att) { return wattroff(win, att); }
427 #define wattroff UNDEF(wattroff)
431 inline int UNDEF(chgat)(int n,attr_t attr, short color, const void *opts) {
432 return chgat(n,attr,color,opts); }
434 #define chgat UNDEF(chgat)
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); }
442 #define mvchgat UNDEF(mvchgat)
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); }
450 #define mvwchgat UNDEF(mvwchgat)
454 inline int UNDEF(wattrset)(WINDOW *win, int att) { return wattrset(win, att); }
456 #define wattrset UNDEF(wattrset)
460 inline chtype UNDEF(winch)(const WINDOW* win) { return winch(win); }
462 #define winch UNDEF(winch)
466 inline int UNDEF(mvwaddch)(WINDOW *win, int y, int x, const chtype ch)
467 { return mvwaddch(win, y, x, ch); }
469 #define mvwaddch UNDEF(mvwaddch)
473 inline int UNDEF(mvwaddchnstr)(WINDOW *win, int y, int x, chtype *str, int n)
474 { return mvwaddchnstr(win, y, x, str, n); }
476 #define mvwaddchnstr UNDEF(mvwaddchnstr)
480 inline int UNDEF(mvwaddchstr)(WINDOW *win, int y, int x, chtype *str)
481 { return mvwaddchstr(win, y, x, str); }
483 #define mvwaddchstr UNDEF(mvwaddchstr)
487 inline int UNDEF(addnstr)(const char *str, int n)
488 { return addnstr((char*)str, n); }
490 #define addnstr UNDEF(addnstr)
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); }
497 #define mvwaddnstr UNDEF(mvwaddnstr)
501 inline int UNDEF(mvwaddstr)(WINDOW *win, int y, int x, const char * str)
502 { return mvwaddstr(win, y, x, (char*)str); }
504 #define mvwaddstr UNDEF(mvwaddstr)
508 inline int UNDEF(mvwdelch)(WINDOW *win, int y, int x)
509 { return mvwdelch(win, y, x); }
511 #define mvwdelch UNDEF(mvwdelch)
515 inline int UNDEF(mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
517 #define mvwgetch UNDEF(mvwgetch)
521 inline int UNDEF(mvwgetstr)(WINDOW *win, int y, int x, char *str)
522 {return mvwgetstr(win,y,x, str);}
524 #define mvwgetstr UNDEF(mvwgetstr)
528 inline int UNDEF(mvwgetnstr)(WINDOW *win, int y, int x, char *str, int n)
529 {return mvwgetnstr(win,y,x, str,n);}
531 #define mvwgetnstr UNDEF(mvwgetnstr)
535 inline chtype UNDEF(mvwinch)(WINDOW *win, int y, int x) {
536 return mvwinch(win, y, x);}
538 #define mvwinch UNDEF(mvwinch)
542 inline int UNDEF(mvwinsch)(WINDOW *win, int y, int x, char c)
543 { return mvwinsch(win, y, x, c); }
545 #define mvwinsch UNDEF(mvwinsch)
549 inline int UNDEF(mvaddch)(int y, int x, chtype ch)
550 { return mvaddch(y, x, ch); }
552 #define mvaddch UNDEF(mvaddch)
556 inline int UNDEF(mvaddnstr)(int y, int x, const char *str, int n)
557 { return mvaddnstr(y, x, (char*)str, n); }
559 #define mvaddnstr UNDEF(mvaddnstr)
563 inline int UNDEF(mvaddstr)(int y, int x, const char * str)
564 { return mvaddstr(y, x, (char*)str); }
566 #define mvaddstr UNDEF(mvaddstr)
570 inline int UNDEF(mvdelch)(int y, int x) { return mvdelch(y, x);}
572 #define mvdelch UNDEF(mvdelch)
576 inline int UNDEF(mvgetch)(int y, int x) { return mvgetch(y, x);}
578 #define mvgetch UNDEF(mvgetch)
582 inline int UNDEF(mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
584 #define mvgetstr UNDEF(mvgetstr)
588 inline int UNDEF(mvgetnstr)(int y, int x, char *str, int n) {
589 return mvgetnstr(y, x, str,n);}
591 #define mvgetnstr UNDEF(mvgetnstr)
595 inline chtype UNDEF(mvinch)(int y, int x) { return mvinch(y, x);}
597 #define mvinch UNDEF(mvinch)
601 inline int UNDEF(mvinsch)(int y, int x, char c)
602 { return mvinsch(y, x, c); }
604 #define mvinsch UNDEF(mvinsch)
608 inline void UNDEF(napms)(unsigned long x) { napms(x); }
610 #define napms UNDEF(napms)
614 inline int UNDEF(fixterm)(void) { return fixterm(); }
616 #define fixterm UNDEF(fixterm)
620 inline int UNDEF(resetterm)(void) { return resetterm(); }
622 #define resetterm UNDEF(resetterm)
626 inline int UNDEF(saveterm)(void) { return saveterm(); }
628 #define saveterm UNDEF(saveterm)
632 inline int UNDEF(crmode)(void) { return crmode(); }
634 #define crmode UNDEF(crmode)
638 inline int UNDEF(nocrmode)(void) { return nocrmode(); }
640 #define nocrmode UNDEF(nocrmode)
644 inline chtype UNDEF(getbkgd)(const WINDOW *win) { return getbkgd(win); }
646 #define getbkgd UNDEF(getbkgd)
650 inline int UNDEF(bkgd)(chtype ch) { return bkgd(ch); }
652 #define bkgd UNDEF(bkgd)
656 inline void UNDEF(bkgdset)(chtype ch) { bkgdset(ch); }
658 #define bkgdset UNDEF(bkgdset)
663 * C++ class for windows.
670 friend class NCursesMenu;
671 friend class NCursesForm;
674 static bool b_initialized;
675 static void initialize();
676 static int ripoff_init(WINDOW *,int);
680 short getcolor(int getback) const;
682 static int setpalette(short fore, short back, short pair);
683 static int colorInitialized;
685 // This private constructor is only used during the initialization
686 // of windows generated by ripoffline() calls.
687 NCursesWindow(WINDOW* win, int cols);
690 void err_handler(const char *) const THROWS(NCursesException);
691 // Signal an error with the given message text.
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
698 WINDOW* w; // the curses WINDOW
700 bool alloced; // TRUE if we own the WINDOW
702 NCursesWindow* par; // parent, if subwindow
703 NCursesWindow* subwins; // head of subwindows list
704 NCursesWindow* sib; // next subwindow of parent
706 void kill_subwindows(); // disable all subwindows
707 // Destroy all subwindows.
709 /* Only for use by derived classes. They are then in charge to
710 fill the member variables correctly. */
714 NCursesWindow(WINDOW* &window); // useful only for stdscr
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
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
729 virtual ~NCursesWindow();
731 NCursesWindow Clone();
732 // Make an exact copy of the window.
735 static void useColors(void);
736 // Call this routine very early if you want to have colors.
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.
749 // -------------------------------------------------------------------------
751 // -------------------------------------------------------------------------
752 int lines() const { return LINES; }
753 // Number of lines on terminal, *not* window
755 int cols() const { return COLS; }
756 // Number of cols on terminal, *not* window
758 int tabsize() const { return TABSIZE; }
759 // Size of a tab on terminal, *not* window
761 static int NumberOfColors();
762 // Number of available colors
764 int colors() const { return NumberOfColors(); }
765 // Number of available colors
767 // -------------------------------------------------------------------------
769 // -------------------------------------------------------------------------
770 int height() const { return maxy() + 1; }
771 // Number of lines in this window
773 int width() const { return maxx() + 1; }
774 // Number of columns in this window
776 int begx() const { return w->_begx; }
777 // Column of top left corner relative to stdscr
779 int begy() const { return w->_begy; }
780 // Line of top left corner relative to stdscr
782 int maxx() const { return w->_maxx; }
783 // Largest x coord in window
785 int maxy() const { return w->_maxy; }
786 // Largest y coord in window
788 short getcolor() const;
791 short foreground() const { return getcolor(0); }
792 // Actual foreground color
794 short background() const { return getcolor(1); }
795 // Actual background color
797 int setpalette(short fore, short back);
798 // Set color palette entry
800 int setcolor(short pair);
801 // Set actually used palette entry
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.
811 // -------------------------------------------------------------------------
812 // coordinate positioning
813 // -------------------------------------------------------------------------
814 int move(int y, int x) { return ::wmove(w, y, x); }
815 // Move cursor the this position
817 void getyx(int& y, int& x) const { ::getyx(w, y, x); }
818 // Get current position of the cursor
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.
824 // -------------------------------------------------------------------------
826 // -------------------------------------------------------------------------
827 int getch() { return ::wgetch(w); }
828 // Get a keystroke from the window.
830 int getch(int y, int x) { return ::mvwgetch(w,y,x); }
831 // Move cursor to position and get a keystroke from the window
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
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.
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.
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.
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.
858 __attribute__ ((format (scanf, 2, 3)));
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.
867 __attribute__ ((format (scanf, 4, 5)));
872 // -------------------------------------------------------------------------
874 // -------------------------------------------------------------------------
875 int addch(const chtype ch) { return ::waddch(w, ch); }
876 // Put attributed character to the window.
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
883 int echochar(const chtype ch) { return ::wechochar(w,ch); }
884 // Put attributed character to the window and refresh it immediately.
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.
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.
896 int printw(const char* fmt, ...)
897 // Do a formatted print to the window.
899 __attribute__ ((format (printf, 2, 3)));
904 int printw(int y, int x, const char * fmt, ...)
905 // Move the cursor and then do a formatted print to the window.
907 __attribute__ ((format (printf, 4, 5)));
912 chtype inch() const { return ::winch(w); }
913 // Retrieve attributed character under the current cursor position.
915 chtype inch(int y, int x) { return ::mvwinch(w,y,x); }
916 // Move cursor to requested position and then retrieve attributed character
919 int insch(chtype ch) { return ::winsch(w, ch); }
920 // Insert attributed character into the window before current cursor
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.
928 int insertln() { return ::winsdelln(w,1); }
929 // Insert an empty line above the current line.
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.
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.
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.
946 int attron (chtype at) { return ::wattron (w, at); }
947 // Switch on the window attributes;
949 int attroff(chtype at) { return ::wattroff(w, at); }
950 // Switch off the window attributes;
952 int attrset(chtype at) { return ::wattrset(w, at); }
953 // Set the window attributes;
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.
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
967 // -------------------------------------------------------------------------
969 // -------------------------------------------------------------------------
970 chtype getbkgd() const { return ::getbkgd(w); }
971 // Get current background setting.
973 int bkgd(const chtype ch) { return ::wbkgd(w,ch); }
974 // Set the background property and apply it to the window.
976 void bkgdset(chtype ch) { ::wbkgdset(w,ch); }
977 // Set the background property.
979 // -------------------------------------------------------------------------
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.
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.
998 // -------------------------------------------------------------------------
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.
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.
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.
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.
1017 // -------------------------------------------------------------------------
1019 // -------------------------------------------------------------------------
1020 int erase() { return ::werase(w); }
1021 // Erase the window.
1023 int clear() { return ::wclear(w); }
1024 // Clear the window.
1026 int clearok(bool bf) { return ::clearok(w, bf); }
1027 // Set/Reset the clear flag. If set, the next refresh() will clear the
1030 int clrtobot() { return ::wclrtobot(w); }
1031 // Clear to the end of the window.
1033 int clrtoeol() { return ::wclrtoeol(w); }
1034 // Clear to the end of the line.
1036 int delch() { return ::wdelch(w); }
1037 // Delete character under the cursor.
1039 int delch(int y, int x) { return ::mvwdelch(w,y,x); }
1040 // Move cursor to requested position and delete the character under the
1043 int deleteln() { return ::winsdelln(w,-1); }
1044 // Delete the current line.
1046 // -------------------------------------------------------------------------
1048 // -------------------------------------------------------------------------
1049 int scroll(int amount=1) { return ::wscrl(w,amount); }
1050 // Scroll amount lines. If amount is positive, scroll up, otherwise
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.
1058 int setscrreg(int from, int to) {
1059 return ::wsetscrreg(w,from,to); }
1060 // Define a soft scrolling region.
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.
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.
1071 int touchwin() { return ::wtouchln(w,0,height(),1); }
1072 // Mark the whole window as modified.
1074 int untouchwin() { return ::wtouchln(w,0,height(),0); }
1075 // Mark the whole window as unmodified.
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.
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
1086 bool is_wintouched() const {
1087 return (::is_wintouched(w) ? TRUE:FALSE); }
1088 // Return TRUE if window is marked as changed, FALSE otherwise
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.
1094 int redrawln(int from, int n) { return ::wredrawln(w,from,n); }
1095 // Redraw n lines starting from the requested line
1097 int redrawwin() { return ::wredrawln(w,0,height()); }
1098 // Redraw the whole window
1100 int doupdate() { return ::doupdate(); }
1101 // Do all outputs to make the physical screen looking like the virtual one
1103 void syncdown() { ::wsyncdown(w); }
1104 // Propagate the changes down to all descendant windows
1106 void syncup() { ::wsyncup(w); }
1107 // Propagate the changes up in the hierarchy
1109 void cursyncup() { ::wcursyncup(w); }
1110 // Position the cursor in all ancestor windows corresponding to our setting
1112 int syncok(bool bf) { return ::syncok(w,bf); }
1113 // If called with bf=TRUE, syncup() is called whenever the window is changed
1116 int flushok(bool bf) { return ::flushok(w, bf); }
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()
1123 int keypad(bool bf) { return ::keypad(w, bf); }
1124 // If called with bf=TRUE, the application will interpret function keys.
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.
1130 int standout() { return ::wstandout(w); }
1131 // Enable "standout" attributes
1133 int standend() { return ::wstandend(w); }
1134 // Disable "standout" attributes
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.
1144 virtual int noutrefresh() { return ::wnoutrefresh(w); }
1145 // Propagate the changes in this window to the virtual screen. This is
1146 // redefined in NCursesPanel.
1148 // -------------------------------------------------------------------------
1149 // multiple window control
1150 // -------------------------------------------------------------------------
1151 int overlay(NCursesWindow& win) {
1152 return ::overlay(w, win.w); }
1153 // Overlay this window over win.
1155 int overwrite(NCursesWindow& win) {
1156 return ::overwrite(w, win.w); }
1157 // Overwrite win with this window.
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
1169 // -------------------------------------------------------------------------
1171 // -------------------------------------------------------------------------
1172 bool has_mouse() const;
1173 // Return TRUE if terminal supports a mouse, FALSE otherwise
1175 // -------------------------------------------------------------------------
1176 // traversal support
1177 // -------------------------------------------------------------------------
1178 NCursesWindow* child() { return subwins; }
1179 // Get the first child window.
1181 NCursesWindow* sibling() { return sib; }
1182 // Get the next child of my parent.
1184 NCursesWindow* parent() { return par; }
1187 bool isDescendant(NCursesWindow& win);
1188 // Return TRUE if win is a descendant of this.
1191 // -------------------------------------------------------------------------
1192 // We leave this here for compatibility reasons.
1193 // -------------------------------------------------------------------------
1194 class NCursesColorWindow : public NCursesWindow {
1196 NCursesColorWindow(WINDOW* &window) // useful only for stdscr
1197 : NCursesWindow(window) {
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) {
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
1219 class NCursesPad : public NCursesWindow {
1221 NCursesPad(int lines, int cols);
1223 int echochar(const chtype ch) { return ::pechochar(w,ch); }
1224 // Put the attributed character onto the pad and immediately do a
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
1230 int refresh() { return OK; };
1231 int noutrefresh() { return OK; };
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);
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().
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);
1249 // Does the same like refresh() but without calling doupdate().
1252 #endif // _CURSESW_H