libyui
YShortcut.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YShortcut.h
20 
21  Author: Stefan Hundhammer <shundhammer@suse.de>
22 
23 /-*/
24 
25 
26 #ifndef YShortcut_h
27 #define YShortcut_h
28 
29 #include <iosfwd>
30 #include <string>
31 #include <vector>
32 
33 #include "YWidget.h"
34 #include "YItem.h"
35 
36 
45 class YShortcut
46 {
47 public:
52  YShortcut( YWidget *shortcut_widget );
53 
57  virtual ~YShortcut();
58 
62  enum { None = 0 };
63 
67  YWidget * widget() const { return _widget; }
68 
73  const char * widgetClass() const { return widget()->widgetClass(); }
74 
79  bool isButton() const { return _isButton; }
80 
85  bool isWizardButton() const { return _isWizardButton; }
86 
93  virtual bool isMenuItem() const { return false; }
94 
103  std::string shortcutString();
104 
111  std::string cleanShortcutString();
112 
118  static std::string cleanShortcutString( std::string shortcutString );
119 
124  char preferred();
125 
131  char shortcut();
132 
136  virtual void setShortcut( char newShortcut );
137 
142  void clearShortcut();
143 
148  bool conflict() { return _conflict; }
149 
153  void setConflict( bool newConflictState = true ) { _conflict = newConflictState; }
154 
159  int distinctShortcutChars();
160 
165  bool hasValidShortcutChar();
166 
170  virtual std::string debugLabel() const { return _widget->debugLabel(); }
171 
176  static char shortcutMarker() { return '&'; }
177 
187  static std::string::size_type findShortcutPos( const std::string & str, std::string::size_type start_pos = 0 );
188 
195  static char findShortcut( const std::string & str, std::string::size_type start_pos = 0 );
196 
201  static bool isValid( char c );
202 
207  static char normalized( char c );
208 
213  static std::string getShortcutString( const YWidget * widget );
214 
215 
216 protected:
217 
222  virtual std::string getShortcutString();
223 
224 
225  // Data members
226 
228  std::string _shortcutString;
230 
231  std::string _cleanShortcutString;
233 
237 
241 
242  bool _conflict;
243  bool _isButton;
245 
249 };
250 
251 
252 
263 {
264 public:
269 
273  virtual ~YItemShortcut() {}
274 
278  YItem * item() const { return _item; }
279 
286  virtual void setShortcut( char newShortcut );
287 
293  virtual bool isMenuItem() const { return _isMenuItem; }
294 
298  virtual std::string debugLabel() const
299  { return cleanShortcutString( _item->debugLabel() ); }
300 
301 
302 protected:
303 
308  virtual std::string getShortcutString();
309 
310 
311 private:
312 
313  YItem * _item;
314  bool _isMenuItem;
315 };
316 
317 
318 std::ostream & operator<<( std::ostream & stream, const YShortcut * shortcut );
319 
320 
321 typedef std::vector<YShortcut *> YShortcutList;
322 typedef YShortcutList::iterator YShortcutListIterator;
323 
324 
325 #endif // YShortcut_h
virtual ~YShortcut()
Definition: YShortcut.cc:72
virtual const char * widgetClass() const
Definition: YWidget.h:72
bool _cleanShortcutStringCached
always false :facepalm:
Definition: YShortcut.h:232
char preferred()
Definition: YShortcut.cc:120
std::string _shortcutString
Definition: YShortcut.h:228
virtual std::string debugLabel() const
Definition: YWidget.cc:223
virtual void setShortcut(char newShortcut)
Definition: YShortcut.cc:333
const char * widgetClass() const
Definition: YShortcut.h:73
YItem * item() const
Definition: YShortcut.h:278
Definition: YShortcut.h:45
bool _isButton
Definition: YShortcut.h:243
virtual std::string getShortcutString()
Definition: YShortcut.cc:323
virtual void setShortcut(char newShortcut)
Definition: YShortcut.cc:144
static char normalized(char c)
Definition: YShortcut.cc:302
virtual std::string getShortcutString()
Definition: YShortcut.cc:240
virtual ~YItemShortcut()
Definition: YShortcut.h:273
void setConflict(bool newConflictState=true)
Definition: YShortcut.h:153
int _shortcut
Definition: YShortcut.h:240
bool _conflict
Definition: YShortcut.h:242
int _distinctShortcutChars
Definition: YShortcut.h:248
virtual std::string debugLabel() const
Definition: YShortcut.h:170
virtual bool isMenuItem() const
Definition: YShortcut.h:93
YWidget * _widget
(not owned)
Definition: YShortcut.h:227
Definition: YShortcut.h:262
bool _isWizardButton
Definition: YShortcut.h:244
static char shortcutMarker()
Definition: YShortcut.h:176
std::string shortcutString()
Definition: YShortcut.cc:78
bool isButton() const
Definition: YShortcut.h:79
std::string cleanShortcutString()
Definition: YShortcut.cc:94
bool conflict()
Definition: YShortcut.h:148
Definition: YItem.h:55
virtual std::string debugLabel() const
Definition: YItem.cc:44
static char findShortcut(const std::string &str, std::string::size_type start_pos=0)
Definition: YShortcut.cc:283
void clearShortcut()
Definition: YShortcut.cc:176
int _preferred
Definition: YShortcut.h:236
int distinctShortcutChars()
Definition: YShortcut.cc:183
static std::string::size_type findShortcutPos(const std::string &str, std::string::size_type start_pos=0)
Definition: YShortcut.cc:257
virtual bool isMenuItem() const
Definition: YShortcut.h:293
bool hasValidShortcutChar()
Definition: YShortcut.cc:225
YItemShortcut(YWidget *widget, YItem *item)
Definition: YShortcut.cc:313
YWidget * widget() const
Definition: YShortcut.h:67
bool _shortcutStringCached
is _shortcutString initialized
Definition: YShortcut.h:229
Definition: YWidget.h:54
char shortcut()
Definition: YShortcut.cc:132
bool isWizardButton() const
Definition: YShortcut.h:85
YShortcut(YWidget *shortcut_widget)
Definition: YShortcut.cc:44
static bool isValid(char c)
Definition: YShortcut.cc:292
virtual std::string debugLabel() const
Definition: YShortcut.h:298