libyui
Classes | Public Member Functions | Protected Member Functions

YWidget Class Reference

#include <YWidget.h>

Inheritance diagram for YWidget:
YBarGraph YBusyIndicator YButtonBox YCheckBox YDownloadProgress YEmpty YGraph YImage YInputField YIntField YLabel YLayoutBox YLogView YMultiLineEdit YMultiProgressMeter YPackageSelector YPartitionSplitter YProgressBar YPushButton YRadioButton YRichText YSelectionWidget YSimpleInputField YSingleChildContainerWidget YSpacing YTimezoneSelector YWizard

List of all members.

Classes

class  OptimizeChanges

Public Member Functions

virtual ~YWidget ()
virtual const char * widgetClass () const
virtual string debugLabel () const
string helpText () const
void setHelpText (const string &helpText)
virtual const YPropertySetpropertySet ()
virtual bool setProperty (const string &propertyName, const YPropertyValue &val)
virtual YPropertyValue getProperty (const string &propertyName)
bool hasChildren () const
YWidgetfirstChild () const
YWidgetlastChild () const
YWidgetListConstIterator childrenBegin () const
YWidgetListConstIterator childrenEnd () const
int childrenCount () const
bool contains (YWidget *child) const
virtual void addChild (YWidget *child)
virtual void removeChild (YWidget *child)
void deleteChildren ()
YWidgetparent () const
bool hasParent () const
void setParent (YWidget *newParent)
YDialogfindDialog ()
YWidgetfindWidget (YWidgetID *id, bool doThrow=true) const
virtual int preferredWidth ()=0
virtual int preferredHeight ()=0
virtual int preferredSize (YUIDimension dim)
virtual void setSize (int newWidth, int newHeight)=0
bool isValid () const
bool beingDestroyed () const
void * widgetRep () const
void setWidgetRep (void *toolkitWidgetRep)
bool hasId () const
YWidgetIDid () const
void setId (YWidgetID *newId_disown)
virtual void setEnabled (bool enabled=true)
void setDisabled ()
virtual bool isEnabled () const
virtual bool stretchable (YUIDimension dim) const
void setStretchable (YUIDimension dim, bool newStretch)
void setDefaultStretchable (YUIDimension dim, bool newStretch)
virtual int weight (YUIDimension dim)
bool hasWeight (YUIDimension dim)
void setWeight (YUIDimension dim, int weight)
void setNotify (bool notify=true)
bool notify () const
void setNotifyContextMenu (bool notifyContextMenu=true)
bool notifyContextMenu () const
bool sendKeyEvents () const
void setSendKeyEvents (bool doSend)
bool autoShortcut () const
void setAutoShortcut (bool _newAutoShortcut)
int functionKey () const
bool hasFunctionKey () const
virtual void setFunctionKey (int fkey_no)
virtual bool setKeyboardFocus ()
virtual string shortcutString () const
virtual void setShortcutString (const string &str)
virtual const char * userInputProperty ()
void dumpWidgetTree (int indentationLevel=0)
void dumpDialogWidgetTree ()
void setChildrenEnabled (bool enabled)
virtual void saveUserInput (YMacroRecorder *macroRecorder)
void * operator new (size_t size)
virtual void startMultipleChanges ()
virtual void doneMultipleChanges ()

Protected Member Functions

 YWidget (YWidget *parent)
YWidgetChildrenManagerchildrenManager () const
void setChildrenManager (YWidgetChildrenManager *manager)
void setBeingDestroyed ()
void dumpWidget (YWidget *w, int indentationLevel)

Detailed Description

Abstract base class of all UI widgets


Constructor & Destructor Documentation

YWidget::YWidget ( YWidget parent) [protected]

Constructor.

YWidget::~YWidget ( ) [virtual]

Destructor.


Member Function Documentation

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.

bool YWidget::autoShortcut ( ) const

Returns 'true' if a keyboard shortcut should automatically be assigned to this widget - without complaints in the log file.

bool YWidget::beingDestroyed ( ) const

Check if this widget is in the process of being destroyed.

YWidgetListConstIterator YWidget::childrenBegin ( ) const [inline]

Return an iterator that points to the first child or to childrenEnd() if there are no children.

int YWidget::childrenCount ( ) const [inline]

Returns the current number of children.

YWidgetListConstIterator YWidget::childrenEnd ( ) const [inline]

Return an interator that points after the last child.

YWidgetChildrenManager * YWidget::childrenManager ( ) const [protected]

Returns this widget's children manager.

bool YWidget::contains ( YWidget child) const [inline]

Checks if 'child' is a (direct!) child of this widget.

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 YDumbTab, and YLabel.

void YWidget::deleteChildren ( )

Delete all children and remove them from the children manager's list.

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.

void YWidget::dumpWidget ( YWidget w,
int  indentationLevel 
) [protected]

Helper function for dumpWidgetTree(): Dump one widget to the log file.

void YWidget::dumpWidgetTree ( int  indentationLevel = 0)

Debugging function: Dump the widget tree from here on to the log file.

YDialog * YWidget::findDialog ( )

Traverse up the widget hierarchy and find the dialog this widget belongs to. Returns 0 if there is none.

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'.

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.

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)

virtual YPropertyValue YWidget::getProperty ( const 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 YBarGraph, YBusyIndicator, YCheckBox, YCheckBoxFrame, YComboBox, YContextMenu, YDownloadProgress, YDumbTab, YFrame, YGraph, YInputField, YIntField, YLogView, YMenuButton, YMultiLineEdit, YMultiProgressMeter, YMultiSelectionBox, YPartitionSplitter, YProgressBar, YPushButton, YRadioButton, YRichText, YSelectionBox, YSimpleInputField, YTable, YTimezoneSelector, YTree, and YWizard.

bool YWidget::hasChildren ( ) const [inline]

Returns 'true' if this widget has any children.

bool YWidget::hasFunctionKey ( ) const

Check if a function key is assigned to this widget.

bool YWidget::hasId ( ) const

Returns 'true' if this widget has an ID.

bool YWidget::hasParent ( ) const

Return 'true' if this widget has a parent, 'false' if not.

bool YWidget::hasWeight ( YUIDimension  dim)

Return whether or not the widget has a weight in the specified dimension.

string YWidget::helpText ( ) const

Return the help text for this widget.

YWidgetID * YWidget::id ( ) const

Returns this widget's ID.

bool YWidget::isEnabled ( ) const [virtual]

Returns 'true' if this widget is enabled.

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

YWidget* YWidget::lastChild ( ) const [inline]

Returns the last child or 0 if there is none.

bool YWidget::notify ( ) const

Returns whether the widget will notify, i.e. will case UserInput to return.

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.

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.

YWidget * YWidget::parent ( ) const

Return this widget's parent or 0 if it doesn't have a parent.

virtual int YWidget::preferredHeight ( ) [pure virtual]

Preferred height of the widget.

Derived classes are required to implement this.

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

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.

virtual int YWidget::preferredWidth ( ) [pure virtual]

Preferred width of the widget.

Derived classes are required to implement this.

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

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 YBarGraph, YBusyIndicator, YCheckBox, YCheckBoxFrame, YComboBox, YContextMenu, YDownloadProgress, YDumbTab, YFrame, YGraph, YInputField, YIntField, YLabel, YLogView, YMenuButton, YMultiLineEdit, YMultiProgressMeter, YMultiSelectionBox, YPartitionSplitter, YProgressBar, YPushButton, YRadioButton, YRadioButtonGroup, YRichText, YSelectionBox, YSimpleInputField, YTable, YTimezoneSelector, YTree, and YWizard.

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.

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, YMultiSelectionBox, and YRadioButton.

bool YWidget::sendKeyEvents ( ) const

Returns 'true' if this widget should send key events, i.e. if it has `opt(`keyEvent) set.

void YWidget::setAutoShortcut ( bool  _newAutoShortcut)

Sets the 'autoShortcut' flag.

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".

void YWidget::setChildrenEnabled ( bool  enabled)

Enable or disable all widgets in this widget tree.

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).

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

Set the stretchable state to "newStretch". `hstretch or `vstretch options may override this.

void YWidget::setDisabled ( ) [inline]

Disable this widget (overloaded for better readability).

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.

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.

void YWidget::setHelpText ( const 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.

Reimplemented in YWizard.

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., YCP) it makes sense to have widget IDs to identify widgets.

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.

void YWidget::setNotify ( bool  notify = true)

Sets the Notify property

void YWidget::setNotifyContextMenu ( bool  notifyContextMenu = true)

Sets the notifyContextMenu property

void YWidget::setParent ( YWidget newParent)

Set this widget's parent.

bool YWidget::setProperty ( const 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 YBarGraph, YBusyIndicator, YCheckBox, YCheckBoxFrame, YComboBox, YContextMenu, YDownloadProgress, YDumbTab, YFrame, YGraph, YInputField, YIntField, YLabel, YLogView, YMenuButton, YMultiLineEdit, YMultiProgressMeter, YMultiSelectionBox, YPartitionSplitter, YProgressBar, YPushButton, YRadioButton, YRadioButtonGroup, YRichText, YSelectionBox, YSimpleInputField, YTable, YTimezoneSelector, and YTree.

void YWidget::setSendKeyEvents ( bool  doSend)

Specify whether or not this widget should send key events.

void YWidget::setShortcutString ( const 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 YCheckBox, YCheckBoxFrame, YDumbTab, YInputField, YIntField, YLogView, YMultiLineEdit, YPushButton, YRadioButton, YSelectionWidget, and YSimpleInputField.

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 YAlignment, YButtonBox, YLayoutBox, and YSingleChildContainerWidget.

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

Set the stretchable state to "newStretch" regardless of any `hstretch or `vstretch options.

void YWidget::setWeight ( YUIDimension  dim,
int  weight 
)

Set a weight in the specified dimension.

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.

virtual string YWidget::shortcutString ( ) const [inline, virtual]

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 YCheckBox, YCheckBoxFrame, YDumbTab, YInputField, YIntField, YLogView, YMultiLineEdit, YPushButton, YRadioButton, YSelectionWidget, and YSimpleInputField.

virtual void YWidget::startMultipleChanges ( ) [inline, virtual]

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.

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 or `vstretch option to become stretchable even when by default they are not.

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

virtual const char* YWidget::userInputProperty ( ) [inline, virtual]

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 YCheckBox, YCheckBoxFrame, YComboBox, YInputField, YIntField, YMultiLineEdit, YMultiSelectionBox, YPartitionSplitter, YRadioButton, YSelectionBox, YSimpleInputField, YTable, and YTree.

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.

virtual const char* YWidget::widgetClass ( ) const [inline, virtual]
void * YWidget::widgetRep ( ) const

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


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations Friends