libyui-ncurses  2.44.1
 All Classes Functions Variables
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 
43 class NCWidget : public tnode<NCWidget*>, protected NCursesError
44 {
45 private:
46 
47  friend std::ostream & operator<<( std::ostream & STREAM, const NCWidget & OBJ );
48  friend std::ostream & operator<<( std::ostream & STREAM, const NCWidget * OBJ );
49 
50  NCWidget & operator=( const NCWidget & );
51  NCWidget( const NCWidget & );
52 
53 
54  /**
55  * Make this widget invalid. This operation cannot be reversed.
56  */
57  void invalidate() { magic = 0; }
58 
59  /**
60  * This object is only valid if this magic number is YWIDGET_MAGIC.
61  */
62  int magic;
63 
64 protected:
65 
66  virtual const char * location() const { return "NCWidget"; }
67 
68  virtual void PreDisconnect();
69  virtual void PostDisconnect();
70  virtual void PreReparent();
71  virtual void PostReparent();
72 
73  NCursesWindow * ParentWin();
74 
75  NCWidget *const grabedBy;
76  bool grabFocus();
77  virtual void grabNotify( NCWidget * ) {}
78 
79  virtual bool wantFocus( NCWidget & ngrab ) { return false; }
80 
81 public:
82 
83  void grabSet( NCWidget * ngrab )
84  {
85  if ( grabedBy && grabedBy != ngrab )
86  grabedBy->grabNotify( this );
87 
88  const_cast<NCWidget *&>( grabedBy ) = ngrab;
89  }
90 
91  void grabRelease( NCWidget * ograb )
92  {
93  if ( grabedBy && grabedBy != ograb )
94  grabedBy->grabNotify( this );
95 
96  const_cast<NCWidget *&>( grabedBy ) = 0;
97  }
98 
99 protected:
100 
101  NCursesWindow * win;
102  wsze defsze;
103  wrect framedim;
104  wrect inparent;
105  bool noUpdates;
106  bool skipNoDimWin;
107 
108  void wMoveChildTo( NCWidget & child, const wpos & newpos );
109  void wRelocate( const wrect & newrect );
110  void wRelocate( const wpos & newpos, const wsze & newsze )
111  {
112  wRelocate( wrect( newpos, newsze ) );
113  }
114 
115  virtual void wCreate( const wrect & newrect );
116  virtual void wMoveTo( const wpos & newpos );
117  virtual void wDelete();
118  virtual void wUpdate( bool forced_br = false );
119 
120  wpos ScreenPos() const;
121 
122  NC::WState wstate;
123 
124  virtual void wRedraw();
125  virtual void wRecoded();
126 
127  NClabel * hotlabel;
128 
129 public:
130 
131  NCWidget( NCWidget * myparent );
132  NCWidget( YWidget * parent = 0 );
133  virtual ~NCWidget();
134 
135  bool isValid() const { return magic == YWIDGET_MAGIC; }
136 
137  bool winExist() const { return win != ( NCursesWindow * )0; }
138 
139  virtual const NCstyle::Style & wStyle() const
140  {
141  if ( Parent() )
142  return Top().Value()->wStyle();
143 
144  return NCurses::style()[NCstyle::DefaultStyle];
145  }
146 
147  const NCstyle::StWidget & widgetStyle( bool nonactive = false ) const
148  { return wStyle().getWidget( GetState(), nonactive ); }
149 
150  const NCstyle::StWidget & frameStyle() const
151  { return wStyle().getFrame( GetState() ); }
152 
153  const NCstyle::StList & listStyle() const
154  { return wStyle().getList( GetState() ); }
155 
156  wsze wGetDefsze() const { return defsze; }
157 
158  wrect wGetSize() const { return inparent; }
159 
160  void Update();
161  void Redraw( const bool sub = false );
162  void Recoded();
163 
164  NC::WState GetState() const { return wstate; }
165 
166  void SetState( const NC::WState newstate, const bool force = false );
167 
168  /**
169  * Pure virtual to make sure every widget implements it. Necessary to make
170  * sure that UI requests via YWidget::setEnabled perform, and behave the
171  * same way as direct calls to NCWidget::setEnabled.
172  **/
173  virtual void setEnabled( bool do_bv ) = 0;
174 
175  virtual bool HasHotkey( int key );
176  virtual bool HasFunctionHotkey( int key ) const;
177 
178  virtual NCursesEvent wHandleHotkey( wint_t key );
179  virtual NCursesEvent wHandleInput( wint_t key );
180 
181  void DumpOn( std::ostream & str, std::string prfx ) const;
182 };
183 
184 
185 #include "NCstring.h"
186 #include "NCtext.h"
187 
188 
189 #endif // NCWidget_h
C++ class for windows.
Definition: ncursesw.h:904
Definition: tnode.h:31
Definition: position.h:109
virtual void setEnabled(bool do_bv)=0
Definition: NCWidget.cc:391
Definition: NCtext.h:81
Definition: position.h:154