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