home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / libg++-2.6-fsf.lha / libg++-2.6 / libg++ / src / CursesW.h < prev    next >
C/C++ Source or Header  |  1994-03-14  |  14KB  |  591 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. #include   <curses.h>
  29.  
  30. /* SCO 3.2v4 curses.h includes term.h, which defines lines as a macro.
  31.    Undefine it here, because CursesWindow uses lines as a method.  */
  32. #undef lines
  33.  
  34. // "Convert" macros to inlines, if needed.
  35. #ifdef addch
  36. inline int (addch)(char ch)  { return addch(ch); }
  37. #undef addch
  38. #endif
  39. #ifdef addstr
  40. /* The (char*) cast is to hack around missing const's */
  41. inline int (addstr)(const char * str)  { return addstr((char*)str); }
  42. #undef addstr
  43. #endif
  44. #ifdef clear
  45. inline int (clear)()  { return clear(); }
  46. #undef clear
  47. #endif
  48. #ifdef clearok
  49. inline int (clearok)(WINDOW* win, int bf)  { return clearok(win, bf); }
  50. #undef clearok
  51. #else
  52. extern "C" int clearok(WINDOW*, int);
  53. #endif
  54. #ifdef clrtobot
  55. inline int (clrtobot)()  { return clrtobot(); }
  56. #undef clrtobot
  57. #endif
  58. #ifdef clrtoeol
  59. inline int (clrtoeol)()  { return clrtoeol(); }
  60. #undef clrtoeol
  61. #endif
  62. #ifdef delch
  63. inline int (delch)()  { return delch(); }
  64. #undef delch
  65. #endif
  66. #ifdef deleteln
  67. inline int (deleteln)()  { return deleteln(); }
  68. #undef deleteln
  69. #endif
  70. #ifdef erase
  71. inline int (erase)()  { return erase(); }
  72. #undef erase
  73. #endif
  74. #ifdef flushok
  75. inline int (flushok)(WINDOW* _win, int _bf)  { return flushok(_win, _bf); }
  76. #undef flushok
  77. #else
  78. #define _no_flushok
  79. #endif
  80. #ifdef getch
  81. inline int (getch)()  { return getch(); }
  82. #undef getch
  83. #endif
  84. #ifdef getstr
  85. inline int (getstr)(char *_str)  { return getstr(_str); }
  86. #undef getstr
  87. #endif
  88. #ifdef getyx
  89. inline void (getyx)(WINDOW* win, int& y, int& x) { getyx(win, y, x); }
  90. #undef getyx
  91. #endif
  92. #ifdef inch
  93. inline int (inch)()  { return inch(); }
  94. #undef inch
  95. #endif
  96. #ifdef insch
  97. inline int (insch)(char c)  { return insch(c); }
  98. #undef insch
  99. #endif
  100. #ifdef insertln
  101. inline int (insertln)()  { return insertln(); }
  102. #undef insertln
  103. #endif
  104. #ifdef leaveok
  105. inline int (leaveok)(WINDOW* win, int bf)  { return leaveok(win, bf); }
  106. #undef leaveok
  107. #else
  108. extern "C" int leaveok(WINDOW* win, int bf);
  109. #endif
  110. #ifdef move
  111. inline int (move)(int x, int y)  { return move(x, y); }
  112. #undef move
  113. #endif
  114. #ifdef refresh
  115. inline int (rfresh)()  { return refresh(); }
  116. #undef refresh
  117. #endif
  118. #ifdef scrollok
  119. inline int (scrollok)(WINDOW* win, int bf)  { return scrollok(win, bf); }
  120. #undef scrollok
  121. #else
  122. #ifndef hpux
  123. extern "C" int scrollok(WINDOW*, int);
  124. #else
  125. extern "C" int scrollok(WINDOW*, char);
  126. #endif
  127. #endif
  128. #ifdef standend
  129. inline int (standend)()  { return standend(); }
  130. #undef standend
  131. #endif
  132. #ifdef standout
  133. inline int (standout)()  { return standout(); }
  134. #undef standout
  135. #endif
  136. #ifdef wstandend
  137. inline int (wstandend)(WINDOW *win)  { return wstandend(win); }
  138. #undef wstandend
  139. #endif
  140. #ifdef wstandout
  141. inline int (wstandout)(WINDOW *win)  { return wstandout(win); }
  142. #undef wstandout
  143. #endif
  144. #ifdef winch
  145. inline int (winch)(WINDOW* win) { return winch(win); }
  146. #undef winch
  147. #endif
  148.  
  149. /* deal with conflicting macros in ncurses.h  which is SYSV based*/
  150. #ifdef box
  151. inline (box)(WINDOW* win, chtype v, chtype h) {return box(win, v, h); }
  152. #undef box
  153. #endif
  154. #ifdef scroll
  155. inline (scroll)(WINDOW* win) { return scroll(win); }
  156. #undef scroll
  157. #endif
  158. #ifdef touchwin
  159. inline (touchwin)(WINDOW* win) { return touchwin(win); }
  160. #undef touchwin
  161. #endif
  162.  
  163. #ifdef mvwaddch
  164. inline int (mvwaddch)(WINDOW *win, int y, int x, char ch)
  165. { return mvwaddch(win, y, x, ch); }
  166. #undef mvwaddch
  167. #endif
  168. #ifdef mvwaddstr
  169. inline int (mvwaddstr)(WINDOW *win, int y, int x, const char * str)
  170. { return mvwaddstr(win, y, x, (char*)str); }
  171. #undef mvwaddstr
  172. #endif
  173. #ifdef mvwdelch
  174. inline int (mvwdelch)(WINDOW *win, int y, int x) { return mvwdelch(win, y, x);}
  175. #undef mvwdelch
  176. #endif
  177. #ifdef mvwgetch
  178. inline int (mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
  179. #undef mvwgetch
  180. #endif
  181. #ifdef mvwgetstr
  182. inline int (mvwgetstr)(WINDOW *win, int y, int x, char *str)
  183. {return mvwgetstr(win,y,x, str);}
  184. #undef mvwgetstr
  185. #endif
  186. #ifdef mvwinch
  187. inline int (mvwinch)(WINDOW *win, int y, int x) { return mvwinch(win, y, x);}
  188. #undef mvwinch
  189. #endif
  190. #ifdef mvwinsch
  191. inline int (mvwinsch)(WINDOW *win, int y, int x, char c)
  192. { return mvwinsch(win, y, x, c); }
  193. #undef mvwinsch
  194. #endif
  195.  
  196. #ifdef mvaddch
  197. inline int (mvaddch)(int y, int x, char ch)
  198. { return mvaddch(y, x, ch); }
  199. #undef mvaddch
  200. #endif
  201. #ifdef mvaddstr
  202. inline int (mvaddstr)(int y, int x, const char * str)
  203. { return mvaddstr(y, x, (char*)str); }
  204. #undef mvaddstr
  205. #endif
  206. #ifdef mvdelch
  207. inline int (mvdelch)(int y, int x) { return mvdelch(y, x);}
  208. #undef mvdelch
  209. #endif
  210. #ifdef mvgetch
  211. inline int (mvgetch)(int y, int x) { return mvgetch(y, x);}
  212. #undef mvgetch
  213. #endif
  214. #ifdef mvgetstr
  215. inline int (mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
  216. #undef mvgetstr
  217. #endif
  218. #ifdef mvinch
  219. inline int (mvinch)(int y, int x) { return mvinch(y, x);}
  220. #undef mvinch
  221. #endif
  222. #ifdef mvinsch
  223. inline int (mvinsch)(int y, int x, char c)
  224. { return mvinsch(y, x, c); }
  225. #undef mvinsch
  226. #endif
  227.  
  228. /*
  229.  *
  230.  * C++ class for windows.
  231.  *
  232.  *
  233.  */
  234.  
  235. class CursesWindow 
  236. {
  237. protected:
  238.   static int     count;           // count of all active windows:
  239.                                   //   We rely on the c++ promise that
  240.                                   //   all otherwise uninitialized
  241.                                   //   static class vars are set to 0
  242.  
  243.   WINDOW *       w;               // the curses WINDOW
  244.  
  245.   int            alloced;         // true if we own the WINDOW
  246.  
  247.   CursesWindow*  par;             // parent, if subwindow
  248.   CursesWindow*  subwins;         // head of subwindows list
  249.   CursesWindow*  sib;             // next subwindow of parent
  250.  
  251.   void           kill_subwindows(); // disable all subwindows
  252.  
  253. public:
  254.                  CursesWindow(WINDOW* &window);   // useful only for stdscr
  255.  
  256.                  CursesWindow(int lines,          // number of lines
  257.                               int cols,           // number of columns
  258.                               int begin_y,        // line origin
  259.                               int begin_x);       // col origin
  260.  
  261.                  CursesWindow(CursesWindow& par,  // parent window
  262.                               int lines,          // number of lines
  263.                               int cols,           // number of columns
  264.                               int by,             // absolute or relative
  265.                               int bx,             //   origins:
  266.                               char absrel = 'a'); // if `a', by & bx are
  267.                                                   // absolute screen pos,
  268.                                                   // else if `r', they are
  269.                                                   // relative to par origin
  270.                 ~CursesWindow();
  271.  
  272. // terminal status
  273.   int            lines(); // number of lines on terminal, *not* window
  274.   int            cols();  // number of cols  on terminal, *not* window
  275.  
  276. // window status
  277.   int            height(); // number of lines in this window
  278.   int            width();  // number of cols in this window
  279.   int            begx();   // smallest x coord in window
  280.   int            begy();   // smallest y coord in window
  281.   int            maxx();   // largest  x coord in window
  282.   int            maxy();   // largest  x coord in window
  283.  
  284. // window positioning
  285.   int            move(int y, int x);
  286.  
  287. // coordinate positioning
  288.   void