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