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