1 // * This makes emacs happy -*-Mode: C++;-*-
2 /****************************************************************************
3 * Copyright (c) 1998-2005,2007 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 #ifndef NCURSES_CURSESW_H_incl
31 #define NCURSES_CURSESW_H_incl 1
33 // $Id: cursesw.h,v 1.47 2007/12/16 00:21:05 tom Exp $
41 /* SCO 3.2v4 curses.h includes term.h, which defines lines as a macro.
42 Undefine it here, because NCursesWindow uses lines as a method. */
45 /* "Convert" macros to inlines. We'll define it as another symbol to avoid
46 * conflict with library symbols.
49 #define UNDEF(name) CUR_ ##name
52 inline int UNDEF(addch)(chtype ch) { return addch(ch); }
54 #define addch UNDEF(addch)
58 inline int UNDEF(addchstr)(chtype *at) { return addchstr(at); }
60 #define addchstr UNDEF(addchstr)
64 inline int UNDEF(addnstr)(const char *str, int n)
65 { return addnstr(str, n); }
67 #define addnstr UNDEF(addnstr)
71 inline int UNDEF(addstr)(const char * str) { return addstr(str); }
73 #define addstr UNDEF(addstr)
77 inline int UNDEF(attroff)(chtype at) { return attroff(at); }
79 #define attroff UNDEF(attroff)
83 inline int UNDEF(attron)(chtype at) { return attron(at); }
85 #define attron UNDEF(attron)
89 inline chtype UNDEF(attrset)(chtype at) { return attrset(at); }
91 #define attrset UNDEF(attrset)
95 inline int UNDEF(bkgd)(chtype ch) { return bkgd(ch); }
97 #define bkgd UNDEF(bkgd)
101 inline void UNDEF(bkgdset)(chtype ch) { bkgdset(ch); }
103 #define bkgdset UNDEF(bkgdset)
107 inline int UNDEF(border)(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, chtype tr, chtype bl, chtype br)
108 { return border(ls, rs, ts, bs, tl, tr, bl, br); }
110 #define border UNDEF(border)
114 inline int UNDEF(box)(WINDOW *win, int v, int h) { return box(win, v, h); }
116 #define box UNDEF(box)
120 inline int UNDEF(chgat)(int n, attr_t attr, short color, const void *opts) {
121 return chgat(n, attr, color, opts); }
123 #define chgat UNDEF(chgat)
127 inline int UNDEF(clear)() { return clear(); }
129 #define clear UNDEF(clear)
133 inline int UNDEF(clearok)(WINDOW* win, bool bf) { return clearok(win, bf); }
135 #define clearok UNDEF(clearok)
137 extern "C" NCURSES_IMPEXP int NCURSES_API clearok(WINDOW*, bool);
141 inline int UNDEF(clrtobot)() { return clrtobot(); }
143 #define clrtobot UNDEF(clrtobot)
147 inline int UNDEF(clrtoeol)() { return clrtoeol(); }
149 #define clrtoeol UNDEF(clrtoeol)
153 inline chtype UNDEF(color_set)(short p, void* opts) { return color_set(p, opts); }
155 #define color_set UNDEF(color_set)
159 inline int UNDEF(crmode)(void) { return crmode(); }
161 #define crmode UNDEF(crmode)
165 inline int UNDEF(delch)() { return delch(); }
167 #define delch UNDEF(delch)
171 inline int UNDEF(deleteln)() { return deleteln(); }
173 #define deleteln UNDEF(deleteln)
177 inline int UNDEF(echochar)(chtype ch) { return echochar(ch); }
179 #define echochar UNDEF(echochar)
183 inline int UNDEF(erase)() { return erase(); }
185 #define erase UNDEF(erase)
189 inline int UNDEF(fixterm)(void) { return fixterm(); }
191 #define fixterm UNDEF(fixterm)
195 inline int UNDEF(flushok)(WINDOW* _win, bool _bf) {
196 return flushok(_win, _bf); }
198 #define flushok UNDEF(flushok)
204 inline int UNDEF(getattrs)(WINDOW *win) { return getattrs(win); }
206 #define getattrs UNDEF(getattrs)
210 inline void UNDEF(getbegyx)(WINDOW* win, int& y, int& x) { getbegyx(win, y, x); }
212 #define getbegyx UNDEF(getbegyx)
216 inline chtype UNDEF(getbkgd)(const WINDOW *win) { return getbkgd(win); }
218 #define getbkgd UNDEF(getbkgd)
222 inline int UNDEF(getch)() { return getch(); }
224 #define getch UNDEF(getch)
228 inline void UNDEF(getmaxyx)(WINDOW* win, int& y, int& x) { getmaxyx(win, y, x); }
230 #define getmaxyx UNDEF(getmaxyx)
234 inline int UNDEF(getnstr)(char *_str, int n) { return getnstr(_str, n); }
236 #define getnstr UNDEF(getnstr)
240 inline void UNDEF(getparyx)(WINDOW* win, int& y, int& x) { getparyx(win, y, x); }
242 #define getparyx UNDEF(getparyx)
246 inline int UNDEF(getstr)(char *_str) { return getstr(_str); }
248 #define getstr UNDEF(getstr)
252 inline void UNDEF(getyx)(const WINDOW* win, int& y, int& x) {
255 #define getyx UNDEF(getyx)
259 inline int UNDEF(hline)(chtype ch, int n) { return hline(ch, n); }
261 #define hline UNDEF(hline)
265 inline chtype UNDEF(inch)() { return inch(); }
267 #define inch UNDEF(inch)
271 inline int UNDEF(inchstr)(chtype *str) { return inchstr(str); }
273 #define inchstr UNDEF(inchstr)
277 inline int UNDEF(innstr)(char *_str, int n) { return innstr(_str, n); }
279 #define innstr UNDEF(innstr)
283 inline int UNDEF(insch)(chtype c) { return insch(c); }
285 #define insch UNDEF(insch)
289 inline int UNDEF(insdelln)(int n) { return insdelln(n); }
291 #define insdelln UNDEF(insdelln)
295 inline int UNDEF(insertln)() { return insertln(); }
297 #define insertln UNDEF(insertln)
301 inline int UNDEF(insnstr)(const char *_str, int n) {
302 return insnstr(_str, n); }
304 #define insnstr UNDEF(insnstr)
308 inline int UNDEF(insstr)(const char *_str) {
309 return insstr(_str); }
311 #define insstr UNDEF(insstr)
315 inline int UNDEF(instr)(char *_str) { return instr(_str); }
317 #define instr UNDEF(instr)
321 inline void UNDEF(intrflush)(WINDOW *win, bool bf) { intrflush(); }
323 #define intrflush UNDEF(intrflush)
327 inline int UNDEF(leaveok)(WINDOW* win, bool bf) { return leaveok(win, bf); }
329 #define leaveok UNDEF(leaveok)
331 extern "C" NCURSES_IMPEXP int NCURSES_API leaveok(WINDOW* win, bool bf);
335 inline int UNDEF(move)(int x, int y) { return move(x, y); }
337 #define move UNDEF(move)
341 inline int UNDEF(mvaddch)(int y, int x, chtype ch)
342 { return mvaddch(y, x, ch); }
344 #define mvaddch UNDEF(mvaddch)
348 inline int UNDEF(mvaddnstr)(int y, int x, const char *str, int n)
349 { return mvaddnstr(y, x, str, n); }
351 #define mvaddnstr UNDEF(mvaddnstr)
355 inline int UNDEF(mvaddstr)(int y, int x, const char * str)
356 { return mvaddstr(y, x, str); }
358 #define mvaddstr UNDEF(mvaddstr)
362 inline int UNDEF(mvchgat)(int y, int x, int n,
363 attr_t attr, short color, const void *opts) {
364 return mvchgat(y, x, n, attr, color, opts); }
366 #define mvchgat UNDEF(mvchgat)
370 inline int UNDEF(mvdelch)(int y, int x) { return mvdelch(y, x);}
372 #define mvdelch UNDEF(mvdelch)
376 inline int UNDEF(mvgetch)(int y, int x) { return mvgetch(y, x);}
378 #define mvgetch UNDEF(mvgetch)
382 inline int UNDEF(mvgetnstr)(int y, int x, char *str, int n) {
383 return mvgetnstr(y, x, str, n);}
385 #define mvgetnstr UNDEF(mvgetnstr)
389 inline int UNDEF(mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
391 #define mvgetstr UNDEF(mvgetstr)
395 inline chtype UNDEF(mvinch)(int y, int x) { return mvinch(y, x);}
397 #define mvinch UNDEF(mvinch)
401 inline int UNDEF(mvinnstr)(int y, int x, char *_str, int n) {
402 return mvinnstr(y, x, _str, n); }
404 #define mvinnstr UNDEF(mvinnstr)
408 inline int UNDEF(mvinsch)(int y, int x, chtype c)
409 { return mvinsch(y, x, c); }
411 #define mvinsch UNDEF(mvinsch)
415 inline int UNDEF(mvinsnstr)(int y, int x, const char *_str, int n) {
416 return mvinsnstr(y, x, _str, n); }
418 #define mvinsnstr UNDEF(mvinsnstr)
422 inline int UNDEF(mvinsstr)(int y, int x, const char *_str) {
423 return mvinsstr(y, x, _str); }
425 #define mvinsstr UNDEF(mvinsstr)
429 inline int UNDEF(mvwaddch)(WINDOW *win, int y, int x, const chtype ch)
430 { return mvwaddch(win, y, x, ch); }
432 #define mvwaddch UNDEF(mvwaddch)
436 inline int UNDEF(mvwaddchnstr)(WINDOW *win, int y, int x, const chtype *str, int n)
437 { return mvwaddchnstr(win, y, x, str, n); }
439 #define mvwaddchnstr UNDEF(mvwaddchnstr)
443 inline int UNDEF(mvwaddchstr)(WINDOW *win, int y, int x, const chtype *str)
444 { return mvwaddchstr(win, y, x, str); }
446 #define mvwaddchstr UNDEF(mvwaddchstr)
450 inline int UNDEF(mvwaddnstr)(WINDOW *win, int y, int x, const char *str, int n)
451 { return mvwaddnstr(win, y, x, str, n); }
453 #define mvwaddnstr UNDEF(mvwaddnstr)
457 inline int UNDEF(mvwaddstr)(WINDOW *win, int y, int x, const char * str)
458 { return mvwaddstr(win, y, x, str); }
460 #define mvwaddstr UNDEF(mvwaddstr)
464 inline int UNDEF(mvwchgat)(WINDOW *win, int y, int x, int n,
465 attr_t attr, short color, const void *opts) {
466 return mvwchgat(win, y, x, n, attr, color, opts); }
468 #define mvwchgat UNDEF(mvwchgat)
472 inline int UNDEF(mvwdelch)(WINDOW *win, int y, int x)
473 { return mvwdelch(win, y, x); }
475 #define mvwdelch UNDEF(mvwdelch)
479 inline int UNDEF(mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
481 #define mvwgetch UNDEF(mvwgetch)
485 inline int UNDEF(mvwgetnstr)(WINDOW *win, int y, int x, char *str, int n)
486 {return mvwgetnstr(win, y, x, str, n);}
488 #define mvwgetnstr UNDEF(mvwgetnstr)
492 inline int UNDEF(mvwgetstr)(WINDOW *win, int y, int x, char *str)
493 {return mvwgetstr(win, y, x, str);}
495 #define mvwgetstr UNDEF(mvwgetstr)
499 inline int UNDEF(mvwhline)(WINDOW *win, int y, int x, chtype c, int n) {
500 return mvwhline(win, y, x, c, n); }
502 #define mvwhline UNDEF(mvwhline)
506 inline chtype UNDEF(mvwinch)(WINDOW *win, int y, int x) {
507 return mvwinch(win, y, x);}
509 #define mvwinch UNDEF(mvwinch)
513 inline int UNDEF(mvwinchnstr)(WINDOW *win, int y, int x, chtype *str, int n) { return mvwinchnstr(win, y, x, str, n); }
515 #define mvwinchnstr UNDEF(mvwinchnstr)
519 inline int UNDEF(mvwinchstr)(WINDOW *win, int y, int x, chtype *str) { return mvwinchstr(win, y, x, str); }
521 #define mvwinchstr UNDEF(mvwinchstr)
525 inline int UNDEF(mvwinnstr)(WINDOW *win, int y, int x, char *_str, int n) {
526 return mvwinnstr(win, y, x, _str, n); }
528 #define mvwinnstr UNDEF(mvwinnstr)
532 inline int UNDEF(mvwinsch)(WINDOW *win, int y, int x, chtype c)
533 { return mvwinsch(win, y, x, c); }
535 #define mvwinsch UNDEF(mvwinsch)
539 inline int UNDEF(mvwinsnstr)(WINDOW *w, int y, int x, const char *_str, int n) {
540 return mvwinsnstr(w, y, x, _str, n); }
542 #define mvwinsnstr UNDEF(mvwinsnstr)
546 inline int UNDEF(mvwinsstr)(WINDOW *w, int y, int x, const char *_str) {
547 return mvwinsstr(w, y, x, _str); }
549 #define mvwinsstr UNDEF(mvwinsstr)
553 inline int UNDEF(mvwvline)(WINDOW *win, int y, int x, chtype c, int n) {
554 return mvwvline(win, y, x, c, n); }
556 #define mvwvline UNDEF(mvwvline)
560 inline void UNDEF(napms)(unsigned long x) { napms(x); }
562 #define napms UNDEF(napms)
566 inline int UNDEF(nocrmode)(void) { return nocrmode(); }
568 #define nocrmode UNDEF(nocrmode)
572 inline void UNDEF(nodelay)() { nodelay(); }
574 #define nodelay UNDEF(nodelay)
578 inline int UNDEF(redrawwin)(WINDOW *win) { return redrawwin(win); }
580 #define redrawwin UNDEF(redrawwin)
584 inline int UNDEF(refresh)() { return refresh(); }
586 #define refresh UNDEF(refresh)
590 inline int UNDEF(resetterm)(void) { return resetterm(); }
592 #define resetterm UNDEF(resetterm)
596 inline int UNDEF(saveterm)(void) { return saveterm(); }
598 #define saveterm UNDEF(saveterm)
602 inline int UNDEF(scrl)(int l) { return scrl(l); }
604 #define scrl UNDEF(scrl)
608 inline int UNDEF(scroll)(WINDOW *win) { return scroll(win); }
610 #define scroll UNDEF(scroll)
614 inline int UNDEF(scrollok)(WINDOW* win, bool bf) { return scrollok(win, bf); }
616 #define scrollok UNDEF(scrollok)
618 #if defined(__NCURSES_H)
619 extern "C" NCURSES_IMPEXP int NCURSES_API scrollok(WINDOW*, bool);
621 extern "C" NCURSES_IMPEXP int NCURSES_API scrollok(WINDOW*, char);
626 inline int UNDEF(setscrreg)(int t, int b) { return setscrreg(t, b); }
628 #define setscrreg UNDEF(setscrreg)
632 inline int UNDEF(standend)() { return standend(); }
634 #define standend UNDEF(standend)
638 inline int UNDEF(standout)() { return standout(); }
640 #define standout UNDEF(standout)
644 inline WINDOW *UNDEF(subpad)(WINDOW *p, int l, int c, int y, int x)
645 { return derwin(p, l, c, y, x); }
647 #define subpad UNDEF(subpad)
651 inline void UNDEF(timeout)(int delay) { timeout(delay); }
653 #define timeout UNDEF(timeout)
657 inline int UNDEF(touchline)(WINDOW *win, int s, int c)
658 { return touchline(win, s, c); }
660 #define touchline UNDEF(touchline)
664 inline int UNDEF(touchwin)(WINDOW *win) { return touchwin(win); }
666 #define touchwin UNDEF(touchwin)
670 inline int UNDEF(untouchwin)(WINDOW *win) { return untouchwin(win); }
672 #define untouchwin UNDEF(untouchwin)
676 inline int UNDEF(vline)(chtype ch, int n) { return vline(ch, n); }
678 #define vline UNDEF(vline)
682 inline int UNDEF(waddchstr)(WINDOW *win, chtype *at) { return waddchstr(win, at); }
684 #define waddchstr UNDEF(waddchstr)
688 inline int UNDEF(waddstr)(WINDOW *win, char *str) { return waddstr(win, str); }
690 #define waddstr UNDEF(waddstr)
694 inline int UNDEF(wattroff)(WINDOW *win, int att) { return wattroff(win, att); }
696 #define wattroff UNDEF(wattroff)
700 inline int UNDEF(wattrset)(WINDOW *win, int att) { return wattrset(win, att); }
702 #define wattrset UNDEF(wattrset)
706 inline chtype UNDEF(winch)(const WINDOW* win) { return winch(win); }
708 #define winch UNDEF(winch)
712 inline int UNDEF(winchnstr)(WINDOW *win, chtype *str, int n) { return winchnstr(win, str, n); }
714 #define winchnstr UNDEF(winchnstr)
718 inline int UNDEF(winchstr)(WINDOW *win, chtype *str) { return winchstr(win, str); }
720 #define winchstr UNDEF(winchstr)
724 inline int UNDEF(winsstr)(WINDOW *w, const char *_str) {
725 return winsstr(w, _str); }
727 #define winsstr UNDEF(winsstr)
731 inline int UNDEF(wstandend)(WINDOW *win) { return wstandend(win); }
733 #define wstandend UNDEF(wstandend)
737 inline int UNDEF(wstandout)(WINDOW *win) { return wstandout(win); }
739 #define wstandout UNDEF(wstandout)
744 * C++ class for windows.
748 extern "C" int _nc_ripoffline(int, int (*init)(WINDOW*, int));
749 extern "C" int _nc_xx_ripoff_init(WINDOW *, int);
750 extern "C" int _nc_has_mouse(void);
752 class NCURSES_IMPEXP NCursesWindow
754 friend class NCursesMenu;
755 friend class NCursesForm;
758 static bool b_initialized;
759 static void initialize();
761 friend int _nc_xx_ripoff_init(WINDOW *, int);
765 short getcolor(int getback) const;
766 short getPair() const;
768 static int setpalette(short fore, short back, short pair);
769 static int colorInitialized;
771 // This private constructor is only used during the initialization
772 // of windows generated by ripoffline() calls.
773 NCursesWindow(WINDOW* win, int ncols);
776 virtual void err_handler(const char *) const THROWS(NCursesException);
777 // Signal an error with the given message text.
779 static long count; // count of all active windows:
780 // We rely on the c++ promise that
781 // all otherwise uninitialized
782 // static class vars are set to 0
784 WINDOW* w; // the curses WINDOW
786 bool alloced; // TRUE if we own the WINDOW
788 NCursesWindow* par; // parent, if subwindow
789 NCursesWindow* subwins; // head of subwindows list
790 NCursesWindow* sib; // next subwindow of parent
792 void kill_subwindows(); // disable all subwindows
793 // Destroy all subwindows.
795 /* Only for use by derived classes. They are then in charge to
796 fill the member variables correctly. */
800 NCursesWindow(WINDOW* window); // useful only for stdscr
802 NCursesWindow(int nlines, // number of lines
803 int ncols, // number of columns
804 int begin_y, // line origin
805 int begin_x); // col origin
807 NCursesWindow(NCursesWindow& par,// parent window
808 int nlines, // number of lines
809 int ncols, // number of columns
810 int begin_y, // absolute or relative
811 int begin_x, // origins:
812 char absrel = 'a');// if `a', begin_y & begin_x are
813 // absolute screen pos, else if `r', they are relative to par origin
815 NCursesWindow(NCursesWindow& par,// parent window
817 // this is the very common case that we want to create the subwindow that
818 // is two lines and two columns smaller and begins at (1,1).
819 // We may automatically request the box around it.
821 NCursesWindow& operator=(const NCursesWindow& rhs)
828 NCursesWindow(const NCursesWindow& rhs)
829 : w(rhs.w), alloced(rhs.alloced), par(rhs.par), subwins(rhs.subwins), sib(rhs.sib)
833 virtual ~NCursesWindow();
835 NCursesWindow Clone();
836 // Make an exact copy of the window.
839 static void useColors(void);
840 // Call this routine very early if you want to have colors.
842 static int ripoffline(int ripoff_lines,
843 int (*init)(NCursesWindow& win));
844 // This function is used to generate a window of ripped-of lines.
845 // If the argument is positive, lines are removed from the top, if it
846 // is negative lines are removed from the bottom. This enhances the
847 // lowlevel ripoffline() function because it uses the internal
848 // implementation that allows to remove more than just a single line.
849 // This function must be called before any other ncurses function. The
850 // creation of the window is deferred until ncurses gets initialized.
851 // The initialization function is then called.
853 // -------------------------------------------------------------------------
855 // -------------------------------------------------------------------------
856 int lines() const { initialize(); return LINES; }
857 // Number of lines on terminal, *not* window
859 int cols() const { initialize(); return COLS; }
860 // Number of cols on terminal, *not* window
862 int tabsize() const { initialize(); return TABSIZE; }
863 // Size of a tab on terminal, *not* window
865 static int NumberOfColors();
866 // Number of available colors
868 int colors() const { return NumberOfColors(); }
869 // Number of available colors
871 // -------------------------------------------------------------------------
873 // -------------------------------------------------------------------------
874 int height() const { return maxy() + 1; }
875 // Number of lines in this window
877 int width() const { return maxx() + 1; }
878 // Number of columns in this window
880 int begx() const { return getbegx(w); }
881 // Column of top left corner relative to stdscr
883 int begy() const { return getbegy(w); }
884 // Line of top left corner relative to stdscr
886 int curx() const { return getcurx(w); }
887 // Column of top left corner relative to stdscr
889 int cury() const { return getcury(w); }
890 // Line of top left corner relative to stdscr
892 int maxx() const { return getmaxx(w) == ERR ? ERR : getmaxx(w)-1; }
893 // Largest x coord in window
895 int maxy() const { return getmaxy(w) == ERR ? ERR : getmaxy(w)-1; }
896 // Largest y coord in window
898 short getcolor() const;
901 short foreground() const { return getcolor(0); }
902 // Actual foreground color
904 short background() const { return getcolor(1); }
905 // Actual background color
907 int setpalette(short fore, short back);
908 // Set color palette entry
910 int setcolor(short pair);
911 // Set actually used palette entry
913 // -------------------------------------------------------------------------
914 // window positioning
915 // -------------------------------------------------------------------------
916 virtual int mvwin(int begin_y, int begin_x) {
917 return ::mvwin(w, begin_y, begin_x); }
918 // Move window to new position with the new position as top left corner.
919 // This is virtual because it is redefined in NCursesPanel.
921 // -------------------------------------------------------------------------
922 // coordinate positioning
923 // -------------------------------------------------------------------------
924 int move(int y, int x) { return ::wmove(w, y, x); }
925 // Move cursor the this position
927 void getyx(int& y, int& x) const { ::getyx(w, y, x); }
928 // Get current position of the cursor
930 void getbegyx(int& y, int& x) const { ::getbegyx(w, y, x); }
931 // Get beginning of the window
933 void getmaxyx(int& y, int& x) const { ::getmaxyx(w, y, x); }
934 // Get size of the window
936 void getparyx(int& y, int& x) const { ::getparyx(w, y, x); }
937 // Get parent's beginning of the window
939 int mvcur(int oldrow, int oldcol, int newrow, int newcol) const {
940 return ::mvcur(oldrow, oldcol, newrow, newcol); }
941 // Perform lowlevel cursor motion that takes effect immediately.
943 // -------------------------------------------------------------------------
945 // -------------------------------------------------------------------------
946 int getch() { return ::wgetch(w); }
947 // Get a keystroke from the window.
949 int getch(int y, int x) { return ::mvwgetch(w, y, x); }
950 // Move cursor to position and get a keystroke from the window
952 int getstr(char* str, int n=-1) {
953 return ::wgetnstr(w, str, n); }
954 // Read a series of characters into str until a newline or carriage return
955 // is received. Read at most n characters. If n is negative, the limit is
958 int getstr(int y, int x, char* str, int n=-1) {
959 return ::mvwgetnstr(w, y, x, str, n); }
960 // Move the cursor to the requested position and then perform the getstr()
961 // as described above.
963 int instr(char *s, int n=-1) { return ::winnstr(w, s, n); }
964 // Get a string of characters from the window into the buffer s. Retrieve
965 // at most n characters, if n is negative retrieve all characters up to the
966 // end of the current line. Attributes are stripped from the characters.
968 int instr(int y, int x, char *s, int n=-1) {
969 return ::mvwinnstr(w, y, x, s, n); }
970 // Move the cursor to the requested position and then perform the instr()
971 // as described above.
973 int scanw(const char* fmt, ...)
974 // Perform a scanw function from the window.
976 __attribute__ ((format (scanf, 2, 3)));
981 int scanw(const char*, va_list);
982 // Perform a scanw function from the window.
984 int scanw(int y, int x, const char* fmt, ...)
985 // Move the cursor to the requested position and then perform a scanw
988 __attribute__ ((format (scanf, 4, 5)));
993 int scanw(int y, int x, const char* fmt, va_list);
994 // Move the cursor to the requested position and then perform a scanw
997 // -------------------------------------------------------------------------
999 // -------------------------------------------------------------------------
1000 int addch(const chtype ch) { return ::waddch(w, ch); }
1001 // Put attributed character to the window.
1003 int addch(int y, int x, const chtype ch) {
1004 return ::mvwaddch(w, y, x, ch); }
1005 // Move cursor to the requested position and then put attributed character
1008 int echochar(const chtype ch) { return ::wechochar(w, ch); }
1009 // Put attributed character to the window and refresh it immediately.
1011 int addstr(const char* str, int n=-1) {
1012 return ::waddnstr(w, str, n); }
1013 // Write the string str to the window, stop writing if the terminating
1014 // NUL or the limit n is reached. If n is negative, it is ignored.
1016 int addstr(int y, int x, const char * str, int n=-1) {
1017 return ::mvwaddnstr(w, y, x, str, n); }
1018 // Move the cursor to the requested position and then perform the addchstr
1019 // as described above.
1021 int addchstr(const chtype* str, int n=-1) {
1022 return ::waddchnstr(w, str, n); }
1023 // Write the string str to the window, stop writing if the terminating
1024 // NUL or the limit n is reached. If n is negative, it is ignored.
1026 int addchstr(int y, int x, const chtype * str, int n=-1) {
1027 return ::mvwaddchnstr(w, y, x, str, n); }
1028 // Move the cursor to the requested position and then perform the addchstr
1029 // as described above.
1031 int printw(const char* fmt, ...)
1032 // Do a formatted print to the window.
1033 #if (__GNUG__ >= 2) && !defined(printf)
1034 __attribute__ ((format (printf, 2, 3)));
1039 int printw(int y, int x, const char * fmt, ...)
1040 // Move the cursor and then do a formatted print to the window.
1041 #if (__GNUG__ >= 2) && !defined(printf)
1042 __attribute__ ((format (printf, 4, 5)));
1047 int printw(const char* fmt, va_list args);
1048 // Do a formatted print to the window.
1050 int printw(int y, int x, const char * fmt, va_list args);
1051 // Move the cursor and then do a formatted print to the window.
1053 chtype inch() const { return ::winch(w); }
1054 // Retrieve attributed character under the current cursor position.
1056 chtype inch(int y, int x) { return ::mvwinch(w, y, x); }
1057 // Move cursor to requested position and then retrieve attributed character
1058 // at this position.
1060 int inchstr(chtype* str, int n=-1) {
1061 return ::winchnstr(w, str, n); }
1062 // Read the string str from the window, stop reading if the terminating
1063 // NUL or the limit n is reached. If n is negative, it is ignored.
1065 int inchstr(int y, int x, chtype * str, int n=-1) {
1066 return ::mvwinchnstr(w, y, x, str, n); }
1067 // Move the cursor to the requested position and then perform the inchstr
1068 // as described above.
1070 int insch(chtype ch) { return ::winsch(w, ch); }
1071 // Insert attributed character into the window before current cursor
1074 int insch(int y, int x, chtype ch) {
1075 return ::mvwinsch(w, y, x, ch); }
1076 // Move cursor to requested position and then insert the attributed
1077 // character before that position.
1079 int insertln() { return ::winsdelln(w, 1); }
1080 // Insert an empty line above the current line.
1082 int insdelln(int n=1) { return ::winsdelln(w, n); }
1083 // If n>0 insert that many lines above the current line. If n<0 delete
1084 // that many lines beginning with the current line.
1086 int insstr(const char *s, int n=-1) {
1087 return ::winsnstr(w, s, n); }
1088 // Insert the string into the window before the current cursor position.
1089 // Insert stops at end of string or when the limit n is reached. If n is
1090 // negative, it is ignored.
1092 int insstr(int y, int x, const char *s, int n=-1) {
1093 return ::mvwinsnstr(w, y, x, s, n); }
1094 // Move the cursor to the requested position and then perform the insstr()
1095 // as described above.
1097 int attron (chtype at) { return ::wattron (w, at); }
1098 // Switch on the window attributes;
1100 int attroff(chtype at) { return ::wattroff(w, static_cast<int>(at)); }
1101 // Switch off the window attributes;
1103 int attrset(chtype at) { return ::wattrset(w, static_cast<int>(at)); }
1104 // Set the window attributes;
1106 chtype attrget() { return ::getattrs(w); }
1107 // Get the window attributes;
1109 int color_set(short color_pair_number, void* opts=NULL) {
1110 return ::wcolor_set(w, color_pair_number, opts); }
1111 // Set the window color attribute;
1113 int chgat(int n, attr_t attr, short color, const void *opts=NULL) {
1114 return ::wchgat(w, n, attr, color, opts); }
1115 // Change the attributes of the next n characters in the current line. If
1116 // n is negative or greater than the number of remaining characters in the
1117 // line, the attributes will be changed up to the end of the line.
1119 int chgat(int y, int x,
1120 int n, attr_t attr, short color, const void *opts=NULL) {
1121 return ::mvwchgat(w, y, x, n, attr, color, opts); }
1122 // Move the cursor to the requested position and then perform chgat() as
1125 // -------------------------------------------------------------------------
1127 // -------------------------------------------------------------------------
1128 chtype getbkgd() const { return ::getbkgd(w); }
1129 // Get current background setting.
1131 int bkgd(const chtype ch) { return ::wbkgd(w, ch); }
1132 // Set the background property and apply it to the window.
1134 void bkgdset(chtype ch) { ::wbkgdset(w, ch); }
1135 // Set the background property.
1137 // -------------------------------------------------------------------------
1139 // -------------------------------------------------------------------------
1140 int box(chtype vert=0, chtype hor=0) {
1141 return ::wborder(w, vert, vert, hor, hor, 0, 0, 0, 0); }
1142 // Draw a box around the window with the given vertical and horizontal
1143 // drawing characters. If you specify a zero as character, curses will try
1144 // to find a "nice" character.
1146 int border(chtype left=0, chtype right=0,
1147 chtype top =0, chtype bottom=0,
1148 chtype top_left =0, chtype top_right=0,
1149 chtype bottom_left =0, chtype bottom_right=0) {
1150 return ::wborder(w, left, right, top, bottom, top_left, top_right,
1151 bottom_left, bottom_right); }
1152 // Draw a border around the window with the given characters for the
1153 // various parts of the border. If you pass zero for a character, curses
1154 // will try to find "nice" characters.
1156 // -------------------------------------------------------------------------
1158 // -------------------------------------------------------------------------
1159 int hline(int len, chtype ch=0) { return ::whline(w, ch, len); }
1160 // Draw a horizontal line of len characters with the given character. If
1161 // you pass zero for the character, curses will try to find a "nice" one.
1163 int hline(int y, int x, int len, chtype ch=0) {
1164 return ::mvwhline(w, y, x, ch, len); }
1165 // Move the cursor to the requested position and then draw a horizontal line.
1167 int vline(int len, chtype ch=0) { return ::wvline(w, ch, len); }
1168 // Draw a vertical 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 vline(int y, int x, int len, chtype ch=0) {
1172 return ::mvwvline(w, y, x, ch, len); }
1173 // Move the cursor to the requested position and then draw a vertical line.
1175 // -------------------------------------------------------------------------
1177 // -------------------------------------------------------------------------
1178 int erase() { return ::werase(w); }
1179 // Erase the window.
1181 int clear() { return ::wclear(w); }
1182 // Clear the window.
1184 int clearok(bool bf) { return ::clearok(w, bf); }
1185 // Set/Reset the clear flag. If set, the next refresh() will clear the
1188 int clrtobot() { return ::wclrtobot(w); }
1189 // Clear to the end of the window.
1191 int clrtoeol() { return ::wclrtoeol(w); }
1192 // Clear to the end of the line.
1194 int delch() { return ::wdelch(w); }
1195 // Delete character under the cursor.
1197 int delch(int y, int x) { return ::mvwdelch(w, y, x); }
1198 // Move cursor to requested position and delete the character under the
1201 int deleteln() { return ::winsdelln(w, -1); }
1202 // Delete the current line.
1204 // -------------------------------------------------------------------------
1206 // -------------------------------------------------------------------------
1207 int scroll(int amount=1) { return ::wscrl(w, amount); }
1208 // Scroll amount lines. If amount is positive, scroll up, otherwise
1211 int scrollok(bool bf) { return ::scrollok(w, bf); }
1212 // If bf is TRUE, window scrolls if cursor is moved off the bottom
1213 // edge of the window or a scrolling region, otherwise the cursor is left
1214 // at the bottom line.
1216 int setscrreg(int from, int to) {
1217 return ::wsetscrreg(w, from, to); }
1218 // Define a soft scrolling region.
1220 int idlok(bool bf) { return ::idlok(w, bf); }
1221 // If bf is TRUE, use insert/delete line hardware support if possible.
1222 // Otherwise do it in software.
1224 void idcok(bool bf) { ::idcok(w, bf); }
1225 // If bf is TRUE, use insert/delete character hardware support if possible.
1226 // Otherwise do it in software.
1228 int touchline(int s, int c) { return ::touchline(w, s, c); }
1229 // Mark the given lines as modified.
1231 int touchwin() { return ::wtouchln(w, 0, height(), 1); }
1232 // Mark the whole window as modified.
1234 int untouchwin() { return ::wtouchln(w, 0, height(), 0); }
1235 // Mark the whole window as unmodified.
1237 int touchln(int s, int cnt, bool changed=TRUE) {
1238 return ::wtouchln(w, s, cnt, static_cast<int>(changed ? 1 : 0)); }
1239 // Mark cnt lines beginning from line s as changed or unchanged, depending
1240 // on the value of the changed flag.
1242 bool is_linetouched(int line) const {
1243 return (::is_linetouched(w, line) ? TRUE:FALSE); }
1244 // Return TRUE if line is marked as changed, FALSE otherwise
1246 bool is_wintouched() const {
1247 return (::is_wintouched(w) ? TRUE:FALSE); }
1248 // Return TRUE if window is marked as changed, FALSE otherwise
1250 int leaveok(bool bf) { return ::leaveok(w, bf); }
1251 // If bf is TRUE, curses will leave the cursor after an update whereever
1252 // it is after the update.
1254 int redrawln(int from, int n) { return ::wredrawln(w, from, n); }
1255 // Redraw n lines starting from the requested line
1257 int redrawwin() { return ::wredrawln(w, 0, height()); }
1258 // Redraw the whole window
1260 int doupdate() { return ::doupdate(); }
1261 // Do all outputs to make the physical screen looking like the virtual one
1263 void syncdown() { ::wsyncdown(w); }
1264 // Propagate the changes down to all descendant windows
1266 void syncup() { ::wsyncup(w); }
1267 // Propagate the changes up in the hierarchy
1269 void cursyncup() { ::wcursyncup(w); }
1270 // Position the cursor in all ancestor windows corresponding to our setting
1272 int syncok(bool bf) { return ::syncok(w, bf); }
1273 // If called with bf=TRUE, syncup() is called whenever the window is changed
1276 int flushok(bool bf) { return ::flushok(w, bf); }
1279 void immedok(bool bf) { ::immedok(w, bf); }
1280 // If called with bf=TRUE, any change in the window will cause an
1281 // automatic immediate refresh()
1283 int intrflush(bool bf) { return ::intrflush(w, bf); }
1285 int keypad(bool bf) { return ::keypad(w, bf); }
1286 // If called with bf=TRUE, the application will interpret function keys.
1288 int nodelay(bool bf) { return ::nodelay(w, bf); }
1290 int meta(bool bf) { return ::meta(w, bf); }
1291 // If called with bf=TRUE, keys may generate 8-Bit characters. Otherwise
1292 // 7-Bit characters are generated.
1294 int standout() { return ::wstandout(w); }
1295 // Enable "standout" attributes
1297 int standend() { return ::wstandend(w); }
1298 // Disable "standout" attributes
1300 // -------------------------------------------------------------------------
1301 // The next two are virtual, because we redefine them in the
1302 // NCursesPanel class.
1303 // -------------------------------------------------------------------------
1304 virtual int refresh() { return ::wrefresh(w); }
1305 // Propagate the changes in this window to the virtual screen and call
1306 // doupdate(). This is redefined in NCursesPanel.
1308 virtual int noutrefresh() { return ::wnoutrefresh(w); }
1309 // Propagate the changes in this window to the virtual screen. This is
1310 // redefined in NCursesPanel.
1312 // -------------------------------------------------------------------------
1313 // multiple window control
1314 // -------------------------------------------------------------------------
1315 int overlay(NCursesWindow& win) {
1316 return ::overlay(w, win.w); }
1317 // Overlay this window over win.
1319 int overwrite(NCursesWindow& win) {
1320 return ::overwrite(w, win.w); }
1321 // Overwrite win with this window.
1323 int copywin(NCursesWindow& win,
1324 int sminrow, int smincol,
1325 int dminrow, int dmincol,
1326 int dmaxrow, int dmaxcol, bool overlaywin=TRUE) {
1327 return ::copywin(w, win.w, sminrow, smincol, dminrow, dmincol,
1328 dmaxrow, dmaxcol, static_cast<int>(overlaywin ? 1 : 0)); }
1329 // Overlay or overwrite the rectangle in win given by dminrow,dmincol,
1330 // dmaxrow,dmaxcol with the rectangle in this window beginning at
1333 // -------------------------------------------------------------------------
1334 // Extended functions
1335 // -------------------------------------------------------------------------
1336 #ifdef NCURSES_EXT_FUNCS
1337 int wresize(int newLines, int newColumns) {
1338 return ::wresize(w, newLines, newColumns); }
1341 // -------------------------------------------------------------------------
1343 // -------------------------------------------------------------------------
1344 bool has_mouse() const;
1345 // Return TRUE if terminal supports a mouse, FALSE otherwise
1347 // -------------------------------------------------------------------------
1348 // traversal support
1349 // -------------------------------------------------------------------------
1350 NCursesWindow* child() { return subwins; }
1351 // Get the first child window.
1353 NCursesWindow* sibling() { return sib; }
1354 // Get the next child of my parent.
1356 NCursesWindow* parent() { return par; }
1359 bool isDescendant(NCursesWindow& win);
1360 // Return TRUE if win is a descendant of this.
1363 // -------------------------------------------------------------------------
1364 // We leave this here for compatibility reasons.
1365 // -------------------------------------------------------------------------
1366 class NCURSES_IMPEXP NCursesColorWindow : public NCursesWindow
1369 NCursesColorWindow(WINDOW* &window) // useful only for stdscr
1370 : NCursesWindow(window) {
1373 NCursesColorWindow(int nlines, // number of lines
1374 int ncols, // number of columns
1375 int begin_y, // line origin
1376 int begin_x) // col origin
1377 : NCursesWindow(nlines, ncols, begin_y, begin_x) {
1380 NCursesColorWindow(NCursesWindow& parentWin,// parent window
1381 int nlines, // number of lines
1382 int ncols, // number of columns
1383 int begin_y, // absolute or relative
1384 int begin_x, // origins:
1385 char absrel = 'a') // if `a', by & bx are
1386 : NCursesWindow(parentWin,
1387 nlines, ncols, // absolute screen pos,
1388 begin_y, begin_x, // else if `r', they are
1389 absrel ) { // relative to par origin
1393 // These enum definitions really belong inside the NCursesPad class, but only
1394 // recent compilers support that feature.
1397 REQ_PAD_REFRESH = KEY_MAX + 1,
1405 const Pad_Request PAD_LOW = REQ_PAD_REFRESH; // lowest op-code
1406 const Pad_Request PAD_HIGH = REQ_PAD_EXIT; // highest op-code
1408 // -------------------------------------------------------------------------
1409 // Pad Support. We allow an association of a pad with a "real" window
1410 // through which the pad may be viewed.
1411 // -------------------------------------------------------------------------
1412 class NCURSES_IMPEXP NCursesPad : public NCursesWindow
1415 NCursesWindow* viewWin; // the "viewport" window
1416 NCursesWindow* viewSub; // the "viewport" subwindow
1418 int h_gridsize, v_gridsize;
1421 int min_row, min_col; // top left row/col of the pads display area
1423 NCursesWindow* Win(void) const {
1424 // Get the window into which the pad should be copied (if any)
1425 return (viewSub?viewSub:(viewWin?viewWin:0));
1428 NCursesWindow* getWindow(void) const {
1432 NCursesWindow* getSubWindow(void) const {
1436 virtual int driver (int key); // Virtualize keystroke key
1437 // The driver translates the keystroke c into an Pad_Request
1439 virtual void OnUnknownOperation(int pad_req) {
1442 // This is called if the driver returns an unknown op-code
1444 virtual void OnNavigationError(int pad_req) {
1447 // This is called if a navigation request couldn't be satisfied
1449 virtual void OnOperation(int pad_req) {
1451 // OnOperation is called if a Pad_Operation was executed and just before
1452 // the refresh() operation is done.
1455 NCursesPad(int nlines, int ncols);
1456 // create a pad with the given size
1458 NCursesPad& operator=(const NCursesPad& rhs)
1462 NCursesWindow::operator=(rhs);
1467 NCursesPad(const NCursesPad& rhs)
1468 : NCursesWindow(rhs),
1469 viewWin(rhs.viewWin),
1470 viewSub(rhs.viewSub),
1471 h_gridsize(rhs.h_gridsize),
1472 v_gridsize(rhs.v_gridsize),
1473 min_row(rhs.min_row),
1474 min_col(rhs.min_col)
1478 virtual ~NCursesPad() {}
1480 int echochar(const chtype ch) { return ::pechochar(w, ch); }
1481 // Put the attributed character onto the pad and immediately do a
1485 // If a viewport is defined the pad is displayed in this window, otherwise
1488 int refresh(int pminrow, int pmincol,
1489 int sminrow, int smincol,
1490 int smaxrow, int smaxcol) {
1491 return ::prefresh(w, pminrow, pmincol,
1492 sminrow, smincol, smaxrow, smaxcol);
1494 // The coordinates sminrow,smincol,smaxrow,smaxcol describe a rectangle
1495 // on the screen. <b>refresh</b> copies a rectangle of this size beginning
1496 // with top left corner pminrow,pmincol onto the screen and calls doupdate().
1499 // If a viewport is defined the pad is displayed in this window, otherwise
1502 int noutrefresh(int pminrow, int pmincol,
1503 int sminrow, int smincol,
1504 int smaxrow, int smaxcol) {
1505 return ::pnoutrefresh(w, pminrow, pmincol,
1506 sminrow, smincol, smaxrow, smaxcol);
1508 // Does the same as refresh() but without calling doupdate().
1510 virtual void setWindow(NCursesWindow& view, int v_grid = 1, int h_grid = 1);
1511 // Add the window "view" as viewing window to the pad.
1513 virtual void setSubWindow(NCursesWindow& sub);
1514 // Use the subwindow "sub" of the viewport window for the actual viewing.
1515 // The full viewport window is usually used to provide some decorations
1516 // like frames, titles etc.
1518 virtual void operator() (void);
1519 // Perform Pad's operation
1522 // A FramedPad is constructed always with a viewport window. This viewport
1523 // will be framed (by a box() command) and the interior of the box is the
1524 // viewport subwindow. On the frame we display scrollbar sliders.
1525 class NCURSES_IMPEXP NCursesFramedPad : public NCursesPad
1528 virtual void OnOperation(int pad_req);
1531 NCursesFramedPad(NCursesWindow& win, int nlines, int ncols,
1532 int v_grid = 1, int h_grid = 1)
1533 : NCursesPad(nlines, ncols) {
1534 NCursesPad::setWindow(win, v_grid, h_grid);
1535 NCursesPad::setSubWindow(*(new NCursesWindow(win)));
1537 // Construct the FramedPad with the given Window win as viewport.
1539 virtual ~NCursesFramedPad() {
1540 delete getSubWindow();
1543 void setWindow(NCursesWindow& view, int v_grid = 1, int h_grid = 1) {
1544 err_handler("Operation not allowed");
1546 // Disable this call; the viewport is already defined
1548 void setSubWindow(NCursesWindow& sub) {
1549 err_handler("Operation not allowed");
1551 // Disable this call; the viewport subwindow is already defined
1555 #endif /* NCURSES_CURSESW_H_incl */