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