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