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.57 2020/07/04 20:38:43 tom Exp $
41 #if defined(BUILDING_NCURSES_CXX)
42 # define NCURSES_CXX_IMPEXP NCURSES_EXPORT_GENERAL_EXPORT
44 # define NCURSES_CXX_IMPEXP NCURSES_EXPORT_GENERAL_IMPORT
47 #define NCURSES_CXX_WRAPPED_VAR(type,name) extern NCURSES_CXX_IMPEXP type NCURSES_PUBLIC_VAR(name)(void)
49 #define NCURSES_CXX_EXPORT(type) NCURSES_CXX_IMPEXP type NCURSES_API
50 #define NCURSES_CXX_EXPORT_VAR(type) NCURSES_CXX_IMPEXP type
54 /* SCO 3.2v4 curses.h includes term.h, which defines lines as a macro.
55 Undefine it here, because NCursesWindow uses lines as a method. */
58 /* "Convert" macros to inlines. We'll define it as another symbol to avoid
59 * conflict with library symbols.
62 #define UNDEF(name) CUR_ ##name
65 inline int UNDEF(addch)(chtype ch) { return addch(ch); }
67 #define addch UNDEF(addch)
71 inline int UNDEF(addchstr)(chtype *at) { return addchstr(at); }
73 #define addchstr UNDEF(addchstr)
77 inline int UNDEF(addnstr)(const char *str, int n)
78 { return addnstr(str, n); }
80 #define addnstr UNDEF(addnstr)
84 inline int UNDEF(addstr)(const char * str) { return addstr(str); }
86 #define addstr UNDEF(addstr)
90 inline int UNDEF(attroff)(chtype at) { return attroff(at); }
92 #define attroff UNDEF(attroff)
96 inline int UNDEF(attron)(chtype at) { return attron(at); }
98 #define attron UNDEF(attron)
102 inline chtype UNDEF(attrset)(chtype at) { return attrset(at); }
104 #define attrset UNDEF(attrset)
108 inline int UNDEF(bkgd)(chtype ch) { return bkgd(ch); }
110 #define bkgd UNDEF(bkgd)
114 inline void UNDEF(bkgdset)(chtype ch) { bkgdset(ch); }
116 #define bkgdset UNDEF(bkgdset)
120 inline int UNDEF(border)(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, chtype tr, chtype bl, chtype br)
121 { return border(ls, rs, ts, bs, tl, tr, bl, br); }
123 #define border UNDEF(border)
127 inline int UNDEF(box)(WINDOW *win, int v, int h) { return box(win, v, h); }
129 #define box UNDEF(box)
133 inline int UNDEF(chgat)(int n, attr_t attr, NCURSES_PAIRS_T color, const void *opts) {
134 return chgat(n, attr, color, opts); }
136 #define chgat UNDEF(chgat)
140 inline int UNDEF(clear)() { return clear(); }
142 #define clear UNDEF(clear)
146 inline int UNDEF(clearok)(WINDOW* win, bool bf) { return clearok(win, bf); }
148 #define clearok UNDEF(clearok)
150 extern "C" NCURSES_IMPEXP int NCURSES_API clearok(WINDOW*, bool);
154 inline int UNDEF(clrtobot)() { return clrtobot(); }
156 #define clrtobot UNDEF(clrtobot)
160 inline int UNDEF(clrtoeol)() { return clrtoeol(); }
162 #define clrtoeol UNDEF(clrtoeol)
166 inline chtype UNDEF(color_set)(NCURSES_PAIRS_T p, void* opts) { return color_set(p, opts); }
168 #define color_set UNDEF(color_set)
172 inline int UNDEF(crmode)(void) { return crmode(); }
174 #define crmode UNDEF(crmode)
178 inline int UNDEF(delch)() { return delch(); }
180 #define delch UNDEF(delch)
184 inline int UNDEF(deleteln)() { return deleteln(); }
186 #define deleteln UNDEF(deleteln)
190 inline int UNDEF(echochar)(chtype ch) { return echochar(ch); }
192 #define echochar UNDEF(echochar)
196 inline int UNDEF(erase)() { return erase(); }
198 #define erase UNDEF(erase)
202 inline int UNDEF(fixterm)(void) { return fixterm(); }
204 #define fixterm UNDEF(fixterm)
208 inline int UNDEF(flushok)(WINDOW* _win, bool _bf) {
209 return flushok(_win, _bf); }
211 #define flushok UNDEF(flushok)
217 inline int UNDEF(getattrs)(WINDOW *win) { return getattrs(win); }
219 #define getattrs UNDEF(getattrs)
223 inline void UNDEF(getbegyx)(WINDOW* win, int& y, int& x) { getbegyx(win, y, x); }
225 #define getbegyx UNDEF(getbegyx)
229 inline chtype UNDEF(getbkgd)(const WINDOW *win) { return getbkgd(win); }
231 #define getbkgd UNDEF(getbkgd)
235 inline int UNDEF(getch)() { return getch(); }
237 #define getch UNDEF(getch)
241 inline void UNDEF(getmaxyx)(WINDOW* win, int& y, int& x) { getmaxyx(win, y, x); }
243 #define getmaxyx UNDEF(getmaxyx)
247 inline int UNDEF(getnstr)(char *_str, int n) { return getnstr(_str, n); }
249 #define getnstr UNDEF(getnstr)
253 inline void UNDEF(getparyx)(WINDOW* win, int& y, int& x) { getparyx(win, y, x); }
255 #define getparyx UNDEF(getparyx)
259 inline int UNDEF(getstr)(char *_str) { return getstr(_str); }
261 #define getstr UNDEF(getstr)
265 inline void UNDEF(getyx)(const WINDOW* win, int& y, int& x) {
268 #define getyx UNDEF(getyx)
272 inline int UNDEF(hline)(chtype ch, int n) { return hline(ch, n); }
274 #define hline UNDEF(hline)
278 inline chtype UNDEF(inch)() { return inch(); }
280 #define inch UNDEF(inch)
284 inline int UNDEF(inchstr)(chtype *str) { return inchstr(str); }
286 #define inchstr UNDEF(inchstr)
290 inline int UNDEF(innstr)(char *_str, int n) { return innstr(_str, n); }
292 #define innstr UNDEF(innstr)
296 inline int UNDEF(insch)(chtype c) { return insch(c); }
298 #define insch UNDEF(insch)
302 inline int UNDEF(insdelln)(int n) { return insdelln(n); }
304 #define insdelln UNDEF(insdelln)
308 inline int UNDEF(insertln)() { return insertln(); }
310 #define insertln UNDEF(insertln)
314 inline int UNDEF(insnstr)(const char *_str, int n) {
315 return insnstr(_str, n); }
317 #define insnstr UNDEF(insnstr)
321 inline int UNDEF(insstr)(const char *_str) {
322 return insstr(_str); }
324 #define insstr UNDEF(insstr)
328 inline int UNDEF(instr)(char *_str) { return instr(_str); }
330 #define instr UNDEF(instr)
334 inline void UNDEF(intrflush)(WINDOW *win, bool bf) { intrflush(); }
336 #define intrflush UNDEF(intrflush)
339 #ifdef is_linetouched
340 inline int UNDEF(is_linetouched)(WINDOW *w, int l) { return is_linetouched(w,l); }
341 #undef is_linetouched
342 #define is_linetouched UNDEF(is_linetouched)
346 inline int UNDEF(leaveok)(WINDOW* win, bool bf) { return leaveok(win, bf); }
348 #define leaveok UNDEF(leaveok)
350 extern "C" NCURSES_IMPEXP int NCURSES_API leaveok(WINDOW* win, bool bf);
354 inline int UNDEF(move)(int x, int y) { return move(x, y); }
356 #define move UNDEF(move)
360 inline int UNDEF(mvaddch)(int y, int x, chtype ch)
361 { return mvaddch(y, x, ch); }
363 #define mvaddch UNDEF(mvaddch)
367 inline int UNDEF(mvaddnstr)(int y, int x, const char *str, int n)
368 { return mvaddnstr(y, x, str, n); }
370 #define mvaddnstr UNDEF(mvaddnstr)
374 inline int UNDEF(mvaddstr)(int y, int x, const char * str)
375 { return mvaddstr(y, x, str); }
377 #define mvaddstr UNDEF(mvaddstr)
381 inline int UNDEF(mvchgat)(int y, int x, int n,
382 attr_t attr, NCURSES_PAIRS_T color, const void *opts) {
383 return mvchgat(y, x, n, attr, color, opts); }
385 #define mvchgat UNDEF(mvchgat)
389 inline int UNDEF(mvdelch)(int y, int x) { return mvdelch(y, x);}
391 #define mvdelch UNDEF(mvdelch)
395 inline int UNDEF(mvgetch)(int y, int x) { return mvgetch(y, x);}
397 #define mvgetch UNDEF(mvgetch)
401 inline int UNDEF(mvgetnstr)(int y, int x, char *str, int n) {
402 return mvgetnstr(y, x, str, n);}
404 #define mvgetnstr UNDEF(mvgetnstr)
408 inline int UNDEF(mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
410 #define mvgetstr UNDEF(mvgetstr)
414 inline chtype UNDEF(mvinch)(int y, int x) { return mvinch(y, x);}
416 #define mvinch UNDEF(mvinch)
420 inline int UNDEF(mvinnstr)(int y, int x, char *_str, int n) {
421 return mvinnstr(y, x, _str, n); }
423 #define mvinnstr UNDEF(mvinnstr)
427 inline int UNDEF(mvinsch)(int y, int x, chtype c)
428 { return mvinsch(y, x, c); }
430 #define mvinsch UNDEF(mvinsch)
434 inline int UNDEF(mvinsnstr)(int y, int x, const char *_str, int n) {
435 return mvinsnstr(y, x, _str, n); }
437 #define mvinsnstr UNDEF(mvinsnstr)
441 inline int UNDEF(mvinsstr)(int y, int x, const char *_str) {
442 return mvinsstr(y, x, _str); }
444 #define mvinsstr UNDEF(mvinsstr)
448 inline int UNDEF(mvwaddch)(WINDOW *win, int y, int x, const chtype ch)
449 { return mvwaddch(win, y, x, ch); }
451 #define mvwaddch UNDEF(mvwaddch)
455 inline int UNDEF(mvwaddchnstr)(WINDOW *win, int y, int x, const chtype *str, int n)
456 { return mvwaddchnstr(win, y, x, str, n); }
458 #define mvwaddchnstr UNDEF(mvwaddchnstr)
462 inline int UNDEF(mvwaddchstr)(WINDOW *win, int y, int x, const chtype *str)
463 { return mvwaddchstr(win, y, x, str); }
465 #define mvwaddchstr UNDEF(mvwaddchstr)
469 inline int UNDEF(mvwaddnstr)(WINDOW *win, int y, int x, const char *str, int n)
470 { return mvwaddnstr(win, y, x, str, n); }
472 #define mvwaddnstr UNDEF(mvwaddnstr)
476 inline int UNDEF(mvwaddstr)(WINDOW *win, int y, int x, const char * str)
477 { return mvwaddstr(win, y, x, str); }
479 #define mvwaddstr UNDEF(mvwaddstr)
483 inline int UNDEF(mvwchgat)(WINDOW *win, int y, int x, int n,
484 attr_t attr, NCURSES_PAIRS_T color, const void *opts) {
485 return mvwchgat(win, y, x, n, attr, color, opts); }
487 #define mvwchgat UNDEF(mvwchgat)
491 inline int UNDEF(mvwdelch)(WINDOW *win, int y, int x)
492 { return mvwdelch(win, y, x); }
494 #define mvwdelch UNDEF(mvwdelch)
498 inline int UNDEF(mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
500 #define mvwgetch UNDEF(mvwgetch)
504 inline int UNDEF(mvwgetnstr)(WINDOW *win, int y, int x, char *str, int n)
505 {return mvwgetnstr(win, y, x, str, n);}
507 #define mvwgetnstr UNDEF(mvwgetnstr)
511 inline int UNDEF(mvwgetstr)(WINDOW *win, int y, int x, char *str)
512 {return mvwgetstr(win, y, x, str);}
514 #define mvwgetstr UNDEF(mvwgetstr)
518 inline int UNDEF(mvwhline)(WINDOW *win, int y, int x, chtype c, int n) {
519 return mvwhline(win, y, x, c, n); }
521 #define mvwhline UNDEF(mvwhline)
525 inline chtype UNDEF(mvwinch)(WINDOW *win, int y, int x) {
526 return mvwinch(win, y, x);}
528 #define mvwinch UNDEF(mvwinch)
532 inline int UNDEF(mvwinchnstr)(WINDOW *win, int y, int x, chtype *str, int n) { return mvwinchnstr(win, y, x, str, n); }
534 #define mvwinchnstr UNDEF(mvwinchnstr)
538 inline int UNDEF(mvwinchstr)(WINDOW *win, int y, int x, chtype *str) { return mvwinchstr(win, y, x, str); }
540 #define mvwinchstr UNDEF(mvwinchstr)
544 inline int UNDEF(mvwinnstr)(WINDOW *win, int y, int x, char *_str, int n) {
545 return mvwinnstr(win, y, x, _str, n); }
547 #define mvwinnstr UNDEF(mvwinnstr)
551 inline int UNDEF(mvwinsch)(WINDOW *win, int y, int x, chtype c)
552 { return mvwinsch(win, y, x, c); }
554 #define mvwinsch UNDEF(mvwinsch)
558 inline int UNDEF(mvwinsnstr)(WINDOW *w, int y, int x, const char *_str, int n) {
559 return mvwinsnstr(w, y, x, _str, n); }
561 #define mvwinsnstr UNDEF(mvwinsnstr)
565 inline int UNDEF(mvwinsstr)(WINDOW *w, int y, int x, const char *_str) {
566 return mvwinsstr(w, y, x, _str); }
568 #define mvwinsstr UNDEF(mvwinsstr)
572 inline int UNDEF(mvwvline)(WINDOW *win, int y, int x, chtype c, int n) {
573 return mvwvline(win, y, x, c, n); }
575 #define mvwvline UNDEF(mvwvline)
579 inline void UNDEF(napms)(unsigned long x) { napms(x); }
581 #define napms UNDEF(napms)
585 inline int UNDEF(nocrmode)(void) { return nocrmode(); }
587 #define nocrmode UNDEF(nocrmode)
591 inline void UNDEF(nodelay)() { nodelay(); }
593 #define nodelay UNDEF(nodelay)
597 inline int UNDEF(redrawwin)(WINDOW *win) { return redrawwin(win); }
599 #define redrawwin UNDEF(redrawwin)
603 inline int UNDEF(refresh)() { return refresh(); }
605 #define refresh UNDEF(refresh)
609 inline int UNDEF(resetterm)(void) { return resetterm(); }
611 #define resetterm UNDEF(resetterm)
615 inline int UNDEF(saveterm)(void) { return saveterm(); }
617 #define saveterm UNDEF(saveterm)
621 inline int UNDEF(scrl)(int l) { return scrl(l); }
623 #define scrl UNDEF(scrl)
627 inline int UNDEF(scroll)(WINDOW *win) { return scroll(win); }
629 #define scroll UNDEF(scroll)
633 inline int UNDEF(scrollok)(WINDOW* win, bool bf) { return scrollok(win, bf); }
635 #define scrollok UNDEF(scrollok)
637 #if defined(__NCURSES_H)
638 extern "C" NCURSES_IMPEXP int NCURSES_API scrollok(WINDOW*, bool);
640 extern "C" NCURSES_IMPEXP int NCURSES_API scrollok(WINDOW*, char);
645 inline int UNDEF(setscrreg)(int t, int b) { return setscrreg(t, b); }
647 #define setscrreg UNDEF(setscrreg)
651 inline int UNDEF(standend)() { return standend(); }
653 #define standend UNDEF(standend)
657 inline int UNDEF(standout)() { return standout(); }
659 #define standout UNDEF(standout)
663 inline WINDOW *UNDEF(subpad)(WINDOW *p, int l, int c, int y, int x)
664 { return derwin(p, l, c, y, x); }
666 #define subpad UNDEF(subpad)
670 inline void UNDEF(timeout)(int delay) { timeout(delay); }
672 #define timeout UNDEF(timeout)
676 inline int UNDEF(touchline)(WINDOW *win, int s, int c)
677 { return touchline(win, s, c); }
679 #define touchline UNDEF(touchline)
683 inline int UNDEF(touchwin)(WINDOW *win) { return touchwin(win); }
685 #define touchwin UNDEF(touchwin)
689 inline int UNDEF(untouchwin)(WINDOW *win) { return untouchwin(win); }
691 #define untouchwin UNDEF(untouchwin)
695 inline int UNDEF(vline)(chtype ch, int n) { return vline(ch, n); }
697 #define vline UNDEF(vline)
701 inline int UNDEF(waddchstr)(WINDOW *win, chtype *at) { return waddchstr(win, at); }
703 #define waddchstr UNDEF(waddchstr)
707 inline int UNDEF(waddstr)(WINDOW *win, char *str) { return waddstr(win, str); }
709 #define waddstr UNDEF(waddstr)
713 inline int UNDEF(wattroff)(WINDOW *win, int att) { return wattroff(win, att); }
715 #define wattroff UNDEF(wattroff)
719 inline int UNDEF(wattrset)(WINDOW *win, int att) { return wattrset(win, att); }
721 #define wattrset UNDEF(wattrset)
725 inline chtype UNDEF(winch)(const WINDOW* win) { return winch(win); }
727 #define winch UNDEF(winch)
731 inline int UNDEF(winchnstr)(WINDOW *win, chtype *str, int n) { return winchnstr(win, str, n); }
733 #define winchnstr UNDEF(winchnstr)
737 inline int UNDEF(winchstr)(WINDOW *win, chtype *str) { return winchstr(win, str); }
739 #define winchstr UNDEF(winchstr)
743 inline int UNDEF(winsstr)(WINDOW *w, const char *_str) {
744 return winsstr(w, _str); }
746 #define winsstr UNDEF(winsstr)
750 inline int UNDEF(wstandend)(WINDOW *win) { return wstandend(win); }
752 #define wstandend UNDEF(wstandend)
756 inline int UNDEF(wstandout)(WINDOW *win) { return wstandout(win); }
758 #define wstandout UNDEF(wstandout)
763 * C++ class for windows.
767 extern "C" int _nc_ripoffline(int, int (*init)(WINDOW*, int));
768 extern "C" int _nc_xx_ripoff_init(WINDOW *, int);
769 extern "C" int _nc_has_mouse(void);
771 class NCURSES_CXX_IMPEXP NCursesWindow
773 friend class NCursesMenu;
774 friend class NCursesForm;
777 static bool b_initialized;
778 static void initialize();
780 friend int _nc_xx_ripoff_init(WINDOW *, int);
784 NCURSES_COLOR_T getcolor(int getback) const;
785 NCURSES_PAIRS_T getPair() const;
787 static int setpalette(NCURSES_COLOR_T fore, NCURSES_COLOR_T back, NCURSES_PAIRS_T pair);
788 static int colorInitialized;
790 // This private constructor is only used during the initialization
791 // of windows generated by ripoffline() calls.
792 NCursesWindow(WINDOW* win, int ncols);
795 virtual void err_handler(const char *) const THROWS(NCursesException);
796 // Signal an error with the given message text.
798 static long count; // count of all active windows:
799 // We rely on the c++ promise that
800 // all otherwise uninitialized
801 // static class vars are set to 0
803 WINDOW* w; // the curses WINDOW
805 bool alloced; // TRUE if we own the WINDOW
807 NCursesWindow* par; // parent, if subwindow
808 NCursesWindow* subwins; // head of subwindows list
809 NCursesWindow* sib; // next subwindow of parent
811 void kill_subwindows(); // disable all subwindows
812 // Destroy all subwindows.
814 /* Only for use by derived classes. They are then in charge to
815 fill the member variables correctly. */
819 NCursesWindow(WINDOW* window); // useful only for stdscr
821 NCursesWindow(int nlines, // number of lines
822 int ncols, // number of columns
823 int begin_y, // line origin
824 int begin_x); // col origin
826 NCursesWindow(NCursesWindow& par,// parent window
827 int nlines, // number of lines
828 int ncols, // number of columns
829 int begin_y, // absolute or relative
830 int begin_x, // origins:
831 char absrel = 'a');// if `a', begin_y & begin_x are
832 // absolute screen pos, else if `r', they are relative to par origin
834 NCursesWindow(NCursesWindow& par,// parent window
836 // this is the very common case that we want to create the subwindow that
837 // is two lines and two columns smaller and begins at (1,1).
838 // We may automatically request the box around it.
840 NCursesWindow& operator=(const NCursesWindow& rhs)
847 NCursesWindow(const NCursesWindow& rhs)
848 : w(rhs.w), alloced(rhs.alloced), par(rhs.par), subwins(rhs.subwins), sib(rhs.sib)
852 virtual ~NCursesWindow() THROWS(NCursesException);
854 NCursesWindow Clone();
855 // Make an exact copy of the window.
858 static void useColors(void);
859 // Call this routine very early if you want to have colors.
861 static int ripoffline(int ripoff_lines,
862 int (*init)(NCursesWindow& win));
863 // This function is used to generate a window of ripped-of lines.
864 // If the argument is positive, lines are removed from the top, if it
865 // is negative lines are removed from the bottom. This enhances the
866 // lowlevel ripoffline() function because it uses the internal
867 // implementation that allows to remove more than just a single line.
868 // This function must be called before any other ncurses function. The
869 // creation of the window is deferred until ncurses gets initialized.
870 // The initialization function is then called.
872 // -------------------------------------------------------------------------
874 // -------------------------------------------------------------------------
875 int lines() const { initialize(); return LINES; }
876 // Number of lines on terminal, *not* window
878 int cols() const { initialize(); return COLS; }
879 // Number of cols on terminal, *not* window
881 int tabsize() const { initialize(); return TABSIZE; }
882 // Size of a tab on terminal, *not* window
884 static int NumberOfColors();
885 // Number of available colors
887 int colors() const { return NumberOfColors(); }
888 // Number of available colors
890 // -------------------------------------------------------------------------
892 // -------------------------------------------------------------------------
893 int height() const { return maxy() + 1; }
894 // Number of lines in this window
896 int width() const { return maxx() + 1; }
897 // Number of columns in this window
899 int begx() const { return getbegx(w); }
900 // Column of top left corner relative to stdscr
902 int begy() const { return getbegy(w); }
903 // Line of top left corner relative to stdscr
905 int curx() const { return getcurx(w); }
906 // Column of top left corner relative to stdscr
908 int cury() const { return getcury(w); }
909 // Line of top left corner relative to stdscr
911 int maxx() const { return getmaxx(w) == ERR ? ERR : getmaxx(w)-1; }
912 // Largest x coord in window
914 int maxy() const { return getmaxy(w) == ERR ? ERR : getmaxy(w)-1; }
915 // Largest y coord in window
917 NCURSES_PAIRS_T getcolor() const;
920 NCURSES_COLOR_T foreground() const { return getcolor(0); }
921 // Actual foreground color
923 NCURSES_COLOR_T background() const { return getcolor(1); }
924 // Actual background color
926 int setpalette(NCURSES_COLOR_T fore, NCURSES_COLOR_T back);
927 // Set color palette entry
929 int setcolor(NCURSES_PAIRS_T pair);
930 // Set actually used palette entry
932 // -------------------------------------------------------------------------
933 // window positioning
934 // -------------------------------------------------------------------------
935 virtual int mvwin(int begin_y, int begin_x) {
936 return ::mvwin(w, begin_y, begin_x); }
937 // Move window to new position with the new position as top left corner.
938 // This is virtual because it is redefined in NCursesPanel.
940 // -------------------------------------------------------------------------
941 // coordinate positioning
942 // -------------------------------------------------------------------------
943 int move(int y, int x) { return ::wmove(w, y, x); }
944 // Move cursor the this position
946 void getyx(int& y, int& x) const { ::getyx(w, y, x); }
947 // Get current position of the cursor
949 void getbegyx(int& y, int& x) const { ::getbegyx(w, y, x); }
950 // Get beginning of the window
952 void getmaxyx(int& y, int& x) const { ::getmaxyx(w, y, x); }
953 // Get size of the window
955 void getparyx(int& y, int& x) const { ::getparyx(w, y, x); }
956 // Get parent's beginning of the window
958 int mvcur(int oldrow, int oldcol, int newrow, int newcol) const {
959 return ::mvcur(oldrow, oldcol, newrow, newcol); }
960 // Perform lowlevel cursor motion that takes effect immediately.
962 // -------------------------------------------------------------------------
964 // -------------------------------------------------------------------------
965 int getch() { return ::wgetch(w); }
966 // Get a keystroke from the window.
968 int getch(int y, int x) { return ::mvwgetch(w, y, x); }
969 // Move cursor to position and get a keystroke from the window
971 int getstr(char* str, int n=-1) {
972 return ::wgetnstr(w, str, n); }
973 // Read a series of characters into str until a newline or carriage return
974 // is received. Read at most n characters. If n is negative, the limit is
977 int getstr(int y, int x, char* str, int n=-1) {
978 return ::mvwgetnstr(w, y, x, str, n); }
979 // Move the cursor to the requested position and then perform the getstr()
980 // as described above.
982 int instr(char *s, int n=-1) { return ::winnstr(w, s, n); }
983 // Get a string of characters from the window into the buffer s. Retrieve
984 // at most n characters, if n is negative retrieve all characters up to the
985 // end of the current line. Attributes are stripped from the characters.
987 int instr(int y, int x, char *s, int n=-1) {
988 return ::mvwinnstr(w, y, x, s, n); }
989 // Move the cursor to the requested position and then perform the instr()
990 // as described above.
992 int scanw(const char* fmt, ...)
993 // Perform a scanw function from the window.
995 __attribute__ ((format (scanf, 2, 3)));
1000 int scanw(const char*, va_list);
1001 // Perform a scanw function from the window.
1003 int scanw(int y, int x, const char* fmt, ...)
1004 // Move the cursor to the requested position and then perform a scanw
1007 __attribute__ ((format (scanf, 4, 5)));
1012 int scanw(int y, int x, const char* fmt, va_list);
1013 // Move the cursor to the requested position and then perform a scanw
1016 // -------------------------------------------------------------------------
1018 // -------------------------------------------------------------------------
1019 int addch(const chtype ch) { return ::waddch(w, ch); }
1020 // Put attributed character to the window.
1022 int addch(int y, int x, const chtype ch) {
1023 return ::mvwaddch(w, y, x, ch); }
1024 // Move cursor to the requested position and then put attributed character
1027 int echochar(const chtype ch) { return ::wechochar(w, ch); }
1028 // Put attributed character to the window and refresh it immediately.
1030 int addstr(const char* str, int n=-1) {
1031 return ::waddnstr(w, str, n); }
1032 // Write the string str to the window, stop writing if the terminating
1033 // NUL or the limit n is reached. If n is negative, it is ignored.
1035 int addstr(int y, int x, const char * str, int n=-1) {
1036 return ::mvwaddnstr(w, y, x, str, n); }
1037 // Move the cursor to the requested position and then perform the addchstr
1038 // as described above.
1040 int addchstr(const chtype* str, int n=-1) {
1041 return ::waddchnstr(w, str, n); }
1042 // Write the string str to the window, stop writing if the terminating
1043 // NUL or the limit n is reached. If n is negative, it is ignored.
1045 int addchstr(int y, int x, const chtype * str, int n=-1) {
1046 return ::mvwaddchnstr(w, y, x, str, n); }
1047 // Move the cursor to the requested position and then perform the addchstr
1048 // as described above.
1050 int printw(const char* fmt, ...)
1051 // Do a formatted print to the window.
1052 #if (__GNUG__ >= 2) && !defined(printf)
1053 __attribute__ ((format (printf, 2, 3)));
1058 int printw(int y, int x, const char * fmt, ...)
1059 // Move the cursor and then do a formatted print to the window.
1060 #if (__GNUG__ >= 2) && !defined(printf)
1061 __attribute__ ((format (printf, 4, 5)));
1066 int printw(const char* fmt, va_list args);
1067 // Do a formatted print to the window.
1069 int printw(int y, int x, const char * fmt, va_list args);
1070 // Move the cursor and then do a formatted print to the window.
1072 chtype inch() const { return ::winch(w); }
1073 // Retrieve attributed character under the current cursor position.
1075 chtype inch(int y, int x) { return ::mvwinch(w, y, x); }
1076 // Move cursor to requested position and then retrieve attributed character
1077 // at this position.
1079 int inchstr(chtype* str, int n=-1) {
1080 return ::winchnstr(w, str, n); }
1081 // Read the string str from the window, stop reading if the terminating
1082 // NUL or the limit n is reached. If n is negative, it is ignored.
1084 int inchstr(int y, int x, chtype * str, int n=-1) {
1085 return ::mvwinchnstr(w, y, x, str, n); }
1086 // Move the cursor to the requested position and then perform the inchstr
1087 // as described above.
1089 int insch(chtype ch) { return ::winsch(w, ch); }
1090 // Insert attributed character into the window before current cursor
1093 int insch(int y, int x, chtype ch) {
1094 return ::mvwinsch(w, y, x, ch); }
1095 // Move cursor to requested position and then insert the attributed
1096 // character before that position.
1098 int insertln() { return ::winsdelln(w, 1); }
1099 // Insert an empty line above the current line.
1101 int insdelln(int n=1) { return ::winsdelln(w, n); }
1102 // If n>0 insert that many lines above the current line. If n<0 delete
1103 // that many lines beginning with the current line.
1105 int insstr(const char *s, int n=-1) {
1106 return ::winsnstr(w, s, n); }
1107 // Insert the string into the window before the current cursor position.
1108 // Insert stops at end of string or when the limit n is reached. If n is
1109 // negative, it is ignored.
1111 int insstr(int y, int x, const char *s, int n=-1) {
1112 return ::mvwinsnstr(w, y, x, s, n); }
1113 // Move the cursor to the requested position and then perform the insstr()
1114 // as described above.
1116 int attron (chtype at) { return ::wattron (w, at); }
1117 // Switch on the window attributes;
1119 int attroff(chtype at) { return ::wattroff(w, static_cast<int>(at)); }
1120 // Switch off the window attributes;
1122 int attrset(chtype at) { return ::wattrset(w, static_cast<int>(at)); }
1123 // Set the window attributes;
1125 chtype attrget() { return ::getattrs(w); }
1126 // Get the window attributes;
1128 int color_set(NCURSES_PAIRS_T color_pair_number, void* opts=NULL) {
1129 return ::wcolor_set(w, color_pair_number, opts); }
1130 // Set the window color attribute;
1132 int chgat(int n, attr_t attr, NCURSES_PAIRS_T color, const void *opts=NULL) {
1133 return ::wchgat(w, n, attr, color, opts); }
1134 // Change the attributes of the next n characters in the current line. If
1135 // n is negative or greater than the number of remaining characters in the
1136 // line, the attributes will be changed up to the end of the line.
1138 int chgat(int y, int x,
1139 int n, attr_t attr, NCURSES_PAIRS_T color, const void *opts=NULL) {
1140 return ::mvwchgat(w, y, x, n, attr, color, opts); }
1141 // Move the cursor to the requested position and then perform chgat() as
1144 // -------------------------------------------------------------------------
1146 // -------------------------------------------------------------------------
1147 chtype getbkgd() const { return ::getbkgd(w); }
1148 // Get current background setting.
1150 int bkgd(const chtype ch) { return ::wbkgd(w, ch); }
1151 // Set the background property and apply it to the window.
1153 void bkgdset(chtype ch) { ::wbkgdset(w, ch); }
1154 // Set the background property.
1156 // -------------------------------------------------------------------------
1158 // -------------------------------------------------------------------------
1159 int box(chtype vert=0, chtype hor=0) {
1160 return ::wborder(w, vert, vert, hor, hor, 0, 0, 0, 0); }
1161 // Draw a box around the window with the given vertical and horizontal
1162 // drawing characters. If you specify a zero as character, curses will try
1163 // to find a "nice" character.
1165 int border(chtype left=0, chtype right=0,
1166 chtype top =0, chtype bottom=0,
1167 chtype top_left =0, chtype top_right=0,
1168 chtype bottom_left =0, chtype bottom_right=0) {
1169 return ::wborder(w, left, right, top, bottom, top_left, top_right,
1170 bottom_left, bottom_right); }
1171 // Draw a border around the window with the given characters for the
1172 // various parts of the border. If you pass zero for a character, curses
1173 // will try to find "nice" characters.
1175 // -------------------------------------------------------------------------
1177 // -------------------------------------------------------------------------
1178 int hline(int len, chtype ch=0) { return ::whline(w, ch, len); }
1179 // Draw a horizontal line of len characters with the given character. If
1180 // you pass zero for the character, curses will try to find a "nice" one.
1182 int hline(int y, int x, int len, chtype ch=0) {
1183 return ::mvwhline(w, y, x, ch, len); }
1184 // Move the cursor to the requested position and then draw a horizontal line.
1186 int vline(int len, chtype ch=0) { return ::wvline(w, ch, len); }
1187 // Draw a vertical line of len characters with the given character. If
1188 // you pass zero for the character, curses will try to find a "nice" one.
1190 int vline(int y, int x, int len, chtype ch=0) {
1191 return ::mvwvline(w, y, x, ch, len); }
1192 // Move the cursor to the requested position and then draw a vertical line.
1194 // -------------------------------------------------------------------------
1196 // -------------------------------------------------------------------------
1197 int erase() { return ::werase(w); }
1198 // Erase the window.
1200 int clear() { return ::wclear(w); }
1201 // Clear the window.
1203 int clearok(bool bf) { return ::clearok(w, bf); }
1204 // Set/Reset the clear flag. If set, the next refresh() will clear the
1207 int clrtobot() { return ::wclrtobot(w); }
1208 // Clear to the end of the window.
1210 int clrtoeol() { return ::wclrtoeol(w); }
1211 // Clear to the end of the line.
1213 int delch() { return ::wdelch(w); }
1214 // Delete character under the cursor.
1216 int delch(int y, int x) { return ::mvwdelch(w, y, x); }
1217 // Move cursor to requested position and delete the character under the
1220 int deleteln() { return ::winsdelln(w, -1); }
1221 // Delete the current line.
1223 // -------------------------------------------------------------------------
1225 // -------------------------------------------------------------------------
1226 int scroll(int amount=1) { return ::wscrl(w, amount); }
1227 // Scroll amount lines. If amount is positive, scroll up, otherwise
1230 int scrollok(bool bf) { return ::scrollok(w, bf); }
1231 // If bf is TRUE, window scrolls if cursor is moved off the bottom
1232 // edge of the window or a scrolling region, otherwise the cursor is left
1233 // at the bottom line.
1235 int setscrreg(int from, int to) {
1236 return ::wsetscrreg(w, from, to); }
1237 // Define a soft scrolling region.
1239 int idlok(bool bf) { return ::idlok(w, bf); }
1240 // If bf is TRUE, use insert/delete line hardware support if possible.
1241 // Otherwise do it in software.
1243 void idcok(bool bf) { ::idcok(w, bf); }
1244 // If bf is TRUE, use insert/delete character hardware support if possible.
1245 // Otherwise do it in software.
1247 int touchline(int s, int c) { return ::touchline(w, s, c); }
1248 // Mark the given lines as modified.
1250 int touchwin() { return ::wtouchln(w, 0, height(), 1); }
1251 // Mark the whole window as modified.
1253 int untouchwin() { return ::wtouchln(w, 0, height(), 0); }
1254 // Mark the whole window as unmodified.
1256 int touchln(int s, int cnt, bool changed=TRUE) {
1257 return ::wtouchln(w, s, cnt, static_cast<int>(changed ? 1 : 0)); }
1258 // Mark cnt lines beginning from line s as changed or unchanged, depending
1259 // on the value of the changed flag.
1261 bool is_linetouched(int line) const {
1262 return (::is_linetouched(w, line) == TRUE ? TRUE:FALSE); }
1263 // Return TRUE if line is marked as changed, FALSE otherwise
1265 bool is_wintouched() const {
1266 return (::is_wintouched(w) ? TRUE:FALSE); }
1267 // Return TRUE if window is marked as changed, FALSE otherwise
1269 int leaveok(bool bf) { return ::leaveok(w, bf); }
1270 // If bf is TRUE, curses will leave the cursor after an update wherever
1271 // it is after the update.
1273 int redrawln(int from, int n) { return ::wredrawln(w, from, n); }
1274 // Redraw n lines starting from the requested line
1276 int redrawwin() { return ::wredrawln(w, 0, height()); }
1277 // Redraw the whole window
1279 int doupdate() { return ::doupdate(); }
1280 // Do all outputs to make the physical screen looking like the virtual one
1282 void syncdown() { ::wsyncdown(w); }
1283 // Propagate the changes down to all descendant windows
1285 void syncup() { ::wsyncup(w); }
1286 // Propagate the changes up in the hierarchy
1288 void cursyncup() { ::wcursyncup(w); }
1289 // Position the cursor in all ancestor windows corresponding to our setting
1291 int syncok(bool bf) { return ::syncok(w, bf); }
1292 // If called with bf=TRUE, syncup() is called whenever the window is changed
1295 int flushok(bool bf) { return ::flushok(w, bf); }
1298 void immedok(bool bf) { ::immedok(w, bf); }
1299 // If called with bf=TRUE, any change in the window will cause an
1300 // automatic immediate refresh()
1302 int intrflush(bool bf) { return ::intrflush(w, bf); }
1304 int keypad(bool bf) { return ::keypad(w, bf); }
1305 // If called with bf=TRUE, the application will interpret function keys.
1307 int nodelay(bool bf) { return ::nodelay(w, bf); }
1309 int meta(bool bf) { return ::meta(w, bf); }
1310 // If called with bf=TRUE, keys may generate 8-Bit characters. Otherwise
1311 // 7-Bit characters are generated.
1313 int standout() { return ::wstandout(w); }
1314 // Enable "standout" attributes
1316 int standend() { return ::wstandend(w); }
1317 // Disable "standout" attributes
1319 // -------------------------------------------------------------------------
1320 // The next two are virtual, because we redefine them in the
1321 // NCursesPanel class.
1322 // -------------------------------------------------------------------------
1323 virtual int refresh() { return ::wrefresh(w); }
1324 // Propagate the changes in this window to the virtual screen and call
1325 // doupdate(). This is redefined in NCursesPanel.
1327 virtual int noutrefresh() { return ::wnoutrefresh(w); }
1328 // Propagate the changes in this window to the virtual screen. This is
1329 // redefined in NCursesPanel.
1331 // -------------------------------------------------------------------------
1332 // multiple window control
1333 // -------------------------------------------------------------------------
1334 int overlay(NCursesWindow& win) {
1335 return ::overlay(w, win.w); }
1336 // Overlay this window over win.
1338 int overwrite(NCursesWindow& win) {
1339 return ::overwrite(w, win.w); }
1340 // Overwrite win with this window.
1342 int copywin(NCursesWindow& win,
1343 int sminrow, int smincol,
1344 int dminrow, int dmincol,
1345 int dmaxrow, int dmaxcol, bool overlaywin=TRUE) {
1346 return ::copywin(w, win.w, sminrow, smincol, dminrow, dmincol,
1347 dmaxrow, dmaxcol, static_cast<int>(overlaywin ? 1 : 0)); }
1348 // Overlay or overwrite the rectangle in win given by dminrow,dmincol,
1349 // dmaxrow,dmaxcol with the rectangle in this window beginning at
1352 // -------------------------------------------------------------------------
1353 // Extended functions
1354 // -------------------------------------------------------------------------
1355 #if defined(NCURSES_EXT_FUNCS) && (NCURSES_EXT_FUNCS != 0)
1356 int wresize(int newLines, int newColumns) {
1357 return ::wresize(w, newLines, newColumns); }
1360 // -------------------------------------------------------------------------
1362 // -------------------------------------------------------------------------
1363 bool has_mouse() const;
1364 // Return TRUE if terminal supports a mouse, FALSE otherwise
1366 // -------------------------------------------------------------------------
1367 // traversal support
1368 // -------------------------------------------------------------------------
1369 NCursesWindow* child() { return subwins; }
1370 // Get the first child window.
1372 NCursesWindow* sibling() { return sib; }
1373 // Get the next child of my parent.
1375 NCursesWindow* parent() { return par; }
1378 bool isDescendant(NCursesWindow& win);
1379 // Return TRUE if win is a descendant of this.
1382 // -------------------------------------------------------------------------
1383 // We leave this here for compatibility reasons.
1384 // -------------------------------------------------------------------------
1385 class NCURSES_CXX_IMPEXP NCursesColorWindow : public NCursesWindow
1388 NCursesColorWindow(WINDOW* &window) // useful only for stdscr
1389 : NCursesWindow(window) {
1392 NCursesColorWindow(int nlines, // number of lines
1393 int ncols, // number of columns
1394 int begin_y, // line origin
1395 int begin_x) // col origin
1396 : NCursesWindow(nlines, ncols, begin_y, begin_x) {
1399 NCursesColorWindow(NCursesWindow& parentWin,// parent window
1400 int nlines, // number of lines
1401 int ncols, // number of columns
1402 int begin_y, // absolute or relative
1403 int begin_x, // origins:
1404 char absrel = 'a') // if `a', by & bx are
1405 : NCursesWindow(parentWin,
1406 nlines, ncols, // absolute screen pos,
1407 begin_y, begin_x, // else if `r', they are
1408 absrel ) { // relative to par origin
1412 // These enum definitions really belong inside the NCursesPad class, but only
1413 // recent compilers support that feature.
1416 REQ_PAD_REFRESH = KEY_MAX + 1,
1424 const Pad_Request PAD_LOW = REQ_PAD_REFRESH; // lowest op-code
1425 const Pad_Request PAD_HIGH = REQ_PAD_EXIT; // highest op-code
1427 // -------------------------------------------------------------------------
1428 // Pad Support. We allow an association of a pad with a "real" window
1429 // through which the pad may be viewed.
1430 // -------------------------------------------------------------------------
1431 class NCURSES_CXX_IMPEXP NCursesPad : public NCursesWindow
1434 NCursesWindow* viewWin; // the "viewport" window
1435 NCursesWindow* viewSub; // the "viewport" subwindow
1437 int h_gridsize, v_gridsize;
1440 int min_row, min_col; // top left row/col of the pads display area
1442 NCursesWindow* Win(void) const {
1443 // Get the window into which the pad should be copied (if any)
1444 return (viewSub?viewSub:(viewWin?viewWin:0));
1447 NCursesWindow* getWindow(void) const {
1451 NCursesWindow* getSubWindow(void) const {
1455 virtual int driver (int key); // Virtualize keystroke key
1456 // The driver translates the keystroke c into an Pad_Request
1458 virtual void OnUnknownOperation(int pad_req) {
1462 // This is called if the driver returns an unknown op-code
1464 virtual void OnNavigationError(int pad_req) {
1468 // This is called if a navigation request couldn't be satisfied
1470 virtual void OnOperation(int pad_req) {
1473 // OnOperation is called if a Pad_Operation was executed and just before
1474 // the refresh() operation is done.
1477 NCursesPad(int nlines, int ncols);
1478 // create a pad with the given size
1480 NCursesPad& operator=(const NCursesPad& rhs)
1484 NCursesWindow::operator=(rhs);
1489 NCursesPad(const NCursesPad& rhs)
1490 : NCursesWindow(rhs),
1491 viewWin(rhs.viewWin),
1492 viewSub(rhs.viewSub),
1493 h_gridsize(rhs.h_gridsize),
1494 v_gridsize(rhs.v_gridsize),
1495 min_row(rhs.min_row),
1496 min_col(rhs.min_col)
1500 virtual ~NCursesPad() THROWS(NCursesException) {}
1502 int echochar(const chtype ch) { return ::pechochar(w, ch); }
1503 // Put the attributed character onto the pad and immediately do a
1507 // If a viewport is defined the pad is displayed in this window, otherwise
1510 int refresh(int pminrow, int pmincol,
1511 int sminrow, int smincol,
1512 int smaxrow, int smaxcol) {
1513 return ::prefresh(w, pminrow, pmincol,
1514 sminrow, smincol, smaxrow, smaxcol);
1516 // The coordinates sminrow,smincol,smaxrow,smaxcol describe a rectangle
1517 // on the screen. <b>refresh</b> copies a rectangle of this size beginning
1518 // with top left corner pminrow,pmincol onto the screen and calls doupdate().
1521 // If a viewport is defined the pad is displayed in this window, otherwise
1524 int noutrefresh(int pminrow, int pmincol,
1525 int sminrow, int smincol,
1526 int smaxrow, int smaxcol) {
1527 return ::pnoutrefresh(w, pminrow, pmincol,
1528 sminrow, smincol, smaxrow, smaxcol);
1530 // Does the same as refresh() but without calling doupdate().
1532 virtual void setWindow(NCursesWindow& view, int v_grid = 1, int h_grid = 1);
1533 // Add the window "view" as viewing window to the pad.
1535 virtual void setSubWindow(NCursesWindow& sub);
1536 // Use the subwindow "sub" of the viewport window for the actual viewing.
1537 // The full viewport window is usually used to provide some decorations
1538 // like frames, titles etc.
1540 virtual void operator() (void);
1541 // Perform Pad's operation
1544 // A FramedPad is constructed always with a viewport window. This viewport
1545 // will be framed (by a box() command) and the interior of the box is the
1546 // viewport subwindow. On the frame we display scrollbar sliders.
1547 class NCURSES_CXX_IMPEXP NCursesFramedPad : public NCursesPad
1550 virtual void OnOperation(int pad_req);
1553 NCursesFramedPad(NCursesWindow& win, int nlines, int ncols,
1554 int v_grid = 1, int h_grid = 1)
1555 : NCursesPad(nlines, ncols) {
1556 NCursesPad::setWindow(win, v_grid, h_grid);
1557 NCursesPad::setSubWindow(*(new NCursesWindow(win)));
1559 // Construct the FramedPad with the given Window win as viewport.
1561 virtual ~NCursesFramedPad() THROWS(NCursesException) {
1562 delete getSubWindow();
1565 void setWindow(NCursesWindow& view, int v_grid = 1, int h_grid = 1) {
1569 err_handler("Operation not allowed");
1571 // Disable this call; the viewport is already defined
1573 void setSubWindow(NCursesWindow& sub) {
1575 err_handler("Operation not allowed");
1577 // Disable this call; the viewport subwindow is already defined
1581 #endif /* NCURSES_CURSESW_H_incl */