|
||||
File indexing completed on 2025-01-18 10:02:12
0001 // * This makes emacs happy -*-Mode: C++;-*- 0002 // vile:cppmode 0003 /**************************************************************************** 0004 * Copyright 2019-2021,2022 Thomas E. Dickey * 0005 * Copyright 1998-2012,2014 Free Software Foundation, Inc. * 0006 * * 0007 * Permission is hereby granted, free of charge, to any person obtaining a * 0008 * copy of this software and associated documentation files (the * 0009 * "Software"), to deal in the Software without restriction, including * 0010 * without limitation the rights to use, copy, modify, merge, publish, * 0011 * distribute, distribute with modifications, sublicense, and/or sell * 0012 * copies of the Software, and to permit persons to whom the Software is * 0013 * furnished to do so, subject to the following conditions: * 0014 * * 0015 * The above copyright notice and this permission notice shall be included * 0016 * in all copies or substantial portions of the Software. * 0017 * * 0018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 0019 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 0020 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 0021 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 0022 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 0023 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 0024 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 0025 * * 0026 * Except as contained in this notice, the name(s) of the above copyright * 0027 * holders shall not be used in advertising or otherwise to promote the * 0028 * sale, use or other dealings in this Software without prior written * 0029 * authorization. * 0030 ****************************************************************************/ 0031 0032 /**************************************************************************** 0033 * Author: Juergen Pfeifer, 1997 * 0034 ****************************************************************************/ 0035 0036 #ifndef NCURSES_CURSESP_H_incl 0037 #define NCURSES_CURSESP_H_incl 1 0038 0039 // $Id: cursesp.h,v 1.36 2022/08/20 20:52:15 tom Exp $ 0040 0041 #include <ncursesw/cursesw.h> 0042 0043 extern "C" { 0044 # include <ncursesw/panel.h> 0045 } 0046 0047 class NCURSES_CXX_IMPEXP NCursesPanel 0048 : public NCursesWindow 0049 { 0050 protected: 0051 PANEL *p; 0052 static NCursesPanel *dummy; 0053 0054 private: 0055 // This structure is used for the panel's user data field to link the 0056 // PANEL* to the C++ object and to provide extra space for a user pointer. 0057 typedef struct { 0058 void* m_user; // the pointer for the user's data 0059 const NCursesPanel* m_back; // backward pointer to C++ object 0060 const PANEL* m_owner; // the panel itself 0061 } UserHook; 0062 0063 inline UserHook *UserPointer() 0064 { 0065 UserHook* uptr = reinterpret_cast<UserHook*>( 0066 const_cast<void *>(::panel_userptr (p))); 0067 return uptr; 0068 } 0069 0070 void init(); // Initialize the panel object 0071 0072 protected: 0073 void set_user(void *user) 0074 { 0075 UserHook* uptr = UserPointer(); 0076 if (uptr != 0 && uptr->m_back==this && uptr->m_owner==p) { 0077 uptr->m_user = user; 0078 } 0079 } 0080 // Set the user pointer of the panel. 0081 0082 void *get_user() 0083 { 0084 UserHook* uptr = UserPointer(); 0085 void *result = 0; 0086 if (uptr != 0 && uptr->m_back==this && uptr->m_owner==p) 0087 result = uptr->m_user; 0088 return result; 0089 } 0090 0091 void OnError (int err) const THROW2(NCursesException const, NCursesPanelException) 0092 { 0093 if (err==ERR) 0094 THROW(new NCursesPanelException (this, err)); 0095 } 0096 // If err is equal to the curses error indicator ERR, an error handler 0097 // is called. 0098 0099 // Get a keystroke. Default implementation calls getch() 0100 virtual int getKey(void); 0101 0102 public: 0103 NCursesPanel(int nlines, 0104 int ncols, 0105 int begin_y = 0, 0106 int begin_x = 0) 0107 : NCursesWindow(nlines,ncols,begin_y,begin_x), p(0) 0108 { 0109 init(); 0110 } 0111 // Create a panel with this size starting at the requested position. 0112 0113 NCursesPanel() 0114 : NCursesWindow(::stdscr), p(0) 0115 { 0116 init(); 0117 } 0118 // This constructor creates the default Panel associated with the 0119 // ::stdscr window 0120 0121 NCursesPanel& operator=(const NCursesPanel& rhs) 0122 { 0123 if (this != &rhs) { 0124 *this = rhs; 0125 NCursesWindow::operator=(rhs); 0126 } 0127 return *this; 0128 } 0129 0130 NCursesPanel(const NCursesPanel& rhs) 0131 : NCursesWindow(rhs), 0132 p(rhs.p) 0133 { 0134 } 0135 0136 virtual ~NCursesPanel() THROWS(NCursesException); 0137 0138 // basic manipulation 0139 inline void hide() 0140 { 0141 OnError (::hide_panel(p)); 0142 } 0143 // Hide the panel. It stays in the stack but becomes invisible. 0144 0145 inline void show() 0146 { 0147 OnError (::show_panel(p)); 0148 } 0149 // Show the panel, i.e. make it visible. 0150 0151 inline void top() 0152 { 0153 OnError (::top_panel(p)); 0154 } 0155 // Make this panel the top panel in the stack. 0156 0157 inline void bottom() 0158 { 0159 OnError (::bottom_panel(p)); 0160 } 0161 // Make this panel the bottom panel in the stack. 0162 // N.B.: The panel associated with ::stdscr is always on the bottom. So 0163 // actually bottom() makes the panel the first above ::stdscr. 0164 0165 virtual int mvwin(int y, int x) NCURSES_OVERRIDE 0166 { 0167 OnError(::move_panel(p, y, x)); 0168 return OK; 0169 } 0170 0171 inline bool hidden() const 0172 { 0173 return (::panel_hidden (p) ? TRUE : FALSE); 0174 } 0175 // Return TRUE if the panel is hidden, FALSE otherwise. 0176 0177 /* The functions panel_above() and panel_below() are not reflected in 0178 the NCursesPanel class. The reason for this is, that we cannot 0179 assume that a panel retrieved by those operations is one wrapped 0180 by a C++ class. Although this situation might be handled, we also 0181 need a reverse mapping from PANEL to NCursesPanel which needs some 0182 redesign of the low level stuff. At the moment, we define them in the 0183 interface but they will always produce an error. */ 0184 inline NCursesPanel& above() const 0185 { 0186 OnError(ERR); 0187 return *dummy; 0188 } 0189 0190 inline NCursesPanel& below() const 0191 { 0192 OnError(ERR); 0193 return *dummy; 0194 } 0195 0196 // Those two are rewrites of the corresponding virtual members of 0197 // NCursesWindow 0198 virtual int refresh() NCURSES_OVERRIDE; 0199 // Propagate all panel changes to the virtual screen and update the 0200 // physical screen. 0201 0202 virtual int noutrefresh() NCURSES_OVERRIDE; 0203 // Propagate all panel changes to the virtual screen. 0204 0205 static void redraw(); 0206 // Redraw all panels. 0207 0208 // decorations 0209 virtual void frame(const char* title=NULL, 0210 const char* btitle=NULL); 0211 // Put a frame around the panel and put the title centered in the top line 0212 // and btitle in the bottom line. 0213 0214 virtual void boldframe(const char* title=NULL, 0215 const char* btitle=NULL); 0216 // Same as frame(), but use highlighted attributes. 0217 0218 virtual void label(const char* topLabel, 0219 const char* bottomLabel); 0220 // Put the title centered in the top line and btitle in the bottom line. 0221 0222 virtual void centertext(int row,const char* label); 0223 // Put the label text centered in the specified row. 0224 }; 0225 0226 /* We use templates to provide a typesafe mechanism to associate 0227 * user data with a panel. A NCursesUserPanel<T> is a panel 0228 * associated with some user data of type T. 0229 */ 0230 template<class T> class NCursesUserPanel : public NCursesPanel 0231 { 0232 public: 0233 NCursesUserPanel (int nlines, 0234 int ncols, 0235 int begin_y = 0, 0236 int begin_x = 0, 0237 const T* p_UserData = STATIC_CAST(T*)(0)) 0238 : NCursesPanel (nlines, ncols, begin_y, begin_x) 0239 { 0240 if (p) 0241 set_user (const_cast<void *>(reinterpret_cast<const void*> 0242 (p_UserData))); 0243 }; 0244 // This creates an user panel of the requested size with associated 0245 // user data pointed to by p_UserData. 0246 0247 explicit NCursesUserPanel(const T* p_UserData = STATIC_CAST(T*)(0)) : NCursesPanel() 0248 { 0249 if (p) 0250 set_user(const_cast<void *>(reinterpret_cast<const void*>(p_UserData))); 0251 }; 0252 // This creates an user panel associated with the ::stdscr and user data 0253 // pointed to by p_UserData. 0254 0255 virtual ~NCursesUserPanel() THROWS(NCursesException) {}; 0256 0257 T* UserData (void) 0258 { 0259 return reinterpret_cast<T*>(get_user ()); 0260 }; 0261 // Retrieve the user data associated with the panel. 0262 0263 virtual void setUserData (const T* p_UserData) 0264 { 0265 if (p) 0266 set_user (const_cast<void *>(reinterpret_cast<const void*>(p_UserData))); 0267 } 0268 // Associate the user panel with the user data pointed to by p_UserData. 0269 }; 0270 0271 #endif /* NCURSES_CURSESP_H_incl */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |