]> git.saurik.com Git - wxWidgets.git/blame - include/wx/accel.h
Fix menu event handlers calling order.
[wxWidgets.git] / include / wx / accel.h
CommitLineData
1e6feb95
VZ
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$
77ffb593 8// Copyright: (c) wxWidgets team
65571936 9// Licence: wxWindows licence
1e6feb95
VZ
10///////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_ACCEL_H_BASE_
13#define _WX_ACCEL_H_BASE_
14
1e6feb95
VZ
15#include "wx/defs.h"
16
17#if wxUSE_ACCEL
18
19#include "wx/object.h"
20
b5dbe15d
VS
21class WXDLLIMPEXP_FWD_CORE wxAcceleratorTable;
22class WXDLLIMPEXP_FWD_CORE wxMenuItem;
23class WXDLLIMPEXP_FWD_CORE wxKeyEvent;
1e6feb95
VZ
24
25// ----------------------------------------------------------------------------
26// constants
27// ----------------------------------------------------------------------------
28
29// wxAcceleratorEntry flags
7cec3a32 30enum wxAcceleratorEntryFlags
1e6feb95
VZ
31{
32 wxACCEL_NORMAL = 0x0000, // no modifiers
33 wxACCEL_ALT = 0x0001, // hold Alt key down
34 wxACCEL_CTRL = 0x0002, // hold Ctrl key down
e3141a34
SC
35 wxACCEL_SHIFT = 0x0004, // hold Shift key down
36#if defined(__WXMAC__) || defined(__WXCOCOA__)
5266f345 37 wxACCEL_RAW_CTRL= 0x0008, //
e3141a34 38#else
5266f345 39 wxACCEL_RAW_CTRL= wxACCEL_CTRL,
e3141a34 40#endif
5266f345 41 wxACCEL_CMD = wxACCEL_CTRL
1e6feb95
VZ
42};
43
44// ----------------------------------------------------------------------------
45// an entry in wxAcceleratorTable corresponds to one accelerator
46// ----------------------------------------------------------------------------
47
53a2db12 48class WXDLLIMPEXP_CORE wxAcceleratorEntry
1e6feb95
VZ
49{
50public:
51 wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0,
52 wxMenuItem *item = NULL)
54380f29
GD
53 : m_flags(flags)
54 , m_keyCode(keyCode)
55 , m_command(cmd)
56 , m_item(item)
57 { }
58
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)
64 { }
65
90527a50
VZ
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);
69
54380f29 70 wxAcceleratorEntry& operator=(const wxAcceleratorEntry& entry)
1e6feb95 71 {
162e998c
PC
72 if (&entry != this)
73 Set(entry.m_flags, entry.m_keyCode, entry.m_command, entry.m_item);
54380f29 74 return *this;
1e6feb95 75 }
4629016d 76
1e6feb95
VZ
77 void Set(int flags, int keyCode, int cmd, wxMenuItem *item = NULL)
78 {
79 m_flags = flags;
80 m_keyCode = keyCode;
81 m_command = cmd;
82 m_item = item;
83 }
84
85 void SetMenuItem(wxMenuItem *item) { m_item = item; }
86
87 int GetFlags() const { return m_flags; }
88 int GetKeyCode() const { return m_keyCode; }
89 int GetCommand() const { return m_command; }
90
91 wxMenuItem *GetMenuItem() const { return m_item; }
92
93 bool operator==(const wxAcceleratorEntry& entry) const
94 {
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;
99 }
100
101 bool operator!=(const wxAcceleratorEntry& entry) const
102 { return !(*this == entry); }
103
b82d2a00 104#if defined(__WXMOTIF__)
45f22d48 105 // Implementation use only
b82d2a00 106 bool MatchesEvent(const wxKeyEvent& event) const;
45f22d48 107#endif
4629016d 108
ee0a94cf
RR
109 bool IsOk() const
110 {
395da337 111 return m_keyCode != 0;
ee0a94cf
RR
112 }
113
114
115 // string <-> wxAcceleratorEntry conversion
116 // ----------------------------------------
117
118 // returns a wxString for the this accelerator.
119 // this function formats it using the <flags>-<keycode> format
4c51a665 120 // where <flags> maybe a hyphen-separated list of "shift|alt|ctrl"
86f5e64b
VZ
121 wxString ToString() const { return AsPossiblyLocalizedString(true); }
122
123 // same as above but without translating, useful if the string is meant to
124 // be stored in a file or otherwise stored, instead of being shown to the
125 // user
126 wxString ToRawString() const { return AsPossiblyLocalizedString(false); }
ee0a94cf
RR
127
128 // returns true if the given string correctly initialized this object
129 // (i.e. if IsOk() returns true after this call)
90527a50 130 bool FromString(const wxString& str);
ee0a94cf
RR
131
132
1e6feb95 133private:
86f5e64b
VZ
134 wxString AsPossiblyLocalizedString(bool localized) const;
135
90527a50
VZ
136 // common part of Create() and FromString()
137 static bool ParseAccel(const wxString& str, int *flags, int *keycode);
138
139
1e6feb95
VZ
140 int m_flags; // combination of wxACCEL_XXX constants
141 int m_keyCode; // ASCII or virtual keycode
142 int m_command; // Command id to generate
143
144 // the menu item this entry corresponds to, may be NULL
145 wxMenuItem *m_item;
146
147 // for compatibility with old code, use accessors now!
b5dbe15d 148 friend class WXDLLIMPEXP_FWD_CORE wxMenu;
1e6feb95
VZ
149};
150
151// ----------------------------------------------------------------------------
152// include wxAcceleratorTable class declaration, it is only used by the library
153// and so doesn't have any published user visible interface
154// ----------------------------------------------------------------------------
155
156#if defined(__WXUNIVERSAL__)
157 #include "wx/generic/accel.h"
158#elif defined(__WXMSW__)
159 #include "wx/msw/accel.h"
34138703 160#elif defined(__WXMOTIF__)
1e6feb95 161 #include "wx/motif/accel.h"
1be7a35c 162#elif defined(__WXGTK20__)
1e6feb95 163 #include "wx/gtk/accel.h"
1be7a35c
MR
164#elif defined(__WXGTK__)
165 #include "wx/gtk1/accel.h"
34138703 166#elif defined(__WXMAC__)
ef0e9220 167 #include "wx/osx/accel.h"
0201182b
DE
168#elif defined(__WXCOCOA__)
169 #include "wx/generic/accel.h"
1777b9bb 170#elif defined(__WXPM__)
1e6feb95 171 #include "wx/os2/accel.h"
34138703
JS
172#endif
173
53a2db12 174extern WXDLLIMPEXP_DATA_CORE(wxAcceleratorTable) wxNullAcceleratorTable;
1e6feb95
VZ
175
176#endif // wxUSE_ACCEL
177
34138703
JS
178#endif
179 // _WX_ACCEL_H_BASE_