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