1 // * This makes emacs happy -*-Mode: C++;-*-
3 /****************************************************************************
4 * Copyright 2019,2020 Thomas E. Dickey *
5 * Copyright 1998-2014,2017 Free Software Foundation, Inc. *
7 * Permission is hereby granted, free of charge, to any person obtaining a *
8 * copy of this software and associated documentation files (the *
9 * "Software"), to deal in the Software without restriction, including *
10 * without limitation the rights to use, copy, modify, merge, publish, *
11 * distribute, distribute with modifications, sublicense, and/or sell *
12 * copies of the Software, and to permit persons to whom the Software is *
13 * furnished to do so, subject to the following conditions: *
15 * The above copyright notice and this permission notice shall be included *
16 * in all copies or substantial portions of the Software. *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
21 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
24 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
26 * Except as contained in this notice, the name(s) of the above copyright *
27 * holders shall not be used in advertising or otherwise to promote the *
28 * sale, use or other dealings in this Software without prior written *
30 ****************************************************************************/
32 #ifndef NCURSES_CURSESW_H_incl
33 #define NCURSES_CURSESW_H_incl 1
35 // $Id: cursesw.h,v 1.56 2020/02/02 23:34:34 tom Exp $
43 /* SCO 3.2v4 curses.h includes term.h, which defines lines as a macro.
44 Undefine it here, because NCursesWindow uses lines as a method. */
47 /* "Convert" macros to inlines. We'll define it as another symbol to avoid
48 * conflict with library symbols.
51 #define UNDEF(name) CUR_ ##name
54 inline int UNDEF(addch)(chtype ch) { return addch(ch); }
56 #define addch UNDEF(addch)
60 inline int UNDEF(addchstr)(chtype *at) { return addchstr(at); }
62 #define addchstr UNDEF(addchstr)
66 inline int UNDEF(addnstr)(const char *str, int n)
67 { return addnstr(str, n); }
69 #define addnstr UNDEF(addnstr)
73 inline int UNDEF(addstr)(const char * str) { return addstr(str); }
75 #define addstr UNDEF(addstr)
79 inline int UNDEF(attroff)(chtype at) { return attroff(at); }
81 #define attroff UNDEF(attroff)
85 inline int UNDEF(attron)(chtype at) { return attron(at); }
87 #define attron UNDEF(attron)
91 inline chtype UNDEF(attrset)(chtype at) { return attrset(at); }
93 #define attrset UNDEF(attrset)
97 inline int UNDEF(bkgd)(chtype ch) { return bkgd(ch); }
99 #define bkgd UNDEF(bkgd)
103 inline void UNDEF(bkgdset)(chtype ch) { bkgdset(ch); }
105 #define bkgdset UNDEF(bkgdset)
109 inline int UNDEF(border)(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, chtype tr, chtype bl, chtype br)
110 { return border(ls, rs, ts, bs, tl, tr, bl, br); }
112 #define border UNDEF(border)
116 inline int UNDEF(box)(WINDOW *win, int v, int h) { return box(win, v, h); }
118 #define box UNDEF(box)
122 inline int UNDEF(chgat)(int n, attr_t attr, NCURSES_PAIRS_T color, const void *opts) {
123 return chgat(n, attr, color, opts); }
125 #define chgat UNDEF(chgat)
129 inline int UNDEF(clear)() { return clear(); }
131 #define clear UNDEF(clear)
135 inline int UNDEF(clearok)(WINDOW* win, bool bf) { return clearok(win, bf); }
137 #define clearok UNDEF(clearok)
139 extern "C" NCURSES_IMPEXP int NCURSES_API clearok(WINDOW*, bool);
143 inline int UNDEF(clrtobot)() { return clrtobot(); }
145 #define clrtobot UNDEF(clrtobot)
149 inline int UNDEF(clrtoeol)() { return clrtoeol(); }
151 #define clrtoeol UNDEF(clrtoeol)
155 inline chtype UNDEF(color_set)(NCURSES_PAIRS_T p, void* opts) { return color_set(p, opts); }
157 #define color_set UNDEF(color_set)
161 inline int UNDEF(crmode)(void) { return crmode(); }
163 #define crmode UNDEF(crmode)
167 inline int UNDEF(delch)() { return delch(); }
169 #define delch UNDEF(delch)
173 inline int UNDEF(deleteln)() { return deleteln(); }
175 #define deleteln UNDEF(deleteln)
179 inline int UNDEF(echochar)(chtype ch) { return echochar(ch); }
181 #define echochar UNDEF(echochar)
185 inline int UNDEF(erase)() { return erase(); }
187 #define erase UNDEF(erase)
191 inline int UNDEF(fixterm)(void) { return fixterm(); }
193 #define fixterm UNDEF(fixterm)
197 inline int UNDEF(flushok)(WINDOW* _win, bool _bf) {
198 return flushok(_win, _bf); }
200 #define flushok UNDEF(flushok)
206 inline int UNDEF(getattrs)(WINDOW *win) { return getattrs(win); }
208 #define getattrs UNDEF(getattrs)
212 inline void UNDEF(getbegyx)(WINDOW* win, int& y, int& x) { getbegyx(win, y, x); }
214 #define getbegyx UNDEF(getbegyx)
218 inline chtype UNDEF(getbkgd)(const WINDOW *win) { return getbkgd(win); }
220 #define getbkgd UNDEF(getbkgd)
224 inline int UNDEF(getch)() { return getch(); }
226 #define getch UNDEF(getch)
230 inline void UNDEF(getmaxyx)(WINDOW* win, int& y, int& x) { getmaxyx(win, y, x); }
232 #define getmaxyx UNDEF(getmaxyx)
236 inline int UNDEF(getnstr)(char *_str, int n) { return getnstr(_str, n); }
238 #define getnstr UNDEF(getnstr)
242 inline void UNDEF(getparyx)(WINDOW* win, int& y, int& x) { getparyx(win, y, x); }
244 #define getparyx UNDEF(getparyx)
248 inline int UNDEF(getstr)(char *_str) { return getstr(_str); }
250 #define getstr UNDEF(getstr)
254 inline void UNDEF(getyx)(const WINDOW* win, int& y, int& x) {
257 #define getyx UNDEF(getyx)
261 inline int UNDEF(hline)(chtype ch, int n) { return hline(ch, n); }
263 #define hline UNDEF(hline)
267 inline chtype UNDEF(inch)() { return inch(); }
269 #define inch UNDEF(inch)
273 inline int UNDEF(inchstr)(chtype *str) { return inchstr(str); }
275 #define inchstr UNDEF(inchstr)
279 inline int UNDEF(innstr)(char *_str, int n) { return innstr(_str, n); }
281 #define innstr UNDEF(innstr)
285 inline int UNDEF(insch)(chtype c) { return insch(c); }
287 #define insch UNDEF(insch)
291 inline int UNDEF(insdelln)(int n) { return insdelln(n); }
293 #define insdelln UNDEF(insdelln)
297 inline int UNDEF(insertln)() { return insertln(); }
299 #define insertln UNDEF(insertln)
303 inline int UNDEF(insnstr)(const char *_str, int n) {
304 return insnstr(_str, n); }
306 #define insnstr UNDEF(insnstr)
310 inline int UNDEF(insstr)(const char *_str) {
311 return insstr(_str); }
313 #define insstr UNDEF(insstr)
317 inline int UNDEF(instr)(char *_str) { return instr(_str); }
319 #define instr UNDEF(instr)
323 inline void UNDEF(intrflush)(WINDOW *win, bool bf) { intrflush(); }
325 #define intrflush UNDEF(intrflush)
328 #ifdef is_linetouched
329 inline int UNDEF(is_linetouched)(WINDOW *w, int l) { return is_linetouched(w,l); }
330 #undef is_linetouched
331 #define is_linetouched UNDEF(is_linetouched)
335 inline int UNDEF(leaveok)(WINDOW* win, bool bf) { return leaveok(win, bf); }
337 #define leaveok UNDEF(leaveok)
339 extern "C" NCURSES_IMPEXP int NCURSES_API leaveok(WINDOW* win, bool bf);
343 inline int UNDEF(move)(int x, int y) { return move(x, y); }
345 #define move UNDEF(move)
349 inline int UNDEF(mvaddch)(int y, int x, chtype ch)
350 { return mvaddch(y, x, ch); }
352 #define mvaddch UNDEF(mvaddch)
356 inline int UNDEF(mvaddnstr)(int y, int x, const char *str, int n)
357 { return mvaddnstr(y, x, str, n); }
359 #define mvaddnstr UNDEF(mvaddnstr)
363 inline int UNDEF(mvaddstr)(int y, int x, const char * str)
364 { return mvaddstr(y, x, str); }
366 #define mvaddstr UNDEF(mvaddstr)
370 inline int UNDEF(mvchgat)(int y, int x, int n,
371 attr_t attr, NCURSES_PAIRS_T color, const void *opts) {
372 return mvchgat(y, x, n, attr, color, opts); }
374 #define mvchgat UNDEF(mvchgat)
378 inline int UNDEF(mvdelch)(int y, int x) { return mvdelch(y, x);}
380 #define mvdelch UNDEF(mvdelch)
384 inline int UNDEF(mvgetch)(int y, int x) { return mvgetch(y, x);}
386 #define mvgetch UNDEF(mvgetch)
390 inline int UNDEF(mvgetnstr)(int y, int x, char *str, int n) {
391 return mvgetnstr(y, x, str, n);}
393 #define mvgetnstr UNDEF(mvgetnstr)
397 inline int UNDEF(mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
399 #define mvgetstr UNDEF(mvgetstr)
403 inline chtype UNDEF(mvinch)(int y, int x) { return mvinch(y, x);}
405 #define mvinch UNDEF(mvinch)
409 inline int UNDEF(mvinnstr)(int y, int x, char *_str, int n) {
410 return mvinnstr(y, x, _str, n); }
412 #define mvinnstr UNDEF(mvinnstr)
416 inline int UNDEF(mvinsch)(int y, int x, chtype c)
417 { return mvinsch(y, x, c); }
419 #define mvinsch UNDEF(mvinsch)
423 inline int UNDEF(mvinsnstr)(int y, int x, const char *_str, int n) {
424 return mvinsnstr(y, x, _str, n); }
426 #define mvinsnstr UNDEF(mvinsnstr)
430 inline int UNDEF(mvinsstr)(int y, int x, const char *_str) {
431 return mvinsstr(y, x, _str); }
433 #define mvinsstr UNDEF(mvinsstr)
437 inline int UNDEF(mvwaddch)(WINDOW *win, int y, int x, const chtype ch)
438 { return mvwaddch(win, y, x, ch); }
440 #define mvwaddch UNDEF(mvwaddch)
444 inline int UNDEF(mvwaddchnstr)(WINDOW *win, int y, int x, const chtype *str, int n)
445 { return mvwaddchnstr(win, y, x, str, n); }
447 #define mvwaddchnstr UNDEF(mvwaddchnstr)
451 inline int UNDEF(mvwaddchstr)(WINDOW *win, int y, int x, const chtype *str)
452 { return mvwaddchstr(win, y, x, str); }
454 #define mvwaddchstr UNDEF(mvwaddchstr)
458 inline int UNDEF(mvwaddnstr)(WINDOW *win, int y, int x, const char *str, int n)
459 { return mvwaddnstr(win, y, x, str, n); }
461 #define mvwaddnstr UNDEF(mvwaddnstr)
465 inline int UNDEF(mvwaddstr)(WINDOW *win, int y, int x, const char * str)
466 { return mvwaddstr(win, y, x, str); }
468 #define mvwaddstr UNDEF(mvwaddstr)
472 inline int UNDEF(mvwchgat)(WINDOW *win, int y, int x, int n,
473 attr_t attr, NCURSES_PAIRS_T color, const void *opts) {
474 return mvwchgat(win, y, x, n, attr, color, opts); }
476 #define mvwchgat UNDEF(mvwchgat)
480 inline int UNDEF(mvwdelch)(WINDOW *win, int y, int x)
481 { return mvwdelch(win, y, x); }
483 #define mvwdelch UNDEF(mvwdelch)
487 inline int UNDEF(mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
489 #define mvwgetch UNDEF(mvwgetch)
493 inline int UNDEF(mvwgetnstr)(WINDOW *win, int y, int x, char *str, int n)
494 {return mvwgetnstr(win, y, x, str, n);}
496 #define mvwgetnstr UNDEF(mvwgetnstr)
500 inline int UNDEF(mvwgetstr)(WINDOW *win, int y, int x, char *str)
501 {return mvwgetstr(win, y, x, str);}
503 #define mvwgetstr UNDEF(mvwgetstr)
507 inline int UNDEF(mvwhline)(WINDOW *win, int y, int x, chtype c, int n) {
508 return mvwhline(win, y, x, c, n); }
510 #define mvwhline UNDEF(mvwhline)
514 inline chtype UNDEF(mvwinch)(WINDOW *win, int y, int x) {
515 return mvwinch(win, y, x);}
517 #define mvwinch UNDEF(mvwinch)
521 inline int UNDEF(mvwinchnstr)(WINDOW *win, int y, int x, chtype *str, int n) { return mvwinchnstr(win, y, x, str, n); }
523 #define mvwinchnstr UNDEF(mvwinchnstr)
527 inline int UNDEF(mvwinchstr)(WINDOW *win, int y, int x, chtype *str) { return mvwinchstr(win, y, x, str); }
529 #define mvwinchstr UNDEF(mvwinchstr)
533 inline int UNDEF(mvwinnstr)(WINDOW *win, int y, int x, char *_str, int n) {
534 return mvwinnstr(win, y, x, _str, n); }
536 #define mvwinnstr UNDEF(mvwinnstr)
540 inline int UNDEF(mvwinsch)(WINDOW *win, int y, int x, chtype c)
541 { return mvwinsch(win, y, x, c); }
543 #define mvwinsch UNDEF(mvwinsch)
547 inline int UNDEF(mvwinsnstr)(WINDOW *w, int y, int x, const char *_str, int n) {
548 return mvwinsnstr(w, y, x, _str, n); }
550 #define mvwinsnstr UNDEF(mvwinsnstr)
554 inline int UNDEF(mvwinsstr)(WINDOW *w, int y, int x, const char *_str) {
555 return mvwinsstr(w, y, x, _str); }
557 #define mvwinsstr UNDEF(mvwinsstr)
561 inline int UNDEF(mvwvline)(WINDOW *win, int y, int x, chtype c, int n) {
562 return mvwvline(win, y, x, c, n); }
564 #define mvwvline UNDEF(mvwvline)
568 inline void UNDEF(napms)(unsigned long x) { napms(x); }
570 #define napms UNDEF(napms)
574 inline int UNDEF(nocrmode)(void) { return nocrmode(); }
576 #define nocrmode UNDEF(nocrmode)
580 inline void UNDEF(nodelay)() { nodelay(); }
582 #define nodelay UNDEF(nodelay)
586 inline int UNDEF(redrawwin)(WINDOW *win) { return redrawwin(win); }
588 #define redrawwin UNDEF(redrawwin)
592 inline int UNDEF(refresh)() { return refresh(); }
594 #define refresh UNDEF(refresh)
598 inline int UNDEF(resetterm)(void) { return resetterm(); }
600 #define resetterm UNDEF(resetterm)
604 inline int UNDEF(saveterm)(void) { return saveterm(); }
606 #define saveterm UNDEF(saveterm)
610 inline int UNDEF(scrl)(int l) { return scrl(l); }
612 #define scrl UNDEF(scrl)
616 inline int UNDEF(scroll)(WINDOW *win) { return scroll(win); }
618 #define scroll UNDEF(scroll)
622 inline int UNDEF(scrollok)(WINDOW* win, bool bf) { return scrollok(win, bf); }
624 #define scrollok UNDEF(scrollok)
626 #if defined(__NCURSES_H)
627 extern "C" NCURSES_IMPEXP int NCURSES_API scrollok(WINDOW*, bool);
629 extern "C" NCURSES_IMPEXP int NCURSES_API scrollok(WINDOW*, char);
634 inline int UNDEF(setscrreg)(int t, int b) { return setscrreg(t, b); }
636 #define setscrreg UNDEF(setscrreg)
640 inline int UNDEF(standend)() { return standend(); }
642 #define standend UNDEF(standend)
646 inline int UNDEF(standout)() { return standout(); }
648 #define standout UNDEF(standout)
652 inline WINDOW *UNDEF(subpad)(WINDOW *p, int l, int c, int y, int x)
653 { return derwin(p, l, c, y, x); }
655 #define subpad UNDEF(subpad)
659 inline void UNDEF(timeout)(int delay) { timeout(delay); }
661 #define timeout UNDEF(timeout)
665 inline int UNDEF(touchline)(WINDOW *win, int s, int c)
666 { return touchline(win, s, c); }
668 #define touchline UNDEF(touchline)
672 inline int UNDEF(touchwin)(WINDOW *win) { return touchwin(win); }
674 #define touchwin UNDEF(touchwin)
678 inline int UNDEF(untouchwin)(WINDOW *win) { return untouchwin(win); }
680 #define untouchwin UNDEF(untouchwin)
684 inline int UNDEF(vline)(chtype ch, int n) { return vline(ch, n); }
686 #define vline UNDEF(vline)
690 inline int UNDEF(waddchstr)(WINDOW *win, chtype *at) { return waddchstr(win, at); }
692 #define waddchstr UNDEF(waddchstr)
696 inline int UNDEF(waddstr)(WINDOW *win, char *str) { return waddstr(win, str); }
698 #define waddstr UNDEF(waddstr)
702 inline int UNDEF(wattroff)(WINDOW *win, int att) { return wattroff(win, att); }
704 #define wattroff UNDEF(wattroff)
708 inline int UNDEF(wattrset)(WINDOW *win, int att) { return wattrset(win, att); }
710 #define wattrset UNDEF(wattrset)
714 inline chtype UNDEF(winch)(const WINDOW* win) { return winch(win); }
716 #define winch UNDEF(winch)
720 inline int UNDEF(winchnstr)(WINDOW *win, chtype *str, int n) { return winchnstr(win, str, n); }
722 #define winchnstr UNDEF(winchnstr)
726 inline int UNDEF(winchstr)(WINDOW *win, chtype *str) { return winchstr(win, str); }
728 #define winchstr UNDEF(winchstr)
732 inline int UNDEF(winsstr)(WINDOW *w, const char *_str) {
733 return winsstr(w, _str); }
735 #define winsstr UNDEF(winsstr)
739 inline int UNDEF(wstandend)(WINDOW *win) { return wstandend(win); }
741 #define wstandend UNDEF(wstandend)
745 inline int UNDEF(wstandout)(WINDOW *win) { return wstandout(win); }
747 #define wstandout UNDEF(wstandout)
752 * C++ class for windows.
756 extern "C" int _nc_ripoffline(int, int (*init)(WINDOW*, int));
757 extern "C" int _nc_xx_ripoff_init(WINDOW *, int);
758 extern "C" int _nc_has_mouse(void);
760 class NCURSES_IMPEXP NCursesWindow
762 friend class NCursesMenu;
763 friend class NCursesForm;
766 static bool b_initialized;
767 static void initialize();
769 friend int _nc_xx_ripoff_init(WINDOW *, int);
773 NCURSES_COLOR_T getcolor(int getback) const;
774 NCURSES_PAIRS_T getPair() const;
776 static int setpalette(NCURSES_COLOR_T fore, NCURSES_COLOR_T back, NCURSES_PAIRS_T pair);
777 static int colorInitialized;
779 // This private constructor is only used during the initialization
780 // of windows generated by ripoffline() calls.
781 NCursesWindow(WINDOW* win, int ncols);
784 virtual void err_handler(const char *) const THROWS(NCursesException);
785 // Signal an error with the given message text.
787 static long count; // count of all active windows:
788 // We rely on the c++ promise that
789 // all otherwise uninitialized
790 // static class vars are set to 0
792 WINDOW* w; // the curses WINDOW
794 bool alloced; // TRUE if we own the WINDOW
796 NCursesWindow* par; // parent, if subwindow
797 NCursesWindow* subwins; // head of subwindows list
798 NCursesWindow* sib; // next subwindow of parent
800 void kill_subwindows(); // disable all subwindows
801 // Destroy all subwindows.
803 /* Only for use by derived classes. They are then in charge to
804 fill the member variables correctly. */
808 NCursesWindow(WINDOW* window); // useful only for stdscr
810 NCursesWindow(int nlines, // number of lines
811 int ncols, // number of columns
812 int begin_y, // line origin
813 int begin_x); // col origin
815 NCursesWindow(NCursesWindow& par,// parent window
816 int nlines, // number of lines
817 int ncols, // number of columns
818 int begin_y, // absolute or relative
819 int begin_x, // origins:
820 char absrel = 'a');// if `a', begin_y & begin_x are
821 // absolute screen pos, else if `r', they are relative to par origin
823 NCursesWindow(NCursesWindow& par,// parent window
825 // this is the very common case that we want to create the subwindow that
826 // is two lines and two columns smaller and begins at (1,1).
827 // We may automatically request the box around it.
829 NCursesWindow& operator=(const NCursesWindow& rhs)
836 NCursesWindow(const NCursesWindow& rhs)
837 : w(rhs.w), alloced(rhs.alloced), par(rhs.par), subwins(rhs.subwins), sib(rhs.sib)
841 virtual ~NCursesWindow() THROWS(NCursesException);
843 NCursesWindow Clone();
844 // Make an exact copy of the window.
847 static void useColors(void);
848 // Call this routine very early if you want to have colors.
850 static int ripoffline(int ripoff_lines,
851 int (*init)(NCursesWindow& win));
852 // This function is used to generate a window of ripped-of lines.
853 // If the argument is positive, lines are removed from the top, if it
854 // is negative lines are removed from the bottom. This enhances the
855 // lowlevel ripoffline() function because it uses the internal
856 // implementation that allows to remove more than just a single line.
857 // This function must be called before any other ncurses function. The
858 // creation of the window is deferred until ncurses gets initialized.
859 // The initialization function is then called.
861 // -------------------------------------------------------------------------
863 // -------------------------------------------------------------------------
864 int lines() const { initialize(); return LINES; }
865 // Number of lines on terminal, *not* window
867 int cols() const { initialize(); return COLS; }
868 // Number of cols on terminal, *not* window
870 int tabsize() const { initialize(); return TABSIZE; }
871 // Size of a tab on terminal, *not* window
873 static int NumberOfColors();
874 // Number of available colors
876 int colors() const { return NumberOfColors(); }
877 // Number of available colors
879 // -------------------------------------------------------------------------
881 // -------------------------------------------------------------------------
882 int height() const { return maxy() + 1; }
883 // Number of lines in this window
885 int width() const { return maxx() + 1; }
886 // Number of columns in this window
888 int begx() const { return getbegx(w); }
889 // Column of top left corner relative to stdscr
891 int begy() const { return getbegy(w); }
892 // Line of top left corner relative to stdscr
894 int curx() const { return getcurx(w); }
895 // Column of top left corner relative to stdscr
897 int cury() const { return getcury(w); }
898 // Line of top left corner relative to stdscr
900 int maxx() const { return getmaxx(w) == ERR ? ERR : getmaxx(w)-1; }
901 // Largest x coord in window
903 int maxy() const { return getmaxy(w) == ERR ? ERR : getmaxy(w)-1; }
904 // Largest y coord in window
906 NCURSES_PAIRS_T getcolor() const;
909 NCURSES_COLOR_T foreground() const { return getcolor(0); }
910 // Actual foreground color
912 NCURSES_COLOR_T background() const { return getcolor(1); }
913 // Actual background color
915 int setpalette(NCURSES_COLOR_T fore, NCURSES_COLOR_T back);
916 // Set color palette entry
918 int setcolor(NCURSES_PAIRS_T pair);
919 // Set actually used palette entry
921 // -------------------------------------------------------------------------
922 // window positioning
923 // -------------------------------------------------------------------------
924 virtual int mvwin(int begin_y, int begin_x) {
925 return ::mvwin(w, begin_y, begin_x); }
926 // Move window to new position with the new position as top left corner.
927 // This is virtual because it is redefined in NCursesPanel.
929 // -------------------------------------------------------------------------
930 // coordinate positioning
931 // -------------------------------------------------------------------------
932 int move(int y, int x) { return ::wmove(w, y, x); }
933 // Move cursor the this position
935 void getyx(int& y, int& x) const { ::getyx(w, y, x); }
936 // Get current position of the cursor
938 void getbegyx(int& y, int& x) const { ::getbegyx(w, y, x); }
939 // Get beginning of the window
941 void getmaxyx(int& y, int& x) const { ::getmaxyx(w, y, x); }
942 // Get size of the window
944 void getparyx(int& y, int& x) const { ::getparyx(w, y, x); }
945 // Get parent's beginning of the window
947 int mvcur(int oldrow, int oldcol, int newrow, int newcol) const {
948 return ::mvcur(oldrow, oldcol, newrow, newcol); }
949 // Perform lowlevel cursor motion that takes effect immediately.
951 // -------------------------------------------------------------------------
953 // -------------------------------------------------------------------------
954 int getch() { return ::wgetch(w); }
955 // Get a keystroke from the window.
957 int getch(int y, int x) { return ::mvwgetch(w, y, x); }
958 // Move cursor to position and get a keystroke from the window
960 int getstr(char* str, int n=-1) {
961 return ::wgetnstr(w, str, n); }
962 // Read a series of characters into str until a newline or carriage return
963 // is received. Read at most n characters. If n is negative, the limit is
966 int getstr(int y, int x, char* str, int n=-1) {
967 return ::mvwgetnstr(w, y, x, str, n); }
968 // Move the cursor to the requested position and then perform the getstr()
969 // as described above.
971 int instr(char *s, int n=-1) { return ::winnstr(w, s, n); }
972 // Get a string of characters from the window into the buffer s. Retrieve
973 // at most n characters, if n is negative retrieve all characters up to the
974 // end of the current line. Attributes are stripped from the characters.
976 int instr(int y, int x, char *s, int n=-1) {
977 return ::mvwinnstr(w, y, x, s, n); }
978 // Move the cursor to the requested position and then perform the instr()
979 // as described above.
981 int scanw(const char* fmt, ...)
982 // Perform a scanw function from the window.
984 __attribute__ ((format (scanf, 2, 3)));
989 int scanw(const char*, va_list);
990 // Perform a scanw function from the window.
992 int scanw(int y, int x, const char* fmt, ...)
993 // Move the cursor to the requested position and then perform a scanw
996 __attribute__ ((format (scanf, 4, 5)));
1001 int scanw(int y, int x, const char* fmt, va_list);
1002 // Move the cursor to the requested position and then perform a scanw
1005 // -------------------------------------------------------------------------
1007 // -------------------------------------------------------------------------
1008 int addch(const chtype ch) { return ::waddch(w, ch); }
1009 // Put attributed character to the window.
1011 int addch(int y, int x, const chtype ch) {
1012 return ::mvwaddch(w, y, x, ch); }
1013 // Move cursor to the requested position and then put attributed character
1016 int echochar(const chtype ch) { return ::wechochar(w, ch); }
1017 // Put attributed character to the window and refresh it immediately.
1019 int addstr(const char* str, int n=-1) {
1020 return ::waddnstr(w, str, n); }
1021 // Write the string str to the window, stop writing if the terminating
1022 // NUL or the limit n is reached. If n is negative, it is ignored.
1024 int addstr(int y, int x, const char * str, int n=-1) {
1025 return ::mvwaddnstr(w, y, x, str, n); }
1026 // Move the cursor to the requested position and then perform the addchstr
1027 // as described above.
1029 int addchstr(const chtype* str, int n=-1) {
1030 return ::waddchnstr(w, str, n); }
1031 // Write the string str to the window, stop writing if the terminating
1032 // NUL or the limit n is reached. If n is negative, it is ignored.
1034 int addchstr(int y, int x, const chtype * str, int n=-1) {
1035 return ::mvwaddchnstr(w, y, x, str, n); }
1036 // Move the cursor to the requested position and then perform the addchstr
1037 // as described above.
1039 int printw(const char* fmt, ...)
1040 // Do a formatted print to the window.
1041 #if (__GNUG__ >= 2) && !defined(printf)
1042 __attribute__ ((format (printf, 2, 3)));
1047 int printw(int y, int x, const char * fmt, ...)
1048 // Move the cursor and then do a formatted print to the window.
1049 #if (__GNUG__ >= 2) && !defined(printf)
1050 __attribute__ ((format (printf, 4, 5)));
1055 int printw(const char* fmt, va_list args);
1056 // Do a formatted print to the window.
1058 int printw(int y, int x, const char * fmt, va_list args);
1059 // Move the cursor and then do a formatted print to the window.
1061 chtype inch() const { return ::winch(w); }
1062 // Retrieve attributed character under the current cursor position.
1064 chtype inch(int y, int x) { return ::mvwinch(w, y, x); }
1065 // Move cursor to requested position and then retrieve attributed character
1066 // at this position.
1068 int inchstr(chtype* str, int n=-1) {
1069 return ::winchnstr(w, str, n); }
1070 // Read the string str from the window, stop reading if the terminating
1071 // NUL or the limit n is reached. If n is negative, it is ignored.
1073 int inchstr(int y, int x, chtype * str, int n=-1) {
1074 return ::mvwinchnstr(w, y, x, str, n); }
1075 // Move the cursor to the requested position and then perform the inchstr
1076 // as described above.
1078 int insch(chtype ch) { return ::winsch(w, ch); }
1079 // Insert attributed character into the window before current cursor
1082 int insch(int y, int x, chtype ch) {
1083 return ::mvwinsch(w, y, x, ch); }
1084 // Move cursor to requested position and then insert the attributed
1085 // character before that position.
1087 int insertln() { return ::winsdelln(w, 1); }
1088 // Insert an empty line above the current line.
1090 int insdelln(int n=1) { return ::winsdelln(w, n); }
1091 // If n>0 insert that many lines above the current line. If n<0 delete
1092 // that many lines beginning with the current line.
1094 int insstr(const char *s, int n=-1) {
1095 return ::winsnstr(w, s, n); }
1096 // Insert the string into the window before the current cursor position.
1097 // Insert stops at end of string or when the limit n is reached. If n is
1098 // negative, it is ignored.
1100 int insstr(int y, int x, const char *s, int n=-1) {
1101 return ::mvwinsnstr(w, y, x, s, n); }
1102 // Move the cursor to the requested position and then perform the insstr()
1103 // as described above.
1105 int attron (chtype at) { return ::wattron (w, at); }
1106 // Switch on the window attributes;
1108 int attroff(chtype at) { return ::wattroff(w, static_cast<int>(at)); }
1109 // Switch off the window attributes;
1111 int attrset(chtype at) { return ::wattrset(w, static_cast<int>(at)); }
1112 // Set the window attributes;
1114 chtype attrget() { return ::getattrs(w); }
1115 // Get the window attributes;
1117 int color_set(NCURSES_PAIRS_T color_pair_number, void* opts=NULL) {
1118 return ::wcolor_set(w, color_pair_number, opts); }
1119 // Set the window color attribute;
1121 int chgat(int n, attr_t attr, NCURSES_PAIRS_T color, const void *opts=NULL) {
1122 return ::wchgat(w, n, attr, color, opts); }
1123 // Change the attributes of the next n characters in the current line. If
1124 // n is negative or greater than the number of remaining characters in the
1125 // line, the attributes will be changed up to the end of the line.
1127 int chgat(int y, int x,
1128 int n, attr_t attr, NCURSES_PAIRS_T color, const void *opts=NULL) {
1129 return ::mvwchgat(w, y, x, n, attr, color, opts); }
1130 // Move the cursor to the requested position and then perform chgat() as
1133 // -------------------------------------------------------------------------
1135 // -------------------------------------------------------------------------
1136 chtype getbkgd() const { return ::getbkgd(w); }
1137 // Get current background setting.
1139 int bkgd(const chtype ch) { return ::wbkgd(w, ch); }
1140 // Set the background property and apply it to the window.
1142 void bkgdset(chtype ch) { ::wbkgdset(w, ch); }
1143 // Set the background property.
1145 // -------------------------------------------------------------------------
1147 // -------------------------------------------------------------------------
1148 int box(chtype vert=0, chtype hor=0) {
1149 return ::wborder(w, vert, vert, hor, hor, 0, 0, 0, 0); }
1150 // Draw a box around the window with the given vertical and horizontal
1151 // drawing characters. If you specify a zero as character, curses will try
1152 // to find a "nice" character.
1154 int border(chtype left=0, chtype right=0,
1155 chtype top =0, chtype bottom=0,
1156 chtype top_left =0, chtype top_right=0,
1157 chtype bottom_left =0, chtype bottom_right=0) {
1158 return ::wborder(w, left, right, top, bottom, top_left, top_right,
1159 bottom_left, bottom_right); }
1160 // Draw a border around the window with the given characters for the
1161 // various parts of the border. If you pass zero for a character, curses
1162 // will try to find "nice" characters.
1164 // -------------------------------------------------------------------------
1166 // -------------------------------------------------------------------------
1167 int hline(int len, chtype ch=0) { return ::whline(w, ch, len); }
1168 // Draw a horizontal line of len characters with the given character. If
1169 // you pass zero for the character, curses will try to find a "nice" one.
1171 int hline(int y, int x, int len, chtype ch=0) {
1172 return ::mvwhline(w, y, x, ch, len); }
1173 // Move the cursor to the requested position and then draw a horizontal line.
1175 int vline(int len, chtype ch=0) { return ::wvline(w, ch, len); }
1176 // Draw a vertical line of len characters with the given character. If
1177 // you pass zero for the character, curses will try to find a "nice" one.
1179 int vline(int y, int x, int len, chtype ch=0) {
1180 return ::mvwvline(w, y, x, ch, len); }
1181 // Move the cursor to the requested position and then draw a vertical line.
1183 // -------------------------------------------------------------------------
1185 // -------------------------------------------------------------------------
1186 int erase() { return ::werase(w); }
1187 // Erase the window.
1189 int clear() { return ::wclear(w); }
1190 // Clear the window.
1192 int clearok(bool bf) { return ::clearok(w, bf); }
1193 // Set/Reset the clear flag. If set, the next refresh() will clear the
1196 int clrtobot() { return ::wclrtobot(w); }
1197 // Clear to the end of the window.
1199 int clrtoeol() { return ::wclrtoeol(w); }
1200 // Clear to the end of the line.
1202 int delch() { return ::wdelch(w); }
1203 // Delete character under the cursor.
1205 int delch(int y, int x) { return ::mvwdelch(w, y, x); }
1206 // Move cursor to requested position and delete the character under the
1209 int deleteln() { return ::winsdelln(w, -1); }
1210 // Delete the current line.
1212 // -------------------------------------------------------------------------
1214 // -------------------------------------------------------------------------
1215 int scroll(int amount=1) { return ::wscrl(w, amount); }
1216 // Scroll amount lines. If amount is positive, scroll up, otherwise
1219 int scrollok(bool bf) { return ::scrollok(w, bf); }
1220 // If bf is TRUE, window scrolls if cursor is moved off the bottom
1221 // edge of the window or a scrolling region, otherwise the cursor is left
1222 // at the bottom line.
1224 int setscrreg(int from, int to) {
1225 return ::wsetscrreg(w, from, to); }
1226 // Define a soft scrolling region.
1228 int idlok(bool bf) { return ::idlok(w, bf); }
1229 // If bf is TRUE, use insert/delete line hardware support if possible.
1230 // Otherwise do it in software.
1232 void idcok(bool bf) { ::idcok(w, bf); }
1233 // If bf is TRUE, use insert/delete character hardware support if possible.
1234 // Otherwise do it in software.
1236 int touchline(int s, int c) { return ::touchline(w, s, c); }
1237 // Mark the given lines as modified.
1239 int touchwin() { return ::wtouchln(w, 0, height(), 1); }
1240 // Mark the whole window as modified.
1242 int untouchwin() { return ::wtouchln(w, 0, height(), 0); }
1243 // Mark the whole window as unmodified.
1245 int touchln(int s, int cnt, bool changed=TRUE) {
1246 return ::wtouchln(w, s, cnt, static_cast<int>(changed ? 1 : 0)); }
1247 // Mark cnt lines beginning from line s as changed or unchanged, depending
1248 // on the value of the changed flag.
1250 bool is_linetouched(int line) const {
1251 return (::is_linetouched(w, line) == TRUE ? TRUE:FALSE); }
1252 // Return TRUE if line is marked as changed, FALSE otherwise
1254 bool is_wintouched() const {
1255 return (::is_wintouched(w) ? TRUE:FALSE); }
1256 // Return TRUE if window is marked as changed, FALSE otherwise
1258 int leaveok(bool bf) { return ::leaveok(w, bf); }
1259 // If bf is TRUE, curses will leave the cursor after an update wherever
1260 // it is after the update.
1262 int redrawln(int from, int n) { return ::wredrawln(w, from, n); }
1263 // Redraw n lines starting from the requested line
1265 int redrawwin() { return ::wredrawln(w, 0, height()); }
1266 // Redraw the whole window
1268 int doupdate() { return ::doupdate(); }
1269 // Do all outputs to make the physical screen looking like the virtual one
1271 void syncdown() { ::wsyncdown(w); }
1272 // Propagate the changes down to all descendant windows
1274 void syncup() { ::wsyncup(w); }
1275 // Propagate the changes up in the hierarchy
1277 void cursyncup() { ::wcursyncup(w); }
1278 // Position the cursor in all ancestor windows corresponding to our setting
1280 int syncok(bool bf) { return ::syncok(w, bf); }
1281 // If called with bf=TRUE, syncup() is called whenever the window is changed
1284 int flushok(bool bf) { return ::flushok(w, bf); }
1287 void immedok(bool bf) { ::immedok(w, bf); }
1288 // If called with bf=TRUE, any change in the window will cause an
1289 // automatic immediate refresh()
1291 int intrflush(bool bf) { return ::intrflush(w, bf); }
1293 int keypad(bool bf) { return ::keypad(w, bf); }
1294 // If called with bf=TRUE, the application will interpret function keys.
1296 int nodelay(bool bf) { return ::nodelay(w, bf); }
1298 int meta(bool bf) { return ::meta(w, bf); }
1299 // If called with bf=TRUE, keys may generate 8-Bit characters. Otherwise
1300 // 7-Bit characters are generated.
1302 int standout() { return ::wstandout(w); }
1303 // Enable "standout" attributes
1305 int standend() { return ::wstandend(w); }
1306 // Disable "standout" attributes
1308 // -------------------------------------------------------------------------
1309 // The next two are virtual, because we redefine them in the
1310 // NCursesPanel class.
1311 // -------------------------------------------------------------------------
1312 virtual int refresh() { return ::wrefresh(w); }
1313 // Propagate the changes in this window to the virtual screen and call
1314 // doupdate(). This is redefined in NCursesPanel.
1316 virtual int noutrefresh() { return ::wnoutrefresh(w); }
1317 // Propagate the changes in this window to the virtual screen. This is
1318 // redefined in NCursesPanel.
1320 // -------------------------------------------------------------------------
1321 // multiple window control
1322 // -------------------------------------------------------------------------
1323 int overlay(NCursesWindow& win) {
1324 return ::overlay(w, win.w); }
1325 // Overlay this window over win.
1327 int overwrite(NCursesWindow& win) {
1328 return ::overwrite(w, win.w); }
1329 // Overwrite win with this window.
1331 int copywin(NCursesWindow& win,
1332 int sminrow, int smincol,
1333 int dminrow, int dmincol,
1334 int dmaxrow, int dmaxcol, bool overlaywin=TRUE) {
1335 return ::copywin(w, win.w, sminrow, smincol, dminrow, dmincol,
1336 dmaxrow, dmaxcol, static_cast<int>(overlaywin ? 1 : 0)); }
1337 // Overlay or overwrite the rectangle in win given by dminrow,dmincol,
1338 // dmaxrow,dmaxcol with the rectangle in this window beginning at
1341 // -------------------------------------------------------------------------
1342 // Extended functions
1343 // -------------------------------------------------------------------------
1344 #if defined(NCURSES_EXT_FUNCS) && (NCURSES_EXT_FUNCS != 0)
1345 int wresize(int newLines, int newColumns) {
1346 return ::wresize(w, newLines, newColumns); }
1349 // -------------------------------------------------------------------------
1351 // -------------------------------------------------------------------------
1352 bool has_mouse() const;
1353 // Return TRUE if terminal supports a mouse, FALSE otherwise
1355 // -------------------------------------------------------------------------
1356 // traversal support
1357 // -------------------------------------------------------------------------
1358 NCursesWindow* child() { return subwins; }
1359 // Get the first child window.
1361 NCursesWindow* sibling() { return sib; }
1362 // Get the next child of my parent.
1364 NCursesWindow* parent() { return par; }
1367 bool isDescendant(NCursesWindow& win);
1368 // Return TRUE if win is a descendant of this.
1371 // -------------------------------------------------------------------------
1372 // We leave this here for compatibility reasons.
1373 // -------------------------------------------------------------------------
1374 class NCURSES_IMPEXP NCursesColorWindow : public NCursesWindow
1377 NCursesColorWindow(WINDOW* &window) // useful only for stdscr
1378 : NCursesWindow(window) {
1381 NCursesColorWindow(int nlines, // number of lines
1382 int ncols, // number of columns
1383 int begin_y, // line origin
1384 int begin_x) // col origin
1385 : NCursesWindow(nlines, ncols, begin_y, begin_x) {
1388 NCursesColorWindow(NCursesWindow& parentWin,// parent window
1389 int nlines, // number of lines
1390 int ncols, // number of columns
1391 int begin_y, // absolute or relative
1392 int begin_x, // origins:
1393 char absrel = 'a') // if `a', by & bx are
1394 : NCursesWindow(parentWin,
1395 nlines, ncols, // absolute screen pos,
1396 begin_y, begin_x, // else if `r', they are
1397 absrel ) { // relative to par origin
1401 // These enum definitions really belong inside the NCursesPad class, but only
1402 // recent compilers support that feature.
1405 REQ_PAD_REFRESH = KEY_MAX + 1,
1413 const Pad_Request PAD_LOW = REQ_PAD_REFRESH; // lowest op-code
1414 const Pad_Request PAD_HIGH = REQ_PAD_EXIT; // highest op-code
1416 // -------------------------------------------------------------------------
1417 // Pad Support. We allow an association of a pad with a "real" window
1418 // through which the pad may be viewed.
1419 // -------------------------------------------------------------------------
1420 class NCURSES_IMPEXP NCursesPad : public NCursesWindow
1423 NCursesWindow* viewWin; // the "viewport" window
1424 NCursesWindow* viewSub; // the "viewport" subwindow
1426 int h_gridsize, v_gridsize;
1429 int min_row, min_col; // top left row/col of the pads display area
1431 NCursesWindow* Win(void) const {
1432 // Get the window into which the pad should be copied (if any)
1433 return (viewSub?viewSub:(viewWin?viewWin:0));
1436 NCursesWindow* getWindow(void) const {
1440 NCursesWindow* getSubWindow(void) const {
1444 virtual int driver (int key); // Virtualize keystroke key
1445 // The driver translates the keystroke c into an Pad_Request
1447 virtual void OnUnknownOperation(int pad_req) {
1451 // This is called if the driver returns an unknown op-code
1453 virtual void OnNavigationError(int pad_req) {
1457 // This is called if a navigation request couldn't be satisfied
1459 virtual void OnOperation(int pad_req) {
1462 // OnOperation is called if a Pad_Operation was executed and just before
1463 // the refresh() operation is done.
1466 NCursesPad(int nlines, int ncols);
1467 // create a pad with the given size
1469 NCursesPad& operator=(const NCursesPad& rhs)
1473 NCursesWindow::operator=(rhs);
1478 NCursesPad(const NCursesPad& rhs)
1479 : NCursesWindow(rhs),
1480 viewWin(rhs.viewWin),
1481 viewSub(rhs.viewSub),
1482 h_gridsize(rhs.h_gridsize),
1483 v_gridsize(rhs.v_gridsize),
1484 min_row(rhs.min_row),
1485 min_col(rhs.min_col)
1489 virtual ~NCursesPad() THROWS(NCursesException) {}
1491 int echochar(const chtype ch) { return ::pechochar(w, ch); }
1492 // Put the attributed character onto the pad and immediately do a
1496 // If a viewport is defined the pad is displayed in this window, otherwise
1499 int refresh(int pminrow, int pmincol,
1500 int sminrow, int smincol,
1501 int smaxrow, int smaxcol) {
1502 return ::prefresh(w, pminrow, pmincol,
1503 sminrow, smincol, smaxrow, smaxcol);
1505 // The coordinates sminrow,smincol,smaxrow,smaxcol describe a rectangle
1506 // on the screen. <b>refresh</b> copies a rectangle of this size beginning
1507 // with top left corner pminrow,pmincol onto the screen and calls doupdate().
1510 // If a viewport is defined the pad is displayed in this window, otherwise
1513 int noutrefresh(int pminrow, int pmincol,
1514 int sminrow, int smincol,
1515 int smaxrow, int smaxcol) {
1516 return ::pnoutrefresh(w, pminrow, pmincol,
1517 sminrow, smincol, smaxrow, smaxcol);
1519 // Does the same as refresh() but without calling doupdate().
1521 virtual void setWindow(NCursesWindow& view, int v_grid = 1, int h_grid = 1);
1522 // Add the window "view" as viewing window to the pad.
1524 virtual void setSubWindow(NCursesWindow& sub);
1525 // Use the subwindow "sub" of the viewport window for the actual viewing.
1526 // The full viewport window is usually used to provide some decorations
1527 // like frames, titles etc.
1529 virtual void operator() (void);
1530 // Perform Pad's operation
1533 // A FramedPad is constructed always with a viewport window. This viewport
1534 // will be framed (by a box() command) and the interior of the box is the
1535 // viewport subwindow. On the frame we display scrollbar sliders.
1536 class NCURSES_IMPEXP NCursesFramedPad : public NCursesPad
1539 virtual void OnOperation(int pad_req);
1542 NCursesFramedPad(NCursesWindow& win, int nlines, int ncols,
1543 int v_grid = 1, int h_grid = 1)
1544 : NCursesPad(nlines, ncols) {
1545 NCursesPad::setWindow(win, v_grid, h_grid);
1546 NCursesPad::setSubWindow(*(new NCursesWindow(win)));
1548 // Construct the FramedPad with the given Window win as viewport.
1550 virtual ~NCursesFramedPad() THROWS(NCursesException) {
1551 delete getSubWindow();
1554 void setWindow(NCursesWindow& view, int v_grid = 1, int h_grid = 1) {
1558 err_handler("Operation not allowed");
1560 // Disable this call; the viewport is already defined
1562 void setSubWindow(NCursesWindow& sub) {
1564 err_handler("Operation not allowed");
1566 // Disable this call; the viewport subwindow is already defined
1570 #endif /* NCURSES_CURSESW_H_incl */