rolled back exceptions handling patch, it relied on incorrect assumption about vtables
[wxWidgets.git] / include / wx / event.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/event.h
3 // Purpose: Event classes
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_EVENT_H__
13 #define _WX_EVENT_H__
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) && !defined(__EMX__)
16 // Some older compilers (such as EMX) cannot handle
17 // #pragma interface/implementation correctly, iff
18 // #pragma implementation is used in _two_ translation
19 // units (as created by e.g. event.cpp compiled for
20 // libwx_base and event.cpp compiled for libwx_gui_core).
21 // So we must not use those pragmas for those compilers in
22 // such files.
23 #pragma interface "event.h"
24 #endif
25
26 #include "wx/defs.h"
27 #include "wx/object.h"
28 #include "wx/clntdata.h"
29
30 #if wxUSE_GUI
31 #include "wx/gdicmn.h"
32 #include "wx/cursor.h"
33 #endif
34
35 #include "wx/thread.h"
36
37 #include "wx/dynarray.h"
38
39 // ----------------------------------------------------------------------------
40 // forward declarations
41 // ----------------------------------------------------------------------------
42
43 class WXDLLIMPEXP_BASE wxList;
44
45 #if wxUSE_GUI
46 class WXDLLIMPEXP_CORE wxDC;
47 class WXDLLIMPEXP_CORE wxMenu;
48 class WXDLLIMPEXP_CORE wxWindow;
49 class WXDLLIMPEXP_CORE wxWindowBase;
50 #endif // wxUSE_GUI
51
52 class WXDLLIMPEXP_BASE wxEvtHandler;
53
54 // ----------------------------------------------------------------------------
55 // Event types
56 // ----------------------------------------------------------------------------
57
58 typedef int wxEventType;
59
60 // this is used to make the event table entry type safe, so that for an event
61 // handler only a function with proper parameter list can be given.
62 #define wxStaticCastEvent(type, val) wx_static_cast(type, val)
63
64 // in previous versions of wxWidgets the event types used to be constants
65 // which created difficulties with custom/user event types definition
66 //
67 // starting from wxWidgets 2.4 the event types are now dynamically assigned
68 // using wxNewEventType() which solves this problem, however at price of
69 // several incompatibilities:
70 //
71 // a) event table macros declaration changed, it now uses wxEventTableEntry
72 // ctor instead of initialisation from an agregate - the macro
73 // DECLARE_EVENT_TABLE_ENTRY may be used to write code which can compile
74 // with all versions of wxWidgets
75 //
76 // b) event types can't be used as switch() cases as they're not really
77 // constant any more - there is no magic solution here, you just have to
78 // change the switch()es to if()s
79 //
80 // if these are real problems for you, define WXWIN_COMPATIBILITY_EVENT_TYPES
81 // to get 100% old behaviour, however you won't be able to use the libraries
82 // using the new dynamic event type allocation in such case, so avoid it if
83 // possible.
84
85 #if WXWIN_COMPATIBILITY_EVENT_TYPES
86
87 #define DECLARE_EVENT_TABLE_ENTRY(type, winid, idLast, fn, obj) \
88 { type, winid, idLast, fn, obj }
89
90 #define BEGIN_DECLARE_EVENT_TYPES() enum {
91 #define END_DECLARE_EVENT_TYPES() };
92 #define DECLARE_EVENT_TYPE(name, value) name = wxEVT_FIRST + value,
93 #define DECLARE_LOCAL_EVENT_TYPE(name, value) name = wxEVT_USER_FIRST + value,
94 #define DECLARE_EXPORTED_EVENT_TYPE(expdecl, name, value) \
95 DECLARE_LOCAL_EVENT_TYPE(name, value)
96 #define DEFINE_EVENT_TYPE(name)
97 #define DEFINE_LOCAL_EVENT_TYPE(name)
98
99
100 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
101
102 #define DECLARE_EVENT_TABLE_ENTRY(type, winid, idLast, fn, obj) \
103 wxEventTableEntry(type, winid, idLast, fn, obj)
104
105 #define EMPTY_PARAMETER_VALUE /* Fake macro parameter value */
106
107 #define BEGIN_DECLARE_EVENT_TYPES()
108 #define END_DECLARE_EVENT_TYPES()
109 #define DECLARE_EXPORTED_EVENT_TYPE(expdecl, name, value) \
110 extern expdecl const wxEventType name;
111 #define DECLARE_EVENT_TYPE(name, value) \
112 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE, name, value)
113 #define DECLARE_LOCAL_EVENT_TYPE(name, value) \
114 DECLARE_EXPORTED_EVENT_TYPE(EMPTY_PARAMETER_VALUE, name, value)
115 #define DEFINE_EVENT_TYPE(name) const wxEventType name = wxNewEventType();
116 #define DEFINE_LOCAL_EVENT_TYPE(name) DEFINE_EVENT_TYPE(name)
117
118 // generate a new unique event type
119 extern WXDLLIMPEXP_BASE wxEventType wxNewEventType();
120
121 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
122
123 BEGIN_DECLARE_EVENT_TYPES()
124
125 #if WXWIN_COMPATIBILITY_EVENT_TYPES
126 wxEVT_NULL = 0,
127 wxEVT_FIRST = 10000,
128 wxEVT_USER_FIRST = wxEVT_FIRST + 2000,
129 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
130 // it is important to still have these as constants to avoid
131 // initialization order related problems
132 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_BASE, wxEVT_NULL, 0)
133 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_BASE, wxEVT_FIRST, 10000)
134 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_BASE, wxEVT_USER_FIRST, wxEVT_FIRST + 2000)
135 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES/!WXWIN_COMPATIBILITY_EVENT_TYPES
136
137 DECLARE_EVENT_TYPE(wxEVT_COMMAND_BUTTON_CLICKED, 1)
138 DECLARE_EVENT_TYPE(wxEVT_COMMAND_CHECKBOX_CLICKED, 2)
139 DECLARE_EVENT_TYPE(wxEVT_COMMAND_CHOICE_SELECTED, 3)
140 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_SELECTED, 4)
141 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, 5)
142 DECLARE_EVENT_TYPE(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, 6)
143 // now they are in wx/textctrl.h
144 #if WXWIN_COMPATIBILITY_EVENT_TYPES
145 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TEXT_UPDATED, 7)
146 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TEXT_ENTER, 8)
147 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TEXT_URL, 13)
148 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TEXT_MAXLEN, 14)
149 #endif // WXWIN_COMPATIBILITY_EVENT_TYPES
150 DECLARE_EVENT_TYPE(wxEVT_COMMAND_MENU_SELECTED, 9)
151 DECLARE_EVENT_TYPE(wxEVT_COMMAND_SLIDER_UPDATED, 10)
152 DECLARE_EVENT_TYPE(wxEVT_COMMAND_RADIOBOX_SELECTED, 11)
153 DECLARE_EVENT_TYPE(wxEVT_COMMAND_RADIOBUTTON_SELECTED, 12)
154
155 // wxEVT_COMMAND_SCROLLBAR_UPDATED is now obsolete since we use
156 // wxEVT_SCROLL... events
157
158 DECLARE_EVENT_TYPE(wxEVT_COMMAND_SCROLLBAR_UPDATED, 13)
159 DECLARE_EVENT_TYPE(wxEVT_COMMAND_VLBOX_SELECTED, 14)
160 DECLARE_EVENT_TYPE(wxEVT_COMMAND_COMBOBOX_SELECTED, 15)
161 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TOOL_RCLICKED, 16)
162 DECLARE_EVENT_TYPE(wxEVT_COMMAND_TOOL_ENTER, 17)
163 DECLARE_EVENT_TYPE(wxEVT_COMMAND_SPINCTRL_UPDATED, 18)
164
165 // Sockets and timers send events, too
166 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_BASE, wxEVT_SOCKET, 50)
167 DECLARE_EVENT_TYPE(wxEVT_TIMER , 80)
168
169 // Mouse event types
170 DECLARE_EVENT_TYPE(wxEVT_LEFT_DOWN, 100)
171 DECLARE_EVENT_TYPE(wxEVT_LEFT_UP, 101)
172 DECLARE_EVENT_TYPE(wxEVT_MIDDLE_DOWN, 102)
173 DECLARE_EVENT_TYPE(wxEVT_MIDDLE_UP, 103)
174 DECLARE_EVENT_TYPE(wxEVT_RIGHT_DOWN, 104)
175 DECLARE_EVENT_TYPE(wxEVT_RIGHT_UP, 105)
176 DECLARE_EVENT_TYPE(wxEVT_MOTION, 106)
177 DECLARE_EVENT_TYPE(wxEVT_ENTER_WINDOW, 107)
178 DECLARE_EVENT_TYPE(wxEVT_LEAVE_WINDOW, 108)
179 DECLARE_EVENT_TYPE(wxEVT_LEFT_DCLICK, 109)
180 DECLARE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK, 110)
181 DECLARE_EVENT_TYPE(wxEVT_RIGHT_DCLICK, 111)
182 DECLARE_EVENT_TYPE(wxEVT_SET_FOCUS, 112)
183 DECLARE_EVENT_TYPE(wxEVT_KILL_FOCUS, 113)
184 DECLARE_EVENT_TYPE(wxEVT_CHILD_FOCUS, 114)
185 DECLARE_EVENT_TYPE(wxEVT_MOUSEWHEEL, 115)
186
187 // Non-client mouse events
188 DECLARE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN, 200)
189 DECLARE_EVENT_TYPE(wxEVT_NC_LEFT_UP, 201)
190 DECLARE_EVENT_TYPE(wxEVT_NC_MIDDLE_DOWN, 202)
191 DECLARE_EVENT_TYPE(wxEVT_NC_MIDDLE_UP, 203)
192 DECLARE_EVENT_TYPE(wxEVT_NC_RIGHT_DOWN, 204)
193 DECLARE_EVENT_TYPE(wxEVT_NC_RIGHT_UP, 205)
194 DECLARE_EVENT_TYPE(wxEVT_NC_MOTION, 206)
195 DECLARE_EVENT_TYPE(wxEVT_NC_ENTER_WINDOW, 207)
196 DECLARE_EVENT_TYPE(wxEVT_NC_LEAVE_WINDOW, 208)
197 DECLARE_EVENT_TYPE(wxEVT_NC_LEFT_DCLICK, 209)
198 DECLARE_EVENT_TYPE(wxEVT_NC_MIDDLE_DCLICK, 210)
199 DECLARE_EVENT_TYPE(wxEVT_NC_RIGHT_DCLICK, 211)
200
201 // Character input event type
202 DECLARE_EVENT_TYPE(wxEVT_CHAR, 212)
203 DECLARE_EVENT_TYPE(wxEVT_CHAR_HOOK, 213)
204 DECLARE_EVENT_TYPE(wxEVT_NAVIGATION_KEY, 214)
205 DECLARE_EVENT_TYPE(wxEVT_KEY_DOWN, 215)
206 DECLARE_EVENT_TYPE(wxEVT_KEY_UP, 216)
207 #if wxUSE_HOTKEY
208 DECLARE_EVENT_TYPE(wxEVT_HOTKEY, 217)
209 #endif
210 // Set cursor event
211 DECLARE_EVENT_TYPE(wxEVT_SET_CURSOR, 230)
212
213 // wxScrollBar and wxSlider event identifiers
214 DECLARE_EVENT_TYPE(wxEVT_SCROLL_TOP, 300)
215 DECLARE_EVENT_TYPE(wxEVT_SCROLL_BOTTOM, 301)
216 DECLARE_EVENT_TYPE(wxEVT_SCROLL_LINEUP, 302)
217 DECLARE_EVENT_TYPE(wxEVT_SCROLL_LINEDOWN, 303)
218 DECLARE_EVENT_TYPE(wxEVT_SCROLL_PAGEUP, 304)
219 DECLARE_EVENT_TYPE(wxEVT_SCROLL_PAGEDOWN, 305)
220 DECLARE_EVENT_TYPE(wxEVT_SCROLL_THUMBTRACK, 306)
221 DECLARE_EVENT_TYPE(wxEVT_SCROLL_THUMBRELEASE, 307)
222 DECLARE_EVENT_TYPE(wxEVT_SCROLL_CHANGED, 308)
223
224 // Scroll events from wxWindow
225 DECLARE_EVENT_TYPE(wxEVT_SCROLLWIN_TOP, 320)
226 DECLARE_EVENT_TYPE(wxEVT_SCROLLWIN_BOTTOM, 321)
227 DECLARE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEUP, 322)
228 DECLARE_EVENT_TYPE(wxEVT_SCROLLWIN_LINEDOWN, 323)
229 DECLARE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEUP, 324)
230 DECLARE_EVENT_TYPE(wxEVT_SCROLLWIN_PAGEDOWN, 325)
231 DECLARE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBTRACK, 326)
232 DECLARE_EVENT_TYPE(wxEVT_SCROLLWIN_THUMBRELEASE, 327)
233
234 // System events
235 DECLARE_EVENT_TYPE(wxEVT_SIZE, 400)
236 DECLARE_EVENT_TYPE(wxEVT_MOVE, 401)
237 DECLARE_EVENT_TYPE(wxEVT_CLOSE_WINDOW, 402)
238 DECLARE_EVENT_TYPE(wxEVT_END_SESSION, 403)
239 DECLARE_EVENT_TYPE(wxEVT_QUERY_END_SESSION, 404)
240 DECLARE_EVENT_TYPE(wxEVT_ACTIVATE_APP, 405)
241 DECLARE_EVENT_TYPE(wxEVT_POWER, 406)
242 DECLARE_EVENT_TYPE(wxEVT_ACTIVATE, 409)
243 DECLARE_EVENT_TYPE(wxEVT_CREATE, 410)
244 DECLARE_EVENT_TYPE(wxEVT_DESTROY, 411)
245 DECLARE_EVENT_TYPE(wxEVT_SHOW, 412)
246 DECLARE_EVENT_TYPE(wxEVT_ICONIZE, 413)
247 DECLARE_EVENT_TYPE(wxEVT_MAXIMIZE, 414)
248 DECLARE_EVENT_TYPE(wxEVT_MOUSE_CAPTURE_CHANGED, 415)
249 DECLARE_EVENT_TYPE(wxEVT_PAINT, 416)
250 DECLARE_EVENT_TYPE(wxEVT_ERASE_BACKGROUND, 417)
251 DECLARE_EVENT_TYPE(wxEVT_NC_PAINT, 418)
252 DECLARE_EVENT_TYPE(wxEVT_PAINT_ICON, 419)
253 DECLARE_EVENT_TYPE(wxEVT_MENU_OPEN, 420)
254 DECLARE_EVENT_TYPE(wxEVT_MENU_CLOSE, 421)
255 DECLARE_EVENT_TYPE(wxEVT_MENU_HIGHLIGHT, 422)
256 // DECLARE_EVENT_TYPE(wxEVT_POPUP_MENU_INIT, 423) -- free slot
257 DECLARE_EVENT_TYPE(wxEVT_CONTEXT_MENU, 424)
258 DECLARE_EVENT_TYPE(wxEVT_SYS_COLOUR_CHANGED, 425)
259 DECLARE_EVENT_TYPE(wxEVT_DISPLAY_CHANGED, 426)
260 DECLARE_EVENT_TYPE(wxEVT_SETTING_CHANGED, 427)
261 DECLARE_EVENT_TYPE(wxEVT_QUERY_NEW_PALETTE, 428)
262 DECLARE_EVENT_TYPE(wxEVT_PALETTE_CHANGED, 429)
263 DECLARE_EVENT_TYPE(wxEVT_JOY_BUTTON_DOWN, 430)
264 DECLARE_EVENT_TYPE(wxEVT_JOY_BUTTON_UP, 431)
265 DECLARE_EVENT_TYPE(wxEVT_JOY_MOVE, 432)
266 DECLARE_EVENT_TYPE(wxEVT_JOY_ZMOVE, 433)
267 DECLARE_EVENT_TYPE(wxEVT_DROP_FILES, 434)
268 DECLARE_EVENT_TYPE(wxEVT_DRAW_ITEM, 435)
269 DECLARE_EVENT_TYPE(wxEVT_MEASURE_ITEM, 436)
270 DECLARE_EVENT_TYPE(wxEVT_COMPARE_ITEM, 437)
271 DECLARE_EVENT_TYPE(wxEVT_INIT_DIALOG, 438)
272 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_BASE, wxEVT_IDLE, 439)
273 DECLARE_EVENT_TYPE(wxEVT_UPDATE_UI, 440)
274 DECLARE_EVENT_TYPE(wxEVT_SIZING, 441)
275 DECLARE_EVENT_TYPE(wxEVT_MOVING, 442)
276 DECLARE_EVENT_TYPE(wxEVT_HIBERNATE, 443)
277
278 // Generic command events
279 // Note: a click is a higher-level event than button down/up
280 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LEFT_CLICK, 500)
281 DECLARE_EVENT_TYPE(wxEVT_COMMAND_LEFT_DCLICK, 501)
282 DECLARE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_CLICK, 502)
283 DECLARE_EVENT_TYPE(wxEVT_COMMAND_RIGHT_DCLICK, 503)
284 DECLARE_EVENT_TYPE(wxEVT_COMMAND_SET_FOCUS, 504)
285 DECLARE_EVENT_TYPE(wxEVT_COMMAND_KILL_FOCUS, 505)
286 DECLARE_EVENT_TYPE(wxEVT_COMMAND_ENTER, 506)
287
288 // Help events
289 DECLARE_EVENT_TYPE(wxEVT_HELP, 1050)
290 DECLARE_EVENT_TYPE(wxEVT_DETAILED_HELP, 1051)
291
292 END_DECLARE_EVENT_TYPES()
293
294 // these 2 events are the same
295 #define wxEVT_COMMAND_TOOL_CLICKED wxEVT_COMMAND_MENU_SELECTED
296
297 // ----------------------------------------------------------------------------
298 // Compatibility
299 // ----------------------------------------------------------------------------
300
301 // this event is also used by wxComboBox and wxSpinCtrl which don't include
302 // wx/textctrl.h in all ports [yet], so declare it here as well
303 //
304 // still, any new code using it should include wx/textctrl.h explicitly
305 #if !WXWIN_COMPATIBILITY_EVENT_TYPES
306 extern const wxEventType WXDLLIMPEXP_CORE wxEVT_COMMAND_TEXT_UPDATED;
307 #endif
308
309 // the predefined constants for the number of times we propagate event
310 // upwards window child-parent chain
311 enum Propagation_state
312 {
313 // don't propagate it at all
314 wxEVENT_PROPAGATE_NONE = 0,
315
316 // propagate it until it is processed
317 wxEVENT_PROPAGATE_MAX = INT_MAX
318 };
319
320 /*
321 * wxWidgets events, covering all interesting things that might happen
322 * (button clicking, resizing, setting text in widgets, etc.).
323 *
324 * For each completely new event type, derive a new event class.
325 * An event CLASS represents a C++ class defining a range of similar event TYPES;
326 * examples are canvas events, panel item command events.
327 * An event TYPE is a unique identifier for a particular system event,
328 * such as a button press or a listbox deselection.
329 *
330 */
331
332 class WXDLLIMPEXP_BASE wxEvent : public wxObject
333 {
334 private:
335 wxEvent& operator=(const wxEvent&);
336
337 protected:
338 wxEvent(const wxEvent&); // for implementing Clone()
339
340 public:
341 wxEvent(int winid = 0, wxEventType commandType = wxEVT_NULL );
342
343 void SetEventType(wxEventType typ) { m_eventType = typ; }
344 wxEventType GetEventType() const { return m_eventType; }
345 wxObject *GetEventObject() const { return m_eventObject; }
346 void SetEventObject(wxObject *obj) { m_eventObject = obj; }
347 long GetTimestamp() const { return m_timeStamp; }
348 void SetTimestamp(long ts = 0) { m_timeStamp = ts; }
349 int GetId() const { return m_id; }
350 void SetId(int Id) { m_id = Id; }
351
352 // Can instruct event processor that we wish to ignore this event
353 // (treat as if the event table entry had not been found): this must be done
354 // to allow the event processing by the base classes (calling event.Skip()
355 // is the analog of calling the base class version of a virtual function)
356 void Skip(bool skip = true) { m_skipped = skip; }
357 bool GetSkipped() const { return m_skipped; };
358
359 // this function is used to create a copy of the event polymorphically and
360 // all derived classes must implement it because otherwise wxPostEvent()
361 // for them wouldn't work (it needs to do a copy of the event)
362 virtual wxEvent *Clone() const = 0;
363
364 // Implementation only: this test is explicitly anti OO and this function
365 // exists only for optimization purposes.
366 bool IsCommandEvent() const { return m_isCommandEvent; }
367
368 // Determine if this event should be propagating to the parent window.
369 bool ShouldPropagate() const
370 { return m_propagationLevel != wxEVENT_PROPAGATE_NONE; }
371
372 // Stop an event from propagating to its parent window, returns the old
373 // propagation level value
374 int StopPropagation()
375 {
376 int propagationLevel = m_propagationLevel;
377 m_propagationLevel = wxEVENT_PROPAGATE_NONE;
378 return propagationLevel;
379 }
380
381 // Resume the event propagation by restoring the propagation level
382 // (returned by StopPropagation())
383 void ResumePropagation(int propagationLevel)
384 {
385 m_propagationLevel = propagationLevel;
386 }
387
388 #if WXWIN_COMPATIBILITY_2_4
389 public:
390 #else
391 protected:
392 #endif
393 wxObject* m_eventObject;
394 wxEventType m_eventType;
395 long m_timeStamp;
396 int m_id;
397
398 public:
399 // m_callbackUserData is for internal usage only
400 wxObject* m_callbackUserData;
401
402 protected:
403 // the propagation level: while it is positive, we propagate the event to
404 // the parent window (if any)
405 //
406 // this one doesn't have to be public, we don't have to worry about
407 // backwards compatibility as it is new
408 int m_propagationLevel;
409
410 #if WXWIN_COMPATIBILITY_2_4
411 public:
412 #else
413 protected:
414 #endif
415 bool m_skipped;
416 bool m_isCommandEvent;
417
418 private:
419 // it needs to access our m_propagationLevel
420 friend class WXDLLIMPEXP_BASE wxPropagateOnce;
421
422 DECLARE_ABSTRACT_CLASS(wxEvent)
423 };
424
425 /*
426 * Helper class to temporarily change an event not to propagate.
427 */
428 class WXDLLIMPEXP_BASE wxPropagationDisabler
429 {
430 public:
431 wxPropagationDisabler(wxEvent& event) : m_event(event)
432 {
433 m_propagationLevelOld = m_event.StopPropagation();
434 }
435
436 ~wxPropagationDisabler()
437 {
438 m_event.ResumePropagation(m_propagationLevelOld);
439 }
440
441 private:
442 wxEvent& m_event;
443 int m_propagationLevelOld;
444
445 DECLARE_NO_COPY_CLASS(wxPropagationDisabler)
446 };
447
448 /*
449 * Another one to temporarily lower propagation level.
450 */
451 class WXDLLIMPEXP_BASE wxPropagateOnce
452 {
453 public:
454 wxPropagateOnce(wxEvent& event) : m_event(event)
455 {
456 wxASSERT_MSG( m_event.m_propagationLevel > 0,
457 _T("shouldn't be used unless ShouldPropagate()!") );
458
459 m_event.m_propagationLevel--;
460 }
461
462 ~wxPropagateOnce()
463 {
464 m_event.m_propagationLevel++;
465 }
466
467 private:
468 wxEvent& m_event;
469
470 DECLARE_NO_COPY_CLASS(wxPropagateOnce)
471 };
472
473 #if wxUSE_GUI
474
475
476 // Item or menu event class
477 /*
478 wxEVT_COMMAND_BUTTON_CLICKED
479 wxEVT_COMMAND_CHECKBOX_CLICKED
480 wxEVT_COMMAND_CHOICE_SELECTED
481 wxEVT_COMMAND_LISTBOX_SELECTED
482 wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
483 wxEVT_COMMAND_TEXT_UPDATED
484 wxEVT_COMMAND_TEXT_ENTER
485 wxEVT_COMMAND_MENU_SELECTED
486 wxEVT_COMMAND_SLIDER_UPDATED
487 wxEVT_COMMAND_RADIOBOX_SELECTED
488 wxEVT_COMMAND_RADIOBUTTON_SELECTED
489 wxEVT_COMMAND_SCROLLBAR_UPDATED
490 wxEVT_COMMAND_VLBOX_SELECTED
491 wxEVT_COMMAND_COMBOBOX_SELECTED
492 wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
493 */
494
495 #if WXWIN_COMPATIBILITY_2_4
496 // Backwards compatibility for wxCommandEvent::m_commandString, will lead to compilation errors in some cases of usage
497 class WXDLLIMPEXP_CORE wxCommandEvent;
498
499 class WXDLLIMPEXP_CORE wxCommandEventStringHelper
500 {
501 public:
502 wxCommandEventStringHelper(wxCommandEvent * evt)
503 : m_evt(evt)
504 { }
505
506 void operator=(const wxString &str);
507 operator wxString();
508 const wxChar* c_str() const;
509
510 private:
511 wxCommandEvent* m_evt;
512 };
513 #endif
514
515 #ifdef __VISUALC__
516 // 'this' : used in base member initializer list (for m_commandString)
517 #pragma warning(push)
518 #pragma warning(disable:4355)
519 #endif
520
521 class WXDLLIMPEXP_CORE wxCommandEvent : public wxEvent
522 {
523 public:
524 wxCommandEvent(wxEventType commandType = wxEVT_NULL, int winid = 0);
525
526 wxCommandEvent(const wxCommandEvent& event)
527 : wxEvent(event),
528 #if WXWIN_COMPATIBILITY_2_4
529 m_commandString(this),
530 #endif
531 m_cmdString(event.m_cmdString),
532 m_commandInt(event.m_commandInt),
533 m_extraLong(event.m_extraLong),
534 m_clientData(event.m_clientData),
535 m_clientObject(event.m_clientObject)
536 { }
537
538 // Set/Get client data from controls
539 void SetClientData(void* clientData) { m_clientData = clientData; }
540 void *GetClientData() const { return m_clientData; }
541
542 // Set/Get client object from controls
543 void SetClientObject(wxClientData* clientObject) { m_clientObject = clientObject; }
544 wxClientData *GetClientObject() const { return m_clientObject; }
545
546 // Get listbox selection if single-choice
547 int GetSelection() const { return m_commandInt; }
548
549 // Set/Get listbox/choice selection string
550 void SetString(const wxString& s) { m_cmdString = s; }
551 wxString GetString() const;
552
553 // Get checkbox value
554 bool IsChecked() const { return m_commandInt != 0; }
555
556 // true if the listbox event was a selection.
557 bool IsSelection() const { return (m_extraLong != 0); }
558
559 void SetExtraLong(long extraLong) { m_extraLong = extraLong; }
560 long GetExtraLong() const { return m_extraLong; }
561
562 void SetInt(int i) { m_commandInt = i; }
563 long GetInt() const { return m_commandInt; }
564
565 virtual wxEvent *Clone() const { return new wxCommandEvent(*this); }
566
567 #if WXWIN_COMPATIBILITY_2_4
568 public:
569 wxCommandEventStringHelper m_commandString;
570 #else
571 protected:
572 #endif
573 wxString m_cmdString; // String event argument
574 int m_commandInt;
575 long m_extraLong; // Additional information (e.g. select/deselect)
576 void* m_clientData; // Arbitrary client data
577 wxClientData* m_clientObject; // Arbitrary client object
578
579 private:
580 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxCommandEvent)
581 };
582
583 #ifdef __VISUALC__
584 #pragma warning(pop)
585 #endif
586
587 #if WXWIN_COMPATIBILITY_2_4
588 inline void wxCommandEventStringHelper::operator=(const wxString &str)
589 {
590 m_evt->SetString(str);
591 }
592
593 inline wxCommandEventStringHelper::operator wxString()
594 {
595 return m_evt->GetString();
596 }
597
598 inline const wxChar* wxCommandEventStringHelper::c_str() const
599 {
600 return m_evt->GetString().c_str();
601 }
602 #endif
603
604 // this class adds a possibility to react (from the user) code to a control
605 // notification: allow or veto the operation being reported.
606 class WXDLLIMPEXP_CORE wxNotifyEvent : public wxCommandEvent
607 {
608 public:
609 wxNotifyEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
610 : wxCommandEvent(commandType, winid)
611 { m_bAllow = true; }
612
613 wxNotifyEvent(const wxNotifyEvent& event)
614 : wxCommandEvent(event)
615 { m_bAllow = event.m_bAllow; }
616
617 // veto the operation (usually it's allowed by default)
618 void Veto() { m_bAllow = false; }
619
620 // allow the operation if it was disabled by default
621 void Allow() { m_bAllow = true; }
622
623 // for implementation code only: is the operation allowed?
624 bool IsAllowed() const { return m_bAllow; }
625
626 virtual wxEvent *Clone() const { return new wxNotifyEvent(*this); }
627
628 private:
629 bool m_bAllow;
630
631 private:
632 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxNotifyEvent)
633 };
634
635 // Scroll event class, derived form wxCommandEvent. wxScrollEvents are
636 // sent by wxSlider and wxScrollBar.
637 /*
638 wxEVT_SCROLL_TOP
639 wxEVT_SCROLL_BOTTOM
640 wxEVT_SCROLL_LINEUP
641 wxEVT_SCROLL_LINEDOWN
642 wxEVT_SCROLL_PAGEUP
643 wxEVT_SCROLL_PAGEDOWN
644 wxEVT_SCROLL_THUMBTRACK
645 wxEVT_SCROLL_THUMBRELEASE
646 wxEVT_SCROLL_CHANGED
647 */
648
649 class WXDLLIMPEXP_CORE wxScrollEvent : public wxCommandEvent
650 {
651 public:
652 wxScrollEvent(wxEventType commandType = wxEVT_NULL,
653 int winid = 0, int pos = 0, int orient = 0);
654
655 int GetOrientation() const { return (int) m_extraLong; }
656 int GetPosition() const { return m_commandInt; }
657 void SetOrientation(int orient) { m_extraLong = (long) orient; }
658 void SetPosition(int pos) { m_commandInt = pos; }
659
660 virtual wxEvent *Clone() const { return new wxScrollEvent(*this); }
661
662 private:
663 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxScrollEvent)
664 };
665
666 // ScrollWin event class, derived fom wxEvent. wxScrollWinEvents
667 // are sent by wxWindow.
668 /*
669 wxEVT_SCROLLWIN_TOP
670 wxEVT_SCROLLWIN_BOTTOM
671 wxEVT_SCROLLWIN_LINEUP
672 wxEVT_SCROLLWIN_LINEDOWN
673 wxEVT_SCROLLWIN_PAGEUP
674 wxEVT_SCROLLWIN_PAGEDOWN
675 wxEVT_SCROLLWIN_THUMBTRACK
676 wxEVT_SCROLLWIN_THUMBRELEASE
677 */
678
679 class WXDLLIMPEXP_CORE wxScrollWinEvent : public wxEvent
680 {
681 public:
682 wxScrollWinEvent(wxEventType commandType = wxEVT_NULL,
683 int pos = 0, int orient = 0);
684 wxScrollWinEvent(const wxScrollWinEvent & event) : wxEvent(event)
685 { m_commandInt = event.m_commandInt;
686 m_extraLong = event.m_extraLong; }
687
688 int GetOrientation() const { return (int) m_extraLong; }
689 int GetPosition() const { return m_commandInt; }
690 void SetOrientation(int orient) { m_extraLong = (long) orient; }
691 void SetPosition(int pos) { m_commandInt = pos; }
692
693 virtual wxEvent *Clone() const { return new wxScrollWinEvent(*this); }
694
695 #if WXWIN_COMPATIBILITY_2_4
696 public:
697 #else
698 protected:
699 #endif
700 int m_commandInt;
701 long m_extraLong;
702
703 private:
704 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxScrollWinEvent)
705 };
706
707 // Mouse event class
708
709 /*
710 wxEVT_LEFT_DOWN
711 wxEVT_LEFT_UP
712 wxEVT_MIDDLE_DOWN
713 wxEVT_MIDDLE_UP
714 wxEVT_RIGHT_DOWN
715 wxEVT_RIGHT_UP
716 wxEVT_MOTION
717 wxEVT_ENTER_WINDOW
718 wxEVT_LEAVE_WINDOW
719 wxEVT_LEFT_DCLICK
720 wxEVT_MIDDLE_DCLICK
721 wxEVT_RIGHT_DCLICK
722 wxEVT_NC_LEFT_DOWN
723 wxEVT_NC_LEFT_UP,
724 wxEVT_NC_MIDDLE_DOWN,
725 wxEVT_NC_MIDDLE_UP,
726 wxEVT_NC_RIGHT_DOWN,
727 wxEVT_NC_RIGHT_UP,
728 wxEVT_NC_MOTION,
729 wxEVT_NC_ENTER_WINDOW,
730 wxEVT_NC_LEAVE_WINDOW,
731 wxEVT_NC_LEFT_DCLICK,
732 wxEVT_NC_MIDDLE_DCLICK,
733 wxEVT_NC_RIGHT_DCLICK,
734 */
735
736 // the symbolic names for the mouse buttons
737 enum
738 {
739 wxMOUSE_BTN_ANY = -1,
740 wxMOUSE_BTN_NONE = 0,
741 wxMOUSE_BTN_LEFT = 1,
742 wxMOUSE_BTN_MIDDLE = 2,
743 wxMOUSE_BTN_RIGHT = 3
744 };
745
746 class WXDLLIMPEXP_CORE wxMouseEvent : public wxEvent
747 {
748 public:
749 wxMouseEvent(wxEventType mouseType = wxEVT_NULL);
750 wxMouseEvent(const wxMouseEvent& event) : wxEvent(event)
751 { Assign(event); }
752
753 // Was it a button event? (*doesn't* mean: is any button *down*?)
754 bool IsButton() const { return Button(wxMOUSE_BTN_ANY); }
755
756 // Was it a down event from this (or any) button?
757 bool ButtonDown(int but = wxMOUSE_BTN_ANY) const;
758
759 // Was it a dclick event from this (or any) button?
760 bool ButtonDClick(int but = wxMOUSE_BTN_ANY) const;
761
762 // Was it a up event from this (or any) button?
763 bool ButtonUp(int but = wxMOUSE_BTN_ANY) const;
764
765 // Was the given button?
766 bool Button(int but) const;
767
768 // Was the given button in Down state?
769 bool ButtonIsDown(int but) const;
770
771 // Get the button which is changing state (wxMOUSE_BTN_NONE if none)
772 int GetButton() const;
773
774 // Find state of shift/control keys
775 bool ControlDown() const { return m_controlDown; }
776 bool MetaDown() const { return m_metaDown; }
777 bool AltDown() const { return m_altDown; }
778 bool ShiftDown() const { return m_shiftDown; }
779 bool CmdDown() const
780 {
781 #if defined(__WXMAC__) || defined(__WXCOCOA__)
782 return MetaDown();
783 #else
784 return ControlDown();
785 #endif
786 }
787
788 // Find which event was just generated
789 bool LeftDown() const { return (m_eventType == wxEVT_LEFT_DOWN); }
790 bool MiddleDown() const { return (m_eventType == wxEVT_MIDDLE_DOWN); }
791 bool RightDown() const { return (m_eventType == wxEVT_RIGHT_DOWN); }
792
793 bool LeftUp() const { return (m_eventType == wxEVT_LEFT_UP); }
794 bool MiddleUp() const { return (m_eventType == wxEVT_MIDDLE_UP); }
795 bool RightUp() const { return (m_eventType == wxEVT_RIGHT_UP); }
796
797 bool LeftDClick() const { return (m_eventType == wxEVT_LEFT_DCLICK); }
798 bool MiddleDClick() const { return (m_eventType == wxEVT_MIDDLE_DCLICK); }
799 bool RightDClick() const { return (m_eventType == wxEVT_RIGHT_DCLICK); }
800
801 // Find the current state of the mouse buttons (regardless
802 // of current event type)
803 bool LeftIsDown() const { return m_leftDown; }
804 bool MiddleIsDown() const { return m_middleDown; }
805 bool RightIsDown() const { return m_rightDown; }
806
807 // True if a button is down and the mouse is moving
808 bool Dragging() const
809 {
810 return (m_eventType == wxEVT_MOTION) && ButtonIsDown(wxMOUSE_BTN_ANY);
811 }
812
813 // True if the mouse is moving, and no button is down
814 bool Moving() const
815 {
816 return (m_eventType == wxEVT_MOTION) && !ButtonIsDown(wxMOUSE_BTN_ANY);
817 }
818
819 // True if the mouse is just entering the window
820 bool Entering() const { return (m_eventType == wxEVT_ENTER_WINDOW); }
821
822 // True if the mouse is just leaving the window
823 bool Leaving() const { return (m_eventType == wxEVT_LEAVE_WINDOW); }
824
825 // Find the position of the event
826 void GetPosition(wxCoord *xpos, wxCoord *ypos) const
827 {
828 if (xpos)
829 *xpos = m_x;
830 if (ypos)
831 *ypos = m_y;
832 }
833
834 void GetPosition(long *xpos, long *ypos) const
835 {
836 if (xpos)
837 *xpos = (long)m_x;
838 if (ypos)
839 *ypos = (long)m_y;
840 }
841
842 // Find the position of the event
843 wxPoint GetPosition() const { return wxPoint(m_x, m_y); }
844
845 // Find the logical position of the event given the DC
846 wxPoint GetLogicalPosition(const wxDC& dc) const;
847
848 // Get X position
849 wxCoord GetX() const { return m_x; }
850
851 // Get Y position
852 wxCoord GetY() const { return m_y; }
853
854 // Get wheel rotation, positive or negative indicates direction of
855 // rotation. Current devices all send an event when rotation is equal to
856 // +/-WheelDelta, but this allows for finer resolution devices to be
857 // created in the future. Because of this you shouldn't assume that one
858 // event is equal to 1 line or whatever, but you should be able to either
859 // do partial line scrolling or wait until +/-WheelDelta rotation values
860 // have been accumulated before scrolling.
861 int GetWheelRotation() const { return m_wheelRotation; }
862
863 // Get wheel delta, normally 120. This is the threshold for action to be
864 // taken, and one such action (for example, scrolling one increment)
865 // should occur for each delta.
866 int GetWheelDelta() const { return m_wheelDelta; }
867
868 // Returns the configured number of lines (or whatever) to be scrolled per
869 // wheel action. Defaults to one.
870 int GetLinesPerAction() const { return m_linesPerAction; }
871
872 // Is the system set to do page scrolling?
873 bool IsPageScroll() const { return ((unsigned int)m_linesPerAction == UINT_MAX); }
874
875 virtual wxEvent *Clone() const { return new wxMouseEvent(*this); }
876
877 wxMouseEvent& operator=(const wxMouseEvent& event) { Assign(event); return *this; }
878
879 public:
880 wxCoord m_x, m_y;
881
882 bool m_leftDown;
883 bool m_middleDown;
884 bool m_rightDown;
885
886 bool m_controlDown;
887 bool m_shiftDown;
888 bool m_altDown;
889 bool m_metaDown;
890
891 int m_wheelRotation;
892 int m_wheelDelta;
893 int m_linesPerAction;
894
895 protected:
896 void Assign(const wxMouseEvent& evt);
897
898 private:
899 DECLARE_DYNAMIC_CLASS(wxMouseEvent)
900 };
901
902 // Cursor set event
903
904 /*
905 wxEVT_SET_CURSOR
906 */
907
908 class WXDLLIMPEXP_CORE wxSetCursorEvent : public wxEvent
909 {
910 public:
911 wxSetCursorEvent(wxCoord x = 0, wxCoord y = 0)
912 : wxEvent(0, wxEVT_SET_CURSOR),
913 m_x(x), m_y(y), m_cursor()
914 { }
915
916 wxSetCursorEvent(const wxSetCursorEvent & event)
917 : wxEvent(event),
918 m_x(event.m_x),
919 m_y(event.m_y),
920 m_cursor(event.m_cursor)
921 { }
922
923 wxCoord GetX() const { return m_x; }
924 wxCoord GetY() const { return m_y; }
925
926 void SetCursor(const wxCursor& cursor) { m_cursor = cursor; }
927 const wxCursor& GetCursor() const { return m_cursor; }
928 bool HasCursor() const { return m_cursor.Ok(); }
929
930 virtual wxEvent *Clone() const { return new wxSetCursorEvent(*this); }
931
932 private:
933 wxCoord m_x, m_y;
934 wxCursor m_cursor;
935
936 private:
937 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxSetCursorEvent)
938 };
939
940 // Keyboard input event class
941
942 /*
943 wxEVT_CHAR
944 wxEVT_CHAR_HOOK
945 wxEVT_KEY_DOWN
946 wxEVT_KEY_UP
947 wxEVT_HOTKEY
948 */
949
950 class WXDLLIMPEXP_CORE wxKeyEvent : public wxEvent
951 {
952 public:
953 wxKeyEvent(wxEventType keyType = wxEVT_NULL);
954 wxKeyEvent(const wxKeyEvent& evt);
955
956 // Find state of shift/control keys
957 bool ControlDown() const { return m_controlDown; }
958 bool MetaDown() const { return m_metaDown; }
959 bool AltDown() const { return m_altDown; }
960 bool ShiftDown() const { return m_shiftDown; }
961
962 // "Cmd" is a pseudo key which is Control for PC and Unix platforms but
963 // Apple ("Command") key under Macs: it makes often sense to use it instead
964 // of, say, ControlDown() because Cmd key is used for the same thing under
965 // Mac as Ctrl elsewhere (but Ctrl still exists, just not used for this
966 // purpose under Mac)
967 bool CmdDown() const
968 {
969 #if defined(__WXMAC__) || defined(__WXCOCOA__)
970 return MetaDown();
971 #else
972 return ControlDown();
973 #endif
974 }
975
976 // exclude MetaDown() from HasModifiers() because NumLock under X is often
977 // configured as mod2 modifier, yet the key events even when it is pressed
978 // should be processed normally, not like Ctrl- or Alt-key
979 bool HasModifiers() const { return ControlDown() || AltDown(); }
980
981 // get the key code: an ASCII7 char or an element of wxKeyCode enum
982 int GetKeyCode() const { return (int)m_keyCode; }
983
984 #if wxUSE_UNICODE
985 // get the Unicode character corresponding to this key
986 wxChar GetUnicodeKey() const { return m_uniChar; }
987 #endif // wxUSE_UNICODE
988
989 // get the raw key code (platform-dependent)
990 wxUint32 GetRawKeyCode() const { return m_rawCode; }
991
992 // get the raw key flags (platform-dependent)
993 wxUint32 GetRawKeyFlags() const { return m_rawFlags; }
994
995 // Find the position of the event
996 void GetPosition(wxCoord *xpos, wxCoord *ypos) const
997 {
998 if (xpos) *xpos = m_x;
999 if (ypos) *ypos = m_y;
1000 }
1001
1002 void GetPosition(long *xpos, long *ypos) const
1003 {
1004 if (xpos) *xpos = (long)m_x;
1005 if (ypos) *ypos = (long)m_y;
1006 }
1007
1008 wxPoint GetPosition() const
1009 { return wxPoint(m_x, m_y); }
1010
1011 // Get X position
1012 wxCoord GetX() const { return m_x; }
1013
1014 // Get Y position
1015 wxCoord GetY() const { return m_y; }
1016
1017 // deprecated, Use GetKeyCode instead.
1018 wxDEPRECATED( long KeyCode() const );
1019
1020 virtual wxEvent *Clone() const { return new wxKeyEvent(*this); }
1021
1022 // we do need to copy wxKeyEvent sometimes (in wxTreeCtrl code, for
1023 // example)
1024 wxKeyEvent& operator=(const wxKeyEvent& evt)
1025 {
1026 m_x = evt.m_x;
1027 m_y = evt.m_y;
1028
1029 m_keyCode = evt.m_keyCode;
1030
1031 m_controlDown = evt.m_controlDown;
1032 m_shiftDown = evt.m_shiftDown;
1033 m_altDown = evt.m_altDown;
1034 m_metaDown = evt.m_metaDown;
1035 m_scanCode = evt.m_scanCode;
1036 m_rawCode = evt.m_rawCode;
1037 m_rawFlags = evt.m_rawFlags;
1038 #if wxUSE_UNICODE
1039 m_uniChar = evt.m_uniChar;
1040 #endif
1041
1042 return *this;
1043 }
1044
1045 public:
1046 wxCoord m_x, m_y;
1047
1048 long m_keyCode;
1049
1050 bool m_controlDown;
1051 bool m_shiftDown;
1052 bool m_altDown;
1053 bool m_metaDown;
1054 bool m_scanCode;
1055
1056 #if wxUSE_UNICODE
1057 // This contains the full Unicode character
1058 // in a character events in Unicode mode
1059 wxChar m_uniChar;
1060 #endif
1061
1062 // these fields contain the platform-specific information about
1063 // key that was pressed
1064 wxUint32 m_rawCode;
1065 wxUint32 m_rawFlags;
1066
1067 private:
1068 DECLARE_DYNAMIC_CLASS(wxKeyEvent)
1069 };
1070
1071 // Size event class
1072 /*
1073 wxEVT_SIZE
1074 */
1075
1076 class WXDLLIMPEXP_CORE wxSizeEvent : public wxEvent
1077 {
1078 public:
1079 wxSizeEvent() : wxEvent(0, wxEVT_SIZE)
1080 { }
1081 wxSizeEvent(const wxSize& sz, int winid = 0)
1082 : wxEvent(winid, wxEVT_SIZE),
1083 m_size(sz)
1084 { }
1085 wxSizeEvent(const wxSizeEvent & event)
1086 : wxEvent(event),
1087 m_size(event.m_size), m_rect(event.m_rect)
1088 { }
1089 wxSizeEvent(const wxRect& rect, int id = 0)
1090 : m_size(rect.GetSize()), m_rect(rect)
1091 { m_eventType = wxEVT_SIZING; m_id = id; }
1092
1093 wxSize GetSize() const { return m_size; }
1094 wxRect GetRect() const { return m_rect; }
1095 void SetRect(wxRect rect) { m_rect = rect; }
1096
1097 virtual wxEvent *Clone() const { return new wxSizeEvent(*this); }
1098
1099 public:
1100 // For internal usage only. Will be converted to protected members.
1101 wxSize m_size;
1102 wxRect m_rect; // Used for wxEVT_SIZING
1103
1104 private:
1105 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxSizeEvent)
1106 };
1107
1108 // Move event class
1109
1110 /*
1111 wxEVT_MOVE
1112 */
1113
1114 class WXDLLIMPEXP_CORE wxMoveEvent : public wxEvent
1115 {
1116 public:
1117 wxMoveEvent()
1118 : wxEvent(0, wxEVT_MOVE)
1119 { }
1120 wxMoveEvent(const wxPoint& pos, int winid = 0)
1121 : wxEvent(winid, wxEVT_MOVE),
1122 m_pos(pos)
1123 { }
1124 wxMoveEvent(const wxMoveEvent& event)
1125 : wxEvent(event),
1126 m_pos(event.m_pos)
1127 { }
1128 wxMoveEvent(const wxRect& rect, int id = 0)
1129 : m_pos(rect.GetPosition()), m_rect(rect)
1130 { m_eventType = wxEVT_MOVING; m_id = id; }
1131
1132 wxPoint GetPosition() const { return m_pos; }
1133 void SetPosition(const wxPoint& pos) { m_pos = pos; }
1134 wxRect GetRect() const { return m_rect; }
1135 void SetRect(wxRect rect) { m_rect = rect; }
1136
1137 virtual wxEvent *Clone() const { return new wxMoveEvent(*this); }
1138
1139 #if WXWIN_COMPATIBILITY_2_4
1140 public:
1141 #else
1142 protected:
1143 #endif
1144 wxPoint m_pos;
1145 wxRect m_rect;
1146
1147 private:
1148 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxMoveEvent)
1149 };
1150
1151 // Paint event class
1152 /*
1153 wxEVT_PAINT
1154 wxEVT_NC_PAINT
1155 wxEVT_PAINT_ICON
1156 */
1157
1158 #if defined(__WXDEBUG__) && (defined(__WXMSW__) || defined(__WXPM__))
1159 // see comments in src/msw|os2/dcclient.cpp where g_isPainting is defined
1160 extern WXDLLIMPEXP_CORE int g_isPainting;
1161 #endif // debug
1162
1163 class WXDLLIMPEXP_CORE wxPaintEvent : public wxEvent
1164 {
1165 public:
1166 wxPaintEvent(int Id = 0)
1167 : wxEvent(Id, wxEVT_PAINT)
1168 {
1169 #if defined(__WXDEBUG__) && (defined(__WXMSW__) || defined(__WXPM__))
1170 // set the internal flag for the duration of processing of WM_PAINT
1171 g_isPainting++;
1172 #endif // debug
1173 }
1174
1175 // default copy ctor and dtor are normally fine, we only need them to keep
1176 // g_isPainting updated in debug build
1177 #if defined(__WXDEBUG__) && (defined(__WXMSW__) || defined(__WXPM__))
1178 wxPaintEvent(const wxPaintEvent& event)
1179 : wxEvent(event)
1180 {
1181 g_isPainting++;
1182 }
1183
1184 ~wxPaintEvent()
1185 {
1186 g_isPainting--;
1187 }
1188 #endif // debug
1189
1190 virtual wxEvent *Clone() const { return new wxPaintEvent(*this); }
1191
1192 private:
1193 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxPaintEvent)
1194 };
1195
1196 class WXDLLIMPEXP_CORE wxNcPaintEvent : public wxEvent
1197 {
1198 public:
1199 wxNcPaintEvent(int winid = 0)
1200 : wxEvent(winid, wxEVT_NC_PAINT)
1201 { }
1202
1203 virtual wxEvent *Clone() const { return new wxNcPaintEvent(*this); }
1204
1205 private:
1206 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxNcPaintEvent)
1207 };
1208
1209 // Erase background event class
1210 /*
1211 wxEVT_ERASE_BACKGROUND
1212 */
1213
1214 class WXDLLIMPEXP_CORE wxEraseEvent : public wxEvent
1215 {
1216 public:
1217 wxEraseEvent(int Id = 0, wxDC *dc = (wxDC *) NULL)
1218 : wxEvent(Id, wxEVT_ERASE_BACKGROUND),
1219 m_dc(dc)
1220 { }
1221
1222 wxEraseEvent(const wxEraseEvent& event)
1223 : wxEvent(event),
1224 m_dc(event.m_dc)
1225 { }
1226
1227 wxDC *GetDC() const { return m_dc; }
1228
1229 virtual wxEvent *Clone() const { return new wxEraseEvent(*this); }
1230
1231 #if WXWIN_COMPATIBILITY_2_4
1232 public:
1233 #else
1234 protected:
1235 #endif
1236 wxDC *m_dc;
1237
1238 private:
1239 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxEraseEvent)
1240 };
1241
1242 // Focus event class
1243 /*
1244 wxEVT_SET_FOCUS
1245 wxEVT_KILL_FOCUS
1246 */
1247
1248 class WXDLLIMPEXP_CORE wxFocusEvent : public wxEvent
1249 {
1250 public:
1251 wxFocusEvent(wxEventType type = wxEVT_NULL, int winid = 0)
1252 : wxEvent(winid, type)
1253 { m_win = NULL; }
1254
1255 wxFocusEvent(const wxFocusEvent& event)
1256 : wxEvent(event)
1257 { m_win = event.m_win; }
1258
1259 // The window associated with this event is the window which had focus
1260 // before for SET event and the window which will have focus for the KILL
1261 // one. NB: it may be NULL in both cases!
1262 wxWindow *GetWindow() const { return m_win; }
1263 void SetWindow(wxWindow *win) { m_win = win; }
1264
1265 virtual wxEvent *Clone() const { return new wxFocusEvent(*this); }
1266
1267 private:
1268 wxWindow *m_win;
1269
1270 private:
1271 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxFocusEvent)
1272 };
1273
1274 // wxChildFocusEvent notifies the parent that a child has got the focus: unlike
1275 // wxFocusEvent it is propagated upwards the window chain
1276 class WXDLLIMPEXP_CORE wxChildFocusEvent : public wxCommandEvent
1277 {
1278 public:
1279 wxChildFocusEvent(wxWindow *win = NULL);
1280
1281 wxWindow *GetWindow() const { return (wxWindow *)GetEventObject(); }
1282
1283 virtual wxEvent *Clone() const { return new wxChildFocusEvent(*this); }
1284
1285 private:
1286 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxChildFocusEvent)
1287 };
1288
1289 // Activate event class
1290 /*
1291 wxEVT_ACTIVATE
1292 wxEVT_ACTIVATE_APP
1293 wxEVT_HIBERNATE
1294 */
1295
1296 class WXDLLIMPEXP_CORE wxActivateEvent : public wxEvent
1297 {
1298 public:
1299 wxActivateEvent(wxEventType type = wxEVT_NULL, bool active = true, int Id = 0)
1300 : wxEvent(Id, type)
1301 { m_active = active; }
1302 wxActivateEvent(const wxActivateEvent& event)
1303 : wxEvent(event)
1304 { m_active = event.m_active; }
1305
1306 bool GetActive() const { return m_active; }
1307
1308 virtual wxEvent *Clone() const { return new wxActivateEvent(*this); }
1309
1310 private:
1311 bool m_active;
1312
1313 private:
1314 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxActivateEvent)
1315 };
1316
1317 // InitDialog event class
1318 /*
1319 wxEVT_INIT_DIALOG
1320 */
1321
1322 class WXDLLIMPEXP_CORE wxInitDialogEvent : public wxEvent
1323 {
1324 public:
1325 wxInitDialogEvent(int Id = 0)
1326 : wxEvent(Id, wxEVT_INIT_DIALOG)
1327 { }
1328
1329 virtual wxEvent *Clone() const { return new wxInitDialogEvent(*this); }
1330
1331 private:
1332 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxInitDialogEvent)
1333 };
1334
1335 // Miscellaneous menu event class
1336 /*
1337 wxEVT_MENU_OPEN,
1338 wxEVT_MENU_CLOSE,
1339 wxEVT_MENU_HIGHLIGHT,
1340 */
1341
1342 class WXDLLIMPEXP_CORE wxMenuEvent : public wxEvent
1343 {
1344 public:
1345 wxMenuEvent(wxEventType type = wxEVT_NULL, int winid = 0, wxMenu* menu = NULL)
1346 : wxEvent(winid, type)
1347 { m_menuId = winid; m_menu = menu; }
1348 wxMenuEvent(const wxMenuEvent & event)
1349 : wxEvent(event)
1350 { m_menuId = event.m_menuId; m_menu = event.m_menu; }
1351
1352 // only for wxEVT_MENU_HIGHLIGHT
1353 int GetMenuId() const { return m_menuId; }
1354
1355 // only for wxEVT_MENU_OPEN/CLOSE
1356 bool IsPopup() const { return m_menuId == wxID_ANY; }
1357
1358 // only for wxEVT_MENU_OPEN/CLOSE
1359 wxMenu* GetMenu() const { return m_menu; }
1360
1361 virtual wxEvent *Clone() const { return new wxMenuEvent(*this); }
1362
1363 private:
1364 int m_menuId;
1365 wxMenu* m_menu;
1366
1367 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxMenuEvent)
1368 };
1369
1370 // Window close or session close event class
1371 /*
1372 wxEVT_CLOSE_WINDOW,
1373 wxEVT_END_SESSION,
1374 wxEVT_QUERY_END_SESSION
1375 */
1376
1377 class WXDLLIMPEXP_CORE wxCloseEvent : public wxEvent
1378 {
1379 public:
1380 wxCloseEvent(wxEventType type = wxEVT_NULL, int winid = 0)
1381 : wxEvent(winid, type),
1382 m_loggingOff(true),
1383 m_veto(false), // should be false by default
1384 m_canVeto(true) {}
1385
1386 wxCloseEvent(const wxCloseEvent & event)
1387 : wxEvent(event),
1388 m_loggingOff(event.m_loggingOff),
1389 m_veto(event.m_veto),
1390 m_canVeto(event.m_canVeto) {}
1391
1392 void SetLoggingOff(bool logOff) { m_loggingOff = logOff; }
1393 bool GetLoggingOff() const
1394 {
1395 // m_loggingOff flag is only used by wxEVT_[QUERY_]END_SESSION, it
1396 // doesn't make sense for wxEVT_CLOSE_WINDOW
1397 wxASSERT_MSG( m_eventType != wxEVT_CLOSE_WINDOW,
1398 _T("this flag is for end session events only") );
1399
1400 return m_loggingOff;
1401 }
1402
1403 void Veto(bool veto = true)
1404 {
1405 // GetVeto() will return false anyhow...
1406 wxCHECK_RET( m_canVeto,
1407 wxT("call to Veto() ignored (can't veto this event)") );
1408
1409 m_veto = veto;
1410 }
1411 void SetCanVeto(bool canVeto) { m_canVeto = canVeto; }
1412 bool CanVeto() const { return m_canVeto; }
1413 bool GetVeto() const { return m_canVeto && m_veto; }
1414
1415 virtual wxEvent *Clone() const { return new wxCloseEvent(*this); }
1416
1417 protected:
1418 bool m_loggingOff,
1419 m_veto,
1420 m_canVeto;
1421
1422 private:
1423 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxCloseEvent)
1424 };
1425
1426 /*
1427 wxEVT_SHOW
1428 */
1429
1430 class WXDLLIMPEXP_CORE wxShowEvent : public wxEvent
1431 {
1432 public:
1433 wxShowEvent(int winid = 0, bool show = false)
1434 : wxEvent(winid, wxEVT_SHOW)
1435 { m_show = show; }
1436 wxShowEvent(const wxShowEvent & event)
1437 : wxEvent(event)
1438 { m_show = event.m_show; }
1439
1440 void SetShow(bool show) { m_show = show; }
1441 bool GetShow() const { return m_show; }
1442
1443 virtual wxEvent *Clone() const { return new wxShowEvent(*this); }
1444
1445 protected:
1446 bool m_show;
1447
1448 private:
1449 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxShowEvent)
1450 };
1451
1452 /*
1453 wxEVT_ICONIZE
1454 */
1455
1456 class WXDLLIMPEXP_CORE wxIconizeEvent : public wxEvent
1457 {
1458 public:
1459 wxIconizeEvent(int winid = 0, bool iconized = true)
1460 : wxEvent(winid, wxEVT_ICONIZE)
1461 { m_iconized = iconized; }
1462 wxIconizeEvent(const wxIconizeEvent & event)
1463 : wxEvent(event)
1464 { m_iconized = event.m_iconized; }
1465
1466 // return true if the frame was iconized, false if restored
1467 bool Iconized() const { return m_iconized; }
1468
1469 virtual wxEvent *Clone() const { return new wxIconizeEvent(*this); }
1470
1471 protected:
1472 bool m_iconized;
1473
1474 private:
1475 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxIconizeEvent)
1476 };
1477 /*
1478 wxEVT_MAXIMIZE
1479 */
1480
1481 class WXDLLIMPEXP_CORE wxMaximizeEvent : public wxEvent
1482 {
1483 public:
1484 wxMaximizeEvent(int winid = 0)
1485 : wxEvent(winid, wxEVT_MAXIMIZE)
1486 { }
1487
1488 virtual wxEvent *Clone() const { return new wxMaximizeEvent(*this); }
1489
1490 private:
1491 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxMaximizeEvent)
1492 };
1493
1494 // Joystick event class
1495 /*
1496 wxEVT_JOY_BUTTON_DOWN,
1497 wxEVT_JOY_BUTTON_UP,
1498 wxEVT_JOY_MOVE,
1499 wxEVT_JOY_ZMOVE
1500 */
1501
1502 // Which joystick? Same as Windows ids so no conversion necessary.
1503 enum
1504 {
1505 wxJOYSTICK1,
1506 wxJOYSTICK2
1507 };
1508
1509 // Which button is down?
1510 enum
1511 {
1512 wxJOY_BUTTON_ANY = -1,
1513 wxJOY_BUTTON1 = 1,
1514 wxJOY_BUTTON2 = 2,
1515 wxJOY_BUTTON3 = 4,
1516 wxJOY_BUTTON4 = 8
1517 };
1518
1519 class WXDLLIMPEXP_CORE wxJoystickEvent : public wxEvent
1520 {
1521 #if WXWIN_COMPATIBILITY_2_4
1522 public:
1523 #else
1524 protected:
1525 #endif
1526 wxPoint m_pos;
1527 int m_zPosition;
1528 int m_buttonChange; // Which button changed?
1529 int m_buttonState; // Which buttons are down?
1530 int m_joyStick; // Which joystick?
1531
1532 public:
1533 wxJoystickEvent(wxEventType type = wxEVT_NULL,
1534 int state = 0,
1535 int joystick = wxJOYSTICK1,
1536 int change = 0)
1537 : wxEvent(0, type),
1538 m_pos(),
1539 m_zPosition(0),
1540 m_buttonChange(change),
1541 m_buttonState(state),
1542 m_joyStick(joystick)
1543 {
1544 }
1545 wxJoystickEvent(const wxJoystickEvent & event)
1546 : wxEvent(event),
1547 m_pos(event.m_pos),
1548 m_zPosition(event.m_zPosition),
1549 m_buttonChange(event.m_buttonChange),
1550 m_buttonState(event.m_buttonState),
1551 m_joyStick(event.m_joyStick)
1552 { }
1553
1554 wxPoint GetPosition() const { return m_pos; }
1555 int GetZPosition() const { return m_zPosition; }
1556 int GetButtonState() const { return m_buttonState; }
1557 int GetButtonChange() const { return m_buttonChange; }
1558 int GetJoystick() const { return m_joyStick; }
1559
1560 void SetJoystick(int stick) { m_joyStick = stick; }
1561 void SetButtonState(int state) { m_buttonState = state; }
1562 void SetButtonChange(int change) { m_buttonChange = change; }
1563 void SetPosition(const wxPoint& pos) { m_pos = pos; }
1564 void SetZPosition(int zPos) { m_zPosition = zPos; }
1565
1566 // Was it a button event? (*doesn't* mean: is any button *down*?)
1567 bool IsButton() const { return ((GetEventType() == wxEVT_JOY_BUTTON_DOWN) ||
1568 (GetEventType() == wxEVT_JOY_BUTTON_UP)); }
1569
1570 // Was it a move event?
1571 bool IsMove() const { return (GetEventType() == wxEVT_JOY_MOVE); }
1572
1573 // Was it a zmove event?
1574 bool IsZMove() const { return (GetEventType() == wxEVT_JOY_ZMOVE); }
1575
1576 // Was it a down event from button 1, 2, 3, 4 or any?
1577 bool ButtonDown(int but = wxJOY_BUTTON_ANY) const
1578 { return ((GetEventType() == wxEVT_JOY_BUTTON_DOWN) &&
1579 ((but == wxJOY_BUTTON_ANY) || (but == m_buttonChange))); }
1580
1581 // Was it a up event from button 1, 2, 3 or any?
1582 bool ButtonUp(int but = wxJOY_BUTTON_ANY) const
1583 { return ((GetEventType() == wxEVT_JOY_BUTTON_UP) &&
1584 ((but == wxJOY_BUTTON_ANY) || (but == m_buttonChange))); }
1585
1586 // Was the given button 1,2,3,4 or any in Down state?
1587 bool ButtonIsDown(int but = wxJOY_BUTTON_ANY) const
1588 { return (((but == wxJOY_BUTTON_ANY) && (m_buttonState != 0)) ||
1589 ((m_buttonState & but) == but)); }
1590
1591 virtual wxEvent *Clone() const { return new wxJoystickEvent(*this); }
1592
1593 private:
1594 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxJoystickEvent)
1595 };
1596
1597 // Drop files event class
1598 /*
1599 wxEVT_DROP_FILES
1600 */
1601
1602 class WXDLLIMPEXP_CORE wxDropFilesEvent : public wxEvent
1603 {
1604 public:
1605 int m_noFiles;
1606 wxPoint m_pos;
1607 wxString* m_files;
1608
1609 wxDropFilesEvent(wxEventType type = wxEVT_NULL,
1610 int noFiles = 0,
1611 wxString *files = (wxString *) NULL)
1612 : wxEvent(0, type),
1613 m_noFiles(noFiles),
1614 m_pos(),
1615 m_files(files)
1616 { }
1617
1618 // we need a copy ctor to avoid deleting m_files pointer twice
1619 wxDropFilesEvent(const wxDropFilesEvent& other)
1620 : wxEvent(other),
1621 m_noFiles(other.m_noFiles),
1622 m_pos(other.m_pos),
1623 m_files(NULL)
1624 {
1625 m_files = new wxString[m_noFiles];
1626 for ( int n = 0; n < m_noFiles; n++ )
1627 {
1628 m_files[n] = other.m_files[n];
1629 }
1630 }
1631
1632 virtual ~wxDropFilesEvent()
1633 {
1634 delete [] m_files;
1635 }
1636
1637 wxPoint GetPosition() const { return m_pos; }
1638 int GetNumberOfFiles() const { return m_noFiles; }
1639 wxString *GetFiles() const { return m_files; }
1640
1641 virtual wxEvent *Clone() const { return new wxDropFilesEvent(*this); }
1642
1643 private:
1644 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDropFilesEvent)
1645 };
1646
1647 // Update UI event
1648 /*
1649 wxEVT_UPDATE_UI
1650 */
1651
1652 // Whether to always send update events to windows, or
1653 // to only send update events to those with the
1654 // wxWS_EX_PROCESS_UI_UPDATES style.
1655
1656 enum wxUpdateUIMode
1657 {
1658 // Send UI update events to all windows
1659 wxUPDATE_UI_PROCESS_ALL,
1660
1661 // Send UI update events to windows that have
1662 // the wxWS_EX_PROCESS_UI_UPDATES flag specified
1663 wxUPDATE_UI_PROCESS_SPECIFIED
1664 };
1665
1666 class WXDLLIMPEXP_CORE wxUpdateUIEvent : public wxCommandEvent
1667 {
1668 public:
1669 wxUpdateUIEvent(wxWindowID commandId = 0)
1670 : wxCommandEvent(wxEVT_UPDATE_UI, commandId)
1671 {
1672 m_checked =
1673 m_enabled =
1674 m_setEnabled =
1675 m_setText =
1676 m_setChecked = false;
1677 }
1678 wxUpdateUIEvent(const wxUpdateUIEvent & event)
1679 : wxCommandEvent(event),
1680 m_checked(event.m_checked),
1681 m_enabled(event.m_enabled),
1682 m_setEnabled(event.m_setEnabled),
1683 m_setText(event.m_setText),
1684 m_setChecked(event.m_setChecked),
1685 m_text(event.m_text)
1686 { }
1687
1688 bool GetChecked() const { return m_checked; }
1689 bool GetEnabled() const { return m_enabled; }
1690 wxString GetText() const { return m_text; }
1691 bool GetSetText() const { return m_setText; }
1692 bool GetSetChecked() const { return m_setChecked; }
1693 bool GetSetEnabled() const { return m_setEnabled; }
1694
1695 void Check(bool check) { m_checked = check; m_setChecked = true; }
1696 void Enable(bool enable) { m_enabled = enable; m_setEnabled = true; }
1697 void SetText(const wxString& text) { m_text = text; m_setText = true; }
1698
1699 // Sets the interval between updates in milliseconds.
1700 // Set to -1 to disable updates, or to 0 to update as frequently as possible.
1701 static void SetUpdateInterval(long updateInterval) { sm_updateInterval = updateInterval; }
1702
1703 // Returns the current interval between updates in milliseconds
1704 static long GetUpdateInterval() { return sm_updateInterval; }
1705
1706 // Can we update this window?
1707 static bool CanUpdate(wxWindowBase *win);
1708
1709 // Reset the update time to provide a delay until the next
1710 // time we should update
1711 static void ResetUpdateTime();
1712
1713 // Specify how wxWidgets will send update events: to
1714 // all windows, or only to those which specify that they
1715 // will process the events.
1716 static void SetMode(wxUpdateUIMode mode) { sm_updateMode = mode; }
1717
1718 // Returns the UI update mode
1719 static wxUpdateUIMode GetMode() { return sm_updateMode; }
1720
1721 virtual wxEvent *Clone() const { return new wxUpdateUIEvent(*this); }
1722
1723 protected:
1724 bool m_checked;
1725 bool m_enabled;
1726 bool m_setEnabled;
1727 bool m_setText;
1728 bool m_setChecked;
1729 wxString m_text;
1730 #if wxUSE_LONGLONG
1731 static wxLongLong sm_lastUpdate;
1732 #endif
1733 static long sm_updateInterval;
1734 static wxUpdateUIMode sm_updateMode;
1735
1736 private:
1737 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxUpdateUIEvent)
1738 };
1739
1740 /*
1741 wxEVT_SYS_COLOUR_CHANGED
1742 */
1743
1744 // TODO: shouldn't all events record the window ID?
1745 class WXDLLIMPEXP_CORE wxSysColourChangedEvent : public wxEvent
1746 {
1747 public:
1748 wxSysColourChangedEvent()
1749 : wxEvent(0, wxEVT_SYS_COLOUR_CHANGED)
1750 { }
1751
1752 virtual wxEvent *Clone() const { return new wxSysColourChangedEvent(*this); }
1753
1754 private:
1755 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxSysColourChangedEvent)
1756 };
1757
1758 /*
1759 wxEVT_MOUSE_CAPTURE_CHANGED
1760 The window losing the capture receives this message
1761 (even if it released the capture itself).
1762 */
1763
1764 class WXDLLIMPEXP_CORE wxMouseCaptureChangedEvent : public wxEvent
1765 {
1766 public:
1767 wxMouseCaptureChangedEvent(wxWindowID winid = 0, wxWindow* gainedCapture = NULL)
1768 : wxEvent(winid, wxEVT_MOUSE_CAPTURE_CHANGED),
1769 m_gainedCapture(gainedCapture)
1770 { }
1771
1772 wxMouseCaptureChangedEvent(const wxMouseCaptureChangedEvent& event)
1773 : wxEvent(event),
1774 m_gainedCapture(event.m_gainedCapture)
1775 { }
1776
1777 virtual wxEvent *Clone() const { return new wxMouseCaptureChangedEvent(*this); }
1778
1779 wxWindow* GetCapturedWindow() const { return m_gainedCapture; };
1780
1781 private:
1782 wxWindow* m_gainedCapture;
1783
1784 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxMouseCaptureChangedEvent)
1785 };
1786
1787 /*
1788 wxEVT_DISPLAY_CHANGED
1789 */
1790 class WXDLLIMPEXP_CORE wxDisplayChangedEvent : public wxEvent
1791 {
1792 private:
1793 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDisplayChangedEvent)
1794
1795 public:
1796 wxDisplayChangedEvent()
1797 : wxEvent(0, wxEVT_DISPLAY_CHANGED)
1798 { }
1799
1800 virtual wxEvent *Clone() const { return new wxDisplayChangedEvent(*this); }
1801 };
1802
1803 /*
1804 wxEVT_PALETTE_CHANGED
1805 */
1806
1807 class WXDLLIMPEXP_CORE wxPaletteChangedEvent : public wxEvent
1808 {
1809 public:
1810 wxPaletteChangedEvent(wxWindowID winid = 0)
1811 : wxEvent(winid, wxEVT_PALETTE_CHANGED),
1812 m_changedWindow((wxWindow *) NULL)
1813 { }
1814
1815 wxPaletteChangedEvent(const wxPaletteChangedEvent& event)
1816 : wxEvent(event),
1817 m_changedWindow(event.m_changedWindow)
1818 { }
1819
1820 void SetChangedWindow(wxWindow* win) { m_changedWindow = win; }
1821 wxWindow* GetChangedWindow() const { return m_changedWindow; }
1822
1823 virtual wxEvent *Clone() const { return new wxPaletteChangedEvent(*this); }
1824
1825 protected:
1826 wxWindow* m_changedWindow;
1827
1828 private:
1829 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxPaletteChangedEvent)
1830 };
1831
1832 /*
1833 wxEVT_QUERY_NEW_PALETTE
1834 Indicates the window is getting keyboard focus and should re-do its palette.
1835 */
1836
1837 class WXDLLIMPEXP_CORE wxQueryNewPaletteEvent : public wxEvent
1838 {
1839 public:
1840 wxQueryNewPaletteEvent(wxWindowID winid = 0)
1841 : wxEvent(winid, wxEVT_QUERY_NEW_PALETTE),
1842 m_paletteRealized(false)
1843 { }
1844 wxQueryNewPaletteEvent(const wxQueryNewPaletteEvent & event)
1845 : wxEvent(event),
1846 m_paletteRealized(event.m_paletteRealized)
1847 { }
1848
1849 // App sets this if it changes the palette.
1850 void SetPaletteRealized(bool realized) { m_paletteRealized = realized; }
1851 bool GetPaletteRealized() const { return m_paletteRealized; }
1852
1853 virtual wxEvent *Clone() const { return new wxQueryNewPaletteEvent(*this); }
1854
1855 protected:
1856 bool m_paletteRealized;
1857
1858 private:
1859 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxQueryNewPaletteEvent)
1860 };
1861
1862 /*
1863 Event generated by dialog navigation keys
1864 wxEVT_NAVIGATION_KEY
1865 */
1866 // NB: don't derive from command event to avoid being propagated to the parent
1867 class WXDLLIMPEXP_CORE wxNavigationKeyEvent : public wxEvent
1868 {
1869 public:
1870 wxNavigationKeyEvent()
1871 : wxEvent(0, wxEVT_NAVIGATION_KEY),
1872 m_flags(IsForward | FromTab), // defaults are for TAB
1873 m_focus((wxWindow *)NULL)
1874 {
1875 m_propagationLevel = wxEVENT_PROPAGATE_NONE;
1876 }
1877
1878 wxNavigationKeyEvent(const wxNavigationKeyEvent& event)
1879 : wxEvent(event),
1880 m_flags(event.m_flags),
1881 m_focus(event.m_focus)
1882 { }
1883
1884 // direction: forward (true) or backward (false)
1885 bool GetDirection() const
1886 { return (m_flags & IsForward) != 0; }
1887 void SetDirection(bool bForward)
1888 { if ( bForward ) m_flags |= IsForward; else m_flags &= ~IsForward; }
1889
1890 // it may be a window change event (MDI, notebook pages...) or a control
1891 // change event
1892 bool IsWindowChange() const
1893 { return (m_flags & WinChange) != 0; }
1894 void SetWindowChange(bool bIs)
1895 { if ( bIs ) m_flags |= WinChange; else m_flags &= ~WinChange; }
1896
1897 // Set to true under MSW if the event was generated using the tab key.
1898 // This is required for proper navogation over radio buttons
1899 bool IsFromTab() const
1900 { return (m_flags & FromTab) != 0; }
1901 void SetFromTab(bool bIs)
1902 { if ( bIs ) m_flags |= FromTab; else m_flags &= ~FromTab; }
1903
1904 // the child which has the focus currently (may be NULL - use
1905 // wxWindow::FindFocus then)
1906 wxWindow* GetCurrentFocus() const { return m_focus; }
1907 void SetCurrentFocus(wxWindow *win) { m_focus = win; }
1908
1909 // Set flags
1910 void SetFlags(long flags) { m_flags = flags; }
1911
1912 virtual wxEvent *Clone() const { return new wxNavigationKeyEvent(*this); }
1913
1914 enum
1915 {
1916 IsBackward = 0x0000,
1917 IsForward = 0x0001,
1918 WinChange = 0x0002,
1919 FromTab = 0x0004
1920 };
1921
1922 long m_flags;
1923 wxWindow *m_focus;
1924
1925 private:
1926 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxNavigationKeyEvent)
1927 };
1928
1929 // Window creation/destruction events: the first is sent as soon as window is
1930 // created (i.e. the underlying GUI object exists), but when the C++ object is
1931 // fully initialized (so virtual functions may be called). The second,
1932 // wxEVT_DESTROY, is sent right before the window is destroyed - again, it's
1933 // still safe to call virtual functions at this moment
1934 /*
1935 wxEVT_CREATE
1936 wxEVT_DESTROY
1937 */
1938
1939 class WXDLLIMPEXP_CORE wxWindowCreateEvent : public wxCommandEvent
1940 {
1941 public:
1942 wxWindowCreateEvent(wxWindow *win = NULL);
1943
1944 wxWindow *GetWindow() const { return (wxWindow *)GetEventObject(); }
1945
1946 virtual wxEvent *Clone() const { return new wxWindowCreateEvent(*this); }
1947
1948 private:
1949 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWindowCreateEvent)
1950 };
1951
1952 class WXDLLIMPEXP_CORE wxWindowDestroyEvent : public wxCommandEvent
1953 {
1954 public:
1955 wxWindowDestroyEvent(wxWindow *win = NULL);
1956
1957 wxWindow *GetWindow() const { return (wxWindow *)GetEventObject(); }
1958
1959 virtual wxEvent *Clone() const { return new wxWindowDestroyEvent(*this); }
1960
1961 private:
1962 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWindowDestroyEvent)
1963 };
1964
1965 // A help event is sent when the user clicks on a window in context-help mode.
1966 /*
1967 wxEVT_HELP
1968 wxEVT_DETAILED_HELP
1969 */
1970
1971 class WXDLLIMPEXP_CORE wxHelpEvent : public wxCommandEvent
1972 {
1973 public:
1974 wxHelpEvent(wxEventType type = wxEVT_NULL,
1975 wxWindowID winid = 0,
1976 const wxPoint& pt = wxDefaultPosition)
1977 : wxCommandEvent(type, winid),
1978 m_pos(pt), m_target(), m_link()
1979 { }
1980 wxHelpEvent(const wxHelpEvent & event)
1981 : wxCommandEvent(event),
1982 m_pos(event.m_pos),
1983 m_target(event.m_target),
1984 m_link(event.m_link)
1985 { }
1986
1987 // Position of event (in screen coordinates)
1988 const wxPoint& GetPosition() const { return m_pos; }
1989 void SetPosition(const wxPoint& pos) { m_pos = pos; }
1990
1991 // Optional link to further help
1992 const wxString& GetLink() const { return m_link; }
1993 void SetLink(const wxString& link) { m_link = link; }
1994
1995 // Optional target to display help in. E.g. a window specification
1996 const wxString& GetTarget() const { return m_target; }
1997 void SetTarget(const wxString& target) { m_target = target; }
1998
1999 virtual wxEvent *Clone() const { return new wxHelpEvent(*this); }
2000
2001 protected:
2002 wxPoint m_pos;
2003 wxString m_target;
2004 wxString m_link;
2005
2006 private:
2007 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHelpEvent)
2008 };
2009
2010 // A Context event is sent when the user right clicks on a window or
2011 // presses Shift-F10
2012 // NOTE : Under windows this is a repackaged WM_CONTETXMENU message
2013 // Under other systems it may have to be generated from a right click event
2014 /*
2015 wxEVT_CONTEXT_MENU
2016 */
2017
2018 class WXDLLIMPEXP_CORE wxContextMenuEvent : public wxCommandEvent
2019 {
2020 public:
2021 wxContextMenuEvent(wxEventType type = wxEVT_NULL,
2022 wxWindowID winid = 0,
2023 const wxPoint& pt = wxDefaultPosition)
2024 : wxCommandEvent(type, winid),
2025 m_pos(pt)
2026 { }
2027 wxContextMenuEvent(const wxContextMenuEvent & event)
2028 : wxCommandEvent(event),
2029 m_pos(event.m_pos)
2030 { }
2031
2032 // Position of event (in screen coordinates)
2033 const wxPoint& GetPosition() const { return m_pos; }
2034 void SetPosition(const wxPoint& pos) { m_pos = pos; }
2035
2036 virtual wxEvent *Clone() const { return new wxContextMenuEvent(*this); }
2037
2038 protected:
2039 wxPoint m_pos;
2040
2041 private:
2042 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxContextMenuEvent)
2043 };
2044
2045 // Idle event
2046 /*
2047 wxEVT_IDLE
2048 */
2049
2050 // Whether to always send idle events to windows, or
2051 // to only send update events to those with the
2052 // wxWS_EX_PROCESS_IDLE style.
2053
2054 enum wxIdleMode
2055 {
2056 // Send idle events to all windows
2057 wxIDLE_PROCESS_ALL,
2058
2059 // Send idle events to windows that have
2060 // the wxWS_EX_PROCESS_IDLE flag specified
2061 wxIDLE_PROCESS_SPECIFIED
2062 };
2063
2064 class WXDLLIMPEXP_CORE wxIdleEvent : public wxEvent
2065 {
2066 public:
2067 wxIdleEvent()
2068 : wxEvent(0, wxEVT_IDLE),
2069 m_requestMore(false)
2070 { }
2071 wxIdleEvent(const wxIdleEvent & event)
2072 : wxEvent(event),
2073 m_requestMore(event.m_requestMore)
2074 { }
2075
2076 void RequestMore(bool needMore = true) { m_requestMore = needMore; }
2077 bool MoreRequested() const { return m_requestMore; }
2078
2079 virtual wxEvent *Clone() const { return new wxIdleEvent(*this); }
2080
2081 // Specify how wxWidgets will send idle events: to
2082 // all windows, or only to those which specify that they
2083 // will process the events.
2084 static void SetMode(wxIdleMode mode) { sm_idleMode = mode; }
2085
2086 // Returns the idle event mode
2087 static wxIdleMode GetMode() { return sm_idleMode; }
2088
2089 // Can we send an idle event?
2090 static bool CanSend(wxWindow* win);
2091
2092 protected:
2093 bool m_requestMore;
2094 static wxIdleMode sm_idleMode;
2095
2096 private:
2097 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxIdleEvent)
2098 };
2099
2100 #endif // wxUSE_GUI
2101
2102 /* TODO
2103 wxEVT_POWER,
2104 wxEVT_MOUSE_CAPTURE_CHANGED,
2105 wxEVT_SETTING_CHANGED, // WM_WININICHANGE (NT) / WM_SETTINGCHANGE (Win95)
2106 // wxEVT_FONT_CHANGED, // WM_FONTCHANGE: roll into wxEVT_SETTING_CHANGED, but remember to propagate
2107 // wxEVT_FONT_CHANGED to all other windows (maybe).
2108 wxEVT_DRAW_ITEM, // Leave these three as virtual functions in wxControl?? Platform-specific.
2109 wxEVT_MEASURE_ITEM,
2110 wxEVT_COMPARE_ITEM
2111 */
2112
2113
2114 // ============================================================================
2115 // event handler and related classes
2116 // ============================================================================
2117
2118 // for backwards compatibility and to prevent eVC 4 for ARM from crashing with
2119 // internal compiler error when compiling wx, we define wxObjectEventFunction
2120 // as a wxObject method even though it can only be a wxEvtHandler one
2121 typedef void (wxObject::*wxObjectEventFunction)(wxEvent&);
2122
2123 // we can't have ctors nor base struct in backwards compatibility mode or
2124 // otherwise we won't be able to initialize the objects with an agregate, so
2125 // we have to keep both versions
2126 #if WXWIN_COMPATIBILITY_EVENT_TYPES
2127
2128 struct WXDLLIMPEXP_BASE wxEventTableEntry
2129 {
2130 // For some reason, this can't be wxEventType, or VC++ complains.
2131 int m_eventType; // main event type
2132 int m_id; // control/menu/toolbar id
2133 int m_lastId; // used for ranges of ids
2134 wxObjectEventFunction m_fn; // function to call: not wxEventFunction,
2135 // because of dependency problems
2136
2137 wxObject* m_callbackUserData;
2138 };
2139
2140 #else // !WXWIN_COMPATIBILITY_EVENT_TYPES
2141
2142 // struct containing the members common to static and dynamic event tables
2143 // entries
2144 struct WXDLLIMPEXP_BASE wxEventTableEntryBase
2145 {
2146 private:
2147 wxEventTableEntryBase& operator=(const wxEventTableEntryBase& event);
2148
2149 public:
2150 wxEventTableEntryBase(int winid, int idLast,
2151 wxObjectEventFunction fn, wxObject *data)
2152 : m_id(winid),
2153 m_lastId(idLast),
2154 m_fn(fn),
2155 m_callbackUserData(data)
2156 { }
2157
2158 wxEventTableEntryBase(const wxEventTableEntryBase& event)
2159 : m_id(event.m_id),
2160 m_lastId(event.m_lastId),
2161 m_fn(event.m_fn),
2162 m_callbackUserData(event.m_callbackUserData)
2163 { }
2164
2165 // the range of ids for this entry: if m_lastId == wxID_ANY, the range
2166 // consists only of m_id, otherwise it is m_id..m_lastId inclusive
2167 int m_id,
2168 m_lastId;
2169
2170 // function to call: not wxEventFunction, because of dependency problems
2171 wxObjectEventFunction m_fn;
2172
2173 // arbitrary user data asosciated with the callback
2174 wxObject* m_callbackUserData;
2175 };
2176
2177 // an entry from a static event table
2178 struct WXDLLIMPEXP_BASE wxEventTableEntry : public wxEventTableEntryBase
2179 {
2180 wxEventTableEntry(const int& evType, int winid, int idLast,
2181 wxObjectEventFunction fn, wxObject *data)
2182 : wxEventTableEntryBase(winid, idLast, fn, data),
2183 m_eventType(evType)
2184 { }
2185
2186 // the reference to event type: this allows us to not care about the
2187 // (undefined) order in which the event table entries and the event types
2188 // are initialized: initially the value of this reference might be
2189 // invalid, but by the time it is used for the first time, all global
2190 // objects will have been initialized (including the event type constants)
2191 // and so it will have the correct value when it is needed
2192 const int& m_eventType;
2193
2194 private:
2195 wxEventTableEntry& operator=(const wxEventTableEntry&);
2196 };
2197
2198 // an entry used in dynamic event table managed by wxEvtHandler::Connect()
2199 struct WXDLLIMPEXP_BASE wxDynamicEventTableEntry : public wxEventTableEntryBase
2200 {
2201 wxDynamicEventTableEntry(int evType, int winid, int idLast,
2202 wxObjectEventFunction fn, wxObject *data, wxEvtHandler* eventSink)
2203 : wxEventTableEntryBase(winid, idLast, fn, data),
2204 m_eventType(evType),
2205 m_eventSink(eventSink)
2206 { }
2207
2208 // not a reference here as we can't keep a reference to a temporary int
2209 // created to wrap the constant value typically passed to Connect() - nor
2210 // do we need it
2211 int m_eventType;
2212
2213 // Pointer to object whose function is fn - so we don't assume the
2214 // EventFunction is always a member of the EventHandler receiving the
2215 // message
2216 wxEvtHandler* m_eventSink;
2217
2218 DECLARE_NO_COPY_CLASS(wxDynamicEventTableEntry)
2219 };
2220
2221 #endif // !WXWIN_COMPATIBILITY_EVENT_TYPES
2222
2223 // ----------------------------------------------------------------------------
2224 // wxEventTable: an array of event entries terminated with {0, 0, 0, 0, 0}
2225 // ----------------------------------------------------------------------------
2226
2227 struct WXDLLIMPEXP_BASE wxEventTable
2228 {
2229 const wxEventTable *baseTable; // base event table (next in chain)
2230 const wxEventTableEntry *entries; // bottom of entry array
2231 };
2232
2233 // ----------------------------------------------------------------------------
2234 // wxEventHashTable: a helper of wxEvtHandler to speed up wxEventTable lookups.
2235 // ----------------------------------------------------------------------------
2236
2237 WX_DEFINE_ARRAY_PTR(const wxEventTableEntry*, wxEventTableEntryPointerArray);
2238
2239 class WXDLLIMPEXP_BASE wxEventHashTable
2240 {
2241 private:
2242 // Internal data structs
2243 struct EventTypeTable
2244 {
2245 wxEventType eventType;
2246 wxEventTableEntryPointerArray eventEntryTable;
2247 };
2248 typedef EventTypeTable* EventTypeTablePointer;
2249
2250 public:
2251 // Constructor, needs the event table it needs to hash later on.
2252 // Note: hashing of the event table is not done in the constructor as it
2253 // can be that the event table is not yet full initialize, the hash
2254 // will gets initialized when handling the first event look-up request.
2255 wxEventHashTable(const wxEventTable &table);
2256 // Destructor.
2257 ~wxEventHashTable();
2258
2259 // Handle the given event, in other words search the event table hash
2260 // and call self->ProcessEvent() if a match was found.
2261 bool HandleEvent(wxEvent &event, wxEvtHandler *self);
2262
2263 // Clear table
2264 void Clear();
2265
2266 // Clear all tables
2267 static void ClearAll();
2268
2269 protected:
2270 // Init the hash table with the entries of the static event table.
2271 void InitHashTable();
2272 // Helper funtion of InitHashTable() to insert 1 entry into the hash table.
2273 void AddEntry(const wxEventTableEntry &entry);
2274 // Allocate and init with null pointers the base hash table.
2275 void AllocEventTypeTable(size_t size);
2276 // Grow the hash table in size and transfer all items currently
2277 // in the table to the correct location in the new table.
2278 void GrowEventTypeTable();
2279
2280 protected:
2281 const wxEventTable &m_table;
2282 bool m_rebuildHash;
2283
2284 size_t m_size;
2285 EventTypeTablePointer *m_eventTypeTable;
2286
2287 static wxEventHashTable* sm_first;
2288 wxEventHashTable* m_previous;
2289 wxEventHashTable* m_next;
2290
2291 DECLARE_NO_COPY_CLASS(wxEventHashTable)
2292 };
2293
2294 // ----------------------------------------------------------------------------
2295 // wxEvtHandler: the base class for all objects handling wxWidgets events
2296 // ----------------------------------------------------------------------------
2297
2298 class WXDLLIMPEXP_BASE wxEvtHandler : public wxObject
2299 {
2300 public:
2301 wxEvtHandler();
2302 virtual ~wxEvtHandler();
2303
2304 wxEvtHandler *GetNextHandler() const { return m_nextHandler; }
2305 wxEvtHandler *GetPreviousHandler() const { return m_previousHandler; }
2306 void SetNextHandler(wxEvtHandler *handler) { m_nextHandler = handler; }
2307 void SetPreviousHandler(wxEvtHandler *handler) { m_previousHandler = handler; }
2308
2309 void SetEvtHandlerEnabled(bool enabled) { m_enabled = enabled; }
2310 bool GetEvtHandlerEnabled() const { return m_enabled; }
2311
2312 // process an event right now
2313 virtual bool ProcessEvent(wxEvent& event);
2314
2315 // add an event to be processed later
2316 void AddPendingEvent(wxEvent& event);
2317
2318 // process all pending events
2319 void ProcessPendingEvents();
2320
2321 #if wxUSE_THREADS
2322 bool ProcessThreadEvent(wxEvent& event);
2323 #endif
2324
2325 // Dynamic association of a member function handler with the event handler,
2326 // winid and event type
2327 void Connect(int winid,
2328 int lastId,
2329 int eventType,
2330 wxObjectEventFunction func,
2331 wxObject *userData = (wxObject *) NULL,
2332 wxEvtHandler *eventSink = (wxEvtHandler *) NULL);
2333
2334 // Convenience function: take just one id
2335 void Connect(int winid,
2336 int eventType,
2337 wxObjectEventFunction func,
2338 wxObject *userData = (wxObject *) NULL,
2339 wxEvtHandler *eventSink = (wxEvtHandler *) NULL)
2340 { Connect(winid, wxID_ANY, eventType, func, userData, eventSink); }
2341
2342 // Even more convenient: without id (same as using id of wxID_ANY)
2343 void Connect(int eventType,
2344 wxObjectEventFunction func,
2345 wxObject *userData = (wxObject *) NULL,
2346 wxEvtHandler *eventSink = (wxEvtHandler *) NULL)
2347 { Connect(wxID_ANY, wxID_ANY, eventType, func, userData, eventSink); }
2348
2349 bool Disconnect(int winid,
2350 int lastId,
2351 wxEventType eventType,
2352 wxObjectEventFunction func = NULL,
2353 wxObject *userData = (wxObject *) NULL,
2354 wxEvtHandler *eventSink = (wxEvtHandler *) NULL);
2355
2356 bool Disconnect(int winid = wxID_ANY,
2357 wxEventType eventType = wxEVT_NULL,
2358 wxObjectEventFunction func = NULL,
2359 wxObject *userData = (wxObject *) NULL,
2360 wxEvtHandler *eventSink = (wxEvtHandler *) NULL)
2361 { return Disconnect(winid, wxID_ANY, eventType, func, userData, eventSink); }
2362
2363 bool Disconnect(wxEventType eventType,
2364 wxObjectEventFunction func,
2365 wxObject *userData = (wxObject *) NULL,
2366 wxEvtHandler *eventSink = (wxEvtHandler *) NULL)
2367 { return Disconnect(wxID_ANY, eventType, func, userData, eventSink); }
2368
2369 wxList* GetDynamicEventTable() const { return m_dynamicEvents ; }
2370
2371 // User data can be associated with each wxEvtHandler
2372 void SetClientObject( wxClientData *data ) { DoSetClientObject(data); }
2373 wxClientData *GetClientObject() const { return DoGetClientObject(); }
2374
2375 void SetClientData( void *data ) { DoSetClientData(data); }
2376 void *GetClientData() const { return DoGetClientData(); }
2377
2378 // check if the given event table entry matches this event and call the
2379 // handler if it does
2380 //
2381 // return true if the event was processed, false otherwise (no match or the
2382 // handler decided to skip the event)
2383 static bool ProcessEventIfMatches(const wxEventTableEntryBase& tableEntry,
2384 wxEvtHandler *handler,
2385 wxEvent& event);
2386
2387 // implementation from now on
2388 virtual bool SearchEventTable(wxEventTable& table, wxEvent& event);
2389 bool SearchDynamicEventTable( wxEvent& event );
2390
2391 #if wxUSE_THREADS
2392 void ClearEventLocker();
2393 #endif // wxUSE_THREADS
2394
2395 // Avoid problems at exit by cleaning up static hash table gracefully
2396 void ClearEventHashTable() { GetEventHashTable().Clear(); }
2397
2398 private:
2399 static const wxEventTableEntry sm_eventTableEntries[];
2400
2401 protected:
2402 // hooks for wxWindow used by ProcessEvent()
2403 // -----------------------------------------
2404
2405 // This one is called before trying our own event table to allow plugging
2406 // in the validators.
2407 //
2408 // NB: This method is intentionally *not* inside wxUSE_VALIDATORS!
2409 // It is part of wxBase which doesn't use validators and the code
2410 // is compiled out when building wxBase w/o GUI classes, which affects
2411 // binary compatibility and wxBase library can't be used by GUI
2412 // ports.
2413 virtual bool TryValidator(wxEvent& WXUNUSED(event)) { return false; }
2414
2415 // this one is called after failing to find the event handle in our own
2416 // table to give a chance to the other windows to process it
2417 //
2418 // base class implementation passes the event to wxTheApp
2419 virtual bool TryParent(wxEvent& event);
2420
2421
2422 static const wxEventTable sm_eventTable;
2423 virtual const wxEventTable *GetEventTable() const;
2424
2425 static wxEventHashTable sm_eventHashTable;
2426 virtual wxEventHashTable& GetEventHashTable() const;
2427
2428 wxEvtHandler* m_nextHandler;
2429 wxEvtHandler* m_previousHandler;
2430 wxList* m_dynamicEvents;
2431 wxList* m_pendingEvents;
2432
2433 #if wxUSE_THREADS
2434 #if defined (__VISAGECPP__)
2435 const wxCriticalSection& Lock() const { return m_eventsLocker; }
2436 wxCriticalSection& Lock() { return m_eventsLocker; }
2437
2438 wxCriticalSection m_eventsLocker;
2439 # else
2440 const wxCriticalSection& Lock() const { return *m_eventsLocker; }
2441 wxCriticalSection& Lock() { return *m_eventsLocker; }
2442
2443 wxCriticalSection* m_eventsLocker;
2444 # endif
2445 #endif
2446
2447 // Is event handler enabled?
2448 bool m_enabled;
2449
2450
2451 // The user data: either an object which will be deleted by the container
2452 // when it's deleted or some raw pointer which we do nothing with - only
2453 // one type of data can be used with the given window (i.e. you cannot set
2454 // the void data and then associate the container with wxClientData or vice
2455 // versa)
2456 union
2457 {
2458 wxClientData *m_clientObject;
2459 void *m_clientData;
2460 };
2461
2462 // what kind of data do we have?
2463 wxClientDataType m_clientDataType;
2464
2465 // client data accessors
2466 virtual void DoSetClientObject( wxClientData *data );
2467 virtual wxClientData *DoGetClientObject() const;
2468
2469 virtual void DoSetClientData( void *data );
2470 virtual void *DoGetClientData() const;
2471
2472 private:
2473 DECLARE_DYNAMIC_CLASS_NO_COPY(wxEvtHandler)
2474 };
2475
2476 // Post a message to the given eventhandler which will be processed during the
2477 // next event loop iteration
2478 inline void wxPostEvent(wxEvtHandler *dest, wxEvent& event)
2479 {
2480 wxCHECK_RET( dest, wxT("need an object to post event to in wxPostEvent") );
2481
2482 dest->AddPendingEvent(event);
2483 }
2484
2485 typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&);
2486
2487 #define wxEventHandler(func) \
2488 (wxObjectEventFunction)wxStaticCastEvent(wxEventFunction, &func)
2489
2490 #if wxUSE_GUI
2491
2492 typedef void (wxEvtHandler::*wxCommandEventFunction)(wxCommandEvent&);
2493 typedef void (wxEvtHandler::*wxScrollEventFunction)(wxScrollEvent&);
2494 typedef void (wxEvtHandler::*wxScrollWinEventFunction)(wxScrollWinEvent&);
2495 typedef void (wxEvtHandler::*wxSizeEventFunction)(wxSizeEvent&);
2496 typedef void (wxEvtHandler::*wxMoveEventFunction)(wxMoveEvent&);
2497 typedef void (wxEvtHandler::*wxPaintEventFunction)(wxPaintEvent&);
2498 typedef void (wxEvtHandler::*wxNcPaintEventFunction)(wxNcPaintEvent&);
2499 typedef void (wxEvtHandler::*wxEraseEventFunction)(wxEraseEvent&);
2500 typedef void (wxEvtHandler::*wxMouseEventFunction)(wxMouseEvent&);
2501 typedef void (wxEvtHandler::*wxCharEventFunction)(wxKeyEvent&);
2502 typedef void (wxEvtHandler::*wxFocusEventFunction)(wxFocusEvent&);
2503 typedef void (wxEvtHandler::*wxChildFocusEventFunction)(wxChildFocusEvent&);
2504 typedef void (wxEvtHandler::*wxActivateEventFunction)(wxActivateEvent&);
2505 typedef void (wxEvtHandler::*wxMenuEventFunction)(wxMenuEvent&);
2506 typedef void (wxEvtHandler::*wxJoystickEventFunction)(wxJoystickEvent&);
2507 typedef void (wxEvtHandler::*wxDropFilesEventFunction)(wxDropFilesEvent&);
2508 typedef void (wxEvtHandler::*wxInitDialogEventFunction)(wxInitDialogEvent&);
2509 typedef void (wxEvtHandler::*wxSysColourChangedEventFunction)(wxSysColourChangedEvent&);
2510 typedef void (wxEvtHandler::*wxDisplayChangedEventFunction)(wxDisplayChangedEvent&);
2511 typedef void (wxEvtHandler::*wxUpdateUIEventFunction)(wxUpdateUIEvent&);
2512 typedef void (wxEvtHandler::*wxIdleEventFunction)(wxIdleEvent&);
2513 typedef void (wxEvtHandler::*wxCloseEventFunction)(wxCloseEvent&);
2514 typedef void (wxEvtHandler::*wxShowEventFunction)(wxShowEvent&);
2515 typedef void (wxEvtHandler::*wxIconizeEventFunction)(wxIconizeEvent&);
2516 typedef void (wxEvtHandler::*wxMaximizeEventFunction)(wxMaximizeEvent&);
2517 typedef void (wxEvtHandler::*wxNavigationKeyEventFunction)(wxNavigationKeyEvent&);
2518 typedef void (wxEvtHandler::*wxPaletteChangedEventFunction)(wxPaletteChangedEvent&);
2519 typedef void (wxEvtHandler::*wxQueryNewPaletteEventFunction)(wxQueryNewPaletteEvent&);
2520 typedef void (wxEvtHandler::*wxWindowCreateEventFunction)(wxWindowCreateEvent&);
2521 typedef void (wxEvtHandler::*wxWindowDestroyEventFunction)(wxWindowDestroyEvent&);
2522 typedef void (wxEvtHandler::*wxSetCursorEventFunction)(wxSetCursorEvent&);
2523 typedef void (wxEvtHandler::*wxNotifyEventFunction)(wxNotifyEvent&);
2524 typedef void (wxEvtHandler::*wxHelpEventFunction)(wxHelpEvent&);
2525 typedef void (wxEvtHandler::*wxContextMenuEventFunction)(wxContextMenuEvent&);
2526 typedef void (wxEvtHandler::*wxMouseCaptureChangedEventFunction)(wxMouseCaptureChangedEvent&);
2527
2528 // these typedefs don't have the same name structure as the others, keep for
2529 // backwards compatibility only
2530 #if WXWIN_COMPATIBILITY_2_4
2531 typedef wxSysColourChangedEventFunction wxSysColourChangedFunction;
2532 typedef wxDisplayChangedEventFunction wxDisplayChangedFunction;
2533 #endif // WXWIN_COMPATIBILITY_2_4
2534
2535
2536 #define wxCommandEventHandler(func) \
2537 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxCommandEventFunction, &func)
2538 #define wxScrollEventHandler(func) \
2539 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxScrollEventFunction, &func)
2540 #define wxScrollWinEventHandler(func) \
2541 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxScrollWinEventFunction, &func)
2542 #define wxSizeEventHandler(func) \
2543 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxSizeEventFunction, &func)
2544 #define wxMoveEventHandler(func) \
2545 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMoveEventFunction, &func)
2546 #define wxPaintEventHandler(func) \
2547 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxPaintEventFunction, &func)
2548 #define wxNcPaintEventHandler(func) \
2549 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxNcPaintEventFunction, &func)
2550 #define wxEraseEventHandler(func) \
2551 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxEraseEventFunction, &func)
2552 #define wxMouseEventHandler(func) \
2553 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMouseEventFunction, &func)
2554 #define wxCharEventHandler(func) \
2555 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxCharEventFunction, &func)
2556 #define wxKeyEventHandler(func) wxCharEventHandler(func)
2557 #define wxFocusEventHandler(func) \
2558 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxFocusEventFunction, &func)
2559 #define wxChildFocusEventHandler(func) \
2560 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxChildFocusEventFunction, &func)
2561 #define wxActivateEventHandler(func) \
2562 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxActivateEventFunction, &func)
2563 #define wxMenuEventHandler(func) \
2564 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMenuEventFunction, &func)
2565 #define wxJoystickEventHandler(func) \
2566 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxJoystickEventFunction, &func)
2567 #define wxDropFilesEventHandler(func) \
2568 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDropFilesEventFunction, &func)
2569 #define wxInitDialogEventHandler(func) \
2570 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxInitDialogEventFunction, &func)
2571 #define wxSysColourChangedEventHandler(func) \
2572 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxSysColourChangedEventFunction, &func)
2573 #define wxDisplayChangedEventHandler(func) \
2574 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDisplayChangedEventFunction, &func)
2575 #define wxUpdateUIEventHandler(func) \
2576 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxUpdateUIEventFunction, &func)
2577 #define wxIdleEventHandler(func) \
2578 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxIdleEventFunction, &func)
2579 #define wxCloseEventHandler(func) \
2580 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxCloseEventFunction, &func)
2581 #define wxShowEventHandler(func) \
2582 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxShowEventFunction, &func)
2583 #define wxIconizeEventHandler(func) \
2584 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxIconizeEventFunction, &func)
2585 #define wxMaximizeEventHandler(func) \
2586 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMaximizeEventFunction, &func)
2587 #define wxNavigationKeyEventHandler(func) \
2588 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxNavigationKeyEventFunction, &func)
2589 #define wxPaletteChangedEventHandler(func) \
2590 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxPaletteChangedEventFunction, &func)
2591 #define wxQueryNewPaletteEventHandler(func) \
2592 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxQueryNewPaletteEventFunction, &func)
2593 #define wxWindowCreateEventHandler(func) \
2594 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxWindowCreateEventFunction, &func)
2595 #define wxWindowDestroyEventHandler(func) \
2596 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxWindowDestroyEventFunction, &func)
2597 #define wxSetCursorEventHandler(func) \
2598 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxSetCursorEventFunction, &func)
2599 #define wxNotifyEventHandler(func) \
2600 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxNotifyEventFunction, &func)
2601 #define wxHelpEventHandler(func) \
2602 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxHelpEventFunction, &func)
2603 #define wxContextMenuEventHandler(func) \
2604 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxContextMenuEventFunction, &func)
2605 #define wxMouseCaptureChangedEventHandler(func) \
2606 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxMouseCaptureChangedEventFunction, &func)
2607
2608 #endif // wxUSE_GUI
2609
2610 // N.B. In GNU-WIN32, you *have* to take the address of a member function
2611 // (use &) or the compiler crashes...
2612
2613 #define DECLARE_EVENT_TABLE() \
2614 private: \
2615 static const wxEventTableEntry sm_eventTableEntries[]; \
2616 protected: \
2617 static const wxEventTable sm_eventTable; \
2618 virtual const wxEventTable* GetEventTable() const; \
2619 static wxEventHashTable sm_eventHashTable; \
2620 virtual wxEventHashTable& GetEventHashTable() const;
2621
2622 // N.B.: when building DLL with Borland C++ 5.5 compiler, you must initialize
2623 // sm_eventTable before using it in GetEventTable() or the compiler gives
2624 // E2233 (see http://groups.google.com/groups?selm=397dcc8a%241_2%40dnews)
2625
2626 #define BEGIN_EVENT_TABLE(theClass, baseClass) \
2627 const wxEventTable theClass::sm_eventTable = \
2628 { &baseClass::sm_eventTable, &theClass::sm_eventTableEntries[0] }; \
2629 const wxEventTable *theClass::GetEventTable() const \
2630 { return &theClass::sm_eventTable; } \
2631 wxEventHashTable theClass::sm_eventHashTable(theClass::sm_eventTable); \
2632 wxEventHashTable &theClass::GetEventHashTable() const \
2633 { return theClass::sm_eventHashTable; } \
2634 const wxEventTableEntry theClass::sm_eventTableEntries[] = { \
2635
2636 #define END_EVENT_TABLE() DECLARE_EVENT_TABLE_ENTRY( wxEVT_NULL, 0, 0, 0, 0 ) };
2637
2638 /*
2639 * Event table macros
2640 */
2641
2642 // helpers for writing shorter code below: declare an event macro taking 2, 1
2643 // or none ids (the missing ids default to wxID_ANY)
2644 //
2645 // macro arguments:
2646 // - evt one of wxEVT_XXX constants
2647 // - id1, id2 ids of the first/last id
2648 // - fn the function (should be cast to the right type)
2649 #define wx__DECLARE_EVT2(evt, id1, id2, fn) \
2650 DECLARE_EVENT_TABLE_ENTRY(evt, id1, id2, fn, NULL),
2651 #define wx__DECLARE_EVT1(evt, id, fn) \
2652 wx__DECLARE_EVT2(evt, id, wxID_ANY, fn)
2653 #define wx__DECLARE_EVT0(evt, fn) \
2654 wx__DECLARE_EVT1(evt, wxID_ANY, fn)
2655
2656
2657 // Generic events
2658 #define EVT_CUSTOM(event, winid, func) \
2659 wx__DECLARE_EVT1(event, winid, wxEventHandler(func))
2660 #define EVT_CUSTOM_RANGE(event, id1, id2, func) \
2661 wx__DECLARE_EVT2(event, id1, id2, wxEventHandler(func))
2662
2663 // EVT_COMMAND
2664 #define EVT_COMMAND(winid, event, func) \
2665 wx__DECLARE_EVT1(event, winid, wxCommandEventHandler(func))
2666 #define EVT_COMMAND_RANGE(id1, id2, event, func) \
2667 wx__DECLARE_EVT2(event, id1, id2, wxCommandEventHandler(func))
2668
2669 #define EVT_NOTIFY(event, winid, func) \
2670 wx__DECLARE_EVT1(event, winid, wxNotifyEventHandler(func))
2671 #define EVT_NOTIFY_RANGE(event, id1, id2, func) \
2672 wx__DECLARE_EVT2(event, id1, id2, wxNotifyEventHandler(func))
2673
2674 // Miscellaneous
2675 #define EVT_SIZE(func) wx__DECLARE_EVT0(wxEVT_SIZE, wxSizeEventHandler(func))
2676 #define EVT_SIZING(func) wx__DECLARE_EVT0(wxEVT_SIZING, wxSizeEventHandler(func))
2677 #define EVT_MOVE(func) wx__DECLARE_EVT0(wxEVT_MOVE, wxMoveEventHandler(func))
2678 #define EVT_MOVING(func) wx__DECLARE_EVT0(wxEVT_MOVING, wxMoveEventHandler(func))
2679 #define EVT_CLOSE(func) wx__DECLARE_EVT0(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(func))
2680 #define EVT_END_SESSION(func) wx__DECLARE_EVT0(wxEVT_END_SESSION, wxCloseEventHandler(func))
2681 #define EVT_QUERY_END_SESSION(func) wx__DECLARE_EVT0(wxEVT_QUERY_END_SESSION, wxCloseEventHandler(func))
2682 #define EVT_PAINT(func) wx__DECLARE_EVT0(wxEVT_PAINT, wxPaintEventHandler(func))
2683 #define EVT_NC_PAINT(func) wx__DECLARE_EVT0(wxEVT_NC_PAINT, wxNcPaintEventHandler(func))
2684 #define EVT_ERASE_BACKGROUND(func) wx__DECLARE_EVT0(wxEVT_ERASE_BACKGROUND, wxEraseEventHandler(func))
2685 #define EVT_CHAR(func) wx__DECLARE_EVT0(wxEVT_CHAR, wxCharEventHandler(func))
2686 #define EVT_KEY_DOWN(func) wx__DECLARE_EVT0(wxEVT_KEY_DOWN, wxKeyEventHandler(func))
2687 #define EVT_KEY_UP(func) wx__DECLARE_EVT0(wxEVT_KEY_UP, wxKeyEventHandler(func))
2688 #if wxUSE_HOTKEY
2689 #define EVT_HOTKEY(winid, func) wx__DECLARE_EVT1(wxEVT_HOTKEY, winid, wxCharEventHandler(func))
2690 #endif
2691 #define EVT_CHAR_HOOK(func) wx__DECLARE_EVT0(wxEVT_CHAR_HOOK, wxCharEventHandler(func))
2692 #define EVT_MENU_OPEN(func) wx__DECLARE_EVT0(wxEVT_MENU_OPEN, wxMenuEventHandler(func))
2693 #define EVT_MENU_CLOSE(func) wx__DECLARE_EVT0(wxEVT_MENU_CLOSE, wxMenuEventHandler(func))
2694 #define EVT_MENU_HIGHLIGHT(winid, func) wx__DECLARE_EVT1(wxEVT_MENU_HIGHLIGHT, winid, wxMenuEventHandler(func))
2695 #define EVT_MENU_HIGHLIGHT_ALL(func) wx__DECLARE_EVT0(wxEVT_MENU_HIGHLIGHT, wxMenuEventHandler(func))
2696 #define EVT_SET_FOCUS(func) wx__DECLARE_EVT0(wxEVT_SET_FOCUS, wxFocusEventHandler(func))
2697 #define EVT_KILL_FOCUS(func) wx__DECLARE_EVT0(wxEVT_KILL_FOCUS, wxFocusEventHandler(func))
2698 #define EVT_CHILD_FOCUS(func) wx__DECLARE_EVT0(wxEVT_CHILD_FOCUS, wxChildFocusEventHandler(func))
2699 #define EVT_ACTIVATE(func) wx__DECLARE_EVT0(wxEVT_ACTIVATE, wxActivateEventHandler(func))
2700 #define EVT_ACTIVATE_APP(func) wx__DECLARE_EVT0(wxEVT_ACTIVATE_APP, wxActivateEventHandler(func))
2701 #define EVT_HIBERNATE(func) wx__DECLARE_EVT0(wxEVT_HIBERNATE, wxActivateEventHandler(func))
2702 #define EVT_END_SESSION(func) wx__DECLARE_EVT0(wxEVT_END_SESSION, wxCloseEventHandler(func))
2703 #define EVT_QUERY_END_SESSION(func) wx__DECLARE_EVT0(wxEVT_QUERY_END_SESSION, wxCloseEventHandler(func))
2704 #define EVT_DROP_FILES(func) wx__DECLARE_EVT0(wxEVT_DROP_FILES, wxDropFilesEventHandler(func))
2705 #define EVT_INIT_DIALOG(func) wx__DECLARE_EVT0(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(func))
2706 #define EVT_SYS_COLOUR_CHANGED(func) wx__DECLARE_EVT0(wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEventHandler(func))
2707 #define EVT_DISPLAY_CHANGED(func) wx__DECLARE_EVT0(wxEVT_DISPLAY_CHANGED, wxDisplayChangedEventHandler(func))
2708 #define EVT_SHOW(func) wx__DECLARE_EVT0(wxEVT_SHOW, wxShowEventHandler(func))
2709 #define EVT_MAXIMIZE(func) wx__DECLARE_EVT0(wxEVT_MAXIMIZE, wxMaximizeEventHandler(func))
2710 #define EVT_ICONIZE(func) wx__DECLARE_EVT0(wxEVT_ICONIZE, wxIconizeEventHandler(func))
2711 #define EVT_NAVIGATION_KEY(func) wx__DECLARE_EVT0(wxEVT_NAVIGATION_KEY, wxNavigationKeyEventHandler(func))
2712 #define EVT_PALETTE_CHANGED(func) wx__DECLARE_EVT0(wxEVT_PALETTE_CHANGED, wxPaletteChangedEventHandler(func))
2713 #define EVT_QUERY_NEW_PALETTE(func) wx__DECLARE_EVT0(wxEVT_QUERY_NEW_PALETTE, wxQueryNewPaletteEventHandler(func))
2714 #define EVT_WINDOW_CREATE(func) wx__DECLARE_EVT0(wxEVT_CREATE, wxWindowCreateEventHandler(func))
2715 #define EVT_WINDOW_DESTROY(func) wx__DECLARE_EVT0(wxEVT_DESTROY, wxWindowDestroyEventHandler(func))
2716 #define EVT_SET_CURSOR(func) wx__DECLARE_EVT0(wxEVT_SET_CURSOR, wxSetCursorEventHandler(func))
2717 #define EVT_MOUSE_CAPTURE_CHANGED(func) wx__DECLARE_EVT0(wxEVT_MOUSE_CAPTURE_CHANGED, wxMouseCaptureChangedEventHandler(func))
2718
2719 // Mouse events
2720 #define EVT_LEFT_DOWN(func) wx__DECLARE_EVT0(wxEVT_LEFT_DOWN, wxMouseEventHandler(func))
2721 #define EVT_LEFT_UP(func) wx__DECLARE_EVT0(wxEVT_LEFT_UP, wxMouseEventHandler(func))
2722 #define EVT_MIDDLE_DOWN(func) wx__DECLARE_EVT0(wxEVT_MIDDLE_DOWN, wxMouseEventHandler(func))
2723 #define EVT_MIDDLE_UP(func) wx__DECLARE_EVT0(wxEVT_MIDDLE_UP, wxMouseEventHandler(func))
2724 #define EVT_RIGHT_DOWN(func) wx__DECLARE_EVT0(wxEVT_RIGHT_DOWN, wxMouseEventHandler(func))
2725 #define EVT_RIGHT_UP(func) wx__DECLARE_EVT0(wxEVT_RIGHT_UP, wxMouseEventHandler(func))
2726 #define EVT_MOTION(func) wx__DECLARE_EVT0(wxEVT_MOTION, wxMouseEventHandler(func))
2727 #define EVT_LEFT_DCLICK(func) wx__DECLARE_EVT0(wxEVT_LEFT_DCLICK, wxMouseEventHandler(func))
2728 #define EVT_MIDDLE_DCLICK(func) wx__DECLARE_EVT0(wxEVT_MIDDLE_DCLICK, wxMouseEventHandler(func))
2729 #define EVT_RIGHT_DCLICK(func) wx__DECLARE_EVT0(wxEVT_RIGHT_DCLICK, wxMouseEventHandler(func))
2730 #define EVT_LEAVE_WINDOW(func) wx__DECLARE_EVT0(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(func))
2731 #define EVT_ENTER_WINDOW(func) wx__DECLARE_EVT0(wxEVT_ENTER_WINDOW, wxMouseEventHandler(func))
2732 #define EVT_MOUSEWHEEL(func) wx__DECLARE_EVT0(wxEVT_MOUSEWHEEL, wxMouseEventHandler(func))
2733
2734 // All mouse events
2735 #define EVT_MOUSE_EVENTS(func) \
2736 EVT_LEFT_DOWN(func) \
2737 EVT_LEFT_UP(func) \
2738 EVT_MIDDLE_DOWN(func) \
2739 EVT_MIDDLE_UP(func) \
2740 EVT_RIGHT_DOWN(func) \
2741 EVT_RIGHT_UP(func) \
2742 EVT_MOTION(func) \
2743 EVT_LEFT_DCLICK(func) \
2744 EVT_MIDDLE_DCLICK(func) \
2745 EVT_RIGHT_DCLICK(func) \
2746 EVT_LEAVE_WINDOW(func) \
2747 EVT_ENTER_WINDOW(func) \
2748 EVT_MOUSEWHEEL(func)
2749
2750 // Scrolling from wxWindow (sent to wxScrolledWindow)
2751 #define EVT_SCROLLWIN_TOP(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_TOP, wxScrollWinEventHandler(func))
2752 #define EVT_SCROLLWIN_BOTTOM(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_BOTTOM, wxScrollWinEventHandler(func))
2753 #define EVT_SCROLLWIN_LINEUP(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_LINEUP, wxScrollWinEventHandler(func))
2754 #define EVT_SCROLLWIN_LINEDOWN(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_LINEDOWN, wxScrollWinEventHandler(func))
2755 #define EVT_SCROLLWIN_PAGEUP(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_PAGEUP, wxScrollWinEventHandler(func))
2756 #define EVT_SCROLLWIN_PAGEDOWN(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_PAGEDOWN, wxScrollWinEventHandler(func))
2757 #define EVT_SCROLLWIN_THUMBTRACK(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_THUMBTRACK, wxScrollWinEventHandler(func))
2758 #define EVT_SCROLLWIN_THUMBRELEASE(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_THUMBRELEASE, wxScrollWinEventHandler(func))
2759
2760 #define EVT_SCROLLWIN(func) \
2761 EVT_SCROLLWIN_TOP(func) \
2762 EVT_SCROLLWIN_BOTTOM(func) \
2763 EVT_SCROLLWIN_LINEUP(func) \
2764 EVT_SCROLLWIN_LINEDOWN(func) \
2765 EVT_SCROLLWIN_PAGEUP(func) \
2766 EVT_SCROLLWIN_PAGEDOWN(func) \
2767 EVT_SCROLLWIN_THUMBTRACK(func) \
2768 EVT_SCROLLWIN_THUMBRELEASE(func)
2769
2770 // Scrolling from wxSlider and wxScrollBar
2771 #define EVT_SCROLL_TOP(func) wx__DECLARE_EVT0(wxEVT_SCROLL_TOP, wxScrollEventHandler(func))
2772 #define EVT_SCROLL_BOTTOM(func) wx__DECLARE_EVT0(wxEVT_SCROLL_BOTTOM, wxScrollEventHandler(func))
2773 #define EVT_SCROLL_LINEUP(func) wx__DECLARE_EVT0(wxEVT_SCROLL_LINEUP, wxScrollEventHandler(func))
2774 #define EVT_SCROLL_LINEDOWN(func) wx__DECLARE_EVT0(wxEVT_SCROLL_LINEDOWN, wxScrollEventHandler(func))
2775 #define EVT_SCROLL_PAGEUP(func) wx__DECLARE_EVT0(wxEVT_SCROLL_PAGEUP, wxScrollEventHandler(func))
2776 #define EVT_SCROLL_PAGEDOWN(func) wx__DECLARE_EVT0(wxEVT_SCROLL_PAGEDOWN, wxScrollEventHandler(func))
2777 #define EVT_SCROLL_THUMBTRACK(func) wx__DECLARE_EVT0(wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler(func))
2778 #define EVT_SCROLL_THUMBRELEASE(func) wx__DECLARE_EVT0(wxEVT_SCROLL_THUMBRELEASE, wxScrollEventHandler(func))
2779 #define EVT_SCROLL_CHANGED(func) wx__DECLARE_EVT0(wxEVT_SCROLL_CHANGED, wxScrollEventHandler(func))
2780
2781 #define EVT_SCROLL(func) \
2782 EVT_SCROLL_TOP(func) \
2783 EVT_SCROLL_BOTTOM(func) \
2784 EVT_SCROLL_LINEUP(func) \
2785 EVT_SCROLL_LINEDOWN(func) \
2786 EVT_SCROLL_PAGEUP(func) \
2787 EVT_SCROLL_PAGEDOWN(func) \
2788 EVT_SCROLL_THUMBTRACK(func) \
2789 EVT_SCROLL_THUMBRELEASE(func) \
2790 EVT_SCROLL_CHANGED(func)
2791
2792 // Scrolling from wxSlider and wxScrollBar, with an id
2793 #define EVT_COMMAND_SCROLL_TOP(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_TOP, winid, wxScrollEventHandler(func))
2794 #define EVT_COMMAND_SCROLL_BOTTOM(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_BOTTOM, winid, wxScrollEventHandler(func))
2795 #define EVT_COMMAND_SCROLL_LINEUP(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_LINEUP, winid, wxScrollEventHandler(func))
2796 #define EVT_COMMAND_SCROLL_LINEDOWN(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_LINEDOWN, winid, wxScrollEventHandler(func))
2797 #define EVT_COMMAND_SCROLL_PAGEUP(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_PAGEUP, winid, wxScrollEventHandler(func))
2798 #define EVT_COMMAND_SCROLL_PAGEDOWN(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_PAGEDOWN, winid, wxScrollEventHandler(func))
2799 #define EVT_COMMAND_SCROLL_THUMBTRACK(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_THUMBTRACK, winid, wxScrollEventHandler(func))
2800 #define EVT_COMMAND_SCROLL_THUMBRELEASE(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_THUMBRELEASE, winid, wxScrollEventHandler(func))
2801 #define EVT_COMMAND_SCROLL_CHANGED(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_CHANGED, winid, wxScrollEventHandler(func))
2802
2803 #define EVT_COMMAND_SCROLL(winid, func) \
2804 EVT_COMMAND_SCROLL_TOP(winid, func) \
2805 EVT_COMMAND_SCROLL_BOTTOM(winid, func) \
2806 EVT_COMMAND_SCROLL_LINEUP(winid, func) \
2807 EVT_COMMAND_SCROLL_LINEDOWN(winid, func) \
2808 EVT_COMMAND_SCROLL_PAGEUP(winid, func) \
2809 EVT_COMMAND_SCROLL_PAGEDOWN(winid, func) \
2810 EVT_COMMAND_SCROLL_THUMBTRACK(winid, func) \
2811 EVT_COMMAND_SCROLL_THUMBRELEASE(winid, func) \
2812 EVT_COMMAND_SCROLL_CHANGED(winid, func)
2813
2814 // this is the old name of this event, to be deprecated in 2.8
2815 #define wxEVT_SCROLL_ENDSCROLL wxEVT_SCROLL_CHANGED
2816 #define EVT_COMMAND_SCROLL_ENDSCROLL EVT_COMMAND_SCROLL_CHANGED
2817 #define EVT_SCROLL_ENDSCROLL EVT_SCROLL_CHANGED
2818
2819 // Convenience macros for commonly-used commands
2820 #define EVT_CHECKBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_CHECKBOX_CLICKED, winid, wxCommandEventHandler(func))
2821 #define EVT_CHOICE(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_CHOICE_SELECTED, winid, wxCommandEventHandler(func))
2822 #define EVT_LISTBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_LISTBOX_SELECTED, winid, wxCommandEventHandler(func))
2823 #define EVT_LISTBOX_DCLICK(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, winid, wxCommandEventHandler(func))
2824 #define EVT_MENU(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_MENU_SELECTED, winid, wxCommandEventHandler(func))
2825 #define EVT_MENU_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_COMMAND_MENU_SELECTED, id1, id2, wxCommandEventHandler(func))
2826 #if defined(__SMARTPHONE__)
2827 # define EVT_BUTTON(winid, func) EVT_MENU(winid, func)
2828 #else
2829 # define EVT_BUTTON(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_BUTTON_CLICKED, winid, wxCommandEventHandler(func))
2830 #endif
2831 #define EVT_SLIDER(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_SLIDER_UPDATED, winid, wxCommandEventHandler(func))
2832 #define EVT_RADIOBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_RADIOBOX_SELECTED, winid, wxCommandEventHandler(func))
2833 #define EVT_RADIOBUTTON(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_RADIOBUTTON_SELECTED, winid, wxCommandEventHandler(func))
2834 // EVT_SCROLLBAR is now obsolete since we use EVT_COMMAND_SCROLL... events
2835 #define EVT_SCROLLBAR(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_SCROLLBAR_UPDATED, winid, wxCommandEventHandler(func))
2836 #define EVT_VLBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_VLBOX_SELECTED, winid, wxCommandEventHandler(func))
2837 #define EVT_COMBOBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_COMBOBOX_SELECTED, winid, wxCommandEventHandler(func))
2838 #define EVT_TOOL(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_TOOL_CLICKED, winid, wxCommandEventHandler(func))
2839 #define EVT_TOOL_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_COMMAND_TOOL_CLICKED, id1, id2, wxCommandEventHandler(func))
2840 #define EVT_TOOL_RCLICKED(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_TOOL_RCLICKED, winid, wxCommandEventHandler(func))
2841 #define EVT_TOOL_RCLICKED_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_COMMAND_TOOL_RCLICKED, id1, id2, wxCommandEventHandler(func))
2842 #define EVT_TOOL_ENTER(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_TOOL_ENTER, winid, wxCommandEventHandler(func))
2843 #define EVT_CHECKLISTBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, winid, wxCommandEventHandler(func))
2844
2845 // Generic command events
2846 #define EVT_COMMAND_LEFT_CLICK(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_LEFT_CLICK, winid, wxCommandEventHandler(func))
2847 #define EVT_COMMAND_LEFT_DCLICK(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_LEFT_DCLICK, winid, wxCommandEventHandler(func))
2848 #define EVT_COMMAND_RIGHT_CLICK(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_RIGHT_CLICK, winid, wxCommandEventHandler(func))
2849 #define EVT_COMMAND_RIGHT_DCLICK(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_RIGHT_DCLICK, winid, wxCommandEventHandler(func))
2850 #define EVT_COMMAND_SET_FOCUS(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_SET_FOCUS, winid, wxCommandEventHandler(func))
2851 #define EVT_COMMAND_KILL_FOCUS(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_KILL_FOCUS, winid, wxCommandEventHandler(func))
2852 #define EVT_COMMAND_ENTER(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_ENTER, winid, wxCommandEventHandler(func))
2853
2854 // Joystick events
2855
2856 #define EVT_JOY_BUTTON_DOWN(func) wx__DECLARE_EVT0(wxEVT_JOY_BUTTON_DOWN, wxJoystickEventHandler(func))
2857 #define EVT_JOY_BUTTON_UP(func) wx__DECLARE_EVT0(wxEVT_JOY_BUTTON_UP, wxJoystickEventHandler(func))
2858 #define EVT_JOY_MOVE(func) wx__DECLARE_EVT0(wxEVT_JOY_MOVE, wxJoystickEventHandler(func))
2859 #define EVT_JOY_ZMOVE(func) wx__DECLARE_EVT0(wxEVT_JOY_ZMOVE, wxJoystickEventHandler(func))
2860
2861 // These are obsolete, see _BUTTON_ events
2862 #if WXWIN_COMPATIBILITY_2_4
2863 #define EVT_JOY_DOWN(func) EVT_JOY_BUTTON_DOWN(func)
2864 #define EVT_JOY_UP(func) EVT_JOY_BUTTON_UP(func)
2865 #endif // WXWIN_COMPATIBILITY_2_4
2866
2867 // All joystick events
2868 #define EVT_JOYSTICK_EVENTS(func) \
2869 EVT_JOY_BUTTON_DOWN(func) \
2870 EVT_JOY_BUTTON_UP(func) \
2871 EVT_JOY_MOVE(func) \
2872 EVT_JOY_ZMOVE(func)
2873
2874 // Idle event
2875 #define EVT_IDLE(func) wx__DECLARE_EVT0(wxEVT_IDLE, wxIdleEventHandler(func))
2876
2877 // Update UI event
2878 #define EVT_UPDATE_UI(winid, func) wx__DECLARE_EVT1(wxEVT_UPDATE_UI, winid, wxUpdateUIEventHandler(func))
2879 #define EVT_UPDATE_UI_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_UPDATE_UI, id1, id2, wxUpdateUIEventHandler(func))
2880
2881 // Help events
2882 #define EVT_HELP(winid, func) wx__DECLARE_EVT1(wxEVT_HELP, winid, wxHelpEventHandler(func))
2883 #define EVT_HELP_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_HELP, id1, id2, wxHelpEventHandler(func))
2884 #define EVT_DETAILED_HELP(winid, func) wx__DECLARE_EVT1(wxEVT_DETAILED_HELP, winid, wxHelpEventHandler(func))
2885 #define EVT_DETAILED_HELP_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_DETAILED_HELP, id1, id2, wxHelpEventHandler(func))
2886
2887 // Context Menu Events
2888 #define EVT_CONTEXT_MENU(func) wx__DECLARE_EVT0(wxEVT_CONTEXT_MENU, wxContextMenuEventHandler(func))
2889 #define EVT_COMMAND_CONTEXT_MENU(winid, func) wx__DECLARE_EVT1(wxEVT_CONTEXT_MENU, winid, wxContextMenuEventHandler(func))
2890
2891 // ----------------------------------------------------------------------------
2892 // Global data
2893 // ----------------------------------------------------------------------------
2894
2895 // for pending event processing - notice that there is intentionally no
2896 // WXDLLEXPORT here
2897 extern WXDLLIMPEXP_BASE wxList *wxPendingEvents;
2898 #if wxUSE_THREADS
2899 extern WXDLLIMPEXP_BASE wxCriticalSection *wxPendingEventsLocker;
2900 #endif
2901
2902 // ----------------------------------------------------------------------------
2903 // Helper functions
2904 // ----------------------------------------------------------------------------
2905
2906 #if wxUSE_GUI
2907
2908 // Find a window with the focus, that is also a descendant of the given window.
2909 // This is used to determine the window to initially send commands to.
2910 wxWindow* wxFindFocusDescendant(wxWindow* ancestor);
2911
2912 #endif // wxUSE_GUI
2913
2914 #endif // _WX_EVENT_H__
2915