1 // * This makes emacs happy -*-Mode: C++;-*-
2 /****************************************************************************
3 * Copyright 2019,2020 Thomas E. Dickey *
4 * Copyright 1998-2012,2014 Free Software Foundation, Inc. *
6 * Permission is hereby granted, free of charge, to any person obtaining a *
7 * copy of this software and associated documentation files (the *
8 * "Software"), to deal in the Software without restriction, including *
9 * without limitation the rights to use, copy, modify, merge, publish, *
10 * distribute, distribute with modifications, sublicense, and/or sell *
11 * copies of the Software, and to permit persons to whom the Software is *
12 * furnished to do so, subject to the following conditions: *
14 * The above copyright notice and this permission notice shall be included *
15 * in all copies or substantial portions of the Software. *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
25 * Except as contained in this notice, the name(s) of the above copyright *
26 * holders shall not be used in advertising or otherwise to promote the *
27 * sale, use or other dealings in this Software without prior written *
29 ****************************************************************************/
31 /****************************************************************************
32 * Author: Juergen Pfeifer, 1997 *
33 ****************************************************************************/
35 #ifndef NCURSES_CURSESP_H_incl
36 #define NCURSES_CURSESP_H_incl 1
38 // $Id: cursesp.h,v 1.34 2020/05/24 01:40:20 anonymous.maarten Exp $
46 class NCURSES_CXX_IMPEXP NCursesPanel
47 : public NCursesWindow
51 static NCursesPanel *dummy;
54 // This structure is used for the panel's user data field to link the
55 // PANEL* to the C++ object and to provide extra space for a user pointer.
57 void* m_user; // the pointer for the user's data
58 const NCursesPanel* m_back; // backward pointer to C++ object
59 const PANEL* m_owner; // the panel itself
62 inline UserHook *UserPointer()
64 UserHook* uptr = reinterpret_cast<UserHook*>(
65 const_cast<void *>(::panel_userptr (p)));
69 void init(); // Initialize the panel object
72 void set_user(void *user)
74 UserHook* uptr = UserPointer();
75 if (uptr != 0 && uptr->m_back==this && uptr->m_owner==p) {
79 // Set the user pointer of the panel.
83 UserHook* uptr = UserPointer();
85 if (uptr != 0 && uptr->m_back==this && uptr->m_owner==p)
86 result = uptr->m_user;
90 void OnError (int err) const THROW2(NCursesException const, NCursesPanelException)
93 THROW(new NCursesPanelException (this, err));
95 // If err is equal to the curses error indicator ERR, an error handler
98 // Get a keystroke. Default implementation calls getch()
99 virtual int getKey(void);
102 NCursesPanel(int nlines,
106 : NCursesWindow(nlines,ncols,begin_y,begin_x), p(0)
110 // Create a panel with this size starting at the requested position.
113 : NCursesWindow(::stdscr), p(0)
117 // This constructor creates the default Panel associated with the
120 NCursesPanel& operator=(const NCursesPanel& rhs)
124 NCursesWindow::operator=(rhs);
129 NCursesPanel(const NCursesPanel& rhs)
130 : NCursesWindow(rhs),
135 virtual ~NCursesPanel() THROWS(NCursesException);
137 // basic manipulation
140 OnError (::hide_panel(p));
142 // Hide the panel. It stays in the stack but becomes invisible.
146 OnError (::show_panel(p));
148 // Show the panel, i.e. make it visible.
152 OnError (::top_panel(p));
154 // Make this panel the top panel in the stack.
158 OnError (::bottom_panel(p));
160 // Make this panel the bottom panel in the stack.
161 // N.B.: The panel associated with ::stdscr is always on the bottom. So
162 // actually bottom() makes the panel the first above ::stdscr.
164 virtual int mvwin(int y, int x)
166 OnError(::move_panel(p, y, x));
170 inline bool hidden() const
172 return (::panel_hidden (p) ? TRUE : FALSE);
174 // Return TRUE if the panel is hidden, FALSE otherwise.
176 /* The functions panel_above() and panel_below() are not reflected in
177 the NCursesPanel class. The reason for this is, that we cannot
178 assume that a panel retrieved by those operations is one wrapped
179 by a C++ class. Although this situation might be handled, we also
180 need a reverse mapping from PANEL to NCursesPanel which needs some
181 redesign of the low level stuff. At the moment, we define them in the
182 interface but they will always produce an error. */
183 inline NCursesPanel& above() const
189 inline NCursesPanel& below() const
195 // Those two are rewrites of the corresponding virtual members of
197 virtual int refresh();
198 // Propagate all panel changes to the virtual screen and update the
201 virtual int noutrefresh();
202 // Propagate all panel changes to the virtual screen.
204 static void redraw();
205 // Redraw all panels.
208 virtual void frame(const char* title=NULL,
209 const char* btitle=NULL);
210 // Put a frame around the panel and put the title centered in the top line
211 // and btitle in the bottom line.
213 virtual void boldframe(const char* title=NULL,
214 const char* btitle=NULL);
215 // Same as frame(), but use highlighted attributes.
217 virtual void label(const char* topLabel,
218 const char* bottomLabel);
219 // Put the title centered in the top line and btitle in the bottom line.
221 virtual void centertext(int row,const char* label);
222 // Put the label text centered in the specified row.
225 /* We use templates to provide a typesafe mechanism to associate
226 * user data with a panel. A NCursesUserPanel<T> is a panel
227 * associated with some user data of type T.
229 template<class T> class NCursesUserPanel : public NCursesPanel
232 NCursesUserPanel (int nlines,
236 const T* p_UserData = STATIC_CAST(T*)(0))
237 : NCursesPanel (nlines, ncols, begin_y, begin_x)
240 set_user (const_cast<void *>(reinterpret_cast<const void*>
243 // This creates an user panel of the requested size with associated
244 // user data pointed to by p_UserData.
246 NCursesUserPanel(const T* p_UserData = STATIC_CAST(T*)(0)) : NCursesPanel()
249 set_user(const_cast<void *>(reinterpret_cast<const void*>(p_UserData)));
251 // This creates an user panel associated with the ::stdscr and user data
252 // pointed to by p_UserData.
254 virtual ~NCursesUserPanel() THROWS(NCursesException) {};
258 return reinterpret_cast<T*>(get_user ());
260 // Retrieve the user data associated with the panel.
262 virtual void setUserData (const T* p_UserData)
265 set_user (const_cast<void *>(reinterpret_cast<const void*>(p_UserData)));
267 // Associate the user panel with the user data pointed to by p_UserData.
270 #endif /* NCURSES_CURSESP_H_incl */