]> git.saurik.com Git - wxWidgets.git/blame - src/common/event.cpp
added version info hidden dialog
[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
DW
49#if wxUSE_GUI
50 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
51 // define these here to keep from getting multiply defines externals
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;
237
238#if defined(__BORLANDC__) && defined(__WIN16__)
239/* For 16-bit BC++, these 2 are identical (truncated) */
240const wxEventType wxEVT_COMMAND_NB_PAGE_CHANGED = wxEVT_FIRST + 802;
241const wxEventType wxEVT_COMMAND_NB_PAGE_CHANGING = wxEVT_FIRST + 803;
242#else
243const wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED = wxEVT_FIRST + 802;
244const wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING = wxEVT_FIRST + 803;
245#endif
246
247/* Splitter events */
248const wxEventType wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED = wxEVT_FIRST + 850;
249const wxEventType wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING = wxEVT_FIRST + 851;
250const wxEventType wxEVT_COMMAND_SPLITTER_DOUBLECLICKED = wxEVT_FIRST + 852;
251const wxEventType wxEVT_COMMAND_SPLITTER_UNSPLIT = wxEVT_FIRST + 853;
252
253/* Wizard events */
254const wxEventType wxEVT_WIZARD_PAGE_CHANGED = wxEVT_FIRST + 900;
255const wxEventType wxEVT_WIZARD_PAGE_CHANGING = wxEVT_FIRST + 901;
256const wxEventType wxEVT_WIZARD_CANCEL = wxEVT_FIRST + 902;
257
258/* Calendar events */
259const wxEventType wxEVT_CALENDAR_SEL_CHANGED = wxEVT_FIRST + 950;
260const wxEventType wxEVT_CALENDAR_DAY_CHANGED = wxEVT_FIRST + 951;
261const wxEventType wxEVT_CALENDAR_MONTH_CHANGED = wxEVT_FIRST + 952;
262const wxEventType wxEVT_CALENDAR_YEAR_CHANGED = wxEVT_FIRST + 953;
263const wxEventType wxEVT_CALENDAR_DOUBLECLICKED = wxEVT_FIRST + 954;
264const wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED = wxEVT_FIRST + 955;
265
266const wxEventType wxEVT_USER_FIRST = wxEVT_FIRST + 2000;
267
268 #endif // VisualAge C++ V4.0
269#endif // wxUSE_GUI
270
8e193f38
VZ
271// ----------------------------------------------------------------------------
272// wxWin macros
273// ----------------------------------------------------------------------------
274
0b746ba8
VZ
275 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler, wxObject)
276 IMPLEMENT_ABSTRACT_CLASS(wxEvent, wxObject)
0b746ba8 277 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent, wxEvent)
e90c1d2a
VZ
278
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)
307 #endif // wxUSE_GUI
0b746ba8
VZ
308
309 const wxEventTable *wxEvtHandler::GetEventTable() const
310 { return &wxEvtHandler::sm_eventTable; }
311
312 const wxEventTable wxEvtHandler::sm_eventTable =
313 { (const wxEventTable *)NULL, &wxEvtHandler::sm_eventTableEntries[0] };
314
315 const wxEventTableEntry wxEvtHandler::sm_eventTableEntries[] =
58d1c1ae 316 { { 0, 0, 0, (wxObjectEventFunction) NULL, (wxObject*) NULL } };
0b746ba8 317
c801d85f 318
8e193f38
VZ
319// ----------------------------------------------------------------------------
320// global variables
321// ----------------------------------------------------------------------------
322
323// To put pending event handlers
324wxList *wxPendingEvents = (wxList *)NULL;
325
7214297d 326#if wxUSE_THREADS
8e193f38
VZ
327 // protects wxPendingEvents list
328 wxCriticalSection *wxPendingEventsLocker = (wxCriticalSection *)NULL;
7214297d
GL
329#endif
330
8e193f38
VZ
331// ============================================================================
332// implementation
333// ============================================================================
334
335// ----------------------------------------------------------------------------
336// wxEvent
337// ----------------------------------------------------------------------------
338
c801d85f
KB
339/*
340 * General wxWindows events, covering
341 * all interesting things that might happen (button clicking, resizing,
342 * setting text in widgets, etc.).
343 *
344 * For each completely new event type, derive a new event class.
345 *
346 */
347
348wxEvent::wxEvent(int theId)
349{
0b746ba8
VZ
350 m_eventType = wxEVT_NULL;
351 m_eventObject = (wxObject *) NULL;
0b746ba8
VZ
352 m_timeStamp = 0;
353 m_id = theId;
354 m_skipped = FALSE;
355 m_callbackUserData = (wxObject *) NULL;
193bf013 356 m_isCommandEvent = FALSE;
c801d85f
KB
357}
358
aadbdf11 359void wxEvent::CopyObject(wxObject& object_dest) const
a737331d 360{
e90c1d2a 361 wxEvent *obj = (wxEvent *)&object_dest;
aadbdf11
GL
362 wxObject::CopyObject(object_dest);
363
364 obj->m_eventType = m_eventType;
365 obj->m_eventObject = m_eventObject;
aadbdf11
GL
366 obj->m_timeStamp = m_timeStamp;
367 obj->m_id = m_id;
368 obj->m_skipped = m_skipped;
369 obj->m_callbackUserData = m_callbackUserData;
370 obj->m_isCommandEvent = m_isCommandEvent;
a737331d
GL
371}
372
e90c1d2a
VZ
373#if wxUSE_GUI
374
c801d85f
KB
375/*
376 * Command events
377 *
378 */
379
7798a18e 380wxCommandEvent::wxCommandEvent(wxEventType commandType, int theId)
c801d85f 381{
0b746ba8
VZ
382 m_eventType = commandType;
383 m_clientData = (char *) NULL;
384 m_clientObject = (wxClientData *) NULL;
385 m_extraLong = 0;
386 m_commandInt = 0;
387 m_id = theId;
04392d70 388 m_commandString = wxEmptyString;
193bf013 389 m_isCommandEvent = TRUE;
c801d85f
KB
390}
391
aadbdf11
GL
392void wxCommandEvent::CopyObject(wxObject& obj_d) const
393{
e90c1d2a 394 wxCommandEvent *obj = (wxCommandEvent *)&obj_d;
aadbdf11
GL
395
396 wxEvent::CopyObject(obj_d);
397
924ef850
RR
398 obj->m_clientData = m_clientData;
399 obj->m_clientObject = m_clientObject;
400 obj->m_extraLong = m_extraLong;
401 obj->m_commandInt = m_commandInt;
402 obj->m_commandString = m_commandString;
403}
404
405/*
406 * Notify events
407 */
408
409void wxNotifyEvent::CopyObject(wxObject& obj_d) const
410{
411 wxNotifyEvent *obj = (wxNotifyEvent *)&obj_d;
412
413 wxEvent::CopyObject(obj_d);
414
415 if (!m_bAllow) obj->Veto();
aadbdf11
GL
416}
417
c801d85f
KB
418/*
419 * Scroll events
420 */
421
0b746ba8
VZ
422wxScrollEvent::wxScrollEvent(wxEventType commandType,
423 int id,
424 int pos,
425 int orient)
426 : wxCommandEvent(commandType, id)
c801d85f 427{
0b746ba8
VZ
428 m_extraLong = orient;
429 m_commandInt = pos;
298d19f9
GRG
430 m_isScrolling = TRUE;
431}
432
433void wxScrollEvent::CopyObject(wxObject& obj_d) const
434{
435 wxScrollEvent *obj = (wxScrollEvent*)&obj_d;
436
437 wxCommandEvent::CopyObject(obj_d);
438
439 obj->m_isScrolling = m_isScrolling;
c801d85f
KB
440}
441
d1367c3d
RR
442/*
443 * ScrollWin events
444 */
445
446wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType,
447 int pos,
448 int orient)
d1367c3d 449{
c5b42c87 450 m_eventType = commandType;
d1367c3d
RR
451 m_extraLong = orient;
452 m_commandInt = pos;
298d19f9 453 m_isScrolling = TRUE;
d1367c3d
RR
454}
455
3c679789
RR
456void wxScrollWinEvent::CopyObject(wxObject& obj_d) const
457{
e90c1d2a 458 wxScrollWinEvent *obj = (wxScrollWinEvent*)&obj_d;
3c679789
RR
459
460 wxEvent::CopyObject(obj_d);
461
462 obj->m_extraLong = m_extraLong;
463 obj->m_commandInt = m_commandInt;
298d19f9 464 obj->m_isScrolling = m_isScrolling;
3c679789
RR
465}
466
c801d85f
KB
467/*
468 * Mouse events
469 *
470 */
471
7798a18e 472wxMouseEvent::wxMouseEvent(wxEventType commandType)
c801d85f 473{
0b746ba8
VZ
474 m_eventType = commandType;
475 m_metaDown = FALSE;
476 m_altDown = FALSE;
477 m_controlDown = FALSE;
478 m_shiftDown = FALSE;
479 m_leftDown = FALSE;
480 m_rightDown = FALSE;
481 m_middleDown = FALSE;
482 m_x = 0;
483 m_y = 0;
c801d85f
KB
484}
485
aadbdf11
GL
486void wxMouseEvent::CopyObject(wxObject& obj_d) const
487{
488 wxMouseEvent *obj = (wxMouseEvent *)&obj_d;
489
490 wxEvent::CopyObject(obj_d);
491
492 obj->m_metaDown = m_metaDown;
493 obj->m_altDown = m_altDown;
494 obj->m_controlDown = m_controlDown;
495 obj->m_shiftDown = m_shiftDown;
496 obj->m_leftDown = m_leftDown;
497 obj->m_rightDown = m_rightDown;
498 obj->m_middleDown = m_middleDown;
499 obj->m_x = m_x;
500 obj->m_y = m_y;
501}
502
c801d85f
KB
503// True if was a button dclick event (1 = left, 2 = middle, 3 = right)
504// or any button dclick event (but = -1)
505bool wxMouseEvent::ButtonDClick(int but) const
506{
0b746ba8
VZ
507 switch (but)
508 {
509 case -1:
510 return (LeftDClick() || MiddleDClick() || RightDClick());
511 case 1:
512 return LeftDClick();
513 case 2:
514 return MiddleDClick();
515 case 3:
516 return RightDClick();
517 default:
223d09f6 518 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
0b746ba8
VZ
519 }
520
521 return FALSE;
c801d85f
KB
522}
523
524// True if was a button down event (1 = left, 2 = middle, 3 = right)
525// or any button down event (but = -1)
526bool wxMouseEvent::ButtonDown(int but) const
527{
0b746ba8
VZ
528 switch (but)
529 {
530 case -1:
531 return (LeftDown() || MiddleDown() || RightDown());
532 case 1:
533 return LeftDown();
534 case 2:
535 return MiddleDown();
536 case 3:
537 return RightDown();
538 default:
223d09f6 539 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
0b746ba8
VZ
540 }
541
542 return FALSE;
c801d85f
KB
543}
544
545// True if was a button up event (1 = left, 2 = middle, 3 = right)
546// or any button up event (but = -1)
547bool wxMouseEvent::ButtonUp(int but) const
548{
0b746ba8
VZ
549 switch (but) {
550 case -1:
551 return (LeftUp() || MiddleUp() || RightUp());
552 case 1:
553 return LeftUp();
554 case 2:
555 return MiddleUp();
556 case 3:
557 return RightUp();
558 default:
223d09f6 559 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
0b746ba8
VZ
560 }
561
562 return FALSE;
c801d85f
KB
563}
564
565// True if the given button is currently changing state
566bool wxMouseEvent::Button(int but) const
567{
0b746ba8
VZ
568 switch (but) {
569 case -1:
72cdf4c9 570 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
0b746ba8
VZ
571 case 1:
572 return (LeftDown() || LeftUp() || LeftDClick());
573 case 2:
574 return (MiddleDown() || MiddleUp() || MiddleDClick());
575 case 3:
576 return (RightDown() || RightUp() || RightDClick());
577 default:
223d09f6 578 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
0b746ba8
VZ
579 }
580
581 return FALSE;
c801d85f
KB
582}
583
584bool wxMouseEvent::ButtonIsDown(int but) const
585{
0b746ba8
VZ
586 switch (but) {
587 case -1:
588 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
589 case 1:
590 return LeftIsDown();
591 case 2:
592 return MiddleIsDown();
593 case 3:
594 return RightIsDown();
595 default:
223d09f6 596 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
0b746ba8
VZ
597 }
598
599 return FALSE;
c801d85f
KB
600}
601
602// Find the logical position of the event given the DC
603wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const
604{
0757d27c
JS
605 wxPoint pt(dc.DeviceToLogicalX(m_x), dc.DeviceToLogicalY(m_y));
606 return pt;
c801d85f
KB
607}
608
609
610/*
611 * Keyboard events
612 *
613 */
614
7798a18e 615wxKeyEvent::wxKeyEvent(wxEventType type)
c801d85f 616{
0b746ba8
VZ
617 m_eventType = type;
618 m_shiftDown = FALSE;
619 m_controlDown = FALSE;
620 m_metaDown = FALSE;
621 m_altDown = FALSE;
622 m_keyCode = 0;
b0e813a0 623 m_scanCode = 0;
c801d85f
KB
624}
625
aadbdf11
GL
626void wxKeyEvent::CopyObject(wxObject& obj_d) const
627{
628 wxKeyEvent *obj = (wxKeyEvent *)&obj_d;
629 wxEvent::CopyObject(obj_d);
630
924ef850
RR
631 obj->m_x = m_x;
632 obj->m_y = m_y;
633 obj->m_keyCode = m_keyCode;
634
aadbdf11
GL
635 obj->m_shiftDown = m_shiftDown;
636 obj->m_controlDown = m_controlDown;
637 obj->m_metaDown = m_metaDown;
638 obj->m_altDown = m_altDown;
639 obj->m_keyCode = m_keyCode;
640}
641
642
643/*
644 * Misc events
645 */
646
647void wxSizeEvent::CopyObject(wxObject& obj_d) const
648{
649 wxSizeEvent *obj = (wxSizeEvent *)&obj_d;
650 wxEvent::CopyObject(obj_d);
651
652 obj->m_size = m_size;
653}
654
655void wxMoveEvent::CopyObject(wxObject& obj_d) const
656{
657 wxMoveEvent *obj = (wxMoveEvent *)&obj_d;
658 wxEvent::CopyObject(obj_d);
659
660 obj->m_pos = m_pos;
661}
662
663void wxEraseEvent::CopyObject(wxObject& obj_d) const
664{
665 wxEraseEvent *obj = (wxEraseEvent *)&obj_d;
666 wxEvent::CopyObject(obj_d);
667
668 obj->m_dc = m_dc;
669}
670
671void wxActivateEvent::CopyObject(wxObject& obj_d) const
672{
673 wxActivateEvent *obj = (wxActivateEvent *)&obj_d;
674 wxEvent::CopyObject(obj_d);
675
676 obj->m_active = m_active;
677}
678
679void wxMenuEvent::CopyObject(wxObject& obj_d) const
680{
681 wxMenuEvent *obj = (wxMenuEvent *)&obj_d;
682 wxEvent::CopyObject(obj_d);
683
684 obj->m_menuId = m_menuId;
685}
686
687void wxCloseEvent::CopyObject(wxObject& obj_d) const
688{
689 wxCloseEvent *obj = (wxCloseEvent *)&obj_d;
690 wxEvent::CopyObject(obj_d);
691
692 obj->m_loggingOff = m_loggingOff;
693 obj->m_veto = m_veto;
694#if WXWIN_COMPATIBILITY
695 obj->m_force = m_force;
696#endif
697 obj->m_canVeto = m_canVeto;
698}
e90c1d2a 699
aadbdf11
GL
700void wxShowEvent::CopyObject(wxObject& obj_d) const
701{
702 wxShowEvent *obj = (wxShowEvent *)&obj_d;
703 wxEvent::CopyObject(obj_d);
704
705 obj->m_show = m_show;
706}
f305c661
GL
707
708void wxJoystickEvent::CopyObject(wxObject& obj_d) const
709{
710 wxJoystickEvent *obj = (wxJoystickEvent *)&obj_d;
711 wxEvent::CopyObject(obj_d);
712
713 obj->m_pos = m_pos;
714 obj->m_zPosition = m_zPosition;
715 obj->m_buttonChange = m_buttonChange;
716 obj->m_buttonState = m_buttonState;
717 obj->m_joyStick = m_joyStick;
e90c1d2a 718}
f305c661
GL
719
720void wxDropFilesEvent::CopyObject(wxObject& obj_d) const
721{
722 wxDropFilesEvent *obj = (wxDropFilesEvent *)&obj_d;
723 wxEvent::CopyObject(obj_d);
724
725 obj->m_noFiles = m_noFiles;
726 obj->m_pos = m_pos;
727 // TODO: Problem with obj->m_files. It should be deallocated by the
e90c1d2a 728 // destructor of the event.
f305c661
GL
729}
730
731void wxUpdateUIEvent::CopyObject(wxObject &obj_d) const
732{
733 wxUpdateUIEvent *obj = (wxUpdateUIEvent *)&obj_d;
734 wxEvent::CopyObject(obj_d);
735
736 obj->m_checked = m_checked;
737 obj->m_enabled = m_enabled;
738 obj->m_text = m_text;
739 obj->m_setText = m_setText;
740 obj->m_setChecked = m_setChecked;
741 obj->m_setEnabled = m_setEnabled;
742}
743
744void wxPaletteChangedEvent::CopyObject(wxObject &obj_d) const
745{
746 wxPaletteChangedEvent *obj = (wxPaletteChangedEvent *)&obj_d;
747 wxEvent::CopyObject(obj_d);
748
749 obj->m_changedWindow = m_changedWindow;
750}
751
752void wxQueryNewPaletteEvent::CopyObject(wxObject& obj_d) const
753{
754 wxQueryNewPaletteEvent *obj = (wxQueryNewPaletteEvent *)&obj_d;
755 wxEvent::CopyObject(obj_d);
756
757 obj->m_paletteRealized = m_paletteRealized;
758}
aadbdf11 759
42e69d6b 760wxWindowCreateEvent::wxWindowCreateEvent(wxWindow *win)
cfe17b74 761 : wxEvent()
42e69d6b 762{
cfe17b74 763 SetEventType(wxEVT_CREATE);
42e69d6b
VZ
764 SetEventObject(win);
765}
766
767wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow *win)
cfe17b74 768 : wxEvent()
42e69d6b 769{
cfe17b74 770 SetEventType(wxEVT_DESTROY);
42e69d6b
VZ
771 SetEventObject(win);
772}
773
e90c1d2a
VZ
774#endif // wxUSE_GUI
775
776void wxIdleEvent::CopyObject(wxObject& obj_d) const
777{
778 wxIdleEvent *obj = (wxIdleEvent *)&obj_d;
779 wxEvent::CopyObject(obj_d);
780
781 obj->m_requestMore = m_requestMore;
782}
783
c801d85f
KB
784/*
785 * Event handler
786 */
787
0b746ba8 788wxEvtHandler::wxEvtHandler()
c801d85f 789{
0b746ba8
VZ
790 m_nextHandler = (wxEvtHandler *) NULL;
791 m_previousHandler = (wxEvtHandler *) NULL;
792 m_enabled = TRUE;
793 m_dynamicEvents = (wxList *) NULL;
193bf013 794 m_isWindow = FALSE;
8e193f38 795 m_pendingEvents = (wxList *) NULL;
7214297d 796#if wxUSE_THREADS
41404da7 797# if !defined(__VISAGECPP__)
8e193f38 798 m_eventsLocker = new wxCriticalSection;
41404da7 799# endif
7214297d 800#endif
c801d85f
KB
801}
802
0b746ba8 803wxEvtHandler::~wxEvtHandler()
c801d85f 804{
0b746ba8
VZ
805 // Takes itself out of the list of handlers
806 if (m_previousHandler)
807 m_previousHandler->m_nextHandler = m_nextHandler;
808
809 if (m_nextHandler)
810 m_nextHandler->m_previousHandler = m_previousHandler;
811
812 if (m_dynamicEvents)
fe71f65c 813 {
0b746ba8
VZ
814 wxNode *node = m_dynamicEvents->First();
815 while (node)
816 {
817 wxEventTableEntry *entry = (wxEventTableEntry*)node->Data();
818 if (entry->m_callbackUserData) delete entry->m_callbackUserData;
819 delete entry;
820 node = node->Next();
821 }
822 delete m_dynamicEvents;
823 };
7214297d 824
8e193f38 825 delete m_pendingEvents;
7214297d 826
8e193f38 827#if wxUSE_THREADS
41404da7 828# if !defined(__VISAGECPP__)
7214297d 829 delete m_eventsLocker;
41404da7 830# endif
7214297d 831#endif
c801d85f
KB
832}
833
7214297d 834#if wxUSE_THREADS
aadbdf11 835
7214297d
GL
836bool wxEvtHandler::ProcessThreadEvent(wxEvent& event)
837{
7214297d 838 // check that we are really in a child thread
8e193f38
VZ
839 wxASSERT_MSG( !wxThread::IsMain(),
840 wxT("use ProcessEvent() in main thread") );
841
842 AddPendingEvent(event);
7214297d 843
8e193f38
VZ
844 return TRUE;
845}
846
847#endif // wxUSE_THREADS
848
849void wxEvtHandler::AddPendingEvent(wxEvent& event)
850{
16c1f79c
RR
851 // 1) Add event to list of pending events of this event handler
852
853#if defined(__VISAGECPP__)
854 wxENTER_CRIT_SECT( m_eventsLocker);
855#else
856 wxENTER_CRIT_SECT( *m_eventsLocker);
857#endif
858
8e193f38
VZ
859 if ( !m_pendingEvents )
860 m_pendingEvents = new wxList;
7214297d 861
8e193f38 862 wxEvent *event2 = (wxEvent *)event.Clone();
7214297d 863
8e193f38 864 m_pendingEvents->Append(event2);
7214297d 865
16c1f79c
RR
866#if defined(__VISAGECPP__)
867 wxLEAVE_CRIT_SECT( m_eventsLocker);
868#else
869 wxLEAVE_CRIT_SECT( *m_eventsLocker);
870#endif
871
872 // 2) Add this event handler to list of event handlers that
873 // have pending events.
cfe17b74 874
b568d04f 875 wxENTER_CRIT_SECT(*wxPendingEventsLocker);
72cdf4c9 876
8e193f38
VZ
877 if ( !wxPendingEvents )
878 wxPendingEvents = new wxList;
4d3a259a 879 wxPendingEvents->Append(this);
72cdf4c9 880
ce6d2511
RR
881 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker);
882
16c1f79c
RR
883 // 3) Inform the system that new pending events are somwehere,
884 // and that these should be processed in idle time.
bf9e3e73 885 wxWakeUpIdle();
7214297d
GL
886}
887
888void wxEvtHandler::ProcessPendingEvents()
889{
41404da7 890#if defined(__VISAGECPP__)
16c1f79c 891 wxENTER_CRIT_SECT( m_eventsLocker);
b568d04f 892#else
16c1f79c 893 wxENTER_CRIT_SECT( *m_eventsLocker);
41404da7 894#endif
8e193f38 895
7214297d 896 wxNode *node = m_pendingEvents->First();
8e193f38
VZ
897 while ( node )
898 {
16c1f79c
RR
899 wxEvent *event = (wxEvent *)node->Data();
900 delete node;
cfe17b74 901
16c1f79c 902 // In ProcessEvent, new events might get added and
ce6d2511 903 // we can safely leave the crtical section here.
16c1f79c
RR
904#if defined(__VISAGECPP__)
905 wxLEAVE_CRIT_SECT( m_eventsLocker);
906#else
907 wxLEAVE_CRIT_SECT( *m_eventsLocker);
908#endif
8e193f38 909 ProcessEvent(*event);
9779893b 910 delete event;
16c1f79c
RR
911#if defined(__VISAGECPP__)
912 wxENTER_CRIT_SECT( m_eventsLocker);
913#else
914 wxENTER_CRIT_SECT( *m_eventsLocker);
915#endif
cfe17b74 916
8e193f38 917 node = m_pendingEvents->First();
7214297d 918 }
cfe17b74 919
16c1f79c
RR
920#if defined(__VISAGECPP__)
921 wxLEAVE_CRIT_SECT( m_eventsLocker);
922#else
923 wxLEAVE_CRIT_SECT( *m_eventsLocker);
924#endif
7214297d 925}
7214297d 926
c801d85f
KB
927/*
928 * Event table stuff
929 */
930
931bool wxEvtHandler::ProcessEvent(wxEvent& event)
932{
e90c1d2a 933#if wxUSE_GUI
8e193f38 934 // check that our flag corresponds to reality
193bf013 935 wxASSERT( m_isWindow == IsKindOf(CLASSINFO(wxWindow)) );
e90c1d2a 936#endif // wxUSE_GUI
0b746ba8 937
8e193f38 938 // An event handler can be enabled or disabled
0b746ba8 939 if ( GetEvtHandlerEnabled() )
c801d85f 940 {
924ef850
RR
941
942#if 0
943/*
944 What is this? When using GUI threads, a non main
945 threads can send an event and process it itself.
946 This breaks GTK's GUI threads, so please explain.
947*/
948
8e193f38
VZ
949 // Check whether we are in a child thread.
950 if ( !wxThread::IsMain() )
7214297d 951 return ProcessThreadEvent(event);
924ef850 952#endif
0757d27c 953
8e193f38 954 // Handle per-instance dynamic event tables first
193bf013 955 if ( m_dynamicEvents && SearchDynamicEventTable(event) )
0757d27c 956 return TRUE;
0b746ba8 957
8e193f38 958 // Then static per-class event tables
0b746ba8
VZ
959 const wxEventTable *table = GetEventTable();
960
e90c1d2a 961#if wxUSE_GUI && wxUSE_VALIDATORS
0b746ba8
VZ
962 // Try the associated validator first, if this is a window.
963 // Problem: if the event handler of the window has been replaced,
964 // this wxEvtHandler may no longer be a window.
965 // Therefore validators won't be processed if the handler
966 // has been replaced with SetEventHandler.
967 // THIS CAN BE CURED if PushEventHandler is used instead of
968 // SetEventHandler, and then processing will be passed down the
969 // chain of event handlers.
ce4169a4 970 if (m_isWindow)
0b746ba8
VZ
971 {
972 wxWindow *win = (wxWindow *)this;
973
974 // Can only use the validator of the window which
975 // is receiving the event
193bf013 976 if ( win == event.GetEventObject() )
0b746ba8 977 {
193bf013
VZ
978 wxValidator *validator = win->GetValidator();
979 if ( validator && validator->ProcessEvent(event) )
980 {
981 return TRUE;
982 }
0b746ba8
VZ
983 }
984 }
ce4169a4 985#endif
0b746ba8
VZ
986
987 // Search upwards through the inheritance hierarchy
ce4169a4 988 while (table)
0b746ba8 989 {
193bf013 990 if ( SearchEventTable((wxEventTable&)*table, event) )
0b746ba8
VZ
991 return TRUE;
992 table = table->baseTable;
993 }
c801d85f
KB
994 }
995
0b746ba8
VZ
996 // Try going down the event handler chain
997 if ( GetNextHandler() )
c801d85f 998 {
0b746ba8
VZ
999 if ( GetNextHandler()->ProcessEvent(event) )
1000 return TRUE;
c801d85f 1001 }
c801d85f 1002
e90c1d2a 1003#if wxUSE_GUI
0b746ba8
VZ
1004 // Carry on up the parent-child hierarchy,
1005 // but only if event is a command event: it wouldn't
1006 // make sense for a parent to receive a child's size event, for example
193bf013 1007 if ( m_isWindow && event.IsCommandEvent() )
0b746ba8
VZ
1008 {
1009 wxWindow *win = (wxWindow *)this;
1010 wxWindow *parent = win->GetParent();
1011 if (parent && !parent->IsBeingDeleted())
193bf013 1012 return parent->GetEventHandler()->ProcessEvent(event);
0b746ba8 1013 }
e90c1d2a 1014#endif // wxUSE_GUI
0b746ba8
VZ
1015
1016 // Last try - application object.
193bf013 1017 if ( wxTheApp && (this != wxTheApp) )
0b746ba8 1018 {
193bf013
VZ
1019 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1020 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1021 // processed appropriately via SearchEventTable.
1022 if ( event.GetEventType() != wxEVT_IDLE )
1023 {
1024 if ( wxTheApp->ProcessEvent(event) )
1025 return TRUE;
1026 }
0b746ba8
VZ
1027 }
1028
c801d85f
KB
1029 return FALSE;
1030}
1031
1032bool wxEvtHandler::SearchEventTable(wxEventTable& table, wxEvent& event)
1033{
0b746ba8
VZ
1034 int i = 0;
1035 int commandId = event.GetId();
1036
1037 // BC++ doesn't like while (table.entries[i].m_fn)
1038
2432b92d
JS
1039#ifdef __SC__
1040 while (table.entries[i].m_fn != 0)
1041#else
0b746ba8 1042 while (table.entries[i].m_fn != 0L)
2432b92d 1043#endif
c801d85f 1044 {
0b746ba8
VZ
1045 if ((event.GetEventType() == table.entries[i].m_eventType) &&
1046 (table.entries[i].m_id == -1 || // Match, if event spec says any id will do (id == -1)
1047 (table.entries[i].m_lastId == -1 && commandId == table.entries[i].m_id) ||
1048 (table.entries[i].m_lastId != -1 &&
1049 (commandId >= table.entries[i].m_id && commandId <= table.entries[i].m_lastId))))
1050 {
1051 event.Skip(FALSE);
1052 event.m_callbackUserData = table.entries[i].m_callbackUserData;
1053
1054 (this->*((wxEventFunction) (table.entries[i].m_fn)))(event);
1055
1056 if ( event.GetSkipped() )
1057 return FALSE;
1058 else
1059 return TRUE;
1060 }
1061 i++;
c801d85f 1062 }
0b746ba8 1063 return FALSE;
c801d85f 1064}
97d7bfb8 1065
debe6624 1066void wxEvtHandler::Connect( int id, int lastId,
d4a23fee 1067 wxEventType eventType,
0b746ba8
VZ
1068 wxObjectEventFunction func,
1069 wxObject *userData )
fe71f65c 1070{
0b746ba8
VZ
1071 wxEventTableEntry *entry = new wxEventTableEntry;
1072 entry->m_id = id;
1073 entry->m_lastId = lastId;
1074 entry->m_eventType = eventType;
1075 entry->m_fn = func;
1076 entry->m_callbackUserData = userData;
1077
1078 if (!m_dynamicEvents)
1079 m_dynamicEvents = new wxList;
1080
1081 m_dynamicEvents->Append( (wxObject*) entry );
fe71f65c 1082}
97d7bfb8
RR
1083
1084bool wxEvtHandler::Disconnect( int id, int lastId, wxEventType eventType,
1085 wxObjectEventFunction func,
1086 wxObject *userData )
1087{
1088 if (!m_dynamicEvents)
1089 return FALSE;
cfe17b74 1090
97d7bfb8
RR
1091 wxNode *node = m_dynamicEvents->First();
1092 while (node)
1093 {
1094 wxEventTableEntry *entry = (wxEventTableEntry*)node->Data();
1095 if ((entry->m_id == id) &&
1096 ((entry->m_lastId == lastId) || (lastId == -1)) &&
1097 ((entry->m_eventType == eventType) || (eventType == wxEVT_NULL)) &&
1098 ((entry->m_fn == func) || (func == (wxObjectEventFunction)NULL)) &&
1099 ((entry->m_callbackUserData == userData) || (userData == (wxObject*)NULL)))
1100 {
1101 if (entry->m_callbackUserData) delete entry->m_callbackUserData;
1102 m_dynamicEvents->DeleteNode( node );
1103 delete entry;
1104 return TRUE;
1105 }
1106 node = node->Next();
1107 }
1108 return FALSE;
1109}
fe71f65c
RR
1110
1111bool wxEvtHandler::SearchDynamicEventTable( wxEvent& event )
1112{
193bf013 1113 wxCHECK_MSG( m_dynamicEvents, FALSE,
223d09f6 1114 wxT("caller should check that we have dynamic events") );
0b746ba8
VZ
1115
1116 int commandId = event.GetId();
1117
1118 wxNode *node = m_dynamicEvents->First();
1119 while (node)
fe71f65c 1120 {
0b746ba8
VZ
1121 wxEventTableEntry *entry = (wxEventTableEntry*)node->Data();
1122
1123 if (entry->m_fn)
1124 {
1125 // Match, if event spec says any id will do (id == -1)
1126 if ( (event.GetEventType() == entry->m_eventType) &&
1127 (entry->m_id == -1 ||
1128 (entry->m_lastId == -1 && commandId == entry->m_id) ||
1129 (entry->m_lastId != -1 &&
1130 (commandId >= entry->m_id && commandId <= entry->m_lastId))) )
1131 {
1132 event.Skip(FALSE);
1133 event.m_callbackUserData = entry->m_callbackUserData;
1134
1135 (this->*((wxEventFunction) (entry->m_fn)))(event);
1136
1137 if (event.GetSkipped())
1138 return FALSE;
1139 else
1140 return TRUE;
1141 }
1142 }
1143 node = node->Next();
7b678698 1144 }
0b746ba8 1145 return FALSE;
fe71f65c
RR
1146};
1147
e3065973 1148#if WXWIN_COMPATIBILITY
0b746ba8 1149bool wxEvtHandler::OnClose()
c801d85f 1150{
0b746ba8
VZ
1151 if (GetNextHandler())
1152 return GetNextHandler()->OnClose();
1153 else
1154 return FALSE;
c801d85f 1155}
193bf013 1156#endif // WXWIN_COMPATIBILITY
e3065973 1157
e90c1d2a
VZ
1158#if wxUSE_GUI
1159
e702ff0f
JS
1160// Find a window with the focus, that is also a descendant of the given window.
1161// This is used to determine the window to initially send commands to.
1162wxWindow* wxFindFocusDescendant(wxWindow* ancestor)
1163{
1164 // Process events starting with the window with the focus, if any.
1165 wxWindow* focusWin = wxWindow::FindFocus();
1166 wxWindow* win = focusWin;
1167
1168 // Check if this is a descendant of this frame.
1169 // If not, win will be set to NULL.
1170 while (win)
1171 {
1172 if (win == ancestor)
1173 break;
1174 else
1175 win = win->GetParent();
1176 }
1177 if (win == (wxWindow*) NULL)
1178 focusWin = (wxWindow*) NULL;
1179
1180 return focusWin;
1181}
1182
e90c1d2a 1183#endif // wxUSE_GUI