libyui  3.0.10
 All Classes Functions Variables Enumerations Friends
YShortcutManager Class Reference

#include <YShortcutManager.h>

Collaboration diagram for YShortcutManager:

Public Member Functions

 YShortcutManager (YDialog *dialog)
 
virtual ~YShortcutManager ()
 
void checkShortcuts (bool autoResolve=true)
 
int conflictCount ()
 
void resolveAllConflicts ()
 
YDialogdialog ()
 

Protected Member Functions

void clearShortcutList ()
 
void findShortcutWidgets (YWidgetListConstIterator begin, YWidgetListConstIterator end)
 
void resolveConflict (YShortcut *shortcut)
 
int findShortestWizardButton (const YShortcutList &conflictList)
 
unsigned findShortestWidget (const YShortcutList &conflictList)
 

Protected Attributes

YDialog_dialog
 
YShortcutList _shortcutList
 
int _wanted [sizeof(char)<< 8]
 
bool _used [sizeof(char)<< 8]
 
int _conflictCount
 

Detailed Description

Helper class to manage keyboard shortcuts within one dialog and resolve keyboard shortcut conflicts.

Definition at line 38 of file YShortcutManager.h.

Constructor & Destructor Documentation

YShortcutManager::YShortcutManager ( YDialog dialog)

Constructor.

Definition at line 44 of file YShortcutManager.cc.

YShortcutManager::~YShortcutManager ( )
virtual

Destructor

Definition at line 53 of file YShortcutManager.cc.

Here is the call graph for this function:

Member Function Documentation

void YShortcutManager::checkShortcuts ( bool  autoResolve = true)

Check the keyboard shortcuts of all children of this dialog (not for sub-dialogs!).

Call resolveAllConflicts() if 'autoResolve' is 'true'.

Definition at line 60 of file YShortcutManager.cc.

Here is the call graph for this function:

void YShortcutManager::clearShortcutList ( )
protected

Delete all members of the internal shortcut list, then empty the list.

Definition at line 367 of file YShortcutManager.cc.

int YShortcutManager::conflictCount ( )
inline

Returns the number of shortcut conflicts. Valid only after checkShortcuts() or resolveAllConflicts().

Definition at line 63 of file YShortcutManager.h.

YDialog* YShortcutManager::dialog ( )
inline

Returns the dialog this shortcut manager works on.

Definition at line 104 of file YShortcutManager.h.

void YShortcutManager::findShortcutWidgets ( YWidgetListConstIterator  begin,
YWidgetListConstIterator  end 
)
protected

Recursively search all widgets between iterators 'begin' and 'end' (not those of any sub-dialogs!) for child widgets that could accept a keyboard shortcut and add these to _shortcutList.

Definition at line 379 of file YShortcutManager.cc.

Here is the call graph for this function:

unsigned YShortcutManager::findShortestWidget ( const YShortcutList &  conflictList)
protected

Find the shortest widget in 'conflictList'. Buttons get priority if they have the same number of eligible shortcut characters as another widget.

Returns the index of the shortest widget.

Definition at line 332 of file YShortcutManager.cc.

int YShortcutManager::findShortestWizardButton ( const YShortcutList &  conflictList)
protected

Find the shortest wizard button in 'conflictList', if there is any. Returns the index of that shortest wizard button or -1 if there is none.

Definition at line 307 of file YShortcutManager.cc.

void YShortcutManager::resolveAllConflicts ( )

Resolve shortcut conflicts. Requires checkShortcuts() to be called first.

Note: This may or may not work. There is no general solution to that problem. This method tries its best, but you may end up with widgets that don't have any ( more ) shortcut.

Why? Just picture the following ( admittedly pathologic ) situation:

[& OK] [& OK] [& OK]

This will result in something like this:

[& OK] [O& K] [OK]

I.e. the first OK button will retain its preferred shortcut ( 'O' ), the second OK button's shortcut will be reassigned to 'K' and the third won't get any - there are simply not enough eligible shortcut characters.

This may even fail in much less pathological situations. This example is only supposed to give you a general idea why not to blindly rely on automatic shortcut resolving.

It's always best to resolve conflicts manually. This will generally result in much better shortcuts: Easier to memorize, less chance of picking characters that cannot really do a good job showing their shortcut like very narrow characters ( .e.g., 'i' ) or descender characters ( e.g., 'g', 'p', 'q' - imagine those underlined! ).

Definition at line 161 of file YShortcutManager.cc.

Here is the call graph for this function:

void YShortcutManager::resolveConflict ( YShortcut shortcut)
protected

Pick a new shortcut character for 'shortcut' - one that isn't marked as used in the '_used' array. Unset the conflict marker if that succeeded.

Definition at line 229 of file YShortcutManager.cc.

Here is the call graph for this function:

Member Data Documentation

int YShortcutManager::_conflictCount
protected

Counter for shortcut conflicts

Definition at line 166 of file YShortcutManager.h.

YDialog* YShortcutManager::_dialog
protected

The dialog this shortcut manager works on.

Definition at line 144 of file YShortcutManager.h.

YShortcutList YShortcutManager::_shortcutList
protected

List of all the shortcuts in this dialog.

Definition at line 149 of file YShortcutManager.h.

bool YShortcutManager::_used[sizeof(char)<< 8]
protected

Flags for used shortcut characters.

Definition at line 160 of file YShortcutManager.h.

int YShortcutManager::_wanted[sizeof(char)<< 8]
protected

Counters for wanted shortcut characters.

Definition at line 154 of file YShortcutManager.h.


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