]> git.saurik.com Git - wxWidgets.git/blame - src/common/event.cpp
fixed wxBase compilation (what was msgdlg.h doing in wxchar.cpp?)
[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$
8// Copyright: (c) Julian Smart and Markus Holzem
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"
47#endif // wxUSE_GUI
c801d85f 48
8e193f38
VZ
49// ----------------------------------------------------------------------------
50// wxWin macros
51// ----------------------------------------------------------------------------
52
23f681ec
VZ
53IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject)
54IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject)
e90c1d2a 55
23f681ec 56#if wxUSE_GUI
6b55490a 57 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent)
23f681ec
VZ
58 IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent, wxEvent)
59 IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent, wxCommandEvent)
60 IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent, wxCommandEvent)
61 IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent, wxEvent)
62 IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent, wxEvent)
63 IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent, wxEvent)
64 IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent, wxEvent)
65 IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent, wxEvent)
1e6feb95 66 IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent, wxEvent)
23f681ec
VZ
67 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent, wxEvent)
68 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent, wxEvent)
69 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent, wxEvent)
456bc6d9 70 IMPLEMENT_DYNAMIC_CLASS(wxChildFocusEvent, wxCommandEvent)
23f681ec
VZ
71 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent, wxEvent)
72 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent, wxEvent)
73 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent, wxEvent)
74 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent, wxEvent)
75 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent, wxEvent)
76 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent, wxEvent)
77 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent, wxEvent)
78 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent, wxEvent)
79 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent, wxEvent)
8e72b8b5 80 IMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent, wxEvent)
23f681ec 81 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent, wxEvent)
574c939e 82 IMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent, wxEvent)
23f681ec
VZ
83 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent, wxCommandEvent)
84 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent, wxCommandEvent)
85 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent, wxEvent)
86 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent, wxEvent)
87 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent, wxEvent)
88 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent, wxEvent)
b96340e6 89 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent, wxCommandEvent)
69231000 90 IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent, wxCommandEvent)
a5e84126 91 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent, wxEvent)
23f681ec 92#endif // wxUSE_GUI
0b746ba8 93
23f681ec
VZ
94const wxEventTable *wxEvtHandler::GetEventTable() const
95 { return &wxEvtHandler::sm_eventTable; }
0b746ba8 96
23f681ec
VZ
97const wxEventTable wxEvtHandler::sm_eventTable =
98 { (const wxEventTable *)NULL, &wxEvtHandler::sm_eventTableEntries[0] };
0b746ba8 99
23f681ec 100const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] =
9aaf9bed 101 { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL, 0, 0, (wxObjectEventFunction)NULL, NULL) };
c801d85f 102
8e193f38
VZ
103// ----------------------------------------------------------------------------
104// global variables
105// ----------------------------------------------------------------------------
106
107// To put pending event handlers
108wxList *wxPendingEvents = (wxList *)NULL;
109
7214297d 110#if wxUSE_THREADS
8e193f38
VZ
111 // protects wxPendingEvents list
112 wxCriticalSection *wxPendingEventsLocker = (wxCriticalSection *)NULL;
7214297d
GL
113#endif
114
cbee8f8d
VZ
115#if !WXWIN_COMPATIBILITY_EVENT_TYPES
116
2e4df4bf
VZ
117// common event types are defined here, other event types are defined by the
118// components which use them
119
461697c2 120DEFINE_EVENT_TYPE(wxEVT_NULL)
2e4df4bf
VZ
121DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED)
122DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED)
123DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED)
124DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED)
125DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED)
126DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED)
2e4df4bf
VZ
127DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED)
128DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED)
129DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED)
130DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED)
131DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED)
132DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED)
133DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED)
134DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED)
135DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER)
136DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED)
0b5eceb6
VZ
137
138// Sockets and timers send events, too
2e4df4bf
VZ
139DEFINE_EVENT_TYPE(wxEVT_SOCKET)
140DEFINE_EVENT_TYPE(wxEVT_TIMER)
0b5eceb6
VZ
141
142// Mouse event types
2e4df4bf
VZ
143DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN)
144DEFINE_EVENT_TYPE(wxEVT_LEFT_UP)
145DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN)
146DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP)
147DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN)
148DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP)
149DEFINE_EVENT_TYPE(wxEVT_MOTION)
150DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW)
151DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW)
152DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK)
153DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK)
154DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK)
155DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS)
156DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS)
456bc6d9 157DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS)
d2c52078 158DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL)
0b5eceb6
VZ
159
160// Non-client mouse events
2e4df4bf
VZ
161DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN)
162DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP)
163DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN)
164DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP)
165DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN)
166DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP)
167DEFINE_EVENT_TYPE(wxEVT_NC_MOTION)
168DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW)
169DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW)
170DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK)
171DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK)
172DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK)
0b5eceb6
VZ
173
174// Character input event type
2e4df4bf
VZ
175DEFINE_EVENT_TYPE(wxEVT_CHAR)
176DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK)
177DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY)
178DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN)
179DEFINE_EVENT_TYPE(wxEVT_KEY_UP)
0b5eceb6
VZ
180
181// Set cursor event
2e4df4bf 182DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR)
0b5eceb6
VZ
183
184// wxScrollbar and wxSlider event identifiers
2e4df4bf
VZ
185DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP)
186DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM)
187DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP)
188DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN)
189DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP)
190DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN)
191DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK)
192DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE)
e8b669d3 193DEFINE_EVENT_TYPE(wxEVT_SCROLL_ENDSCROLL)
0b5eceb6
VZ
194
195// Scroll events from wxWindow
2e4df4bf
VZ
196DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP)
197DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM)
198DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP)
199DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN)
200DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP)
201DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN)
202DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK)
203DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE)
0b5eceb6
VZ
204
205// System events
2e4df4bf
VZ
206DEFINE_EVENT_TYPE(wxEVT_SIZE)
207DEFINE_EVENT_TYPE(wxEVT_MOVE)
208DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW)
209DEFINE_EVENT_TYPE(wxEVT_END_SESSION)
210DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION)
211DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP)
212DEFINE_EVENT_TYPE(wxEVT_POWER)
213DEFINE_EVENT_TYPE(wxEVT_ACTIVATE)
214DEFINE_EVENT_TYPE(wxEVT_CREATE)
215DEFINE_EVENT_TYPE(wxEVT_DESTROY)
216DEFINE_EVENT_TYPE(wxEVT_SHOW)
217DEFINE_EVENT_TYPE(wxEVT_ICONIZE)
218DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE)
219DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED)
220DEFINE_EVENT_TYPE(wxEVT_PAINT)
221DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND)
222DEFINE_EVENT_TYPE(wxEVT_NC_PAINT)
223DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON)
ccef86c7
VZ
224DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN)
225DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE)
2e4df4bf 226DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT)
2e4df4bf
VZ
227DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU)
228DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED)
574c939e 229DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED)
2e4df4bf
VZ
230DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED)
231DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE)
232DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED)
233DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN)
234DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP)
235DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE)
236DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE)
237DEFINE_EVENT_TYPE(wxEVT_DROP_FILES)
238DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM)
239DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM)
240DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM)
241DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG)
242DEFINE_EVENT_TYPE(wxEVT_IDLE)
243DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI)
0b5eceb6
VZ
244
245// Generic command events
246// Note: a click is a higher-level event than button down/up
2e4df4bf
VZ
247DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK)
248DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK)
249DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK)
250DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK)
251DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS)
252DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS)
253DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER)
0b5eceb6
VZ
254
255// Help events
2e4df4bf
VZ
256DEFINE_EVENT_TYPE(wxEVT_HELP)
257DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP)
6164f93c
VZ
258
259#endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
260
261// ============================================================================
262// implementation
263// ============================================================================
0b5eceb6 264
0b5eceb6
VZ
265// ----------------------------------------------------------------------------
266// event initialization
267// ----------------------------------------------------------------------------
268
269int wxNewEventType()
270{
271 // MT-FIXME
272 static int s_lastUsedEventType = wxEVT_FIRST;
273
cbee8f8d
VZ
274#if WXWIN_COMPATIBILITY_2
275 // check that we don't overlap with the user-defined types: if it does
276 // happen, the best solution is probably to update the existing code to
277 // use wxNewEventType() instead of wxEVT_USER_FIRST
6164f93c
VZ
278 //
279 // due to the uncertainty
cbee8f8d
VZ
280 wxASSERT_MSG( s_lastUsedEventType < wxEVT_USER_FIRST - 1,
281 _T("possible event type conflict") );
282#endif // WXWIN_COMPATIBILITY_2
283
0b5eceb6
VZ
284 return s_lastUsedEventType++;
285}
286
8e193f38
VZ
287// ----------------------------------------------------------------------------
288// wxEvent
289// ----------------------------------------------------------------------------
290
c801d85f
KB
291/*
292 * General wxWindows events, covering
293 * all interesting things that might happen (button clicking, resizing,
294 * setting text in widgets, etc.).
295 *
296 * For each completely new event type, derive a new event class.
297 *
298 */
299
8e72b8b5 300wxEvent::wxEvent(int theId, wxEventType commandType )
c801d85f 301{
8e72b8b5 302 m_eventType = commandType;
0b746ba8 303 m_eventObject = (wxObject *) NULL;
0b746ba8
VZ
304 m_timeStamp = 0;
305 m_id = theId;
306 m_skipped = FALSE;
307 m_callbackUserData = (wxObject *) NULL;
193bf013 308 m_isCommandEvent = FALSE;
c801d85f
KB
309}
310
8e72b8b5 311wxEvent::wxEvent(const wxEvent &src)
e6a6feba
GD
312 : wxObject()
313 , m_eventObject(src.m_eventObject)
314 , m_eventType(src.m_eventType)
315 , m_timeStamp(src.m_timeStamp)
316 , m_id(src.m_id)
317 , m_callbackUserData(src.m_callbackUserData)
318 , m_skipped(src.m_skipped)
319 , m_isCommandEvent(src.m_isCommandEvent)
a737331d 320{
a737331d
GL
321}
322
e90c1d2a
VZ
323#if wxUSE_GUI
324
c801d85f
KB
325/*
326 * Command events
327 *
328 */
329
7798a18e 330wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId)
e6a6feba 331 : wxEvent(theId, commandType)
c801d85f 332{
0b746ba8
VZ
333 m_clientData = (char *) NULL;
334 m_clientObject = (wxClientData *) NULL;
335 m_extraLong = 0;
336 m_commandInt = 0;
04392d70 337 m_commandString = wxEmptyString;
193bf013 338 m_isCommandEvent = TRUE;
c801d85f
KB
339}
340
341/*
342 * Scroll events
343 */
344
0b746ba8
VZ
345wxScrollEvent::wxScrollEvent(wxEventType commandType,
346 int id,
347 int pos,
348 int orient)
e6a6feba 349 : wxCommandEvent(commandType, id)
c801d85f 350{
0b746ba8
VZ
351 m_extraLong = orient;
352 m_commandInt = pos;
c801d85f
KB
353}
354
d1367c3d
RR
355/*
356 * ScrollWin events
357 */
358
359wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType,
360 int pos,
361 int orient)
d1367c3d 362{
c5b42c87 363 m_eventType = commandType;
d1367c3d
RR
364 m_extraLong = orient;
365 m_commandInt = pos;
366}
367
c801d85f
KB
368/*
369 * Mouse events
370 *
371 */
372
7798a18e 373wxMouseEvent::wxMouseEvent(wxEventType commandType)
c801d85f 374{
0b746ba8
VZ
375 m_eventType = commandType;
376 m_metaDown = FALSE;
377 m_altDown = FALSE;
378 m_controlDown = FALSE;
379 m_shiftDown = FALSE;
380 m_leftDown = FALSE;
381 m_rightDown = FALSE;
382 m_middleDown = FALSE;
383 m_x = 0;
384 m_y = 0;
d2c52078
RD
385 m_wheelRotation = 0;
386 m_wheelDelta = 0;
387 m_linesPerAction = 0;
c801d85f
KB
388}
389
abcbaea7
VZ
390void wxMouseEvent::Assign(const wxMouseEvent& event)
391{
392 m_x = event.m_x;
393 m_y = event.m_y;
394
395 m_leftDown = event.m_leftDown;
396 m_middleDown = event.m_middleDown;
397 m_rightDown = event.m_rightDown;
398
399 m_controlDown = event.m_controlDown;
400 m_shiftDown = event.m_shiftDown;
401 m_altDown = event.m_altDown;
402 m_metaDown = event.m_metaDown;
403
404 m_wheelRotation = event.m_wheelRotation;
405 m_wheelDelta = event.m_wheelDelta;
406 m_linesPerAction = event.m_linesPerAction;
407}
408
c801d85f
KB
409// True if was a button dclick event (1 = left, 2 = middle, 3 = right)
410// or any button dclick event (but = -1)
411bool wxMouseEvent::ButtonDClick(int but) const
412{
0b746ba8
VZ
413 switch (but)
414 {
415 case -1:
416 return (LeftDClick() || MiddleDClick() || RightDClick());
417 case 1:
418 return LeftDClick();
419 case 2:
420 return MiddleDClick();
421 case 3:
422 return RightDClick();
423 default:
223d09f6 424 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
0b746ba8
VZ
425 }
426
427 return FALSE;
c801d85f
KB
428}
429
430// True if was a button down event (1 = left, 2 = middle, 3 = right)
431// or any button down event (but = -1)
432bool wxMouseEvent::ButtonDown(int but) const
433{
0b746ba8
VZ
434 switch (but)
435 {
436 case -1:
437 return (LeftDown() || MiddleDown() || RightDown());
438 case 1:
439 return LeftDown();
440 case 2:
441 return MiddleDown();
442 case 3:
443 return RightDown();
444 default:
223d09f6 445 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
0b746ba8
VZ
446 }
447
448 return FALSE;
c801d85f
KB
449}
450
451// True if was a button up event (1 = left, 2 = middle, 3 = right)
452// or any button up event (but = -1)
453bool wxMouseEvent::ButtonUp(int but) const
454{
1e6feb95
VZ
455 switch (but)
456 {
0b746ba8
VZ
457 case -1:
458 return (LeftUp() || MiddleUp() || RightUp());
459 case 1:
460 return LeftUp();
461 case 2:
462 return MiddleUp();
463 case 3:
464 return RightUp();
465 default:
223d09f6 466 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
0b746ba8
VZ
467 }
468
469 return FALSE;
c801d85f
KB
470}
471
472// True if the given button is currently changing state
473bool wxMouseEvent::Button(int but) const
474{
1e6feb95
VZ
475 switch (but)
476 {
0b746ba8 477 case -1:
72cdf4c9 478 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
0b746ba8
VZ
479 case 1:
480 return (LeftDown() || LeftUp() || LeftDClick());
481 case 2:
482 return (MiddleDown() || MiddleUp() || MiddleDClick());
483 case 3:
484 return (RightDown() || RightUp() || RightDClick());
485 default:
223d09f6 486 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
0b746ba8
VZ
487 }
488
489 return FALSE;
c801d85f
KB
490}
491
492bool wxMouseEvent::ButtonIsDown(int but) const
493{
1e6feb95
VZ
494 switch (but)
495 {
0b746ba8
VZ
496 case -1:
497 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
498 case 1:
499 return LeftIsDown();
500 case 2:
501 return MiddleIsDown();
502 case 3:
503 return RightIsDown();
504 default:
223d09f6 505 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
0b746ba8
VZ
506 }
507
508 return FALSE;
c801d85f
KB
509}
510
1e6feb95
VZ
511int wxMouseEvent::GetButton() const
512{
513 for ( int i = 1; i <= 3; i++ )
514 {
515 if ( Button(i) )
516 {
517 return i;
518 }
519 }
520
521 return -1;
522}
523
c801d85f
KB
524// Find the logical position of the event given the DC
525wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const
526{
0757d27c
JS
527 wxPoint pt(dc.DeviceToLogicalX(m_x), dc.DeviceToLogicalY(m_y));
528 return pt;
c801d85f
KB
529}
530
531
532/*
8e72b8b5 533 * Keyboard event
c801d85f
KB
534 *
535 */
536
7798a18e 537wxKeyEvent::wxKeyEvent(wxEventType type)
c801d85f 538{
0b746ba8
VZ
539 m_eventType = type;
540 m_shiftDown = FALSE;
541 m_controlDown = FALSE;
542 m_metaDown = FALSE;
543 m_altDown = FALSE;
544 m_keyCode = 0;
b0e813a0 545 m_scanCode = 0;
c801d85f
KB
546}
547
aadbdf11 548
42e69d6b 549wxWindowCreateEvent::wxWindowCreateEvent(wxWindow *win)
42e69d6b 550{
cfe17b74 551 SetEventType(wxEVT_CREATE);
42e69d6b
VZ
552 SetEventObject(win);
553}
554
555wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow *win)
42e69d6b 556{
cfe17b74 557 SetEventType(wxEVT_DESTROY);
42e69d6b
VZ
558 SetEventObject(win);
559}
560
456bc6d9
VZ
561wxChildFocusEvent::wxChildFocusEvent(wxWindow *win)
562 : wxCommandEvent(wxEVT_CHILD_FOCUS)
563{
564 SetEventObject(win);
565}
566
dd070522
VZ
567#endif // wxUSE_GUI
568
456bc6d9
VZ
569// ----------------------------------------------------------------------------
570// wxEvtHandler
571// ----------------------------------------------------------------------------
572
c801d85f
KB
573/*
574 * Event handler
575 */
576
0b746ba8 577wxEvtHandler::wxEvtHandler()
c801d85f 578{
0b746ba8
VZ
579 m_nextHandler = (wxEvtHandler *) NULL;
580 m_previousHandler = (wxEvtHandler *) NULL;
581 m_enabled = TRUE;
582 m_dynamicEvents = (wxList *) NULL;
193bf013 583 m_isWindow = FALSE;
8e193f38 584 m_pendingEvents = (wxList *) NULL;
7214297d 585#if wxUSE_THREADS
41404da7 586# if !defined(__VISAGECPP__)
8e193f38 587 m_eventsLocker = new wxCriticalSection;
41404da7 588# endif
7214297d 589#endif
b88c44e7
RD
590 // no client data (yet)
591 m_clientData = NULL;
592 m_clientDataType = wxClientData_None;
c801d85f
KB
593}
594
0b746ba8 595wxEvtHandler::~wxEvtHandler()
c801d85f 596{
0b746ba8
VZ
597 // Takes itself out of the list of handlers
598 if (m_previousHandler)
599 m_previousHandler->m_nextHandler = m_nextHandler;
600
601 if (m_nextHandler)
602 m_nextHandler->m_previousHandler = m_previousHandler;
603
604 if (m_dynamicEvents)
fe71f65c 605 {
0b746ba8
VZ
606 wxNode *node = m_dynamicEvents->First();
607 while (node)
608 {
2e4df4bf
VZ
609#if WXWIN_COMPATIBILITY_EVENT_TYPES
610 wxEventTableEntry *entry = (wxEventTableEntry*)node->Data();
611#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
77d4384e 612 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->Data();
2e4df4bf
VZ
613#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
614
615 if (entry->m_callbackUserData)
616 delete entry->m_callbackUserData;
0b746ba8
VZ
617 delete entry;
618 node = node->Next();
619 }
620 delete m_dynamicEvents;
621 };
7214297d 622
8e193f38 623 delete m_pendingEvents;
7214297d 624
8e193f38 625#if wxUSE_THREADS
41404da7 626# if !defined(__VISAGECPP__)
7214297d 627 delete m_eventsLocker;
41404da7 628# endif
7214297d 629#endif
b88c44e7
RD
630
631 // we only delete object data, not untyped
632 if ( m_clientDataType == wxClientData_Object )
633 delete m_clientObject;
c801d85f
KB
634}
635
7214297d 636#if wxUSE_THREADS
aadbdf11 637
7214297d
GL
638bool wxEvtHandler::ProcessThreadEvent(wxEvent& event)
639{
7214297d 640 // check that we are really in a child thread
8e193f38
VZ
641 wxASSERT_MSG( !wxThread::IsMain(),
642 wxT("use ProcessEvent() in main thread") );
643
644 AddPendingEvent(event);
7214297d 645
8e193f38
VZ
646 return TRUE;
647}
648
649#endif // wxUSE_THREADS
650
651void wxEvtHandler::AddPendingEvent(wxEvent& event)
652{
16c1f79c
RR
653 // 1) Add event to list of pending events of this event handler
654
7a5c8ac4
VZ
655 wxEvent *eventCopy = event.Clone();
656
657 // we must be able to copy the events here so the event class must
658 // implement Clone() properly instead of just providing a NULL stab for it
659 wxCHECK_RET( eventCopy,
660 _T("events of this type aren't supposed to be posted") );
661
16c1f79c
RR
662#if defined(__VISAGECPP__)
663 wxENTER_CRIT_SECT( m_eventsLocker);
664#else
665 wxENTER_CRIT_SECT( *m_eventsLocker);
666#endif
667
8e193f38
VZ
668 if ( !m_pendingEvents )
669 m_pendingEvents = new wxList;
7214297d 670
7a5c8ac4 671 m_pendingEvents->Append(eventCopy);
7214297d 672
16c1f79c
RR
673#if defined(__VISAGECPP__)
674 wxLEAVE_CRIT_SECT( m_eventsLocker);
675#else
676 wxLEAVE_CRIT_SECT( *m_eventsLocker);
677#endif
678
679 // 2) Add this event handler to list of event handlers that
680 // have pending events.
cfe17b74 681
b568d04f 682 wxENTER_CRIT_SECT(*wxPendingEventsLocker);
72cdf4c9 683
8e193f38
VZ
684 if ( !wxPendingEvents )
685 wxPendingEvents = new wxList;
4d3a259a 686 wxPendingEvents->Append(this);
72cdf4c9 687
ce6d2511 688 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker);
6164f93c 689
16c1f79c
RR
690 // 3) Inform the system that new pending events are somwehere,
691 // and that these should be processed in idle time.
bf9e3e73 692 wxWakeUpIdle();
7214297d
GL
693}
694
695void wxEvtHandler::ProcessPendingEvents()
696{
41404da7 697#if defined(__VISAGECPP__)
16c1f79c 698 wxENTER_CRIT_SECT( m_eventsLocker);
b568d04f 699#else
16c1f79c 700 wxENTER_CRIT_SECT( *m_eventsLocker);
41404da7 701#endif
8e193f38 702
7214297d 703 wxNode *node = m_pendingEvents->First();
8e193f38
VZ
704 while ( node )
705 {
16c1f79c
RR
706 wxEvent *event = (wxEvent *)node->Data();
707 delete node;
cfe17b74 708
16c1f79c 709 // In ProcessEvent, new events might get added and
6164f93c 710 // we can safely leave the crtical section here.
16c1f79c
RR
711#if defined(__VISAGECPP__)
712 wxLEAVE_CRIT_SECT( m_eventsLocker);
713#else
714 wxLEAVE_CRIT_SECT( *m_eventsLocker);
715#endif
8e193f38 716 ProcessEvent(*event);
9779893b 717 delete event;
16c1f79c
RR
718#if defined(__VISAGECPP__)
719 wxENTER_CRIT_SECT( m_eventsLocker);
720#else
721 wxENTER_CRIT_SECT( *m_eventsLocker);
722#endif
cfe17b74 723
8e193f38 724 node = m_pendingEvents->First();
7214297d 725 }
cfe17b74 726
16c1f79c
RR
727#if defined(__VISAGECPP__)
728 wxLEAVE_CRIT_SECT( m_eventsLocker);
729#else
730 wxLEAVE_CRIT_SECT( *m_eventsLocker);
731#endif
7214297d 732}
7214297d 733
c801d85f
KB
734/*
735 * Event table stuff
736 */
737
738bool wxEvtHandler::ProcessEvent(wxEvent& event)
739{
e90c1d2a 740#if wxUSE_GUI
1a77875b 741
01f944e6
GD
742 // We have to use the actual window or processing events from
743 // wxWindowNative destructor won't work (we don't see the wxWindow class)
1a77875b 744#ifdef __WXDEBUG__
8e193f38 745 // check that our flag corresponds to reality
1a77875b
JS
746 wxClassInfo* info = NULL;
747#ifdef __WXUNIVERSAL__
748# if defined(__WXMSW__)
749 info = CLASSINFO(wxWindowMSW);
750# elif defined(__WXGTK__)
751 info = CLASSINFO(wxWindowGTK);
ea596687
JS
752# elif defined(__WXX11__)
753 info = CLASSINFO(wxWindowX11);
1a77875b
JS
754# elif defined(__WXMGL__)
755 info = CLASSINFO(wxWindowMGL);
19193a2c
KB
756# elif defined(__WXPM__)
757 info = CLASSINFO(wxWindowOS2);
1a77875b
JS
758# elif defined(__WXMAC__)
759 info = CLASSINFO(wxWindowMac);
760# elif defined(__WXMOTIF__)
761 info = CLASSINFO(wxWindowMotif);
762# endif
763#else
764 info = CLASSINFO(wxWindow);
765#endif
766
9154d8cf
VZ
767 if ( m_isWindow != IsKindOf(info) )
768 {
769 wxString msg = GetClassInfo()->GetClassName();
770 msg += _T(" should [not] be a window but it is [not]");
771
772 wxFAIL_MSG( msg );
773 }
774
775#endif // __WXDEBUG__
1a77875b 776
e90c1d2a 777#endif // wxUSE_GUI
0b746ba8 778
9154d8cf
VZ
779 // allow the application to hook into event processing
780 if ( wxTheApp )
781 {
782 int rc = wxTheApp->FilterEvent(event);
783 if ( rc != -1 )
784 {
785 wxASSERT_MSG( rc == 1 || rc == 0,
786 _T("unexpected wxApp::FilterEvent return value") );
787
788 return rc != 0;
789 }
790 //else: proceed normally
791 }
792
8e193f38 793 // An event handler can be enabled or disabled
0b746ba8 794 if ( GetEvtHandlerEnabled() )
c801d85f 795 {
6164f93c 796
924ef850
RR
797#if 0
798/*
799 What is this? When using GUI threads, a non main
800 threads can send an event and process it itself.
801 This breaks GTK's GUI threads, so please explain.
802*/
803
8e193f38
VZ
804 // Check whether we are in a child thread.
805 if ( !wxThread::IsMain() )
7214297d 806 return ProcessThreadEvent(event);
924ef850 807#endif
0757d27c 808
8e193f38 809 // Handle per-instance dynamic event tables first
193bf013 810 if ( m_dynamicEvents && SearchDynamicEventTable(event) )
0757d27c 811 return TRUE;
0b746ba8 812
8e193f38 813 // Then static per-class event tables
0b746ba8
VZ
814 const wxEventTable *table = GetEventTable();
815
e90c1d2a 816#if wxUSE_GUI && wxUSE_VALIDATORS
0b746ba8
VZ
817 // Try the associated validator first, if this is a window.
818 // Problem: if the event handler of the window has been replaced,
819 // this wxEvtHandler may no longer be a window.
820 // Therefore validators won't be processed if the handler
821 // has been replaced with SetEventHandler.
822 // THIS CAN BE CURED if PushEventHandler is used instead of
823 // SetEventHandler, and then processing will be passed down the
824 // chain of event handlers.
ce4169a4 825 if (m_isWindow)
0b746ba8
VZ
826 {
827 wxWindow *win = (wxWindow *)this;
828
829 // Can only use the validator of the window which
830 // is receiving the event
193bf013 831 if ( win == event.GetEventObject() )
0b746ba8 832 {
193bf013
VZ
833 wxValidator *validator = win->GetValidator();
834 if ( validator && validator->ProcessEvent(event) )
835 {
836 return TRUE;
837 }
0b746ba8
VZ
838 }
839 }
ce4169a4 840#endif
0b746ba8
VZ
841
842 // Search upwards through the inheritance hierarchy
ce4169a4 843 while (table)
0b746ba8 844 {
193bf013 845 if ( SearchEventTable((wxEventTable&)*table, event) )
0b746ba8
VZ
846 return TRUE;
847 table = table->baseTable;
848 }
c801d85f
KB
849 }
850
0b746ba8
VZ
851 // Try going down the event handler chain
852 if ( GetNextHandler() )
c801d85f 853 {
0b746ba8
VZ
854 if ( GetNextHandler()->ProcessEvent(event) )
855 return TRUE;
c801d85f 856 }
c801d85f 857
e90c1d2a 858#if wxUSE_GUI
3bdc265d
VZ
859 // Carry on up the parent-child hierarchy, but only if event is a command
860 // event: it wouldn't make sense for a parent to receive a child's size
861 // event, for example
193bf013 862 if ( m_isWindow && event.IsCommandEvent() )
0b746ba8
VZ
863 {
864 wxWindow *win = (wxWindow *)this;
3bdc265d 865
e4b713a2
VZ
866 // honour the requests to stop propagation at this window: this is
867 // used by the dialogs, for example, to prevent processing the events
868 // from the dialog controls in the parent frame which rarely, if ever,
869 // makes sense
870 if ( !(win->GetExtraStyle() & wxWS_EX_BLOCK_EVENTS) )
3bdc265d
VZ
871 {
872 wxWindow *parent = win->GetParent();
e4b713a2 873 if ( parent && !parent->IsBeingDeleted() )
3bdc265d
VZ
874 return parent->GetEventHandler()->ProcessEvent(event);
875 }
0b746ba8 876 }
e90c1d2a 877#endif // wxUSE_GUI
0b746ba8
VZ
878
879 // Last try - application object.
193bf013 880 if ( wxTheApp && (this != wxTheApp) )
0b746ba8 881 {
193bf013
VZ
882 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
883 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
884 // processed appropriately via SearchEventTable.
885 if ( event.GetEventType() != wxEVT_IDLE )
886 {
887 if ( wxTheApp->ProcessEvent(event) )
888 return TRUE;
889 }
0b746ba8
VZ
890 }
891
c801d85f
KB
892 return FALSE;
893}
894
895bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
896{
68662769
VZ
897 wxEventType eventType = event.GetEventType();
898 int eventId = event.GetId();
0b746ba8 899
68662769
VZ
900 // BC++ doesn't like testing for m_fn without != 0
901 for ( int i = 0; table.entries[i].m_fn != 0; i++ )
c801d85f 902 {
6e58645e
VZ
903 // the line using reference exposes a bug in gcc: although it _seems_
904 // to work, it leads to weird crashes later on during program
905 // execution
906#ifdef __GNUG__
907 wxEventTableEntry entry = table.entries[i];
908#else
68662769 909 const wxEventTableEntry& entry = table.entries[i];
6e58645e 910#endif
68662769
VZ
911
912 // match only if the event type is the same and the id is either -1 in
913 // the event table (meaning "any") or the event id matches the id
914 // specified in the event table either exactly or by falling into
915 // range between first and last
916 if ( eventType == entry.m_eventType )
0b746ba8 917 {
68662769
VZ
918 int tableId1 = entry.m_id,
919 tableId2 = entry.m_lastId;
920
921 if ( (tableId1 == -1) ||
922 (tableId2 == -1 && eventId == tableId1) ||
923 (tableId2 != -1 &&
924 (eventId >= tableId1 && eventId <= tableId2)) )
925 {
926 event.Skip(FALSE);
927 event.m_callbackUserData = entry.m_callbackUserData;
0b746ba8 928
68662769 929 (this->*((wxEventFunction) (entry.m_fn)))(event);
0b746ba8 930
68662769
VZ
931 return !event.GetSkipped();
932 }
0b746ba8 933 }
c801d85f 934 }
68662769 935
0b746ba8 936 return FALSE;
c801d85f 937}
97d7bfb8 938
debe6624 939void wxEvtHandler::Connect( int id, int lastId,
77d4384e 940 int eventType,
0b746ba8
VZ
941 wxObjectEventFunction func,
942 wxObject *userData )
fe71f65c 943{
cbee8f8d 944#if WXWIN_COMPATIBILITY_EVENT_TYPES
2e4df4bf 945 wxEventTableEntry *entry = new wxEventTableEntry;
cbee8f8d
VZ
946 entry->m_eventType = eventType;
947 entry->m_id = id;
948 entry->m_lastId = lastId;
949 entry->m_fn = func;
950 entry->m_callbackUserData = userData;
951#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
0b5eceb6
VZ
952 wxDynamicEventTableEntry *entry =
953 new wxDynamicEventTableEntry(eventType, id, lastId, func, userData);
cbee8f8d 954#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
0b746ba8
VZ
955
956 if (!m_dynamicEvents)
957 m_dynamicEvents = new wxList;
958
959 m_dynamicEvents->Append( (wxObject*) entry );
fe71f65c 960}
97d7bfb8
RR
961
962bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType,
963 wxObjectEventFunction func,
964 wxObject *userData )
965{
966 if (!m_dynamicEvents)
967 return FALSE;
cfe17b74 968
97d7bfb8
RR
969 wxNode *node = m_dynamicEvents->First();
970 while (node)
971 {
2e4df4bf
VZ
972#if WXWIN_COMPATIBILITY_EVENT_TYPES
973 wxEventTableEntry *entry = (wxEventTableEntry*)node->Data();
974#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
975 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->Data();
976#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
977
97d7bfb8
RR
978 if ((entry->m_id == id) &&
979 ((entry->m_lastId == lastId) || (lastId == -1)) &&
980 ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) &&
981 ((entry->m_fn == func) || (func == (wxObjectEventFunction)NULL)) &&
982 ((entry->m_callbackUserData == userData) || (userData == (wxObject*)NULL)))
983 {
2e4df4bf
VZ
984 if (entry->m_callbackUserData)
985 delete entry->m_callbackUserData;
97d7bfb8
RR
986 m_dynamicEvents->DeleteNode( node );
987 delete entry;
988 return TRUE;
989 }
990 node = node->Next();
991 }
992 return FALSE;
993}
fe71f65c
RR
994
995bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
996{
193bf013 997 wxCHECK_MSG( m_dynamicEvents, FALSE,
223d09f6 998 wxT("caller should check that we have dynamic events") );
0b746ba8
VZ
999
1000 int commandId = event.GetId();
1001
1002 wxNode *node = m_dynamicEvents->First();
1003 while (node)
fe71f65c 1004 {
2e4df4bf
VZ
1005#if WXWIN_COMPATIBILITY_EVENT_TYPES
1006 wxEventTableEntry *entry = (wxEventTableEntry*)node->Data();
1007#else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1008 wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->Data();
1009#endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
0b746ba8
VZ
1010
1011 if (entry->m_fn)
1012 {
1013 // Match, if event spec says any id will do (id == -1)
1014 if ( (event.GetEventType() == entry->m_eventType) &&
1015 (entry->m_id == -1 ||
1016 (entry->m_lastId == -1 && commandId == entry->m_id) ||
1017 (entry->m_lastId != -1 &&
1018 (commandId >= entry->m_id && commandId <= entry->m_lastId))) )
1019 {
1020 event.Skip(FALSE);
1021 event.m_callbackUserData = entry->m_callbackUserData;
1022
1023 (this->*((wxEventFunction) (entry->m_fn)))(event);
1024
1025 if (event.GetSkipped())
1026 return FALSE;
1027 else
1028 return TRUE;
1029 }
1030 }
1031 node = node->Next();
7b678698 1032 }
0b746ba8 1033 return FALSE;
fe71f65c
RR
1034};
1035
b88c44e7
RD
1036void wxEvtHandler::DoSetClientObject( wxClientData *data )
1037{
1038 wxASSERT_MSG( m_clientDataType != wxClientData_Void,
1039 wxT("can't have both object and void client data") );
1040
1041 if ( m_clientObject )
1042 delete m_clientObject;
1043
1044 m_clientObject = data;
1045 m_clientDataType = wxClientData_Object;
1046}
1047
1048wxClientData *wxEvtHandler::DoGetClientObject() const
1049{
1050 // it's not an error to call GetClientObject() on a window which doesn't
1051 // have client data at all - NULL will be returned
1052 wxASSERT_MSG( m_clientDataType != wxClientData_Void,
1053 wxT("this window doesn't have object client data") );
1054
1055 return m_clientObject;
1056}
1057
1058void wxEvtHandler::DoSetClientData( void *data )
1059{
1060 wxASSERT_MSG( m_clientDataType != wxClientData_Object,
1061 wxT("can't have both object and void client data") );
1062
1063 m_clientData = data;
1064 m_clientDataType = wxClientData_Void;
1065}
1066
1067void *wxEvtHandler::DoGetClientData() const
1068{
1069 // it's not an error to call GetClientData() on a window which doesn't have
1070 // client data at all - NULL will be returned
1071 wxASSERT_MSG( m_clientDataType != wxClientData_Object,
1072 wxT("this window doesn't have void client data") );
1073
1074 return m_clientData;
1075}
1076
1077
e3065973 1078#if WXWIN_COMPATIBILITY
0b746ba8 1079bool wxEvtHandler::OnClose()
c801d85f 1080{
0b746ba8
VZ
1081 if (GetNextHandler())
1082 return GetNextHandler()->OnClose();
1083 else
1084 return FALSE;
c801d85f 1085}
193bf013 1086#endif // WXWIN_COMPATIBILITY
e3065973 1087
e90c1d2a
VZ
1088#if wxUSE_GUI
1089
e702ff0f
JS
1090// Find a window with the focus, that is also a descendant of the given window.
1091// This is used to determine the window to initially send commands to.
1092wxWindow* wxFindFocusDescendant(wxWindow* ancestor)
1093{
1094 // Process events starting with the window with the focus, if any.
1095 wxWindow* focusWin = wxWindow::FindFocus();
1096 wxWindow* win = focusWin;
1097
1098 // Check if this is a descendant of this frame.
1099 // If not, win will be set to NULL.
1100 while (win)
1101 {
1102 if (win == ancestor)
1103 break;
1104 else
1105 win = win->GetParent();
1106 }
1107 if (win == (wxWindow*) NULL)
1108 focusWin = (wxWindow*) NULL;
1109
1110 return focusWin;
1111}
1112
e90c1d2a 1113#endif // wxUSE_GUI