]> git.saurik.com Git - wxWidgets.git/commitdiff
make wxKeyEvent and wxMouseEvent derive from the same wxKeyboardState object (indirec...
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 19 Sep 2008 18:41:41 +0000 (18:41 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 19 Sep 2008 18:41:41 +0000 (18:41 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55745 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/event.h
include/wx/kbdstate.h [new file with mode: 0644]
include/wx/mousestate.h [new file with mode: 0644]
include/wx/utils.h
interface/wx/event.h
interface/wx/kbdstate.h [new file with mode: 0644]
interface/wx/mousestate.h [new file with mode: 0644]
interface/wx/utils.h
src/common/event.cpp

index 707702b92a8ed0b7c50e7dfad1ffab3113910022..52b6591de3f2da9b268d18e90a908af22fa6dbc1 100644 (file)
@@ -392,6 +392,7 @@ All (GUI):
 - wxWindow::IsBeingDeleted() now returns true not only if the window itself is
   marked for destruction but also if any of its parent windows are.
 - Improved drawing of the hint during column move in wxGrid.
+- Get/HasModifiers() of wxKeyEvent are now also available in wxMouseEvent.
 
 wxGTK:
 
index 684d6724197f83de0f1a6a1c3224c7497d66723b..da1de711aa7ca1d8af57b2d8f3a249657a220912 100644 (file)
@@ -20,6 +20,7 @@
 #if wxUSE_GUI
     #include "wx/gdicmn.h"
     #include "wx/cursor.h"
+    #include "wx/mousestate.h"
 #endif
 
 #include "wx/dynarray.h"
@@ -295,12 +296,6 @@ enum Propagation_state
 
 class WXDLLIMPEXP_BASE wxEvent : public wxObject
 {
-private:
-    wxEvent& operator=(const wxEvent&);
-
-protected:
-    wxEvent(const wxEvent&);                   // for implementing Clone()
-
 public:
     wxEvent(int winid = 0, wxEventType commandType = wxEVT_NULL );
 
@@ -367,10 +362,13 @@ protected:
     // backwards compatibility as it is new
     int               m_propagationLevel;
 
-protected:
     bool              m_skipped;
     bool              m_isCommandEvent;
 
+protected:
+    wxEvent(const wxEvent&);            // for implementing Clone()
+    wxEvent& operator=(const wxEvent&); // for derived classes operator=()
+
 private:
     // it needs to access our m_propagationLevel
     friend class WXDLLIMPEXP_FWD_BASE wxPropagateOnce;
@@ -644,12 +642,17 @@ enum
     wxMOUSE_BTN_MAX
 };
 
-class WXDLLIMPEXP_CORE wxMouseEvent : public wxEvent
+class WXDLLIMPEXP_CORE wxMouseEvent : public wxEvent,
+                                      public wxMouseState
 {
 public:
     wxMouseEvent(wxEventType mouseType = wxEVT_NULL);
-    wxMouseEvent(const wxMouseEvent& event) : wxEvent(event)
-        { Assign(event); }
+    wxMouseEvent(const wxMouseEvent& event)
+        : wxEvent(event),
+          wxMouseState(event)
+    {
+        Assign(event);
+    }
 
     // Was it a button event? (*doesn't* mean: is any button *down*?)
     bool IsButton() const { return Button(wxMOUSE_BTN_ANY); }
@@ -672,20 +675,6 @@ public:
     // Get the button which is changing state (wxMOUSE_BTN_NONE if none)
     int GetButton() const;
 
-    // Find state of shift/control keys
-    bool ControlDown() const { return m_controlDown; }
-    bool MetaDown() const { return m_metaDown; }
-    bool AltDown() const { return m_altDown; }
-    bool ShiftDown() const { return m_shiftDown; }
-    bool CmdDown() const
-    {
-#if defined(__WXMAC__) || defined(__WXCOCOA__)
-        return MetaDown();
-#else
-        return ControlDown();
-#endif
-    }
-
     // Find which event was just generated
     bool LeftDown() const { return (m_eventType == wxEVT_LEFT_DOWN); }
     bool MiddleDown() const { return (m_eventType == wxEVT_MIDDLE_DOWN); }
@@ -792,7 +781,12 @@ public:
 
     virtual wxEvent *Clone() const { return new wxMouseEvent(*this); }
 
-    wxMouseEvent& operator=(const wxMouseEvent& event) { if (&event != this) Assign(event); return *this; }
+    wxMouseEvent& operator=(const wxMouseEvent& event)
+    {
+        if (&event != this)
+            Assign(event);
+        return *this;
+    }
 
 public:
     wxCoord m_x, m_y;
@@ -803,11 +797,6 @@ public:
     bool          m_aux1Down;
     bool          m_aux2Down;
 
-    bool          m_controlDown;
-    bool          m_shiftDown;
-    bool          m_altDown;
-    bool          m_metaDown;
-
     int           m_clickCount;
 
     int           m_wheelAxis;
@@ -870,48 +859,13 @@ private:
  wxEVT_HOTKEY
  */
 
-class WXDLLIMPEXP_CORE wxKeyEvent : public wxEvent
+class WXDLLIMPEXP_CORE wxKeyEvent : public wxEvent,
+                                    public wxKeyboardState
 {
 public:
     wxKeyEvent(wxEventType keyType = wxEVT_NULL);
     wxKeyEvent(const wxKeyEvent& evt);
 
-    // can be used check if the key event has exactly the given modifiers:
-    // "GetModifiers() = wxMOD_CONTROL" is easier to write than "ControlDown()
-    // && !MetaDown() && !AltDown() && !ShiftDown()"
-    int GetModifiers() const
-    {
-        return (m_controlDown ? wxMOD_CONTROL : 0) |
-               (m_shiftDown ? wxMOD_SHIFT : 0) |
-               (m_metaDown ? wxMOD_META : 0) |
-               (m_altDown ? wxMOD_ALT : 0);
-    }
-
-    // Find state of shift/control keys
-    bool ControlDown() const { return m_controlDown; }
-    bool ShiftDown() const { return m_shiftDown; }
-    bool MetaDown() const { return m_metaDown; }
-    bool AltDown() const { return m_altDown; }
-
-    // "Cmd" is a pseudo key which is Control for PC and Unix platforms but
-    // Apple ("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)
-    bool CmdDown() const
-    {
-#if defined(__WXMAC__) || defined(__WXCOCOA__)
-        return MetaDown();
-#else
-        return ControlDown();
-#endif
-    }
-
-    // exclude MetaDown() from HasModifiers() because NumLock under X is often
-    // configured as mod2 modifier, yet the key events even when it is pressed
-    // should be processed normally, not like Ctrl- or Alt-key
-    bool HasModifiers() const { return ControlDown() || AltDown(); }
-
     // get the key code: an ASCII7 char or an element of wxKeyCode enum
     int GetKeyCode() const { return (int)m_keyCode; }
 
@@ -956,15 +910,14 @@ public:
     {
         if (&evt != this)
         {
+            wxEvent::operator=(evt);
+            wxKeyboardState::operator=(evt);
+
             m_x = evt.m_x;
             m_y = evt.m_y;
 
             m_keyCode = evt.m_keyCode;
 
-            m_controlDown = evt.m_controlDown;
-            m_shiftDown = evt.m_shiftDown;
-            m_altDown = evt.m_altDown;
-            m_metaDown = evt.m_metaDown;
             m_scanCode = evt.m_scanCode;
             m_rawCode = evt.m_rawCode;
             m_rawFlags = evt.m_rawFlags;
@@ -980,12 +933,6 @@ public:
 
     long          m_keyCode;
 
-    // TODO: replace those with a single m_modifiers bitmask of wxMOD_XXX?
-    bool          m_controlDown;
-    bool          m_shiftDown;
-    bool          m_altDown;
-    bool          m_metaDown;
-
     // FIXME: what is this for? relation to m_rawXXX?
     bool          m_scanCode;
 
diff --git a/include/wx/kbdstate.h b/include/wx/kbdstate.h
new file mode 100644 (file)
index 0000000..b3a44e8
--- /dev/null
@@ -0,0 +1,91 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        wx/kbdstate.h
+// Purpose:     Declaration of wxKeyboardState class
+// Author:      Vadim Zeitlin
+// Created:     2008-09-19
+// RCS-ID:      $Id$
+// Copyright:   (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
+// Licence:     wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_KBDSTATE_H_
+#define _WX_KBDSTATE_H_
+
+#include "wx/defs.h"
+
+// ----------------------------------------------------------------------------
+// wxKeyboardState stores the state of the keyboard modifier keys
+// ----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_CORE wxKeyboardState
+{
+public:
+    wxKeyboardState()
+        : m_controlDown(false),
+          m_shiftDown(false),
+          m_altDown(false),
+          m_metaDown(false)
+    {
+    }
+
+    // default copy ctor, assignment operator and dtor are ok
+
+
+    // accessors for the various modifier keys
+    // ---------------------------------------
+
+    // should be used check if the key event has exactly the given modifiers:
+    // "GetModifiers() = wxMOD_CONTROL" is easier to write than "ControlDown()
+    // && !MetaDown() && !AltDown() && !ShiftDown()"
+    int GetModifiers() const
+    {
+        return (m_controlDown ? wxMOD_CONTROL : 0) |
+               (m_shiftDown ? wxMOD_SHIFT : 0) |
+               (m_metaDown ? wxMOD_META : 0) |
+               (m_altDown ? wxMOD_ALT : 0);
+    }
+
+    // returns true if any modifiers at all are pressed
+    bool HasModifiers() const { return GetModifiers() != wxMOD_NONE; }
+
+    // accessors for individual modifier keys
+    bool ControlDown() const { return m_controlDown; }
+    bool ShiftDown() const { return m_shiftDown; }
+    bool MetaDown() const { return m_metaDown; }
+    bool AltDown() const { return m_altDown; }
+
+    // "Cmd" is a pseudo key which is Control for PC and Unix platforms but
+    // Apple ("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)
+    bool CmdDown() const
+    {
+#if defined(__WXMAC__) || defined(__WXCOCOA__)
+        return MetaDown();
+#else
+        return ControlDown();
+#endif
+    }
+
+    // these functions are mostly used by wxWidgets itself
+    // ---------------------------------------------------
+
+    void SetControlDown(bool down) { m_controlDown = down; }
+    void SetShiftDown(bool down)   { m_shiftDown = down; }
+    void SetAltDown(bool down)     { m_altDown = down; }
+    void SetMetaDown(bool down)    { m_metaDown = down; }
+
+
+    // for backwards compatibility with the existing code accessing these
+    // members of wxKeyEvent directly, these variables are public, however you
+    // should not use them in any new code, please use the accessors instead
+public:
+    bool m_controlDown : 1;
+    bool m_shiftDown   : 1;
+    bool m_altDown     : 1;
+    bool m_metaDown    : 1;
+};
+
+#endif // _WX_KBDSTATE_H_
+
diff --git a/include/wx/mousestate.h b/include/wx/mousestate.h
new file mode 100644 (file)
index 0000000..14a7551
--- /dev/null
@@ -0,0 +1,70 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        wx/mousestate.h
+// Purpose:     Declaration of wxMouseState class
+// Author:      Vadim Zeitlin
+// Created:     2008-09-19 (extracted from wx/utils.h)
+// RCS-ID:      $Id$
+// Copyright:   (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
+// Licence:     wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_MOUSESTATE_H_
+#define _WX_MOUSESTATE_H_
+
+#include "wx/kbdstate.h"
+
+// ----------------------------------------------------------------------------
+// wxMouseState contains the information about mouse position, buttons and also
+// key modifiers
+// ----------------------------------------------------------------------------
+
+// wxMouseState is used to hold information about button and modifier state
+// and is what is returned from wxGetMouseState.
+class WXDLLIMPEXP_CORE wxMouseState : public wxKeyboardState
+{
+public:
+    wxMouseState()
+        : m_x(0), m_y(0),
+          m_leftDown(false), m_middleDown(false), m_rightDown(false),
+          m_aux1Down(false), m_aux2Down(false)
+    {
+    }
+
+    // default copy ctor, assignment operator and dtor are ok
+
+
+    // accessors for the mouse position
+    wxCoord GetX() const { return m_x; }
+    wxCoord GetY() const { return m_y; }
+    wxPoint GetPosition() const { return wxPoint(m_x, m_y); }
+
+    // accessors for the pressed buttons
+    bool LeftDown()    const { return m_leftDown; }
+    bool MiddleDown()  const { return m_middleDown; }
+    bool RightDown()   const { return m_rightDown; }
+    bool Aux1Down()    const { return m_aux1Down; }
+    bool Aux2Down()    const { return m_aux2Down; }
+
+    // these functions are mostly used by wxWidgets itself
+    void SetX(wxCoord x) { m_x = x; }
+    void SetY(wxCoord y) { m_y = y; }
+
+    void SetLeftDown(bool down)   { m_leftDown = down; }
+    void SetMiddleDown(bool down) { m_middleDown = down; }
+    void SetRightDown(bool down)  { m_rightDown = down; }
+    void SetAux1Down(bool down)   { m_aux1Down = down; }
+    void SetAux2Down(bool down)   { m_aux2Down = down; }
+
+private:
+    bool m_leftDown   : 1;
+    bool m_middleDown : 1;
+    bool m_rightDown  : 1;
+    bool m_aux1Down   : 1;
+    bool m_aux2Down   : 1;
+
+    wxCoord m_x,
+            m_y;
+};
+
+#endif // _WX_MOUSESTATE_H_
+
index 72004ffe134c12660833d23f14f6f99eeb2a9b99..3463946de13bfcee79a5cc1dd9b724fb41594449 100644 (file)
 #include "wx/object.h"
 #include "wx/list.h"
 #include "wx/filefn.h"
+
 #if wxUSE_GUI
     #include "wx/gdicmn.h"
+    #include "wx/mousestate.h"
 #endif
 
 class WXDLLIMPEXP_FWD_BASE wxArrayString;
@@ -208,74 +210,6 @@ WXDLLIMPEXP_CORE bool wxGetKeyState(wxKeyCode key);
 // in wxMSW.
 WXDLLIMPEXP_CORE bool wxSetDetectableAutoRepeat( bool flag );
 
-
-// wxMouseState is used to hold information about button and modifier state
-// and is what is returned from wxGetMouseState.
-class WXDLLIMPEXP_CORE wxMouseState
-{
-public:
-    wxMouseState()
-        : m_x(0), m_y(0),
-          m_leftDown(false), m_middleDown(false), m_rightDown(false),
-          m_aux1Down(false), m_aux2Down(false),
-          m_controlDown(false), m_shiftDown(false), m_altDown(false),
-          m_metaDown(false)
-    {}
-
-    wxCoord GetX() const { return m_x; }
-    wxCoord GetY() const { return m_y; }
-    wxPoint GetPosition() const { return wxPoint(m_x, m_y); }
-
-    bool LeftDown()    const { return m_leftDown; }
-    bool MiddleDown()  const { return m_middleDown; }
-    bool RightDown()   const { return m_rightDown; }
-    bool Aux1Down()    const { return m_aux1Down; }
-    bool Aux2Down()    const { return m_aux2Down; }
-
-    bool ControlDown() const { return m_controlDown; }
-    bool ShiftDown()   const { return m_shiftDown; }
-    bool AltDown()     const { return m_altDown; }
-    bool MetaDown()    const { return m_metaDown; }
-    bool CmdDown() const
-    {
-#if defined(__WXMAC__) || defined(__WXCOCOA__)
-        return MetaDown();
-#else
-        return ControlDown();
-#endif
-    }
-
-    void SetX(wxCoord x) { m_x = x; }
-    void SetY(wxCoord y) { m_y = y; }
-
-    void SetLeftDown(bool down)   { m_leftDown = down; }
-    void SetMiddleDown(bool down) { m_middleDown = down; }
-    void SetRightDown(bool down)  { m_rightDown = down; }
-    void SetAux1Down(bool down)   { m_aux1Down = down; }
-    void SetAux2Down(bool down)   { m_aux2Down = down; }
-
-    void SetControlDown(bool down) { m_controlDown = down; }
-    void SetShiftDown(bool down)   { m_shiftDown = down; }
-    void SetAltDown(bool down)     { m_altDown = down; }
-    void SetMetaDown(bool down)    { m_metaDown = down; }
-
-private:
-    wxCoord m_x,
-            m_y;
-
-    bool m_leftDown     : 1;
-    bool m_middleDown   : 1;
-    bool m_rightDown    : 1;
-    bool m_aux1Down     : 1;
-    bool m_aux2Down     : 1;
-
-    bool m_controlDown  : 1;
-    bool m_shiftDown    : 1;
-    bool m_altDown      : 1;
-    bool m_metaDown     : 1;
-};
-
-
 // Returns the current state of the mouse position, buttons and modifers
 WXDLLIMPEXP_CORE wxMouseState wxGetMouseState();
 
index c77e48c49b89497b17ec724cc6c6b189a382505b..eb776912fea0de60918e12c130049aa1a32c8902 100644 (file)
@@ -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;
 };
 
 
diff --git a/interface/wx/kbdstate.h b/interface/wx/kbdstate.h
new file mode 100644 (file)
index 0000000..9a99a7c
--- /dev/null
@@ -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;
+};
+
diff --git a/interface/wx/mousestate.h b/interface/wx/mousestate.h
new file mode 100644 (file)
index 0000000..0632791
--- /dev/null
@@ -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;
+};
+
+
index aec4146a6790be581fd497380172469a6e33f7ff..e15454fc62f5b8081c04c14cf1a096df2739978e 100644 (file)
@@ -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
 // ============================================================================
index 9e8fbdf5086fb10d8af4ad286e735b532ac11e6c..63b0d382c1ce9323b784512433dc1cd34a983237 100644 (file)
@@ -368,7 +368,7 @@ wxEvent::wxEvent(int theId, wxEventType commandType )
     m_propagationLevel = wxEVENT_PROPAGATE_NONE;
 }
 
-wxEvent::wxEvent(const wxEvent &src)
+wxEvent::wxEvent(const wxEventsrc)
     : wxObject(src)
     , m_eventObject(src.m_eventObject)
     , m_eventType(src.m_eventType)
@@ -381,6 +381,22 @@ wxEvent::wxEvent(const wxEvent &src)
 {
 }
 
+wxEvent& wxEvent::operator=(const wxEvent& src)
+{
+    wxObject::operator=(src);
+
+    m_eventObject = src.m_eventObject;
+    m_eventType = src.m_eventType;
+    m_timeStamp = src.m_timeStamp;
+    m_id = src.m_id;
+    m_callbackUserData = src.m_callbackUserData;
+    m_propagationLevel = src.m_propagationLevel;
+    m_skipped = src.m_skipped;
+    m_isCommandEvent = src.m_isCommandEvent;
+
+    return *this;
+}
+
 #endif // wxUSE_BASE
 
 #if wxUSE_GUI
@@ -534,11 +550,6 @@ wxMouseEvent::wxMouseEvent(wxEventType commandType)
     m_aux1Down = false;
     m_aux2Down = false;
 
-    m_controlDown = false;
-    m_shiftDown = false;
-    m_altDown = false;
-    m_metaDown = false;
-
     m_clickCount = -1;
 
     m_wheelRotation = 0;
@@ -549,7 +560,8 @@ wxMouseEvent::wxMouseEvent(wxEventType commandType)
 
 void wxMouseEvent::Assign(const wxMouseEvent& event)
 {
-    m_eventType = event.m_eventType;
+    wxEvent::operator=(event);
+    wxMouseState::operator=(event);
 
     m_x = event.m_x;
     m_y = event.m_y;
@@ -560,11 +572,6 @@ void wxMouseEvent::Assign(const wxMouseEvent& event)
     m_aux1Down = event.m_aux1Down;
     m_aux2Down = event.m_aux2Down;
 
-    m_controlDown = event.m_controlDown;
-    m_shiftDown = event.m_shiftDown;
-    m_altDown = event.m_altDown;
-    m_metaDown = event.m_metaDown;
-
     m_wheelRotation = event.m_wheelRotation;
     m_wheelDelta = event.m_wheelDelta;
     m_linesPerAction = event.m_linesPerAction;
@@ -749,10 +756,6 @@ wxPoint wxMouseEvent::GetLogicalPosition(const wxDC& dc) const
 wxKeyEvent::wxKeyEvent(wxEventType type)
 {
     m_eventType = type;
-    m_shiftDown = false;
-    m_controlDown = false;
-    m_metaDown = false;
-    m_altDown = false;
     m_keyCode = 0;
     m_scanCode = 0;
 #if wxUSE_UNICODE
@@ -761,17 +764,14 @@ wxKeyEvent::wxKeyEvent(wxEventType type)
 }
 
 wxKeyEvent::wxKeyEvent(const wxKeyEvent& evt)
-    : wxEvent(evt)
+          : wxEvent(evt),
+            wxKeyboardState(evt)
 {
     m_x = evt.m_x;
     m_y = evt.m_y;
 
     m_keyCode = evt.m_keyCode;
 
-    m_controlDown = evt.m_controlDown;
-    m_shiftDown = evt.m_shiftDown;
-    m_altDown = evt.m_altDown;
-    m_metaDown = evt.m_metaDown;
     m_scanCode = evt.m_scanCode;
     m_rawCode = evt.m_rawCode;
     m_rawFlags = evt.m_rawFlags;