home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / gpincl07.lzh / GPINCL07 / XCURSESW.H < prev    next >
C/C++ Source or Header  |  1993-07-24  |  9KB  |  384 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   <curses.h> 
  27.  
  28. /*
  29.  *
  30.  * C++ class for windows.
  31.  *
  32.  *
  33.  */
  34.  
  35. class CursesWindow 
  36. {
  37. protected:
  38.   static int     count;           // count of all active windows:
  39.                                   //   We rely on the c++ promise that
  40.                                   //   all otherwise uninitialized
  41.                                   //   static class vars are set to 0
  42.  
  43.   WINDOW *       w;               // the curses WINDOW
  44.  
  45.   int            alloced;         // true if we own the WINDOW
  46.  
  47.   CursesWindow*  par;             // parent, if subwindow
  48.   CursesWindow*  subwins;         // head of subwindows list
  49.   CursesWindow*  sib;             // next subwindow of parent
  50.  
  51.   void           kill_subwindows(); // disable all subwindows
  52.  
  53. public:
  54.                  CursesWindow(WINDOW* &window);   // useful only for stdscr
  55.  
  56.                  CursesWindow(int lines,          // number of lines
  57.                               int cols,           // number of columns
  58.                               int begin_y,        // line origin
  59.                               int begin_x);       // col origin
  60.  
  61.                  CursesWindow(CursesWindow& par,  // parent window
  62.                               int lines,          // number of lines
  63.                               int cols,           // number of columns
  64.                               int by,             // absolute or relative
  65.                               int bx,             //   origins:
  66.                               char absrel = 'a'); // if `a', by & bx are
  67.                                                   // absolute screen pos,
  68.                                                   // else if `r', they are
  69.                                                   // relative to par origin
  70.                 ~CursesWindow();
  71.  
  72. // terminal status
  73.   int            lines(); // number of lines on terminal, *not* window
  74.   int            cols();  // number of cols  on terminal, *not* window
  75.  
  76. // window status
  77.   int            height(); // number of lines in this window
  78.   int            width();  // number of cols in this window
  79.   int            begx();   // smallest x coord in window
  80.   int            begy();   // smallest y coord in window
  81.   int            maxx();   // largest  x coord in window
  82.   int            maxy();   // largest  x coord in window
  83.  
  84. // window positioning
  85.   int            move(int y, int x);
  86.  
  87. // coordinate positioning
  88.   void           getyx(int& y, int& x);
  89.   int            mvcur(int sy, int ey, int sx, int ex);
  90.  
  91. // input
  92.   int            getch();
  93.   int            getstr(char * str);
  94.   int            scanw(const char *, ...);
  95.  
  96. // input + positioning
  97.   int            mvgetch(int y, int x);
  98.   int            mvgetstr(int y, int x, char * str);
  99.   int            mvscanw(int, int, const char*, ...);
  100.  
  101. // output
  102.   int            addch(const char ch);
  103.   int            addstr(const char * str);
  104.   int            printw(const char * fmt, ...);
  105.   int            inch();
  106.   int            insch(char c);
  107.   int            insertln();
  108.  
  109. // output + positioning
  110.   int            mvaddch(int y, int x, char ch);
  111.   int            mvaddstr(int y, int x, const char * str);
  112.   int            mvprintw(int y, int x, const char * fmt, ...);
  113.   int            mvinch(int y, int x);
  114.   int            mvinsch(int y, int x, char ch);
  115.  
  116. // borders
  117.   int            box(char vert, char  hor);
  118.  
  119. // erasure
  120.   int            erase();
  121.   int            clear();
  122.   int            clearok(cbool bf);
  123.   int            clrtobot();
  124.   int            clrtoeol();
  125.   int            delch();
  126.   int            mvdelch(int y, int x);
  127.   int            deleteln();
  128.  
  129. // screen control
  130.   int            scroll();
  131.   int            scrollok(cbool bf);
  132.   int            touchwin();
  133.   int            refresh();
  134.   int            leaveok(cbool bf);
  135.   int            flushok(cbool bf);
  136.   int            standout();
  137.   int            standend();
  138.  
  139. // multiple window control
  140.   int            overlay(CursesWindow &win);
  141.   int            overwrite(CursesWindow &win);
  142.  
  143.  
  144. // traversal support
  145.   CursesWindow*  child();
  146.   CursesWindow*  sibling();
  147.   CursesWindow*  parent();
  148. };
  149.  
  150.  
  151. inline int CursesWindow::begx()
  152. {
  153.   return w->_begx;
  154. }
  155.  
  156. inline int CursesWindow::begy()
  157. {
  158.   return w->_begy;
  159. }
  160.  
  161. inline int CursesWindow::maxx()
  162. {
  163.   return w->_maxx;
  164. }
  165.  
  166. inline int CursesWindow::maxy()
  167. {
  168.   return w->_maxy;
  169. }
  170.  
  171. inline int CursesWindow::height()
  172. {
  173.   return maxy() - begy() + 1;
  174. }
  175.  
  176. inline int CursesWindow::width()
  177. {
  178.   return maxx() - begx() + 1;
  179. }
  180.  
  181. inline int CursesWindow::box(char vert, char  hor)    
  182. {
  183.   return ::box(w, vert, hor); 
  184. }
  185.  
  186. inline int CursesWindow::overlay(CursesWindow &win)         
  187. {
  188.   return ::overlay(w, win.w); 
  189. }
  190.  
  191. inline int CursesWindow::overwrite(CursesWindow &win)       
  192. {
  193.   return ::overwrite(w, win.w); 
  194. }
  195.  
  196. inline int CursesWindow::scroll()                     
  197. {
  198.   return ::scroll(w); 
  199. }
  200.  
  201.  
  202. inline int CursesWindow::touchwin()                   
  203. {
  204.   return ::touchwin(w); 
  205. }
  206.  
  207. inline int CursesWindow::addch(const char ch)         
  208. {
  209.   return ::waddch(w, ch); 
  210. }
  211.  
  212. inline int CursesWindow::addstr(const char * str)     
  213. {
  214.   return ::waddstr(w, str); 
  215. }
  216.  
  217. inline int CursesWindow::clear()                      
  218. {
  219.   return ::wclear(w); 
  220. }
  221.  
  222. inline int CursesWindow::clrtobot()                   
  223. {
  224.   return ::wclrtobot(w); 
  225. }
  226.  
  227. inline int CursesWindow::clrtoeol()                   
  228. {
  229.   return ::wclrtoeol(w); 
  230. }
  231.  
  232. inline int CursesWindow::delch()                      
  233. {
  234.   return ::wdelch(w); 
  235. }
  236.  
  237. inline int CursesWindow::deleteln()                   
  238. {
  239.   return ::wdeleteln(w); 
  240. }
  241.  
  242. inline int CursesWindow::erase()                      
  243. {
  244.   return ::werase(w); 
  245. }
  246.  
  247. inline int CursesWindow::getch()                      
  248. {
  249.   return ::wgetch(w); 
  250. }
  251.  
  252. inline int CursesWindow::getstr(char * str)           
  253. {
  254.   return ::wgetstr(w, str); 
  255. }
  256.  
  257. inline int CursesWindow::inch()                       
  258. {
  259.   return winch(w); 
  260. }
  261.  
  262. inline int CursesWindow::insch(char c)               
  263. {
  264.   return ::winsch(w, c); 
  265. }
  266.  
  267. inline int CursesWindow::insertln()                   
  268. {
  269.   return ::winsertln(w); 
  270. }
  271.  
  272. inline int CursesWindow::move(int y, int x)           
  273. {
  274.   return ::wmove(w, y, x); 
  275. }
  276.  
  277.  
  278. inline int CursesWindow::mvcur(int sy, int ey, int sx, int ex)
  279. {
  280.   return ::mvcur(sy, ey, sx,ex);
  281. }
  282.  
  283. inline int CursesWindow::mvaddch(int y, int x, char ch)
  284. {
  285.   return (::wmove(w, y, x)==ERR) ? ERR : ::waddch(w, ch);
  286. }
  287.  
  288. inline int CursesWindow::mvgetch(int y, int x)
  289. {
  290.   return (::wmove(w, y, x)==ERR) ? ERR : ::wgetch(w);
  291. }
  292.  
  293. inline int CursesWindow::mvaddstr(int y, int x, const char * str)
  294. {
  295.   return (::wmove(w, y, x)==ERR) ? ERR : ::waddstr(w, str);
  296. }
  297.  
  298. inline int CursesWindow::mvgetstr(int y, int x, char * str)
  299. {
  300.   return (::wmove(w, y, x)==ERR) ? ERR : ::wgetstr(w, str);
  301. }
  302.  
  303. inline int CursesWindow::mvinch(int y, int x)
  304. {
  305.   return (::wmove(w, y, x)==ERR) ? ERR : ::winch(w);
  306. }
  307.  
  308. inline int CursesWindow::mvdelch(int y, int x)
  309. {
  310.   return (::wmove(w, y, x)==ERR) ? ERR : ::wdelch(w);
  311. }
  312.  
  313. inline int CursesWindow::mvinsch(int y, int x, char ch)
  314. {
  315.   return (::wmove(w, y, x)==ERR) ? ERR : ::winsch(w, ch);
  316. }
  317.  
  318. inline int CursesWindow::refresh()                   
  319. {
  320.   return ::wrefresh(w); 
  321. }
  322.  
  323. inline int CursesWindow::clearok(cbool bf)             
  324. {
  325.   return ::clearok(w,bf); 
  326. }
  327.  
  328. inline int CursesWindow::leaveok(cbool bf)             
  329. {
  330.   return ::leaveok(w,bf); 
  331. }
  332.  
  333. inline int CursesWindow::scrollok(cbool bf)            
  334. {
  335.   return ::scrollok(w,bf); 
  336. }
  337.  
  338. inline int CursesWindow::flushok(cbool bf)            
  339. {
  340.   return ::flushok(w, bf); 
  341. }
  342.  
  343. inline void CursesWindow::getyx(int& y, int& x)       
  344. {
  345.   ::getyx(w, y, x); 
  346. }
  347.  
  348. inline int CursesWindow::standout()                   
  349. {
  350.   return ::wstandout(w); 
  351. }
  352.  
  353. inline int CursesWindow::standend()                   
  354. {
  355.   return ::wstandend(w); 
  356. }
  357.  
  358. inline int CursesWindow::lines()                      
  359. {
  360.   return LINES; 
  361. }
  362.  
  363. inline int CursesWindow::cols()                       
  364. {
  365.   return COLS; 
  366. }
  367.  
  368. inline CursesWindow* CursesWindow::child()
  369. {
  370.   return subwins;
  371. }
  372.  
  373. inline CursesWindow* CursesWindow::parent()
  374. {
  375.   return par;
  376. }
  377.  
  378. inline CursesWindow* CursesWindow::sibling()
  379. {
  380.   return sib;
  381. }
  382.  
  383. #endif
  384.