29 #define YUILogComponent "ui-shortcuts"
32 #include "YShortcut.h"
33 #include "YPushButton.h"
38 #define DIM( ARRAY ) ( (int) ( sizeof( ARRAY)/( sizeof( ARRAY[0] ) ) ) )
44 : _widget( shortcutWidget )
100 return _cleanShortcutString;
107 string::size_type pos = 0;
147 if ( newShortcut != YShortcut::None )
149 char findme[] = { (char)tolower( newShortcut ), (char)toupper( newShortcut ), 0 };
150 string::size_type pos = str.find_first_of( findme );
152 if ( pos == string::npos )
154 yuiError() <<
"Can't find '<< " << newShortcut
189 bool contained[
sizeof(char) << 8 ];
191 for (
int i=0; i < DIM( contained ); i++ )
192 contained[i] =
false;
199 for ( string::size_type pos=0; pos < clean.length(); pos++ )
202 contained[ (int) clean[ pos ] ] =
true;
210 for (
int i=0; i < DIM( contained ); i++ )
228 for ( string::size_type pos=0; pos < clean.length(); pos++ )
258 while ( ( pos = str.find(
shortcutMarker(), pos ) ) != string::npos )
260 if ( pos+1 < str.length() )
286 return pos == string::npos ? (char) 0 : str[ pos+1 ];
293 if ( c >=
'a' && c <=
'z' )
return true;
294 if ( c >=
'A' && c <=
'Z' )
return true;
295 if ( c >=
'0' && c <=
'9' )
return true;
303 if ( c >=
'a' && c <=
'z' )
return c -
'a' +
'A';
304 if ( c >=
'A' && c <=
'Z' )
return c;
305 if ( c >=
'0' && c <=
'9' )
return c;
317 return _item->
label();
326 if ( newShortcut != YShortcut::None )
328 char findme[] = { (char)tolower( newShortcut ), (char)toupper( newShortcut ), 0 };
329 string::size_type pos = str.find_first_of( findme );
331 if ( pos == string::npos )
333 yuiError() <<
"Can't find '<< " << newShortcut
std::string label() const
Return this item's label.
static char shortcutMarker()
Static function: Returns the character used for marking keyboard shortcuts.
YShortcut(YWidget *shortcut_widget)
Constructor.
virtual ~YShortcut()
Destructor.
virtual void setShortcut(char newShortcut)
Set (override) the shortcut character.
const char * widgetClass() const
Returns the textual representation of the widget class of the widget this shortcut data belongs to.
bool _cleanShortcutStringCached
always false :facepalm:
static char findShortcut(const std::string &str, std::string::size_type start_pos=0)
Static function: Find the next shortcut marker in a string, beginning at starting position start_pos.
int _preferred
char or 0 (none found) or -1 (not initialized yet)
std::string _shortcutString
YWidget * widget() const
Returns the YWidget this shortcut data belong to.
virtual void setShortcut(char newShortcut)
Set (override) the shortcut character.
static char normalized(char c)
Return the normalized version of shortcut character 'c', i.e.
char shortcut()
The actual shortcut character.
int _distinctShortcutChars
-1 means uninitialized
bool _shortcutStringCached
is _shortcutString initialized
void setLabel(const std::string &newLabel)
Set this item's label.
void clearShortcut()
Clear the shortcut: Override the shortcut character with nothing.
static bool isValid(char c)
Returns 'true' if 'c' is a valid shortcut character, i.e.
std::string shortcutString()
Returns the complete shortcut string (which may or may not contain "&"), i.e.
static std::string::size_type findShortcutPos(const std::string &str, std::string::size_type start_pos=0)
Static function: Find the next occurrence of the shortcut marker ('&') in a string,...
virtual std::string getShortcutString()
Obtain the the shortcut property of this shortcut's widget - the string that contains "&" to designat...
bool hasValidShortcutChar()
Return true if this shortcut contains any character that would be valid as a shortcut character.
virtual std::string getShortcutString()
Obtain the the shortcut property of this shortcut's widget - the string that contains "&" to designat...
int distinctShortcutChars()
Obtain the number of distinct valid shortcut characters in the shortcut string, i....
char preferred()
The preferred shortcut character, i.e.
std::string cleanShortcutString()
Returns the shortcut string ( from the widget's shortcut property ) without any "&" markers.
int _shortcut
char or 0 (none found) or -1 (not initialized yet)