home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / lib / g++-include / cursesw.h < prev    next >
C/C++ Source or Header  |  1994-12-22  |  14KB  |  596 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2.  
  3. /* 
  4. Copyright (C) 1989 Free Software Foundation
  5.     written by Eric Newton (newton@rocky.oswego.edu)
  6.  
  7. This file is part of the GNU C++ Library.  This library is free
  8. software; you can redistribute it and/or modify it under the terms of
  9. the GNU Library General Public License as published by the Free
  10. Software Foundation; either version 2 of the License, or (at your
  11. option) any later version.  This library is distributed in the hope
  12. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  13. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  14. PURPOSE.  See the GNU Library General Public License for more details.
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #ifndef _CursesWindow_h
  21. #ifdef __GNUG__
  22. #pragma interface
  23. #endif
  24. #define _CursesWindow_h
  25.  
  26. #include   <_G_config.h>
  27. #if _G_HAVE_CURSES
  28. // Even many system which mostly have C++-ready header files,
  29. // do not have C++-ready curses.h.
  30. extern "C" {
  31. #include   <curses.h>
  32. }
  33.  
  34. /* SCO 3.2v4 curses.h includes term.h, which defines lines as a macro.
  35.    Undefine it here, because CursesWindow uses lines as a method.  */
  36. #undef lines
  37.  
  38. // "Convert" macros to inlines, if needed.
  39. #ifdef addch
  40. inline int (addch)(char ch)  { return addch(ch); }
  41. #undef addch
  42. #endif
  43. #ifdef addstr
  44. /* The (char*) cast is to hack around missing const's */
  45. inline int (addstr)(const char * str)  { return addstr((char*)str); }
  46. #undef addstr
  47. #endif
  48. #ifdef clear
  49. inline int (clear)()  { return clear(); }
  50. #undef clear
  51. #endif
  52. #ifdef clearok
  53. inline int (clearok)(WINDOW* win, int bf)  { return clearok(win, bf); }
  54. #undef clearok
  55. #else
  56. extern "C" int clearok(WINDOW*, int);
  57. #endif
  58. #ifdef clrtobot
  59. inline int (clrtobot)()  { return clrtobot(); }
  60. #undef clrtobot
  61. #endif
  62. #ifdef clrtoeol
  63. inline int (clrtoeol)()  { return clrtoeol(); }
  64. #undef clrtoeol
  65. #endif
  66. #ifdef delch
  67. inline int (delch)()  { return delch(); }
  68. #undef delch
  69. #endif
  70. #ifdef deleteln
  71. inline int (deleteln)()  { return deleteln(); }
  72. #undef deleteln
  73. #endif
  74. #ifdef erase
  75. inline int (erase)()  { return erase(); }
  76. #undef erase
  77. #endif
  78. #ifdef flushok
  79. inline int (flushok)(WINDOW* _win, int _bf)  { return flushok(_win, _bf); }
  80. #undef flushok
  81. #else
  82. #define _no_flushok
  83. #endif
  84. #ifdef getch
  85. inline int (getch)()  { return getch(); }
  86. #undef getch
  87. #endif
  88. #ifdef getstr
  89. inline int (getstr)(char *_str)  { return getstr(_str); }
  90. #undef getstr
  91. #endif
  92. #ifdef getyx
  93. inline void (getyx)(WINDOW* win, int& y, int& x) { getyx(win, y, x); }
  94. #undef getyx
  95. #endif
  96. #ifdef inch
  97. inline int (inch)()  { return inch(); }
  98. #undef inch
  99. #endif
  100. #ifdef insch
  101. inline int (insch)(char c)  { return insch(c); }
  102. #undef insch
  103. #endif
  104. #ifdef insertln
  105. inline int (insertln)()  { return insertln(); }
  106. #undef insertln
  107. #endif
  108. #ifdef leaveok
  109. inline int (leaveok)(WINDOW* win, int bf)  { return leaveok(win, bf); }
  110. #undef leaveok
  111. #else
  112. extern "C" int leaveok(WINDOW* win, int bf);
  113. #endif
  114. #ifdef move
  115. inline int (move)(int x, int y)  { return move(x, y); }
  116. #undef move
  117. #endif
  118. #ifdef refresh
  119. inline int (rfresh)()  { return refresh(); }
  120. #undef refresh
  121. #endif
  122. #ifdef scrollok
  123. inline int (scrollok)(WINDOW* win, int bf)  { return scrollok(win, bf); }
  124. #undef scrollok
  125. #else
  126. #ifndef hpux
  127. extern "C" int scrollok(WINDOW*, int);
  128. #else
  129. extern "C" int scrollok(WINDOW*, char);
  130. #endif
  131. #endif
  132. #ifdef standend
  133. inline int (standend)()  { return (int) standend(); }
  134. #undef standend
  135. #endif
  136. #ifdef standout
  137. inline int (standout)()  { return (int) standout(); }
  138. #undef standout
  139. #endif
  140. #ifdef wstandend
  141. inline int (wstandend)(WINDOW *win)  { return wstandend(win); }
  142. #undef wstandend
  143. #endif
  144. #ifdef wstandout
  145. inline int (wstandout)(WINDOW *win)  { return wstandout(win); }
  146. #undef wstandout
  147. #endif
  148. #ifdef winch
  149. inline int (winch)(WINDOW* win) { return winch(win); }
  150. #undef winch
  151. #endif
  152.  
  153. /* deal with conflicting macros in ncurses.h  which is SYSV based*/
  154. #ifdef box
  155. inline _G_box(WINDOW* win, chtype v, chtype h) {return box(win, v, h); }
  156. #undef box
  157. inline box(WINDOW* win, chtype v, chtype h) {return _G_box(win, v, h); }
  158. #endif
  159. #ifdef scroll
  160. inline (scroll)(WINDOW* win) { return scroll(win); }
  161. #undef scroll
  162. #endif
  163. #ifdef touchwin
  164. inline (touchwin)(WINDOW* win) { return touchwin(win); }
  165. #undef touchwin
  166. #endif
  167.  
  168. #ifdef mvwaddch
  169. inline int (mvwaddch)(WINDOW *win, int y, int x, char ch)
  170. { return mvwaddch(win, y, x, ch); }
  171. #undef mvwaddch
  172. #endif
  173. #ifdef mvwaddstr
  174. inline int (mvwaddstr)(WINDOW *win, int y, int x, const char * str)
  175. { return mvwaddstr(win, y, x, (char*)str); }
  176. #undef mvwaddstr
  177. #endif
  178. #ifdef mvwdelch
  179. inline int (mvwdelch)(WINDOW *win, int y, int x) { return mvwdelch(win, y, x);}
  180. #undef mvwdelch
  181. #endif
  182. #ifdef mvwgetch
  183. inline int (mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
  184. #undef mvwgetch
  185. #endif
  186. #ifdef mvwgetstr
  187. inline int (mvwgetstr)(WINDOW *win, int y, int x, char *str)
  188. {return mvwgetstr(win,y,x, str);}
  189. #undef mvwgetstr
  190. #endif
  191. #ifdef mvwinch
  192. inline int (mvwinch)(WINDOW *win, int y, int x) { return mvwinch(win, y, x);}
  193. #undef mvwinch
  194. #endif
  195. #ifdef mvwinsch
  196. inline int (mvwinsch)(WINDOW *win, int y, int x, char c)
  197. { return mvwinsch(win, y, x, c); }
  198. #undef mvwinsch
  199. #endif
  200.  
  201. #ifdef mvaddch
  202. inline int (mvaddch)(int y, int x, char ch)
  203. { return mvaddch(y, x, ch); }
  204. #undef mvaddch
  205. #endif
  206. #ifdef mvaddstr
  207. inline int (mvaddstr)(int y, int x, const char * str)
  208. { return mvaddstr(y, x, (char*)str); }
  209. #undef mvaddstr
  210. #endif
  211. #ifdef mvdelch
  212. inline int (mvdelch)(int y, int x) { return mvdelch(y, x);}
  213. #undef mvdelch
  214. #endif
  215. #ifdef mvgetch
  216. inline int (mvgetch)(int y, int x) { return mvgetch(y, x);}
  217. #undef mvgetch
  218. #endif
  219. #ifdef mvgetstr
  220. inline int (mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
  221. #undef mvgetstr
  222. #endif
  223. #ifdef mvinch
  224. inline int (mvinch)(int y, int x) { return mvinch(y, x);}
  225. #undef mvinch
  226. #endif
  227. #ifdef mvinsch
  228. inline int (mvinsch)(int y, int x, char c)
  229. { return mvinsch(y, x, c); }
  230. #undef mvinsch
  231. #endif
  232.  
  233. /*
  234.  *
  235.  * C++ class for windows.
  236.  *
  237.  *
  238.  */
  239.  
  240. class CursesWindow 
  241. {
  242. protected:
  243.   static int     count;           // count of all active windows:
  244.                                   //   We rely on the c++ promise that
  245.                                   //   all otherwise uninitialized
  246.                                   //   static class vars are set to 0
  247.  
  248.   WINDOW *       w;               // the curses WINDOW
  249.  
  250.   int            alloced;         // true if we own the WINDOW
  251.  
  252.   CursesWindow*  par;             // parent, if subwindow
  253.   CursesWindow*  subwins;         // head of subwindows list
  254.   CursesWindow*  sib;             // next subwindow of parent
  255.  
  256.   void           kill_subwindows(); // disable all subwindows
  257.  
  258. public:
  259.                  CursesWindow(WINDOW* &window);   // useful only for stdscr
  260.  
  261.                  CursesWindow(int lines,          // number of lines
  262.                               int cols,           // number of columns
  263.                               int begin_y,        // line origin
  264.                               int begin_x);       // col origin
  265.  
  266.                  CursesWindow(CursesWindow& par,  // parent window
  267.                               int lines,          // number of lines
  268.                               int cols,           // number of columns
  269.                               int by,             // absolute or relative
  270.                               int bx,             //   origins:
  271.                               char absrel = 'a'); // if `a', by & bx are
  272.                                                   // absolute screen pos,
  273.                                                   // else if `r', they are
  274.                                                   // relative to par origin
  275.                 ~CursesWindow();
  276.  
  277. // terminal status
  278.   int            lines(); // number of lines on terminal, *not* window
  279.   int            cols();  // number of cols  on terminal, *not* window
  280.  
  281. // window status
  282.   int            height(); // number of lines in this window
  283.   int            width();  // number of cols in this window
  284.   int            begx();   // smallest x coord in window
  285.   int            begy();   // smallest y coord in window
  286.   int