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