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