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
348 _shortcutStringCached =
false;
349 _cleanShortcutStringCached =
false;
350 _shortcut = newShortcut;
virtual void setShortcut(char newShortcut)
static std::string::size_type findShortcutPos(const std::string &str, std::string::size_type start_pos=0)
virtual std::string getShortcutString()
virtual void setShortcut(char newShortcut)
static char normalized(char c)
virtual std::string getShortcutString()
std::string cleanShortcutString()
static char shortcutMarker()
void setLabel(const std::string &newLabel)
static char findShortcut(const std::string &str, std::string::size_type start_pos=0)
std::string shortcutString()
const char * widgetClass() const
int distinctShortcutChars()
bool hasValidShortcutChar()
std::string label() const
YShortcut(YWidget *shortcut_widget)
static bool isValid(char c)