libyui

/data/gitorious.org/libyui/libyui-master/src/YShortcut.h

00001 /**************************************************************************
00002 Copyright (C) 2000 - 2010 Novell, Inc.
00003 All Rights Reserved.
00004 
00005 This program is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License along
00016 with this program; if not, write to the Free Software Foundation, Inc.,
00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018 
00019 **************************************************************************/
00020 
00021 
00022 /*---------------------------------------------------------------------\
00023 |                                                                      |
00024 |                      __   __    ____ _____ ____                      |
00025 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00026 |                       \ V / _` \___ \ | |   __) |                    |
00027 |                        | | (_| |___) || |  / __/                     |
00028 |                        |_|\__,_|____/ |_| |_____|                    |
00029 |                                                                      |
00030 |                               core system                            |
00031 |                                                        (C) SuSE GmbH |
00032 \----------------------------------------------------------------------/
00033 
00034   File:         YShortcut.h
00035 
00036   Author:       Stefan Hundhammer <sh@suse.de>
00037 
00038 /-*/
00039 
00040 
00041 #ifndef YShortcut_h
00042 #define YShortcut_h
00043 
00044 #include "YWidget.h"
00045 #include <string>
00046 #include <vector>
00047 
00048 using std::vector;
00049 class YItem;
00050 
00051 
00056 class YShortcut
00057 {
00058 public:
00062     YShortcut( YWidget *shortcut_widget );
00063 
00067     virtual ~YShortcut();
00068 
00072     enum { None = 0 };
00073 
00077     YWidget * widget() const { return _widget; }
00078     
00083     const char * widgetClass() const { return widget()->widgetClass(); }
00084 
00089     bool isButton() const { return _isButton; }
00090 
00095     bool isWizardButton() const { return _isWizardButton; }
00096 
00105     string shortcutString();
00106 
00111     string cleanShortcutString();
00112 
00117     static string cleanShortcutString( string shortcutString );
00118 
00123     char preferred();
00124 
00130     char shortcut();
00131 
00135     virtual void setShortcut( char newShortcut );
00136 
00141     void clearShortcut();
00142 
00147     bool conflict() { return _conflict; }
00148 
00152     void setConflict( bool newConflictState = true ) { _conflict = newConflictState; }
00153 
00158     int distinctShortcutChars();
00159 
00164     bool hasValidShortcutChar();
00165     
00170     static char shortcutMarker() { return '&'; }
00171 
00179     static string::size_type findShortcutPos( const string & str, string::size_type start_pos = 0 );
00180 
00187     static char findShortcut( const string & str, string::size_type start_pos = 0 );
00188 
00193     static bool isValid( char c );
00194 
00199     static char normalized( char c );
00200 
00205     static string getShortcutString( const YWidget * widget );
00206 
00207     
00208 protected:
00209 
00214     virtual string getShortcutString();
00215     
00216 
00217     // Data members
00218     
00219     YWidget *   _widget;
00220     string      _shortcutString;
00221     bool        _shortcutStringCached;
00222     
00223     string      _cleanShortcutString;
00224     bool        _cleanShortcutStringCached;
00225     
00226     int         _preferred;     // int to enable initializing with invalid char (-1)
00227     int         _shortcut;      // int to enable initializing with invalid char (-1)
00228     
00229     bool        _conflict;
00230     bool        _isButton;
00231     bool        _isWizardButton;
00232     int         _distinctShortcutChars;
00233 };
00234 
00235 
00236 
00241 class YItemShortcut: public YShortcut
00242 {
00243 public:
00247     YItemShortcut( YWidget * widget, YItem * item )
00248         : YShortcut( widget )
00249         , _item( item )
00250         {}
00251 
00255     virtual ~YItemShortcut() {}
00256 
00260     YItem * item() const { return _item; }
00261 
00266     virtual void setShortcut( char newShortcut );
00267 
00268 protected:
00269 
00274     virtual string getShortcutString();
00275 
00276 
00277 private:
00278 
00279     YItem * _item;
00280 };
00281 
00282 
00283 typedef vector<YShortcut *>             YShortcutList;
00284 typedef YShortcutList::iterator         YShortcutListIterator;
00285 
00286 
00287 #endif // YShortcut_h
 All Classes Functions Variables Enumerations Friends