home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / GCC / GERLIB_USR08B.LHA / gerlib / support / g++include / CursesW.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  13.5 KB  |  581 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 wattrset
  145. inline int (wattrset)(WINDOW *win, int att) { return wattrset(win, att); }
  146. #undef wattrset
  147. #endif
  148. #ifdef winch
  149. inline int (winch)(WINDOW* win) { return winch(win); }
  150. #undef winch
  151. #endif
  152.  
  153. #ifdef mvwaddch
  154. inline int (mvwaddch)(WINDOW *win, int y, int x, char ch)
  155. { return mvwaddch(win, y, x, ch); }
  156. #undef mvwaddch
  157. #endif
  158. #ifdef mvwaddstr
  159. inline int (mvwaddstr)(WINDOW *win, int y, int x, const char * str)
  160. { return mvwaddstr(win, y, x, (char*)str); }
  161. #undef mvwaddstr
  162. #endif
  163. #ifdef mvwdelch
  164. inline int (mvwdelch)(WINDOW *win, int y, int x) { return mvwdelch(win, y, x);}
  165. #undef mvwdelch
  166. #endif
  167. #ifdef mvwgetch
  168. inline int (mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
  169. #undef mvwgetch
  170. #endif
  171. #ifdef mvwgetstr
  172. inline int (mvwgetstr)(WINDOW *win, int y, int x, char *str)
  173. {return mvwgetstr(win,y,x, str);}
  174. #undef mvwgetstr
  175. #endif
  176. #ifdef mvwinch
  177. inline int (mvwinch)(WINDOW *win, int y, int x) { return mvwinch(win, y, x);}
  178. #undef mvwinch
  179. #endif
  180. #ifdef mvwinsch
  181. inline int (mvwinsch)(WINDOW *win, int y, int x, char c)
  182. { return mvwinsch(win, y, x, c); }
  183. #undef mvwinsch
  184. #endif
  185.  
  186. #ifdef mvaddch
  187. inline int (mvaddch)(int y, int x, char ch)
  188. { return mvaddch(y, x, ch); }
  189. #undef mvaddch
  190. #endif
  191. #ifdef mvaddstr
  192. inline int (mvaddstr)(int y, int x, const char * str)
  193. { return mvaddstr(y, x, (char*)str); }
  194. #undef mvaddstr
  195. #endif
  196. #ifdef mvdelch
  197. inline int (mvdelch)(int y, int x) { return mvdelch(y, x);}
  198. #undef mvdelch
  199. #endif
  200. #ifdef mvgetch
  201. inline int (mvgetch)(int y, int x) { return mvgetch(y, x);}
  202. #undef mvgetch
  203. #endif
  204. #ifdef mvgetstr
  205. inline int (mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
  206. #undef mvgetstr
  207. #endif
  208. #ifdef mvinch
  209. inline int (mvinch)(int y, int x) { return mvinch(y, x);}
  210. #undef mvinch
  211. #endif
  212. #ifdef mvinsch
  213. inline int (mvinsch)(int y, int x, char c)
  214. { return mvinsch(y, x, c); }
  215. #undef mvinsch
  216. #endif
  217.  
  218. /*
  219.  *
  220.  * C++ class for windows.
  221.  *
  222.  *
  223.  */
  224.  
  225. class CursesWindow 
  226. {
  227. protected:
  228.   static int     count;           // count of all active windows:
  229.                                   //   We rely on the c++ promise that
  230.                                   //   all otherwise uninitialized
  231.                                   //   static class vars are set to 0
  232.  
  233.   WINDOW *       w;               // the curses WINDOW
  234.  
  235.   int            alloced;         // true if we own the WINDOW
  236.  
  237.   CursesWindow*  par;             // parent, if subwindow
  238.   CursesWindow*  subwins;         // head of subwindows list
  239.   CursesWindow*  sib;             // next subwindow of parent
  240.  
  241.   void           kill_subwindows(); // disable all subwindows
  242.  
  243. public:
  244.                  CursesWindow(WINDOW* &window);   // useful only for stdscr
  245.  
  246.                  CursesWindow(int lines,          // number of lines
  247.                               int cols,           // number of columns
  248.                               int begin_y,        // line origin
  249.                               int begin_x);       // col origin
  250.  
  251.                  CursesWindow(CursesWindow& par,  // parent window
  252.                               int lines,          // number of lines
  253.                               int cols,           // number of columns
  254.                               int by,             // absolute or relative
  255.                               int bx,             //   origins:
  256.                               char absrel = 'a'); // if `a', by & bx are
  257.                                                   // absolute screen pos,
  258.                                                   // else if `r', they are
  259.                                                   // relative to par origin
  260.                 ~CursesWindow();
  261.  
  262. // terminal status
  263.   int            lines(); // number of lines on terminal, *not* window
  264.   int            cols();  // number of cols  on terminal, *not* window
  265.  
  266. // window status
  267.   int            height(); // number of lines in this window
  268.   int            width();  // number of cols in this window
  269.   int            begx();   // smallest x coord in window
  270.   int            begy();   // smallest y coord in window
  271.   int            maxx();   // largest  x coord in window
  272.   int            maxy();   // largest  x coord in window
  273.  
  274. // window positioning
  275.   int            move(int y, int x);
  276.  
  277. // coordinate positioning
  278.   void           getyx(int& y, int& x);
  279.   int            mvcur(int sy, int ey, int sx, int ex);
  280.  
  281. // input
  282.   int            getch();
  283.   int            getstr(char * str);
  284.   int            scanw(const char *, ...);
  285.  
  286. // input + positioning
  287.   int            mvgetch(int y, int x);
  288.   int            mvgetstr(int y, int x, char * str);
  289.   int            mvscanw(int, int, const char*, ...);
  290.  
  291. // output
  292.   int            addch(const char ch);
  293.   int            addstr(const char * str);
  294.   int            printw(const char * fmt, ...);
  295.   int            inch();
  296.   int            insch(char c);
  297.   int            insertln();
  298.  
  299. // output + positioning
  300.   int            mvaddch(int y, int x, char ch);
  301.   int            mvaddstr(int y, int x, const char * str);
  302.   int            mvprintw(int y, int x, const char * fmt, ...);
  303.   int            mvinch(int y, int x);
  304.   int            mvinsch(int y, int x, char ch);
  305.  
  306. // borders
  307.   int            box(char vert, char  hor);
  308.  
  309. // erasure
  310.   int            erase();
  311.   int            clear();
  312.   int            clearok(int bf);
  313.   int            clrtobot();
  314.   int            clrtoeol();
  315.   int            delch();
  316.   int            mvdelch(int y, int x);
  317.   int            deleteln();
  318.  
  319. // screen control
  320.   int            scroll();
  321.   int            scrollok(int bf);
  322.   int            touchwin();
  323.   int            refresh();
  324.   int            leaveok(int bf);
  325. #ifndef _no_flushok
  326.   int            flushok(int bf);
  327. #endif
  328.   int            standout();
  329.   int            standend();
  330.  
  331. // multiple window control
  332.   int            overlay(CursesWindow &win);
  333.   int            overwrite(CursesWindow &win);
  334.  
  335.  
  336. // traversal support
  337.   CursesWindow*  child();
  338.   CursesWindow*  sibling();
  339.   CursesWindow*  parent();
  340. };
  341.  
  342.  
  343. inline int CursesWindow::begx()
  344. {
  345.   return w->_begx;
  346. }
  347.  
  348. inline int CursesWindow::begy()
  349. {
  350.   return w->_begy;
  351. }
  352.  
  353. inline int CursesWindow::maxx()
  354. {
  355.   return w->_maxx;
  356. }
  357.  
  358. inline int CursesWindow::maxy()
  359. {
  360.   return w->_maxy;
  361. }
  362.  
  363. inline int CursesWindow::height()
  364. {
  365.   return maxy() - begy() + 1;
  366. }
  367.  
  368. inline int CursesWindow::width()
  369. {
  370.   return maxx() - begx() + 1;
  371. }
  372.  
  373. inline int CursesWindow::box(char vert, char  hor)    
  374. {
  375.   return ::box(w, vert, hor); 
  376. }
  377.  
  378. inline int CursesWindow::overlay(CursesWindow &win)         
  379. {
  380.   return ::overlay(w, win.w); 
  381. }
  382.  
  383. inline int CursesWindow::overwrite(CursesWindow &win)       
  384. {
  385.   return ::overwrite(w, win.w); 
  386. }
  387.  
  388. inline int CursesWindow::scroll()                     
  389. {
  390.   return ::scroll(w); 
  391. }
  392.  
  393.  
  394. inline int CursesWindow::touchwin()                   
  395. {
  396.   return ::touchwin(w); 
  397. }
  398.  
  399. inline int CursesWindow::addch(const char ch)         
  400. {
  401.   return ::waddch(w, ch); 
  402. }
  403.  
  404. inline int CursesWindow::addstr(const char * str)     
  405. {
  406.   // The (char*) cast is to hack around prototypes in curses.h that
  407.   // have const missing in the parameter lists.  [E.g. SVR4]
  408.   return ::waddstr(w, (char*)str); 
  409. }
  410.  
  411. inline int CursesWindow::clear()                      
  412. {
  413.   return ::wclear(w); 
  414. }
  415.  
  416. inline int CursesWindow::clrtobot()                   
  417. {
  418.   return ::wclrtobot(w); 
  419. }
  420.  
  421. inline int CursesWindow::clrtoeol()                   
  422. {
  423.   return ::wclrtoeol(w); 
  424. }
  425.  
  426. inline int CursesWindow::delch()                      
  427. {
  428.   return ::wdelch(w); 
  429. }
  430.  
  431. inline int CursesWindow::deleteln()                   
  432. {
  433.   return ::wdeleteln(w); 
  434. }
  435.  
  436. inline int CursesWindow::erase()                      
  437. {
  438.   return ::werase(w); 
  439. }
  440.  
  441. inline int CursesWindow::getch()                      
  442. {
  443.   return ::wgetch(w); 
  444. }
  445.  
  446. inline int CursesWindow::getstr(char * str)           
  447. {
  448.   return ::wgetstr(w, str); 
  449. }
  450.  
  451. inline int CursesWindow::inch()                       
  452. {
  453.   return winch(w); 
  454. }
  455.  
  456. inline int CursesWindow::insch(char c)               
  457. {
  458.   return ::winsch(w, c); 
  459. }
  460.  
  461. inline int CursesWindow::insertln()                   
  462. {
  463.   return ::winsertln(w); 
  464. }
  465.  
  466. inline int CursesWindow::move(int y, int x)           
  467. {
  468.   return ::wmove(w, y, x); 
  469. }
  470.  
  471.  
  472. inline int CursesWindow::mvcur(int sy, int ey, int sx, int ex)
  473. {
  474.   return ::mvcur(sy, ey, sx,ex);
  475. }
  476.  
  477. inline int CursesWindow::mvaddch(int y, int x, char ch)
  478. {
  479.   return (::wmove(w, y, x)==ERR) ? ERR : ::waddch(w, ch);
  480. }
  481.  
  482. inline int CursesWindow::mvgetch(int y, int x)
  483. {
  484.   return (::wmove(w, y, x)==ERR) ? ERR : ::wgetch(w);
  485. }
  486.  
  487. inline int CursesWindow::mvaddstr(int y, int x, const char * str)
  488. {
  489.   return (::wmove(w, y, x)==ERR) ? ERR : ::waddstr(w, (char*)str);
  490. }
  491.  
  492. inline int CursesWindow::mvgetstr(int y, int x, char * str)
  493. {
  494.   return (::wmove(w, y, x)==ERR) ? ERR : ::wgetstr(w, str);
  495. }
  496.  
  497. inline int CursesWindow::mvinch(int y, int x)
  498. {
  499.   return (::wmove(w, y, x)==ERR) ? ERR : ::winch(w);
  500. }
  501.  
  502. inline int CursesWindow::mvdelch(int y, int x)
  503. {
  504.   return (::wmove(w, y, x)==ERR) ? ERR : ::wdelch(w);
  505. }
  506.  
  507. inline int CursesWindow::mvinsch(int y, int x, char ch)
  508. {
  509.   return (::wmove(w, y, x)==ERR) ? ERR : ::winsch(w, ch);
  510. }
  511.  
  512. inline int CursesWindow::refresh()                   
  513. {
  514.   return ::wrefresh(w); 
  515. }
  516.  
  517. inline int CursesWindow::clearok(int bf)             
  518. {
  519.   return ::clearok(w,bf); 
  520. }
  521.  
  522. inline int CursesWindow::leaveok(int bf)             
  523. {
  524.   return ::leaveok(w,bf); 
  525. }
  526.  
  527. inline int CursesWindow::scrollok(int bf)            
  528. {
  529.   return ::scrollok(w,bf); 
  530. }
  531.  
  532. #ifndef _no_flushok
  533. inline int CursesWindow::flushok(int bf)            
  534. {
  535.   return ::flushok(w, bf); 
  536. }
  537. #endif
  538.  
  539. inline void CursesWindow::getyx(int& y, int& x)       
  540. {
  541.   ::getyx(w, y, x); 
  542. }
  543.  
  544. inline int CursesWindow::standout()                   
  545. {
  546.   return ::wstandout(w); 
  547. }
  548.  
  549. inline int CursesWindow::standend()                   
  550. {
  551.   return ::wstandend(w); 
  552. }
  553.  
  554. inline int CursesWindow::lines()                      
  555. {
  556.   return LINES; 
  557. }
  558.  
  559. inline int CursesWindow::cols()                       
  560. {
  561.   return COLS; 
  562. }
  563.  
  564. inline CursesWindow* CursesWindow::child()
  565. {
  566.   return subwins;
  567. }
  568.  
  569. inline CursesWindow* CursesWindow::parent()
  570. {
  571.   return par;
  572. }
  573.  
  574. inline CursesWindow* CursesWindow::sibling()
  575. {
  576.   return sib;
  577. }
  578.  
  579. #endif /* _G_HAVE_CURSES */
  580. #endif
  581.