1 // * This makes emacs happy -*-Mode: C++;-*-
13 class NCursesPanel : public NCursesWindow {
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 const 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
28 void set_user(const void *user) {
29 UserHook* uptr = (UserHook*)::panel_userptr (p);
30 assert (uptr && uptr->m_back==this && uptr->m_owner==p);
34 const void *get_user() {
35 UserHook* uptr = (UserHook*)::panel_userptr (p);
36 assert (uptr && uptr->m_back==this && uptr->m_owner==p);
40 void OnError (int err) const THROWS((NCursesPanelException)) {
42 THROW(new NCursesPanelException (this, err));
46 NCursesPanel(int lines = 0,
51 virtual ~NCursesPanel();
55 OnError (::hide_panel(p));
59 OnError (::show_panel(p));
63 OnError (::top_panel(p));
66 inline void bottom() {
67 OnError (::bottom_panel(p));
70 inline void mvpan(int y, int x) {
71 OnError (::move_panel(p, y, x));
74 inline void mvwin(int y, int x) {
75 OnError (::move_panel(p, y, x));
78 inline bool hidden() const {
79 return ::panel_hidden (p);
82 static void redraw(); // redraw all panels
83 static void refresh(); // update screen
86 virtual void frame(const char *title=NULL, const char* btitle=NULL);
87 virtual void boldframe(const char *title=NULL, const char* btitle=NULL);
88 virtual void label(const char *topLabel, const char *bottomLabel);
89 virtual void centertext(int row,const char *label);
94 /* We use templates to provide a typesafe mechanism to associate
95 * user data with a panel. A NCursesUserPanel<T> is a panel
96 * associated with some user data of type T.
98 template<class T> class NCursesUserPanel : public NCursesPanel
101 NCursesUserPanel (int lines = 0,
105 : NCursesPanel (lines, cols, begin_y, begin_x) {
108 NCursesUserPanel (const T* p_UserData,
113 : NCursesPanel (lines, cols, begin_y, begin_x) {
115 set_user ((const void *)p_UserData);
118 virtual ~NCursesUserPanel() {};
120 const T* UserData (void) const {
121 return (const T*)get_user ();
124 virtual void setUserData (const T* p_UserData) {
126 set_user ((const void *)p_UserData);