1 // * This makes emacs happy -*-Mode: C++;-*-
3 /****************************************************************************
4 * Copyright (c) 1998-2011,2014 Free Software Foundation, Inc. *
6 * Permission is hereby granted, free of charge, to any person obtaining a *
7 * copy of this software and associated documentation files (the *
8 * "Software"), to deal in the Software without restriction, including *
9 * without limitation the rights to use, copy, modify, merge, publish, *
10 * distribute, distribute with modifications, sublicense, and/or sell *
11 * copies of the Software, and to permit persons to whom the Software is *
12 * furnished to do so, subject to the following conditions: *
14 * The above copyright notice and this permission notice shall be included *
15 * in all copies or substantial portions of the Software. *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
25 * Except as contained in this notice, the name(s) of the above copyright *
26 * holders shall not be used in advertising or otherwise to promote the *
27 * sale, use or other dealings in this Software without prior written *
29 ****************************************************************************/
31 #ifndef NCURSES_CURSESW_H_incl
32 #define NCURSES_CURSESW_H_incl 1
34 // $Id: cursesw.h,v 1.50 2014/02/01 22:17:37 tom Exp $
42 /* SCO 3.2v4 curses.h includes term.h, which defines lines as a macro.
43 Undefine it here, because NCursesWindow uses lines as a method. */
46 /* "Convert" macros to inlines. We'll define it as another symbol to avoid
47 * conflict with library symbols.
50 #define UNDEF(name) CUR_ ##name
53 inline int UNDEF(addch)(chtype ch) { return addch(ch); }
55 #define addch UNDEF(addch)
59 inline int UNDEF(addchstr)(chtype *at) { return addchstr(at); }
61 #define addchstr UNDEF(addchstr)
65 inline int UNDEF(addnstr)(const char *str, int n)
66 { return addnstr(str, n); }
68 #define addnstr UNDEF(addnstr)
72 inline int UNDEF(addstr)(const char * str) { return addstr(str); }
74 #define addstr UNDEF(addstr)
78 inline int UNDEF(attroff)(chtype at) { return attroff(at); }
80 #define attroff UNDEF(attroff)
84 inline int UNDEF(attron)(chtype at) { return attron(at); }
86 #define attron UNDEF(attron)
90 inline chtype UNDEF(attrset)(chtype at) { return attrset(at); }
92 #define attrset UNDEF(attrset)
96 inline int UNDEF(bkgd)(chtype ch) { return bkgd(ch); }
98 #define bkgd UNDEF(bkgd)
102 inline void UNDEF(bkgdset)(chtype ch) { bkgdset(ch); }
104 #define bkgdset UNDEF(bkgdset)
108 inline int UNDEF(border)(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, chtype tr, chtype bl, chtype br)
109 { return border(ls, rs, ts, bs, tl, tr, bl, br); }
111 #define border UNDEF(border)
115 inline int UNDEF(box)(WINDOW *win, int v, int h) { return box(win, v, h); }
117 #define box UNDEF(box)
121 inline int UNDEF(chgat)(int n, attr_t attr, NCURSES_PAIRS_T color, const void *opts) {
122 return chgat(n, attr, color, opts); }
124 #define chgat UNDEF(chgat)
128 inline int UNDEF(clear)() { return clear(); }
130 #define clear UNDEF(clear)
134 inline int UNDEF(clearok)(WINDOW* win, bool bf) { return clearok(win, bf); }
136 #define clearok UNDEF(clearok)
138 extern "C" NCURSES_IMPEXP int NCURSES_API clearok(WINDOW*, bool);
142 inline int UNDEF(clrtobot)() { return clrtobot(); }
144 #define clrtobot UNDEF(clrtobot)
148 inline int UNDEF(clrtoeol)() { return clrtoeol(); }
150 #define clrtoeol UNDEF(clrtoeol)
154 inline chtype UNDEF(color_set)(NCURSES_PAIRS_T p, void* opts) { return color_set(p, opts); }
156 #define color_set UNDEF(color_set)
160 inline int UNDEF(crmode)(void) { return crmode(); }
162 #define crmode UNDEF(crmode)
166 inline int UNDEF(delch)() { return delch(); }
168 #define delch UNDEF(delch)
172 inline int UNDEF(deleteln)() { return deleteln(); }
174 #define deleteln UNDEF(deleteln)
178 inline int UNDEF(echochar)(chtype ch) { return echochar(ch); }
180 #define echochar UNDEF(echochar)
184 inline int UNDEF(erase)() { return erase(); }
186 #define erase UNDEF(erase)
190 inline int UNDEF(fixterm)(void) { return fixterm(); }
192 #define fixterm UNDEF(fixterm)
196 inline int UNDEF(flushok)(WINDOW* _win, bool _bf) {
197 return flushok(_win, _bf); }
199 #define flushok UNDEF(flushok)
205 inline int UNDEF(getattrs)(WINDOW *win) { return getattrs(win); }
207 #define getattrs UNDEF(getattrs)
211 inline void UNDEF(getbegyx)(WINDOW* win, int& y, int& x) { getbegyx(win, y, x); }
213 #define getbegyx UNDEF(getbegyx)
217 inline chtype UNDEF(getbkgd)(const WINDOW *win) { return getbkgd(win); }
219 #define getbkgd UNDEF(getbkgd)
223 inline int UNDEF(getch)() { return getch(); }
225 #define getch UNDEF(getch)
229 inline void UNDEF(getmaxyx)(WINDOW* win, int& y, int& x) { getmaxyx(win, y, x); }
231 #define getmaxyx UNDEF(getmaxyx)
235 inline int UNDEF(getnstr)(char *_str, int n) { return getnstr(_str, n); }
237 #define getnstr UNDEF(getnstr)
241 inline void UNDEF(getparyx)(WINDOW* win, int& y, int& x) { getparyx(win, y, x); }
243 #define getparyx UNDEF(getparyx)
247 inline int UNDEF(getstr)(char *_str) { return getstr(_str); }
249 #define getstr UNDEF(getstr)
253 inline void UNDEF(getyx)(const WINDOW* win, int& y, int& x) {
256 #define getyx UNDEF(getyx)
260 inline int UNDEF(hline)(chtype ch, int n) { return hline(ch, n); }
262 #define hline UNDEF(hline)
266 inline chtype UNDEF(inch)() { return inch(); }
268 #define inch UNDEF(inch)
272 inline int UNDEF(inchstr)(chtype *str) { return inchstr(str); }
274 #define inchstr UNDEF(inchstr)
278 inline int UNDEF(innstr)(char *_str, int n) { return innstr(_str, n); }
280 #define innstr UNDEF(innstr)
284 inline int UNDEF(insch)(chtype c) { return insch(c); }
286 #define insch UNDEF(insch)
290 inline int UNDEF(insdelln)(int n) { return insdelln(n); }
292 #define insdelln UNDEF(insdelln)
296 inline int UNDEF(insertln)() { return insertln(); }
298 #define insertln UNDEF(insertln)
302 inline int UNDEF(insnstr)(const char *_str, int n) {
303 return insnstr(_str, n); }
305 #define insnstr UNDEF(insnstr)
309 inline int UNDEF(insstr)(const char *_str) {
310 return insstr(_str); }
312 #define insstr UNDEF(insstr)
316 inline int UNDEF(instr)(char *_str) { return instr(_str); }
318 #define instr UNDEF(instr)
322 inline void UNDEF(intrflush)(WINDOW *win, bool bf) { intrflush(); }
324 #define intrflush UNDEF(intrflush)
328 inline int UNDEF(leaveok)(WINDOW* win, bool bf) { return leaveok(win, bf); }
330 #define leaveok UNDEF(leaveok)
332 extern "C" NCURSES_IMPEXP int NCURSES_API leaveok(WINDOW* win, bool bf);
336 inline int UNDEF(move)(int x, int y) { return move(x, y); }
338 #define move UNDEF(move)
342 inline int UNDEF(mvaddch)(int y, int x, chtype ch)
343 { return mvaddch(y, x, ch); }
345 #define mvaddch UNDEF(mvaddch)
349 inline int UNDEF(mvaddnstr)(int y, int x, const char *str, int n)
350 { return mvaddnstr(y, x, str, n); }
352 #define mvaddnstr UNDEF(mvaddnstr)
356 inline int UNDEF(mvaddstr)(int y, int x, const char * str)
357 { return mvaddstr(y, x, str); }
359 #define mvaddstr UNDEF(mvaddstr)
363 inline int UNDEF(mvchgat)(int y, int x, int n,
364 attr_t attr, NCURSES_PAIRS_T color, const void *opts) {
365 return mvchgat(y, x, n, attr, color, opts); }
367 #define mvchgat UNDEF(mvchgat)
371 inline int UNDEF(mvdelch)(int y, int x) { return mvdelch(y, x);}
373 #define mvdelch UNDEF(mvdelch)
377 inline int UNDEF(mvgetch)(int y, int x) { return mvgetch(y, x);}
379 #define mvgetch UNDEF(mvgetch)
383 inline int UNDEF(mvgetnstr)(int y, int x, char *str, int n) {
384 return mvgetnstr(y, x, str, n);}
386 #define mvgetnstr UNDEF(mvgetnstr)
390 inline int UNDEF(mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
392 #define mvgetstr UNDEF(mvgetstr)
396 inline chtype UNDEF(mvinch)(int y, int x) { return mvinch(y, x);}
398 #define mvinch UNDEF(mvinch)
402 inline int UNDEF(mvinnstr)(int y, int x, char *_str, int n) {
403 return mvinnstr(y, x, _str, n); }
405 #define mvinnstr UNDEF(mvinnstr)
409 inline int UNDEF(mvinsch)(int y, int x, chtype c)
410 { return mvinsch(y, x, c); }
412 #define mvinsch UNDEF(mvinsch)
416 inline int UNDEF(mvinsnstr)(int y, int x, const char *_str, int n) {
417 return mvinsnstr(y, x, _str, n); }
419 #define mvinsnstr UNDEF(mvinsnstr)
423 inline int UNDEF(mvinsstr)(int y, int x, const char *_str) {
424 return mvinsstr(y, x, _str); }
426 #define mvinsstr UNDEF(mvinsstr)
430 inline int UNDEF(mvwaddch)(WINDOW *win, int y, int x, const chtype ch)
431 { return mvwaddch(win, y, x, ch); }
433 #define mvwaddch UNDEF(mvwaddch)
437 inline int UNDEF(mvwaddchnstr)(WINDOW *win, int y, int x, const chtype *str, int n)
438 { return mvwaddchnstr(win, y, x, str, n); }
440 #define mvwaddchnstr UNDEF(mvwaddchnstr)
444 inline int UNDEF(mvwaddchstr)(WINDOW *win, int y, int x, const chtype *str)
445 { return mvwaddchstr(win, y, x, str); }
447 #define mvwaddchstr UNDEF(mvwaddchstr)
451 inline int UNDEF(mvwaddnstr)(WINDOW *win, int y, int x, const char *str, int n)
452 { return mvwaddnstr(win, y, x, str, n); }
454 #define mvwaddnstr UNDEF(mvwaddnstr)
458 inline int UNDEF(mvwaddstr)(WINDOW *win, int y, int x, const char * str)
459 { return mvwaddstr(win, y, x, str); }
461 #define mvwaddstr UNDEF(mvwaddstr)
465 inline int UNDEF(mvwchgat)(WINDOW *win, int y, int x, int n,
466 attr_t attr, NCURSES_PAIRS_T color, const void *opts) {
467 return mvwchgat(win, y, x, n, attr, color, opts); }
469 #define mvwchgat UNDEF(mvwchgat)
473 inline int UNDEF(mvwdelch)(WINDOW *win, int y, int x)
474 { return mvwdelch(win, y, x); }
476 #define mvwdelch UNDEF(mvwdelch)
480 inline int UNDEF(mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
482 #define mvwgetch UNDEF(mvwgetch)
486 inline int UNDEF(mvwgetnstr)(WINDOW *win, int y, int x, char *str, int n)
487 {return mvwgetnstr(win, y, x, str, n);}
489 #define mvwgetnstr UNDEF(mvwgetnstr)
493 inline int UNDEF(mvwgetstr)(WINDOW *win, int y, int x, char *str)
494 {return mvwgetstr(win, y, x, str);}
496 #define mvwgetstr UNDEF(mvwgetstr)
500 inline int UNDEF(mvwhline)(WINDOW *win, int y, int x, chtype c, int n) {
501 return mvwhline(win, y, x, c, n); }
503 #define mvwhline UNDEF(mvwhline)
507 inline chtype UNDEF(mvwinch)(WINDOW *win, int y, int x) {
508 return mvwinch(win, y, x);}
510 #define mvwinch UNDEF(mvwinch)
514 inline int UNDEF(mvwinchnstr)(WINDOW *win, int y, int x, chtype *str, int n) { return mvwinchnstr(win, y, x, str, n); }
516 #define mvwinchnstr UNDEF(mvwinchnstr)
520 inline int UNDEF(mvwinchstr)(WINDOW *win, int y, int x, chtype *str) { return mvwinchstr(win, y, x, str); }
522 #define mvwinchstr UNDEF(mvwinchstr)
526 inline int UNDEF(mvwinnstr)(WINDOW *win, int y, int x, char *_str, int n) {
527 return mvwinnstr(win, y, x, _str, n); }
529 #define mvwinnstr UNDEF(mvwinnstr)
533 inline int UNDEF(mvwinsch)(WINDOW *win, int y, int x, chtype c)
534 { return mvwinsch(win, y, x, c); }
536 #define mvwinsch UNDEF(mvwinsch)
540 inline int UNDEF(mvwinsnstr)(WINDOW *w, int y, int x, const char *_str, int n) {
541 return mvwinsnstr(w, y, x, _str, n); }
543 #define mvwinsnstr UNDEF(mvwinsnstr)
547 inline int UNDEF(mvwinsstr)(WINDOW *w, int y, int x, const char *_str) {
548 return mvwinsstr(w, y, x, _str); }
550 #define mvwinsstr UNDEF(mvwinsstr)
554 inline int UNDEF(mvwvline)(WINDOW *win, int y, int x, chtype c, int n) {
555 return mvwvline(win, y, x, c, n); }
557 #define mvwvline UNDEF(mvwvline)
561 inline void UNDEF(napms)(unsigned long x) { napms(x); }
563 #define napms UNDEF(napms)
567 inline int UNDEF(nocrmode)(void) { return nocrmode(); }
569 #define nocrmode UNDEF(nocrmode)
573 inline void UNDEF(nodelay)() { nodelay(); }
575 #define nodelay UNDEF(nodelay)
579 inline int UNDEF(redrawwin)(WINDOW *win) { return redrawwin(win); }
581 #define redrawwin UNDEF(redrawwin)
585 inline int UNDEF(refresh)() { return refresh(); }
587 #define refresh UNDEF(refresh)
591 inline int UNDEF(resetterm)(void) { return resetterm(); }
593 #define resetterm UNDEF(resetterm)
597 inline int UNDEF(saveterm)(void) { return saveterm(); }
599 #define saveterm UNDEF(saveterm)
603 inline int UNDEF(scrl)(int l) { return scrl(l); }
605 #define scrl UNDEF(scrl)
609 inline int UNDEF(scroll)(WINDOW *win) { return scroll(win); }
611 #define scroll UNDEF(scroll)
615 inline int UNDEF(scrollok)(WINDOW* win, bool bf) { return scrollok(win, bf); }
617 #define scrollok UNDEF(scrollok)
619 #if defined(__NCURSES_H)
620 extern "C" NCURSES_IMPEXP int NCURSES_API scrollok(WINDOW*, bool);
622 extern "C" NCURSES_IMPEXP int NCURSES_API scrollok(WINDOW*, char);
627 inline int UNDEF(setscrreg)(int t, int b) { return setscrreg(t, b); }
629 #define setscrreg UNDEF(setscrreg)
633 inline int UNDEF(standend)() { return standend(); }
635 #define standend UNDEF(standend)
639 inline int UNDEF(standout)() { return standout(); }
641 #define standout UNDEF(standout)
645 inline WINDOW *UNDEF(subpad)(WINDOW *p, int l, int c, int y, int x)
646 { return derwin(p, l, c, y, x); }
648 #define subpad UNDEF(subpad)
652 inline void UNDEF(timeout)(int delay) { timeout(delay); }
654 #define timeout UNDEF(timeout)
658 inline int UNDEF(touchline)(WINDOW *win, int s, int c)
659 { return touchline(win, s, c); }
661 #define touchline UNDEF(touchline)
665 inline int UNDEF(touchwin)(WINDOW *win) { return touchwin(win); }
667 #define touchwin UNDEF(touchwin)
671 inline int UNDEF(untouchwin)(WINDOW *win) { return untouchwin(win); }
673 #define untouchwin UNDEF(untouchwin)
677 inline int UNDEF(vline)(chtype ch, int n) { return vline(ch, n); }
679 #define vline UNDEF(vline)
683 inline int UNDEF(waddchstr)(WINDOW *win, chtype *at) { return waddchstr(win, at); }
685 #define waddchstr UNDEF(waddchstr)
689 inline int UNDEF(waddstr)(WINDOW *win, char *str) { return waddstr(win, str); }
691 #define waddstr UNDEF(waddstr)
695 inline int UNDEF(wattroff)(WINDOW *win, int att) { return wattroff(win, att); }
697 #define wattroff UNDEF(wattroff)
701 inline int UNDEF(wattrset)(WINDOW *win, int att) { return wattrset(win, att); }
703 #define wattrset UNDEF(wattrset)
707 inline chtype UNDEF(winch)(const WINDOW* win) { return winch(win); }
709 #define winch UNDEF(winch)
713 inline int UNDEF(winchnstr)(WINDOW *win, chtype *str, int n) { return winchnstr(win, str, n); }
715 #define winchnstr UNDEF(winchnstr)
719 inline int UNDEF(winchstr)(WINDOW *win, chtype *str) { return winchstr(win, str); }
721 #define winchstr UNDEF(winchstr)
725 inline int UNDEF(winsstr)(WINDOW *w, const char *_str) {
726 return winsstr(w, _str); }
728 #define winsstr UNDEF(winsstr)
732 inline int UNDEF(wstandend)(WINDOW *win) { return wstandend(win); }
734 #define wstandend UNDEF(wstandend)
738 inline int UNDEF(wstandout)(WINDOW *win) { return wstandout(win); }
740 #define wstandout UNDEF(wstandout)
745 * C++ class for windows.
749 extern "C" int _nc_ripoffline(int, int (*init)(WINDOW*, int));
750 extern "C" int _nc_xx_ripoff_init(WINDOW *, int);
751 extern "C" int _nc_has_mouse(void);
753 class NCURSES_IMPEXP NCursesWindow
755 friend class NCursesMenu;
756 friend class NCursesForm;
759 static bool b_initialized;
760 static void initialize();
762 friend int _nc_xx_ripoff_init(WINDOW *, int);
766 NCURSES_COLOR_T getcolor(int getback) const;
767 NCURSES_PAIRS_T getPair() const;
769 static int setpalette(NCURSES_COLOR_T fore, NCURSES_COLOR_T back, NCURSES_PAIRS_T pair);
770 static int colorInitialized;
772 // This private constructor is only used during the initialization
773 // of windows generated by ripoffline() calls.
774 NCursesWindow(WINDOW* win, int ncols);
777 virtual void err_handler(const char *) const THROWS(NCursesException);
778 // Signal an error with the given message text.
780 static long count; // count of all active windows:
781 // We rely on the c++ promise that
782 // all otherwise uninitialized
783 // static class vars are set to 0
785 WINDOW* w; // the curses WINDOW
787 bool alloced; // TRUE if we own the WINDOW
789 NCursesWindow* par; // parent, if subwindow
790 NCursesWindow* subwins; // head of subwindows list
791 NCursesWindow* sib; // next subwindow of parent
793 void kill_subwindows(); // disable all subwindows
794 // Destroy all subwindows.
796 /* Only for use by derived classes. They are then in charge to
797 fill the member variables correctly. */
801 NCursesWindow(WINDOW* window); // useful only for stdscr
803 NCursesWindow(int nlines, // number of lines
804 int ncols, // number of columns
805 int begin_y, // line origin
806 int begin_x); // col origin
808 NCursesWindow(NCursesWindow& par,// parent window
809 int nlines, // number of lines
810 int ncols, // number of columns
811 int begin_y, // absolute or relative
812 int begin_x, // origins:
813 char absrel = 'a');// if `a', begin_y & begin_x are
814 // absolute screen pos, else if `r', they are relative to par origin
816 NCursesWindow(NCursesWindow& par,// parent window
818 // this is the very common case that we want to create the subwindow that
819 // is two lines and two columns smaller and begins at (1,1).
820 // We may automatically request the box around it.
822 NCursesWindow& operator=(const NCursesWindow& rhs)
829 NCursesWindow(const NCursesWindow& rhs)
830 : w(rhs.w), alloced(rhs.alloced), par(rhs.par), subwins(rhs.subwins), sib(rhs.sib)
834 virtual ~NCursesWindow();
836 NCursesWindow Clone();
837 // Make an exact copy of the window.
840 static void useColors(void);
841 // Call this routine very early if you want to have colors.
843 static int ripoffline(int ripoff_lines,
844 int (*init)(NCursesWindow& win));
845 // This function is used to generate a window of ripped-of lines.
846 // If the argument is positive, lines are removed from the top, if it
847 // is negative lines are removed from the bottom. This enhances the
848 // lowlevel ripoffline() function because it uses the internal
849 // implementation that allows to remove more than just a single line.
850 // This function must be called before any other ncurses function. The
851 // creation of the window is deferred until ncurses gets initialized.
852 // The initialization function is then called.
854 // -------------------------------------------------------------------------
856 // -------------------------------------------------------------------------
857 int lines() const { initialize(); return LINES; }
858 // Number of lines on terminal, *not* window
860 int cols() const { initialize(); return COLS; }
861 // Number of cols on terminal, *not* window
863 int tabsize() const { initialize(); return TABSIZE; }
864 // Size of a tab on terminal, *not* window
866 static int NumberOfColors();
867 // Number of available colors
869 int colors() const { return NumberOfColors(); }
870 // Number of available colors
872 // -------------------------------------------------------------------------
874 // -------------------------------------------------------------------------
875 int height() const { return maxy() + 1; }
876 // Number of lines in this window
878 int width() const { return maxx() + 1; }
879 // Number of columns in this window
881 int begx() const { return getbegx(w); }
882 // Column of top left corner relative to stdscr
884 int begy() const { return getbegy(w); }
885 // Line of top left corner relative to stdscr
887 int curx() const { return getcurx(w); }
888 // Column of top left corner relative to stdscr
890 int cury() const { return getcury(w); }
891 // Line of top left corner relative to stdscr
893 int maxx() const { return getmaxx(w) == ERR ? ERR : getmaxx(w)-1; }
894 // Largest x coord in window
896 int maxy() const { return getmaxy(w) == ERR ? ERR : getmaxy(w)-1; }
897 // Largest y coord in window
899 NCURSES_PAIRS_T getcolor() const;
902 NCURSES_COLOR_T foreground() const { return getcolor(0); }
903 // Actual foreground color
905 NCURSES_COLOR_T background() const { return getcolor(1); }
906 // Actual background color
908 int setpalette(NCURSES_COLOR_T fore, NCURSES_COLOR_T back);
909 // Set color palette entry
911 int setcolor(NCURSES_PAIRS_T pair);
912 // Set actually used palette entry
914 // -------------------------------------------------------------------------
915 // window positioning
916 // -------------------------------------------------------------------------
917 virtual int mvwin(int begin_y, int begin_x) {
918 return ::mvwin(w, begin_y, begin_x); }
919 // Move window to new position with the new position as top left corner.
920 // This is virtual because it is redefined in NCursesPanel.
922 // -------------------------------------------------------------------------
923 // coordinate positioning
924 // -------------------------------------------------------------------------
925 int move(int y, int x) { return ::wmove(w, y, x); }
926 // Move cursor the this position
928 void getyx(int& y, int& x) const { ::getyx(w, y, x); }
929 // Get current position of the cursor
931 void getbegyx(int& y, int& x) const { ::getbegyx(w, y, x); }
932 // Get beginning of the window
934 void getmaxyx(int& y, int& x) const { ::getmaxyx(w, y, x); }
935 // Get size of the window
937 void getparyx(int& y, int& x) const { ::getparyx(w, y, x); }
938 // Get parent's beginning of the window
940 int mvcur(int oldrow, int oldcol, int newrow, int newcol) const {
941 return ::mvcur(oldrow, oldcol, newrow, newcol); }
942 // Perform lowlevel cursor motion that takes effect immediately.
944 // -------------------------------------------------------------------------
946 // -------------------------------------------------------------------------
947 int getch() { return ::wgetch(w); }
948 // Get a keystroke from the window.
950 int getch(int y, int x) { return ::mvwgetch(w, y, x); }
951 // Move cursor to position and get a keystroke from the window
953 int getstr(char* str, int n=-1) {
954 return ::wgetnstr(w, str, n); }
955 // Read a series of characters into str until a newline or carriage return
956 // is received. Read at most n characters. If n is negative, the limit is
959 int getstr(int y, int x, char* str, int n=-1) {
960 return ::mvwgetnstr(w, y, x, str, n); }
961 // Move the cursor to the requested position and then perform the getstr()
962 // as described above.
964 int instr(char *s, int n=-1) { return ::winnstr(w, s, n); }
965 // Get a string of characters from the window into the buffer s. Retrieve
966 // at most n characters, if n is negative retrieve all characters up to the
967 // end of the current line. Attributes are stripped from the characters.
969 int instr(int y, int x, char *s, int n=-1) {
970 return ::mvwinnstr(w, y, x, s, n); }
971 // Move the cursor to the requested position and then perform the instr()
972 // as described above.
974 int scanw(const char* fmt, ...)
975 // Perform a scanw function from the window.
977 __attribute__ ((format (scanf, 2, 3)));
982 int scanw(const char*, va_list);
983 // Perform a scanw function from the window.
985 int scanw(int y, int x, const char* fmt, ...)
986 // Move the cursor to the requested position and then perform a scanw
989 __attribute__ ((format (scanf, 4, 5)));
994 int scanw(int y, int x, const char* fmt, va_list);
995 // Move the cursor to the requested position and then perform a scanw
998 // -------------------------------------------------------------------------
1000 // -------------------------------------------------------------------------
1001 int addch(const chtype ch) { return ::waddch(w, ch); }
1002 // Put attributed character to the window.
1004 int addch(int y, int x, const chtype ch) {
1005 return ::mvwaddch(w, y, x, ch); }
1006 // Move cursor to the requested position and then put attributed character
1009 int echochar(const chtype ch) { return ::wechochar(w, ch); }
1010 // Put attributed character to the window and refresh it immediately.
1012 int addstr(const char* str, int n=-1) {
1013 return ::waddnstr(w, str, n); }
1014 // Write the string str to the window, stop writing if the terminating
1015 // NUL or the limit n is reached. If n is negative, it is ignored.
1017 int addstr(int y, int x, const char * str, int n=-1) {
1018 return ::mvwaddnstr(w, y, x, str, n); }
1019 // Move the cursor to the requested position and then perform the addchstr
1020 // as described above.
1022 int addchstr(const chtype* str, int n=-1) {
1023 return ::waddchnstr(w, str, n); }
1024 // Write the string str to the window, stop writing if the terminating
1025 // NUL or the limit n is reached. If n is negative, it is ignored.
1027 int addchstr(int y, int x, const chtype * str, int n=-1) {
1028 return ::mvwaddchnstr(w, y, x, str, n); }
1029 // Move the cursor to the requested position and then perform the addchstr
1030 // as described above.
1032 int printw(const char* fmt, ...)
1033 // Do a formatted print to the window.
1034 #if (__GNUG__ >= 2) && !defined(printf)
1035 __attribute__ ((format (printf, 2, 3)));
1040 int printw(int y, int x, const char * fmt, ...)
1041 // Move the cursor and then do a formatted print to the window.
1042 #if (__GNUG__ >= 2) && !defined(printf)
1043 __attribute__ ((format (printf, 4, 5)));
1048 int printw(const char* fmt, va_list args);
1049 // Do a formatted print to the window.
1051 int printw(int y, int x, const char * fmt, va_list args);
1052 // Move the cursor and then do a formatted print to the window.
1054 chtype inch() const { return ::winch(w); }
1055 // Retrieve attributed character under the current cursor position.
1057 chtype inch(int y, int x) { return ::mvwinch(w, y, x); }
1058 // Move cursor to requested position and then retrieve attributed character
1059 // at this position.
1061 int inchstr(chtype* str, int n=-1) {
1062 return ::winchnstr(w, str, n); }
1063 // Read the string str from the window, stop reading if the terminating
1064 // NUL or the limit n is reached. If n is negative, it is ignored.
1066 int inchstr(int y, int x, chtype * str, int n=-1) {
1067 return ::mvwinchnstr(w, y, x, str, n); }
1068 // Move the cursor to the requested position and then perform the inchstr
1069 // as described above.
1071 int insch(chtype ch) { return ::winsch(w, ch); }
1072 // Insert attributed character into the window before current cursor
1075 int insch(int y, int x, chtype ch) {
1076 return ::mvwinsch(w, y, x, ch); }
1077 // Move cursor to requested position and then insert the attributed
1078 // character before that position.
1080 int insertln() { return ::winsdelln(w, 1); }
1081 // Insert an empty line above the current line.
1083 int insdelln(int n=1) { return ::winsdelln(w, n); }
1084 // If n>0 insert that many lines above the current line. If n<0 delete
1085 // that many lines beginning with the current line.
1087 int insstr(const char *s, int n=-1) {
1088 return ::winsnstr(w, s, n); }
1089 // Insert the string into the window before the current cursor position.
1090 // Insert stops at end of string or when the limit n is reached. If n is
1091 // negative, it is ignored.
1093 int insstr(int y, int x, const char *s, int n=-1) {
1094 return ::mvwinsnstr(w, y, x, s, n); }
1095 // Move the cursor to the requested position and then perform the insstr()
1096 // as described above.
1098 int attron (chtype at) { return ::wattron (w, at); }
1099 // Switch on the window attributes;
1101 int attroff(chtype at) { return ::wattroff(w, static_cast<int>(at)); }
1102 // Switch off the window attributes;
1104 int attrset(chtype at) { return ::wattrset(w, static_cast<int>(at)); }
1105 // Set the window attributes;
1107 chtype attrget() { return ::getattrs(w); }
1108 // Get the window attributes;
1110 int color_set(NCURSES_PAIRS_T color_pair_number, void* opts=NULL) {
1111 return ::wcolor_set(w, color_pair_number, opts); }
1112 // Set the window color attribute;
1114 int chgat(int n, attr_t attr, NCURSES_PAIRS_T color, const void *opts=NULL) {
1115 return ::wchgat(w, n, attr, color, opts); }
1116 // Change the attributes of the next n characters in the current line. If
1117 // n is negative or greater than the number of remaining characters in the
1118 // line, the attributes will be changed up to the end of the line.
1120 int chgat(int y, int x,
1121 int n, attr_t attr, NCURSES_PAIRS_T color, const void *opts=NULL) {
1122 return ::mvwchgat(w, y, x, n, attr, color, opts); }
1123 // Move the cursor to the requested position and then perform chgat() as
1126 // -------------------------------------------------------------------------
1128 // -------------------------------------------------------------------------
1129 chtype getbkgd() const { return ::getbkgd(w); }
1130 // Get current background setting.
1132 int bkgd(const chtype ch) { return ::wbkgd(w, ch); }
1133 // Set the background property and apply it to the window.
1135 void bkgdset(chtype ch) { ::wbkgdset(w, ch); }
1136 // Set the background property.
1138 // -------------------------------------------------------------------------
1140 // -------------------------------------------------------------------------
1141 int box(chtype vert=0, chtype hor=0) {
1142 return ::wborder(w, vert, vert, hor, hor, 0, 0, 0, 0); }
1143 // Draw a box around the window with the given vertical and horizontal
1144 // drawing characters. If you specify a zero as character, curses will try
1145 // to find a "nice" character.
1147 int border(chtype left=0, chtype right=0,
1148 chtype top =0, chtype bottom=0,
1149 chtype top_left =0, chtype top_right=0,
1150 chtype bottom_left =0, chtype bottom_right=0) {
1151 return ::wborder(w, left, right, top, bottom, top_left, top_right,
1152 bottom_left, bottom_right); }
1153 // Draw a border around the window with the given characters for the
1154 // various parts of the border. If you pass zero for a character, curses
1155 // will try to find "nice" characters.
1157 // -------------------------------------------------------------------------
1159 // -------------------------------------------------------------------------
1160 int hline(int len, chtype ch=0) { return ::whline(w, ch, len); }
1161 // Draw a horizontal line of len characters with the given character. If
1162 // you pass zero for the character, curses will try to find a "nice" one.
1164 int hline(int y, int x, int len, chtype ch=0) {
1165 return ::mvwhline(w, y, x, ch, len); }
1166 // Move the cursor to the requested position and then draw a horizontal line.
1168 int vline(int len, chtype ch=0) { return ::wvline(w, ch, len); }
1169 // Draw a vertical line of len characters with the given character. If
1170 // you pass zero for the character, curses will try to find a "nice" one.
1172 int vline(int y, int x, int len, chtype ch=0) {
1173 return ::mvwvline(w, y, x, ch, len); }
1174 // Move the cursor to the requested position and then draw a vertical line.
1176 // -------------------------------------------------------------------------
1178 // -------------------------------------------------------------------------
1179 int erase() { return ::werase(w); }
1180 // Erase the window.
1182 int clear() { return ::wclear(w); }
1183 // Clear the window.
1185 int clearok(bool bf) { return ::clearok(w, bf); }
1186 // Set/Reset the clear flag. If set, the next refresh() will clear the
1189 int clrtobot() { return ::wclrtobot(w); }
1190 // Clear to the end of the window.
1192 int clrtoeol() { return ::wclrtoeol(w); }
1193 // Clear to the end of the line.
1195 int delch() { return ::wdelch(w); }
1196 // Delete character under the cursor.
1198 int delch(int y, int x) { return ::mvwdelch(w, y, x); }
1199 // Move cursor to requested position and delete the character under the
1202 int deleteln() { return ::winsdelln(w, -1); }
1203 // Delete the current line.
1205 // -------------------------------------------------------------------------
1207 // -------------------------------------------------------------------------
1208 int scroll(int amount=1) { return ::wscrl(w, amount); }
1209 // Scroll amount lines. If amount is positive, scroll up, otherwise
1212 int scrollok(bool bf) { return ::scrollok(w, bf); }
1213 // If bf is TRUE, window scrolls if cursor is moved off the bottom
1214 // edge of the window or a scrolling region, otherwise the cursor is left
1215 // at the bottom line.
1217 int setscrreg(int from, int to) {
1218 return ::wsetscrreg(w, from, to); }
1219 // Define a soft scrolling region.
1221 int idlok(bool bf) { return ::idlok(w, bf); }
1222 // If bf is TRUE, use insert/delete line hardware support if possible.
1223 // Otherwise do it in software.
1225 void idcok(bool bf) { ::idcok(w, bf); }
1226 // If bf is TRUE, use insert/delete character hardware support if possible.
1227 // Otherwise do it in software.
1229 int touchline(int s, int c) { return ::touchline(w, s, c); }
1230 // Mark the given lines as modified.
1232 int touchwin() { return ::wtouchln(w, 0, height(), 1); }
1233 // Mark the whole window as modified.
1235 int untouchwin() { return ::wtouchln(w, 0, height(), 0); }
1236 // Mark the whole window as unmodified.
1238 int touchln(int s, int cnt, bool changed=TRUE) {
1239 return ::wtouchln(w, s, cnt, static_cast<int>(changed ? 1 : 0)); }
1240 // Mark cnt lines beginning from line s as changed or unchanged, depending
1241 // on the value of the changed flag.
1243 bool is_linetouched(int line) const {
1244 return (::is_linetouched(w, line) ? TRUE:FALSE); }
1245 // Return TRUE if line is marked as changed, FALSE otherwise
1247 bool is_wintouched() const {
1248 return (::is_wintouched(w) ? TRUE:FALSE); }
1249 // Return TRUE if window is marked as changed, FALSE otherwise
1251 int leaveok(bool bf) { return ::leaveok(w, bf); }
1252 // If bf is TRUE, curses will leave the cursor after an update whereever
1253 // it is after the update.
1255 int redrawln(int from, int n) { return ::wredrawln(w, from, n); }
1256 // Redraw n lines starting from the requested line
1258 int redrawwin() { return ::wredrawln(w, 0, height()); }
1259 // Redraw the whole window
1261 int doupdate() { return ::doupdate(); }
1262 // Do all outputs to make the physical screen looking like the virtual one
1264 void syncdown() { ::wsyncdown(w); }
1265 // Propagate the changes down to all descendant windows
1267 void syncup() { ::wsyncup(w); }
1268 // Propagate the changes up in the hierarchy
1270 void cursyncup() { ::wcursyncup(w); }
1271 // Position the cursor in all ancestor windows corresponding to our setting
1273 int syncok(bool bf) { return ::syncok(w, bf); }
1274 // If called with bf=TRUE, syncup() is called whenever the window is changed
1277 int flushok(bool bf) { return ::flushok(w, bf); }
1280 void immedok(bool bf) { ::immedok(w, bf); }
1281 // If called with bf=TRUE, any change in the window will cause an
1282 // automatic immediate refresh()
1284 int intrflush(bool bf) { return ::intrflush(w, bf); }
1286 int keypad(bool bf) { return ::keypad(w, bf); }
1287 // If called with bf=TRUE, the application will interpret function keys.
1289 int nodelay(bool bf) { return ::nodelay(w, bf); }
1291 int meta(bool bf) { return ::meta(w, bf); }
1292 // If called with bf=TRUE, keys may generate 8-Bit characters. Otherwise
1293 // 7-Bit characters are generated.
1295 int standout() { return ::wstandout(w); }
1296 // Enable "standout" attributes
1298 int standend() { return ::wstandend(w); }
1299 // Disable "standout" attributes
1301 // -------------------------------------------------------------------------
1302 // The next two are virtual, because we redefine them in the
1303 // NCursesPanel class.
1304 // -------------------------------------------------------------------------
1305 virtual int refresh() { return ::wrefresh(w); }
1306 // Propagate the changes in this window to the virtual screen and call
1307 // doupdate(). This is redefined in NCursesPanel.
1309 virtual int noutrefresh() { return ::wnoutrefresh(w); }
1310 // Propagate the changes in this window to the virtual screen. This is
1311 // redefined in NCursesPanel.
1313 // -------------------------------------------------------------------------
1314 // multiple window control
1315 // -------------------------------------------------------------------------
1316 int overlay(NCursesWindow& win) {
1317 return ::overlay(w, win.w); }
1318 // Overlay this window over win.
1320 int overwrite(NCursesWindow& win) {
1321 return ::overwrite(w, win.w); }
1322 // Overwrite win with this window.
1324 int copywin(NCursesWindow& win,
1325 int sminrow, int smincol,
1326 int dminrow, int dmincol,
1327 int dmaxrow, int dmaxcol, bool overlaywin=TRUE) {
1328 return ::copywin(w, win.w, sminrow, smincol, dminrow, dmincol,
1329 dmaxrow, dmaxcol, static_cast<int>(overlaywin ? 1 : 0)); }
1330 // Overlay or overwrite the rectangle in win given by dminrow,dmincol,
1331 // dmaxrow,dmaxcol with the rectangle in this window beginning at
1334 // -------------------------------------------------------------------------
1335 // Extended functions
1336 // -------------------------------------------------------------------------
1337 #if defined(NCURSES_EXT_FUNCS) && (NCURSES_EXT_FUNCS != 0)
1338 int wresize(int newLines, int newColumns) {
1339 return ::wresize(w, newLines, newColumns); }
1342 // -------------------------------------------------------------------------
1344 // -------------------------------------------------------------------------
1345 bool has_mouse() const;
1346 // Return TRUE if terminal supports a mouse, FALSE otherwise
1348 // -------------------------------------------------------------------------
1349 // traversal support
1350 // -------------------------------------------------------------------------
1351 NCursesWindow* child() { return subwins; }
1352 // Get the first child window.
1354 NCursesWindow* sibling() { return sib; }
1355 // Get the next child of my parent.
1357 NCursesWindow* parent() { return par; }
1360 bool isDescendant(NCursesWindow& win);
1361 // Return TRUE if win is a descendant of this.
1364 // -------------------------------------------------------------------------
1365 // We leave this here for compatibility reasons.
1366 // -------------------------------------------------------------------------
1367 class NCURSES_IMPEXP NCursesColorWindow : public NCursesWindow
1370 NCursesColorWindow(WINDOW* &window) // useful only for stdscr
1371 : NCursesWindow(window) {
1374 NCursesColorWindow(int nlines, // number of lines
1375 int ncols, // number of columns
1376 int begin_y, // line origin
1377 int begin_x) // col origin
1378 : NCursesWindow(nlines, ncols, begin_y, begin_x) {
1381 NCursesColorWindow(NCursesWindow& parentWin,// parent window
1382 int nlines, // number of lines
1383 int ncols, // number of columns
1384 int begin_y, // absolute or relative
1385 int begin_x, // origins:
1386 char absrel = 'a') // if `a', by & bx are
1387 : NCursesWindow(parentWin,
1388 nlines, ncols, // absolute screen pos,
1389 begin_y, begin_x, // else if `r', they are
1390 absrel ) { // relative to par origin
1394 // These enum definitions really belong inside the NCursesPad class, but only
1395 // recent compilers support that feature.
1398 REQ_PAD_REFRESH = KEY_MAX + 1,
1406 const Pad_Request PAD_LOW = REQ_PAD_REFRESH; // lowest op-code
1407 const Pad_Request PAD_HIGH = REQ_PAD_EXIT; // highest op-code
1409 // -------------------------------------------------------------------------
1410 // Pad Support. We allow an association of a pad with a "real" window
1411 // through which the pad may be viewed.
1412 // -------------------------------------------------------------------------
1413 class NCURSES_IMPEXP NCursesPad : public NCursesWindow
1416 NCursesWindow* viewWin; // the "viewport" window
1417 NCursesWindow* viewSub; // the "viewport" subwindow
1419 int h_gridsize, v_gridsize;
1422 int min_row, min_col; // top left row/col of the pads display area
1424 NCursesWindow* Win(void) const {
1425 // Get the window into which the pad should be copied (if any)
1426 return (viewSub?viewSub:(viewWin?viewWin:0));
1429 NCursesWindow* getWindow(void) const {
1433 NCursesWindow* getSubWindow(void) const {
1437 virtual int driver (int key); // Virtualize keystroke key
1438 // The driver translates the keystroke c into an Pad_Request
1440 virtual void OnUnknownOperation(int pad_req) {
1444 // This is called if the driver returns an unknown op-code
1446 virtual void OnNavigationError(int pad_req) {
1450 // This is called if a navigation request couldn't be satisfied
1452 virtual void OnOperation(int pad_req) {
1455 // OnOperation is called if a Pad_Operation was executed and just before
1456 // the refresh() operation is done.
1459 NCursesPad(int nlines, int ncols);
1460 // create a pad with the given size
1462 NCursesPad& operator=(const NCursesPad& rhs)
1466 NCursesWindow::operator=(rhs);
1471 NCursesPad(const NCursesPad& rhs)
1472 : NCursesWindow(rhs),
1473 viewWin(rhs.viewWin),
1474 viewSub(rhs.viewSub),
1475 h_gridsize(rhs.h_gridsize),
1476 v_gridsize(rhs.v_gridsize),
1477 min_row(rhs.min_row),
1478 min_col(rhs.min_col)
1482 virtual ~NCursesPad() {}
1484 int echochar(const chtype ch) { return ::pechochar(w, ch); }
1485 // Put the attributed character onto the pad and immediately do a
1489 // If a viewport is defined the pad is displayed in this window, otherwise
1492 int refresh(int pminrow, int pmincol,
1493 int sminrow, int smincol,
1494 int smaxrow, int smaxcol) {
1495 return ::prefresh(w, pminrow, pmincol,
1496 sminrow, smincol, smaxrow, smaxcol);
1498 // The coordinates sminrow,smincol,smaxrow,smaxcol describe a rectangle
1499 // on the screen. <b>refresh</b> copies a rectangle of this size beginning
1500 // with top left corner pminrow,pmincol onto the screen and calls doupdate().
1503 // If a viewport is defined the pad is displayed in this window, otherwise
1506 int noutrefresh(int pminrow, int pmincol,
1507 int sminrow, int smincol,
1508 int smaxrow, int smaxcol) {
1509 return ::pnoutrefresh(w, pminrow, pmincol,
1510 sminrow, smincol, smaxrow, smaxcol);
1512 // Does the same as refresh() but without calling doupdate().
1514 virtual void setWindow(NCursesWindow& view, int v_grid = 1, int h_grid = 1);
1515 // Add the window "view" as viewing window to the pad.
1517 virtual void setSubWindow(NCursesWindow& sub);
1518 // Use the subwindow "sub" of the viewport window for the actual viewing.
1519 // The full viewport window is usually used to provide some decorations
1520 // like frames, titles etc.
1522 virtual void operator() (void);
1523 // Perform Pad's operation
1526 // A FramedPad is constructed always with a viewport window. This viewport
1527 // will be framed (by a box() command) and the interior of the box is the
1528 // viewport subwindow. On the frame we display scrollbar sliders.
1529 class NCURSES_IMPEXP NCursesFramedPad : public NCursesPad
1532 virtual void OnOperation(int pad_req);
1535 NCursesFramedPad(NCursesWindow& win, int nlines, int ncols,
1536 int v_grid = 1, int h_grid = 1)
1537 : NCursesPad(nlines, ncols) {
1538 NCursesPad::setWindow(win, v_grid, h_grid);
1539 NCursesPad::setSubWindow(*(new NCursesWindow(win)));
1541 // Construct the FramedPad with the given Window win as viewport.
1543 virtual ~NCursesFramedPad() {
1544 delete getSubWindow();
1547 void setWindow(NCursesWindow& view, int v_grid = 1, int h_grid = 1) {
1551 err_handler("Operation not allowed");
1553 // Disable this call; the viewport is already defined
1555 void setSubWindow(NCursesWindow& sub) {
1557 err_handler("Operation not allowed");
1559 // Disable this call; the viewport subwindow is already defined
1563 #endif /* NCURSES_CURSESW_H_incl */