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