22 #ifndef CURSES_PLUSPLUS_H 23 #define CURSES_PLUSPLUS_H 26 #include <ncursesw/curses.h> 28 #include <cwidget/generic/util/eassert.h> 35 #include <cwidget-config.h> 65 wchtype(
const wchar_t &_ch,
const attr_t &_attrs)
70 bool operator==(
const wchtype &other)
const 72 return ch==other.
ch && attrs==other.
attrs;
75 bool operator!=(
const wchtype &other)
const 77 return ch!=other.
ch || attrs!=other.
attrs;
80 bool operator<(
const wchtype &other)
const 82 return ch<other.
ch || (ch==other.
ch && attrs<other.
attrs);
85 bool operator<=(
const wchtype &other)
const 87 return (*
this) == other || (*this) < other;
90 bool operator>(
const wchtype &other)
const 92 return !((*this)<=other);
95 bool operator>=(
const wchtype &other)
const 97 return !((*this)<other);
113 struct TRAITS_CLASS<chtype> {
114 typedef chtype char_type;
116 static void assign (char_type& c1,
const char_type& c2)
118 static bool eq (
const char_type & c1,
const char_type& c2)
119 {
return (c1 == c2); }
120 static bool ne (
const char_type& c1,
const char_type& c2)
121 {
return (c1 != c2); }
122 static bool lt (
const char_type& c1,
const char_type& c2)
123 {
return (c1 < c2); }
124 static char_type eos () {
return 0; }
125 static bool is_del(char_type a) {
return isspace(a|A_CHARTEXT); }
127 static int compare (
const char_type* s1,
const char_type* s2,
size_t n);
128 static size_t length (
const char_type* s);
129 static char_type* copy (char_type* s1,
const char_type* s2,
size_t n)
130 {
return (char_type*) memcpy (s1, s2, n*
sizeof(char_type)); }
131 static char_type* move (char_type* s1,
const char_type* s2,
size_t n)
132 {
return (char_type*) memmove (s1, s2, n*
sizeof(char_type)); }
133 static char_type* assign (char_type* s1,
size_t n,
const char_type& c);
140 static void assign (char_type& c1,
const char_type& c2)
142 static bool eq (
const char_type & c1,
const char_type& c2)
143 {
return (c1 == c2); }
144 static bool ne (
const char_type& c1,
const char_type& c2)
145 {
return (c1 != c2); }
146 static bool lt (
const char_type& c1,
const char_type& c2)
147 {
return (c1 < c2); }
149 static bool is_del(char_type a) {
return isspace(a.
ch); }
151 static int compare (
const char_type* s1,
const char_type* s2,
size_t n);
152 static size_t length (
const char_type* s);
153 static char_type* copy (char_type* s1,
const char_type* s2,
size_t n)
154 {
return (char_type*) memcpy (s1, s2, n*
sizeof(char_type)); }
155 static char_type* move (char_type* s1,
const char_type* s2,
size_t n)
156 {
return (char_type*) memmove (s1, s2, n*
sizeof(char_type)); }
157 static char_type* assign (char_type* s1,
size_t n,
const char_type& c);
172 typedef std::basic_string<chtype> super;
174 chstring(
const std::basic_string<chtype> &s)
175 :std::basic_string<chtype>(s) {}
193 chstring &operator=(
const std::string &s);
196 void apply_style(
const style &st);
201 typedef std::basic_string<wchtype> super;
203 wchstring(
const std::basic_string<wchtype> &s)
204 :std::basic_string<wchtype>(s) {}
230 void apply_style(
const style &st);
236 inline chtype _getbkgd(WINDOW *win)
241 inline int _box(WINDOW *win, chtype verch, chtype horch)
243 return box(win, verch, horch);
246 inline void _getyx(WINDOW *win,
int &y,
int &x)
251 inline void _getparyx(WINDOW *win,
int &y,
int &x)
256 inline void _getbegyx(WINDOW *win,
int &y,
int &x)
261 inline void _getmaxyx(WINDOW *win,
int &y,
int &x)
266 inline int _getmaxy(WINDOW *win)
271 inline int _getmaxx(WINDOW *win)
276 inline int _touchwin(WINDOW *win)
278 return touchwin(win);
281 inline int _untouchwin(WINDOW *win)
283 return untouchwin(win);
376 cwindow_master *parent;
390 cwindow_master(WINDOW *_win, cwindow_master *_parent)
391 :win(_win), refs(0), parent(_parent)
415 cwindow_master *master;
418 cwindow(WINDOW *_win, cwindow_master *_master)
419 :win(_win), master(_master)
424 cwindow(WINDOW *_win):win(_win), master(
new cwindow_master(_win, NULL))
438 cwindow derwin(
int h,
int w,
int y,
int x)
440 WINDOW *new_win=::derwin(win, h, w, y, x);
441 return cwindow(new_win,
new cwindow_master(new_win, master));
444 int mvwin(
int y,
int x) {return ::mvwin(win, y, x);}
446 void syncup() {wsyncup(win);}
447 int syncok(
bool bf) {return ::syncok(win, bf);}
448 void cursyncup() {wcursyncup(win);}
449 void syncdown() {wsyncdown(win);}
451 int scroll(
int n=1) {
return wscrl(win, n);}
454 int addch(chtype
ch) {
return waddch(win, ch);}
455 int mvaddch(
int y,
int x, chtype ch) {
return mvwaddch(win, y, x, ch);}
457 int add_wch(
wchar_t wch)
464 if(setcchar(&cch, tmp, 0, 0, 0)==ERR)
467 return wadd_wch(win, &cch);
470 int mvadd_wch(
int y,
int x,
wchar_t wch)
476 int add_wch(
const cchar_t *cch)
478 return wadd_wch(win, cch);
481 int mvadd_wch(
int y,
int x,
const cchar_t *cch)
483 return mvwadd_wch(win, y, x, cch);
486 int addstr(
const std::wstring &str) {
return addstr(str.c_str());}
487 int addnstr(
const std::wstring &str,
int n) {
return addnstr(str.c_str(), n);}
488 int mvaddstr(
int y,
int x,
const std::wstring &str) {
return mvaddstr(y, x, str.c_str());}
489 int mvaddnstr(
int y,
int x,
const std::wstring &str,
int n) {
return mvaddnstr(y, x, str.c_str(), n);}
491 int addstr(
const wchar_t *str) {
return waddwstr(win, str);}
492 int addnstr(
const wchar_t *str,
int n) {
return waddnwstr(win, str, n);}
493 int mvaddstr(
int y,
int x,
const wchar_t *str) {
return mvwaddwstr(win, y, x, str);}
494 int mvaddnstr(
int y,
int x,
const wchar_t *str,
int n) {
return mvwaddnwstr(win, y, x, str, n);}
496 int addstr(
const char *str) {
return waddstr(win, str);}
497 int addnstr(
const char *str,
int n) {
return waddnstr(win, str, n);}
498 int mvaddstr(
int y,
int x,
const char *str) {
return mvwaddstr(win, y, x, str);}
499 int mvaddnstr(
int y,
int x,
const char *str,
int n) {
return mvwaddnstr(win, y, x, str, n);}
504 int addnstr(
const wchstring &str,
size_t n);
505 int mvaddstr(
int y,
int x,
const wchstring &str);
506 int mvaddnstr(
int y,
int x,
const wchstring &str,
size_t n);
508 int addstr(
const chstring &str) {
return waddchstr(win, str.c_str());}
509 int addnstr(
const chstring &str,
int n) {
return waddchnstr(win, str.c_str(), n);}
510 int mvaddstr(
int y,
int x,
const chstring &str) {
return mvwaddchstr(win, y, x, str.c_str());}
511 int mvaddnstr(
int y,
int x,
const chstring &str,
int n) {
return mvwaddchnstr(win, y, x, str.c_str(), n);}
513 int attroff(
int attrs) {
return wattroff(win, attrs);}
514 int attron(
int attrs) {
return wattron(win, attrs);}
515 int attrset(
int attrs) {
return wattrset(win, attrs);}
518 void bkgdset(
const chtype ch) {wbkgdset(win, ch);}
519 int bkgd(
const chtype ch) {
return wbkgd(win, ch);}
520 chtype getbkgd() {
return _getbkgd(win);}
522 int border(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, chtype tr, chtype bl, chtype br)
523 {
return wborder(win, ls, rs, ts, bs, tl, tr, bl, br);}
525 int box(chtype verch, chtype horch) {
return _box(win, verch, horch);}
526 int hline(chtype ch,
int n) {
return whline(win, ch, n);}
527 int vline(chtype ch,
int n) {
return wvline(win, ch, n);}
528 int mvhline(
int y,
int x, chtype ch,
int n) {
return mvwhline(win, y, x, ch, n);}
529 int mvvline(
int y,
int x, chtype ch,
int n) {
return mvwvline(win, y, x, ch, n);}
531 int delch() {
return wdelch(win);}
532 int mvdelch(
int y,
int x) {
return mvwdelch(win, y, x);}
534 int deleteln() {
return wdeleteln(win);}
535 int insdelln(
int n) {
return winsdelln(win,n);}
536 int insertln() {
return winsertln(win);}
538 int echochar(chtype ch) {
return wechochar(win, ch);}
540 int getch() {
return wgetch(win);}
541 int mvgetch(
int y,
int x) {
return mvwgetch(win, y, x);}
543 int get_wch(wint_t *wch) {
return wget_wch(win, wch);}
544 int mvget_wch(
int y,
int x, wint_t *wch) {
return mvwget_wch(win, y, x, wch);}
546 int move(
int y,
int x) {
return wmove(win, y, x);}
547 void getyx(
int &y,
int &x) {_getyx(win, y, x);}
548 void getparyx(
int &y,
int &x) {_getparyx(win, y, x);}
549 void getbegyx(
int &y,
int &x) {_getbegyx(win, y, x);}
550 void getmaxyx(
int &y,
int &x) {_getmaxyx(win, y, x);}
551 int getmaxy() {
return _getmaxy(win);}
552 int getmaxx() {
return _getmaxx(win);}
554 void show_string_as_progbar(
int x,
int y,
const std::wstring &s,
555 int attr1,
int attr2,
int size1,
559 void display_header(std::wstring s,
const attr_t attr);
560 void display_status(std::wstring s,
const attr_t attr);
564 int overlay(
cwindow &dstwin) {return ::overlay(win, dstwin.win);}
565 int overwrite(
cwindow &dstwin) {return ::overwrite(win, dstwin.win);}
566 int copywin(
cwindow &dstwin,
int sminrow,
int smincol,
int dminrow,
int dmincol,
int dmaxrow,
int dmaxcol,
int overlay)
567 {return ::copywin(win, dstwin.win, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, overlay);}
569 int refresh() {
return wrefresh(win);}
570 int noutrefresh() {
return wnoutrefresh(win);}
572 int touch() {
return _touchwin(win);}
573 int untouch() {
return _untouchwin(win);}
574 int touchln(
int y,
int n,
int changed) {return ::wtouchln(win, y, n, changed);}
575 int touchline(
int start,
int count) {
return touchln(start, count, 1);}
576 int untouchline(
int start,
int count) {
return touchln(start, count, 0);}
578 int erase() {
return werase(win);}
579 int clear() {
return wclear(win);}
580 int clrtobot() {
return wclrtobot(win);}
581 int clrtoeol() {
return wclrtoeol(win);}
583 int keypad(
bool bf) {return ::keypad(win,bf);}
584 int meta(
bool bf) {return ::meta(win,bf);}
585 int nodelay(
bool bf) {return ::nodelay(win, bf);}
586 int notimeout(
bool bf) {return ::notimeout(win, bf);}
587 void timeout(
int delay) {wtimeout(win, delay);}
589 int clearok(
bool bf) {return ::clearok(win, bf);}
590 int idlok(
bool bf) {return ::idlok(win, bf);}
591 void idcok(
bool bf) {::idcok(win, bf);}
592 void immedok(
bool bf) {::immedok(win, bf);}
593 #if defined(NCURSES_VERSION_MAJOR) && NCURSES_VERSION_MAJOR>=5 594 int leaveok(
bool bf) {
int rval=::leaveok(win, bf); curs_set(bf?0:1);
return rval;}
596 int leaveok(
bool bf) {return ::leaveok(win, bf);}
598 int setscrreg(
int top,
int bot) {
return wsetscrreg(win, top, bot);}
599 int scrollok(
bool bf) {return ::scrollok(win,bf);}
601 int printw(
char *str, ...);
604 bool enclose(
int y,
int x) {
return wenclose(win, y, x);}
606 WINDOW *getwin() {
return win;}
607 operator bool () {
return win!=NULL;}
610 cwindow_master *newmaster=a.master;
618 bool operator ==(
cwindow &other) {
return win==other.win;}
619 bool operator !=(
cwindow &other) {
return win!=other.win;}
621 static void remove_cruft();
Definition: curses++.h:102