libyui  3.12.1
YMenuWidget Class Referenceabstract

Abstract base class for widgets that handle menus, e.g. More...

#include <YMenuWidget.h>

Inheritance diagram for YMenuWidget:
Collaboration diagram for YMenuWidget:

Public Member Functions

virtual ~YMenuWidget ()
 Destructor.
 
virtual const char * widgetClass () const
 Returns a descriptive name of this widget class for logging, debugging etc.
 
virtual void rebuildMenuTree ()=0
 Rebuild the displayed menu tree from the internally stored YMenuItems. More...
 
virtual void addItems (const YItemCollection &itemCollection)
 Add multiple items. More...
 
virtual void addItem (YItem *item_disown)
 Add one item. More...
 
virtual void deleteAllItems ()
 Delete all items. More...
 
void resolveShortcutConflicts ()
 Resolve keyboard shortcut conflicts: Change shortcuts of menu items if there are duplicates in the respective menu level. More...
 
virtual void setItemEnabled (YMenuItem *item, bool enabled)
 Enable or disable an item. More...
 
virtual void setItemVisible (YMenuItem *item, bool visible)
 Show or hide an item. More...
 
YMenuItemfindItem (std::vector< std::string > &path) const
 Support for the Rest API for UI testing: More...
 
virtual void activateItem (YMenuItem *item)=0
 Support for the Rest API for UI testing: More...
 
YMenuItemfindMenuItem (int index)
 Recursively find the first menu item with the specified index. More...
 
- Public Member Functions inherited from YSelectionWidget
virtual ~YSelectionWidget ()
 Destructor.
 
std::string label () const
 Return this widget's label (the caption above the item list).
 
virtual void setLabel (const std::string &newLabel)
 Change this widget's label (the caption above the item list). More...
 
void addItem (const std::string &itemLabel, bool selected=false)
 Overloaded for convenience: Add an item by string.
 
void addItem (const std::string &itemLabel, const std::string &iconName, bool selected=false)
 Overloaded for convenience: Add an item with a text and an icon. More...
 
void setItems (const YItemCollection &itemCollection)
 Delete all items and add new items.
 
YItemIterator itemsBegin ()
 Return an iterator that points to the first item. More...
 
YItemConstIterator itemsBegin () const
 
YItemIterator itemsEnd ()
 Return an iterator that points behind the last item.
 
YItemConstIterator itemsEnd () const
 
bool hasItems () const
 Return 'true' if this widget has any items.
 
int itemsCount () const
 Return the number of items. More...
 
YItemitemAt (int index) const
 Return the item at index 'index' (from 0) or 0 if there is no such item.
 
YItemfirstItem () const
 Return the first item or 0 if there is none.
 
virtual YItemselectedItem ()
 Return the (first) selected item or 0 if none is selected.
 
virtual YItemCollection selectedItems ()
 Return all selected items. More...
 
bool hasSelectedItem ()
 Return 'true' if any item is selected.
 
virtual void selectItem (YItem *item, bool selected=true)
 Select or deselect an item. More...
 
virtual void setItemStatus (YItem *item, int status)
 Set the status of an item. More...
 
virtual void deselectAllItems ()
 Deselect all items. More...
 
void setIconBasePath (const std::string &basePath)
 Set this widget's base path where to look up icons. More...
 
std::string iconBasePath () const
 Return this widget's base path where to look up icons as set with setIconBasePath().
 
std::string iconFullPath (const std::string &iconName) const
 Return the full path + file name for the specified icon name. More...
 
std::string iconFullPath (YItem *item) const
 Return the full path + file name for the icon of the specified item. More...
 
bool itemsContain (YItem *item) const
 Return 'true' if this widget's items contain the specified item.
 
YItemfindItem (const std::string &itemLabel) const
 Find the (first) item with the specified label. More...
 
void dumpItems () const
 Dump all items and their selection state to the log.
 
bool enforceSingleSelection () const
 Return 'true' if this base class should enforce single selection.
 
virtual void shortcutChanged ()
 Notification that any shortcut of any item was changed by the shortcut conflict manager YShortcutManager. More...
 
virtual std::string shortcutString () const
 Get the string of this widget that holds the keyboard shortcut. More...
 
virtual void setShortcutString (const std::string &str)
 Set the string of this widget that holds the keyboard shortcut. More...
 
- Public Member Functions inherited from YWidget
virtual ~YWidget ()
 Destructor.
 
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 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

 YMenuWidget (YWidget *parent, const std::string &label="")
 Constructor. More...
 
void resolveShortcutConflicts (YItemConstIterator begin, YItemConstIterator end)
 Resolve keyboard shortcut conflicts between iterators 'begin' and 'end'.
 
YMenuItemfindMenuItem (int index, YItemConstIterator begin, YItemConstIterator end)
 Recursively find the first menu item with the specified index from iterator 'begin' to iterator 'end'. More...
 
YMenuItemfindItem (std::vector< std::string >::iterator path_begin, std::vector< std::string >::iterator path_end, YItemConstIterator begin, YItemConstIterator end) const
 Recursively looks for the first item in the tree of the menu items using depth first search. More...
 
YMenuItemitemAt (int index)
 Alias for findMenuItem(). More...
 
void assignUniqueIndex (YItemIterator begin, YItemIterator end)
 Assign a unique index to all items from iterator 'begin' to iterator 'end'.
 
- Protected Member Functions inherited from YSelectionWidget
 YSelectionWidget (YWidget *parent, const std::string &label, bool enforceSingleSelection, bool recursiveSelection=false)
 Constructor. More...
 
void setEnforceSingleSelection (bool on)
 Set single selection mode on or off. More...
 
void setEnforceInitialSelection (bool on)
 In single selection mode, enforce selecting an initial item ('true' by default). More...
 
bool enforceInitialSelection () const
 Return 'true' if this class enforces an initial selection.
 
bool recursiveSelection () const
 Return 'true' if this base class should select children recursively.
 
YItemfindSelectedItem (YItemConstIterator begin, YItemConstIterator end)
 Recursively try to find the first selected item between iterators 'begin' and 'end'. More...
 
void findSelectedItems (YItemCollection &selectedItems, YItemConstIterator begin, YItemConstIterator end)
 Recursively find all selected items between iterators 'begin' and 'end' and add each of them to the 'selectedItems' YItemCollection.
 
void deselectAllItems (YItemIterator begin, YItemIterator end)
 Recursively deselect all items between iterators 'begin' and 'end'.
 
YItemfindItem (const std::string &wantedItemLabel, YItemConstIterator begin, YItemConstIterator end) const
 Recursively try to find an item with label 'wantedItemLabel' between iterators 'begin' and 'end'. More...
 
bool itemsContain (YItem *wantedItem, YItemConstIterator begin, YItemConstIterator end) const
 Recursively check if 'wantedItem' is between iterators 'begin' and 'end'.
 
- Protected Member Functions inherited from YWidget
 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 for widgets that handle menus, e.g.

YMenuButton or YMenuBar.

Definition at line 38 of file YMenuWidget.h.

Constructor & Destructor Documentation

◆ YMenuWidget()

YMenuWidget::YMenuWidget ( YWidget parent,
const std::string &  label = "" 
)
protected

Constructor.

'label' is only passed through to the inherited class. For a menu button, this would be the label on the button; a menu bar does not have a label.

Definition at line 51 of file YMenuWidget.cc.

Member Function Documentation

◆ activateItem()

virtual void YMenuWidget::activateItem ( YMenuItem item)
pure virtual

Support for the Rest API for UI testing:

Activate the item selected in the tree. This can be used in tests to simulate user input.

Derived classes are required to implement this.

◆ addItem()

void YMenuWidget::addItem ( YItem item_disown)
virtual

Add one item.

This widget assumes ownership of the item object and will delete it in its destructor.

This reimplementation will assign an index to the item that is unique for all items in this MenuButton. That index can be used later with findMenuItem() to find the item by that index.

Note
Do not forget to call resolveShortcutConflicts and rebuildMenuTree (in this order!) after adding all elements.

Reimplemented from YSelectionWidget.

Reimplemented from YSelectionWidget.

Definition at line 77 of file YMenuWidget.cc.

Here is the call graph for this function:

◆ addItems()

void YMenuWidget::addItems ( const YItemCollection itemCollection)
virtual

Add multiple items.

For some UIs, this can be more efficient than calling addItem() multiple times. This function also automatically calls resolveShortcutConflicts() and rebuildMenuTree() at the end.

Derived classes can overwrite this function, but they should call this base class function at the end of the new implementation.

Reimplemented from YSelectionWidget.

Reimplemented from YSelectionWidget.

Definition at line 68 of file YMenuWidget.cc.

Here is the call graph for this function:

◆ deleteAllItems()

void YMenuWidget::deleteAllItems ( )
virtual

Delete all items.

Reimplemented from YSelectionWidget.

Reimplemented from YSelectionWidget.

Definition at line 103 of file YMenuWidget.cc.

Here is the call graph for this function:

◆ findItem() [1/2]

YMenuItem * YMenuWidget::findItem ( std::vector< std::string > &  path) const

Support for the Rest API for UI testing:

Return the item in the tree which matches a path of labels. This returns 0 if there is no such item or if it is not a leaf menu item.

'path' specifies the user-visible labels (i.e. the translated texts) of each menu level ( ["File", "Export", "As XML"] ).

Definition at line 269 of file YMenuWidget.cc.

Here is the call graph for this function:

◆ findItem() [2/2]

YMenuItem * YMenuWidget::findItem ( std::vector< std::string >::iterator  path_begin,
std::vector< std::string >::iterator  path_end,
YItemConstIterator  begin,
YItemConstIterator  end 
) const
protected

Recursively looks for the first item in the tree of the menu items using depth first search.

Return nullptr if item which matches full path is not found. Path is a vector of strings, where next element is a child item, so in case one needs to select File->Export->As PDF, for instance, Vector will look like [ "File", "Export", "As PDF" ].

Definition at line 277 of file YMenuWidget.cc.

Here is the call graph for this function:

◆ findMenuItem() [1/2]

YMenuItem * YMenuWidget::findMenuItem ( int  index)

Recursively find the first menu item with the specified index.

Returns 0 if there is no such item.

Definition at line 127 of file YMenuWidget.cc.

Here is the call graph for this function:

◆ findMenuItem() [2/2]

YMenuItem * YMenuWidget::findMenuItem ( int  index,
YItemConstIterator  begin,
YItemConstIterator  end 
)
protected

Recursively find the first menu item with the specified index from iterator 'begin' to iterator 'end'.

Returns 0 if there is no such item.

Definition at line 134 of file YMenuWidget.cc.

Here is the call graph for this function:

◆ itemAt()

YMenuItem* YMenuWidget::itemAt ( int  index)
inlineprotected

Alias for findMenuItem().

Reimplemented to ensure consistent behaviour with YSelectionWidget::itemAt().

Definition at line 208 of file YMenuWidget.h.

Here is the call graph for this function:

◆ rebuildMenuTree()

virtual void YMenuWidget::rebuildMenuTree ( )
pure virtual

Rebuild the displayed menu tree from the internally stored YMenuItems.

The application should call this (once) after all items have been added with addItem(). YMenuButton::addItems() calls this automatically.

Derived classes are required to implement this.

◆ resolveShortcutConflicts()

void YMenuWidget::resolveShortcutConflicts ( )

Resolve keyboard shortcut conflicts: Change shortcuts of menu items if there are duplicates in the respective menu level.

This has to be called after all items are added, but before rebuildMenuTree() (see above). YMenuWidget::addItems() calls this automatically.

Definition at line 262 of file YMenuWidget.cc.

Here is the call graph for this function:

◆ setItemEnabled()

void YMenuWidget::setItemEnabled ( YMenuItem item,
bool  enabled 
)
virtual

Enable or disable an item.

This default implementation only updates the item's 'enabled' field.

Derived classes should overwrite this method and either update the item's 'enabled' field in their implementation or call this default implementation.

Definition at line 111 of file YMenuWidget.cc.

Here is the call graph for this function:

◆ setItemVisible()

void YMenuWidget::setItemVisible ( YMenuItem item,
bool  visible 
)
virtual

Show or hide an item.

This default implementation only updates the item's 'visible' field.

Derived classes should overwrite this method and either update the item's 'visible' field in their implementation or call this default implementation.

Definition at line 119 of file YMenuWidget.cc.

Here is the call graph for this function:

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