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"
50 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
51 // must define these static for VA or else you get multiply defined symbols everywhere
52 const wxEventType wxEVT_NULL
= 0;
53 const wxEventType wxEVT_FIRST
= 10000;
55 const wxEventType wxEVT_COMMAND_BUTTON_CLICKED
= wxEVT_FIRST
+ 1;
56 const wxEventType wxEVT_COMMAND_CHECKBOX_CLICKED
= wxEVT_FIRST
+ 2;
57 const wxEventType wxEVT_COMMAND_CHOICE_SELECTED
= wxEVT_FIRST
+ 3;
58 const wxEventType wxEVT_COMMAND_LISTBOX_SELECTED
= wxEVT_FIRST
+ 4;
59 const wxEventType wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
= wxEVT_FIRST
+ 5;
60 const wxEventType wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
= wxEVT_FIRST
+ 6;
61 const wxEventType wxEVT_COMMAND_TEXT_UPDATED
= wxEVT_FIRST
+ 7;
62 const wxEventType wxEVT_COMMAND_TEXT_ENTER
= wxEVT_FIRST
+ 8;
63 const wxEventType wxEVT_COMMAND_MENU_SELECTED
= wxEVT_FIRST
+ 9;
64 const wxEventType wxEVT_COMMAND_TOOL_CLICKED
= wxEVT_COMMAND_MENU_SELECTED
;
65 const wxEventType wxEVT_COMMAND_SLIDER_UPDATED
= wxEVT_FIRST
+ 10;
66 const wxEventType wxEVT_COMMAND_RADIOBOX_SELECTED
= wxEVT_FIRST
+ 11;
67 const wxEventType wxEVT_COMMAND_RADIOBUTTON_SELECTED
= wxEVT_FIRST
+ 12;
68 //const wxEventType wxEVT_COMMAND_SCROLLBAR_UPDATED is now obsolete since we use wxEVT_SCROLL... events
69 const wxEventType wxEVT_COMMAND_SCROLLBAR_UPDATED
= wxEVT_FIRST
+ 13;
70 const wxEventType wxEVT_COMMAND_VLBOX_SELECTED
= wxEVT_FIRST
+ 14;
71 const wxEventType wxEVT_COMMAND_COMBOBOX_SELECTED
= wxEVT_FIRST
+ 15;
72 const wxEventType wxEVT_COMMAND_TOOL_RCLICKED
= wxEVT_FIRST
+ 16;
73 const wxEventType wxEVT_COMMAND_TOOL_ENTER
= wxEVT_FIRST
+ 17;
74 const wxEventType wxEVT_COMMAND_SPINCTRL_UPDATED
= wxEVT_FIRST
+ 18;
76 /* Sockets send events, too */
77 const wxEventType wxEVT_SOCKET
= wxEVT_FIRST
+ 50;
78 const wxEventType wxEVT_TIMER
= wxEVT_FIRST
+ 80;
80 /* Mouse event types */
81 const wxEventType wxEVT_LEFT_DOWN
= wxEVT_FIRST
+ 100;
82 const wxEventType wxEVT_LEFT_UP
= wxEVT_FIRST
+ 101;
83 const wxEventType wxEVT_MIDDLE_DOWN
= wxEVT_FIRST
+ 102;
84 const wxEventType wxEVT_MIDDLE_UP
= wxEVT_FIRST
+ 103;
85 const wxEventType wxEVT_RIGHT_DOWN
= wxEVT_FIRST
+ 104;
86 const wxEventType wxEVT_RIGHT_UP
= wxEVT_FIRST
+ 105;
87 const wxEventType wxEVT_MOTION
= wxEVT_FIRST
+ 106;
88 const wxEventType wxEVT_ENTER_WINDOW
= wxEVT_FIRST
+ 107;
89 const wxEventType wxEVT_LEAVE_WINDOW
= wxEVT_FIRST
+ 108;
90 const wxEventType wxEVT_LEFT_DCLICK
= wxEVT_FIRST
+ 109;
91 const wxEventType wxEVT_MIDDLE_DCLICK
= wxEVT_FIRST
+ 110;
92 const wxEventType wxEVT_RIGHT_DCLICK
= wxEVT_FIRST
+ 111;
93 const wxEventType wxEVT_SET_FOCUS
= wxEVT_FIRST
+ 112;
94 const wxEventType wxEVT_KILL_FOCUS
= wxEVT_FIRST
+ 113;
96 /* Non-client mouse events */
97 const wxEventType wxEVT_NC_LEFT_DOWN
= wxEVT_FIRST
+ 200;
98 const wxEventType wxEVT_NC_LEFT_UP
= wxEVT_FIRST
+ 201;
99 const wxEventType wxEVT_NC_MIDDLE_DOWN
= wxEVT_FIRST
+ 202;
100 const wxEventType wxEVT_NC_MIDDLE_UP
= wxEVT_FIRST
+ 203;
101 const wxEventType wxEVT_NC_RIGHT_DOWN
= wxEVT_FIRST
+ 204;
102 const wxEventType wxEVT_NC_RIGHT_UP
= wxEVT_FIRST
+ 205;
103 const wxEventType wxEVT_NC_MOTION
= wxEVT_FIRST
+ 206;
104 const wxEventType wxEVT_NC_ENTER_WINDOW
= wxEVT_FIRST
+ 207;
105 const wxEventType wxEVT_NC_LEAVE_WINDOW
= wxEVT_FIRST
+ 208;
106 const wxEventType wxEVT_NC_LEFT_DCLICK
= wxEVT_FIRST
+ 209;
107 const wxEventType wxEVT_NC_MIDDLE_DCLICK
= wxEVT_FIRST
+ 210;
108 const wxEventType wxEVT_NC_RIGHT_DCLICK
= wxEVT_FIRST
+ 211;
110 /* Character input event type */
111 const wxEventType wxEVT_CHAR
= wxEVT_FIRST
+ 212;
112 const wxEventType wxEVT_CHAR_HOOK
= wxEVT_FIRST
+ 213;
113 const wxEventType wxEVT_NAVIGATION_KEY
= wxEVT_FIRST
+ 214;
114 const wxEventType wxEVT_KEY_DOWN
= wxEVT_FIRST
+ 215;
115 const wxEventType wxEVT_KEY_UP
= wxEVT_FIRST
+ 216;
118 * wxScrollbar and wxSlider event identifiers
120 const wxEventType wxEVT_SCROLL_TOP
= wxEVT_FIRST
+ 300;
121 const wxEventType wxEVT_SCROLL_BOTTOM
= wxEVT_FIRST
+ 301;
122 const wxEventType wxEVT_SCROLL_LINEUP
= wxEVT_FIRST
+ 302;
123 const wxEventType wxEVT_SCROLL_LINEDOWN
= wxEVT_FIRST
+ 303;
124 const wxEventType wxEVT_SCROLL_PAGEUP
= wxEVT_FIRST
+ 304;
125 const wxEventType wxEVT_SCROLL_PAGEDOWN
= wxEVT_FIRST
+ 305;
126 const wxEventType wxEVT_SCROLL_THUMBTRACK
= wxEVT_FIRST
+ 306;
127 const wxEventType wxEVT_SCROLL_THUMBRELEASE
= wxEVT_FIRST
+ 307;
130 * Scroll events from wxWindow
132 const wxEventType wxEVT_SCROLLWIN_TOP
= wxEVT_FIRST
+ 320;
133 const wxEventType wxEVT_SCROLLWIN_BOTTOM
= wxEVT_FIRST
+ 321;
134 const wxEventType wxEVT_SCROLLWIN_LINEUP
= wxEVT_FIRST
+ 322;
135 const wxEventType wxEVT_SCROLLWIN_LINEDOWN
= wxEVT_FIRST
+ 323;
136 const wxEventType wxEVT_SCROLLWIN_PAGEUP
= wxEVT_FIRST
+ 324;
137 const wxEventType wxEVT_SCROLLWIN_PAGEDOWN
= wxEVT_FIRST
+ 325;
138 const wxEventType wxEVT_SCROLLWIN_THUMBTRACK
= wxEVT_FIRST
+ 326;
139 const wxEventType wxEVT_SCROLLWIN_THUMBRELEASE
= wxEVT_FIRST
+ 327;
144 const wxEventType wxEVT_SIZE
= wxEVT_FIRST
+ 400;
145 const wxEventType wxEVT_MOVE
= wxEVT_FIRST
+ 401;
146 const wxEventType wxEVT_CLOSE_WINDOW
= wxEVT_FIRST
+ 402;
147 const wxEventType wxEVT_END_SESSION
= wxEVT_FIRST
+ 403;
148 const wxEventType wxEVT_QUERY_END_SESSION
= wxEVT_FIRST
+ 404;
149 const wxEventType wxEVT_ACTIVATE_APP
= wxEVT_FIRST
+ 405;
150 const wxEventType wxEVT_POWER
= wxEVT_FIRST
+ 406;
151 const wxEventType wxEVT_ACTIVATE
= wxEVT_FIRST
+ 409;
152 const wxEventType wxEVT_CREATE
= wxEVT_FIRST
+ 410;
153 const wxEventType wxEVT_DESTROY
= wxEVT_FIRST
+ 411;
154 const wxEventType wxEVT_SHOW
= wxEVT_FIRST
+ 412;
155 const wxEventType wxEVT_ICONIZE
= wxEVT_FIRST
+ 413;
156 const wxEventType wxEVT_MAXIMIZE
= wxEVT_FIRST
+ 414;
157 const wxEventType wxEVT_MOUSE_CAPTURE_CHANGED
= wxEVT_FIRST
+ 415;
158 const wxEventType wxEVT_PAINT
= wxEVT_FIRST
+ 416;
159 const wxEventType wxEVT_ERASE_BACKGROUND
= wxEVT_FIRST
+ 417;
160 const wxEventType wxEVT_NC_PAINT
= wxEVT_FIRST
+ 418;
161 const wxEventType wxEVT_PAINT_ICON
= wxEVT_FIRST
+ 419;
162 const wxEventType wxEVT_MENU_CHAR
= wxEVT_FIRST
+ 420;
163 const wxEventType wxEVT_MENU_INIT
= wxEVT_FIRST
+ 421;
164 const wxEventType wxEVT_MENU_HIGHLIGHT
= wxEVT_FIRST
+ 422;
165 const wxEventType wxEVT_POPUP_MENU_INIT
= wxEVT_FIRST
+ 423;
166 const wxEventType wxEVT_CONTEXT_MENU
= wxEVT_FIRST
+ 424;
167 const wxEventType wxEVT_SYS_COLOUR_CHANGED
= wxEVT_FIRST
+ 425;
168 const wxEventType wxEVT_SETTING_CHANGED
= wxEVT_FIRST
+ 426;
169 const wxEventType wxEVT_QUERY_NEW_PALETTE
= wxEVT_FIRST
+ 427;
170 const wxEventType wxEVT_PALETTE_CHANGED
= wxEVT_FIRST
+ 428;
171 const wxEventType wxEVT_JOY_BUTTON_DOWN
= wxEVT_FIRST
+ 429;
172 const wxEventType wxEVT_JOY_BUTTON_UP
= wxEVT_FIRST
+ 430;
173 const wxEventType wxEVT_JOY_MOVE
= wxEVT_FIRST
+ 431;
174 const wxEventType wxEVT_JOY_ZMOVE
= wxEVT_FIRST
+ 432;
175 const wxEventType wxEVT_DROP_FILES
= wxEVT_FIRST
+ 433;
176 const wxEventType wxEVT_DRAW_ITEM
= wxEVT_FIRST
+ 434;
177 const wxEventType wxEVT_MEASURE_ITEM
= wxEVT_FIRST
+ 435;
178 const wxEventType wxEVT_COMPARE_ITEM
= wxEVT_FIRST
+ 436;
179 const wxEventType wxEVT_INIT_DIALOG
= wxEVT_FIRST
+ 437;
180 const wxEventType wxEVT_IDLE
= wxEVT_FIRST
+ 438;
181 const wxEventType wxEVT_UPDATE_UI
= wxEVT_FIRST
+ 439;
184 const wxEventType wxEVT_END_PROCESS
= wxEVT_FIRST
+ 440;
187 const wxEventType wxEVT_DIALUP_CONNECTED
= wxEVT_FIRST
+ 450;
188 const wxEventType wxEVT_DIALUP_DISCONNECTED
= wxEVT_FIRST
+ 451;
190 /* Generic command events */
191 /* Note: a click is a higher-level event than button down/up */
192 const wxEventType wxEVT_COMMAND_LEFT_CLICK
= wxEVT_FIRST
+ 500;
193 const wxEventType wxEVT_COMMAND_LEFT_DCLICK
= wxEVT_FIRST
+ 501;
194 const wxEventType wxEVT_COMMAND_RIGHT_CLICK
= wxEVT_FIRST
+ 502;
195 const wxEventType wxEVT_COMMAND_RIGHT_DCLICK
= wxEVT_FIRST
+ 503;
196 const wxEventType wxEVT_COMMAND_SET_FOCUS
= wxEVT_FIRST
+ 504;
197 const wxEventType wxEVT_COMMAND_KILL_FOCUS
= wxEVT_FIRST
+ 505;
198 const wxEventType wxEVT_COMMAND_ENTER
= wxEVT_FIRST
+ 506;
200 /* Tree control event types */
201 const wxEventType wxEVT_COMMAND_TREE_BEGIN_DRAG
= wxEVT_FIRST
+ 600;
202 const wxEventType wxEVT_COMMAND_TREE_BEGIN_RDRAG
= wxEVT_FIRST
+ 601;
203 const wxEventType wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
= wxEVT_FIRST
+ 602;
204 const wxEventType wxEVT_COMMAND_TREE_END_LABEL_EDIT
= wxEVT_FIRST
+ 603;
205 const wxEventType wxEVT_COMMAND_TREE_DELETE_ITEM
= wxEVT_FIRST
+ 604;
206 const wxEventType wxEVT_COMMAND_TREE_GET_INFO
= wxEVT_FIRST
+ 605;
207 const wxEventType wxEVT_COMMAND_TREE_SET_INFO
= wxEVT_FIRST
+ 606;
208 const wxEventType wxEVT_COMMAND_TREE_ITEM_EXPANDED
= wxEVT_FIRST
+ 607;
209 const wxEventType wxEVT_COMMAND_TREE_ITEM_EXPANDING
= wxEVT_FIRST
+ 608;
210 const wxEventType wxEVT_COMMAND_TREE_ITEM_COLLAPSED
= wxEVT_FIRST
+ 609;
211 const wxEventType wxEVT_COMMAND_TREE_ITEM_COLLAPSING
= wxEVT_FIRST
+ 610;
212 const wxEventType wxEVT_COMMAND_TREE_SEL_CHANGED
= wxEVT_FIRST
+ 611;
213 const wxEventType wxEVT_COMMAND_TREE_SEL_CHANGING
= wxEVT_FIRST
+ 612;
214 const wxEventType wxEVT_COMMAND_TREE_KEY_DOWN
= wxEVT_FIRST
+ 613;
215 const wxEventType wxEVT_COMMAND_TREE_ITEM_ACTIVATED
= wxEVT_FIRST
+ 614;
216 const wxEventType wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
= wxEVT_FIRST
+ 615;
217 const wxEventType wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK
= wxEVT_FIRST
+ 616;
219 /* List control event types */
220 const wxEventType wxEVT_COMMAND_LIST_BEGIN_DRAG
= wxEVT_FIRST
+ 700;
221 const wxEventType wxEVT_COMMAND_LIST_BEGIN_RDRAG
= wxEVT_FIRST
+ 701;
222 const wxEventType wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
= wxEVT_FIRST
+ 702;
223 const wxEventType wxEVT_COMMAND_LIST_END_LABEL_EDIT
= wxEVT_FIRST
+ 703;
224 const wxEventType wxEVT_COMMAND_LIST_DELETE_ITEM
= wxEVT_FIRST
+ 704;
225 const wxEventType wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
= wxEVT_FIRST
+ 705;
226 const wxEventType wxEVT_COMMAND_LIST_GET_INFO
= wxEVT_FIRST
+ 706;
227 const wxEventType wxEVT_COMMAND_LIST_SET_INFO
= wxEVT_FIRST
+ 707;
228 const wxEventType wxEVT_COMMAND_LIST_ITEM_SELECTED
= wxEVT_FIRST
+ 708;
229 const wxEventType wxEVT_COMMAND_LIST_ITEM_DESELECTED
= wxEVT_FIRST
+ 709;
230 const wxEventType wxEVT_COMMAND_LIST_KEY_DOWN
= wxEVT_FIRST
+ 710;
231 const wxEventType wxEVT_COMMAND_LIST_INSERT_ITEM
= wxEVT_FIRST
+ 711;
232 const wxEventType wxEVT_COMMAND_LIST_COL_CLICK
= wxEVT_FIRST
+ 712;
233 const wxEventType wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
= wxEVT_FIRST
+ 713;
234 const wxEventType wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
= wxEVT_FIRST
+ 714;
235 const wxEventType wxEVT_COMMAND_LIST_ITEM_ACTIVATED
= wxEVT_FIRST
+ 715;
237 /* Tab and notebook control event types */
238 const wxEventType wxEVT_COMMAND_TAB_SEL_CHANGED
= wxEVT_FIRST
+ 800;
239 const wxEventType wxEVT_COMMAND_TAB_SEL_CHANGING
= wxEVT_FIRST
+ 801;
240 const wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
= wxEVT_FIRST
+ 802;
241 const wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
= wxEVT_FIRST
+ 803;
243 /* Splitter events */
244 const wxEventType wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
= wxEVT_FIRST
+ 850;
245 const wxEventType wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
= wxEVT_FIRST
+ 851;
246 const wxEventType wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
= wxEVT_FIRST
+ 852;
247 const wxEventType wxEVT_COMMAND_SPLITTER_UNSPLIT
= wxEVT_FIRST
+ 853;
250 const wxEventType wxEVT_WIZARD_PAGE_CHANGED
= wxEVT_FIRST
+ 900;
251 const wxEventType wxEVT_WIZARD_PAGE_CHANGING
= wxEVT_FIRST
+ 901;
252 const wxEventType wxEVT_WIZARD_CANCEL
= wxEVT_FIRST
+ 902;
254 /* Calendar events */
255 const wxEventType wxEVT_CALENDAR_SEL_CHANGED
= wxEVT_FIRST
+ 950;
256 const wxEventType wxEVT_CALENDAR_DAY_CHANGED
= wxEVT_FIRST
+ 951;
257 const wxEventType wxEVT_CALENDAR_MONTH_CHANGED
= wxEVT_FIRST
+ 952;
258 const wxEventType wxEVT_CALENDAR_YEAR_CHANGED
= wxEVT_FIRST
+ 953;
259 const wxEventType wxEVT_CALENDAR_DOUBLECLICKED
= wxEVT_FIRST
+ 954;
260 const wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED
= wxEVT_FIRST
+ 955;
262 const wxEventType wxEVT_USER_FIRST
= wxEVT_FIRST
+ 2000;
265 // ----------------------------------------------------------------------------
267 // ----------------------------------------------------------------------------
269 IMPLEMENT_DYNAMIC_CLASS(wxEvtHandler
, wxObject
)
270 IMPLEMENT_ABSTRACT_CLASS(wxEvent
, wxObject
)
271 IMPLEMENT_DYNAMIC_CLASS(wxIdleEvent
, wxEvent
)
274 IMPLEMENT_DYNAMIC_CLASS(wxCommandEvent
, wxEvent
)
275 IMPLEMENT_DYNAMIC_CLASS(wxNotifyEvent
, wxCommandEvent
)
276 IMPLEMENT_DYNAMIC_CLASS(wxScrollEvent
, wxCommandEvent
)
277 IMPLEMENT_DYNAMIC_CLASS(wxScrollWinEvent
, wxEvent
)
278 IMPLEMENT_DYNAMIC_CLASS(wxMouseEvent
, wxEvent
)
279 IMPLEMENT_DYNAMIC_CLASS(wxKeyEvent
, wxEvent
)
280 IMPLEMENT_DYNAMIC_CLASS(wxSizeEvent
, wxEvent
)
281 IMPLEMENT_DYNAMIC_CLASS(wxPaintEvent
, wxEvent
)
282 IMPLEMENT_DYNAMIC_CLASS(wxEraseEvent
, wxEvent
)
283 IMPLEMENT_DYNAMIC_CLASS(wxMoveEvent
, wxEvent
)
284 IMPLEMENT_DYNAMIC_CLASS(wxFocusEvent
, wxEvent
)
285 IMPLEMENT_DYNAMIC_CLASS(wxCloseEvent
, wxEvent
)
286 IMPLEMENT_DYNAMIC_CLASS(wxShowEvent
, wxEvent
)
287 IMPLEMENT_DYNAMIC_CLASS(wxMaximizeEvent
, wxEvent
)
288 IMPLEMENT_DYNAMIC_CLASS(wxIconizeEvent
, wxEvent
)
289 IMPLEMENT_DYNAMIC_CLASS(wxMenuEvent
, wxEvent
)
290 IMPLEMENT_DYNAMIC_CLASS(wxJoystickEvent
, wxEvent
)
291 IMPLEMENT_DYNAMIC_CLASS(wxDropFilesEvent
, wxEvent
)
292 IMPLEMENT_DYNAMIC_CLASS(wxActivateEvent
, wxEvent
)
293 IMPLEMENT_DYNAMIC_CLASS(wxInitDialogEvent
, wxEvent
)
294 IMPLEMENT_DYNAMIC_CLASS(wxSysColourChangedEvent
, wxEvent
)
295 IMPLEMENT_DYNAMIC_CLASS(wxUpdateUIEvent
, wxCommandEvent
)
296 IMPLEMENT_DYNAMIC_CLASS(wxNavigationKeyEvent
, wxCommandEvent
)
297 IMPLEMENT_DYNAMIC_CLASS(wxPaletteChangedEvent
, wxEvent
)
298 IMPLEMENT_DYNAMIC_CLASS(wxQueryNewPaletteEvent
, wxEvent
)
299 IMPLEMENT_DYNAMIC_CLASS(wxWindowCreateEvent
, wxEvent
)
300 IMPLEMENT_DYNAMIC_CLASS(wxWindowDestroyEvent
, wxEvent
)
303 const wxEventTable
*wxEvtHandler::GetEventTable() const
304 { return &wxEvtHandler::sm_eventTable
; }
306 const wxEventTable
wxEvtHandler::sm_eventTable
=
307 { (const wxEventTable
*)NULL
, &wxEvtHandler::sm_eventTableEntries
[0] };
309 const wxEventTableEntry
wxEvtHandler::sm_eventTableEntries
[] =
310 { { 0, 0, 0, (wxObjectEventFunction
) NULL
, (wxObject
*) NULL
} };
313 // ----------------------------------------------------------------------------
315 // ----------------------------------------------------------------------------
317 // To put pending event handlers
318 wxList
*wxPendingEvents
= (wxList
*)NULL
;
321 // protects wxPendingEvents list
322 wxCriticalSection
*wxPendingEventsLocker
= (wxCriticalSection
*)NULL
;
325 // ============================================================================
327 // ============================================================================
329 // ----------------------------------------------------------------------------
331 // ----------------------------------------------------------------------------
334 * General wxWindows events, covering
335 * all interesting things that might happen (button clicking, resizing,
336 * setting text in widgets, etc.).
338 * For each completely new event type, derive a new event class.
342 wxEvent::wxEvent(int theId
)
344 m_eventType
= wxEVT_NULL
;
345 m_eventObject
= (wxObject
*) NULL
;
349 m_callbackUserData
= (wxObject
*) NULL
;
350 m_isCommandEvent
= FALSE
;
353 void wxEvent::CopyObject(wxObject
& object_dest
) const
355 wxEvent
*obj
= (wxEvent
*)&object_dest
;
356 wxObject::CopyObject(object_dest
);
358 obj
->m_eventType
= m_eventType
;
359 obj
->m_eventObject
= m_eventObject
;
360 obj
->m_timeStamp
= m_timeStamp
;
362 obj
->m_skipped
= m_skipped
;
363 obj
->m_callbackUserData
= m_callbackUserData
;
364 obj
->m_isCommandEvent
= m_isCommandEvent
;
374 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
376 m_eventType
= commandType
;
377 m_clientData
= (char *) NULL
;
378 m_clientObject
= (wxClientData
*) NULL
;
382 m_commandString
= wxEmptyString
;
383 m_isCommandEvent
= TRUE
;
386 void wxCommandEvent::CopyObject(wxObject
& obj_d
) const
388 wxCommandEvent
*obj
= (wxCommandEvent
*)&obj_d
;
390 wxEvent::CopyObject(obj_d
);
392 obj
->m_clientData
= m_clientData
;
393 obj
->m_clientObject
= m_clientObject
;
394 obj
->m_extraLong
= m_extraLong
;
395 obj
->m_commandInt
= m_commandInt
;
396 obj
->m_commandString
= m_commandString
;
403 void wxNotifyEvent::CopyObject(wxObject
& obj_d
) const
405 wxNotifyEvent
*obj
= (wxNotifyEvent
*)&obj_d
;
407 wxEvent::CopyObject(obj_d
);
409 if (!m_bAllow
) obj
->Veto();
416 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
420 : wxCommandEvent(commandType
, id
)
422 m_extraLong
= orient
;
430 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
434 m_eventType
= commandType
;
435 m_extraLong
= orient
;
439 void wxScrollWinEvent::CopyObject(wxObject
& obj_d
) const
441 wxScrollWinEvent
*obj
= (wxScrollWinEvent
*)&obj_d
;
443 wxEvent::CopyObject(obj_d
);
445 obj
->m_extraLong
= m_extraLong
;
446 obj
->m_commandInt
= m_commandInt
;
454 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
456 m_eventType
= commandType
;
459 m_controlDown
= FALSE
;
463 m_middleDown
= FALSE
;
468 void wxMouseEvent::CopyObject(wxObject
& obj_d
) const
470 wxMouseEvent
*obj
= (wxMouseEvent
*)&obj_d
;
472 wxEvent::CopyObject(obj_d
);
474 obj
->m_metaDown
= m_metaDown
;
475 obj
->m_altDown
= m_altDown
;
476 obj
->m_controlDown
= m_controlDown
;
477 obj
->m_shiftDown
= m_shiftDown
;
478 obj
->m_leftDown
= m_leftDown
;
479 obj
->m_rightDown
= m_rightDown
;
480 obj
->m_middleDown
= m_middleDown
;
485 // True if was a button dclick event (1 = left, 2 = middle, 3 = right)
486 // or any button dclick event (but = -1)
487 bool wxMouseEvent::ButtonDClick(int but
) const
492 return (LeftDClick() || MiddleDClick() || RightDClick());
496 return MiddleDClick();
498 return RightDClick();
500 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
506 // True if was a button down event (1 = left, 2 = middle, 3 = right)
507 // or any button down event (but = -1)
508 bool wxMouseEvent::ButtonDown(int but
) const
513 return (LeftDown() || MiddleDown() || RightDown());
521 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
527 // True if was a button up event (1 = left, 2 = middle, 3 = right)
528 // or any button up event (but = -1)
529 bool wxMouseEvent::ButtonUp(int but
) const
533 return (LeftUp() || MiddleUp() || RightUp());
541 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
547 // True if the given button is currently changing state
548 bool wxMouseEvent::Button(int but
) const
552 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
554 return (LeftDown() || LeftUp() || LeftDClick());
556 return (MiddleDown() || MiddleUp() || MiddleDClick());
558 return (RightDown() || RightUp() || RightDClick());
560 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
566 bool wxMouseEvent::ButtonIsDown(int but
) const
570 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
574 return MiddleIsDown();
576 return RightIsDown();
578 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
584 // Find the logical position of the event given the DC
585 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
587 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
597 wxKeyEvent::wxKeyEvent(wxEventType type
)
601 m_controlDown
= FALSE
;
608 void wxKeyEvent::CopyObject(wxObject
& obj_d
) const
610 wxKeyEvent
*obj
= (wxKeyEvent
*)&obj_d
;
611 wxEvent::CopyObject(obj_d
);
615 obj
->m_keyCode
= m_keyCode
;
617 obj
->m_shiftDown
= m_shiftDown
;
618 obj
->m_controlDown
= m_controlDown
;
619 obj
->m_metaDown
= m_metaDown
;
620 obj
->m_altDown
= m_altDown
;
621 obj
->m_keyCode
= m_keyCode
;
629 void wxSizeEvent::CopyObject(wxObject
& obj_d
) const
631 wxSizeEvent
*obj
= (wxSizeEvent
*)&obj_d
;
632 wxEvent::CopyObject(obj_d
);
634 obj
->m_size
= m_size
;
637 void wxMoveEvent::CopyObject(wxObject
& obj_d
) const
639 wxMoveEvent
*obj
= (wxMoveEvent
*)&obj_d
;
640 wxEvent::CopyObject(obj_d
);
645 void wxEraseEvent::CopyObject(wxObject
& obj_d
) const
647 wxEraseEvent
*obj
= (wxEraseEvent
*)&obj_d
;
648 wxEvent::CopyObject(obj_d
);
653 void wxActivateEvent::CopyObject(wxObject
& obj_d
) const
655 wxActivateEvent
*obj
= (wxActivateEvent
*)&obj_d
;
656 wxEvent::CopyObject(obj_d
);
658 obj
->m_active
= m_active
;
661 void wxMenuEvent::CopyObject(wxObject
& obj_d
) const
663 wxMenuEvent
*obj
= (wxMenuEvent
*)&obj_d
;
664 wxEvent::CopyObject(obj_d
);
666 obj
->m_menuId
= m_menuId
;
669 void wxCloseEvent::CopyObject(wxObject
& obj_d
) const
671 wxCloseEvent
*obj
= (wxCloseEvent
*)&obj_d
;
672 wxEvent::CopyObject(obj_d
);
674 obj
->m_loggingOff
= m_loggingOff
;
675 obj
->m_veto
= m_veto
;
676 #if WXWIN_COMPATIBILITY
677 obj
->m_force
= m_force
;
679 obj
->m_canVeto
= m_canVeto
;
682 void wxShowEvent::CopyObject(wxObject
& obj_d
) const
684 wxShowEvent
*obj
= (wxShowEvent
*)&obj_d
;
685 wxEvent::CopyObject(obj_d
);
687 obj
->m_show
= m_show
;
690 void wxJoystickEvent::CopyObject(wxObject
& obj_d
) const
692 wxJoystickEvent
*obj
= (wxJoystickEvent
*)&obj_d
;
693 wxEvent::CopyObject(obj_d
);
696 obj
->m_zPosition
= m_zPosition
;
697 obj
->m_buttonChange
= m_buttonChange
;
698 obj
->m_buttonState
= m_buttonState
;
699 obj
->m_joyStick
= m_joyStick
;
702 void wxDropFilesEvent::CopyObject(wxObject
& obj_d
) const
704 wxDropFilesEvent
*obj
= (wxDropFilesEvent
*)&obj_d
;
705 wxEvent::CopyObject(obj_d
);
707 obj
->m_noFiles
= m_noFiles
;
709 // TODO: Problem with obj->m_files. It should be deallocated by the
710 // destructor of the event.
713 void wxUpdateUIEvent::CopyObject(wxObject
&obj_d
) const
715 wxUpdateUIEvent
*obj
= (wxUpdateUIEvent
*)&obj_d
;
716 wxEvent::CopyObject(obj_d
);
718 obj
->m_checked
= m_checked
;
719 obj
->m_enabled
= m_enabled
;
720 obj
->m_text
= m_text
;
721 obj
->m_setText
= m_setText
;
722 obj
->m_setChecked
= m_setChecked
;
723 obj
->m_setEnabled
= m_setEnabled
;
726 void wxPaletteChangedEvent::CopyObject(wxObject
&obj_d
) const
728 wxPaletteChangedEvent
*obj
= (wxPaletteChangedEvent
*)&obj_d
;
729 wxEvent::CopyObject(obj_d
);
731 obj
->m_changedWindow
= m_changedWindow
;
734 void wxQueryNewPaletteEvent::CopyObject(wxObject
& obj_d
) const
736 wxQueryNewPaletteEvent
*obj
= (wxQueryNewPaletteEvent
*)&obj_d
;
737 wxEvent::CopyObject(obj_d
);
739 obj
->m_paletteRealized
= m_paletteRealized
;
742 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
745 SetEventType(wxEVT_CREATE
);
749 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
752 SetEventType(wxEVT_DESTROY
);
758 void wxIdleEvent::CopyObject(wxObject
& obj_d
) const
760 wxIdleEvent
*obj
= (wxIdleEvent
*)&obj_d
;
761 wxEvent::CopyObject(obj_d
);
763 obj
->m_requestMore
= m_requestMore
;
770 wxEvtHandler::wxEvtHandler()
772 m_nextHandler
= (wxEvtHandler
*) NULL
;
773 m_previousHandler
= (wxEvtHandler
*) NULL
;
775 m_dynamicEvents
= (wxList
*) NULL
;
777 m_pendingEvents
= (wxList
*) NULL
;
779 # if !defined(__VISAGECPP__)
780 m_eventsLocker
= new wxCriticalSection
;
785 wxEvtHandler::~wxEvtHandler()
787 // Takes itself out of the list of handlers
788 if (m_previousHandler
)
789 m_previousHandler
->m_nextHandler
= m_nextHandler
;
792 m_nextHandler
->m_previousHandler
= m_previousHandler
;
796 wxNode
*node
= m_dynamicEvents
->First();
799 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
800 if (entry
->m_callbackUserData
) delete entry
->m_callbackUserData
;
804 delete m_dynamicEvents
;
807 delete m_pendingEvents
;
810 # if !defined(__VISAGECPP__)
811 delete m_eventsLocker
;
818 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
820 // check that we are really in a child thread
821 wxASSERT_MSG( !wxThread::IsMain(),
822 wxT("use ProcessEvent() in main thread") );
824 AddPendingEvent(event
);
829 #endif // wxUSE_THREADS
831 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
833 // 1) Add event to list of pending events of this event handler
835 #if defined(__VISAGECPP__)
836 wxENTER_CRIT_SECT( m_eventsLocker
);
838 wxENTER_CRIT_SECT( *m_eventsLocker
);
841 if ( !m_pendingEvents
)
842 m_pendingEvents
= new wxList
;
844 wxEvent
*event2
= (wxEvent
*)event
.Clone();
846 m_pendingEvents
->Append(event2
);
848 #if defined(__VISAGECPP__)
849 wxLEAVE_CRIT_SECT( m_eventsLocker
);
851 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
854 // 2) Add this event handler to list of event handlers that
855 // have pending events.
857 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
859 if ( !wxPendingEvents
)
860 wxPendingEvents
= new wxList
;
861 wxPendingEvents
->Append(this);
863 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
865 // 3) Inform the system that new pending events are somwehere,
866 // and that these should be processed in idle time.
870 void wxEvtHandler::ProcessPendingEvents()
872 #if defined(__VISAGECPP__)
873 wxENTER_CRIT_SECT( m_eventsLocker
);
875 wxENTER_CRIT_SECT( *m_eventsLocker
);
878 wxNode
*node
= m_pendingEvents
->First();
881 wxEvent
*event
= (wxEvent
*)node
->Data();
884 // In ProcessEvent, new events might get added and
885 // we can safely leave the crtical section here.
886 #if defined(__VISAGECPP__)
887 wxLEAVE_CRIT_SECT( m_eventsLocker
);
889 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
891 ProcessEvent(*event
);
893 #if defined(__VISAGECPP__)
894 wxENTER_CRIT_SECT( m_eventsLocker
);
896 wxENTER_CRIT_SECT( *m_eventsLocker
);
899 node
= m_pendingEvents
->First();
902 #if defined(__VISAGECPP__)
903 wxLEAVE_CRIT_SECT( m_eventsLocker
);
905 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
913 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
916 // check that our flag corresponds to reality
917 wxASSERT( m_isWindow
== IsKindOf(CLASSINFO(wxWindow
)) );
920 // An event handler can be enabled or disabled
921 if ( GetEvtHandlerEnabled() )
926 What is this? When using GUI threads, a non main
927 threads can send an event and process it itself.
928 This breaks GTK's GUI threads, so please explain.
931 // Check whether we are in a child thread.
932 if ( !wxThread::IsMain() )
933 return ProcessThreadEvent(event
);
936 // Handle per-instance dynamic event tables first
937 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
940 // Then static per-class event tables
941 const wxEventTable
*table
= GetEventTable();
943 #if wxUSE_GUI && wxUSE_VALIDATORS
944 // Try the associated validator first, if this is a window.
945 // Problem: if the event handler of the window has been replaced,
946 // this wxEvtHandler may no longer be a window.
947 // Therefore validators won't be processed if the handler
948 // has been replaced with SetEventHandler.
949 // THIS CAN BE CURED if PushEventHandler is used instead of
950 // SetEventHandler, and then processing will be passed down the
951 // chain of event handlers.
954 wxWindow
*win
= (wxWindow
*)this;
956 // Can only use the validator of the window which
957 // is receiving the event
958 if ( win
== event
.GetEventObject() )
960 wxValidator
*validator
= win
->GetValidator();
961 if ( validator
&& validator
->ProcessEvent(event
) )
969 // Search upwards through the inheritance hierarchy
972 if ( SearchEventTable((wxEventTable
&)*table
, event
) )
974 table
= table
->baseTable
;
978 // Try going down the event handler chain
979 if ( GetNextHandler() )
981 if ( GetNextHandler()->ProcessEvent(event
) )
986 // Carry on up the parent-child hierarchy,
987 // but only if event is a command event: it wouldn't
988 // make sense for a parent to receive a child's size event, for example
989 if ( m_isWindow
&& event
.IsCommandEvent() )
991 wxWindow
*win
= (wxWindow
*)this;
992 wxWindow
*parent
= win
->GetParent();
993 if (parent
&& !parent
->IsBeingDeleted())
994 return parent
->GetEventHandler()->ProcessEvent(event
);
998 // Last try - application object.
999 if ( wxTheApp
&& (this != wxTheApp
) )
1001 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1002 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1003 // processed appropriately via SearchEventTable.
1004 if ( event
.GetEventType() != wxEVT_IDLE
)
1006 if ( wxTheApp
->ProcessEvent(event
) )
1014 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
1017 int commandId
= event
.GetId();
1019 // BC++ doesn't like while (table.entries[i].m_fn)
1022 while (table
.entries
[i
].m_fn
!= 0)
1024 while (table
.entries
[i
].m_fn
!= 0L)
1027 if ((event
.GetEventType() == table
.entries
[i
].m_eventType
) &&
1028 (table
.entries
[i
].m_id
== -1 || // Match, if event spec says any id will do (id == -1)
1029 (table
.entries
[i
].m_lastId
== -1 && commandId
== table
.entries
[i
].m_id
) ||
1030 (table
.entries
[i
].m_lastId
!= -1 &&
1031 (commandId
>= table
.entries
[i
].m_id
&& commandId
<= table
.entries
[i
].m_lastId
))))
1034 event
.m_callbackUserData
= table
.entries
[i
].m_callbackUserData
;
1036 (this->*((wxEventFunction
) (table
.entries
[i
].m_fn
)))(event
);
1038 if ( event
.GetSkipped() )
1048 void wxEvtHandler::Connect( int id
, int lastId
,
1049 wxEventType eventType
,
1050 wxObjectEventFunction func
,
1051 wxObject
*userData
)
1053 wxEventTableEntry
*entry
= new wxEventTableEntry
;
1055 entry
->m_lastId
= lastId
;
1056 entry
->m_eventType
= eventType
;
1058 entry
->m_callbackUserData
= userData
;
1060 if (!m_dynamicEvents
)
1061 m_dynamicEvents
= new wxList
;
1063 m_dynamicEvents
->Append( (wxObject
*) entry
);
1066 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
1067 wxObjectEventFunction func
,
1068 wxObject
*userData
)
1070 if (!m_dynamicEvents
)
1073 wxNode
*node
= m_dynamicEvents
->First();
1076 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
1077 if ((entry
->m_id
== id
) &&
1078 ((entry
->m_lastId
== lastId
) || (lastId
== -1)) &&
1079 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1080 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
1081 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
1083 if (entry
->m_callbackUserData
) delete entry
->m_callbackUserData
;
1084 m_dynamicEvents
->DeleteNode( node
);
1088 node
= node
->Next();
1093 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1095 wxCHECK_MSG( m_dynamicEvents
, FALSE
,
1096 wxT("caller should check that we have dynamic events") );
1098 int commandId
= event
.GetId();
1100 wxNode
*node
= m_dynamicEvents
->First();
1103 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
1107 // Match, if event spec says any id will do (id == -1)
1108 if ( (event
.GetEventType() == entry
->m_eventType
) &&
1109 (entry
->m_id
== -1 ||
1110 (entry
->m_lastId
== -1 && commandId
== entry
->m_id
) ||
1111 (entry
->m_lastId
!= -1 &&
1112 (commandId
>= entry
->m_id
&& commandId
<= entry
->m_lastId
))) )
1115 event
.m_callbackUserData
= entry
->m_callbackUserData
;
1117 (this->*((wxEventFunction
) (entry
->m_fn
)))(event
);
1119 if (event
.GetSkipped())
1125 node
= node
->Next();
1130 #if WXWIN_COMPATIBILITY
1131 bool wxEvtHandler::OnClose()
1133 if (GetNextHandler())
1134 return GetNextHandler()->OnClose();
1138 #endif // WXWIN_COMPATIBILITY
1142 // Find a window with the focus, that is also a descendant of the given window.
1143 // This is used to determine the window to initially send commands to.
1144 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1146 // Process events starting with the window with the focus, if any.
1147 wxWindow
* focusWin
= wxWindow::FindFocus();
1148 wxWindow
* win
= focusWin
;
1150 // Check if this is a descendant of this frame.
1151 // If not, win will be set to NULL.
1154 if (win
== ancestor
)
1157 win
= win
->GetParent();
1159 if (win
== (wxWindow
*) NULL
)
1160 focusWin
= (wxWindow
*) NULL
;