libyui-ncurses
Loading...
Searching...
No Matches
ncursesp.h
1/*
2 Copyright (C) 2000-2012 Novell, Inc
3 This library is free software; you can redistribute it and/or modify
4 it under the terms of the GNU Lesser General Public License as
5 published by the Free Software Foundation; either version 2.1 of the
6 License, or (at your option) version 3.0 of the License. This library
7 is distributed in the hope that it will be useful, but WITHOUT ANY
8 WARRANTY; without even the implied warranty of MERCHANTABILITY or
9 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10 License for more details. You should have received a copy of the GNU
11 Lesser General Public License along with this library; if not, write
12 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13 Floor, Boston, MA 02110-1301 USA
14*/
15
16
17/*-/
18
19 File: ncursesp.h
20
21 Author: Michael Andres <ma@suse.de>
22
23/-*/
24
25#ifndef _NCURSESP_H
26#define _NCURSESP_H
27
28#include <iosfwd>
29
30#include "ncursesw.h"
31#include <ncursesw/panel.h>
32
34{
35 friend std::ostream & operator<<( std::ostream & Stream, const NCursesPanel & Obj_Cv );
36 friend std::ostream & operator<<( std::ostream & Stream, const NCursesPanel * Obj_Cv );
37
38 friend class NCDialog;
39
40protected:
41
42 PANEL *p;
43 static NCursesPanel *dummy;
44
45private:
51 typedef struct
52 {
56 void * m_user;
60 const NCursesPanel* m_back;
64 const PANEL* m_owner;
65 } UserHook;
66
70 void init();
71
72protected:
76 void set_user( void *user )
77 {
78 UserHook* uptr = ( UserHook* )::panel_userptr( p );
79 assert( uptr && uptr->m_back == this && uptr->m_owner == p );
80 uptr->m_user = user;
81 }
82
83 void *get_user() const
84 {
85 UserHook* uptr = ( UserHook* )::panel_userptr( p );
86 assert( uptr && uptr->m_back == this && uptr->m_owner == p );
87 return uptr->m_user;
88 }
89
90 static const NCursesPanel * get_Panel_of( const PANEL & pan )
91 {
92 UserHook* uptr = ( UserHook* )::panel_userptr( &pan );
93
94 if ( uptr && uptr->m_owner == &pan
95 && uptr->m_back && uptr->m_back->p == &pan )
96 {
97 return uptr->m_back;
98 }
99
100 return 0;
101 }
102
107 void OnError( int err ) const THROWS( NCursesPanelException )
108 {
109 if ( err == ERR )
110 THROW( new NCursesPanelException( this, err ) );
111 }
112
113public:
118 int cols,
119 int begin_y = 0,
120 int begin_x = 0 )
121 : NCursesWindow( lines, cols, begin_y, begin_x ), p(0)
122 {
123 init();
124 }
125
130 NCursesPanel() : NCursesWindow( ::stdscr ), p(0) { init(); }
131
132 virtual ~NCursesPanel();
133
134 // basic manipulation
135
139 virtual int resize( int lines, int columns )
140 {
141 ::wresize( w, lines, columns );
142 return ::replace_panel( p, w );
143 }
144
148 inline void hide()
149 {
150 // [ma] hiding a hiden one should not abort.
151 if ( !hidden() )
152 {
153 OnError( ::hide_panel( p ) );
154 }
155 }
156
160 inline void show()
161 {
162 OnError( ::show_panel( p ) );
163 }
164
168 inline void top()
169 {
170 OnError( ::top_panel( p ) );
171 }
172
178 inline void bottom()
179 {
180 // warning FIX for broken bottom_panel (libpanel)
181 // [ma] panel stack is messed up if the last panel is
182 // moved to the bottom.
183 if ( ::panel_above( 0 ) != p )
184 {
185 OnError( ::bottom_panel( p ) );
186 }
187 }
188
189 inline int mvwin( int y, int x )
190 {
191 OnError( ::move_panel( p, y, x ) );
192 return OK;
193 }
194
198 inline bool hidden() const
199 {
200 return ( ::panel_hidden( p ) );
201 }
202
212 inline NCursesPanel& above() const
213 {
214 OnError( ERR );
215 return *dummy;
216 }
217
218 inline NCursesPanel& below() const
219 {
220 OnError( ERR );
221 return *dummy;
222 }
223
224 inline PANEL * PANEL_above() const
225 {
226 return( p ? ::panel_above( p ) : 0 );
227 }
228
229 inline PANEL * PANEL_below() const
230 {
231 return( p ? ::panel_below( p ) : 0 );
232 }
233
234 int transparent( int y, int x );
235
236 // Those two are rewrites of the corresponding virtual members of NCursesWindow
237
242 virtual int refresh();
243
247 virtual int noutrefresh();
248
252 static void redraw();
253
254 // decorations
259 virtual void frame( const char* title = NULL,
260 const char* btitle = NULL );
261
265 virtual void boldframe( const char* title = NULL,
266 const char* btitle = NULL );
267
271 virtual void label( const char* topLabel,
272 const char* bottomLabel );
273
277 virtual void centertext( int row, const char* label );
278};
279
280
287template<class T> class NCursesUserPanel : public NCursesPanel
288{
289
290public:
296 int cols,
297 int begin_y = 0,
298 int begin_x = 0,
299 const T* p_UserData = ( T* )0 )
300 : NCursesPanel( lines, cols, begin_y, begin_x )
301 {
302 if ( p )
303 set_user(( void * )p_UserData );
304 };
305
310 NCursesUserPanel( const T* p_UserData = ( T* )0 ) : NCursesPanel()
311 {
312 if ( p )
313 set_user(( void * )p_UserData );
314 };
315
316 virtual ~NCursesUserPanel() {};
317
321 T* UserData( void ) const
322 {
323 return ( T* )get_user();
324 };
325
329 virtual void setUserData( const T* p_UserData )
330 {
331 if ( p )
332 set_user(( void * )p_UserData );
333 }
334
338 static T* UserDataOf( const PANEL & pan )
339 {
340 const NCursesUserPanel<T> * p = dynamic_cast<const NCursesUserPanel<T>*>( get_Panel_of( pan ) );
341
342 if ( p )
343 {
344 return p->UserData();
345 }
346
347 return ( T* )0;
348 };
349};
350
351#endif // _NCURSESP_H
Definition NCDialog.h:40
Definition ncursesp.h:34
void OnError(int err) const THROWS(NCursesPanelException)
Definition ncursesp.h:107
void bottom()
Definition ncursesp.h:178
int mvwin(int y, int x)
Definition ncursesp.h:189
static void redraw()
Definition ncursesp.cc:94
bool hidden() const
Definition ncursesp.h:198
NCursesPanel & above() const
Definition ncursesp.h:212
virtual void frame(const char *title=NULL, const char *btitle=NULL)
Definition ncursesp.cc:134
virtual int refresh()
Definition ncursesp.cc:112
NCursesPanel(int lines, int cols, int begin_y=0, int begin_x=0)
Definition ncursesp.h:117
virtual void centertext(int row, const char *label)
Definition ncursesp.cc:164
virtual int resize(int lines, int columns)
Definition ncursesp.h:139
void top()
Definition ncursesp.h:168
void set_user(void *user)
Definition ncursesp.h:76
void show()
Definition ncursesp.h:160
virtual int noutrefresh()
Definition ncursesp.cc:119
virtual void boldframe(const char *title=NULL, const char *btitle=NULL)
Definition ncursesp.cc:126
virtual void label(const char *topLabel, const char *bottomLabel)
Definition ncursesp.cc:154
NCursesPanel()
Definition ncursesp.h:130
void hide()
Definition ncursesp.h:148
Associate user data with a panel. We use templates to provide a typesafe mechanism to associate user ...
Definition ncursesp.h:288
static T * UserDataOf(const PANEL &pan)
Definition ncursesp.h:338
NCursesUserPanel(const T *p_UserData=(T *) 0)
Definition ncursesp.h:310
T * UserData(void) const
Definition ncursesp.h:321
NCursesUserPanel(int lines, int cols, int begin_y=0, int begin_x=0, const T *p_UserData=(T *) 0)
Definition ncursesp.h:295
virtual void setUserData(const T *p_UserData)
Definition ncursesp.h:329
C++ class for windows.
Definition ncursesw.h:907
WINDOW * w
Definition ncursesw.h:949
static int lines()
Definition ncursesw.h:1044
static int cols()
Definition ncursesw.h:1049