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