1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/event.cpp
3 // Purpose: Event classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/evtloop.h"
34 #include "wx/stopwatch.h"
35 #include "wx/module.h"
38 #include "wx/window.h"
39 #include "wx/control.h"
41 #include "wx/textctrl.h"
42 #include "wx/validate.h"
46 #include "wx/thread.h"
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
53 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler
, wxObject
)
54 IMPLEMENT_ABSTRACT_CLASS(wxEvent
, wxObject
)
55 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent
, wxEvent
)
59 IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent
, wxEvent
)
60 IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent
, wxCommandEvent
)
61 IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent
, wxCommandEvent
)
62 IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent
, wxEvent
)
63 IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent
, wxEvent
)
64 IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent
, wxEvent
)
65 IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent
, wxEvent
)
66 IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent
, wxEvent
)
67 IMPLEMENT_DYNAMIC_CLASS(wxNcPaintEvent
, wxEvent
)
68 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent
, wxEvent
)
69 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent
, wxEvent
)
70 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent
, wxEvent
)
71 IMPLEMENT_DYNAMIC_CLASS(wxChildFocusEvent
, wxCommandEvent
)
72 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent
, wxEvent
)
73 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent
, wxEvent
)
74 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent
, wxEvent
)
75 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent
, wxEvent
)
76 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent
, wxEvent
)
77 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent
, wxEvent
)
78 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent
, wxEvent
)
79 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent
, wxEvent
)
80 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent
, wxEvent
)
81 IMPLEMENT_DYNAMIC_CLASS(wxSetCursorEvent
, wxEvent
)
82 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent
, wxEvent
)
83 IMPLEMENT_DYNAMIC_CLASS(wxDisplayChangedEvent
, wxEvent
)
84 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent
, wxCommandEvent
)
85 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent
, wxEvent
)
86 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent
, wxEvent
)
87 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent
, wxEvent
)
88 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent
, wxEvent
)
89 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent
, wxEvent
)
90 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent
, wxCommandEvent
)
91 IMPLEMENT_DYNAMIC_CLASS(wxContextMenuEvent
, wxCommandEvent
)
92 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureChangedEvent
, wxEvent
)
93 IMPLEMENT_DYNAMIC_CLASS(wxMouseCaptureLostEvent
, wxEvent
)
94 IMPLEMENT_DYNAMIC_CLASS(wxClipboardTextEvent
, wxCommandEvent
)
99 const wxEventTable
*wxEvtHandler::GetEventTable() const
100 { return &wxEvtHandler::sm_eventTable
; }
102 const wxEventTable
wxEvtHandler::sm_eventTable
=
103 { (const wxEventTable
*)NULL
, &wxEvtHandler::sm_eventTableEntries
[0] };
105 wxEventHashTable
&wxEvtHandler::GetEventHashTable() const
106 { return wxEvtHandler::sm_eventHashTable
; }
108 wxEventHashTable
wxEvtHandler::sm_eventHashTable(wxEvtHandler::sm_eventTable
);
110 const wxEventTableEntry
wxEvtHandler::sm_eventTableEntries
[] =
111 { DECLARE_EVENT_TABLE_ENTRY(wxEVT_NULL
, 0, 0, (wxObjectEventFunction
)NULL
, NULL
) };
114 // wxUSE_MEMORY_TRACING considers memory freed from the static objects dtors
115 // leaked, so we need to manually clean up all event tables before checking for
116 // the memory leaks when using it, however this breaks re-initializing the
117 // library (i.e. repeated calls to wxInitialize/wxUninitialize) because the
118 // event tables won't be rebuilt the next time, so disable this by default
119 #if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
121 class wxEventTableEntryModule
: public wxModule
124 wxEventTableEntryModule() { }
125 virtual bool OnInit() { return true; }
126 virtual void OnExit() { wxEventHashTable::ClearAll(); }
128 DECLARE_DYNAMIC_CLASS(wxEventTableEntryModule
)
131 IMPLEMENT_DYNAMIC_CLASS(wxEventTableEntryModule
, wxModule
)
133 #endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING
135 // ----------------------------------------------------------------------------
137 // ----------------------------------------------------------------------------
139 // To put pending event handlers
140 wxList
*wxPendingEvents
= (wxList
*)NULL
;
143 // protects wxPendingEvents list
144 wxCriticalSection
*wxPendingEventsLocker
= (wxCriticalSection
*)NULL
;
147 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
149 // common event types are defined here, other event types are defined by the
150 // components which use them
152 const wxEventType wxEVT_FIRST
= 10000;
153 const wxEventType wxEVT_USER_FIRST
= wxEVT_FIRST
+ 2000;
155 DEFINE_EVENT_TYPE(wxEVT_NULL
)
156 DEFINE_EVENT_TYPE(wxEVT_IDLE
)
157 DEFINE_EVENT_TYPE(wxEVT_SOCKET
)
158 DEFINE_EVENT_TYPE(wxEVT_TIMER
)
160 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
166 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
168 DEFINE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED
)
169 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED
)
170 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED
)
171 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED
)
172 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
)
173 DEFINE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
)
174 DEFINE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED
)
175 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED
)
176 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED
)
177 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED
)
178 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED
)
179 DEFINE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED
)
180 DEFINE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED
)
181 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED
)
182 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER
)
183 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED
)
184 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED
)
187 DEFINE_EVENT_TYPE(wxEVT_LEFT_DOWN
)
188 DEFINE_EVENT_TYPE(wxEVT_LEFT_UP
)
189 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DOWN
)
190 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_UP
)
191 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DOWN
)
192 DEFINE_EVENT_TYPE(wxEVT_RIGHT_UP
)
193 DEFINE_EVENT_TYPE(wxEVT_MOTION
)
194 DEFINE_EVENT_TYPE(wxEVT_ENTER_WINDOW
)
195 DEFINE_EVENT_TYPE(wxEVT_LEAVE_WINDOW
)
196 DEFINE_EVENT_TYPE(wxEVT_LEFT_DCLICK
)
197 DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK
)
198 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK
)
199 DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS
)
200 DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS
)
201 DEFINE_EVENT_TYPE(wxEVT_CHILD_FOCUS
)
202 DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL
)
203 DEFINE_EVENT_TYPE(wxEVT_AUX1_DOWN
)
204 DEFINE_EVENT_TYPE(wxEVT_AUX1_UP
)
205 DEFINE_EVENT_TYPE(wxEVT_AUX1_DCLICK
)
206 DEFINE_EVENT_TYPE(wxEVT_AUX2_DOWN
)
207 DEFINE_EVENT_TYPE(wxEVT_AUX2_UP
)
208 DEFINE_EVENT_TYPE(wxEVT_AUX2_DCLICK
)
210 // Non-client mouse events
211 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN
)
212 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_UP
)
213 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN
)
214 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP
)
215 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN
)
216 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_UP
)
217 DEFINE_EVENT_TYPE(wxEVT_NC_MOTION
)
218 DEFINE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW
)
219 DEFINE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW
)
220 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK
)
221 DEFINE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK
)
222 DEFINE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK
)
224 // Character input event type
225 DEFINE_EVENT_TYPE(wxEVT_CHAR
)
226 DEFINE_EVENT_TYPE(wxEVT_CHAR_HOOK
)
227 DEFINE_EVENT_TYPE(wxEVT_NAVIGATION_KEY
)
228 DEFINE_EVENT_TYPE(wxEVT_KEY_DOWN
)
229 DEFINE_EVENT_TYPE(wxEVT_KEY_UP
)
231 DEFINE_EVENT_TYPE(wxEVT_HOTKEY
)
235 DEFINE_EVENT_TYPE(wxEVT_SET_CURSOR
)
237 // wxScrollbar and wxSlider event identifiers
238 DEFINE_EVENT_TYPE(wxEVT_SCROLL_TOP
)
239 DEFINE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM
)
240 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEUP
)
241 DEFINE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN
)
242 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP
)
243 DEFINE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN
)
244 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK
)
245 DEFINE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE
)
246 DEFINE_EVENT_TYPE(wxEVT_SCROLL_CHANGED
)
248 // Scroll events from wxWindow
249 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP
)
250 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM
)
251 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP
)
252 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN
)
253 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP
)
254 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN
)
255 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK
)
256 DEFINE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE
)
259 DEFINE_EVENT_TYPE(wxEVT_SIZE
)
260 DEFINE_EVENT_TYPE(wxEVT_SIZING
)
261 DEFINE_EVENT_TYPE(wxEVT_MOVE
)
262 DEFINE_EVENT_TYPE(wxEVT_MOVING
)
263 DEFINE_EVENT_TYPE(wxEVT_MOVE_START
)
264 DEFINE_EVENT_TYPE(wxEVT_MOVE_END
)
265 DEFINE_EVENT_TYPE(wxEVT_CLOSE_WINDOW
)
266 DEFINE_EVENT_TYPE(wxEVT_END_SESSION
)
267 DEFINE_EVENT_TYPE(wxEVT_QUERY_END_SESSION
)
268 DEFINE_EVENT_TYPE(wxEVT_HIBERNATE
)
269 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE_APP
)
270 DEFINE_EVENT_TYPE(wxEVT_ACTIVATE
)
271 DEFINE_EVENT_TYPE(wxEVT_CREATE
)
272 DEFINE_EVENT_TYPE(wxEVT_DESTROY
)
273 DEFINE_EVENT_TYPE(wxEVT_SHOW
)
274 DEFINE_EVENT_TYPE(wxEVT_ICONIZE
)
275 DEFINE_EVENT_TYPE(wxEVT_MAXIMIZE
)
276 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED
)
277 DEFINE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_LOST
)
278 DEFINE_EVENT_TYPE(wxEVT_PAINT
)
279 DEFINE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND
)
280 DEFINE_EVENT_TYPE(wxEVT_NC_PAINT
)
281 DEFINE_EVENT_TYPE(wxEVT_PAINT_ICON
)
282 DEFINE_EVENT_TYPE(wxEVT_MENU_OPEN
)
283 DEFINE_EVENT_TYPE(wxEVT_MENU_CLOSE
)
284 DEFINE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT
)
285 DEFINE_EVENT_TYPE(wxEVT_CONTEXT_MENU
)
286 DEFINE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED
)
287 DEFINE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED
)
288 DEFINE_EVENT_TYPE(wxEVT_SETTING_CHANGED
)
289 DEFINE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE
)
290 DEFINE_EVENT_TYPE(wxEVT_PALETTE_CHANGED
)
291 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN
)
292 DEFINE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP
)
293 DEFINE_EVENT_TYPE(wxEVT_JOY_MOVE
)
294 DEFINE_EVENT_TYPE(wxEVT_JOY_ZMOVE
)
295 DEFINE_EVENT_TYPE(wxEVT_DROP_FILES
)
296 DEFINE_EVENT_TYPE(wxEVT_DRAW_ITEM
)
297 DEFINE_EVENT_TYPE(wxEVT_MEASURE_ITEM
)
298 DEFINE_EVENT_TYPE(wxEVT_COMPARE_ITEM
)
299 DEFINE_EVENT_TYPE(wxEVT_INIT_DIALOG
)
300 DEFINE_EVENT_TYPE(wxEVT_UPDATE_UI
)
303 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_COPY
)
304 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_CUT
)
305 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TEXT_PASTE
)
307 // Generic command events
308 // Note: a click is a higher-level event than button down/up
309 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK
)
310 DEFINE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK
)
311 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK
)
312 DEFINE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK
)
313 DEFINE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS
)
314 DEFINE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS
)
315 DEFINE_EVENT_TYPE(wxEVT_COMMAND_ENTER
)
318 DEFINE_EVENT_TYPE(wxEVT_HELP
)
319 DEFINE_EVENT_TYPE(wxEVT_DETAILED_HELP
)
321 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
327 wxIdleMode
wxIdleEvent::sm_idleMode
= wxIDLE_PROCESS_ALL
;
329 // ============================================================================
331 // ============================================================================
333 // ----------------------------------------------------------------------------
334 // event initialization
335 // ----------------------------------------------------------------------------
340 static int s_lastUsedEventType
= wxEVT_FIRST
;
342 return s_lastUsedEventType
++;
345 // ----------------------------------------------------------------------------
347 // ----------------------------------------------------------------------------
350 * General wxWidgets events, covering
351 * all interesting things that might happen (button clicking, resizing,
352 * setting text in widgets, etc.).
354 * For each completely new event type, derive a new event class.
358 wxEvent::wxEvent(int theId
, wxEventType commandType
)
360 m_eventType
= commandType
;
361 m_eventObject
= (wxObject
*) NULL
;
365 m_callbackUserData
= (wxObject
*) NULL
;
366 m_isCommandEvent
= false;
367 m_propagationLevel
= wxEVENT_PROPAGATE_NONE
;
370 wxEvent::wxEvent(const wxEvent
&src
)
372 , m_eventObject(src
.m_eventObject
)
373 , m_eventType(src
.m_eventType
)
374 , m_timeStamp(src
.m_timeStamp
)
376 , m_callbackUserData(src
.m_callbackUserData
)
377 , m_propagationLevel(src
.m_propagationLevel
)
378 , m_skipped(src
.m_skipped
)
379 , m_isCommandEvent(src
.m_isCommandEvent
)
393 // 'this' : used in base member initializer list (for m_commandString)
394 #pragma warning(disable:4355)
397 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
398 : wxEvent(theId
, commandType
)
400 m_clientData
= (char *) NULL
;
401 m_clientObject
= (wxClientData
*) NULL
;
404 m_isCommandEvent
= true;
406 // the command events are propagated upwards by default
407 m_propagationLevel
= wxEVENT_PROPAGATE_MAX
;
411 #pragma warning(default:4355)
414 wxString
wxCommandEvent::GetString() const
416 if(m_eventType
!= wxEVT_COMMAND_TEXT_UPDATED
|| !m_eventObject
)
421 wxTextCtrl
*txt
= wxDynamicCast(m_eventObject
, wxTextCtrl
);
423 return txt
->GetValue();
425 #endif // wxUSE_TEXTCTRL
435 wxLongLong
wxUpdateUIEvent::sm_lastUpdate
= 0;
438 long wxUpdateUIEvent::sm_updateInterval
= 0;
440 wxUpdateUIMode
wxUpdateUIEvent::sm_updateMode
= wxUPDATE_UI_PROCESS_ALL
;
443 bool wxUpdateUIEvent::CanUpdate(wxWindowBase
*win
)
445 // Don't update if we've switched global updating off
446 // and this window doesn't support updates.
448 (GetMode() == wxUPDATE_UI_PROCESS_SPECIFIED
&&
449 ((win
->GetExtraStyle() & wxWS_EX_PROCESS_UI_UPDATES
) == 0)))
452 if (sm_updateInterval
== -1)
455 if (sm_updateInterval
== 0)
458 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
459 wxLongLong now
= wxGetLocalTimeMillis();
460 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
467 // If we don't have wxStopWatch or wxLongLong, we
468 // should err on the safe side and update now anyway.
473 // Reset the update time to provide a delay until the next
474 // time we should update
475 void wxUpdateUIEvent::ResetUpdateTime()
477 #if wxUSE_STOPWATCH && wxUSE_LONGLONG
478 if (sm_updateInterval
> 0)
480 wxLongLong now
= wxGetLocalTimeMillis();
481 if (now
> (sm_lastUpdate
+ sm_updateInterval
))
493 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
497 : wxCommandEvent(commandType
, id
)
499 m_extraLong
= orient
;
507 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
511 m_eventType
= commandType
;
512 m_extraLong
= orient
;
521 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
523 m_eventType
= commandType
;
529 m_middleDown
= false;
534 m_controlDown
= false;
543 m_linesPerAction
= 0;
547 void wxMouseEvent::Assign(const wxMouseEvent
& event
)
549 m_eventType
= event
.m_eventType
;
554 m_leftDown
= event
.m_leftDown
;
555 m_middleDown
= event
.m_middleDown
;
556 m_rightDown
= event
.m_rightDown
;
557 m_aux1Down
= event
.m_aux1Down
;
558 m_aux2Down
= event
.m_aux2Down
;
560 m_controlDown
= event
.m_controlDown
;
561 m_shiftDown
= event
.m_shiftDown
;
562 m_altDown
= event
.m_altDown
;
563 m_metaDown
= event
.m_metaDown
;
565 m_wheelRotation
= event
.m_wheelRotation
;
566 m_wheelDelta
= event
.m_wheelDelta
;
567 m_linesPerAction
= event
.m_linesPerAction
;
568 m_wheelAxis
= event
.m_wheelAxis
;
571 // return true if was a button dclick event
572 bool wxMouseEvent::ButtonDClick(int but
) const
577 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
580 case wxMOUSE_BTN_ANY
:
581 return (LeftDClick() || MiddleDClick() || RightDClick() ||
582 Aux1DClick() || Aux2DClick());
584 case wxMOUSE_BTN_LEFT
:
587 case wxMOUSE_BTN_MIDDLE
:
588 return MiddleDClick();
590 case wxMOUSE_BTN_RIGHT
:
591 return RightDClick();
593 case wxMOUSE_BTN_AUX1
:
596 case wxMOUSE_BTN_AUX2
:
601 // return true if was a button down event
602 bool wxMouseEvent::ButtonDown(int but
) const
607 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
610 case wxMOUSE_BTN_ANY
:
611 return (LeftDown() || MiddleDown() || RightDown() ||
612 Aux1Down() || Aux2Down());
614 case wxMOUSE_BTN_LEFT
:
617 case wxMOUSE_BTN_MIDDLE
:
620 case wxMOUSE_BTN_RIGHT
:
623 case wxMOUSE_BTN_AUX1
:
626 case wxMOUSE_BTN_AUX2
:
631 // return true if was a button up event
632 bool wxMouseEvent::ButtonUp(int but
) const
637 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
640 case wxMOUSE_BTN_ANY
:
641 return (LeftUp() || MiddleUp() || RightUp() ||
642 Aux1Up() || Aux2Up());
644 case wxMOUSE_BTN_LEFT
:
647 case wxMOUSE_BTN_MIDDLE
:
650 case wxMOUSE_BTN_RIGHT
:
653 case wxMOUSE_BTN_AUX1
:
656 case wxMOUSE_BTN_AUX2
:
661 // return true if the given button is currently changing state
662 bool wxMouseEvent::Button(int but
) const
667 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
670 case wxMOUSE_BTN_ANY
:
671 return ButtonUp(wxMOUSE_BTN_ANY
) ||
672 ButtonDown(wxMOUSE_BTN_ANY
) ||
673 ButtonDClick(wxMOUSE_BTN_ANY
);
675 case wxMOUSE_BTN_LEFT
:
676 return LeftDown() || LeftUp() || LeftDClick();
678 case wxMOUSE_BTN_MIDDLE
:
679 return MiddleDown() || MiddleUp() || MiddleDClick();
681 case wxMOUSE_BTN_RIGHT
:
682 return RightDown() || RightUp() || RightDClick();
684 case wxMOUSE_BTN_AUX1
:
685 return Aux1Down() || Aux1Up() || Aux1DClick();
687 case wxMOUSE_BTN_AUX2
:
688 return Aux2Down() || Aux2Up() || Aux2DClick();
692 bool wxMouseEvent::ButtonIsDown(int but
) const
697 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
700 case wxMOUSE_BTN_ANY
:
701 return LeftIsDown() || MiddleIsDown() || RightIsDown() || Aux1Down() || Aux2Down();
703 case wxMOUSE_BTN_LEFT
:
706 case wxMOUSE_BTN_MIDDLE
:
707 return MiddleIsDown();
709 case wxMOUSE_BTN_RIGHT
:
710 return RightIsDown();
712 case wxMOUSE_BTN_AUX1
:
715 case wxMOUSE_BTN_AUX2
:
720 int wxMouseEvent::GetButton() const
722 for ( int i
= 1; i
< wxMOUSE_BTN_MAX
; i
++ )
730 return wxMOUSE_BTN_NONE
;
733 // Find the logical position of the event given the DC
734 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
736 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
746 wxKeyEvent::wxKeyEvent(wxEventType type
)
750 m_controlDown
= false;
760 wxKeyEvent::wxKeyEvent(const wxKeyEvent
& evt
)
766 m_keyCode
= evt
.m_keyCode
;
768 m_controlDown
= evt
.m_controlDown
;
769 m_shiftDown
= evt
.m_shiftDown
;
770 m_altDown
= evt
.m_altDown
;
771 m_metaDown
= evt
.m_metaDown
;
772 m_scanCode
= evt
.m_scanCode
;
773 m_rawCode
= evt
.m_rawCode
;
774 m_rawFlags
= evt
.m_rawFlags
;
777 m_uniChar
= evt
.m_uniChar
;
781 #if WXWIN_COMPATIBILITY_2_6
782 long wxKeyEvent::KeyCode() const
786 #endif // WXWIN_COMPATIBILITY_2_6
788 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
790 SetEventType(wxEVT_CREATE
);
794 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
796 SetEventType(wxEVT_DESTROY
);
800 wxChildFocusEvent::wxChildFocusEvent(wxWindow
*win
)
801 : wxCommandEvent(wxEVT_CHILD_FOCUS
)
806 // ----------------------------------------------------------------------------
808 // ----------------------------------------------------------------------------
811 wxHelpEvent::Origin
wxHelpEvent::GuessOrigin(Origin origin
)
813 if ( origin
== Origin_Unknown
)
815 // assume that the event comes from the help button if it's not from
816 // keyboard and that pressing F1 always results in the help event
817 origin
= wxGetKeyState(WXK_F1
) ? Origin_Keyboard
: Origin_HelpButton
;
828 // ----------------------------------------------------------------------------
830 // ----------------------------------------------------------------------------
832 static const int EVENT_TYPE_TABLE_INIT_SIZE
= 31; // Not too big not too small...
834 wxEventHashTable
* wxEventHashTable::sm_first
= NULL
;
836 wxEventHashTable::wxEventHashTable(const wxEventTable
&table
)
840 AllocEventTypeTable(EVENT_TYPE_TABLE_INIT_SIZE
);
844 m_next
->m_previous
= this;
848 wxEventHashTable::~wxEventHashTable()
851 m_next
->m_previous
= m_previous
;
853 m_previous
->m_next
= m_next
;
854 if (sm_first
== this)
860 void wxEventHashTable::Clear()
862 for ( size_t i
= 0; i
< m_size
; i
++ )
864 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
868 delete[] m_eventTypeTable
;
869 m_eventTypeTable
= NULL
;
874 #if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
877 void wxEventHashTable::ClearAll()
879 wxEventHashTable
* table
= sm_first
;
883 table
= table
->m_next
;
887 #endif // __WXDEBUG__ && wxUSE_MEMORY_TRACING
889 bool wxEventHashTable::HandleEvent(wxEvent
&event
, wxEvtHandler
*self
)
894 m_rebuildHash
= false;
897 if (!m_eventTypeTable
)
900 // Find all entries for the given event type.
901 wxEventType eventType
= event
.GetEventType();
902 const EventTypeTablePointer eTTnode
= m_eventTypeTable
[eventType
% m_size
];
903 if (eTTnode
&& eTTnode
->eventType
== eventType
)
905 // Now start the search for an event handler
906 // that can handle an event with the given ID.
907 const wxEventTableEntryPointerArray
&
908 eventEntryTable
= eTTnode
->eventEntryTable
;
910 const size_t count
= eventEntryTable
.GetCount();
911 for (size_t n
= 0; n
< count
; n
++)
914 ProcessEventIfMatches(*eventEntryTable
[n
], self
, event
) )
924 void wxEventHashTable::InitHashTable()
926 // Loop over the event tables and all its base tables.
927 const wxEventTable
*table
= &m_table
;
930 // Retrieve all valid event handler entries
931 const wxEventTableEntry
*entry
= table
->entries
;
932 while (entry
->m_fn
!= 0)
934 // Add the event entry in the Hash.
940 table
= table
->baseTable
;
943 // Lets free some memory.
945 for(i
= 0; i
< m_size
; i
++)
947 EventTypeTablePointer eTTnode
= m_eventTypeTable
[i
];
950 eTTnode
->eventEntryTable
.Shrink();
955 void wxEventHashTable::AddEntry(const wxEventTableEntry
&entry
)
957 // This might happen 'accidentally' as the app is exiting
958 if (!m_eventTypeTable
)
961 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[entry
.m_eventType
% m_size
];
962 EventTypeTablePointer eTTnode
= *peTTnode
;
966 if (eTTnode
->eventType
!= entry
.m_eventType
)
969 GrowEventTypeTable();
970 // Try again to add it.
977 eTTnode
= new EventTypeTable
;
978 eTTnode
->eventType
= entry
.m_eventType
;
982 // Fill all hash entries between entry.m_id and entry.m_lastId...
983 eTTnode
->eventEntryTable
.Add(&entry
);
986 void wxEventHashTable::AllocEventTypeTable(size_t size
)
988 m_eventTypeTable
= new EventTypeTablePointer
[size
];
989 memset((void *)m_eventTypeTable
, 0, sizeof(EventTypeTablePointer
)*size
);
993 void wxEventHashTable::GrowEventTypeTable()
995 size_t oldSize
= m_size
;
996 EventTypeTablePointer
*oldEventTypeTable
= m_eventTypeTable
;
998 // TODO: Search the most optimal grow sequence
999 AllocEventTypeTable(/* GetNextPrime(oldSize) */oldSize
*2+1);
1001 for ( size_t i
= 0; i
< oldSize
; /* */ )
1003 EventTypeTablePointer eTToldNode
= oldEventTypeTable
[i
];
1006 EventTypeTablePointer
*peTTnode
= &m_eventTypeTable
[eTToldNode
->eventType
% m_size
];
1007 EventTypeTablePointer eTTnode
= *peTTnode
;
1009 // Check for collision, we don't want any.
1012 GrowEventTypeTable();
1013 continue; // Don't increment the counter,
1014 // as we still need to add this element.
1018 // Get the old value and put it in the new table.
1019 *peTTnode
= oldEventTypeTable
[i
];
1026 delete[] oldEventTypeTable
;
1030 // ----------------------------------------------------------------------------
1032 // ----------------------------------------------------------------------------
1038 wxEvtHandler::wxEvtHandler()
1040 m_nextHandler
= (wxEvtHandler
*) NULL
;
1041 m_previousHandler
= (wxEvtHandler
*) NULL
;
1043 m_dynamicEvents
= (wxList
*) NULL
;
1044 m_pendingEvents
= (wxList
*) NULL
;
1046 # if !defined(__VISAGECPP__)
1047 m_eventsLocker
= new wxCriticalSection
;
1051 // no client data (yet)
1052 m_clientData
= NULL
;
1053 m_clientDataType
= wxClientData_None
;
1056 wxEvtHandler::~wxEvtHandler()
1058 // Takes itself out of the list of handlers
1059 if (m_previousHandler
)
1060 m_previousHandler
->m_nextHandler
= m_nextHandler
;
1063 m_nextHandler
->m_previousHandler
= m_previousHandler
;
1065 if (m_dynamicEvents
)
1067 for ( wxList::iterator it
= m_dynamicEvents
->begin(),
1068 end
= m_dynamicEvents
->end();
1072 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1073 wxEventTableEntry
*entry
= (wxEventTableEntry
*)*it
;
1074 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1075 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)*it
;
1076 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1078 if (entry
->m_callbackUserData
)
1079 delete entry
->m_callbackUserData
;
1082 delete m_dynamicEvents
;
1085 if (m_pendingEvents
)
1086 m_pendingEvents
->DeleteContents(true);
1087 delete m_pendingEvents
;
1090 # if !defined(__VISAGECPP__)
1091 delete m_eventsLocker
;
1094 // Remove us from wxPendingEvents if necessary.
1095 if(wxPendingEventsLocker
)
1096 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
1097 if ( wxPendingEvents
)
1099 // Delete all occurences of this from the list of pending events
1100 while (wxPendingEvents
->DeleteObject(this)) { } // Do nothing
1102 if(wxPendingEventsLocker
)
1103 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
1106 // we only delete object data, not untyped
1107 if ( m_clientDataType
== wxClientData_Object
)
1108 delete m_clientObject
;
1113 bool wxEvtHandler::ProcessThreadEvent(const wxEvent
& event
)
1115 // check that we are really in a child thread
1116 wxASSERT_MSG( !wxThread::IsMain(),
1117 wxT("use ProcessEvent() in main thread") );
1119 AddPendingEvent(event
);
1124 void wxEvtHandler::ClearEventLocker()
1126 #if !defined(__VISAGECPP__)
1127 delete m_eventsLocker
;
1128 m_eventsLocker
= NULL
;
1132 #endif // wxUSE_THREADS
1134 void wxEvtHandler::AddPendingEvent(const wxEvent
& event
)
1136 // 1) Add event to list of pending events of this event handler
1138 wxEvent
*eventCopy
= event
.Clone();
1140 // we must be able to copy the events here so the event class must
1141 // implement Clone() properly instead of just providing a NULL stab for it
1142 wxCHECK_RET( eventCopy
,
1143 _T("events of this type aren't supposed to be posted") );
1145 wxENTER_CRIT_SECT( Lock() );
1147 if ( !m_pendingEvents
)
1148 m_pendingEvents
= new wxList
;
1150 m_pendingEvents
->Append(eventCopy
);
1152 wxLEAVE_CRIT_SECT( Lock() );
1154 // 2) Add this event handler to list of event handlers that
1155 // have pending events.
1157 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
1159 if ( !wxPendingEvents
)
1160 wxPendingEvents
= new wxList
;
1161 wxPendingEvents
->Append(this);
1163 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
1165 // 3) Inform the system that new pending events are somewhere,
1166 // and that these should be processed in idle time.
1170 void wxEvtHandler::ProcessPendingEvents()
1172 // this method is only called by wxApp if this handler does have
1174 wxCHECK_RET( m_pendingEvents
,
1175 wxT("Please call wxApp::ProcessPendingEvents() instead") );
1177 wxENTER_CRIT_SECT( Lock() );
1179 // we leave the loop once we have processed all events that were present at
1180 // the start of ProcessPendingEvents because otherwise we could get into
1181 // infinite loop if the pending event handler execution resulted in another
1182 // event being posted
1183 size_t n
= m_pendingEvents
->size();
1184 for ( wxList::compatibility_iterator node
= m_pendingEvents
->GetFirst();
1186 node
= m_pendingEvents
->GetFirst() )
1188 wxEvent
*event
= (wxEvent
*)node
->GetData();
1190 // It's importan we remove event from list before processing it.
1191 // Else a nested event loop, for example from a modal dialog, might
1192 // process the same event again.
1194 m_pendingEvents
->Erase(node
);
1196 wxLEAVE_CRIT_SECT( Lock() );
1198 ProcessEvent(*event
);
1202 wxENTER_CRIT_SECT( Lock() );
1208 wxLEAVE_CRIT_SECT( Lock() );
1215 wxEvtHandler::ProcessEventIfMatches(const wxEventTableEntryBase
& entry
,
1216 wxEvtHandler
*handler
,
1219 int tableId1
= entry
.m_id
,
1220 tableId2
= entry
.m_lastId
;
1222 // match only if the event type is the same and the id is either -1 in
1223 // the event table (meaning "any") or the event id matches the id
1224 // specified in the event table either exactly or by falling into
1225 // range between first and last
1226 if ((tableId1
== wxID_ANY
) ||
1227 (tableId2
== wxID_ANY
&& tableId1
== event
.GetId()) ||
1228 (tableId2
!= wxID_ANY
&&
1229 (event
.GetId() >= tableId1
&& event
.GetId() <= tableId2
)))
1232 event
.m_callbackUserData
= entry
.m_callbackUserData
;
1234 #if wxUSE_EXCEPTIONS
1237 // call the handler via wxApp method which allows the user to catch
1238 // any exceptions which may be thrown by any handler in the program
1240 wxTheApp
->HandleEvent(handler
, (wxEventFunction
)entry
.m_fn
, event
);
1243 #endif // wxUSE_EXCEPTIONS
1245 // no need for an extra virtual function call
1246 (handler
->*((wxEventFunction
) (entry
.m_fn
)))(event
);
1249 if (!event
.GetSkipped())
1256 bool wxEvtHandler::TryParent(wxEvent
& event
)
1258 if ( wxTheApp
&& (this != wxTheApp
) )
1260 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1261 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1262 // processed appropriately via SearchEventTable.
1263 if ( event
.GetEventType() != wxEVT_IDLE
)
1265 if ( wxTheApp
->ProcessEvent(event
) )
1273 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
1275 // allow the application to hook into event processing
1278 int rc
= wxTheApp
->FilterEvent(event
);
1281 wxASSERT_MSG( rc
== 1 || rc
== 0,
1282 _T("unexpected wxApp::FilterEvent return value") );
1286 //else: proceed normally
1289 // An event handler can be enabled or disabled
1290 if ( GetEvtHandlerEnabled() )
1292 // if we have a validator, it has higher priority than our own event
1294 if ( TryValidator(event
) )
1297 // Handle per-instance dynamic event tables first
1298 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
1301 // Then static per-class event tables
1302 if ( GetEventHashTable().HandleEvent(event
, this) )
1306 // Try going down the event handler chain
1307 if ( GetNextHandler() )
1309 // notice that we shouldn't let the parent have the event even if the
1310 // next handler does not process it because it will have already passed
1311 // it to the parent in this case
1312 return GetNextHandler()->ProcessEvent(event
);
1315 // Finally propagate the event upwards the window chain and/or to the
1316 // application object as necessary
1317 return TryParent(event
);
1320 bool wxEvtHandler::SafelyProcessEvent(wxEvent
& event
)
1322 #if wxUSE_EXCEPTIONS
1326 return ProcessEvent(event
);
1327 #if wxUSE_EXCEPTIONS
1331 wxEventLoopBase
*loop
= wxEventLoopBase::GetActive();
1334 if ( !wxTheApp
|| !wxTheApp
->OnExceptionInMainLoop() )
1339 //else: continue running current event loop
1345 // OnExceptionInMainLoop() threw, possibly rethrowing the same
1346 // exception again: very good, but we still need Exit() to
1353 #endif // wxUSE_EXCEPTIONS
1357 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
1359 const wxEventType eventType
= event
.GetEventType();
1360 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
1362 const wxEventTableEntry
& entry
= table
.entries
[i
];
1363 if ( eventType
== entry
.m_eventType
)
1365 if ( ProcessEventIfMatches(entry
, this, event
) )
1373 void wxEvtHandler::Connect( int id
, int lastId
,
1375 wxObjectEventFunction func
,
1377 wxEvtHandler
* eventSink
)
1379 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1380 wxEventTableEntry
*entry
= new wxEventTableEntry
;
1381 entry
->m_eventType
= eventType
;
1383 entry
->m_lastId
= lastId
;
1385 entry
->m_callbackUserData
= userData
;
1386 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1387 wxDynamicEventTableEntry
*entry
=
1388 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
, eventSink
);
1389 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1391 if (!m_dynamicEvents
)
1392 m_dynamicEvents
= new wxList
;
1394 // Insert at the front of the list so most recent additions are found first
1395 m_dynamicEvents
->Insert( (wxObject
*) entry
);
1398 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
1399 wxObjectEventFunction func
,
1401 wxEvtHandler
* eventSink
)
1403 if (!m_dynamicEvents
)
1406 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1409 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1410 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
1411 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1412 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1413 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1415 if ((entry
->m_id
== id
) &&
1416 ((entry
->m_lastId
== lastId
) || (lastId
== wxID_ANY
)) &&
1417 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1418 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
1419 ((entry
->m_eventSink
== eventSink
) || (eventSink
== (wxEvtHandler
*)NULL
)) &&
1420 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
1422 if (entry
->m_callbackUserData
)
1423 delete entry
->m_callbackUserData
;
1424 m_dynamicEvents
->Erase( node
);
1428 node
= node
->GetNext();
1433 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1435 wxCHECK_MSG( m_dynamicEvents
, false,
1436 wxT("caller should check that we have dynamic events") );
1438 wxList::compatibility_iterator node
= m_dynamicEvents
->GetFirst();
1441 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1442 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->GetData();
1443 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1444 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
1445 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1447 // get next node before (maybe) calling the event handler as it could
1448 // call Disconnect() invalidating the current node
1449 node
= node
->GetNext();
1451 if ((event
.GetEventType() == entry
->m_eventType
) && (entry
->m_fn
!= 0))
1453 wxEvtHandler
*handler
=
1454 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
1455 entry
->m_eventSink
? entry
->m_eventSink
1460 if ( ProcessEventIfMatches(*entry
, handler
, event
) )
1470 void wxEvtHandler::DoSetClientObject( wxClientData
*data
)
1472 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1473 wxT("can't have both object and void client data") );
1475 if ( m_clientObject
)
1476 delete m_clientObject
;
1478 m_clientObject
= data
;
1479 m_clientDataType
= wxClientData_Object
;
1482 wxClientData
*wxEvtHandler::DoGetClientObject() const
1484 // it's not an error to call GetClientObject() on a window which doesn't
1485 // have client data at all - NULL will be returned
1486 wxASSERT_MSG( m_clientDataType
!= wxClientData_Void
,
1487 wxT("this window doesn't have object client data") );
1489 return m_clientObject
;
1492 void wxEvtHandler::DoSetClientData( void *data
)
1494 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1495 wxT("can't have both object and void client data") );
1497 m_clientData
= data
;
1498 m_clientDataType
= wxClientData_Void
;
1501 void *wxEvtHandler::DoGetClientData() const
1503 // it's not an error to call GetClientData() on a window which doesn't have
1504 // client data at all - NULL will be returned
1505 wxASSERT_MSG( m_clientDataType
!= wxClientData_Object
,
1506 wxT("this window doesn't have void client data") );
1508 return m_clientData
;
1511 #endif // wxUSE_BASE
1515 // Find a window with the focus, that is also a descendant of the given window.
1516 // This is used to determine the window to initially send commands to.
1517 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1519 // Process events starting with the window with the focus, if any.
1520 wxWindow
* focusWin
= wxWindow::FindFocus();
1521 wxWindow
* win
= focusWin
;
1523 // Check if this is a descendant of this frame.
1524 // If not, win will be set to NULL.
1527 if (win
== ancestor
)
1530 win
= win
->GetParent();
1532 if (win
== (wxWindow
*) NULL
)
1533 focusWin
= (wxWindow
*) NULL
;
1538 // ----------------------------------------------------------------------------
1540 // ----------------------------------------------------------------------------
1542 wxEventBlocker::wxEventBlocker(wxWindow
*win
, wxEventType type
)
1544 wxCHECK_RET(win
, wxT("Null window given to wxEventBlocker"));
1549 m_window
->PushEventHandler(this);
1552 wxEventBlocker::~wxEventBlocker()
1554 wxEvtHandler
*popped
= m_window
->PopEventHandler(false);
1555 wxCHECK_RET(popped
== this,
1556 wxT("Don't push other event handlers into a window managed by wxEventBlocker!"));
1559 bool wxEventBlocker::ProcessEvent(wxEvent
& event
)
1561 // should this event be blocked?
1562 for ( size_t i
= 0; i
< m_eventsToBlock
.size(); i
++ )
1564 wxEventType t
= (wxEventType
)m_eventsToBlock
[i
];
1565 if ( t
== wxEVT_ANY
|| t
== event
.GetEventType() )
1566 return true; // yes, it should: mark this event as processed