1 // * This makes emacs happy -*-Mode: C++;-*-
3 /****************************************************************************
4 * Copyright 2019-2021,2022 Thomas E. Dickey *
5 * Copyright 1998-2012,2014 Free Software Foundation, Inc. *
7 * Permission is hereby granted, free of charge, to any person obtaining a *
8 * copy of this software and associated documentation files (the *
9 * "Software"), to deal in the Software without restriction, including *
10 * without limitation the rights to use, copy, modify, merge, publish, *
11 * distribute, distribute with modifications, sublicense, and/or sell *
12 * copies of the Software, and to permit persons to whom the Software is *
13 * furnished to do so, subject to the following conditions: *
15 * The above copyright notice and this permission notice shall be included *
16 * in all copies or substantial portions of the Software. *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
21 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
24 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
26 * Except as contained in this notice, the name(s) of the above copyright *
27 * holders shall not be used in advertising or otherwise to promote the *
28 * sale, use or other dealings in this Software without prior written *
30 ****************************************************************************/
32 /****************************************************************************
33 * Author: Juergen Pfeifer, 1997 *
34 ****************************************************************************/
36 #ifndef NCURSES_CURSESP_H_incl
37 #define NCURSES_CURSESP_H_incl 1
39 // $Id: cursesp.h,v 1.36 2022/08/20 20:52:15 tom Exp $
47 class NCURSES_CXX_IMPEXP NCursesPanel
48 : public NCursesWindow
52 static NCursesPanel *dummy;
55 // This structure is used for the panel's user data field to link the
56 // PANEL* to the C++ object and to provide extra space for a user pointer.
58 void* m_user; // the pointer for the user's data
59 const NCursesPanel* m_back; // backward pointer to C++ object
60 const PANEL* m_owner; // the panel itself
63 inline UserHook *UserPointer()
65 UserHook* uptr = reinterpret_cast<UserHook*>(
66 const_cast<void *>(::panel_userptr (p)));
70 void init(); // Initialize the panel object
73 void set_user(void *user)
75 UserHook* uptr = UserPointer();
76 if (uptr != 0 && uptr->m_back==this && uptr->m_owner==p) {
80 // Set the user pointer of the panel.
84 UserHook* uptr = UserPointer();
86 if (uptr != 0 && uptr->m_back==this && uptr->m_owner==p)
87 result = uptr->m_user;
91 void OnError (int err) const THROW2(NCursesException const, NCursesPanelException)
94 THROW(new NCursesPanelException (this, err));
96 // If err is equal to the curses error indicator ERR, an error handler
99 // Get a keystroke. Default implementation calls getch()
100 virtual int getKey(void);
103 NCursesPanel(int nlines,
107 : NCursesWindow(nlines,ncols,begin_y,begin_x), p(0)
111 // Create a panel with this size starting at the requested position.
114 : NCursesWindow(::stdscr), p(0)
118 // This constructor creates the default Panel associated with the
121 NCursesPanel& operator=(const NCursesPanel& rhs)
125 NCursesWindow::operator=(rhs);
130 NCursesPanel(const NCursesPanel& rhs)
131 : NCursesWindow(rhs),
136 virtual ~NCursesPanel() THROWS(NCursesException);
138 // basic manipulation
141 OnError (::hide_panel(p));
143 // Hide the panel. It stays in the stack but becomes invisible.
147 OnError (::show_panel(p));
149 // Show the panel, i.e. make it visible.
153 OnError (::top_panel(p));
155 // Make this panel the top panel in the stack.
159 OnError (::bottom_panel(p));
161 // Make this panel the bottom panel in the stack.
162 // N.B.: The panel associated with ::stdscr is always on the bottom. So
163 // actually bottom() makes the panel the first above ::stdscr.
165 virtual int mvwin(int y, int x) NCURSES_OVERRIDE
167 OnError(::move_panel(p, y, x));
171 inline bool hidden() const
173 return (::panel_hidden (p) ? TRUE : FALSE);
175 // Return TRUE if the panel is hidden, FALSE otherwise.
177 /* The functions panel_above() and panel_below() are not reflected in
178 the NCursesPanel class. The reason for this is, that we cannot
179 assume that a panel retrieved by those operations is one wrapped
180 by a C++ class. Although this situation might be handled, we also
181 need a reverse mapping from PANEL to NCursesPanel which needs some
182 redesign of the low level stuff. At the moment, we define them in the
183 interface but they will always produce an error. */
184 inline NCursesPanel& above() const
190 inline NCursesPanel& below() const
196 // Those two are rewrites of the corresponding virtual members of
198 virtual int refresh() NCURSES_OVERRIDE;
199 // Propagate all panel changes to the virtual screen and update the
202 virtual int noutrefresh() NCURSES_OVERRIDE;
203 // Propagate all panel changes to the virtual screen.
205 static void redraw();
206 // Redraw all panels.
209 virtual void frame(const char* title=NULL,
210 const char* btitle=NULL);
211 // Put a frame around the panel and put the title centered in the top line
212 // and btitle in the bottom line.
214 virtual void boldframe(const char* title=NULL,
215 const char* btitle=NULL);
216 // Same as frame(), but use highlighted attributes.
218 virtual void label(const char* topLabel,
219 const char* bottomLabel);
220 // Put the title centered in the top line and btitle in the bottom line.
222 virtual void centertext(int row,const char* label);
223 // Put the label text centered in the specified row.
226 /* We use templates to provide a typesafe mechanism to associate
227 * user data with a panel. A NCursesUserPanel<T> is a panel
228 * associated with some user data of type T.
230 template<class T> class NCursesUserPanel : public NCursesPanel
233 NCursesUserPanel (int nlines,
237 const T* p_UserData = STATIC_CAST(T*)(0))
238 : NCursesPanel (nlines, ncols, begin_y, begin_x)
241 set_user (const_cast<void *>(reinterpret_cast<const void*>
244 // This creates an user panel of the requested size with associated
245 // user data pointed to by p_UserData.
247 explicit NCursesUserPanel(const T* p_UserData = STATIC_CAST(T*)(0)) : NCursesPanel()
250 set_user(const_cast<void *>(reinterpret_cast<const void*>(p_UserData)));
252 // This creates an user panel associated with the ::stdscr and user data
253 // pointed to by p_UserData.
255 virtual ~NCursesUserPanel() THROWS(NCursesException) {};
259 return reinterpret_cast<T*>(get_user ());
261 // Retrieve the user data associated with the panel.
263 virtual void setUserData (const T* p_UserData)
266 set_user (const_cast<void *>(reinterpret_cast<const void*>(p_UserData)));
268 // Associate the user panel with the user data pointed to by p_UserData.
271 #endif /* NCURSES_CURSESP_H_incl */