remove wxNewEventFunctor() overload which allowed calls to "Bind(evt, &WrongClass...
[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 #include "wx/defs.h"
16 #include "wx/cpp.h"
17 #include "wx/object.h"
18 #include "wx/clntdata.h"
19
20 #if wxUSE_GUI
21 #include "wx/gdicmn.h"
22 #include "wx/cursor.h"
23 #include "wx/mousestate.h"
24 #endif
25
26 #include "wx/dynarray.h"
27 #include "wx/thread.h"
28 #include "wx/tracker.h"
29
30 #if !wxEVENTS_COMPATIBILITY_2_8
31 #include "wx/meta/convertible.h"
32 #endif
33
34 // ----------------------------------------------------------------------------
35 // forward declarations
36 // ----------------------------------------------------------------------------
37
38 class WXDLLIMPEXP_FWD_BASE wxList;
39 class WXDLLIMPEXP_FWD_BASE wxEvent;
40 #if wxUSE_GUI
41 class WXDLLIMPEXP_FWD_CORE wxDC;
42 class WXDLLIMPEXP_FWD_CORE wxMenu;
43 class WXDLLIMPEXP_FWD_CORE wxWindow;
44 class WXDLLIMPEXP_FWD_CORE wxWindowBase;
45 #endif // wxUSE_GUI
46
47 // We operate with pointer to members of wxEvtHandler (such functions are used
48 // as event handlers in the event tables or as arguments to Connect()) but by
49 // default MSVC uses a restricted (but more efficient) representation of
50 // pointers to members which can't deal with multiple base classes. To avoid
51 // mysterious (as the compiler is not good enough to detect this and give a
52 // sensible error message) errors in the user code as soon as it defines
53 // classes inheriting from both wxEvtHandler (possibly indirectly, e.g. via
54 // wxWindow) and something else (including our own wxTrackable but not limited
55 // to it), we use the special MSVC keyword telling the compiler to use a more
56 // general pointer to member representation for the classes inheriting from
57 // wxEvtHandler.
58 #ifdef __VISUALC__
59 #define wxMSVC_FWD_MULTIPLE_BASES __multiple_inheritance
60 #else
61 #define wxMSVC_FWD_MULTIPLE_BASES
62 #endif
63
64 class WXDLLIMPEXP_FWD_BASE wxMSVC_FWD_MULTIPLE_BASES wxEvtHandler;
65 class wxEventConnectionRef;
66
67 // ----------------------------------------------------------------------------
68 // Event types
69 // ----------------------------------------------------------------------------
70
71 typedef int wxEventType;
72
73 #define wxEVT_ANY ((wxEventType)-1)
74
75 // this is used to make the event table entry type safe, so that for an event
76 // handler only a function with proper parameter list can be given. See also
77 // the wxEVENT_HANDLER_CAST-macro.
78 #define wxStaticCastEvent(type, val) static_cast<type>(val)
79
80 #define DECLARE_EVENT_TABLE_ENTRY(type, winid, idLast, fn, obj) \
81 wxEventTableEntry(type, winid, idLast, wxNewEventTableFunctor(type, fn), obj)
82
83 #define DECLARE_EVENT_TABLE_TERMINATOR() \
84 wxEventTableEntry(wxEVT_NULL, 0, 0, 0, 0)
85
86 // obsolete event declaration/definition macros, we don't need them any longer
87 // but we keep them for compatibility as it doesn't cost us anything anyhow
88 #define BEGIN_DECLARE_EVENT_TYPES()
89 #define END_DECLARE_EVENT_TYPES()
90 #define DECLARE_EXPORTED_EVENT_TYPE(expdecl, name, value) \
91 extern expdecl const wxEventType name;
92 #define DECLARE_EVENT_TYPE(name, value) \
93 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_CORE, name, value)
94 #define DECLARE_LOCAL_EVENT_TYPE(name, value) \
95 DECLARE_EXPORTED_EVENT_TYPE(wxEMPTY_PARAMETER_VALUE, name, value)
96 #define DEFINE_EVENT_TYPE(name) const wxEventType name = wxNewEventType();
97 #define DEFINE_LOCAL_EVENT_TYPE(name) DEFINE_EVENT_TYPE(name)
98
99 // generate a new unique event type
100 extern WXDLLIMPEXP_BASE wxEventType wxNewEventType();
101
102 // New macros to create templatized event types:
103
104 #if wxEVENTS_COMPATIBILITY_2_8
105
106 // Define/Declare a wxEventType-based event type:
107
108 #define wxDEFINE_EVENT( name, type ) \
109 const wxEventType name( wxNewEventType() )
110
111 #define wxDECLARE_EXPORTED_EVENT( expdecl, name, type ) \
112 extern const expdecl wxEventType name
113
114 // Define/Declare a wxEventType-based event type and initialize it with a
115 // predefined event type. (Only used for wxEVT_SPIN_XXX for backward
116 // compatibility)
117
118 #define wxDEFINE_EVENT_ALIAS( name, type, value ) \
119 const wxEventType name = value
120
121 #define wxDECLARE_EXPORTED_EVENT_ALIAS( expdecl, name, type ) \
122 extern const expdecl wxEventType name
123
124 // Declare a local (not exported) wxEventType-based event type:
125
126 #define wxDECLARE_EVENT( name, type ) \
127 wxDECLARE_EXPORTED_EVENT( wxEMPTY_PARAMETER_VALUE, name, type )
128
129 #else
130 // Define/Declare a templatized event type with the corresponding event as
131 // a nested typedef:
132
133 #define wxDEFINE_EVENT( name, type ) \
134 const wxEventTypeTag< type > name( wxNewEventType() )
135
136 #define wxDECLARE_EXPORTED_EVENT( expdecl, name, type ) \
137 extern const expdecl wxEventTypeTag< type > name
138
139 // Define/Declare a templatized event type and initialize it with a
140 // predefined event type. (Only used for wxEVT_SPIN_XXX for backward
141 // compatibility)
142
143 #define wxDEFINE_EVENT_ALIAS( name, type, value ) \
144 const wxEventTypeTag< type > name( value )
145
146 #define wxDECLARE_EXPORTED_EVENT_ALIAS( expdecl, name, type ) \
147 extern const expdecl wxEventTypeTag< type > name
148
149 // Declare a local (not exported) templatized event type:
150
151 #define wxDECLARE_EVENT( name, type ) \
152 wxDECLARE_EXPORTED_EVENT( wxEMPTY_PARAMETER_VALUE, name, type )
153
154 #endif
155
156 // Try to cast the given event handler to the correct handler type:
157
158 #define wxEVENT_HANDLER_CAST( functype, func ) \
159 ( wxObjectEventFunction )( wxEventFunction )wxStaticCastEvent( functype, &func )
160
161 // Template which associates the correct event object with the event type
162
163 #if !wxEVENTS_COMPATIBILITY_2_8
164
165 // The tag is a type associated to the event type (which is an integer itself,
166 // in spite of its name) value. It exists in order to be used as a template
167 // parameter and provide a mapping between the event type values and their
168 // corresponding wxEvent-derived classes.
169 template <typename T>
170 class wxEventTypeTag
171 {
172 public:
173 // The class of wxEvent-derived class carried by the events of this type.
174 typedef T EventClass;
175
176 wxEventTypeTag(wxEventType type) { m_type = type; }
177
178 // Return a wxEventType reference for the initialization of the static
179 // event tables. See wxEventTableEntry::m_eventType for a more thorough
180 // explanation.
181 operator const wxEventType&() const { return m_type; }
182
183 private:
184 wxEventType m_type;
185 };
186
187 #endif // !wxEVENTS_COMPATIBILITY_2_8
188
189 // These are needed for the functor definitions
190 typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&);
191
192 // We had some trouble (specifically with eVC for ARM WinCE build) with using
193 // wxEventFunction in the past so we had introduced wxObjectEventFunction which
194 // used to be a typedef for a member of wxObject and not wxEvtHandler to work
195 // around this but as eVC is not really supported any longer we now only keep
196 // this for backwards compatibility and, despite its name, this is a typedef
197 // for wxEvtHandler member now -- but if we have the same problem with another
198 // compiler we can restore its old definition for it.
199 typedef wxEventFunction wxObjectEventFunction;
200
201
202 // The event functor which is stored in the static and dynamic event tables:
203 class WXDLLIMPEXP_BASE wxEventFunctor
204 {
205 public:
206 virtual ~wxEventFunctor();
207
208 // Invoke the actual event handler:
209 virtual void operator()(wxEvtHandler *, wxEvent&) = 0;
210
211 // this function tests whether this functor is matched, for the purpose of
212 // finding it in an event table in Disconnect(), by the given func
213 virtual bool Matches(const wxEventFunctor& func) const = 0;
214
215 // these functions are used for functors comparison in Matches()
216 virtual void *GetHandler() const { return GetEvtHandler(); }
217 virtual wxEventFunction GetMethod() const { return NULL; }
218
219 // this one is also used elsewhere in the code and should be overridden to
220 // return non-NULL if we are indeed associated with an wxEvtHandler
221 virtual wxEvtHandler *GetEvtHandler() const { return NULL; }
222 };
223
224 // A plain method functor: notice that it is used even with the new events as
225 // it is reused as a specialization of wxEventFunctorMethod for legacy untyped
226 // event types
227 class WXDLLIMPEXP_BASE wxObjectEventFunctor : public wxEventFunctor
228 {
229 public:
230 wxObjectEventFunctor(wxObjectEventFunction method, wxEvtHandler *handler)
231 {
232 m_handler = handler;
233 m_method = method;
234 }
235
236 virtual void operator()(wxEvtHandler *handler, wxEvent& event);
237
238 virtual bool Matches(const wxEventFunctor& func) const
239 {
240 void * const handler = func.GetHandler();
241 if ( handler && GetHandler() != handler )
242 return false;
243
244 const wxEventFunction method = GetMethod();
245
246 // FIXME-VC6: amazing but true: replacing "method == NULL" here with
247 // "!method" makes VC6 crash with an ICE in DLL build (only!)
248 return method == NULL || GetMethod() == method;
249 }
250
251 virtual wxEvtHandler *GetEvtHandler() const { return m_handler; }
252 virtual wxEventFunction GetMethod() const { return m_method; }
253
254 private:
255 wxEvtHandler *m_handler;
256 wxEventFunction m_method;
257 };
258
259 #if wxEVENTS_COMPATIBILITY_2_8
260
261 // Create a functor for the legacy events: handler can be NULL and its default
262 // value is used by the event table macros
263
264 inline wxObjectEventFunctor *
265 wxNewEventFunctor(const wxEventType& WXUNUSED(evtType),
266 wxObjectEventFunction method,
267 wxEvtHandler *handler = NULL)
268 {
269 return new wxObjectEventFunctor(method, handler);
270 }
271
272 inline wxObjectEventFunctor
273 wxMakeEventFunctor(const wxEventType& WXUNUSED(evtType),
274 wxObjectEventFunction method,
275 wxEvtHandler *handler)
276 {
277 return wxObjectEventFunctor(method, handler);
278 }
279
280 #else // !wxEVENTS_COMPATIBILITY_2_8
281
282 // functor forwarding the event to anything callable (function, static method,
283 // generalized functor...)
284 template <typename EventTag, typename Functor>
285 class wxEventFunctorFunction : public wxEventFunctor
286 {
287 public:
288 typedef typename EventTag::EventClass EventArg;
289
290 wxEventFunctorFunction(Functor handler)
291 {
292 m_handler = handler;
293 }
294
295 virtual void operator()(wxEvtHandler *WXUNUSED(handler), wxEvent& event)
296 {
297 m_handler(static_cast<EventArg&>(event));
298 }
299
300 virtual bool Matches(const wxEventFunctor& WXUNUSED(func)) const
301 {
302 // we have no way to compare arbitrary functors so just consider them
303 // to be equal: this means that disconnecting a functor will always
304 // find the last functor connected which in turn implies that it's
305 // probably a bad idea to connect more than one functor if you plan to
306 // disconnect them but this limitation doesn't seem very important in
307 // practice
308 return true;
309 }
310
311 private:
312 Functor m_handler;
313 };
314
315 namespace wxPrivate
316 {
317
318 // helper template defining nested "type" typedef as the event class
319 // corresponding to the given event type
320 template <typename T> struct EventClassOf;
321
322 // the typed events provide the information about the class of the events they
323 // carry themselves:
324 template <typename T>
325 struct EventClassOf< wxEventTypeTag<T> >
326 {
327 typedef typename wxEventTypeTag<T>::EventClass type;
328 };
329
330 // for the old untyped events we don't have information about the exact event
331 // class carried by them
332 template <>
333 struct EventClassOf<wxEventType>
334 {
335 typedef wxEvent type;
336 };
337
338
339 // helper class defining operations different for method functors using an
340 // object of wxEvtHandler-derived class as handler and the others
341 template <typename T, typename A, bool> struct HandlerImpl;
342
343 // specialization for handlers deriving from wxEvtHandler
344 template <typename T, typename A>
345 struct HandlerImpl<T, A, true>
346 {
347 static bool IsEvtHandler()
348 { return true; }
349 static T *ConvertFromEvtHandler(wxEvtHandler *p)
350 { return static_cast<T *>(p); }
351 static wxEvtHandler *ConvertToEvtHandler(T *p)
352 { return p; }
353 static wxEventFunction ConvertToEvtFunction(void (T::*f)(A&))
354 { return static_cast<wxEventFunction>(
355 reinterpret_cast<void (T::*)(wxEvent&)>(f)); }
356 };
357
358 // specialization for handlers not deriving from wxEvtHandler
359 template <typename T, typename A>
360 struct HandlerImpl<T, A, false>
361 {
362 static bool IsEvtHandler()
363 { return false; }
364 static T *ConvertFromEvtHandler(wxEvtHandler *)
365 { return NULL; }
366 static wxEvtHandler *ConvertToEvtHandler(T *)
367 { return NULL; }
368 static wxEventFunction ConvertToEvtFunction(void (T::*)(A&))
369 { return NULL; }
370 };
371
372 } // namespace wxPrivate
373
374 // functor forwarding the event to a method of the given object
375 //
376 // notice that the object class may be different from the class in which the
377 // method is defined but it must be convertible to this class
378 //
379 // also, the type of the handler parameter doesn't need to be exactly the same
380 // as EventTag::EventClass but it must be its base class -- this is explicitly
381 // allowed to handle different events in the same handler taking wxEvent&, for
382 // example
383 template
384 <typename EventTag, typename Class, typename EventArg, typename EventHandler>
385 class wxEventFunctorMethod
386 : public wxEventFunctor,
387 private wxPrivate::HandlerImpl
388 <
389 Class,
390 EventArg,
391 wxConvertibleTo<Class, wxEvtHandler>::value != 0
392 >
393 {
394 private:
395 static void CheckHandlerArgument(EventArg *) { }
396
397 public:
398 // the event class associated with the given event tag
399 typedef typename wxPrivate::EventClassOf<EventTag>::type EventClass;
400
401
402 wxEventFunctorMethod(void (Class::*method)(EventArg&), EventHandler *handler)
403 {
404 wxASSERT_MSG( handler || this->IsEvtHandler(),
405 "handlers defined in non-wxEvtHandler-derived classes "
406 "must be connected with a valid sink object" );
407
408 // if you get an error here it means that the signature of the handler
409 // you're trying to use is not compatible with (i.e. is not the same as
410 // or a base class of) the real event class used for this event type
411 CheckHandlerArgument(static_cast<EventClass *>(NULL));
412
413 m_handler = handler;
414 m_method = method;
415 }
416
417 virtual void operator()(wxEvtHandler *handler, wxEvent& event)
418 {
419 Class * realHandler = m_handler;
420 if ( !realHandler )
421 {
422 realHandler = this->ConvertFromEvtHandler(handler);
423
424 // this is not supposed to happen but check for it nevertheless
425 wxCHECK_RET( realHandler, "invalid event handler" );
426 }
427
428 // the real (run-time) type of event is EventClass and we checked in
429 // the ctor that EventClass can be converted to EventArg, so this cast
430 // is always valid
431 (realHandler->*m_method)(static_cast<EventArg&>(event));
432 }
433
434 virtual bool Matches(const wxEventFunctor& func) const
435 {
436 void * const handler = func.GetHandler();
437 if ( handler && GetHandler() != handler )
438 return false;
439
440 const wxEventFunction method = GetMethod();
441 return !method || GetMethod() == method;
442 }
443
444 virtual void *GetHandler() const
445 {
446 return m_handler;
447 }
448
449 virtual wxEventFunction GetMethod() const
450 {
451 return this->ConvertToEvtFunction(m_method);
452 }
453
454 virtual wxEvtHandler *GetEvtHandler() const
455 {
456 return this->ConvertToEvtHandler(m_handler);
457 }
458
459 private:
460 EventHandler *m_handler;
461 void (Class::*m_method)(EventArg&);
462 };
463
464
465 // Create functors for the templatized events, either allocated on the heap for
466 // wxNewXXX() variants (this is needed in wxEvtHandler::Bind<>() to store them
467 // in dynamic event table) or just by returning them as temporary objects (this
468 // is enough for Unbind<>() and we avoid unnecessary heap allocation like this).
469
470
471 // Create functors wrapping other functors (including functions):
472 template <typename EventTag, typename Functor>
473 inline wxEventFunctorFunction<EventTag, Functor> *
474 wxNewEventFunctor(const EventTag&, Functor func)
475 {
476 return new wxEventFunctorFunction<EventTag, Functor>(func);
477 }
478
479 template <typename EventTag, typename Functor>
480 inline wxEventFunctorFunction<EventTag, Functor>
481 wxMakeEventFunctor(const EventTag&, Functor func)
482 {
483 return wxEventFunctorFunction<EventTag, Functor>(func);
484 }
485
486
487 // Create functors for methods:
488 template
489 <typename EventTag, typename Class, typename EventArg, typename EventHandler>
490 inline wxEventFunctorMethod<EventTag, Class, EventArg, EventHandler> *
491 wxNewEventFunctor(const EventTag&,
492 void (Class::*method)(EventArg&),
493 EventHandler *handler)
494 {
495 return new wxEventFunctorMethod<EventTag, Class, EventArg, EventHandler>(
496 method, handler);
497 }
498
499 template
500 <typename EventTag, typename Class, typename EventArg, typename EventHandler>
501 inline wxEventFunctorMethod<EventTag, Class, EventArg, EventHandler>
502 wxMakeEventFunctor(const EventTag&,
503 void (Class::*method)(EventArg&),
504 EventHandler *handler)
505 {
506 return wxEventFunctorMethod<EventTag, Class, EventArg, EventHandler>(
507 method, handler);
508 }
509
510 // Create an event functor for the event table via DECLARE_EVENT_TABLE_ENTRY:
511 // in this case we don't have the handler (as it's always the same as the
512 // object which generated the event) so we must use Class as its type
513 template <typename EventTag, typename Class, typename EventArg>
514 inline wxEventFunctorMethod<EventTag, Class, EventArg, Class> *
515 wxNewEventTableFunctor(const EventTag&, void (Class::*method)(EventArg&))
516 {
517 return new wxEventFunctorMethod<EventTag, Class, EventArg, Class>(
518 method, NULL);
519 }
520
521 #endif // !wxEVENTS_COMPATIBILITY_2_8
522
523
524 // many, but not all, standard event types
525
526 // some generic events
527 extern WXDLLIMPEXP_BASE const wxEventType wxEVT_NULL;
528 extern WXDLLIMPEXP_BASE const wxEventType wxEVT_FIRST;
529 extern WXDLLIMPEXP_BASE const wxEventType wxEVT_USER_FIRST;
530
531 // Need events declared to do this
532 class WXDLLIMPEXP_FWD_CORE wxCommandEvent;
533 class WXDLLIMPEXP_FWD_CORE wxThreadEvent;
534 class WXDLLIMPEXP_FWD_CORE wxMouseEvent;
535 class WXDLLIMPEXP_FWD_CORE wxFocusEvent;
536 class WXDLLIMPEXP_FWD_CORE wxChildFocusEvent;
537 class WXDLLIMPEXP_FWD_CORE wxKeyEvent;
538 class WXDLLIMPEXP_FWD_CORE wxNavigationKeyEvent;
539 class WXDLLIMPEXP_FWD_CORE wxSetCursorEvent;
540 class WXDLLIMPEXP_FWD_CORE wxScrollEvent;
541 class WXDLLIMPEXP_FWD_CORE wxSpinEvent;
542 class WXDLLIMPEXP_FWD_CORE wxScrollWinEvent;
543 class WXDLLIMPEXP_FWD_CORE wxSizeEvent;
544 class WXDLLIMPEXP_FWD_CORE wxMoveEvent;
545 class WXDLLIMPEXP_FWD_CORE wxCloseEvent;
546 class WXDLLIMPEXP_FWD_CORE wxActivateEvent;
547 class WXDLLIMPEXP_FWD_CORE wxWindowCreateEvent;
548 class WXDLLIMPEXP_FWD_CORE wxWindowDestroyEvent;
549 class WXDLLIMPEXP_FWD_CORE wxShowEvent;
550 class WXDLLIMPEXP_FWD_CORE wxIconizeEvent;
551 class WXDLLIMPEXP_FWD_CORE wxMaximizeEvent;
552 class WXDLLIMPEXP_FWD_CORE wxMouseCaptureChangedEvent;
553 class WXDLLIMPEXP_FWD_CORE wxMouseCaptureLostEvent;
554 class WXDLLIMPEXP_FWD_CORE wxPaintEvent;
555 class WXDLLIMPEXP_FWD_CORE wxEraseEvent;
556 class WXDLLIMPEXP_FWD_CORE wxNcPaintEvent;
557 class WXDLLIMPEXP_FWD_CORE wxMenuEvent;
558 class WXDLLIMPEXP_FWD_CORE wxContextMenuEvent;
559 class WXDLLIMPEXP_FWD_CORE wxSysColourChangedEvent;
560 class WXDLLIMPEXP_FWD_CORE wxDisplayChangedEvent;
561 class WXDLLIMPEXP_FWD_CORE wxQueryNewPaletteEvent;
562 class WXDLLIMPEXP_FWD_CORE wxPaletteChangedEvent;
563 class WXDLLIMPEXP_FWD_CORE wxJoystickEvent;
564 class WXDLLIMPEXP_FWD_CORE wxDropFilesEvent;
565 class WXDLLIMPEXP_FWD_CORE wxInitDialogEvent;
566 class WXDLLIMPEXP_FWD_CORE wxIdleEvent;
567 class WXDLLIMPEXP_FWD_CORE wxUpdateUIEvent;
568 class WXDLLIMPEXP_FWD_CORE wxClipboardTextEvent;
569 class WXDLLIMPEXP_FWD_CORE wxHelpEvent;
570
571
572 // Command events
573 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEvent);
574 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEvent);
575 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEvent);
576 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEvent);
577 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEvent);
578 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, wxCommandEvent);
579 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_MENU_SELECTED, wxCommandEvent);
580 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_SLIDER_UPDATED, wxCommandEvent);
581 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEvent);
582 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEvent);
583
584 // wxEVT_COMMAND_SCROLLBAR_UPDATED is deprecated, use wxEVT_SCROLL... events
585 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_SCROLLBAR_UPDATED, wxCommandEvent);
586 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_VLBOX_SELECTED, wxCommandEvent);
587 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEvent);
588 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TOOL_RCLICKED, wxCommandEvent);
589 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED, wxCommandEvent);
590 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TOOL_ENTER, wxCommandEvent);
591 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_COMBOBOX_DROPDOWN, wxCommandEvent);
592 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_COMBOBOX_CLOSEUP, wxCommandEvent);
593
594 // Thread events
595 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_THREAD, wxThreadEvent);
596
597 // Mouse event types
598 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_LEFT_DOWN, wxMouseEvent);
599 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_LEFT_UP, wxMouseEvent);
600 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MIDDLE_DOWN, wxMouseEvent);
601 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MIDDLE_UP, wxMouseEvent);
602 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_RIGHT_DOWN, wxMouseEvent);
603 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_RIGHT_UP, wxMouseEvent);
604 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOTION, wxMouseEvent);
605 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_ENTER_WINDOW, wxMouseEvent);
606 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_LEAVE_WINDOW, wxMouseEvent);
607 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_LEFT_DCLICK, wxMouseEvent);
608 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MIDDLE_DCLICK, wxMouseEvent);
609 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_RIGHT_DCLICK, wxMouseEvent);
610 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SET_FOCUS, wxFocusEvent);
611 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_KILL_FOCUS, wxFocusEvent);
612 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CHILD_FOCUS, wxChildFocusEvent);
613 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOUSEWHEEL, wxMouseEvent);
614 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX1_DOWN, wxMouseEvent);
615 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX1_UP, wxMouseEvent);
616 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX1_DCLICK, wxMouseEvent);
617 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX2_DOWN, wxMouseEvent);
618 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX2_UP, wxMouseEvent);
619 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_AUX2_DCLICK, wxMouseEvent);
620
621 // Character input event type
622 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CHAR, wxKeyEvent);
623 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CHAR_HOOK, wxKeyEvent);
624 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_NAVIGATION_KEY, wxNavigationKeyEvent);
625 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_KEY_DOWN, wxKeyEvent);
626 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_KEY_UP, wxKeyEvent);
627 #if wxUSE_HOTKEY
628 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_HOTKEY, wxKeyEvent);
629 #endif
630 // Set cursor event
631 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SET_CURSOR, wxSetCursorEvent);
632
633 // wxScrollBar and wxSlider event identifiers
634 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_TOP, wxScrollEvent);
635 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_BOTTOM, wxScrollEvent);
636 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_LINEUP, wxScrollEvent);
637 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_LINEDOWN, wxScrollEvent);
638 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_PAGEUP, wxScrollEvent);
639 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_PAGEDOWN, wxScrollEvent);
640 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_THUMBTRACK, wxScrollEvent);
641 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_THUMBRELEASE, wxScrollEvent);
642 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLL_CHANGED, wxScrollEvent);
643
644 // Due to a bug in older wx versions, wxSpinEvents were being sent with type of
645 // wxEVT_SCROLL_LINEUP, wxEVT_SCROLL_LINEDOWN and wxEVT_SCROLL_THUMBTRACK. But
646 // with the type-safe events in place, these event types are associated with
647 // wxScrollEvent. To allow handling of spin events, new event types have been
648 // defined in spinbutt.h/spinnbuttcmn.cpp. To maintain backward compatibility
649 // the spin event types are being initialized with the scroll event types.
650
651 #if wxUSE_SPINBTN
652
653 wxDECLARE_EXPORTED_EVENT_ALIAS( WXDLLIMPEXP_CORE, wxEVT_SPIN_UP, wxSpinEvent );
654 wxDECLARE_EXPORTED_EVENT_ALIAS( WXDLLIMPEXP_CORE, wxEVT_SPIN_DOWN, wxSpinEvent );
655 wxDECLARE_EXPORTED_EVENT_ALIAS( WXDLLIMPEXP_CORE, wxEVT_SPIN, wxSpinEvent );
656
657 #endif
658
659 // Scroll events from wxWindow
660 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_TOP, wxScrollWinEvent);
661 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_BOTTOM, wxScrollWinEvent);
662 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_LINEUP, wxScrollWinEvent);
663 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_LINEDOWN, wxScrollWinEvent);
664 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_PAGEUP, wxScrollWinEvent);
665 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_PAGEDOWN, wxScrollWinEvent);
666 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_THUMBTRACK, wxScrollWinEvent);
667 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SCROLLWIN_THUMBRELEASE, wxScrollWinEvent);
668
669 // System events
670 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SIZE, wxSizeEvent);
671 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOVE, wxMoveEvent);
672 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CLOSE_WINDOW, wxCloseEvent);
673 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_END_SESSION, wxCloseEvent);
674 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_QUERY_END_SESSION, wxCloseEvent);
675 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_ACTIVATE_APP, wxActivateEvent);
676 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_ACTIVATE, wxActivateEvent);
677 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CREATE, wxWindowCreateEvent);
678 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_DESTROY, wxWindowDestroyEvent);
679 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SHOW, wxShowEvent);
680 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_ICONIZE, wxIconizeEvent);
681 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MAXIMIZE, wxMaximizeEvent);
682 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOUSE_CAPTURE_CHANGED, wxMouseCaptureChangedEvent);
683 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOUSE_CAPTURE_LOST, wxMouseCaptureLostEvent);
684 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_PAINT, wxPaintEvent);
685 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_ERASE_BACKGROUND, wxEraseEvent);
686 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_NC_PAINT, wxNcPaintEvent);
687 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MENU_OPEN, wxMenuEvent);
688 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MENU_CLOSE, wxMenuEvent);
689 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MENU_HIGHLIGHT, wxMenuEvent);
690 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_CONTEXT_MENU, wxContextMenuEvent);
691 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEvent);
692 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_DISPLAY_CHANGED, wxDisplayChangedEvent);
693 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_QUERY_NEW_PALETTE, wxQueryNewPaletteEvent);
694 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_PALETTE_CHANGED, wxPaletteChangedEvent);
695 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_JOY_BUTTON_DOWN, wxJoystickEvent);
696 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_JOY_BUTTON_UP, wxJoystickEvent);
697 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_JOY_MOVE, wxJoystickEvent);
698 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_JOY_ZMOVE, wxJoystickEvent);
699 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_DROP_FILES, wxDropFilesEvent);
700 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_INIT_DIALOG, wxInitDialogEvent);
701 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_BASE, wxEVT_IDLE, wxIdleEvent);
702 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_UPDATE_UI, wxUpdateUIEvent);
703 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_SIZING, wxSizeEvent);
704 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOVING, wxMoveEvent);
705 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOVE_START, wxMoveEvent);
706 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_MOVE_END, wxMoveEvent);
707 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_HIBERNATE, wxActivateEvent);
708
709 // Clipboard events
710 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TEXT_COPY, wxClipboardTextEvent);
711 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TEXT_CUT, wxClipboardTextEvent);
712 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TEXT_PASTE, wxClipboardTextEvent);
713
714 // Generic command events
715 // Note: a click is a higher-level event than button down/up
716 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_LEFT_CLICK, wxCommandEvent);
717 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_LEFT_DCLICK, wxCommandEvent);
718 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_RIGHT_CLICK, wxCommandEvent);
719 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_RIGHT_DCLICK, wxCommandEvent);
720 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_SET_FOCUS, wxCommandEvent);
721 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_KILL_FOCUS, wxCommandEvent);
722 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_ENTER, wxCommandEvent);
723
724 // Help events
725 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_HELP, wxHelpEvent);
726 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_DETAILED_HELP, wxHelpEvent);
727
728 // these 2 events are the same
729 #define wxEVT_COMMAND_TOOL_CLICKED wxEVT_COMMAND_MENU_SELECTED
730
731 // ----------------------------------------------------------------------------
732 // Compatibility
733 // ----------------------------------------------------------------------------
734
735 // this event is also used by wxComboBox and wxSpinCtrl which don't include
736 // wx/textctrl.h in all ports [yet], so declare it here as well
737 //
738 // still, any new code using it should include wx/textctrl.h explicitly
739 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEvent);
740
741
742 // ----------------------------------------------------------------------------
743 // wxEvent(-derived) classes
744 // ----------------------------------------------------------------------------
745
746 // the predefined constants for the number of times we propagate event
747 // upwards window child-parent chain
748 enum wxEventPropagation
749 {
750 // don't propagate it at all
751 wxEVENT_PROPAGATE_NONE = 0,
752
753 // propagate it until it is processed
754 wxEVENT_PROPAGATE_MAX = INT_MAX
755 };
756
757 // The different categories for a wxEvent; see wxEvent::GetEventCategory.
758 // NOTE: they are used as OR-combinable flags by wxEventLoopBase::YieldFor
759 enum wxEventCategory
760 {
761 // this is the category for those events which are generated to update
762 // the appearance of the GUI but which (usually) do not comport data
763 // processing, i.e. which do not provide input or output data
764 // (e.g. size events, scroll events, etc).
765 // They are events NOT directly generated by the user's input devices.
766 wxEVT_CATEGORY_UI = 1,
767
768 // this category groups those events which are generated directly from the
769 // user through input devices like mouse and keyboard and usually result in
770 // data to be processed from the application.
771 // (e.g. mouse clicks, key presses, etc)
772 wxEVT_CATEGORY_USER_INPUT = 2,
773
774 // this category is for wxSocketEvent
775 wxEVT_CATEGORY_SOCKET = 4,
776
777 // this category is for wxTimerEvent
778 wxEVT_CATEGORY_TIMER = 8,
779
780 // this category is for any event used to send notifications from the
781 // secondary threads to the main one or in general for notifications among
782 // different threads (which may or may not be user-generated)
783 wxEVT_CATEGORY_THREAD = 16,
784
785
786 // implementation only
787
788 // used in the implementations of wxEventLoopBase::YieldFor
789 wxEVT_CATEGORY_UNKNOWN = 32,
790
791 // a special category used as an argument to wxEventLoopBase::YieldFor to indicate that
792 // Yield() should leave all wxEvents on the queue while emptying the native event queue
793 // (native events will be processed but the wxEvents they generate will be queued)
794 wxEVT_CATEGORY_CLIPBOARD = 64,
795
796
797 // shortcut masks
798
799 // this category groups those events which are emitted in response to
800 // events of the native toolkit and which typically are not-"delayable".
801 wxEVT_CATEGORY_NATIVE_EVENTS = wxEVT_CATEGORY_UI|wxEVT_CATEGORY_USER_INPUT,
802
803 // used in wxEventLoopBase::YieldFor to specify all event categories should be processed:
804 wxEVT_CATEGORY_ALL =
805 wxEVT_CATEGORY_UI|wxEVT_CATEGORY_USER_INPUT|wxEVT_CATEGORY_SOCKET| \
806 wxEVT_CATEGORY_TIMER|wxEVT_CATEGORY_THREAD|wxEVT_CATEGORY_UNKNOWN| \
807 wxEVT_CATEGORY_CLIPBOARD
808 };
809
810 /*
811 * wxWidgets events, covering all interesting things that might happen
812 * (button clicking, resizing, setting text in widgets, etc.).
813 *
814 * For each completely new event type, derive a new event class.
815 * An event CLASS represents a C++ class defining a range of similar event TYPES;
816 * examples are canvas events, panel item command events.
817 * An event TYPE is a unique identifier for a particular system event,
818 * such as a button press or a listbox deselection.
819 *
820 */
821
822 class WXDLLIMPEXP_BASE wxEvent : public wxObject
823 {
824 public:
825 wxEvent(int winid = 0, wxEventType commandType = wxEVT_NULL );
826
827 void SetEventType(wxEventType typ) { m_eventType = typ; }
828 wxEventType GetEventType() const { return m_eventType; }
829
830 wxObject *GetEventObject() const { return m_eventObject; }
831 void SetEventObject(wxObject *obj) { m_eventObject = obj; }
832
833 long GetTimestamp() const { return m_timeStamp; }
834 void SetTimestamp(long ts = 0) { m_timeStamp = ts; }
835
836 int GetId() const { return m_id; }
837 void SetId(int Id) { m_id = Id; }
838
839 // Can instruct event processor that we wish to ignore this event
840 // (treat as if the event table entry had not been found): this must be done
841 // to allow the event processing by the base classes (calling event.Skip()
842 // is the analog of calling the base class version of a virtual function)
843 void Skip(bool skip = true) { m_skipped = skip; }
844 bool GetSkipped() const { return m_skipped; }
845
846 // This function is used to create a copy of the event polymorphically and
847 // all derived classes must implement it because otherwise wxPostEvent()
848 // for them wouldn't work (it needs to do a copy of the event)
849 virtual wxEvent *Clone() const = 0;
850
851 // this function is used to selectively process events in wxEventLoopBase::YieldFor
852 // NOTE: by default it returns wxEVT_CATEGORY_UI just because the major
853 // part of wxWidgets events belong to that category.
854 virtual wxEventCategory GetEventCategory() const
855 { return wxEVT_CATEGORY_UI; }
856
857 // Implementation only: this test is explicitly anti OO and this function
858 // exists only for optimization purposes.
859 bool IsCommandEvent() const { return m_isCommandEvent; }
860
861 // Determine if this event should be propagating to the parent window.
862 bool ShouldPropagate() const
863 { return m_propagationLevel != wxEVENT_PROPAGATE_NONE; }
864
865 // Stop an event from propagating to its parent window, returns the old
866 // propagation level value
867 int StopPropagation()
868 {
869 int propagationLevel = m_propagationLevel;
870 m_propagationLevel = wxEVENT_PROPAGATE_NONE;
871 return propagationLevel;
872 }
873
874 // Resume the event propagation by restoring the propagation level
875 // (returned by StopPropagation())
876 void ResumePropagation(int propagationLevel)
877 {
878 m_propagationLevel = propagationLevel;
879 }
880
881
882 // This is for internal use only and is only called by
883 // wxEvtHandler::ProcessEvent() to check whether it's the first time this
884 // event is being processed
885 bool WasProcessed()
886 {
887 if ( m_wasProcessed )
888 return true;
889
890 m_wasProcessed = true;
891
892 return false;
893 }
894
895 protected:
896 wxObject* m_eventObject;
897 wxEventType m_eventType;
898 long m_timeStamp;
899 int m_id;
900
901 public:
902 // m_callbackUserData is for internal usage only
903 wxObject* m_callbackUserData;
904
905 protected:
906 // the propagation level: while it is positive, we propagate the event to
907 // the parent window (if any)
908 int m_propagationLevel;
909
910 bool m_skipped;
911 bool m_isCommandEvent;
912
913 // initially false but becomes true as soon as WasProcessed() is called for
914 // the first time, as this is done only by ProcessEvent() it explains the
915 // variable name: it becomes true after ProcessEvent() was called at least
916 // once for this event
917 bool m_wasProcessed;
918
919 protected:
920 wxEvent(const wxEvent&); // for implementing Clone()
921 wxEvent& operator=(const wxEvent&); // for derived classes operator=()
922
923 private:
924 // it needs to access our m_propagationLevel
925 friend class WXDLLIMPEXP_FWD_BASE wxPropagateOnce;
926
927 DECLARE_ABSTRACT_CLASS(wxEvent)
928 };
929
930 /*
931 * Helper class to temporarily change an event not to propagate.
932 */
933 class WXDLLIMPEXP_BASE wxPropagationDisabler
934 {
935 public:
936 wxPropagationDisabler(wxEvent& event) : m_event(event)
937 {
938 m_propagationLevelOld = m_event.StopPropagation();
939 }
940
941 ~wxPropagationDisabler()
942 {
943 m_event.ResumePropagation(m_propagationLevelOld);
944 }
945
946 private:
947 wxEvent& m_event;
948 int m_propagationLevelOld;
949
950 wxDECLARE_NO_COPY_CLASS(wxPropagationDisabler);
951 };
952
953 /*
954 * Another one to temporarily lower propagation level.
955 */
956 class WXDLLIMPEXP_BASE wxPropagateOnce
957 {
958 public:
959 wxPropagateOnce(wxEvent& event) : m_event(event)
960 {
961 wxASSERT_MSG( m_event.m_propagationLevel > 0,
962 _T("shouldn't be used unless ShouldPropagate()!") );
963
964 m_event.m_propagationLevel--;
965 }
966
967 ~wxPropagateOnce()
968 {
969 m_event.m_propagationLevel++;
970 }
971
972 private:
973 wxEvent& m_event;
974
975 wxDECLARE_NO_COPY_CLASS(wxPropagateOnce);
976 };
977
978
979 #if wxUSE_GUI
980
981
982 // Item or menu event class
983 /*
984 wxEVT_COMMAND_BUTTON_CLICKED
985 wxEVT_COMMAND_CHECKBOX_CLICKED
986 wxEVT_COMMAND_CHOICE_SELECTED
987 wxEVT_COMMAND_LISTBOX_SELECTED
988 wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
989 wxEVT_COMMAND_TEXT_UPDATED
990 wxEVT_COMMAND_TEXT_ENTER
991 wxEVT_COMMAND_MENU_SELECTED
992 wxEVT_COMMAND_SLIDER_UPDATED
993 wxEVT_COMMAND_RADIOBOX_SELECTED
994 wxEVT_COMMAND_RADIOBUTTON_SELECTED
995 wxEVT_COMMAND_SCROLLBAR_UPDATED
996 wxEVT_COMMAND_VLBOX_SELECTED
997 wxEVT_COMMAND_COMBOBOX_SELECTED
998 wxEVT_COMMAND_TOGGLEBUTTON_CLICKED
999 */
1000
1001 class WXDLLIMPEXP_CORE wxCommandEvent : public wxEvent
1002 {
1003 public:
1004 wxCommandEvent(wxEventType commandType = wxEVT_NULL, int winid = 0);
1005
1006 wxCommandEvent(const wxCommandEvent& event)
1007 : wxEvent(event),
1008 m_cmdString(event.m_cmdString),
1009 m_commandInt(event.m_commandInt),
1010 m_extraLong(event.m_extraLong),
1011 m_clientData(event.m_clientData),
1012 m_clientObject(event.m_clientObject)
1013 { }
1014
1015 // Set/Get client data from controls
1016 void SetClientData(void* clientData) { m_clientData = clientData; }
1017 void *GetClientData() const { return m_clientData; }
1018
1019 // Set/Get client object from controls
1020 void SetClientObject(wxClientData* clientObject) { m_clientObject = clientObject; }
1021 wxClientData *GetClientObject() const { return m_clientObject; }
1022
1023 // Get listbox selection if single-choice
1024 int GetSelection() const { return m_commandInt; }
1025
1026 // Set/Get listbox/choice selection string
1027 void SetString(const wxString& s) { m_cmdString = s; }
1028 wxString GetString() const;
1029
1030 // Get checkbox value
1031 bool IsChecked() const { return m_commandInt != 0; }
1032
1033 // true if the listbox event was a selection.
1034 bool IsSelection() const { return (m_extraLong != 0); }
1035
1036 void SetExtraLong(long extraLong) { m_extraLong = extraLong; }
1037 long GetExtraLong() const { return m_extraLong; }
1038
1039 void SetInt(int i) { m_commandInt = i; }
1040 int GetInt() const { return m_commandInt; }
1041
1042 virtual wxEvent *Clone() const { return new wxCommandEvent(*this); }
1043 virtual wxEventCategory GetEventCategory() const { return wxEVT_CATEGORY_USER_INPUT; }
1044
1045 protected:
1046 wxString m_cmdString; // String event argument
1047 int m_commandInt;
1048 long m_extraLong; // Additional information (e.g. select/deselect)
1049 void* m_clientData; // Arbitrary client data
1050 wxClientData* m_clientObject; // Arbitrary client object
1051
1052 private:
1053 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxCommandEvent)
1054 };
1055
1056 // this class adds a possibility to react (from the user) code to a control
1057 // notification: allow or veto the operation being reported.
1058 class WXDLLIMPEXP_CORE wxNotifyEvent : public wxCommandEvent
1059 {
1060 public:
1061 wxNotifyEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
1062 : wxCommandEvent(commandType, winid)
1063 { m_bAllow = true; }
1064
1065 wxNotifyEvent(const wxNotifyEvent& event)
1066 : wxCommandEvent(event)
1067 { m_bAllow = event.m_bAllow; }
1068
1069 // veto the operation (usually it's allowed by default)
1070 void Veto() { m_bAllow = false; }
1071
1072 // allow the operation if it was disabled by default
1073 void Allow() { m_bAllow = true; }
1074
1075 // for implementation code only: is the operation allowed?
1076 bool IsAllowed() const { return m_bAllow; }
1077
1078 virtual wxEvent *Clone() const { return new wxNotifyEvent(*this); }
1079
1080 private:
1081 bool m_bAllow;
1082
1083 private:
1084 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxNotifyEvent)
1085 };
1086
1087
1088 // Thread event
1089
1090 class WXDLLIMPEXP_CORE wxThreadEvent : public wxCommandEvent
1091 {
1092 public:
1093 wxThreadEvent(wxEventType eventType = wxEVT_COMMAND_THREAD, int id = wxID_ANY)
1094 : wxCommandEvent(eventType, id)
1095 { }
1096
1097 wxThreadEvent(const wxThreadEvent& event)
1098 : wxCommandEvent(event)
1099 {
1100 // make sure our string member (which uses COW, aka refcounting) is not
1101 // shared by other wxString instances:
1102 SetString(GetString().c_str());
1103 }
1104
1105 virtual wxEvent *Clone() const
1106 {
1107 wxThreadEvent* ev = new wxThreadEvent(*this);
1108
1109 // make sure our string member (which uses COW, aka refcounting) is not
1110 // shared by other wxString instances:
1111 ev->SetString(GetString().c_str());
1112 return ev;
1113 }
1114
1115 // this is important to avoid that calling wxEventLoopBase::YieldFor thread events
1116 // gets processed when this is unwanted:
1117 virtual wxEventCategory GetEventCategory() const
1118 { return wxEVT_CATEGORY_THREAD; }
1119
1120 private:
1121 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxThreadEvent)
1122 };
1123
1124
1125
1126 // Scroll event class, derived form wxCommandEvent. wxScrollEvents are
1127 // sent by wxSlider and wxScrollBar.
1128 /*
1129 wxEVT_SCROLL_TOP
1130 wxEVT_SCROLL_BOTTOM
1131 wxEVT_SCROLL_LINEUP
1132 wxEVT_SCROLL_LINEDOWN
1133 wxEVT_SCROLL_PAGEUP
1134 wxEVT_SCROLL_PAGEDOWN
1135 wxEVT_SCROLL_THUMBTRACK
1136 wxEVT_SCROLL_THUMBRELEASE
1137 wxEVT_SCROLL_CHANGED
1138 */
1139
1140 class WXDLLIMPEXP_CORE wxScrollEvent : public wxCommandEvent
1141 {
1142 public:
1143 wxScrollEvent(wxEventType commandType = wxEVT_NULL,
1144 int winid = 0, int pos = 0, int orient = 0);
1145
1146 int GetOrientation() const { return (int) m_extraLong; }
1147 int GetPosition() const { return m_commandInt; }
1148 void SetOrientation(int orient) { m_extraLong = (long) orient; }
1149 void SetPosition(int pos) { m_commandInt = pos; }
1150
1151 virtual wxEvent *Clone() const { return new wxScrollEvent(*this); }
1152
1153 private:
1154 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxScrollEvent)
1155 };
1156
1157 // ScrollWin event class, derived fom wxEvent. wxScrollWinEvents
1158 // are sent by wxWindow.
1159 /*
1160 wxEVT_SCROLLWIN_TOP
1161 wxEVT_SCROLLWIN_BOTTOM
1162 wxEVT_SCROLLWIN_LINEUP
1163 wxEVT_SCROLLWIN_LINEDOWN
1164 wxEVT_SCROLLWIN_PAGEUP
1165 wxEVT_SCROLLWIN_PAGEDOWN
1166 wxEVT_SCROLLWIN_THUMBTRACK
1167 wxEVT_SCROLLWIN_THUMBRELEASE
1168 */
1169
1170 class WXDLLIMPEXP_CORE wxScrollWinEvent : public wxEvent
1171 {
1172 public:
1173 wxScrollWinEvent(wxEventType commandType = wxEVT_NULL,
1174 int pos = 0, int orient = 0);
1175 wxScrollWinEvent(const wxScrollWinEvent& event) : wxEvent(event)
1176 { m_commandInt = event.m_commandInt;
1177 m_extraLong = event.m_extraLong; }
1178
1179 int GetOrientation() const { return (int) m_extraLong; }
1180 int GetPosition() const { return m_commandInt; }
1181 void SetOrientation(int orient) { m_extraLong = (long) orient; }
1182 void SetPosition(int pos) { m_commandInt = pos; }
1183
1184 virtual wxEvent *Clone() const { return new wxScrollWinEvent(*this); }
1185
1186 protected:
1187 int m_commandInt;
1188 long m_extraLong;
1189
1190 private:
1191 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxScrollWinEvent)
1192 };
1193
1194
1195
1196 // Mouse event class
1197
1198 /*
1199 wxEVT_LEFT_DOWN
1200 wxEVT_LEFT_UP
1201 wxEVT_MIDDLE_DOWN
1202 wxEVT_MIDDLE_UP
1203 wxEVT_RIGHT_DOWN
1204 wxEVT_RIGHT_UP
1205 wxEVT_MOTION
1206 wxEVT_ENTER_WINDOW
1207 wxEVT_LEAVE_WINDOW
1208 wxEVT_LEFT_DCLICK
1209 wxEVT_MIDDLE_DCLICK
1210 wxEVT_RIGHT_DCLICK
1211 wxEVT_NC_LEFT_DOWN
1212 wxEVT_NC_LEFT_UP,
1213 wxEVT_NC_MIDDLE_DOWN,
1214 wxEVT_NC_MIDDLE_UP,
1215 wxEVT_NC_RIGHT_DOWN,
1216 wxEVT_NC_RIGHT_UP,
1217 wxEVT_NC_MOTION,
1218 wxEVT_NC_ENTER_WINDOW,
1219 wxEVT_NC_LEAVE_WINDOW,
1220 wxEVT_NC_LEFT_DCLICK,
1221 wxEVT_NC_MIDDLE_DCLICK,
1222 wxEVT_NC_RIGHT_DCLICK,
1223 */
1224
1225 // the symbolic names for the mouse buttons
1226 enum
1227 {
1228 wxMOUSE_BTN_ANY = -1,
1229 wxMOUSE_BTN_NONE = 0,
1230 wxMOUSE_BTN_LEFT = 1,
1231 wxMOUSE_BTN_MIDDLE = 2,
1232 wxMOUSE_BTN_RIGHT = 3,
1233 wxMOUSE_BTN_AUX1 = 4,
1234 wxMOUSE_BTN_AUX2 = 5,
1235 wxMOUSE_BTN_MAX
1236 };
1237
1238 class WXDLLIMPEXP_CORE wxMouseEvent : public wxEvent,
1239 public wxMouseState
1240 {
1241 public:
1242 wxMouseEvent(wxEventType mouseType = wxEVT_NULL);
1243 wxMouseEvent(const wxMouseEvent& event)
1244 : wxEvent(event),
1245 wxMouseState(event)
1246 {
1247 Assign(event);
1248 }
1249
1250 // Was it a button event? (*doesn't* mean: is any button *down*?)
1251 bool IsButton() const { return Button(wxMOUSE_BTN_ANY); }
1252
1253 // Was it a down event from this (or any) button?
1254 bool ButtonDown(int but = wxMOUSE_BTN_ANY) const;
1255
1256 // Was it a dclick event from this (or any) button?
1257 bool ButtonDClick(int but = wxMOUSE_BTN_ANY) const;
1258
1259 // Was it a up event from this (or any) button?
1260 bool ButtonUp(int but = wxMOUSE_BTN_ANY) const;
1261
1262 // Was the given button?
1263 bool Button(int but) const;
1264
1265 // Was the given button in Down state?
1266 bool ButtonIsDown(int but) const;
1267
1268 // Get the button which is changing state (wxMOUSE_BTN_NONE if none)
1269 int GetButton() const;
1270
1271 // Find which event was just generated
1272 bool LeftDown() const { return (m_eventType == wxEVT_LEFT_DOWN); }
1273 bool MiddleDown() const { return (m_eventType == wxEVT_MIDDLE_DOWN); }
1274 bool RightDown() const { return (m_eventType == wxEVT_RIGHT_DOWN); }
1275 bool Aux1Down() const { return (m_eventType == wxEVT_AUX1_DOWN); }
1276 bool Aux2Down() const { return (m_eventType == wxEVT_AUX2_DOWN); }
1277
1278 bool LeftUp() const { return (m_eventType == wxEVT_LEFT_UP); }
1279 bool MiddleUp() const { return (m_eventType == wxEVT_MIDDLE_UP); }
1280 bool RightUp() const { return (m_eventType == wxEVT_RIGHT_UP); }
1281 bool Aux1Up() const { return (m_eventType == wxEVT_AUX1_UP); }
1282 bool Aux2Up() const { return (m_eventType == wxEVT_AUX2_UP); }
1283
1284 bool LeftDClick() const { return (m_eventType == wxEVT_LEFT_DCLICK); }
1285 bool MiddleDClick() const { return (m_eventType == wxEVT_MIDDLE_DCLICK); }
1286 bool RightDClick() const { return (m_eventType == wxEVT_RIGHT_DCLICK); }
1287 bool Aux1DClick() const { return (m_eventType == wxEVT_AUX1_UP); }
1288 bool Aux2DClick() const { return (m_eventType == wxEVT_AUX2_UP); }
1289
1290 // Find the current state of the mouse buttons (regardless
1291 // of current event type)
1292 bool LeftIsDown() const { return m_leftDown; }
1293 bool MiddleIsDown() const { return m_middleDown; }
1294 bool RightIsDown() const { return m_rightDown; }
1295 bool Aux1IsDown() const { return m_aux1Down; }
1296 bool Aux2IsDown() const { return m_aux2Down; }
1297
1298 // True if a button is down and the mouse is moving
1299 bool Dragging() const
1300 {
1301 return (m_eventType == wxEVT_MOTION) && ButtonIsDown(wxMOUSE_BTN_ANY);
1302 }
1303
1304 // True if the mouse is moving, and no button is down
1305 bool Moving() const
1306 {
1307 return (m_eventType == wxEVT_MOTION) && !ButtonIsDown(wxMOUSE_BTN_ANY);
1308 }
1309
1310 // True if the mouse is just entering the window
1311 bool Entering() const { return (m_eventType == wxEVT_ENTER_WINDOW); }
1312
1313 // True if the mouse is just leaving the window
1314 bool Leaving() const { return (m_eventType == wxEVT_LEAVE_WINDOW); }
1315
1316 // Returns the number of mouse clicks associated with this event.
1317 int GetClickCount() const { return m_clickCount; }
1318
1319
1320 // Find the position of the event
1321 void GetPosition(wxCoord *xpos, wxCoord *ypos) const
1322 {
1323 if (xpos)
1324 *xpos = m_x;
1325 if (ypos)
1326 *ypos = m_y;
1327 }
1328
1329 void GetPosition(long *xpos, long *ypos) const
1330 {
1331 if (xpos)
1332 *xpos = (long)m_x;
1333 if (ypos)
1334 *ypos = (long)m_y;
1335 }
1336
1337 // Find the position of the event
1338 wxPoint GetPosition() const { return wxPoint(m_x, m_y); }
1339
1340 // Find the logical position of the event given the DC
1341 wxPoint GetLogicalPosition(const wxDC& dc) const;
1342
1343 // Get X position
1344 wxCoord GetX() const { return m_x; }
1345
1346 // Get Y position
1347 wxCoord GetY() const { return m_y; }
1348
1349 // Get wheel rotation, positive or negative indicates direction of
1350 // rotation. Current devices all send an event when rotation is equal to
1351 // +/-WheelDelta, but this allows for finer resolution devices to be
1352 // created in the future. Because of this you shouldn't assume that one
1353 // event is equal to 1 line or whatever, but you should be able to either
1354 // do partial line scrolling or wait until +/-WheelDelta rotation values
1355 // have been accumulated before scrolling.
1356 int GetWheelRotation() const { return m_wheelRotation; }
1357
1358 // Get wheel delta, normally 120. This is the threshold for action to be
1359 // taken, and one such action (for example, scrolling one increment)
1360 // should occur for each delta.
1361 int GetWheelDelta() const { return m_wheelDelta; }
1362
1363 // Gets the axis the wheel operation concerns, 0 being the y axis as on
1364 // most mouse wheels, 1 is the x axis for things like MightyMouse scrolls
1365 // or horizontal trackpad scrolling
1366 int GetWheelAxis() const { return m_wheelAxis; }
1367
1368 // Returns the configured number of lines (or whatever) to be scrolled per
1369 // wheel action. Defaults to one.
1370 int GetLinesPerAction() const { return m_linesPerAction; }
1371
1372 // Is the system set to do page scrolling?
1373 bool IsPageScroll() const { return ((unsigned int)m_linesPerAction == UINT_MAX); }
1374
1375 virtual wxEvent *Clone() const { return new wxMouseEvent(*this); }
1376 virtual wxEventCategory GetEventCategory() const { return wxEVT_CATEGORY_USER_INPUT; }
1377
1378 wxMouseEvent& operator=(const wxMouseEvent& event)
1379 {
1380 if (&event != this)
1381 Assign(event);
1382 return *this;
1383 }
1384
1385 public:
1386 wxCoord m_x, m_y;
1387
1388 bool m_leftDown;
1389 bool m_middleDown;
1390 bool m_rightDown;
1391 bool m_aux1Down;
1392 bool m_aux2Down;
1393
1394 int m_clickCount;
1395
1396 int m_wheelAxis;
1397 int m_wheelRotation;
1398 int m_wheelDelta;
1399 int m_linesPerAction;
1400
1401 protected:
1402 void Assign(const wxMouseEvent& evt);
1403
1404 private:
1405 DECLARE_DYNAMIC_CLASS(wxMouseEvent)
1406 };
1407
1408 // Cursor set event
1409
1410 /*
1411 wxEVT_SET_CURSOR
1412 */
1413
1414 class WXDLLIMPEXP_CORE wxSetCursorEvent : public wxEvent
1415 {
1416 public:
1417 wxSetCursorEvent(wxCoord x = 0, wxCoord y = 0)
1418 : wxEvent(0, wxEVT_SET_CURSOR),
1419 m_x(x), m_y(y), m_cursor()
1420 { }
1421
1422 wxSetCursorEvent(const wxSetCursorEvent& event)
1423 : wxEvent(event),
1424 m_x(event.m_x),
1425 m_y(event.m_y),
1426 m_cursor(event.m_cursor)
1427 { }
1428
1429 wxCoord GetX() const { return m_x; }
1430 wxCoord GetY() const { return m_y; }
1431
1432 void SetCursor(const wxCursor& cursor) { m_cursor = cursor; }
1433 const wxCursor& GetCursor() const { return m_cursor; }
1434 bool HasCursor() const { return m_cursor.Ok(); }
1435
1436 virtual wxEvent *Clone() const { return new wxSetCursorEvent(*this); }
1437
1438 private:
1439 wxCoord m_x, m_y;
1440 wxCursor m_cursor;
1441
1442 private:
1443 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxSetCursorEvent)
1444 };
1445
1446 // Keyboard input event class
1447
1448 /*
1449 wxEVT_CHAR
1450 wxEVT_CHAR_HOOK
1451 wxEVT_KEY_DOWN
1452 wxEVT_KEY_UP
1453 wxEVT_HOTKEY
1454 */
1455
1456 class WXDLLIMPEXP_CORE wxKeyEvent : public wxEvent,
1457 public wxKeyboardState
1458 {
1459 public:
1460 wxKeyEvent(wxEventType keyType = wxEVT_NULL);
1461 wxKeyEvent(const wxKeyEvent& evt);
1462
1463 // get the key code: an ASCII7 char or an element of wxKeyCode enum
1464 int GetKeyCode() const { return (int)m_keyCode; }
1465
1466 #if wxUSE_UNICODE
1467 // get the Unicode character corresponding to this key
1468 wxChar GetUnicodeKey() const { return m_uniChar; }
1469 #endif // wxUSE_UNICODE
1470
1471 // get the raw key code (platform-dependent)
1472 wxUint32 GetRawKeyCode() const { return m_rawCode; }
1473
1474 // get the raw key flags (platform-dependent)
1475 wxUint32 GetRawKeyFlags() const { return m_rawFlags; }
1476
1477 // Find the position of the event
1478 void GetPosition(wxCoord *xpos, wxCoord *ypos) const
1479 {
1480 if (xpos) *xpos = m_x;
1481 if (ypos) *ypos = m_y;
1482 }
1483
1484 void GetPosition(long *xpos, long *ypos) const
1485 {
1486 if (xpos) *xpos = (long)m_x;
1487 if (ypos) *ypos = (long)m_y;
1488 }
1489
1490 wxPoint GetPosition() const
1491 { return wxPoint(m_x, m_y); }
1492
1493 // Get X position
1494 wxCoord GetX() const { return m_x; }
1495
1496 // Get Y position
1497 wxCoord GetY() const { return m_y; }
1498
1499 virtual wxEvent *Clone() const { return new wxKeyEvent(*this); }
1500 virtual wxEventCategory GetEventCategory() const { return wxEVT_CATEGORY_USER_INPUT; }
1501
1502 // we do need to copy wxKeyEvent sometimes (in wxTreeCtrl code, for
1503 // example)
1504 wxKeyEvent& operator=(const wxKeyEvent& evt)
1505 {
1506 if ( &evt != this )
1507 {
1508 wxEvent::operator=(evt);
1509
1510 // Borland C++ 5.82 doesn't compile an explicit call to an
1511 // implicitly defined operator=() so need to do it this way:
1512 *static_cast<wxKeyboardState *>(this) = evt;
1513
1514 m_x = evt.m_x;
1515 m_y = evt.m_y;
1516
1517 m_keyCode = evt.m_keyCode;
1518
1519 m_rawCode = evt.m_rawCode;
1520 m_rawFlags = evt.m_rawFlags;
1521 #if wxUSE_UNICODE
1522 m_uniChar = evt.m_uniChar;
1523 #endif
1524 }
1525 return *this;
1526 }
1527
1528 public:
1529 wxCoord m_x, m_y;
1530
1531 long m_keyCode;
1532
1533 #if wxUSE_UNICODE
1534 // This contains the full Unicode character
1535 // in a character events in Unicode mode
1536 wxChar m_uniChar;
1537 #endif
1538
1539 // these fields contain the platform-specific information about
1540 // key that was pressed
1541 wxUint32 m_rawCode;
1542 wxUint32 m_rawFlags;
1543
1544 private:
1545 DECLARE_DYNAMIC_CLASS(wxKeyEvent)
1546 };
1547
1548 // Size event class
1549 /*
1550 wxEVT_SIZE
1551 */
1552
1553 class WXDLLIMPEXP_CORE wxSizeEvent : public wxEvent
1554 {
1555 public:
1556 wxSizeEvent() : wxEvent(0, wxEVT_SIZE)
1557 { }
1558 wxSizeEvent(const wxSize& sz, int winid = 0)
1559 : wxEvent(winid, wxEVT_SIZE),
1560 m_size(sz)
1561 { }
1562 wxSizeEvent(const wxSizeEvent& event)
1563 : wxEvent(event),
1564 m_size(event.m_size), m_rect(event.m_rect)
1565 { }
1566 wxSizeEvent(const wxRect& rect, int id = 0)
1567 : m_size(rect.GetSize()), m_rect(rect)
1568 { m_eventType = wxEVT_SIZING; m_id = id; }
1569
1570 wxSize GetSize() const { return m_size; }
1571 wxRect GetRect() const { return m_rect; }
1572 void SetRect(const wxRect& rect) { m_rect = rect; }
1573
1574 virtual wxEvent *Clone() const { return new wxSizeEvent(*this); }
1575
1576 public:
1577 // For internal usage only. Will be converted to protected members.
1578 wxSize m_size;
1579 wxRect m_rect; // Used for wxEVT_SIZING
1580
1581 private:
1582 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxSizeEvent)
1583 };
1584
1585 // Move event class
1586
1587 /*
1588 wxEVT_MOVE
1589 */
1590
1591 class WXDLLIMPEXP_CORE wxMoveEvent : public wxEvent
1592 {
1593 public:
1594 wxMoveEvent()
1595 : wxEvent(0, wxEVT_MOVE)
1596 { }
1597 wxMoveEvent(const wxPoint& pos, int winid = 0)
1598 : wxEvent(winid, wxEVT_MOVE),
1599 m_pos(pos)
1600 { }
1601 wxMoveEvent(const wxMoveEvent& event)
1602 : wxEvent(event),
1603 m_pos(event.m_pos)
1604 { }
1605 wxMoveEvent(const wxRect& rect, int id = 0)
1606 : m_pos(rect.GetPosition()), m_rect(rect)
1607 { m_eventType = wxEVT_MOVING; m_id = id; }
1608
1609 wxPoint GetPosition() const { return m_pos; }
1610 void SetPosition(const wxPoint& pos) { m_pos = pos; }
1611 wxRect GetRect() const { return m_rect; }
1612 void SetRect(const wxRect& rect) { m_rect = rect; }
1613
1614 virtual wxEvent *Clone() const { return new wxMoveEvent(*this); }
1615
1616 protected:
1617 wxPoint m_pos;
1618 wxRect m_rect;
1619
1620 private:
1621 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxMoveEvent)
1622 };
1623
1624 // Paint event class
1625 /*
1626 wxEVT_PAINT
1627 wxEVT_NC_PAINT
1628 wxEVT_PAINT_ICON
1629 */
1630
1631 #if wxDEBUG_LEVEL && (defined(__WXMSW__) || defined(__WXPM__))
1632 #define wxHAS_PAINT_DEBUG
1633
1634 // see comments in src/msw|os2/dcclient.cpp where g_isPainting is defined
1635 extern WXDLLIMPEXP_CORE int g_isPainting;
1636 #endif // debug
1637
1638 class WXDLLIMPEXP_CORE wxPaintEvent : public wxEvent
1639 {
1640 public:
1641 wxPaintEvent(int Id = 0)
1642 : wxEvent(Id, wxEVT_PAINT)
1643 {
1644 #ifdef wxHAS_PAINT_DEBUG
1645 // set the internal flag for the duration of redrawing
1646 g_isPainting++;
1647 #endif // debug
1648 }
1649
1650 // default copy ctor and dtor are normally fine, we only need them to keep
1651 // g_isPainting updated in debug build
1652 #ifdef wxHAS_PAINT_DEBUG
1653 wxPaintEvent(const wxPaintEvent& event)
1654 : wxEvent(event)
1655 {
1656 g_isPainting++;
1657 }
1658
1659 virtual ~wxPaintEvent()
1660 {
1661 g_isPainting--;
1662 }
1663 #endif // debug
1664
1665 virtual wxEvent *Clone() const { return new wxPaintEvent(*this); }
1666
1667 private:
1668 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxPaintEvent)
1669 };
1670
1671 class WXDLLIMPEXP_CORE wxNcPaintEvent : public wxEvent
1672 {
1673 public:
1674 wxNcPaintEvent(int winid = 0)
1675 : wxEvent(winid, wxEVT_NC_PAINT)
1676 { }
1677
1678 virtual wxEvent *Clone() const { return new wxNcPaintEvent(*this); }
1679
1680 private:
1681 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxNcPaintEvent)
1682 };
1683
1684 // Erase background event class
1685 /*
1686 wxEVT_ERASE_BACKGROUND
1687 */
1688
1689 class WXDLLIMPEXP_CORE wxEraseEvent : public wxEvent
1690 {
1691 public:
1692 wxEraseEvent(int Id = 0, wxDC *dc = NULL)
1693 : wxEvent(Id, wxEVT_ERASE_BACKGROUND),
1694 m_dc(dc)
1695 { }
1696
1697 wxEraseEvent(const wxEraseEvent& event)
1698 : wxEvent(event),
1699 m_dc(event.m_dc)
1700 { }
1701
1702 wxDC *GetDC() const { return m_dc; }
1703
1704 virtual wxEvent *Clone() const { return new wxEraseEvent(*this); }
1705
1706 protected:
1707 wxDC *m_dc;
1708
1709 private:
1710 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxEraseEvent)
1711 };
1712
1713 // Focus event class
1714 /*
1715 wxEVT_SET_FOCUS
1716 wxEVT_KILL_FOCUS
1717 */
1718
1719 class WXDLLIMPEXP_CORE wxFocusEvent : public wxEvent
1720 {
1721 public:
1722 wxFocusEvent(wxEventType type = wxEVT_NULL, int winid = 0)
1723 : wxEvent(winid, type)
1724 { m_win = NULL; }
1725
1726 wxFocusEvent(const wxFocusEvent& event)
1727 : wxEvent(event)
1728 { m_win = event.m_win; }
1729
1730 // The window associated with this event is the window which had focus
1731 // before for SET event and the window which will have focus for the KILL
1732 // one. NB: it may be NULL in both cases!
1733 wxWindow *GetWindow() const { return m_win; }
1734 void SetWindow(wxWindow *win) { m_win = win; }
1735
1736 virtual wxEvent *Clone() const { return new wxFocusEvent(*this); }
1737
1738 private:
1739 wxWindow *m_win;
1740
1741 private:
1742 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxFocusEvent)
1743 };
1744
1745 // wxChildFocusEvent notifies the parent that a child has got the focus: unlike
1746 // wxFocusEvent it is propagated upwards the window chain
1747 class WXDLLIMPEXP_CORE wxChildFocusEvent : public wxCommandEvent
1748 {
1749 public:
1750 wxChildFocusEvent(wxWindow *win = NULL);
1751
1752 wxWindow *GetWindow() const { return (wxWindow *)GetEventObject(); }
1753
1754 virtual wxEvent *Clone() const { return new wxChildFocusEvent(*this); }
1755
1756 private:
1757 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxChildFocusEvent)
1758 };
1759
1760 // Activate event class
1761 /*
1762 wxEVT_ACTIVATE
1763 wxEVT_ACTIVATE_APP
1764 wxEVT_HIBERNATE
1765 */
1766
1767 class WXDLLIMPEXP_CORE wxActivateEvent : public wxEvent
1768 {
1769 public:
1770 wxActivateEvent(wxEventType type = wxEVT_NULL, bool active = true, int Id = 0)
1771 : wxEvent(Id, type)
1772 { m_active = active; }
1773 wxActivateEvent(const wxActivateEvent& event)
1774 : wxEvent(event)
1775 { m_active = event.m_active; }
1776
1777 bool GetActive() const { return m_active; }
1778
1779 virtual wxEvent *Clone() const { return new wxActivateEvent(*this); }
1780
1781 private:
1782 bool m_active;
1783
1784 private:
1785 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxActivateEvent)
1786 };
1787
1788 // InitDialog event class
1789 /*
1790 wxEVT_INIT_DIALOG
1791 */
1792
1793 class WXDLLIMPEXP_CORE wxInitDialogEvent : public wxEvent
1794 {
1795 public:
1796 wxInitDialogEvent(int Id = 0)
1797 : wxEvent(Id, wxEVT_INIT_DIALOG)
1798 { }
1799
1800 virtual wxEvent *Clone() const { return new wxInitDialogEvent(*this); }
1801
1802 private:
1803 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxInitDialogEvent)
1804 };
1805
1806 // Miscellaneous menu event class
1807 /*
1808 wxEVT_MENU_OPEN,
1809 wxEVT_MENU_CLOSE,
1810 wxEVT_MENU_HIGHLIGHT,
1811 */
1812
1813 class WXDLLIMPEXP_CORE wxMenuEvent : public wxEvent
1814 {
1815 public:
1816 wxMenuEvent(wxEventType type = wxEVT_NULL, int winid = 0, wxMenu* menu = NULL)
1817 : wxEvent(winid, type)
1818 { m_menuId = winid; m_menu = menu; }
1819 wxMenuEvent(const wxMenuEvent& event)
1820 : wxEvent(event)
1821 { m_menuId = event.m_menuId; m_menu = event.m_menu; }
1822
1823 // only for wxEVT_MENU_HIGHLIGHT
1824 int GetMenuId() const { return m_menuId; }
1825
1826 // only for wxEVT_MENU_OPEN/CLOSE
1827 bool IsPopup() const { return m_menuId == wxID_ANY; }
1828
1829 // only for wxEVT_MENU_OPEN/CLOSE
1830 wxMenu* GetMenu() const { return m_menu; }
1831
1832 virtual wxEvent *Clone() const { return new wxMenuEvent(*this); }
1833
1834 private:
1835 int m_menuId;
1836 wxMenu* m_menu;
1837
1838 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxMenuEvent)
1839 };
1840
1841 // Window close or session close event class
1842 /*
1843 wxEVT_CLOSE_WINDOW,
1844 wxEVT_END_SESSION,
1845 wxEVT_QUERY_END_SESSION
1846 */
1847
1848 class WXDLLIMPEXP_CORE wxCloseEvent : public wxEvent
1849 {
1850 public:
1851 wxCloseEvent(wxEventType type = wxEVT_NULL, int winid = 0)
1852 : wxEvent(winid, type),
1853 m_loggingOff(true),
1854 m_veto(false), // should be false by default
1855 m_canVeto(true) {}
1856
1857 wxCloseEvent(const wxCloseEvent& event)
1858 : wxEvent(event),
1859 m_loggingOff(event.m_loggingOff),
1860 m_veto(event.m_veto),
1861 m_canVeto(event.m_canVeto) {}
1862
1863 void SetLoggingOff(bool logOff) { m_loggingOff = logOff; }
1864 bool GetLoggingOff() const
1865 {
1866 // m_loggingOff flag is only used by wxEVT_[QUERY_]END_SESSION, it
1867 // doesn't make sense for wxEVT_CLOSE_WINDOW
1868 wxASSERT_MSG( m_eventType != wxEVT_CLOSE_WINDOW,
1869 _T("this flag is for end session events only") );
1870
1871 return m_loggingOff;
1872 }
1873
1874 void Veto(bool veto = true)
1875 {
1876 // GetVeto() will return false anyhow...
1877 wxCHECK_RET( m_canVeto,
1878 wxT("call to Veto() ignored (can't veto this event)") );
1879
1880 m_veto = veto;
1881 }
1882 void SetCanVeto(bool canVeto) { m_canVeto = canVeto; }
1883 bool CanVeto() const { return m_canVeto; }
1884 bool GetVeto() const { return m_canVeto && m_veto; }
1885
1886 virtual wxEvent *Clone() const { return new wxCloseEvent(*this); }
1887
1888 protected:
1889 bool m_loggingOff,
1890 m_veto,
1891 m_canVeto;
1892
1893 private:
1894 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxCloseEvent)
1895 };
1896
1897 /*
1898 wxEVT_SHOW
1899 */
1900
1901 class WXDLLIMPEXP_CORE wxShowEvent : public wxEvent
1902 {
1903 public:
1904 wxShowEvent(int winid = 0, bool show = false)
1905 : wxEvent(winid, wxEVT_SHOW)
1906 { m_show = show; }
1907 wxShowEvent(const wxShowEvent& event)
1908 : wxEvent(event)
1909 { m_show = event.m_show; }
1910
1911 void SetShow(bool show) { m_show = show; }
1912
1913 // return true if the window was shown, false if hidden
1914 bool IsShown() const { return m_show; }
1915
1916 #if WXWIN_COMPATIBILITY_2_8
1917 wxDEPRECATED( bool GetShow() const { return IsShown(); } )
1918 #endif
1919
1920 virtual wxEvent *Clone() const { return new wxShowEvent(*this); }
1921
1922 protected:
1923 bool m_show;
1924
1925 private:
1926 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxShowEvent)
1927 };
1928
1929 /*
1930 wxEVT_ICONIZE
1931 */
1932
1933 class WXDLLIMPEXP_CORE wxIconizeEvent : public wxEvent
1934 {
1935 public:
1936 wxIconizeEvent(int winid = 0, bool iconized = true)
1937 : wxEvent(winid, wxEVT_ICONIZE)
1938 { m_iconized = iconized; }
1939 wxIconizeEvent(const wxIconizeEvent& event)
1940 : wxEvent(event)
1941 { m_iconized = event.m_iconized; }
1942
1943 #if WXWIN_COMPATIBILITY_2_8
1944 wxDEPRECATED( bool Iconized() const { return IsIconized(); } )
1945 #endif
1946 // return true if the frame was iconized, false if restored
1947 bool IsIconized() const { return m_iconized; }
1948
1949 virtual wxEvent *Clone() const { return new wxIconizeEvent(*this); }
1950
1951 protected:
1952 bool m_iconized;
1953
1954 private:
1955 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxIconizeEvent)
1956 };
1957 /*
1958 wxEVT_MAXIMIZE
1959 */
1960
1961 class WXDLLIMPEXP_CORE wxMaximizeEvent : public wxEvent
1962 {
1963 public:
1964 wxMaximizeEvent(int winid = 0)
1965 : wxEvent(winid, wxEVT_MAXIMIZE)
1966 { }
1967
1968 virtual wxEvent *Clone() const { return new wxMaximizeEvent(*this); }
1969
1970 private:
1971 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxMaximizeEvent)
1972 };
1973
1974 // Joystick event class
1975 /*
1976 wxEVT_JOY_BUTTON_DOWN,
1977 wxEVT_JOY_BUTTON_UP,
1978 wxEVT_JOY_MOVE,
1979 wxEVT_JOY_ZMOVE
1980 */
1981
1982 // Which joystick? Same as Windows ids so no conversion necessary.
1983 enum
1984 {
1985 wxJOYSTICK1,
1986 wxJOYSTICK2
1987 };
1988
1989 // Which button is down?
1990 enum
1991 {
1992 wxJOY_BUTTON_ANY = -1,
1993 wxJOY_BUTTON1 = 1,
1994 wxJOY_BUTTON2 = 2,
1995 wxJOY_BUTTON3 = 4,
1996 wxJOY_BUTTON4 = 8
1997 };
1998
1999 class WXDLLIMPEXP_CORE wxJoystickEvent : public wxEvent
2000 {
2001 protected:
2002 wxPoint m_pos;
2003 int m_zPosition;
2004 int m_buttonChange; // Which button changed?
2005 int m_buttonState; // Which buttons are down?
2006 int m_joyStick; // Which joystick?
2007
2008 public:
2009 wxJoystickEvent(wxEventType type = wxEVT_NULL,
2010 int state = 0,
2011 int joystick = wxJOYSTICK1,
2012 int change = 0)
2013 : wxEvent(0, type),
2014 m_pos(),
2015 m_zPosition(0),
2016 m_buttonChange(change),
2017 m_buttonState(state),
2018 m_joyStick(joystick)
2019 {
2020 }
2021 wxJoystickEvent(const wxJoystickEvent& event)
2022 : wxEvent(event),
2023 m_pos(event.m_pos),
2024 m_zPosition(event.m_zPosition),
2025 m_buttonChange(event.m_buttonChange),
2026 m_buttonState(event.m_buttonState),
2027 m_joyStick(event.m_joyStick)
2028 { }
2029
2030 wxPoint GetPosition() const { return m_pos; }
2031 int GetZPosition() const { return m_zPosition; }
2032 int GetButtonState() const { return m_buttonState; }
2033 int GetButtonChange() const { return m_buttonChange; }
2034 int GetJoystick() const { return m_joyStick; }
2035
2036 void SetJoystick(int stick) { m_joyStick = stick; }
2037 void SetButtonState(int state) { m_buttonState = state; }
2038 void SetButtonChange(int change) { m_buttonChange = change; }
2039 void SetPosition(const wxPoint& pos) { m_pos = pos; }
2040 void SetZPosition(int zPos) { m_zPosition = zPos; }
2041
2042 // Was it a button event? (*doesn't* mean: is any button *down*?)
2043 bool IsButton() const { return ((GetEventType() == wxEVT_JOY_BUTTON_DOWN) ||
2044 (GetEventType() == wxEVT_JOY_BUTTON_UP)); }
2045
2046 // Was it a move event?
2047 bool IsMove() const { return (GetEventType() == wxEVT_JOY_MOVE); }
2048
2049 // Was it a zmove event?
2050 bool IsZMove() const { return (GetEventType() == wxEVT_JOY_ZMOVE); }
2051
2052 // Was it a down event from button 1, 2, 3, 4 or any?
2053 bool ButtonDown(int but = wxJOY_BUTTON_ANY) const
2054 { return ((GetEventType() == wxEVT_JOY_BUTTON_DOWN) &&
2055 ((but == wxJOY_BUTTON_ANY) || (but == m_buttonChange))); }
2056
2057 // Was it a up event from button 1, 2, 3 or any?
2058 bool ButtonUp(int but = wxJOY_BUTTON_ANY) const
2059 { return ((GetEventType() == wxEVT_JOY_BUTTON_UP) &&
2060 ((but == wxJOY_BUTTON_ANY) || (but == m_buttonChange))); }
2061
2062 // Was the given button 1,2,3,4 or any in Down state?
2063 bool ButtonIsDown(int but = wxJOY_BUTTON_ANY) const
2064 { return (((but == wxJOY_BUTTON_ANY) && (m_buttonState != 0)) ||
2065 ((m_buttonState & but) == but)); }
2066
2067 virtual wxEvent *Clone() const { return new wxJoystickEvent(*this); }
2068
2069 private:
2070 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxJoystickEvent)
2071 };
2072
2073 // Drop files event class
2074 /*
2075 wxEVT_DROP_FILES
2076 */
2077
2078 class WXDLLIMPEXP_CORE wxDropFilesEvent : public wxEvent
2079 {
2080 public:
2081 int m_noFiles;
2082 wxPoint m_pos;
2083 wxString* m_files;
2084
2085 wxDropFilesEvent(wxEventType type = wxEVT_NULL,
2086 int noFiles = 0,
2087 wxString *files = NULL)
2088 : wxEvent(0, type),
2089 m_noFiles(noFiles),
2090 m_pos(),
2091 m_files(files)
2092 { }
2093
2094 // we need a copy ctor to avoid deleting m_files pointer twice
2095 wxDropFilesEvent(const wxDropFilesEvent& other)
2096 : wxEvent(other),
2097 m_noFiles(other.m_noFiles),
2098 m_pos(other.m_pos),
2099 m_files(NULL)
2100 {
2101 m_files = new wxString[m_noFiles];
2102 for ( int n = 0; n < m_noFiles; n++ )
2103 {
2104 m_files[n] = other.m_files[n];
2105 }
2106 }
2107
2108 virtual ~wxDropFilesEvent()
2109 {
2110 delete [] m_files;
2111 }
2112
2113 wxPoint GetPosition() const { return m_pos; }
2114 int GetNumberOfFiles() const { return m_noFiles; }
2115 wxString *GetFiles() const { return m_files; }
2116
2117 virtual wxEvent *Clone() const { return new wxDropFilesEvent(*this); }
2118
2119 private:
2120 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDropFilesEvent)
2121 };
2122
2123 // Update UI event
2124 /*
2125 wxEVT_UPDATE_UI
2126 */
2127
2128 // Whether to always send update events to windows, or
2129 // to only send update events to those with the
2130 // wxWS_EX_PROCESS_UI_UPDATES style.
2131
2132 enum wxUpdateUIMode
2133 {
2134 // Send UI update events to all windows
2135 wxUPDATE_UI_PROCESS_ALL,
2136
2137 // Send UI update events to windows that have
2138 // the wxWS_EX_PROCESS_UI_UPDATES flag specified
2139 wxUPDATE_UI_PROCESS_SPECIFIED
2140 };
2141
2142 class WXDLLIMPEXP_CORE wxUpdateUIEvent : public wxCommandEvent
2143 {
2144 public:
2145 wxUpdateUIEvent(wxWindowID commandId = 0)
2146 : wxCommandEvent(wxEVT_UPDATE_UI, commandId)
2147 {
2148 m_checked =
2149 m_enabled =
2150 m_shown =
2151 m_setEnabled =
2152 m_setShown =
2153 m_setText =
2154 m_setChecked = false;
2155 }
2156 wxUpdateUIEvent(const wxUpdateUIEvent& event)
2157 : wxCommandEvent(event),
2158 m_checked(event.m_checked),
2159 m_enabled(event.m_enabled),
2160 m_shown(event.m_shown),
2161 m_setEnabled(event.m_setEnabled),
2162 m_setShown(event.m_setShown),
2163 m_setText(event.m_setText),
2164 m_setChecked(event.m_setChecked),
2165 m_text(event.m_text)
2166 { }
2167
2168 bool GetChecked() const { return m_checked; }
2169 bool GetEnabled() const { return m_enabled; }
2170 bool GetShown() const { return m_shown; }
2171 wxString GetText() const { return m_text; }
2172 bool GetSetText() const { return m_setText; }
2173 bool GetSetChecked() const { return m_setChecked; }
2174 bool GetSetEnabled() const { return m_setEnabled; }
2175 bool GetSetShown() const { return m_setShown; }
2176
2177 void Check(bool check) { m_checked = check; m_setChecked = true; }
2178 void Enable(bool enable) { m_enabled = enable; m_setEnabled = true; }
2179 void Show(bool show) { m_shown = show; m_setShown = true; }
2180 void SetText(const wxString& text) { m_text = text; m_setText = true; }
2181
2182 // Sets the interval between updates in milliseconds.
2183 // Set to -1 to disable updates, or to 0 to update as frequently as possible.
2184 static void SetUpdateInterval(long updateInterval) { sm_updateInterval = updateInterval; }
2185
2186 // Returns the current interval between updates in milliseconds
2187 static long GetUpdateInterval() { return sm_updateInterval; }
2188
2189 // Can we update this window?
2190 static bool CanUpdate(wxWindowBase *win);
2191
2192 // Reset the update time to provide a delay until the next
2193 // time we should update
2194 static void ResetUpdateTime();
2195
2196 // Specify how wxWidgets will send update events: to
2197 // all windows, or only to those which specify that they
2198 // will process the events.
2199 static void SetMode(wxUpdateUIMode mode) { sm_updateMode = mode; }
2200
2201 // Returns the UI update mode
2202 static wxUpdateUIMode GetMode() { return sm_updateMode; }
2203
2204 virtual wxEvent *Clone() const { return new wxUpdateUIEvent(*this); }
2205
2206 protected:
2207 bool m_checked;
2208 bool m_enabled;
2209 bool m_shown;
2210 bool m_setEnabled;
2211 bool m_setShown;
2212 bool m_setText;
2213 bool m_setChecked;
2214 wxString m_text;
2215 #if wxUSE_LONGLONG
2216 static wxLongLong sm_lastUpdate;
2217 #endif
2218 static long sm_updateInterval;
2219 static wxUpdateUIMode sm_updateMode;
2220
2221 private:
2222 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxUpdateUIEvent)
2223 };
2224
2225 /*
2226 wxEVT_SYS_COLOUR_CHANGED
2227 */
2228
2229 // TODO: shouldn't all events record the window ID?
2230 class WXDLLIMPEXP_CORE wxSysColourChangedEvent : public wxEvent
2231 {
2232 public:
2233 wxSysColourChangedEvent()
2234 : wxEvent(0, wxEVT_SYS_COLOUR_CHANGED)
2235 { }
2236
2237 virtual wxEvent *Clone() const { return new wxSysColourChangedEvent(*this); }
2238
2239 private:
2240 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxSysColourChangedEvent)
2241 };
2242
2243 /*
2244 wxEVT_MOUSE_CAPTURE_CHANGED
2245 The window losing the capture receives this message
2246 (even if it released the capture itself).
2247 */
2248
2249 class WXDLLIMPEXP_CORE wxMouseCaptureChangedEvent : public wxEvent
2250 {
2251 public:
2252 wxMouseCaptureChangedEvent(wxWindowID winid = 0, wxWindow* gainedCapture = NULL)
2253 : wxEvent(winid, wxEVT_MOUSE_CAPTURE_CHANGED),
2254 m_gainedCapture(gainedCapture)
2255 { }
2256
2257 wxMouseCaptureChangedEvent(const wxMouseCaptureChangedEvent& event)
2258 : wxEvent(event),
2259 m_gainedCapture(event.m_gainedCapture)
2260 { }
2261
2262 virtual wxEvent *Clone() const { return new wxMouseCaptureChangedEvent(*this); }
2263
2264 wxWindow* GetCapturedWindow() const { return m_gainedCapture; }
2265
2266 private:
2267 wxWindow* m_gainedCapture;
2268
2269 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxMouseCaptureChangedEvent)
2270 };
2271
2272 /*
2273 wxEVT_MOUSE_CAPTURE_LOST
2274 The window losing the capture receives this message, unless it released it
2275 it itself or unless wxWindow::CaptureMouse was called on another window
2276 (and so capture will be restored when the new capturer releases it).
2277 */
2278
2279 class WXDLLIMPEXP_CORE wxMouseCaptureLostEvent : public wxEvent
2280 {
2281 public:
2282 wxMouseCaptureLostEvent(wxWindowID winid = 0)
2283 : wxEvent(winid, wxEVT_MOUSE_CAPTURE_LOST)
2284 {}
2285
2286 wxMouseCaptureLostEvent(const wxMouseCaptureLostEvent& event)
2287 : wxEvent(event)
2288 {}
2289
2290 virtual wxEvent *Clone() const { return new wxMouseCaptureLostEvent(*this); }
2291
2292 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxMouseCaptureLostEvent)
2293 };
2294
2295 /*
2296 wxEVT_DISPLAY_CHANGED
2297 */
2298 class WXDLLIMPEXP_CORE wxDisplayChangedEvent : public wxEvent
2299 {
2300 private:
2301 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDisplayChangedEvent)
2302
2303 public:
2304 wxDisplayChangedEvent()
2305 : wxEvent(0, wxEVT_DISPLAY_CHANGED)
2306 { }
2307
2308 virtual wxEvent *Clone() const { return new wxDisplayChangedEvent(*this); }
2309 };
2310
2311 /*
2312 wxEVT_PALETTE_CHANGED
2313 */
2314
2315 class WXDLLIMPEXP_CORE wxPaletteChangedEvent : public wxEvent
2316 {
2317 public:
2318 wxPaletteChangedEvent(wxWindowID winid = 0)
2319 : wxEvent(winid, wxEVT_PALETTE_CHANGED),
2320 m_changedWindow(NULL)
2321 { }
2322
2323 wxPaletteChangedEvent(const wxPaletteChangedEvent& event)
2324 : wxEvent(event),
2325 m_changedWindow(event.m_changedWindow)
2326 { }
2327
2328 void SetChangedWindow(wxWindow* win) { m_changedWindow = win; }
2329 wxWindow* GetChangedWindow() const { return m_changedWindow; }
2330
2331 virtual wxEvent *Clone() const { return new wxPaletteChangedEvent(*this); }
2332
2333 protected:
2334 wxWindow* m_changedWindow;
2335
2336 private:
2337 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxPaletteChangedEvent)
2338 };
2339
2340 /*
2341 wxEVT_QUERY_NEW_PALETTE
2342 Indicates the window is getting keyboard focus and should re-do its palette.
2343 */
2344
2345 class WXDLLIMPEXP_CORE wxQueryNewPaletteEvent : public wxEvent
2346 {
2347 public:
2348 wxQueryNewPaletteEvent(wxWindowID winid = 0)
2349 : wxEvent(winid, wxEVT_QUERY_NEW_PALETTE),
2350 m_paletteRealized(false)
2351 { }
2352 wxQueryNewPaletteEvent(const wxQueryNewPaletteEvent& event)
2353 : wxEvent(event),
2354 m_paletteRealized(event.m_paletteRealized)
2355 { }
2356
2357 // App sets this if it changes the palette.
2358 void SetPaletteRealized(bool realized) { m_paletteRealized = realized; }
2359 bool GetPaletteRealized() const { return m_paletteRealized; }
2360
2361 virtual wxEvent *Clone() const { return new wxQueryNewPaletteEvent(*this); }
2362
2363 protected:
2364 bool m_paletteRealized;
2365
2366 private:
2367 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxQueryNewPaletteEvent)
2368 };
2369
2370 /*
2371 Event generated by dialog navigation keys
2372 wxEVT_NAVIGATION_KEY
2373 */
2374 // NB: don't derive from command event to avoid being propagated to the parent
2375 class WXDLLIMPEXP_CORE wxNavigationKeyEvent : public wxEvent
2376 {
2377 public:
2378 wxNavigationKeyEvent()
2379 : wxEvent(0, wxEVT_NAVIGATION_KEY),
2380 m_flags(IsForward | FromTab), // defaults are for TAB
2381 m_focus(NULL)
2382 {
2383 m_propagationLevel = wxEVENT_PROPAGATE_NONE;
2384 }
2385
2386 wxNavigationKeyEvent(const wxNavigationKeyEvent& event)
2387 : wxEvent(event),
2388 m_flags(event.m_flags),
2389 m_focus(event.m_focus)
2390 { }
2391
2392 // direction: forward (true) or backward (false)
2393 bool GetDirection() const
2394 { return (m_flags & IsForward) != 0; }
2395 void SetDirection(bool bForward)
2396 { if ( bForward ) m_flags |= IsForward; else m_flags &= ~IsForward; }
2397
2398 // it may be a window change event (MDI, notebook pages...) or a control
2399 // change event
2400 bool IsWindowChange() const
2401 { return (m_flags & WinChange) != 0; }
2402 void SetWindowChange(bool bIs)
2403 { if ( bIs ) m_flags |= WinChange; else m_flags &= ~WinChange; }
2404
2405 // Set to true under MSW if the event was generated using the tab key.
2406 // This is required for proper navogation over radio buttons
2407 bool IsFromTab() const
2408 { return (m_flags & FromTab) != 0; }
2409 void SetFromTab(bool bIs)
2410 { if ( bIs ) m_flags |= FromTab; else m_flags &= ~FromTab; }
2411
2412 // the child which has the focus currently (may be NULL - use
2413 // wxWindow::FindFocus then)
2414 wxWindow* GetCurrentFocus() const { return m_focus; }
2415 void SetCurrentFocus(wxWindow *win) { m_focus = win; }
2416
2417 // Set flags
2418 void SetFlags(long flags) { m_flags = flags; }
2419
2420 virtual wxEvent *Clone() const { return new wxNavigationKeyEvent(*this); }
2421
2422 enum wxNavigationKeyEventFlags
2423 {
2424 IsBackward = 0x0000,
2425 IsForward = 0x0001,
2426 WinChange = 0x0002,
2427 FromTab = 0x0004
2428 };
2429
2430 long m_flags;
2431 wxWindow *m_focus;
2432
2433 private:
2434 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxNavigationKeyEvent)
2435 };
2436
2437 // Window creation/destruction events: the first is sent as soon as window is
2438 // created (i.e. the underlying GUI object exists), but when the C++ object is
2439 // fully initialized (so virtual functions may be called). The second,
2440 // wxEVT_DESTROY, is sent right before the window is destroyed - again, it's
2441 // still safe to call virtual functions at this moment
2442 /*
2443 wxEVT_CREATE
2444 wxEVT_DESTROY
2445 */
2446
2447 class WXDLLIMPEXP_CORE wxWindowCreateEvent : public wxCommandEvent
2448 {
2449 public:
2450 wxWindowCreateEvent(wxWindow *win = NULL);
2451
2452 wxWindow *GetWindow() const { return (wxWindow *)GetEventObject(); }
2453
2454 virtual wxEvent *Clone() const { return new wxWindowCreateEvent(*this); }
2455
2456 private:
2457 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWindowCreateEvent)
2458 };
2459
2460 class WXDLLIMPEXP_CORE wxWindowDestroyEvent : public wxCommandEvent
2461 {
2462 public:
2463 wxWindowDestroyEvent(wxWindow *win = NULL);
2464
2465 wxWindow *GetWindow() const { return (wxWindow *)GetEventObject(); }
2466
2467 virtual wxEvent *Clone() const { return new wxWindowDestroyEvent(*this); }
2468
2469 private:
2470 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxWindowDestroyEvent)
2471 };
2472
2473 // A help event is sent when the user clicks on a window in context-help mode.
2474 /*
2475 wxEVT_HELP
2476 wxEVT_DETAILED_HELP
2477 */
2478
2479 class WXDLLIMPEXP_CORE wxHelpEvent : public wxCommandEvent
2480 {
2481 public:
2482 // how was this help event generated?
2483 enum Origin
2484 {
2485 Origin_Unknown, // unrecognized event source
2486 Origin_Keyboard, // event generated from F1 key press
2487 Origin_HelpButton // event from [?] button on the title bar (Windows)
2488 };
2489
2490 wxHelpEvent(wxEventType type = wxEVT_NULL,
2491 wxWindowID winid = 0,
2492 const wxPoint& pt = wxDefaultPosition,
2493 Origin origin = Origin_Unknown)
2494 : wxCommandEvent(type, winid),
2495 m_pos(pt),
2496 m_origin(GuessOrigin(origin))
2497 { }
2498 wxHelpEvent(const wxHelpEvent& event)
2499 : wxCommandEvent(event),
2500 m_pos(event.m_pos),
2501 m_target(event.m_target),
2502 m_link(event.m_link),
2503 m_origin(event.m_origin)
2504 { }
2505
2506 // Position of event (in screen coordinates)
2507 const wxPoint& GetPosition() const { return m_pos; }
2508 void SetPosition(const wxPoint& pos) { m_pos = pos; }
2509
2510 // Optional link to further help
2511 const wxString& GetLink() const { return m_link; }
2512 void SetLink(const wxString& link) { m_link = link; }
2513
2514 // Optional target to display help in. E.g. a window specification
2515 const wxString& GetTarget() const { return m_target; }
2516 void SetTarget(const wxString& target) { m_target = target; }
2517
2518 virtual wxEvent *Clone() const { return new wxHelpEvent(*this); }
2519
2520 // optional indication of the event source
2521 Origin GetOrigin() const { return m_origin; }
2522 void SetOrigin(Origin origin) { m_origin = origin; }
2523
2524 protected:
2525 wxPoint m_pos;
2526 wxString m_target;
2527 wxString m_link;
2528 Origin m_origin;
2529
2530 // we can try to guess the event origin ourselves, even if none is
2531 // specified in the ctor
2532 static Origin GuessOrigin(Origin origin);
2533
2534 private:
2535 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHelpEvent)
2536 };
2537
2538 // A Clipboard Text event is sent when a window intercepts text copy/cut/paste
2539 // message, i.e. the user has cut/copied/pasted data from/into a text control
2540 // via ctrl-C/X/V, ctrl/shift-del/insert, a popup menu command, etc.
2541 // NOTE : under windows these events are *NOT* generated automatically
2542 // for a Rich Edit text control.
2543 /*
2544 wxEVT_COMMAND_TEXT_COPY
2545 wxEVT_COMMAND_TEXT_CUT
2546 wxEVT_COMMAND_TEXT_PASTE
2547 */
2548
2549 class WXDLLIMPEXP_CORE wxClipboardTextEvent : public wxCommandEvent
2550 {
2551 public:
2552 wxClipboardTextEvent(wxEventType type = wxEVT_NULL,
2553 wxWindowID winid = 0)
2554 : wxCommandEvent(type, winid)
2555 { }
2556 wxClipboardTextEvent(const wxClipboardTextEvent& event)
2557 : wxCommandEvent(event)
2558 { }
2559
2560 virtual wxEvent *Clone() const { return new wxClipboardTextEvent(*this); }
2561
2562 private:
2563 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxClipboardTextEvent)
2564 };
2565
2566 // A Context event is sent when the user right clicks on a window or
2567 // presses Shift-F10
2568 // NOTE : Under windows this is a repackaged WM_CONTETXMENU message
2569 // Under other systems it may have to be generated from a right click event
2570 /*
2571 wxEVT_CONTEXT_MENU
2572 */
2573
2574 class WXDLLIMPEXP_CORE wxContextMenuEvent : public wxCommandEvent
2575 {
2576 public:
2577 wxContextMenuEvent(wxEventType type = wxEVT_NULL,
2578 wxWindowID winid = 0,
2579 const wxPoint& pt = wxDefaultPosition)
2580 : wxCommandEvent(type, winid),
2581 m_pos(pt)
2582 { }
2583 wxContextMenuEvent(const wxContextMenuEvent& event)
2584 : wxCommandEvent(event),
2585 m_pos(event.m_pos)
2586 { }
2587
2588 // Position of event (in screen coordinates)
2589 const wxPoint& GetPosition() const { return m_pos; }
2590 void SetPosition(const wxPoint& pos) { m_pos = pos; }
2591
2592 virtual wxEvent *Clone() const { return new wxContextMenuEvent(*this); }
2593
2594 protected:
2595 wxPoint m_pos;
2596
2597 private:
2598 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxContextMenuEvent)
2599 };
2600
2601 #endif // wxUSE_GUI
2602
2603 // Idle event
2604 /*
2605 wxEVT_IDLE
2606 */
2607
2608 // Whether to always send idle events to windows, or
2609 // to only send update events to those with the
2610 // wxWS_EX_PROCESS_IDLE style.
2611
2612 enum wxIdleMode
2613 {
2614 // Send idle events to all windows
2615 wxIDLE_PROCESS_ALL,
2616
2617 // Send idle events to windows that have
2618 // the wxWS_EX_PROCESS_IDLE flag specified
2619 wxIDLE_PROCESS_SPECIFIED
2620 };
2621
2622 class WXDLLIMPEXP_BASE wxIdleEvent : public wxEvent
2623 {
2624 public:
2625 wxIdleEvent()
2626 : wxEvent(0, wxEVT_IDLE),
2627 m_requestMore(false)
2628 { }
2629 wxIdleEvent(const wxIdleEvent& event)
2630 : wxEvent(event),
2631 m_requestMore(event.m_requestMore)
2632 { }
2633
2634 void RequestMore(bool needMore = true) { m_requestMore = needMore; }
2635 bool MoreRequested() const { return m_requestMore; }
2636
2637 virtual wxEvent *Clone() const { return new wxIdleEvent(*this); }
2638
2639 // Specify how wxWidgets will send idle events: to
2640 // all windows, or only to those which specify that they
2641 // will process the events.
2642 static void SetMode(wxIdleMode mode) { sm_idleMode = mode; }
2643
2644 // Returns the idle event mode
2645 static wxIdleMode GetMode() { return sm_idleMode; }
2646
2647 protected:
2648 bool m_requestMore;
2649 static wxIdleMode sm_idleMode;
2650
2651 private:
2652 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxIdleEvent)
2653 };
2654
2655 /* TODO
2656 wxEVT_MOUSE_CAPTURE_CHANGED,
2657 wxEVT_SETTING_CHANGED, // WM_WININICHANGE (NT) / WM_SETTINGCHANGE (Win95)
2658 // wxEVT_FONT_CHANGED, // WM_FONTCHANGE: roll into wxEVT_SETTING_CHANGED, but remember to propagate
2659 // wxEVT_FONT_CHANGED to all other windows (maybe).
2660 wxEVT_DRAW_ITEM, // Leave these three as virtual functions in wxControl?? Platform-specific.
2661 wxEVT_MEASURE_ITEM,
2662 wxEVT_COMPARE_ITEM
2663 */
2664
2665
2666
2667 // ============================================================================
2668 // event handler and related classes
2669 // ============================================================================
2670
2671
2672 // struct containing the members common to static and dynamic event tables
2673 // entries
2674 struct WXDLLIMPEXP_BASE wxEventTableEntryBase
2675 {
2676 wxEventTableEntryBase(int winid, int idLast,
2677 wxEventFunctor* fn, wxObject *data)
2678 : m_id(winid),
2679 m_lastId(idLast),
2680 m_fn(fn),
2681 m_callbackUserData(data)
2682 { }
2683
2684 wxEventTableEntryBase( const wxEventTableEntryBase &entry )
2685 : m_id( entry.m_id ),
2686 m_lastId( entry.m_lastId ),
2687 m_fn( entry.m_fn ),
2688 m_callbackUserData( entry.m_callbackUserData )
2689 {
2690 // This is a 'hack' to ensure that only one instance tries to delete
2691 // the functor pointer. It is safe as long as the only place where the
2692 // copy constructor is being called is when the static event tables are
2693 // being initialized (a temporary instance is created and then this
2694 // constructor is called).
2695
2696 const_cast<wxEventTableEntryBase&>( entry ).m_fn = NULL;
2697 }
2698
2699 ~wxEventTableEntryBase()
2700 {
2701 delete m_fn;
2702 }
2703
2704 // the range of ids for this entry: if m_lastId == wxID_ANY, the range
2705 // consists only of m_id, otherwise it is m_id..m_lastId inclusive
2706 int m_id,
2707 m_lastId;
2708
2709 // function/method/functor to call
2710 wxEventFunctor* m_fn;
2711
2712 // arbitrary user data associated with the callback
2713 wxObject* m_callbackUserData;
2714
2715 private:
2716 wxDECLARE_NO_ASSIGN_CLASS(wxEventTableEntryBase);
2717 };
2718
2719 // an entry from a static event table
2720 struct WXDLLIMPEXP_BASE wxEventTableEntry : public wxEventTableEntryBase
2721 {
2722 wxEventTableEntry(const int& evType, int winid, int idLast,
2723 wxEventFunctor* fn, wxObject *data)
2724 : wxEventTableEntryBase(winid, idLast, fn, data),
2725 m_eventType(evType)
2726 { }
2727
2728 // the reference to event type: this allows us to not care about the
2729 // (undefined) order in which the event table entries and the event types
2730 // are initialized: initially the value of this reference might be
2731 // invalid, but by the time it is used for the first time, all global
2732 // objects will have been initialized (including the event type constants)
2733 // and so it will have the correct value when it is needed
2734 const int& m_eventType;
2735
2736 private:
2737 wxDECLARE_NO_ASSIGN_CLASS(wxEventTableEntry);
2738 };
2739
2740 // an entry used in dynamic event table managed by wxEvtHandler::Connect()
2741 struct WXDLLIMPEXP_BASE wxDynamicEventTableEntry : public wxEventTableEntryBase
2742 {
2743 wxDynamicEventTableEntry(int evType, int winid, int idLast,
2744 wxEventFunctor* fn, wxObject *data)
2745 : wxEventTableEntryBase(winid, idLast, fn, data),
2746 m_eventType(evType)
2747 { }
2748
2749 // not a reference here as we can't keep a reference to a temporary int
2750 // created to wrap the constant value typically passed to Connect() - nor
2751 // do we need it
2752 int m_eventType;
2753
2754 private:
2755 wxDECLARE_NO_ASSIGN_CLASS(wxDynamicEventTableEntry);
2756 };
2757
2758 // ----------------------------------------------------------------------------
2759 // wxEventTable: an array of event entries terminated with {0, 0, 0, 0, 0}
2760 // ----------------------------------------------------------------------------
2761
2762 struct WXDLLIMPEXP_BASE wxEventTable
2763 {
2764 const wxEventTable *baseTable; // base event table (next in chain)
2765 const wxEventTableEntry *entries; // bottom of entry array
2766 };
2767
2768 // ----------------------------------------------------------------------------
2769 // wxEventHashTable: a helper of wxEvtHandler to speed up wxEventTable lookups.
2770 // ----------------------------------------------------------------------------
2771
2772 WX_DEFINE_ARRAY_PTR(const wxEventTableEntry*, wxEventTableEntryPointerArray);
2773
2774 class WXDLLIMPEXP_BASE wxEventHashTable
2775 {
2776 private:
2777 // Internal data structs
2778 struct EventTypeTable
2779 {
2780 wxEventType eventType;
2781 wxEventTableEntryPointerArray eventEntryTable;
2782 };
2783 typedef EventTypeTable* EventTypeTablePointer;
2784
2785 public:
2786 // Constructor, needs the event table it needs to hash later on.
2787 // Note: hashing of the event table is not done in the constructor as it
2788 // can be that the event table is not yet full initialize, the hash
2789 // will gets initialized when handling the first event look-up request.
2790 wxEventHashTable(const wxEventTable &table);
2791 // Destructor.
2792 ~wxEventHashTable();
2793
2794 // Handle the given event, in other words search the event table hash
2795 // and call self->ProcessEvent() if a match was found.
2796 bool HandleEvent(wxEvent& event, wxEvtHandler *self);
2797
2798 // Clear table
2799 void Clear();
2800
2801 #if wxUSE_MEMORY_TRACING
2802 // Clear all tables: only used to work around problems in memory tracing
2803 // code
2804 static void ClearAll();
2805 #endif // wxUSE_MEMORY_TRACING
2806
2807 protected:
2808 // Init the hash table with the entries of the static event table.
2809 void InitHashTable();
2810 // Helper funtion of InitHashTable() to insert 1 entry into the hash table.
2811 void AddEntry(const wxEventTableEntry &entry);
2812 // Allocate and init with null pointers the base hash table.
2813 void AllocEventTypeTable(size_t size);
2814 // Grow the hash table in size and transfer all items currently
2815 // in the table to the correct location in the new table.
2816 void GrowEventTypeTable();
2817
2818 protected:
2819 const wxEventTable &m_table;
2820 bool m_rebuildHash;
2821
2822 size_t m_size;
2823 EventTypeTablePointer *m_eventTypeTable;
2824
2825 static wxEventHashTable* sm_first;
2826 wxEventHashTable* m_previous;
2827 wxEventHashTable* m_next;
2828
2829 wxDECLARE_NO_COPY_CLASS(wxEventHashTable);
2830 };
2831
2832 // ----------------------------------------------------------------------------
2833 // wxEvtHandler: the base class for all objects handling wxWidgets events
2834 // ----------------------------------------------------------------------------
2835
2836 class WXDLLIMPEXP_BASE wxEvtHandler : public wxObject
2837 , public wxTrackable
2838 {
2839 public:
2840 wxEvtHandler();
2841 virtual ~wxEvtHandler();
2842
2843
2844 // Event handler chain
2845 // -------------------
2846
2847 wxEvtHandler *GetNextHandler() const { return m_nextHandler; }
2848 wxEvtHandler *GetPreviousHandler() const { return m_previousHandler; }
2849 virtual void SetNextHandler(wxEvtHandler *handler) { m_nextHandler = handler; }
2850 virtual void SetPreviousHandler(wxEvtHandler *handler) { m_previousHandler = handler; }
2851
2852 void SetEvtHandlerEnabled(bool enabled) { m_enabled = enabled; }
2853 bool GetEvtHandlerEnabled() const { return m_enabled; }
2854
2855 void Unlink();
2856 bool IsUnlinked() const;
2857
2858
2859
2860 // Event queuing and processing
2861 // ----------------------------
2862
2863 // Process an event right now: this can only be called from the main
2864 // thread, use QueueEvent() for scheduling the events for
2865 // processing from other threads.
2866 virtual bool ProcessEvent(wxEvent& event);
2867
2868 // Process an event by calling ProcessEvent and handling any exceptions
2869 // thrown by event handlers. It's mostly useful when processing wx events
2870 // when called from C code (e.g. in GTK+ callback) when the exception
2871 // wouldn't correctly propagate to wxEventLoop.
2872 bool SafelyProcessEvent(wxEvent& event);
2873 // NOTE: uses ProcessEvent()
2874
2875 // Schedule the given event to be processed later. It takes ownership of
2876 // the event pointer, i.e. it will be deleted later. This is safe to call
2877 // from multiple threads although you still need to ensure that wxString
2878 // fields of the event object are deep copies and not use the same string
2879 // buffer as other wxString objects in this thread.
2880 virtual void QueueEvent(wxEvent *event);
2881
2882 // Add an event to be processed later: notice that this function is not
2883 // safe to call from threads other than main, use QueueEvent()
2884 virtual void AddPendingEvent(const wxEvent& event)
2885 {
2886 // notice that the thread-safety problem comes from the fact that
2887 // Clone() doesn't make deep copies of wxString fields of wxEvent
2888 // object and so the same wxString could be used from both threads when
2889 // the event object is destroyed in this one -- QueueEvent() avoids
2890 // this problem as the event pointer is not used any more in this
2891 // thread at all after it is called.
2892 QueueEvent(event.Clone());
2893 }
2894
2895 void ProcessPendingEvents();
2896 // NOTE: uses ProcessEvent()
2897
2898 void DeletePendingEvents();
2899
2900 #if wxUSE_THREADS
2901 bool ProcessThreadEvent(const wxEvent& event);
2902 // NOTE: uses AddPendingEvent(); call only from secondary threads
2903 #endif
2904
2905
2906 // Connecting and disconnecting
2907 // ----------------------------
2908
2909 // These functions are used for old, untyped, event handlers and don't
2910 // check that the type of the function passed to them actually matches the
2911 // type of the event. They also only allow connecting events to methods of
2912 // wxEvtHandler-derived classes.
2913 //
2914 // The template Connect() methods below are safer and allow connecting
2915 // events to arbitrary functions or functors -- but require compiler
2916 // support for templates.
2917
2918 // Dynamic association of a member function handler with the event handler,
2919 // winid and event type
2920 void Connect(int winid,
2921 int lastId,
2922 wxEventType eventType,
2923 wxObjectEventFunction func,
2924 wxObject *userData = NULL,
2925 wxEvtHandler *eventSink = NULL)
2926 {
2927 DoConnect(winid, lastId, eventType,
2928 wxNewEventFunctor(eventType, func, eventSink),
2929 userData);
2930 }
2931
2932 // Convenience function: take just one id
2933 void Connect(int winid,
2934 wxEventType eventType,
2935 wxObjectEventFunction func,
2936 wxObject *userData = NULL,
2937 wxEvtHandler *eventSink = NULL)
2938 { Connect(winid, wxID_ANY, eventType, func, userData, eventSink); }
2939
2940 // Even more convenient: without id (same as using id of wxID_ANY)
2941 void Connect(wxEventType eventType,
2942 wxObjectEventFunction func,
2943 wxObject *userData = NULL,
2944 wxEvtHandler *eventSink = NULL)
2945 { Connect(wxID_ANY, wxID_ANY, eventType, func, userData, eventSink); }
2946
2947 bool Disconnect(int winid,
2948 int lastId,
2949 wxEventType eventType,
2950 wxObjectEventFunction func = NULL,
2951 wxObject *userData = NULL,
2952 wxEvtHandler *eventSink = NULL)
2953 {
2954 return DoDisconnect(winid, lastId, eventType,
2955 wxMakeEventFunctor(eventType, func, eventSink),
2956 userData );
2957 }
2958
2959 bool Disconnect(int winid = wxID_ANY,
2960 wxEventType eventType = wxEVT_NULL,
2961 wxObjectEventFunction func = NULL,
2962 wxObject *userData = NULL,
2963 wxEvtHandler *eventSink = NULL)
2964 { return Disconnect(winid, wxID_ANY, eventType, func, userData, eventSink); }
2965
2966 bool Disconnect(wxEventType eventType,
2967 wxObjectEventFunction func,
2968 wxObject *userData = NULL,
2969 wxEvtHandler *eventSink = NULL)
2970 { return Disconnect(wxID_ANY, eventType, func, userData, eventSink); }
2971
2972 #if !wxEVENTS_COMPATIBILITY_2_8
2973 // Bind arbitrary functor (including just a function) to an event:
2974 template <typename EventTag, typename Functor>
2975 void Bind(const EventTag& eventType,
2976 Functor functor,
2977 int winid = wxID_ANY,
2978 int lastId = wxID_ANY,
2979 wxObject *userData = NULL)
2980 {
2981 DoConnect(winid, lastId, eventType,
2982 wxNewEventFunctor(eventType, functor),
2983 userData);
2984 }
2985
2986
2987 template <typename EventTag, typename Functor>
2988 bool Unbind(const EventTag& eventType,
2989 Functor functor,
2990 int winid = wxID_ANY,
2991 int lastId = wxID_ANY,
2992 wxObject *userData = NULL)
2993 {
2994 return DoDisconnect(winid, lastId, eventType,
2995 wxMakeEventFunctor(eventType, functor),
2996 userData);
2997 }
2998
2999
3000 // Bind a method of a class (called on the specified handler which must
3001 // be convertible to this class) object to an event:
3002
3003 template <typename EventTag, typename Class, typename EventArg, typename EventHandler>
3004 void Bind(const EventTag &eventType,
3005 void (Class::*method)(EventArg &),
3006 EventHandler *handler,
3007 int winid = wxID_ANY,
3008 int lastId = wxID_ANY,
3009 wxObject *userData = NULL)
3010 {
3011 DoConnect(winid, lastId, eventType,
3012 wxNewEventFunctor(eventType, method, handler),
3013 userData);
3014 }
3015
3016 template <typename EventTag, typename Class, typename EventArg, typename EventHandler>
3017 bool Unbind(const EventTag &eventType,
3018 void (Class::*method)(EventArg&),
3019 EventHandler *handler,
3020 int winid = wxID_ANY,
3021 int lastId = wxID_ANY,
3022 wxObject *userData = NULL )
3023 {
3024 return DoDisconnect(winid, lastId, eventType,
3025 wxMakeEventFunctor(eventType, method, handler),
3026 userData);
3027 }
3028 #endif // !wxEVENTS_COMPATIBILITY_2_8
3029
3030 wxList* GetDynamicEventTable() const { return m_dynamicEvents ; }
3031
3032 // User data can be associated with each wxEvtHandler
3033 void SetClientObject( wxClientData *data ) { DoSetClientObject(data); }
3034 wxClientData *GetClientObject() const { return DoGetClientObject(); }
3035
3036 void SetClientData( void *data ) { DoSetClientData(data); }
3037 void *GetClientData() const { return DoGetClientData(); }
3038
3039
3040 // implementation from now on
3041 // --------------------------
3042
3043 // check if the given event table entry matches this event by id (the check
3044 // for the event type should be done by caller) and call the handler if it
3045 // does
3046 //
3047 // return true if the event was processed, false otherwise (no match or the
3048 // handler decided to skip the event)
3049 static bool ProcessEventIfMatchesId(const wxEventTableEntryBase& tableEntry,
3050 wxEvtHandler *handler,
3051 wxEvent& event);
3052
3053 virtual bool SearchEventTable(wxEventTable& table, wxEvent& event);
3054 bool SearchDynamicEventTable( wxEvent& event );
3055
3056 // Avoid problems at exit by cleaning up static hash table gracefully
3057 void ClearEventHashTable() { GetEventHashTable().Clear(); }
3058 void OnSinkDestroyed( wxEvtHandler *sink );
3059
3060
3061 // The method tries to process the event in this event handler.
3062 //
3063 // It is meant to be called from ProcessEvent() only and is not virtual,
3064 // additional event handlers can be hooked into the normal event processing
3065 // logic using TryBefore() and TryAfter() hooks.
3066 bool ProcessEventHere(wxEvent& event);
3067
3068
3069 private:
3070 void DoConnect(int winid,
3071 int lastId,
3072 wxEventType eventType,
3073 wxEventFunctor *func,
3074 wxObject* userData = NULL);
3075
3076 bool DoDisconnect(int winid,
3077 int lastId,
3078 wxEventType eventType,
3079 const wxEventFunctor& func,
3080 wxObject *userData = NULL);
3081
3082 static const wxEventTableEntry sm_eventTableEntries[];
3083
3084 protected:
3085 // hooks for wxWindow used by ProcessEvent()
3086 // -----------------------------------------
3087
3088 // this one is called before trying our own event table to allow plugging
3089 // in the event handlers overriding the default logic, this is used by e.g.
3090 // validators.
3091 virtual bool TryBefore(wxEvent& event);
3092
3093 // this one is called after failing to find the event handle in our own
3094 // table to give a chance to the other windows to process it
3095 //
3096 // base class implementation passes the event to wxTheApp
3097 virtual bool TryAfter(wxEvent& event);
3098
3099 #ifdef WXWIN_COMPATIBILITY_2_8
3100 // deprecated method: override TryBefore() instead of this one
3101 wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
3102 virtual bool TryValidator(wxEvent& WXUNUSED(event)), return false; )
3103
3104 wxDEPRECATED_BUT_USED_INTERNALLY_INLINE(
3105 virtual bool TryParent(wxEvent& event), return DoTryApp(event); )
3106 #endif // WXWIN_COMPATIBILITY_2_8
3107
3108
3109 static const wxEventTable sm_eventTable;
3110 virtual const wxEventTable *GetEventTable() const;
3111
3112 static wxEventHashTable sm_eventHashTable;
3113 virtual wxEventHashTable& GetEventHashTable() const;
3114
3115 wxEvtHandler* m_nextHandler;
3116 wxEvtHandler* m_previousHandler;
3117 wxList* m_dynamicEvents;
3118 wxList* m_pendingEvents;
3119
3120 #if wxUSE_THREADS
3121 // critical section protecting m_pendingEvents
3122 wxCriticalSection m_pendingEventsLock;
3123 #endif // wxUSE_THREADS
3124
3125 // Is event handler enabled?
3126 bool m_enabled;
3127
3128
3129 // The user data: either an object which will be deleted by the container
3130 // when it's deleted or some raw pointer which we do nothing with - only
3131 // one type of data can be used with the given window (i.e. you cannot set
3132 // the void data and then associate the container with wxClientData or vice
3133 // versa)
3134 union
3135 {
3136 wxClientData *m_clientObject;
3137 void *m_clientData;
3138 };
3139
3140 // what kind of data do we have?
3141 wxClientDataType m_clientDataType;
3142
3143 // client data accessors
3144 virtual void DoSetClientObject( wxClientData *data );
3145 virtual wxClientData *DoGetClientObject() const;
3146
3147 virtual void DoSetClientData( void *data );
3148 virtual void *DoGetClientData() const;
3149
3150 // Search tracker objects for event connection with this sink
3151 wxEventConnectionRef *FindRefInTrackerList(wxEvtHandler *handler);
3152
3153 private:
3154 // pass the event to wxTheApp instance, called from TryAfter()
3155 bool DoTryApp(wxEvent& event);
3156
3157 DECLARE_DYNAMIC_CLASS_NO_COPY(wxEvtHandler)
3158 };
3159
3160 WX_DEFINE_ARRAY_WITH_DECL_PTR(wxEvtHandler *, wxEvtHandlerArray, class WXDLLIMPEXP_BASE);
3161
3162 // ----------------------------------------------------------------------------
3163 // wxEventConnectionRef represents all connections between two event handlers
3164 // and enables automatic disconnect when an event handler sink goes out of
3165 // scope. Each connection/disconnect increases/decreases ref count, and
3166 // when it reaches zero the node goes out of scope.
3167 // ----------------------------------------------------------------------------
3168
3169 class wxEventConnectionRef : public wxTrackerNode
3170 {
3171 public:
3172 wxEventConnectionRef() : m_src(NULL), m_sink(NULL), m_refCount(0) { }
3173 wxEventConnectionRef(wxEvtHandler *src, wxEvtHandler *sink)
3174 : m_src(src), m_sink(sink), m_refCount(1)
3175 {
3176 m_sink->AddNode(this);
3177 }
3178
3179 // The sink is being destroyed
3180 virtual void OnObjectDestroy( )
3181 {
3182 if ( m_src )
3183 m_src->OnSinkDestroyed( m_sink );
3184 delete this;
3185 }
3186
3187 virtual wxEventConnectionRef *ToEventConnection() { return this; }
3188
3189 void IncRef() { m_refCount++; }
3190 void DecRef()
3191 {
3192 if ( !--m_refCount )
3193 {
3194 // The sink holds the only external pointer to this object
3195 if ( m_sink )
3196 m_sink->RemoveNode(this);
3197 delete this;
3198 }
3199 }
3200
3201 private:
3202 wxEvtHandler *m_src,
3203 *m_sink;
3204 int m_refCount;
3205
3206 friend class wxEvtHandler;
3207
3208 wxDECLARE_NO_ASSIGN_CLASS(wxEventConnectionRef);
3209 };
3210
3211 inline void wxObjectEventFunctor::operator()(wxEvtHandler *handler, wxEvent& event)
3212 {
3213 wxEvtHandler * const realHandler = m_handler ? m_handler : handler;
3214
3215 (realHandler->*m_method)(event);
3216 }
3217
3218 // Post a message to the given event handler which will be processed during the
3219 // next event loop iteration.
3220 //
3221 // Notice that this one is not thread-safe, use wxQueueEvent()
3222 inline void wxPostEvent(wxEvtHandler *dest, const wxEvent& event)
3223 {
3224 wxCHECK_RET( dest, "need an object to post event to" );
3225
3226 dest->AddPendingEvent(event);
3227 }
3228
3229 // Wrapper around wxEvtHandler::QueueEvent(): adds an event for later
3230 // processing, unlike wxPostEvent it is safe to use from different thread even
3231 // for events with wxString members
3232 inline void wxQueueEvent(wxEvtHandler *dest, wxEvent *event)
3233 {
3234 wxCHECK_RET( dest, "need an object to queue event for" );
3235
3236 dest->QueueEvent(event);
3237 }
3238
3239 typedef void (wxEvtHandler::*wxEventFunction)(wxEvent&);
3240 typedef void (wxEvtHandler::*wxIdleEventFunction)(wxIdleEvent&);
3241
3242 #define wxEventHandler(func) \
3243 wxEVENT_HANDLER_CAST(wxEventFunction, func)
3244 #define wxIdleEventHandler(func) \
3245 wxEVENT_HANDLER_CAST(wxIdleEventFunction, func)
3246
3247 #if wxUSE_GUI
3248
3249 // ----------------------------------------------------------------------------
3250 // wxEventBlocker: helper class to temporarily disable event handling for a window
3251 // ----------------------------------------------------------------------------
3252
3253 class WXDLLIMPEXP_CORE wxEventBlocker : public wxEvtHandler
3254 {
3255 public:
3256 wxEventBlocker(wxWindow *win, wxEventType type = wxEVT_ANY);
3257 virtual ~wxEventBlocker();
3258
3259 void Block(wxEventType type)
3260 {
3261 m_eventsToBlock.push_back(type);
3262 }
3263
3264 virtual bool ProcessEvent(wxEvent& event);
3265
3266 protected:
3267 wxArrayInt m_eventsToBlock;
3268 wxWindow *m_window;
3269
3270 wxDECLARE_NO_COPY_CLASS(wxEventBlocker);
3271 };
3272
3273 typedef void (wxEvtHandler::*wxCommandEventFunction)(wxCommandEvent&);
3274 typedef void (wxEvtHandler::*wxThreadEventFunction)(wxThreadEvent&);
3275 typedef void (wxEvtHandler::*wxScrollEventFunction)(wxScrollEvent&);
3276 typedef void (wxEvtHandler::*wxScrollWinEventFunction)(wxScrollWinEvent&);
3277 typedef void (wxEvtHandler::*wxSizeEventFunction)(wxSizeEvent&);
3278 typedef void (wxEvtHandler::*wxMoveEventFunction)(wxMoveEvent&);
3279 typedef void (wxEvtHandler::*wxPaintEventFunction)(wxPaintEvent&);
3280 typedef void (wxEvtHandler::*wxNcPaintEventFunction)(wxNcPaintEvent&);
3281 typedef void (wxEvtHandler::*wxEraseEventFunction)(wxEraseEvent&);
3282 typedef void (wxEvtHandler::*wxMouseEventFunction)(wxMouseEvent&);
3283 typedef void (wxEvtHandler::*wxCharEventFunction)(wxKeyEvent&);
3284 typedef void (wxEvtHandler::*wxFocusEventFunction)(wxFocusEvent&);
3285 typedef void (wxEvtHandler::*wxChildFocusEventFunction)(wxChildFocusEvent&);
3286 typedef void (wxEvtHandler::*wxActivateEventFunction)(wxActivateEvent&);
3287 typedef void (wxEvtHandler::*wxMenuEventFunction)(wxMenuEvent&);
3288 typedef void (wxEvtHandler::*wxJoystickEventFunction)(wxJoystickEvent&);
3289 typedef void (wxEvtHandler::*wxDropFilesEventFunction)(wxDropFilesEvent&);
3290 typedef void (wxEvtHandler::*wxInitDialogEventFunction)(wxInitDialogEvent&);
3291 typedef void (wxEvtHandler::*wxSysColourChangedEventFunction)(wxSysColourChangedEvent&);
3292 typedef void (wxEvtHandler::*wxDisplayChangedEventFunction)(wxDisplayChangedEvent&);
3293 typedef void (wxEvtHandler::*wxUpdateUIEventFunction)(wxUpdateUIEvent&);
3294 typedef void (wxEvtHandler::*wxCloseEventFunction)(wxCloseEvent&);
3295 typedef void (wxEvtHandler::*wxShowEventFunction)(wxShowEvent&);
3296 typedef void (wxEvtHandler::*wxIconizeEventFunction)(wxIconizeEvent&);
3297 typedef void (wxEvtHandler::*wxMaximizeEventFunction)(wxMaximizeEvent&);
3298 typedef void (wxEvtHandler::*wxNavigationKeyEventFunction)(wxNavigationKeyEvent&);
3299 typedef void (wxEvtHandler::*wxPaletteChangedEventFunction)(wxPaletteChangedEvent&);
3300 typedef void (wxEvtHandler::*wxQueryNewPaletteEventFunction)(wxQueryNewPaletteEvent&);
3301 typedef void (wxEvtHandler::*wxWindowCreateEventFunction)(wxWindowCreateEvent&);
3302 typedef void (wxEvtHandler::*wxWindowDestroyEventFunction)(wxWindowDestroyEvent&);
3303 typedef void (wxEvtHandler::*wxSetCursorEventFunction)(wxSetCursorEvent&);
3304 typedef void (wxEvtHandler::*wxNotifyEventFunction)(wxNotifyEvent&);
3305 typedef void (wxEvtHandler::*wxHelpEventFunction)(wxHelpEvent&);
3306 typedef void (wxEvtHandler::*wxContextMenuEventFunction)(wxContextMenuEvent&);
3307 typedef void (wxEvtHandler::*wxMouseCaptureChangedEventFunction)(wxMouseCaptureChangedEvent&);
3308 typedef void (wxEvtHandler::*wxMouseCaptureLostEventFunction)(wxMouseCaptureLostEvent&);
3309 typedef void (wxEvtHandler::*wxClipboardTextEventFunction)(wxClipboardTextEvent&);
3310
3311
3312 #define wxCommandEventHandler(func) \
3313 wxEVENT_HANDLER_CAST(wxCommandEventFunction, func)
3314 #define wxThreadEventHandler(func) \
3315 wxEVENT_HANDLER_CAST(wxThreadEventFunction, func)
3316 #define wxScrollEventHandler(func) \
3317 wxEVENT_HANDLER_CAST(wxScrollEventFunction, func)
3318 #define wxScrollWinEventHandler(func) \
3319 wxEVENT_HANDLER_CAST(wxScrollWinEventFunction, func)
3320 #define wxSizeEventHandler(func) \
3321 wxEVENT_HANDLER_CAST(wxSizeEventFunction, func)
3322 #define wxMoveEventHandler(func) \
3323 wxEVENT_HANDLER_CAST(wxMoveEventFunction, func)
3324 #define wxPaintEventHandler(func) \
3325 wxEVENT_HANDLER_CAST(wxPaintEventFunction, func)
3326 #define wxNcPaintEventHandler(func) \
3327 wxEVENT_HANDLER_CAST(wxNcPaintEventFunction, func)
3328 #define wxEraseEventHandler(func) \
3329 wxEVENT_HANDLER_CAST(wxEraseEventFunction, func)
3330 #define wxMouseEventHandler(func) \
3331 wxEVENT_HANDLER_CAST(wxMouseEventFunction, func)
3332 #define wxCharEventHandler(func) \
3333 wxEVENT_HANDLER_CAST(wxCharEventFunction, func)
3334 #define wxKeyEventHandler(func) wxCharEventHandler(func)
3335 #define wxFocusEventHandler(func) \
3336 wxEVENT_HANDLER_CAST(wxFocusEventFunction, func)
3337 #define wxChildFocusEventHandler(func) \
3338 wxEVENT_HANDLER_CAST(wxChildFocusEventFunction, func)
3339 #define wxActivateEventHandler(func) \
3340 wxEVENT_HANDLER_CAST(wxActivateEventFunction, func)
3341 #define wxMenuEventHandler(func) \
3342 wxEVENT_HANDLER_CAST(wxMenuEventFunction, func)
3343 #define wxJoystickEventHandler(func) \
3344 wxEVENT_HANDLER_CAST(wxJoystickEventFunction, func)
3345 #define wxDropFilesEventHandler(func) \
3346 wxEVENT_HANDLER_CAST(wxDropFilesEventFunction, func)
3347 #define wxInitDialogEventHandler(func) \
3348 wxEVENT_HANDLER_CAST(wxInitDialogEventFunction, func)
3349 #define wxSysColourChangedEventHandler(func) \
3350 wxEVENT_HANDLER_CAST(wxSysColourChangedEventFunction, func)
3351 #define wxDisplayChangedEventHandler(func) \
3352 wxEVENT_HANDLER_CAST(wxDisplayChangedEventFunction, func)
3353 #define wxUpdateUIEventHandler(func) \
3354 wxEVENT_HANDLER_CAST(wxUpdateUIEventFunction, func)
3355 #define wxCloseEventHandler(func) \
3356 wxEVENT_HANDLER_CAST(wxCloseEventFunction, func)
3357 #define wxShowEventHandler(func) \
3358 wxEVENT_HANDLER_CAST(wxShowEventFunction, func)
3359 #define wxIconizeEventHandler(func) \
3360 wxEVENT_HANDLER_CAST(wxIconizeEventFunction, func)
3361 #define wxMaximizeEventHandler(func) \
3362 wxEVENT_HANDLER_CAST(wxMaximizeEventFunction, func)
3363 #define wxNavigationKeyEventHandler(func) \
3364 wxEVENT_HANDLER_CAST(wxNavigationKeyEventFunction, func)
3365 #define wxPaletteChangedEventHandler(func) \
3366 wxEVENT_HANDLER_CAST(wxPaletteChangedEventFunction, func)
3367 #define wxQueryNewPaletteEventHandler(func) \
3368 wxEVENT_HANDLER_CAST(wxQueryNewPaletteEventFunction, func)
3369 #define wxWindowCreateEventHandler(func) \
3370 wxEVENT_HANDLER_CAST(wxWindowCreateEventFunction, func)
3371 #define wxWindowDestroyEventHandler(func) \
3372 wxEVENT_HANDLER_CAST(wxWindowDestroyEventFunction, func)
3373 #define wxSetCursorEventHandler(func) \
3374 wxEVENT_HANDLER_CAST(wxSetCursorEventFunction, func)
3375 #define wxNotifyEventHandler(func) \
3376 wxEVENT_HANDLER_CAST(wxNotifyEventFunction, func)
3377 #define wxHelpEventHandler(func) \
3378 wxEVENT_HANDLER_CAST(wxHelpEventFunction, func)
3379 #define wxContextMenuEventHandler(func) \
3380 wxEVENT_HANDLER_CAST(wxContextMenuEventFunction, func)
3381 #define wxMouseCaptureChangedEventHandler(func) \
3382 wxEVENT_HANDLER_CAST(wxMouseCaptureChangedEventFunction, func)
3383 #define wxMouseCaptureLostEventHandler(func) \
3384 wxEVENT_HANDLER_CAST(wxMouseCaptureLostEventFunction, func)
3385 #define wxClipboardTextEventHandler(func) \
3386 wxEVENT_HANDLER_CAST(wxClipboardTextEventFunction, func)
3387
3388 #endif // wxUSE_GUI
3389
3390 // N.B. In GNU-WIN32, you *have* to take the address of a member function
3391 // (use &) or the compiler crashes...
3392
3393 #define DECLARE_EVENT_TABLE() \
3394 private: \
3395 static const wxEventTableEntry sm_eventTableEntries[]; \
3396 protected: \
3397 static const wxEventTable sm_eventTable; \
3398 virtual const wxEventTable* GetEventTable() const; \
3399 static wxEventHashTable sm_eventHashTable; \
3400 virtual wxEventHashTable& GetEventHashTable() const;
3401
3402 // N.B.: when building DLL with Borland C++ 5.5 compiler, you must initialize
3403 // sm_eventTable before using it in GetEventTable() or the compiler gives
3404 // E2233 (see http://groups.google.com/groups?selm=397dcc8a%241_2%40dnews)
3405
3406 #define BEGIN_EVENT_TABLE(theClass, baseClass) \
3407 const wxEventTable theClass::sm_eventTable = \
3408 { &baseClass::sm_eventTable, &theClass::sm_eventTableEntries[0] }; \
3409 const wxEventTable *theClass::GetEventTable() const \
3410 { return &theClass::sm_eventTable; } \
3411 wxEventHashTable theClass::sm_eventHashTable(theClass::sm_eventTable); \
3412 wxEventHashTable &theClass::GetEventHashTable() const \
3413 { return theClass::sm_eventHashTable; } \
3414 const wxEventTableEntry theClass::sm_eventTableEntries[] = { \
3415
3416 #define BEGIN_EVENT_TABLE_TEMPLATE1(theClass, baseClass, T1) \
3417 template<typename T1> \
3418 const wxEventTable theClass<T1>::sm_eventTable = \
3419 { &baseClass::sm_eventTable, &theClass<T1>::sm_eventTableEntries[0] }; \
3420 template<typename T1> \
3421 const wxEventTable *theClass<T1>::GetEventTable() const \
3422 { return &theClass<T1>::sm_eventTable; } \
3423 template<typename T1> \
3424 wxEventHashTable theClass<T1>::sm_eventHashTable(theClass<T1>::sm_eventTable); \
3425 template<typename T1> \
3426 wxEventHashTable &theClass<T1>::GetEventHashTable() const \
3427 { return theClass<T1>::sm_eventHashTable; } \
3428 template<typename T1> \
3429 const wxEventTableEntry theClass<T1>::sm_eventTableEntries[] = { \
3430
3431 #define BEGIN_EVENT_TABLE_TEMPLATE2(theClass, baseClass, T1, T2) \
3432 template<typename T1, typename T2> \
3433 const wxEventTable theClass<T1, T2>::sm_eventTable = \
3434 { &baseClass::sm_eventTable, &theClass<T1, T2>::sm_eventTableEntries[0] }; \
3435 template<typename T1, typename T2> \
3436 const wxEventTable *theClass<T1, T2>::GetEventTable() const \
3437 { return &theClass<T1, T2>::sm_eventTable; } \
3438 template<typename T1, typename T2> \
3439 wxEventHashTable theClass<T1, T2>::sm_eventHashTable(theClass<T1, T2>::sm_eventTable); \
3440 template<typename T1, typename T2> \
3441 wxEventHashTable &theClass<T1, T2>::GetEventHashTable() const \
3442 { return theClass<T1, T2>::sm_eventHashTable; } \
3443 template<typename T1, typename T2> \
3444 const wxEventTableEntry theClass<T1, T2>::sm_eventTableEntries[] = { \
3445
3446 #define BEGIN_EVENT_TABLE_TEMPLATE3(theClass, baseClass, T1, T2, T3) \
3447 template<typename T1, typename T2, typename T3> \
3448 const wxEventTable theClass<T1, T2, T3>::sm_eventTable = \
3449 { &baseClass::sm_eventTable, &theClass<T1, T2, T3>::sm_eventTableEntries[0] }; \
3450 template<typename T1, typename T2, typename T3> \
3451 const wxEventTable *theClass<T1, T2, T3>::GetEventTable() const \
3452 { return &theClass<T1, T2, T3>::sm_eventTable; } \
3453 template<typename T1, typename T2, typename T3> \
3454 wxEventHashTable theClass<T1, T2, T3>::sm_eventHashTable(theClass<T1, T2, T3>::sm_eventTable); \
3455 template<typename T1, typename T2, typename T3> \
3456 wxEventHashTable &theClass<T1, T2, T3>::GetEventHashTable() const \
3457 { return theClass<T1, T2, T3>::sm_eventHashTable; } \
3458 template<typename T1, typename T2, typename T3> \
3459 const wxEventTableEntry theClass<T1, T2, T3>::sm_eventTableEntries[] = { \
3460
3461 #define BEGIN_EVENT_TABLE_TEMPLATE4(theClass, baseClass, T1, T2, T3, T4) \
3462 template<typename T1, typename T2, typename T3, typename T4> \
3463 const wxEventTable theClass<T1, T2, T3, T4>::sm_eventTable = \
3464 { &baseClass::sm_eventTable, &theClass<T1, T2, T3, T4>::sm_eventTableEntries[0] }; \
3465 template<typename T1, typename T2, typename T3, typename T4> \
3466 const wxEventTable *theClass<T1, T2, T3, T4>::GetEventTable() const \
3467 { return &theClass<T1, T2, T3, T4>::sm_eventTable; } \
3468 template<typename T1, typename T2, typename T3, typename T4> \
3469 wxEventHashTable theClass<T1, T2, T3, T4>::sm_eventHashTable(theClass<T1, T2, T3, T4>::sm_eventTable); \
3470 template<typename T1, typename T2, typename T3, typename T4> \
3471 wxEventHashTable &theClass<T1, T2, T3, T4>::GetEventHashTable() const \
3472 { return theClass<T1, T2, T3, T4>::sm_eventHashTable; } \
3473 template<typename T1, typename T2, typename T3, typename T4> \
3474 const wxEventTableEntry theClass<T1, T2, T3, T4>::sm_eventTableEntries[] = { \
3475
3476 #define BEGIN_EVENT_TABLE_TEMPLATE5(theClass, baseClass, T1, T2, T3, T4, T5) \
3477 template<typename T1, typename T2, typename T3, typename T4, typename T5> \
3478 const wxEventTable theClass<T1, T2, T3, T4, T5>::sm_eventTable = \
3479 { &baseClass::sm_eventTable, &theClass<T1, T2, T3, T4, T5>::sm_eventTableEntries[0] }; \
3480 template<typename T1, typename T2, typename T3, typename T4, typename T5> \
3481 const wxEventTable *theClass<T1, T2, T3, T4, T5>::GetEventTable() const \
3482 { return &theClass<T1, T2, T3, T4, T5>::sm_eventTable; } \
3483 template<typename T1, typename T2, typename T3, typename T4, typename T5> \
3484 wxEventHashTable theClass<T1, T2, T3, T4, T5>::sm_eventHashTable(theClass<T1, T2, T3, T4, T5>::sm_eventTable); \
3485 template<typename T1, typename T2, typename T3, typename T4, typename T5> \
3486 wxEventHashTable &theClass<T1, T2, T3, T4, T5>::GetEventHashTable() const \
3487 { return theClass<T1, T2, T3, T4, T5>::sm_eventHashTable; } \
3488 template<typename T1, typename T2, typename T3, typename T4, typename T5> \
3489 const wxEventTableEntry theClass<T1, T2, T3, T4, T5>::sm_eventTableEntries[] = { \
3490
3491 #define BEGIN_EVENT_TABLE_TEMPLATE7(theClass, baseClass, T1, T2, T3, T4, T5, T6, T7) \
3492 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> \
3493 const wxEventTable theClass<T1, T2, T3, T4, T5, T6, T7>::sm_eventTable = \
3494 { &baseClass::sm_eventTable, &theClass<T1, T2, T3, T4, T5, T6, T7>::sm_eventTableEntries[0] }; \
3495 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> \
3496 const wxEventTable *theClass<T1, T2, T3, T4, T5, T6, T7>::GetEventTable() const \
3497 { return &theClass<T1, T2, T3, T4, T5, T6, T7>::sm_eventTable; } \
3498 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> \
3499 wxEventHashTable theClass<T1, T2, T3, T4, T5, T6, T7>::sm_eventHashTable(theClass<T1, T2, T3, T4, T5, T6, T7>::sm_eventTable); \
3500 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> \
3501 wxEventHashTable &theClass<T1, T2, T3, T4, T5, T6, T7>::GetEventHashTable() const \
3502 { return theClass<T1, T2, T3, T4, T5, T6, T7>::sm_eventHashTable; } \
3503 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7> \
3504 const wxEventTableEntry theClass<T1, T2, T3, T4, T5, T6, T7>::sm_eventTableEntries[] = { \
3505
3506 #define BEGIN_EVENT_TABLE_TEMPLATE8(theClass, baseClass, T1, T2, T3, T4, T5, T6, T7, T8) \
3507 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> \
3508 const wxEventTable theClass<T1, T2, T3, T4, T5, T6, T7, T8>::sm_eventTable = \
3509 { &baseClass::sm_eventTable, &theClass<T1, T2, T3, T4, T5, T6, T7, T8>::sm_eventTableEntries[0] }; \
3510 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> \
3511 const wxEventTable *theClass<T1, T2, T3, T4, T5, T6, T7, T8>::GetEventTable() const \
3512 { return &theClass<T1, T2, T3, T4, T5, T6, T7, T8>::sm_eventTable; } \
3513 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> \
3514 wxEventHashTable theClass<T1, T2, T3, T4, T5, T6, T7, T8>::sm_eventHashTable(theClass<T1, T2, T3, T4, T5, T6, T7, T8>::sm_eventTable); \
3515 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> \
3516 wxEventHashTable &theClass<T1, T2, T3, T4, T5, T6, T7, T8>::GetEventHashTable() const \
3517 { return theClass<T1, T2, T3, T4, T5, T6, T7, T8>::sm_eventHashTable; } \
3518 template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> \
3519 const wxEventTableEntry theClass<T1, T2, T3, T4, T5, T6, T7, T8>::sm_eventTableEntries[] = { \
3520
3521 #define END_EVENT_TABLE() DECLARE_EVENT_TABLE_TERMINATOR() };
3522
3523 /*
3524 * Event table macros
3525 */
3526
3527 // helpers for writing shorter code below: declare an event macro taking 2, 1
3528 // or none ids (the missing ids default to wxID_ANY)
3529 //
3530 // macro arguments:
3531 // - evt one of wxEVT_XXX constants
3532 // - id1, id2 ids of the first/last id
3533 // - fn the function (should be cast to the right type)
3534 #define wx__DECLARE_EVT2(evt, id1, id2, fn) \
3535 DECLARE_EVENT_TABLE_ENTRY(evt, id1, id2, fn, NULL),
3536 #define wx__DECLARE_EVT1(evt, id, fn) \
3537 wx__DECLARE_EVT2(evt, id, wxID_ANY, fn)
3538 #define wx__DECLARE_EVT0(evt, fn) \
3539 wx__DECLARE_EVT1(evt, wxID_ANY, fn)
3540
3541
3542 // Generic events
3543 #define EVT_CUSTOM(event, winid, func) \
3544 wx__DECLARE_EVT1(event, winid, wxEventHandler(func))
3545 #define EVT_CUSTOM_RANGE(event, id1, id2, func) \
3546 wx__DECLARE_EVT2(event, id1, id2, wxEventHandler(func))
3547
3548 // EVT_COMMAND
3549 #define EVT_COMMAND(winid, event, func) \
3550 wx__DECLARE_EVT1(event, winid, wxCommandEventHandler(func))
3551
3552 #define EVT_COMMAND_RANGE(id1, id2, event, func) \
3553 wx__DECLARE_EVT2(event, id1, id2, wxCommandEventHandler(func))
3554
3555 #define EVT_NOTIFY(event, winid, func) \
3556 wx__DECLARE_EVT1(event, winid, wxNotifyEventHandler(func))
3557
3558 #define EVT_NOTIFY_RANGE(event, id1, id2, func) \
3559 wx__DECLARE_EVT2(event, id1, id2, wxNotifyEventHandler(func))
3560
3561 // Miscellaneous
3562 #define EVT_SIZE(func) wx__DECLARE_EVT0(wxEVT_SIZE, wxSizeEventHandler(func))
3563 #define EVT_SIZING(func) wx__DECLARE_EVT0(wxEVT_SIZING, wxSizeEventHandler(func))
3564 #define EVT_MOVE(func) wx__DECLARE_EVT0(wxEVT_MOVE, wxMoveEventHandler(func))
3565 #define EVT_MOVING(func) wx__DECLARE_EVT0(wxEVT_MOVING, wxMoveEventHandler(func))
3566 #define EVT_MOVE_START(func) wx__DECLARE_EVT0(wxEVT_MOVE_START, wxMoveEventHandler(func))
3567 #define EVT_MOVE_END(func) wx__DECLARE_EVT0(wxEVT_MOVE_END, wxMoveEventHandler(func))
3568 #define EVT_CLOSE(func) wx__DECLARE_EVT0(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(func))
3569 #define EVT_END_SESSION(func) wx__DECLARE_EVT0(wxEVT_END_SESSION, wxCloseEventHandler(func))
3570 #define EVT_QUERY_END_SESSION(func) wx__DECLARE_EVT0(wxEVT_QUERY_END_SESSION, wxCloseEventHandler(func))
3571 #define EVT_PAINT(func) wx__DECLARE_EVT0(wxEVT_PAINT, wxPaintEventHandler(func))
3572 #define EVT_NC_PAINT(func) wx__DECLARE_EVT0(wxEVT_NC_PAINT, wxNcPaintEventHandler(func))
3573 #define EVT_ERASE_BACKGROUND(func) wx__DECLARE_EVT0(wxEVT_ERASE_BACKGROUND, wxEraseEventHandler(func))
3574 #define EVT_CHAR(func) wx__DECLARE_EVT0(wxEVT_CHAR, wxCharEventHandler(func))
3575 #define EVT_KEY_DOWN(func) wx__DECLARE_EVT0(wxEVT_KEY_DOWN, wxKeyEventHandler(func))
3576 #define EVT_KEY_UP(func) wx__DECLARE_EVT0(wxEVT_KEY_UP, wxKeyEventHandler(func))
3577 #if wxUSE_HOTKEY
3578 #define EVT_HOTKEY(winid, func) wx__DECLARE_EVT1(wxEVT_HOTKEY, winid, wxCharEventHandler(func))
3579 #endif
3580 #define EVT_CHAR_HOOK(func) wx__DECLARE_EVT0(wxEVT_CHAR_HOOK, wxCharEventHandler(func))
3581 #define EVT_MENU_OPEN(func) wx__DECLARE_EVT0(wxEVT_MENU_OPEN, wxMenuEventHandler(func))
3582 #define EVT_MENU_CLOSE(func) wx__DECLARE_EVT0(wxEVT_MENU_CLOSE, wxMenuEventHandler(func))
3583 #define EVT_MENU_HIGHLIGHT(winid, func) wx__DECLARE_EVT1(wxEVT_MENU_HIGHLIGHT, winid, wxMenuEventHandler(func))
3584 #define EVT_MENU_HIGHLIGHT_ALL(func) wx__DECLARE_EVT0(wxEVT_MENU_HIGHLIGHT, wxMenuEventHandler(func))
3585 #define EVT_SET_FOCUS(func) wx__DECLARE_EVT0(wxEVT_SET_FOCUS, wxFocusEventHandler(func))
3586 #define EVT_KILL_FOCUS(func) wx__DECLARE_EVT0(wxEVT_KILL_FOCUS, wxFocusEventHandler(func))
3587 #define EVT_CHILD_FOCUS(func) wx__DECLARE_EVT0(wxEVT_CHILD_FOCUS, wxChildFocusEventHandler(func))
3588 #define EVT_ACTIVATE(func) wx__DECLARE_EVT0(wxEVT_ACTIVATE, wxActivateEventHandler(func))
3589 #define EVT_ACTIVATE_APP(func) wx__DECLARE_EVT0(wxEVT_ACTIVATE_APP, wxActivateEventHandler(func))
3590 #define EVT_HIBERNATE(func) wx__DECLARE_EVT0(wxEVT_HIBERNATE, wxActivateEventHandler(func))
3591 #define EVT_END_SESSION(func) wx__DECLARE_EVT0(wxEVT_END_SESSION, wxCloseEventHandler(func))
3592 #define EVT_QUERY_END_SESSION(func) wx__DECLARE_EVT0(wxEVT_QUERY_END_SESSION, wxCloseEventHandler(func))
3593 #define EVT_DROP_FILES(func) wx__DECLARE_EVT0(wxEVT_DROP_FILES, wxDropFilesEventHandler(func))
3594 #define EVT_INIT_DIALOG(func) wx__DECLARE_EVT0(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(func))
3595 #define EVT_SYS_COLOUR_CHANGED(func) wx__DECLARE_EVT0(wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEventHandler(func))
3596 #define EVT_DISPLAY_CHANGED(func) wx__DECLARE_EVT0(wxEVT_DISPLAY_CHANGED, wxDisplayChangedEventHandler(func))
3597 #define EVT_SHOW(func) wx__DECLARE_EVT0(wxEVT_SHOW, wxShowEventHandler(func))
3598 #define EVT_MAXIMIZE(func) wx__DECLARE_EVT0(wxEVT_MAXIMIZE, wxMaximizeEventHandler(func))
3599 #define EVT_ICONIZE(func) wx__DECLARE_EVT0(wxEVT_ICONIZE, wxIconizeEventHandler(func))
3600 #define EVT_NAVIGATION_KEY(func) wx__DECLARE_EVT0(wxEVT_NAVIGATION_KEY, wxNavigationKeyEventHandler(func))
3601 #define EVT_PALETTE_CHANGED(func) wx__DECLARE_EVT0(wxEVT_PALETTE_CHANGED, wxPaletteChangedEventHandler(func))
3602 #define EVT_QUERY_NEW_PALETTE(func) wx__DECLARE_EVT0(wxEVT_QUERY_NEW_PALETTE, wxQueryNewPaletteEventHandler(func))
3603 #define EVT_WINDOW_CREATE(func) wx__DECLARE_EVT0(wxEVT_CREATE, wxWindowCreateEventHandler(func))
3604 #define EVT_WINDOW_DESTROY(func) wx__DECLARE_EVT0(wxEVT_DESTROY, wxWindowDestroyEventHandler(func))
3605 #define EVT_SET_CURSOR(func) wx__DECLARE_EVT0(wxEVT_SET_CURSOR, wxSetCursorEventHandler(func))
3606 #define EVT_MOUSE_CAPTURE_CHANGED(func) wx__DECLARE_EVT0(wxEVT_MOUSE_CAPTURE_CHANGED, wxMouseCaptureChangedEventHandler(func))
3607 #define EVT_MOUSE_CAPTURE_LOST(func) wx__DECLARE_EVT0(wxEVT_MOUSE_CAPTURE_LOST, wxMouseCaptureLostEventHandler(func))
3608
3609 // Mouse events
3610 #define EVT_LEFT_DOWN(func) wx__DECLARE_EVT0(wxEVT_LEFT_DOWN, wxMouseEventHandler(func))
3611 #define EVT_LEFT_UP(func) wx__DECLARE_EVT0(wxEVT_LEFT_UP, wxMouseEventHandler(func))
3612 #define EVT_MIDDLE_DOWN(func) wx__DECLARE_EVT0(wxEVT_MIDDLE_DOWN, wxMouseEventHandler(func))
3613 #define EVT_MIDDLE_UP(func) wx__DECLARE_EVT0(wxEVT_MIDDLE_UP, wxMouseEventHandler(func))
3614 #define EVT_RIGHT_DOWN(func) wx__DECLARE_EVT0(wxEVT_RIGHT_DOWN, wxMouseEventHandler(func))
3615 #define EVT_RIGHT_UP(func) wx__DECLARE_EVT0(wxEVT_RIGHT_UP, wxMouseEventHandler(func))
3616 #define EVT_MOTION(func) wx__DECLARE_EVT0(wxEVT_MOTION, wxMouseEventHandler(func))
3617 #define EVT_LEFT_DCLICK(func) wx__DECLARE_EVT0(wxEVT_LEFT_DCLICK, wxMouseEventHandler(func))
3618 #define EVT_MIDDLE_DCLICK(func) wx__DECLARE_EVT0(wxEVT_MIDDLE_DCLICK, wxMouseEventHandler(func))
3619 #define EVT_RIGHT_DCLICK(func) wx__DECLARE_EVT0(wxEVT_RIGHT_DCLICK, wxMouseEventHandler(func))
3620 #define EVT_LEAVE_WINDOW(func) wx__DECLARE_EVT0(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(func))
3621 #define EVT_ENTER_WINDOW(func) wx__DECLARE_EVT0(wxEVT_ENTER_WINDOW, wxMouseEventHandler(func))
3622 #define EVT_MOUSEWHEEL(func) wx__DECLARE_EVT0(wxEVT_MOUSEWHEEL, wxMouseEventHandler(func))
3623 #define EVT_MOUSE_AUX1_DOWN(func) wx__DECLARE_EVT0(wxEVT_AUX1_DOWN, wxMouseEventHandler(func))
3624 #define EVT_MOUSE_AUX1_UP(func) wx__DECLARE_EVT0(wxEVT_AUX1_UP, wxMouseEventHandler(func))
3625 #define EVT_MOUSE_AUX1_DCLICK(func) wx__DECLARE_EVT0(wxEVT_AUX1_DCLICK, wxMouseEventHandler(func))
3626 #define EVT_MOUSE_AUX2_DOWN(func) wx__DECLARE_EVT0(wxEVT_AUX2_DOWN, wxMouseEventHandler(func))
3627 #define EVT_MOUSE_AUX2_UP(func) wx__DECLARE_EVT0(wxEVT_AUX2_UP, wxMouseEventHandler(func))
3628 #define EVT_MOUSE_AUX2_DCLICK(func) wx__DECLARE_EVT0(wxEVT_AUX2_DCLICK, wxMouseEventHandler(func))
3629
3630 // All mouse events
3631 #define EVT_MOUSE_EVENTS(func) \
3632 EVT_LEFT_DOWN(func) \
3633 EVT_LEFT_UP(func) \
3634 EVT_LEFT_DCLICK(func) \
3635 EVT_MIDDLE_DOWN(func) \
3636 EVT_MIDDLE_UP(func) \
3637 EVT_MIDDLE_DCLICK(func) \
3638 EVT_RIGHT_DOWN(func) \
3639 EVT_RIGHT_UP(func) \
3640 EVT_RIGHT_DCLICK(func) \
3641 EVT_MOUSE_AUX1_DOWN(func) \
3642 EVT_MOUSE_AUX1_UP(func) \
3643 EVT_MOUSE_AUX1_DCLICK(func) \
3644 EVT_MOUSE_AUX2_DOWN(func) \
3645 EVT_MOUSE_AUX2_UP(func) \
3646 EVT_MOUSE_AUX2_DCLICK(func) \
3647 EVT_MOTION(func) \
3648 EVT_LEAVE_WINDOW(func) \
3649 EVT_ENTER_WINDOW(func) \
3650 EVT_MOUSEWHEEL(func)
3651
3652 // Scrolling from wxWindow (sent to wxScrolledWindow)
3653 #define EVT_SCROLLWIN_TOP(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_TOP, wxScrollWinEventHandler(func))
3654 #define EVT_SCROLLWIN_BOTTOM(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_BOTTOM, wxScrollWinEventHandler(func))
3655 #define EVT_SCROLLWIN_LINEUP(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_LINEUP, wxScrollWinEventHandler(func))
3656 #define EVT_SCROLLWIN_LINEDOWN(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_LINEDOWN, wxScrollWinEventHandler(func))
3657 #define EVT_SCROLLWIN_PAGEUP(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_PAGEUP, wxScrollWinEventHandler(func))
3658 #define EVT_SCROLLWIN_PAGEDOWN(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_PAGEDOWN, wxScrollWinEventHandler(func))
3659 #define EVT_SCROLLWIN_THUMBTRACK(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_THUMBTRACK, wxScrollWinEventHandler(func))
3660 #define EVT_SCROLLWIN_THUMBRELEASE(func) wx__DECLARE_EVT0(wxEVT_SCROLLWIN_THUMBRELEASE, wxScrollWinEventHandler(func))
3661
3662 #define EVT_SCROLLWIN(func) \
3663 EVT_SCROLLWIN_TOP(func) \
3664 EVT_SCROLLWIN_BOTTOM(func) \
3665 EVT_SCROLLWIN_LINEUP(func) \
3666 EVT_SCROLLWIN_LINEDOWN(func) \
3667 EVT_SCROLLWIN_PAGEUP(func) \
3668 EVT_SCROLLWIN_PAGEDOWN(func) \
3669 EVT_SCROLLWIN_THUMBTRACK(func) \
3670 EVT_SCROLLWIN_THUMBRELEASE(func)
3671
3672 // Scrolling from wxSlider and wxScrollBar
3673 #define EVT_SCROLL_TOP(func) wx__DECLARE_EVT0(wxEVT_SCROLL_TOP, wxScrollEventHandler(func))
3674 #define EVT_SCROLL_BOTTOM(func) wx__DECLARE_EVT0(wxEVT_SCROLL_BOTTOM, wxScrollEventHandler(func))
3675 #define EVT_SCROLL_LINEUP(func) wx__DECLARE_EVT0(wxEVT_SCROLL_LINEUP, wxScrollEventHandler(func))
3676 #define EVT_SCROLL_LINEDOWN(func) wx__DECLARE_EVT0(wxEVT_SCROLL_LINEDOWN, wxScrollEventHandler(func))
3677 #define EVT_SCROLL_PAGEUP(func) wx__DECLARE_EVT0(wxEVT_SCROLL_PAGEUP, wxScrollEventHandler(func))
3678 #define EVT_SCROLL_PAGEDOWN(func) wx__DECLARE_EVT0(wxEVT_SCROLL_PAGEDOWN, wxScrollEventHandler(func))
3679 #define EVT_SCROLL_THUMBTRACK(func) wx__DECLARE_EVT0(wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler(func))
3680 #define EVT_SCROLL_THUMBRELEASE(func) wx__DECLARE_EVT0(wxEVT_SCROLL_THUMBRELEASE, wxScrollEventHandler(func))
3681 #define EVT_SCROLL_CHANGED(func) wx__DECLARE_EVT0(wxEVT_SCROLL_CHANGED, wxScrollEventHandler(func))
3682
3683 #define EVT_SCROLL(func) \
3684 EVT_SCROLL_TOP(func) \
3685 EVT_SCROLL_BOTTOM(func) \
3686 EVT_SCROLL_LINEUP(func) \
3687 EVT_SCROLL_LINEDOWN(func) \
3688 EVT_SCROLL_PAGEUP(func) \
3689 EVT_SCROLL_PAGEDOWN(func) \
3690 EVT_SCROLL_THUMBTRACK(func) \
3691 EVT_SCROLL_THUMBRELEASE(func) \
3692 EVT_SCROLL_CHANGED(func)
3693
3694 // Scrolling from wxSlider and wxScrollBar, with an id
3695 #define EVT_COMMAND_SCROLL_TOP(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_TOP, winid, wxScrollEventHandler(func))
3696 #define EVT_COMMAND_SCROLL_BOTTOM(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_BOTTOM, winid, wxScrollEventHandler(func))
3697 #define EVT_COMMAND_SCROLL_LINEUP(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_LINEUP, winid, wxScrollEventHandler(func))
3698 #define EVT_COMMAND_SCROLL_LINEDOWN(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_LINEDOWN, winid, wxScrollEventHandler(func))
3699 #define EVT_COMMAND_SCROLL_PAGEUP(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_PAGEUP, winid, wxScrollEventHandler(func))
3700 #define EVT_COMMAND_SCROLL_PAGEDOWN(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_PAGEDOWN, winid, wxScrollEventHandler(func))
3701 #define EVT_COMMAND_SCROLL_THUMBTRACK(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_THUMBTRACK, winid, wxScrollEventHandler(func))
3702 #define EVT_COMMAND_SCROLL_THUMBRELEASE(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_THUMBRELEASE, winid, wxScrollEventHandler(func))
3703 #define EVT_COMMAND_SCROLL_CHANGED(winid, func) wx__DECLARE_EVT1(wxEVT_SCROLL_CHANGED, winid, wxScrollEventHandler(func))
3704
3705 #define EVT_COMMAND_SCROLL(winid, func) \
3706 EVT_COMMAND_SCROLL_TOP(winid, func) \
3707 EVT_COMMAND_SCROLL_BOTTOM(winid, func) \
3708 EVT_COMMAND_SCROLL_LINEUP(winid, func) \
3709 EVT_COMMAND_SCROLL_LINEDOWN(winid, func) \
3710 EVT_COMMAND_SCROLL_PAGEUP(winid, func) \
3711 EVT_COMMAND_SCROLL_PAGEDOWN(winid, func) \
3712 EVT_COMMAND_SCROLL_THUMBTRACK(winid, func) \
3713 EVT_COMMAND_SCROLL_THUMBRELEASE(winid, func) \
3714 EVT_COMMAND_SCROLL_CHANGED(winid, func)
3715
3716 #if WXWIN_COMPATIBILITY_2_6
3717 // compatibility macros for the old name, deprecated in 2.8
3718 #define wxEVT_SCROLL_ENDSCROLL wxEVT_SCROLL_CHANGED
3719 #define EVT_COMMAND_SCROLL_ENDSCROLL EVT_COMMAND_SCROLL_CHANGED
3720 #define EVT_SCROLL_ENDSCROLL EVT_SCROLL_CHANGED
3721 #endif // WXWIN_COMPATIBILITY_2_6
3722
3723 // Convenience macros for commonly-used commands
3724 #define EVT_CHECKBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_CHECKBOX_CLICKED, winid, wxCommandEventHandler(func))
3725 #define EVT_CHOICE(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_CHOICE_SELECTED, winid, wxCommandEventHandler(func))
3726 #define EVT_LISTBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_LISTBOX_SELECTED, winid, wxCommandEventHandler(func))
3727 #define EVT_LISTBOX_DCLICK(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, winid, wxCommandEventHandler(func))
3728 #define EVT_MENU(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_MENU_SELECTED, winid, wxCommandEventHandler(func))
3729 #define EVT_MENU_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_COMMAND_MENU_SELECTED, id1, id2, wxCommandEventHandler(func))
3730 #if defined(__SMARTPHONE__)
3731 # define EVT_BUTTON(winid, func) EVT_MENU(winid, func)
3732 #else
3733 # define EVT_BUTTON(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_BUTTON_CLICKED, winid, wxCommandEventHandler(func))
3734 #endif
3735 #define EVT_SLIDER(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_SLIDER_UPDATED, winid, wxCommandEventHandler(func))
3736 #define EVT_RADIOBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_RADIOBOX_SELECTED, winid, wxCommandEventHandler(func))
3737 #define EVT_RADIOBUTTON(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_RADIOBUTTON_SELECTED, winid, wxCommandEventHandler(func))
3738 // EVT_SCROLLBAR is now obsolete since we use EVT_COMMAND_SCROLL... events
3739 #define EVT_SCROLLBAR(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_SCROLLBAR_UPDATED, winid, wxCommandEventHandler(func))
3740 #define EVT_VLBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_VLBOX_SELECTED, winid, wxCommandEventHandler(func))
3741 #define EVT_COMBOBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_COMBOBOX_SELECTED, winid, wxCommandEventHandler(func))
3742 #define EVT_TOOL(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_TOOL_CLICKED, winid, wxCommandEventHandler(func))
3743 #define EVT_TOOL_DROPDOWN(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_TOOL_DROPDOWN_CLICKED, winid, wxCommandEventHandler(func))
3744 #define EVT_TOOL_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_COMMAND_TOOL_CLICKED, id1, id2, wxCommandEventHandler(func))
3745 #define EVT_TOOL_RCLICKED(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_TOOL_RCLICKED, winid, wxCommandEventHandler(func))
3746 #define EVT_TOOL_RCLICKED_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_COMMAND_TOOL_RCLICKED, id1, id2, wxCommandEventHandler(func))
3747 #define EVT_TOOL_ENTER(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_TOOL_ENTER, winid, wxCommandEventHandler(func))
3748 #define EVT_CHECKLISTBOX(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, winid, wxCommandEventHandler(func))
3749 #define EVT_COMBOBOX_DROPDOWN(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_COMBOBOX_DROPDOWN, winid, wxCommandEventHandler(func))
3750 #define EVT_COMBOBOX_CLOSEUP(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_COMBOBOX_CLOSEUP, winid, wxCommandEventHandler(func))
3751
3752 // Generic command events
3753 #define EVT_COMMAND_LEFT_CLICK(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_LEFT_CLICK, winid, wxCommandEventHandler(func))
3754 #define EVT_COMMAND_LEFT_DCLICK(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_LEFT_DCLICK, winid, wxCommandEventHandler(func))
3755 #define EVT_COMMAND_RIGHT_CLICK(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_RIGHT_CLICK, winid, wxCommandEventHandler(func))
3756 #define EVT_COMMAND_RIGHT_DCLICK(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_RIGHT_DCLICK, winid, wxCommandEventHandler(func))
3757 #define EVT_COMMAND_SET_FOCUS(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_SET_FOCUS, winid, wxCommandEventHandler(func))
3758 #define EVT_COMMAND_KILL_FOCUS(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_KILL_FOCUS, winid, wxCommandEventHandler(func))
3759 #define EVT_COMMAND_ENTER(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_ENTER, winid, wxCommandEventHandler(func))
3760
3761 // Joystick events
3762
3763 #define EVT_JOY_BUTTON_DOWN(func) wx__DECLARE_EVT0(wxEVT_JOY_BUTTON_DOWN, wxJoystickEventHandler(func))
3764 #define EVT_JOY_BUTTON_UP(func) wx__DECLARE_EVT0(wxEVT_JOY_BUTTON_UP, wxJoystickEventHandler(func))
3765 #define EVT_JOY_MOVE(func) wx__DECLARE_EVT0(wxEVT_JOY_MOVE, wxJoystickEventHandler(func))
3766 #define EVT_JOY_ZMOVE(func) wx__DECLARE_EVT0(wxEVT_JOY_ZMOVE, wxJoystickEventHandler(func))
3767
3768 // All joystick events
3769 #define EVT_JOYSTICK_EVENTS(func) \
3770 EVT_JOY_BUTTON_DOWN(func) \
3771 EVT_JOY_BUTTON_UP(func) \
3772 EVT_JOY_MOVE(func) \
3773 EVT_JOY_ZMOVE(func)
3774
3775 // Idle event
3776 #define EVT_IDLE(func) wx__DECLARE_EVT0(wxEVT_IDLE, wxIdleEventHandler(func))
3777
3778 // Update UI event
3779 #define EVT_UPDATE_UI(winid, func) wx__DECLARE_EVT1(wxEVT_UPDATE_UI, winid, wxUpdateUIEventHandler(func))
3780 #define EVT_UPDATE_UI_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_UPDATE_UI, id1, id2, wxUpdateUIEventHandler(func))
3781
3782 // Help events
3783 #define EVT_HELP(winid, func) wx__DECLARE_EVT1(wxEVT_HELP, winid, wxHelpEventHandler(func))
3784 #define EVT_HELP_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_HELP, id1, id2, wxHelpEventHandler(func))
3785 #define EVT_DETAILED_HELP(winid, func) wx__DECLARE_EVT1(wxEVT_DETAILED_HELP, winid, wxHelpEventHandler(func))
3786 #define EVT_DETAILED_HELP_RANGE(id1, id2, func) wx__DECLARE_EVT2(wxEVT_DETAILED_HELP, id1, id2, wxHelpEventHandler(func))
3787
3788 // Context Menu Events
3789 #define EVT_CONTEXT_MENU(func) wx__DECLARE_EVT0(wxEVT_CONTEXT_MENU, wxContextMenuEventHandler(func))
3790 #define EVT_COMMAND_CONTEXT_MENU(winid, func) wx__DECLARE_EVT1(wxEVT_CONTEXT_MENU, winid, wxContextMenuEventHandler(func))
3791
3792 // Clipboard text Events
3793 #define EVT_TEXT_CUT(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_TEXT_CUT, winid, wxClipboardTextEventHandler(func))
3794 #define EVT_TEXT_COPY(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_TEXT_COPY, winid, wxClipboardTextEventHandler(func))
3795 #define EVT_TEXT_PASTE(winid, func) wx__DECLARE_EVT1(wxEVT_COMMAND_TEXT_PASTE, winid, wxClipboardTextEventHandler(func))
3796
3797 // Thread events
3798 #define EVT_THREAD(id, func) wx__DECLARE_EVT1(wxEVT_COMMAND_THREAD, id, wxThreadEventHandler(func))
3799
3800 // ----------------------------------------------------------------------------
3801 // Helper functions
3802 // ----------------------------------------------------------------------------
3803
3804 // This is an ugly hack to allow the use of Bind() instead of Connect() inside
3805 // the library code if the library was built with support for it, here is how
3806 // it is used:
3807 //
3808 // class SomeEventHandlingClass : wxBIND_OR_CONNECT_HACK_BASE_CLASS
3809 // public SomeBaseClass
3810 // {
3811 // public:
3812 // SomeEventHandlingClass(wxWindow *win)
3813 // {
3814 // // connect to the event for the given window
3815 // wxBIND_OR_CONNECT_HACK(win, wxEVT_SOMETHING, wxSomeEventHandler,
3816 // SomeEventHandlingClass::OnSomeEvent, this);
3817 // }
3818 //
3819 // private:
3820 // void OnSomeEvent(wxSomeEvent&) { ... }
3821 // };
3822 //
3823 // This is *not* meant to be used by library users, it is only defined here
3824 // (and not in a private header) because the base class must be visible from
3825 // other public headers, please do NOT use this in your code, it will be
3826 // removed from future wx versions without warning.
3827 #if wxEVENTS_COMPATIBILITY_2_8
3828 #define wxBIND_OR_CONNECT_HACK_BASE_CLASS public wxEvtHandler,
3829 #define wxBIND_OR_CONNECT_HACK_ONLY_BASE_CLASS : public wxEvtHandler
3830 #define wxBIND_OR_CONNECT_HACK(w, evt, handler, func, obj) \
3831 win->Connect(evt, handler(func), NULL, obj)
3832 #else // wxEVENTS_COMPATIBILITY_2_8
3833 #define wxBIND_OR_CONNECT_HACK_BASE_CLASS
3834 #define wxBIND_OR_CONNECT_HACK_ONLY_BASE_CLASS
3835 #define wxBIND_OR_CONNECT_HACK(w, evt, handler, func, obj) \
3836 win->Bind(evt, &func, obj)
3837 #endif // wxEVENTS_COMPATIBILITY_2_8/!wxEVENTS_COMPATIBILITY_2_8
3838
3839 #if wxUSE_GUI
3840
3841 // Find a window with the focus, that is also a descendant of the given window.
3842 // This is used to determine the window to initially send commands to.
3843 WXDLLIMPEXP_CORE wxWindow* wxFindFocusDescendant(wxWindow* ancestor);
3844
3845 #endif // wxUSE_GUI
3846
3847 #endif // _WX_EVENT_H_