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