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 // ----------------------------------------------------------------------------
55 static int wxCurrentEventType
= 10000;
57 return wxCurrentEventType
++;
60 const int wxEVT_NULL
= 0;
61 const int wxEVT_FIRST
= 10000;
63 const int wxEVT_COMMAND_BUTTON_CLICKED
= wxNewEventType();
64 const int wxEVT_COMMAND_CHECKBOX_CLICKED
= wxNewEventType();
65 const int wxEVT_COMMAND_CHOICE_SELECTED
= wxNewEventType();
66 const int wxEVT_COMMAND_LISTBOX_SELECTED
= wxNewEventType();
67 const int wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
= wxNewEventType();
68 const int wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
= wxNewEventType();
69 const int wxEVT_COMMAND_TEXT_UPDATED
= wxNewEventType();
70 const int wxEVT_COMMAND_TEXT_ENTER
= wxNewEventType();
71 const int wxEVT_COMMAND_MENU_SELECTED
= wxNewEventType();
72 const int wxEVT_COMMAND_TOOL_CLICKED
= wxNewEventType();
73 const int wxEVT_COMMAND_SLIDER_UPDATED
= wxNewEventType();
74 const int wxEVT_COMMAND_RADIOBOX_SELECTED
= wxNewEventType();
75 const int wxEVT_COMMAND_RADIOBUTTON_SELECTED
= wxNewEventType();
76 const int wxEVT_COMMAND_SCROLLBAR_UPDATED
= wxNewEventType();
77 const int wxEVT_COMMAND_VLBOX_SELECTED
= wxNewEventType();
78 const int wxEVT_COMMAND_COMBOBOX_SELECTED
= wxNewEventType();
79 const int wxEVT_COMMAND_TOOL_RCLICKED
= wxNewEventType();
80 const int wxEVT_COMMAND_TOOL_ENTER
= wxNewEventType();
81 const int wxEVT_COMMAND_SPINCTRL_UPDATED
= wxNewEventType();
83 // Sockets and timers send events, too
84 const int wxEVT_SOCKET
= wxNewEventType();
85 const int wxEVT_TIMER
= wxNewEventType();
88 const int wxEVT_LEFT_DOWN
= wxNewEventType();
89 const int wxEVT_LEFT_UP
= wxNewEventType();
90 const int wxEVT_MIDDLE_DOWN
= wxNewEventType();
91 const int wxEVT_MIDDLE_UP
= wxNewEventType();
92 const int wxEVT_RIGHT_DOWN
= wxNewEventType();
93 const int wxEVT_RIGHT_UP
= wxNewEventType();
94 const int wxEVT_MOTION
= wxNewEventType();
95 const int wxEVT_ENTER_WINDOW
= wxNewEventType();
96 const int wxEVT_LEAVE_WINDOW
= wxNewEventType();
97 const int wxEVT_LEFT_DCLICK
= wxNewEventType();
98 const int wxEVT_MIDDLE_DCLICK
= wxNewEventType();
99 const int wxEVT_RIGHT_DCLICK
= wxNewEventType();
100 const int wxEVT_SET_FOCUS
= wxNewEventType();
101 const int wxEVT_KILL_FOCUS
= wxNewEventType();
103 // Non-client mouse events
104 const int wxEVT_NC_LEFT_DOWN
= wxNewEventType();
105 const int wxEVT_NC_LEFT_UP
= wxNewEventType();
106 const int wxEVT_NC_MIDDLE_DOWN
= wxNewEventType();
107 const int wxEVT_NC_MIDDLE_UP
= wxNewEventType();
108 const int wxEVT_NC_RIGHT_DOWN
= wxNewEventType();
109 const int wxEVT_NC_RIGHT_UP
= wxNewEventType();
110 const int wxEVT_NC_MOTION
= wxNewEventType();
111 const int wxEVT_NC_ENTER_WINDOW
= wxNewEventType();
112 const int wxEVT_NC_LEAVE_WINDOW
= wxNewEventType();
113 const int wxEVT_NC_LEFT_DCLICK
= wxNewEventType();
114 const int wxEVT_NC_MIDDLE_DCLICK
= wxNewEventType();
115 const int wxEVT_NC_RIGHT_DCLICK
= wxNewEventType();
117 // Character input event type
118 const int wxEVT_CHAR
= wxNewEventType();
119 const int wxEVT_CHAR_HOOK
= wxNewEventType();
120 const int wxEVT_NAVIGATION_KEY
= wxNewEventType();
121 const int wxEVT_KEY_DOWN
= wxNewEventType();
122 const int wxEVT_KEY_UP
= wxNewEventType();
125 const int wxEVT_SET_CURSOR
= wxNewEventType();
127 // wxScrollbar and wxSlider event identifiers
128 const int wxEVT_SCROLL_TOP
= wxNewEventType();
129 const int wxEVT_SCROLL_BOTTOM
= wxNewEventType();
130 const int wxEVT_SCROLL_LINEUP
= wxNewEventType();
131 const int wxEVT_SCROLL_LINEDOWN
= wxNewEventType();
132 const int wxEVT_SCROLL_PAGEUP
= wxNewEventType();
133 const int wxEVT_SCROLL_PAGEDOWN
= wxNewEventType();
134 const int wxEVT_SCROLL_THUMBTRACK
= wxNewEventType();
135 const int wxEVT_SCROLL_THUMBRELEASE
= wxNewEventType();
137 // Scroll events from wxWindow
138 const int wxEVT_SCROLLWIN_TOP
= wxNewEventType();
139 const int wxEVT_SCROLLWIN_BOTTOM
= wxNewEventType();
140 const int wxEVT_SCROLLWIN_LINEUP
= wxNewEventType();
141 const int wxEVT_SCROLLWIN_LINEDOWN
= wxNewEventType();
142 const int wxEVT_SCROLLWIN_PAGEUP
= wxNewEventType();
143 const int wxEVT_SCROLLWIN_PAGEDOWN
= wxNewEventType();
144 const int wxEVT_SCROLLWIN_THUMBTRACK
= wxNewEventType();
145 const int wxEVT_SCROLLWIN_THUMBRELEASE
= wxNewEventType();
148 const int wxEVT_SIZE
= wxNewEventType();
149 const int wxEVT_MOVE
= wxNewEventType();
150 const int wxEVT_CLOSE_WINDOW
= wxNewEventType();
151 const int wxEVT_END_SESSION
= wxNewEventType();
152 const int wxEVT_QUERY_END_SESSION
= wxNewEventType();
153 const int wxEVT_ACTIVATE_APP
= wxNewEventType();
154 const int wxEVT_POWER
= wxNewEventType();
155 const int wxEVT_ACTIVATE
= wxNewEventType();
156 const int wxEVT_CREATE
= wxNewEventType();
157 const int wxEVT_DESTROY
= wxNewEventType();
158 const int wxEVT_SHOW
= wxNewEventType();
159 const int wxEVT_ICONIZE
= wxNewEventType();
160 const int wxEVT_MAXIMIZE
= wxNewEventType();
161 const int wxEVT_MOUSE_CAPTURE_CHANGED
= wxNewEventType();
162 const int wxEVT_PAINT
= wxNewEventType();
163 const int wxEVT_ERASE_BACKGROUND
= wxNewEventType();
164 const int wxEVT_NC_PAINT
= wxNewEventType();
165 const int wxEVT_PAINT_ICON
= wxNewEventType();
166 const int wxEVT_MENU_CHAR
= wxNewEventType();
167 const int wxEVT_MENU_INIT
= wxNewEventType();
168 const int wxEVT_MENU_HIGHLIGHT
= wxNewEventType();
169 const int wxEVT_POPUP_MENU_INIT
= wxNewEventType();
170 const int wxEVT_CONTEXT_MENU
= wxNewEventType();
171 const int wxEVT_SYS_COLOUR_CHANGED
= wxNewEventType();
172 const int wxEVT_SETTING_CHANGED
= wxNewEventType();
173 const int wxEVT_QUERY_NEW_PALETTE
= wxNewEventType();
174 const int wxEVT_PALETTE_CHANGED
= wxNewEventType();
175 const int wxEVT_JOY_BUTTON_DOWN
= wxNewEventType();
176 const int wxEVT_JOY_BUTTON_UP
= wxNewEventType();
177 const int wxEVT_JOY_MOVE
= wxNewEventType();
178 const int wxEVT_JOY_ZMOVE
= wxNewEventType();
179 const int wxEVT_DROP_FILES
= wxNewEventType();
180 const int wxEVT_DRAW_ITEM
= wxNewEventType();
181 const int wxEVT_MEASURE_ITEM
= wxNewEventType();
182 const int wxEVT_COMPARE_ITEM
= wxNewEventType();
183 const int wxEVT_INIT_DIALOG
= wxNewEventType();
184 const int wxEVT_IDLE
= wxNewEventType();
185 const int wxEVT_UPDATE_UI
= wxNewEventType();
188 const int wxEVT_END_PROCESS
= wxNewEventType();
191 const int wxEVT_DIALUP_CONNECTED
= wxNewEventType();
192 const int wxEVT_DIALUP_DISCONNECTED
= wxNewEventType();
194 // Generic command events
195 // Note: a click is a higher-level event than button down/up
196 const int wxEVT_COMMAND_LEFT_CLICK
= wxNewEventType();
197 const int wxEVT_COMMAND_LEFT_DCLICK
= wxNewEventType();
198 const int wxEVT_COMMAND_RIGHT_CLICK
= wxNewEventType();
199 const int wxEVT_COMMAND_RIGHT_DCLICK
= wxNewEventType();
200 const int wxEVT_COMMAND_SET_FOCUS
= wxNewEventType();
201 const int wxEVT_COMMAND_KILL_FOCUS
= wxNewEventType();
202 const int wxEVT_COMMAND_ENTER
= wxNewEventType();
204 // Tree control event types
205 const int wxEVT_COMMAND_TREE_BEGIN_DRAG
= wxNewEventType();
206 const int wxEVT_COMMAND_TREE_BEGIN_RDRAG
= wxNewEventType();
207 const int wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
= wxNewEventType();
208 const int wxEVT_COMMAND_TREE_END_LABEL_EDIT
= wxNewEventType();
209 const int wxEVT_COMMAND_TREE_DELETE_ITEM
= wxNewEventType();
210 const int wxEVT_COMMAND_TREE_GET_INFO
= wxNewEventType();
211 const int wxEVT_COMMAND_TREE_SET_INFO
= wxNewEventType();
212 const int wxEVT_COMMAND_TREE_ITEM_EXPANDED
= wxNewEventType();
213 const int wxEVT_COMMAND_TREE_ITEM_EXPANDING
= wxNewEventType();
214 const int wxEVT_COMMAND_TREE_ITEM_COLLAPSED
= wxNewEventType();
215 const int wxEVT_COMMAND_TREE_ITEM_COLLAPSING
= wxNewEventType();
216 const int wxEVT_COMMAND_TREE_SEL_CHANGED
= wxNewEventType();
217 const int wxEVT_COMMAND_TREE_SEL_CHANGING
= wxNewEventType();
218 const int wxEVT_COMMAND_TREE_KEY_DOWN
= wxNewEventType();
219 const int wxEVT_COMMAND_TREE_ITEM_ACTIVATED
= wxNewEventType();
220 const int wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
= wxNewEventType();
221 const int wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK
= wxNewEventType();
222 const int wxEVT_COMMAND_TREE_END_DRAG
= wxNewEventType();
224 // List control event types
225 const int wxEVT_COMMAND_LIST_BEGIN_DRAG
= wxNewEventType();
226 const int wxEVT_COMMAND_LIST_BEGIN_RDRAG
= wxNewEventType();
227 const int wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
= wxNewEventType();
228 const int wxEVT_COMMAND_LIST_END_LABEL_EDIT
= wxNewEventType();
229 const int wxEVT_COMMAND_LIST_DELETE_ITEM
= wxNewEventType();
230 const int wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
= wxNewEventType();
231 const int wxEVT_COMMAND_LIST_GET_INFO
= wxNewEventType();
232 const int wxEVT_COMMAND_LIST_SET_INFO
= wxNewEventType();
233 const int wxEVT_COMMAND_LIST_ITEM_SELECTED
= wxNewEventType();
234 const int wxEVT_COMMAND_LIST_ITEM_DESELECTED
= wxNewEventType();
235 const int wxEVT_COMMAND_LIST_KEY_DOWN
= wxNewEventType();
236 const int wxEVT_COMMAND_LIST_INSERT_ITEM
= wxNewEventType();
237 const int wxEVT_COMMAND_LIST_COL_CLICK
= wxNewEventType();
238 const int wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
= wxNewEventType();
239 const int wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
= wxNewEventType();
240 const int wxEVT_COMMAND_LIST_ITEM_ACTIVATED
= wxNewEventType();
242 // Tab and notebook control event types
243 const int wxEVT_COMMAND_TAB_SEL_CHANGED
= wxNewEventType();
244 const int wxEVT_COMMAND_TAB_SEL_CHANGING
= wxNewEventType();
245 const int wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
= wxNewEventType();
246 const int wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
= wxNewEventType();
249 const int wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
= wxNewEventType();
250 const int wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
= wxNewEventType();
251 const int wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
= wxNewEventType();
252 const int wxEVT_COMMAND_SPLITTER_UNSPLIT
= wxNewEventType();
255 const int wxEVT_WIZARD_PAGE_CHANGED
= wxNewEventType();
256 const int wxEVT_WIZARD_PAGE_CHANGING
= wxNewEventType();
257 const int wxEVT_WIZARD_CANCEL
= wxNewEventType();
260 const int wxEVT_CALENDAR_SEL_CHANGED
= wxNewEventType();
261 const int wxEVT_CALENDAR_DAY_CHANGED
= wxNewEventType();
262 const int wxEVT_CALENDAR_MONTH_CHANGED
= wxNewEventType();
263 const int wxEVT_CALENDAR_YEAR_CHANGED
= wxNewEventType();
264 const int wxEVT_CALENDAR_DOUBLECLICKED
= wxNewEventType();
265 const int wxEVT_CALENDAR_WEEKDAY_CLICKED
= wxNewEventType();
268 const int wxEVT_HELP
= wxNewEventType();
269 const int wxEVT_DETAILED_HELP
= wxNewEventType();
271 // ----------------------------------------------------------------------------
273 // ----------------------------------------------------------------------------
275 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler
, wxObject
)
276 IMPLEMENT_ABSTRACT_CLASS(wxEvent
, wxObject
)
277 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent
, wxEvent
)
280 IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent
, wxEvent
)
281 IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent
, wxCommandEvent
)
282 IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent
, wxCommandEvent
)
283 IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent
, wxEvent
)
284 IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent
, wxEvent
)
285 IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent
, wxEvent
)
286 IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent
, wxEvent
)
287 IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent
, wxEvent
)
288 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent
, wxEvent
)
289 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent
, wxEvent
)
290 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent
, wxEvent
)
291 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent
, wxEvent
)
292 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent
, wxEvent
)
293 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent
, wxEvent
)
294 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent
, wxEvent
)
295 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent
, wxEvent
)
296 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent
, wxEvent
)
297 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent
, wxEvent
)
298 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent
, wxEvent
)
299 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent
, wxEvent
)
300 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent
, wxEvent
)
301 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent
, wxCommandEvent
)
302 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent
, wxCommandEvent
)
303 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent
, wxEvent
)
304 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent
, wxEvent
)
305 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent
, wxEvent
)
306 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent
, wxEvent
)
307 IMPLEMENT_DYNAMIC_CLASS(wxHelpEvent
, wxCommandEvent
)
310 const wxEventTable
*wxEvtHandler::GetEventTable() const
311 { return &wxEvtHandler::sm_eventTable
; }
313 const wxEventTable
wxEvtHandler::sm_eventTable
=
314 { (const wxEventTable
*)NULL
, &wxEvtHandler::sm_eventTableEntries
[0] };
316 const wxEventTableEntry
wxEvtHandler::sm_eventTableEntries
[] =
317 { { 0, 0, 0, (wxObjectEventFunction
) NULL
, (wxObject
*) NULL
} };
320 // ----------------------------------------------------------------------------
322 // ----------------------------------------------------------------------------
324 // To put pending event handlers
325 wxList
*wxPendingEvents
= (wxList
*)NULL
;
328 // protects wxPendingEvents list
329 wxCriticalSection
*wxPendingEventsLocker
= (wxCriticalSection
*)NULL
;
332 // ============================================================================
334 // ============================================================================
336 // ----------------------------------------------------------------------------
338 // ----------------------------------------------------------------------------
341 * General wxWindows events, covering
342 * all interesting things that might happen (button clicking, resizing,
343 * setting text in widgets, etc.).
345 * For each completely new event type, derive a new event class.
349 wxEvent::wxEvent(int theId
)
351 m_eventType
= wxEVT_NULL
;
352 m_eventObject
= (wxObject
*) NULL
;
356 m_callbackUserData
= (wxObject
*) NULL
;
357 m_isCommandEvent
= FALSE
;
360 void wxEvent::CopyObject(wxObject
& object_dest
) const
362 wxEvent
*obj
= (wxEvent
*)&object_dest
;
363 wxObject::CopyObject(object_dest
);
365 obj
->m_eventType
= m_eventType
;
366 obj
->m_eventObject
= m_eventObject
;
367 obj
->m_timeStamp
= m_timeStamp
;
369 obj
->m_skipped
= m_skipped
;
370 obj
->m_callbackUserData
= m_callbackUserData
;
371 obj
->m_isCommandEvent
= m_isCommandEvent
;
381 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
383 m_eventType
= commandType
;
384 m_clientData
= (char *) NULL
;
385 m_clientObject
= (wxClientData
*) NULL
;
389 m_commandString
= wxEmptyString
;
390 m_isCommandEvent
= TRUE
;
393 void wxCommandEvent::CopyObject(wxObject
& obj_d
) const
395 wxCommandEvent
*obj
= (wxCommandEvent
*)&obj_d
;
397 wxEvent::CopyObject(obj_d
);
399 obj
->m_clientData
= m_clientData
;
400 obj
->m_clientObject
= m_clientObject
;
401 obj
->m_extraLong
= m_extraLong
;
402 obj
->m_commandInt
= m_commandInt
;
403 obj
->m_commandString
= m_commandString
;
410 void wxNotifyEvent::CopyObject(wxObject
& obj_d
) const
412 wxNotifyEvent
*obj
= (wxNotifyEvent
*)&obj_d
;
414 wxEvent::CopyObject(obj_d
);
416 if (!m_bAllow
) obj
->Veto();
423 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
427 : wxCommandEvent(commandType
, id
)
429 m_extraLong
= orient
;
437 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
441 m_eventType
= commandType
;
442 m_extraLong
= orient
;
446 void wxScrollWinEvent::CopyObject(wxObject
& obj_d
) const
448 wxScrollWinEvent
*obj
= (wxScrollWinEvent
*)&obj_d
;
450 wxEvent::CopyObject(obj_d
);
452 obj
->m_extraLong
= m_extraLong
;
453 obj
->m_commandInt
= m_commandInt
;
461 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
463 m_eventType
= commandType
;
466 m_controlDown
= FALSE
;
470 m_middleDown
= FALSE
;
475 void wxMouseEvent::CopyObject(wxObject
& obj_d
) const
477 wxMouseEvent
*obj
= (wxMouseEvent
*)&obj_d
;
479 wxEvent::CopyObject(obj_d
);
481 obj
->m_metaDown
= m_metaDown
;
482 obj
->m_altDown
= m_altDown
;
483 obj
->m_controlDown
= m_controlDown
;
484 obj
->m_shiftDown
= m_shiftDown
;
485 obj
->m_leftDown
= m_leftDown
;
486 obj
->m_rightDown
= m_rightDown
;
487 obj
->m_middleDown
= m_middleDown
;
492 // True if was a button dclick event (1 = left, 2 = middle, 3 = right)
493 // or any button dclick event (but = -1)
494 bool wxMouseEvent::ButtonDClick(int but
) const
499 return (LeftDClick() || MiddleDClick() || RightDClick());
503 return MiddleDClick();
505 return RightDClick();
507 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
513 // True if was a button down event (1 = left, 2 = middle, 3 = right)
514 // or any button down event (but = -1)
515 bool wxMouseEvent::ButtonDown(int but
) const
520 return (LeftDown() || MiddleDown() || RightDown());
528 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
534 // True if was a button up event (1 = left, 2 = middle, 3 = right)
535 // or any button up event (but = -1)
536 bool wxMouseEvent::ButtonUp(int but
) const
540 return (LeftUp() || MiddleUp() || RightUp());
548 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
554 // True if the given button is currently changing state
555 bool wxMouseEvent::Button(int but
) const
559 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
561 return (LeftDown() || LeftUp() || LeftDClick());
563 return (MiddleDown() || MiddleUp() || MiddleDClick());
565 return (RightDown() || RightUp() || RightDClick());
567 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
573 bool wxMouseEvent::ButtonIsDown(int but
) const
577 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
581 return MiddleIsDown();
583 return RightIsDown();
585 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
591 // Find the logical position of the event given the DC
592 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
594 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
604 wxKeyEvent::wxKeyEvent(wxEventType type
)
608 m_controlDown
= FALSE
;
615 void wxKeyEvent::CopyObject(wxObject
& obj_d
) const
617 wxKeyEvent
*obj
= (wxKeyEvent
*)&obj_d
;
618 wxEvent::CopyObject(obj_d
);
622 obj
->m_keyCode
= m_keyCode
;
624 obj
->m_shiftDown
= m_shiftDown
;
625 obj
->m_controlDown
= m_controlDown
;
626 obj
->m_metaDown
= m_metaDown
;
627 obj
->m_altDown
= m_altDown
;
628 obj
->m_keyCode
= m_keyCode
;
636 void wxSizeEvent::CopyObject(wxObject
& obj_d
) const
638 wxSizeEvent
*obj
= (wxSizeEvent
*)&obj_d
;
639 wxEvent::CopyObject(obj_d
);
641 obj
->m_size
= m_size
;
644 void wxMoveEvent::CopyObject(wxObject
& obj_d
) const
646 wxMoveEvent
*obj
= (wxMoveEvent
*)&obj_d
;
647 wxEvent::CopyObject(obj_d
);
652 void wxEraseEvent::CopyObject(wxObject
& obj_d
) const
654 wxEraseEvent
*obj
= (wxEraseEvent
*)&obj_d
;
655 wxEvent::CopyObject(obj_d
);
660 void wxActivateEvent::CopyObject(wxObject
& obj_d
) const
662 wxActivateEvent
*obj
= (wxActivateEvent
*)&obj_d
;
663 wxEvent::CopyObject(obj_d
);
665 obj
->m_active
= m_active
;
668 void wxMenuEvent::CopyObject(wxObject
& obj_d
) const
670 wxMenuEvent
*obj
= (wxMenuEvent
*)&obj_d
;
671 wxEvent::CopyObject(obj_d
);
673 obj
->m_menuId
= m_menuId
;
676 void wxCloseEvent::CopyObject(wxObject
& obj_d
) const
678 wxCloseEvent
*obj
= (wxCloseEvent
*)&obj_d
;
679 wxEvent::CopyObject(obj_d
);
681 obj
->m_loggingOff
= m_loggingOff
;
682 obj
->m_veto
= m_veto
;
683 #if WXWIN_COMPATIBILITY
684 obj
->m_force
= m_force
;
686 obj
->m_canVeto
= m_canVeto
;
689 void wxShowEvent::CopyObject(wxObject
& obj_d
) const
691 wxShowEvent
*obj
= (wxShowEvent
*)&obj_d
;
692 wxEvent::CopyObject(obj_d
);
694 obj
->m_show
= m_show
;
697 void wxJoystickEvent::CopyObject(wxObject
& obj_d
) const
699 wxJoystickEvent
*obj
= (wxJoystickEvent
*)&obj_d
;
700 wxEvent::CopyObject(obj_d
);
703 obj
->m_zPosition
= m_zPosition
;
704 obj
->m_buttonChange
= m_buttonChange
;
705 obj
->m_buttonState
= m_buttonState
;
706 obj
->m_joyStick
= m_joyStick
;
709 void wxDropFilesEvent::CopyObject(wxObject
& obj_d
) const
711 wxDropFilesEvent
*obj
= (wxDropFilesEvent
*)&obj_d
;
712 wxEvent::CopyObject(obj_d
);
714 obj
->m_noFiles
= m_noFiles
;
716 // TODO: Problem with obj->m_files. It should be deallocated by the
717 // destructor of the event.
720 void wxUpdateUIEvent::CopyObject(wxObject
&obj_d
) const
722 wxUpdateUIEvent
*obj
= (wxUpdateUIEvent
*)&obj_d
;
723 wxEvent::CopyObject(obj_d
);
725 obj
->m_checked
= m_checked
;
726 obj
->m_enabled
= m_enabled
;
727 obj
->m_text
= m_text
;
728 obj
->m_setText
= m_setText
;
729 obj
->m_setChecked
= m_setChecked
;
730 obj
->m_setEnabled
= m_setEnabled
;
733 void wxPaletteChangedEvent::CopyObject(wxObject
&obj_d
) const
735 wxPaletteChangedEvent
*obj
= (wxPaletteChangedEvent
*)&obj_d
;
736 wxEvent::CopyObject(obj_d
);
738 obj
->m_changedWindow
= m_changedWindow
;
741 void wxQueryNewPaletteEvent::CopyObject(wxObject
& obj_d
) const
743 wxQueryNewPaletteEvent
*obj
= (wxQueryNewPaletteEvent
*)&obj_d
;
744 wxEvent::CopyObject(obj_d
);
746 obj
->m_paletteRealized
= m_paletteRealized
;
749 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
751 SetEventType(wxEVT_CREATE
);
755 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
757 SetEventType(wxEVT_DESTROY
);
763 void wxIdleEvent::CopyObject(wxObject
& obj_d
) const
765 wxIdleEvent
*obj
= (wxIdleEvent
*)&obj_d
;
766 wxEvent::CopyObject(obj_d
);
768 obj
->m_requestMore
= m_requestMore
;
775 wxEvtHandler::wxEvtHandler()
777 m_nextHandler
= (wxEvtHandler
*) NULL
;
778 m_previousHandler
= (wxEvtHandler
*) NULL
;
780 m_dynamicEvents
= (wxList
*) NULL
;
782 m_pendingEvents
= (wxList
*) NULL
;
784 # if !defined(__VISAGECPP__)
785 m_eventsLocker
= new wxCriticalSection
;
790 wxEvtHandler::~wxEvtHandler()
792 // Takes itself out of the list of handlers
793 if (m_previousHandler
)
794 m_previousHandler
->m_nextHandler
= m_nextHandler
;
797 m_nextHandler
->m_previousHandler
= m_previousHandler
;
801 wxNode
*node
= m_dynamicEvents
->First();
804 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
805 if (entry
->m_callbackUserData
) delete entry
->m_callbackUserData
;
809 delete m_dynamicEvents
;
812 delete m_pendingEvents
;
815 # if !defined(__VISAGECPP__)
816 delete m_eventsLocker
;
823 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
825 // check that we are really in a child thread
826 wxASSERT_MSG( !wxThread::IsMain(),
827 wxT("use ProcessEvent() in main thread") );
829 AddPendingEvent(event
);
834 #endif // wxUSE_THREADS
836 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
838 // 1) Add event to list of pending events of this event handler
840 #if defined(__VISAGECPP__)
841 wxENTER_CRIT_SECT( m_eventsLocker
);
843 wxENTER_CRIT_SECT( *m_eventsLocker
);
846 if ( !m_pendingEvents
)
847 m_pendingEvents
= new wxList
;
849 wxEvent
*event2
= (wxEvent
*)event
.Clone();
851 m_pendingEvents
->Append(event2
);
853 #if defined(__VISAGECPP__)
854 wxLEAVE_CRIT_SECT( m_eventsLocker
);
856 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
859 // 2) Add this event handler to list of event handlers that
860 // have pending events.
862 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
864 if ( !wxPendingEvents
)
865 wxPendingEvents
= new wxList
;
866 wxPendingEvents
->Append(this);
868 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
870 // 3) Inform the system that new pending events are somwehere,
871 // and that these should be processed in idle time.
875 void wxEvtHandler::ProcessPendingEvents()
877 #if defined(__VISAGECPP__)
878 wxENTER_CRIT_SECT( m_eventsLocker
);
880 wxENTER_CRIT_SECT( *m_eventsLocker
);
883 wxNode
*node
= m_pendingEvents
->First();
886 wxEvent
*event
= (wxEvent
*)node
->Data();
889 // In ProcessEvent, new events might get added and
890 // we can safely leave the crtical section here.
891 #if defined(__VISAGECPP__)
892 wxLEAVE_CRIT_SECT( m_eventsLocker
);
894 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
896 ProcessEvent(*event
);
898 #if defined(__VISAGECPP__)
899 wxENTER_CRIT_SECT( m_eventsLocker
);
901 wxENTER_CRIT_SECT( *m_eventsLocker
);
904 node
= m_pendingEvents
->First();
907 #if defined(__VISAGECPP__)
908 wxLEAVE_CRIT_SECT( m_eventsLocker
);
910 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
918 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
921 // check that our flag corresponds to reality
922 wxASSERT( m_isWindow
== IsKindOf(CLASSINFO(wxWindow
)) );
925 // An event handler can be enabled or disabled
926 if ( GetEvtHandlerEnabled() )
931 What is this? When using GUI threads, a non main
932 threads can send an event and process it itself.
933 This breaks GTK's GUI threads, so please explain.
936 // Check whether we are in a child thread.
937 if ( !wxThread::IsMain() )
938 return ProcessThreadEvent(event
);
941 // Handle per-instance dynamic event tables first
942 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
945 // Then static per-class event tables
946 const wxEventTable
*table
= GetEventTable();
948 #if wxUSE_GUI && wxUSE_VALIDATORS
949 // Try the associated validator first, if this is a window.
950 // Problem: if the event handler of the window has been replaced,
951 // this wxEvtHandler may no longer be a window.
952 // Therefore validators won't be processed if the handler
953 // has been replaced with SetEventHandler.
954 // THIS CAN BE CURED if PushEventHandler is used instead of
955 // SetEventHandler, and then processing will be passed down the
956 // chain of event handlers.
959 wxWindow
*win
= (wxWindow
*)this;
961 // Can only use the validator of the window which
962 // is receiving the event
963 if ( win
== event
.GetEventObject() )
965 wxValidator
*validator
= win
->GetValidator();
966 if ( validator
&& validator
->ProcessEvent(event
) )
974 // Search upwards through the inheritance hierarchy
977 if ( SearchEventTable((wxEventTable
&)*table
, event
) )
979 table
= table
->baseTable
;
983 // Try going down the event handler chain
984 if ( GetNextHandler() )
986 if ( GetNextHandler()->ProcessEvent(event
) )
991 // Carry on up the parent-child hierarchy,
992 // but only if event is a command event: it wouldn't
993 // make sense for a parent to receive a child's size event, for example
994 if ( m_isWindow
&& event
.IsCommandEvent() )
996 wxWindow
*win
= (wxWindow
*)this;
997 wxWindow
*parent
= win
->GetParent();
998 if (parent
&& !parent
->IsBeingDeleted())
999 return parent
->GetEventHandler()->ProcessEvent(event
);
1003 // Last try - application object.
1004 if ( wxTheApp
&& (this != wxTheApp
) )
1006 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1007 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1008 // processed appropriately via SearchEventTable.
1009 if ( event
.GetEventType() != wxEVT_IDLE
)
1011 if ( wxTheApp
->ProcessEvent(event
) )
1019 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
1021 wxEventType eventType
= event
.GetEventType();
1022 int eventId
= event
.GetId();
1024 // BC++ doesn't like testing for m_fn without != 0
1025 for ( int i
= 0; table
.entries
[i
].m_fn
!= 0; i
++ )
1027 // the line using reference exposes a bug in gcc: although it _seems_
1028 // to work, it leads to weird crashes later on during program
1031 wxEventTableEntry entry
= table
.entries
[i
];
1033 const wxEventTableEntry
& entry
= table
.entries
[i
];
1036 // match only if the event type is the same and the id is either -1 in
1037 // the event table (meaning "any") or the event id matches the id
1038 // specified in the event table either exactly or by falling into
1039 // range between first and last
1040 if ( eventType
== entry
.m_eventType
)
1042 int tableId1
= entry
.m_id
,
1043 tableId2
= entry
.m_lastId
;
1045 if ( (tableId1
== -1) ||
1046 (tableId2
== -1 && eventId
== tableId1
) ||
1048 (eventId
>= tableId1
&& eventId
<= tableId2
)) )
1051 event
.m_callbackUserData
= entry
.m_callbackUserData
;
1053 (this->*((wxEventFunction
) (entry
.m_fn
)))(event
);
1055 return !event
.GetSkipped();
1063 void wxEvtHandler::Connect( int id
, int lastId
,
1065 wxObjectEventFunction func
,
1066 wxObject
*userData
)
1068 wxDynamicEventTableEntry
*entry
= new wxDynamicEventTableEntry
;
1070 entry
->m_lastId
= lastId
;
1071 entry
->m_eventType
= eventType
;
1073 entry
->m_callbackUserData
= userData
;
1075 if (!m_dynamicEvents
)
1076 m_dynamicEvents
= new wxList
;
1078 m_dynamicEvents
->Append( (wxObject
*) entry
);
1081 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
1082 wxObjectEventFunction func
,
1083 wxObject
*userData
)
1085 if (!m_dynamicEvents
)
1088 wxNode
*node
= m_dynamicEvents
->First();
1091 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
1092 if ((entry
->m_id
== id
) &&
1093 ((entry
->m_lastId
== lastId
) || (lastId
== -1)) &&
1094 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1095 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
1096 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
1098 if (entry
->m_callbackUserData
) delete entry
->m_callbackUserData
;
1099 m_dynamicEvents
->DeleteNode( node
);
1103 node
= node
->Next();
1108 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1110 wxCHECK_MSG( m_dynamicEvents
, FALSE
,
1111 wxT("caller should check that we have dynamic events") );
1113 int commandId
= event
.GetId();
1115 wxNode
*node
= m_dynamicEvents
->First();
1118 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->Data();
1122 // Match, if event spec says any id will do (id == -1)
1123 if ( (event
.GetEventType() == entry
->m_eventType
) &&
1124 (entry
->m_id
== -1 ||
1125 (entry
->m_lastId
== -1 && commandId
== entry
->m_id
) ||
1126 (entry
->m_lastId
!= -1 &&
1127 (commandId
>= entry
->m_id
&& commandId
<= entry
->m_lastId
))) )
1130 event
.m_callbackUserData
= entry
->m_callbackUserData
;
1132 (this->*((wxEventFunction
) (entry
->m_fn
)))(event
);
1134 if (event
.GetSkipped())
1140 node
= node
->Next();
1145 #if WXWIN_COMPATIBILITY
1146 bool wxEvtHandler::OnClose()
1148 if (GetNextHandler())
1149 return GetNextHandler()->OnClose();
1153 #endif // WXWIN_COMPATIBILITY
1157 // Find a window with the focus, that is also a descendant of the given window.
1158 // This is used to determine the window to initially send commands to.
1159 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1161 // Process events starting with the window with the focus, if any.
1162 wxWindow
* focusWin
= wxWindow::FindFocus();
1163 wxWindow
* win
= focusWin
;
1165 // Check if this is a descendant of this frame.
1166 // If not, win will be set to NULL.
1169 if (win
== ancestor
)
1172 win
= win
->GetParent();
1174 if (win
== (wxWindow
*) NULL
)
1175 focusWin
= (wxWindow
*) NULL
;