1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxEvtHandler, wxEventBlocker and many
4 // wxEvent-derived classes
5 // Author: wxWidgets team
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 The predefined constants for the number of times we propagate event
12 upwards window child-parent chain.
14 enum wxEventPropagation
16 /// don't propagate it at all
17 wxEVENT_PROPAGATE_NONE
= 0,
19 /// propagate it until it is processed
20 wxEVENT_PROPAGATE_MAX
= INT_MAX
24 The different categories for a wxEvent; see wxEvent::GetEventCategory.
26 @note They are used as OR-combinable flags by wxEventLoopBase::YieldFor.
31 This is the category for those events which are generated to update
32 the appearance of the GUI but which (usually) do not comport data
33 processing, i.e. which do not provide input or output data
34 (e.g. size events, scroll events, etc).
35 They are events NOT directly generated by the user's input devices.
37 wxEVT_CATEGORY_UI
= 1,
40 This category groups those events which are generated directly from the
41 user through input devices like mouse and keyboard and usually result in
42 data to be processed from the application
43 (e.g. mouse clicks, key presses, etc).
45 wxEVT_CATEGORY_USER_INPUT
= 2,
47 /// This category is for wxSocketEvent
48 wxEVT_CATEGORY_SOCKET
= 4,
50 /// This category is for wxTimerEvent
51 wxEVT_CATEGORY_TIMER
= 8,
54 This category is for any event used to send notifications from the
55 secondary threads to the main one or in general for notifications among
56 different threads (which may or may not be user-generated).
57 See e.g. wxThreadEvent.
59 wxEVT_CATEGORY_THREAD
= 16,
62 This mask is used in wxEventLoopBase::YieldFor to specify that all event
63 categories should be processed.
66 wxEVT_CATEGORY_UI
|wxEVT_CATEGORY_USER_INPUT
|wxEVT_CATEGORY_SOCKET
| \
67 wxEVT_CATEGORY_TIMER
|wxEVT_CATEGORY_THREAD
73 An event is a structure holding information about an event passed to a
74 callback or member function.
76 wxEvent used to be a multipurpose event object, and is an abstract base class
77 for other event classes (see below).
79 For more information about events, see the @ref overview_events overview.
82 In wxPerl custom event classes should be derived from
83 @c Wx::PlEvent and @c Wx::PlCommandEvent.
89 @see wxCommandEvent, wxMouseEvent
91 class wxEvent
: public wxObject
97 Notice that events are usually created by wxWidgets itself and creating
98 e.g. a wxPaintEvent in your code and sending it to e.g. a wxTextCtrl
99 will not usually affect it at all as native controls have no specific
100 knowledge about wxWidgets events. However you may construct objects of
101 specific types and pass them to wxEvtHandler::ProcessEvent() if you
102 want to create your own custom control and want to process its events
103 in the same manner as the standard ones.
105 Also please notice that the order of parameters in this constructor is
106 different from almost all the derived classes which specify the event
107 type as the first argument.
110 The identifier of the object (window, timer, ...) which generated
113 The unique type of event, e.g. wxEVT_PAINT, wxEVT_SIZE or
114 wxEVT_COMMAND_BUTTON_CLICKED.
116 wxEvent(int id
= 0, wxEventType eventType
= wxEVT_NULL
);
119 Returns a copy of the event.
121 Any event that is posted to the wxWidgets event system for later action
122 (via wxEvtHandler::AddPendingEvent, wxEvtHandler::QueueEvent or wxPostEvent())
123 must implement this method.
125 All wxWidgets events fully implement this method, but any derived events
126 implemented by the user should also implement this method just in case they
127 (or some event derived from them) are ever posted.
129 All wxWidgets events implement a copy constructor, so the easiest way of
130 implementing the Clone function is to implement a copy constructor for
131 a new event (call it MyEvent) and then define the Clone function like this:
134 wxEvent *Clone() const { return new MyEvent(*this); }
137 virtual wxEvent
* Clone() const = 0;
140 Returns the object (usually a window) associated with the event, if any.
142 wxObject
* GetEventObject() const;
145 Returns the identifier of the given event type, such as @c wxEVT_COMMAND_BUTTON_CLICKED.
147 wxEventType
GetEventType() const;
150 Returns a generic category for this event.
151 wxEvent implementation returns @c wxEVT_CATEGORY_UI by default.
153 This function is used to selectively process events in wxEventLoopBase::YieldFor.
155 virtual wxEventCategory
GetEventCategory() const;
158 Returns the identifier associated with this event, such as a button command id.
163 Returns @true if the event handler should be skipped, @false otherwise.
165 bool GetSkipped() const;
168 Gets the timestamp for the event. The timestamp is the time in milliseconds
169 since some fixed moment (not necessarily the standard Unix Epoch, so only
170 differences between the timestamps and not their absolute values usually make sense).
173 wxWidgets returns a non-NULL timestamp only for mouse and key events
174 (see wxMouseEvent and wxKeyEvent).
176 long GetTimestamp() const;
179 Returns @true if the event is or is derived from wxCommandEvent else it returns @false.
181 @note exists only for optimization purposes.
183 bool IsCommandEvent() const;
186 Sets the propagation level to the given value (for example returned from an
187 earlier call to wxEvent::StopPropagation).
189 void ResumePropagation(int propagationLevel
);
192 Sets the originating object.
194 void SetEventObject(wxObject
* object
);
199 void SetEventType(wxEventType type
);
202 Sets the identifier associated with this event, such as a button command id.
207 Sets the timestamp for the event.
209 void SetTimestamp(long timeStamp
= 0);
212 Test if this event should be propagated or not, i.e. if the propagation level
213 is currently greater than 0.
215 bool ShouldPropagate() const;
218 This method can be used inside an event handler to control whether further
219 event handlers bound to this event will be called after the current one returns.
221 Without Skip() (or equivalently if Skip(@false) is used), the event will not
222 be processed any more. If Skip(@true) is called, the event processing system
223 continues searching for a further handler function for this event, even though
224 it has been processed already in the current handler.
226 In general, it is recommended to skip all non-command events to allow the
227 default handling to take place. The command events are, however, normally not
228 skipped as usually a single command such as a button click or menu item
229 selection must only be processed by one handler.
231 void Skip(bool skip
= true);
234 Stop the event from propagating to its parent window.
236 Returns the old propagation level value which may be later passed to
237 ResumePropagation() to allow propagating the event again.
239 int StopPropagation();
243 Indicates how many levels the event can propagate.
245 This member is protected and should typically only be set in the constructors
246 of the derived classes. It may be temporarily changed by StopPropagation()
247 and ResumePropagation() and tested with ShouldPropagate().
249 The initial value is set to either @c wxEVENT_PROPAGATE_NONE (by default)
250 meaning that the event shouldn't be propagated at all or to
251 @c wxEVENT_PROPAGATE_MAX (for command events) meaning that it should be
252 propagated as much as necessary.
254 Any positive number means that the event should be propagated but no more than
255 the given number of times. E.g. the propagation level may be set to 1 to
256 propagate the event to its parent only, but not to its grandparent.
258 int m_propagationLevel
;
262 @class wxEventBlocker
264 This class is a special event handler which allows to discard
265 any event (or a set of event types) directed to a specific window.
270 void MyWindow::DoSomething()
273 // block all events directed to this window while
274 // we do the 1000 FunctionWhichSendsEvents() calls
275 wxEventBlocker blocker(this);
277 for ( int i = 0; i 1000; i++ )
278 FunctionWhichSendsEvents(i);
280 } // ~wxEventBlocker called, old event handler is restored
282 // the event generated by this call will be processed:
283 FunctionWhichSendsEvents(0)
290 @see @ref overview_events_processing, wxEvtHandler
292 class wxEventBlocker
: public wxEvtHandler
296 Constructs the blocker for the given window and for the given event type.
298 If @a type is @c wxEVT_ANY, then all events for that window are blocked.
299 You can call Block() after creation to add other event types to the list
302 Note that the @a win window @b must remain alive until the
303 wxEventBlocker object destruction.
305 wxEventBlocker(wxWindow
* win
, wxEventType type
= -1);
308 Destructor. The blocker will remove itself from the chain of event handlers for
309 the window provided in the constructor, thus restoring normal processing of events.
311 virtual ~wxEventBlocker();
314 Adds to the list of event types which should be blocked the given @a eventType.
316 void Block(wxEventType eventType
);
324 A class that can handle events from the windowing system.
325 wxWindow is (and therefore all window classes are) derived from this class.
327 When events are received, wxEvtHandler invokes the method listed in the
328 event table using itself as the object. When using multiple inheritance
329 <b>it is imperative that the wxEvtHandler(-derived) class is the first
330 class inherited</b> such that the @c this pointer for the overall object
331 will be identical to the @c this pointer of the wxEvtHandler portion.
336 @see @ref overview_events_processing, wxEventBlocker, wxEventLoopBase
338 class wxEvtHandler
: public wxObject
, public wxTrackable
349 If the handler is part of a chain, the destructor will unlink itself
352 virtual ~wxEvtHandler();
356 @name Event queuing and processing
361 Queue event for a later processing.
363 This method is similar to ProcessEvent() but while the latter is
364 synchronous, i.e. the event is processed immediately, before the
365 function returns, this one is asynchronous and returns immediately
366 while the event will be processed at some later time (usually during
367 the next event loop iteration).
369 Another important difference is that this method takes ownership of the
370 @a event parameter, i.e. it will delete it itself. This implies that
371 the event should be allocated on the heap and that the pointer can't be
372 used any more after the function returns (as it can be deleted at any
375 QueueEvent() can be used for inter-thread communication from the worker
376 threads to the main thread, it is safe in the sense that it uses
377 locking internally and avoids the problem mentioned in AddPendingEvent()
378 documentation by ensuring that the @a event object is not used by the
379 calling thread any more. Care should still be taken to avoid that some
380 fields of this object are used by it, notably any wxString members of
381 the event object must not be shallow copies of another wxString object
382 as this would result in them still using the same string buffer behind
383 the scenes. For example:
385 void FunctionInAWorkerThread(const wxString& str)
387 wxCommandEvent* evt = new wxCommandEvent;
389 // NOT evt->SetString(str) as this would be a shallow copy
390 evt->SetString(str.c_str()); // make a deep copy
392 wxTheApp->QueueEvent( evt );
396 Note that you can use wxThreadEvent instead of wxCommandEvent
397 to avoid this problem:
399 void FunctionInAWorkerThread(const wxString& str)
404 // wxThreadEvent::Clone() makes sure that the internal wxString
405 // member is not shared by other wxString instances:
406 wxTheApp->QueueEvent( evt.Clone() );
410 Finally notice that this method automatically wakes up the event loop
411 if it is currently idle by calling ::wxWakeUpIdle() so there is no need
412 to do it manually when using it.
417 A heap-allocated event to be queued, QueueEvent() takes ownership
418 of it. This parameter shouldn't be @c NULL.
420 virtual void QueueEvent(wxEvent
*event
);
423 Post an event to be processed later.
425 This function is similar to QueueEvent() but can't be used to post
426 events from worker threads for the event objects with wxString fields
427 (i.e. in practice most of them) because of an unsafe use of the same
428 wxString object which happens because the wxString field in the
429 original @a event object and its copy made internally by this function
430 share the same string buffer internally. Use QueueEvent() to avoid
433 A copy of @a event is made by the function, so the original can be deleted
434 as soon as function returns (it is common that the original is created
435 on the stack). This requires that the wxEvent::Clone() method be
436 implemented by event so that it can be duplicated and stored until it
440 Event to add to the pending events queue.
442 virtual void AddPendingEvent(const wxEvent
& event
);
445 Processes an event, searching event tables and calling zero or more suitable
446 event handler function(s).
448 Normally, your application would not call this function: it is called in the
449 wxWidgets implementation to dispatch incoming user interface events to the
450 framework (and application).
452 However, you might need to call it if implementing new functionality
453 (such as a new control) where you define new event types, as opposed to
454 allowing the user to override virtual functions.
456 Notice that you don't usually need to override ProcessEvent() to
457 customize the event handling, overriding the specially provided
458 TryBefore() and TryAfter() functions is usually enough. For example,
459 wxMDIParentFrame may override TryBefore() to ensure that the menu
460 events are processed in the active child frame before being processed
461 in the parent frame itself.
463 The normal order of event table searching is as follows:
464 -# wxApp::FilterEvent() is called. If it returns anything but @c -1
465 (default) the processing stops here.
466 -# TryBefore() is called (this is where wxValidator are taken into
467 account for wxWindow objects). If this returns @true, the function exits.
468 -# If the object is disabled (via a call to wxEvtHandler::SetEvtHandlerEnabled)
469 the function skips to step (7).
470 -# Dynamic event table of the handlers bound using Bind<>() is
471 searched. If a handler is found, it is executed and the function
472 returns @true unless the handler used wxEvent::Skip() to indicate
473 that it didn't handle the event in which case the search continues.
474 -# Static events table of the handlers bound using event table
475 macros is searched for this event handler. If this fails, the base
476 class event table table is tried, and so on until no more tables
477 exist or an appropriate function was found. If a handler is found,
478 the same logic as in the previous step applies.
479 -# The search is applied down the entire chain of event handlers (usually the
480 chain has a length of one). This chain can be formed using wxEvtHandler::SetNextHandler():
481 @image html overview_events_chain.png
482 (referring to the image, if @c A->ProcessEvent is called and it doesn't handle
483 the event, @c B->ProcessEvent will be called and so on...).
484 Note that in the case of wxWindow you can build a stack of event handlers
485 (see wxWindow::PushEventHandler() for more info).
486 If any of the handlers of the chain return @true, the function exits.
487 -# TryAfter() is called: for the wxWindow object this may propagate the
488 event to the window parent (recursively). If the event is still not
489 processed, ProcessEvent() on wxTheApp object is called as the last
492 Notice that steps (2)-(6) are performed in ProcessEventLocally()
493 which is called by this function.
498 @true if a suitable event handler function was found and executed,
499 and the function did not call wxEvent::Skip.
501 @see SearchEventTable()
503 virtual bool ProcessEvent(wxEvent
& event
);
506 Try to process the event in this handler and all those chained to it.
508 As explained in ProcessEvent() documentation, the event handlers may be
509 chained in a doubly-linked list. This function tries to process the
510 event in this handler (including performing any pre-processing done in
511 TryBefore(), e.g. applying validators) and all those following it in
512 the chain until the event is processed or the chain is exhausted.
514 This function is called from ProcessEvent() and, in turn, calls
515 TryThis() for each handler in turn. It is not virtual and so cannot be
516 overridden but can, and should, be called to forward an event to
517 another handler instead of ProcessEvent() which would result in a
518 duplicate call to TryAfter(), e.g. resulting in all unprocessed events
519 being sent to the application object multiple times.
526 @true if this handler of one of those chained to it processed the
529 bool ProcessEventLocally(wxEvent
& event
);
532 Processes an event by calling ProcessEvent() and handles any exceptions
533 that occur in the process.
534 If an exception is thrown in event handler, wxApp::OnExceptionInMainLoop is called.
539 @return @true if the event was processed, @false if no handler was found
540 or an exception was thrown.
542 @see wxWindow::HandleWindowEvent
544 bool SafelyProcessEvent(wxEvent
& event
);
547 Processes the pending events previously queued using QueueEvent() or
548 AddPendingEvent(); you must call this function only if you are sure
549 there are pending events for this handler, otherwise a @c wxCHECK
552 The real processing still happens in ProcessEvent() which is called by this
555 Note that this function needs a valid application object (see
556 wxAppConsole::GetInstance()) because wxApp holds the list of the event
557 handlers with pending events and this function manipulates that list.
559 void ProcessPendingEvents();
562 Deletes all events queued on this event handler using QueueEvent() or
565 Use with care because the events which are deleted are (obviously) not
566 processed and this may have unwanted consequences (e.g. user actions events
569 void DeletePendingEvents();
572 Searches the event table, executing an event handler function if an appropriate
576 Event table to be searched.
578 Event to be matched against an event table entry.
580 @return @true if a suitable event handler function was found and
581 executed, and the function did not call wxEvent::Skip.
583 @remarks This function looks through the object's event table and tries
584 to find an entry that will match the event.
585 An entry will match if:
586 @li The event type matches, and
587 @li the identifier or identifier range matches, or the event table
588 entry's identifier is zero.
590 If a suitable function is called but calls wxEvent::Skip, this
591 function will fail, and searching will continue.
593 @todo this function in the header is listed as an "implementation only" function;
594 are we sure we want to document it?
598 virtual bool SearchEventTable(wxEventTable
& table
,
605 @name Connecting and disconnecting
610 Connects the given function dynamically with the event handler, id and
613 Notice that Bind() provides a more flexible and safer way to do the
614 same thing as Connect(), please use it in any new code -- while
615 Connect() is not formally deprecated due to its existing widespread
616 usage, it has no advantages compared to Bind().
618 This is an alternative to the use of static event tables. It is more
619 flexible as it allows to connect events generated by some object to an
620 event handler defined in a different object of a different class (which
621 is impossible to do directly with the event tables -- the events can be
622 only handled in another object if they are propagated upwards to it).
623 Do make sure to specify the correct @a eventSink when connecting to an
624 event of a different object.
626 See @ref overview_events_bind for more detailed explanation
627 of this function and the @ref page_samples_event sample for usage
630 This specific overload allows you to connect an event handler to a @e range
632 Do not confuse @e source IDs with event @e types: source IDs identify the
633 event generator objects (typically wxMenuItem or wxWindow objects) while the
634 event @e type identify which type of events should be handled by the
635 given @e function (an event generator object may generate many different
639 The first ID of the identifier range to be associated with the event
642 The last ID of the identifier range to be associated with the event
645 The event type to be associated with this event handler.
647 The event handler function. Note that this function should
648 be explicitly converted to the correct type which can be done using a macro
649 called @c wxFooEventHandler for the handler for any @c wxFooEvent.
651 Data to be associated with the event table entry.
653 Object whose member function should be called. It must be specified
654 when connecting an event generated by one object to a member
655 function of a different object. If it is omitted, @c this is used.
658 In wxPerl this function takes 4 arguments: @a id, @a lastid,
659 @a type, @a method; if @a method is undef, the handler is
665 void Connect(int id
, int lastId
, wxEventType eventType
,
666 wxObjectEventFunction function
,
667 wxObject
* userData
= NULL
,
668 wxEvtHandler
* eventSink
= NULL
);
671 See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*)
672 overload for more info.
674 This overload can be used to attach an event handler to a single source ID:
678 frame->Connect( wxID_EXIT,
679 wxEVT_COMMAND_MENU_SELECTED,
680 wxCommandEventHandler(MyFrame::OnQuit) );
684 Not supported by wxPerl.
687 void Connect(int id
, wxEventType eventType
,
688 wxObjectEventFunction function
,
689 wxObject
* userData
= NULL
,
690 wxEvtHandler
* eventSink
= NULL
);
693 See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*)
694 overload for more info.
696 This overload will connect the given event handler so that regardless of the
697 ID of the event source, the handler will be called.
700 Not supported by wxPerl.
703 void Connect(wxEventType eventType
,
704 wxObjectEventFunction function
,
705 wxObject
* userData
= NULL
,
706 wxEvtHandler
* eventSink
= NULL
);
709 Disconnects the given function dynamically from the event handler, using the
710 specified parameters as search criteria and returning @true if a matching
711 function has been found and removed.
713 This method can only disconnect functions which have been added using the
714 Connect() method. There is no way to disconnect functions connected using
715 the (static) event tables.
718 The event type associated with this event handler.
720 The event handler function.
722 Data associated with the event table entry.
724 Object whose member function should be called.
727 Not supported by wxPerl.
730 bool Disconnect(wxEventType eventType
,
731 wxObjectEventFunction function
,
732 wxObject
* userData
= NULL
,
733 wxEvtHandler
* eventSink
= NULL
);
736 See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*)
737 overload for more info.
739 This overload takes the additional @a id parameter.
742 Not supported by wxPerl.
745 bool Disconnect(int id
= wxID_ANY
,
746 wxEventType eventType
= wxEVT_NULL
,
747 wxObjectEventFunction function
= NULL
,
748 wxObject
* userData
= NULL
,
749 wxEvtHandler
* eventSink
= NULL
);
752 See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*)
753 overload for more info.
755 This overload takes an additional range of source IDs.
758 In wxPerl this function takes 3 arguments: @a id,
762 bool Disconnect(int id
, int lastId
,
763 wxEventType eventType
,
764 wxObjectEventFunction function
= NULL
,
765 wxObject
* userData
= NULL
,
766 wxEvtHandler
* eventSink
= NULL
);
771 @name Binding and Unbinding
776 Binds the given function, functor or method dynamically with the event.
778 This offers basically the same functionality as Connect(), but it is
779 more flexible as it also allows you to use ordinary functions and
780 arbitrary functors as event handlers. It is also less restrictive then
781 Connect() because you can use an arbitrary method as an event handler,
782 where as Connect() requires a wxEvtHandler derived handler.
784 See @ref overview_events_bind for more detailed explanation
785 of this function and the @ref page_samples_event sample for usage
789 The event type to be associated with this event handler.
791 The event handler functor. This can be an ordinary function but also
792 an arbitrary functor like boost::function<>.
794 The first ID of the identifier range to be associated with the event
797 The last ID of the identifier range to be associated with the event
800 Data to be associated with the event table entry.
802 @see @ref overview_cpp_rtti_disabled
806 template <typename EventTag
, typename Functor
>
807 void Bind(const EventTag
& eventType
,
810 int lastId
= wxID_ANY
,
811 wxObject
*userData
= NULL
);
814 See the Bind<>(const EventTag&, Functor, int, int, wxObject*) overload for
817 This overload will bind the given method as the event handler.
820 The event type to be associated with this event handler.
822 The event handler method. This can be an arbitrary method (doesn't need
823 to be from a wxEvtHandler derived class).
825 Object whose method should be called. It must always be specified
826 so it can be checked at compile time whether the given method is an
827 actual member of the given handler.
829 The first ID of the identifier range to be associated with the event
832 The last ID of the identifier range to be associated with the event
835 Data to be associated with the event table entry.
837 @see @ref overview_cpp_rtti_disabled
841 template <typename EventTag
, typename Class
, typename EventArg
, typename EventHandler
>
842 void Bind(const EventTag
&eventType
,
843 void (Class::*method
)(EventArg
&),
844 EventHandler
*handler
,
846 int lastId
= wxID_ANY
,
847 wxObject
*userData
= NULL
);
849 Unbinds the given function, functor or method dynamically from the
850 event handler, using the specified parameters as search criteria and
851 returning @true if a matching function has been found and removed.
853 This method can only unbind functions, functors or methods which have
854 been added using the Bind<>() method. There is no way to unbind
855 functions bound using the (static) event tables.
858 The event type associated with this event handler.
860 The event handler functor. This can be an ordinary function but also
861 an arbitrary functor like boost::function<>.
863 The first ID of the identifier range associated with the event
866 The last ID of the identifier range associated with the event
869 Data associated with the event table entry.
871 @see @ref overview_cpp_rtti_disabled
875 template <typename EventTag
, typename Functor
>
876 bool Unbind(const EventTag
& eventType
,
879 int lastId
= wxID_ANY
,
880 wxObject
*userData
= NULL
);
883 See the Unbind<>(const EventTag&, Functor, int, int, wxObject*)
884 overload for more info.
886 This overload unbinds the given method from the event..
889 The event type associated with this event handler.
891 The event handler method associated with this event.
893 Object whose method was called.
895 The first ID of the identifier range associated with the event
898 The last ID of the identifier range associated with the event
901 Data associated with the event table entry.
903 @see @ref overview_cpp_rtti_disabled
907 template <typename EventTag
, typename Class
, typename EventArg
, typename EventHandler
>
908 bool Unbind(const EventTag
&eventType
,
909 void (Class::*method
)(EventArg
&),
910 EventHandler
*handler
,
912 int lastId
= wxID_ANY
,
913 wxObject
*userData
= NULL
);
916 @name User-supplied data
921 Returns user-supplied client data.
923 @remarks Normally, any extra data the programmer wishes to associate with
924 the object should be made available by deriving a new class with
929 void* GetClientData() const;
932 Returns a pointer to the user-supplied client data object.
934 @see SetClientObject(), wxClientData
936 wxClientData
* GetClientObject() const;
939 Sets user-supplied client data.
942 Data to be associated with the event handler.
944 @remarks Normally, any extra data the programmer wishes to associate
945 with the object should be made available by deriving a new
946 class with new data members. You must not call this method
947 and SetClientObject on the same class - only one of them.
951 void SetClientData(void* data
);
954 Set the client data object. Any previous object will be deleted.
956 @see GetClientObject(), wxClientData
958 void SetClientObject(wxClientData
* data
);
964 @name Event handler chaining
966 wxEvtHandler can be arranged in a double-linked list of handlers
967 which is automatically iterated by ProcessEvent() if needed.
972 Returns @true if the event handler is enabled, @false otherwise.
974 @see SetEvtHandlerEnabled()
976 bool GetEvtHandlerEnabled() const;
979 Returns the pointer to the next handler in the chain.
981 @see SetNextHandler(), GetPreviousHandler(), SetPreviousHandler(),
982 wxWindow::PushEventHandler, wxWindow::PopEventHandler
984 wxEvtHandler
* GetNextHandler() const;
987 Returns the pointer to the previous handler in the chain.
989 @see SetPreviousHandler(), GetNextHandler(), SetNextHandler(),
990 wxWindow::PushEventHandler, wxWindow::PopEventHandler
992 wxEvtHandler
* GetPreviousHandler() const;
995 Enables or disables the event handler.
998 @true if the event handler is to be enabled, @false if it is to be disabled.
1000 @remarks You can use this function to avoid having to remove the event
1001 handler from the chain, for example when implementing a
1002 dialog editor and changing from edit to test mode.
1004 @see GetEvtHandlerEnabled()
1006 void SetEvtHandlerEnabled(bool enabled
);
1009 Sets the pointer to the next handler.
1012 See ProcessEvent() for more info about how the chains of event handlers
1013 are internally used.
1014 Also remember that wxEvtHandler uses double-linked lists and thus if you
1015 use this function, you should also call SetPreviousHandler() on the
1016 argument passed to this function:
1018 handlerA->SetNextHandler(handlerB);
1019 handlerB->SetPreviousHandler(handlerA);
1023 The event handler to be set as the next handler.
1026 @see @ref overview_events_processing
1028 virtual void SetNextHandler(wxEvtHandler
* handler
);
1031 Sets the pointer to the previous handler.
1032 All remarks about SetNextHandler() apply to this function as well.
1035 The event handler to be set as the previous handler.
1038 @see @ref overview_events_processing
1040 virtual void SetPreviousHandler(wxEvtHandler
* handler
);
1043 Unlinks this event handler from the chain it's part of (if any);
1044 then links the "previous" event handler to the "next" one
1045 (so that the chain won't be interrupted).
1047 E.g. if before calling Unlink() you have the following chain:
1048 @image html evthandler_unlink_before.png
1049 then after calling @c B->Unlink() you'll have:
1050 @image html evthandler_unlink_after.png
1057 Returns @true if the next and the previous handler pointers of this
1058 event handler instance are @NULL.
1062 @see SetPreviousHandler(), SetNextHandler()
1064 bool IsUnlinked() const;
1070 Method called by ProcessEvent() before examining this object event
1073 This method can be overridden to hook into the event processing logic
1074 as early as possible. You should usually call the base class version
1075 when overriding this method, even if wxEvtHandler itself does nothing
1076 here, some derived classes do use this method, e.g. wxWindow implements
1077 support for wxValidator in it.
1081 class MyClass : public BaseClass // inheriting from wxEvtHandler
1085 virtual bool TryBefore(wxEvent& event)
1087 if ( MyPreProcess(event) )
1090 return BaseClass::TryBefore(event);
1097 virtual bool TryBefore(wxEvent
& event
);
1100 Try to process the event in this event handler.
1102 This method is called from ProcessEventLocally() and thus, indirectly,
1103 from ProcessEvent(), please see the detailed description of the event
1104 processing logic there.
1106 It is currently @em not virtual and so may not be overridden.
1113 @true if this object itself defines a handler for this event and
1114 the handler didn't skip the event.
1116 bool TryThis(wxEvent
& event
);
1119 Method called by ProcessEvent() as last resort.
1121 This method can be overridden to implement post-processing for the
1122 events which were not processed anywhere else.
1124 The base class version handles forwarding the unprocessed events to
1125 wxApp at wxEvtHandler level and propagating them upwards the window
1126 child-parent chain at wxWindow level and so should usually be called
1127 when overriding this method:
1129 class MyClass : public BaseClass // inheriting from wxEvtHandler
1133 virtual bool TryAfter(wxEvent& event)
1135 if ( BaseClass::TryAfter(event) )
1138 return MyPostProcess(event);
1145 virtual bool TryAfter(wxEvent
& event
);
1150 Flags for categories of keys.
1152 These values are used by wxKeyEvent::IsKeyInCategory(). They may be
1153 combined via the bitwise operators |, &, and ~.
1157 enum wxKeyCategoryFlags
1159 /// arrow keys, on and off numeric keypads
1162 /// page up and page down keys, on and off numeric keypads
1163 WXK_CATEGORY_PAGING
,
1165 /// home and end keys, on and off numeric keypads
1168 /// tab key, on and off numeric keypads
1171 /// backspace and delete keys, on and off numeric keypads
1174 /// union of WXK_CATEGORY_ARROW, WXK_CATEGORY_PAGING, and WXK_CATEGORY_JUMP categories
1175 WXK_CATEGORY_NAVIGATION
1182 This event class contains information about key press and release events.
1184 The main information carried by this event is the key being pressed or
1185 released. It can be accessed using either GetKeyCode() function or
1186 GetUnicodeKey(). For the printable characters, the latter should be used as
1187 it works for any keys, including non-Latin-1 characters that can be entered
1188 when using national keyboard layouts. GetKeyCode() should be used to handle
1189 special characters (such as cursor arrows keys or @c HOME or @c INS and so
1190 on) which correspond to ::wxKeyCode enum elements above the @c WXK_START
1191 constant. While GetKeyCode() also returns the character code for Latin-1
1192 keys for compatibility, it doesn't work for Unicode characters in general
1193 and will return @c WXK_NONE for any non-Latin-1 ones. For this reason, it's
1194 recommended to always use GetUnicodeKey() and only fall back to GetKeyCode()
1195 if GetUnicodeKey() returned @c WXK_NONE meaning that the event corresponds
1196 to a non-printable special keys.
1198 While both of these functions can be used with the events of @c
1199 wxEVT_KEY_DOWN, @c wxEVT_KEY_UP and @c wxEVT_CHAR types, the values
1200 returned by them are different for the first two events and the last one.
1201 For the latter, the key returned corresponds to the character that would
1202 appear in e.g. a text zone if the user pressed the key in it. As such, its
1203 value depends on the current state of the Shift key and, for the letters,
1204 on the state of Caps Lock modifier. For example, if @c A key is pressed
1205 without Shift being held down, wxKeyEvent of type @c wxEVT_CHAR generated
1206 for this key press will return (from either GetKeyCode() or GetUnicodeKey()
1207 as their meanings coincide for ASCII characters) key code of 97
1208 corresponding the ASCII value of @c a. And if the same key is pressed but
1209 with Shift being held (or Caps Lock being active), then the key could would
1210 be 65, i.e. ASCII value of capital @c A.
1212 However for the key down and up events the returned key code will instead
1213 be @c A independently of the state of the modifier keys i.e. it depends
1214 only on physical key being pressed and is not translated to its logical
1215 representation using the current keyboard state. Such untranslated key
1216 codes are defined as follows:
1217 - For the letters they correspond to the @e upper case value of the
1219 - For the other alphanumeric keys (e.g. @c 7 or @c +), the untranslated
1220 key code corresponds to the character produced by the key when it is
1221 pressed without Shift. E.g. in standard US keyboard layout the
1222 untranslated key code for the key @c =/+ in the upper right corner of
1223 the keyboard is 61 which is the ASCII value of @c =.
1224 - For the rest of the keys (i.e. special non-printable keys) it is the
1225 same as the normal key code as no translation is used anyhow.
1227 Notice that the first rule applies to all Unicode letters, not just the
1228 usual Latin-1 ones. However for non-Latin-1 letters only GetUnicodeKey()
1229 can be used to retrieve the key code as GetKeyCode() just returns @c
1230 WXK_NONE in this case.
1232 To summarize: you should handle @c wxEVT_CHAR if you need the translated
1233 key and @c wxEVT_KEY_DOWN if you only need the value of the key itself,
1234 independent of the current keyboard state.
1236 @note Not all key down events may be generated by the user. As an example,
1237 @c wxEVT_KEY_DOWN with @c = key code can be generated using the
1238 standard US keyboard layout but not using the German one because the @c
1239 = key corresponds to Shift-0 key combination in this layout and the key
1240 code for it is @c 0, not @c =. Because of this you should avoid
1241 requiring your users to type key events that might be impossible to
1242 enter on their keyboard.
1245 Another difference between key and char events is that another kind of
1246 translation is done for the latter ones when the Control key is pressed:
1247 char events for ASCII letters in this case carry codes corresponding to the
1248 ASCII value of Ctrl-Latter, i.e. 1 for Ctrl-A, 2 for Ctrl-B and so on until
1249 26 for Ctrl-Z. This is convenient for terminal-like applications and can be
1250 completely ignored by all the other ones (if you need to handle Ctrl-A it
1251 is probably a better idea to use the key event rather than the char one).
1252 Notice that currently no translation is done for the presses of @c [, @c
1253 \\, @c ], @c ^ and @c _ keys which might be mapped to ASCII values from 27
1256 Finally, modifier keys only generate key events but no char events at all.
1257 The modifiers keys are @c WXK_SHIFT, @c WXK_CONTROL, @c WXK_ALT and various
1258 @c WXK_WINDOWS_XXX from ::wxKeyCode enum.
1260 Modifier keys events are special in one additional aspect: usually the
1261 keyboard state associated with a key press is well defined, e.g.
1262 wxKeyboardState::ShiftDown() returns @c true only if the Shift key was held
1263 pressed when the key that generated this event itself was pressed. There is
1264 an ambiguity for the key press events for Shift key itself however. By
1265 convention, it is considered to be already pressed when it is pressed and
1266 already released when it is released. In other words, @c wxEVT_KEY_DOWN
1267 event for the Shift key itself will have @c wxMOD_SHIFT in GetModifiers()
1268 and ShiftDown() will return true while the @c wxEVT_KEY_UP event for Shift
1269 itself will not have @c wxMOD_SHIFT in its modifiers and ShiftDown() will
1273 @b Tip: You may discover the key codes and modifiers generated by all the
1274 keys on your system interactively by running the @ref
1275 page_samples_keyboard wxWidgets sample and pressing some keys in it.
1277 @note If a key down (@c EVT_KEY_DOWN) event is caught and the event handler
1278 does not call @c event.Skip() then the corresponding char event
1279 (@c EVT_CHAR) will not happen. This is by design and enables the
1280 programs that handle both types of events to avoid processing the
1281 same key twice. As a consequence, if you do not want to suppress the
1282 @c wxEVT_CHAR events for the keys you handle, always call @c
1283 event.Skip() in your @c wxEVT_KEY_DOWN handler. Not doing may also
1284 prevent accelerators defined using this key from working.
1286 @note For Windows programmers: The key and char events in wxWidgets are
1287 similar to but slightly different from Windows @c WM_KEYDOWN and
1288 @c WM_CHAR events. In particular, Alt-x combination will generate a
1289 char event in wxWidgets (unless it is used as an accelerator) and
1290 almost all keys, including ones without ASCII equivalents, generate
1294 @beginEventTable{wxKeyEvent}
1295 @event{EVT_KEY_DOWN(func)}
1296 Process a @c wxEVT_KEY_DOWN event (any key has been pressed).
1297 @event{EVT_KEY_UP(func)}
1298 Process a @c wxEVT_KEY_UP event (any key has been released).
1299 @event{EVT_CHAR(func)}
1300 Process a @c wxEVT_CHAR event.
1303 @see wxKeyboardState
1308 class wxKeyEvent
: public wxEvent
,
1309 public wxKeyboardState
1314 Currently, the only valid event types are @c wxEVT_CHAR and @c wxEVT_CHAR_HOOK.
1316 wxKeyEvent(wxEventType keyEventType
= wxEVT_NULL
);
1319 Returns the key code of the key that generated this event.
1321 ASCII symbols return normal ASCII values, while events from special
1322 keys such as "left cursor arrow" (@c WXK_LEFT) return values outside of
1323 the ASCII range. See ::wxKeyCode for a full list of the virtual key
1326 Note that this method returns a meaningful value only for special
1327 non-alphanumeric keys or if the user entered a character that can be
1328 represented in current locale's default charset. Otherwise, e.g. if the
1329 user enters a Japanese character in a program not using Japanese
1330 locale, this method returns @c WXK_NONE and GetUnicodeKey() should be
1331 used to obtain the corresponding Unicode character.
1333 Using GetUnicodeKey() is in general the right thing to do if you are
1334 interested in the characters typed by the user, GetKeyCode() should be
1335 only used for special keys (for which GetUnicodeKey() returns @c
1336 WXK_NONE). To handle both kinds of keys you might write:
1338 void MyHandler::OnChar(wxKeyEvent& event)
1340 if ( event.GetUnicodeKey() != WXK_NONE )
1342 // It's a printable character
1343 wxLogMessage("You pressed '%c'", event.GetUnicodeKey());
1347 // It's a special key, deal with all the known ones:
1363 int GetKeyCode() const;
1366 Returns true if the key is in the given key category.
1369 A bitwise combination of named ::wxKeyCategoryFlags constants.
1373 bool IsKeyInCategory(int category
) const;
1377 Obtains the position (in client coordinates) at which the key was pressed.
1379 wxPoint
GetPosition() const;
1380 void GetPosition(long* x
, long* y
) const;
1384 Returns the raw key code for this event. This is a platform-dependent scan code
1385 which should only be used in advanced applications.
1387 @note Currently the raw key codes are not supported by all ports, use
1388 @ifdef_ wxHAS_RAW_KEY_CODES to determine if this feature is available.
1390 wxUint32
GetRawKeyCode() const;
1393 Returns the low level key flags for this event. The flags are
1394 platform-dependent and should only be used in advanced applications.
1396 @note Currently the raw key flags are not supported by all ports, use
1397 @ifdef_ wxHAS_RAW_KEY_CODES to determine if this feature is available.
1399 wxUint32
GetRawKeyFlags() const;
1402 Returns the Unicode character corresponding to this key event.
1404 If the key pressed doesn't have any character value (e.g. a cursor key)
1405 this method will return @c WXK_NONE. In this case you should use
1406 GetKeyCode() to retrieve the value of the key.
1408 This function is only available in Unicode build, i.e. when
1409 @c wxUSE_UNICODE is 1.
1411 wxChar
GetUnicodeKey() const;
1414 Returns the X position (in client coordinates) of the event.
1416 wxCoord
GetX() const;
1419 Returns the Y position (in client coordinates) of the event.
1421 wxCoord
GetY() const;
1427 @class wxJoystickEvent
1429 This event class contains information about joystick events, particularly
1430 events received by windows.
1432 @beginEventTable{wxJoystickEvent}
1433 @event{EVT_JOY_BUTTON_DOWN(func)}
1434 Process a @c wxEVT_JOY_BUTTON_DOWN event.
1435 @event{EVT_JOY_BUTTON_UP(func)}
1436 Process a @c wxEVT_JOY_BUTTON_UP event.
1437 @event{EVT_JOY_MOVE(func)}
1438 Process a @c wxEVT_JOY_MOVE event.
1439 @event{EVT_JOY_ZMOVE(func)}
1440 Process a @c wxEVT_JOY_ZMOVE event.
1441 @event{EVT_JOYSTICK_EVENTS(func)}
1442 Processes all joystick events.
1450 class wxJoystickEvent
: public wxEvent
1456 wxJoystickEvent(wxEventType eventType
= wxEVT_NULL
, int state
= 0,
1457 int joystick
= wxJOYSTICK1
,
1461 Returns @true if the event was a down event from the specified button
1465 Can be @c wxJOY_BUTTONn where @c n is 1, 2, 3 or 4; or @c wxJOY_BUTTON_ANY to
1466 indicate any button down event.
1468 bool ButtonDown(int button
= wxJOY_BUTTON_ANY
) const;
1471 Returns @true if the specified button (or any button) was in a down state.
1474 Can be @c wxJOY_BUTTONn where @c n is 1, 2, 3 or 4; or @c wxJOY_BUTTON_ANY to
1475 indicate any button down event.
1477 bool ButtonIsDown(int button
= wxJOY_BUTTON_ANY
) const;
1480 Returns @true if the event was an up event from the specified button
1484 Can be @c wxJOY_BUTTONn where @c n is 1, 2, 3 or 4; or @c wxJOY_BUTTON_ANY to
1485 indicate any button down event.
1487 bool ButtonUp(int button
= wxJOY_BUTTON_ANY
) const;
1490 Returns the identifier of the button changing state.
1492 This is a @c wxJOY_BUTTONn identifier, where @c n is one of 1, 2, 3, 4.
1494 int GetButtonChange() const;
1497 Returns the down state of the buttons.
1499 This is a @c wxJOY_BUTTONn identifier, where @c n is one of 1, 2, 3, 4.
1501 int GetButtonState() const;
1504 Returns the identifier of the joystick generating the event - one of
1505 wxJOYSTICK1 and wxJOYSTICK2.
1507 int GetJoystick() const;
1510 Returns the x, y position of the joystick event.
1512 wxPoint
GetPosition() const;
1515 Returns the z position of the joystick event.
1517 int GetZPosition() const;
1520 Returns @true if this was a button up or down event
1521 (@e not 'is any button down?').
1523 bool IsButton() const;
1526 Returns @true if this was an x, y move event.
1528 bool IsMove() const;
1531 Returns @true if this was a z move event.
1533 bool IsZMove() const;
1539 @class wxScrollWinEvent
1541 A scroll event holds information about events sent from scrolling windows.
1543 Note that you can use the EVT_SCROLLWIN* macros for intercepting scroll window events
1544 from the receiving window.
1546 @beginEventTable{wxScrollWinEvent}
1547 @event{EVT_SCROLLWIN(func)}
1548 Process all scroll events.
1549 @event{EVT_SCROLLWIN_TOP(func)}
1550 Process wxEVT_SCROLLWIN_TOP scroll-to-top events.
1551 @event{EVT_SCROLLWIN_BOTTOM(func)}
1552 Process wxEVT_SCROLLWIN_BOTTOM scroll-to-bottom events.
1553 @event{EVT_SCROLLWIN_LINEUP(func)}
1554 Process wxEVT_SCROLLWIN_LINEUP line up events.
1555 @event{EVT_SCROLLWIN_LINEDOWN(func)}
1556 Process wxEVT_SCROLLWIN_LINEDOWN line down events.
1557 @event{EVT_SCROLLWIN_PAGEUP(func)}
1558 Process wxEVT_SCROLLWIN_PAGEUP page up events.
1559 @event{EVT_SCROLLWIN_PAGEDOWN(func)}
1560 Process wxEVT_SCROLLWIN_PAGEDOWN page down events.
1561 @event{EVT_SCROLLWIN_THUMBTRACK(func)}
1562 Process wxEVT_SCROLLWIN_THUMBTRACK thumbtrack events
1563 (frequent events sent as the user drags the thumbtrack).
1564 @event{EVT_SCROLLWIN_THUMBRELEASE(func)}
1565 Process wxEVT_SCROLLWIN_THUMBRELEASE thumb release events.
1572 @see wxScrollEvent, @ref overview_events
1574 class wxScrollWinEvent
: public wxEvent
1580 wxScrollWinEvent(wxEventType commandType
= wxEVT_NULL
, int pos
= 0,
1581 int orientation
= 0);
1584 Returns wxHORIZONTAL or wxVERTICAL, depending on the orientation of the
1587 @todo wxHORIZONTAL and wxVERTICAL should go in their own enum
1589 int GetOrientation() const;
1592 Returns the position of the scrollbar for the thumb track and release events.
1594 Note that this field can't be used for the other events, you need to query
1595 the window itself for the current position in that case.
1597 int GetPosition() const;
1603 @class wxSysColourChangedEvent
1605 This class is used for system colour change events, which are generated
1606 when the user changes the colour settings using the control panel.
1607 This is only appropriate under Windows.
1610 The default event handler for this event propagates the event to child windows,
1611 since Windows only sends the events to top-level windows.
1612 If intercepting this event for a top-level window, remember to call the base
1613 class handler, or to pass the event on to the window's children explicitly.
1615 @beginEventTable{wxSysColourChangedEvent}
1616 @event{EVT_SYS_COLOUR_CHANGED(func)}
1617 Process a @c wxEVT_SYS_COLOUR_CHANGED event.
1623 @see @ref overview_events
1625 class wxSysColourChangedEvent
: public wxEvent
1631 wxSysColourChangedEvent();
1637 @class wxWindowCreateEvent
1639 This event is sent just after the actual window associated with a wxWindow
1640 object has been created.
1642 Since it is derived from wxCommandEvent, the event propagates up
1643 the window hierarchy.
1645 @beginEventTable{wxWindowCreateEvent}
1646 @event{EVT_WINDOW_CREATE(func)}
1647 Process a @c wxEVT_CREATE event.
1653 @see @ref overview_events, wxWindowDestroyEvent
1655 class wxWindowCreateEvent
: public wxCommandEvent
1661 wxWindowCreateEvent(wxWindow
* win
= NULL
);
1663 /// Retutn the window being created.
1664 wxWindow
*GetWindow() const;
1672 A paint event is sent when a window's contents needs to be repainted.
1674 The handler of this event must create a wxPaintDC object and use it for
1675 painting the window contents. For example:
1677 void MyWindow::OnPaint(wxPaintEvent& event)
1685 Notice that you must @e not create other kinds of wxDC (e.g. wxClientDC or
1686 wxWindowDC) in EVT_PAINT handlers and also don't create wxPaintDC outside
1687 of this event handlers.
1690 You can optimize painting by retrieving the rectangles that have been damaged
1691 and only repainting these. The rectangles are in terms of the client area,
1692 and are unscrolled, so you will need to do some calculations using the current
1693 view position to obtain logical, scrolled units.
1694 Here is an example of using the wxRegionIterator class:
1696 // Called when window needs to be repainted.
1697 void MyWindow::OnPaint(wxPaintEvent& event)
1701 // Find Out where the window is scrolled to
1702 int vbX,vbY; // Top left corner of client
1703 GetViewStart(&vbX,&vbY);
1705 int vX,vY,vW,vH; // Dimensions of client area in pixels
1706 wxRegionIterator upd(GetUpdateRegion()); // get the update rect list
1715 // Alternatively we can do this:
1716 // wxRect rect(upd.GetRect());
1718 // Repaint this rectangle
1727 Please notice that in general it is impossible to change the drawing of a
1728 standard control (such as wxButton) and so you shouldn't attempt to handle
1729 paint events for them as even if it might work on some platforms, this is
1730 inherently not portable and won't work everywhere.
1733 @beginEventTable{wxPaintEvent}
1734 @event{EVT_PAINT(func)}
1735 Process a @c wxEVT_PAINT event.
1741 @see @ref overview_events
1743 class wxPaintEvent
: public wxEvent
1749 wxPaintEvent(int id
= 0);
1755 @class wxMaximizeEvent
1757 An event being sent when a top level window is maximized. Notice that it is
1758 not sent when the window is restored to its original size after it had been
1759 maximized, only a normal wxSizeEvent is generated in this case.
1761 @beginEventTable{wxMaximizeEvent}
1762 @event{EVT_MAXIMIZE(func)}
1763 Process a @c wxEVT_MAXIMIZE event.
1769 @see @ref overview_events, wxTopLevelWindow::Maximize,
1770 wxTopLevelWindow::IsMaximized
1772 class wxMaximizeEvent
: public wxEvent
1776 Constructor. Only used by wxWidgets internally.
1778 wxMaximizeEvent(int id
= 0);
1782 The possibles modes to pass to wxUpdateUIEvent::SetMode().
1786 /** Send UI update events to all windows. */
1787 wxUPDATE_UI_PROCESS_ALL
,
1789 /** Send UI update events to windows that have
1790 the wxWS_EX_PROCESS_UI_UPDATES flag specified. */
1791 wxUPDATE_UI_PROCESS_SPECIFIED
1796 @class wxUpdateUIEvent
1798 This class is used for pseudo-events which are called by wxWidgets
1799 to give an application the chance to update various user interface elements.
1801 Without update UI events, an application has to work hard to check/uncheck,
1802 enable/disable, show/hide, and set the text for elements such as menu items
1803 and toolbar buttons. The code for doing this has to be mixed up with the code
1804 that is invoked when an action is invoked for a menu item or button.
1806 With update UI events, you define an event handler to look at the state of the
1807 application and change UI elements accordingly. wxWidgets will call your member
1808 functions in idle time, so you don't have to worry where to call this code.
1810 In addition to being a clearer and more declarative method, it also means you don't
1811 have to worry whether you're updating a toolbar or menubar identifier. The same
1812 handler can update a menu item and toolbar button, if the identifier is the same.
1813 Instead of directly manipulating the menu or button, you call functions in the event
1814 object, such as wxUpdateUIEvent::Check. wxWidgets will determine whether such a
1815 call has been made, and which UI element to update.
1817 These events will work for popup menus as well as menubars. Just before a menu is
1818 popped up, wxMenu::UpdateUI is called to process any UI events for the window that
1821 If you find that the overhead of UI update processing is affecting your application,
1822 you can do one or both of the following:
1823 @li Call wxUpdateUIEvent::SetMode with a value of wxUPDATE_UI_PROCESS_SPECIFIED,
1824 and set the extra style wxWS_EX_PROCESS_UI_UPDATES for every window that should
1825 receive update events. No other windows will receive update events.
1826 @li Call wxUpdateUIEvent::SetUpdateInterval with a millisecond value to set the delay
1827 between updates. You may need to call wxWindow::UpdateWindowUI at critical points,
1828 for example when a dialog is about to be shown, in case the user sees a slight
1829 delay before windows are updated.
1831 Note that although events are sent in idle time, defining a wxIdleEvent handler
1832 for a window does not affect this because the events are sent from wxWindow::OnInternalIdle
1833 which is always called in idle time.
1835 wxWidgets tries to optimize update events on some platforms.
1836 On Windows and GTK+, events for menubar items are only sent when the menu is about
1837 to be shown, and not in idle time.
1840 @beginEventTable{wxUpdateUIEvent}
1841 @event{EVT_UPDATE_UI(id, func)}
1842 Process a @c wxEVT_UPDATE_UI event for the command with the given id.
1843 @event{EVT_UPDATE_UI_RANGE(id1, id2, func)}
1844 Process a @c wxEVT_UPDATE_UI event for any command with id included in the given range.
1850 @see @ref overview_events
1852 class wxUpdateUIEvent
: public wxCommandEvent
1858 wxUpdateUIEvent(wxWindowID commandId
= 0);
1861 Returns @true if it is appropriate to update (send UI update events to)
1864 This function looks at the mode used (see wxUpdateUIEvent::SetMode),
1865 the wxWS_EX_PROCESS_UI_UPDATES flag in @a window, the time update events
1866 were last sent in idle time, and the update interval, to determine whether
1867 events should be sent to this window now. By default this will always
1868 return @true because the update mode is initially wxUPDATE_UI_PROCESS_ALL
1869 and the interval is set to 0; so update events will be sent as often as
1870 possible. You can reduce the frequency that events are sent by changing the
1871 mode and/or setting an update interval.
1873 @see ResetUpdateTime(), SetUpdateInterval(), SetMode()
1875 static bool CanUpdate(wxWindow
* window
);
1878 Check or uncheck the UI element.
1880 void Check(bool check
);
1883 Enable or disable the UI element.
1885 void Enable(bool enable
);
1888 Returns @true if the UI element should be checked.
1890 bool GetChecked() const;
1893 Returns @true if the UI element should be enabled.
1895 bool GetEnabled() const;
1898 Static function returning a value specifying how wxWidgets will send update
1899 events: to all windows, or only to those which specify that they will process
1904 static wxUpdateUIMode
GetMode();
1907 Returns @true if the application has called Check().
1908 For wxWidgets internal use only.
1910 bool GetSetChecked() const;
1913 Returns @true if the application has called Enable().
1914 For wxWidgets internal use only.
1916 bool GetSetEnabled() const;
1919 Returns @true if the application has called Show().
1920 For wxWidgets internal use only.
1922 bool GetSetShown() const;
1925 Returns @true if the application has called SetText().
1926 For wxWidgets internal use only.
1928 bool GetSetText() const;
1931 Returns @true if the UI element should be shown.
1933 bool GetShown() const;
1936 Returns the text that should be set for the UI element.
1938 wxString
GetText() const;
1941 Returns the current interval between updates in milliseconds.
1942 The value -1 disables updates, 0 updates as frequently as possible.
1944 @see SetUpdateInterval().
1946 static long GetUpdateInterval();
1949 Used internally to reset the last-updated time to the current time.
1951 It is assumed that update events are normally sent in idle time, so this
1952 is called at the end of idle processing.
1954 @see CanUpdate(), SetUpdateInterval(), SetMode()
1956 static void ResetUpdateTime();
1959 Specify how wxWidgets will send update events: to all windows, or only to
1960 those which specify that they will process the events.
1963 this parameter may be one of the ::wxUpdateUIMode enumeration values.
1964 The default mode is wxUPDATE_UI_PROCESS_ALL.
1966 static void SetMode(wxUpdateUIMode mode
);
1969 Sets the text for this UI element.
1971 void SetText(const wxString
& text
);
1974 Sets the interval between updates in milliseconds.
1976 Set to -1 to disable updates, or to 0 to update as frequently as possible.
1979 Use this to reduce the overhead of UI update events if your application
1980 has a lot of windows. If you set the value to -1 or greater than 0,
1981 you may also need to call wxWindow::UpdateWindowUI at appropriate points
1982 in your application, such as when a dialog is about to be shown.
1984 static void SetUpdateInterval(long updateInterval
);
1987 Show or hide the UI element.
1989 void Show(bool show
);
1995 @class wxClipboardTextEvent
1997 This class represents the events generated by a control (typically a
1998 wxTextCtrl but other windows can generate these events as well) when its
1999 content gets copied or cut to, or pasted from the clipboard.
2001 There are three types of corresponding events wxEVT_COMMAND_TEXT_COPY,
2002 wxEVT_COMMAND_TEXT_CUT and wxEVT_COMMAND_TEXT_PASTE.
2004 If any of these events is processed (without being skipped) by an event
2005 handler, the corresponding operation doesn't take place which allows to
2006 prevent the text from being copied from or pasted to a control. It is also
2007 possible to examine the clipboard contents in the PASTE event handler and
2008 transform it in some way before inserting in a control -- for example,
2009 changing its case or removing invalid characters.
2011 Finally notice that a CUT event is always preceded by the COPY event which
2012 makes it possible to only process the latter if it doesn't matter if the
2013 text was copied or cut.
2016 These events are currently only generated by wxTextCtrl under GTK+.
2017 They are generated by all controls under Windows.
2019 @beginEventTable{wxClipboardTextEvent}
2020 @event{EVT_TEXT_COPY(id, func)}
2021 Some or all of the controls content was copied to the clipboard.
2022 @event{EVT_TEXT_CUT(id, func)}
2023 Some or all of the controls content was cut (i.e. copied and
2025 @event{EVT_TEXT_PASTE(id, func)}
2026 Clipboard content was pasted into the control.
2035 class wxClipboardTextEvent
: public wxCommandEvent
2041 wxClipboardTextEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0);
2049 This event class contains information about the events generated by the mouse:
2050 they include mouse buttons press and release events and mouse move events.
2052 All mouse events involving the buttons use @c wxMOUSE_BTN_LEFT for the
2053 left mouse button, @c wxMOUSE_BTN_MIDDLE for the middle one and
2054 @c wxMOUSE_BTN_RIGHT for the right one. And if the system supports more
2055 buttons, the @c wxMOUSE_BTN_AUX1 and @c wxMOUSE_BTN_AUX2 events
2056 can also be generated. Note that not all mice have even a middle button so a
2057 portable application should avoid relying on the events from it (but the right
2058 button click can be emulated using the left mouse button with the control key
2059 under Mac platforms with a single button mouse).
2061 For the @c wxEVT_ENTER_WINDOW and @c wxEVT_LEAVE_WINDOW events
2062 purposes, the mouse is considered to be inside the window if it is in the
2063 window client area and not inside one of its children. In other words, the
2064 parent window receives @c wxEVT_LEAVE_WINDOW event not only when the
2065 mouse leaves the window entirely but also when it enters one of its children.
2067 The position associated with a mouse event is expressed in the window
2068 coordinates of the window which generated the event, you can use
2069 wxWindow::ClientToScreen() to convert it to screen coordinates and possibly
2070 call wxWindow::ScreenToClient() next to convert it to window coordinates of
2073 @note Note that under Windows CE mouse enter and leave events are not natively
2074 supported by the system but are generated by wxWidgets itself. This has several
2075 drawbacks: the LEAVE_WINDOW event might be received some time after the mouse
2076 left the window and the state variables for it may have changed during this time.
2078 @note Note the difference between methods like wxMouseEvent::LeftDown and
2079 the inherited wxMouseState::LeftIsDown: the former returns @true when
2080 the event corresponds to the left mouse button click while the latter
2081 returns @true if the left mouse button is currently being pressed.
2082 For example, when the user is dragging the mouse you can use
2083 wxMouseEvent::LeftIsDown to test whether the left mouse button is
2084 (still) depressed. Also, by convention, if wxMouseEvent::LeftDown
2085 returns @true, wxMouseEvent::LeftIsDown will also return @true in
2086 wxWidgets whatever the underlying GUI behaviour is (which is
2087 platform-dependent). The same applies, of course, to other mouse
2091 @beginEventTable{wxMouseEvent}
2092 @event{EVT_LEFT_DOWN(func)}
2093 Process a @c wxEVT_LEFT_DOWN event. The handler of this event should normally
2094 call event.Skip() to allow the default processing to take place as otherwise
2095 the window under mouse wouldn't get the focus.
2096 @event{EVT_LEFT_UP(func)}
2097 Process a @c wxEVT_LEFT_UP event.
2098 @event{EVT_LEFT_DCLICK(func)}
2099 Process a @c wxEVT_LEFT_DCLICK event.
2100 @event{EVT_MIDDLE_DOWN(func)}
2101 Process a @c wxEVT_MIDDLE_DOWN event.
2102 @event{EVT_MIDDLE_UP(func)}
2103 Process a @c wxEVT_MIDDLE_UP event.
2104 @event{EVT_MIDDLE_DCLICK(func)}
2105 Process a @c wxEVT_MIDDLE_DCLICK event.
2106 @event{EVT_RIGHT_DOWN(func)}
2107 Process a @c wxEVT_RIGHT_DOWN event.
2108 @event{EVT_RIGHT_UP(func)}
2109 Process a @c wxEVT_RIGHT_UP event.
2110 @event{EVT_RIGHT_DCLICK(func)}
2111 Process a @c wxEVT_RIGHT_DCLICK event.
2112 @event{EVT_MOUSE_AUX1_DOWN(func)}
2113 Process a @c wxEVT_AUX1_DOWN event.
2114 @event{EVT_MOUSE_AUX1_UP(func)}
2115 Process a @c wxEVT_AUX1_UP event.
2116 @event{EVT_MOUSE_AUX1_DCLICK(func)}
2117 Process a @c wxEVT_AUX1_DCLICK event.
2118 @event{EVT_MOUSE_AUX2_DOWN(func)}
2119 Process a @c wxEVT_AUX2_DOWN event.
2120 @event{EVT_MOUSE_AUX2_UP(func)}
2121 Process a @c wxEVT_AUX2_UP event.
2122 @event{EVT_MOUSE_AUX2_DCLICK(func)}
2123 Process a @c wxEVT_AUX2_DCLICK event.
2124 @event{EVT_MOTION(func)}
2125 Process a @c wxEVT_MOTION event.
2126 @event{EVT_ENTER_WINDOW(func)}
2127 Process a @c wxEVT_ENTER_WINDOW event.
2128 @event{EVT_LEAVE_WINDOW(func)}
2129 Process a @c wxEVT_LEAVE_WINDOW event.
2130 @event{EVT_MOUSEWHEEL(func)}
2131 Process a @c wxEVT_MOUSEWHEEL event.
2132 @event{EVT_MOUSE_EVENTS(func)}
2133 Process all mouse events.
2141 class wxMouseEvent
: public wxEvent
,
2146 Constructor. Valid event types are:
2148 @li wxEVT_ENTER_WINDOW
2149 @li wxEVT_LEAVE_WINDOW
2152 @li wxEVT_LEFT_DCLICK
2153 @li wxEVT_MIDDLE_DOWN
2155 @li wxEVT_MIDDLE_DCLICK
2156 @li wxEVT_RIGHT_DOWN
2158 @li wxEVT_RIGHT_DCLICK
2159 @li wxEVT_MOUSE_AUX1_DOWN
2160 @li wxEVT_MOUSE_AUX1_UP
2161 @li wxEVT_MOUSE_AUX1_DCLICK
2162 @li wxEVT_MOUSE_AUX2_DOWN
2163 @li wxEVT_MOUSE_AUX2_UP
2164 @li wxEVT_MOUSE_AUX2_DCLICK
2166 @li wxEVT_MOUSEWHEEL
2168 wxMouseEvent(wxEventType mouseEventType
= wxEVT_NULL
);
2171 Returns @true if the event was a first extra button double click.
2173 bool Aux1DClick() const;
2176 Returns @true if the first extra button mouse button changed to down.
2178 bool Aux1Down() const;
2181 Returns @true if the first extra button mouse button changed to up.
2183 bool Aux1Up() const;
2186 Returns @true if the event was a second extra button double click.
2188 bool Aux2DClick() const;
2191 Returns @true if the second extra button mouse button changed to down.
2193 bool Aux2Down() const;
2196 Returns @true if the second extra button mouse button changed to up.
2198 bool Aux2Up() const;
2201 Returns @true if the event was generated by the specified button.
2203 @see wxMouseState::ButtoinIsDown()
2205 bool Button(wxMouseButton but
) const;
2208 If the argument is omitted, this returns @true if the event was a mouse
2209 double click event. Otherwise the argument specifies which double click event
2210 was generated (see Button() for the possible values).
2212 bool ButtonDClick(wxMouseButton but
= wxMOUSE_BTN_ANY
) const;
2215 If the argument is omitted, this returns @true if the event was a mouse
2216 button down event. Otherwise the argument specifies which button-down event
2217 was generated (see Button() for the possible values).
2219 bool ButtonDown(wxMouseButton but
= wxMOUSE_BTN_ANY
) const;
2222 If the argument is omitted, this returns @true if the event was a mouse
2223 button up event. Otherwise the argument specifies which button-up event
2224 was generated (see Button() for the possible values).
2226 bool ButtonUp(wxMouseButton but
= wxMOUSE_BTN_ANY
) const;
2229 Returns @true if this was a dragging event (motion while a button is depressed).
2233 bool Dragging() const;
2236 Returns @true if the mouse was entering the window.
2240 bool Entering() const;
2243 Returns the mouse button which generated this event or @c wxMOUSE_BTN_NONE
2244 if no button is involved (for mouse move, enter or leave event, for example).
2245 Otherwise @c wxMOUSE_BTN_LEFT is returned for the left button down, up and
2246 double click events, @c wxMOUSE_BTN_MIDDLE and @c wxMOUSE_BTN_RIGHT
2247 for the same events for the middle and the right buttons respectively.
2249 int GetButton() const;
2252 Returns the number of mouse clicks for this event: 1 for a simple click, 2
2253 for a double-click, 3 for a triple-click and so on.
2255 Currently this function is implemented only in wxMac and returns -1 for the
2256 other platforms (you can still distinguish simple clicks from double-clicks as
2257 they generate different kinds of events however).
2261 int GetClickCount() const;
2264 Returns the configured number of lines (or whatever) to be scrolled per
2265 wheel action. Defaults to three.
2267 int GetLinesPerAction() const;
2270 Returns the logical mouse position in pixels (i.e. translated according to the
2271 translation set for the DC, which usually indicates that the window has been
2274 wxPoint
GetLogicalPosition(const wxDC
& dc
) const;
2277 Get wheel delta, normally 120.
2279 This is the threshold for action to be taken, and one such action
2280 (for example, scrolling one increment) should occur for each delta.
2282 int GetWheelDelta() const;
2285 Get wheel rotation, positive or negative indicates direction of rotation.
2287 Current devices all send an event when rotation is at least +/-WheelDelta, but
2288 finer resolution devices can be created in the future.
2290 Because of this you shouldn't assume that one event is equal to 1 line, but you
2291 should be able to either do partial line scrolling or wait until several
2292 events accumulate before scrolling.
2294 int GetWheelRotation() const;
2297 Gets the axis the wheel operation concerns; @c 0 is the Y axis as on
2298 most mouse wheels, @c 1 is the X axis.
2300 Note that only some models of mouse have horizontal wheel axis.
2302 int GetWheelAxis() const;
2305 Returns @true if the event was a mouse button event (not necessarily a button
2306 down event - that may be tested using ButtonDown()).
2308 bool IsButton() const;
2311 Returns @true if the system has been setup to do page scrolling with
2312 the mouse wheel instead of line scrolling.
2314 bool IsPageScroll() const;
2317 Returns @true if the mouse was leaving the window.
2321 bool Leaving() const;
2324 Returns @true if the event was a left double click.
2326 bool LeftDClick() const;
2329 Returns @true if the left mouse button changed to down.
2331 bool LeftDown() const;
2334 Returns @true if the left mouse button changed to up.
2336 bool LeftUp() const;
2339 Returns @true if the Meta key was down at the time of the event.
2341 bool MetaDown() const;
2344 Returns @true if the event was a middle double click.
2346 bool MiddleDClick() const;
2349 Returns @true if the middle mouse button changed to down.
2351 bool MiddleDown() const;
2354 Returns @true if the middle mouse button changed to up.
2356 bool MiddleUp() const;
2359 Returns @true if this was a motion event and no mouse buttons were pressed.
2360 If any mouse button is held pressed, then this method returns @false and
2361 Dragging() returns @true.
2363 bool Moving() const;
2366 Returns @true if the event was a right double click.
2368 bool RightDClick() const;
2371 Returns @true if the right mouse button changed to down.
2373 bool RightDown() const;
2376 Returns @true if the right mouse button changed to up.
2378 bool RightUp() const;
2384 @class wxDropFilesEvent
2386 This class is used for drop files events, that is, when files have been dropped
2387 onto the window. This functionality is currently only available under Windows.
2389 The window must have previously been enabled for dropping by calling
2390 wxWindow::DragAcceptFiles().
2392 Important note: this is a separate implementation to the more general drag and drop
2393 implementation documented in the @ref overview_dnd. It uses the older, Windows
2394 message-based approach of dropping files.
2396 @beginEventTable{wxDropFilesEvent}
2397 @event{EVT_DROP_FILES(func)}
2398 Process a @c wxEVT_DROP_FILES event.
2406 @see @ref overview_events
2408 class wxDropFilesEvent
: public wxEvent
2414 wxDropFilesEvent(wxEventType id
= 0, int noFiles
= 0,
2415 wxString
* files
= NULL
);
2418 Returns an array of filenames.
2420 wxString
* GetFiles() const;
2423 Returns the number of files dropped.
2425 int GetNumberOfFiles() const;
2428 Returns the position at which the files were dropped.
2429 Returns an array of filenames.
2431 wxPoint
GetPosition() const;
2437 @class wxCommandEvent
2439 This event class contains information about command events, which originate
2440 from a variety of simple controls.
2442 Note that wxCommandEvents and wxCommandEvent-derived event classes by default
2443 and unlike other wxEvent-derived classes propagate upward from the source
2444 window (the window which emits the event) up to the first parent which processes
2445 the event. Be sure to read @ref overview_events_propagation.
2447 More complex controls, such as wxTreeCtrl, have separate command event classes.
2449 @beginEventTable{wxCommandEvent}
2450 @event{EVT_COMMAND(id, event, func)}
2451 Process a command, supplying the window identifier, command event identifier,
2452 and member function.
2453 @event{EVT_COMMAND_RANGE(id1, id2, event, func)}
2454 Process a command for a range of window identifiers, supplying the minimum and
2455 maximum window identifiers, command event identifier, and member function.
2456 @event{EVT_BUTTON(id, func)}
2457 Process a @c wxEVT_COMMAND_BUTTON_CLICKED command, which is generated by a wxButton control.
2458 @event{EVT_CHECKBOX(id, func)}
2459 Process a @c wxEVT_COMMAND_CHECKBOX_CLICKED command, which is generated by a wxCheckBox control.
2460 @event{EVT_CHOICE(id, func)}
2461 Process a @c wxEVT_COMMAND_CHOICE_SELECTED command, which is generated by a wxChoice control.
2462 @event{EVT_COMBOBOX(id, func)}
2463 Process a @c wxEVT_COMMAND_COMBOBOX_SELECTED command, which is generated by a wxComboBox control.
2464 @event{EVT_LISTBOX(id, func)}
2465 Process a @c wxEVT_COMMAND_LISTBOX_SELECTED command, which is generated by a wxListBox control.
2466 @event{EVT_LISTBOX_DCLICK(id, func)}
2467 Process a @c wxEVT_COMMAND_LISTBOX_DOUBLECLICKED command, which is generated by a wxListBox control.
2468 @event{EVT_CHECKLISTBOX(id, func)}
2469 Process a @c wxEVT_COMMAND_CHECKLISTBOX_TOGGLED command, which is generated by a wxCheckListBox control.
2470 @event{EVT_MENU(id, func)}
2471 Process a @c wxEVT_COMMAND_MENU_SELECTED command, which is generated by a menu item.
2472 @event{EVT_MENU_RANGE(id1, id2, func)}
2473 Process a @c wxEVT_COMMAND_MENU_RANGE command, which is generated by a range of menu items.
2474 @event{EVT_CONTEXT_MENU(func)}
2475 Process the event generated when the user has requested a popup menu to appear by
2476 pressing a special keyboard key (under Windows) or by right clicking the mouse.
2477 @event{EVT_RADIOBOX(id, func)}
2478 Process a @c wxEVT_COMMAND_RADIOBOX_SELECTED command, which is generated by a wxRadioBox control.
2479 @event{EVT_RADIOBUTTON(id, func)}
2480 Process a @c wxEVT_COMMAND_RADIOBUTTON_SELECTED command, which is generated by a wxRadioButton control.
2481 @event{EVT_SCROLLBAR(id, func)}
2482 Process a @c wxEVT_COMMAND_SCROLLBAR_UPDATED command, which is generated by a wxScrollBar
2483 control. This is provided for compatibility only; more specific scrollbar event macros
2484 should be used instead (see wxScrollEvent).
2485 @event{EVT_SLIDER(id, func)}
2486 Process a @c wxEVT_COMMAND_SLIDER_UPDATED command, which is generated by a wxSlider control.
2487 @event{EVT_TEXT(id, func)}
2488 Process a @c wxEVT_COMMAND_TEXT_UPDATED command, which is generated by a wxTextCtrl control.
2489 @event{EVT_TEXT_ENTER(id, func)}
2490 Process a @c wxEVT_COMMAND_TEXT_ENTER command, which is generated by a wxTextCtrl control.
2491 Note that you must use wxTE_PROCESS_ENTER flag when creating the control if you want it
2492 to generate such events.
2493 @event{EVT_TEXT_MAXLEN(id, func)}
2494 Process a @c wxEVT_COMMAND_TEXT_MAXLEN command, which is generated by a wxTextCtrl control
2495 when the user tries to enter more characters into it than the limit previously set
2496 with SetMaxLength().
2497 @event{EVT_TOGGLEBUTTON(id, func)}
2498 Process a @c wxEVT_COMMAND_TOGGLEBUTTON_CLICKED event.
2499 @event{EVT_TOOL(id, func)}
2500 Process a @c wxEVT_COMMAND_TOOL_CLICKED event (a synonym for @c wxEVT_COMMAND_MENU_SELECTED).
2501 Pass the id of the tool.
2502 @event{EVT_TOOL_RANGE(id1, id2, func)}
2503 Process a @c wxEVT_COMMAND_TOOL_CLICKED event for a range of identifiers. Pass the ids of the tools.
2504 @event{EVT_TOOL_RCLICKED(id, func)}
2505 Process a @c wxEVT_COMMAND_TOOL_RCLICKED event. Pass the id of the tool. (Not available on wxOSX.)
2506 @event{EVT_TOOL_RCLICKED_RANGE(id1, id2, func)}
2507 Process a @c wxEVT_COMMAND_TOOL_RCLICKED event for a range of ids. Pass the ids of the tools. (Not available on wxOSX.)
2508 @event{EVT_TOOL_ENTER(id, func)}
2509 Process a @c wxEVT_COMMAND_TOOL_ENTER event. Pass the id of the toolbar itself.
2510 The value of wxCommandEvent::GetSelection() is the tool id, or -1 if the mouse cursor
2511 has moved off a tool. (Not available on wxOSX.)
2512 @event{EVT_COMMAND_LEFT_CLICK(id, func)}
2513 Process a @c wxEVT_COMMAND_LEFT_CLICK command, which is generated by a control (wxMSW only).
2514 @event{EVT_COMMAND_LEFT_DCLICK(id, func)}
2515 Process a @c wxEVT_COMMAND_LEFT_DCLICK command, which is generated by a control (wxMSW only).
2516 @event{EVT_COMMAND_RIGHT_CLICK(id, func)}
2517 Process a @c wxEVT_COMMAND_RIGHT_CLICK command, which is generated by a control (wxMSW only).
2518 @event{EVT_COMMAND_SET_FOCUS(id, func)}
2519 Process a @c wxEVT_COMMAND_SET_FOCUS command, which is generated by a control (wxMSW only).
2520 @event{EVT_COMMAND_KILL_FOCUS(id, func)}
2521 Process a @c wxEVT_COMMAND_KILL_FOCUS command, which is generated by a control (wxMSW only).
2522 @event{EVT_COMMAND_ENTER(id, func)}
2523 Process a @c wxEVT_COMMAND_ENTER command, which is generated by a control.
2529 class wxCommandEvent
: public wxEvent
2535 wxCommandEvent(wxEventType commandEventType
= wxEVT_NULL
, int id
= 0);
2538 Returns client data pointer for a listbox or choice selection event
2539 (not valid for a deselection).
2541 void* GetClientData() const;
2544 Returns client object pointer for a listbox or choice selection event
2545 (not valid for a deselection).
2547 wxClientData
* GetClientObject() const;
2550 Returns extra information dependant on the event objects type.
2552 If the event comes from a listbox selection, it is a boolean
2553 determining whether the event was a selection (@true) or a
2554 deselection (@false). A listbox deselection only occurs for
2555 multiple-selection boxes, and in this case the index and string values
2556 are indeterminate and the listbox must be examined by the application.
2558 long GetExtraLong() const;
2561 Returns the integer identifier corresponding to a listbox, choice or
2562 radiobox selection (only if the event was a selection, not a deselection),
2563 or a boolean value representing the value of a checkbox.
2568 Returns item index for a listbox or choice selection event (not valid for
2571 int GetSelection() const;
2574 Returns item string for a listbox or choice selection event. If one
2575 or several items have been deselected, returns the index of the first
2576 deselected item. If some items have been selected and others deselected
2577 at the same time, it will return the index of the first selected item.
2579 wxString
GetString() const;
2582 This method can be used with checkbox and menu events: for the checkboxes, the
2583 method returns @true for a selection event and @false for a deselection one.
2584 For the menu events, this method indicates if the menu item just has become
2585 checked or unchecked (and thus only makes sense for checkable menu items).
2587 Notice that this method can not be used with wxCheckListBox currently.
2589 bool IsChecked() const;
2592 For a listbox or similar event, returns @true if it is a selection, @false
2593 if it is a deselection. If some items have been selected and others deselected
2594 at the same time, it will return @true.
2596 bool IsSelection() const;
2599 Sets the client data for this event.
2601 void SetClientData(void* clientData
);
2604 Sets the client object for this event. The client object is not owned by the
2605 event object and the event object will not delete the client object in its destructor.
2607 The client object must be owned and deleted by another object (e.g. a control)
2608 that has longer life time than the event object.
2610 void SetClientObject(wxClientData
* clientObject
);
2613 Sets the @b m_extraLong member.
2615 void SetExtraLong(long extraLong
);
2618 Sets the @b m_commandInt member.
2620 void SetInt(int intCommand
);
2623 Sets the @b m_commandString member.
2625 void SetString(const wxString
& string
);
2631 @class wxActivateEvent
2633 An activate event is sent when a window or application is being activated
2636 @beginEventTable{wxActivateEvent}
2637 @event{EVT_ACTIVATE(func)}
2638 Process a @c wxEVT_ACTIVATE event.
2639 @event{EVT_ACTIVATE_APP(func)}
2640 Process a @c wxEVT_ACTIVATE_APP event.
2641 This event is received by the wxApp-derived instance only.
2642 @event{EVT_HIBERNATE(func)}
2643 Process a hibernate event, supplying the member function. This event applies
2644 to wxApp only, and only on Windows SmartPhone and PocketPC.
2645 It is generated when the system is low on memory; the application should free
2646 up as much memory as possible, and restore full working state when it receives
2647 a wxEVT_ACTIVATE or wxEVT_ACTIVATE_APP event.
2653 @see @ref overview_events, wxApp::IsActive
2655 class wxActivateEvent
: public wxEvent
2661 wxActivateEvent(wxEventType eventType
= wxEVT_NULL
, bool active
= true,
2665 Returns @true if the application or window is being activated, @false otherwise.
2667 bool GetActive() const;
2673 @class wxContextMenuEvent
2675 This class is used for context menu events, sent to give
2676 the application a chance to show a context (popup) menu for a wxWindow.
2678 Note that if wxContextMenuEvent::GetPosition returns wxDefaultPosition, this
2679 means that the event originated from a keyboard context button event, and you
2680 should compute a suitable position yourself, for example by calling wxGetMousePosition().
2682 When a keyboard context menu button is pressed on Windows, a right-click event
2683 with default position is sent first, and if this event is not processed, the
2684 context menu event is sent. So if you process mouse events and you find your
2685 context menu event handler is not being called, you could call wxEvent::Skip()
2686 for mouse right-down events.
2688 @beginEventTable{wxContextMenuEvent}
2689 @event{EVT_CONTEXT_MENU(func)}
2690 A right click (or other context menu command depending on platform) has been detected.
2697 @see wxCommandEvent, @ref overview_events
2699 class wxContextMenuEvent
: public wxCommandEvent
2705 wxContextMenuEvent(wxEventType id
= wxEVT_NULL
, int id
= 0,
2706 const wxPoint
& pos
= wxDefaultPosition
);
2709 Returns the position in screen coordinates at which the menu should be shown.
2710 Use wxWindow::ScreenToClient to convert to client coordinates.
2712 You can also omit a position from wxWindow::PopupMenu in order to use
2713 the current mouse pointer position.
2715 If the event originated from a keyboard event, the value returned from this
2716 function will be wxDefaultPosition.
2718 const wxPoint
& GetPosition() const;
2721 Sets the position at which the menu should be shown.
2723 void SetPosition(const wxPoint
& point
);
2731 An erase event is sent when a window's background needs to be repainted.
2733 On some platforms, such as GTK+, this event is simulated (simply generated just
2734 before the paint event) and may cause flicker. It is therefore recommended that
2735 you set the text background colour explicitly in order to prevent flicker.
2736 The default background colour under GTK+ is grey.
2738 To intercept this event, use the EVT_ERASE_BACKGROUND macro in an event table
2741 You must call wxEraseEvent::GetDC and use the returned device context if it is
2742 non-@NULL. If it is @NULL, create your own temporary wxClientDC object.
2745 Use the device context returned by GetDC to draw on, don't create
2746 a wxPaintDC in the event handler.
2748 @beginEventTable{wxEraseEvent}
2749 @event{EVT_ERASE_BACKGROUND(func)}
2750 Process a @c wxEVT_ERASE_BACKGROUND event.
2756 @see @ref overview_events
2758 class wxEraseEvent
: public wxEvent
2764 wxEraseEvent(int id
= 0, wxDC
* dc
= NULL
);
2767 Returns the device context associated with the erase event to draw on.
2769 wxDC
* GetDC() const;
2777 A focus event is sent when a window's focus changes. The window losing focus
2778 receives a "kill focus" event while the window gaining it gets a "set focus" one.
2780 Notice that the set focus event happens both when the user gives focus to the
2781 window (whether using the mouse or keyboard) and when it is done from the
2782 program itself using wxWindow::SetFocus.
2784 @beginEventTable{wxFocusEvent}
2785 @event{EVT_SET_FOCUS(func)}
2786 Process a @c wxEVT_SET_FOCUS event.
2787 @event{EVT_KILL_FOCUS(func)}
2788 Process a @c wxEVT_KILL_FOCUS event.
2794 @see @ref overview_events
2796 class wxFocusEvent
: public wxEvent
2802 wxFocusEvent(wxEventType eventType
= wxEVT_NULL
, int id
= 0);
2805 Returns the window associated with this event, that is the window which had the
2806 focus before for the @c wxEVT_SET_FOCUS event and the window which is
2807 going to receive focus for the @c wxEVT_KILL_FOCUS one.
2809 Warning: the window pointer may be @NULL!
2811 wxWindow
*GetWindow() const;
2817 @class wxChildFocusEvent
2819 A child focus event is sent to a (parent-)window when one of its child windows
2820 gains focus, so that the window could restore the focus back to its corresponding
2821 child if it loses it now and regains later.
2823 Notice that child window is the direct child of the window receiving event.
2824 Use wxWindow::FindFocus() to retreive the window which is actually getting focus.
2826 @beginEventTable{wxChildFocusEvent}
2827 @event{EVT_CHILD_FOCUS(func)}
2828 Process a @c wxEVT_CHILD_FOCUS event.
2834 @see @ref overview_events
2836 class wxChildFocusEvent
: public wxCommandEvent
2843 The direct child which is (or which contains the window which is) receiving
2846 wxChildFocusEvent(wxWindow
* win
= NULL
);
2849 Returns the direct child which receives the focus, or a (grand-)parent of the
2850 control receiving the focus.
2852 To get the actually focused control use wxWindow::FindFocus.
2854 wxWindow
*GetWindow() const;
2860 @class wxMouseCaptureLostEvent
2862 An mouse capture lost event is sent to a window that obtained mouse capture,
2863 which was subsequently loss due to "external" event, for example when a dialog
2864 box is shown or if another application captures the mouse.
2866 If this happens, this event is sent to all windows that are on capture stack
2867 (i.e. called CaptureMouse, but didn't call ReleaseMouse yet). The event is
2868 not sent if the capture changes because of a call to CaptureMouse or
2871 This event is currently emitted under Windows only.
2873 @beginEventTable{wxMouseCaptureLostEvent}
2874 @event{EVT_MOUSE_CAPTURE_LOST(func)}
2875 Process a @c wxEVT_MOUSE_CAPTURE_LOST event.
2883 @see wxMouseCaptureChangedEvent, @ref overview_events,
2884 wxWindow::CaptureMouse, wxWindow::ReleaseMouse, wxWindow::GetCapture
2886 class wxMouseCaptureLostEvent
: public wxEvent
2892 wxMouseCaptureLostEvent(wxWindowID windowId
= 0);
2898 @class wxNotifyEvent
2900 This class is not used by the event handlers by itself, but is a base class
2901 for other event classes (such as wxBookCtrlEvent).
2903 It (or an object of a derived class) is sent when the controls state is being
2904 changed and allows the program to wxNotifyEvent::Veto() this change if it wants
2905 to prevent it from happening.
2910 @see wxBookCtrlEvent
2912 class wxNotifyEvent
: public wxCommandEvent
2916 Constructor (used internally by wxWidgets only).
2918 wxNotifyEvent(wxEventType eventType
= wxEVT_NULL
, int id
= 0);
2921 This is the opposite of Veto(): it explicitly allows the event to be processed.
2922 For most events it is not necessary to call this method as the events are allowed
2923 anyhow but some are forbidden by default (this will be mentioned in the corresponding
2929 Returns @true if the change is allowed (Veto() hasn't been called) or @false
2930 otherwise (if it was).
2932 bool IsAllowed() const;
2935 Prevents the change announced by this event from happening.
2937 It is in general a good idea to notify the user about the reasons for vetoing
2938 the change because otherwise the applications behaviour (which just refuses to
2939 do what the user wants) might be quite surprising.
2946 @class wxThreadEvent
2948 This class adds some simple functionalities to wxCommandEvent coinceived
2949 for inter-threads communications.
2951 This event is not natively emitted by any control/class: this is just
2952 an helper class for the user.
2953 Its most important feature is the GetEventCategory() implementation which
2954 allows thread events to @b NOT be processed by wxEventLoopBase::YieldFor calls
2955 (unless the @c wxEVT_CATEGORY_THREAD is specified - which is never in wx code).
2958 @category{events,threading}
2960 @see @ref overview_thread, wxEventLoopBase::YieldFor
2962 class wxThreadEvent
: public wxCommandEvent
2968 wxThreadEvent(wxEventType eventType
= wxEVT_COMMAND_THREAD
, int id
= wxID_ANY
);
2971 Clones this event making sure that all internal members which use
2972 COW (only @c m_commandString for now; see @ref overview_refcount)
2973 are unshared (see wxObject::UnShare).
2975 virtual wxEvent
*Clone() const;
2978 Returns @c wxEVT_CATEGORY_THREAD.
2980 This is important to avoid unwanted processing of thread events
2981 when calling wxEventLoopBase::YieldFor().
2983 virtual wxEventCategory
GetEventCategory() const;
2986 Sets custom data payload.
2988 The @a payload argument may be of any type that wxAny can handle
2989 (i.e. pretty much anything). Note that T's copy constructor must be
2990 thread-safe, i.e. create a copy that doesn't share anything with
2991 the original (see Clone()).
2993 @note This method is not available with Visual C++ 6.
2997 @see GetPayload(), wxAny
2999 template<typename T
>
3000 void SetPayload(const T
& payload
);
3003 Get custom data payload.
3005 Correct type is checked in debug builds.
3007 @note This method is not available with Visual C++ 6.
3011 @see SetPayload(), wxAny
3013 template<typename T
>
3014 T
GetPayload() const;
3021 A help event is sent when the user has requested context-sensitive help.
3022 This can either be caused by the application requesting context-sensitive help mode
3023 via wxContextHelp, or (on MS Windows) by the system generating a WM_HELP message when
3024 the user pressed F1 or clicked on the query button in a dialog caption.
3026 A help event is sent to the window that the user clicked on, and is propagated
3027 up the window hierarchy until the event is processed or there are no more event
3030 The application should call wxEvent::GetId to check the identity of the
3031 clicked-on window, and then either show some suitable help or call wxEvent::Skip()
3032 if the identifier is unrecognised.
3034 Calling Skip is important because it allows wxWidgets to generate further
3035 events for ancestors of the clicked-on window. Otherwise it would be impossible to
3036 show help for container windows, since processing would stop after the first window
3039 @beginEventTable{wxHelpEvent}
3040 @event{EVT_HELP(id, func)}
3041 Process a @c wxEVT_HELP event.
3042 @event{EVT_HELP_RANGE(id1, id2, func)}
3043 Process a @c wxEVT_HELP event for a range of ids.
3049 @see wxContextHelp, wxDialog, @ref overview_events
3051 class wxHelpEvent
: public wxCommandEvent
3055 Indicates how a wxHelpEvent was generated.
3059 Origin_Unknown
, /**< unrecognized event source. */
3060 Origin_Keyboard
, /**< event generated from F1 key press. */
3062 /** event generated by wxContextHelp or from the [?] button on
3063 the title bar (Windows). */
3070 wxHelpEvent(wxEventType type
= wxEVT_NULL
,
3071 wxWindowID winid
= 0,
3072 const wxPoint
& pt
= wxDefaultPosition
,
3073 wxHelpEvent::Origin origin
= Origin_Unknown
);
3076 Returns the origin of the help event which is one of the ::wxHelpEventOrigin
3079 The application may handle events generated using the keyboard or mouse
3080 differently, e.g. by using wxGetMousePosition() for the mouse events.
3084 wxHelpEvent::Origin
GetOrigin() const;
3087 Returns the left-click position of the mouse, in screen coordinates.
3088 This allows the application to position the help appropriately.
3090 const wxPoint
& GetPosition() const;
3093 Set the help event origin, only used internally by wxWidgets normally.
3097 void SetOrigin(wxHelpEvent::Origin origin
);
3100 Sets the left-click position of the mouse, in screen coordinates.
3102 void SetPosition(const wxPoint
& pt
);
3108 @class wxScrollEvent
3110 A scroll event holds information about events sent from stand-alone
3111 scrollbars (see wxScrollBar) and sliders (see wxSlider).
3113 Note that scrolled windows send the wxScrollWinEvent which does not derive from
3114 wxCommandEvent, but from wxEvent directly - don't confuse these two kinds of
3115 events and use the event table macros mentioned below only for the scrollbar-like
3118 @section scrollevent_diff The difference between EVT_SCROLL_THUMBRELEASE and EVT_SCROLL_CHANGED
3120 The EVT_SCROLL_THUMBRELEASE event is only emitted when actually dragging the thumb
3121 using the mouse and releasing it (This EVT_SCROLL_THUMBRELEASE event is also followed
3122 by an EVT_SCROLL_CHANGED event).
3124 The EVT_SCROLL_CHANGED event also occurs when using the keyboard to change the thumb
3125 position, and when clicking next to the thumb (In all these cases the EVT_SCROLL_THUMBRELEASE
3126 event does not happen).
3128 In short, the EVT_SCROLL_CHANGED event is triggered when scrolling/ moving has finished
3129 independently of the way it had started. Please see the widgets sample ("Slider" page)
3130 to see the difference between EVT_SCROLL_THUMBRELEASE and EVT_SCROLL_CHANGED in action.
3133 Note that unless specifying a scroll control identifier, you will need to test for scrollbar
3134 orientation with wxScrollEvent::GetOrientation, since horizontal and vertical scroll events
3135 are processed using the same event handler.
3137 @beginEventTable{wxScrollEvent}
3138 You can use EVT_COMMAND_SCROLL... macros with window IDs for when intercepting
3139 scroll events from controls, or EVT_SCROLL... macros without window IDs for
3140 intercepting scroll events from the receiving window -- except for this, the
3141 macros behave exactly the same.
3142 @event{EVT_SCROLL(func)}
3143 Process all scroll events.
3144 @event{EVT_SCROLL_TOP(func)}
3145 Process wxEVT_SCROLL_TOP scroll-to-top events (minimum position).
3146 @event{EVT_SCROLL_BOTTOM(func)}
3147 Process wxEVT_SCROLL_BOTTOM scroll-to-bottom events (maximum position).
3148 @event{EVT_SCROLL_LINEUP(func)}
3149 Process wxEVT_SCROLL_LINEUP line up events.
3150 @event{EVT_SCROLL_LINEDOWN(func)}
3151 Process wxEVT_SCROLL_LINEDOWN line down events.
3152 @event{EVT_SCROLL_PAGEUP(func)}
3153 Process wxEVT_SCROLL_PAGEUP page up events.
3154 @event{EVT_SCROLL_PAGEDOWN(func)}
3155 Process wxEVT_SCROLL_PAGEDOWN page down events.
3156 @event{EVT_SCROLL_THUMBTRACK(func)}
3157 Process wxEVT_SCROLL_THUMBTRACK thumbtrack events (frequent events sent as the
3158 user drags the thumbtrack).
3159 @event{EVT_SCROLL_THUMBRELEASE(func)}
3160 Process wxEVT_SCROLL_THUMBRELEASE thumb release events.
3161 @event{EVT_SCROLL_CHANGED(func)}
3162 Process wxEVT_SCROLL_CHANGED end of scrolling events (MSW only).
3163 @event{EVT_COMMAND_SCROLL(id, func)}
3164 Process all scroll events.
3165 @event{EVT_COMMAND_SCROLL_TOP(id, func)}
3166 Process wxEVT_SCROLL_TOP scroll-to-top events (minimum position).
3167 @event{EVT_COMMAND_SCROLL_BOTTOM(id, func)}
3168 Process wxEVT_SCROLL_BOTTOM scroll-to-bottom events (maximum position).
3169 @event{EVT_COMMAND_SCROLL_LINEUP(id, func)}
3170 Process wxEVT_SCROLL_LINEUP line up events.
3171 @event{EVT_COMMAND_SCROLL_LINEDOWN(id, func)}
3172 Process wxEVT_SCROLL_LINEDOWN line down events.
3173 @event{EVT_COMMAND_SCROLL_PAGEUP(id, func)}
3174 Process wxEVT_SCROLL_PAGEUP page up events.
3175 @event{EVT_COMMAND_SCROLL_PAGEDOWN(id, func)}
3176 Process wxEVT_SCROLL_PAGEDOWN page down events.
3177 @event{EVT_COMMAND_SCROLL_THUMBTRACK(id, func)}
3178 Process wxEVT_SCROLL_THUMBTRACK thumbtrack events (frequent events sent
3179 as the user drags the thumbtrack).
3180 @event{EVT_COMMAND_SCROLL_THUMBRELEASE(func)}
3181 Process wxEVT_SCROLL_THUMBRELEASE thumb release events.
3182 @event{EVT_COMMAND_SCROLL_CHANGED(func)}
3183 Process wxEVT_SCROLL_CHANGED end of scrolling events (MSW only).
3189 @see wxScrollBar, wxSlider, wxSpinButton, wxScrollWinEvent, @ref overview_events
3191 class wxScrollEvent
: public wxCommandEvent
3197 wxScrollEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0, int pos
= 0,
3198 int orientation
= 0);
3201 Returns wxHORIZONTAL or wxVERTICAL, depending on the orientation of the
3204 int GetOrientation() const;
3207 Returns the position of the scrollbar.
3209 int GetPosition() const;
3213 See wxIdleEvent::SetMode() for more info.
3217 /** Send idle events to all windows */
3220 /** Send idle events to windows that have the wxWS_EX_PROCESS_IDLE flag specified */
3221 wxIDLE_PROCESS_SPECIFIED
3228 This class is used for idle events, which are generated when the system becomes
3229 idle. Note that, unless you do something specifically, the idle events are not
3230 sent if the system remains idle once it has become it, e.g. only a single idle
3231 event will be generated until something else resulting in more normal events
3232 happens and only then is the next idle event sent again.
3234 If you need to ensure a continuous stream of idle events, you can either use
3235 wxIdleEvent::RequestMore method in your handler or call wxWakeUpIdle() periodically
3236 (for example from a timer event handler), but note that both of these approaches
3237 (and especially the first one) increase the system load and so should be avoided
3240 By default, idle events are sent to all windows (and also wxApp, as usual).
3241 If this is causing a significant overhead in your application, you can call
3242 wxIdleEvent::SetMode with the value wxIDLE_PROCESS_SPECIFIED, and set the
3243 wxWS_EX_PROCESS_IDLE extra window style for every window which should receive
3246 @beginEventTable{wxIdleEvent}
3247 @event{EVT_IDLE(func)}
3248 Process a @c wxEVT_IDLE event.
3254 @see @ref overview_events, wxUpdateUIEvent, wxWindow::OnInternalIdle
3256 class wxIdleEvent
: public wxEvent
3265 Returns @true if it is appropriate to send idle events to this window.
3267 This function looks at the mode used (see wxIdleEvent::SetMode),
3268 and the wxWS_EX_PROCESS_IDLE style in @a window to determine whether idle
3269 events should be sent to this window now.
3271 By default this will always return @true because the update mode is initially
3272 wxIDLE_PROCESS_ALL. You can change the mode to only send idle events to
3273 windows with the wxWS_EX_PROCESS_IDLE extra window style set.
3277 static bool CanSend(wxWindow
* window
);
3280 Static function returning a value specifying how wxWidgets will send idle
3281 events: to all windows, or only to those which specify that they
3282 will process the events.
3286 static wxIdleMode
GetMode();
3289 Returns @true if the OnIdle function processing this event requested more
3294 bool MoreRequested() const;
3297 Tells wxWidgets that more processing is required.
3299 This function can be called by an OnIdle handler for a window or window event
3300 handler to indicate that wxApp::OnIdle should forward the OnIdle event once
3301 more to the application windows.
3303 If no window calls this function during OnIdle, then the application will
3304 remain in a passive event loop (not calling OnIdle) until a new event is
3305 posted to the application by the windowing system.
3307 @see MoreRequested()
3309 void RequestMore(bool needMore
= true);
3312 Static function for specifying how wxWidgets will send idle events: to
3313 all windows, or only to those which specify that they will process the events.
3316 Can be one of the ::wxIdleMode values.
3317 The default is wxIDLE_PROCESS_ALL.
3319 static void SetMode(wxIdleMode mode
);
3325 @class wxInitDialogEvent
3327 A wxInitDialogEvent is sent as a dialog or panel is being initialised.
3328 Handlers for this event can transfer data to the window.
3330 The default handler calls wxWindow::TransferDataToWindow.
3332 @beginEventTable{wxInitDialogEvent}
3333 @event{EVT_INIT_DIALOG(func)}
3334 Process a @c wxEVT_INIT_DIALOG event.
3340 @see @ref overview_events
3342 class wxInitDialogEvent
: public wxEvent
3348 wxInitDialogEvent(int id
= 0);
3354 @class wxWindowDestroyEvent
3356 This event is sent as early as possible during the window destruction
3359 For the top level windows, as early as possible means that this is done by
3360 wxFrame or wxDialog destructor, i.e. after the destructor of the derived
3361 class was executed and so any methods specific to the derived class can't
3362 be called any more from this event handler. If you need to do this, you
3363 must call wxWindow::SendDestroyEvent() from your derived class destructor.
3365 For the child windows, this event is generated just before deleting the
3366 window from wxWindow::Destroy() (which is also called when the parent
3367 window is deleted) or from the window destructor if operator @c delete was
3368 used directly (which is not recommended for this very reason).
3370 It is usually pointless to handle this event in the window itself but it ca
3371 be very useful to receive notifications about the window destruction in the
3372 parent window or in any other object interested in this window.
3377 @see @ref overview_events, wxWindowCreateEvent
3379 class wxWindowDestroyEvent
: public wxCommandEvent
3385 wxWindowDestroyEvent(wxWindow
* win
= NULL
);
3387 /// Retutn the window being destroyed.
3388 wxWindow
*GetWindow() const;
3393 @class wxNavigationKeyEvent
3395 This event class contains information about navigation events,
3396 generated by navigation keys such as tab and page down.
3398 This event is mainly used by wxWidgets implementations.
3399 A wxNavigationKeyEvent handler is automatically provided by wxWidgets
3400 when you make a class into a control container with the macro
3401 WX_DECLARE_CONTROL_CONTAINER.
3403 @beginEventTable{wxNavigationKeyEvent}
3404 @event{EVT_NAVIGATION_KEY(func)}
3405 Process a navigation key event.
3411 @see wxWindow::Navigate, wxWindow::NavigateIn
3413 class wxNavigationKeyEvent
: public wxEvent
3417 Flags which can be used with wxNavigationKeyEvent.
3419 enum wxNavigationKeyEventFlags
3421 IsBackward
= 0x0000,
3427 wxNavigationKeyEvent();
3428 wxNavigationKeyEvent(const wxNavigationKeyEvent
& event
);
3431 Returns the child that has the focus, or @NULL.
3433 wxWindow
* GetCurrentFocus() const;
3436 Returns @true if the navigation was in the forward direction.
3438 bool GetDirection() const;
3441 Returns @true if the navigation event was from a tab key.
3442 This is required for proper navigation over radio buttons.
3444 bool IsFromTab() const;
3447 Returns @true if the navigation event represents a window change
3448 (for example, from Ctrl-Page Down in a notebook).
3450 bool IsWindowChange() const;
3453 Sets the current focus window member.
3455 void SetCurrentFocus(wxWindow
* currentFocus
);
3458 Sets the direction to forward if @a direction is @true, or backward
3461 void SetDirection(bool direction
);
3464 Sets the flags for this event.
3465 The @a flags can be a combination of the ::wxNavigationKeyEventFlags values.
3467 void SetFlags(long flags
);
3470 Marks the navigation event as from a tab key.
3472 void SetFromTab(bool fromTab
);
3475 Marks the event as a window change event.
3477 void SetWindowChange(bool windowChange
);
3483 @class wxMouseCaptureChangedEvent
3485 An mouse capture changed event is sent to a window that loses its
3486 mouse capture. This is called even if wxWindow::ReleaseMouse
3487 was called by the application code. Handling this event allows
3488 an application to cater for unexpected capture releases which
3489 might otherwise confuse mouse handling code.
3493 @beginEventTable{wxMouseCaptureChangedEvent}
3494 @event{EVT_MOUSE_CAPTURE_CHANGED(func)}
3495 Process a @c wxEVT_MOUSE_CAPTURE_CHANGED event.
3501 @see wxMouseCaptureLostEvent, @ref overview_events,
3502 wxWindow::CaptureMouse, wxWindow::ReleaseMouse, wxWindow::GetCapture
3504 class wxMouseCaptureChangedEvent
: public wxEvent
3510 wxMouseCaptureChangedEvent(wxWindowID windowId
= 0,
3511 wxWindow
* gainedCapture
= NULL
);
3514 Returns the window that gained the capture, or @NULL if it was a
3515 non-wxWidgets window.
3517 wxWindow
* GetCapturedWindow() const;
3525 This event class contains information about window and session close events.
3527 The handler function for EVT_CLOSE is called when the user has tried to close a
3528 a frame or dialog box using the window manager (X) or system menu (Windows).
3529 It can also be invoked by the application itself programmatically, for example by
3530 calling the wxWindow::Close function.
3532 You should check whether the application is forcing the deletion of the window
3533 using wxCloseEvent::CanVeto. If this is @false, you @e must destroy the window
3534 using wxWindow::Destroy.
3536 If the return value is @true, it is up to you whether you respond by destroying
3539 If you don't destroy the window, you should call wxCloseEvent::Veto to
3540 let the calling code know that you did not destroy the window.
3541 This allows the wxWindow::Close function to return @true or @false depending
3542 on whether the close instruction was honoured or not.
3544 Example of a wxCloseEvent handler:
3547 void MyFrame::OnClose(wxCloseEvent& event)
3549 if ( event.CanVeto() && m_bFileNotSaved )
3551 if ( wxMessageBox("The file has not been saved... continue closing?",
3553 wxICON_QUESTION | wxYES_NO) != wxYES )
3560 Destroy(); // you may also do: event.Skip();
3561 // since the default event handler does call Destroy(), too
3565 The EVT_END_SESSION event is slightly different as it is sent by the system
3566 when the user session is ending (e.g. because of log out or shutdown) and
3567 so all windows are being forcefully closed. At least under MSW, after the
3568 handler for this event is executed the program is simply killed by the
3569 system. Because of this, the default handler for this event provided by
3570 wxWidgets calls all the usual cleanup code (including wxApp::OnExit()) so
3571 that it could still be executed and exit()s the process itself, without
3572 waiting for being killed. If this behaviour is for some reason undesirable,
3573 make sure that you define a handler for this event in your wxApp-derived
3574 class and do not call @c event.Skip() in it (but be aware that the system
3575 will still kill your application).
3577 @beginEventTable{wxCloseEvent}
3578 @event{EVT_CLOSE(func)}
3579 Process a @c wxEVT_CLOSE_WINDOW command event, supplying the member function.
3580 This event applies to wxFrame and wxDialog classes.
3581 @event{EVT_QUERY_END_SESSION(func)}
3582 Process a @c wxEVT_QUERY_END_SESSION session event, supplying the member function.
3583 This event can be handled in wxApp-derived class only.
3584 @event{EVT_END_SESSION(func)}
3585 Process a @c wxEVT_END_SESSION session event, supplying the member function.
3586 This event can be handled in wxApp-derived class only.
3592 @see wxWindow::Close, @ref overview_windowdeletion
3594 class wxCloseEvent
: public wxEvent
3600 wxCloseEvent(wxEventType commandEventType
= wxEVT_NULL
, int id
= 0);
3603 Returns @true if you can veto a system shutdown or a window close event.
3604 Vetoing a window close event is not possible if the calling code wishes to
3605 force the application to exit, and so this function must be called to check this.
3607 bool CanVeto() const;
3610 Returns @true if the user is just logging off or @false if the system is
3611 shutting down. This method can only be called for end session and query end
3612 session events, it doesn't make sense for close window event.
3614 bool GetLoggingOff() const;
3617 Sets the 'can veto' flag.
3619 void SetCanVeto(bool canVeto
);
3622 Sets the 'logging off' flag.
3624 void SetLoggingOff(bool loggingOff
);
3627 Call this from your event handler to veto a system shutdown or to signal
3628 to the calling application that a window close did not happen.
3630 You can only veto a shutdown if CanVeto() returns @true.
3632 void Veto(bool veto
= true);
3640 This class is used for a variety of menu-related events. Note that
3641 these do not include menu command events, which are
3642 handled using wxCommandEvent objects.
3644 The default handler for @c wxEVT_MENU_HIGHLIGHT displays help
3645 text in the first field of the status bar.
3647 @beginEventTable{wxMenuEvent}
3648 @event{EVT_MENU_OPEN(func)}
3649 A menu is about to be opened. On Windows, this is only sent once for each
3650 navigation of the menubar (up until all menus have closed).
3651 @event{EVT_MENU_CLOSE(func)}
3652 A menu has been just closed.
3653 @event{EVT_MENU_HIGHLIGHT(id, func)}
3654 The menu item with the specified id has been highlighted: used to show
3655 help prompts in the status bar by wxFrame
3656 @event{EVT_MENU_HIGHLIGHT_ALL(func)}
3657 A menu item has been highlighted, i.e. the currently selected menu item has changed.
3663 @see wxCommandEvent, @ref overview_events
3665 class wxMenuEvent
: public wxEvent
3671 wxMenuEvent(wxEventType id
= wxEVT_NULL
, int id
= 0, wxMenu
* menu
= NULL
);
3674 Returns the menu which is being opened or closed. This method should only be
3675 used with the @c OPEN and @c CLOSE events and even for them the
3676 returned pointer may be @NULL in some ports.
3678 wxMenu
* GetMenu() const;
3681 Returns the menu identifier associated with the event.
3682 This method should be only used with the @c HIGHLIGHT events.
3684 int GetMenuId() const;
3687 Returns @true if the menu which is being opened or closed is a popup menu,
3688 @false if it is a normal one.
3690 This method should only be used with the @c OPEN and @c CLOSE events.
3692 bool IsPopup() const;
3698 An event being sent when the window is shown or hidden.
3699 The event is triggered by calls to wxWindow::Show(), and any user
3700 action showing a previously hidden window or vice versa (if allowed by
3701 the current platform and/or window manager).
3702 Notice that the event is not triggered when the application is iconized
3703 (minimized) or restored under wxMSW.
3705 Currently only wxMSW, wxGTK and wxOS2 generate such events.
3707 @onlyfor{wxmsw,wxgtk,wxos2}
3709 @beginEventTable{wxShowEvent}
3710 @event{EVT_SHOW(func)}
3711 Process a @c wxEVT_SHOW event.
3717 @see @ref overview_events, wxWindow::Show,
3721 class wxShowEvent
: public wxEvent
3727 wxShowEvent(int winid
= 0, bool show
= false);
3730 Set whether the windows was shown or hidden.
3732 void SetShow(bool show
);
3735 Return @true if the window has been shown, @false if it has been
3738 bool IsShown() const;
3741 @deprecated This function is deprecated in favour of IsShown().
3743 bool GetShow() const;
3749 @class wxIconizeEvent
3751 An event being sent when the frame is iconized (minimized) or restored.
3753 Currently only wxMSW and wxGTK generate such events.
3755 @onlyfor{wxmsw,wxgtk}
3757 @beginEventTable{wxIconizeEvent}
3758 @event{EVT_ICONIZE(func)}
3759 Process a @c wxEVT_ICONIZE event.
3765 @see @ref overview_events, wxTopLevelWindow::Iconize,
3766 wxTopLevelWindow::IsIconized
3768 class wxIconizeEvent
: public wxEvent
3774 wxIconizeEvent(int id
= 0, bool iconized
= true);
3777 Returns @true if the frame has been iconized, @false if it has been
3780 bool IsIconized() const;
3783 @deprecated This function is deprecated in favour of IsIconized().
3785 bool Iconized() const;
3793 A move event holds information about wxTopLevelWindow move change events.
3795 @beginEventTable{wxMoveEvent}
3796 @event{EVT_MOVE(func)}
3797 Process a @c wxEVT_MOVE event, which is generated when a window is moved.
3798 @event{EVT_MOVE_START(func)}
3799 Process a @c wxEVT_MOVE_START event, which is generated when the user starts
3800 to move or size a window. wxMSW only.
3801 @event{EVT_MOVE_END(func)}
3802 Process a @c wxEVT_MOVE_END event, which is generated when the user stops
3803 moving or sizing a window. wxMSW only.
3809 @see wxPoint, @ref overview_events
3811 class wxMoveEvent
: public wxEvent
3817 wxMoveEvent(const wxPoint
& pt
, int id
= 0);
3820 Returns the position of the window generating the move change event.
3822 wxPoint
GetPosition() const;
3829 A size event holds information about size change events of wxWindow.
3831 The EVT_SIZE handler function will be called when the window has been resized.
3833 You may wish to use this for frames to resize their child windows as appropriate.
3835 Note that the size passed is of the whole window: call wxWindow::GetClientSize()
3836 for the area which may be used by the application.
3838 When a window is resized, usually only a small part of the window is damaged
3839 and you may only need to repaint that area. However, if your drawing depends on the
3840 size of the window, you may need to clear the DC explicitly and repaint the whole window.
3841 In which case, you may need to call wxWindow::Refresh to invalidate the entire window.
3843 @beginEventTable{wxSizeEvent}
3844 @event{EVT_SIZE(func)}
3845 Process a @c wxEVT_SIZE event.
3851 @see wxSize, @ref overview_events
3853 class wxSizeEvent
: public wxEvent
3859 wxSizeEvent(const wxSize
& sz
, int id
= 0);
3862 Returns the entire size of the window generating the size change event.
3864 This is the new total size of the window, i.e. the same size as would
3865 be returned by wxWindow::GetSize() if it were called now. Use
3866 wxWindow::GetClientSize() if you catch this event in a top level window
3867 such as wxFrame to find the size available for the window contents.
3869 wxSize
GetSize() const;
3875 @class wxSetCursorEvent
3877 A wxSetCursorEvent is generated from wxWindow when the mouse cursor is about
3878 to be set as a result of mouse motion.
3880 This event gives the application the chance to perform specific mouse cursor
3881 processing based on the current position of the mouse within the window.
3882 Use wxSetCursorEvent::SetCursor to specify the cursor you want to be displayed.
3884 @beginEventTable{wxSetCursorEvent}
3885 @event{EVT_SET_CURSOR(func)}
3886 Process a @c wxEVT_SET_CURSOR event.
3892 @see ::wxSetCursor, wxWindow::wxSetCursor
3894 class wxSetCursorEvent
: public wxEvent
3898 Constructor, used by the library itself internally to initialize the event
3901 wxSetCursorEvent(wxCoord x
= 0, wxCoord y
= 0);
3904 Returns a reference to the cursor specified by this event.
3906 const wxCursor
& GetCursor() const;
3909 Returns the X coordinate of the mouse in client coordinates.
3911 wxCoord
GetX() const;
3914 Returns the Y coordinate of the mouse in client coordinates.
3916 wxCoord
GetY() const;
3919 Returns @true if the cursor specified by this event is a valid cursor.
3921 @remarks You cannot specify wxNullCursor with this event, as it is not
3922 considered a valid cursor.
3924 bool HasCursor() const;
3927 Sets the cursor associated with this event.
3929 void SetCursor(const wxCursor
& cursor
);
3934 // ============================================================================
3935 // Global functions/macros
3936 // ============================================================================
3938 /** @addtogroup group_funcmacro_events */
3942 A value uniquely identifying the type of the event.
3944 The values of this type should only be created using wxNewEventType().
3946 See the macro DEFINE_EVENT_TYPE() for more info.
3948 @see @ref overview_events_introduction
3950 typedef int wxEventType
;
3953 A special event type usually used to indicate that some wxEvent has yet
3956 wxEventType wxEVT_NULL
;
3959 Generates a new unique event type.
3961 Usually this function is only used by wxDEFINE_EVENT() and not called
3964 wxEventType
wxNewEventType();
3967 Define a new event type associated with the specified event class.
3969 This macro defines a new unique event type @a name associated with the
3974 wxDEFINE_EVENT(MY_COMMAND_EVENT, wxCommandEvent);
3976 class MyCustomEvent : public wxEvent { ... };
3977 wxDEFINE_EVENT(MY_CUSTOM_EVENT, MyCustomEvent);
3980 @see wxDECLARE_EVENT(), @ref overview_events_custom
3982 #define wxDEFINE_EVENT(name, cls) \
3983 const wxEventTypeTag< cls > name(wxNewEventType())
3986 Declares a custom event type.
3988 This macro declares a variable called @a name which must be defined
3989 elsewhere using wxDEFINE_EVENT().
3991 The class @a cls must be the wxEvent-derived class associated with the
3992 events of this type and its full declaration must be visible from the point
3993 of use of this macro.
3997 wxDECLARE_EVENT(MY_COMMAND_EVENT, wxCommandEvent);
3999 class MyCustomEvent : public wxEvent { ... };
4000 wxDECLARE_EVENT(MY_CUSTOM_EVENT, MyCustomEvent);
4003 #define wxDECLARE_EVENT(name, cls) \
4004 wxDECLARE_EXPORTED_EVENT(wxEMPTY_PARAMETER_VALUE, name, cls)
4007 Variant of wxDECLARE_EVENT() used for event types defined inside a shared
4010 This is mostly used by wxWidgets internally, e.g.
4012 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEvent)
4015 #define wxDECLARE_EXPORTED_EVENT( expdecl, name, cls ) \
4016 extern const expdecl wxEventTypeTag< cls > name;
4019 Helper macro for definition of custom event table macros.
4021 This macro must only be used if wxEVENTS_COMPATIBILITY_2_8 is 1, otherwise
4022 it is better and more clear to just use the address of the function
4023 directly as this is all this macro does in this case. However it needs to
4024 explicitly cast @a func to @a functype, which is the type of wxEvtHandler
4025 member function taking the custom event argument when
4026 wxEVENTS_COMPATIBILITY_2_8 is 0.
4028 See wx__DECLARE_EVT0 for an example of use.
4030 @see @ref overview_events_custom_ownclass
4032 #define wxEVENT_HANDLER_CAST(functype, func) (&func)
4035 This macro is used to define event table macros for handling custom
4040 class MyEvent : public wxEvent { ... };
4042 // note that this is not necessary unless using old compilers: for the
4043 // reasonably new ones just use &func instead of MyEventHandler(func)
4044 typedef void (wxEvtHandler::*MyEventFunction)(MyEvent&);
4045 #define MyEventHandler(func) wxEVENT_HANDLER_CAST(MyEventFunction, func)
4047 wxDEFINE_EVENT(MY_EVENT_TYPE, MyEvent);
4049 #define EVT_MY(id, func) \
4050 wx__DECLARE_EVT1(MY_EVENT_TYPE, id, MyEventHandler(func))
4054 wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
4055 EVT_MY(wxID_ANY, MyFrame::OnMyEvent)
4060 The event type to handle.
4062 The identifier of events to handle.
4064 The event handler method.
4066 #define wx__DECLARE_EVT1(evt, id, fn) \
4067 wx__DECLARE_EVT2(evt, id, wxID_ANY, fn)
4070 Generalized version of the wx__DECLARE_EVT1() macro taking a range of
4071 IDs instead of a single one.
4072 Argument @a id1 is the first identifier of the range, @a id2 is the
4073 second identifier of the range.
4075 #define wx__DECLARE_EVT2(evt, id1, id2, fn) \
4076 DECLARE_EVENT_TABLE_ENTRY(evt, id1, id2, fn, NULL),
4079 Simplified version of the wx__DECLARE_EVT1() macro, to be used when the
4080 event type must be handled regardless of the ID associated with the
4081 specific event instances.
4083 #define wx__DECLARE_EVT0(evt, fn) \
4084 wx__DECLARE_EVT1(evt, wxID_ANY, fn)
4087 Use this macro inside a class declaration to declare a @e static event table
4090 In the implementation file you'll need to use the wxBEGIN_EVENT_TABLE()
4091 and the wxEND_EVENT_TABLE() macros, plus some additional @c EVT_xxx macro
4094 Note that this macro requires a final semicolon.
4096 @see @ref overview_events_eventtables
4098 #define wxDECLARE_EVENT_TABLE()
4101 Use this macro in a source file to start listing @e static event handlers
4102 for a specific class.
4104 Use wxEND_EVENT_TABLE() to terminate the event-declaration block.
4106 @see @ref overview_events_eventtables
4108 #define wxBEGIN_EVENT_TABLE(theClass, baseClass)
4111 Use this macro in a source file to end listing @e static event handlers
4112 for a specific class.
4114 Use wxBEGIN_EVENT_TABLE() to start the event-declaration block.
4116 @see @ref overview_events_eventtables
4118 #define wxEND_EVENT_TABLE()
4121 In a GUI application, this function posts @a event to the specified @e dest
4122 object using wxEvtHandler::AddPendingEvent().
4124 Otherwise, it dispatches @a event immediately using
4125 wxEvtHandler::ProcessEvent(). See the respective documentation for details
4126 (and caveats). Because of limitation of wxEvtHandler::AddPendingEvent()
4127 this function is not thread-safe for event objects having wxString fields,
4128 use wxQueueEvent() instead.
4132 void wxPostEvent(wxEvtHandler
* dest
, const wxEvent
& event
);
4135 Queue an event for processing on the given object.
4137 This is a wrapper around wxEvtHandler::QueueEvent(), see its documentation
4143 The object to queue the event on, can't be @c NULL.
4145 The heap-allocated and non-@c NULL event to queue, the function takes
4148 void wxQueueEvent(wxEvtHandler
* dest
, wxEvent
*event
);