1 /////////////////////////////////////////////////////////////////////////////// 2 // Name: wx/accel.h 3 // Purpose: wxAcceleratorEntry and wxAcceleratorTable classes 4 // Author: Julian Smart, Robert Roebling, Vadim Zeitlin 5 // Modified by: 6 // Created: 31.05.01 (extracted from other files) 7 // RCS-ID: $Id: accel.h 66927 2011-02-16 23:27:30Z JS $ 8 // Copyright: (c) wxWidgets team 9 // Licence: wxWindows licence 10 /////////////////////////////////////////////////////////////////////////////// 11 12 #ifndef _WX_ACCEL_H_BASE_ 13 #define _WX_ACCEL_H_BASE_ 14 15 #include "wx/defs.h" 16 17 #if wxUSE_ACCEL 18 19 #include "wx/object.h" 20 21 class WXDLLIMPEXP_FWD_CORE wxAcceleratorTable; 22 class WXDLLIMPEXP_FWD_CORE wxMenuItem; 23 class WXDLLIMPEXP_FWD_CORE wxKeyEvent; 24 25 // ---------------------------------------------------------------------------- 26 // constants 27 // ---------------------------------------------------------------------------- 28 29 // wxAcceleratorEntry flags 30 enum 31 { 32 wxACCEL_NORMAL = 0x0000, // no modifiers 33 wxACCEL_ALT = 0x0001, // hold Alt key down 34 wxACCEL_CTRL = 0x0002, // hold Ctrl key down 35 wxACCEL_SHIFT = 0x0004, // hold Shift key down 36 #if defined(__WXMAC__) || defined(__WXCOCOA__) 37 wxACCEL_CMD = 0x0008 // Command key on OS X 38 #else 39 wxACCEL_CMD = wxACCEL_CTRL 40 #endif 41 }; 42 43 // ---------------------------------------------------------------------------- 44 // an entry in wxAcceleratorTable corresponds to one accelerator 45 // ---------------------------------------------------------------------------- 46 47 class WXDLLEXPORT wxAcceleratorEntry 48 { 49 public: 50 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0, 51 wxMenuItem *item = NULL) m_flags(flags)52 : m_flags(flags) 53 , m_keyCode(keyCode) 54 , m_command(cmd) 55 , m_item(item) 56 { } 57 wxAcceleratorEntry(const wxAcceleratorEntry & entry)58 wxAcceleratorEntry(const wxAcceleratorEntry& entry) 59 : m_flags(entry.m_flags) 60 , m_keyCode(entry.m_keyCode) 61 , m_command(entry.m_command) 62 , m_item(entry.m_item) 63 { } 64 65 // create accelerator corresponding to the specified string, return NULL if 66 // string couldn't be parsed or a pointer to be deleted by the caller 67 static wxAcceleratorEntry *Create(const wxString& str); 68 69 wxAcceleratorEntry& operator=(const wxAcceleratorEntry& entry) 70 { 71 Set(entry.m_flags, entry.m_keyCode, entry.m_command, entry.m_item); 72 return *this; 73 } 74 75 void Set(int flags, int keyCode, int cmd, wxMenuItem *item = NULL) 76 { 77 m_flags = flags; 78 m_keyCode = keyCode; 79 m_command = cmd; 80 m_item = item; 81 } 82 SetMenuItem(wxMenuItem * item)83 void SetMenuItem(wxMenuItem *item) { m_item = item; } 84 GetFlags()85 int GetFlags() const { return m_flags; } GetKeyCode()86 int GetKeyCode() const { return m_keyCode; } GetCommand()87 int GetCommand() const { return m_command; } 88 GetMenuItem()89 wxMenuItem *GetMenuItem() const { return m_item; } 90 91 bool operator==(const wxAcceleratorEntry& entry) const 92 { 93 return m_flags == entry.m_flags && 94 m_keyCode == entry.m_keyCode && 95 m_command == entry.m_command && 96 m_item == entry.m_item; 97 } 98 99 bool operator!=(const wxAcceleratorEntry& entry) const 100 { return !(*this == entry); } 101 102 #if defined(__WXMOTIF__) 103 // Implementation use only 104 bool MatchesEvent(const wxKeyEvent& event) const; 105 #endif 106 IsOk()107 bool IsOk() const 108 { 109 return m_keyCode != 0; 110 } 111 112 113 // string <-> wxAcceleratorEntry conversion 114 // ---------------------------------------- 115 116 // returns a wxString for the this accelerator. 117 // this function formats it using the <flags>-<keycode> format 118 // where <flags> maybe a hyphen-separed list of "shift|alt|ctrl" 119 wxString ToString() const; 120 121 // returns true if the given string correctly initialized this object 122 // (i.e. if IsOk() returns true after this call) 123 bool FromString(const wxString& str); 124 125 126 private: 127 // common part of Create() and FromString() 128 static bool ParseAccel(const wxString& str, int *flags, int *keycode); 129 130 131 int m_flags; // combination of wxACCEL_XXX constants 132 int m_keyCode; // ASCII or virtual keycode 133 int m_command; // Command id to generate 134 135 // the menu item this entry corresponds to, may be NULL 136 wxMenuItem *m_item; 137 138 // for compatibility with old code, use accessors now! 139 friend class WXDLLIMPEXP_FWD_CORE wxMenu; 140 }; 141 142 // ---------------------------------------------------------------------------- 143 // include wxAcceleratorTable class declaration, it is only used by the library 144 // and so doesn't have any published user visible interface 145 // ---------------------------------------------------------------------------- 146 147 #if defined(__WXUNIVERSAL__) 148 #include "wx/generic/accel.h" 149 #elif defined(__WXMSW__) 150 #include "wx/msw/accel.h" 151 #elif defined(__WXMOTIF__) 152 #include "wx/motif/accel.h" 153 #elif defined(__WXGTK20__) 154 #include "wx/gtk/accel.h" 155 #elif defined(__WXGTK__) 156 #include "wx/gtk1/accel.h" 157 #elif defined(__WXMAC__) 158 #include "wx/mac/accel.h" 159 #elif defined(__WXCOCOA__) 160 #include "wx/generic/accel.h" 161 #elif defined(__WXPM__) 162 #include "wx/os2/accel.h" 163 #endif 164 165 extern WXDLLEXPORT_DATA(wxAcceleratorTable) wxNullAcceleratorTable; 166 167 #endif // wxUSE_ACCEL 168 169 #endif 170 // _WX_ACCEL_H_BASE_ 171