29 #define YUILogComponent "ui-shortcuts" 32 #include "YShortcut.h" 33 #include "YPushButton.h" 38 #define DIM( ARRAY ) ( (int) ( sizeof( ARRAY)/( sizeof( ARRAY[0] ) ) ) ) 42 : _widget( shortcutWidget )
46 _distinctShortcutChars = -1;
48 _shortcutStringCached =
false;
49 _cleanShortcutStringCached =
false;
52 _isButton = ( button != 0 );
56 _isWizardButton = strstr( shortcutWidget->
widgetClass(),
"WizardButton" );
77 if ( ! _shortcutStringCached )
80 _shortcutStringCached =
true;
86 return _shortcutString;
93 if ( ! _cleanShortcutStringCached )
98 return _cleanShortcutString;
105 std::string::size_type pos = 0;
107 while ( ( pos =
findShortcutPos( shortcutString, pos ) ) != std::string::npos )
109 shortcutString.erase( pos, ( std::string::size_type ) 1 );
119 if ( _preferred < 0 )
124 return (
char) _preferred;
136 return (
char) _shortcut;
145 if ( newShortcut != YShortcut::None )
147 char findme[] = { (char)tolower( newShortcut ), (char)toupper( newShortcut ), 0 };
148 std::string::size_type pos = str.find_first_of( findme );
150 if ( pos == std::string::npos )
152 yuiError() <<
"Can't find '<< " << newShortcut
166 _shortcutStringCached =
false;
167 _cleanShortcutStringCached =
false;
168 _shortcut = newShortcut;
182 if ( _distinctShortcutChars < 0 )
187 bool contained[
sizeof(char) << 8 ];
189 for (
int i=0; i < DIM( contained ); i++ )
190 contained[i] =
false;
197 for ( std::string::size_type pos=0; pos < clean.length(); pos++ )
200 contained[ (
int) clean[ pos ] ] =
true;
206 _distinctShortcutChars=0;
208 for (
int i=0; i < DIM( contained ); i++ )
212 _distinctShortcutChars++;
217 return _distinctShortcutChars;
226 for ( std::string::size_type pos=0; pos < clean.length(); pos++ )
247 return std::string(
"" );
253 std::string::size_type
256 while ( ( pos = str.find(
shortcutMarker(), pos ) ) != std::string::npos )
258 if ( pos+1 < str.length() )
271 return std::string::npos;
275 return std::string::npos;
284 return pos == std::string::npos ? (char) 0 : str[ pos+1 ];
291 if ( c >=
'a' && c <=
'z' )
return true;
292 if ( c >=
'A' && c <=
'Z' )
return true;
293 if ( c >=
'0' && c <=
'9' )
return true;
301 if ( c >=
'a' && c <=
'z' )
return c -
'a' +
'A';
302 if ( c >=
'A' && c <=
'Z' )
return c;
303 if ( c >=
'0' && c <=
'9' )
return c;
315 return _item->label();
324 if ( newShortcut != YShortcut::None )
326 char findme[] = { (char)tolower( newShortcut ), (char)toupper( newShortcut ), 0 };
327 std::string::size_type pos = str.find_first_of( findme );
329 if ( pos == std::string::npos )
331 yuiError() <<
"Can't find '<< " << newShortcut
343 _item->setLabel( str );
348 _shortcutStringCached =
false;
349 _cleanShortcutStringCached =
false;
350 _shortcut = newShortcut;
virtual ~YShortcut()
Destructor.
char preferred()
The preferred shortcut character, i.e.
virtual void setShortcut(char newShortcut)
Set (override) the shortcut character.
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.
virtual std::string getShortcutString()
Obtain the the shortcut property of this shortcut's widget - the string that contains "&" to designat...
const char * widgetClass() const
Returns the textual representation of the widget class of the widget this shortcut data belongs 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.
virtual std::string getShortcutString()
Obtain the the shortcut property of this shortcut's widget - the string that contains "&" to designat...
std::string cleanShortcutString()
Returns the shortcut string ( from the widget's shortcut property ) without any "&" markers...
static char shortcutMarker()
Static function: Returns the character used for marking keyboard shortcuts.
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...
std::string shortcutString()
Returns the complete shortcut string (which may or may not contain "&"), i.e.
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.
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.