158189Selan // This may look like C code, but it is really -*- C++ -*-
258189Selan 
358189Selan /*
458189Selan Copyright (C) 1989 Free Software Foundation
558189Selan     written by Eric Newton (newton@rocky.oswego.edu)
658189Selan 
758189Selan This file is part of the GNU C++ Library.  This library is free
858189Selan software; you can redistribute it and/or modify it under the terms of
958189Selan the GNU Library General Public License as published by the Free
1058189Selan Software Foundation; either version 2 of the License, or (at your
1158189Selan option) any later version.  This library is distributed in the hope
1258189Selan that it will be useful, but WITHOUT ANY WARRANTY; without even the
1358189Selan implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
1458189Selan PURPOSE.  See the GNU Library General Public License for more details.
1558189Selan You should have received a copy of the GNU Library General Public
1658189Selan License along with this library; if not, write to the Free Software
1758189Selan Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
1858189Selan */
1958189Selan 
2058189Selan #ifndef _CursesWindow_h
2158189Selan #ifdef __GNUG__
2258189Selan #pragma interface
2358189Selan #endif
2458189Selan #define _CursesWindow_h
2558189Selan 
2658189Selan #include   <curses.h>
2758189Selan 
2858189Selan #if _G_HAVE_CURSES
2958189Selan 
3058189Selan // "Convert" macros to inlines, if needed.
3158189Selan #ifdef addch
3258189Selan inline int (addch)(char ch)  { return addch(ch); }
3358189Selan #undef addch
3458189Selan #endif
3558189Selan #ifdef addstr
3658189Selan /* The (char*) cast is to hack around missing const's */
3758189Selan inline int (addstr)(const char * str)  { return addstr((char*)str); }
3858189Selan #undef addstr
3958189Selan #endif
4058189Selan #ifdef clear
4158189Selan inline int (clear)()  { return clear(); }
4258189Selan #undef clear
4358189Selan #endif
4458189Selan #ifdef clearok
4558189Selan inline int (clearok)(WINDOW* win, int bf)  { return clearok(win, bf); }
4658189Selan #undef clearok
4758189Selan #else
4858189Selan extern "C" int clearok(WINDOW*, int);
4958189Selan #endif
5058189Selan #ifdef clrtobot
5158189Selan inline int (clrtobot)()  { return clrtobot(); }
5258189Selan #undef clrtobot
5358189Selan #endif
5458189Selan #ifdef clrtoeol
5558189Selan inline int (clrtoeol)()  { return clrtoeol(); }
5658189Selan #undef clrtoeol
5758189Selan #endif
5858189Selan #ifdef delch
5958189Selan inline int (delch)()  { return delch(); }
6058189Selan #undef delch
6158189Selan #endif
6258189Selan #ifdef deleteln
6358189Selan inline int (deleteln)()  { return deleteln(); }
6458189Selan #undef deleteln
6558189Selan #endif
6658189Selan #ifdef erase
6758189Selan inline int (erase)()  { return erase(); }
6858189Selan #undef erase
6958189Selan #endif
7058189Selan #ifdef flushok
7158189Selan inline int (flushok)(WINDOW* _win, int _bf)  { return flushok(_win, _bf); }
7258189Selan #undef flushok
7358189Selan #else
7458189Selan #define _no_flushok
7558189Selan #endif
7658189Selan #ifdef getch
7758189Selan inline int (getch)()  { return getch(); }
7858189Selan #undef getch
7958189Selan #endif
8058189Selan #ifdef getstr
8158189Selan inline int (getstr)(char *_str)  { return getstr(_str); }
8258189Selan #undef getstr
8358189Selan #endif
8458189Selan #ifdef getyx
8558189Selan inline void (getyx)(WINDOW* win, int& y, int& x) { getyx(win, y, x); }
8658189Selan #undef getyx
8758189Selan #endif
8858189Selan #ifdef inch
8958189Selan inline int (inch)()  { return inch(); }
9058189Selan #undef inch
9158189Selan #endif
9258189Selan #ifdef insch
9358189Selan inline int (insch)(char c)  { return insch(c); }
9458189Selan #undef insch
9558189Selan #endif
9658189Selan #ifdef insertln
9758189Selan inline int (insertln)()  { return insertln(); }
9858189Selan #undef insertln
9958189Selan #endif
10058189Selan #ifdef leaveok
10158189Selan inline int (leaveok)(WINDOW* win, int bf)  { return leaveok(win, bf); }
10258189Selan #undef leaveok
10358189Selan #else
10458189Selan extern "C" int leaveok(WINDOW* win, int bf);
10558189Selan #endif
10658189Selan #ifdef move
10758189Selan inline int (move)(int x, int y)  { return move(x, y); }
10858189Selan #undef move
10958189Selan #endif
11058189Selan #ifdef refresh
11158189Selan inline int (rfresh)()  { return refresh(); }
11258189Selan #undef refresh
11358189Selan #endif
11458189Selan #ifdef scrollok
11558189Selan inline int (scrollok)(WINDOW* win, int bf)  { return scrollok(win, bf); }
11658189Selan #undef scrollok
11758189Selan #else
11858189Selan #ifndef hpux
11958189Selan extern "C" int scrollok(WINDOW*, int);
12058189Selan #else
12158189Selan extern "C" int scrollok(WINDOW*, char);
12258189Selan #endif
12358189Selan #endif
12458189Selan #ifdef standend
125*60385Selan inline char * (standend)()  { return standend(); }
12658189Selan #undef standend
12758189Selan #endif
12858189Selan #ifdef standout
129*60385Selan inline char * (standout)()  { return standout(); }
13058189Selan #undef standout
13158189Selan #endif
13258189Selan #ifdef winch
13358189Selan inline int (winch)(WINDOW* win) { return winch(win); }
13458189Selan #undef winch
13558189Selan #endif
13658189Selan 
13758189Selan #ifdef mvwaddch
13858189Selan inline int (mvwaddch)(WINDOW *win, int y, int x, char ch)
13958189Selan { return mvwaddch(win, y, x, ch); }
14058189Selan #undef mvwaddch
14158189Selan #endif
14258189Selan #ifdef mvwaddstr
14358189Selan inline int (mvwaddstr)(WINDOW *win, int y, int x, const char * str)
14458189Selan { return mvwaddstr(win, y, x, (char*)str); }
14558189Selan #undef mvwaddstr
14658189Selan #endif
14758189Selan #ifdef mvwdelch
14858189Selan inline int (mvwdelch)(WINDOW *win, int y, int x) { return mvwdelch(win, y, x);}
14958189Selan #undef mvwdelch
15058189Selan #endif
15158189Selan #ifdef mvwgetch
15258189Selan inline int (mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
15358189Selan #undef mvwgetch
15458189Selan #endif
15558189Selan #ifdef mvwgetstr
15658189Selan inline int (mvwgetstr)(WINDOW *win, int y, int x, char *str)
15758189Selan {return mvwgetstr(win,y,x, str);}
15858189Selan #undef mvwgetstr
15958189Selan #endif
16058189Selan #ifdef mvwinch
16158189Selan inline int (mvwinch)(WINDOW *win, int y, int x) { return mvwinch(win, y, x);}
16258189Selan #undef mvwinch
16358189Selan #endif
16458189Selan #ifdef mvwinsch
16558189Selan inline int (mvwinsch)(WINDOW *win, int y, int x, char c)
16658189Selan { return mvwinsch(win, y, x, c); }
16758189Selan #undef mvwinsch
16858189Selan #endif
16958189Selan 
17058189Selan #ifdef mvaddch
17158189Selan inline int (mvaddch)(int y, int x, char ch)
17258189Selan { return mvaddch(y, x, ch); }
17358189Selan #undef mvaddch
17458189Selan #endif
17558189Selan #ifdef mvaddstr
17658189Selan inline int (mvaddstr)(int y, int x, const char * str)
17758189Selan { return mvaddstr(y, x, (char*)str); }
17858189Selan #undef mvaddstr
17958189Selan #endif
18058189Selan #ifdef mvdelch
18158189Selan inline int (mvdelch)(int y, int x) { return mvdelch(y, x);}
18258189Selan #undef mvdelch
18358189Selan #endif
18458189Selan #ifdef mvgetch
18558189Selan inline int (mvgetch)(int y, int x) { return mvgetch(y, x);}
18658189Selan #undef mvgetch
18758189Selan #endif
18858189Selan #ifdef mvgetstr
18958189Selan inline int (mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
19058189Selan #undef mvgetstr
19158189Selan #endif
19258189Selan #ifdef mvinch
19358189Selan inline int (mvinch)(int y, int x) { return mvinch(y, x);}
19458189Selan #undef mvinch
19558189Selan #endif
19658189Selan #ifdef mvinsch
19758189Selan inline int (mvinsch)(int y, int x, char c)
19858189Selan { return mvinsch(y, x, c); }
19958189Selan #undef mvinsch
20058189Selan #endif
20158189Selan 
20258189Selan /*
20358189Selan  *
20458189Selan  * C++ class for windows.
20558189Selan  *
20658189Selan  *
20758189Selan  */
20858189Selan 
20958189Selan class CursesWindow
21058189Selan {
21158189Selan protected:
21258189Selan   static int     count;           // count of all active windows:
21358189Selan                                   //   We rely on the c++ promise that
21458189Selan                                   //   all otherwise uninitialized
21558189Selan                                   //   static class vars are set to 0
21658189Selan 
21758189Selan   WINDOW *       w;               // the curses WINDOW
21858189Selan 
21958189Selan   int            alloced;         // true if we own the WINDOW
22058189Selan 
22158189Selan   CursesWindow*  par;             // parent, if subwindow
22258189Selan   CursesWindow*  subwins;         // head of subwindows list
22358189Selan   CursesWindow*  sib;             // next subwindow of parent
22458189Selan 
22558189Selan   void           kill_subwindows(); // disable all subwindows
22658189Selan 
22758189Selan public:
22858189Selan                  CursesWindow(WINDOW* &window);   // useful only for stdscr
22958189Selan 
23058189Selan                  CursesWindow(int lines,          // number of lines
23158189Selan                               int cols,           // number of columns
23258189Selan                               int begin_y,        // line origin
23358189Selan                               int begin_x);       // col origin
23458189Selan 
23558189Selan                  CursesWindow(CursesWindow& par,  // parent window
23658189Selan                               int lines,          // number of lines
23758189Selan                               int cols,           // number of columns
23858189Selan                               int by,             // absolute or relative
23958189Selan                               int bx,             //   origins:
24058189Selan                               char absrel = 'a'); // if `a', by & bx are
24158189Selan                                                   // absolute screen pos,
24258189Selan                                                   // else if `r', they are
24358189Selan                                                   // relative to par origin
24458189Selan                 ~CursesWindow();
24558189Selan 
24658189Selan // terminal status
24758189Selan   int            lines(); // number of lines on terminal, *not* window
24858189Selan   int            cols();  // number of cols  on terminal, *not* window
24958189Selan 
25058189Selan // window status
25158189Selan   int            height(); // number of lines in this window
25258189Selan   int            width();  // number of cols in this window
25358189Selan   int            begx();   // smallest x coord in window
25458189Selan   int            begy();   // smallest y coord in window
25558189Selan   int            maxx();   // largest  x coord in window
25658189Selan   int            maxy();   // largest  x coord in window
25758189Selan 
25858189Selan // window positioning
25958189Selan   int            move(int y, int x);
26058189Selan 
26158189Selan // coordinate positioning
26258189Selan   void           getyx(int& y, int& x);
26358189Selan   int            mvcur(int sy, int ey, int sx, int ex);
26458189Selan 
26558189Selan // input
26658189Selan   int            getch();
26758189Selan   int            getstr(char * str);
26858189Selan   int            scanw(const char *, ...);
26958189Selan 
27058189Selan // input + positioning
27158189Selan   int            mvgetch(int y, int x);
27258189Selan   int            mvgetstr(int y, int x, char * str);
27358189Selan   int            mvscanw(int, int, const char*, ...);
27458189Selan 
27558189Selan // output
27658189Selan   int            addch(const char ch);
27758189Selan   int            addstr(const char * str);
27858189Selan   int            printw(const char * fmt, ...);
27958189Selan   int            inch();
28058189Selan   int            insch(char c);
28158189Selan   int            insertln();
28258189Selan 
28358189Selan // output + positioning
28458189Selan   int            mvaddch(int y, int x, char ch);
28558189Selan   int            mvaddstr(int y, int x, const char * str);
28658189Selan   int            mvprintw(int y, int x, const char * fmt, ...);
28758189Selan   int            mvinch(int y, int x);
28858189Selan   int            mvinsch(int y, int x, char ch);
28958189Selan 
29058189Selan // borders
29158189Selan   int            box(char vert, char  hor);
29258189Selan 
29358189Selan // erasure
29458189Selan   int            erase();
29558189Selan   int            clear();
29658189Selan   int            clearok(int bf);
29758189Selan   int            clrtobot();
29858189Selan   int            clrtoeol();
29958189Selan   int            delch();
30058189Selan   int            mvdelch(int y, int x);
30158189Selan   int            deleteln();
30258189Selan 
30358189Selan // screen control
30458189Selan   int            scroll();
30558189Selan   int            scrollok(int bf);
30658189Selan   int            touchwin();
30758189Selan   int            refresh();
30858189Selan   int            leaveok(int bf);
30958189Selan #ifndef _no_flushok
31058189Selan   int            flushok(int bf);
31158189Selan #endif
312*60385Selan   char*            standout();
313*60385Selan   char*            standend();
31458189Selan 
31558189Selan // multiple window control
31658189Selan   int            overlay(CursesWindow &win);
31758189Selan   int            overwrite(CursesWindow &win);
31858189Selan 
31958189Selan 
32058189Selan // traversal support
32158189Selan   CursesWindow*  child();
32258189Selan   CursesWindow*  sibling();
32358189Selan   CursesWindow*  parent();
32458189Selan };
32558189Selan 
32658189Selan 
begx()32758189Selan inline int CursesWindow::begx()
32858189Selan {
329*60385Selan   return w->begx;
33058189Selan }
33158189Selan 
begy()33258189Selan inline int CursesWindow::begy()
33358189Selan {
334*60385Selan   return w->begy;
33558189Selan }
33658189Selan 
maxx()33758189Selan inline int CursesWindow::maxx()
33858189Selan {
339*60385Selan   return w->maxx;
34058189Selan }
34158189Selan 
maxy()34258189Selan inline int CursesWindow::maxy()
34358189Selan {
344*60385Selan   return w->maxy;
34558189Selan }
34658189Selan 
height()34758189Selan inline int CursesWindow::height()
34858189Selan {
34958189Selan   return maxy() - begy() + 1;
35058189Selan }
35158189Selan 
width()35258189Selan inline int CursesWindow::width()
35358189Selan {
35458189Selan   return maxx() - begx() + 1;
35558189Selan }
35658189Selan 
box(char vert,char hor)35758189Selan inline int CursesWindow::box(char vert, char  hor)
35858189Selan {
35958189Selan   return ::box(w, vert, hor);
36058189Selan }
36158189Selan 
overlay(CursesWindow & win)36258189Selan inline int CursesWindow::overlay(CursesWindow &win)
36358189Selan {
36458189Selan   return ::overlay(w, win.w);
36558189Selan }
36658189Selan 
overwrite(CursesWindow & win)36758189Selan inline int CursesWindow::overwrite(CursesWindow &win)
36858189Selan {
36958189Selan   return ::overwrite(w, win.w);
37058189Selan }
37158189Selan 
scroll()37258189Selan inline int CursesWindow::scroll()
37358189Selan {
37458189Selan   return ::scroll(w);
37558189Selan }
37658189Selan 
37758189Selan 
touchwin()37858189Selan inline int CursesWindow::touchwin()
37958189Selan {
38058189Selan   return ::touchwin(w);
38158189Selan }
38258189Selan 
addch(const char ch)38358189Selan inline int CursesWindow::addch(const char ch)
38458189Selan {
38558189Selan   return ::waddch(w, ch);
38658189Selan }
38758189Selan 
addstr(const char * str)38858189Selan inline int CursesWindow::addstr(const char * str)
38958189Selan {
39058189Selan   // The (char*) cast is to hack around prototypes in curses.h that
39158189Selan   // have const missing in the parameter lists.  [E.g. SVR4]
39258189Selan   return ::waddstr(w, (char*)str);
39358189Selan }
39458189Selan 
clear()39558189Selan inline int CursesWindow::clear()
39658189Selan {
39758189Selan   return ::wclear(w);
39858189Selan }
39958189Selan 
clrtobot()40058189Selan inline int CursesWindow::clrtobot()
40158189Selan {
40258189Selan   return ::wclrtobot(w);
40358189Selan }
40458189Selan 
clrtoeol()40558189Selan inline int CursesWindow::clrtoeol()
40658189Selan {
40758189Selan   return ::wclrtoeol(w);
40858189Selan }
40958189Selan 
delch()41058189Selan inline int CursesWindow::delch()
41158189Selan {
41258189Selan   return ::wdelch(w);
41358189Selan }
41458189Selan 
deleteln()41558189Selan inline int CursesWindow::deleteln()
41658189Selan {
41758189Selan   return ::wdeleteln(w);
41858189Selan }
41958189Selan 
erase()42058189Selan inline int CursesWindow::erase()
42158189Selan {
42258189Selan   return ::werase(w);
42358189Selan }
42458189Selan 
getch()42558189Selan inline int CursesWindow::getch()
42658189Selan {
42758189Selan   return ::wgetch(w);
42858189Selan }
42958189Selan 
getstr(char * str)43058189Selan inline int CursesWindow::getstr(char * str)
43158189Selan {
43258189Selan   return ::wgetstr(w, str);
43358189Selan }
43458189Selan 
inch()43558189Selan inline int CursesWindow::inch()
43658189Selan {
43758189Selan   return winch(w);
43858189Selan }
43958189Selan 
insch(char c)44058189Selan inline int CursesWindow::insch(char c)
44158189Selan {
44258189Selan   return ::winsch(w, c);
44358189Selan }
44458189Selan 
insertln()44558189Selan inline int CursesWindow::insertln()
44658189Selan {
44758189Selan   return ::winsertln(w);
44858189Selan }
44958189Selan 
move(int y,int x)45058189Selan inline int CursesWindow::move(int y, int x)
45158189Selan {
45258189Selan   return ::wmove(w, y, x);
45358189Selan }
45458189Selan 
45558189Selan 
mvcur(int sy,int ey,int sx,int ex)45658189Selan inline int CursesWindow::mvcur(int sy, int ey, int sx, int ex)
45758189Selan {
45858189Selan   return ::mvcur(sy, ey, sx,ex);
45958189Selan }
46058189Selan 
mvaddch(int y,int x,char ch)46158189Selan inline int CursesWindow::mvaddch(int y, int x, char ch)
46258189Selan {
46358189Selan   return (::wmove(w, y, x)==ERR) ? ERR : ::waddch(w, ch);
46458189Selan }
46558189Selan 
mvgetch(int y,int x)46658189Selan inline int CursesWindow::mvgetch(int y, int x)
46758189Selan {
46858189Selan   return (::wmove(w, y, x)==ERR) ? ERR : ::wgetch(w);
46958189Selan }
47058189Selan 
mvaddstr(int y,int x,const char * str)47158189Selan inline int CursesWindow::mvaddstr(int y, int x, const char * str)
47258189Selan {
47358189Selan   return (::wmove(w, y, x)==ERR) ? ERR : ::waddstr(w, (char*)str);
47458189Selan }
47558189Selan 
mvgetstr(int y,int x,char * str)47658189Selan inline int CursesWindow::mvgetstr(int y, int x, char * str)
47758189Selan {
47858189Selan   return (::wmove(w, y, x)==ERR) ? ERR : ::wgetstr(w, str);
47958189Selan }
48058189Selan 
mvinch(int y,int x)48158189Selan inline int CursesWindow::mvinch(int y, int x)
48258189Selan {
48358189Selan   return (::wmove(w, y, x)==ERR) ? ERR : ::winch(w);
48458189Selan }
48558189Selan 
mvdelch(int y,int x)48658189Selan inline int CursesWindow::mvdelch(int y, int x)
48758189Selan {
48858189Selan   return (::wmove(w, y, x)==ERR) ? ERR : ::wdelch(w);
48958189Selan }
49058189Selan 
mvinsch(int y,int x,char ch)49158189Selan inline int CursesWindow::mvinsch(int y, int x, char ch)
49258189Selan {
49358189Selan   return (::wmove(w, y, x)==ERR) ? ERR : ::winsch(w, ch);
49458189Selan }
49558189Selan 
refresh()49658189Selan inline int CursesWindow::refresh()
49758189Selan {
49858189Selan   return ::wrefresh(w);
49958189Selan }
50058189Selan 
clearok(int bf)50158189Selan inline int CursesWindow::clearok(int bf)
50258189Selan {
50358189Selan   return ::clearok(w,bf);
50458189Selan }
50558189Selan 
leaveok(int bf)50658189Selan inline int CursesWindow::leaveok(int bf)
50758189Selan {
50858189Selan   return ::leaveok(w,bf);
50958189Selan }
51058189Selan 
scrollok(int bf)51158189Selan inline int CursesWindow::scrollok(int bf)
51258189Selan {
51358189Selan   return ::scrollok(w,bf);
51458189Selan }
51558189Selan 
51658189Selan #ifndef _no_flushok
flushok(int bf)51758189Selan inline int CursesWindow::flushok(int bf)
51858189Selan {
51958189Selan   return ::flushok(w, bf);
52058189Selan }
52158189Selan #endif
52258189Selan 
getyx(int & y,int & x)52358189Selan inline void CursesWindow::getyx(int& y, int& x)
52458189Selan {
52558189Selan   ::getyx(w, y, x);
52658189Selan }
52758189Selan 
standout()528*60385Selan inline char *CursesWindow::standout()
52958189Selan {
53058189Selan   return ::wstandout(w);
53158189Selan }
53258189Selan 
standend()533*60385Selan inline char *CursesWindow::standend()
53458189Selan {
53558189Selan   return ::wstandend(w);
53658189Selan }
53758189Selan 
lines()53858189Selan inline int CursesWindow::lines()
53958189Selan {
54058189Selan   return LINES;
54158189Selan }
54258189Selan 
cols()54358189Selan inline int CursesWindow::cols()
54458189Selan {
54558189Selan   return COLS;
54658189Selan }
54758189Selan 
child()54858189Selan inline CursesWindow* CursesWindow::child()
54958189Selan {
55058189Selan   return subwins;
55158189Selan }
55258189Selan 
parent()55358189Selan inline CursesWindow* CursesWindow::parent()
55458189Selan {
55558189Selan   return par;
55658189Selan }
55758189Selan 
sibling()55858189Selan inline CursesWindow* CursesWindow::sibling()
55958189Selan {
56058189Selan   return sib;
56158189Selan }
56258189Selan 
56358189Selan #endif /* _G_HAVE_CURSES */
564*60385Selan 
56558189Selan #endif
566