1 // * This makes emacs happy -*-Mode: C++;-*-
2 /****************************************************************************
3 * Copyright (c) 1998-2002,2003 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.18 2003/10/25 15:04:46 tom Exp $
45 class NCURSES_IMPEXP NCursesPanel
: public NCursesWindow
{
48 static NCursesPanel
*dummy
;
51 // This structure is used for the panel's user data field to link the
52 // PANEL* to the C++ object and to provide extra space for a user pointer.
54 void* m_user
; // the pointer for the user's data
55 const NCursesPanel
* m_back
; // backward pointer to C++ object
56 const PANEL
* m_owner
; // the panel itself
59 void init(); // Initialize the panel object
62 void set_user(void *user
) {
63 UserHook
* uptr
= (UserHook
*)::panel_userptr (p
);
64 assert (uptr
!= 0 && uptr
->m_back
==this && uptr
->m_owner
==p
);
67 // Set the user pointer of the panel.
70 UserHook
* uptr
= (UserHook
*)::panel_userptr (p
);
71 assert (uptr
!= 0 && uptr
->m_back
==this && uptr
->m_owner
==p
);
75 void OnError (int err
) const THROWS((NCursesPanelException
)) {
77 THROW(new NCursesPanelException (this, err
));
79 // If err is equal to the curses error indicator ERR, an error handler
82 // Get a keystroke. Default implementation calls getch()
83 virtual int getKey(void);
86 NCursesPanel(int lines
,
90 : NCursesWindow(lines
,cols
,begin_y
,begin_x
) {
93 // Create a panel with this size starting at the requested position.
95 NCursesPanel() : NCursesWindow(::stdscr
) { init(); }
96 // This constructor creates the default Panel associated with the
99 virtual ~NCursesPanel();
101 // basic manipulation
103 OnError (::hide_panel(p
));
105 // Hide the panel. It stays in the stack but becomes invisible.
108 OnError (::show_panel(p
));
110 // Show the panel, i.e. make it visible.
113 OnError (::top_panel(p
));
115 // Make this panel the top panel in the stack.
117 inline void bottom() {
118 OnError (::bottom_panel(p
));
120 // Make this panel the bottom panel in the stack.
121 // N.B.: The panel associated with ::stdscr is always on the bottom. So
122 // actually bottom() makes the panel the first above ::stdscr.
124 virtual int mvwin(int y
, int x
) {
125 OnError(::move_panel(p
, y
, x
));
129 inline bool hidden() const {
130 return (::panel_hidden (p
) ? TRUE
: FALSE
);
132 // Return TRUE if the panel is hidden, FALSE otherwise.
134 /* The functions panel_above() and panel_below() are not reflected in
135 the NCursesPanel class. The reason for this is, that we cannot
136 assume that a panel retrieved by those operations is one wrapped
137 by a C++ class. Although this situation might be handled, we also
138 need a reverse mapping from PANEL to NCursesPanel which needs some
139 redesign of the low level stuff. At the moment, we define them in the
140 interface but they will always produce an error. */
141 inline NCursesPanel
& above() const {
146 inline NCursesPanel
& below() const {
151 // Those two are rewrites of the corresponding virtual members of
153 virtual int refresh();
154 // Propagate all panel changes to the virtual screen and update the
157 virtual int noutrefresh();
158 // Propagate all panel changes to the virtual screen.
160 static void redraw();
161 // Redraw all panels.
164 virtual void frame(const char* title
=NULL
,
165 const char* btitle
=NULL
);
166 // Put a frame around the panel and put the title centered in the top line
167 // and btitle in the bottom line.
169 virtual void boldframe(const char* title
=NULL
,
170 const char* btitle
=NULL
);
171 // Same as frame(), but use highlighted attributes.
173 virtual void label(const char* topLabel
,
174 const char* bottomLabel
);
175 // Put the title centered in the top line and btitle in the bottom line.
177 virtual void centertext(int row
,const char* label
);
178 // Put the label text centered in the specified row.
181 /* We use templates to provide a typesafe mechanism to associate
182 * user data with a panel. A NCursesUserPanel<T> is a panel
183 * associated with some user data of type T.
185 template<class T
> class NCursesUserPanel
: public NCursesPanel
188 NCursesUserPanel (int lines
,
192 const T
* p_UserData
= (T
*)0)
193 : NCursesPanel (lines
, cols
, begin_y
, begin_x
) {
195 set_user ((void *)p_UserData
);
197 // This creates an user panel of the requested size with associated
198 // user data pointed to by p_UserData.
200 NCursesUserPanel(const T
* p_UserData
= (T
*)0) : NCursesPanel() {
202 set_user((void *)p_UserData
);
204 // This creates an user panel associated with the ::stdscr and user data
205 // pointed to by p_UserData.
207 virtual ~NCursesUserPanel() {};
209 T
* UserData (void) const {
210 return (T
*)get_user ();
212 // Retrieve the user data associated with the panel.
214 virtual void setUserData (const T
* p_UserData
) {
216 set_user ((void *)p_UserData
);
218 // Associate the user panel with the user data pointed to by p_UserData.
221 #endif // NCURSES_CURSESP_H_incl