23 #ifndef CURSES_PLUSPLUS_H
24 #define CURSES_PLUSPLUS_H
27 #include <ncursesw/curses.h>
29 #include <cwidget/generic/util/eassert.h>
36 #include <cwidget-config.h>
64 wchtype(
const wchar_t &_ch,
const attr_t &_attrs)
69 bool operator==(
const wchtype &other)
const
74 bool operator!=(
const wchtype &other)
const
76 return ch!=other.ch ||
attrs!=other.attrs;
79 bool operator<(
const wchtype &other)
const
81 return ch<other.ch || (
ch==other.ch &&
attrs<other.attrs);
84 bool operator<=(
const wchtype &other)
const
86 return (*
this) == other || (*this) < other;
89 bool operator>(
const wchtype &other)
const
91 return !((*this)<=other);
94 bool operator>=(
const wchtype &other)
const
96 return !((*this)<other);
112 struct TRAITS_CLASS<chtype> {
113 typedef chtype char_type;
115 static void assign (char_type& c1,
const char_type& c2)
117 static bool eq (
const char_type & c1,
const char_type& c2)
118 {
return (c1 == c2); }
119 static bool ne (
const char_type& c1,
const char_type& c2)
120 {
return (c1 != c2); }
121 static bool lt (
const char_type& c1,
const char_type& c2)
122 {
return (c1 < c2); }
123 static char_type eos () {
return 0; }
124 static bool is_del(char_type a) {
return isspace(a|A_CHARTEXT); }
126 static int compare (
const char_type* s1,
const char_type* s2,
size_t n);
127 static size_t length (
const char_type* s);
128 static char_type* copy (char_type* s1,
const char_type* s2,
size_t n)
129 {
return (char_type*) memcpy (s1, s2, n*
sizeof(char_type)); }
130 static char_type* move (char_type* s1,
const char_type* s2,
size_t n)
131 {
return (char_type*) memmove (s1, s2, n*
sizeof(char_type)); }
132 static char_type* assign (char_type* s1,
size_t n,
const char_type& c);
142 {
return (c1 == c2); }
144 {
return (c1 != c2); }
146 {
return (c1 < c2); }
148 static bool is_del(
char_type a) {
return isspace(a.
ch); }
151 static size_t length (
const char_type* s);
171 typedef std::basic_string<chtype> super;
173 chstring(
const std::basic_string<chtype> &s)
174 :std::basic_string<chtype>(s) {}
200 typedef std::basic_string<wchtype> super;
202 wchstring(
const std::basic_string<wchtype> &s)
203 :std::basic_string<wchtype>(s) {}
222 wchstring(
size_t n, wchtype c)
225 wchstring(
size_t n,
wchar_t c, attr_t a)
226 :super(n, wchtype(c, a)) {}
235 inline chtype _getbkgd(WINDOW *win)
240 inline int _box(WINDOW *win, chtype verch, chtype horch)
242 return box(win, verch, horch);
245 inline void _getyx(WINDOW *win,
int &y,
int &x)
250 inline void _getparyx(WINDOW *win,
int &y,
int &x)
255 inline void _getbegyx(WINDOW *win,
int &y,
int &x)
260 inline void _getmaxyx(WINDOW *win,
int &y,
int &x)
265 inline int _getmaxy(WINDOW *win)
270 inline int _getmaxx(WINDOW *win)
275 inline int _touchwin(WINDOW *win)
277 return touchwin(win);
280 inline int _untouchwin(WINDOW *win)
282 return untouchwin(win);
375 cwindow_master *parent;
389 cwindow_master(WINDOW *_win, cwindow_master *_parent)
390 :win(_win), refs(0), parent(_parent)
414 cwindow_master *master;
417 cwindow(WINDOW *_win, cwindow_master *_master)
418 :win(_win), master(_master)
423 cwindow(WINDOW *_win):win(_win), master(
new cwindow_master(_win, NULL))
437 cwindow derwin(
int h,
int w,
int y,
int x)
439 WINDOW *new_win=::derwin(win, h, w, y, x);
440 return cwindow(new_win,
new cwindow_master(new_win, master));
443 int mvwin(
int y,
int x) {return ::mvwin(win, y, x);}
445 void syncup() {wsyncup(win);}
446 int syncok(
bool bf) {return ::syncok(win, bf);}
447 void cursyncup() {wcursyncup(win);}
448 void syncdown() {wsyncdown(win);}
450 int scroll(
int n=1) {
return wscrl(win, n);}
453 int addch(chtype ch) {
return waddch(win, ch);}
454 int mvaddch(
int y,
int x, chtype ch) {
return mvwaddch(win, y, x, ch);}
456 int add_wch(
wchar_t wch)
463 if(setcchar(&cch, tmp, 0, 0, 0)==ERR)
466 return wadd_wch(win, &cch);
469 int mvadd_wch(
int y,
int x,
wchar_t wch)
475 int add_wch(
const cchar_t *cch)
477 return wadd_wch(win, cch);
480 int mvadd_wch(
int y,
int x,
const cchar_t *cch)
482 return mvwadd_wch(win, y, x, cch);
485 int addstr(
const std::wstring &str) {
return addstr(str.c_str());}
486 int addnstr(
const std::wstring &str,
int n) {
return addnstr(str.c_str(), n);}
487 int mvaddstr(
int y,
int x,
const std::wstring &str) {
return mvaddstr(y, x, str.c_str());}
488 int mvaddnstr(
int y,
int x,
const std::wstring &str,
int n) {
return mvaddnstr(y, x, str.c_str(), n);}
490 int addstr(
const wchar_t *str) {
return waddwstr(win, str);}
491 int addnstr(
const wchar_t *str,
int n) {
return waddnwstr(win, str, n);}
492 int mvaddstr(
int y,
int x,
const wchar_t *str) {
return mvwaddwstr(win, y, x, str);}
493 int mvaddnstr(
int y,
int x,
const wchar_t *str,
int n) {
return mvwaddnwstr(win, y, x, str, n);}
495 int addstr(
const char *str) {
return waddstr(win, str);}
496 int addnstr(
const char *str,
int n) {
return waddnstr(win, str, n);}
497 int mvaddstr(
int y,
int x,
const char *str) {
return mvwaddstr(win, y, x, str);}
498 int mvaddnstr(
int y,
int x,
const char *str,
int n) {
return mvwaddnstr(win, y, x, str, n);}
503 int addnstr(
const wchstring &str,
size_t n);
504 int mvaddstr(
int y,
int x,
const wchstring &str);
505 int mvaddnstr(
int y,
int x,
const wchstring &str,
size_t n);
507 int addstr(
const chstring &str) {
return waddchstr(win, str.c_str());}
508 int addnstr(
const chstring &str,
int n) {
return waddchnstr(win, str.c_str(), n);}
509 int mvaddstr(
int y,
int x,
const chstring &str) {
return mvwaddchstr(win, y, x, str.c_str());}
510 int mvaddnstr(
int y,
int x,
const chstring &str,
int n) {
return mvwaddchnstr(win, y, x, str.c_str(), n);}
512 int attroff(
int attrs) {
return wattroff(win, attrs);}
513 int attron(
int attrs) {
return wattron(win, attrs);}
514 int attrset(
int attrs) {
return wattrset(win, attrs);}
517 void bkgdset(
const chtype ch) {wbkgdset(win, ch);}
518 int bkgd(
const chtype ch) {
return wbkgd(win, ch);}
519 chtype getbkgd() {
return _getbkgd(win);}
521 int border(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, chtype tr, chtype bl, chtype br)
522 {
return wborder(win, ls, rs, ts, bs, tl, tr, bl, br);}
524 int box(chtype verch, chtype horch) {
return _box(win, verch, horch);}
525 int hline(chtype ch,
int n) {
return whline(win, ch, n);}
526 int vline(chtype ch,
int n) {
return wvline(win, ch, n);}
527 int mvhline(
int y,
int x, chtype ch,
int n) {
return mvwhline(win, y, x, ch, n);}
528 int mvvline(
int y,
int x, chtype ch,
int n) {
return mvwvline(win, y, x, ch, n);}
530 int delch() {
return wdelch(win);}
531 int mvdelch(
int y,
int x) {
return mvwdelch(win, y, x);}
533 int deleteln() {
return wdeleteln(win);}
534 int insdelln(
int n) {
return winsdelln(win,n);}
535 int insertln() {
return winsertln(win);}
537 int echochar(chtype ch) {
return wechochar(win, ch);}
539 int getch() {
return wgetch(win);}
540 int mvgetch(
int y,
int x) {
return mvwgetch(win, y, x);}
542 int get_wch(wint_t *wch) {
return wget_wch(win, wch);}
543 int mvget_wch(
int y,
int x, wint_t *wch) {
return mvwget_wch(win, y, x, wch);}
545 int move(
int y,
int x) {
return wmove(win, y, x);}
546 void getyx(
int &y,
int &x) {_getyx(win, y, x);}
547 void getparyx(
int &y,
int &x) {_getparyx(win, y, x);}
548 void getbegyx(
int &y,
int &x) {_getbegyx(win, y, x);}
549 void getmaxyx(
int &y,
int &x) {_getmaxyx(win, y, x);}
550 int getmaxy() {
return _getmaxy(win);}
551 int getmaxx() {
return _getmaxx(win);}
553 void show_string_as_progbar(
int x,
int y,
const std::wstring &s,
554 int attr1,
int attr2,
int size1,
558 void display_header(std::wstring s,
const attr_t attr);
559 void display_status(std::wstring s,
const attr_t attr);
563 int overlay(
cwindow &dstwin) {return ::overlay(win, dstwin.win);}
564 int overwrite(
cwindow &dstwin) {return ::overwrite(win, dstwin.win);}
565 int copywin(
cwindow &dstwin,
int sminrow,
int smincol,
int dminrow,
int dmincol,
int dmaxrow,
int dmaxcol,
int overlay)
566 {return ::copywin(win, dstwin.win, sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol, overlay);}
568 int refresh() {
return wrefresh(win);}
569 int noutrefresh() {
return wnoutrefresh(win);}
571 int touch() {
return _touchwin(win);}
572 int untouch() {
return _untouchwin(win);}
573 int touchln(
int y,
int n,
int changed) {return ::wtouchln(win, y, n, changed);}
574 int touchline(
int start,
int count) {
return touchln(start, count, 1);}
575 int untouchline(
int start,
int count) {
return touchln(start, count, 0);}
577 int erase() {
return werase(win);}
578 int clear() {
return wclear(win);}
579 int clrtobot() {
return wclrtobot(win);}
580 int clrtoeol() {
return wclrtoeol(win);}
582 int keypad(
bool bf) {return ::keypad(win,bf);}
583 int meta(
bool bf) {return ::meta(win,bf);}
584 int nodelay(
bool bf) {return ::nodelay(win, bf);}
585 int notimeout(
bool bf) {return ::notimeout(win, bf);}
586 void timeout(
int delay) {wtimeout(win, delay);}
588 int clearok(
bool bf) {return ::clearok(win, bf);}
589 int idlok(
bool bf) {return ::idlok(win, bf);}
590 void idcok(
bool bf) {::idcok(win, bf);}
591 void immedok(
bool bf) {::immedok(win, bf);}
592 #if defined(NCURSES_VERSION_MAJOR) && NCURSES_VERSION_MAJOR>=5
593 int leaveok(
bool bf) {
int rval=::leaveok(win, bf); curs_set(bf?0:1);
return rval;}
595 int leaveok(
bool bf) {return ::leaveok(win, bf);}
597 int setscrreg(
int top,
int bot) {
return wsetscrreg(win, top, bot);}
598 int scrollok(
bool bf) {return ::scrollok(win,bf);}
600 int printw(
char *str, ...);
603 bool enclose(
int y,
int x) {
return wenclose(win, y, x);}
605 WINDOW *getwin() {
return win;}
606 operator bool () {
return win!=NULL;}
609 cwindow_master *newmaster=a.master;
617 bool operator ==(
cwindow &other) {
return win==other.win;}
618 bool operator !=(
cwindow &other) {
return win!=other.win;}
620 static void remove_cruft();