]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
c54de5ae | 2 | // Name: src/common/event.cpp |
c801d85f KB |
3 | // Purpose: Event classes |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
55d99c7a | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
8e193f38 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
c801d85f KB |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
0b746ba8 | 24 | #pragma hdrstop |
c801d85f KB |
25 | #endif |
26 | ||
d5da0ce7 | 27 | #include "wx/event.h" |
937013e0 | 28 | #include "wx/evtloop.h" |
d5da0ce7 | 29 | |
c801d85f | 30 | #ifndef WX_PRECOMP |
e90c1d2a | 31 | #include "wx/list.h" |
8bd9fa33 | 32 | #include "wx/log.h" |
8ecff181 | 33 | #include "wx/app.h" |
de6185e2 | 34 | #include "wx/utils.h" |
bb90a3e6 | 35 | #include "wx/stopwatch.h" |
02761f6c | 36 | #include "wx/module.h" |
e90c1d2a VZ |
37 | |
38 | #if wxUSE_GUI | |
a8ff046b | 39 | #include "wx/window.h" |
e90c1d2a | 40 | #include "wx/control.h" |
e90c1d2a | 41 | #include "wx/dc.h" |
dca94103 | 42 | #include "wx/spinbutt.h" |
75a29298 | 43 | #include "wx/textctrl.h" |
264cb7f5 | 44 | #include "wx/validate.h" |
e90c1d2a | 45 | #endif // wxUSE_GUI |
c801d85f KB |
46 | #endif |
47 | ||
204abcd4 | 48 | #include "wx/thread.h" |
47b6fabc | 49 | |
d102b02a | 50 | #if wxUSE_BASE |
664e1314 | 51 | #include "wx/scopedptr.h" |
d102b02a VZ |
52 | |
53 | wxDECLARE_SCOPED_PTR(wxEvent, wxEventPtr) | |
54 | wxDEFINE_SCOPED_PTR(wxEvent, wxEventPtr) | |
55 | #endif // wxUSE_BASE | |
204abcd4 | 56 | |
8e193f38 VZ |
57 | // ---------------------------------------------------------------------------- |
58 | // wxWin macros | |
59 | // ---------------------------------------------------------------------------- | |
60 | ||
3ed2104c VZ |
61 | #if wxUSE_BASE |
62 | IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject) | |
63 | IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject) | |
b46b1d59 | 64 | IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent) |
3ed2104c | 65 | #endif // wxUSE_BASE |
e90c1d2a | 66 | |
23f681ec VZ |
67 | #if wxUSE_GUI |
68 | IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent) | |
43c8c1f3 | 69 | IMPLEMENT_DYNAMIC_CLASS(wxThreadEvent, wxCommandEvent) |
23f681ec VZ |
70 | IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent) |
71 | IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent) | |
72 | IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent, wxEvent) | |
73 | IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent, wxEvent) | |
74 | IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent) | |
75 | IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent) | |
76 | IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent) | |
1e6feb95 | 77 | IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent, wxEvent) |
23f681ec VZ |
78 | IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent) |
79 | IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent) | |
80 | IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent) | |
456bc6d9 | 81 | IMPLEMENT_DYNAMIC_CLASS(wxChildFocusEvent, wxCommandEvent) |
23f681ec VZ |
82 | IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent, wxEvent) |
83 | IMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent) | |
84 | IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent) | |
85 | IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent) | |
86 | IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent) | |
87 | IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent) | |
88 | IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent) | |
89 | IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent, wxEvent) | |
90 | IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent, wxEvent) | |
8e72b8b5 | 91 | IMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent, wxEvent) |
23f681ec | 92 | IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent) |
574c939e | 93 | IMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent, wxEvent) |
23f681ec | 94 | IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent) |
75299490 | 95 | IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxEvent) |
23f681ec VZ |
96 | IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent, wxEvent) |
97 | IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent, wxEvent) | |
98 | IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent, wxEvent) | |
99 | IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent, wxEvent) | |
b96340e6 | 100 | IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent, wxCommandEvent) |
69231000 | 101 | IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent, wxCommandEvent) |
a5e84126 | 102 | IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent, wxEvent) |
63e819f2 | 103 | IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureLostEvent, wxEvent) |
78c91815 | 104 | IMPLEMENT_DYNAMIC_CLASS(wxClipboardTextEvent, wxCommandEvent) |
23f681ec | 105 | #endif // wxUSE_GUI |
0b746ba8 | 106 | |
3ed2104c VZ |
107 | #if wxUSE_BASE |
108 | ||
23f681ec VZ |
109 | const wxEventTable *wxEvtHandler::GetEventTable() const |
110 | { return &wxEvtHandler::sm_eventTable; } | |
0b746ba8 | 111 | |
23f681ec VZ |
112 | const wxEventTable wxEvtHandler::sm_eventTable = |
113 | { (const wxEventTable *)NULL, &wxEvtHandler::sm_eventTableEntries[0] }; | |
0b746ba8 | 114 | |
b5a98acd VZ |
115 | wxEventHashTable &wxEvtHandler::GetEventHashTable() const |
116 | { return wxEvtHandler::sm_eventHashTable; } | |
117 | ||
118 | wxEventHashTable wxEvtHandler::sm_eventHashTable(wxEvtHandler::sm_eventTable); | |
119 | ||
23f681ec | 120 | const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] = |
3c778901 | 121 | { DECLARE_EVENT_TABLE_TERMINATOR() }; |
c801d85f | 122 | |
1a18887b | 123 | |
a0826b11 VZ |
124 | // wxUSE_MEMORY_TRACING considers memory freed from the static objects dtors |
125 | // leaked, so we need to manually clean up all event tables before checking for | |
126 | // the memory leaks when using it, however this breaks re-initializing the | |
127 | // library (i.e. repeated calls to wxInitialize/wxUninitialize) because the | |
128 | // event tables won't be rebuilt the next time, so disable this by default | |
aa767a45 | 129 | #if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING |
a0826b11 | 130 | |
afa039f9 JS |
131 | class wxEventTableEntryModule: public wxModule |
132 | { | |
afa039f9 | 133 | public: |
a0826b11 VZ |
134 | wxEventTableEntryModule() { } |
135 | virtual bool OnInit() { return true; } | |
136 | virtual void OnExit() { wxEventHashTable::ClearAll(); } | |
137 | ||
138 | DECLARE_DYNAMIC_CLASS(wxEventTableEntryModule) | |
afa039f9 | 139 | }; |
a0826b11 | 140 | |
afa039f9 | 141 | IMPLEMENT_DYNAMIC_CLASS(wxEventTableEntryModule, wxModule) |
a0826b11 VZ |
142 | |
143 | #endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING | |
1a18887b | 144 | |
8e193f38 VZ |
145 | // ---------------------------------------------------------------------------- |
146 | // global variables | |
147 | // ---------------------------------------------------------------------------- | |
148 | ||
2e4df4bf VZ |
149 | // common event types are defined here, other event types are defined by the |
150 | // components which use them | |
b5a98acd | 151 | |
c15d9c85 VS |
152 | const wxEventType wxEVT_FIRST = 10000; |
153 | const wxEventType wxEVT_USER_FIRST = wxEVT_FIRST + 2000; | |
2e4df4bf | 154 | |
461697c2 | 155 | DEFINE_EVENT_TYPE(wxEVT_NULL) |
9b11752c | 156 | wxDEFINE_EVENT( wxEVT_IDLE, wxIdleEvent ); |
886dd7d2 | 157 | |
886dd7d2 VZ |
158 | #endif // wxUSE_BASE |
159 | ||
160 | #if wxUSE_GUI | |
161 | ||
9b11752c VZ |
162 | wxDEFINE_EVENT( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEvent ); |
163 | wxDEFINE_EVENT( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEvent ); | |
164 | wxDEFINE_EVENT( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEvent ); | |
165 | wxDEFINE_EVENT( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEvent ); | |
166 | wxDEFINE_EVENT( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEvent ); | |
167 | wxDEFINE_EVENT( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, wxCommandEvent ); | |
168 | wxDEFINE_EVENT( wxEVT_COMMAND_MENU_SELECTED, wxCommandEvent ); | |
169 | wxDEFINE_EVENT( wxEVT_COMMAND_SLIDER_UPDATED, wxCommandEvent ); | |
170 | wxDEFINE_EVENT( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEvent ); | |
171 | wxDEFINE_EVENT( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEvent ); | |
172 | wxDEFINE_EVENT( wxEVT_COMMAND_SCROLLBAR_UPDATED, wxCommandEvent ); | |
173 | wxDEFINE_EVENT( wxEVT_COMMAND_VLBOX_SELECTED, wxCommandEvent ); | |
174 | wxDEFINE_EVENT( wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEvent ); | |
175 | wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_RCLICKED, wxCommandEvent ); | |
176 | wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_ENTER, wxCommandEvent ); | |
177 | wxDEFINE_EVENT( wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEvent ); | |
178 | wxDEFINE_EVENT( wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, wxCommandEvent ); | |
179 | wxDEFINE_EVENT( wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED, wxCommandEvent ); | |
0b5eceb6 | 180 | |
0b5eceb6 | 181 | // Mouse event types |
9b11752c VZ |
182 | wxDEFINE_EVENT( wxEVT_LEFT_DOWN, wxMouseEvent ); |
183 | wxDEFINE_EVENT( wxEVT_LEFT_UP, wxMouseEvent ); | |
184 | wxDEFINE_EVENT( wxEVT_MIDDLE_DOWN, wxMouseEvent ); | |
185 | wxDEFINE_EVENT( wxEVT_MIDDLE_UP, wxMouseEvent ); | |
186 | wxDEFINE_EVENT( wxEVT_RIGHT_DOWN, wxMouseEvent ); | |
187 | wxDEFINE_EVENT( wxEVT_RIGHT_UP, wxMouseEvent ); | |
188 | wxDEFINE_EVENT( wxEVT_MOTION, wxMouseEvent ); | |
189 | wxDEFINE_EVENT( wxEVT_ENTER_WINDOW, wxMouseEvent ); | |
190 | wxDEFINE_EVENT( wxEVT_LEAVE_WINDOW, wxMouseEvent ); | |
191 | wxDEFINE_EVENT( wxEVT_LEFT_DCLICK, wxMouseEvent ); | |
192 | wxDEFINE_EVENT( wxEVT_MIDDLE_DCLICK, wxMouseEvent ); | |
193 | wxDEFINE_EVENT( wxEVT_RIGHT_DCLICK, wxMouseEvent ); | |
194 | wxDEFINE_EVENT( wxEVT_SET_FOCUS, wxFocusEvent ); | |
195 | wxDEFINE_EVENT( wxEVT_KILL_FOCUS, wxFocusEvent ); | |
196 | wxDEFINE_EVENT( wxEVT_CHILD_FOCUS, wxChildFocusEvent ); | |
197 | wxDEFINE_EVENT( wxEVT_MOUSEWHEEL, wxMouseEvent ); | |
198 | wxDEFINE_EVENT( wxEVT_AUX1_DOWN, wxMouseEvent ); | |
199 | wxDEFINE_EVENT( wxEVT_AUX1_UP, wxMouseEvent ); | |
200 | wxDEFINE_EVENT( wxEVT_AUX1_DCLICK, wxMouseEvent ); | |
201 | wxDEFINE_EVENT( wxEVT_AUX2_DOWN, wxMouseEvent ); | |
202 | wxDEFINE_EVENT( wxEVT_AUX2_UP, wxMouseEvent ); | |
203 | wxDEFINE_EVENT( wxEVT_AUX2_DCLICK, wxMouseEvent ); | |
0b5eceb6 VZ |
204 | |
205 | // Character input event type | |
9b11752c VZ |
206 | wxDEFINE_EVENT( wxEVT_CHAR, wxKeyEvent ); |
207 | wxDEFINE_EVENT( wxEVT_CHAR_HOOK, wxKeyEvent ); | |
208 | wxDEFINE_EVENT( wxEVT_NAVIGATION_KEY, wxNavigationKeyEvent ); | |
209 | wxDEFINE_EVENT( wxEVT_KEY_DOWN, wxKeyEvent ); | |
210 | wxDEFINE_EVENT( wxEVT_KEY_UP, wxKeyEvent ); | |
5048c832 | 211 | #if wxUSE_HOTKEY |
9b11752c | 212 | wxDEFINE_EVENT( wxEVT_HOTKEY, wxKeyEvent ); |
5048c832 | 213 | #endif |
0b5eceb6 VZ |
214 | |
215 | // Set cursor event | |
9b11752c | 216 | wxDEFINE_EVENT( wxEVT_SET_CURSOR, wxSetCursorEvent ); |
0b5eceb6 VZ |
217 | |
218 | // wxScrollbar and wxSlider event identifiers | |
9b11752c VZ |
219 | wxDEFINE_EVENT( wxEVT_SCROLL_TOP, wxScrollEvent ); |
220 | wxDEFINE_EVENT( wxEVT_SCROLL_BOTTOM, wxScrollEvent ); | |
221 | wxDEFINE_EVENT( wxEVT_SCROLL_LINEUP, wxScrollEvent ); | |
222 | wxDEFINE_EVENT( wxEVT_SCROLL_LINEDOWN, wxScrollEvent ); | |
223 | wxDEFINE_EVENT( wxEVT_SCROLL_PAGEUP, wxScrollEvent ); | |
224 | wxDEFINE_EVENT( wxEVT_SCROLL_PAGEDOWN, wxScrollEvent ); | |
225 | wxDEFINE_EVENT( wxEVT_SCROLL_THUMBTRACK, wxScrollEvent ); | |
226 | wxDEFINE_EVENT( wxEVT_SCROLL_THUMBRELEASE, wxScrollEvent ); | |
227 | wxDEFINE_EVENT( wxEVT_SCROLL_CHANGED, wxScrollEvent ); | |
0b5eceb6 | 228 | |
dca94103 VZ |
229 | // Due to a bug in older wx versions, wxSpinEvents were being sent with type of |
230 | // wxEVT_SCROLL_LINEUP, wxEVT_SCROLL_LINEDOWN and wxEVT_SCROLL_THUMBTRACK. But | |
231 | // with the type-safe events in place, these event types are associated with | |
232 | // wxScrollEvent. To allow handling of spin events, new event types have been | |
233 | // defined in spinbutt.h/spinnbuttcmn.cpp. To maintain backward compatibility | |
234 | // the spin event types are being initialized with the scroll event types. | |
235 | ||
236 | #if wxUSE_SPINBTN | |
237 | ||
9b11752c VZ |
238 | wxDEFINE_EVENT_ALIAS( wxEVT_SPIN_UP, wxSpinEvent, wxEVT_SCROLL_LINEUP ); |
239 | wxDEFINE_EVENT_ALIAS( wxEVT_SPIN_DOWN, wxSpinEvent, wxEVT_SCROLL_LINEDOWN ); | |
240 | wxDEFINE_EVENT_ALIAS( wxEVT_SPIN, wxSpinEvent, wxEVT_SCROLL_THUMBTRACK ); | |
dca94103 VZ |
241 | |
242 | #endif // wxUSE_SPINBTN | |
243 | ||
0b5eceb6 | 244 | // Scroll events from wxWindow |
9b11752c VZ |
245 | wxDEFINE_EVENT( wxEVT_SCROLLWIN_TOP, wxScrollWinEvent ); |
246 | wxDEFINE_EVENT( wxEVT_SCROLLWIN_BOTTOM, wxScrollWinEvent ); | |
247 | wxDEFINE_EVENT( wxEVT_SCROLLWIN_LINEUP, wxScrollWinEvent ); | |
248 | wxDEFINE_EVENT( wxEVT_SCROLLWIN_LINEDOWN, wxScrollWinEvent ); | |
249 | wxDEFINE_EVENT( wxEVT_SCROLLWIN_PAGEUP, wxScrollWinEvent ); | |
250 | wxDEFINE_EVENT( wxEVT_SCROLLWIN_PAGEDOWN, wxScrollWinEvent ); | |
251 | wxDEFINE_EVENT( wxEVT_SCROLLWIN_THUMBTRACK, wxScrollWinEvent ); | |
252 | wxDEFINE_EVENT( wxEVT_SCROLLWIN_THUMBRELEASE, wxScrollWinEvent ); | |
0b5eceb6 VZ |
253 | |
254 | // System events | |
9b11752c VZ |
255 | wxDEFINE_EVENT( wxEVT_SIZE, wxSizeEvent ); |
256 | wxDEFINE_EVENT( wxEVT_SIZING, wxSizeEvent ); | |
257 | wxDEFINE_EVENT( wxEVT_MOVE, wxMoveEvent ); | |
258 | wxDEFINE_EVENT( wxEVT_MOVING, wxMoveEvent ); | |
259 | wxDEFINE_EVENT( wxEVT_MOVE_START, wxMoveEvent ); | |
260 | wxDEFINE_EVENT( wxEVT_MOVE_END, wxMoveEvent ); | |
261 | wxDEFINE_EVENT( wxEVT_CLOSE_WINDOW, wxCloseEvent ); | |
262 | wxDEFINE_EVENT( wxEVT_END_SESSION, wxCloseEvent ); | |
263 | wxDEFINE_EVENT( wxEVT_QUERY_END_SESSION, wxCloseEvent ); | |
264 | wxDEFINE_EVENT( wxEVT_HIBERNATE, wxActivateEvent ); | |
265 | wxDEFINE_EVENT( wxEVT_ACTIVATE_APP, wxActivateEvent ); | |
266 | wxDEFINE_EVENT( wxEVT_ACTIVATE, wxActivateEvent ); | |
267 | wxDEFINE_EVENT( wxEVT_CREATE, wxWindowCreateEvent ); | |
268 | wxDEFINE_EVENT( wxEVT_DESTROY, wxWindowDestroyEvent ); | |
269 | wxDEFINE_EVENT( wxEVT_SHOW, wxShowEvent ); | |
270 | wxDEFINE_EVENT( wxEVT_ICONIZE, wxIconizeEvent ); | |
271 | wxDEFINE_EVENT( wxEVT_MAXIMIZE, wxMaximizeEvent ); | |
272 | wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_CHANGED, wxMouseCaptureChangedEvent ); | |
273 | wxDEFINE_EVENT( wxEVT_MOUSE_CAPTURE_LOST, wxMouseCaptureLostEvent ); | |
274 | wxDEFINE_EVENT( wxEVT_PAINT, wxPaintEvent ); | |
275 | wxDEFINE_EVENT( wxEVT_ERASE_BACKGROUND, wxEraseEvent ); | |
276 | wxDEFINE_EVENT( wxEVT_NC_PAINT, wxNcPaintEvent ); | |
277 | wxDEFINE_EVENT( wxEVT_MENU_OPEN, wxMenuEvent ); | |
278 | wxDEFINE_EVENT( wxEVT_MENU_CLOSE, wxMenuEvent ); | |
279 | wxDEFINE_EVENT( wxEVT_MENU_HIGHLIGHT, wxMenuEvent ); | |
280 | wxDEFINE_EVENT( wxEVT_CONTEXT_MENU, wxContextMenuEvent ); | |
281 | wxDEFINE_EVENT( wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEvent ); | |
282 | wxDEFINE_EVENT( wxEVT_DISPLAY_CHANGED, wxDisplayChangedEvent ); | |
283 | wxDEFINE_EVENT( wxEVT_QUERY_NEW_PALETTE, wxQueryNewPaletteEvent ); | |
284 | wxDEFINE_EVENT( wxEVT_PALETTE_CHANGED, wxPaletteChangedEvent ); | |
285 | wxDEFINE_EVENT( wxEVT_JOY_BUTTON_DOWN, wxJoystickEvent ); | |
286 | wxDEFINE_EVENT( wxEVT_JOY_BUTTON_UP, wxJoystickEvent ); | |
287 | wxDEFINE_EVENT( wxEVT_JOY_MOVE, wxJoystickEvent ); | |
288 | wxDEFINE_EVENT( wxEVT_JOY_ZMOVE, wxJoystickEvent ); | |
289 | wxDEFINE_EVENT( wxEVT_DROP_FILES, wxDropFilesEvent ); | |
290 | wxDEFINE_EVENT( wxEVT_INIT_DIALOG, wxInitDialogEvent ); | |
291 | wxDEFINE_EVENT( wxEVT_UPDATE_UI, wxUpdateUIEvent ); | |
0b5eceb6 | 292 | |
78c91815 | 293 | // Clipboard events |
9b11752c VZ |
294 | wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_COPY, wxClipboardTextEvent ); |
295 | wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_CUT, wxClipboardTextEvent ); | |
296 | wxDEFINE_EVENT( wxEVT_COMMAND_TEXT_PASTE, wxClipboardTextEvent ); | |
78c91815 | 297 | |
0b5eceb6 VZ |
298 | // Generic command events |
299 | // Note: a click is a higher-level event than button down/up | |
9b11752c VZ |
300 | wxDEFINE_EVENT( wxEVT_COMMAND_LEFT_CLICK, wxCommandEvent ); |
301 | wxDEFINE_EVENT( wxEVT_COMMAND_LEFT_DCLICK, wxCommandEvent ); | |
302 | wxDEFINE_EVENT( wxEVT_COMMAND_RIGHT_CLICK, wxCommandEvent ); | |
303 | wxDEFINE_EVENT( wxEVT_COMMAND_RIGHT_DCLICK, wxCommandEvent ); | |
304 | wxDEFINE_EVENT( wxEVT_COMMAND_SET_FOCUS, wxCommandEvent ); | |
305 | wxDEFINE_EVENT( wxEVT_COMMAND_KILL_FOCUS, wxCommandEvent ); | |
306 | wxDEFINE_EVENT( wxEVT_COMMAND_ENTER, wxCommandEvent ); | |
0b5eceb6 VZ |
307 | |
308 | // Help events | |
9b11752c VZ |
309 | wxDEFINE_EVENT( wxEVT_HELP, wxHelpEvent ); |
310 | wxDEFINE_EVENT( wxEVT_DETAILED_HELP, wxHelpEvent ); | |
6164f93c | 311 | |
d48b06bd | 312 | // Thread event |
9b11752c | 313 | wxDEFINE_EVENT( wxEVT_COMMAND_THREAD, wxThreadEvent ); |
d48b06bd | 314 | |
886dd7d2 VZ |
315 | #endif // wxUSE_GUI |
316 | ||
317 | #if wxUSE_BASE | |
318 | ||
b46b1d59 VZ |
319 | wxIdleMode wxIdleEvent::sm_idleMode = wxIDLE_PROCESS_ALL; |
320 | ||
6164f93c VZ |
321 | // ============================================================================ |
322 | // implementation | |
323 | // ============================================================================ | |
0b5eceb6 | 324 | |
0b5eceb6 VZ |
325 | // ---------------------------------------------------------------------------- |
326 | // event initialization | |
327 | // ---------------------------------------------------------------------------- | |
328 | ||
329 | int wxNewEventType() | |
330 | { | |
331 | // MT-FIXME | |
332 | static int s_lastUsedEventType = wxEVT_FIRST; | |
333 | ||
334 | return s_lastUsedEventType++; | |
335 | } | |
3c778901 VZ |
336 | // ---------------------------------------------------------------------------- |
337 | // wxEventFunctor | |
338 | // ---------------------------------------------------------------------------- | |
339 | ||
340 | wxEventFunctor::~wxEventFunctor() | |
341 | { | |
342 | } | |
0b5eceb6 | 343 | |
8e193f38 VZ |
344 | // ---------------------------------------------------------------------------- |
345 | // wxEvent | |
346 | // ---------------------------------------------------------------------------- | |
347 | ||
c801d85f | 348 | /* |
d48b06bd FM |
349 | * General wxWidgets events, covering all interesting things that might happen |
350 | * (button clicking, resizing, setting text in widgets, etc.). | |
c801d85f KB |
351 | * |
352 | * For each completely new event type, derive a new event class. | |
353 | * | |
354 | */ | |
355 | ||
d48b06bd | 356 | wxEvent::wxEvent(int theId, wxEventType commandType) |
c801d85f | 357 | { |
8e72b8b5 | 358 | m_eventType = commandType; |
3c778901 | 359 | m_eventObject = NULL; |
0b746ba8 VZ |
360 | m_timeStamp = 0; |
361 | m_id = theId; | |
1c624631 | 362 | m_skipped = false; |
3c778901 | 363 | m_callbackUserData = NULL; |
1c624631 | 364 | m_isCommandEvent = false; |
1648d51b | 365 | m_propagationLevel = wxEVENT_PROPAGATE_NONE; |
29de6f40 | 366 | m_wasProcessed = false; |
c801d85f KB |
367 | } |
368 | ||
0e097789 | 369 | wxEvent::wxEvent(const wxEvent& src) |
a34ef99b | 370 | : wxObject(src) |
e6a6feba GD |
371 | , m_eventObject(src.m_eventObject) |
372 | , m_eventType(src.m_eventType) | |
373 | , m_timeStamp(src.m_timeStamp) | |
374 | , m_id(src.m_id) | |
375 | , m_callbackUserData(src.m_callbackUserData) | |
6fd5903a | 376 | , m_propagationLevel(src.m_propagationLevel) |
e6a6feba GD |
377 | , m_skipped(src.m_skipped) |
378 | , m_isCommandEvent(src.m_isCommandEvent) | |
29de6f40 | 379 | , m_wasProcessed(false) |
a737331d | 380 | { |
a737331d GL |
381 | } |
382 | ||
0e097789 VZ |
383 | wxEvent& wxEvent::operator=(const wxEvent& src) |
384 | { | |
385 | wxObject::operator=(src); | |
386 | ||
387 | m_eventObject = src.m_eventObject; | |
388 | m_eventType = src.m_eventType; | |
389 | m_timeStamp = src.m_timeStamp; | |
390 | m_id = src.m_id; | |
391 | m_callbackUserData = src.m_callbackUserData; | |
392 | m_propagationLevel = src.m_propagationLevel; | |
393 | m_skipped = src.m_skipped; | |
394 | m_isCommandEvent = src.m_isCommandEvent; | |
395 | ||
29de6f40 VZ |
396 | // don't change m_wasProcessed |
397 | ||
0e097789 VZ |
398 | return *this; |
399 | } | |
400 | ||
3ed2104c VZ |
401 | #endif // wxUSE_BASE |
402 | ||
e90c1d2a VZ |
403 | #if wxUSE_GUI |
404 | ||
c801d85f KB |
405 | /* |
406 | * Command events | |
407 | * | |
408 | */ | |
409 | ||
21eefb76 VZ |
410 | #ifdef __VISUALC__ |
411 | // 'this' : used in base member initializer list (for m_commandString) | |
412 | #pragma warning(disable:4355) | |
413 | #endif | |
414 | ||
7798a18e | 415 | wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId) |
b5a98acd | 416 | : wxEvent(theId, commandType) |
c801d85f | 417 | { |
3c778901 VZ |
418 | m_clientData = NULL; |
419 | m_clientObject = NULL; | |
0b746ba8 VZ |
420 | m_extraLong = 0; |
421 | m_commandInt = 0; | |
1c624631 | 422 | m_isCommandEvent = true; |
1648d51b VZ |
423 | |
424 | // the command events are propagated upwards by default | |
425 | m_propagationLevel = wxEVENT_PROPAGATE_MAX; | |
c801d85f KB |
426 | } |
427 | ||
21eefb76 VZ |
428 | #ifdef __VISUALC__ |
429 | #pragma warning(default:4355) | |
430 | #endif | |
431 | ||
ab1931f9 KH |
432 | wxString wxCommandEvent::GetString() const |
433 | { | |
cc6ceca7 VZ |
434 | if (m_eventType != wxEVT_COMMAND_TEXT_UPDATED || !m_eventObject) |
435 | { | |
ab1931f9 | 436 | return m_cmdString; |
cc6ceca7 | 437 | } |
ab1931f9 KH |
438 | else |
439 | { | |
89438177 | 440 | #if wxUSE_TEXTCTRL |
ab1931f9 | 441 | wxTextCtrl *txt = wxDynamicCast(m_eventObject, wxTextCtrl); |
cc6ceca7 | 442 | if ( txt ) |
ab1931f9 KH |
443 | return txt->GetValue(); |
444 | else | |
89438177 | 445 | #endif // wxUSE_TEXTCTRL |
ab1931f9 KH |
446 | return m_cmdString; |
447 | } | |
448 | } | |
449 | ||
0b30bb0b JS |
450 | /* |
451 | * UI update events | |
452 | */ | |
453 | ||
454 | #if wxUSE_LONGLONG | |
e39af974 | 455 | wxLongLong wxUpdateUIEvent::sm_lastUpdate = 0; |
0b30bb0b JS |
456 | #endif |
457 | ||
e39af974 JS |
458 | long wxUpdateUIEvent::sm_updateInterval = 0; |
459 | ||
460 | wxUpdateUIMode wxUpdateUIEvent::sm_updateMode = wxUPDATE_UI_PROCESS_ALL; | |
0b30bb0b JS |
461 | |
462 | // Can we update? | |
a7bc03c9 | 463 | bool wxUpdateUIEvent::CanUpdate(wxWindowBase *win) |
0b30bb0b | 464 | { |
e39af974 JS |
465 | // Don't update if we've switched global updating off |
466 | // and this window doesn't support updates. | |
467 | if (win && | |
468 | (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED && | |
469 | ((win->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES) == 0))) | |
1c624631 | 470 | return false; |
b5a98acd | 471 | |
e39af974 | 472 | if (sm_updateInterval == -1) |
1c624631 | 473 | return false; |
534b127c WS |
474 | |
475 | if (sm_updateInterval == 0) | |
1c624631 | 476 | return true; |
534b127c | 477 | |
0b30bb0b | 478 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG |
534b127c WS |
479 | wxLongLong now = wxGetLocalTimeMillis(); |
480 | if (now > (sm_lastUpdate + sm_updateInterval)) | |
481 | { | |
1c624631 | 482 | return true; |
0b30bb0b | 483 | } |
534b127c | 484 | |
1c624631 | 485 | return false; |
534b127c WS |
486 | #else |
487 | // If we don't have wxStopWatch or wxLongLong, we | |
488 | // should err on the safe side and update now anyway. | |
489 | return true; | |
490 | #endif | |
0b30bb0b JS |
491 | } |
492 | ||
493 | // Reset the update time to provide a delay until the next | |
494 | // time we should update | |
495 | void wxUpdateUIEvent::ResetUpdateTime() | |
496 | { | |
497 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG | |
e39af974 | 498 | if (sm_updateInterval > 0) |
0b30bb0b JS |
499 | { |
500 | wxLongLong now = wxGetLocalTimeMillis(); | |
e39af974 | 501 | if (now > (sm_lastUpdate + sm_updateInterval)) |
0b30bb0b | 502 | { |
e39af974 | 503 | sm_lastUpdate = now; |
0b30bb0b JS |
504 | } |
505 | } | |
506 | #endif | |
507 | } | |
508 | ||
c801d85f KB |
509 | /* |
510 | * Scroll events | |
511 | */ | |
512 | ||
0b746ba8 VZ |
513 | wxScrollEvent::wxScrollEvent(wxEventType commandType, |
514 | int id, | |
515 | int pos, | |
516 | int orient) | |
e6a6feba | 517 | : wxCommandEvent(commandType, id) |
c801d85f | 518 | { |
0b746ba8 VZ |
519 | m_extraLong = orient; |
520 | m_commandInt = pos; | |
c801d85f KB |
521 | } |
522 | ||
d1367c3d RR |
523 | /* |
524 | * ScrollWin events | |
525 | */ | |
526 | ||
527 | wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType, | |
528 | int pos, | |
529 | int orient) | |
d1367c3d | 530 | { |
c5b42c87 | 531 | m_eventType = commandType; |
d1367c3d RR |
532 | m_extraLong = orient; |
533 | m_commandInt = pos; | |
534 | } | |
535 | ||
c801d85f KB |
536 | /* |
537 | * Mouse events | |
538 | * | |
539 | */ | |
540 | ||
7798a18e | 541 | wxMouseEvent::wxMouseEvent(wxEventType commandType) |
c801d85f | 542 | { |
0b746ba8 | 543 | m_eventType = commandType; |
8866abbb VZ |
544 | |
545 | m_x = 0; | |
546 | m_y = 0; | |
547 | ||
1c624631 | 548 | m_leftDown = false; |
1c624631 | 549 | m_middleDown = false; |
8866abbb | 550 | m_rightDown = false; |
01101e2d VZ |
551 | m_aux1Down = false; |
552 | m_aux2Down = false; | |
8866abbb | 553 | |
8866abbb VZ |
554 | m_clickCount = -1; |
555 | ||
d2c52078 RD |
556 | m_wheelRotation = 0; |
557 | m_wheelDelta = 0; | |
558 | m_linesPerAction = 0; | |
aea37008 | 559 | m_wheelAxis = 0; |
c801d85f KB |
560 | } |
561 | ||
abcbaea7 VZ |
562 | void wxMouseEvent::Assign(const wxMouseEvent& event) |
563 | { | |
0e097789 | 564 | wxEvent::operator=(event); |
3232da9d VZ |
565 | |
566 | // Borland C++ 5.82 doesn't compile an explicit call to an implicitly | |
567 | // defined operator=() so need to do it this way: | |
568 | *static_cast<wxMouseState *>(this) = event; | |
92309201 | 569 | |
abcbaea7 VZ |
570 | m_x = event.m_x; |
571 | m_y = event.m_y; | |
572 | ||
573 | m_leftDown = event.m_leftDown; | |
574 | m_middleDown = event.m_middleDown; | |
575 | m_rightDown = event.m_rightDown; | |
01101e2d VZ |
576 | m_aux1Down = event.m_aux1Down; |
577 | m_aux2Down = event.m_aux2Down; | |
abcbaea7 | 578 | |
abcbaea7 VZ |
579 | m_wheelRotation = event.m_wheelRotation; |
580 | m_wheelDelta = event.m_wheelDelta; | |
581 | m_linesPerAction = event.m_linesPerAction; | |
aea37008 | 582 | m_wheelAxis = event.m_wheelAxis; |
abcbaea7 VZ |
583 | } |
584 | ||
3e89999c | 585 | // return true if was a button dclick event |
c801d85f KB |
586 | bool wxMouseEvent::ButtonDClick(int but) const |
587 | { | |
0b746ba8 VZ |
588 | switch (but) |
589 | { | |
3e89999c VZ |
590 | default: |
591 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick")); | |
592 | // fall through | |
593 | ||
594 | case wxMOUSE_BTN_ANY: | |
01101e2d VZ |
595 | return (LeftDClick() || MiddleDClick() || RightDClick() || |
596 | Aux1DClick() || Aux2DClick()); | |
3e89999c VZ |
597 | |
598 | case wxMOUSE_BTN_LEFT: | |
0b746ba8 | 599 | return LeftDClick(); |
3e89999c VZ |
600 | |
601 | case wxMOUSE_BTN_MIDDLE: | |
0b746ba8 | 602 | return MiddleDClick(); |
3e89999c VZ |
603 | |
604 | case wxMOUSE_BTN_RIGHT: | |
0b746ba8 | 605 | return RightDClick(); |
01101e2d VZ |
606 | |
607 | case wxMOUSE_BTN_AUX1: | |
608 | return Aux1DClick(); | |
609 | ||
610 | case wxMOUSE_BTN_AUX2: | |
611 | return Aux2DClick(); | |
0b746ba8 | 612 | } |
c801d85f KB |
613 | } |
614 | ||
3e89999c | 615 | // return true if was a button down event |
c801d85f KB |
616 | bool wxMouseEvent::ButtonDown(int but) const |
617 | { | |
0b746ba8 VZ |
618 | switch (but) |
619 | { | |
3e89999c VZ |
620 | default: |
621 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown")); | |
622 | // fall through | |
623 | ||
624 | case wxMOUSE_BTN_ANY: | |
01101e2d VZ |
625 | return (LeftDown() || MiddleDown() || RightDown() || |
626 | Aux1Down() || Aux2Down()); | |
3e89999c VZ |
627 | |
628 | case wxMOUSE_BTN_LEFT: | |
0b746ba8 | 629 | return LeftDown(); |
3e89999c VZ |
630 | |
631 | case wxMOUSE_BTN_MIDDLE: | |
0b746ba8 | 632 | return MiddleDown(); |
3e89999c VZ |
633 | |
634 | case wxMOUSE_BTN_RIGHT: | |
0b746ba8 | 635 | return RightDown(); |
01101e2d VZ |
636 | |
637 | case wxMOUSE_BTN_AUX1: | |
638 | return Aux1Down(); | |
639 | ||
640 | case wxMOUSE_BTN_AUX2: | |
641 | return Aux2Down(); | |
0b746ba8 | 642 | } |
c801d85f KB |
643 | } |
644 | ||
3e89999c | 645 | // return true if was a button up event |
c801d85f KB |
646 | bool wxMouseEvent::ButtonUp(int but) const |
647 | { | |
1e6feb95 VZ |
648 | switch (but) |
649 | { | |
3e89999c VZ |
650 | default: |
651 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp")); | |
652 | // fall through | |
653 | ||
654 | case wxMOUSE_BTN_ANY: | |
01101e2d VZ |
655 | return (LeftUp() || MiddleUp() || RightUp() || |
656 | Aux1Up() || Aux2Up()); | |
3e89999c VZ |
657 | |
658 | case wxMOUSE_BTN_LEFT: | |
0b746ba8 | 659 | return LeftUp(); |
3e89999c VZ |
660 | |
661 | case wxMOUSE_BTN_MIDDLE: | |
0b746ba8 | 662 | return MiddleUp(); |
3e89999c VZ |
663 | |
664 | case wxMOUSE_BTN_RIGHT: | |
0b746ba8 | 665 | return RightUp(); |
01101e2d VZ |
666 | |
667 | case wxMOUSE_BTN_AUX1: | |
668 | return Aux1Up(); | |
669 | ||
670 | case wxMOUSE_BTN_AUX2: | |
671 | return Aux2Up(); | |
0b746ba8 | 672 | } |
c801d85f KB |
673 | } |
674 | ||
3e89999c | 675 | // return true if the given button is currently changing state |
c801d85f KB |
676 | bool wxMouseEvent::Button(int but) const |
677 | { | |
1e6feb95 VZ |
678 | switch (but) |
679 | { | |
0b746ba8 | 680 | default: |
223d09f6 | 681 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button")); |
3e89999c VZ |
682 | // fall through |
683 | ||
684 | case wxMOUSE_BTN_ANY: | |
685 | return ButtonUp(wxMOUSE_BTN_ANY) || | |
686 | ButtonDown(wxMOUSE_BTN_ANY) || | |
687 | ButtonDClick(wxMOUSE_BTN_ANY); | |
688 | ||
689 | case wxMOUSE_BTN_LEFT: | |
690 | return LeftDown() || LeftUp() || LeftDClick(); | |
691 | ||
692 | case wxMOUSE_BTN_MIDDLE: | |
693 | return MiddleDown() || MiddleUp() || MiddleDClick(); | |
694 | ||
695 | case wxMOUSE_BTN_RIGHT: | |
696 | return RightDown() || RightUp() || RightDClick(); | |
01101e2d VZ |
697 | |
698 | case wxMOUSE_BTN_AUX1: | |
699 | return Aux1Down() || Aux1Up() || Aux1DClick(); | |
700 | ||
701 | case wxMOUSE_BTN_AUX2: | |
702 | return Aux2Down() || Aux2Up() || Aux2DClick(); | |
0b746ba8 | 703 | } |
c801d85f KB |
704 | } |
705 | ||
706 | bool wxMouseEvent::ButtonIsDown(int but) const | |
707 | { | |
1e6feb95 VZ |
708 | switch (but) |
709 | { | |
3e89999c VZ |
710 | default: |
711 | wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown")); | |
712 | // fall through | |
713 | ||
714 | case wxMOUSE_BTN_ANY: | |
01101e2d | 715 | return LeftIsDown() || MiddleIsDown() || RightIsDown() || Aux1Down() || Aux2Down(); |
3e89999c VZ |
716 | |
717 | case wxMOUSE_BTN_LEFT: | |
0b746ba8 | 718 | return LeftIsDown(); |
3e89999c VZ |
719 | |
720 | case wxMOUSE_BTN_MIDDLE: | |
0b746ba8 | 721 | return MiddleIsDown(); |
3e89999c VZ |
722 | |
723 | case wxMOUSE_BTN_RIGHT: | |
0b746ba8 | 724 | return RightIsDown(); |
01101e2d VZ |
725 | |
726 | case wxMOUSE_BTN_AUX1: | |
727 | return Aux1IsDown(); | |
728 | ||
729 | case wxMOUSE_BTN_AUX2: | |
730 | return Aux2IsDown(); | |
0b746ba8 | 731 | } |
c801d85f KB |
732 | } |
733 | ||
1e6feb95 VZ |
734 | int wxMouseEvent::GetButton() const |
735 | { | |
01101e2d | 736 | for ( int i = 1; i < wxMOUSE_BTN_MAX; i++ ) |
1e6feb95 VZ |
737 | { |
738 | if ( Button(i) ) | |
739 | { | |
740 | return i; | |
741 | } | |
742 | } | |
743 | ||
3e89999c | 744 | return wxMOUSE_BTN_NONE; |
1e6feb95 VZ |
745 | } |
746 | ||
c801d85f KB |
747 | // Find the logical position of the event given the DC |
748 | wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const | |
749 | { | |
0757d27c JS |
750 | wxPoint pt(dc.DeviceToLogicalX(m_x), dc.DeviceToLogicalY(m_y)); |
751 | return pt; | |
c801d85f KB |
752 | } |
753 | ||
754 | ||
755 | /* | |
8e72b8b5 | 756 | * Keyboard event |
c801d85f KB |
757 | * |
758 | */ | |
759 | ||
7798a18e | 760 | wxKeyEvent::wxKeyEvent(wxEventType type) |
c801d85f | 761 | { |
0b746ba8 | 762 | m_eventType = type; |
0b746ba8 | 763 | m_keyCode = 0; |
b0e813a0 | 764 | m_scanCode = 0; |
2b5f62a0 VZ |
765 | #if wxUSE_UNICODE |
766 | m_uniChar = 0; | |
767 | #endif | |
c801d85f KB |
768 | } |
769 | ||
92309201 | 770 | wxKeyEvent::wxKeyEvent(const wxKeyEvent& evt) |
0e097789 VZ |
771 | : wxEvent(evt), |
772 | wxKeyboardState(evt) | |
2b5f62a0 VZ |
773 | { |
774 | m_x = evt.m_x; | |
775 | m_y = evt.m_y; | |
776 | ||
777 | m_keyCode = evt.m_keyCode; | |
778 | ||
2b5f62a0 VZ |
779 | m_scanCode = evt.m_scanCode; |
780 | m_rawCode = evt.m_rawCode; | |
781 | m_rawFlags = evt.m_rawFlags; | |
92309201 | 782 | |
2b5f62a0 VZ |
783 | #if wxUSE_UNICODE |
784 | m_uniChar = evt.m_uniChar; | |
785 | #endif | |
786 | } | |
12a3f227 | 787 | |
42e69d6b | 788 | wxWindowCreateEvent::wxWindowCreateEvent(wxWindow *win) |
42e69d6b | 789 | { |
cfe17b74 | 790 | SetEventType(wxEVT_CREATE); |
42e69d6b VZ |
791 | SetEventObject(win); |
792 | } | |
793 | ||
794 | wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow *win) | |
42e69d6b | 795 | { |
cfe17b74 | 796 | SetEventType(wxEVT_DESTROY); |
42e69d6b VZ |
797 | SetEventObject(win); |
798 | } | |
799 | ||
456bc6d9 VZ |
800 | wxChildFocusEvent::wxChildFocusEvent(wxWindow *win) |
801 | : wxCommandEvent(wxEVT_CHILD_FOCUS) | |
802 | { | |
803 | SetEventObject(win); | |
804 | } | |
805 | ||
b107e8d5 VZ |
806 | // ---------------------------------------------------------------------------- |
807 | // wxHelpEvent | |
808 | // ---------------------------------------------------------------------------- | |
809 | ||
810 | /* static */ | |
811 | wxHelpEvent::Origin wxHelpEvent::GuessOrigin(Origin origin) | |
812 | { | |
813 | if ( origin == Origin_Unknown ) | |
814 | { | |
815 | // assume that the event comes from the help button if it's not from | |
816 | // keyboard and that pressing F1 always results in the help event | |
817 | origin = wxGetKeyState(WXK_F1) ? Origin_Keyboard : Origin_HelpButton; | |
818 | } | |
819 | ||
820 | return origin; | |
821 | } | |
822 | ||
dd070522 VZ |
823 | #endif // wxUSE_GUI |
824 | ||
9416681d VS |
825 | |
826 | #if wxUSE_BASE | |
827 | ||
b5a98acd VZ |
828 | // ---------------------------------------------------------------------------- |
829 | // wxEventHashTable | |
830 | // ---------------------------------------------------------------------------- | |
831 | ||
afa039f9 JS |
832 | static const int EVENT_TYPE_TABLE_INIT_SIZE = 31; // Not too big not too small... |
833 | ||
834 | wxEventHashTable* wxEventHashTable::sm_first = NULL; | |
b5a98acd VZ |
835 | |
836 | wxEventHashTable::wxEventHashTable(const wxEventTable &table) | |
837 | : m_table(table), | |
1c624631 | 838 | m_rebuildHash(true) |
b5a98acd VZ |
839 | { |
840 | AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE); | |
1a18887b | 841 | |
afa039f9 JS |
842 | m_next = sm_first; |
843 | if (m_next) | |
844 | m_next->m_previous = this; | |
845 | sm_first = this; | |
b5a98acd VZ |
846 | } |
847 | ||
848 | wxEventHashTable::~wxEventHashTable() | |
afa039f9 JS |
849 | { |
850 | if (m_next) | |
851 | m_next->m_previous = m_previous; | |
852 | if (m_previous) | |
853 | m_previous->m_next = m_next; | |
854 | if (sm_first == this) | |
855 | sm_first = m_next; | |
1a18887b | 856 | |
afa039f9 JS |
857 | Clear(); |
858 | } | |
859 | ||
860 | void wxEventHashTable::Clear() | |
b5a98acd | 861 | { |
a0826b11 | 862 | for ( size_t i = 0; i < m_size; i++ ) |
b5a98acd VZ |
863 | { |
864 | EventTypeTablePointer eTTnode = m_eventTypeTable[i]; | |
a0826b11 | 865 | delete eTTnode; |
b5a98acd VZ |
866 | } |
867 | ||
a0826b11 | 868 | delete[] m_eventTypeTable; |
afa039f9 | 869 | m_eventTypeTable = NULL; |
a0826b11 | 870 | |
afa039f9 JS |
871 | m_size = 0; |
872 | } | |
873 | ||
aa767a45 | 874 | #if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING |
a0826b11 | 875 | |
afa039f9 JS |
876 | // Clear all tables |
877 | void wxEventHashTable::ClearAll() | |
878 | { | |
879 | wxEventHashTable* table = sm_first; | |
880 | while (table) | |
881 | { | |
882 | table->Clear(); | |
883 | table = table->m_next; | |
884 | } | |
b5a98acd VZ |
885 | } |
886 | ||
a0826b11 VZ |
887 | #endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING |
888 | ||
b5a98acd VZ |
889 | bool wxEventHashTable::HandleEvent(wxEvent &event, wxEvtHandler *self) |
890 | { | |
891 | if (m_rebuildHash) | |
892 | { | |
893 | InitHashTable(); | |
1c624631 | 894 | m_rebuildHash = false; |
b5a98acd | 895 | } |
1a18887b | 896 | |
afa039f9 | 897 | if (!m_eventTypeTable) |
1a18887b | 898 | return false; |
b5a98acd VZ |
899 | |
900 | // Find all entries for the given event type. | |
901 | wxEventType eventType = event.GetEventType(); | |
902 | const EventTypeTablePointer eTTnode = m_eventTypeTable[eventType % m_size]; | |
903 | if (eTTnode && eTTnode->eventType == eventType) | |
904 | { | |
905 | // Now start the search for an event handler | |
906 | // that can handle an event with the given ID. | |
1c624631 VZ |
907 | const wxEventTableEntryPointerArray& |
908 | eventEntryTable = eTTnode->eventEntryTable; | |
b5a98acd | 909 | |
1c624631 VZ |
910 | const size_t count = eventEntryTable.GetCount(); |
911 | for (size_t n = 0; n < count; n++) | |
b5a98acd | 912 | { |
03f3617b VZ |
913 | const wxEventTableEntry& entry = *eventEntryTable[n]; |
914 | if ( wxEvtHandler::ProcessEventIfMatchesId(entry, self, event) ) | |
1c624631 | 915 | return true; |
b5a98acd | 916 | } |
b5a98acd VZ |
917 | } |
918 | ||
1c624631 | 919 | return false; |
b5a98acd VZ |
920 | } |
921 | ||
922 | void wxEventHashTable::InitHashTable() | |
923 | { | |
924 | // Loop over the event tables and all its base tables. | |
925 | const wxEventTable *table = &m_table; | |
926 | while (table) | |
927 | { | |
928 | // Retrieve all valid event handler entries | |
929 | const wxEventTableEntry *entry = table->entries; | |
930 | while (entry->m_fn != 0) | |
931 | { | |
932 | // Add the event entry in the Hash. | |
933 | AddEntry(*entry); | |
934 | ||
935 | entry++; | |
936 | } | |
937 | ||
938 | table = table->baseTable; | |
939 | } | |
940 | ||
941 | // Lets free some memory. | |
942 | size_t i; | |
943 | for(i = 0; i < m_size; i++) | |
944 | { | |
945 | EventTypeTablePointer eTTnode = m_eventTypeTable[i]; | |
946 | if (eTTnode) | |
947 | { | |
948 | eTTnode->eventEntryTable.Shrink(); | |
949 | } | |
950 | } | |
951 | } | |
952 | ||
953 | void wxEventHashTable::AddEntry(const wxEventTableEntry &entry) | |
954 | { | |
afa039f9 JS |
955 | // This might happen 'accidentally' as the app is exiting |
956 | if (!m_eventTypeTable) | |
957 | return; | |
1a18887b | 958 | |
b5a98acd VZ |
959 | EventTypeTablePointer *peTTnode = &m_eventTypeTable[entry.m_eventType % m_size]; |
960 | EventTypeTablePointer eTTnode = *peTTnode; | |
961 | ||
962 | if (eTTnode) | |
963 | { | |
964 | if (eTTnode->eventType != entry.m_eventType) | |
965 | { | |
966 | // Resize the table! | |
967 | GrowEventTypeTable(); | |
968 | // Try again to add it. | |
969 | AddEntry(entry); | |
970 | return; | |
971 | } | |
972 | } | |
973 | else | |
974 | { | |
975 | eTTnode = new EventTypeTable; | |
976 | eTTnode->eventType = entry.m_eventType; | |
977 | *peTTnode = eTTnode; | |
978 | } | |
979 | ||
980 | // Fill all hash entries between entry.m_id and entry.m_lastId... | |
981 | eTTnode->eventEntryTable.Add(&entry); | |
982 | } | |
983 | ||
984 | void wxEventHashTable::AllocEventTypeTable(size_t size) | |
985 | { | |
986 | m_eventTypeTable = new EventTypeTablePointer[size]; | |
987 | memset((void *)m_eventTypeTable, 0, sizeof(EventTypeTablePointer)*size); | |
988 | m_size = size; | |
989 | } | |
990 | ||
991 | void wxEventHashTable::GrowEventTypeTable() | |
992 | { | |
993 | size_t oldSize = m_size; | |
994 | EventTypeTablePointer *oldEventTypeTable = m_eventTypeTable; | |
995 | ||
996 | // TODO: Search the most optimal grow sequence | |
997 | AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize*2+1); | |
998 | ||
999 | for ( size_t i = 0; i < oldSize; /* */ ) | |
1000 | { | |
1001 | EventTypeTablePointer eTToldNode = oldEventTypeTable[i]; | |
1002 | if (eTToldNode) | |
1003 | { | |
1004 | EventTypeTablePointer *peTTnode = &m_eventTypeTable[eTToldNode->eventType % m_size]; | |
1005 | EventTypeTablePointer eTTnode = *peTTnode; | |
1006 | ||
1007 | // Check for collision, we don't want any. | |
1008 | if (eTTnode) | |
1009 | { | |
1010 | GrowEventTypeTable(); | |
1011 | continue; // Don't increment the counter, | |
1012 | // as we still need to add this element. | |
1013 | } | |
1014 | else | |
1015 | { | |
1016 | // Get the old value and put it in the new table. | |
1017 | *peTTnode = oldEventTypeTable[i]; | |
1018 | } | |
1019 | } | |
1020 | ||
1021 | i++; | |
1022 | } | |
1023 | ||
1024 | delete[] oldEventTypeTable; | |
1025 | } | |
1026 | ||
456bc6d9 VZ |
1027 | // ---------------------------------------------------------------------------- |
1028 | // wxEvtHandler | |
1029 | // ---------------------------------------------------------------------------- | |
1030 | ||
0b746ba8 | 1031 | wxEvtHandler::wxEvtHandler() |
c801d85f | 1032 | { |
3c778901 VZ |
1033 | m_nextHandler = NULL; |
1034 | m_previousHandler = NULL; | |
1c624631 | 1035 | m_enabled = true; |
3c778901 VZ |
1036 | m_dynamicEvents = NULL; |
1037 | m_pendingEvents = NULL; | |
aa767a45 | 1038 | |
b88c44e7 RD |
1039 | // no client data (yet) |
1040 | m_clientData = NULL; | |
1041 | m_clientDataType = wxClientData_None; | |
c801d85f KB |
1042 | } |
1043 | ||
0b746ba8 | 1044 | wxEvtHandler::~wxEvtHandler() |
c801d85f | 1045 | { |
7f853dd0 | 1046 | Unlink(); |
0b746ba8 VZ |
1047 | |
1048 | if (m_dynamicEvents) | |
fe71f65c | 1049 | { |
3c448b2e VZ |
1050 | for ( wxList::iterator it = m_dynamicEvents->begin(), |
1051 | end = m_dynamicEvents->end(); | |
1052 | it != end; | |
1053 | ++it ) | |
0b746ba8 | 1054 | { |
df5168c4 | 1055 | wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)*it; |
2e4df4bf | 1056 | |
cc6ceca7 | 1057 | // Remove ourselves from sink destructor notifications |
3c778901 | 1058 | // (this has usually been done, in wxTrackable destructor) |
f3ff831f | 1059 | wxEvtHandler *eventSink = entry->m_fn->GetEvtHandler(); |
cc6ceca7 | 1060 | if ( eventSink ) |
2ef989c9 | 1061 | { |
cc6ceca7 VZ |
1062 | wxEventConnectionRef * const |
1063 | evtConnRef = FindRefInTrackerList(eventSink); | |
1064 | if ( evtConnRef ) | |
1065 | { | |
1066 | eventSink->RemoveNode(evtConnRef); | |
1067 | delete evtConnRef; | |
1068 | } | |
2ef989c9 | 1069 | } |
cc6ceca7 | 1070 | |
3c778901 | 1071 | delete entry->m_callbackUserData; |
0b746ba8 | 1072 | delete entry; |
0b746ba8 VZ |
1073 | } |
1074 | delete m_dynamicEvents; | |
dde19c21 | 1075 | } |
7214297d | 1076 | |
5875d39c VZ |
1077 | if (m_pendingEvents) |
1078 | m_pendingEvents->DeleteContents(true); | |
7ce2fb71 | 1079 | delete m_pendingEvents; |
7214297d | 1080 | |
dde19c21 FM |
1081 | // Remove us from the list of the pending events if necessary. |
1082 | wxEventLoopBase *loop = wxEventLoopBase::GetActive(); | |
1083 | if (loop) | |
1084 | loop->RemovePendingEventHandler(this); | |
b88c44e7 RD |
1085 | |
1086 | // we only delete object data, not untyped | |
1087 | if ( m_clientDataType == wxClientData_Object ) | |
1088 | delete m_clientObject; | |
c801d85f KB |
1089 | } |
1090 | ||
7f853dd0 FM |
1091 | void wxEvtHandler::Unlink() |
1092 | { | |
1093 | // this event handler must take itself out of the chain of handlers: | |
1094 | ||
1095 | if (m_previousHandler) | |
1096 | m_previousHandler->SetNextHandler(m_nextHandler); | |
1097 | ||
1098 | if (m_nextHandler) | |
1099 | m_nextHandler->SetPreviousHandler(m_previousHandler); | |
1100 | ||
1101 | m_nextHandler = NULL; | |
1102 | m_previousHandler = NULL; | |
1103 | } | |
1104 | ||
1105 | bool wxEvtHandler::IsUnlinked() const | |
1106 | { | |
1107 | return m_previousHandler == NULL && | |
1108 | m_nextHandler == NULL; | |
1109 | } | |
1110 | ||
7214297d | 1111 | #if wxUSE_THREADS |
aadbdf11 | 1112 | |
76bfdc9a | 1113 | bool wxEvtHandler::ProcessThreadEvent(const wxEvent& event) |
7214297d | 1114 | { |
7214297d | 1115 | // check that we are really in a child thread |
8e193f38 VZ |
1116 | wxASSERT_MSG( !wxThread::IsMain(), |
1117 | wxT("use ProcessEvent() in main thread") ); | |
1118 | ||
1119 | AddPendingEvent(event); | |
7214297d | 1120 | |
1c624631 | 1121 | return true; |
8e193f38 VZ |
1122 | } |
1123 | ||
1124 | #endif // wxUSE_THREADS | |
1125 | ||
c3f94162 | 1126 | void wxEvtHandler::QueueEvent(wxEvent *event) |
8e193f38 | 1127 | { |
c3f94162 | 1128 | wxCHECK_RET( event, "NULL event can't be posted" ); |
7a5c8ac4 | 1129 | |
dde19c21 FM |
1130 | wxEventLoopBase* loop = wxEventLoopBase::GetActive(); |
1131 | if (!loop) | |
1132 | { | |
1133 | // we need an event loop which manages the list of event handlers with | |
1134 | // pending events... cannot proceed without it! | |
1135 | wxLogDebug("No event loop is running!"); | |
1136 | return; | |
1137 | } | |
1138 | ||
c3f94162 | 1139 | // 1) Add this event to our list of pending events |
8ebec7dc | 1140 | wxENTER_CRIT_SECT( m_pendingEventsLock ); |
16c1f79c | 1141 | |
8e193f38 VZ |
1142 | if ( !m_pendingEvents ) |
1143 | m_pendingEvents = new wxList; | |
7214297d | 1144 | |
c3f94162 | 1145 | m_pendingEvents->Append(event); |
7214297d | 1146 | |
16c1f79c RR |
1147 | // 2) Add this event handler to list of event handlers that |
1148 | // have pending events. | |
cfe17b74 | 1149 | |
dde19c21 | 1150 | loop->AppendPendingEventHandler(this); |
6164f93c | 1151 | |
a715b990 VZ |
1152 | // only release m_pendingEventsLock now because otherwise there is a race |
1153 | // condition as described in the ticket #9093: we could process the event | |
1154 | // just added to m_pendingEvents in our ProcessPendingEvents() below before | |
079f4130 | 1155 | // we had time to append this pointer to wxHandlersWithPendingEvents list; thus |
a715b990 VZ |
1156 | // breaking the invariant that a handler should be in the list iff it has |
1157 | // any pending events to process | |
1158 | wxLEAVE_CRIT_SECT( m_pendingEventsLock ); | |
1159 | ||
90e572f1 | 1160 | // 3) Inform the system that new pending events are somewhere, |
16c1f79c | 1161 | // and that these should be processed in idle time. |
bf9e3e73 | 1162 | wxWakeUpIdle(); |
7214297d GL |
1163 | } |
1164 | ||
1165 | void wxEvtHandler::ProcessPendingEvents() | |
1166 | { | |
dde19c21 FM |
1167 | wxEventLoopBase* loop = wxEventLoopBase::GetActive(); |
1168 | if (!loop) | |
1169 | { | |
1170 | // we need an event loop which manages the list of event handlers with | |
1171 | // pending events... cannot proceed without it! | |
1172 | wxLogDebug("No event loop is running!"); | |
1173 | return; | |
1174 | } | |
1175 | ||
d48b06bd FM |
1176 | // we need to process only a single pending event in this call because |
1177 | // each call to ProcessEvent() could result in the destruction of this | |
1178 | // same event handler (see the comment at the end of this function) | |
1179 | ||
8ebec7dc | 1180 | wxENTER_CRIT_SECT( m_pendingEventsLock ); |
8e193f38 | 1181 | |
7ce2fb71 VZ |
1182 | // this method is only called by wxApp if this handler does have |
1183 | // pending events | |
1184 | wxCHECK_RET( m_pendingEvents && !m_pendingEvents->IsEmpty(), | |
1185 | "should have pending events if called" ); | |
5fa150e2 | 1186 | |
19c4d916 | 1187 | wxList::compatibility_iterator node = m_pendingEvents->GetFirst(); |
d48b06bd FM |
1188 | wxEvent* pEvent = static_cast<wxEvent *>(node->GetData()); |
1189 | ||
1190 | // find the first event which can be processed now: | |
dde19c21 FM |
1191 | wxEventLoopBase* evtLoop = wxEventLoopBase::GetActive(); |
1192 | if (evtLoop && evtLoop->IsYielding()) | |
d48b06bd | 1193 | { |
dde19c21 | 1194 | while (node && pEvent && !evtLoop->IsEventAllowedInsideYield(pEvent->GetEventCategory())) |
d48b06bd FM |
1195 | { |
1196 | node = node->GetNext(); | |
1197 | pEvent = node ? static_cast<wxEvent *>(node->GetData()) : NULL; | |
1198 | } | |
1199 | ||
1200 | if (!node) | |
1201 | { | |
1202 | // all our events are NOT processable now... signal this: | |
dde19c21 FM |
1203 | loop->DelayPendingEventHandler(this); |
1204 | ||
1205 | // see the comment at the beginning of evtloop.h header for the | |
1206 | // logic behind YieldFor() and behind DelayPendingEventHandler() | |
1207 | ||
d48b06bd FM |
1208 | wxLEAVE_CRIT_SECT( m_pendingEventsLock ); |
1209 | ||
1210 | return; | |
1211 | } | |
1212 | } | |
1213 | ||
1214 | wxEventPtr event(pEvent); | |
5875d39c | 1215 | |
19c4d916 VZ |
1216 | // it's important we remove event from list before processing it, else a |
1217 | // nested event loop, for example from a modal dialog, might process the | |
1218 | // same event again. | |
1219 | m_pendingEvents->Erase(node); | |
7b0d5c59 | 1220 | |
19c4d916 | 1221 | if ( m_pendingEvents->IsEmpty() ) |
1512f0f7 | 1222 | { |
dde19c21 FM |
1223 | // if there are no more pending events left, we don't need to |
1224 | // stay in this list | |
1225 | loop->RemovePendingEventHandler(this); | |
1512f0f7 | 1226 | } |
5fa150e2 | 1227 | |
8ebec7dc | 1228 | wxLEAVE_CRIT_SECT( m_pendingEventsLock ); |
7b0d5c59 | 1229 | |
19c4d916 | 1230 | ProcessEvent(*event); |
cfe17b74 | 1231 | |
19c4d916 VZ |
1232 | // careful: this object could have been deleted by the event handler |
1233 | // executed by the above ProcessEvent() call, so we can't access any fields | |
1234 | // of this object any more | |
7214297d | 1235 | } |
7214297d | 1236 | |
c801d85f KB |
1237 | /* |
1238 | * Event table stuff | |
1239 | */ | |
1c624631 | 1240 | /* static */ bool |
03f3617b VZ |
1241 | wxEvtHandler::ProcessEventIfMatchesId(const wxEventTableEntryBase& entry, |
1242 | wxEvtHandler *handler, | |
1243 | wxEvent& event) | |
1c624631 VZ |
1244 | { |
1245 | int tableId1 = entry.m_id, | |
1246 | tableId2 = entry.m_lastId; | |
1247 | ||
1248 | // match only if the event type is the same and the id is either -1 in | |
1249 | // the event table (meaning "any") or the event id matches the id | |
1250 | // specified in the event table either exactly or by falling into | |
1251 | // range between first and last | |
1a18887b WS |
1252 | if ((tableId1 == wxID_ANY) || |
1253 | (tableId2 == wxID_ANY && tableId1 == event.GetId()) || | |
1254 | (tableId2 != wxID_ANY && | |
1c624631 VZ |
1255 | (event.GetId() >= tableId1 && event.GetId() <= tableId2))) |
1256 | { | |
1257 | event.Skip(false); | |
1258 | event.m_callbackUserData = entry.m_callbackUserData; | |
1259 | ||
1260 | #if wxUSE_EXCEPTIONS | |
1261 | if ( wxTheApp ) | |
1262 | { | |
1263 | // call the handler via wxApp method which allows the user to catch | |
1264 | // any exceptions which may be thrown by any handler in the program | |
1265 | // in one place | |
3c778901 | 1266 | wxTheApp->CallEventHandler(handler, *entry.m_fn, event); |
1c624631 VZ |
1267 | } |
1268 | else | |
8bd2a804 | 1269 | #endif // wxUSE_EXCEPTIONS |
1c624631 | 1270 | { |
3c778901 | 1271 | (*entry.m_fn)(handler, event); |
1c624631 | 1272 | } |
1c624631 VZ |
1273 | |
1274 | if (!event.GetSkipped()) | |
1275 | return true; | |
1276 | } | |
1277 | ||
1278 | return false; | |
1279 | } | |
c801d85f | 1280 | |
4caf847c | 1281 | bool wxEvtHandler::TryParent(wxEvent& event) |
c801d85f | 1282 | { |
358e9f2f VZ |
1283 | if ( GetNextHandler() ) |
1284 | { | |
1285 | // the next handler will pass it to wxTheApp if it doesn't process it, | |
1286 | // so return from here to avoid doing it again | |
1287 | return GetNextHandler()->TryParent(event); | |
1288 | } | |
1289 | ||
4caf847c | 1290 | if ( wxTheApp && (this != wxTheApp) ) |
9154d8cf | 1291 | { |
4caf847c VZ |
1292 | // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always |
1293 | // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be | |
1294 | // processed appropriately via SearchEventTable. | |
1295 | if ( event.GetEventType() != wxEVT_IDLE ) | |
1296 | { | |
1297 | if ( wxTheApp->ProcessEvent(event) ) | |
1c624631 | 1298 | return true; |
4caf847c | 1299 | } |
9154d8cf VZ |
1300 | } |
1301 | ||
1c624631 | 1302 | return false; |
4caf847c | 1303 | } |
0b746ba8 | 1304 | |
4caf847c VZ |
1305 | bool wxEvtHandler::ProcessEvent(wxEvent& event) |
1306 | { | |
9154d8cf | 1307 | // allow the application to hook into event processing |
29de6f40 VZ |
1308 | // |
1309 | // note that we should only do it if we're the first event handler called | |
1310 | // to avoid calling FilterEvent() multiple times as the event goes through | |
1311 | // the event handler chain and possibly upwards the window hierarchy | |
1312 | if ( !event.WasProcessed() ) | |
9154d8cf | 1313 | { |
29de6f40 | 1314 | if ( wxTheApp ) |
9154d8cf | 1315 | { |
d48b06bd FM |
1316 | /* |
1317 | CANNOT ENABLE: ProcessEvent() must always immediately process the event! | |
1318 | ||
1319 | if (wxTheApp->IsYielding() && | |
1320 | !wxTheApp->IsEventAllowedInsideYield(event.GetEventCategory())) | |
1321 | { | |
1322 | wxEvent* queuedEv = event.Clone(); | |
1323 | ||
1324 | // queue this event rather than processing it now | |
1325 | QueueEvent(queuedEv); | |
1326 | // the wxWakeUpIdle call shouldn't probably be done | |
1327 | // in this context (there's wxYield in the call stack) | |
1328 | ||
1329 | return true; | |
1330 | // it's not completely true that the event was processed; | |
1331 | // but we cannot even say it was skipped or discarded... | |
1332 | } | |
1333 | //else: either we're not inside a wxYield() call or if we are, | |
1334 | // we can process this event immediately. | |
1335 | */ | |
1336 | ||
29de6f40 VZ |
1337 | int rc = wxTheApp->FilterEvent(event); |
1338 | if ( rc != -1 ) | |
1339 | { | |
1340 | wxASSERT_MSG( rc == 1 || rc == 0, | |
1341 | "unexpected wxApp::FilterEvent return value" ); | |
9154d8cf | 1342 | |
29de6f40 VZ |
1343 | return rc != 0; |
1344 | } | |
1345 | //else: proceed normally | |
9154d8cf | 1346 | } |
9154d8cf VZ |
1347 | } |
1348 | ||
25250d33 VZ |
1349 | if ( ProcessEventHere(event) ) |
1350 | return true; | |
1351 | ||
29de6f40 VZ |
1352 | // pass the event to the next handler, notice that we shouldn't call |
1353 | // TryParent() even if it doesn't handle the event as the last handler in | |
1354 | // the chain will do it | |
1355 | if ( GetNextHandler() ) | |
1356 | return GetNextHandler()->ProcessEvent(event); | |
1357 | ||
25250d33 | 1358 | // propagate the event upwards the window chain and/or to the application |
c9c1faa4 | 1359 | // object if it wasn't processed at this level |
25250d33 VZ |
1360 | return TryParent(event); |
1361 | } | |
1362 | ||
1363 | bool wxEvtHandler::ProcessEventHere(wxEvent& event) | |
1364 | { | |
29de6f40 VZ |
1365 | // If the event handler is disabled it doesn't process any events |
1366 | if ( !GetEvtHandlerEnabled() ) | |
1367 | return false; | |
4caf847c | 1368 | |
29de6f40 VZ |
1369 | // If we have a validator, it has higher priority than our own event |
1370 | // handlers | |
1371 | if ( TryValidator(event) ) | |
1372 | return true; | |
0b746ba8 | 1373 | |
29de6f40 VZ |
1374 | // Handle per-instance dynamic event tables first |
1375 | if ( m_dynamicEvents && SearchDynamicEventTable(event) ) | |
1376 | return true; | |
c801d85f | 1377 | |
29de6f40 VZ |
1378 | // Then static per-class event tables |
1379 | if ( GetEventHashTable().HandleEvent(event, this) ) | |
25250d33 | 1380 | return true; |
c801d85f | 1381 | |
25250d33 VZ |
1382 | // We don't have a handler for this event. |
1383 | return false; | |
c801d85f KB |
1384 | } |
1385 | ||
937013e0 VS |
1386 | bool wxEvtHandler::SafelyProcessEvent(wxEvent& event) |
1387 | { | |
1388 | #if wxUSE_EXCEPTIONS | |
1389 | try | |
1390 | { | |
1391 | #endif | |
1392 | return ProcessEvent(event); | |
1393 | #if wxUSE_EXCEPTIONS | |
1394 | } | |
1395 | catch ( ... ) | |
1396 | { | |
1397 | wxEventLoopBase *loop = wxEventLoopBase::GetActive(); | |
1398 | try | |
1399 | { | |
1400 | if ( !wxTheApp || !wxTheApp->OnExceptionInMainLoop() ) | |
1401 | { | |
1402 | if ( loop ) | |
1403 | loop->Exit(); | |
1404 | } | |
1405 | //else: continue running current event loop | |
1406 | ||
1407 | return false; | |
1408 | } | |
1409 | catch ( ... ) | |
1410 | { | |
1411 | // OnExceptionInMainLoop() threw, possibly rethrowing the same | |
1412 | // exception again: very good, but we still need Exit() to | |
1413 | // be called | |
1414 | if ( loop ) | |
1415 | loop->Exit(); | |
1416 | throw; | |
1417 | } | |
1418 | } | |
1419 | #endif // wxUSE_EXCEPTIONS | |
1420 | } | |
1421 | ||
b5a98acd | 1422 | |
c801d85f KB |
1423 | bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event) |
1424 | { | |
1c624631 | 1425 | const wxEventType eventType = event.GetEventType(); |
68662769 | 1426 | for ( int i = 0; table.entries[i].m_fn != 0; i++ ) |
c801d85f | 1427 | { |
68662769 | 1428 | const wxEventTableEntry& entry = table.entries[i]; |
68662769 | 1429 | if ( eventType == entry.m_eventType ) |
0b746ba8 | 1430 | { |
03f3617b | 1431 | if ( ProcessEventIfMatchesId(entry, this, event) ) |
1c624631 | 1432 | return true; |
0b746ba8 | 1433 | } |
c801d85f | 1434 | } |
68662769 | 1435 | |
1c624631 | 1436 | return false; |
c801d85f | 1437 | } |
97d7bfb8 | 1438 | |
f3ff831f VZ |
1439 | void wxEvtHandler::DoConnect(int id, |
1440 | int lastId, | |
1441 | wxEventType eventType, | |
1442 | wxEventFunctor *func, | |
1443 | wxObject *userData) | |
fe71f65c | 1444 | { |
0b5eceb6 | 1445 | wxDynamicEventTableEntry *entry = |
3c778901 | 1446 | new wxDynamicEventTableEntry(eventType, id, lastId, func, userData); |
0b746ba8 VZ |
1447 | |
1448 | if (!m_dynamicEvents) | |
1449 | m_dynamicEvents = new wxList; | |
1450 | ||
92309201 RD |
1451 | // Insert at the front of the list so most recent additions are found first |
1452 | m_dynamicEvents->Insert( (wxObject*) entry ); | |
cc6ceca7 VZ |
1453 | |
1454 | // Make sure we get to know when a sink is destroyed | |
f3ff831f | 1455 | wxEvtHandler *eventSink = func->GetEvtHandler(); |
886274c6 | 1456 | if ( eventSink && eventSink != this ) |
2ef989c9 | 1457 | { |
cc6ceca7 VZ |
1458 | wxEventConnectionRef *evtConnRef = FindRefInTrackerList(eventSink); |
1459 | if ( evtConnRef ) | |
1460 | evtConnRef->IncRef( ); | |
2ef989c9 | 1461 | else |
e822d1bd | 1462 | new wxEventConnectionRef(this, eventSink); |
2ef989c9 | 1463 | } |
fe71f65c | 1464 | } |
97d7bfb8 | 1465 | |
3c778901 | 1466 | bool |
f3ff831f VZ |
1467 | wxEvtHandler::DoDisconnect(int id, |
1468 | int lastId, | |
1469 | wxEventType eventType, | |
1470 | const wxEventFunctor& func, | |
1471 | wxObject *userData) | |
97d7bfb8 RR |
1472 | { |
1473 | if (!m_dynamicEvents) | |
1c624631 | 1474 | return false; |
cfe17b74 | 1475 | |
2ef989c9 | 1476 | // Remove connection from tracker node (wxEventConnectionRef) |
f3ff831f | 1477 | wxEvtHandler *eventSink = func.GetEvtHandler(); |
886274c6 | 1478 | if ( eventSink && eventSink != this ) |
2ef989c9 | 1479 | { |
cc6ceca7 VZ |
1480 | wxEventConnectionRef *evtConnRef = FindRefInTrackerList(eventSink); |
1481 | if ( evtConnRef ) | |
1482 | evtConnRef->DecRef(); | |
2ef989c9 RR |
1483 | } |
1484 | ||
df5168c4 | 1485 | wxList::compatibility_iterator node = m_dynamicEvents->GetFirst(); |
97d7bfb8 RR |
1486 | while (node) |
1487 | { | |
ad684023 | 1488 | wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData(); |
2e4df4bf | 1489 | |
97d7bfb8 | 1490 | if ((entry->m_id == id) && |
1a18887b | 1491 | ((entry->m_lastId == lastId) || (lastId == wxID_ANY)) && |
97d7bfb8 | 1492 | ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) && |
03f3617b | 1493 | entry->m_fn->Matches(func) && |
3c778901 | 1494 | ((entry->m_callbackUserData == userData) || !userData)) |
97d7bfb8 | 1495 | { |
3c778901 | 1496 | delete entry->m_callbackUserData; |
df5168c4 | 1497 | m_dynamicEvents->Erase( node ); |
97d7bfb8 | 1498 | delete entry; |
1c624631 | 1499 | return true; |
97d7bfb8 | 1500 | } |
b1d4dd7a | 1501 | node = node->GetNext(); |
97d7bfb8 | 1502 | } |
1c624631 | 1503 | return false; |
97d7bfb8 | 1504 | } |
fe71f65c RR |
1505 | |
1506 | bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event ) | |
1507 | { | |
1c624631 | 1508 | wxCHECK_MSG( m_dynamicEvents, false, |
223d09f6 | 1509 | wxT("caller should check that we have dynamic events") ); |
0b746ba8 | 1510 | |
df5168c4 | 1511 | wxList::compatibility_iterator node = m_dynamicEvents->GetFirst(); |
0b746ba8 | 1512 | while (node) |
fe71f65c | 1513 | { |
1c624631 | 1514 | wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData(); |
0b746ba8 | 1515 | |
7fce89b9 VZ |
1516 | // get next node before (maybe) calling the event handler as it could |
1517 | // call Disconnect() invalidating the current node | |
1518 | node = node->GetNext(); | |
1519 | ||
03f3617b | 1520 | if ( event.GetEventType() == entry->m_eventType ) |
0b746ba8 | 1521 | { |
f3ff831f | 1522 | wxEvtHandler *handler = entry->m_fn->GetEvtHandler(); |
03f3617b VZ |
1523 | if ( !handler ) |
1524 | handler = this; | |
1525 | if ( ProcessEventIfMatchesId(*entry, handler, event) ) | |
1c624631 | 1526 | return true; |
0b746ba8 | 1527 | } |
7b678698 | 1528 | } |
1c624631 VZ |
1529 | |
1530 | return false; | |
4115960d | 1531 | } |
fe71f65c | 1532 | |
b88c44e7 RD |
1533 | void wxEvtHandler::DoSetClientObject( wxClientData *data ) |
1534 | { | |
1535 | wxASSERT_MSG( m_clientDataType != wxClientData_Void, | |
1536 | wxT("can't have both object and void client data") ); | |
1537 | ||
1538 | if ( m_clientObject ) | |
1539 | delete m_clientObject; | |
1540 | ||
1541 | m_clientObject = data; | |
1542 | m_clientDataType = wxClientData_Object; | |
1543 | } | |
1544 | ||
1545 | wxClientData *wxEvtHandler::DoGetClientObject() const | |
1546 | { | |
1547 | // it's not an error to call GetClientObject() on a window which doesn't | |
1548 | // have client data at all - NULL will be returned | |
1549 | wxASSERT_MSG( m_clientDataType != wxClientData_Void, | |
1550 | wxT("this window doesn't have object client data") ); | |
1551 | ||
1552 | return m_clientObject; | |
1553 | } | |
1554 | ||
1555 | void wxEvtHandler::DoSetClientData( void *data ) | |
1556 | { | |
1557 | wxASSERT_MSG( m_clientDataType != wxClientData_Object, | |
1558 | wxT("can't have both object and void client data") ); | |
1559 | ||
1560 | m_clientData = data; | |
1561 | m_clientDataType = wxClientData_Void; | |
1562 | } | |
1563 | ||
1564 | void *wxEvtHandler::DoGetClientData() const | |
1565 | { | |
1566 | // it's not an error to call GetClientData() on a window which doesn't have | |
1567 | // client data at all - NULL will be returned | |
1568 | wxASSERT_MSG( m_clientDataType != wxClientData_Object, | |
1569 | wxT("this window doesn't have void client data") ); | |
1570 | ||
1571 | return m_clientData; | |
1572 | } | |
1573 | ||
cc6ceca7 VZ |
1574 | // A helper to find an wxEventConnectionRef object |
1575 | wxEventConnectionRef * | |
1576 | wxEvtHandler::FindRefInTrackerList(wxEvtHandler *eventSink) | |
2ef989c9 | 1577 | { |
cc6ceca7 | 1578 | for ( wxTrackerNode *node = eventSink->GetFirst(); node; node = node->m_nxt ) |
2ef989c9 | 1579 | { |
cc6ceca7 VZ |
1580 | // we only want wxEventConnectionRef nodes here |
1581 | wxEventConnectionRef *evtConnRef = node->ToEventConnection(); | |
1582 | if ( evtConnRef && evtConnRef->m_src == this ) | |
2ef989c9 | 1583 | { |
cc6ceca7 VZ |
1584 | wxASSERT( evtConnRef->m_sink==eventSink ); |
1585 | return evtConnRef; | |
2ef989c9 RR |
1586 | } |
1587 | } | |
cc6ceca7 | 1588 | |
2ef989c9 RR |
1589 | return NULL; |
1590 | } | |
1591 | ||
1592 | void wxEvtHandler::OnSinkDestroyed( wxEvtHandler *sink ) | |
1593 | { | |
1594 | wxASSERT(m_dynamicEvents); | |
cc6ceca7 | 1595 | |
2ef989c9 RR |
1596 | // remove all connections with this sink |
1597 | wxList::compatibility_iterator node = m_dynamicEvents->GetFirst(), node_nxt; | |
1598 | while (node) | |
1599 | { | |
1600 | wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData(); | |
1601 | node_nxt = node->GetNext(); | |
cc6ceca7 | 1602 | |
f3ff831f | 1603 | if ( entry->m_fn->GetEvtHandler() == sink ) |
2ef989c9 | 1604 | { |
3c778901 | 1605 | delete entry->m_callbackUserData; |
2ef989c9 RR |
1606 | m_dynamicEvents->Erase( node ); |
1607 | delete entry; | |
1608 | } | |
1609 | node = node_nxt; | |
1610 | } | |
1611 | } | |
1612 | ||
4caf847c VZ |
1613 | #endif // wxUSE_BASE |
1614 | ||
e90c1d2a VZ |
1615 | #if wxUSE_GUI |
1616 | ||
e702ff0f JS |
1617 | // Find a window with the focus, that is also a descendant of the given window. |
1618 | // This is used to determine the window to initially send commands to. | |
1619 | wxWindow* wxFindFocusDescendant(wxWindow* ancestor) | |
1620 | { | |
1621 | // Process events starting with the window with the focus, if any. | |
1622 | wxWindow* focusWin = wxWindow::FindFocus(); | |
1623 | wxWindow* win = focusWin; | |
1624 | ||
1625 | // Check if this is a descendant of this frame. | |
1626 | // If not, win will be set to NULL. | |
1627 | while (win) | |
1628 | { | |
1629 | if (win == ancestor) | |
1630 | break; | |
1631 | else | |
1632 | win = win->GetParent(); | |
1633 | } | |
3c778901 VZ |
1634 | if (win == NULL) |
1635 | focusWin = NULL; | |
e702ff0f JS |
1636 | |
1637 | return focusWin; | |
1638 | } | |
1639 | ||
c4fa5aa7 VZ |
1640 | // ---------------------------------------------------------------------------- |
1641 | // wxEventBlocker | |
1642 | // ---------------------------------------------------------------------------- | |
1643 | ||
1644 | wxEventBlocker::wxEventBlocker(wxWindow *win, wxEventType type) | |
1645 | { | |
1646 | wxCHECK_RET(win, wxT("Null window given to wxEventBlocker")); | |
1647 | ||
1648 | m_window = win; | |
1649 | ||
1650 | Block(type); | |
1651 | m_window->PushEventHandler(this); | |
1652 | } | |
1653 | ||
1654 | wxEventBlocker::~wxEventBlocker() | |
1655 | { | |
1656 | wxEvtHandler *popped = m_window->PopEventHandler(false); | |
aa767a45 | 1657 | wxCHECK_RET(popped == this, |
c4fa5aa7 VZ |
1658 | wxT("Don't push other event handlers into a window managed by wxEventBlocker!")); |
1659 | } | |
1660 | ||
1661 | bool wxEventBlocker::ProcessEvent(wxEvent& event) | |
1662 | { | |
1663 | // should this event be blocked? | |
1664 | for ( size_t i = 0; i < m_eventsToBlock.size(); i++ ) | |
1665 | { | |
1666 | wxEventType t = (wxEventType)m_eventsToBlock[i]; | |
1667 | if ( t == wxEVT_ANY || t == event.GetEventType() ) | |
1668 | return true; // yes, it should: mark this event as processed | |
1669 | } | |
1670 | ||
1671 | return false; | |
1672 | } | |
1673 | ||
e90c1d2a | 1674 | #endif // wxUSE_GUI |
3c778901 | 1675 |