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