1 // * This makes emacs happy -*-Mode: C++;-*-
2 /****************************************************************************
3 * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 #ifndef NCURSES_CURSESW_H_incl
31 #define NCURSES_CURSESW_H_incl 1
33 // $Id: cursesw.h,v 1.28 2001/07/15 01:17:56 tom Exp $
39 #if HAVE_STRSTREAM_H && (USE_STRSTREAM_VSCAN||USE_STRSTREAM_VSCAN_CAST)
40 #include <strstream.h>
47 /* SCO 3.2v4 curses.h includes term.h, which defines lines as a macro.
48 Undefine it here, because NCursesWindow uses lines as a method. */
51 /* "Convert" macros to inlines. We'll define it as another symbol to avoid
52 * conflict with library symbols.
55 #define UNDEF(name) CUR_ ##name
58 inline int UNDEF(addch)(chtype ch) { return addch(ch); }
60 #define addch UNDEF(addch)
64 inline int UNDEF(echochar)(chtype ch) { return echochar(ch); }
66 #define echochar UNDEF(echochar)
70 inline int UNDEF(insdelln)(int n) { return insdelln(n); }
72 #define insdelln UNDEF(insdelln)
76 /* The (char*) cast is to hack around missing const's */
77 inline int UNDEF(addstr)(const char * str) { return addstr((char*)str); }
79 #define addstr UNDEF(addstr)
83 inline int UNDEF(attron)(chtype at) { return attron(at); }
85 #define attron UNDEF(attron)
89 inline int UNDEF(attroff)(chtype at) { return attroff(at); }
91 #define attroff UNDEF(attroff)
95 inline chtype UNDEF(attrset)(chtype at) { return attrset(at); }
97 #define attrset UNDEF(attrset)
101 inline chtype UNDEF(color_set)(short p,void* opts) { return color_set(p,opts); }
103 #define color_set UNDEF(color_set)
107 inline int UNDEF(border)(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, chtype tr, chtype bl, chtype br)
108 { return border(ls,rs,ts,bs,tl,tr,bl,br); }
110 #define border UNDEF(border)
114 inline int UNDEF(box)(WINDOW *win, int v, int h) { return box(win, v, h); }
116 #define box UNDEF(box)
120 inline int UNDEF(mvwhline)(WINDOW *win,int y,int x,chtype c,int n) {
121 return mvwhline(win,y,x,c,n); }
123 #define mvwhline UNDEF(mvwhline)
127 inline int UNDEF(mvwvline)(WINDOW *win,int y,int x,chtype c,int n) {
128 return mvwvline(win,y,x,c,n); }
130 #define mvwvline UNDEF(mvwvline)
134 inline int UNDEF(clear)() { return clear(); }
136 #define clear UNDEF(clear)
140 inline int UNDEF(clearok)(WINDOW* win, bool bf) { return clearok(win, bf); }
142 #define clearok UNDEF(clearok)
144 extern "C" NCURSES_IMPEXP int NCURSES_API clearok(WINDOW*, bool);
148 inline int UNDEF(clrtobot)() { return clrtobot(); }
150 #define clrtobot UNDEF(clrtobot)
154 inline int UNDEF(clrtoeol)() { return clrtoeol(); }
156 #define clrtoeol UNDEF(clrtoeol)
160 inline int UNDEF(delch)() { return delch(); }
162 #define delch UNDEF(delch)
166 inline int UNDEF(deleteln)() { return deleteln(); }
168 #define deleteln UNDEF(deleteln)
172 inline int UNDEF(erase)() { return erase(); }
174 #define erase UNDEF(erase)
178 inline int UNDEF(flushok)(WINDOW* _win, bool _bf) {
179 return flushok(_win, _bf); }
181 #define flushok UNDEF(flushok)
187 inline int UNDEF(getch)() { return getch(); }
189 #define getch UNDEF(getch)
193 inline int UNDEF(getstr)(char *_str) { return getstr(_str); }
195 #define getstr UNDEF(getstr)
199 inline int UNDEF(instr)(char *_str) { return instr(_str); }
201 #define instr UNDEF(instr)
205 inline int UNDEF(innstr)(char *_str, int n) { return innstr(_str,n); }
207 #define innstr UNDEF(innstr)
211 inline int UNDEF(mvwinnstr)(WINDOW *win, int y, int x, char *_str, int n) {
212 return mvwinnstr(win,y,x,_str,n); }
214 #define mvwinnstr UNDEF(mvwinnstr)
218 inline int UNDEF(mvinnstr)(int y, int x, char *_str, int n) {
219 return mvinnstr(y,x,_str,n); }
221 #define mvinnstr UNDEF(mvinnstr)
225 inline int UNDEF(winsstr)(WINDOW *w, const char *_str) {
226 return winsstr(w,_str); }
228 #define winsstr UNDEF(winsstr)
232 inline int UNDEF(mvwinsstr)(WINDOW *w, int y, int x, const char *_str) {
233 return mvwinsstr(w,y,x,_str); }
235 #define mvwinsstr UNDEF(mvwinsstr)
239 inline int UNDEF(insstr)(const char *_str) {
240 return insstr(_str); }
242 #define insstr UNDEF(insstr)
246 inline int UNDEF(mvinsstr)(int y, int x,const char *_str) {
247 return mvinsstr(y,x,_str); }
249 #define mvinsstr UNDEF(mvinsstr)
253 inline int UNDEF(insnstr)(const char *_str, int n) {
254 return insnstr(_str,n); }
256 #define insnstr UNDEF(insnstr)
260 inline int UNDEF(mvwinsnstr)(WINDOW *w, int y, int x,const char *_str, int n) {
261 return mvwinsnstr(w,y,x,_str,n); }
263 #define mvwinsnstr UNDEF(mvwinsnstr)
267 inline int UNDEF(mvinsnstr)(int y, int x,const char *_str, int n) {
268 return mvinsnstr(y,x,_str,n); }
270 #define mvinsnstr UNDEF(mvinsnstr)
274 inline int UNDEF(getnstr)(char *_str, int n) { return getnstr(_str,n); }
276 #define getnstr UNDEF(getnstr)
280 inline void UNDEF(getyx)(const WINDOW* win, int& y, int& x) {
283 #define getyx UNDEF(getyx)
287 inline void UNDEF(getbegyx)(WINDOW* win, int& y, int& x) { getbegyx(win, y, x); }
289 #define getbegyx UNDEF(getbegyx)
293 inline void UNDEF(getmaxyx)(WINDOW* win, int& y, int& x) { getmaxyx(win, y, x); }
295 #define getmaxyx UNDEF(getmaxyx)
299 inline int UNDEF(hline)(chtype ch, int n) { return hline(ch, n); }
301 #define hline UNDEF(hline)
305 inline chtype UNDEF(inch)() { return inch(); }
307 #define inch UNDEF(inch)
311 inline int UNDEF(insch)(char c) { return insch(c); }
313 #define insch UNDEF(insch)
317 inline int UNDEF(insertln)() { return insertln(); }
319 #define insertln UNDEF(insertln)
323 inline int UNDEF(leaveok)(WINDOW* win, bool bf) { return leaveok(win, bf); }
325 #define leaveok UNDEF(leaveok)
327 extern "C" NCURSES_IMPEXP int NCURSES_API leaveok(WINDOW* win, bool bf);
331 inline int UNDEF(move)(int x, int y) { return move(x, y); }
333 #define move UNDEF(move)
337 inline int UNDEF(refresh)() { return refresh(); }
339 #define refresh UNDEF(refresh)
343 inline int UNDEF(redrawwin)(WINDOW *win) { return redrawwin(win); }
345 #define redrawwin UNDEF(redrawwin)
349 inline int UNDEF(scrl)(int l) { return scrl(l); }
351 #define scrl UNDEF(scrl)
355 inline int UNDEF(scroll)(WINDOW *win) { return scroll(win); }
357 #define scroll UNDEF(scroll)
361 inline int UNDEF(scrollok)(WINDOW* win, bool bf) { return scrollok(win, bf); }
363 #define scrollok UNDEF(scrollok)
365 #if defined(__NCURSES_H)
366 extern "C" NCURSES_IMPEXP int NCURSES_API scrollok(WINDOW*, bool);
368 extern "C" NCURSES_IMPEXP int NCURSES_API scrollok(WINDOW*, char);
373 inline int UNDEF(setscrreg)(int t, int b) { return setscrreg(t, b); }
375 #define setscrreg UNDEF(setscrreg)
379 inline int UNDEF(standend)() { return standend(); }
381 #define standend UNDEF(standend)
385 inline int UNDEF(standout)() { return standout(); }
387 #define standout UNDEF(standout)
391 inline WINDOW *UNDEF(subpad)(WINDOW *p, int l, int c, int y, int x)
392 { return derwin(p,l,c,y,x); }
394 #define subpad UNDEF(subpad)
398 inline void UNDEF(timeout)(int delay) { timeout(delay); }
400 #define timeout UNDEF(timeout)
404 inline int UNDEF(touchline)(WINDOW *win, int s, int c)
405 { return touchline(win,s,c); }
407 #define touchline UNDEF(touchline)
411 inline int UNDEF(touchwin)(WINDOW *win) { return touchwin(win); }
413 #define touchwin UNDEF(touchwin)
417 inline int UNDEF(untouchwin)(WINDOW *win) { return untouchwin(win); }
419 #define untouchwin UNDEF(untouchwin)
423 inline int UNDEF(vline)(chtype ch, int n) { return vline(ch, n); }
425 #define vline UNDEF(vline)
429 inline int UNDEF(waddstr)(WINDOW *win, char *str) { return waddstr(win, str); }
431 #define waddstr UNDEF(waddstr)
435 inline int UNDEF(waddchstr)(WINDOW *win, chtype *at) { return waddchstr(win, at); }
437 #define waddchstr UNDEF(waddchstr)
441 inline int UNDEF(wstandend)(WINDOW *win) { return wstandend(win); }
443 #define wstandend UNDEF(wstandend)
447 inline int UNDEF(wstandout)(WINDOW *win) { return wstandout(win); }
449 #define wstandout UNDEF(wstandout)
454 inline int UNDEF(wattroff)(WINDOW *win, int att) { return wattroff(win, att); }
456 #define wattroff UNDEF(wattroff)
460 inline int UNDEF(chgat)(int n,attr_t attr, short color, const void *opts) {
461 return chgat(n,attr,color,opts); }
463 #define chgat UNDEF(chgat)
467 inline int UNDEF(mvchgat)(int y, int x, int n,
468 attr_t attr, short color, const void *opts) {
469 return mvchgat(y,x,n,attr,color,opts); }
471 #define mvchgat UNDEF(mvchgat)
475 inline int UNDEF(mvwchgat)(WINDOW *win, int y, int x, int n,
476 attr_t attr, short color, const void *opts) {
477 return mvwchgat(win,y,x,n,attr,color,opts); }
479 #define mvwchgat UNDEF(mvwchgat)
483 inline int UNDEF(wattrset)(WINDOW *win, int att) { return wattrset(win, att); }
485 #define wattrset UNDEF(wattrset)
489 inline chtype UNDEF(winch)(const WINDOW* win) { return winch(win); }
491 #define winch UNDEF(winch)
495 inline int UNDEF(mvwaddch)(WINDOW *win, int y, int x, const chtype ch)
496 { return mvwaddch(win, y, x, ch); }
498 #define mvwaddch UNDEF(mvwaddch)
502 inline int UNDEF(mvwaddchnstr)(WINDOW *win, int y, int x, chtype *str, int n)
503 { return mvwaddchnstr(win, y, x, str, n); }
505 #define mvwaddchnstr UNDEF(mvwaddchnstr)
509 inline int UNDEF(mvwaddchstr)(WINDOW *win, int y, int x, chtype *str)
510 { return mvwaddchstr(win, y, x, str); }
512 #define mvwaddchstr UNDEF(mvwaddchstr)
516 inline int UNDEF(addnstr)(const char *str, int n)
517 { return addnstr((char*)str, n); }
519 #define addnstr UNDEF(addnstr)
523 inline int UNDEF(mvwaddnstr)(WINDOW *win, int y, int x, const char *str, int n)
524 { return mvwaddnstr(win, y, x, (char*)str, n); }
526 #define mvwaddnstr UNDEF(mvwaddnstr)
530 inline int UNDEF(mvwaddstr)(WINDOW *win, int y, int x, const char * str)
531 { return mvwaddstr(win, y, x, (char*)str); }
533 #define mvwaddstr UNDEF(mvwaddstr)
537 inline int UNDEF(mvwdelch)(WINDOW *win, int y, int x)
538 { return mvwdelch(win, y, x); }
540 #define mvwdelch UNDEF(mvwdelch)
544 inline int UNDEF(mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
546 #define mvwgetch UNDEF(mvwgetch)
550 inline int UNDEF(mvwgetstr)(WINDOW *win, int y, int x, char *str)
551 {return mvwgetstr(win,y,x, str);}
553 #define mvwgetstr UNDEF(mvwgetstr)
557 inline int UNDEF(mvwgetnstr)(WINDOW *win, int y, int x, char *str, int n)
558 {return mvwgetnstr(win,y,x, str,n);}
560 #define mvwgetnstr UNDEF(mvwgetnstr)
564 inline chtype UNDEF(mvwinch)(WINDOW *win, int y, int x) {
565 return mvwinch(win, y, x);}
567 #define mvwinch UNDEF(mvwinch)
571 inline int UNDEF(mvwinsch)(WINDOW *win, int y, int x, char c)
572 { return mvwinsch(win, y, x, c); }
574 #define mvwinsch UNDEF(mvwinsch)
578 inline int UNDEF(mvaddch)(int y, int x, chtype ch)
579 { return mvaddch(y, x, ch); }
581 #define mvaddch UNDEF(mvaddch)
585 inline int UNDEF(mvaddnstr)(int y, int x, const char *str, int n)
586 { return mvaddnstr(y, x, (char*)str, n); }
588 #define mvaddnstr UNDEF(mvaddnstr)
592 inline int UNDEF(mvaddstr)(int y, int x, const char * str)
593 { return mvaddstr(y, x, (char*)str); }
595 #define mvaddstr UNDEF(mvaddstr)
599 inline int UNDEF(mvdelch)(int y, int x) { return mvdelch(y, x);}
601 #define mvdelch UNDEF(mvdelch)
605 inline int UNDEF(mvgetch)(int y, int x) { return mvgetch(y, x);}
607 #define mvgetch UNDEF(mvgetch)
611 inline int UNDEF(mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
613 #define mvgetstr UNDEF(mvgetstr)
617 inline int UNDEF(mvgetnstr)(int y, int x, char *str, int n) {
618 return mvgetnstr(y, x, str,n);}
620 #define mvgetnstr UNDEF(mvgetnstr)
624 inline chtype UNDEF(mvinch)(int y, int x) { return mvinch(y, x);}
626 #define mvinch UNDEF(mvinch)
630 inline int UNDEF(mvinsch)(int y, int x, char c)
631 { return mvinsch(y, x, c); }
633 #define mvinsch UNDEF(mvinsch)
637 inline void UNDEF(napms)(unsigned long x) { napms(x); }
639 #define napms UNDEF(napms)
643 inline int UNDEF(fixterm)(void) { return fixterm(); }
645 #define fixterm UNDEF(fixterm)
649 inline int UNDEF(resetterm)(void) { return resetterm(); }
651 #define resetterm UNDEF(resetterm)
655 inline int UNDEF(saveterm)(void) { return saveterm(); }
657 #define saveterm UNDEF(saveterm)
661 inline int UNDEF(crmode)(void) { return crmode(); }
663 #define crmode UNDEF(crmode)
667 inline int UNDEF(nocrmode)(void) { return nocrmode(); }
669 #define nocrmode UNDEF(nocrmode)
673 inline chtype UNDEF(getbkgd)(const WINDOW *win) { return getbkgd(win); }
675 #define getbkgd UNDEF(getbkgd)
679 inline int UNDEF(bkgd)(chtype ch) { return bkgd(ch); }
681 #define bkgd UNDEF(bkgd)
685 inline void UNDEF(bkgdset)(chtype ch) { bkgdset(ch); }
687 #define bkgdset UNDEF(bkgdset)
692 * C++ class for windows.
697 class NCURSES_IMPEXP NCursesWindow
699 friend class NCursesMenu;
700 friend class NCursesForm;
703 static bool b_initialized;
704 static void initialize();
705 static int ripoff_init(WINDOW *,int);
709 short getcolor(int getback) const;
711 static int setpalette(short fore, short back, short pair);
712 static int colorInitialized;
714 // This private constructor is only used during the initialization
715 // of windows generated by ripoffline() calls.
716 NCursesWindow(WINDOW* win, int cols);
719 void err_handler(const char *) const THROWS(NCursesException);
720 // Signal an error with the given message text.
722 static long count; // count of all active windows:
723 // We rely on the c++ promise that
724 // all otherwise uninitialized
725 // static class vars are set to 0
727 WINDOW* w; // the curses WINDOW
729 bool alloced; // TRUE if we own the WINDOW
731 NCursesWindow* par; // parent, if subwindow
732 NCursesWindow* subwins; // head of subwindows list
733 NCursesWindow* sib; // next subwindow of parent
735 void kill_subwindows(); // disable all subwindows
736 // Destroy all subwindows.
738 /* Only for use by derived classes. They are then in charge to
739 fill the member variables correctly. */
743 NCursesWindow(WINDOW* &window); // useful only for stdscr
745 NCursesWindow(int lines, // number of lines
746 int cols, // number of columns
747 int begin_y, // line origin
748 int begin_x); // col origin
750 NCursesWindow(NCursesWindow& par,// parent window
751 int lines, // number of lines
752 int cols, // number of columns
753 int begin_y, // absolute or relative
754 int begin_x, // origins:
755 char absrel = 'a');// if `a', begin_y & begin_x are
756 // absolute screen pos, else if `r', they are relative to par origin
758 NCursesWindow(NCursesWindow& par,// parent window
760 // this is the very common case that we want to create the subwindow that
761 // is two lines and two columns smaller and begins at (1,1).
762 // We may automatically request the box around it.
764 virtual ~NCursesWindow();
766 NCursesWindow Clone();
767 // Make an exact copy of the window.
770 static void useColors(void);
771 // Call this routine very early if you want to have colors.
773 static int ripoffline(int ripoff_lines,
774 int (*init)(NCursesWindow& win));
775 // This function is used to generate a window of ripped-of lines.
776 // If the argument is positive, lines are removed from the top, if it
777 // is negative lines are removed from the bottom. This enhances the
778 // lowlevel ripoffline() function because it uses the internal
779 // implementation that allows to remove more than just a single line.
780 // This function must be called before any other ncurses function. The
781 // creation of the window is deferred until ncurses gets initialized.
782 // The initialization function is then called.
784 // -------------------------------------------------------------------------
786 // -------------------------------------------------------------------------
787 int lines() const { initialize(); return LINES; }
788 // Number of lines on terminal, *not* window
790 int cols() const { initialize(); return COLS; }
791 // Number of cols on terminal, *not* window
793 int tabsize() const { initialize(); return TABSIZE; }
794 // Size of a tab on terminal, *not* window
796 static int NumberOfColors();
797 // Number of available colors
799 int colors() const { return NumberOfColors(); }
800 // Number of available colors
802 // -------------------------------------------------------------------------
804 // -------------------------------------------------------------------------
805 int height() const { return maxy() + 1; }
806 // Number of lines in this window
808 int width() const { return maxx() + 1; }
809 // Number of columns in this window
811 int begx() const { return w->_begx; }
812 // Column of top left corner relative to stdscr
814 int begy() const { return w->_begy; }
815 // Line of top left corner relative to stdscr
817 int maxx() const { return w->_maxx; }
818 // Largest x coord in window
820 int maxy() const { return w->_maxy; }
821 // Largest y coord in window
823 short getcolor() const;
826 short foreground() const { return getcolor(0); }
827 // Actual foreground color
829 short background() const { return getcolor(1); }
830 // Actual background color
832 int setpalette(short fore, short back);
833 // Set color palette entry
835 int setcolor(short pair);
836 // Set actually used palette entry
838 // -------------------------------------------------------------------------
839 // window positioning
840 // -------------------------------------------------------------------------
841 virtual int mvwin(int begin_y, int begin_x) {
842 return ::mvwin(w,begin_y,begin_x); }
843 // Move window to new position with the new position as top left corner.
844 // This is virtual because it is redefined in NCursesPanel.
846 // -------------------------------------------------------------------------
847 // coordinate positioning
848 // -------------------------------------------------------------------------
849 int move(int y, int x) { return ::wmove(w, y, x); }
850 // Move cursor the this position
852 void getyx(int& y, int& x) const { ::getyx(w, y, x); }
853 // Get current position of the cursor
855 int mvcur(int oldrow, int oldcol, int newrow, int newcol) const {
856 return ::mvcur(oldrow, oldcol, newrow, newcol); }
857 // Perform lowlevel cursor motion that takes effect immediately.
859 // -------------------------------------------------------------------------
861 // -------------------------------------------------------------------------
862 int getch() { return ::wgetch(w); }
863 // Get a keystroke from the window.
865 int getch(int y, int x) { return ::mvwgetch(w,y,x); }
866 // Move cursor to position and get a keystroke from the window
868 int getstr(char* str, int n=-1) {
869 return ::wgetnstr(w, str,n); }
870 // Read a series of characters into str until a newline or carriage return
871 // is received. Read at most n characters. If n is negative, the limit is
874 int getstr(int y, int x, char* str, int n=-1) {
875 return ::mvwgetnstr(w,y,x,str,n); }
876 // Move the cursor to the requested position and then perform the getstr()
877 // as described above.
879 int instr(char *s, int n=-1) { return ::winnstr(w,s,n); }
880 // Get a string of characters from the window into the buffer s. Retrieve
881 // at most n characters, if n is negative retrieve all characters up to the
882 // end of the current line. Attributes are stripped from the characters.
884 int instr(int y, int x, char *s, int n=-1) {
885 return ::mvwinnstr(w,y,x,s,n); }
886 // Move the cursor to the requested position and then perform the instr()
887 // as described above.
889 int scanw(const char* fmt, ...)
890 // Perform a scanw function from the window.
892 __attribute__ ((format (scanf, 2, 3)));
897 int scanw(int y, int x, const char* fmt, ...)
898 // Move the cursor to the requested position and then perform a scanw
901 __attribute__ ((format (scanf, 4, 5)));
906 // -------------------------------------------------------------------------
908 // -------------------------------------------------------------------------
909 int addch(const chtype ch) { return ::waddch(w, ch); }
910 // Put attributed character to the window.
912 int addch(int y, int x, const chtype ch) {
913 return ::mvwaddch(w,y,x,ch); }
914 // Move cursor to the requested position and then put attributed character
917 int echochar(const chtype ch) { return ::wechochar(w,ch); }
918 // Put attributed character to the window and refresh it immediately.
920 int addstr(const char* str, int n=-1) {
921 return ::waddnstr(w, (char*)str,n); }
922 // Write the string str to the window, stop writing if the terminating
923 // NUL or the limit n is reached. If n is negative, it is ignored.
925 int addstr(int y, int x, const char * str, int n=-1) {
926 return ::mvwaddnstr(w,y,x,(char*)str,n); }
927 // Move the cursor to the requested position and then perform the addstr
928 // as described above.
930 int printw(const char* fmt, ...)
931 // Do a formatted print to the window.
932 #if (__GNUG__ >= 2) && !defined(printf)
933 __attribute__ ((format (printf, 2, 3)));
938 int printw(int y, int x, const char * fmt, ...)
939 // Move the cursor and then do a formatted print to the window.
940 #if (__GNUG__ >= 2) && !defined(printf)
941 __attribute__ ((format (printf, 4, 5)));
946 chtype inch() const { return ::winch(w); }
947 // Retrieve attributed character under the current cursor position.
949 chtype inch(int y, int x) { return ::mvwinch(w,y,x); }
950 // Move cursor to requested position and then retrieve attributed character
953 int insch(chtype ch) { return ::winsch(w, ch); }
954 // Insert attributed character into the window before current cursor
957 int insch(int y, int x, chtype ch) {
958 return ::mvwinsch(w,y,x,(char)ch); }
959 // Move cursor to requested position and then insert the attributed
960 // character before that position.
962 int insertln() { return ::winsdelln(w,1); }
963 // Insert an empty line above the current line.
965 int insdelln(int n=1) { return ::winsdelln(w,n); }
966 // If n>0 insert that many lines above the current line. If n<0 delete
967 // that many lines beginning with the current line.
969 int insstr(const char *s, int n=-1) {
970 return ::winsnstr(w,s,n); }
971 // Insert the string into the window before the current cursor position.
972 // Insert stops at end of string or when the limit n is reached. If n is
973 // negative, it is ignored.
975 int insstr(int y, int x, const char *s, int n=-1) {
976 return ::mvwinsnstr(w,y,x,s,n); }
977 // Move the cursor to the requested position and then perform the insstr()
978 // as described above.
980 int attron (chtype at) { return ::wattron (w, at); }
981 // Switch on the window attributes;
983 int attroff(chtype at) { return ::wattroff(w, (int) at); }
984 // Switch off the window attributes;
986 int attrset(chtype at) { return ::wattrset(w, (int) at); }
987 // Set the window attributes;
989 int color_set(short color_pair_number, void* opts=NULL) {
990 return ::wcolor_set(w, color_pair_number, opts); }
991 // Set the window color attribute;
993 int chgat(int n,attr_t attr, short color, const void *opts=NULL) {
994 return ::wchgat(w,n,attr,color,opts); }
995 // Change the attributes of the next n characters in the current line. If
996 // n is negative or greater than the number of remaining characters in the
997 // line, the attributes will be changed up to the end of the line.
999 int chgat(int y, int x,
1000 int n,attr_t attr, short color, const void *opts=NULL) {
1001 return ::mvwchgat(w,y,x,n,attr,color,opts); }
1002 // Move the cursor to the requested position and then perform chgat() as
1005 // -------------------------------------------------------------------------
1007 // -------------------------------------------------------------------------
1008 chtype getbkgd() const { return ::getbkgd(w); }
1009 // Get current background setting.
1011 int bkgd(const chtype ch) { return ::wbkgd(w,ch); }
1012 // Set the background property and apply it to the window.
1014 void bkgdset(chtype ch) { ::wbkgdset(w,ch); }
1015 // Set the background property.
1017 // -------------------------------------------------------------------------
1019 // -------------------------------------------------------------------------
1020 int box(chtype vert=0, chtype hor=0) {
1021 return ::wborder(w, vert, vert, hor, hor, 0, 0 ,0, 0); }
1022 // Draw a box around the window with the given vertical and horizontal
1023 // drawing characters. If you specify a zero as character, curses will try
1024 // to find a "nice" character.
1026 int border(chtype left=0, chtype right=0,
1027 chtype top =0, chtype bottom=0,
1028 chtype top_left =0, chtype top_right=0,
1029 chtype bottom_left =0, chtype bottom_right=0) {
1030 return ::wborder(w,left,right,top,bottom,top_left,top_right,
1031 bottom_left,bottom_right); }
1032 // Draw a border around the window with the given characters for the
1033 // various parts of the border. If you pass zero for a character, curses
1034 // will try to find "nice" characters.
1036 // -------------------------------------------------------------------------
1038 // -------------------------------------------------------------------------
1039 int hline(int len, chtype ch=0) { return ::whline(w, ch, len); }
1040 // Draw a horizontal line of len characters with the given character. If
1041 // you pass zero for the character, curses will try to find a "nice" one.
1043 int hline(int y, int x, int len, chtype ch=0) {
1044 return ::mvwhline(w,y,x,ch,len); }
1045 // Move the cursor to the requested position and then draw a horizontal line.
1047 int vline(int len, chtype ch=0) { return ::wvline(w, ch, len); }
1048 // Draw a vertical line of len characters with the given character. If
1049 // you pass zero for the character, curses will try to find a "nice" one.
1051 int vline(int y, int x, int len, chtype ch=0) {
1052 return ::mvwvline(w,y,x,ch,len); }
1053 // Move the cursor to the requested position and then draw a vertical line.
1055 // -------------------------------------------------------------------------
1057 // -------------------------------------------------------------------------
1058 int erase() { return ::werase(w); }
1059 // Erase the window.
1061 int clear() { return ::wclear(w); }
1062 // Clear the window.
1064 int clearok(bool bf) { return ::clearok(w, bf); }
1065 // Set/Reset the clear flag. If set, the next refresh() will clear the
1068 int clrtobot() { return ::wclrtobot(w); }
1069 // Clear to the end of the window.
1071 int clrtoeol() { return ::wclrtoeol(w); }
1072 // Clear to the end of the line.
1074 int delch() { return ::wdelch(w); }
1075 // Delete character under the cursor.
1077 int delch(int y, int x) { return ::mvwdelch(w,y,x); }
1078 // Move cursor to requested position and delete the character under the
1081 int deleteln() { return ::winsdelln(w,-1); }
1082 // Delete the current line.
1084 // -------------------------------------------------------------------------
1086 // -------------------------------------------------------------------------
1087 int scroll(int amount=1) { return ::wscrl(w,amount); }
1088 // Scroll amount lines. If amount is positive, scroll up, otherwise
1091 int scrollok(bool bf) { return ::scrollok(w, bf); }
1092 // If bf is TRUE, window scrolls if cursor is moved off the bottom
1093 // edge of the window or a scrolling region, otherwise the cursor is left
1094 // at the bottom line.
1096 int setscrreg(int from, int to) {
1097 return ::wsetscrreg(w,from,to); }
1098 // Define a soft scrolling region.
1100 int idlok(bool bf) { return ::idlok(w, bf); }
1101 // If bf is TRUE, use insert/delete line hardware support if possible.
1102 // Otherwise do it in software.
1105 void idcok(bool bf) { ::idcok(w, bf); }
1106 // If bf is TRUE, use insert/delete character hardware support if possible.
1107 // Otherwise do it in software.
1109 int touchwin() { return ::wtouchln(w,0,height(),1); }
1110 // Mark the whole window as modified.
1112 int untouchwin() { return ::wtouchln(w,0,height(),0); }
1113 // Mark the whole window as unmodified.
1115 int touchln(int s, int cnt, bool changed=TRUE) {
1116 return ::wtouchln(w,s,cnt,(int)(changed?1:0)); }
1117 // Mark cnt lines beginning from line s as changed or unchanged, depending
1118 // on the value of the changed flag.
1120 bool is_linetouched(int line) const {
1121 return (::is_linetouched(w,line) ? TRUE:FALSE); }
1122 // Return TRUE if line is marked as changed, FALSE otherwise
1124 bool is_wintouched() const {
1125 return (::is_wintouched(w) ? TRUE:FALSE); }
1126 // Return TRUE if window is marked as changed, FALSE otherwise
1128 int leaveok(bool bf) { return ::leaveok(w, bf); }
1129 // If bf is TRUE, curses will leave the cursor after an update whereever
1130 // it is after the update.
1132 int redrawln(int from, int n) { return ::wredrawln(w,from,n); }
1133 // Redraw n lines starting from the requested line
1135 int redrawwin() { return ::wredrawln(w,0,height()); }
1136 // Redraw the whole window
1138 int doupdate() { return ::doupdate(); }
1139 // Do all outputs to make the physical screen looking like the virtual one
1141 void syncdown() { ::wsyncdown(w); }
1142 // Propagate the changes down to all descendant windows
1144 void syncup() { ::wsyncup(w); }
1145 // Propagate the changes up in the hierarchy
1147 void cursyncup() { ::wcursyncup(w); }
1148 // Position the cursor in all ancestor windows corresponding to our setting
1150 int syncok(bool bf) { return ::syncok(w,bf); }
1151 // If called with bf=TRUE, syncup() is called whenever the window is changed
1154 int flushok(bool bf) { return ::flushok(w, bf); }
1157 void immedok(bool bf) { ::immedok(w,bf); }
1158 // If called with bf=TRUE, any change in the window will cause an
1159 // automatic immediate refresh()
1161 int keypad(bool bf) { return ::keypad(w, bf); }
1162 // If called with bf=TRUE, the application will interpret function keys.
1164 int meta(bool bf) { return ::meta(w,bf); }
1165 // If called with bf=TRUE, keys may generate 8-Bit characters. Otherwise
1166 // 7-Bit characters are generated.
1168 int standout() { return ::wstandout(w); }
1169 // Enable "standout" attributes
1171 int standend() { return ::wstandend(w); }
1172 // Disable "standout" attributes
1174 // -------------------------------------------------------------------------
1175 // The next two are virtual, because we redefine them in the
1176 // NCursesPanel class.
1177 // -------------------------------------------------------------------------
1178 virtual int refresh() { return ::wrefresh(w); }
1179 // Propagate the changes in this window to the virtual screen and call
1180 // doupdate(). This is redefined in NCursesPanel.
1182 virtual int noutrefresh() { return ::wnoutrefresh(w); }
1183 // Propagate the changes in this window to the virtual screen. This is
1184 // redefined in NCursesPanel.
1186 // -------------------------------------------------------------------------
1187 // multiple window control
1188 // -------------------------------------------------------------------------
1189 int overlay(NCursesWindow& win) {
1190 return ::overlay(w, win.w); }
1191 // Overlay this window over win.
1193 int overwrite(NCursesWindow& win) {
1194 return ::overwrite(w, win.w); }
1195 // Overwrite win with this window.
1197 int copywin(NCursesWindow& win,
1198 int sminrow, int smincol,
1199 int dminrow, int dmincol,
1200 int dmaxrow, int dmaxcol, bool overlay=TRUE) {
1201 return ::copywin(w,win.w,sminrow,smincol,dminrow,dmincol,
1202 dmaxrow,dmaxcol,(int)(overlay?1:0)); }
1203 // Overlay or overwrite the rectangle in win given by dminrow,dmincol,
1204 // dmaxrow,dmaxcol with the rectangle in this window beginning at
1207 // -------------------------------------------------------------------------
1209 // -------------------------------------------------------------------------
1210 bool has_mouse() const;
1211 // Return TRUE if terminal supports a mouse, FALSE otherwise
1213 // -------------------------------------------------------------------------
1214 // traversal support
1215 // -------------------------------------------------------------------------
1216 NCursesWindow* child() { return subwins; }
1217 // Get the first child window.
1219 NCursesWindow* sibling() { return sib; }
1220 // Get the next child of my parent.
1222 NCursesWindow* parent() { return par; }
1225 bool isDescendant(NCursesWindow& win);
1226 // Return TRUE if win is a descendant of this.
1229 // -------------------------------------------------------------------------
1230 // We leave this here for compatibility reasons.
1231 // -------------------------------------------------------------------------
1232 class NCURSES_IMPEXP NCursesColorWindow : public NCursesWindow {
1234 NCursesColorWindow(WINDOW* &window) // useful only for stdscr
1235 : NCursesWindow(window) {
1238 NCursesColorWindow(int lines, // number of lines
1239 int cols, // number of columns
1240 int begin_y, // line origin
1241 int begin_x) // col origin
1242 : NCursesWindow(lines,cols,begin_y,begin_x) {
1245 NCursesColorWindow(NCursesWindow& par,// parent window
1246 int lines, // number of lines
1247 int cols, // number of columns
1248 int begin_y, // absolute or relative
1249 int begin_x, // origins:
1250 char absrel = 'a') // if `a', by & bx are
1251 : NCursesWindow(par,lines,cols, // absolute screen pos,
1252 begin_y,begin_x, // else if `r', they are
1253 absrel ) { // relative to par origin
1257 // These enum definitions really belong inside the NCursesPad class, but only
1258 // recent compilers support that feature.
1261 REQ_PAD_REFRESH = KEY_MAX + 1,
1269 const Pad_Request PAD_LOW = REQ_PAD_REFRESH; // lowest op-code
1270 const Pad_Request PAD_HIGH = REQ_PAD_EXIT; // highest op-code
1272 // -------------------------------------------------------------------------
1273 // Pad Support. We allow an association of a pad with a "real" window
1274 // through which the pad may be viewed.
1275 // -------------------------------------------------------------------------
1276 class NCURSES_IMPEXP NCursesPad : public NCursesWindow {
1278 NCursesWindow* viewWin; // the "viewport" window
1279 NCursesWindow* viewSub; // the "viewport" subwindow
1281 int h_gridsize, v_gridsize;
1284 int min_row, min_col; // top left row/col of the pads display area
1286 NCursesWindow* Win(void) const {
1287 // Get the window into which the pad should be copied (if any)
1288 return (viewSub?viewSub:(viewWin?viewWin:0));
1291 NCursesWindow* getWindow(void) const {
1295 NCursesWindow* getSubWindow(void) const {
1299 virtual int driver (int key); // Virtualize keystroke key
1300 // The driver translates the keystroke c into an Pad_Request
1302 virtual void OnUnknownOperation(int pad_req) {
1305 // This is called if the driver returns an unknown op-code
1307 virtual void OnNavigationError(int pad_req) {
1310 // This is called if a navigation request couldn't be satisfied
1312 virtual void OnOperation(int pad_req) {
1314 // OnOperation is called if a Pad_Operation was executed and just before
1315 // the refresh() operation is done.
1318 NCursesPad(int lines, int cols);
1319 // create a pad with the given size
1321 virtual ~NCursesPad() {}
1323 int echochar(const chtype ch) { return ::pechochar(w,ch); }
1324 // Put the attributed character onto the pad and immediately do a
1328 // If a viewport is defined the pad is displayed in this window, otherwise
1331 int refresh(int pminrow, int pmincol,
1332 int sminrow, int smincol,
1333 int smaxrow, int smaxcol) {
1334 return ::prefresh(w,pminrow,pmincol,
1335 sminrow,smincol,smaxrow,smaxcol);
1337 // The coordinates sminrow,smincol,smaxrow,smaxcol describe a rectangle
1338 // on the screen. <b>refresh</b> copies a rectangle of this size beginning
1339 // with top left corner pminrow,pmincol onto the screen and calls doupdate().
1342 // If a viewport is defined the pad is displayed in this window, otherwise
1345 int noutrefresh(int pminrow, int pmincol,
1346 int sminrow, int smincol,
1347 int smaxrow, int smaxcol) {
1348 return ::pnoutrefresh(w,pminrow,pmincol,
1349 sminrow,smincol,smaxrow,smaxcol);
1351 // Does the same as refresh() but without calling doupdate().
1353 virtual void setWindow(NCursesWindow& view, int v_grid = 1, int h_grid = 1);
1354 // Add the window "view" as viewing window to the pad.
1356 virtual void setSubWindow(NCursesWindow& sub);
1357 // Use the subwindow "sub" of the viewport window for the actual viewing.
1358 // The full viewport window is usually used to provide some decorations
1359 // like frames, titles etc.
1361 virtual void operator() (void);
1362 // Perform Pad's operation
1365 // A FramedPad is constructed always with a viewport window. This viewport
1366 // will be framed (by a box() command) and the interior of the box is the
1367 // viewport subwindow. On the frame we display scrollbar sliders.
1368 class NCURSES_IMPEXP NCursesFramedPad : public NCursesPad {
1370 virtual void OnOperation(int pad_req);
1373 NCursesFramedPad(NCursesWindow& win, int lines, int cols,
1374 int v_grid = 1, int h_grid = 1)
1375 : NCursesPad(lines,cols) {
1376 NCursesPad::setWindow(win,v_grid,h_grid);
1377 NCursesPad::setSubWindow(*(new NCursesWindow(win)));
1379 // Construct the FramedPad with the given Window win as viewport.
1381 virtual ~NCursesFramedPad() {
1382 delete getSubWindow();
1385 void setWindow(NCursesWindow& view, int v_grid = 1, int h_grid = 1) {
1386 err_handler("Operation not allowed");
1388 // Disable this call; the viewport is already defined
1390 void setSubWindow(NCursesWindow& sub) {
1391 err_handler("Operation not allowed");
1393 // Disable this call; the viewport subwindow is already defined
1397 #endif // NCURSES_CURSESW_H_incl