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