libyui
YWidget.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: YWidget.h
20 
21  Author: Stefan Hundhammer <shundhammer@suse.de>
22 
23 /-*/
24 
25 #ifndef YWidget_h
26 #define YWidget_h
27 
28 #include <string>
29 #include <iosfwd>
30 
31 #include "YTypes.h"
32 #include "YProperty.h"
33 #include "YUISymbols.h"
34 #include "YUIException.h"
35 #include "YChildrenManager.h"
36 #include "ImplPtr.h"
37 
38 
39 class YDialog;
40 class YWidgetID;
41 class YMacroRecorder;
42 
43 
47 
48 class YWidgetPrivate;
49 
50 
54 class YWidget
55 {
56 protected:
60  YWidget( YWidget * parent );
61 
62 public:
66  virtual ~YWidget();
67 
72  virtual const char * widgetClass() const { return "YWidget"; }
73 
85  virtual std::string debugLabel() const;
86 
90  std::string helpText() const;
91 
99  void setHelpText( const std::string & helpText );
100 
101 
102  //
103  // Property Management
104  //
105 
138  virtual const YPropertySet & propertySet();
139 
152  virtual bool setProperty( const std::string & propertyName,
153  const YPropertyValue & val );
154 
161  virtual YPropertyValue getProperty( const std::string & propertyName );
162 
163 
164  //
165  // Children Management
166  //
167  // Even though many widget classes are leaf classes and thus cannot have
168  // children by design, it makes sense to have the children management in
169  // this base class: Then descending down a widget tree is transparent to
170  // the outside without the need to check for container widget classes,
171  // casting to those container widget classes and only calling child
172  // management methods in that case.
173  //
174  // By default, YWidget and derived classes have a YWidgetChildrenRejector
175  // as their children manager, i.e. any attempt to add a child will result
176  // in a YUITooManyChildrenException.
177  //
178  // Derived classes that can (semantically) handle children should set the
179  // children manager to one of
180  //
181  // - YWidgetChildrenManager: handles any number of child widgets;
182  // useful for VBox / HBox
183  //
184  // - YSingleWidgetChildManager: handles exactly one child
185  // useful for widgets like Alignment, Frame, Dialog
186  //
187 
188 
192  bool hasChildren() const
193  { return childrenManager()->hasChildren(); }
194 
199  YWidget * firstChild() const
200  { return childrenManager()->firstChild(); }
201 
205  YWidget * lastChild() const
206  { return childrenManager()->lastChild(); }
207 
212  YWidgetListIterator childrenBegin() const
213  { return childrenManager()->begin(); }
214 
218  YWidgetListIterator childrenEnd() const
219  { return childrenManager()->end(); }
220 
225  YWidgetListConstIterator childrenConstBegin() const
226  { return childrenManager()->begin(); }
227 
231  YWidgetListConstIterator childrenConstEnd() const
232  { return childrenManager()->end(); }
233 
238  YWidgetListIterator begin()
239  { return childrenBegin(); }
240 
245  YWidgetListIterator end()
246  { return childrenEnd(); }
247 
251  int childrenCount() const { return childrenManager()->count(); }
252 
256  bool contains( YWidget * child ) const
257  { return childrenManager()->contains( child ); }
258 
265  virtual void addChild( YWidget * child );
266 
271  virtual void removeChild( YWidget * child );
272 
276  void deleteChildren();
277 
281  YWidget * parent() const;
282 
286  bool hasParent() const;
287 
291  void setParent( YWidget * newParent );
292 
297  YDialog * findDialog();
298 
305  YWidget * findWidget( YWidgetID * id, bool doThrow = true ) const;
306 
307 
308  //
309  // Geometry Management
310  //
311 
317  virtual int preferredWidth() = 0;
318 
324  virtual int preferredHeight() = 0;
325 
336  virtual int preferredSize( YUIDimension dim );
337 
353  virtual void setSize( int newWidth, int newHeight ) = 0;
354 
355 
356  //
357  // Misc
358  //
359 
360 
368  bool isValid() const;
369 
373  bool beingDestroyed() const;
374 
379  void * widgetRep() const;
380 
390  void setWidgetRep( void * toolkitWidgetRep );
391 
395  bool hasId() const;
396 
400  YWidgetID * id() const;
401 
413  void setId( YWidgetID * newId_disown );
414 
421  virtual void setEnabled( bool enabled = true );
422 
426  void setDisabled() { setEnabled( false); }
427 
431  virtual bool isEnabled() const;
432 
441  virtual bool stretchable( YUIDimension dim ) const;
442 
447  void setStretchable( YUIDimension dim, bool newStretch );
448 
453  void setDefaultStretchable( YUIDimension dim, bool newStretch );
454 
465  virtual int weight( YUIDimension dim );
466 
471  bool hasWeight( YUIDimension dim );
472 
476  void setWeight( YUIDimension dim, int weight );
477 
481  void setNotify( bool notify = true );
482 
487  bool notify() const;
488 
492  void setNotifyContextMenu( bool notifyContextMenu = true );
493 
498  bool notifyContextMenu() const;
499 
500 
505  bool sendKeyEvents() const;
506 
510  void setSendKeyEvents( bool doSend );
511 
516  bool autoShortcut() const;
517 
521  void setAutoShortcut( bool _newAutoShortcut );
522 
527  int functionKey() const;
528 
532  bool hasFunctionKey() const;
533 
541  virtual void setFunctionKey( int fkey_no );
542 
552  virtual bool setKeyboardFocus();
553 
560  virtual std::string shortcutString() const { return std::string( "" ); }
561 
568  virtual void setShortcutString( const std::string & str );
569 
576  virtual const char * userInputProperty() { return (const char *) 0; }
577 
582  void dumpWidgetTree( int indentationLevel = 0 );
583 
590  void dumpDialogWidgetTree();
591 
595  void setChildrenEnabled( bool enabled );
596 
597  //
598  // Macro Recorder Support
599  //
600 
619  virtual void saveUserInput( YMacroRecorder *macroRecorder );
620 
628  void * operator new( size_t size );
629 
630 
631  // NCurses optimizations
632 
633 
640  virtual void startMultipleChanges() {}
641  virtual void doneMultipleChanges() {}
642 
643 
644 protected:
645 
650 
664  void setChildrenManager( YWidgetChildrenManager * manager );
665 
674  void setBeingDestroyed();
675 
680  void dumpWidget( YWidget *w, int indentationLevel );
681 
682 
683 private:
684 
688  void invalidate();
689 
693  YWidget( const YWidget & other );
694 
698  const YWidget & operator=( const YWidget & other );
699 
700 private:
701 
702  //
703  // Data Members
704  //
705 
706  int _magic; // should always be the first member
708  static YPropertySet _propertySet;
709  static bool _usedOperatorNew;
710 
711 
712 #include "YWidget_OptimizeChanges.h"
713 
714 };
715 
716 
717 std::ostream & operator<<( std::ostream & stream, const YWidget * widget );
718 
719 
720 #endif // YWidget_h
virtual std::string shortcutString() const
Definition: YWidget.h:560
int childrenCount() const
Definition: YWidget.h:251
virtual void setEnabled(bool enabled=true)
Definition: YWidget.cc:500
Definition: YMacroRecorder.h:38
bool beingDestroyed() const
Definition: YWidget.cc:258
bool hasWeight(YUIDimension dim)
Definition: YWidget.cc:590
YWidget * firstChild() const
Definition: YWidget.h:199
void setChildrenManager(YWidgetChildrenManager *manager)
Definition: YWidget.cc:166
bool hasChildren() const
Definition: YChildrenManager.h:61
bool hasChildren() const
Definition: YWidget.h:192
virtual const char * widgetClass() const
Definition: YWidget.h:72
YWidgetChildrenManager * childrenManager() const
Definition: YWidget.cc:159
ChildrenList::iterator begin()
Definition: YChildrenManager.h:76
T * lastChild()
Definition: YChildrenManager.h:119
Definition: YProperty.h:104
YWidgetListIterator end()
Definition: YWidget.h:245
void dumpDialogWidgetTree()
Definition: YWidget.cc:663
YWidgetListConstIterator childrenConstEnd() const
Definition: YWidget.h:231
void setNotifyContextMenu(bool notifyContextMenu=true)
Definition: YWidget.cc:528
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Definition: YWidget.cc:432
virtual bool stretchable(YUIDimension dim) const
Definition: YWidget.cc:572
virtual std::string debugLabel() const
Definition: YWidget.cc:223
void * widgetRep() const
Definition: YWidget.cc:486
virtual bool isEnabled() const
Definition: YWidget.cc:507
bool notify() const
Definition: YWidget.cc:534
Definition: YProperty.h:197
void dumpWidgetTree(int indentationLevel=0)
Definition: YWidget.cc:674
bool notifyContextMenu() const
Definition: YWidget.cc:540
void setAutoShortcut(bool _newAutoShortcut)
Definition: YWidget.cc:318
YWidget * parent() const
Definition: YWidget.cc:271
YWidget * findWidget(YWidgetID *id, bool doThrow=true) const
Definition: YWidget.cc:607
void deleteChildren()
Definition: YWidget.cc:202
virtual int preferredSize(YUIDimension dim)
Definition: YWidget.cc:546
void setHelpText(const std::string &helpText)
Definition: YWidget.cc:348
virtual void setFunctionKey(int fkey_no)
Definition: YWidget.cc:336
void setSendKeyEvents(bool doSend)
Definition: YWidget.cc:306
void setDisabled()
Definition: YWidget.h:426
YWidget(YWidget *parent)
Definition: YWidget.cc:106
std::string helpText() const
Definition: YWidget.cc:342
YDialog * findDialog()
Definition: YWidget.cc:376
Definition: YChildrenManager.h:37
virtual void startMultipleChanges()
Definition: YWidget.h:640
virtual void setSize(int newWidth, int newHeight)=0
virtual const YPropertySet & propertySet()
Definition: YWidget.cc:395
bool isValid() const
Definition: YWidget.cc:244
virtual void saveUserInput(YMacroRecorder *macroRecorder)
Definition: YWidget.cc:719
Definition: YWidget.cc:56
void setId(YWidgetID *newId_disown)
Definition: YWidget.cc:361
YWidgetID * id() const
Definition: YWidget.cc:355
void setWeight(YUIDimension dim, int weight)
Definition: YWidget.cc:584
virtual int preferredHeight()=0
int functionKey() const
Definition: YWidget.cc:324
virtual ~YWidget()
Definition: YWidget.cc:137
virtual int preferredWidth()=0
virtual YPropertyValue getProperty(const std::string &propertyName)
Definition: YWidget.cc:457
void setWidgetRep(void *toolkitWidgetRep)
Definition: YWidget.cc:493
void setBeingDestroyed()
Definition: YWidget.cc:264
void setDefaultStretchable(YUIDimension dim, bool newStretch)
Definition: YWidget.cc:566
YWidgetListConstIterator childrenConstBegin() const
Definition: YWidget.h:225
bool hasParent() const
Definition: YWidget.cc:278
bool hasId() const
Definition: YWidget.cc:370
void dumpWidget(YWidget *w, int indentationLevel)
Definition: YWidget.cc:692
virtual bool setKeyboardFocus()
Definition: YWidget.cc:599
virtual void addChild(YWidget *child)
Definition: YWidget.cc:176
void setChildrenEnabled(bool enabled)
Definition: YWidget.cc:643
bool contains(T *child) const
Definition: YChildrenManager.h:150
YWidgetListIterator childrenBegin() const
Definition: YWidget.h:212
Definition: YChildrenManager.h:173
virtual void setShortcutString(const std::string &str)
Definition: YWidget.cc:513
void setNotify(bool notify=true)
Definition: YWidget.cc:522
void setParent(YWidget *newParent)
Definition: YWidget.cc:285
YWidgetListIterator begin()
Definition: YWidget.h:238
YWidget * lastChild() const
Definition: YWidget.h:205
bool autoShortcut() const
Definition: YWidget.cc:312
bool hasFunctionKey() const
Definition: YWidget.cc:330
void setStretchable(YUIDimension dim, bool newStretch)
Definition: YWidget.cc:560
Definition: YChildrenManager.h:214
virtual void removeChild(YWidget *child)
Definition: YWidget.cc:191
Definition: YDialog.h:47
virtual int weight(YUIDimension dim)
Definition: YWidget.cc:578
Definition: YWidgetID.h:36
Definition: YWidget.h:54
ChildrenList::iterator end()
Definition: YChildrenManager.h:82
T * firstChild()
Definition: YChildrenManager.h:113
virtual const char * userInputProperty()
Definition: YWidget.h:576
bool contains(YWidget *child) const
Definition: YWidget.h:256
bool sendKeyEvents() const
Definition: YWidget.cc:300
int count() const
Definition: YChildrenManager.h:71
YWidgetListIterator childrenEnd() const
Definition: YWidget.h:218