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