45 #include <sigc++/signal.h> 46 #include <sigc++/trackable.h> 48 #include <cwidget/curses++.h> 49 #include <cwidget/generic/util/ref_ptr.h> 50 #include <cwidget/style.h> 52 #include <cwidget/generic/util/eassert.h> 66 util::ref_ptr<widgets::widget>
settoplevel(
const util::ref_ptr<widgets::widget> &);
69 void updatecursornow();
86 size(
int _w,
int _h):w(_w), h(_h) {}
92 point(
int _x,
int _y):x(_x), y(_y) {}
98 rect(
int _x,
int _y,
int _w,
int _h):x(_x), y(_y), w(_w), h(_h) {}
99 void set_size(
const size &s) {w=s.w; h=s.h;}
100 size get_size() {
return size(w, h);}
107 class widget:
virtual public sigc::trackable
114 friend void toplevel::redraw();
118 friend void toplevel::updatecursornow();
119 friend void toplevel::handleresize();
122 struct binding_connection
128 sigc::slot0<void> slot;
130 binding_connection():bindings(NULL) {}
131 binding_connection(
const std::string &_keyname,
config::keybindings *_bindings,
const sigc::slot0<void> &_slot)
132 :keyname(_keyname), bindings(_bindings), slot(_slot) {}
136 std::list<binding_connection> auxillary_bindings, auxillary_post_bindings;
156 mutable int refcount;
168 bool pre_display_erase:1;
175 void set_owner_window(
cwindow _win,
int x,
int y,
int w,
int h);
178 void set_isfocussed(
bool _isfocussed);
180 cwindow get_win() {
return win;}
187 virtual void paint(
const style &st)=0;
206 eassert(refcount > 0);
213 eassert(refcount > 0);
220 static void handle_pending_deletes();
226 virtual void show_all();
228 void toggle_visible()
235 void set_visible(
bool _visible)
237 if(visible!=_visible)
254 virtual void dispatch_mouse(
short id,
int x,
int y,
int z, mmask_t bstate);
271 virtual int width_request()=0;
278 virtual int height_request(
int width)=0;
295 void alloc_size(
int x,
int y,
int w,
int h);
300 virtual bool focus_me();
304 bool get_isfocussed() {
return isfocussed;}
317 void display(
const style &st);
319 int timeout(
int msecs);
324 virtual void destroy();
328 virtual bool get_cursorvisible()=0;
329 virtual point get_cursorloc()=0;
331 int get_startx() {
return geom.x;}
332 int get_starty() {
return geom.y;}
333 int get_width() {
return geom.w;}
334 int get_height() {
return geom.h;}
336 bool get_visible() {
return visible;}
339 void sync() {
if(win) {win.touch(); win.noutrefresh();}}
341 int scroll(
int n=1) {
return win?win.scroll(n):0;}
343 int addch(chtype ch) {
return win?win.addch(ch):0;}
344 int mvaddch(
int y,
int x, chtype ch) {
return win?win.mvaddch(y,x,ch):0;}
346 int add_wch(
wchar_t wch)
348 return win?win.add_wch(wch):0;
351 int add_wch(
const cchar_t *cch)
353 return win?win.add_wch(cch):0;
356 int mvadd_wch(
int y,
int x,
wchar_t wch)
358 return win?win.mvadd_wch(y, x, wch):0;
361 int mvadd_wch(
int y,
int x,
const cchar_t *cch)
363 return win?win.mvadd_wch(y, x, cch):0;
366 int addstr(
const char *str) {
return win?win.addstr(str):0;}
367 int addnstr(
const char *str,
int n) {
return win?win.addnstr(str, n):0;}
368 int mvaddstr(
int y,
int x,
const char *str) {
return win?win.mvaddstr(y, x, str):0;}
369 int mvaddnstr(
int y,
int x,
const char *str,
int n) {
return win?win.mvaddnstr(y, x, str, n):0;}
371 int addstr(
const wchar_t *str) {
return win?win.addstr(str):0;}
372 int addnstr(
const wchar_t *str,
int n) {
return win?win.addnstr(str, n):0;}
373 int mvaddstr(
int y,
int x,
const wchar_t *str) {
return win?win.mvaddstr(y, x, str):0;}
374 int mvaddnstr(
int y,
int x,
const wchar_t *str,
int n) {
return win?win.mvaddnstr(y, x, str, n):0;}
376 int addstr(
const std::wstring &str) {
return win?win.addstr(str):0;}
377 int addnstr(
const std::wstring &str,
int n) {
return win?win.addnstr(str, n):0;}
378 int mvaddstr(
int y,
int x,
const std::wstring &str) {
return win?win.mvaddstr(y, x, str):0;}
379 int mvaddnstr(
int y,
int x,
const std::wstring &str,
int n) {
return win?win.mvaddnstr(y, x, str, n):0;}
381 int addstr(
const wchstring &str) {
return win?win.addstr(str):0;}
382 int addnstr(
const wchstring &str,
int n) {
return win?win.addnstr(str, n):0;}
383 int mvaddstr(
int y,
int x,
const wchstring &str) {
return win?win.mvaddstr(y, x, str):0;}
384 int mvaddnstr(
int y,
int x,
const wchstring &str,
int n) {
return win?win.mvaddnstr(y, x, str, n):0;}
386 int addstr(
const chstring &str) {
return win?win.addstr(str):0;}
387 int addnstr(
const chstring &str,
int n) {
return win?win.addnstr(str, n):0;}
388 int mvaddstr(
int y,
int x,
const chstring &str) {
return win?win.mvaddstr(y, x, str):0;}
389 int mvaddnstr(
int y,
int x,
const chstring &str,
int n) {
return win?win.mvaddnstr(y, x, str, n):0;}
391 int attroff(
int attrs) {
return win?win.attroff(attrs):0;}
392 int attron(
int attrs) {
return win?win.attron(attrs):0;}
393 int attrset(
int attrs) {
return win?win.attrset(attrs):0;}
395 void bkgdset(
const chtype ch) {
if(win) win.bkgdset(ch);}
396 int bkgd(
const chtype ch) {
return win?win.bkgd(ch):0;}
397 chtype getbkgd() {
return win?win.getbkgd():0;}
399 int border(chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, chtype tr, chtype bl, chtype br)
400 {
return win?win.border(ls,rs,ts,bs,tl,tr,bl,br):0;}
401 int box(chtype verch, chtype horch) {
return win?win.box(verch,horch):0;}
402 int hline(chtype ch,
int n) {
return win?win.hline(ch,n):0;}
403 int vline(chtype ch,
int n) {
return win?win.vline(ch,n):0;}
404 int mvhline(
int y,
int x, chtype ch,
int n) {
return win?win.mvhline(y, x, ch, n):0;}
405 int mvvline(
int y,
int x, chtype ch,
int n) {
return win?win.mvvline(y,x,ch,n):0;}
407 int delch() {
return win?win.delch():0;}
408 int mvdelch(
int y,
int x) {
return win?win.mvdelch(y, x):0;}
410 int deleteln() {
return win?win.deleteln():0;}
411 int insdelln(
int n) {
return win?win.insdelln(n):0;}
412 int insertln() {
return win?win.insertln():0;}
414 int echochar(chtype ch) {
return win?win.echochar(ch):0;}
416 int move(
int y,
int x) {
return win?win.move(y,x):0;}
417 void getyx(
int &y,
int &x) {
if(win) win.getyx(y,x);
else y=x=0;}
418 void getbegyx(
int &y,
int &x) {
if(win) win.getbegyx(y,x);
else y=x=0;}
419 void getmaxyx(
int &y,
int &x) {
if(win) win.getmaxyx(y,x);
else y=x=0;}
420 int getmaxy() {
return win?win.getmaxy():0;}
421 int getmaxx() {
return win?win.getmaxx():0;}
423 void show_string_as_progbar(
int x,
int y,
const std::wstring &s,
425 int size1,
int totalsize)
428 win.show_string_as_progbar(x, y, s,
434 void display_header(std::wstring s,
const style &st) {
if(win) win.display_header(s, st.
get_attrs());}
435 void display_status(std::wstring s,
const style &st) {
if(win) win.display_status(s, st.
get_attrs());}
437 int erase() {
return win?win.erase():0;}
438 int clear() {
return win?win.clear():0;}
439 int clrtobot() {
return win?win.clrtobot():0;}
440 int clrtoeol() {
return win?win.clrtoeol():0;}
444 int keypad(
bool bf) {
return win?win.keypad(bf):0;}
445 int meta(
bool bf) {
return win?win.meta(bf):0;}
447 bool enclose(
int y,
int x)
450 return y>=geom.y && y<geom.y+geom.h && x>=geom.x && x<geom.x+geom.w;
464 pre_display_erase=opaque;
470 void set_bg_style(
const style &new_style);
476 void apply_style(
const style &st);
478 typedef std::list<binding_connection>::iterator key_connection;
481 key_connection connect_key(
const std::string &
key,
483 const sigc::slot0<void> &slot);
486 key_connection connect_key_post(
const std::string &key,
488 const sigc::slot0<void> &slot);
491 void disconnect_key(key_connection c);
493 void disconnect_key_post(key_connection c);
504 sigc::signal0<void> shown_sig;
508 sigc::signal0<void> hidden_sig;
511 sigc::signal0<void> destroyed;
515 sigc::signal0<void> do_layout;
521 sigc::signal0<void> focussed;
522 sigc::signal0<void> unfocussed;