]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - c++/cursesw.cc
ncurses 5.6 - patch 20070908
[ncurses.git] / c++ / cursesw.cc
index acf9ce94b0ae47a3bc3c7ac37d1499b2eeaab06f..527bb7c40e4c39af6c539b7a3e3b6aaea603b999 100644 (file)
@@ -42,7 +42,7 @@
 #include "internal.h"
 #include "cursesw.h"
 
-MODULE_ID("$Id: cursesw.cc,v 1.46 2007/01/27 22:31:12 tom Exp $")
+MODULE_ID("$Id: cursesw.cc,v 1.48 2007/03/24 19:00:58 tom Exp $")
 
 #define COLORS_NEED_INITIALIZATION  -1
 #define COLORS_NOT_INITIALIZED       0
@@ -165,12 +165,17 @@ NCursesWindow::NCursesWindow(int nlines, int ncols, int begin_y, int begin_x)
     set_keyboard();
 }
 
-NCursesWindow::NCursesWindow(WINDOW* &window)
+NCursesWindow::NCursesWindow(WINDOW* window)
   : w(0), alloced(FALSE), par(0), subwins(0), sib(0)
 {
     constructing();
 
-    w = window;
+    // We used to use a reference on the "window" parameter, but we cannot do
+    // that with an opaque pointer (see NCURSES_OPAQUE).  If the parameter was
+    // "::stdscr", that is first set via the "constructing() call, and is null
+    // up to that point.  So we allow a null pointer here as meaning the "same"
+    // as "::stdscr".
+    w = window ? window : ::stdscr;
     set_keyboard();
 }
 
@@ -355,13 +360,19 @@ NCursesWindow::useColors(void)
     }
 }
 
+short
+NCursesWindow::getPair() const
+{
+    return static_cast<short>(PAIR_NUMBER(getattrs(w)));
+}
+
 short
 NCursesWindow::getcolor(int getback) const
 {
     short fore, back;
 
     if (HaveColors()) {
-       if (::pair_content(static_cast<short>(PAIR_NUMBER(w->_attrs)), &fore, &back) == ERR)
+       if (::pair_content(getPair(), &fore, &back) == ERR)
            err_handler("Can't get color pair");
     } else {
        // Monochrome means white on black
@@ -379,7 +390,7 @@ int NCursesWindow::NumberOfColors()
 short
 NCursesWindow::getcolor() const
 {
-    return (HaveColors()) ? PAIR_NUMBER(w->_attrs) : 0;
+    return (HaveColors()) ? getPair() : 0;
 }
 
 int
@@ -391,7 +402,7 @@ NCursesWindow::setpalette(short fore, short back, short pair)
 int
 NCursesWindow::setpalette(short fore, short back)
 {
-    return setpalette(fore, back, static_cast<short>(PAIR_NUMBER(w->_attrs)));
+    return setpalette(fore, back, getPair());
 }