1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Event classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "event.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
37 #include "wx/control.h"
46 #include "wx/validate.h"
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler
, wxObject
)
54 IMPLEMENT_ABSTRACT_CLASS(wxEvent
, wxObject
)
55 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(wxEraseEvent
, wxEvent
)
67 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent
, wxEvent
)
68 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent
, wxEvent
)
69 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent
, wxEvent
)
70 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent
, wxEvent
)
71 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent
, wxEvent
)
72 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent
, wxEvent
)
73 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent
, wxEvent
)
74 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent
, wxEvent
)
75 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent
, wxEvent
)
76 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent
, wxEvent
)
77 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent
, wxEvent
)
78 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent
, wxEvent
)
79 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent
, wxCommandEvent
)
80 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent
, wxCommandEvent
)
81 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent
, wxEvent
)
82 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent
, wxEvent
)
83 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent
, wxEvent
)
84 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent
, wxEvent
)
85 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent
, wxCommandEvent
)
88 const wxEventTable
*wxEvtHandler::GetEventTable() const
89 { return &wxEvtHandler::sm_eventTable
; }
91 const wxEventTable
wxEvtHandler::sm_eventTable
=
92 { (const wxEventTable
*)NULL
, &wxEvtHandler::sm_eventTableEntries
[0] };
94 const wxEventTableEntry
wxEvtHandler::sm_eventTableEntries
[] =
95 { DECLARE_EVENT_TABLE_ENTRY(0, 0, 0, (wxObjectEventFunction
)NULL
, NULL
) };
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 // To put pending event handlers
102 wxList
*wxPendingEvents
= (wxList
*)NULL
;
105 // protects wxPendingEvents list
106 wxCriticalSection
*wxPendingEventsLocker
= (wxCriticalSection
*)NULL
;
109 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
111 wxEventType wxEVT_COMMAND_BUTTON_CLICKED
= wxNewEventType();
112 wxEventType wxEVT_COMMAND_CHECKBOX_CLICKED
= wxNewEventType();
113 wxEventType wxEVT_COMMAND_CHOICE_SELECTED
= wxNewEventType();
114 wxEventType wxEVT_COMMAND_LISTBOX_SELECTED
= wxNewEventType();
115 wxEventType wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
= wxNewEventType();
116 wxEventType wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
= wxNewEventType();
117 wxEventType wxEVT_COMMAND_TEXT_UPDATED
= wxNewEventType();
118 wxEventType wxEVT_COMMAND_TEXT_ENTER
= wxNewEventType();
119 wxEventType wxEVT_COMMAND_MENU_SELECTED
= wxNewEventType();
120 wxEventType wxEVT_COMMAND_SLIDER_UPDATED
= wxNewEventType();
121 wxEventType wxEVT_COMMAND_RADIOBOX_SELECTED
= wxNewEventType();
122 wxEventType wxEVT_COMMAND_RADIOBUTTON_SELECTED
= wxNewEventType();
123 wxEventType wxEVT_COMMAND_SCROLLBAR_UPDATED
= wxNewEventType();
124 wxEventType wxEVT_COMMAND_VLBOX_SELECTED
= wxNewEventType();
125 wxEventType wxEVT_COMMAND_COMBOBOX_SELECTED
= wxNewEventType();
126 wxEventType wxEVT_COMMAND_TOOL_RCLICKED
= wxNewEventType();
127 wxEventType wxEVT_COMMAND_TOOL_ENTER
= wxNewEventType();
128 wxEventType wxEVT_COMMAND_SPINCTRL_UPDATED
= wxNewEventType();
130 // Sockets and timers send events, too
131 wxEventType wxEVT_SOCKET
= wxNewEventType();
132 wxEventType wxEVT_TIMER
= wxNewEventType();
135 wxEventType wxEVT_LEFT_DOWN
= wxNewEventType();
136 wxEventType wxEVT_LEFT_UP
= wxNewEventType();
137 wxEventType wxEVT_MIDDLE_DOWN
= wxNewEventType();
138 wxEventType wxEVT_MIDDLE_UP
= wxNewEventType();
139 wxEventType wxEVT_RIGHT_DOWN
= wxNewEventType();
140 wxEventType wxEVT_RIGHT_UP
= wxNewEventType();
141 wxEventType wxEVT_MOTION
= wxNewEventType();
142 wxEventType wxEVT_ENTER_WINDOW
= wxNewEventType();
143 wxEventType wxEVT_LEAVE_WINDOW
= wxNewEventType();
144 wxEventType wxEVT_LEFT_DCLICK
= wxNewEventType();
145 wxEventType wxEVT_MIDDLE_DCLICK
= wxNewEventType();
146 wxEventType wxEVT_RIGHT_DCLICK
= wxNewEventType();
147 wxEventType wxEVT_SET_FOCUS
= wxNewEventType();
148 wxEventType wxEVT_KILL_FOCUS
= wxNewEventType();
150 // Non-client mouse events
151 wxEventType wxEVT_NC_LEFT_DOWN
= wxNewEventType();
152 wxEventType wxEVT_NC_LEFT_UP
= wxNewEventType();
153 wxEventType wxEVT_NC_MIDDLE_DOWN
= wxNewEventType();
154 wxEventType wxEVT_NC_MIDDLE_UP
= wxNewEventType();
155 wxEventType wxEVT_NC_RIGHT_DOWN
= wxNewEventType();
156 wxEventType wxEVT_NC_RIGHT_UP
= wxNewEventType();
157 wxEventType wxEVT_NC_MOTION
= wxNewEventType();
158 wxEventType wxEVT_NC_ENTER_WINDOW
= wxNewEventType();
159 wxEventType wxEVT_NC_LEAVE_WINDOW
= wxNewEventType();
160 wxEventType wxEVT_NC_LEFT_DCLICK
= wxNewEventType();
161 wxEventType wxEVT_NC_MIDDLE_DCLICK
= wxNewEventType();
162 wxEventType wxEVT_NC_RIGHT_DCLICK
= wxNewEventType();
164 // Character input event type
165 wxEventType wxEVT_CHAR
= wxNewEventType();
166 wxEventType wxEVT_CHAR_HOOK
= wxNewEventType();
167 wxEventType wxEVT_NAVIGATION_KEY
= wxNewEventType();
168 wxEventType wxEVT_KEY_DOWN
= wxNewEventType();
169 wxEventType wxEVT_KEY_UP
= wxNewEventType();
172 wxEventType wxEVT_SET_CURSOR
= wxNewEventType();
174 // wxScrollbar and wxSlider event identifiers
175 wxEventType wxEVT_SCROLL_TOP
= wxNewEventType();
176 wxEventType wxEVT_SCROLL_BOTTOM
= wxNewEventType();
177 wxEventType wxEVT_SCROLL_LINEUP
= wxNewEventType();
178 wxEventType wxEVT_SCROLL_LINEDOWN
= wxNewEventType();
179 wxEventType wxEVT_SCROLL_PAGEUP
= wxNewEventType();
180 wxEventType wxEVT_SCROLL_PAGEDOWN
= wxNewEventType();
181 wxEventType wxEVT_SCROLL_THUMBTRACK
= wxNewEventType();
182 wxEventType wxEVT_SCROLL_THUMBRELEASE
= wxNewEventType();
184 // Scroll events from wxWindow
185 wxEventType wxEVT_SCROLLWIN_TOP
= wxNewEventType();
186 wxEventType wxEVT_SCROLLWIN_BOTTOM
= wxNewEventType();
187 wxEventType wxEVT_SCROLLWIN_LINEUP
= wxNewEventType();
188 wxEventType wxEVT_SCROLLWIN_LINEDOWN
= wxNewEventType();
189 wxEventType wxEVT_SCROLLWIN_PAGEUP
= wxNewEventType();
190 wxEventType wxEVT_SCROLLWIN_PAGEDOWN
= wxNewEventType();
191 wxEventType wxEVT_SCROLLWIN_THUMBTRACK
= wxNewEventType();
192 wxEventType wxEVT_SCROLLWIN_THUMBRELEASE
= wxNewEventType();
195 wxEventType wxEVT_SIZE
= wxNewEventType();
196 wxEventType wxEVT_MOVE
= wxNewEventType();
197 wxEventType wxEVT_CLOSE_WINDOW
= wxNewEventType();
198 wxEventType wxEVT_END_SESSION
= wxNewEventType();
199 wxEventType wxEVT_QUERY_END_SESSION
= wxNewEventType();
200 wxEventType wxEVT_ACTIVATE_APP
= wxNewEventType();
201 wxEventType wxEVT_POWER
= wxNewEventType();
202 wxEventType wxEVT_ACTIVATE
= wxNewEventType();
203 wxEventType wxEVT_CREATE
= wxNewEventType();
204 wxEventType wxEVT_DESTROY
= wxNewEventType();
205 wxEventType wxEVT_SHOW
= wxNewEventType();
206 wxEventType wxEVT_ICONIZE
= wxNewEventType();
207 wxEventType wxEVT_MAXIMIZE
= wxNewEventType();
208 wxEventType wxEVT_MOUSE_CAPTURE_CHANGED
= wxNewEventType();
209 wxEventType wxEVT_PAINT
= wxNewEventType();
210 wxEventType wxEVT_ERASE_BACKGROUND
= wxNewEventType();
211 wxEventType wxEVT_NC_PAINT
= wxNewEventType();
212 wxEventType wxEVT_PAINT_ICON
= wxNewEventType();
213 wxEventType wxEVT_MENU_CHAR
= wxNewEventType();
214 wxEventType wxEVT_MENU_INIT
= wxNewEventType();
215 wxEventType wxEVT_MENU_HIGHLIGHT
= wxNewEventType();
216 wxEventType wxEVT_POPUP_MENU_INIT
= wxNewEventType();
217 wxEventType wxEVT_CONTEXT_MENU
= wxNewEventType();
218 wxEventType wxEVT_SYS_COLOUR_CHANGED
= wxNewEventType();
219 wxEventType wxEVT_SETTING_CHANGED
= wxNewEventType();
220 wxEventType wxEVT_QUERY_NEW_PALETTE
= wxNewEventType();
221 wxEventType wxEVT_PALETTE_CHANGED
= wxNewEventType();
222 wxEventType wxEVT_JOY_BUTTON_DOWN
= wxNewEventType();
223 wxEventType wxEVT_JOY_BUTTON_UP
= wxNewEventType();
224 wxEventType wxEVT_JOY_MOVE
= wxNewEventType();
225 wxEventType wxEVT_JOY_ZMOVE
= wxNewEventType();
226 wxEventType wxEVT_DROP_FILES
= wxNewEventType();
227 wxEventType wxEVT_DRAW_ITEM
= wxNewEventType();
228 wxEventType wxEVT_MEASURE_ITEM
= wxNewEventType();
229 wxEventType wxEVT_COMPARE_ITEM
= wxNewEventType();
230 wxEventType wxEVT_INIT_DIALOG
= wxNewEventType();
231 wxEventType wxEVT_IDLE
= wxNewEventType();
232 wxEventType wxEVT_UPDATE_UI
= wxNewEventType();
235 wxEventType wxEVT_END_PROCESS
= wxNewEventType();
238 wxEventType wxEVT_DIALUP_CONNECTED
= wxNewEventType();
239 wxEventType wxEVT_DIALUP_DISCONNECTED
= wxNewEventType();
241 // Generic command events
242 // Note: a click is a higher-level event than button down/up
243 wxEventType wxEVT_COMMAND_LEFT_CLICK
= wxNewEventType();
244 wxEventType wxEVT_COMMAND_LEFT_DCLICK
= wxNewEventType();
245 wxEventType wxEVT_COMMAND_RIGHT_CLICK
= wxNewEventType();
246 wxEventType wxEVT_COMMAND_RIGHT_DCLICK
= wxNewEventType();
247 wxEventType wxEVT_COMMAND_SET_FOCUS
= wxNewEventType();
248 wxEventType wxEVT_COMMAND_KILL_FOCUS
= wxNewEventType();
249 wxEventType wxEVT_COMMAND_ENTER
= wxNewEventType();
251 // Tree control event types
252 wxEventType wxEVT_COMMAND_TREE_BEGIN_DRAG
= wxNewEventType();
253 wxEventType wxEVT_COMMAND_TREE_BEGIN_RDRAG
= wxNewEventType();
254 wxEventType wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
= wxNewEventType();
255 wxEventType wxEVT_COMMAND_TREE_END_LABEL_EDIT
= wxNewEventType();
256 wxEventType wxEVT_COMMAND_TREE_DELETE_ITEM
= wxNewEventType();
257 wxEventType wxEVT_COMMAND_TREE_GET_INFO
= wxNewEventType();
258 wxEventType wxEVT_COMMAND_TREE_SET_INFO
= wxNewEventType();
259 wxEventType wxEVT_COMMAND_TREE_ITEM_EXPANDED
= wxNewEventType();
260 wxEventType wxEVT_COMMAND_TREE_ITEM_EXPANDING
= wxNewEventType();
261 wxEventType wxEVT_COMMAND_TREE_ITEM_COLLAPSED
= wxNewEventType();
262 wxEventType wxEVT_COMMAND_TREE_ITEM_COLLAPSING
= wxNewEventType();
263 wxEventType wxEVT_COMMAND_TREE_SEL_CHANGED
= wxNewEventType();
264 wxEventType wxEVT_COMMAND_TREE_SEL_CHANGING
= wxNewEventType();
265 wxEventType wxEVT_COMMAND_TREE_KEY_DOWN
= wxNewEventType();
266 wxEventType wxEVT_COMMAND_TREE_ITEM_ACTIVATED
= wxNewEventType();
267 wxEventType wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
= wxNewEventType();
268 wxEventType wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK
= wxNewEventType();
269 wxEventType wxEVT_COMMAND_TREE_END_DRAG
= wxNewEventType();
271 // List control event types
272 wxEventType wxEVT_COMMAND_LIST_BEGIN_DRAG
= wxNewEventType();
273 wxEventType wxEVT_COMMAND_LIST_BEGIN_RDRAG
= wxNewEventType();
274 wxEventType wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
= wxNewEventType();
275 wxEventType wxEVT_COMMAND_LIST_END_LABEL_EDIT
= wxNewEventType();
276 wxEventType wxEVT_COMMAND_LIST_DELETE_ITEM
= wxNewEventType();
277 wxEventType wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
= wxNewEventType();
278 wxEventType wxEVT_COMMAND_LIST_GET_INFO
= wxNewEventType();
279 wxEventType wxEVT_COMMAND_LIST_SET_INFO
= wxNewEventType();
280 wxEventType wxEVT_COMMAND_LIST_ITEM_SELECTED
= wxNewEventType();
281 wxEventType wxEVT_COMMAND_LIST_ITEM_DESELECTED
= wxNewEventType();
282 wxEventType wxEVT_COMMAND_LIST_KEY_DOWN
= wxNewEventType();
283 wxEventType wxEVT_COMMAND_LIST_INSERT_ITEM
= wxNewEventType();
284 wxEventType wxEVT_COMMAND_LIST_COL_CLICK
= wxNewEventType();
285 wxEventType wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
= wxNewEventType();
286 wxEventType wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
= wxNewEventType();
287 wxEventType wxEVT_COMMAND_LIST_ITEM_ACTIVATED
= wxNewEventType();
289 // Tab and notebook control event types
290 wxEventType wxEVT_COMMAND_TAB_SEL_CHANGED
= wxNewEventType();
291 wxEventType wxEVT_COMMAND_TAB_SEL_CHANGING
= wxNewEventType();
292 wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
= wxNewEventType();
293 wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
= wxNewEventType();
296 wxEventType wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
= wxNewEventType();
297 wxEventType wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
= wxNewEventType();
298 wxEventType wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
= wxNewEventType();
299 wxEventType wxEVT_COMMAND_SPLITTER_UNSPLIT
= wxNewEventType();
302 wxEventType wxEVT_WIZARD_PAGE_CHANGED
= wxNewEventType();
303 wxEventType wxEVT_WIZARD_PAGE_CHANGING
= wxNewEventType();
304 wxEventType wxEVT_WIZARD_CANCEL
= wxNewEventType();
307 wxEventType wxEVT_CALENDAR_SEL_CHANGED
= wxNewEventType();
308 wxEventType wxEVT_CALENDAR_DAY_CHANGED
= wxNewEventType();
309 wxEventType wxEVT_CALENDAR_MONTH_CHANGED
= wxNewEventType();
310 wxEventType wxEVT_CALENDAR_YEAR_CHANGED
= wxNewEventType();
311 wxEventType wxEVT_CALENDAR_DOUBLECLICKED
= wxNewEventType();
312 wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED
= wxNewEventType();
315 wxEventType wxEVT_HELP
= wxNewEventType();
316 wxEventType wxEVT_DETAILED_HELP
= wxNewEventType();
318 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
320 // ============================================================================
322 // ============================================================================
324 // ----------------------------------------------------------------------------
325 // event initialization
326 // ----------------------------------------------------------------------------
331 static int s_lastUsedEventType
= wxEVT_FIRST
;
333 #if WXWIN_COMPATIBILITY_2
334 // check that we don't overlap with the user-defined types: if it does
335 // happen, the best solution is probably to update the existing code to
336 // use wxNewEventType() instead of wxEVT_USER_FIRST
338 // due to the uncertainty
339 wxASSERT_MSG( s_lastUsedEventType
< wxEVT_USER_FIRST
- 1,
340 _T("possible event type conflict") );
341 #endif // WXWIN_COMPATIBILITY_2
343 return s_lastUsedEventType
++;
346 // ----------------------------------------------------------------------------
348 // ----------------------------------------------------------------------------
351 * General wxWindows events, covering
352 * all interesting things that might happen (button clicking, resizing,
353 * setting text in widgets, etc.).
355 * For each completely new event type, derive a new event class.
359 wxEvent::wxEvent(int theId
)
361 m_eventType
= wxEVT_NULL
;
362 m_eventObject
= (wxObject
*) NULL
;
366 m_callbackUserData
= (wxObject
*) NULL
;
367 m_isCommandEvent
= FALSE
;
370 void wxEvent::CopyObject(wxObject
& object_dest
) const
372 wxEvent
*obj
= (wxEvent
*)&object_dest
;
373 wxObject::CopyObject(object_dest
);
375 obj
->m_eventType
= m_eventType
;
376 obj
->m_eventObject
= m_eventObject
;
377 obj
->m_timeStamp
= m_timeStamp
;
379 obj
->m_skipped
= m_skipped
;
380 obj
->m_callbackUserData
= m_callbackUserData
;
381 obj
->m_isCommandEvent
= m_isCommandEvent
;
391 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
393 m_eventType
= commandType
;
394 m_clientData
= (char *) NULL
;
395 m_clientObject
= (wxClientData
*) NULL
;
399 m_commandString
= wxEmptyString
;
400 m_isCommandEvent
= TRUE
;
403 void wxCommandEvent::CopyObject(wxObject
& obj_d
) const
405 wxCommandEvent
*obj
= (wxCommandEvent
*)&obj_d
;
407 wxEvent::CopyObject(obj_d
);
409 obj
->m_clientData
= m_clientData
;
410 obj
->m_clientObject
= m_clientObject
;
411 obj
->m_extraLong
= m_extraLong
;
412 obj
->m_commandInt
= m_commandInt
;
413 obj
->m_commandString
= m_commandString
;
420 void wxNotifyEvent::CopyObject(wxObject
& obj_d
) const
422 wxNotifyEvent
*obj
= (wxNotifyEvent
*)&obj_d
;
424 wxEvent::CopyObject(obj_d
);
426 if (!m_bAllow
) obj
->Veto();
433 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
437 : wxCommandEvent(commandType
, id
)
439 m_extraLong
= orient
;
447 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
451 m_eventType
= commandType
;
452 m_extraLong
= orient
;
456 void wxScrollWinEvent::CopyObject(wxObject
& obj_d
) const
458 wxScrollWinEvent
*obj
= (wxScrollWinEvent
*)&obj_d
;
460 wxEvent::CopyObject(obj_d
);
462 obj
->m_extraLong
= m_extraLong
;
463 obj
->m_commandInt
= m_commandInt
;
471 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
473 m_eventType
= commandType
;
476 m_controlDown
= FALSE
;
480 m_middleDown
= FALSE
;
485 void wxMouseEvent::CopyObject(wxObject
& obj_d
) const
487 wxMouseEvent
*obj
= (wxMouseEvent
*)&obj_d
;
489 wxEvent::CopyObject(obj_d
);
491 obj
->m_metaDown
= m_metaDown
;
492 obj
->m_altDown
= m_altDown
;
493 obj
->m_controlDown
= m_controlDown
;
494 obj
->m_shiftDown
= m_shiftDown
;
495 obj
->m_leftDown
= m_leftDown
;
496 obj
->m_rightDown
= m_rightDown
;
497 obj
->m_middleDown
= m_middleDown
;
502 // True if was a button dclick event (1 = left, 2 = middle, 3 = right)
503 // or any button dclick event (but = -1)
504 bool wxMouseEvent::ButtonDClick(int but
) const
509 return (LeftDClick() || MiddleDClick() || RightDClick());
513 return MiddleDClick();
515 return RightDClick();
517 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
523 // True if was a button down event (1 = left, 2 = middle, 3 = right)
524 // or any button down event (but = -1)
525 bool wxMouseEvent::ButtonDown(int but
) const
530 return (LeftDown() || MiddleDown() || RightDown());
538 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
544 // True if was a button up event (1 = left, 2 = middle, 3 = right)
545 // or any button up event (but = -1)
546 bool wxMouseEvent::ButtonUp(int but
) const
550 return (LeftUp() || MiddleUp() || RightUp());
558 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
564 // True if the given button is currently changing state
565 bool wxMouseEvent::Button(int but
) const
569 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
571 return (LeftDown() || LeftUp() || LeftDClick());
573 return (MiddleDown() || MiddleUp() || MiddleDClick());
575 return (RightDown() || RightUp() || RightDClick());
577 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
583 bool wxMouseEvent::ButtonIsDown(int but
) const
587 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
591 return MiddleIsDown();
593 return RightIsDown();
595 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
601 // Find the logical position of the event given the DC
602 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
604 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
614 wxKeyEvent::wxKeyEvent(wxEventType type
)
618 m_controlDown
= FALSE
;
625 void wxKeyEvent::CopyObject(wxObject
& obj_d
) const
627 wxKeyEvent
*obj
= (wxKeyEvent
*)&obj_d
;
628 wxEvent::CopyObject(obj_d
);
632 obj
->m_keyCode
= m_keyCode
;
634 obj
->m_shiftDown
= m_shiftDown
;
635 obj
->m_controlDown
= m_controlDown
;
636 obj
->m_metaDown
= m_metaDown
;
637 obj
->m_altDown
= m_altDown
;
638 obj
->m_keyCode
= m_keyCode
;
646 void wxSizeEvent::CopyObject(wxObject
& obj_d
) const
648 wxSizeEvent
*obj
= (wxSizeEvent
*)&obj_d
;
649 wxEvent::CopyObject(obj_d
);
651 obj
->m_size
= m_size
;
654 void wxMoveEvent::CopyObject(wxObject
& obj_d
) const
656 wxMoveEvent
*obj
= (wxMoveEvent
*)&obj_d
;
657 wxEvent::CopyObject(obj_d
);
662 void wxEraseEvent::CopyObject(wxObject
& obj_d
) const
664 wxEraseEvent
*obj
= (wxEraseEvent
*)&obj_d
;
665 wxEvent::CopyObject(obj_d
);
670 void wxActivateEvent::CopyObject(wxObject
& obj_d
) const
672 wxActivateEvent
*obj
= (wxActivateEvent
*)&obj_d
;
673 wxEvent::CopyObject(obj_d
);
675 obj
->m_active
= m_active
;
678 void wxMenuEvent::CopyObject(wxObject
& obj_d
) const
680 wxMenuEvent
*obj
= (wxMenuEvent
*)&obj_d
;
681 wxEvent::CopyObject(obj_d
);
683 obj
->m_menuId
= m_menuId
;
686 void wxCloseEvent::CopyObject(wxObject
& obj_d
) const
688 wxCloseEvent
*obj
= (wxCloseEvent
*)&obj_d
;
689 wxEvent::CopyObject(obj_d
);
691 obj
->m_loggingOff
= m_loggingOff
;
692 obj
->m_veto
= m_veto
;
693 #if WXWIN_COMPATIBILITY
694 obj
->m_force
= m_force
;
696 obj
->m_canVeto
= m_canVeto
;
699 void wxShowEvent::CopyObject(wxObject
& obj_d
) const
701 wxShowEvent
*obj
= (wxShowEvent
*)&obj_d
;
702 wxEvent::CopyObject(obj_d
);
704 obj
->m_show
= m_show
;
707 void wxJoystickEvent::CopyObject(wxObject
& obj_d
) const
709 wxJoystickEvent
*obj
= (wxJoystickEvent
*)&obj_d
;
710 wxEvent::CopyObject(obj_d
);
713 obj
->m_zPosition
= m_zPosition
;
714 obj
->m_buttonChange
= m_buttonChange
;
715 obj
->m_buttonState
= m_buttonState
;
716 obj
->m_joyStick
= m_joyStick
;
719 void wxDropFilesEvent::CopyObject(wxObject
& obj_d
) const
721 wxDropFilesEvent
*obj
= (wxDropFilesEvent
*)&obj_d
;
722 wxEvent::CopyObject(obj_d
);
724 obj
->m_noFiles
= m_noFiles
;
726 // TODO: Problem with obj->m_files. It should be deallocated by the
727 // destructor of the event.
730 void wxUpdateUIEvent::CopyObject(wxObject
&obj_d
) const
732 wxUpdateUIEvent
*obj
= (wxUpdateUIEvent
*)&obj_d
;
733 wxEvent::CopyObject(obj_d
);
735 obj
->m_checked
= m_checked
;
736 obj
->m_enabled
= m_enabled
;
737 obj
->m_text
= m_text
;
738 obj
->m_setText
= m_setText
;
739 obj
->m_setChecked
= m_setChecked
;
740 obj
->m_setEnabled
= m_setEnabled
;
743 void wxPaletteChangedEvent::CopyObject(wxObject
&obj_d
) const
745 wxPaletteChangedEvent
*obj
= (wxPaletteChangedEvent
*)&obj_d
;
746 wxEvent::CopyObject(obj_d
);
748 obj
->m_changedWindow
= m_changedWindow
;
751 void wxQueryNewPaletteEvent::CopyObject(wxObject
& obj_d
) const
753 wxQueryNewPaletteEvent
*obj
= (wxQueryNewPaletteEvent
*)&obj_d
;
754 wxEvent::CopyObject(obj_d
);
756 obj
->m_paletteRealized
= m_paletteRealized
;
759 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
761 SetEventType(wxEVT_CREATE
);
765 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
767 SetEventType(wxEVT_DESTROY
);
773 void wxIdleEvent::CopyObject(wxObject
& obj_d
) const
775 wxIdleEvent
*obj
= (wxIdleEvent
*)&obj_d
;
776 wxEvent::CopyObject(obj_d
);
778 obj
->m_requestMore
= m_requestMore
;
785 wxEvtHandler::wxEvtHandler()
787 m_nextHandler
= (wxEvtHandler
*) NULL
;
788 m_previousHandler
= (wxEvtHandler
*) NULL
;
790 m_dynamicEvents
= (wxList
*) NULL
;
792 m_pendingEvents
= (wxList
*) NULL
;
794 # if !defined(__VISAGECPP__)
795 m_eventsLocker
= new wxCriticalSection
;
800 wxEvtHandler::~wxEvtHandler()
802 // Takes itself out of the list of handlers
803 if (m_previousHandler
)
804 m_previousHandler
->m_nextHandler
= m_nextHandler
;
807 m_nextHandler
->m_previousHandler
= m_previousHandler
;
811 wxNode
*node
= m_dynamicEvents
->First();
814 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
815 if (entry
->m_callbackUserData
) delete entry
->m_callbackUserData
;
819 delete m_dynamicEvents
;
822 delete m_pendingEvents
;
825 # if !defined(__VISAGECPP__)
826 delete m_eventsLocker
;
833 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
835 // check that we are really in a child thread
836 wxASSERT_MSG( !wxThread::IsMain(),
837 wxT("use ProcessEvent() in main thread") );
839 AddPendingEvent(event
);
844 #endif // wxUSE_THREADS
846 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
848 // 1) Add event to list of pending events of this event handler
850 #if defined(__VISAGECPP__)
851 wxENTER_CRIT_SECT( m_eventsLocker
);
853 wxENTER_CRIT_SECT( *m_eventsLocker
);
856 if ( !m_pendingEvents
)
857 m_pendingEvents
= new wxList
;
859 wxEvent
*event2
= (wxEvent
*)event
.Clone();
861 m_pendingEvents
->Append(event2
);
863 #if defined(__VISAGECPP__)
864 wxLEAVE_CRIT_SECT( m_eventsLocker
);
866 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
869 // 2) Add this event handler to list of event handlers that
870 // have pending events.
872 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
874 if ( !wxPendingEvents
)
875 wxPendingEvents
= new wxList
;
876 wxPendingEvents
->Append(this);
878 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
880 // 3) Inform the system that new pending events are somwehere,
881 // and that these should be processed in idle time.
885 void wxEvtHandler::ProcessPendingEvents()
887 #if defined(__VISAGECPP__)
888 wxENTER_CRIT_SECT( m_eventsLocker
);
890 wxENTER_CRIT_SECT( *m_eventsLocker
);
893 wxNode
*node
= m_pendingEvents
->First();
896 wxEvent
*event
= (wxEvent
*)node
->Data();
899 // In ProcessEvent, new events might get added and
900 // we can safely leave the crtical section here.
901 #if defined(__VISAGECPP__)
902 wxLEAVE_CRIT_SECT( m_eventsLocker
);
904 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
906 ProcessEvent(*event
);
908 #if defined(__VISAGECPP__)
909 wxENTER_CRIT_SECT( m_eventsLocker
);
911 wxENTER_CRIT_SECT( *m_eventsLocker
);
914 node
= m_pendingEvents
->First();
917 #if defined(__VISAGECPP__)
918 wxLEAVE_CRIT_SECT( m_eventsLocker
);
920 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
928 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
931 // check that our flag corresponds to reality
932 wxASSERT( m_isWindow
== IsKindOf(CLASSINFO(wxWindow
)) );
935 // An event handler can be enabled or disabled
936 if ( GetEvtHandlerEnabled() )
941 What is this? When using GUI threads, a non main
942 threads can send an event and process it itself.
943 This breaks GTK's GUI threads, so please explain.
946 // Check whether we are in a child thread.
947 if ( !wxThread::IsMain() )
948 return ProcessThreadEvent(event
);
951 // Handle per-instance dynamic event tables first
952 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
955 // Then static per-class event tables
956 const wxEventTable
*table
= GetEventTable();
958 #if wxUSE_GUI && wxUSE_VALIDATORS
959 // Try the associated validator first, if this is a window.
960 // Problem: if the event handler of the window has been replaced,
961 // this wxEvtHandler may no longer be a window.
962 // Therefore validators won't be processed if the handler
963 // has been replaced with SetEventHandler.
964 // THIS CAN BE CURED if PushEventHandler is used instead of
965 // SetEventHandler, and then processing will be passed down the
966 // chain of event handlers.
969 wxWindow
*win
= (wxWindow
*)this;
971 // Can only use the validator of the window which
972 // is receiving the event
973 if ( win
== event
.GetEventObject() )
975 wxValidator
*validator
= win
->GetValidator();
976 if ( validator
&& validator
->ProcessEvent(event
) )
984 // Search upwards through the inheritance hierarchy
987 if ( SearchEventTable((wxEventTable
&)*table
, event
) )
989 table
= table
->baseTable
;
993 // Try going down the event handler chain
994 if ( GetNextHandler() )
996 if ( GetNextHandler()->ProcessEvent(event
) )
1001 // Carry on up the parent-child hierarchy,
1002 // but only if event is a command event: it wouldn't
1003 // make sense for a parent to receive a child's size event, for example
1004 if ( m_isWindow
&& event
.IsCommandEvent() )
1006 wxWindow
*win
= (wxWindow
*)this;
1007 wxWindow
*parent
= win
->GetParent();
1008 if (parent
&& !parent
->IsBeingDeleted())
1009 return parent
->GetEventHandler()->ProcessEvent(event
);
1013 // Last try - application object.
1014 if ( wxTheApp
&& (this != wxTheApp
) )
1016 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1017 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1018 // processed appropriately via SearchEventTable.
1019 if ( event
.GetEventType() != wxEVT_IDLE
)
1021 if ( wxTheApp
->ProcessEvent(event
) )
1029 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
1031 wxEventType eventType
= event
.GetEventType();
1032 int eventId
= event
.GetId();
1034 // BC++ doesn't like testing for m_fn without != 0
1035 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
1037 // the line using reference exposes a bug in gcc: although it _seems_
1038 // to work, it leads to weird crashes later on during program
1041 wxEventTableEntry entry
= table
.entries
[i
];
1043 const wxEventTableEntry
& entry
= table
.entries
[i
];
1046 // match only if the event type is the same and the id is either -1 in
1047 // the event table (meaning "any") or the event id matches the id
1048 // specified in the event table either exactly or by falling into
1049 // range between first and last
1050 if ( eventType
== entry
.m_eventType
)
1052 int tableId1
= entry
.m_id
,
1053 tableId2
= entry
.m_lastId
;
1055 if ( (tableId1
== -1) ||
1056 (tableId2
== -1 && eventId
== tableId1
) ||
1058 (eventId
>= tableId1
&& eventId
<= tableId2
)) )
1061 event
.m_callbackUserData
= entry
.m_callbackUserData
;
1063 (this->*((wxEventFunction
) (entry
.m_fn
)))(event
);
1065 return !event
.GetSkipped();
1073 void wxEvtHandler::Connect( int id
, int lastId
,
1075 wxObjectEventFunction func
,
1076 wxObject
*userData
)
1078 #if WXWIN_COMPATIBILITY_EVENT_TYPES
1079 wxDynamicEventTableEntry
*entry
= new wxDynamicEventTableEntry
;
1080 entry
->m_eventType
= eventType
;
1082 entry
->m_lastId
= lastId
;
1084 entry
->m_callbackUserData
= userData
;
1085 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
1086 wxDynamicEventTableEntry
*entry
=
1087 new wxDynamicEventTableEntry(eventType
, id
, lastId
, func
, userData
);
1088 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
1090 if (!m_dynamicEvents
)
1091 m_dynamicEvents
= new wxList
;
1093 m_dynamicEvents
->Append( (wxObject
*) entry
);
1096 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
1097 wxObjectEventFunction func
,
1098 wxObject
*userData
)
1100 if (!m_dynamicEvents
)
1103 wxNode
*node
= m_dynamicEvents
->First();
1106 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
1107 if ((entry
->m_id
== id
) &&
1108 ((entry
->m_lastId
== lastId
) || (lastId
== -1)) &&
1109 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1110 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
1111 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
1113 if (entry
->m_callbackUserData
) delete entry
->m_callbackUserData
;
1114 m_dynamicEvents
->DeleteNode( node
);
1118 node
= node
->Next();
1123 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1125 wxCHECK_MSG( m_dynamicEvents
, FALSE
,
1126 wxT("caller should check that we have dynamic events") );
1128 int commandId
= event
.GetId();
1130 wxNode
*node
= m_dynamicEvents
->First();
1133 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
1137 // Match, if event spec says any id will do (id == -1)
1138 if ( (event
.GetEventType() == entry
->m_eventType
) &&
1139 (entry
->m_id
== -1 ||
1140 (entry
->m_lastId
== -1 && commandId
== entry
->m_id
) ||
1141 (entry
->m_lastId
!= -1 &&
1142 (commandId
>= entry
->m_id
&& commandId
<= entry
->m_lastId
))) )
1145 event
.m_callbackUserData
= entry
->m_callbackUserData
;
1147 (this->*((wxEventFunction
) (entry
->m_fn
)))(event
);
1149 if (event
.GetSkipped())
1155 node
= node
->Next();
1160 #if WXWIN_COMPATIBILITY
1161 bool wxEvtHandler::OnClose()
1163 if (GetNextHandler())
1164 return GetNextHandler()->OnClose();
1168 #endif // WXWIN_COMPATIBILITY
1172 // Find a window with the focus, that is also a descendant of the given window.
1173 // This is used to determine the window to initially send commands to.
1174 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1176 // Process events starting with the window with the focus, if any.
1177 wxWindow
* focusWin
= wxWindow::FindFocus();
1178 wxWindow
* win
= focusWin
;
1180 // Check if this is a descendant of this frame.
1181 // If not, win will be set to NULL.
1184 if (win
== ancestor
)
1187 win
= win
->GetParent();
1189 if (win
== (wxWindow
*) NULL
)
1190 focusWin
= (wxWindow
*) NULL
;