]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - c++/cursesw.cc
ncurses 5.9 - patch 20130928
[ncurses.git] / c++ / cursesw.cc
index acf9ce94b0ae47a3bc3c7ac37d1499b2eeaab06f..adbcf6e71ef053f350051a68c54aa8ccbffc867a 100644 (file)
@@ -1,6 +1,6 @@
 // * this is for making emacs happy: -*-Mode: C++;-*-
 /****************************************************************************
- * Copyright (c) 2007 Free Software Foundation, Inc.                        *
+ * Copyright (c) 2007-2011,2012 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -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.53 2012/12/08 22:06:41 tom Exp $")
 
 #define COLORS_NEED_INITIALIZATION  -1
 #define COLORS_NOT_INITIALIZED       0
@@ -84,6 +84,29 @@ NCursesWindow::scanw(int y, int x, const char* fmt, ...)
 }
 
 
+int
+NCursesWindow::scanw(const char* fmt, va_list args)
+{
+    int result = ERR;
+
+    result = ::vw_scanw (w, const_cast<NCURSES_CONST char *>(fmt), args);
+
+    return result;
+}
+
+
+int
+NCursesWindow::scanw(int y, int x, const char* fmt, va_list args)
+{
+    int result = ERR;
+
+    if (::wmove(w, y, x) != ERR) {
+       result = ::vw_scanw (w, const_cast<NCURSES_CONST char *>(fmt), args);
+    }
+    return result;
+}
+
+
 int
 NCursesWindow::printw(const char * fmt, ...)
 {
@@ -109,6 +132,25 @@ NCursesWindow::printw(int y, int x, const char * fmt, ...)
 }
 
 
+int
+NCursesWindow::printw(const char * fmt, va_list args)
+{
+    int result = ::vw_printw(w, fmt, args);
+    return result;
+}
+
+
+int
+NCursesWindow::printw(int y, int x, const char * fmt, va_list args)
+{
+    int result = ::wmove(w, y, x);
+    if (result == OK) {
+       result = ::vw_printw(w, fmt, args);
+    }
+    return result;
+}
+
+
 void
 NCursesWindow::set_keyboard(void)
 {
@@ -150,7 +192,6 @@ NCursesWindow::NCursesWindow()
     constructing();
 
     w = static_cast<WINDOW *>(0);
-    set_keyboard();
 }
 
 NCursesWindow::NCursesWindow(int nlines, int ncols, int begin_y, int begin_x)
@@ -165,12 +206,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();
 }
 
@@ -238,19 +284,19 @@ static RIPOFFINIT* prip = R_INIT;
 NCursesWindow::NCursesWindow(WINDOW *win, int ncols)
   : w(0), alloced(FALSE), par(0), subwins(0), sib(0)
 {
+    (void) ncols;
     initialize();
     w = win;
-    assert((w->_maxx +1 ) == ncols);
 }
 
 int _nc_xx_ripoff_init(WINDOW *w, int ncols)
 {
+    (void) ncols;
     int res = ERR;
 
     RIPOFFINIT init = *prip++;
     if (init) {
-       NCursesWindow* W = new NCursesWindow(w,ncols);
-       res = init(*W);
+       res = init(*(new NCursesWindow(w,ncols)));
     }
     return res;
 }
@@ -355,13 +401,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 +431,7 @@ int NCursesWindow::NumberOfColors()
 short
 NCursesWindow::getcolor() const
 {
-    return (HaveColors()) ? PAIR_NUMBER(w->_attrs) : 0;
+    return (HaveColors()) ? getPair() : 0;
 }
 
 int
@@ -391,7 +443,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());
 }
 
 
@@ -411,7 +463,7 @@ NCursesWindow::setcolor(short pair)
 #if HAVE_HAS_KEY
 bool NCursesWindow::has_mouse() const
 {
-    return ((::has_key(KEY_MOUSE) || ::_nc_has_mouse())
+    return ((::has_key(KEY_MOUSE) || ::has_mouse())
             ? TRUE : FALSE);
 }
 #endif