X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=c%2B%2B%2Fcursesw.cc;h=662edb5ad476edbf5052821603b9af58b7ffebd8;hp=b3bd3071c5f218ab2ab410143b1cb4bcde683991;hb=a8987e73ec254703634802b4f7ee30d3a485524d;hpb=661078ddbde3ce0f3b06e95642fbb9b5fef7dca1 diff --git a/c++/cursesw.cc b/c++/cursesw.cc index b3bd3071..662edb5a 100644 --- a/c++/cursesw.cc +++ b/c++/cursesw.cc @@ -19,13 +19,14 @@ modified by Ulrich Drepper (drepper@karlsruhe.gmd.de) and Anatoly Ivasyuk (anatoly@nick.csh.rit.edu) - modified by Juergen Pfeifer (Juergen.Pfeifer@T-Online.de) + modified by Juergen Pfeifer + and Thomas Dickey (noting that more than 70% of this file has been changed) */ -#include "cursesw.h" #include "internal.h" +#include "cursesw.h" -MODULE_ID("$Id: cursesw.cc,v 1.10 1997/10/20 21:26:35 juergen Exp $") +MODULE_ID("$Id: cursesw.cc,v 1.26 2003/10/25 15:02:46 tom Exp $") #define COLORS_NEED_INITIALIZATION -1 #define COLORS_NOT_INITIALIZED 0 @@ -36,46 +37,73 @@ MODULE_ID("$Id: cursesw.cc,v 1.10 1997/10/20 21:26:35 juergen Exp $") long NCursesWindow::count = 0L; bool NCursesWindow::b_initialized = FALSE; +/* + * The ncurses library has a fallback for vsscanf(), which may work... + */ +#if !(USE_STRSTREAM_VSCAN || USE_STRSTREAM_VSCAN_CAST) +# undef USE_STDIO_VSCAN +# define USE_STDIO_VSCAN 1 +#endif + +#if defined(__GNUG__) +# ifndef _IO_va_list +# define _IO_va_list char * +# endif +#endif + int NCursesWindow::scanw(const char* fmt, ...) { -#if defined(__GNUG__) - va_list args; - va_start(args, fmt); + int result = ERR; char buf[BUFSIZ]; - int result = wgetstr(w, buf); - if (result == OK) { - strstreambuf ss(buf, BUFSIZ); - result = ss.vscan(fmt, args); + + if (::wgetnstr(w, buf, sizeof(buf)) != ERR) { + va_list args; + va_start(args, fmt); +#if USE_STDIO_VSCAN + if (::vsscanf(buf, fmt, args) != -1) + result = OK; +#elif USE_STRSTREAM_VSCAN /* powerpc, os390 */ + strstreambuf ss(buf, sizeof(buf)); + if (ss.vscan(fmt, args) != -1) + result = OK; +#elif USE_STRSTREAM_VSCAN_CAST /* pre-gcc 3.0 */ + strstreambuf ss(buf, sizeof(buf)); + if (ss.vscan(fmt, (_IO_va_list)args) != -1) + result = OK; +#endif + va_end(args); } - va_end(args); return result; -#else - return ERR; -#endif } int NCursesWindow::scanw(int y, int x, const char* fmt, ...) { -#if defined(__GNUG__) - va_list args; - va_start(args, fmt); + int result = ERR; char buf[BUFSIZ]; - int result = wmove(w, y, x); - if (result == OK) { - result = wgetstr(w, buf); - if (result == OK) { - strstreambuf ss(buf, BUFSIZ); - result = ss.vscan(fmt, args); + + if (::wmove(w, y, x) != ERR) { + if (::wgetnstr(w, buf, sizeof(buf)) != ERR) { + va_list args; + va_start(args, fmt); +#if USE_STDIO_VSCAN + if (::vsscanf(buf, fmt, args) != -1) + result = OK; +#elif USE_STRSTREAM_VSCAN /* powerpc, os390 */ + strstreambuf ss(buf, sizeof(buf)); + if (ss.vscan(fmt, args) != -1) + result = OK; +#elif USE_STRSTREAM_VSCAN_CAST /* pre-gcc 3.0 */ + strstreambuf ss(buf, sizeof(buf)); + if (ss.vscan(fmt, (_IO_va_list)args) != -1) + result = OK; +#endif + va_end(args); } } - va_end(args); return result; -#else - return ERR; -#endif } @@ -85,7 +113,7 @@ NCursesWindow::printw(const char * fmt, ...) va_list args; va_start(args, fmt); char buf[BUFSIZ]; - vsprintf(buf, fmt, args); + ::vsprintf(buf, fmt, args); va_end(args); return waddstr(w, buf); } @@ -96,10 +124,10 @@ NCursesWindow::printw(int y, int x, const char * fmt, ...) { va_list args; va_start(args, fmt); - int result = wmove(w, y, x); + int result = ::wmove(w, y, x); if (result == OK) { char buf[BUFSIZ]; - vsprintf(buf, fmt, args); + ::vsprintf(buf, fmt, args); result = waddstr(w, buf); } va_end(args); @@ -136,9 +164,8 @@ NCursesWindow::initialize() { } NCursesWindow::NCursesWindow() { - if (!b_initialized) - initialize(); - + initialize(); + w = (WINDOW *)0; init(); alloced = FALSE; @@ -148,8 +175,7 @@ NCursesWindow::NCursesWindow() { NCursesWindow::NCursesWindow(int lines, int cols, int begin_y, int begin_x) { - if (!b_initialized) - initialize(); + initialize(); w = ::newwin(lines, cols, begin_y, begin_x); if (w == 0) { @@ -164,9 +190,8 @@ NCursesWindow::NCursesWindow(int lines, int cols, int begin_y, int begin_x) NCursesWindow::NCursesWindow(WINDOW* &window) { - if (!b_initialized) - initialize(); - + initialize(); + w = window; init(); alloced = FALSE; @@ -177,7 +202,8 @@ NCursesWindow::NCursesWindow(WINDOW* &window) NCursesWindow::NCursesWindow(NCursesWindow& win, int l, int c, int begin_y, int begin_x, char absrel) { - if (absrel == 'a') { // absolute origin + initialize(); + if (absrel == 'a') { // absolute origin begin_y -= win.begy(); begin_x -= win.begx(); } @@ -198,7 +224,29 @@ NCursesWindow::NCursesWindow(NCursesWindow& win, int l, int c, alloced = TRUE; count++; } - + +NCursesWindow::NCursesWindow(NCursesWindow& win, + bool do_box NCURSES_PARAM_INIT(TRUE)) +{ + initialize(); + w = :: derwin(win.w,win.height()-2,win.width()-2,1,1); + if (w == 0) { + err_handler("Cannot construct subwindow"); + } + + par = &win; + sib = win.subwins; + win.subwins = this; + subwins = 0; + alloced = TRUE; + count++; + + if (do_box) { + win.box(); + win.touchwin(); + } +} + NCursesWindow NCursesWindow::Clone() { WINDOW *d = ::dupwin(w); NCursesWindow W(d); @@ -217,6 +265,7 @@ static RIPOFFINIT* prip = R_INIT; extern "C" int _nc_ripoffline(int,int (*init)(WINDOW*,int)); NCursesWindow::NCursesWindow(WINDOW *win, int cols) { + initialize(); w = win; assert((w->_maxx+1)==cols); alloced = FALSE; @@ -296,7 +345,7 @@ NCursesWindow::~NCursesWindow() } if (alloced && w != 0) - delwin(w); + ::delwin(w); if (alloced) { --count; @@ -317,7 +366,7 @@ int NCursesWindow::colorInitialized = COLORS_NOT_INITIALIZED; void NCursesWindow::useColors(void) { - if (colorInitialized == COLORS_NOT_INITIALIZED) { + if (colorInitialized == COLORS_NOT_INITIALIZED) { if (b_initialized) { if (::has_colors()) { ::start_color(); @@ -332,12 +381,12 @@ NCursesWindow::useColors(void) } short -NCursesWindow::getcolor(int getback) const +NCursesWindow::getcolor(int getback) const { short fore, back; if (colorInitialized==COLORS_ARE_REALLY_THERE) { - if (pair_content(PAIR_NUMBER(w->_attrs), &fore, &back)) + if (::pair_content((short)PAIR_NUMBER(w->_attrs), &fore, &back)) err_handler("Can't get color pair"); } else { @@ -357,7 +406,7 @@ int NCursesWindow::NumberOfColors() } short -NCursesWindow::getcolor() const +NCursesWindow::getcolor() const { if (colorInitialized==COLORS_ARE_REALLY_THERE) return PAIR_NUMBER(w->_attrs); @@ -369,7 +418,7 @@ int NCursesWindow::setpalette(short fore, short back, short pair) { if (colorInitialized==COLORS_ARE_REALLY_THERE) - return init_pair(pair, fore, back); + return ::init_pair(pair, fore, back); else return OK; } @@ -378,7 +427,7 @@ int NCursesWindow::setpalette(short fore, short back) { if (colorInitialized==COLORS_ARE_REALLY_THERE) - return setpalette(fore, back, PAIR_NUMBER(w->_attrs)); + return setpalette(fore, back, (short)PAIR_NUMBER(w->_attrs)); else return OK; } @@ -390,25 +439,18 @@ NCursesWindow::setcolor(short pair) if (colorInitialized==COLORS_ARE_REALLY_THERE) { if ((pair < 1) || (pair > COLOR_PAIRS)) err_handler("Can't set color pair"); - + attroff(A_COLOR); attrset(COLOR_PAIR(pair)); } return OK; } +#if HAVE_HAS_KEY extern "C" int _nc_has_mouse(void); bool NCursesWindow::has_mouse() const { - return ((::has_key(KEY_MOUSE) || ::_nc_has_mouse()) + return ((::has_key(KEY_MOUSE) || ::_nc_has_mouse()) ? TRUE : FALSE); } - -NCursesPad::NCursesPad(int lines, int cols) : NCursesWindow() { - w = ::newpad(lines,cols); - if (w==(WINDOW*)0) { - count--; - err_handler("Cannot construct window"); - } - alloced = TRUE; -} +#endif