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 )
48 _distinctShortcutChars = -1;
50 _shortcutStringCached =
false;
51 _cleanShortcutStringCached =
false;
54 _isButton = ( button != 0 );
58 _isWizardButton = strstr( shortcutWidget->
widgetClass(),
"WizardButton" );
79 if ( ! _shortcutStringCached )
82 _shortcutStringCached =
true;
88 return _shortcutString;
95 if ( ! _cleanShortcutStringCached )
100 return _cleanShortcutString;
107 string::size_type pos = 0;
121 if ( _preferred < 0 )
126 return (
char) _preferred;
138 return (
char) _shortcut;
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
168 _shortcutStringCached =
false;
169 _cleanShortcutStringCached =
false;
170 _shortcut = newShortcut;
184 if ( _distinctShortcutChars < 0 )
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;
208 _distinctShortcutChars=0;
210 for (
int i=0; i < DIM( contained ); i++ )
214 _distinctShortcutChars++;
219 return _distinctShortcutChars;
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
350 _shortcutStringCached =
false;
351 _cleanShortcutStringCached =
false;
352 _shortcut = newShortcut;
virtual ~YShortcut()
Destructor.
std::string label() const
Return this item's label.
char preferred()
The preferred shortcut character, i.e.
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...
virtual std::string getShortcutString()
Obtain the the shortcut property of this shortcut's widget - the string that contains "&" to designat...
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.
virtual std::string getShortcutString()
Obtain the the shortcut property of this shortcut's widget - the string that contains "&" to designat...
static char shortcutMarker()
Static function: Returns the character used for marking keyboard shortcuts.
std::string shortcutString()
Returns the complete shortcut string (which may or may not contain "&"), i.e.
std::string cleanShortcutString()
Returns the shortcut string ( from the widget's shortcut property ) without any "&" markers...
void setLabel(const std::string &newLabel)
Set this item's label.
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...
void clearShortcut()
Clear the shortcut: Override the shortcut character with nothing.
int distinctShortcutChars()
Obtain the number of distinct valid shortcut characters in the shortcut string, 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, beginning at starting position start_pos.
bool hasValidShortcutChar()
Return true if this shortcut contains any character that would be valid as a shortcut character...
YWidget * widget() const
Returns the YWidget this shortcut data belong to.
char shortcut()
The actual shortcut character.
YShortcut(YWidget *shortcut_widget)
Constructor.
static bool isValid(char c)
Returns 'true' if 'c' is a valid shortcut character, i.e.