]> ncurses.scripts.mit.edu Git - ncurses.git/blob - c++/cursesp.cc
3bcf3d260f365e4120efac4a65d0d03a9e558b5b
[ncurses.git] / c++ / cursesp.cc
1 // * this is for making emacs happy: -*-Mode: C++;-*-
2 /****************************************************************************
3  * Copyright (c) 1998,1999 Free Software Foundation, Inc.                   *
4  *                                                                          *
5  * Permission is hereby granted, free of charge, to any person obtaining a  *
6  * copy of this software and associated documentation files (the            *
7  * "Software"), to deal in the Software without restriction, including      *
8  * without limitation the rights to use, copy, modify, merge, publish,      *
9  * distribute, distribute with modifications, sublicense, and/or sell       *
10  * copies of the Software, and to permit persons to whom the Software is    *
11  * furnished to do so, subject to the following conditions:                 *
12  *                                                                          *
13  * The above copyright notice and this permission notice shall be included  *
14  * in all copies or substantial portions of the Software.                   *
15  *                                                                          *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23  *                                                                          *
24  * Except as contained in this notice, the name(s) of the above copyright   *
25  * holders shall not be used in advertising or otherwise to promote the     *
26  * sale, use or other dealings in this Software without prior written       *
27  * authorization.                                                           *
28  ****************************************************************************/
29
30 /****************************************************************************
31  *   Author: Juergen Pfeifer <juergen.pfeifer@gmx.net> 1993,1997            *
32  ****************************************************************************/
33
34 #include "cursesp.h"
35 #include "internal.h"
36
37 MODULE_ID("$Id: cursesp.cc,v 1.15 1999/10/30 23:59:37 tom Exp $")
38
39 NCursesPanel* NCursesPanel::dummy = (NCursesPanel*)0;
40
41 void NCursesPanel::init() {
42   p = ::new_panel(w);
43   if (!p)
44     OnError(ERR);
45   
46   UserHook* hook = new UserHook;
47   hook->m_user  = NULL;
48   hook->m_back  = this;
49   hook->m_owner = p;
50   ::set_panel_userptr(p, (void *)hook);
51 }  
52
53 NCursesPanel::~NCursesPanel() {
54   UserHook* hook = (UserHook*)::panel_userptr(p);
55   assert(hook != 0 && hook->m_back==this && hook->m_owner==p);
56   delete hook;
57   ::del_panel(p);
58   ::update_panels();
59 }
60
61 void
62 NCursesPanel::redraw() {
63   PANEL *pan;
64   
65   pan = ::panel_above(NULL);
66   while (pan) {
67     ::touchwin(panel_window(pan));
68     pan = ::panel_above(pan);
69   }
70   ::update_panels();
71   ::doupdate();
72 }
73
74 int
75 NCursesPanel::refresh() {
76   ::update_panels();
77   return doupdate();
78 }
79
80 int
81 NCursesPanel::noutrefresh() {
82   ::update_panels();
83   return OK;
84 }
85
86 void
87 NCursesPanel::boldframe(const char *title, const char* btitle) {
88   standout();
89   frame(title, btitle);
90   standend();
91 }
92
93 void
94 NCursesPanel::frame(const char *title,const char *btitle) {
95   int err = OK;
96   if (!title && !btitle) {
97     err = box();
98   } 
99   else {
100     err = box();
101     if (err==OK)
102       label(title,btitle); 
103   }
104   OnError(err);
105 }
106
107 void
108 NCursesPanel::label(const char *tLabel, const char *bLabel) {
109   if (tLabel) 
110     centertext(0,tLabel);
111   if (bLabel) 
112     centertext(maxy(),bLabel);
113 }
114
115 void
116 NCursesPanel::centertext(int row,const char *label) {
117   if (label) {
118     int x = (maxx() - strlen(label)) / 2;
119     if (x<0)
120       x=0;
121     OnError(addstr(row, x, label, width()));
122   }
123 }