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 WXDLLEXPORT wxAcceleratorTable
;
22 class WXDLLEXPORT wxMenuItem
;
23 class WXDLLEXPORT wxKeyEvent
;
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
29 // wxAcceleratorEntry flags
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
39 wxACCEL_CMD
= wxACCEL_CTRL
43 // ----------------------------------------------------------------------------
44 // an entry in wxAcceleratorTable corresponds to one accelerator
45 // ----------------------------------------------------------------------------
47 class WXDLLEXPORT wxAcceleratorEntry
50 wxAcceleratorEntry(int flags
= 0, int keyCode
= 0, int cmd
= 0,
51 wxMenuItem
*item
= NULL
)
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
)
65 wxAcceleratorEntry
& operator=(const wxAcceleratorEntry
& entry
)
67 Set(entry
.m_flags
, entry
.m_keyCode
, entry
.m_command
, entry
.m_item
);
71 void Set(int flags
, int keyCode
, int cmd
, wxMenuItem
*item
= NULL
)
79 void SetMenuItem(wxMenuItem
*item
) { m_item
= item
; }
81 int GetFlags() const { return m_flags
; }
82 int GetKeyCode() const { return m_keyCode
; }
83 int GetCommand() const { return m_command
; }
85 wxMenuItem
*GetMenuItem() const { return m_item
; }
87 bool operator==(const wxAcceleratorEntry
& entry
) const
89 return m_flags
== entry
.m_flags
&&
90 m_keyCode
== entry
.m_keyCode
&&
91 m_command
== entry
.m_command
&&
92 m_item
== entry
.m_item
;
95 bool operator!=(const wxAcceleratorEntry
& entry
) const
96 { return !(*this == entry
); }
98 #if defined(__WXMOTIF__)
99 // Implementation use only
100 bool MatchesEvent(const wxKeyEvent
& event
) const;
105 return m_flags
!= 0 &&
110 // string <-> wxAcceleratorEntry conversion
111 // ----------------------------------------
113 // returns a wxString for the this accelerator.
114 // this function formats it using the <flags>-<keycode> format
115 // where <flags> maybe a hyphen-separed list of "shift|alt|ctrl"
116 wxString
ToString() const;
118 // returns true if the given string correctly initialized this object
119 // (i.e. if IsOk() returns true after this call)
120 bool FromString(const wxString
&str
);
124 int m_flags
; // combination of wxACCEL_XXX constants
125 int m_keyCode
; // ASCII or virtual keycode
126 int m_command
; // Command id to generate
128 // the menu item this entry corresponds to, may be NULL
131 // for compatibility with old code, use accessors now!
132 friend class WXDLLEXPORT wxMenu
;
135 // ----------------------------------------------------------------------------
136 // include wxAcceleratorTable class declaration, it is only used by the library
137 // and so doesn't have any published user visible interface
138 // ----------------------------------------------------------------------------
140 #if defined(__WXUNIVERSAL__)
141 #include "wx/generic/accel.h"
142 #elif defined(__WXMSW__)
143 #include "wx/msw/accel.h"
144 #elif defined(__WXMOTIF__)
145 #include "wx/motif/accel.h"
146 #elif defined(__WXGTK20__)
147 #include "wx/gtk/accel.h"
148 #elif defined(__WXGTK__)
149 #include "wx/gtk1/accel.h"
150 #elif defined(__WXMAC__)
151 #include "wx/mac/accel.h"
152 #elif defined(__WXCOCOA__)
153 #include "wx/generic/accel.h"
154 #elif defined(__WXPM__)
155 #include "wx/os2/accel.h"
158 extern WXDLLEXPORT_DATA(wxAcceleratorTable
) wxNullAcceleratorTable
;
160 #endif // wxUSE_ACCEL