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