/////////////////////////////////////////////////////////////////////////////
// Name: event.h
-// Purpose: interface of wxEventHandler, wxEventBlocker and many
+// Purpose: interface of wxEvtHandler, wxEventBlocker and many
// wxEvent-derived classes
// Author: wxWidgets team
// RCS-ID: $Id$
/////////////////////////////////////////////////////////////////////////////
-
/**
@class wxEvent
{
public:
/**
- Constructor. Should not need to be used directly by an application.
+ Constructor.
+
+ Notice that events are usually created by wxWidgets itself and creating
+ e.g. a wxPaintEvent in your code and sending it to e.g. a wxTextCtrl
+ will not usually affect it at all as native controls have no specific
+ knowledge about wxWidgets events. However you may construct objects of
+ specific types and pass them to wxEvtHandler::ProcessEvent() if you
+ want to create your own custom control and want to process its events
+ in the same manner as the standard ones.
+
+ Also please notice that the order of parameters in this constructor is
+ different from almost all the derived classes which specify the event
+ type as the first argument.
+
+ @param id
+ The identifier of the object (window, timer, ...) which generated
+ this event.
+ @param eventType
+ The unique type of event, e.g. wxEVT_PAINT, wxEVT_SIZE or
+ wxEVT_COMMAND_BUTTON_CLICKED.
*/
wxEvent(int id = 0, wxEventType eventType = wxEVT_NULL);
Gets the timestamp for the event. The timestamp is the time in milliseconds
since some fixed moment (not necessarily the standard Unix Epoch, so only
differences between the timestamps and not their absolute values usually make sense).
+
+ @warning
+ wxWidgets returns a non-NULL timestamp only for mouse and key events
+ (see wxMouseEvent and wxKeyEvent).
*/
long GetTimestamp() const;
/**
Sets the timestamp for the event.
*/
- void SetTimestamp(long = 0);
+ void SetTimestamp(long timeStamp = 0);
/**
Test if this event should be propagated or not, i.e. if the propagation level
Note that the @a win window @b must remain alive until the
wxEventBlocker object destruction.
*/
- wxEventBlocker(wxWindow* win, wxEventType type = wxEVT_ANY);
+ wxEventBlocker(wxWindow* win, wxEventType type = -1);
/**
Destructor. The blocker will remove itself from the chain of event handlers for
@class wxEvtHandler
A class that can handle events from the windowing system.
- wxWindow (and therefore all window classes) are derived from this class.
+ wxWindow is (and therefore all window classes are) derived from this class.
When events are received, wxEvtHandler invokes the method listed in the
event table using itself as the object. When using multiple inheritance
- it is imperative that the wxEvtHandler(-derived) class be the first
- class inherited such that the "this" pointer for the overall object
- will be identical to the "this" pointer for the wxEvtHandler portion.
+ <b>it is imperative that the wxEvtHandler(-derived) class is the first
+ class inherited</b> such that the @c this pointer for the overall object
+ will be identical to the @c this pointer of the wxEvtHandler portion.
@library{wxbase}
@category{events}
share the same string buffer internally. Use QueueEvent() to avoid
this.
- A copy of event is made by the function, so the original can be deleted
+ A copy of @a event is made by the function, so the original can be deleted
as soon as function returns (it is common that the original is created
on the stack). This requires that the wxEvent::Clone() method be
implemented by event so that it can be duplicated and stored until it
@param eventSink
Object whose member function should be called.
*/
- bool Disconnect(wxEventType eventType = wxEVT_NULL,
- wxObjectEventFunction function = NULL,
+ bool Disconnect(wxEventType eventType,
+ wxObjectEventFunction function,
wxObject* userData = NULL,
wxEvtHandler* eventSink = NULL);
This overload takes an additional range of source IDs.
*/
- bool Disconnect(int id, int lastId = wxID_ANY,
- wxEventType eventType = wxEVT_NULL,
+ bool Disconnect(int id, int lastId,
+ wxEventType eventType,
wxObjectEventFunction function = NULL,
wxObject* userData = NULL,
wxEvtHandler* eventSink = NULL);
(such as a new control) where you define new event types, as opposed to
allowing the user to override virtual functions.
- An instance where you might actually override the ProcessEvent function is where
+ An instance where you might actually override the ProcessEvent() function is where
you want to direct event processing to event handlers not normally noticed by
wxWidgets. For example, in the document/view architecture, documents and views
- are potential event handlers. When an event reaches a frame, ProcessEvent will
+ are potential event handlers. When an event reaches a frame, ProcessEvent() will
need to be called on the associated document and view in case event handler functions
are associated with these objects. The property classes library (wxProperty) also
- overrides ProcessEvent for similar reasons.
+ overrides ProcessEvent() for similar reasons.
The normal order of event table searching is as follows:
-# If the object is disabled (via a call to wxEvtHandler::SetEvtHandlerEnabled)
@li The event type matches, and
@li the identifier or identifier range matches, or the event table
entry's identifier is zero.
+
If a suitable function is called but calls wxEvent::Skip, this
function will fail, and searching will continue.
parent window receives @c wxEVT_LEAVE_WINDOW event not only when the
mouse leaves the window entirely but also when it enters one of its children.
+ The position associated with a mouse event is expressed in the window
+ coordinates of the window which generated the event, you can use
+ wxWindow::ClientToScreen() to convert it to screen coordinates and possibly
+ call wxWindow::ScreenToClient() next to convert it to window coordinates of
+ another window.
+
@note Note that under Windows CE mouse enter and leave events are not natively
supported by the system but are generated by wxWidgets itself. This has several
drawbacks: the LEAVE_WINDOW event might be received some time after the mouse
*/
int GetWheelRotation() const;
+ /**
+ Gets the axis the wheel operation concerns; @c 0 is the Y axis as on
+ most mouse wheels, @c 1 is the X axis.
+
+ Note that only some models of mouse have horizontal wheel axis.
+ */
+ int GetWheelAxis() const;
+
/**
Returns X coordinate of the physical mouse event position.
*/
Process a command for a range of window identifiers, supplying the minimum and
maximum window identifiers, command event identifier, and member function.
@event{EVT_BUTTON(id, func)}
- Process a wxEVT_COMMAND_BUTTON_CLICKED command, which is generated by a wxButton control.
+ Process a @c wxEVT_COMMAND_BUTTON_CLICKED command, which is generated by a wxButton control.
@event{EVT_CHECKBOX(id, func)}
- Process a wxEVT_COMMAND_CHECKBOX_CLICKED command, which is generated by a wxCheckBox control.
+ Process a @c wxEVT_COMMAND_CHECKBOX_CLICKED command, which is generated by a wxCheckBox control.
@event{EVT_CHOICE(id, func)}
- Process a wxEVT_COMMAND_CHOICE_SELECTED command, which is generated by a wxChoice control.
+ Process a @c wxEVT_COMMAND_CHOICE_SELECTED command, which is generated by a wxChoice control.
@event{EVT_COMBOBOX(id, func)}
- Process a wxEVT_COMMAND_COMBOBOX_SELECTED command, which is generated by a wxComboBox control.
+ Process a @c wxEVT_COMMAND_COMBOBOX_SELECTED command, which is generated by a wxComboBox control.
@event{EVT_LISTBOX(id, func)}
- Process a wxEVT_COMMAND_LISTBOX_SELECTED command, which is generated by a wxListBox control.
+ Process a @c wxEVT_COMMAND_LISTBOX_SELECTED command, which is generated by a wxListBox control.
@event{EVT_LISTBOX_DCLICK(id, func)}
- Process a wxEVT_COMMAND_LISTBOX_DOUBLECLICKED command, which is generated by a wxListBox control.
+ Process a @c wxEVT_COMMAND_LISTBOX_DOUBLECLICKED command, which is generated by a wxListBox control.
@event{EVT_MENU(id, func)}
- Process a wxEVT_COMMAND_MENU_SELECTED command, which is generated by a menu item.
+ Process a @c wxEVT_COMMAND_MENU_SELECTED command, which is generated by a menu item.
@event{EVT_MENU_RANGE(id1, id2, func)}
- Process a wxEVT_COMMAND_MENU_RANGE command, which is generated by a range of menu items.
+ Process a @c wxEVT_COMMAND_MENU_RANGE command, which is generated by a range of menu items.
@event{EVT_CONTEXT_MENU(func)}
Process the event generated when the user has requested a popup menu to appear by
pressing a special keyboard key (under Windows) or by right clicking the mouse.
@event{EVT_RADIOBOX(id, func)}
- Process a wxEVT_COMMAND_RADIOBOX_SELECTED command, which is generated by a wxRadioBox control.
+ Process a @c wxEVT_COMMAND_RADIOBOX_SELECTED command, which is generated by a wxRadioBox control.
@event{EVT_RADIOBUTTON(id, func)}
- Process a wxEVT_COMMAND_RADIOBUTTON_SELECTED command, which is generated by a wxRadioButton control.
+ Process a @c wxEVT_COMMAND_RADIOBUTTON_SELECTED command, which is generated by a wxRadioButton control.
@event{EVT_SCROLLBAR(id, func)}
- Process a wxEVT_COMMAND_SCROLLBAR_UPDATED command, which is generated by a wxScrollBar
+ Process a @c wxEVT_COMMAND_SCROLLBAR_UPDATED command, which is generated by a wxScrollBar
control. This is provided for compatibility only; more specific scrollbar event macros
should be used instead (see wxScrollEvent).
@event{EVT_SLIDER(id, func)}
- Process a wxEVT_COMMAND_SLIDER_UPDATED command, which is generated by a wxSlider control.
+ Process a @c wxEVT_COMMAND_SLIDER_UPDATED command, which is generated by a wxSlider control.
@event{EVT_TEXT(id, func)}
- Process a wxEVT_COMMAND_TEXT_UPDATED command, which is generated by a wxTextCtrl control.
+ Process a @c wxEVT_COMMAND_TEXT_UPDATED command, which is generated by a wxTextCtrl control.
@event{EVT_TEXT_ENTER(id, func)}
- Process a wxEVT_COMMAND_TEXT_ENTER command, which is generated by a wxTextCtrl control.
+ Process a @c wxEVT_COMMAND_TEXT_ENTER command, which is generated by a wxTextCtrl control.
Note that you must use wxTE_PROCESS_ENTER flag when creating the control if you want it
to generate such events.
@event{EVT_TEXT_MAXLEN(id, func)}
- Process a wxEVT_COMMAND_TEXT_MAXLEN command, which is generated by a wxTextCtrl control
+ Process a @c wxEVT_COMMAND_TEXT_MAXLEN command, which is generated by a wxTextCtrl control
when the user tries to enter more characters into it than the limit previously set
with SetMaxLength().
@event{EVT_TOGGLEBUTTON(id, func)}
- Process a wxEVT_COMMAND_TOGGLEBUTTON_CLICKED event.
+ Process a @c wxEVT_COMMAND_TOGGLEBUTTON_CLICKED event.
@event{EVT_TOOL(id, func)}
- Process a wxEVT_COMMAND_TOOL_CLICKED event (a synonym for wxEVT_COMMAND_MENU_SELECTED).
+ Process a @c wxEVT_COMMAND_TOOL_CLICKED event (a synonym for @c wxEVT_COMMAND_MENU_SELECTED).
Pass the id of the tool.
@event{EVT_TOOL_RANGE(id1, id2, func)}
- Process a wxEVT_COMMAND_TOOL_CLICKED event for a range of identifiers. Pass the ids of the tools.
+ Process a @c wxEVT_COMMAND_TOOL_CLICKED event for a range of identifiers. Pass the ids of the tools.
@event{EVT_TOOL_RCLICKED(id, func)}
- Process a wxEVT_COMMAND_TOOL_RCLICKED event. Pass the id of the tool.
+ Process a @c wxEVT_COMMAND_TOOL_RCLICKED event. Pass the id of the tool.
@event{EVT_TOOL_RCLICKED_RANGE(id1, id2, func)}
- Process a wxEVT_COMMAND_TOOL_RCLICKED event for a range of ids. Pass the ids of the tools.
+ Process a @c wxEVT_COMMAND_TOOL_RCLICKED event for a range of ids. Pass the ids of the tools.
@event{EVT_TOOL_ENTER(id, func)}
- Process a wxEVT_COMMAND_TOOL_ENTER event. Pass the id of the toolbar itself.
+ Process a @c wxEVT_COMMAND_TOOL_ENTER event. Pass the id of the toolbar itself.
The value of wxCommandEvent::GetSelection() is the tool id, or -1 if the mouse cursor
has moved off a tool.
@event{EVT_COMMAND_LEFT_CLICK(id, func)}
- Process a wxEVT_COMMAND_LEFT_CLICK command, which is generated by a control (Windows 95 and NT only).
+ Process a @c wxEVT_COMMAND_LEFT_CLICK command, which is generated by a control (wxMSW only).
@event{EVT_COMMAND_LEFT_DCLICK(id, func)}
- Process a wxEVT_COMMAND_LEFT_DCLICK command, which is generated by a control (Windows 95 and NT only).
+ Process a @c wxEVT_COMMAND_LEFT_DCLICK command, which is generated by a control (wxMSW only).
@event{EVT_COMMAND_RIGHT_CLICK(id, func)}
- Process a wxEVT_COMMAND_RIGHT_CLICK command, which is generated by a control (Windows 95 and NT only).
+ Process a @c wxEVT_COMMAND_RIGHT_CLICK command, which is generated by a control (wxMSW only).
@event{EVT_COMMAND_SET_FOCUS(id, func)}
- Process a wxEVT_COMMAND_SET_FOCUS command, which is generated by a control (Windows 95 and NT only).
+ Process a @c wxEVT_COMMAND_SET_FOCUS command, which is generated by a control (wxMSW only).
@event{EVT_COMMAND_KILL_FOCUS(id, func)}
- Process a wxEVT_COMMAND_KILL_FOCUS command, which is generated by a control (Windows 95 and NT only).
+ Process a @c wxEVT_COMMAND_KILL_FOCUS command, which is generated by a control (wxMSW only).
@event{EVT_COMMAND_ENTER(id, func)}
- Process a wxEVT_COMMAND_ENTER command, which is generated by a control.
+ Process a @c wxEVT_COMMAND_ENTER command, which is generated by a control.
@endEventTable
@library{wxcore}
/**
Constructor.
*/
- wxCommandEvent(wxEventType commandEventType = 0, int id = 0);
+ wxCommandEvent(wxEventType commandEventType = wxEVT_NULL, int id = 0);
/**
Returns client data pointer for a listbox or choice selection event
-/**
- Indicates how a wxHelpEvent was generated.
-*/
enum wxHelpEventOrigin
{
- wxHE_ORIGIN_UNKNOWN = -1, /**< unrecognized event source. */
- wxHE_ORIGIN_KEYBOARD, /**< event generated from F1 key press. */
+ wxHE_ORIGIN_UNKNOWN = -1,
+ wxHE_ORIGIN_KEYBOARD,
/** event generated by wxContextHelp or from the [?] button on
the title bar (Windows). */
class wxHelpEvent : public wxCommandEvent
{
public:
+ /**
+ Indicates how a wxHelpEvent was generated.
+ */
+ enum Origin
+ {
+ Origin_Unknown, /**< unrecognized event source. */
+ Origin_Keyboard, /**< event generated from F1 key press. */
+
+ /** event generated by wxContextHelp or from the [?] button on
+ the title bar (Windows). */
+ Origin_HelpButton
+ };
+
/**
Constructor.
*/
wxHelpEvent(wxEventType type = wxEVT_NULL,
wxWindowID winid = 0,
const wxPoint& pt = wxDefaultPosition,
- wxHelpEventOrigin origin = wxHE_ORIGIN_UNKNOWN);
+ wxHelpEvent::Origin origin = Origin_Unknown);
/**
Returns the origin of the help event which is one of the ::wxHelpEventOrigin
@see SetOrigin()
*/
- wxHelpEventOrigin GetOrigin() const;
+ wxHelpEvent::Origin GetOrigin() const;
/**
Returns the left-click position of the mouse, in screen coordinates.
@see GetOrigin()
*/
- void SetOrigin(wxHelpEventOrigin);
+ void SetOrigin(wxHelpEvent::Origin origin);
/**
Sets the left-click position of the mouse, in screen coordinates.
This allows the wxWindow::Close function to return @true or @false depending
on whether the close instruction was honoured or not.
+ Example of a wxCloseEvent handler:
+
+ @code
+ void MyFrame::OnClose(wxCloseEvent& event)
+ {
+ if ( event.CanVeto() && m_bFileNotSaved )
+ {
+ if ( wxMessageBox("The file has not been saved... continue closing?",
+ "Please confirm",
+ wxICON_QUESTION | wxYES_NO) != wxYES )
+ {
+ event.Veto();
+ return;
+ }
+ }
+
+ Destroy(); // you may also do: event.Skip();
+ // since the default event handler does call Destroy(), too
+ }
+ @endcode
+
The EVT_END_SESSION event is slightly different as it is sent by the system
when the user session is ending (e.g. because of log out or shutdown) and
so all windows are being forcefully closed. At least under MSW, after the
these do not include menu command events, which are
handled using wxCommandEvent objects.
- The default handler for wxEVT_MENU_HIGHLIGHT displays help
+ The default handler for @c wxEVT_MENU_HIGHLIGHT displays help
text in the first field of the status bar.
@beginEventTable{wxMenuEvent}
// Global functions/macros
// ============================================================================
-/** @ingroup group_funcmacro_misc */
+/** @ingroup group_funcmacro_events */
//@{
+/**
+ Each wxEvent-derived class has an @e event-type associated.
+ See the macro DEFINE_EVENT_TYPE() for more info.
+
+ @see @ref overview_eventhandling_custom
+*/
+typedef int wxEventType;
+
+/**
+ Initializes a new event type using wxNewEventType().
+*/
+#define DEFINE_EVENT_TYPE(name) const wxEventType name = wxNewEventType();
+
+/**
+ Generates a new unique event type.
+*/
+wxEventType wxNewEventType();
+
+/**
+ Use this macro inside a class declaration to declare a @e static event table
+ for that class.
+
+ In the implementation file you'll need to use the BEGIN_EVENT_TABLE()
+ and the END_EVENT_TABLE() macros, plus some additional @c EVT_xxx macro
+ to capture events.
+
+ @see @ref overview_eventhandling_eventtables
+*/
+#define DECLARE_EVENT_TABLE()
+
+/**
+ Use this macro in a source file to start listing @e static event handlers
+ for a specific class.
+
+ Use END_EVENT_TABLE() to terminate the event-declaration block.
+
+ @see @ref overview_eventhandling_eventtables
+*/
+#define BEGIN_EVENT_TABLE(theClass, baseClass)
+
+/**
+ Use this macro in a source file to end listing @e static event handlers
+ for a specific class.
+
+ Use BEGIN_EVENT_TABLE() to start the event-declaration block.
+
+ @see @ref overview_eventhandling_eventtables
+*/
+#define END_EVENT_TABLE()
+
/**
In a GUI application, this function posts @a event to the specified @e dest
object using wxEvtHandler::AddPendingEvent().