1 // * This makes emacs happy -*-Mode: C++;-*-
5 // $Id: cursesp.h,v 1.10 1998/02/17 09:01:28 juergen Exp $
13 class NCursesPanel : public NCursesWindow {
16 static NCursesPanel *dummy;
19 // This structure is used for the panel's user data field to link the
20 // PANEL* to the C++ object and to provide extra space for a user pointer.
22 void* m_user; // the pointer for the user's data
23 const NCursesPanel* m_back; // backward pointer to C++ object
24 const PANEL* m_owner; // the panel itself
27 void init(); // Initialize the panel object
30 void set_user(void *user) {
31 UserHook* uptr = (UserHook*)::panel_userptr (p);
32 assert (uptr && uptr->m_back==this && uptr->m_owner==p);
35 // Set the user pointer of the panel.
38 UserHook* uptr = (UserHook*)::panel_userptr (p);
39 assert (uptr && uptr->m_back==this && uptr->m_owner==p);
43 void OnError (int err) const THROWS((NCursesPanelException)) {
45 THROW(new NCursesPanelException (this, err));
47 // If err is equal to the curses error indicator ERR, an error handler
51 NCursesPanel(int lines,
55 : NCursesWindow(lines,cols,begin_y,begin_x) {
58 // Create a panel with this size starting at the requested position.
60 NCursesPanel() : NCursesWindow(::stdscr) { init(); }
61 // This constructor creates the default Panel associated with the
64 virtual ~NCursesPanel();
68 OnError (::hide_panel(p));
70 // Hide the panel. It stays in the stack but becomes invisible.
73 OnError (::show_panel(p));
75 // Show the panel, i.e. make it visible.
78 OnError (::top_panel(p));
80 // Make this panel the top panel in the stack.
82 inline void bottom() {
83 OnError (::bottom_panel(p));
85 // Make this panel the bottom panel in the stack.
86 // N.B.: The panel associated with ::stdscr is always on the bottom. So
87 // actually bottom() makes the panel the first above ::stdscr.
89 inline int mvwin(int y, int x) {
90 OnError(::move_panel(p, y, x));
94 inline bool hidden() const {
95 return (::panel_hidden (p) ? TRUE : FALSE);
97 // Return TRUE if the panel is hidden, FALSE otherwise.
99 /* The functions panel_above() and panel_below() are not reflected in
100 the NCursesPanel class. The reason for this is, that we cannot
101 assume that a panel retrieved by those operations is one wrapped
102 by a C++ class. Although this situation might be handled, we also
103 need a reverse mapping from PANEL to NCursesPanel which needs some
104 redesign of the low level stuff. At the moment, we define them in the
105 interface but they will always produce an error. */
106 inline NCursesPanel& above() const {
111 inline NCursesPanel& below() const {
116 // Those two are rewrites of the corresponding virtual members of
119 // Propagate all panel changes to the virtual screen and update the
123 // Propagate all panel changes to the virtual screen.
125 static void redraw();
126 // Redraw all panels.
129 virtual void frame(const char* title=NULL,
130 const char* btitle=NULL);
131 // Put a frame around the panel and put the title centered in the top line
132 // and btitle in the bottom line.
134 virtual void boldframe(const char* title=NULL,
135 const char* btitle=NULL);
136 // Same as frame(), but use highlighted attributes.
138 virtual void label(const char* topLabel,
139 const char* bottomLabel);
140 // Put the title centered in the top line and btitle in the bottom line.
142 virtual void centertext(int row,const char* label);
143 // Put the label text centered in the specified row.
146 /* We use templates to provide a typesafe mechanism to associate
147 * user data with a panel. A NCursesUserPanel<T> is a panel
148 * associated with some user data of type T.
150 template<class T> class NCursesUserPanel : public NCursesPanel
153 NCursesUserPanel (int lines,
157 const T* p_UserData = (T*)0)
158 : NCursesPanel (lines, cols, begin_y, begin_x) {
160 set_user ((void *)p_UserData);
162 // This creates an user panel of the requested size with associated
163 // user data pointed to by p_UserData.
165 NCursesUserPanel(const T* p_UserData = (T*)0) : NCursesPanel() {
167 set_user((void *)p_UserData);
169 // This creates an user panel associated with the ::stdscr and user data
170 // pointed to by p_UserData.
172 virtual ~NCursesUserPanel() {};
174 T* UserData (void) const {
175 return (T*)get_user ();
177 // Retrieve the user data associated with the panel.
179 virtual void setUserData (const T* p_UserData) {
181 set_user ((void *)p_UserData);
183 // Associate the user panel with the user data pointed to by p_UserData.