libyui  3.3.2
YWidget Class Referenceabstract

Abstract base class of all UI widgets. More...

#include <YWidget.h>

Inheritance diagram for YWidget:

Classes

class  OptimizeChanges
 Helper class that calls startMultipleChanges() in its constructor and cares about the necessary call to doneMultipleChanges() when it goes out of scope. More...
 

Public Member Functions

virtual ~YWidget ()
 Destructor.
 
virtual const char * widgetClass () const
 Returns a descriptive name of this widget class for logging, debugging etc.
 
virtual std::string debugLabel () const
 Returns a descriptive label of this widget instance. More...
 
std::string helpText () const
 Return the help text for this widget.
 
void setHelpText (const std::string &helpText)
 Set a help text for this widget. More...
 
virtual const YPropertySetpropertySet ()
 Return this class's property set. More...
 
virtual bool setProperty (const std::string &propertyName, const YPropertyValue &val)
 Set a property. More...
 
virtual YPropertyValue getProperty (const std::string &propertyName)
 Get a property. More...
 
bool hasChildren () const
 Returns 'true' if this widget has any children.
 
YWidgetfirstChild () const
 Returns the first child or 0 if there is none. More...
 
YWidgetlastChild () const
 Returns the last child or 0 if there is none.
 
YWidgetListIterator childrenBegin () const
 Return an iterator that points to the first child or to childrenEnd() if there are no children.
 
YWidgetListIterator childrenEnd () const
 Return an interator that points after the last child.
 
YWidgetListConstIterator childrenConstBegin () const
 Return a const iterator that points to the first child or to childrenEnd() if there are no children.
 
YWidgetListConstIterator childrenConstEnd () const
 Return a const interator that points after the last child.
 
YWidgetListIterator begin ()
 A helper for the range-based "for" loop. More...
 
YWidgetListIterator end ()
 A helper for the range-based "for" loop. More...
 
int childrenCount () const
 Returns the current number of children.
 
bool contains (YWidget *child) const
 Checks if 'child' is a (direct!) child of this widget.
 
virtual void addChild (YWidget *child)
 Add a new child. More...
 
virtual void removeChild (YWidget *child)
 Remove a child. More...
 
void deleteChildren ()
 Delete all children and remove them from the children manager's list.
 
YWidgetparent () const
 Return this widget's parent or 0 if it doesn't have a parent.
 
bool hasParent () const
 Return 'true' if this widget has a parent, 'false' if not.
 
void setParent (YWidget *newParent)
 Set this widget's parent.
 
YDialogfindDialog ()
 Traverse up the widget hierarchy and find the dialog this widget belongs to. More...
 
YWidgetfindWidget (YWidgetID *id, bool doThrow=true) const
 Recursively find a widget by its ID. More...
 
virtual int preferredWidth ()=0
 Preferred width of the widget. More...
 
virtual int preferredHeight ()=0
 Preferred height of the widget. More...
 
virtual int preferredSize (YUIDimension dim)
 Preferred size of the widget in the specified dimension. More...
 
virtual void setSize (int newWidth, int newHeight)=0
 Set the new size of the widget. More...
 
bool isValid () const
 Checks whether or not this object is valid. More...
 
bool beingDestroyed () const
 Check if this widget is in the process of being destroyed.
 
void * widgetRep () const
 Return a pointer to the underlying toolkit's (Qt, ...) widget representing this abstract UI widget.
 
void setWidgetRep (void *toolkitWidgetRep)
 Set the pointer to the underlying toolkit's (Qt, ...) widget representing this abstract UI widget. More...
 
bool hasId () const
 Returns 'true' if this widget has an ID.
 
YWidgetIDid () const
 Returns this widget's ID.
 
void setId (YWidgetID *newId_disown)
 Set this widget's ID. More...
 
virtual void setEnabled (bool enabled=true)
 Enable or disable this widget, i.e. More...
 
void setDisabled ()
 Disable this widget (overloaded for better readability).
 
virtual bool isEnabled () const
 Returns 'true' if this widget is enabled.
 
virtual bool stretchable (YUIDimension dim) const
 This is a boolean value that determines whether the widget is resizable beyond its preferred size in the specified dimension. More...
 
void setStretchable (YUIDimension dim, bool newStretch)
 Set the stretchable state to "newStretch" regardless of any hstretch or vstretch options.
 
void setDefaultStretchable (YUIDimension dim, bool newStretch)
 Set the stretchable state to "newStretch". More...
 
virtual int weight (YUIDimension dim)
 The weight is used in situations where all widgets can get their preferred size and yet space is available. More...
 
bool hasWeight (YUIDimension dim)
 Return whether or not the widget has a weight in the specified dimension.
 
void setWeight (YUIDimension dim, int weight)
 Set a weight in the specified dimension.
 
void setNotify (bool notify=true)
 Sets the Notify property.
 
bool notify () const
 Returns whether the widget will notify, i.e. More...
 
void setNotifyContextMenu (bool notifyContextMenu=true)
 Sets the notifyContextMenu property.
 
bool notifyContextMenu () const
 Returns whether the widget will send an event when the user clicks selects the context menu e.g. More...
 
bool sendKeyEvents () const
 Returns 'true' if this widget should send key events, i.e. More...
 
void setSendKeyEvents (bool doSend)
 Specify whether or not this widget should send key events.
 
bool autoShortcut () const
 Returns 'true' if a keyboard shortcut should automatically be assigned to this widget - without complaints in the log file.
 
void setAutoShortcut (bool _newAutoShortcut)
 Sets the 'autoShortcut' flag.
 
int functionKey () const
 Return a function key number that is assigned to this widget. More...
 
bool hasFunctionKey () const
 Check if a function key is assigned to this widget.
 
virtual void setFunctionKey (int fkey_no)
 Assign a function key to this widget (1 for F1, 2 for F2, etc. More...
 
virtual bool setKeyboardFocus ()
 Set the keyboard focus to this widget. More...
 
virtual std::string shortcutString () const
 Get the string of this widget that holds the keyboard shortcut, if any. More...
 
virtual void setShortcutString (const std::string &str)
 Set the string of this widget that holds the keyboard shortcut, if any. More...
 
virtual const char * userInputProperty ()
 The name of the widget property that will return user input, if there is any. More...
 
void dumpWidgetTree (int indentationLevel=0)
 Debugging function: Dump the widget tree from here on to the log file.
 
void dumpDialogWidgetTree ()
 Debugging function: Dump the widget tree from this widget's dialog parent. More...
 
void setChildrenEnabled (bool enabled)
 Enable or disable all widgets in this widget tree.
 
virtual void saveUserInput (YMacroRecorder *macroRecorder)
 Recursively save the user input of all child widgets to a macro recorder: More...
 
void * operator new (size_t size)
 Overloaded operator new to ensure widgets are always created on the heap, never on the stack. More...
 
virtual void startMultipleChanges ()
 In some UIs updating the screen content is an expensive operation. More...
 
virtual void doneMultipleChanges ()
 

Protected Member Functions

 YWidget (YWidget *parent)
 Constructor.
 
YWidgetChildrenManagerchildrenManager () const
 Returns this widget's children manager.
 
void setChildrenManager (YWidgetChildrenManager *manager)
 Sets a new children manager for this widget. More...
 
void setBeingDestroyed ()
 Set the "being destroyed" flag, i.e. More...
 
void dumpWidget (YWidget *w, int indentationLevel)
 Helper function for dumpWidgetTree(): Dump one widget to the log file.
 

Detailed Description

Abstract base class of all UI widgets.

Definition at line 54 of file YWidget.h.

Member Function Documentation

◆ addChild()

void YWidget::addChild ( YWidget child)
virtual

Add a new child.

This may throw exceptions if more children are added than this widget can handle.

Reimplemented in YAlignment.

Definition at line 174 of file YWidget.cc.

Here is the call graph for this function:

◆ begin()

YWidgetListIterator YWidget::begin ( )
inline

A helper for the range-based "for" loop.

Returns
Iterator pointing to the beginning of the children list

Definition at line 238 of file YWidget.h.

Here is the call graph for this function:

◆ debugLabel()

std::string YWidget::debugLabel ( ) const
virtual

Returns a descriptive label of this widget instance.

This default implementation returns this widget's "shortcut property" (possibly trunctated to avoid over-long texts) - the property that contains the keyboard shortcut used to activate this widget or to move the keyboard focus to it. In most cases this is this widget's label.

Note: This is usually translated to the user's target language. This makes this useful for debugging only.

Reimplemented in YLabel, and YDumbTab.

Definition at line 221 of file YWidget.cc.

Here is the call graph for this function:

◆ dumpDialogWidgetTree()

void YWidget::dumpDialogWidgetTree ( )

Debugging function: Dump the widget tree from this widget's dialog parent.

If there is no such dialog parent, dump the widget tree from here on.

Definition at line 658 of file YWidget.cc.

Here is the call graph for this function:

◆ end()

YWidgetListIterator YWidget::end ( )
inline

A helper for the range-based "for" loop.

Returns
Iterator pointing to the end of the children list

Definition at line 245 of file YWidget.h.

Here is the call graph for this function:

◆ findDialog()

YDialog * YWidget::findDialog ( )

Traverse up the widget hierarchy and find the dialog this widget belongs to.

Returns 0 if there is none.

Definition at line 374 of file YWidget.cc.

Here is the call graph for this function:

◆ findWidget()

YWidget * YWidget::findWidget ( YWidgetID id,
bool  doThrow = true 
) const

Recursively find a widget by its ID.

If there is no widget with that ID, this function throws a YUIWidgetNotFoundException if 'doThrow' is 'true'. It returns 0 if 'doThrow' is 'false'.

Definition at line 602 of file YWidget.cc.

Here is the call graph for this function:

◆ firstChild()

YWidget* YWidget::firstChild ( ) const
inline

Returns the first child or 0 if there is none.

Useful mostly for children managers that handle only one child.

Definition at line 199 of file YWidget.h.

Here is the call graph for this function:

◆ functionKey()

int YWidget::functionKey ( ) const

Return a function key number that is assigned to this widget.

(1 for F1, 2 for F2, etc.; 0 for none)

Definition at line 322 of file YWidget.cc.

◆ getProperty()

YPropertyValue YWidget::getProperty ( const std::string &  propertyName)
virtual

Get a property.

Derived classes need to implement this.

This method may throw exceptions, for example

  • if there is no property with that name

Reimplemented in YWizard, YComboBox, YPushButton, YTable, YCheckBoxFrame, YInputField, YCheckBox, YPartitionSplitter, YLogView, YIntField, YRadioButton, YRichText, YBarGraph, YMultiProgressMeter, YLabel, YMenuButton, YMultiLineEdit, YContextMenu, YDownloadProgress, YTree, YSelectionBox, YBusyIndicator, YRadioButtonGroup, YProgressBar, YDumbTab, YSimpleInputField, YGraph, YFrame, YMultiSelectionBox, and YTimezoneSelector.

Definition at line 453 of file YWidget.cc.

Here is the call graph for this function:

◆ isValid()

bool YWidget::isValid ( ) const

Checks whether or not this object is valid.

This is to enable dangling pointer error checking (i.e. this object is already deallocated, but a pointer to it is still in use).

See also the YUI_CHECK_WIDGET() macro in YUIException.h

Definition at line 242 of file YWidget.cc.

◆ notify()

bool YWidget::notify ( ) const

Returns whether the widget will notify, i.e.

will case UserInput to return.

Definition at line 529 of file YWidget.cc.

◆ notifyContextMenu()

bool YWidget::notifyContextMenu ( ) const

Returns whether the widget will send an event when the user clicks selects the context menu e.g.

via right click.

Definition at line 535 of file YWidget.cc.

◆ operator new()

void * YWidget::operator new ( size_t  size)

Overloaded operator new to ensure widgets are always created on the heap, never on the stack.

Simpler implementations of this have a tendency to be fooled by poorly implemented derived classes.

Definition at line 128 of file YWidget.cc.

◆ preferredHeight()

virtual int YWidget::preferredHeight ( )
pure virtual

Preferred height of the widget.

Derived classes are required to implement this.

Implemented in YButtonBox, YAlignment, YLayoutBox, YSpacing, YEmpty, and YSingleChildContainerWidget.

◆ preferredSize()

int YWidget::preferredSize ( YUIDimension  dim)
virtual

Preferred size of the widget in the specified dimension.

This default implementation calls preferredWidth() or preferredHeight() which makes sense for most cases.

Derived classes can reimplement this, but this is discouraged.

Note: Even in that case, preferredWidth() and preferredHeight() need to be implemented, but they might then call preferredSize().

Reimplemented in YLayoutBox.

Definition at line 541 of file YWidget.cc.

◆ preferredWidth()

virtual int YWidget::preferredWidth ( )
pure virtual

Preferred width of the widget.

Derived classes are required to implement this.

Implemented in YButtonBox, YAlignment, YLayoutBox, YSpacing, YEmpty, and YSingleChildContainerWidget.

◆ propertySet()

const YPropertySet & YWidget::propertySet ( )
virtual

Return this class's property set.

This also initializes the property upon the first call.

Derived classes should reimplement this.

Remember to add the base class's property set to your own in reimplemented versions, e.g.:

const YPropertySet &
MyWidgetClass::propertySet()
{
    static YPropertySet propSet;

    if ( propSet.isEmpty() )
    {
        // Add properties for the derived class
       propSet.add( YProperty( YUIProperty_Value, YStringProperty ) );
       propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );

        // Add base class properties
       propSet.add( YWidget::propertySet() );
    }

    return propSet;
}

Otherwise the base class's properties will not be available in the derived class. It is also important that the base class's properties are added after those of the derived class so the derived class's properties have priority over those of the base class.

Reimplemented in YWizard, YComboBox, YPushButton, YTable, YCheckBoxFrame, YInputField, YCheckBox, YPartitionSplitter, YLogView, YIntField, YRadioButton, YRichText, YBarGraph, YMultiProgressMeter, YLabel, YMenuButton, YMultiLineEdit, YContextMenu, YDownloadProgress, YTree, YSelectionBox, YBusyIndicator, YRadioButtonGroup, YProgressBar, YDumbTab, YSimpleInputField, YGraph, YFrame, YMultiSelectionBox, and YTimezoneSelector.

Definition at line 393 of file YWidget.cc.

Here is the call graph for this function:

◆ removeChild()

void YWidget::removeChild ( YWidget child)
virtual

Remove a child.

This only removes the child from the children manager's list; it does not delete it.

Definition at line 189 of file YWidget.cc.

Here is the call graph for this function:

◆ saveUserInput()

void YWidget::saveUserInput ( YMacroRecorder macroRecorder)
virtual

Recursively save the user input of all child widgets to a macro recorder:

All child widgets that could contain data entered by the user are requested to send their contents to the macro recorder, e.g. input fields, check boxes etc.

This default implementation records this widget's user input property (the property returned by userInputProperty) and then recursively calls saveUserInput() for all child widgets. This is suitable for most cases, for container widgets as well as for leaf widgets that have no or exactly one property that needs to be recorded.

Widgets that need another number of properties recorded should reimplement this method (and NOT call this default method in the new implementation).

Reimplemented in YInputField, YRadioButton, and YMultiSelectionBox.

Definition at line 714 of file YWidget.cc.

Here is the call graph for this function:

◆ sendKeyEvents()

bool YWidget::sendKeyEvents ( ) const

Returns 'true' if this widget should send key events, i.e.

if it has opt(keyEvent) set.

Definition at line 298 of file YWidget.cc.

◆ setBeingDestroyed()

void YWidget::setBeingDestroyed ( )
protected

Set the "being destroyed" flag, i.e.

indicate that this widget is in the process of being destroyed. The base class method already sets this, but sometimes it might be useful to call this in a derived class's destructor so certain optimizations work better.

This status intentionally cannot be reverted to "not being destroyed".

Definition at line 262 of file YWidget.cc.

◆ setChildrenManager()

void YWidget::setChildrenManager ( YWidgetChildrenManager manager)
protected

Sets a new children manager for this widget.

The widget assumes ownership of this children manager and will delete it when appropriate.

The default children manager (a YWidgetChildrenRejector) rejects all children. This is useful for leaf widgets such as PushButton, ComboBox etc.

Derived classes that can handle children might want to set the children manager to a YWidgetChildrenManager (the base class that does not reject children) or to a YSingleWidgetChildManager (the class that handles exactly one child widget).

Definition at line 164 of file YWidget.cc.

◆ setDefaultStretchable()

void YWidget::setDefaultStretchable ( YUIDimension  dim,
bool  newStretch 
)

Set the stretchable state to "newStretch".

hstretch orvstretch options may override this.

Definition at line 561 of file YWidget.cc.

◆ setEnabled()

void YWidget::setEnabled ( bool  enabled = true)
virtual

Enable or disable this widget, i.e.

make it accept or reject user input.

Derived classes should call the base class method to update the internal "enabled" flag.

Definition at line 495 of file YWidget.cc.

◆ setFunctionKey()

void YWidget::setFunctionKey ( int  fkey_no)
virtual

Assign a function key to this widget (1 for F1, 2 for F2, etc.

; 0 for none)

Derived classes may want to overwrite this function, but they should call this base class function in the new function.

Reimplemented in YPushButton.

Definition at line 334 of file YWidget.cc.

◆ setHelpText()

void YWidget::setHelpText ( const std::string &  helpText)

Set a help text for this widget.

Currently, the UI does not do anything with this text but store it. Displaying the text at a convenient time is currently the application's responsibility. This may change in future versions.

Definition at line 346 of file YWidget.cc.

Here is the call graph for this function:

◆ setId()

void YWidget::setId ( YWidgetID newId_disown)

Set this widget's ID.

The widget assumes ownership of this ID and will delete it when needed. (In the widget's destructor or when a new ID is set)

Widget IDs are purely for application use. C++ applications don't need to use them; they are much better off using widget pointers. For other languages, though, that can't use C++ pointers (e.g. Ruby) it makes sense to have widget IDs to identify widgets.

Definition at line 359 of file YWidget.cc.

◆ setKeyboardFocus()

bool YWidget::setKeyboardFocus ( )
virtual

Set the keyboard focus to this widget.

The default implementation just emits a warning message. Overwrite this function for all widgets that can accept the keyboard focus.

This function returns true if the widget did accept the keyboard focus, and false if not.

Definition at line 594 of file YWidget.cc.

◆ setProperty()

bool YWidget::setProperty ( const std::string &  propertyName,
const YPropertyValue val 
)
virtual

Set a property.

Derived classes need to implement this.

This method may throw exceptions, for example

  • if there is no property with that name
  • if the expected type and the type mismatch
  • if the value is out of range

This function returns 'true' if the value was successfully set and 'false' if that value requires special handling (not in error cases: those are covered by exceptions).

Reimplemented in YComboBox, YPushButton, YTable, YCheckBoxFrame, YInputField, YCheckBox, YPartitionSplitter, YLogView, YIntField, YRadioButton, YRichText, YBarGraph, YMultiProgressMeter, YLabel, YMenuButton, YMultiLineEdit, YContextMenu, YDownloadProgress, YTree, YSelectionBox, YBusyIndicator, YRadioButtonGroup, YProgressBar, YDumbTab, YSimpleInputField, YGraph, YFrame, YMultiSelectionBox, and YTimezoneSelector.

Definition at line 428 of file YWidget.cc.

Here is the call graph for this function:

◆ setShortcutString()

void YWidget::setShortcutString ( const std::string &  str)
virtual

Set the string of this widget that holds the keyboard shortcut, if any.

Most widgets will call setLabel().

Overwrite this for widgets that can have keyboard shortcuts.

Reimplemented in YSelectionWidget, YPushButton, YInputField, YCheckBox, YLogView, YIntField, YRadioButton, YMultiLineEdit, YCheckBoxFrame, YDumbTab, and YSimpleInputField.

Definition at line 508 of file YWidget.cc.

Here is the call graph for this function:

◆ setSize()

virtual void YWidget::setSize ( int  newWidth,
int  newHeight 
)
pure virtual

Set the new size of the widget.

Layout manager widgets (like YLayoutBox) call this during geometry management after all widgets are queried about their preferred widths and heights. Depending on layout constraints, widgets might be resized beyond or below their preferred size.

The sizes passed here are not meant to affect any future preferredWidth() or preferredHeight() calls; they are just the outcome of all kinds of compromises (too little screen space or too much) for the current geometry management calculation.

Derived classes are required to implement this function.

Implemented in YButtonBox, YAlignment, YLayoutBox, and YSingleChildContainerWidget.

◆ setWidgetRep()

void YWidget::setWidgetRep ( void *  toolkitWidgetRep)

Set the pointer to the underlying toolkit's (Qt, ...) widget representing this abstract UI widget.

This pointer might be useful for derived UIs to store a counterpart of the toolkit widget in each YWidget. The abstract UI does not need that, though; this is purely for the convenience of derived UIs. All the abstract UI ever does with that pointer is store it.

Definition at line 488 of file YWidget.cc.

◆ shortcutString()

virtual std::string YWidget::shortcutString ( ) const
inlinevirtual

Get the string of this widget that holds the keyboard shortcut, if any.

Most widgets will return label().

Overwrite this for widgets that can have keyboard shortcuts.

Reimplemented in YSelectionWidget, YPushButton, YInputField, YCheckBox, YLogView, YIntField, YRadioButton, YMultiLineEdit, YCheckBoxFrame, YDumbTab, and YSimpleInputField.

Definition at line 560 of file YWidget.h.

Here is the call graph for this function:

◆ startMultipleChanges()

virtual void YWidget::startMultipleChanges ( )
inlinevirtual

In some UIs updating the screen content is an expensive operation.

Use startMultipleChanges() to tell the ui that you're going to perform multiple chages to the widget. The UI may delay any screen updates until doneMultipleChanges() is called.

Definition at line 640 of file YWidget.h.

Here is the call graph for this function:

◆ stretchable()

bool YWidget::stretchable ( YUIDimension  dim) const
virtual

This is a boolean value that determines whether the widget is resizable beyond its preferred size in the specified dimension.

A selection box is stretchable in both dimensions, a push button is not stretchable by default, a frame is stretchable if its contents are stretchable. Most widgets accept a hstretch orvstretch option to become stretchable even when by default they are not.

Reimplemented in YButtonBox, YAlignment, YDumbTab, YLayoutBox, YSquash, and YSingleChildContainerWidget.

Definition at line 567 of file YWidget.cc.

◆ userInputProperty()

virtual const char* YWidget::userInputProperty ( )
inlinevirtual

The name of the widget property that will return user input, if there is any.

Widgets that do have user input (such as InputField, ComboBox, SelBox) should overwrite this methods. Widgets that are purely passive (such as Label, RichText) should not.

Reimplemented in YComboBox, YInputField, YCheckBox, YTable, YIntField, YRadioButton, YPartitionSplitter, YMultiLineEdit, YTree, YSelectionBox, YCheckBoxFrame, YSimpleInputField, and YMultiSelectionBox.

Definition at line 576 of file YWidget.h.

Here is the call graph for this function:

◆ weight()

int YWidget::weight ( YUIDimension  dim)
virtual

The weight is used in situations where all widgets can get their preferred size and yet space is available.

The remaining space will be devided between all stretchable widgets according to their weights. A widget with greater weight will get more space. The default weight for all widgets is 0.

Derived classes can overwrite this function, but they should call this base class function in the new function.

Definition at line 573 of file YWidget.cc.


The documentation for this class was generated from the following files: