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