include/shortcutcust/shortcutcust.h

Go to the documentation of this file.
00001 
00002 // Name:        shortcutcust.h
00003 // Purpose:     Classes for allowing the user to customise shortcuts.
00004 // Author:      Julian Smart
00005 // Modified by:
00006 // Created:     2009-04-13
00007 // RCS-ID:      $Id$
00008 // Copyright:   (c) Julian Smart
00009 // Licence:     New BSD License
00011 
00012 #ifndef _WX_SHORTBARCUST_H_
00013 #define _WX_SHORTBARCUST_H_
00014 
00015 #include "wx/accel.h"
00016 #include "wx/confbase.h"
00017 #include "wx/dynarray.h"
00018 #include "wx/textctrl.h"
00019 
00025 class wxShortcutItem: public wxObject
00026 {
00027 public:
00028     wxShortcutItem() { Init(); }
00029     wxShortcutItem(int id, const wxString& name, const wxString& category,
00030         const wxString& descr, int flags, int keyCode)
00031     {
00032         Init();
00033         m_id = id; 
00034         m_name = name; 
00035         m_category = category;
00036         m_description = descr; 
00037         m_flags = flags; 
00038         m_keyCode = keyCode;
00039     }
00040     wxShortcutItem(const wxShortcutItem& item) { Copy(item); }
00041     ~wxShortcutItem() {}
00042 
00043     void Init();
00044 
00045     void Copy(const wxShortcutItem& item, bool excludeId = false);
00046 
00047     bool operator==(const wxShortcutItem& item) const;
00048 
00049     wxShortcutItem& SetId(int id) { m_id = id; return *this; }
00050     int GetId() const { return m_id; }
00051 
00052     // state
00053     wxShortcutItem& Enable(bool enable) { m_enabled = enable; return *this; }
00054 
00055     bool IsEnabled() const { return m_enabled; }
00056 
00057     wxShortcutItem& SetName(const wxString& name) { m_name = name; return *this; }
00058     const wxString& GetName() const { return m_name; }
00059 
00060     wxShortcutItem& SetCategory(const wxString& cat) { m_category = cat; return *this; }
00061     const wxString& GetCategory() const { return m_category; }
00062 
00063     wxShortcutItem& SetDescription(const wxString& descr) { m_description = descr; return *this; }
00064     const wxString& GetDescription() const { return m_description; }
00065 
00066     wxShortcutItem& SetFlags(int flags) { m_flags = flags; return *this; }
00067     int GetFlags() const { return m_flags; }
00068 
00069     wxShortcutItem& SetKeyCode(int keyCode) { m_keyCode = keyCode; return *this; }
00070     int GetKeyCode() const { return m_keyCode; }
00071 
00072 public:
00073 
00074     int                     m_id;
00075     bool                    m_enabled;
00076     wxString                m_name;
00077     wxString                m_category;
00078     wxString                m_description;
00079     int                     m_flags;
00080     int                     m_keyCode;
00081 };
00082 
00083 WX_DECLARE_OBJARRAY(wxShortcutItem, wxShortcutItemArray);
00084 
00090 class wxShortcutManager: public wxObject
00091 {
00092 public:
00093     wxShortcutManager(const wxShortcutManager& manager) { Init(); Copy(manager); }
00094     wxShortcutManager() { Init(); }
00095     ~wxShortcutManager() {}
00096     
00098     void Copy(const wxShortcutManager& manager);
00099 
00101     void Init();
00102 
00104     void Clear();
00105 
00107     void Add(const wxShortcutItem& info);
00108 
00110     wxShortcutItem* Find(const wxString& name) const;
00111 
00113     int FindIndex(const wxString& name) const;
00114 
00116     wxShortcutItem* FindById(int id) const;
00117 
00119     wxShortcutItem* GetNth(int n) const;
00120 
00122     int GetCount() const { return m_shortcuts.GetCount(); }
00123 
00125     virtual bool Save(wxConfigBase& config);
00126 
00128     virtual bool Load(wxConfigBase& config);
00129 
00131     virtual bool SaveOriginalShortcuts();
00132 
00134     virtual bool ResetShortcuts();
00135     
00137     virtual wxAcceleratorTable MakeAcceleratorTable();
00138     
00140     virtual bool SetAcceleratorTable(wxWindow* window);
00141 
00143     virtual bool UpdateMenuBar(wxMenuBar* menuBar);
00144 
00146     virtual bool UpdateMenu(wxMenu* menu);
00147 
00149     wxShortcutItemArray& GetShortcuts() { return m_shortcuts; }
00150 
00152     virtual wxString GetReadableShortcutString(const wxShortcutItem& item) const;
00153     
00155     virtual wxString GetMenuShortcutString(const wxShortcutItem& item) const;
00156 
00158     static bool IsValidShortcutKeyCode(int keycode);
00159 
00162     wxShortcutItemArray GetMatchingShortcuts(const wxShortcutItem& item, int idException = -1) const;
00163     
00164 protected:
00165 
00166     wxShortcutItemArray m_shortcuts;
00167     wxShortcutItemArray m_originalShortcuts;
00168 };
00169 
00175 class wxShortcutCtrl: public wxTextCtrl
00176 {
00177     DECLARE_DYNAMIC_CLASS(wxShortcutCtrl)
00178     DECLARE_EVENT_TABLE()
00179 
00180 public:
00181     wxShortcutCtrl() { Init(); }
00182 
00183     wxShortcutCtrl(wxWindow* parent, wxWindowID id, const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition,
00184         const wxSize& size = wxDefaultSize, int style = 0)
00185     {
00186         Init();
00187         Create(parent, id, value, pos, size, style);
00188     }
00189     bool Create(wxWindow* parent, wxWindowID id, const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition,
00190         const wxSize& size = wxDefaultSize, int style = 0);
00191 
00192     void Init();
00193 
00194     void SetShortcut(const wxShortcutItem& item) { m_shortcut = item; }
00195     const wxShortcutItem& GetShortcut() const { return m_shortcut; }
00196 
00197     void OnKeyDown(wxKeyEvent& event);
00198 
00199     wxString GetShortcutString() const;
00200     
00201     void ApplyShortcut();
00202 
00203 protected:
00204 
00205     wxShortcutItem  m_shortcut;
00206 };
00207 
00208 #endif
00209     // _WX_SHORTBARCUST_H_

Generated on Wed May 6 19:20:19 2009 for AxTk by  doxygen 1.5.1