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