libyui
 
Loading...
Searching...
No Matches
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
46{
47public:
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
160
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
216protected:
217
222 virtual std::string getShortcutString();
223
224
225 // Data members
226
228 std::string _shortcutString;
230
231 std::string _cleanShortcutString;
233
237
241
245
249};
250
251
252
263{
264public:
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
302protected:
303
308 virtual std::string getShortcutString();
309
310
311private:
312
313 YItem * _item;
314 bool _isMenuItem;
315};
316
317
318std::ostream & operator<<( std::ostream & stream, const YShortcut * shortcut );
319
320
321typedef std::vector<YShortcut *> YShortcutList;
322typedef YShortcutList::iterator YShortcutListIterator;
323
324
325#endif // YShortcut_h
virtual std::string getShortcutString()
Definition YShortcut.cc:323
virtual void setShortcut(char newShortcut)
Definition YShortcut.cc:333
YItemShortcut(YWidget *widget, YItem *item)
Definition YShortcut.cc:313
YItem * item() const
Definition YShortcut.h:278
virtual bool isMenuItem() const
Definition YShortcut.h:293
virtual ~YItemShortcut()
Definition YShortcut.h:273
virtual std::string debugLabel() const
Definition YShortcut.h:298
Definition YItem.h:56
Definition YShortcut.h:46
int _preferred
Definition YShortcut.h:236
YWidget * _widget
(not owned)
Definition YShortcut.h:227
char preferred()
Definition YShortcut.cc:120
static char normalized(char c)
Definition YShortcut.cc:302
YShortcut(YWidget *shortcut_widget)
Definition YShortcut.cc:44
virtual std::string getShortcutString()
Definition YShortcut.cc:240
bool _cleanShortcutStringCached
always false :facepalm:
Definition YShortcut.h:232
void setConflict(bool newConflictState=true)
Definition YShortcut.h:153
int distinctShortcutChars()
Definition YShortcut.cc:183
bool _shortcutStringCached
is _shortcutString initialized
Definition YShortcut.h:229
static std::string::size_type findShortcutPos(const std::string &str, std::string::size_type start_pos=0)
Definition YShortcut.cc:257
YWidget * widget() const
Definition YShortcut.h:67
bool _isButton
Definition YShortcut.h:243
bool isButton() const
Definition YShortcut.h:79
int _distinctShortcutChars
Definition YShortcut.h:248
bool hasValidShortcutChar()
Definition YShortcut.cc:225
bool _isWizardButton
Definition YShortcut.h:244
static char findShortcut(const std::string &str, std::string::size_type start_pos=0)
Definition YShortcut.cc:283
std::string shortcutString()
Definition YShortcut.cc:78
virtual bool isMenuItem() const
Definition YShortcut.h:93
bool conflict()
Definition YShortcut.h:148
bool _conflict
Definition YShortcut.h:242
int _shortcut
Definition YShortcut.h:240
static std::string cleanShortcutString(std::string shortcutString)
virtual ~YShortcut()
Definition YShortcut.cc:72
const char * widgetClass() const
Definition YShortcut.h:73
static char shortcutMarker()
Definition YShortcut.h:176
std::string _shortcutString
Definition YShortcut.h:228
virtual void setShortcut(char newShortcut)
Definition YShortcut.cc:144
static bool isValid(char c)
Definition YShortcut.cc:292
virtual std::string debugLabel() const
Definition YShortcut.h:170
void clearShortcut()
Definition YShortcut.cc:176
std::string cleanShortcutString()
Definition YShortcut.cc:94
bool isWizardButton() const
Definition YShortcut.h:85
char shortcut()
Definition YShortcut.cc:132
Definition YWidget.h:55
virtual const char * widgetClass() const
Definition YWidget.h:72