1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxAcceleratorEntry and wxAcceleratorTable classes
4 // Author: Julian Smart, Robert Roebling, Vadim Zeitlin
6 // Created: 31.05.01 (extracted from other files)
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_ACCEL_H_BASE_
13 #define _WX_ACCEL_H_BASE_
19 #include "wx/object.h"
21 class WXDLLIMPEXP_FWD_CORE wxAcceleratorTable
;
22 class WXDLLIMPEXP_FWD_CORE wxMenuItem
;
23 class WXDLLIMPEXP_FWD_CORE wxKeyEvent
;
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
29 // wxAcceleratorEntry flags
30 enum wxAcceleratorEntryFlags
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_RAW_CTRL
= 0x0008, //
39 wxACCEL_RAW_CTRL
= wxACCEL_CTRL
,
41 wxACCEL_CMD
= wxACCEL_CTRL
44 // ----------------------------------------------------------------------------
45 // an entry in wxAcceleratorTable corresponds to one accelerator
46 // ----------------------------------------------------------------------------
48 class WXDLLIMPEXP_CORE wxAcceleratorEntry
51 wxAcceleratorEntry(int flags
= 0, int keyCode
= 0, int cmd
= 0,
52 wxMenuItem
*item
= NULL
)
59 wxAcceleratorEntry(const wxAcceleratorEntry
& entry
)
60 : m_flags(entry
.m_flags
)
61 , m_keyCode(entry
.m_keyCode
)
62 , m_command(entry
.m_command
)
63 , m_item(entry
.m_item
)
66 // create accelerator corresponding to the specified string, return NULL if
67 // string couldn't be parsed or a pointer to be deleted by the caller
68 static wxAcceleratorEntry
*Create(const wxString
& str
);
70 wxAcceleratorEntry
& operator=(const wxAcceleratorEntry
& entry
)
73 Set(entry
.m_flags
, entry
.m_keyCode
, entry
.m_command
, entry
.m_item
);
77 void Set(int flags
, int keyCode
, int cmd
, wxMenuItem
*item
= NULL
)
85 void SetMenuItem(wxMenuItem
*item
) { m_item
= item
; }
87 int GetFlags() const { return m_flags
; }
88 int GetKeyCode() const { return m_keyCode
; }
89 int GetCommand() const { return m_command
; }
91 wxMenuItem
*GetMenuItem() const { return m_item
; }
93 bool operator==(const wxAcceleratorEntry
& entry
) const
95 return m_flags
== entry
.m_flags
&&
96 m_keyCode
== entry
.m_keyCode
&&
97 m_command
== entry
.m_command
&&
98 m_item
== entry
.m_item
;
101 bool operator!=(const wxAcceleratorEntry
& entry
) const
102 { return !(*this == entry
); }
104 #if defined(__WXMOTIF__)
105 // Implementation use only
106 bool MatchesEvent(const wxKeyEvent
& event
) const;
111 return m_keyCode
!= 0;
115 // string <-> wxAcceleratorEntry conversion
116 // ----------------------------------------
118 // returns a wxString for the this accelerator.
119 // this function formats it using the <flags>-<keycode> format
120 // where <flags> maybe a hyphen-separated list of "shift|alt|ctrl"
121 wxString
ToString() const;
123 // returns true if the given string correctly initialized this object
124 // (i.e. if IsOk() returns true after this call)
125 bool FromString(const wxString
& str
);
129 // common part of Create() and FromString()
130 static bool ParseAccel(const wxString
& str
, int *flags
, int *keycode
);
133 int m_flags
; // combination of wxACCEL_XXX constants
134 int m_keyCode
; // ASCII or virtual keycode
135 int m_command
; // Command id to generate
137 // the menu item this entry corresponds to, may be NULL
140 // for compatibility with old code, use accessors now!
141 friend class WXDLLIMPEXP_FWD_CORE wxMenu
;
144 // ----------------------------------------------------------------------------
145 // include wxAcceleratorTable class declaration, it is only used by the library
146 // and so doesn't have any published user visible interface
147 // ----------------------------------------------------------------------------
149 #if defined(__WXUNIVERSAL__)
150 #include "wx/generic/accel.h"
151 #elif defined(__WXMSW__)
152 #include "wx/msw/accel.h"
153 #elif defined(__WXMOTIF__)
154 #include "wx/motif/accel.h"
155 #elif defined(__WXGTK20__)
156 #include "wx/gtk/accel.h"
157 #elif defined(__WXGTK__)
158 #include "wx/gtk1/accel.h"
159 #elif defined(__WXMAC__)
160 #include "wx/osx/accel.h"
161 #elif defined(__WXCOCOA__)
162 #include "wx/generic/accel.h"
163 #elif defined(__WXPM__)
164 #include "wx/os2/accel.h"
167 extern WXDLLIMPEXP_DATA_CORE(wxAcceleratorTable
) wxNullAcceleratorTable
;
169 #endif // wxUSE_ACCEL