]> git.saurik.com Git - wxWidgets.git/blob - src/common/event.cpp
added Id cvs tag
[wxWidgets.git] / src / common / event.cpp
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$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "event.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/defs.h"
33 #include "wx/app.h"
34 #include "wx/list.h"
35
36 #if wxUSE_GUI
37 #include "wx/control.h"
38 #include "wx/utils.h"
39 #include "wx/dc.h"
40 #endif // wxUSE_GUI
41 #endif
42
43 #include "wx/event.h"
44
45 #if wxUSE_GUI
46 #include "wx/validate.h"
47 #endif // wxUSE_GUI
48
49 // ----------------------------------------------------------------------------
50 // event constants
51 // ----------------------------------------------------------------------------
52
53 wxEventType wxEVT_NULL = 0;
54 wxEventType wxEVT_FIRST = 10000;
55
56 #if WXWIN_COMPATIBILITY_2
57 wxEventType wxEVT_USER_FIRST = wxEVT_FIRST + 2000;
58 #endif // WXWIN_COMPATIBILITY_2
59
60 // ----------------------------------------------------------------------------
61 // wxWin macros
62 // ----------------------------------------------------------------------------
63
64 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject)
65 IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject)
66 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent)
67
68 #if wxUSE_GUI
69 IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent)
70 IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent)
71 IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent)
72 IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent, wxEvent)
73 IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent, wxEvent)
74 IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent)
75 IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent)
76 IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent)
77 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent)
78 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent)
79 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent)
80 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent, wxEvent)
81 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent)
82 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent)
83 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent)
84 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent)
85 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent)
86 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent)
87 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent, wxEvent)
88 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent, wxEvent)
89 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent)
90 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent)
91 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxCommandEvent)
92 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent, wxEvent)
93 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent, wxEvent)
94 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent, wxEvent)
95 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent, wxEvent)
96 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent, wxCommandEvent)
97 #endif // wxUSE_GUI
98
99 const wxEventTable *wxEvtHandler::GetEventTable() const
100 { return &wxEvtHandler::sm_eventTable; }
101
102 const wxEventTable wxEvtHandler::sm_eventTable =
103 { (const wxEventTable *)NULL, &wxEvtHandler::sm_eventTableEntries[0] };
104
105 const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] =
106 { wxEventTableEntry(0, 0, 0, (wxObjectEventFunction)NULL, NULL) };
107
108 // ----------------------------------------------------------------------------
109 // global variables
110 // ----------------------------------------------------------------------------
111
112 // To put pending event handlers
113 wxList *wxPendingEvents = (wxList *)NULL;
114
115 #if wxUSE_THREADS
116 // protects wxPendingEvents list
117 wxCriticalSection *wxPendingEventsLocker = (wxCriticalSection *)NULL;
118 #endif
119
120 wxEventType wxEVT_COMMAND_BUTTON_CLICKED;
121 wxEventType wxEVT_COMMAND_CHECKBOX_CLICKED;
122 wxEventType wxEVT_COMMAND_CHOICE_SELECTED;
123 wxEventType wxEVT_COMMAND_LISTBOX_SELECTED;
124 wxEventType wxEVT_COMMAND_LISTBOX_DOUBLECLICKED;
125 wxEventType wxEVT_COMMAND_CHECKLISTBOX_TOGGLED;
126 wxEventType wxEVT_COMMAND_TEXT_UPDATED;
127 wxEventType wxEVT_COMMAND_TEXT_ENTER;
128 wxEventType wxEVT_COMMAND_MENU_SELECTED;
129 wxEventType wxEVT_COMMAND_TOOL_CLICKED;
130 wxEventType wxEVT_COMMAND_SLIDER_UPDATED;
131 wxEventType wxEVT_COMMAND_RADIOBOX_SELECTED;
132 wxEventType wxEVT_COMMAND_RADIOBUTTON_SELECTED;
133 wxEventType wxEVT_COMMAND_SCROLLBAR_UPDATED;
134 wxEventType wxEVT_COMMAND_VLBOX_SELECTED;
135 wxEventType wxEVT_COMMAND_COMBOBOX_SELECTED;
136 wxEventType wxEVT_COMMAND_TOOL_RCLICKED;
137 wxEventType wxEVT_COMMAND_TOOL_ENTER;
138 wxEventType wxEVT_COMMAND_SPINCTRL_UPDATED;
139
140 // Sockets and timers send events, too
141 wxEventType wxEVT_SOCKET;
142 wxEventType wxEVT_TIMER;
143
144 // Mouse event types
145 wxEventType wxEVT_LEFT_DOWN;
146 wxEventType wxEVT_LEFT_UP;
147 wxEventType wxEVT_MIDDLE_DOWN;
148 wxEventType wxEVT_MIDDLE_UP;
149 wxEventType wxEVT_RIGHT_DOWN;
150 wxEventType wxEVT_RIGHT_UP;
151 wxEventType wxEVT_MOTION;
152 wxEventType wxEVT_ENTER_WINDOW;
153 wxEventType wxEVT_LEAVE_WINDOW;
154 wxEventType wxEVT_LEFT_DCLICK;
155 wxEventType wxEVT_MIDDLE_DCLICK;
156 wxEventType wxEVT_RIGHT_DCLICK;
157 wxEventType wxEVT_SET_FOCUS;
158 wxEventType wxEVT_KILL_FOCUS;
159
160 // Non-client mouse events
161 wxEventType wxEVT_NC_LEFT_DOWN;
162 wxEventType wxEVT_NC_LEFT_UP;
163 wxEventType wxEVT_NC_MIDDLE_DOWN;
164 wxEventType wxEVT_NC_MIDDLE_UP;
165 wxEventType wxEVT_NC_RIGHT_DOWN;
166 wxEventType wxEVT_NC_RIGHT_UP;
167 wxEventType wxEVT_NC_MOTION;
168 wxEventType wxEVT_NC_ENTER_WINDOW;
169 wxEventType wxEVT_NC_LEAVE_WINDOW;
170 wxEventType wxEVT_NC_LEFT_DCLICK;
171 wxEventType wxEVT_NC_MIDDLE_DCLICK;
172 wxEventType wxEVT_NC_RIGHT_DCLICK;
173
174 // Character input event type
175 wxEventType wxEVT_CHAR;
176 wxEventType wxEVT_CHAR_HOOK;
177 wxEventType wxEVT_NAVIGATION_KEY;
178 wxEventType wxEVT_KEY_DOWN;
179 wxEventType wxEVT_KEY_UP;
180
181 // Set cursor event
182 wxEventType wxEVT_SET_CURSOR;
183
184 // wxScrollbar and wxSlider event identifiers
185 wxEventType wxEVT_SCROLL_TOP;
186 wxEventType wxEVT_SCROLL_BOTTOM;
187 wxEventType wxEVT_SCROLL_LINEUP;
188 wxEventType wxEVT_SCROLL_LINEDOWN;
189 wxEventType wxEVT_SCROLL_PAGEUP;
190 wxEventType wxEVT_SCROLL_PAGEDOWN;
191 wxEventType wxEVT_SCROLL_THUMBTRACK;
192 wxEventType wxEVT_SCROLL_THUMBRELEASE;
193
194 // Scroll events from wxWindow
195 wxEventType wxEVT_SCROLLWIN_TOP;
196 wxEventType wxEVT_SCROLLWIN_BOTTOM;
197 wxEventType wxEVT_SCROLLWIN_LINEUP;
198 wxEventType wxEVT_SCROLLWIN_LINEDOWN;
199 wxEventType wxEVT_SCROLLWIN_PAGEUP;
200 wxEventType wxEVT_SCROLLWIN_PAGEDOWN;
201 wxEventType wxEVT_SCROLLWIN_THUMBTRACK;
202 wxEventType wxEVT_SCROLLWIN_THUMBRELEASE;
203
204 // System events
205 wxEventType wxEVT_SIZE;
206 wxEventType wxEVT_MOVE;
207 wxEventType wxEVT_CLOSE_WINDOW;
208 wxEventType wxEVT_END_SESSION;
209 wxEventType wxEVT_QUERY_END_SESSION;
210 wxEventType wxEVT_ACTIVATE_APP;
211 wxEventType wxEVT_POWER;
212 wxEventType wxEVT_ACTIVATE;
213 wxEventType wxEVT_CREATE;
214 wxEventType wxEVT_DESTROY;
215 wxEventType wxEVT_SHOW;
216 wxEventType wxEVT_ICONIZE;
217 wxEventType wxEVT_MAXIMIZE;
218 wxEventType wxEVT_MOUSE_CAPTURE_CHANGED;
219 wxEventType wxEVT_PAINT;
220 wxEventType wxEVT_ERASE_BACKGROUND;
221 wxEventType wxEVT_NC_PAINT;
222 wxEventType wxEVT_PAINT_ICON;
223 wxEventType wxEVT_MENU_CHAR;
224 wxEventType wxEVT_MENU_INIT;
225 wxEventType wxEVT_MENU_HIGHLIGHT;
226 wxEventType wxEVT_POPUP_MENU_INIT;
227 wxEventType wxEVT_CONTEXT_MENU;
228 wxEventType wxEVT_SYS_COLOUR_CHANGED;
229 wxEventType wxEVT_SETTING_CHANGED;
230 wxEventType wxEVT_QUERY_NEW_PALETTE;
231 wxEventType wxEVT_PALETTE_CHANGED;
232 wxEventType wxEVT_JOY_BUTTON_DOWN;
233 wxEventType wxEVT_JOY_BUTTON_UP;
234 wxEventType wxEVT_JOY_MOVE;
235 wxEventType wxEVT_JOY_ZMOVE;
236 wxEventType wxEVT_DROP_FILES;
237 wxEventType wxEVT_DRAW_ITEM;
238 wxEventType wxEVT_MEASURE_ITEM;
239 wxEventType wxEVT_COMPARE_ITEM;
240 wxEventType wxEVT_INIT_DIALOG;
241 wxEventType wxEVT_IDLE;
242 wxEventType wxEVT_UPDATE_UI;
243
244 // System misc.
245 wxEventType wxEVT_END_PROCESS;
246
247 // Dial up events
248 wxEventType wxEVT_DIALUP_CONNECTED;
249 wxEventType wxEVT_DIALUP_DISCONNECTED;
250
251 // Generic command events
252 // Note: a click is a higher-level event than button down/up
253 wxEventType wxEVT_COMMAND_LEFT_CLICK;
254 wxEventType wxEVT_COMMAND_LEFT_DCLICK;
255 wxEventType wxEVT_COMMAND_RIGHT_CLICK;
256 wxEventType wxEVT_COMMAND_RIGHT_DCLICK;
257 wxEventType wxEVT_COMMAND_SET_FOCUS;
258 wxEventType wxEVT_COMMAND_KILL_FOCUS;
259 wxEventType wxEVT_COMMAND_ENTER;
260
261 // Tree control event types
262 wxEventType wxEVT_COMMAND_TREE_BEGIN_DRAG;
263 wxEventType wxEVT_COMMAND_TREE_BEGIN_RDRAG;
264 wxEventType wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT;
265 wxEventType wxEVT_COMMAND_TREE_END_LABEL_EDIT;
266 wxEventType wxEVT_COMMAND_TREE_DELETE_ITEM;
267 wxEventType wxEVT_COMMAND_TREE_GET_INFO;
268 wxEventType wxEVT_COMMAND_TREE_SET_INFO;
269 wxEventType wxEVT_COMMAND_TREE_ITEM_EXPANDED;
270 wxEventType wxEVT_COMMAND_TREE_ITEM_EXPANDING;
271 wxEventType wxEVT_COMMAND_TREE_ITEM_COLLAPSED;
272 wxEventType wxEVT_COMMAND_TREE_ITEM_COLLAPSING;
273 wxEventType wxEVT_COMMAND_TREE_SEL_CHANGED;
274 wxEventType wxEVT_COMMAND_TREE_SEL_CHANGING;
275 wxEventType wxEVT_COMMAND_TREE_KEY_DOWN;
276 wxEventType wxEVT_COMMAND_TREE_ITEM_ACTIVATED;
277 wxEventType wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK;
278 wxEventType wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK;
279 wxEventType wxEVT_COMMAND_TREE_END_DRAG;
280
281 // List control event types
282 wxEventType wxEVT_COMMAND_LIST_BEGIN_DRAG;
283 wxEventType wxEVT_COMMAND_LIST_BEGIN_RDRAG;
284 wxEventType wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT;
285 wxEventType wxEVT_COMMAND_LIST_END_LABEL_EDIT;
286 wxEventType wxEVT_COMMAND_LIST_DELETE_ITEM;
287 wxEventType wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS;
288 wxEventType wxEVT_COMMAND_LIST_GET_INFO;
289 wxEventType wxEVT_COMMAND_LIST_SET_INFO;
290 wxEventType wxEVT_COMMAND_LIST_ITEM_SELECTED;
291 wxEventType wxEVT_COMMAND_LIST_ITEM_DESELECTED;
292 wxEventType wxEVT_COMMAND_LIST_KEY_DOWN;
293 wxEventType wxEVT_COMMAND_LIST_INSERT_ITEM;
294 wxEventType wxEVT_COMMAND_LIST_COL_CLICK;
295 wxEventType wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK;
296 wxEventType wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK;
297 wxEventType wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
298
299 // Tab and notebook control event types
300 wxEventType wxEVT_COMMAND_TAB_SEL_CHANGED;
301 wxEventType wxEVT_COMMAND_TAB_SEL_CHANGING;
302 wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED;
303 wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING;
304
305 // Splitter events
306 wxEventType wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED;
307 wxEventType wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING;
308 wxEventType wxEVT_COMMAND_SPLITTER_DOUBLECLICKED;
309 wxEventType wxEVT_COMMAND_SPLITTER_UNSPLIT;
310
311 // Wizard events
312 wxEventType wxEVT_WIZARD_PAGE_CHANGED;
313 wxEventType wxEVT_WIZARD_PAGE_CHANGING;
314 wxEventType wxEVT_WIZARD_CANCEL;
315
316 // Calendar events
317 wxEventType wxEVT_CALENDAR_SEL_CHANGED;
318 wxEventType wxEVT_CALENDAR_DAY_CHANGED;
319 wxEventType wxEVT_CALENDAR_MONTH_CHANGED;
320 wxEventType wxEVT_CALENDAR_YEAR_CHANGED;
321 wxEventType wxEVT_CALENDAR_DOUBLECLICKED;
322 wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED;
323
324 // Help events
325 wxEventType wxEVT_HELP;
326 wxEventType wxEVT_DETAILED_HELP;
327
328 // ============================================================================
329 // implementation
330 // ============================================================================
331
332 // ----------------------------------------------------------------------------
333 // event initialization
334 // ----------------------------------------------------------------------------
335
336 int wxNewEventType()
337 {
338 // MT-FIXME
339 static int s_lastUsedEventType = wxEVT_FIRST;
340
341 return s_lastUsedEventType++;
342 }
343
344 static void InitEvents()
345 {
346 #ifdef __WXDEBUG__
347 // this function is supposed to be called only once, as normally this
348 // should be always true we only do this check in debug mode
349 static bool s_inInitEvents = FALSE;
350 wxCHECK_RET( !s_inInitEvents, _T("InitEvents() reentrancy!") );
351
352 // note that we don't reset it to FALSE any more as we shouldn't be called
353 // again
354 s_inInitEvents = TRUE;
355 #endif // __WXDEBUG__
356
357 wxEVT_COMMAND_BUTTON_CLICKED = wxNewEventType();
358 wxEVT_COMMAND_CHECKBOX_CLICKED = wxNewEventType();
359 wxEVT_COMMAND_CHOICE_SELECTED = wxNewEventType();
360 wxEVT_COMMAND_LISTBOX_SELECTED = wxNewEventType();
361 wxEVT_COMMAND_LISTBOX_DOUBLECLICKED = wxNewEventType();
362 wxEVT_COMMAND_CHECKLISTBOX_TOGGLED = wxNewEventType();
363 wxEVT_COMMAND_TEXT_UPDATED = wxNewEventType();
364 wxEVT_COMMAND_TEXT_ENTER = wxNewEventType();
365 wxEVT_COMMAND_MENU_SELECTED = wxNewEventType();
366 wxEVT_COMMAND_TOOL_CLICKED = wxNewEventType();
367 wxEVT_COMMAND_SLIDER_UPDATED = wxNewEventType();
368 wxEVT_COMMAND_RADIOBOX_SELECTED = wxNewEventType();
369 wxEVT_COMMAND_RADIOBUTTON_SELECTED = wxNewEventType();
370 wxEVT_COMMAND_SCROLLBAR_UPDATED = wxNewEventType();
371 wxEVT_COMMAND_VLBOX_SELECTED = wxNewEventType();
372 wxEVT_COMMAND_COMBOBOX_SELECTED = wxNewEventType();
373 wxEVT_COMMAND_TOOL_RCLICKED = wxNewEventType();
374 wxEVT_COMMAND_TOOL_ENTER = wxNewEventType();
375 wxEVT_COMMAND_SPINCTRL_UPDATED = wxNewEventType();
376
377 // Sockets and timers send events, too
378 wxEVT_SOCKET = wxNewEventType();
379 wxEVT_TIMER = wxNewEventType();
380
381 // Mouse event types
382 wxEVT_LEFT_DOWN = wxNewEventType();
383 wxEVT_LEFT_UP = wxNewEventType();
384 wxEVT_MIDDLE_DOWN = wxNewEventType();
385 wxEVT_MIDDLE_UP = wxNewEventType();
386 wxEVT_RIGHT_DOWN = wxNewEventType();
387 wxEVT_RIGHT_UP = wxNewEventType();
388 wxEVT_MOTION = wxNewEventType();
389 wxEVT_ENTER_WINDOW = wxNewEventType();
390 wxEVT_LEAVE_WINDOW = wxNewEventType();
391 wxEVT_LEFT_DCLICK = wxNewEventType();
392 wxEVT_MIDDLE_DCLICK = wxNewEventType();
393 wxEVT_RIGHT_DCLICK = wxNewEventType();
394 wxEVT_SET_FOCUS = wxNewEventType();
395 wxEVT_KILL_FOCUS = wxNewEventType();
396
397 // Non-client mouse events
398 wxEVT_NC_LEFT_DOWN = wxNewEventType();
399 wxEVT_NC_LEFT_UP = wxNewEventType();
400 wxEVT_NC_MIDDLE_DOWN = wxNewEventType();
401 wxEVT_NC_MIDDLE_UP = wxNewEventType();
402 wxEVT_NC_RIGHT_DOWN = wxNewEventType();
403 wxEVT_NC_RIGHT_UP = wxNewEventType();
404 wxEVT_NC_MOTION = wxNewEventType();
405 wxEVT_NC_ENTER_WINDOW = wxNewEventType();
406 wxEVT_NC_LEAVE_WINDOW = wxNewEventType();
407 wxEVT_NC_LEFT_DCLICK = wxNewEventType();
408 wxEVT_NC_MIDDLE_DCLICK = wxNewEventType();
409 wxEVT_NC_RIGHT_DCLICK = wxNewEventType();
410
411 // Character input event type
412 wxEVT_CHAR = wxNewEventType();
413 wxEVT_CHAR_HOOK = wxNewEventType();
414 wxEVT_NAVIGATION_KEY = wxNewEventType();
415 wxEVT_KEY_DOWN = wxNewEventType();
416 wxEVT_KEY_UP = wxNewEventType();
417
418 // Set cursor event
419 wxEVT_SET_CURSOR = wxNewEventType();
420
421 // wxScrollbar and wxSlider event identifiers
422 wxEVT_SCROLL_TOP = wxNewEventType();
423 wxEVT_SCROLL_BOTTOM = wxNewEventType();
424 wxEVT_SCROLL_LINEUP = wxNewEventType();
425 wxEVT_SCROLL_LINEDOWN = wxNewEventType();
426 wxEVT_SCROLL_PAGEUP = wxNewEventType();
427 wxEVT_SCROLL_PAGEDOWN = wxNewEventType();
428 wxEVT_SCROLL_THUMBTRACK = wxNewEventType();
429 wxEVT_SCROLL_THUMBRELEASE = wxNewEventType();
430
431 // Scroll events from wxWindow
432 wxEVT_SCROLLWIN_TOP = wxNewEventType();
433 wxEVT_SCROLLWIN_BOTTOM = wxNewEventType();
434 wxEVT_SCROLLWIN_LINEUP = wxNewEventType();
435 wxEVT_SCROLLWIN_LINEDOWN = wxNewEventType();
436 wxEVT_SCROLLWIN_PAGEUP = wxNewEventType();
437 wxEVT_SCROLLWIN_PAGEDOWN = wxNewEventType();
438 wxEVT_SCROLLWIN_THUMBTRACK = wxNewEventType();
439 wxEVT_SCROLLWIN_THUMBRELEASE = wxNewEventType();
440
441 // System events
442 wxEVT_SIZE = wxNewEventType();
443 wxEVT_MOVE = wxNewEventType();
444 wxEVT_CLOSE_WINDOW = wxNewEventType();
445 wxEVT_END_SESSION = wxNewEventType();
446 wxEVT_QUERY_END_SESSION = wxNewEventType();
447 wxEVT_ACTIVATE_APP = wxNewEventType();
448 wxEVT_POWER = wxNewEventType();
449 wxEVT_ACTIVATE = wxNewEventType();
450 wxEVT_CREATE = wxNewEventType();
451 wxEVT_DESTROY = wxNewEventType();
452 wxEVT_SHOW = wxNewEventType();
453 wxEVT_ICONIZE = wxNewEventType();
454 wxEVT_MAXIMIZE = wxNewEventType();
455 wxEVT_MOUSE_CAPTURE_CHANGED = wxNewEventType();
456 wxEVT_PAINT = wxNewEventType();
457 wxEVT_ERASE_BACKGROUND = wxNewEventType();
458 wxEVT_NC_PAINT = wxNewEventType();
459 wxEVT_PAINT_ICON = wxNewEventType();
460 wxEVT_MENU_CHAR = wxNewEventType();
461 wxEVT_MENU_INIT = wxNewEventType();
462 wxEVT_MENU_HIGHLIGHT = wxNewEventType();
463 wxEVT_POPUP_MENU_INIT = wxNewEventType();
464 wxEVT_CONTEXT_MENU = wxNewEventType();
465 wxEVT_SYS_COLOUR_CHANGED = wxNewEventType();
466 wxEVT_SETTING_CHANGED = wxNewEventType();
467 wxEVT_QUERY_NEW_PALETTE = wxNewEventType();
468 wxEVT_PALETTE_CHANGED = wxNewEventType();
469 wxEVT_JOY_BUTTON_DOWN = wxNewEventType();
470 wxEVT_JOY_BUTTON_UP = wxNewEventType();
471 wxEVT_JOY_MOVE = wxNewEventType();
472 wxEVT_JOY_ZMOVE = wxNewEventType();
473 wxEVT_DROP_FILES = wxNewEventType();
474 wxEVT_DRAW_ITEM = wxNewEventType();
475 wxEVT_MEASURE_ITEM = wxNewEventType();
476 wxEVT_COMPARE_ITEM = wxNewEventType();
477 wxEVT_INIT_DIALOG = wxNewEventType();
478 wxEVT_IDLE = wxNewEventType();
479 wxEVT_UPDATE_UI = wxNewEventType();
480
481 // System misc.
482 wxEVT_END_PROCESS = wxNewEventType();
483
484 // Dial up events
485 wxEVT_DIALUP_CONNECTED = wxNewEventType();
486 wxEVT_DIALUP_DISCONNECTED = wxNewEventType();
487
488 // Generic command events
489 // Note: a click is a higher-level event than button down/up
490 wxEVT_COMMAND_LEFT_CLICK = wxNewEventType();
491 wxEVT_COMMAND_LEFT_DCLICK = wxNewEventType();
492 wxEVT_COMMAND_RIGHT_CLICK = wxNewEventType();
493 wxEVT_COMMAND_RIGHT_DCLICK = wxNewEventType();
494 wxEVT_COMMAND_SET_FOCUS = wxNewEventType();
495 wxEVT_COMMAND_KILL_FOCUS = wxNewEventType();
496 wxEVT_COMMAND_ENTER = wxNewEventType();
497
498 // Tree control event types
499 wxEVT_COMMAND_TREE_BEGIN_DRAG = wxNewEventType();
500 wxEVT_COMMAND_TREE_BEGIN_RDRAG = wxNewEventType();
501 wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT = wxNewEventType();
502 wxEVT_COMMAND_TREE_END_LABEL_EDIT = wxNewEventType();
503 wxEVT_COMMAND_TREE_DELETE_ITEM = wxNewEventType();
504 wxEVT_COMMAND_TREE_GET_INFO = wxNewEventType();
505 wxEVT_COMMAND_TREE_SET_INFO = wxNewEventType();
506 wxEVT_COMMAND_TREE_ITEM_EXPANDED = wxNewEventType();
507 wxEVT_COMMAND_TREE_ITEM_EXPANDING = wxNewEventType();
508 wxEVT_COMMAND_TREE_ITEM_COLLAPSED = wxNewEventType();
509 wxEVT_COMMAND_TREE_ITEM_COLLAPSING = wxNewEventType();
510 wxEVT_COMMAND_TREE_SEL_CHANGED = wxNewEventType();
511 wxEVT_COMMAND_TREE_SEL_CHANGING = wxNewEventType();
512 wxEVT_COMMAND_TREE_KEY_DOWN = wxNewEventType();
513 wxEVT_COMMAND_TREE_ITEM_ACTIVATED = wxNewEventType();
514 wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK = wxNewEventType();
515 wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK = wxNewEventType();
516 wxEVT_COMMAND_TREE_END_DRAG = wxNewEventType();
517
518 // List control event types
519 wxEVT_COMMAND_LIST_BEGIN_DRAG = wxNewEventType();
520 wxEVT_COMMAND_LIST_BEGIN_RDRAG = wxNewEventType();
521 wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT = wxNewEventType();
522 wxEVT_COMMAND_LIST_END_LABEL_EDIT = wxNewEventType();
523 wxEVT_COMMAND_LIST_DELETE_ITEM = wxNewEventType();
524 wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS = wxNewEventType();
525 wxEVT_COMMAND_LIST_GET_INFO = wxNewEventType();
526 wxEVT_COMMAND_LIST_SET_INFO = wxNewEventType();
527 wxEVT_COMMAND_LIST_ITEM_SELECTED = wxNewEventType();
528 wxEVT_COMMAND_LIST_ITEM_DESELECTED = wxNewEventType();
529 wxEVT_COMMAND_LIST_KEY_DOWN = wxNewEventType();
530 wxEVT_COMMAND_LIST_INSERT_ITEM = wxNewEventType();
531 wxEVT_COMMAND_LIST_COL_CLICK = wxNewEventType();
532 wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK = wxNewEventType();
533 wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK = wxNewEventType();
534 wxEVT_COMMAND_LIST_ITEM_ACTIVATED = wxNewEventType();
535
536 // Tab and notebook control event types
537 wxEVT_COMMAND_TAB_SEL_CHANGED = wxNewEventType();
538 wxEVT_COMMAND_TAB_SEL_CHANGING = wxNewEventType();
539 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED = wxNewEventType();
540 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING = wxNewEventType();
541
542 // Splitter events
543 wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED = wxNewEventType();
544 wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING = wxNewEventType();
545 wxEVT_COMMAND_SPLITTER_DOUBLECLICKED = wxNewEventType();
546 wxEVT_COMMAND_SPLITTER_UNSPLIT = wxNewEventType();
547
548 // Wizard events
549 wxEVT_WIZARD_PAGE_CHANGED = wxNewEventType();
550 wxEVT_WIZARD_PAGE_CHANGING = wxNewEventType();
551 wxEVT_WIZARD_CANCEL = wxNewEventType();
552
553 // Calendar events
554 wxEVT_CALENDAR_SEL_CHANGED = wxNewEventType();
555 wxEVT_CALENDAR_DAY_CHANGED = wxNewEventType();
556 wxEVT_CALENDAR_MONTH_CHANGED = wxNewEventType();
557 wxEVT_CALENDAR_YEAR_CHANGED = wxNewEventType();
558 wxEVT_CALENDAR_DOUBLECLICKED = wxNewEventType();
559 wxEVT_CALENDAR_WEEKDAY_CLICKED = wxNewEventType();
560
561 // Help events
562 wxEVT_HELP = wxNewEventType();
563 wxEVT_DETAILED_HELP = wxNewEventType();
564 }
565
566 // ----------------------------------------------------------------------------
567 // wxEventTableEntry
568 // ----------------------------------------------------------------------------
569
570 wxEventTableEntry::wxEventTableEntry(int evType, int id, int idLast,
571 wxObjectEventFunction fn, wxObject *data)
572 {
573 static bool s_initEventsDone = FALSE;
574 if ( !s_initEventsDone )
575 {
576 InitEvents();
577
578 s_initEventsDone = TRUE;
579 }
580
581 m_eventType = evType;
582 m_id = id;
583 m_lastId = idLast;
584 m_fn = fn;
585 m_callbackUserData = data;
586 }
587
588 // ----------------------------------------------------------------------------
589 // wxEvent
590 // ----------------------------------------------------------------------------
591
592 /*
593 * General wxWindows events, covering
594 * all interesting things that might happen (button clicking, resizing,
595 * setting text in widgets, etc.).
596 *
597 * For each completely new event type, derive a new event class.
598 *
599 */
600
601 wxEvent::wxEvent(int theId)
602 {
603 m_eventType = wxEVT_NULL;
604 m_eventObject = (wxObject *) NULL;
605 m_timeStamp = 0;
606 m_id = theId;
607 m_skipped = FALSE;
608 m_callbackUserData = (wxObject *) NULL;
609 m_isCommandEvent = FALSE;
610 }
611
612 void wxEvent::CopyObject(wxObject& object_dest) const
613 {
614 wxEvent *obj = (wxEvent *)&object_dest;
615 wxObject::CopyObject(object_dest);
616
617 obj->m_eventType = m_eventType;
618 obj->m_eventObject = m_eventObject;
619 obj->m_timeStamp = m_timeStamp;
620 obj->m_id = m_id;
621 obj->m_skipped = m_skipped;
622 obj->m_callbackUserData = m_callbackUserData;
623 obj->m_isCommandEvent = m_isCommandEvent;
624 }
625
626 #if wxUSE_GUI
627
628 /*
629 * Command events
630 *
631 */
632
633 wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId)
634 {
635 m_eventType = commandType;
636 m_clientData = (char *) NULL;
637 m_clientObject = (wxClientData *) NULL;
638 m_extraLong = 0;
639 m_commandInt = 0;
640 m_id = theId;
641 m_commandString = wxEmptyString;
642 m_isCommandEvent = TRUE;
643 }
644
645 void wxCommandEvent::CopyObject(wxObject& obj_d) const
646 {
647 wxCommandEvent *obj = (wxCommandEvent *)&obj_d;
648
649 wxEvent::CopyObject(obj_d);
650
651 obj->m_clientData = m_clientData;
652 obj->m_clientObject = m_clientObject;
653 obj->m_extraLong = m_extraLong;
654 obj->m_commandInt = m_commandInt;
655 obj->m_commandString = m_commandString;
656 }
657
658 /*
659 * Notify events
660 */
661
662 void wxNotifyEvent::CopyObject(wxObject& obj_d) const
663 {
664 wxNotifyEvent *obj = (wxNotifyEvent *)&obj_d;
665
666 wxEvent::CopyObject(obj_d);
667
668 if (!m_bAllow) obj->Veto();
669 }
670
671 /*
672 * Scroll events
673 */
674
675 wxScrollEvent::wxScrollEvent(wxEventType commandType,
676 int id,
677 int pos,
678 int orient)
679 : wxCommandEvent(commandType, id)
680 {
681 m_extraLong = orient;
682 m_commandInt = pos;
683 }
684
685 /*
686 * ScrollWin events
687 */
688
689 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType,
690 int pos,
691 int orient)
692 {
693 m_eventType = commandType;
694 m_extraLong = orient;
695 m_commandInt = pos;
696 }
697
698 void wxScrollWinEvent::CopyObject(wxObject& obj_d) const
699 {
700 wxScrollWinEvent *obj = (wxScrollWinEvent*)&obj_d;
701
702 wxEvent::CopyObject(obj_d);
703
704 obj->m_extraLong = m_extraLong;
705 obj->m_commandInt = m_commandInt;
706 }
707
708 /*
709 * Mouse events
710 *
711 */
712
713 wxMouseEvent::wxMouseEvent(wxEventType commandType)
714 {
715 m_eventType = commandType;
716 m_metaDown = FALSE;
717 m_altDown = FALSE;
718 m_controlDown = FALSE;
719 m_shiftDown = FALSE;
720 m_leftDown = FALSE;
721 m_rightDown = FALSE;
722 m_middleDown = FALSE;
723 m_x = 0;
724 m_y = 0;
725 }
726
727 void wxMouseEvent::CopyObject(wxObject& obj_d) const
728 {
729 wxMouseEvent *obj = (wxMouseEvent *)&obj_d;
730
731 wxEvent::CopyObject(obj_d);
732
733 obj->m_metaDown = m_metaDown;
734 obj->m_altDown = m_altDown;
735 obj->m_controlDown = m_controlDown;
736 obj->m_shiftDown = m_shiftDown;
737 obj->m_leftDown = m_leftDown;
738 obj->m_rightDown = m_rightDown;
739 obj->m_middleDown = m_middleDown;
740 obj->m_x = m_x;
741 obj->m_y = m_y;
742 }
743
744 // True if was a button dclick event (1 = left, 2 = middle, 3 = right)
745 // or any button dclick event (but = -1)
746 bool wxMouseEvent::ButtonDClick(int but) const
747 {
748 switch (but)
749 {
750 case -1:
751 return (LeftDClick() || MiddleDClick() || RightDClick());
752 case 1:
753 return LeftDClick();
754 case 2:
755 return MiddleDClick();
756 case 3:
757 return RightDClick();
758 default:
759 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
760 }
761
762 return FALSE;
763 }
764
765 // True if was a button down event (1 = left, 2 = middle, 3 = right)
766 // or any button down event (but = -1)
767 bool wxMouseEvent::ButtonDown(int but) const
768 {
769 switch (but)
770 {
771 case -1:
772 return (LeftDown() || MiddleDown() || RightDown());
773 case 1:
774 return LeftDown();
775 case 2:
776 return MiddleDown();
777 case 3:
778 return RightDown();
779 default:
780 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
781 }
782
783 return FALSE;
784 }
785
786 // True if was a button up event (1 = left, 2 = middle, 3 = right)
787 // or any button up event (but = -1)
788 bool wxMouseEvent::ButtonUp(int but) const
789 {
790 switch (but) {
791 case -1:
792 return (LeftUp() || MiddleUp() || RightUp());
793 case 1:
794 return LeftUp();
795 case 2:
796 return MiddleUp();
797 case 3:
798 return RightUp();
799 default:
800 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
801 }
802
803 return FALSE;
804 }
805
806 // True if the given button is currently changing state
807 bool wxMouseEvent::Button(int but) const
808 {
809 switch (but) {
810 case -1:
811 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
812 case 1:
813 return (LeftDown() || LeftUp() || LeftDClick());
814 case 2:
815 return (MiddleDown() || MiddleUp() || MiddleDClick());
816 case 3:
817 return (RightDown() || RightUp() || RightDClick());
818 default:
819 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
820 }
821
822 return FALSE;
823 }
824
825 bool wxMouseEvent::ButtonIsDown(int but) const
826 {
827 switch (but) {
828 case -1:
829 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
830 case 1:
831 return LeftIsDown();
832 case 2:
833 return MiddleIsDown();
834 case 3:
835 return RightIsDown();
836 default:
837 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
838 }
839
840 return FALSE;
841 }
842
843 // Find the logical position of the event given the DC
844 wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const
845 {
846 wxPoint pt(dc.DeviceToLogicalX(m_x), dc.DeviceToLogicalY(m_y));
847 return pt;
848 }
849
850
851 /*
852 * Keyboard events
853 *
854 */
855
856 wxKeyEvent::wxKeyEvent(wxEventType type)
857 {
858 m_eventType = type;
859 m_shiftDown = FALSE;
860 m_controlDown = FALSE;
861 m_metaDown = FALSE;
862 m_altDown = FALSE;
863 m_keyCode = 0;
864 m_scanCode = 0;
865 }
866
867 void wxKeyEvent::CopyObject(wxObject& obj_d) const
868 {
869 wxKeyEvent *obj = (wxKeyEvent *)&obj_d;
870 wxEvent::CopyObject(obj_d);
871
872 obj->m_x = m_x;
873 obj->m_y = m_y;
874 obj->m_keyCode = m_keyCode;
875
876 obj->m_shiftDown = m_shiftDown;
877 obj->m_controlDown = m_controlDown;
878 obj->m_metaDown = m_metaDown;
879 obj->m_altDown = m_altDown;
880 obj->m_keyCode = m_keyCode;
881 }
882
883
884 /*
885 * Misc events
886 */
887
888 void wxSizeEvent::CopyObject(wxObject& obj_d) const
889 {
890 wxSizeEvent *obj = (wxSizeEvent *)&obj_d;
891 wxEvent::CopyObject(obj_d);
892
893 obj->m_size = m_size;
894 }
895
896 void wxMoveEvent::CopyObject(wxObject& obj_d) const
897 {
898 wxMoveEvent *obj = (wxMoveEvent *)&obj_d;
899 wxEvent::CopyObject(obj_d);
900
901 obj->m_pos = m_pos;
902 }
903
904 void wxEraseEvent::CopyObject(wxObject& obj_d) const
905 {
906 wxEraseEvent *obj = (wxEraseEvent *)&obj_d;
907 wxEvent::CopyObject(obj_d);
908
909 obj->m_dc = m_dc;
910 }
911
912 void wxActivateEvent::CopyObject(wxObject& obj_d) const
913 {
914 wxActivateEvent *obj = (wxActivateEvent *)&obj_d;
915 wxEvent::CopyObject(obj_d);
916
917 obj->m_active = m_active;
918 }
919
920 void wxMenuEvent::CopyObject(wxObject& obj_d) const
921 {
922 wxMenuEvent *obj = (wxMenuEvent *)&obj_d;
923 wxEvent::CopyObject(obj_d);
924
925 obj->m_menuId = m_menuId;
926 }
927
928 void wxCloseEvent::CopyObject(wxObject& obj_d) const
929 {
930 wxCloseEvent *obj = (wxCloseEvent *)&obj_d;
931 wxEvent::CopyObject(obj_d);
932
933 obj->m_loggingOff = m_loggingOff;
934 obj->m_veto = m_veto;
935 #if WXWIN_COMPATIBILITY
936 obj->m_force = m_force;
937 #endif
938 obj->m_canVeto = m_canVeto;
939 }
940
941 void wxShowEvent::CopyObject(wxObject& obj_d) const
942 {
943 wxShowEvent *obj = (wxShowEvent *)&obj_d;
944 wxEvent::CopyObject(obj_d);
945
946 obj->m_show = m_show;
947 }
948
949 void wxJoystickEvent::CopyObject(wxObject& obj_d) const
950 {
951 wxJoystickEvent *obj = (wxJoystickEvent *)&obj_d;
952 wxEvent::CopyObject(obj_d);
953
954 obj->m_pos = m_pos;
955 obj->m_zPosition = m_zPosition;
956 obj->m_buttonChange = m_buttonChange;
957 obj->m_buttonState = m_buttonState;
958 obj->m_joyStick = m_joyStick;
959 }
960
961 void wxDropFilesEvent::CopyObject(wxObject& obj_d) const
962 {
963 wxDropFilesEvent *obj = (wxDropFilesEvent *)&obj_d;
964 wxEvent::CopyObject(obj_d);
965
966 obj->m_noFiles = m_noFiles;
967 obj->m_pos = m_pos;
968 // TODO: Problem with obj->m_files. It should be deallocated by the
969 // destructor of the event.
970 }
971
972 void wxUpdateUIEvent::CopyObject(wxObject &obj_d) const
973 {
974 wxUpdateUIEvent *obj = (wxUpdateUIEvent *)&obj_d;
975 wxEvent::CopyObject(obj_d);
976
977 obj->m_checked = m_checked;
978 obj->m_enabled = m_enabled;
979 obj->m_text = m_text;
980 obj->m_setText = m_setText;
981 obj->m_setChecked = m_setChecked;
982 obj->m_setEnabled = m_setEnabled;
983 }
984
985 void wxPaletteChangedEvent::CopyObject(wxObject &obj_d) const
986 {
987 wxPaletteChangedEvent *obj = (wxPaletteChangedEvent *)&obj_d;
988 wxEvent::CopyObject(obj_d);
989
990 obj->m_changedWindow = m_changedWindow;
991 }
992
993 void wxQueryNewPaletteEvent::CopyObject(wxObject& obj_d) const
994 {
995 wxQueryNewPaletteEvent *obj = (wxQueryNewPaletteEvent *)&obj_d;
996 wxEvent::CopyObject(obj_d);
997
998 obj->m_paletteRealized = m_paletteRealized;
999 }
1000
1001 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow *win)
1002 {
1003 SetEventType(wxEVT_CREATE);
1004 SetEventObject(win);
1005 }
1006
1007 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow *win)
1008 {
1009 SetEventType(wxEVT_DESTROY);
1010 SetEventObject(win);
1011 }
1012
1013 #endif // wxUSE_GUI
1014
1015 void wxIdleEvent::CopyObject(wxObject& obj_d) const
1016 {
1017 wxIdleEvent *obj = (wxIdleEvent *)&obj_d;
1018 wxEvent::CopyObject(obj_d);
1019
1020 obj->m_requestMore = m_requestMore;
1021 }
1022
1023 /*
1024 * Event handler
1025 */
1026
1027 wxEvtHandler::wxEvtHandler()
1028 {
1029 m_nextHandler = (wxEvtHandler *) NULL;
1030 m_previousHandler = (wxEvtHandler *) NULL;
1031 m_enabled = TRUE;
1032 m_dynamicEvents = (wxList *) NULL;
1033 m_isWindow = FALSE;
1034 m_pendingEvents = (wxList *) NULL;
1035 #if wxUSE_THREADS
1036 # if !defined(__VISAGECPP__)
1037 m_eventsLocker = new wxCriticalSection;
1038 # endif
1039 #endif
1040 }
1041
1042 wxEvtHandler::~wxEvtHandler()
1043 {
1044 // Takes itself out of the list of handlers
1045 if (m_previousHandler)
1046 m_previousHandler->m_nextHandler = m_nextHandler;
1047
1048 if (m_nextHandler)
1049 m_nextHandler->m_previousHandler = m_previousHandler;
1050
1051 if (m_dynamicEvents)
1052 {
1053 wxNode *node = m_dynamicEvents->First();
1054 while (node)
1055 {
1056 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->Data();
1057 if (entry->m_callbackUserData) delete entry->m_callbackUserData;
1058 delete entry;
1059 node = node->Next();
1060 }
1061 delete m_dynamicEvents;
1062 };
1063
1064 delete m_pendingEvents;
1065
1066 #if wxUSE_THREADS
1067 # if !defined(__VISAGECPP__)
1068 delete m_eventsLocker;
1069 # endif
1070 #endif
1071 }
1072
1073 #if wxUSE_THREADS
1074
1075 bool wxEvtHandler::ProcessThreadEvent(wxEvent& event)
1076 {
1077 // check that we are really in a child thread
1078 wxASSERT_MSG( !wxThread::IsMain(),
1079 wxT("use ProcessEvent() in main thread") );
1080
1081 AddPendingEvent(event);
1082
1083 return TRUE;
1084 }
1085
1086 #endif // wxUSE_THREADS
1087
1088 void wxEvtHandler::AddPendingEvent(wxEvent& event)
1089 {
1090 // 1) Add event to list of pending events of this event handler
1091
1092 #if defined(__VISAGECPP__)
1093 wxENTER_CRIT_SECT( m_eventsLocker);
1094 #else
1095 wxENTER_CRIT_SECT( *m_eventsLocker);
1096 #endif
1097
1098 if ( !m_pendingEvents )
1099 m_pendingEvents = new wxList;
1100
1101 wxEvent *event2 = (wxEvent *)event.Clone();
1102
1103 m_pendingEvents->Append(event2);
1104
1105 #if defined(__VISAGECPP__)
1106 wxLEAVE_CRIT_SECT( m_eventsLocker);
1107 #else
1108 wxLEAVE_CRIT_SECT( *m_eventsLocker);
1109 #endif
1110
1111 // 2) Add this event handler to list of event handlers that
1112 // have pending events.
1113
1114 wxENTER_CRIT_SECT(*wxPendingEventsLocker);
1115
1116 if ( !wxPendingEvents )
1117 wxPendingEvents = new wxList;
1118 wxPendingEvents->Append(this);
1119
1120 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker);
1121
1122 // 3) Inform the system that new pending events are somwehere,
1123 // and that these should be processed in idle time.
1124 wxWakeUpIdle();
1125 }
1126
1127 void wxEvtHandler::ProcessPendingEvents()
1128 {
1129 #if defined(__VISAGECPP__)
1130 wxENTER_CRIT_SECT( m_eventsLocker);
1131 #else
1132 wxENTER_CRIT_SECT( *m_eventsLocker);
1133 #endif
1134
1135 wxNode *node = m_pendingEvents->First();
1136 while ( node )
1137 {
1138 wxEvent *event = (wxEvent *)node->Data();
1139 delete node;
1140
1141 // In ProcessEvent, new events might get added and
1142 // we can safely leave the crtical section here.
1143 #if defined(__VISAGECPP__)
1144 wxLEAVE_CRIT_SECT( m_eventsLocker);
1145 #else
1146 wxLEAVE_CRIT_SECT( *m_eventsLocker);
1147 #endif
1148 ProcessEvent(*event);
1149 delete event;
1150 #if defined(__VISAGECPP__)
1151 wxENTER_CRIT_SECT( m_eventsLocker);
1152 #else
1153 wxENTER_CRIT_SECT( *m_eventsLocker);
1154 #endif
1155
1156 node = m_pendingEvents->First();
1157 }
1158
1159 #if defined(__VISAGECPP__)
1160 wxLEAVE_CRIT_SECT( m_eventsLocker);
1161 #else
1162 wxLEAVE_CRIT_SECT( *m_eventsLocker);
1163 #endif
1164 }
1165
1166 /*
1167 * Event table stuff
1168 */
1169
1170 bool wxEvtHandler::ProcessEvent(wxEvent& event)
1171 {
1172 #if wxUSE_GUI
1173 // check that our flag corresponds to reality
1174 wxASSERT( m_isWindow == IsKindOf(CLASSINFO(wxWindow)) );
1175 #endif // wxUSE_GUI
1176
1177 // An event handler can be enabled or disabled
1178 if ( GetEvtHandlerEnabled() )
1179 {
1180
1181 #if 0
1182 /*
1183 What is this? When using GUI threads, a non main
1184 threads can send an event and process it itself.
1185 This breaks GTK's GUI threads, so please explain.
1186 */
1187
1188 // Check whether we are in a child thread.
1189 if ( !wxThread::IsMain() )
1190 return ProcessThreadEvent(event);
1191 #endif
1192
1193 // Handle per-instance dynamic event tables first
1194 if ( m_dynamicEvents && SearchDynamicEventTable(event) )
1195 return TRUE;
1196
1197 // Then static per-class event tables
1198 const wxEventTable *table = GetEventTable();
1199
1200 #if wxUSE_GUI && wxUSE_VALIDATORS
1201 // Try the associated validator first, if this is a window.
1202 // Problem: if the event handler of the window has been replaced,
1203 // this wxEvtHandler may no longer be a window.
1204 // Therefore validators won't be processed if the handler
1205 // has been replaced with SetEventHandler.
1206 // THIS CAN BE CURED if PushEventHandler is used instead of
1207 // SetEventHandler, and then processing will be passed down the
1208 // chain of event handlers.
1209 if (m_isWindow)
1210 {
1211 wxWindow *win = (wxWindow *)this;
1212
1213 // Can only use the validator of the window which
1214 // is receiving the event
1215 if ( win == event.GetEventObject() )
1216 {
1217 wxValidator *validator = win->GetValidator();
1218 if ( validator && validator->ProcessEvent(event) )
1219 {
1220 return TRUE;
1221 }
1222 }
1223 }
1224 #endif
1225
1226 // Search upwards through the inheritance hierarchy
1227 while (table)
1228 {
1229 if ( SearchEventTable((wxEventTable&)*table, event) )
1230 return TRUE;
1231 table = table->baseTable;
1232 }
1233 }
1234
1235 // Try going down the event handler chain
1236 if ( GetNextHandler() )
1237 {
1238 if ( GetNextHandler()->ProcessEvent(event) )
1239 return TRUE;
1240 }
1241
1242 #if wxUSE_GUI
1243 // Carry on up the parent-child hierarchy,
1244 // but only if event is a command event: it wouldn't
1245 // make sense for a parent to receive a child's size event, for example
1246 if ( m_isWindow && event.IsCommandEvent() )
1247 {
1248 wxWindow *win = (wxWindow *)this;
1249 wxWindow *parent = win->GetParent();
1250 if (parent && !parent->IsBeingDeleted())
1251 return parent->GetEventHandler()->ProcessEvent(event);
1252 }
1253 #endif // wxUSE_GUI
1254
1255 // Last try - application object.
1256 if ( wxTheApp && (this != wxTheApp) )
1257 {
1258 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1259 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1260 // processed appropriately via SearchEventTable.
1261 if ( event.GetEventType() != wxEVT_IDLE )
1262 {
1263 if ( wxTheApp->ProcessEvent(event) )
1264 return TRUE;
1265 }
1266 }
1267
1268 return FALSE;
1269 }
1270
1271 bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
1272 {
1273 wxEventType eventType = event.GetEventType();
1274 int eventId = event.GetId();
1275
1276 // BC++ doesn't like testing for m_fn without != 0
1277 for ( int i = 0; table.entries[i].m_fn != 0; i++ )
1278 {
1279 // the line using reference exposes a bug in gcc: although it _seems_
1280 // to work, it leads to weird crashes later on during program
1281 // execution
1282 #ifdef __GNUG__
1283 wxEventTableEntry entry = table.entries[i];
1284 #else
1285 const wxEventTableEntry& entry = table.entries[i];
1286 #endif
1287
1288 // match only if the event type is the same and the id is either -1 in
1289 // the event table (meaning "any") or the event id matches the id
1290 // specified in the event table either exactly or by falling into
1291 // range between first and last
1292 if ( eventType == entry.m_eventType )
1293 {
1294 int tableId1 = entry.m_id,
1295 tableId2 = entry.m_lastId;
1296
1297 if ( (tableId1 == -1) ||
1298 (tableId2 == -1 && eventId == tableId1) ||
1299 (tableId2 != -1 &&
1300 (eventId >= tableId1 && eventId <= tableId2)) )
1301 {
1302 event.Skip(FALSE);
1303 event.m_callbackUserData = entry.m_callbackUserData;
1304
1305 (this->*((wxEventFunction) (entry.m_fn)))(event);
1306
1307 return !event.GetSkipped();
1308 }
1309 }
1310 }
1311
1312 return FALSE;
1313 }
1314
1315 void wxEvtHandler::Connect( int id, int lastId,
1316 int eventType,
1317 wxObjectEventFunction func,
1318 wxObject *userData )
1319 {
1320 wxDynamicEventTableEntry *entry =
1321 new wxDynamicEventTableEntry(eventType, id, lastId, func, userData);
1322
1323 if (!m_dynamicEvents)
1324 m_dynamicEvents = new wxList;
1325
1326 m_dynamicEvents->Append( (wxObject*) entry );
1327 }
1328
1329 bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType,
1330 wxObjectEventFunction func,
1331 wxObject *userData )
1332 {
1333 if (!m_dynamicEvents)
1334 return FALSE;
1335
1336 wxNode *node = m_dynamicEvents->First();
1337 while (node)
1338 {
1339 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->Data();
1340 if ((entry->m_id == id) &&
1341 ((entry->m_lastId == lastId) || (lastId == -1)) &&
1342 ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) &&
1343 ((entry->m_fn == func) || (func == (wxObjectEventFunction)NULL)) &&
1344 ((entry->m_callbackUserData == userData) || (userData == (wxObject*)NULL)))
1345 {
1346 if (entry->m_callbackUserData) delete entry->m_callbackUserData;
1347 m_dynamicEvents->DeleteNode( node );
1348 delete entry;
1349 return TRUE;
1350 }
1351 node = node->Next();
1352 }
1353 return FALSE;
1354 }
1355
1356 bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
1357 {
1358 wxCHECK_MSG( m_dynamicEvents, FALSE,
1359 wxT("caller should check that we have dynamic events") );
1360
1361 int commandId = event.GetId();
1362
1363 wxNode *node = m_dynamicEvents->First();
1364 while (node)
1365 {
1366 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->Data();
1367
1368 if (entry->m_fn)
1369 {
1370 // Match, if event spec says any id will do (id == -1)
1371 if ( (event.GetEventType() == entry->m_eventType) &&
1372 (entry->m_id == -1 ||
1373 (entry->m_lastId == -1 && commandId == entry->m_id) ||
1374 (entry->m_lastId != -1 &&
1375 (commandId >= entry->m_id && commandId <= entry->m_lastId))) )
1376 {
1377 event.Skip(FALSE);
1378 event.m_callbackUserData = entry->m_callbackUserData;
1379
1380 (this->*((wxEventFunction) (entry->m_fn)))(event);
1381
1382 if (event.GetSkipped())
1383 return FALSE;
1384 else
1385 return TRUE;
1386 }
1387 }
1388 node = node->Next();
1389 }
1390 return FALSE;
1391 };
1392
1393 #if WXWIN_COMPATIBILITY
1394 bool wxEvtHandler::OnClose()
1395 {
1396 if (GetNextHandler())
1397 return GetNextHandler()->OnClose();
1398 else
1399 return FALSE;
1400 }
1401 #endif // WXWIN_COMPATIBILITY
1402
1403 #if wxUSE_GUI
1404
1405 // Find a window with the focus, that is also a descendant of the given window.
1406 // This is used to determine the window to initially send commands to.
1407 wxWindow* wxFindFocusDescendant(wxWindow* ancestor)
1408 {
1409 // Process events starting with the window with the focus, if any.
1410 wxWindow* focusWin = wxWindow::FindFocus();
1411 wxWindow* win = focusWin;
1412
1413 // Check if this is a descendant of this frame.
1414 // If not, win will be set to NULL.
1415 while (win)
1416 {
1417 if (win == ancestor)
1418 break;
1419 else
1420 win = win->GetParent();
1421 }
1422 if (win == (wxWindow*) NULL)
1423 focusWin = (wxWindow*) NULL;
1424
1425 return focusWin;
1426 }
1427
1428 #endif // wxUSE_GUI