libyui
 
Loading...
Searching...
No Matches
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
39class YDialog;
40class YWidgetID;
41class YMacroRecorder;
42
43
44typedef YChildrenManager<YWidget> YWidgetChildrenManager;
45typedef YSingleChildManager<YWidget> YSingleWidgetChildManager;
46typedef YChildrenRejector<YWidget> YWidgetChildrenRejector;
47
48class YWidgetPrivate;
49
50
55{
56protected:
61
62public:
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
200 { return childrenManager()->firstChild(); }
201
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
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
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
633 void operator delete( void * ptr ) noexcept;
634
635
636 // NCurses optimizations
637
638
645 virtual void startMultipleChanges() {}
646 virtual void doneMultipleChanges() {}
647
648
649protected:
650
654 YWidgetChildrenManager * childrenManager() const;
655
669 void setChildrenManager( YWidgetChildrenManager * manager );
670
679 void setBeingDestroyed();
680
685 void dumpWidget( YWidget *w, int indentationLevel );
686
687
688private:
689
693 void invalidate();
694
698 YWidget( const YWidget & other );
699
703 const YWidget & operator=( const YWidget & other );
704
705private:
706
707 //
708 // Data Members
709 //
710
711 int _magic; // should always be the first member
712 ImplPtr<YWidgetPrivate> priv;
713 static YPropertySet _propertySet;
714 static bool _usedOperatorNew;
715
716
717#include "YWidget_OptimizeChanges.h"
718
719};
720
721
722std::ostream & operator<<( std::ostream & stream, const YWidget * widget );
723
724
725#endif // YWidget_h
Definition YChildrenManager.h:38
T * lastChild()
Definition YChildrenManager.h:119
bool hasChildren() const
Definition YChildrenManager.h:61
ChildrenList::iterator end()
Definition YChildrenManager.h:82
int count() const
Definition YChildrenManager.h:71
T * firstChild()
Definition YChildrenManager.h:113
bool contains(T *child) const
Definition YChildrenManager.h:150
ChildrenList::iterator begin()
Definition YChildrenManager.h:76
Definition YChildrenManager.h:215
Definition YDialog.h:48
Definition YMacroRecorder.h:39
Definition YProperty.h:198
Definition YProperty.h:105
Definition YChildrenManager.h:174
Definition YWidgetID.h:37
Definition YWidget.h:55
bool hasChildren() const
Definition YWidget.h:192
virtual int preferredWidth()=0
bool hasParent() const
Definition YWidget.cc:284
void setParent(YWidget *newParent)
Definition YWidget.cc:291
void setId(YWidgetID *newId_disown)
Definition YWidget.cc:367
bool hasId() const
Definition YWidget.cc:376
void dumpWidgetTree(int indentationLevel=0)
Definition YWidget.cc:680
YWidgetID * id() const
Definition YWidget.cc:361
YDialog * findDialog()
Definition YWidget.cc:382
bool notifyContextMenu() const
Definition YWidget.cc:546
virtual const YPropertySet & propertySet()
Definition YWidget.cc:401
bool autoShortcut() const
Definition YWidget.cc:318
virtual const char * widgetClass() const
Definition YWidget.h:72
virtual void setShortcutString(const std::string &str)
Definition YWidget.cc:519
YWidgetListIterator end()
Definition YWidget.h:245
virtual void saveUserInput(YMacroRecorder *macroRecorder)
Definition YWidget.cc:725
YWidgetListIterator childrenBegin() const
Definition YWidget.h:212
bool isValid() const
Definition YWidget.cc:250
std::string helpText() const
Definition YWidget.cc:348
void setWeight(YUIDimension dim, int weight)
Definition YWidget.cc:590
void setHelpText(const std::string &helpText)
Definition YWidget.cc:354
void setWidgetRep(void *toolkitWidgetRep)
Definition YWidget.cc:499
YWidgetListIterator begin()
Definition YWidget.h:238
virtual bool setKeyboardFocus()
Definition YWidget.cc:605
YWidget * firstChild() const
Definition YWidget.h:199
virtual int preferredSize(YUIDimension dim)
Definition YWidget.cc:552
YWidgetListIterator childrenEnd() const
Definition YWidget.h:218
YWidgetChildrenManager * childrenManager() const
Definition YWidget.cc:165
YWidget * lastChild() const
Definition YWidget.h:205
int functionKey() const
Definition YWidget.cc:330
YWidget(YWidget *parent)
Definition YWidget.cc:106
virtual bool isEnabled() const
Definition YWidget.cc:513
YWidgetListConstIterator childrenConstBegin() const
Definition YWidget.h:225
bool sendKeyEvents() const
Definition YWidget.cc:306
YWidgetListConstIterator childrenConstEnd() const
Definition YWidget.h:231
void setNotifyContextMenu(bool notifyContextMenu=true)
Definition YWidget.cc:534
bool contains(YWidget *child) const
Definition YWidget.h:256
YWidget * findWidget(YWidgetID *id, bool doThrow=true) const
Definition YWidget.cc:613
void setNotify(bool notify=true)
Definition YWidget.cc:528
virtual void addChild(YWidget *child)
Definition YWidget.cc:182
virtual void setSize(int newWidth, int newHeight)=0
void setAutoShortcut(bool _newAutoShortcut)
Definition YWidget.cc:324
void deleteChildren()
Definition YWidget.cc:208
void setDefaultStretchable(YUIDimension dim, bool newStretch)
Definition YWidget.cc:572
virtual void startMultipleChanges()
Definition YWidget.h:645
void setSendKeyEvents(bool doSend)
Definition YWidget.cc:312
bool notify() const
Definition YWidget.cc:540
YWidget * parent() const
Definition YWidget.cc:277
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Definition YWidget.cc:438
void setDisabled()
Definition YWidget.h:426
virtual std::string shortcutString() const
Definition YWidget.h:560
void setChildrenManager(YWidgetChildrenManager *manager)
Definition YWidget.cc:172
void dumpWidget(YWidget *w, int indentationLevel)
Definition YWidget.cc:698
virtual ~YWidget()
Definition YWidget.cc:143
void dumpDialogWidgetTree()
Definition YWidget.cc:669
virtual int weight(YUIDimension dim)
Definition YWidget.cc:584
virtual void setFunctionKey(int fkey_no)
Definition YWidget.cc:342
bool beingDestroyed() const
Definition YWidget.cc:264
virtual void setEnabled(bool enabled=true)
Definition YWidget.cc:506
virtual std::string debugLabel() const
Definition YWidget.cc:229
void setChildrenEnabled(bool enabled)
Definition YWidget.cc:649
virtual void removeChild(YWidget *child)
Definition YWidget.cc:197
void * widgetRep() const
Definition YWidget.cc:492
virtual YPropertyValue getProperty(const std::string &propertyName)
Definition YWidget.cc:463
int childrenCount() const
Definition YWidget.h:251
virtual const char * userInputProperty()
Definition YWidget.h:576
virtual int preferredHeight()=0
bool hasFunctionKey() const
Definition YWidget.cc:336
bool hasWeight(YUIDimension dim)
Definition YWidget.cc:596
void setBeingDestroyed()
Definition YWidget.cc:270
virtual bool stretchable(YUIDimension dim) const
Definition YWidget.cc:578
void setStretchable(YUIDimension dim, bool newStretch)
Definition YWidget.cc:566
Definition YWidget.cc:57