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