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.42 2007/03/03 21:49:18 tom Exp $
44 /* SCO 3.2v4 curses.h includes term.h, which defines lines as a macro.
45 Undefine it here, because NCursesWindow uses lines as a method. */
48 /* "Convert" macros to inlines. We'll define it as another symbol to avoid
49 * conflict with library symbols.
52 #define UNDEF(name) CUR_ ##name
55 inline int UNDEF(addch)(chtype ch) { return addch(ch); }
57 #define addch UNDEF(addch)
61 inline int UNDEF(echochar)(chtype ch) { return echochar(ch); }
63 #define echochar UNDEF(echochar)
67 inline int UNDEF(insdelln)(int n) { return insdelln(n); }
69 #define insdelln UNDEF(insdelln)
73 inline int UNDEF(addstr)(const char * str) { return addstr(str); }
75 #define addstr UNDEF(addstr)
79 inline int UNDEF(attron)(chtype at) { return attron(at); }
81 #define attron UNDEF(attron)
85 inline int UNDEF(attroff)(chtype at) { return attroff(at); }
87 #define attroff UNDEF(attroff)
91 inline chtype UNDEF(attrset)(chtype at) { return attrset(at); }
93 #define attrset UNDEF(attrset)
97 inline chtype UNDEF(color_set)(short p, void* opts) { return color_set(p, opts); }
99 #define color_set UNDEF(color_set)
103 inline int UNDEF(border)(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, chtype tr, chtype bl, chtype br)
104 { return border(ls, rs, ts, bs, tl, tr, bl, br); }
106 #define border UNDEF(border)
110 inline int UNDEF(box)(WINDOW *win, int v, int h) { return box(win, v, h); }
112 #define box UNDEF(box)
116 inline int UNDEF(mvwhline)(WINDOW *win, int y, int x, chtype c, int n) {
117 return mvwhline(win, y, x, c, n); }
119 #define mvwhline UNDEF(mvwhline)
123 inline int UNDEF(mvwvline)(WINDOW *win, int y, int x, chtype c, int n) {
124 return mvwvline(win, y, x, c, n); }
126 #define mvwvline UNDEF(mvwvline)
130 inline int UNDEF(clear)() { return clear(); }
132 #define clear UNDEF(clear)
136 inline int UNDEF(clearok)(WINDOW* win, bool bf) { return clearok(win, bf); }
138 #define clearok UNDEF(clearok)
140 extern "C" NCURSES_IMPEXP int NCURSES_API clearok(WINDOW*, bool);
144 inline int UNDEF(clrtobot)() { return clrtobot(); }
146 #define clrtobot UNDEF(clrtobot)
150 inline int UNDEF(clrtoeol)() { return clrtoeol(); }
152 #define clrtoeol UNDEF(clrtoeol)
156 inline int UNDEF(delch)() { return delch(); }
158 #define delch UNDEF(delch)
162 inline int UNDEF(deleteln)() { return deleteln(); }
164 #define deleteln UNDEF(deleteln)
168 inline int UNDEF(erase)() { return erase(); }
170 #define erase UNDEF(erase)
174 inline int UNDEF(flushok)(WINDOW* _win, bool _bf) {
175 return flushok(_win, _bf); }
177 #define flushok UNDEF(flushok)
183 inline int UNDEF(getch)() { return getch(); }
185 #define getch UNDEF(getch)
189 inline int UNDEF(getstr)(char *_str) { return getstr(_str); }
191 #define getstr UNDEF(getstr)
195 inline int UNDEF(instr)(char *_str) { return instr(_str); }
197 #define instr UNDEF(instr)
201 inline int UNDEF(innstr)(char *_str, int n) { return innstr(_str, n); }
203 #define innstr UNDEF(innstr)
207 inline int UNDEF(mvwinnstr)(WINDOW *win, int y, int x, char *_str, int n) {
208 return mvwinnstr(win, y, x, _str, n); }
210 #define mvwinnstr UNDEF(mvwinnstr)
214 inline int UNDEF(mvinnstr)(int y, int x, char *_str, int n) {
215 return mvinnstr(y, x, _str, n); }
217 #define mvinnstr UNDEF(mvinnstr)
221 inline int UNDEF(winsstr)(WINDOW *w, const char *_str) {
222 return winsstr(w, _str); }
224 #define winsstr UNDEF(winsstr)
228 inline int UNDEF(mvwinsstr)(WINDOW *w, int y, int x, const char *_str) {
229 return mvwinsstr(w, y, x, _str); }
231 #define mvwinsstr UNDEF(mvwinsstr)
235 inline int UNDEF(insstr)(const char *_str) {
236 return insstr(_str); }
238 #define insstr UNDEF(insstr)
242 inline int UNDEF(mvinsstr)(int y, int x, const char *_str) {
243 return mvinsstr(y, x, _str); }
245 #define mvinsstr UNDEF(mvinsstr)
249 inline int UNDEF(insnstr)(const char *_str, int n) {
250 return insnstr(_str, n); }
252 #define insnstr UNDEF(insnstr)
256 inline int UNDEF(mvwinsnstr)(WINDOW *w, int y, int x, const char *_str, int n) {
257 return mvwinsnstr(w, y, x, _str, n); }
259 #define mvwinsnstr UNDEF(mvwinsnstr)
263 inline int UNDEF(mvinsnstr)(int y, int x, const char *_str, int n) {
264 return mvinsnstr(y, x, _str, n); }
266 #define mvinsnstr UNDEF(mvinsnstr)
270 inline int UNDEF(getnstr)(char *_str, int n) { return getnstr(_str, n); }
272 #define getnstr UNDEF(getnstr)
276 inline void UNDEF(getyx)(const WINDOW* win, int& y, int& x) {
279 #define getyx UNDEF(getyx)
283 inline void UNDEF(getbegyx)(WINDOW* win, int& y, int& x) { getbegyx(win, y, x); }
285 #define getbegyx UNDEF(getbegyx)
289 inline void UNDEF(getmaxyx)(WINDOW* win, int& y, int& x) { getmaxyx(win, y, x); }
291 #define getmaxyx UNDEF(getmaxyx)
295 inline int UNDEF(hline)(chtype ch, int n) { return hline(ch, n); }
297 #define hline UNDEF(hline)
301 inline chtype UNDEF(inch)() { return inch(); }
303 #define inch UNDEF(inch)
307 inline int UNDEF(insch)(chtype c) { return insch(c); }
309 #define insch UNDEF(insch)
313 inline int UNDEF(insertln)() { return insertln(); }
315 #define insertln UNDEF(insertln)
319 inline int UNDEF(leaveok)(WINDOW* win, bool bf) { return leaveok(win, bf); }
321 #define leaveok UNDEF(leaveok)
323 extern "C" NCURSES_IMPEXP int NCURSES_API leaveok(WINDOW* win, bool bf);
327 inline int UNDEF(move)(int x, int y) { return move(x, y); }
329 #define move UNDEF(move)
333 inline int UNDEF(refresh)() { return refresh(); }
335 #define refresh UNDEF(refresh)
339 inline int UNDEF(redrawwin)(WINDOW *win) { return redrawwin(win); }
341 #define redrawwin UNDEF(redrawwin)
345 inline int UNDEF(scrl)(int l) { return scrl(l); }
347 #define scrl UNDEF(scrl)
351 inline int UNDEF(scroll)(WINDOW *win) { return scroll(win); }
353 #define scroll UNDEF(scroll)
357 inline int UNDEF(scrollok)(WINDOW* win, bool bf) { return scrollok(win, bf); }
359 #define scrollok UNDEF(scrollok)
361 #if defined(__NCURSES_H)
362 extern "C" NCURSES_IMPEXP int NCURSES_API scrollok(WINDOW*, bool);
364 extern "C" NCURSES_IMPEXP int NCURSES_API scrollok(WINDOW*, char);
369 inline int UNDEF(setscrreg)(int t, int b) { return setscrreg(t, b); }
371 #define setscrreg UNDEF(setscrreg)
375 inline int UNDEF(standend)() { return standend(); }
377 #define standend UNDEF(standend)
381 inline int UNDEF(standout)() { return standout(); }
383 #define standout UNDEF(standout)
387 inline WINDOW *UNDEF(subpad)(WINDOW *p, int l, int c, int y, int x)
388 { return derwin(p, l, c, y, x); }
390 #define subpad UNDEF(subpad)
394 inline void UNDEF(timeout)(int delay) { timeout(delay); }
396 #define timeout UNDEF(timeout)
400 inline int UNDEF(touchline)(WINDOW *win, int s, int c)
401 { return touchline(win, s, c); }
403 #define touchline UNDEF(touchline)
407 inline int UNDEF(touchwin)(WINDOW *win) { return touchwin(win); }
409 #define touchwin UNDEF(touchwin)
413 inline int UNDEF(untouchwin)(WINDOW *win) { return untouchwin(win); }
415 #define untouchwin UNDEF(untouchwin)
419 inline int UNDEF(vline)(chtype ch, int n) { return vline(ch, n); }
421 #define vline UNDEF(vline)
425 inline int UNDEF(waddstr)(WINDOW *win, char *str) { return waddstr(win, str); }
427 #define waddstr UNDEF(waddstr)
431 inline int UNDEF(waddchstr)(WINDOW *win, chtype *at) { return waddchstr(win, at); }
433 #define waddchstr UNDEF(waddchstr)
437 inline int UNDEF(wstandend)(WINDOW *win) { return wstandend(win); }
439 #define wstandend UNDEF(wstandend)
443 inline int UNDEF(wstandout)(WINDOW *win) { return wstandout(win); }
445 #define wstandout UNDEF(wstandout)
450 inline int UNDEF(wattroff)(WINDOW *win, int att) { return wattroff(win, att); }
452 #define wattroff UNDEF(wattroff)
456 inline int UNDEF(chgat)(int n, attr_t attr, short color, const void *opts) {
457 return chgat(n, attr, color, opts); }
459 #define chgat UNDEF(chgat)
463 inline int UNDEF(mvchgat)(int y, int x, int n,
464 attr_t attr, short color, const void *opts) {
465 return mvchgat(y, x, n, attr, color, opts); }
467 #define mvchgat UNDEF(mvchgat)
471 inline int UNDEF(mvwchgat)(WINDOW *win, int y, int x, int n,
472 attr_t attr, short color, const void *opts) {
473 return mvwchgat(win, y, x, n, attr, color, opts); }
475 #define mvwchgat UNDEF(mvwchgat)
479 inline int UNDEF(wattrset)(WINDOW *win, int att) { return wattrset(win, att); }
481 #define wattrset UNDEF(wattrset)
485 inline chtype UNDEF(winch)(const WINDOW* win) { return winch(win); }
487 #define winch UNDEF(winch)
491 inline int UNDEF(mvwaddch)(WINDOW *win, int y, int x, const chtype ch)
492 { return mvwaddch(win, y, x, ch); }
494 #define mvwaddch UNDEF(mvwaddch)
498 inline int UNDEF(mvwaddchnstr)(WINDOW *win, int y, int x, chtype *str, int n)
499 { return mvwaddchnstr(win, y, x, str, n); }
501 #define mvwaddchnstr UNDEF(mvwaddchnstr)
505 inline int UNDEF(mvwaddchstr)(WINDOW *win, int y, int x, chtype *str)
506 { return mvwaddchstr(win, y, x, str); }
508 #define mvwaddchstr UNDEF(mvwaddchstr)
512 inline int UNDEF(addnstr)(const char *str, int n)
513 { return addnstr(str, n); }
515 #define addnstr UNDEF(addnstr)
519 inline int UNDEF(mvwaddnstr)(WINDOW *win, int y, int x, const char *str, int n)
520 { return mvwaddnstr(win, y, x, str, n); }
522 #define mvwaddnstr UNDEF(mvwaddnstr)
526 inline int UNDEF(mvwaddstr)(WINDOW *win, int y, int x, const char * str)
527 { return mvwaddstr(win, y, x, str); }
529 #define mvwaddstr UNDEF(mvwaddstr)
533 inline int UNDEF(mvwdelch)(WINDOW *win, int y, int x)
534 { return mvwdelch(win, y, x); }
536 #define mvwdelch UNDEF(mvwdelch)
540 inline int UNDEF(mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
542 #define mvwgetch UNDEF(mvwgetch)
546 inline int UNDEF(mvwgetstr)(WINDOW *win, int y, int x, char *str)
547 {return mvwgetstr(win, y, x, str);}
549 #define mvwgetstr UNDEF(mvwgetstr)
553 inline int UNDEF(mvwgetnstr)(WINDOW *win, int y, int x, char *str, int n)
554 {return mvwgetnstr(win, y, x, str, n);}
556 #define mvwgetnstr UNDEF(mvwgetnstr)
560 inline chtype UNDEF(mvwinch)(WINDOW *win, int y, int x) {
561 return mvwinch(win, y, x);}
563 #define mvwinch UNDEF(mvwinch)
567 inline int UNDEF(mvwinsch)(WINDOW *win, int y, int x, chtype c)
568 { return mvwinsch(win, y, x, c); }
570 #define mvwinsch UNDEF(mvwinsch)
574 inline int UNDEF(mvaddch)(int y, int x, chtype ch)
575 { return mvaddch(y, x, ch); }
577 #define mvaddch UNDEF(mvaddch)
581 inline int UNDEF(mvaddnstr)(int y, int x, const char *str, int n)
582 { return mvaddnstr(y, x, str, n); }
584 #define mvaddnstr UNDEF(mvaddnstr)
588 inline int UNDEF(mvaddstr)(int y, int x, const char * str)
589 { return mvaddstr(y, x, str); }
591 #define mvaddstr UNDEF(mvaddstr)
595 inline int UNDEF(mvdelch)(int y, int x) { return mvdelch(y, x);}
597 #define mvdelch UNDEF(mvdelch)
601 inline int UNDEF(mvgetch)(int y, int x) { return mvgetch(y, x);}
603 #define mvgetch UNDEF(mvgetch)
607 inline int UNDEF(mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
609 #define mvgetstr UNDEF(mvgetstr)
613 inline int UNDEF(mvgetnstr)(int y, int x, char *str, int n) {
614 return mvgetnstr(y, x, str, n);}
616 #define mvgetnstr UNDEF(mvgetnstr)
620 inline chtype UNDEF(mvinch)(int y, int x) { return mvinch(y, x);}
622 #define mvinch UNDEF(mvinch)
626 inline int UNDEF(mvinsch)(int y, int x, chtype c)
627 { return mvinsch(y, x, c); }
629 #define mvinsch UNDEF(mvinsch)
633 inline void UNDEF(napms)(unsigned long x) { napms(x); }
635 #define napms UNDEF(napms)
639 inline int UNDEF(fixterm)(void) { return fixterm(); }
641 #define fixterm UNDEF(fixterm)
645 inline int UNDEF(resetterm)(void) { return resetterm(); }
647 #define resetterm UNDEF(resetterm)
651 inline int UNDEF(saveterm)(void) { return saveterm(); }
653 #define saveterm UNDEF(saveterm)
657 inline int UNDEF(crmode)(void) { return crmode(); }
659 #define crmode UNDEF(crmode)
663 inline int UNDEF(nocrmode)(void) { return nocrmode(); }
665 #define nocrmode UNDEF(nocrmode)
669 inline chtype UNDEF(getbkgd)(const WINDOW *win) { return getbkgd(win); }
671 #define getbkgd UNDEF(getbkgd)
675 inline int UNDEF(bkgd)(chtype ch) { return bkgd(ch); }
677 #define bkgd UNDEF(bkgd)
681 inline void UNDEF(bkgdset)(chtype ch) { bkgdset(ch); }
683 #define bkgdset UNDEF(bkgdset)
688 * C++ class for windows.
692 extern "C" int _nc_ripoffline(int, int (*init)(WINDOW*, int));
693 extern "C" int _nc_xx_ripoff_init(WINDOW *, int);
694 extern "C" int _nc_has_mouse(void);
696 class NCURSES_IMPEXP NCursesWindow
698 friend class NCursesMenu;
699 friend class NCursesForm;
702 static bool b_initialized;
703 static void initialize();
705 friend int _nc_xx_ripoff_init(WINDOW *, int);
709 short getcolor(int getback) const;
710 short getPair() const;
712 static int setpalette(short fore, short back, short pair);
713 static int colorInitialized;
715 // This private constructor is only used during the initialization
716 // of windows generated by ripoffline() calls.
717 NCursesWindow(WINDOW* win, int ncols);
720 virtual void err_handler(const char *) const THROWS(NCursesException);
721 // Signal an error with the given message text.
723 static long count; // count of all active windows:
724 // We rely on the c++ promise that
725 // all otherwise uninitialized
726 // static class vars are set to 0
728 WINDOW* w; // the curses WINDOW
730 bool alloced; // TRUE if we own the WINDOW
732 NCursesWindow* par; // parent, if subwindow
733 NCursesWindow* subwins; // head of subwindows list
734 NCursesWindow* sib; // next subwindow of parent
736 void kill_subwindows(); // disable all subwindows
737 // Destroy all subwindows.
739 /* Only for use by derived classes. They are then in charge to
740 fill the member variables correctly. */
744 NCursesWindow(WINDOW* &window); // useful only for stdscr
746 NCursesWindow(int nlines, // number of lines
747 int ncols, // number of columns
748 int begin_y, // line origin
749 int begin_x); // col origin
751 NCursesWindow(NCursesWindow& par,// parent window
752 int nlines, // number of lines
753 int ncols, // number of columns
754 int begin_y, // absolute or relative
755 int begin_x, // origins:
756 char absrel = 'a');// if `a', begin_y & begin_x are
757 // absolute screen pos, else if `r', they are relative to par origin
759 NCursesWindow(NCursesWindow& par,// parent window
761 // this is the very common case that we want to create the subwindow that
762 // is two lines and two columns smaller and begins at (1,1).
763 // We may automatically request the box around it.
765 NCursesWindow& operator=(const NCursesWindow& rhs)
772 NCursesWindow(const NCursesWindow& rhs)
773 : w(rhs.w), alloced(rhs.alloced), par(rhs.par), subwins(rhs.subwins), sib(rhs.sib)
777 virtual ~NCursesWindow();
779 NCursesWindow Clone();
780 // Make an exact copy of the window.
783 static void useColors(void);
784 // Call this routine very early if you want to have colors.
786 static int ripoffline(int ripoff_lines,
787 int (*init)(NCursesWindow& win));
788 // This function is used to generate a window of ripped-of lines.
789 // If the argument is positive, lines are removed from the top, if it
790 // is negative lines are removed from the bottom. This enhances the
791 // lowlevel ripoffline() function because it uses the internal
792 // implementation that allows to remove more than just a single line.
793 // This function must be called before any other ncurses function. The
794 // creation of the window is deferred until ncurses gets initialized.
795 // The initialization function is then called.
797 // -------------------------------------------------------------------------
799 // -------------------------------------------------------------------------
800 int lines() const { initialize(); return LINES; }
801 // Number of lines on terminal, *not* window
803 int cols() const { initialize(); return COLS; }
804 // Number of cols on terminal, *not* window
806 int tabsize() const { initialize(); return TABSIZE; }
807 // Size of a tab on terminal, *not* window
809 static int NumberOfColors();
810 // Number of available colors
812 int colors() const { return NumberOfColors(); }
813 // Number of available colors
815 // -------------------------------------------------------------------------
817 // -------------------------------------------------------------------------
818 int height() const { return maxy() + 1; }
819 // Number of lines in this window
821 int width() const { return maxx() + 1; }
822 // Number of columns in this window
824 int begx() const { return getbegx(w); }
825 // Column of top left corner relative to stdscr
827 int begy() const { return getbegy(w); }
828 // Line of top left corner relative to stdscr
830 int maxx() const { return getmaxx(w) == ERR ? ERR : getmaxx(w)-1; }
831 // Largest x coord in window
833 int maxy() const { return getmaxy(w) == ERR ? ERR : getmaxy(w)-1; }
834 // Largest y coord in window
836 short getcolor() const;
839 short foreground() const { return getcolor(0); }
840 // Actual foreground color
842 short background() const { return getcolor(1); }
843 // Actual background color
845 int setpalette(short fore, short back);
846 // Set color palette entry
848 int setcolor(short pair);
849 // Set actually used palette entry
851 // -------------------------------------------------------------------------
852 // window positioning
853 // -------------------------------------------------------------------------
854 virtual int mvwin(int begin_y, int begin_x) {
855 return ::mvwin(w, begin_y, begin_x); }
856 // Move window to new position with the new position as top left corner.
857 // This is virtual because it is redefined in NCursesPanel.
859 // -------------------------------------------------------------------------
860 // coordinate positioning
861 // -------------------------------------------------------------------------
862 int move(int y, int x) { return ::wmove(w, y, x); }
863 // Move cursor the this position
865 void getyx(int& y, int& x) const { ::getyx(w, y, x); }
866 // Get current position of the cursor
868 int mvcur(int oldrow, int oldcol, int newrow, int newcol) const {
869 return ::mvcur(oldrow, oldcol, newrow, newcol); }
870 // Perform lowlevel cursor motion that takes effect immediately.
872 // -------------------------------------------------------------------------
874 // -------------------------------------------------------------------------
875 int getch() { return ::wgetch(w); }
876 // Get a keystroke from the window.
878 int getch(int y, int x) { return ::mvwgetch(w, y, x); }
879 // Move cursor to position and get a keystroke from the window
881 int getstr(char* str, int n=-1) {
882 return ::wgetnstr(w, str, n); }
883 // Read a series of characters into str until a newline or carriage return
884 // is received. Read at most n characters. If n is negative, the limit is
887 int getstr(int y, int x, char* str, int n=-1) {
888 return ::mvwgetnstr(w, y, x, str, n); }
889 // Move the cursor to the requested position and then perform the getstr()
890 // as described above.
892 int instr(char *s, int n=-1) { return ::winnstr(w, s, n); }
893 // Get a string of characters from the window into the buffer s. Retrieve
894 // at most n characters, if n is negative retrieve all characters up to the
895 // end of the current line. Attributes are stripped from the characters.
897 int instr(int y, int x, char *s, int n=-1) {
898 return ::mvwinnstr(w, y, x, s, n); }
899 // Move the cursor to the requested position and then perform the instr()
900 // as described above.
902 int scanw(const char* fmt, ...)
903 // Perform a scanw function from the window.
905 __attribute__ ((format (scanf, 2, 3)));
910 int scanw(int y, int x, const char* fmt, ...)
911 // Move the cursor to the requested position and then perform a scanw
914 __attribute__ ((format (scanf, 4, 5)));
919 // -------------------------------------------------------------------------
921 // -------------------------------------------------------------------------
922 int addch(const chtype ch) { return ::waddch(w, ch); }
923 // Put attributed character to the window.
925 int addch(int y, int x, const chtype ch) {
926 return ::mvwaddch(w, y, x, ch); }
927 // Move cursor to the requested position and then put attributed character
930 int echochar(const chtype ch) { return ::wechochar(w, ch); }
931 // Put attributed character to the window and refresh it immediately.
933 int addstr(const char* str, int n=-1) {
934 return ::waddnstr(w, str, n); }
935 // Write the string str to the window, stop writing if the terminating
936 // NUL or the limit n is reached. If n is negative, it is ignored.
938 int addstr(int y, int x, const char * str, int n=-1) {
939 return ::mvwaddnstr(w, y, x, str, n); }
940 // Move the cursor to the requested position and then perform the addstr
941 // as described above.
943 int printw(const char* fmt, ...)
944 // Do a formatted print to the window.
945 #if (__GNUG__ >= 2) && !defined(printf)
946 __attribute__ ((format (printf, 2, 3)));
951 int printw(int y, int x, const char * fmt, ...)
952 // Move the cursor and then do a formatted print to the window.
953 #if (__GNUG__ >= 2) && !defined(printf)
954 __attribute__ ((format (printf, 4, 5)));
959 chtype inch() const { return ::winch(w); }
960 // Retrieve attributed character under the current cursor position.
962 chtype inch(int y, int x) { return ::mvwinch(w, y, x); }
963 // Move cursor to requested position and then retrieve attributed character
966 int insch(chtype ch) { return ::winsch(w, ch); }
967 // Insert attributed character into the window before current cursor
970 int insch(int y, int x, chtype ch) {
971 return ::mvwinsch(w, y, x, ch); }
972 // Move cursor to requested position and then insert the attributed
973 // character before that position.
975 int insertln() { return ::winsdelln(w, 1); }
976 // Insert an empty line above the current line.
978 int insdelln(int n=1) { return ::winsdelln(w, n); }
979 // If n>0 insert that many lines above the current line. If n<0 delete
980 // that many lines beginning with the current line.
982 int insstr(const char *s, int n=-1) {
983 return ::winsnstr(w, s, n); }
984 // Insert the string into the window before the current cursor position.
985 // Insert stops at end of string or when the limit n is reached. If n is
986 // negative, it is ignored.
988 int insstr(int y, int x, const char *s, int n=-1) {
989 return ::mvwinsnstr(w, y, x, s, n); }
990 // Move the cursor to the requested position and then perform the insstr()
991 // as described above.
993 int attron (chtype at) { return ::wattron (w, at); }
994 // Switch on the window attributes;
996 int attroff(chtype at) { return ::wattroff(w, static_cast<int>(at)); }
997 // Switch off the window attributes;
999 int attrset(chtype at) { return ::wattrset(w, static_cast<int>(at)); }
1000 // Set the window attributes;
1002 int color_set(short color_pair_number, void* opts=NULL) {
1003 return ::wcolor_set(w, color_pair_number, opts); }
1004 // Set the window color attribute;
1006 int chgat(int n, attr_t attr, short color, const void *opts=NULL) {
1007 return ::wchgat(w, n, attr, color, opts); }
1008 // Change the attributes of the next n characters in the current line. If
1009 // n is negative or greater than the number of remaining characters in the
1010 // line, the attributes will be changed up to the end of the line.
1012 int chgat(int y, int x,
1013 int n, attr_t attr, short color, const void *opts=NULL) {
1014 return ::mvwchgat(w, y, x, n, attr, color, opts); }
1015 // Move the cursor to the requested position and then perform chgat() as
1018 // -------------------------------------------------------------------------
1020 // -------------------------------------------------------------------------
1021 chtype getbkgd() const { return ::getbkgd(w); }
1022 // Get current background setting.
1024 int bkgd(const chtype ch) { return ::wbkgd(w, ch); }
1025 // Set the background property and apply it to the window.
1027 void bkgdset(chtype ch) { ::wbkgdset(w, ch); }
1028 // Set the background property.
1030 // -------------------------------------------------------------------------
1032 // -------------------------------------------------------------------------
1033 int box(chtype vert=0, chtype hor=0) {
1034 return ::wborder(w, vert, vert, hor, hor, 0, 0, 0, 0); }
1035 // Draw a box around the window with the given vertical and horizontal
1036 // drawing characters. If you specify a zero as character, curses will try
1037 // to find a "nice" character.
1039 int border(chtype left=0, chtype right=0,
1040 chtype top =0, chtype bottom=0,
1041 chtype top_left =0, chtype top_right=0,
1042 chtype bottom_left =0, chtype bottom_right=0) {
1043 return ::wborder(w, left, right, top, bottom, top_left, top_right,
1044 bottom_left, bottom_right); }
1045 // Draw a border around the window with the given characters for the
1046 // various parts of the border. If you pass zero for a character, curses
1047 // will try to find "nice" characters.
1049 // -------------------------------------------------------------------------
1051 // -------------------------------------------------------------------------
1052 int hline(int len, chtype ch=0) { return ::whline(w, ch, len); }
1053 // Draw a horizontal line of len characters with the given character. If
1054 // you pass zero for the character, curses will try to find a "nice" one.
1056 int hline(int y, int x, int len, chtype ch=0) {
1057 return ::mvwhline(w, y, x, ch, len); }
1058 // Move the cursor to the requested position and then draw a horizontal line.
1060 int vline(int len, chtype ch=0) { return ::wvline(w, ch, len); }
1061 // Draw a vertical line of len characters with the given character. If
1062 // you pass zero for the character, curses will try to find a "nice" one.
1064 int vline(int y, int x, int len, chtype ch=0) {
1065 return ::mvwvline(w, y, x, ch, len); }
1066 // Move the cursor to the requested position and then draw a vertical line.
1068 // -------------------------------------------------------------------------
1070 // -------------------------------------------------------------------------
1071 int erase() { return ::werase(w); }
1072 // Erase the window.
1074 int clear() { return ::wclear(w); }
1075 // Clear the window.
1077 int clearok(bool bf) { return ::clearok(w, bf); }
1078 // Set/Reset the clear flag. If set, the next refresh() will clear the
1081 int clrtobot() { return ::wclrtobot(w); }
1082 // Clear to the end of the window.
1084 int clrtoeol() { return ::wclrtoeol(w); }
1085 // Clear to the end of the line.
1087 int delch() { return ::wdelch(w); }
1088 // Delete character under the cursor.
1090 int delch(int y, int x) { return ::mvwdelch(w, y, x); }
1091 // Move cursor to requested position and delete the character under the
1094 int deleteln() { return ::winsdelln(w, -1); }
1095 // Delete the current line.
1097 // -------------------------------------------------------------------------
1099 // -------------------------------------------------------------------------
1100 int scroll(int amount=1) { return ::wscrl(w, amount); }
1101 // Scroll amount lines. If amount is positive, scroll up, otherwise
1104 int scrollok(bool bf) { return ::scrollok(w, bf); }
1105 // If bf is TRUE, window scrolls if cursor is moved off the bottom
1106 // edge of the window or a scrolling region, otherwise the cursor is left
1107 // at the bottom line.
1109 int setscrreg(int from, int to) {
1110 return ::wsetscrreg(w, from, to); }
1111 // Define a soft scrolling region.
1113 int idlok(bool bf) { return ::idlok(w, bf); }
1114 // If bf is TRUE, use insert/delete line hardware support if possible.
1115 // Otherwise do it in software.
1118 void idcok(bool bf) { ::idcok(w, bf); }
1119 // If bf is TRUE, use insert/delete character hardware support if possible.
1120 // Otherwise do it in software.
1122 int touchwin() { return ::wtouchln(w, 0, height(), 1); }
1123 // Mark the whole window as modified.
1125 int untouchwin() { return ::wtouchln(w, 0, height(), 0); }
1126 // Mark the whole window as unmodified.
1128 int touchln(int s, int cnt, bool changed=TRUE) {
1129 return ::wtouchln(w, s, cnt, static_cast<int>(changed ? 1 : 0)); }
1130 // Mark cnt lines beginning from line s as changed or unchanged, depending
1131 // on the value of the changed flag.
1133 bool is_linetouched(int line) const {
1134 return (::is_linetouched(w, line) ? TRUE:FALSE); }
1135 // Return TRUE if line is marked as changed, FALSE otherwise
1137 bool is_wintouched() const {
1138 return (::is_wintouched(w) ? TRUE:FALSE); }
1139 // Return TRUE if window is marked as changed, FALSE otherwise
1141 int leaveok(bool bf) { return ::leaveok(w, bf); }
1142 // If bf is TRUE, curses will leave the cursor after an update whereever
1143 // it is after the update.
1145 int redrawln(int from, int n) { return ::wredrawln(w, from, n); }
1146 // Redraw n lines starting from the requested line
1148 int redrawwin() { return ::wredrawln(w, 0, height()); }
1149 // Redraw the whole window
1151 int doupdate() { return ::doupdate(); }
1152 // Do all outputs to make the physical screen looking like the virtual one
1154 void syncdown() { ::wsyncdown(w); }
1155 // Propagate the changes down to all descendant windows
1157 void syncup() { ::wsyncup(w); }
1158 // Propagate the changes up in the hierarchy
1160 void cursyncup() { ::wcursyncup(w); }
1161 // Position the cursor in all ancestor windows corresponding to our setting
1163 int syncok(bool bf) { return ::syncok(w, bf); }
1164 // If called with bf=TRUE, syncup() is called whenever the window is changed
1167 int flushok(bool bf) { return ::flushok(w, bf); }
1170 void immedok(bool bf) { ::immedok(w, bf); }
1171 // If called with bf=TRUE, any change in the window will cause an
1172 // automatic immediate refresh()
1174 int keypad(bool bf) { return ::keypad(w, bf); }
1175 // If called with bf=TRUE, the application will interpret function keys.
1177 int meta(bool bf) { return ::meta(w, bf); }
1178 // If called with bf=TRUE, keys may generate 8-Bit characters. Otherwise
1179 // 7-Bit characters are generated.
1181 int standout() { return ::wstandout(w); }
1182 // Enable "standout" attributes
1184 int standend() { return ::wstandend(w); }
1185 // Disable "standout" attributes
1187 // -------------------------------------------------------------------------
1188 // The next two are virtual, because we redefine them in the
1189 // NCursesPanel class.
1190 // -------------------------------------------------------------------------
1191 virtual int refresh() { return ::wrefresh(w); }
1192 // Propagate the changes in this window to the virtual screen and call
1193 // doupdate(). This is redefined in NCursesPanel.
1195 virtual int noutrefresh() { return ::wnoutrefresh(w); }
1196 // Propagate the changes in this window to the virtual screen. This is
1197 // redefined in NCursesPanel.
1199 // -------------------------------------------------------------------------
1200 // multiple window control
1201 // -------------------------------------------------------------------------
1202 int overlay(NCursesWindow& win) {
1203 return ::overlay(w, win.w); }
1204 // Overlay this window over win.
1206 int overwrite(NCursesWindow& win) {
1207 return ::overwrite(w, win.w); }
1208 // Overwrite win with this window.
1210 int copywin(NCursesWindow& win,
1211 int sminrow, int smincol,
1212 int dminrow, int dmincol,
1213 int dmaxrow, int dmaxcol, bool overlaywin=TRUE) {
1214 return ::copywin(w, win.w, sminrow, smincol, dminrow, dmincol,
1215 dmaxrow, dmaxcol, static_cast<int>(overlaywin ? 1 : 0)); }
1216 // Overlay or overwrite the rectangle in win given by dminrow,dmincol,
1217 // dmaxrow,dmaxcol with the rectangle in this window beginning at
1220 // -------------------------------------------------------------------------
1222 // -------------------------------------------------------------------------
1223 bool has_mouse() const;
1224 // Return TRUE if terminal supports a mouse, FALSE otherwise
1226 // -------------------------------------------------------------------------
1227 // traversal support
1228 // -------------------------------------------------------------------------
1229 NCursesWindow* child() { return subwins; }
1230 // Get the first child window.
1232 NCursesWindow* sibling() { return sib; }
1233 // Get the next child of my parent.
1235 NCursesWindow* parent() { return par; }
1238 bool isDescendant(NCursesWindow& win);
1239 // Return TRUE if win is a descendant of this.
1242 // -------------------------------------------------------------------------
1243 // We leave this here for compatibility reasons.
1244 // -------------------------------------------------------------------------
1245 class NCURSES_IMPEXP NCursesColorWindow : public NCursesWindow
1248 NCursesColorWindow(WINDOW* &window) // useful only for stdscr
1249 : NCursesWindow(window) {
1252 NCursesColorWindow(int nlines, // number of lines
1253 int ncols, // number of columns
1254 int begin_y, // line origin
1255 int begin_x) // col origin
1256 : NCursesWindow(nlines, ncols, begin_y, begin_x) {
1259 NCursesColorWindow(NCursesWindow& parentWin,// parent window
1260 int nlines, // number of lines
1261 int ncols, // number of columns
1262 int begin_y, // absolute or relative
1263 int begin_x, // origins:
1264 char absrel = 'a') // if `a', by & bx are
1265 : NCursesWindow(parentWin,
1266 nlines, ncols, // absolute screen pos,
1267 begin_y, begin_x, // else if `r', they are
1268 absrel ) { // relative to par origin
1272 // These enum definitions really belong inside the NCursesPad class, but only
1273 // recent compilers support that feature.
1276 REQ_PAD_REFRESH = KEY_MAX + 1,
1284 const Pad_Request PAD_LOW = REQ_PAD_REFRESH; // lowest op-code
1285 const Pad_Request PAD_HIGH = REQ_PAD_EXIT; // highest op-code
1287 // -------------------------------------------------------------------------
1288 // Pad Support. We allow an association of a pad with a "real" window
1289 // through which the pad may be viewed.
1290 // -------------------------------------------------------------------------
1291 class NCURSES_IMPEXP NCursesPad : public NCursesWindow
1294 NCursesWindow* viewWin; // the "viewport" window
1295 NCursesWindow* viewSub; // the "viewport" subwindow
1297 int h_gridsize, v_gridsize;
1300 int min_row, min_col; // top left row/col of the pads display area
1302 NCursesWindow* Win(void) const {
1303 // Get the window into which the pad should be copied (if any)
1304 return (viewSub?viewSub:(viewWin?viewWin:0));
1307 NCursesWindow* getWindow(void) const {
1311 NCursesWindow* getSubWindow(void) const {
1315 virtual int driver (int key); // Virtualize keystroke key
1316 // The driver translates the keystroke c into an Pad_Request
1318 virtual void OnUnknownOperation(int pad_req) {
1321 // This is called if the driver returns an unknown op-code
1323 virtual void OnNavigationError(int pad_req) {
1326 // This is called if a navigation request couldn't be satisfied
1328 virtual void OnOperation(int pad_req) {
1330 // OnOperation is called if a Pad_Operation was executed and just before
1331 // the refresh() operation is done.
1334 NCursesPad(int nlines, int ncols);
1335 // create a pad with the given size
1337 NCursesPad& operator=(const NCursesPad& rhs)
1341 NCursesWindow::operator=(rhs);
1346 NCursesPad(const NCursesPad& rhs)
1347 : NCursesWindow(rhs),
1348 viewWin(rhs.viewWin),
1349 viewSub(rhs.viewSub),
1350 h_gridsize(rhs.h_gridsize),
1351 v_gridsize(rhs.v_gridsize),
1352 min_row(rhs.min_row),
1353 min_col(rhs.min_col)
1357 virtual ~NCursesPad() {}
1359 int echochar(const chtype ch) { return ::pechochar(w, ch); }
1360 // Put the attributed character onto the pad and immediately do a
1364 // If a viewport is defined the pad is displayed in this window, otherwise
1367 int refresh(int pminrow, int pmincol,
1368 int sminrow, int smincol,
1369 int smaxrow, int smaxcol) {
1370 return ::prefresh(w, pminrow, pmincol,
1371 sminrow, smincol, smaxrow, smaxcol);
1373 // The coordinates sminrow,smincol,smaxrow,smaxcol describe a rectangle
1374 // on the screen. <b>refresh</b> copies a rectangle of this size beginning
1375 // with top left corner pminrow,pmincol onto the screen and calls doupdate().
1378 // If a viewport is defined the pad is displayed in this window, otherwise
1381 int noutrefresh(int pminrow, int pmincol,
1382 int sminrow, int smincol,
1383 int smaxrow, int smaxcol) {
1384 return ::pnoutrefresh(w, pminrow, pmincol,
1385 sminrow, smincol, smaxrow, smaxcol);
1387 // Does the same as refresh() but without calling doupdate().
1389 virtual void setWindow(NCursesWindow& view, int v_grid = 1, int h_grid = 1);
1390 // Add the window "view" as viewing window to the pad.
1392 virtual void setSubWindow(NCursesWindow& sub);
1393 // Use the subwindow "sub" of the viewport window for the actual viewing.
1394 // The full viewport window is usually used to provide some decorations
1395 // like frames, titles etc.
1397 virtual void operator() (void);
1398 // Perform Pad's operation
1401 // A FramedPad is constructed always with a viewport window. This viewport
1402 // will be framed (by a box() command) and the interior of the box is the
1403 // viewport subwindow. On the frame we display scrollbar sliders.
1404 class NCURSES_IMPEXP NCursesFramedPad : public NCursesPad
1407 virtual void OnOperation(int pad_req);
1410 NCursesFramedPad(NCursesWindow& win, int nlines, int ncols,
1411 int v_grid = 1, int h_grid = 1)
1412 : NCursesPad(nlines, ncols) {
1413 NCursesPad::setWindow(win, v_grid, h_grid);
1414 NCursesPad::setSubWindow(*(new NCursesWindow(win)));
1416 // Construct the FramedPad with the given Window win as viewport.
1418 virtual ~NCursesFramedPad() {
1419 delete getSubWindow();
1422 void setWindow(NCursesWindow& view, int v_grid = 1, int h_grid = 1) {
1423 err_handler("Operation not allowed");
1425 // Disable this call; the viewport is already defined
1427 void setSubWindow(NCursesWindow& sub) {
1428 err_handler("Operation not allowed");
1430 // Disable this call; the viewport subwindow is already defined
1434 #endif /* NCURSES_CURSESW_H_incl */