1 // * This makes emacs happy -*-Mode: C++;-*-
2 /****************************************************************************
3 * Copyright (c) 1998-2005,2007 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 ****************************************************************************/
34 #ifndef NCURSES_CURSESP_H_incl
35 #define NCURSES_CURSESP_H_incl 1
37 // $Id: cursesp.h,v 1.27 2007/04/07 17:12:54 tom Exp $
45 class NCURSES_IMPEXP NCursesPanel
46 : public NCursesWindow
50 static NCursesPanel *dummy;
53 // This structure is used for the panel's user data field to link the
54 // PANEL* to the C++ object and to provide extra space for a user pointer.
56 void* m_user; // the pointer for the user's data
57 const NCursesPanel* m_back; // backward pointer to C++ object
58 const PANEL* m_owner; // the panel itself
61 inline UserHook *UserPointer()
63 UserHook* uptr = reinterpret_cast<UserHook*>(
64 const_cast<void *>(::panel_userptr (p)));
68 void init(); // Initialize the panel object
71 void set_user(void *user)
73 UserHook* uptr = UserPointer();
74 assert (uptr != 0 && uptr->m_back==this && uptr->m_owner==p);
77 // Set the user pointer of the panel.
81 UserHook* uptr = UserPointer();
82 assert (uptr != 0 && uptr->m_back==this && uptr->m_owner==p);
86 void OnError (int err) const THROWS(NCursesPanelException)
89 THROW(new NCursesPanelException (this, err));
91 // If err is equal to the curses error indicator ERR, an error handler
94 // Get a keystroke. Default implementation calls getch()
95 virtual int getKey(void);
98 NCursesPanel(int nlines,
102 : NCursesWindow(nlines,ncols,begin_y,begin_x), p(0)
106 // Create a panel with this size starting at the requested position.
109 : NCursesWindow(::stdscr), p(0)
113 // This constructor creates the default Panel associated with the
116 NCursesPanel& operator=(const NCursesPanel& rhs)
120 NCursesWindow::operator=(rhs);
125 NCursesPanel(const NCursesPanel& rhs)
126 : NCursesWindow(rhs),
131 virtual ~NCursesPanel();
133 // basic manipulation
136 OnError (::hide_panel(p));
138 // Hide the panel. It stays in the stack but becomes invisible.
142 OnError (::show_panel(p));
144 // Show the panel, i.e. make it visible.
148 OnError (::top_panel(p));
150 // Make this panel the top panel in the stack.
154 OnError (::bottom_panel(p));
156 // Make this panel the bottom panel in the stack.
157 // N.B.: The panel associated with ::stdscr is always on the bottom. So
158 // actually bottom() makes the panel the first above ::stdscr.
160 virtual int mvwin(int y, int x)
162 OnError(::move_panel(p, y, x));
166 inline bool hidden() const
168 return (::panel_hidden (p) ? TRUE : FALSE);
170 // Return TRUE if the panel is hidden, FALSE otherwise.
172 /* The functions panel_above() and panel_below() are not reflected in
173 the NCursesPanel class. The reason for this is, that we cannot
174 assume that a panel retrieved by those operations is one wrapped
175 by a C++ class. Although this situation might be handled, we also
176 need a reverse mapping from PANEL to NCursesPanel which needs some
177 redesign of the low level stuff. At the moment, we define them in the
178 interface but they will always produce an error. */
179 inline NCursesPanel& above() const
185 inline NCursesPanel& below() const
191 // Those two are rewrites of the corresponding virtual members of
193 virtual int refresh();
194 // Propagate all panel changes to the virtual screen and update the
197 virtual int noutrefresh();
198 // Propagate all panel changes to the virtual screen.
200 static void redraw();
201 // Redraw all panels.
204 virtual void frame(const char* title=NULL,
205 const char* btitle=NULL);
206 // Put a frame around the panel and put the title centered in the top line
207 // and btitle in the bottom line.
209 virtual void boldframe(const char* title=NULL,
210 const char* btitle=NULL);
211 // Same as frame(), but use highlighted attributes.
213 virtual void label(const char* topLabel,
214 const char* bottomLabel);
215 // Put the title centered in the top line and btitle in the bottom line.
217 virtual void centertext(int row,const char* label);
218 // Put the label text centered in the specified row.
221 /* We use templates to provide a typesafe mechanism to associate
222 * user data with a panel. A NCursesUserPanel<T> is a panel
223 * associated with some user data of type T.
225 template<class T> class NCursesUserPanel : public NCursesPanel
228 NCursesUserPanel (int nlines,
232 const T* p_UserData = STATIC_CAST(T*)(0))
233 : NCursesPanel (nlines, ncols, begin_y, begin_x)
236 set_user (const_cast<void *>(p_UserData));
238 // This creates an user panel of the requested size with associated
239 // user data pointed to by p_UserData.
241 NCursesUserPanel(const T* p_UserData = STATIC_CAST(T*)(0)) : NCursesPanel()
244 set_user(const_cast<void *>(p_UserData));
246 // This creates an user panel associated with the ::stdscr and user data
247 // pointed to by p_UserData.
249 virtual ~NCursesUserPanel() {};
251 T* UserData (void) const
253 return reinterpret_cast<T*>(get_user ());
255 // Retrieve the user data associated with the panel.
257 virtual void setUserData (const T* p_UserData)
260 set_user (const_cast<void *>(p_UserData));
262 // Associate the user panel with the user data pointed to by p_UserData.
265 #endif /* NCURSES_CURSESP_H_incl */