1 // * This makes emacs happy -*-Mode: C++;-*-
5 // $Id: cursesw.h,v 1.18 1999/10/23 15:16:53 tom 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 chtype UNDEF(color_set)(short p,void* opts) { return color_set(p,opts); }
80 #define color_set UNDEF(color_set)
84 inline int UNDEF(border)(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, chtype tr, chtype bl, chtype br)
85 { return border(ls,rs,ts,bs,tl,tr,bl,br); }
87 #define border UNDEF(border)
91 inline int UNDEF(box)(WINDOW *win, int v, int h) { return box(win, v, h); }
93 #define box UNDEF(box)
97 inline int UNDEF(mvwhline)(WINDOW *win,int y,int x,chtype c,int n) {
98 return mvwhline(win,y,x,c,n); }
100 #define mvwhline UNDEF(mvwhline)
104 inline int UNDEF(mvwvline)(WINDOW *win,int y,int x,chtype c,int n) {
105 return mvwvline(win,y,x,c,n); }
107 #define mvwvline UNDEF(mvwvline)
111 inline int UNDEF(clear)() { return clear(); }
113 #define clear UNDEF(clear)
117 inline int UNDEF(clearok)(WINDOW* win, bool bf) { return clearok(win, bf); }
119 #define clearok UNDEF(clearok)
121 extern "C" int clearok(WINDOW*, bool);
125 inline int UNDEF(clrtobot)() { return clrtobot(); }
127 #define clrtobot UNDEF(clrtobot)
131 inline int UNDEF(clrtoeol)() { return clrtoeol(); }
133 #define clrtoeol UNDEF(clrtoeol)
137 inline int UNDEF(delch)() { return delch(); }
139 #define delch UNDEF(delch)
143 inline int UNDEF(deleteln)() { return deleteln(); }
145 #define deleteln UNDEF(deleteln)
149 inline int UNDEF(erase)() { return erase(); }
151 #define erase UNDEF(erase)
155 inline int UNDEF(flushok)(WINDOW* _win, bool _bf) {
156 return flushok(_win, _bf); }
158 #define flushok UNDEF(flushok)
164 inline int UNDEF(getch)() { return getch(); }
166 #define getch UNDEF(getch)
170 inline int UNDEF(getstr)(char *_str) { return getstr(_str); }
172 #define getstr UNDEF(getstr)
176 inline int UNDEF(instr)(char *_str) { return instr(_str); }
178 #define instr UNDEF(instr)
182 inline int UNDEF(innstr)(char *_str, int n) { return innstr(_str,n); }
184 #define innstr UNDEF(innstr)
188 inline int UNDEF(mvwinnstr)(WINDOW *win, int y, int x, char *_str, int n) {
189 return mvwinnstr(win,y,x,_str,n); }
191 #define mvwinnstr UNDEF(mvwinnstr)
195 inline int UNDEF(mvinnstr)(int y, int x, char *_str, int n) {
196 return mvinnstr(y,x,_str,n); }
198 #define mvinnstr UNDEF(mvinnstr)
202 inline int UNDEF(winsstr)(WINDOW *w, const char *_str) {
203 return winsstr(w,_str); }
205 #define winsstr UNDEF(winsstr)
209 inline int UNDEF(mvwinsstr)(WINDOW *w, int y, int x, const char *_str) {
210 return mvwinsstr(w,y,x,_str); }
212 #define mvwinsstr UNDEF(mvwinsstr)
216 inline int UNDEF(insstr)(const char *_str) {
217 return insstr(_str); }
219 #define insstr UNDEF(insstr)
223 inline int UNDEF(mvinsstr)(int y, int x,const char *_str) {
224 return mvinsstr(y,x,_str); }
226 #define mvinsstr UNDEF(mvinsstr)
230 inline int UNDEF(insnstr)(const char *_str, int n) {
231 return insnstr(_str,n); }
233 #define insnstr UNDEF(insnstr)
237 inline int UNDEF(mvwinsnstr)(WINDOW *w, int y, int x,const char *_str, int n) {
238 return mvwinsnstr(w,y,x,_str,n); }
240 #define mvwinsnstr UNDEF(mvwinsnstr)
244 inline int UNDEF(mvinsnstr)(int y, int x,const char *_str, int n) {
245 return mvinsnstr(y,x,_str,n); }
247 #define mvinsnstr UNDEF(mvinsnstr)
251 inline int UNDEF(getnstr)(char *_str, int n) { return getnstr(_str,n); }
253 #define getnstr UNDEF(getnstr)
257 inline void UNDEF(getyx)(const WINDOW* win, int& y, int& x) {
260 #define getyx UNDEF(getyx)
264 inline void UNDEF(getbegyx)(WINDOW* win, int& y, int& x) { getbegyx(win, y, x); }
266 #define getbegyx UNDEF(getbegyx)
270 inline void UNDEF(getmaxyx)(WINDOW* win, int& y, int& x) { getmaxyx(win, y, x); }
272 #define getmaxyx UNDEF(getmaxyx)
276 inline int UNDEF(hline)(chtype ch, int n) { return hline(ch, n); }
278 #define hline UNDEF(hline)
282 inline chtype UNDEF(inch)() { return inch(); }
284 #define inch UNDEF(inch)
288 inline int UNDEF(insch)(char c) { return insch(c); }
290 #define insch UNDEF(insch)
294 inline int UNDEF(insertln)() { return insertln(); }
296 #define insertln UNDEF(insertln)
300 inline int UNDEF(leaveok)(WINDOW* win, bool bf) { return leaveok(win, bf); }
302 #define leaveok UNDEF(leaveok)
304 extern "C" int leaveok(WINDOW* win, bool bf);
308 inline int UNDEF(move)(int x, int y) { return move(x, y); }
310 #define move UNDEF(move)
314 inline int UNDEF(refresh)() { return refresh(); }
316 #define refresh UNDEF(refresh)
320 inline int UNDEF(redrawwin)(WINDOW *win) { return redrawwin(win); }
322 #define redrawwin UNDEF(redrawwin)
326 inline int UNDEF(scrl)(int l) { return scrl(l); }
328 #define scrl UNDEF(scrl)
332 inline int UNDEF(scroll)(WINDOW *win) { return scroll(win); }
334 #define scroll UNDEF(scroll)
338 inline int UNDEF(scrollok)(WINDOW* win, bool bf) { return scrollok(win, bf); }
340 #define scrollok UNDEF(scrollok)
342 #if defined(__NCURSES_H)
343 extern "C" int scrollok(WINDOW*, bool);
345 extern "C" int scrollok(WINDOW*, char);
350 inline int UNDEF(setscrreg)(int t, int b) { return setscrreg(t, b); }
352 #define setscrreg UNDEF(setscrreg)
356 inline int UNDEF(standend)() { return standend(); }
358 #define standend UNDEF(standend)
362 inline int UNDEF(standout)() { return standout(); }
364 #define standout UNDEF(standout)
368 inline WINDOW *UNDEF(subpad)(WINDOW *p, int l, int c, int y, int x)
369 { return derwin(p,l,c,y,x); }
371 #define subpad UNDEF(subpad)
375 inline void UNDEF(timeout)(int delay) { timeout(delay); }
377 #define timeout UNDEF(timeout)
381 inline int UNDEF(touchline)(WINDOW *win, int s, int c)
382 { return touchline(win,s,c); }
384 #define touchline UNDEF(touchline)
388 inline int UNDEF(touchwin)(WINDOW *win) { return touchwin(win); }
390 #define touchwin UNDEF(touchwin)
394 inline int UNDEF(untouchwin)(WINDOW *win) { return untouchwin(win); }
396 #define untouchwin UNDEF(untouchwin)
400 inline int UNDEF(vline)(chtype ch, int n) { return vline(ch, n); }
402 #define vline UNDEF(vline)
406 inline int UNDEF(waddstr)(WINDOW *win, char *str) { return waddstr(win, str); }
408 #define waddstr UNDEF(waddstr)
412 inline int UNDEF(waddchstr)(WINDOW *win, chtype *at) { return waddchstr(win, at); }
414 #define waddchstr UNDEF(waddchstr)
418 inline int UNDEF(wstandend)(WINDOW *win) { return wstandend(win); }
420 #define wstandend UNDEF(wstandend)
424 inline int UNDEF(wstandout)(WINDOW *win) { return wstandout(win); }
426 #define wstandout UNDEF(wstandout)
431 inline int UNDEF(wattroff)(WINDOW *win, int att) { return wattroff(win, att); }
433 #define wattroff UNDEF(wattroff)
437 inline int UNDEF(chgat)(int n,attr_t attr, short color, const void *opts) {
438 return chgat(n,attr,color,opts); }
440 #define chgat UNDEF(chgat)
444 inline int UNDEF(mvchgat)(int y, int x, int n,
445 attr_t attr, short color, const void *opts) {
446 return mvchgat(y,x,n,attr,color,opts); }
448 #define mvchgat UNDEF(mvchgat)
452 inline int UNDEF(mvwchgat)(WINDOW *win, int y, int x, int n,
453 attr_t attr, short color, const void *opts) {
454 return mvwchgat(win,y,x,n,attr,color,opts); }
456 #define mvwchgat UNDEF(mvwchgat)
460 inline int UNDEF(wattrset)(WINDOW *win, int att) { return wattrset(win, att); }
462 #define wattrset UNDEF(wattrset)
466 inline chtype UNDEF(winch)(const WINDOW* win) { return winch(win); }
468 #define winch UNDEF(winch)
472 inline int UNDEF(mvwaddch)(WINDOW *win, int y, int x, const chtype ch)
473 { return mvwaddch(win, y, x, ch); }
475 #define mvwaddch UNDEF(mvwaddch)
479 inline int UNDEF(mvwaddchnstr)(WINDOW *win, int y, int x, chtype *str, int n)
480 { return mvwaddchnstr(win, y, x, str, n); }
482 #define mvwaddchnstr UNDEF(mvwaddchnstr)
486 inline int UNDEF(mvwaddchstr)(WINDOW *win, int y, int x, chtype *str)
487 { return mvwaddchstr(win, y, x, str); }
489 #define mvwaddchstr UNDEF(mvwaddchstr)
493 inline int UNDEF(addnstr)(const char *str, int n)
494 { return addnstr((char*)str, n); }
496 #define addnstr UNDEF(addnstr)
500 inline int UNDEF(mvwaddnstr)(WINDOW *win, int y, int x, const char *str, int n)
501 { return mvwaddnstr(win, y, x, (char*)str, n); }
503 #define mvwaddnstr UNDEF(mvwaddnstr)
507 inline int UNDEF(mvwaddstr)(WINDOW *win, int y, int x, const char * str)
508 { return mvwaddstr(win, y, x, (char*)str); }
510 #define mvwaddstr UNDEF(mvwaddstr)
514 inline int UNDEF(mvwdelch)(WINDOW *win, int y, int x)
515 { return mvwdelch(win, y, x); }
517 #define mvwdelch UNDEF(mvwdelch)
521 inline int UNDEF(mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
523 #define mvwgetch UNDEF(mvwgetch)
527 inline int UNDEF(mvwgetstr)(WINDOW *win, int y, int x, char *str)
528 {return mvwgetstr(win,y,x, str);}
530 #define mvwgetstr UNDEF(mvwgetstr)
534 inline int UNDEF(mvwgetnstr)(WINDOW *win, int y, int x, char *str, int n)
535 {return mvwgetnstr(win,y,x, str,n);}
537 #define mvwgetnstr UNDEF(mvwgetnstr)
541 inline chtype UNDEF(mvwinch)(WINDOW *win, int y, int x) {
542 return mvwinch(win, y, x);}
544 #define mvwinch UNDEF(mvwinch)
548 inline int UNDEF(mvwinsch)(WINDOW *win, int y, int x, char c)
549 { return mvwinsch(win, y, x, c); }
551 #define mvwinsch UNDEF(mvwinsch)
555 inline int UNDEF(mvaddch)(int y, int x, chtype ch)
556 { return mvaddch(y, x, ch); }
558 #define mvaddch UNDEF(mvaddch)
562 inline int UNDEF(mvaddnstr)(int y, int x, const char *str, int n)
563 { return mvaddnstr(y, x, (char*)str, n); }
565 #define mvaddnstr UNDEF(mvaddnstr)
569 inline int UNDEF(mvaddstr)(int y, int x, const char * str)
570 { return mvaddstr(y, x, (char*)str); }
572 #define mvaddstr UNDEF(mvaddstr)
576 inline int UNDEF(mvdelch)(int y, int x) { return mvdelch(y, x);}
578 #define mvdelch UNDEF(mvdelch)
582 inline int UNDEF(mvgetch)(int y, int x) { return mvgetch(y, x);}
584 #define mvgetch UNDEF(mvgetch)
588 inline int UNDEF(mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
590 #define mvgetstr UNDEF(mvgetstr)
594 inline int UNDEF(mvgetnstr)(int y, int x, char *str, int n) {
595 return mvgetnstr(y, x, str,n);}
597 #define mvgetnstr UNDEF(mvgetnstr)
601 inline chtype UNDEF(mvinch)(int y, int x) { return mvinch(y, x);}
603 #define mvinch UNDEF(mvinch)
607 inline int UNDEF(mvinsch)(int y, int x, char c)
608 { return mvinsch(y, x, c); }
610 #define mvinsch UNDEF(mvinsch)
614 inline void UNDEF(napms)(unsigned long x) { napms(x); }
616 #define napms UNDEF(napms)
620 inline int UNDEF(fixterm)(void) { return fixterm(); }
622 #define fixterm UNDEF(fixterm)
626 inline int UNDEF(resetterm)(void) { return resetterm(); }
628 #define resetterm UNDEF(resetterm)
632 inline int UNDEF(saveterm)(void) { return saveterm(); }
634 #define saveterm UNDEF(saveterm)
638 inline int UNDEF(crmode)(void) { return crmode(); }
640 #define crmode UNDEF(crmode)
644 inline int UNDEF(nocrmode)(void) { return nocrmode(); }
646 #define nocrmode UNDEF(nocrmode)
650 inline chtype UNDEF(getbkgd)(const WINDOW *win) { return getbkgd(win); }
652 #define getbkgd UNDEF(getbkgd)
656 inline int UNDEF(bkgd)(chtype ch) { return bkgd(ch); }
658 #define bkgd UNDEF(bkgd)
662 inline void UNDEF(bkgdset)(chtype ch) { bkgdset(ch); }
664 #define bkgdset UNDEF(bkgdset)
669 * C++ class for windows.
676 friend class NCursesMenu;
677 friend class NCursesForm;
680 static bool b_initialized;
681 static void initialize();
682 static int ripoff_init(WINDOW *,int);
686 short getcolor(int getback) const;
688 static int setpalette(short fore, short back, short pair);
689 static int colorInitialized;
691 // This private constructor is only used during the initialization
692 // of windows generated by ripoffline() calls.
693 NCursesWindow(WINDOW* win, int cols);
696 void err_handler(const char *) const THROWS(NCursesException);
697 // Signal an error with the given message text.
699 static long count; // count of all active windows:
700 // We rely on the c++ promise that
701 // all otherwise uninitialized
702 // static class vars are set to 0
704 WINDOW* w; // the curses WINDOW
706 bool alloced; // TRUE if we own the WINDOW
708 NCursesWindow* par; // parent, if subwindow
709 NCursesWindow* subwins; // head of subwindows list
710 NCursesWindow* sib; // next subwindow of parent
712 void kill_subwindows(); // disable all subwindows
713 // Destroy all subwindows.
715 /* Only for use by derived classes. They are then in charge to
716 fill the member variables correctly. */
720 NCursesWindow(WINDOW* &window); // useful only for stdscr
722 NCursesWindow(int lines, // number of lines
723 int cols, // number of columns
724 int begin_y, // line origin
725 int begin_x); // col origin
727 NCursesWindow(NCursesWindow& par,// parent window
728 int lines, // number of lines
729 int cols, // number of columns
730 int begin_y, // absolute or relative
731 int begin_x, // origins:
732 char absrel = 'a');// if `a', by & bx are
733 // absolute screen pos, else if `r', they are relative to par origin
735 NCursesWindow(NCursesWindow& par,// parent window
737 // this is the very common case that we want to create the subwindow that
738 // is two lines and two columns smaller and begins at (1,1).
739 // We may automatically request the box around it.
741 virtual ~NCursesWindow();
743 NCursesWindow Clone();
744 // Make an exact copy of the window.
747 static void useColors(void);
748 // Call this routine very early if you want to have colors.
750 static int ripoffline(int ripoff_lines,
751 int (*init)(NCursesWindow& win));
752 // This function is used to generate a window of ripped-of lines.
753 // If the argument is positive, lines are removed from the top, if it
754 // is negative lines are removed from the bottom. This enhances the
755 // lowlevel ripoffline() function because it uses the internal
756 // implementation that allows to remove more than just a single line.
757 // This function must be called before any other ncurses function. The
758 // creation of the window is defered until ncurses gets initialized.
759 // The initialization function is then called.
761 // -------------------------------------------------------------------------
763 // -------------------------------------------------------------------------
764 int lines() const { return LINES; }
765 // Number of lines on terminal, *not* window
767 int cols() const { return COLS; }
768 // Number of cols on terminal, *not* window
770 int tabsize() const { return TABSIZE; }
771 // Size of a tab on terminal, *not* window
773 static int NumberOfColors();
774 // Number of available colors
776 int colors() const { return NumberOfColors(); }
777 // Number of available colors
779 // -------------------------------------------------------------------------
781 // -------------------------------------------------------------------------
782 int height() const { return maxy() + 1; }
783 // Number of lines in this window
785 int width() const { return maxx() + 1; }
786 // Number of columns in this window
788 int begx() const { return w->_begx; }
789 // Column of top left corner relative to stdscr
791 int begy() const { return w->_begy; }
792 // Line of top left corner relative to stdscr
794 int maxx() const { return w->_maxx; }
795 // Largest x coord in window
797 int maxy() const { return w->_maxy; }
798 // Largest y coord in window
800 short getcolor() const;
803 short foreground() const { return getcolor(0); }
804 // Actual foreground color
806 short background() const { return getcolor(1); }
807 // Actual background color
809 int setpalette(short fore, short back);
810 // Set color palette entry
812 int setcolor(short pair);
813 // Set actually used palette entry
815 // -------------------------------------------------------------------------
816 // window positioning
817 // -------------------------------------------------------------------------
818 virtual int mvwin(int begin_y, int begin_x) {
819 return ::mvwin(w,begin_y,begin_x); }
820 // Move window to new position with the new position as top left corner.
821 // This is virtual because it is redefined in NCursesPanel.
823 // -------------------------------------------------------------------------
824 // coordinate positioning
825 // -------------------------------------------------------------------------
826 int move(int y, int x) { return ::wmove(w, y, x); }
827 // Move cursor the this position
829 void getyx(int& y, int& x) const { ::getyx(w, y, x); }
830 // Get current position of the cursor
832 int mvcur(int oldrow, int oldcol, int newrow, int newcol) const {
833 return ::mvcur(oldrow, oldcol, newrow, newcol); }
834 // Perform lowlevel cursor motion that takes effect immediately.
836 // -------------------------------------------------------------------------
838 // -------------------------------------------------------------------------
839 int getch() { return ::wgetch(w); }
840 // Get a keystroke from the window.
842 int getch(int y, int x) { return ::mvwgetch(w,y,x); }
843 // Move cursor to position and get a keystroke from the window
845 int getstr(char* str, int n=-1) {
846 return ::wgetnstr(w, str,n); }
847 // Read a series of characters into str until a newline or carriage return
848 // is received. Read at most n characters. If n is negative, the limit is
851 int getstr(int y, int x, char* str, int n=-1) {
852 return ::mvwgetnstr(w,y,x,str,n); }
853 // Move the cursor to the requested position and then perform the getstr()
854 // as described above.
856 int instr(char *s, int n=-1) { return ::winnstr(w,s,n); }
857 // Get a string of characters from the window into the buffer s. Retrieve
858 // at most n characters, if n is negative retrieve all characters up to the
859 // end of the current line. Attributes are stripped from the characters.
861 int instr(int y, int x, char *s, int n=-1) {
862 return ::mvwinnstr(w,y,x,s,n); }
863 // Move the cursor to the requested position and then perform the instr()
864 // as described above.
866 int scanw(const char* fmt, ...)
867 // Perform a scanw function from the window. This only works if you're
868 // using the GNU C++ compiler.
870 __attribute__ ((format (scanf, 2, 3)));
875 int scanw(int y, int x, const char* fmt, ...)
876 // Move the cursor to the requested position and then perform a scanw
877 // from the window. This nly works if you're using the GNU C++ compiler.
879 __attribute__ ((format (scanf, 4, 5)));
884 // -------------------------------------------------------------------------
886 // -------------------------------------------------------------------------
887 int addch(const chtype ch) { return ::waddch(w, ch); }
888 // Put attributed character to the window.
890 int addch(int y, int x, const chtype ch) {
891 return ::mvwaddch(w,y,x,ch); }
892 // Move cursor to the requested position and then put attributed character
895 int echochar(const chtype ch) { return ::wechochar(w,ch); }
896 // Put attributed character to the window and refresh it immediately.
898 int addstr(const char* str, int n=-1) {
899 return ::waddnstr(w, (char*)str,n); }
900 // Write the string str to the window, stop writing if the terminating
901 // NUL or the limit n is reached. If n is negative, it is ignored.
903 int addstr(int y, int x, const char * str, int n=-1) {
904 return ::mvwaddnstr(w,y,x,(char*)str,n); }
905 // Move the cursor to the requested position and then perform the addstr
906 // as described above.
908 int printw(const char* fmt, ...)
909 // Do a formatted print to the window.
911 __attribute__ ((format (printf, 2, 3)));
916 int printw(int y, int x, const char * fmt, ...)
917 // Move the cursor and then do a formatted print to the window.
919 __attribute__ ((format (printf, 4, 5)));
924 chtype inch() const { return ::winch(w); }
925 // Retrieve attributed character under the current cursor position.
927 chtype inch(int y, int x) { return ::mvwinch(w,y,x); }
928 // Move cursor to requested position and then retrieve attributed character
931 int insch(chtype ch) { return ::winsch(w, ch); }
932 // Insert attributed character into the window before current cursor
935 int insch(int y, int x, chtype ch) {
936 return ::mvwinsch(w,y,x,(char)ch); }
937 // Move cursor to requested position and then insert the attributed
938 // character before that position.
940 int insertln() { return ::winsdelln(w,1); }
941 // Insert an empty line above the current line.
943 int insdelln(int n=1) { return ::winsdelln(w,n); }
944 // If n>0 insert that many lines above the current line. If n<0 delete
945 // that many lines beginning with the current line.
947 int insstr(const char *s, int n=-1) {
948 return ::winsnstr(w,s,n); }
949 // Insert the string into the window before the current cursor position.
950 // Insert stops at end of string or when the limit n is reached. If n is
951 // negative, it is ignored.
953 int insstr(int y, int x, const char *s, int n=-1) {
954 return ::mvwinsnstr(w,y,x,s,n); }
955 // Move the cursor to the requested position and then perform the insstr()
956 // as described above.
958 int attron (chtype at) { return ::wattron (w, at); }
959 // Switch on the window attributes;
961 int attroff(chtype at) { return ::wattroff(w, (int) at); }
962 // Switch off the window attributes;
964 int attrset(chtype at) { return ::wattrset(w, (int) at); }
965 // Set the window attributes;
967 int color_set(short color_pair_number, void* opts=NULL) {
968 return ::wcolor_set(w, color_pair_number, opts); }
969 // Set the window color attribute;
971 int chgat(int n,attr_t attr, short color, const void *opts=NULL) {
972 return ::wchgat(w,n,attr,color,opts); }
973 // Change the attributes of the next n characters in the current line. If
974 // n is negative or greater than the number of remaining characters in the
975 // line, the attributes will be changed up to the end of the line.
977 int chgat(int y, int x,
978 int n,attr_t attr, short color, const void *opts=NULL) {
979 return ::mvwchgat(w,y,x,n,attr,color,opts); }
980 // Move the cursor to the requested position and then perform chgat() as
983 // -------------------------------------------------------------------------
985 // -------------------------------------------------------------------------
986 chtype getbkgd() const { return ::getbkgd(w); }
987 // Get current background setting.
989 int bkgd(const chtype ch) { return ::wbkgd(w,ch); }
990 // Set the background property and apply it to the window.
992 void bkgdset(chtype ch) { ::wbkgdset(w,ch); }
993 // Set the background property.
995 // -------------------------------------------------------------------------
997 // -------------------------------------------------------------------------
998 int box(chtype vert=0, chtype hor=0) {
999 return ::wborder(w, vert, vert, hor, hor, 0, 0 ,0, 0); }
1000 // Draw a box around the window with the given vertical and horizontal
1001 // drawing characters. If you specifiy a zero as character, curses will try
1002 // to find a "nice" character.
1004 int border(chtype left=0, chtype right=0,
1005 chtype top =0, chtype bottom=0,
1006 chtype top_left =0, chtype top_right=0,
1007 chtype bottom_left =0, chtype bottom_right=0) {
1008 return ::wborder(w,left,right,top,bottom,top_left,top_right,
1009 bottom_left,bottom_right); }
1010 // Draw a border around the window with the given characters for the
1011 // various parts of the border. If you pass zero for a character, curses
1012 // will try to find "nice" characters.
1014 // -------------------------------------------------------------------------
1016 // -------------------------------------------------------------------------
1017 int hline(int len, chtype ch=0) { return ::whline(w, ch, len); }
1018 // Draw a horizontal line of len characters with the given character. If
1019 // you pass zero for the character, curses will try to find a "nice" one.
1021 int hline(int y, int x, int len, chtype ch=0) {
1022 return ::mvwhline(w,y,x,ch,len); }
1023 // Move the cursor to the requested position and then draw a horizontal line.
1025 int vline(int len, chtype ch=0) { return ::wvline(w, ch, len); }
1026 // Draw a vertical line of len characters with the given character. If
1027 // you pass zero for the character, curses will try to find a "nice" one.
1029 int vline(int y, int x, int len, chtype ch=0) {
1030 return ::mvwvline(w,y,x,ch,len); }
1031 // Move the cursor to the requested position and then draw a vertical line.
1033 // -------------------------------------------------------------------------
1035 // -------------------------------------------------------------------------
1036 int erase() { return ::werase(w); }
1037 // Erase the window.
1039 int clear() { return ::wclear(w); }
1040 // Clear the window.
1042 int clearok(bool bf) { return ::clearok(w, bf); }
1043 // Set/Reset the clear flag. If set, the next refresh() will clear the
1046 int clrtobot() { return ::wclrtobot(w); }
1047 // Clear to the end of the window.
1049 int clrtoeol() { return ::wclrtoeol(w); }
1050 // Clear to the end of the line.
1052 int delch() { return ::wdelch(w); }
1053 // Delete character under the cursor.
1055 int delch(int y, int x) { return ::mvwdelch(w,y,x); }
1056 // Move cursor to requested position and delete the character under the
1059 int deleteln() { return ::winsdelln(w,-1); }
1060 // Delete the current line.
1062 // -------------------------------------------------------------------------
1064 // -------------------------------------------------------------------------
1065 int scroll(int amount=1) { return ::wscrl(w,amount); }
1066 // Scroll amount lines. If amount is positive, scroll up, otherwise
1069 int scrollok(bool bf) { return ::scrollok(w, bf); }
1070 // If bf is TRUE, window scrolls if cursor is moved off the bottom
1071 // edge of the window or a scrolling region, otherwise the cursor is left
1072 // at the bottom line.
1074 int setscrreg(int from, int to) {
1075 return ::wsetscrreg(w,from,to); }
1076 // Define a soft scrolling region.
1078 int idlok(bool bf) { return ::idlok(w, bf); }
1079 // If bf is TRUE, use insert/delete line hardware support if possible.
1080 // Otherwise do it in software.
1083 void idcok(bool bf) { ::idcok(w, bf); }
1084 // If bf is TRUE, use insert/delete character hardware support if possible.
1085 // Otherwise do it in software.
1087 int touchwin() { return ::wtouchln(w,0,height(),1); }
1088 // Mark the whole window as modified.
1090 int untouchwin() { return ::wtouchln(w,0,height(),0); }
1091 // Mark the whole window as unmodified.
1093 int touchln(int s, int cnt, bool changed=TRUE) {
1094 return ::wtouchln(w,s,cnt,(int)(changed?1:0)); }
1095 // Mark cnt lines beginning from line s as changed or unchanged, depending
1096 // on the value of the changed flag.
1098 bool is_linetouched(int line) const {
1099 return (::is_linetouched(w,line) ? TRUE:FALSE); }
1100 // Return TRUE if line is marked as changed, FALSE otherwise
1102 bool is_wintouched() const {
1103 return (::is_wintouched(w) ? TRUE:FALSE); }
1104 // Return TRUE if window is marked as changed, FALSE otherwise
1106 int leaveok(bool bf) { return ::leaveok(w, bf); }
1107 // If bf is TRUE, curses will leave the cursor after an update whereever
1108 // it is after the update.
1110 int redrawln(int from, int n) { return ::wredrawln(w,from,n); }
1111 // Redraw n lines starting from the requested line
1113 int redrawwin() { return ::wredrawln(w,0,height()); }
1114 // Redraw the whole window
1116 int doupdate() { return ::doupdate(); }
1117 // Do all outputs to make the physical screen looking like the virtual one
1119 void syncdown() { ::wsyncdown(w); }
1120 // Propagate the changes down to all descendant windows
1122 void syncup() { ::wsyncup(w); }
1123 // Propagate the changes up in the hierarchy
1125 void cursyncup() { ::wcursyncup(w); }
1126 // Position the cursor in all ancestor windows corresponding to our setting
1128 int syncok(bool bf) { return ::syncok(w,bf); }
1129 // If called with bf=TRUE, syncup() is called whenever the window is changed
1132 int flushok(bool bf) { return ::flushok(w, bf); }
1135 void immedok(bool bf) { ::immedok(w,bf); }
1136 // If called with bf=TRUE, any change in the window will cause an
1137 // automatic immediate refresh()
1139 int keypad(bool bf) { return ::keypad(w, bf); }
1140 // If called with bf=TRUE, the application will interpret function keys.
1142 int meta(bool bf) { return ::meta(w,bf); }
1143 // If called with bf=TRUE, keys may generate 8-Bit characters. Otherwise
1144 // 7-Bit characters are generated.
1146 int standout() { return ::wstandout(w); }
1147 // Enable "standout" attributes
1149 int standend() { return ::wstandend(w); }
1150 // Disable "standout" attributes
1152 // -------------------------------------------------------------------------
1153 // The next two are virtual, because we redefine them in the
1154 // NCursesPanel class.
1155 // -------------------------------------------------------------------------
1156 virtual int refresh() { return ::wrefresh(w); }
1157 // Propagate the changes in this window to the virtual screen and call
1158 // doupdate(). This is redefined in NCursesPanel.
1160 virtual int noutrefresh() { return ::wnoutrefresh(w); }
1161 // Propagate the changes in this window to the virtual screen. This is
1162 // redefined in NCursesPanel.
1164 // -------------------------------------------------------------------------
1165 // multiple window control
1166 // -------------------------------------------------------------------------
1167 int overlay(NCursesWindow& win) {
1168 return ::overlay(w, win.w); }
1169 // Overlay this window over win.
1171 int overwrite(NCursesWindow& win) {
1172 return ::overwrite(w, win.w); }
1173 // Overwrite win with this window.
1175 int copywin(NCursesWindow& win,
1176 int sminrow, int smincol,
1177 int dminrow, int dmincol,
1178 int dmaxrow, int dmaxcol, bool overlay=TRUE) {
1179 return ::copywin(w,win.w,sminrow,smincol,dminrow,dmincol,
1180 dmaxrow,dmaxcol,(int)(overlay?1:0)); }
1181 // Overlay or overwrite the rectangle in win given by dminrow,dmincol,
1182 // dmaxrow,dmaxcol with the rectangle in this window beginning at
1185 // -------------------------------------------------------------------------
1187 // -------------------------------------------------------------------------
1188 bool has_mouse() const;
1189 // Return TRUE if terminal supports a mouse, FALSE otherwise
1191 // -------------------------------------------------------------------------
1192 // traversal support
1193 // -------------------------------------------------------------------------
1194 NCursesWindow* child() { return subwins; }
1195 // Get the first child window.
1197 NCursesWindow* sibling() { return sib; }
1198 // Get the next child of my parent.
1200 NCursesWindow* parent() { return par; }
1203 bool isDescendant(NCursesWindow& win);
1204 // Return TRUE if win is a descendant of this.
1207 // -------------------------------------------------------------------------
1208 // We leave this here for compatibility reasons.
1209 // -------------------------------------------------------------------------
1210 class NCursesColorWindow : public NCursesWindow {
1212 NCursesColorWindow(WINDOW* &window) // useful only for stdscr
1213 : NCursesWindow(window) {
1216 NCursesColorWindow(int lines, // number of lines
1217 int cols, // number of columns
1218 int begin_y, // line origin
1219 int begin_x) // col origin
1220 : NCursesWindow(lines,cols,begin_y,begin_x) {
1223 NCursesColorWindow(NCursesWindow& par,// parent window
1224 int lines, // number of lines
1225 int cols, // number of columns
1226 int begin_y, // absolute or relative
1227 int begin_x, // origins:
1228 char absrel = 'a') // if `a', by & bx are
1229 : NCursesWindow(par,lines,cols, // absolute screen pos,
1230 begin_y,begin_x, // else if `r', they are
1231 absrel ) { // relative to par origin
1235 // These enum definitions really belong inside the NCursesPad class, but only
1236 // recent compilers support that feature.
1239 REQ_PAD_REFRESH = KEY_MAX + 1,
1247 const Pad_Request PAD_LOW = REQ_PAD_REFRESH; // lowest op-code
1248 const Pad_Request PAD_HIGH = REQ_PAD_EXIT; // highest op-code
1250 // -------------------------------------------------------------------------
1251 // Pad Support. We allow an association of a pad with a "real" window
1252 // through which the pad may be viewed.
1253 // -------------------------------------------------------------------------
1254 class NCursesPad : public NCursesWindow {
1256 NCursesWindow* viewWin; // the "viewport" window
1257 NCursesWindow* viewSub; // the "viewport" subwindow
1259 int h_gridsize, v_gridsize;
1262 int min_row, min_col; // top left row/col of the pads display area
1264 NCursesWindow* Win(void) const {
1265 // Get the window into which the pad should be copied (if any)
1266 return (viewSub?viewSub:(viewWin?viewWin:0));
1269 NCursesWindow* getWindow(void) const {
1273 NCursesWindow* getSubWindow(void) const {
1277 virtual int driver (int key); // Virtualize keystroke key
1278 // The driver translates the keystroke c into an Pad_Request
1280 virtual void OnUnknownOperation(int pad_req) {
1283 // This is called if the driver returns an unknown op-code
1285 virtual void OnNavigationError(int pad_req) {
1288 // This is called if a navigation request couldn't be satisfied
1290 virtual void OnOperation(int pad_req) {
1292 // OnOperation is called if a Pad_Operation was executed and just before
1293 // the refresh() operation is done.
1296 NCursesPad(int lines, int cols);
1297 // create a pad with the given size
1299 virtual ~NCursesPad() {}
1301 int echochar(const chtype ch) { return ::pechochar(w,ch); }
1302 // Put the attributed character onto the pad and immediately do a
1306 // If a viewport is defined the pad is displayed in this window, otherwise
1309 int refresh(int pminrow, int pmincol,
1310 int sminrow, int smincol,
1311 int smaxrow, int smaxcol) {
1312 return ::prefresh(w,pminrow,pmincol,
1313 sminrow,smincol,smaxrow,smaxcol);
1315 // The coordinates sminrow,smincol,smaxrow,smaxcol describe a rectangle
1316 // on the screen. <b>refresh</b> copies a rectangle of this size beginning
1317 // with top left corner pminrow,pmincol onto the screen and calls doupdate().
1320 // If a viewport is defined the pad is displayed in this window, otherwise
1323 int noutrefresh(int pminrow, int pmincol,
1324 int sminrow, int smincol,
1325 int smaxrow, int smaxcol) {
1326 return ::pnoutrefresh(w,pminrow,pmincol,
1327 sminrow,smincol,smaxrow,smaxcol);
1329 // Does the same like refresh() but without calling doupdate().
1331 virtual void setWindow(NCursesWindow& view, int v_grid = 1, int h_grid = 1);
1332 // Add the window "view" as viewing window to the pad.
1334 virtual void setSubWindow(NCursesWindow& sub);
1335 // Use the subwindow "sub" of the viewport window for the actual viewing.
1336 // The full viewport window is usually used to provide some decorations
1337 // like frames, titles etc.
1339 virtual void operator() (void);
1340 // Perform Pad's operation
1343 // A FramedPad is constructed always with a viewport window. This viewport
1344 // will be framed (by a box() command) and the interior of the box is the
1345 // viewport subwindow. On the frame we display scrollbar sliders.
1346 class NCursesFramedPad : public NCursesPad {
1348 virtual void OnOperation(int pad_req);
1351 NCursesFramedPad(NCursesWindow& win, int lines, int cols,
1352 int v_grid = 1, int h_grid = 1)
1353 : NCursesPad(lines,cols) {
1354 NCursesPad::setWindow(win,v_grid,h_grid);
1355 NCursesPad::setSubWindow(*(new NCursesWindow(win)));
1357 // Construct the FramedPad with the given Window win as viewport.
1359 virtual ~NCursesFramedPad() {
1360 delete getSubWindow();
1363 void setWindow(NCursesWindow& view, int v_grid = 1, int h_grid = 1) {
1364 err_handler("Operation not allowed");
1366 // Disable this call; the viewport is already defined
1368 void setSubWindow(NCursesWindow& sub) {
1369 err_handler("Operation not allowed");
1371 // Disable this call; the viewport subwindow is already defined
1375 #endif // _CURSESW_H