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