make wxKeyEvent and wxMouseEvent derive from the same wxKeyboardState object (indirectly via wxMouseState in the case of the latter) to make Get/HasModifiers() available in wxMouseEvent as well while avoiding code duplication
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55745 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -698,10 +698,13 @@ public:
|
||||
Process a wxEVT_CHAR event.
|
||||
@endEventTable
|
||||
|
||||
@see wxKeyboardState
|
||||
|
||||
@library{wxcore}
|
||||
@category{events}
|
||||
*/
|
||||
class wxKeyEvent : public wxEvent
|
||||
class wxKeyEvent : public wxEvent,
|
||||
public wxKeyboardState
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -710,32 +713,6 @@ public:
|
||||
*/
|
||||
wxKeyEvent(wxEventType keyEventType = wxEVT_NULL);
|
||||
|
||||
/**
|
||||
Returns @true if the Alt key was down at the time of the key event.
|
||||
|
||||
Notice that GetModifiers() is easier to use correctly than this function
|
||||
so you should consider using it in new code.
|
||||
*/
|
||||
bool AltDown() const;
|
||||
|
||||
/**
|
||||
CMD is a pseudo key which is the same as Control for PC and Unix
|
||||
platforms but the special APPLE (a.k.a as COMMAND) key under Macs:
|
||||
it makes often sense to use it instead of, say, ControlDown() because Cmd
|
||||
key is used for the same thing under Mac as Ctrl elsewhere (but Ctrl still
|
||||
exists, just not used for this purpose under Mac). So for non-Mac platforms
|
||||
this is the same as ControlDown() and under Mac this is the same as MetaDown().
|
||||
*/
|
||||
bool CmdDown() const;
|
||||
|
||||
/**
|
||||
Returns @true if the control key was down at the time of the key event.
|
||||
|
||||
Notice that GetModifiers() is easier to use correctly than this function
|
||||
so you should consider using it in new code.
|
||||
*/
|
||||
bool ControlDown() const;
|
||||
|
||||
/**
|
||||
Returns the virtual key code. ASCII events return normal ASCII values,
|
||||
while non-ASCII events return values such as @b WXK_LEFT for the left cursor
|
||||
@@ -747,33 +724,6 @@ public:
|
||||
*/
|
||||
int GetKeyCode() const;
|
||||
|
||||
/**
|
||||
Return the bitmask of modifier keys which were pressed when this event
|
||||
happened. See @ref page_keymodifiers for the full list of modifiers.
|
||||
|
||||
Notice that this function is easier to use correctly than, for example,
|
||||
ControlDown() because when using the latter you also have to remember to
|
||||
test that none of the other modifiers is pressed:
|
||||
|
||||
@code
|
||||
if ( ControlDown() && !AltDown() && !ShiftDown() && !MetaDown() )
|
||||
... handle Ctrl-XXX ...
|
||||
@endcode
|
||||
|
||||
and forgetting to do it can result in serious program bugs (e.g. program
|
||||
not working with European keyboard layout where ALTGR key which is seen by
|
||||
the program as combination of CTRL and ALT is used). On the other hand,
|
||||
you can simply write:
|
||||
|
||||
@code
|
||||
if ( GetModifiers() == wxMOD_CONTROL )
|
||||
... handle Ctrl-XXX ...
|
||||
@endcode
|
||||
|
||||
with this function.
|
||||
*/
|
||||
int GetModifiers() const;
|
||||
|
||||
//@{
|
||||
/**
|
||||
Obtains the position (in client coordinates) at which the key was pressed.
|
||||
@@ -817,33 +767,6 @@ public:
|
||||
Returns the Y position (in client coordinates) of the event.
|
||||
*/
|
||||
wxCoord GetY() const;
|
||||
|
||||
/**
|
||||
Returns @true if either CTRL or ALT keys was down at the time of the
|
||||
key event.
|
||||
|
||||
Note that this function does not take into account neither SHIFT nor
|
||||
META key states (the reason for ignoring the latter is that it is
|
||||
common for NUMLOCK key to be configured as META under X but the key
|
||||
presses even while NUMLOCK is on should be still processed normally).
|
||||
*/
|
||||
bool HasModifiers() const;
|
||||
|
||||
/**
|
||||
Returns @true if the Meta key was down at the time of the key event.
|
||||
|
||||
Notice that GetModifiers() is easier to use correctly than this function
|
||||
so you should consider using it in new code.
|
||||
*/
|
||||
bool MetaDown() const;
|
||||
|
||||
/**
|
||||
Returns @true if the shift key was down at the time of the key event.
|
||||
|
||||
Notice that GetModifiers() is easier to use correctly than this function
|
||||
so you should consider using it in new code.
|
||||
*/
|
||||
bool ShiftDown() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -1546,9 +1469,10 @@ public:
|
||||
@library{wxcore}
|
||||
@category{events}
|
||||
|
||||
@see wxKeyEvent::CmdDown
|
||||
@see wxKeyEvent
|
||||
*/
|
||||
class wxMouseEvent : public wxEvent
|
||||
class wxMouseEvent : public wxEvent,
|
||||
public wxMouseState
|
||||
{
|
||||
public:
|
||||
/**
|
||||
@@ -1576,11 +1500,6 @@ public:
|
||||
*/
|
||||
wxMouseEvent(wxEventType mouseEventType = wxEVT_NULL);
|
||||
|
||||
/**
|
||||
Returns @true if the Alt key was down at the time of the event.
|
||||
*/
|
||||
bool AltDown() const;
|
||||
|
||||
/**
|
||||
Returns @true if the event was a first extra button double click.
|
||||
*/
|
||||
@@ -1659,18 +1578,6 @@ public:
|
||||
*/
|
||||
bool ButtonUp(int = wxMOUSE_BTN_ANY) const;
|
||||
|
||||
/**
|
||||
Same as MetaDown() under Mac, same as ControlDown() elsewhere.
|
||||
|
||||
@see wxKeyEvent::CmdDown
|
||||
*/
|
||||
bool CmdDown() const;
|
||||
|
||||
/**
|
||||
Returns @true if the control key was down at the time of the event.
|
||||
*/
|
||||
bool ControlDown() const;
|
||||
|
||||
/**
|
||||
Returns @true if this was a dragging event (motion while a button is depressed).
|
||||
|
||||
@@ -1865,11 +1772,6 @@ public:
|
||||
Returns @true if the right mouse button changed to up.
|
||||
*/
|
||||
bool RightUp() const;
|
||||
|
||||
/**
|
||||
Returns @true if the shift key was down at the time of the event.
|
||||
*/
|
||||
bool ShiftDown() const;
|
||||
};
|
||||
|
||||
|
||||
|
130
interface/wx/kbdstate.h
Normal file
130
interface/wx/kbdstate.h
Normal file
@@ -0,0 +1,130 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/kbdstate.h
|
||||
// Purpose: documentation of wxKeyboardState
|
||||
// Author: wxWidgets team
|
||||
// Created: 2008-09-19
|
||||
// RCS-ID: $Id$
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
Provides methods for testing the state of the keyboard modifier keys.
|
||||
|
||||
This class is used as a base class of wxKeyEvent and wxMouseState and,
|
||||
hence, indirectly, of wxMouseEvent, so its methods may be used to get
|
||||
information about the modifier keys which were pressed when the event
|
||||
occurred.
|
||||
|
||||
This class is implemented entirely inline in @<wx/keystate.h@> and thus has
|
||||
no linking requirements.
|
||||
|
||||
@category{misc}
|
||||
|
||||
@see wxKeyEvent, wxMouseState
|
||||
*/
|
||||
class wxKeyboardState
|
||||
{
|
||||
public:
|
||||
/**
|
||||
Default constructor.
|
||||
|
||||
By default, no modifiers are active.
|
||||
*/
|
||||
wxKeyboardState();
|
||||
|
||||
/**
|
||||
Return the bit mask of all pressed modifier keys.
|
||||
|
||||
The return value is a combination of @c wxMOD_ALT, @c wxMOD_CONTROL,
|
||||
@c wxMOD_SHIFT and @c wxMOD_META bit masks. Additionally, @c wxMOD_NONE
|
||||
is defined as 0, i.e. corresponds to no modifiers (see HasModifiers())
|
||||
and @c wxMOD_CMD is either @c wxMOD_CONTROL (MSW and Unix) or @c
|
||||
wxMOD_META (Mac), see CmdDown(). See @ref page_keymodifiers for the
|
||||
full list of modifiers.
|
||||
|
||||
Notice that this function is easier to use correctly than, for example,
|
||||
ControlDown() because when using the latter you also have to remember to
|
||||
test that none of the other modifiers is pressed:
|
||||
|
||||
@code
|
||||
if ( ControlDown() && !AltDown() && !ShiftDown() && !MetaDown() )
|
||||
... handle Ctrl-XXX ...
|
||||
@endcode
|
||||
|
||||
and forgetting to do it can result in serious program bugs (e.g. program
|
||||
not working with European keyboard layout where @c AltGr key which is
|
||||
seen by the program as combination of CTRL and ALT is used). On the
|
||||
other hand, you can simply write:
|
||||
|
||||
@code
|
||||
if ( GetModifiers() == wxMOD_CONTROL )
|
||||
... handle Ctrl-XXX ...
|
||||
@endcode
|
||||
|
||||
with this function.
|
||||
*/
|
||||
int GetModifiers() const;
|
||||
|
||||
/**
|
||||
Returns true if any modifiers at all are pressed.
|
||||
|
||||
This is equivalent to @c GetModifiers() @c != @c wxMOD_NONE.
|
||||
*/
|
||||
bool HasModifiers() const;
|
||||
|
||||
/**
|
||||
Returns true if the Control key is pressed.
|
||||
|
||||
This function doesn't distinguish between right and left control keys.
|
||||
|
||||
In portable code you usually want to use CmdDown() to automatically
|
||||
test for the more frequently used Command key (and not the rarely used
|
||||
Control one) under Mac.
|
||||
|
||||
Notice that GetModifiers() should usually be used instead of this one.
|
||||
*/
|
||||
bool ControlDown() const;
|
||||
|
||||
/**
|
||||
Returns true if the Shift key is pressed.
|
||||
|
||||
This function doesn't distinguish between right and left shift keys.
|
||||
|
||||
Notice that GetModifiers() should usually be used instead of this one.
|
||||
*/
|
||||
bool ShiftDown() const;
|
||||
|
||||
/**
|
||||
Returns true if the Meta/Windows/Apple key is pressed.
|
||||
|
||||
This function tests the state of the key traditionally called Meta
|
||||
under Unix systems, Windows keys under MSW and Apple, or Command, key
|
||||
under Mac.
|
||||
|
||||
Notice that GetModifiers() should usually be used instead of this one.
|
||||
|
||||
@see CmdDown()
|
||||
*/
|
||||
bool MetaDown() const;
|
||||
|
||||
/**
|
||||
Returns true if the Alt key is pressed.
|
||||
|
||||
Notice that GetModifiers() should usually be used instead of this one.
|
||||
*/
|
||||
bool AltDown() const;
|
||||
|
||||
/**
|
||||
Returns true if the key used for command accelerators is pressed.
|
||||
|
||||
@c Cmd is a pseudo key which is Control for PC and Unix platforms but
|
||||
Apple (or Command) key under Macs: it makes often sense to use it
|
||||
instead of ControlDown() because @c Command key is used for the same
|
||||
thing under Mac as @c Control elsewhere (even though @c Control still
|
||||
exists, it is usually not used for the same purpose under Mac).
|
||||
|
||||
Notice that GetModifiers() should usually be used instead of this one.
|
||||
*/
|
||||
bool CmdDown() const;
|
||||
};
|
||||
|
71
interface/wx/mousestate.h
Normal file
71
interface/wx/mousestate.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/mousestate.h
|
||||
// Purpose: documentation of wxMouseState
|
||||
// Author: wxWidgets team
|
||||
// Created: 2008-09-19
|
||||
// RCS-ID: $Id$
|
||||
// Licence: wxWindows license
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
@class wxMouseState
|
||||
|
||||
Represents the mouse state.
|
||||
|
||||
This class is used as a base class by wxMouseEvent and so its methods may
|
||||
be used to obtain information about the mouse state for the mouse events.
|
||||
It also inherits from wxKeyboardState and so carries information about the
|
||||
keyboard state and not only the mouse one.
|
||||
|
||||
This class is implemented entirely inline in @<wx/mousestate.h@> and thus
|
||||
has no linking requirements.
|
||||
|
||||
@category{misc}
|
||||
|
||||
@see wxGetMouseState(), wxMouseEvent
|
||||
*/
|
||||
class wxMouseState : public wxKeyboardState
|
||||
{
|
||||
public:
|
||||
/**
|
||||
Default constructor.
|
||||
*/
|
||||
wxMouseState();
|
||||
|
||||
/**
|
||||
Returns X coordinate of the physical mouse event position.
|
||||
*/
|
||||
wxCoord GetX() const;
|
||||
/**
|
||||
Returns Y coordinate of the physical mouse event position.
|
||||
*/
|
||||
wxCoord GetY() const;
|
||||
/**
|
||||
Returns the physical mouse position.
|
||||
*/
|
||||
wxPoint GetPosition() const;
|
||||
|
||||
/**
|
||||
Returns @true if the left mouse button changed to down.
|
||||
*/
|
||||
bool LeftDown() const;
|
||||
/**
|
||||
Returns @true if the middle mouse button changed to down.
|
||||
*/
|
||||
bool MiddleDown() const;
|
||||
/**
|
||||
Returns @true if the right mouse button changed to down.
|
||||
*/
|
||||
bool RightDown() const;
|
||||
/**
|
||||
Returns @true if the first extra button mouse button changed to down.
|
||||
*/
|
||||
bool Aux1Down() const;
|
||||
/**
|
||||
Returns @true if the second extra button mouse button changed to down.
|
||||
*/
|
||||
bool Aux2Down() const;
|
||||
};
|
||||
|
||||
|
@@ -88,86 +88,6 @@ public:
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@class wxMouseState
|
||||
|
||||
Represents the mouse state.
|
||||
|
||||
The methods of this class generally mirror the corresponding methods of
|
||||
wxMouseEvent.
|
||||
|
||||
This class is implemented entirely in @<wx/utils.h@>, meaning no extra
|
||||
library needs to be linked to use this class.
|
||||
|
||||
@category{misc}
|
||||
|
||||
@see wxGetMouseState()
|
||||
*/
|
||||
class wxMouseState
|
||||
{
|
||||
public:
|
||||
/**
|
||||
Default constructor.
|
||||
*/
|
||||
wxMouseState();
|
||||
|
||||
/**
|
||||
Returns X coordinate of the physical mouse event position.
|
||||
*/
|
||||
wxCoord GetX() const;
|
||||
/**
|
||||
Returns Y coordinate of the physical mouse event position.
|
||||
*/
|
||||
wxCoord GetY() const;
|
||||
/**
|
||||
Returns the physical mouse position.
|
||||
*/
|
||||
wxPoint GetPosition() const;
|
||||
|
||||
/**
|
||||
Returns @true if the left mouse button changed to down.
|
||||
*/
|
||||
bool LeftDown() const;
|
||||
/**
|
||||
Returns @true if the middle mouse button changed to down.
|
||||
*/
|
||||
bool MiddleDown() const;
|
||||
/**
|
||||
Returns @true if the right mouse button changed to down.
|
||||
*/
|
||||
bool RightDown() const;
|
||||
/**
|
||||
Returns @true if the first extra button mouse button changed to down.
|
||||
*/
|
||||
bool Aux1Down() const;
|
||||
/**
|
||||
Returns @true if the second extra button mouse button changed to down.
|
||||
*/
|
||||
bool Aux2Down() const;
|
||||
|
||||
/**
|
||||
Returns @true if the control key is down.
|
||||
*/
|
||||
bool ControlDown() const;
|
||||
/**
|
||||
Returns @true if the shift key is down.
|
||||
*/
|
||||
bool ShiftDown() const;
|
||||
/**
|
||||
Returns @true if the alt key is down.
|
||||
*/
|
||||
bool AltDown() const;
|
||||
/**
|
||||
Returns @true if the meta key is down.
|
||||
*/
|
||||
bool MetaDown() const;
|
||||
/**
|
||||
Same as MetaDown() under Mac systems, ControlDown() for the others.
|
||||
*/
|
||||
bool CmdDown() const;
|
||||
};
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// Global functions/macros
|
||||
// ============================================================================
|
||||
|
Reference in New Issue
Block a user