libyui-ncurses
 
Loading...
Searching...
No Matches
NCWidget.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: NCWidget.h
20
21 Author: Michael Andres <ma@suse.de>
22
23/-*/
24
25#ifndef NCWidget_h
26#define NCWidget_h
27
28
29#include <iosfwd>
30
31#include "NCurses.h"
32#include "tnode.h"
33
34class NCursesWindow;
35class NClabel;
36
37
38#define DLOC location() << ' '
39
40#define YWIDGET_MAGIC 42
41
42// debug option: enable verbose event logging
43#define VERBOSE_EVENTS 0
44
45class NCWidget : public tnode<NCWidget*>, protected NCursesError
46{
47private:
48
49 friend std::ostream & operator<<( std::ostream & str, const NCWidget & obj );
50 friend std::ostream & operator<<( std::ostream & str, const NCWidget * obj );
51
52 NCWidget & operator=( const NCWidget & );
53 NCWidget( const NCWidget & );
54
55
59 void invalidate() { magic = 0; }
60
64 int magic;
65
66protected:
67
68 virtual const char * location() const { return "NCWidget"; }
69
70 virtual void PreDisconnect();
71 virtual void PostDisconnect();
72 virtual void PreReparent();
73 virtual void PostReparent();
74
75 NCursesWindow * ParentWin();
76
77 NCWidget *const grabedBy;
78 bool grabFocus();
79 virtual void grabNotify( NCWidget * ) {}
80
81 virtual bool wantFocus( NCWidget & ngrab ) { return false; }
82
83public:
84
85 void grabSet( NCWidget * ngrab )
86 {
87 if ( grabedBy && grabedBy != ngrab )
88 grabedBy->grabNotify( this );
89
90 const_cast<NCWidget *&>( grabedBy ) = ngrab;
91 }
92
93 void grabRelease( NCWidget * ograb )
94 {
95 if ( grabedBy && grabedBy != ograb )
96 grabedBy->grabNotify( this );
97
98 const_cast<NCWidget *&>( grabedBy ) = 0;
99 }
100
101protected:
102
104 wsze defsze;
105 wrect framedim;
106 wrect inparent;
107 bool noUpdates;
108 bool skipNoDimWin;
109
110 void wMoveChildTo( NCWidget & child, const wpos & newpos );
111 void wRelocate( const wrect & newrect );
112 void wRelocate( const wpos & newpos, const wsze & newsze )
113 {
114 wRelocate( wrect( newpos, newsze ) );
115 }
116
117 virtual void wCreate( const wrect & newrect );
118 virtual void wMoveTo( const wpos & newpos );
119 virtual void wDelete();
120 virtual void wUpdate( bool forced_br = false );
121
122 wpos ScreenPos() const;
123
124 NC::WState wstate;
125
126 virtual void wRedraw();
127 virtual void wRecoded();
128
129 NClabel * hotlabel;
130
131public:
132
133 NCWidget( NCWidget * myparent );
134 NCWidget( YWidget * parent = 0 );
135 virtual ~NCWidget();
136
137 bool isValid() const { return magic == YWIDGET_MAGIC; }
138
139 bool winExist() const { return win != ( NCursesWindow * )0; }
140
141 virtual const NCstyle::Style & wStyle() const
142 {
143 if ( Parent() )
144 return Top().Value()->wStyle();
145
146 return NCurses::style()[NCstyle::DefaultStyle];
147 }
148
149 const NCstyle::StWidget & widgetStyle( bool nonactive = false ) const
150 { return wStyle().getWidget( GetState(), nonactive ); }
151
152 const NCstyle::StWidget & frameStyle() const
153 { return wStyle().getFrame( GetState() ); }
154
155 const NCstyle::StList & listStyle() const
156 { return wStyle().getList( GetState() ); }
157
158 wsze wGetDefsze() const { return defsze; }
159
160 wrect wGetSize() const { return inparent; }
161
162 void Update();
163 void Redraw( bool sub = false );
164 void Recoded();
165
166 NC::WState GetState() const { return wstate; }
167
168 void SetState( const NC::WState newstate, bool force = false );
169
175 virtual void setEnabled( bool do_bv ) = 0;
176
177 virtual bool HasHotkey( int key );
178 virtual bool HasFunctionHotkey( int key ) const;
179
180 virtual NCursesEvent wHandleHotkey( wint_t key );
181 virtual NCursesEvent wHandleInput( wint_t key );
182
183 void DumpOn( std::ostream & str, std::string prfx ) const;
184};
185
186
187#include "NCstring.h"
188#include "NCtext.h"
189
190
191#endif // NCWidget_h
Definition NCWidget.h:46
virtual void setEnabled(bool do_bv)=0
Definition NCWidget.cc:392
NCursesWindow * win
(owned)
Definition NCWidget.h:103
Multi-line string, with optional hotkey, drawable.
Definition NCtext.h:82
C++ class for windows.
Definition ncursesw.h:907
self & Top()
Definition tnode.h:324
Screen position pair in the order line, column: (L, C)
Definition position.h:110
A rectangle is defined by its position and size: wpos Pos, wsze Sze.
Definition position.h:194
Screen dimension (screen size) in the order height, width: (H, W)
Definition position.h:154