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 // define these here to keep from getting multiply defines externals
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;
79 /* Mouse event types */
80 const wxEventType wxEVT_LEFT_DOWN
= wxEVT_FIRST
+ 100;
81 const wxEventType wxEVT_LEFT_UP
= wxEVT_FIRST
+ 101;
82 const wxEventType wxEVT_MIDDLE_DOWN
= wxEVT_FIRST
+ 102;
83 const wxEventType wxEVT_MIDDLE_UP
= wxEVT_FIRST
+ 103;
84 const wxEventType wxEVT_RIGHT_DOWN
= wxEVT_FIRST
+ 104;
85 const wxEventType wxEVT_RIGHT_UP
= wxEVT_FIRST
+ 105;
86 const wxEventType wxEVT_MOTION
= wxEVT_FIRST
+ 106;
87 const wxEventType wxEVT_ENTER_WINDOW
= wxEVT_FIRST
+ 107;
88 const wxEventType wxEVT_LEAVE_WINDOW
= wxEVT_FIRST
+ 108;
89 const wxEventType wxEVT_LEFT_DCLICK
= wxEVT_FIRST
+ 109;
90 const wxEventType wxEVT_MIDDLE_DCLICK
= wxEVT_FIRST
+ 110;
91 const wxEventType wxEVT_RIGHT_DCLICK
= wxEVT_FIRST
+ 111;
92 const wxEventType wxEVT_SET_FOCUS
= wxEVT_FIRST
+ 112;
93 const wxEventType wxEVT_KILL_FOCUS
= wxEVT_FIRST
+ 113;
95 /* Non-client mouse events */
96 const wxEventType wxEVT_NC_LEFT_DOWN
= wxEVT_FIRST
+ 200;
97 const wxEventType wxEVT_NC_LEFT_UP
= wxEVT_FIRST
+ 201;
98 const wxEventType wxEVT_NC_MIDDLE_DOWN
= wxEVT_FIRST
+ 202;
99 const wxEventType wxEVT_NC_MIDDLE_UP
= wxEVT_FIRST
+ 203;
100 const wxEventType wxEVT_NC_RIGHT_DOWN
= wxEVT_FIRST
+ 204;
101 const wxEventType wxEVT_NC_RIGHT_UP
= wxEVT_FIRST
+ 205;
102 const wxEventType wxEVT_NC_MOTION
= wxEVT_FIRST
+ 206;
103 const wxEventType wxEVT_NC_ENTER_WINDOW
= wxEVT_FIRST
+ 207;
104 const wxEventType wxEVT_NC_LEAVE_WINDOW
= wxEVT_FIRST
+ 208;
105 const wxEventType wxEVT_NC_LEFT_DCLICK
= wxEVT_FIRST
+ 209;
106 const wxEventType wxEVT_NC_MIDDLE_DCLICK
= wxEVT_FIRST
+ 210;
107 const wxEventType wxEVT_NC_RIGHT_DCLICK
= wxEVT_FIRST
+ 211;
109 /* Character input event type */
110 const wxEventType wxEVT_CHAR
= wxEVT_FIRST
+ 212;
111 const wxEventType wxEVT_CHAR_HOOK
= wxEVT_FIRST
+ 213;
112 const wxEventType wxEVT_NAVIGATION_KEY
= wxEVT_FIRST
+ 214;
113 const wxEventType wxEVT_KEY_DOWN
= wxEVT_FIRST
+ 215;
114 const wxEventType wxEVT_KEY_UP
= wxEVT_FIRST
+ 216;
117 * wxScrollbar and wxSlider event identifiers
119 const wxEventType wxEVT_SCROLL_TOP
= wxEVT_FIRST
+ 300;
120 const wxEventType wxEVT_SCROLL_BOTTOM
= wxEVT_FIRST
+ 301;
121 const wxEventType wxEVT_SCROLL_LINEUP
= wxEVT_FIRST
+ 302;
122 const wxEventType wxEVT_SCROLL_LINEDOWN
= wxEVT_FIRST
+ 303;
123 const wxEventType wxEVT_SCROLL_PAGEUP
= wxEVT_FIRST
+ 304;
124 const wxEventType wxEVT_SCROLL_PAGEDOWN
= wxEVT_FIRST
+ 305;
125 const wxEventType wxEVT_SCROLL_THUMBTRACK
= wxEVT_FIRST
+ 306;
128 * Scroll events from wxWindow
130 const wxEventType wxEVT_SCROLLWIN_TOP
= wxEVT_FIRST
+ 320;
131 const wxEventType wxEVT_SCROLLWIN_BOTTOM
= wxEVT_FIRST
+ 321;
132 const wxEventType wxEVT_SCROLLWIN_LINEUP
= wxEVT_FIRST
+ 322;
133 const wxEventType wxEVT_SCROLLWIN_LINEDOWN
= wxEVT_FIRST
+ 323;
134 const wxEventType wxEVT_SCROLLWIN_PAGEUP
= wxEVT_FIRST
+ 324;
135 const wxEventType wxEVT_SCROLLWIN_PAGEDOWN
= wxEVT_FIRST
+ 325;
136 const wxEventType wxEVT_SCROLLWIN_THUMBTRACK
= wxEVT_FIRST
+ 326;
141 const wxEventType wxEVT_SIZE
= wxEVT_FIRST
+ 400;
142 const wxEventType wxEVT_MOVE
= wxEVT_FIRST
+ 401;
143 const wxEventType wxEVT_CLOSE_WINDOW
= wxEVT_FIRST
+ 402;
144 const wxEventType wxEVT_END_SESSION
= wxEVT_FIRST
+ 403;
145 const wxEventType wxEVT_QUERY_END_SESSION
= wxEVT_FIRST
+ 404;
146 const wxEventType wxEVT_ACTIVATE_APP
= wxEVT_FIRST
+ 405;
147 const wxEventType wxEVT_POWER
= wxEVT_FIRST
+ 406;
148 const wxEventType wxEVT_ACTIVATE
= wxEVT_FIRST
+ 409;
149 const wxEventType wxEVT_CREATE
= wxEVT_FIRST
+ 410;
150 const wxEventType wxEVT_DESTROY
= wxEVT_FIRST
+ 411;
151 const wxEventType wxEVT_SHOW
= wxEVT_FIRST
+ 412;
152 const wxEventType wxEVT_ICONIZE
= wxEVT_FIRST
+ 413;
153 const wxEventType wxEVT_MAXIMIZE
= wxEVT_FIRST
+ 414;
154 const wxEventType wxEVT_MOUSE_CAPTURE_CHANGED
= wxEVT_FIRST
+ 415;
155 const wxEventType wxEVT_PAINT
= wxEVT_FIRST
+ 416;
156 const wxEventType wxEVT_ERASE_BACKGROUND
= wxEVT_FIRST
+ 417;
157 const wxEventType wxEVT_NC_PAINT
= wxEVT_FIRST
+ 418;
158 const wxEventType wxEVT_PAINT_ICON
= wxEVT_FIRST
+ 419;
159 const wxEventType wxEVT_MENU_CHAR
= wxEVT_FIRST
+ 420;
160 const wxEventType wxEVT_MENU_INIT
= wxEVT_FIRST
+ 421;
161 const wxEventType wxEVT_MENU_HIGHLIGHT
= wxEVT_FIRST
+ 422;
162 const wxEventType wxEVT_POPUP_MENU_INIT
= wxEVT_FIRST
+ 423;
163 const wxEventType wxEVT_CONTEXT_MENU
= wxEVT_FIRST
+ 424;
164 const wxEventType wxEVT_SYS_COLOUR_CHANGED
= wxEVT_FIRST
+ 425;
165 const wxEventType wxEVT_SETTING_CHANGED
= wxEVT_FIRST
+ 426;
166 const wxEventType wxEVT_QUERY_NEW_PALETTE
= wxEVT_FIRST
+ 427;
167 const wxEventType wxEVT_PALETTE_CHANGED
= wxEVT_FIRST
+ 428;
168 const wxEventType wxEVT_JOY_BUTTON_DOWN
= wxEVT_FIRST
+ 429;
169 const wxEventType wxEVT_JOY_BUTTON_UP
= wxEVT_FIRST
+ 430;
170 const wxEventType wxEVT_JOY_MOVE
= wxEVT_FIRST
+ 431;
171 const wxEventType wxEVT_JOY_ZMOVE
= wxEVT_FIRST
+ 432;
172 const wxEventType wxEVT_DROP_FILES
= wxEVT_FIRST
+ 433;
173 const wxEventType wxEVT_DRAW_ITEM
= wxEVT_FIRST
+ 434;
174 const wxEventType wxEVT_MEASURE_ITEM
= wxEVT_FIRST
+ 435;
175 const wxEventType wxEVT_COMPARE_ITEM
= wxEVT_FIRST
+ 436;
176 const wxEventType wxEVT_INIT_DIALOG
= wxEVT_FIRST
+ 437;
177 const wxEventType wxEVT_IDLE
= wxEVT_FIRST
+ 438;
178 const wxEventType wxEVT_UPDATE_UI
= wxEVT_FIRST
+ 439;
181 const wxEventType wxEVT_END_PROCESS
= wxEVT_FIRST
+ 440;
184 const wxEventType wxEVT_DIALUP_CONNECTED
= wxEVT_FIRST
+ 450;
185 const wxEventType wxEVT_DIALUP_DISCONNECTED
= wxEVT_FIRST
+ 451;
187 /* Generic command events */
188 /* Note: a click is a higher-level event than button down/up */
189 const wxEventType wxEVT_COMMAND_LEFT_CLICK
= wxEVT_FIRST
+ 500;
190 const wxEventType wxEVT_COMMAND_LEFT_DCLICK
= wxEVT_FIRST
+ 501;
191 const wxEventType wxEVT_COMMAND_RIGHT_CLICK
= wxEVT_FIRST
+ 502;
192 const wxEventType wxEVT_COMMAND_RIGHT_DCLICK
= wxEVT_FIRST
+ 503;
193 const wxEventType wxEVT_COMMAND_SET_FOCUS
= wxEVT_FIRST
+ 504;
194 const wxEventType wxEVT_COMMAND_KILL_FOCUS
= wxEVT_FIRST
+ 505;
195 const wxEventType wxEVT_COMMAND_ENTER
= wxEVT_FIRST
+ 506;
197 /* Tree control event types */
198 const wxEventType wxEVT_COMMAND_TREE_BEGIN_DRAG
= wxEVT_FIRST
+ 600;
199 const wxEventType wxEVT_COMMAND_TREE_BEGIN_RDRAG
= wxEVT_FIRST
+ 601;
200 const wxEventType wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
= wxEVT_FIRST
+ 602;
201 const wxEventType wxEVT_COMMAND_TREE_END_LABEL_EDIT
= wxEVT_FIRST
+ 603;
202 const wxEventType wxEVT_COMMAND_TREE_DELETE_ITEM
= wxEVT_FIRST
+ 604;
203 const wxEventType wxEVT_COMMAND_TREE_GET_INFO
= wxEVT_FIRST
+ 605;
204 const wxEventType wxEVT_COMMAND_TREE_SET_INFO
= wxEVT_FIRST
+ 606;
205 const wxEventType wxEVT_COMMAND_TREE_ITEM_EXPANDED
= wxEVT_FIRST
+ 607;
206 const wxEventType wxEVT_COMMAND_TREE_ITEM_EXPANDING
= wxEVT_FIRST
+ 608;
207 const wxEventType wxEVT_COMMAND_TREE_ITEM_COLLAPSED
= wxEVT_FIRST
+ 609;
208 const wxEventType wxEVT_COMMAND_TREE_ITEM_COLLAPSING
= wxEVT_FIRST
+ 610;
209 const wxEventType wxEVT_COMMAND_TREE_SEL_CHANGED
= wxEVT_FIRST
+ 611;
210 const wxEventType wxEVT_COMMAND_TREE_SEL_CHANGING
= wxEVT_FIRST
+ 612;
211 const wxEventType wxEVT_COMMAND_TREE_KEY_DOWN
= wxEVT_FIRST
+ 613;
212 const wxEventType wxEVT_COMMAND_TREE_ITEM_ACTIVATED
= wxEVT_FIRST
+ 614;
213 const wxEventType wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK
= wxEVT_FIRST
+ 615;
214 const wxEventType wxEVT_COMMAND_TREE_ITEM_MIDDLE_CLICK
= wxEVT_FIRST
+ 616;
216 /* List control event types */
217 const wxEventType wxEVT_COMMAND_LIST_BEGIN_DRAG
= wxEVT_FIRST
+ 700;
218 const wxEventType wxEVT_COMMAND_LIST_BEGIN_RDRAG
= wxEVT_FIRST
+ 701;
219 const wxEventType wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT
= wxEVT_FIRST
+ 702;
220 const wxEventType wxEVT_COMMAND_LIST_END_LABEL_EDIT
= wxEVT_FIRST
+ 703;
221 const wxEventType wxEVT_COMMAND_LIST_DELETE_ITEM
= wxEVT_FIRST
+ 704;
222 const wxEventType wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS
= wxEVT_FIRST
+ 705;
223 const wxEventType wxEVT_COMMAND_LIST_GET_INFO
= wxEVT_FIRST
+ 706;
224 const wxEventType wxEVT_COMMAND_LIST_SET_INFO
= wxEVT_FIRST
+ 707;
225 const wxEventType wxEVT_COMMAND_LIST_ITEM_SELECTED
= wxEVT_FIRST
+ 708;
226 const wxEventType wxEVT_COMMAND_LIST_ITEM_DESELECTED
= wxEVT_FIRST
+ 709;
227 const wxEventType wxEVT_COMMAND_LIST_KEY_DOWN
= wxEVT_FIRST
+ 710;
228 const wxEventType wxEVT_COMMAND_LIST_INSERT_ITEM
= wxEVT_FIRST
+ 711;
229 const wxEventType wxEVT_COMMAND_LIST_COL_CLICK
= wxEVT_FIRST
+ 712;
230 const wxEventType wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK
= wxEVT_FIRST
+ 713;
231 const wxEventType wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK
= wxEVT_FIRST
+ 714;
232 const wxEventType wxEVT_COMMAND_LIST_ITEM_ACTIVATED
= wxEVT_FIRST
+ 715;
234 /* Tab and notebook control event types */
235 const wxEventType wxEVT_COMMAND_TAB_SEL_CHANGED
= wxEVT_FIRST
+ 800;
236 const wxEventType wxEVT_COMMAND_TAB_SEL_CHANGING
= wxEVT_FIRST
+ 801;
238 #if defined(__BORLANDC__) && defined(__WIN16__)
239 /* For 16-bit BC++, these 2 are identical (truncated) */
240 const wxEventType wxEVT_COMMAND_NB_PAGE_CHANGED
= wxEVT_FIRST
+ 802;
241 const wxEventType wxEVT_COMMAND_NB_PAGE_CHANGING
= wxEVT_FIRST
+ 803;
243 const wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
= wxEVT_FIRST
+ 802;
244 const wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
= wxEVT_FIRST
+ 803;
247 /* Splitter events */
248 const wxEventType wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGED
= wxEVT_FIRST
+ 850;
249 const wxEventType wxEVT_COMMAND_SPLITTER_SASH_POS_CHANGING
= wxEVT_FIRST
+ 851;
250 const wxEventType wxEVT_COMMAND_SPLITTER_DOUBLECLICKED
= wxEVT_FIRST
+ 852;
251 const wxEventType wxEVT_COMMAND_SPLITTER_UNSPLIT
= wxEVT_FIRST
+ 853;
254 const wxEventType wxEVT_WIZARD_PAGE_CHANGED
= wxEVT_FIRST
+ 900;
255 const wxEventType wxEVT_WIZARD_PAGE_CHANGING
= wxEVT_FIRST
+ 901;
256 const wxEventType wxEVT_WIZARD_CANCEL
= wxEVT_FIRST
+ 902;
258 /* Calendar events */
259 const wxEventType wxEVT_CALENDAR_SEL_CHANGED
= wxEVT_FIRST
+ 950;
260 const wxEventType wxEVT_CALENDAR_DAY_CHANGED
= wxEVT_FIRST
+ 951;
261 const wxEventType wxEVT_CALENDAR_MONTH_CHANGED
= wxEVT_FIRST
+ 952;
262 const wxEventType wxEVT_CALENDAR_YEAR_CHANGED
= wxEVT_FIRST
+ 953;
263 const wxEventType wxEVT_CALENDAR_DOUBLECLICKED
= wxEVT_FIRST
+ 954;
264 const wxEventType wxEVT_CALENDAR_WEEKDAY_CLICKED
= wxEVT_FIRST
+ 955;
266 const wxEventType wxEVT_USER_FIRST
= wxEVT_FIRST
+ 2000;
268 #endif // VisualAge C++ V4.0
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
)
309 const wxEventTable
*wxEvtHandler::GetEventTable() const
310 { return &wxEvtHandler::sm_eventTable
; }
312 const wxEventTable
wxEvtHandler::sm_eventTable
=
313 { (const wxEventTable
*)NULL
, &wxEvtHandler::sm_eventTableEntries
[0] };
315 const wxEventTableEntry
wxEvtHandler::sm_eventTableEntries
[] =
316 { { 0, 0, 0, (wxObjectEventFunction
) NULL
, (wxObject
*) NULL
} };
319 // ----------------------------------------------------------------------------
321 // ----------------------------------------------------------------------------
323 // To put pending event handlers
324 wxList
*wxPendingEvents
= (wxList
*)NULL
;
327 // protects wxPendingEvents list
328 wxCriticalSection
*wxPendingEventsLocker
= (wxCriticalSection
*)NULL
;
331 // ============================================================================
333 // ============================================================================
335 // ----------------------------------------------------------------------------
337 // ----------------------------------------------------------------------------
340 * General wxWindows events, covering
341 * all interesting things that might happen (button clicking, resizing,
342 * setting text in widgets, etc.).
344 * For each completely new event type, derive a new event class.
348 wxEvent::wxEvent(int theId
)
350 m_eventType
= wxEVT_NULL
;
351 m_eventObject
= (wxObject
*) NULL
;
355 m_callbackUserData
= (wxObject
*) NULL
;
356 m_isCommandEvent
= FALSE
;
359 void wxEvent::CopyObject(wxObject
& object_dest
) const
361 wxEvent
*obj
= (wxEvent
*)&object_dest
;
362 wxObject::CopyObject(object_dest
);
364 obj
->m_eventType
= m_eventType
;
365 obj
->m_eventObject
= m_eventObject
;
366 obj
->m_timeStamp
= m_timeStamp
;
368 obj
->m_skipped
= m_skipped
;
369 obj
->m_callbackUserData
= m_callbackUserData
;
370 obj
->m_isCommandEvent
= m_isCommandEvent
;
380 wxCommandEvent::wxCommandEvent(wxEventType commandType
, int theId
)
382 m_eventType
= commandType
;
383 m_clientData
= (char *) NULL
;
384 m_clientObject
= (wxClientData
*) NULL
;
388 m_commandString
= wxEmptyString
;
389 m_isCommandEvent
= TRUE
;
392 void wxCommandEvent::CopyObject(wxObject
& obj_d
) const
394 wxCommandEvent
*obj
= (wxCommandEvent
*)&obj_d
;
396 wxEvent::CopyObject(obj_d
);
398 obj
->m_clientData
= m_clientData
;
399 obj
->m_clientObject
= m_clientObject
;
400 obj
->m_extraLong
= m_extraLong
;
401 obj
->m_commandInt
= m_commandInt
;
402 obj
->m_commandString
= m_commandString
;
409 void wxNotifyEvent::CopyObject(wxObject
& obj_d
) const
411 wxNotifyEvent
*obj
= (wxNotifyEvent
*)&obj_d
;
413 wxEvent::CopyObject(obj_d
);
415 if (!m_bAllow
) obj
->Veto();
422 wxScrollEvent::wxScrollEvent(wxEventType commandType
,
426 : wxCommandEvent(commandType
, id
)
428 m_extraLong
= orient
;
430 m_isScrolling
= TRUE
;
433 void wxScrollEvent::CopyObject(wxObject
& obj_d
) const
435 wxScrollEvent
*obj
= (wxScrollEvent
*)&obj_d
;
437 wxCommandEvent::CopyObject(obj_d
);
439 obj
->m_isScrolling
= m_isScrolling
;
446 wxScrollWinEvent::wxScrollWinEvent(wxEventType commandType
,
450 m_eventType
= commandType
;
451 m_extraLong
= orient
;
453 m_isScrolling
= TRUE
;
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
;
464 obj
->m_isScrolling
= m_isScrolling
;
472 wxMouseEvent::wxMouseEvent(wxEventType commandType
)
474 m_eventType
= commandType
;
477 m_controlDown
= FALSE
;
481 m_middleDown
= FALSE
;
486 void wxMouseEvent::CopyObject(wxObject
& obj_d
) const
488 wxMouseEvent
*obj
= (wxMouseEvent
*)&obj_d
;
490 wxEvent::CopyObject(obj_d
);
492 obj
->m_metaDown
= m_metaDown
;
493 obj
->m_altDown
= m_altDown
;
494 obj
->m_controlDown
= m_controlDown
;
495 obj
->m_shiftDown
= m_shiftDown
;
496 obj
->m_leftDown
= m_leftDown
;
497 obj
->m_rightDown
= m_rightDown
;
498 obj
->m_middleDown
= m_middleDown
;
503 // True if was a button dclick event (1 = left, 2 = middle, 3 = right)
504 // or any button dclick event (but = -1)
505 bool wxMouseEvent::ButtonDClick(int but
) const
510 return (LeftDClick() || MiddleDClick() || RightDClick());
514 return MiddleDClick();
516 return RightDClick();
518 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDClick"));
524 // True if was a button down event (1 = left, 2 = middle, 3 = right)
525 // or any button down event (but = -1)
526 bool wxMouseEvent::ButtonDown(int but
) const
531 return (LeftDown() || MiddleDown() || RightDown());
539 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonDown"));
545 // True if was a button up event (1 = left, 2 = middle, 3 = right)
546 // or any button up event (but = -1)
547 bool wxMouseEvent::ButtonUp(int but
) const
551 return (LeftUp() || MiddleUp() || RightUp());
559 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonUp"));
565 // True if the given button is currently changing state
566 bool wxMouseEvent::Button(int but
) const
570 return (ButtonUp(-1) || ButtonDown(-1) || ButtonDClick(-1));
572 return (LeftDown() || LeftUp() || LeftDClick());
574 return (MiddleDown() || MiddleUp() || MiddleDClick());
576 return (RightDown() || RightUp() || RightDClick());
578 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::Button"));
584 bool wxMouseEvent::ButtonIsDown(int but
) const
588 return (LeftIsDown() || MiddleIsDown() || RightIsDown());
592 return MiddleIsDown();
594 return RightIsDown();
596 wxFAIL_MSG(wxT("invalid parameter in wxMouseEvent::ButtonIsDown"));
602 // Find the logical position of the event given the DC
603 wxPoint
wxMouseEvent::GetLogicalPosition(const wxDC
& dc
) const
605 wxPoint
pt(dc
.DeviceToLogicalX(m_x
), dc
.DeviceToLogicalY(m_y
));
615 wxKeyEvent::wxKeyEvent(wxEventType type
)
619 m_controlDown
= FALSE
;
626 void wxKeyEvent::CopyObject(wxObject
& obj_d
) const
628 wxKeyEvent
*obj
= (wxKeyEvent
*)&obj_d
;
629 wxEvent::CopyObject(obj_d
);
633 obj
->m_keyCode
= m_keyCode
;
635 obj
->m_shiftDown
= m_shiftDown
;
636 obj
->m_controlDown
= m_controlDown
;
637 obj
->m_metaDown
= m_metaDown
;
638 obj
->m_altDown
= m_altDown
;
639 obj
->m_keyCode
= m_keyCode
;
647 void wxSizeEvent::CopyObject(wxObject
& obj_d
) const
649 wxSizeEvent
*obj
= (wxSizeEvent
*)&obj_d
;
650 wxEvent::CopyObject(obj_d
);
652 obj
->m_size
= m_size
;
655 void wxMoveEvent::CopyObject(wxObject
& obj_d
) const
657 wxMoveEvent
*obj
= (wxMoveEvent
*)&obj_d
;
658 wxEvent::CopyObject(obj_d
);
663 void wxEraseEvent::CopyObject(wxObject
& obj_d
) const
665 wxEraseEvent
*obj
= (wxEraseEvent
*)&obj_d
;
666 wxEvent::CopyObject(obj_d
);
671 void wxActivateEvent::CopyObject(wxObject
& obj_d
) const
673 wxActivateEvent
*obj
= (wxActivateEvent
*)&obj_d
;
674 wxEvent::CopyObject(obj_d
);
676 obj
->m_active
= m_active
;
679 void wxMenuEvent::CopyObject(wxObject
& obj_d
) const
681 wxMenuEvent
*obj
= (wxMenuEvent
*)&obj_d
;
682 wxEvent::CopyObject(obj_d
);
684 obj
->m_menuId
= m_menuId
;
687 void wxCloseEvent::CopyObject(wxObject
& obj_d
) const
689 wxCloseEvent
*obj
= (wxCloseEvent
*)&obj_d
;
690 wxEvent::CopyObject(obj_d
);
692 obj
->m_loggingOff
= m_loggingOff
;
693 obj
->m_veto
= m_veto
;
694 #if WXWIN_COMPATIBILITY
695 obj
->m_force
= m_force
;
697 obj
->m_canVeto
= m_canVeto
;
700 void wxShowEvent::CopyObject(wxObject
& obj_d
) const
702 wxShowEvent
*obj
= (wxShowEvent
*)&obj_d
;
703 wxEvent::CopyObject(obj_d
);
705 obj
->m_show
= m_show
;
708 void wxJoystickEvent::CopyObject(wxObject
& obj_d
) const
710 wxJoystickEvent
*obj
= (wxJoystickEvent
*)&obj_d
;
711 wxEvent::CopyObject(obj_d
);
714 obj
->m_zPosition
= m_zPosition
;
715 obj
->m_buttonChange
= m_buttonChange
;
716 obj
->m_buttonState
= m_buttonState
;
717 obj
->m_joyStick
= m_joyStick
;
720 void wxDropFilesEvent::CopyObject(wxObject
& obj_d
) const
722 wxDropFilesEvent
*obj
= (wxDropFilesEvent
*)&obj_d
;
723 wxEvent::CopyObject(obj_d
);
725 obj
->m_noFiles
= m_noFiles
;
727 // TODO: Problem with obj->m_files. It should be deallocated by the
728 // destructor of the event.
731 void wxUpdateUIEvent::CopyObject(wxObject
&obj_d
) const
733 wxUpdateUIEvent
*obj
= (wxUpdateUIEvent
*)&obj_d
;
734 wxEvent::CopyObject(obj_d
);
736 obj
->m_checked
= m_checked
;
737 obj
->m_enabled
= m_enabled
;
738 obj
->m_text
= m_text
;
739 obj
->m_setText
= m_setText
;
740 obj
->m_setChecked
= m_setChecked
;
741 obj
->m_setEnabled
= m_setEnabled
;
744 void wxPaletteChangedEvent::CopyObject(wxObject
&obj_d
) const
746 wxPaletteChangedEvent
*obj
= (wxPaletteChangedEvent
*)&obj_d
;
747 wxEvent::CopyObject(obj_d
);
749 obj
->m_changedWindow
= m_changedWindow
;
752 void wxQueryNewPaletteEvent::CopyObject(wxObject
& obj_d
) const
754 wxQueryNewPaletteEvent
*obj
= (wxQueryNewPaletteEvent
*)&obj_d
;
755 wxEvent::CopyObject(obj_d
);
757 obj
->m_paletteRealized
= m_paletteRealized
;
760 wxWindowCreateEvent::wxWindowCreateEvent(wxWindow
*win
)
763 SetEventType(wxEVT_CREATE
);
767 wxWindowDestroyEvent::wxWindowDestroyEvent(wxWindow
*win
)
770 SetEventType(wxEVT_DESTROY
);
776 void wxIdleEvent::CopyObject(wxObject
& obj_d
) const
778 wxIdleEvent
*obj
= (wxIdleEvent
*)&obj_d
;
779 wxEvent::CopyObject(obj_d
);
781 obj
->m_requestMore
= m_requestMore
;
788 wxEvtHandler::wxEvtHandler()
790 m_nextHandler
= (wxEvtHandler
*) NULL
;
791 m_previousHandler
= (wxEvtHandler
*) NULL
;
793 m_dynamicEvents
= (wxList
*) NULL
;
795 m_pendingEvents
= (wxList
*) NULL
;
797 # if !defined(__VISAGECPP__)
798 m_eventsLocker
= new wxCriticalSection
;
803 wxEvtHandler::~wxEvtHandler()
805 // Takes itself out of the list of handlers
806 if (m_previousHandler
)
807 m_previousHandler
->m_nextHandler
= m_nextHandler
;
810 m_nextHandler
->m_previousHandler
= m_previousHandler
;
814 wxNode
*node
= m_dynamicEvents
->First();
817 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
818 if (entry
->m_callbackUserData
) delete entry
->m_callbackUserData
;
822 delete m_dynamicEvents
;
825 delete m_pendingEvents
;
828 # if !defined(__VISAGECPP__)
829 delete m_eventsLocker
;
836 bool wxEvtHandler::ProcessThreadEvent(wxEvent
& event
)
838 // check that we are really in a child thread
839 wxASSERT_MSG( !wxThread::IsMain(),
840 wxT("use ProcessEvent() in main thread") );
842 AddPendingEvent(event
);
847 #endif // wxUSE_THREADS
849 void wxEvtHandler::AddPendingEvent(wxEvent
& event
)
851 // 1) Add event to list of pending events of this event handler
853 #if defined(__VISAGECPP__)
854 wxENTER_CRIT_SECT( m_eventsLocker
);
856 wxENTER_CRIT_SECT( *m_eventsLocker
);
859 if ( !m_pendingEvents
)
860 m_pendingEvents
= new wxList
;
862 wxEvent
*event2
= (wxEvent
*)event
.Clone();
864 m_pendingEvents
->Append(event2
);
866 #if defined(__VISAGECPP__)
867 wxLEAVE_CRIT_SECT( m_eventsLocker
);
869 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
872 // 2) Add this event handler to list of event handlers that
873 // have pending events.
875 wxENTER_CRIT_SECT(*wxPendingEventsLocker
);
877 if ( !wxPendingEvents
)
878 wxPendingEvents
= new wxList
;
879 wxPendingEvents
->Append(this);
881 wxLEAVE_CRIT_SECT(*wxPendingEventsLocker
);
883 // 3) Inform the system that new pending events are somwehere,
884 // and that these should be processed in idle time.
888 void wxEvtHandler::ProcessPendingEvents()
890 #if defined(__VISAGECPP__)
891 wxENTER_CRIT_SECT( m_eventsLocker
);
893 wxENTER_CRIT_SECT( *m_eventsLocker
);
896 wxNode
*node
= m_pendingEvents
->First();
899 wxEvent
*event
= (wxEvent
*)node
->Data();
902 // In ProcessEvent, new events might get added and
903 // we can safely leave the crtical section here.
904 #if defined(__VISAGECPP__)
905 wxLEAVE_CRIT_SECT( m_eventsLocker
);
907 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
909 ProcessEvent(*event
);
911 #if defined(__VISAGECPP__)
912 wxENTER_CRIT_SECT( m_eventsLocker
);
914 wxENTER_CRIT_SECT( *m_eventsLocker
);
917 node
= m_pendingEvents
->First();
920 #if defined(__VISAGECPP__)
921 wxLEAVE_CRIT_SECT( m_eventsLocker
);
923 wxLEAVE_CRIT_SECT( *m_eventsLocker
);
931 bool wxEvtHandler::ProcessEvent(wxEvent
& event
)
934 // check that our flag corresponds to reality
935 wxASSERT( m_isWindow
== IsKindOf(CLASSINFO(wxWindow
)) );
938 // An event handler can be enabled or disabled
939 if ( GetEvtHandlerEnabled() )
944 What is this? When using GUI threads, a non main
945 threads can send an event and process it itself.
946 This breaks GTK's GUI threads, so please explain.
949 // Check whether we are in a child thread.
950 if ( !wxThread::IsMain() )
951 return ProcessThreadEvent(event
);
954 // Handle per-instance dynamic event tables first
955 if ( m_dynamicEvents
&& SearchDynamicEventTable(event
) )
958 // Then static per-class event tables
959 const wxEventTable
*table
= GetEventTable();
961 #if wxUSE_GUI && wxUSE_VALIDATORS
962 // Try the associated validator first, if this is a window.
963 // Problem: if the event handler of the window has been replaced,
964 // this wxEvtHandler may no longer be a window.
965 // Therefore validators won't be processed if the handler
966 // has been replaced with SetEventHandler.
967 // THIS CAN BE CURED if PushEventHandler is used instead of
968 // SetEventHandler, and then processing will be passed down the
969 // chain of event handlers.
972 wxWindow
*win
= (wxWindow
*)this;
974 // Can only use the validator of the window which
975 // is receiving the event
976 if ( win
== event
.GetEventObject() )
978 wxValidator
*validator
= win
->GetValidator();
979 if ( validator
&& validator
->ProcessEvent(event
) )
987 // Search upwards through the inheritance hierarchy
990 if ( SearchEventTable((wxEventTable
&)*table
, event
) )
992 table
= table
->baseTable
;
996 // Try going down the event handler chain
997 if ( GetNextHandler() )
999 if ( GetNextHandler()->ProcessEvent(event
) )
1004 // Carry on up the parent-child hierarchy,
1005 // but only if event is a command event: it wouldn't
1006 // make sense for a parent to receive a child's size event, for example
1007 if ( m_isWindow
&& event
.IsCommandEvent() )
1009 wxWindow
*win
= (wxWindow
*)this;
1010 wxWindow
*parent
= win
->GetParent();
1011 if (parent
&& !parent
->IsBeingDeleted())
1012 return parent
->GetEventHandler()->ProcessEvent(event
);
1016 // Last try - application object.
1017 if ( wxTheApp
&& (this != wxTheApp
) )
1019 // Special case: don't pass wxEVT_IDLE to wxApp, since it'll always
1020 // swallow it. wxEVT_IDLE is sent explicitly to wxApp so it will be
1021 // processed appropriately via SearchEventTable.
1022 if ( event
.GetEventType() != wxEVT_IDLE
)
1024 if ( wxTheApp
->ProcessEvent(event
) )
1032 bool wxEvtHandler::SearchEventTable(wxEventTable
& table
, wxEvent
& event
)
1035 int commandId
= event
.GetId();
1037 // BC++ doesn't like while (table.entries[i].m_fn)
1040 while (table
.entries
[i
].m_fn
!= 0)
1042 while (table
.entries
[i
].m_fn
!= 0L)
1045 if ((event
.GetEventType() == table
.entries
[i
].m_eventType
) &&
1046 (table
.entries
[i
].m_id
== -1 || // Match, if event spec says any id will do (id == -1)
1047 (table
.entries
[i
].m_lastId
== -1 && commandId
== table
.entries
[i
].m_id
) ||
1048 (table
.entries
[i
].m_lastId
!= -1 &&
1049 (commandId
>= table
.entries
[i
].m_id
&& commandId
<= table
.entries
[i
].m_lastId
))))
1052 event
.m_callbackUserData
= table
.entries
[i
].m_callbackUserData
;
1054 (this->*((wxEventFunction
) (table
.entries
[i
].m_fn
)))(event
);
1056 if ( event
.GetSkipped() )
1066 void wxEvtHandler::Connect( int id
, int lastId
,
1067 wxEventType eventType
,
1068 wxObjectEventFunction func
,
1069 wxObject
*userData
)
1071 wxEventTableEntry
*entry
= new wxEventTableEntry
;
1073 entry
->m_lastId
= lastId
;
1074 entry
->m_eventType
= eventType
;
1076 entry
->m_callbackUserData
= userData
;
1078 if (!m_dynamicEvents
)
1079 m_dynamicEvents
= new wxList
;
1081 m_dynamicEvents
->Append( (wxObject
*) entry
);
1084 bool wxEvtHandler::Disconnect( int id
, int lastId
, wxEventType eventType
,
1085 wxObjectEventFunction func
,
1086 wxObject
*userData
)
1088 if (!m_dynamicEvents
)
1091 wxNode
*node
= m_dynamicEvents
->First();
1094 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
1095 if ((entry
->m_id
== id
) &&
1096 ((entry
->m_lastId
== lastId
) || (lastId
== -1)) &&
1097 ((entry
->m_eventType
== eventType
) || (eventType
== wxEVT_NULL
)) &&
1098 ((entry
->m_fn
== func
) || (func
== (wxObjectEventFunction
)NULL
)) &&
1099 ((entry
->m_callbackUserData
== userData
) || (userData
== (wxObject
*)NULL
)))
1101 if (entry
->m_callbackUserData
) delete entry
->m_callbackUserData
;
1102 m_dynamicEvents
->DeleteNode( node
);
1106 node
= node
->Next();
1111 bool wxEvtHandler::SearchDynamicEventTable( wxEvent
& event
)
1113 wxCHECK_MSG( m_dynamicEvents
, FALSE
,
1114 wxT("caller should check that we have dynamic events") );
1116 int commandId
= event
.GetId();
1118 wxNode
*node
= m_dynamicEvents
->First();
1121 wxEventTableEntry
*entry
= (wxEventTableEntry
*)node
->Data();
1125 // Match, if event spec says any id will do (id == -1)
1126 if ( (event
.GetEventType() == entry
->m_eventType
) &&
1127 (entry
->m_id
== -1 ||
1128 (entry
->m_lastId
== -1 && commandId
== entry
->m_id
) ||
1129 (entry
->m_lastId
!= -1 &&
1130 (commandId
>= entry
->m_id
&& commandId
<= entry
->m_lastId
))) )
1133 event
.m_callbackUserData
= entry
->m_callbackUserData
;
1135 (this->*((wxEventFunction
) (entry
->m_fn
)))(event
);
1137 if (event
.GetSkipped())
1143 node
= node
->Next();
1148 #if WXWIN_COMPATIBILITY
1149 bool wxEvtHandler::OnClose()
1151 if (GetNextHandler())
1152 return GetNextHandler()->OnClose();
1156 #endif // WXWIN_COMPATIBILITY
1160 // Find a window with the focus, that is also a descendant of the given window.
1161 // This is used to determine the window to initially send commands to.
1162 wxWindow
* wxFindFocusDescendant(wxWindow
* ancestor
)
1164 // Process events starting with the window with the focus, if any.
1165 wxWindow
* focusWin
= wxWindow::FindFocus();
1166 wxWindow
* win
= focusWin
;
1168 // Check if this is a descendant of this frame.
1169 // If not, win will be set to NULL.
1172 if (win
== ancestor
)
1175 win
= win
->GetParent();
1177 if (win
== (wxWindow
*) NULL
)
1178 focusWin
= (wxWindow
*) NULL
;