1 // * This makes emacs happy -*-Mode: C++;-*-
2 /****************************************************************************
3 * Copyright (c) 1998,1999,2000,2001 Free Software Foundation, Inc. *
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: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
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. *
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 *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Juergen Pfeifer, 1997 *
32 * Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en *
33 ****************************************************************************/
35 #ifndef NCURSES_CURSESP_H_incl
36 #define NCURSES_CURSESP_H_incl 1
38 // $Id: cursesp.h,v 1.17 2002/07/06 15:47:52 juergen Exp $
46 class NCURSES_IMPEXP NCursesPanel : public NCursesWindow {
49 static NCursesPanel *dummy;
52 // This structure is used for the panel's user data field to link the
53 // PANEL* to the C++ object and to provide extra space for a user pointer.
55 void* m_user; // the pointer for the user's data
56 const NCursesPanel* m_back; // backward pointer to C++ object
57 const PANEL* m_owner; // the panel itself
60 void init(); // Initialize the panel object
63 void set_user(void *user) {
64 UserHook* uptr = (UserHook*)::panel_userptr (p);
65 assert (uptr != 0 && uptr->m_back==this && uptr->m_owner==p);
68 // Set the user pointer of the panel.
71 UserHook* uptr = (UserHook*)::panel_userptr (p);
72 assert (uptr != 0 && uptr->m_back==this && uptr->m_owner==p);
76 void OnError (int err) const THROWS((NCursesPanelException)) {
78 THROW(new NCursesPanelException (this, err));
80 // If err is equal to the curses error indicator ERR, an error handler
83 // Get a keystroke. Default implementation calls getch()
84 virtual int getKey(void);
87 NCursesPanel(int lines,
91 : NCursesWindow(lines,cols,begin_y,begin_x) {
94 // Create a panel with this size starting at the requested position.
96 NCursesPanel() : NCursesWindow(::stdscr) { init(); }
97 // This constructor creates the default Panel associated with the
100 virtual ~NCursesPanel();
102 // basic manipulation
104 OnError (::hide_panel(p));
106 // Hide the panel. It stays in the stack but becomes invisible.
109 OnError (::show_panel(p));
111 // Show the panel, i.e. make it visible.
114 OnError (::top_panel(p));
116 // Make this panel the top panel in the stack.
118 inline void bottom() {
119 OnError (::bottom_panel(p));
121 // Make this panel the bottom panel in the stack.
122 // N.B.: The panel associated with ::stdscr is always on the bottom. So
123 // actually bottom() makes the panel the first above ::stdscr.
125 virtual int mvwin(int y, int x) {
126 OnError(::move_panel(p, y, x));
130 inline bool hidden() const {
131 return (::panel_hidden (p) ? TRUE : FALSE);
133 // Return TRUE if the panel is hidden, FALSE otherwise.
135 /* The functions panel_above() and panel_below() are not reflected in
136 the NCursesPanel class. The reason for this is, that we cannot
137 assume that a panel retrieved by those operations is one wrapped
138 by a C++ class. Although this situation might be handled, we also
139 need a reverse mapping from PANEL to NCursesPanel which needs some
140 redesign of the low level stuff. At the moment, we define them in the
141 interface but they will always produce an error. */
142 inline NCursesPanel& above() const {
147 inline NCursesPanel& below() const {
152 // Those two are rewrites of the corresponding virtual members of
154 virtual int refresh();
155 // Propagate all panel changes to the virtual screen and update the
158 virtual int noutrefresh();
159 // Propagate all panel changes to the virtual screen.
161 static void redraw();
162 // Redraw all panels.
165 virtual void frame(const char* title=NULL,
166 const char* btitle=NULL);
167 // Put a frame around the panel and put the title centered in the top line
168 // and btitle in the bottom line.
170 virtual void boldframe(const char* title=NULL,
171 const char* btitle=NULL);
172 // Same as frame(), but use highlighted attributes.
174 virtual void label(const char* topLabel,
175 const char* bottomLabel);
176 // Put the title centered in the top line and btitle in the bottom line.
178 virtual void centertext(int row,const char* label);
179 // Put the label text centered in the specified row.
182 /* We use templates to provide a typesafe mechanism to associate
183 * user data with a panel. A NCursesUserPanel<T> is a panel
184 * associated with some user data of type T.
186 template<class T> class NCursesUserPanel : public NCursesPanel
189 NCursesUserPanel (int lines,
193 const T* p_UserData = (T*)0)
194 : NCursesPanel (lines, cols, begin_y, begin_x) {
196 set_user ((void *)p_UserData);
198 // This creates an user panel of the requested size with associated
199 // user data pointed to by p_UserData.
201 NCursesUserPanel(const T* p_UserData = (T*)0) : NCursesPanel() {
203 set_user((void *)p_UserData);
205 // This creates an user panel associated with the ::stdscr and user data
206 // pointed to by p_UserData.
208 virtual ~NCursesUserPanel() {};
210 T* UserData (void) const {
211 return (T*)get_user ();
213 // Retrieve the user data associated with the panel.
215 virtual void setUserData (const T* p_UserData) {
217 set_user ((void *)p_UserData);
219 // Associate the user panel with the user data pointed to by p_UserData.
222 #endif // NCURSES_CURSESP_H_incl