libyui-ncurses  2.55.0
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 
34 class NCursesWindow;
35 class 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 
45 class NCWidget : public tnode<NCWidget*>, protected NCursesError
46 {
47 private:
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 
56  /**
57  * Make this widget invalid. This operation cannot be reversed.
58  */
59  void invalidate() { magic = 0; }
60 
61  /**
62  * This object is only valid if this magic number is YWIDGET_MAGIC.
63  */
64  int magic;
65 
66 protected:
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 
83 public:
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 
101 protected:
102 
103  NCursesWindow * win;
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 
131 public:
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 
170  /**
171  * Pure virtual to make sure every widget implements it. Necessary to make
172  * sure that UI requests via YWidget::setEnabled perform, and behave the
173  * same way as direct calls to NCWidget::setEnabled.
174  **/
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
wsze
Definition: position.h:155
NCursesError
Definition: NCurses.h:51
NCursesWindow
C++ class for windows.
Definition: ncursesw.h:904
NCWidget::setEnabled
virtual void setEnabled(bool do_bv)=0
Pure virtual to make sure every widget implements it.
Definition: NCWidget.cc:391
NClabel
Definition: NCtext.h:82
tnode
Definition: tnode.h:32
NCWidget
Definition: NCWidget.h:46
NCstyle::StWidget
Definition: NCstyle.h:358
wpos
Definition: position.h:110
NCstyle::StList
Definition: NCstyle.h:367
NCursesEvent
Definition: NCurses.h:73
wrect
Definition: position.h:198
NCstyle::Style
Definition: NCstyle.h:525