X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=c%2B%2B%2Fcursesw.cc;h=106202a5379d6c24d855c9bd6abf5f51c71c04d2;hp=905a7b52c20d9a5a0536af4fd9744efc0ddf3e30;hb=55ccd2b959766810cf7db8d1c4462f338ce0afc8;hpb=46722468f47c2b77b3987729b4bcf2321cccfd01 diff --git a/c++/cursesw.cc b/c++/cursesw.cc index 905a7b52..106202a5 100644 --- a/c++/cursesw.cc +++ b/c++/cursesw.cc @@ -20,13 +20,13 @@ and Anatoly Ivasyuk (anatoly@nick.csh.rit.edu) modified by Juergen Pfeifer - Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en + and Thomas Dickey (noting that more than 70% of this file has been changed) */ #include "internal.h" #include "cursesw.h" -MODULE_ID("$Id: cursesw.cc,v 1.25 2002/07/06 15:47:52 juergen Exp $") +MODULE_ID("$Id: cursesw.cc,v 1.32 2005/08/13 18:12:17 tom Exp $") #define COLORS_NEED_INITIALIZATION -1 #define COLORS_NOT_INITIALIZED 0 @@ -150,7 +150,8 @@ NCursesWindow::err_handler(const char *msg) const THROWS(NCursesException) } void -NCursesWindow::initialize() { +NCursesWindow::initialize() +{ if (!b_initialized) { ::initscr(); b_initialized = TRUE; @@ -163,21 +164,24 @@ NCursesWindow::initialize() { } } -NCursesWindow::NCursesWindow() { +NCursesWindow::NCursesWindow() + : w(0), alloced(0), par(0), subwins(0), sib(0) +{ initialize(); - w = (WINDOW *)0; + w = static_cast(0); init(); alloced = FALSE; subwins = par = sib = 0; count++; } -NCursesWindow::NCursesWindow(int lines, int cols, int begin_y, int begin_x) +NCursesWindow::NCursesWindow(int nlines, int ncols, int begin_y, int begin_x) + : w(0), alloced(0), par(0), subwins(0), sib(0) { initialize(); - w = ::newwin(lines, cols, begin_y, begin_x); + w = ::newwin(nlines, ncols, begin_y, begin_x); if (w == 0) { err_handler("Cannot construct window"); } @@ -189,6 +193,7 @@ NCursesWindow::NCursesWindow(int lines, int cols, int begin_y, int begin_x) } NCursesWindow::NCursesWindow(WINDOW* &window) + : w(0), alloced(0), par(0), subwins(0), sib(0) { initialize(); @@ -201,6 +206,7 @@ NCursesWindow::NCursesWindow(WINDOW* &window) NCursesWindow::NCursesWindow(NCursesWindow& win, int l, int c, int begin_y, int begin_x, char absrel) + : w(0), alloced(0), par(0), subwins(0), sib(0) { initialize(); if (absrel == 'a') { // absolute origin @@ -227,9 +233,12 @@ NCursesWindow::NCursesWindow(NCursesWindow& win, int l, int c, NCursesWindow::NCursesWindow(NCursesWindow& win, bool do_box NCURSES_PARAM_INIT(TRUE)) + : w(0), alloced(0), par(0), subwins(0), sib(0) { initialize(); - w = :: derwin(win.w,win.height()-2,win.width()-2,1,1); + int myHeight = win.height(); + int myWidth = win.width(); + w = :: derwin(win.w, myHeight - 2, myWidth - 2, 1, 1); if (w == 0) { err_handler("Cannot construct subwindow"); } @@ -247,7 +256,8 @@ NCursesWindow::NCursesWindow(NCursesWindow& win, } } -NCursesWindow NCursesWindow::Clone() { +NCursesWindow NCursesWindow::Clone() +{ WINDOW *d = ::dupwin(w); NCursesWindow W(d); W.subwins = subwins; @@ -262,31 +272,32 @@ static RIPOFFINIT R_INIT[5]; // There can't be more static int r_init_idx = 0; static RIPOFFINIT* prip = R_INIT; -extern "C" int _nc_ripoffline(int,int (*init)(WINDOW*,int)); - -NCursesWindow::NCursesWindow(WINDOW *win, int cols) { +NCursesWindow::NCursesWindow(WINDOW *win, int ncols) + : w(0), alloced(0), par(0), subwins(0), sib(0) +{ initialize(); w = win; - assert((w->_maxx+1)==cols); + assert((w->_maxx+1)==ncols); alloced = FALSE; subwins = par = sib = 0; } -int NCursesWindow::ripoff_init(WINDOW *w, int cols) +int _nc_xx_ripoff_init(WINDOW *w, int ncols) { int res = ERR; RIPOFFINIT init = *prip++; if (init) { - NCursesWindow* W = new NCursesWindow(w,cols); + NCursesWindow* W = new NCursesWindow(w,ncols); res = init(*W); } return res; } int NCursesWindow::ripoffline(int ripoff_lines, - int (*init)(NCursesWindow& win)) { - int code = ::_nc_ripoffline(ripoff_lines,ripoff_init); + int (*init)(NCursesWindow& win)) +{ + int code = ::_nc_ripoffline(ripoff_lines,_nc_xx_ripoff_init); if (code==OK && init && ripoff_lines) { R_INIT[r_init_idx++] = init; } @@ -294,7 +305,8 @@ int NCursesWindow::ripoffline(int ripoff_lines, } bool -NCursesWindow::isDescendant(NCursesWindow& win) { +NCursesWindow::isDescendant(NCursesWindow& win) +{ for (NCursesWindow* p = subwins; p != NULL; p = p->sib) { if (p==&win) return TRUE; @@ -386,7 +398,7 @@ NCursesWindow::getcolor(int getback) const short fore, back; if (colorInitialized==COLORS_ARE_REALLY_THERE) { - if (::pair_content((short)PAIR_NUMBER(w->_attrs), &fore, &back)) + if (::pair_content(static_cast(PAIR_NUMBER(w->_attrs)), &fore, &back)) err_handler("Can't get color pair"); } else { @@ -427,7 +439,7 @@ int NCursesWindow::setpalette(short fore, short back) { if (colorInitialized==COLORS_ARE_REALLY_THERE) - return setpalette(fore, back, (short)PAIR_NUMBER(w->_attrs)); + return setpalette(fore, back, static_cast(PAIR_NUMBER(w->_attrs))); else return OK; } @@ -447,9 +459,8 @@ NCursesWindow::setcolor(short pair) } #if HAVE_HAS_KEY -extern "C" int _nc_has_mouse(void); - -bool NCursesWindow::has_mouse() const { +bool NCursesWindow::has_mouse() const +{ return ((::has_key(KEY_MOUSE) || ::_nc_has_mouse()) ? TRUE : FALSE); }