]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxGetMouseState which returns the current state of the mouse.
authorRobin Dunn <robin@alldunn.com>
Thu, 5 Jan 2006 04:31:27 +0000 (04:31 +0000)
committerRobin Dunn <robin@alldunn.com>
Thu, 5 Jan 2006 04:31:27 +0000 (04:31 +0000)
Returns an instance of a wxMouseState object that contains the current
position of the mouse pointer in screen coordinants, as well as
boolean values indicating the up/down status of the mouse buttons and
the modifier keys.  Implemented for wxMSW, wxGTK and wxMac.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36691 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
docs/latex/wx/function.tex
include/wx/utils.h
src/gtk/window.cpp
src/gtk1/window.cpp
src/mac/carbon/app.cpp
src/msw/window.cpp

index 92eb3d4dc479b9c684711d20780e58bf9b2b5deb..81898ce7fc2f36bb9aff836a343be87fc113fa36 100644 (file)
@@ -51,6 +51,7 @@ All (GUI):
 - Implemented <sub> and <sup> handling in wxHTML (based on patch
   by Sandro Sigala)
 - Added caption parameter to wxGetFontFromUser and wxGetColourFromUser.
+- Added wxGetMouseState function.
 
 wxMSW:
 
index cc3f336e885d5ff39a6923b7f4be48522994d924..9b71dc053296825a1661316b8cd85d8b023128ee 100644 (file)
@@ -128,6 +128,7 @@ the corresponding topic.
 \helpref{wxGetLocalTimeMillis}{wxgetlocaltimemillis}\\
 \helpref{wxGetLocalTime}{wxgetlocaltime}\\
 \helpref{wxGetMousePosition}{wxgetmouseposition}\\
+\helpref{wxGetMouseState}{wxgetmousestate}\\
 \helpref{wxGetMultipleChoices}{wxgetmultiplechoices}\\
 \helpref{wxGetMultipleChoice}{wxgetmultiplechoice}\\
 \helpref{wxGetNumberFromUser}{wxgetnumberfromuser}\\
@@ -3009,6 +3010,55 @@ Returns the mouse position in screen coordinates.
 <wx/utils.h>
 
 
+\membersection{::wxGetMouseState}\label{wxgetmousestate}
+
+\func{wxMouseState}{wxGetMouseState}{\void}
+
+Returns the current state of the mouse.  Returns a wxMouseState
+instance that contains the current position of the mouse pointer in
+screen coordinants, as well as boolean values indicating the up/down
+status of the mouse buttons and the modifier keys.
+
+\wxheading{Include files}
+
+<wx/utils.h>
+
+wxMouseState has the following interface:
+
+\begin{verbatim}
+class wxMouseState
+{
+public:
+    wxMouseState();
+
+    wxCoord     GetX();
+    wxCoord     GetY();
+
+    bool        LeftDown();
+    bool        MiddleDown();
+    bool        RightDown();
+
+    bool        ControlDown();
+    bool        ShiftDown();
+    bool        AltDown();
+    bool        MetaDown();
+    bool        CmdDown();
+
+    void        SetX(wxCoord x);
+    void        SetY(wxCoord y);
+
+    void        SetLeftDown(bool down);
+    void        SetMiddleDown(bool down);
+    void        SetRightDown(bool down);
+    
+    void        SetControlDown(bool down);
+    void        SetShiftDown(bool down);
+    void        SetAltDown(bool down);
+    void        SetMetaDown(bool down);
+};
+\end{verbatim}
+
+
 \membersection{::wxGetResource}\label{wxgetresource}
 
 \func{bool}{wxGetResource}{\param{const wxString\& }{section}, \param{const wxString\& }{entry},
index 03e24056b0d6b7560d24864c64f1ba7ba11d7c38..517385f7b7dd210c5b525495f1a77a5e6332f80f 100644 (file)
@@ -114,6 +114,70 @@ WXDLLEXPORT bool wxGetKeyState(wxKeyCode key);
 // in wxMSW.
 WXDLLEXPORT bool wxSetDetectableAutoRepeat( bool flag );
 
+
+// wxMouseState is used to hold information about button and modifier state
+// and is what is returned from wxGetMouseState.
+class WXDLLEXPORT wxMouseState
+{
+public:
+    wxMouseState()
+        : m_x(0), m_y(0),
+          m_leftDown(false), m_middleDown(false), m_rightDown(false),
+          m_controlDown(false), m_shiftDown(false), m_altDown(false),
+          m_metaDown(false)
+    {}
+
+    wxCoord     GetX() { return m_x; }
+    wxCoord     GetY() { return m_y; }
+
+    bool        LeftDown()    { return m_leftDown; }
+    bool        MiddleDown()  { return m_middleDown; }
+    bool        RightDown()   { return m_rightDown; }
+    
+    bool        ControlDown() { return m_controlDown; }
+    bool        ShiftDown()   { return m_shiftDown; }
+    bool        AltDown()     { return m_altDown; }
+    bool        MetaDown()    { return m_metaDown; }
+    bool        CmdDown() 
+    {
+#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        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;
+    wxCoord     m_y;
+
+    bool        m_leftDown;
+    bool        m_middleDown;
+    bool        m_rightDown;
+
+    bool        m_controlDown;
+    bool        m_shiftDown;
+    bool        m_altDown;
+    bool        m_metaDown;
+};
+
+
+// Returns the current state of the mouse position, buttons and modifers
+WXDLLEXPORT wxMouseState wxGetMouseState();
+
+
 // ----------------------------------------------------------------------------
 // Window ID management
 // ----------------------------------------------------------------------------
index 1e9038e20aa76953e0fff90d58e6308fb7fa21a6..d27d7d642bb4e35fea1a88643742c65568c694f0 100644 (file)
@@ -2672,6 +2672,31 @@ wxWindow *wxGetActiveWindow()
     return wxWindow::FindFocus();
 }
 
+
+wxMouseState wxGetMouseState()
+{
+    wxMouseState ms;
+
+    gint x;
+    gint y;
+    GdkModifierType mask;
+
+    gdk_window_get_pointer(NULL, &x, &y, &mask);
+
+    ms.SetX(x);
+    ms.SetY(y);
+    ms.SetLeftDown(mask & GDK_BUTTON1_MASK);
+    ms.SetMiddleDown(mask & GDK_BUTTON2_MASK);
+    ms.SetRightDown(mask & GDK_BUTTON3_MASK);
+
+    ms.SetControlDown(mask & GDK_CONTROL_MASK);
+    ms.SetShiftDown(mask & GDK_SHIFT_MASK);
+    ms.SetAltDown(mask & GDK_MOD1_MASK);
+    ms.SetMetaDown(mask & GDK_MOD2_MASK);
+    
+    return ms;
+}
 //-----------------------------------------------------------------------------
 // wxWindowGTK
 //-----------------------------------------------------------------------------
index 1e9038e20aa76953e0fff90d58e6308fb7fa21a6..d27d7d642bb4e35fea1a88643742c65568c694f0 100644 (file)
@@ -2672,6 +2672,31 @@ wxWindow *wxGetActiveWindow()
     return wxWindow::FindFocus();
 }
 
+
+wxMouseState wxGetMouseState()
+{
+    wxMouseState ms;
+
+    gint x;
+    gint y;
+    GdkModifierType mask;
+
+    gdk_window_get_pointer(NULL, &x, &y, &mask);
+
+    ms.SetX(x);
+    ms.SetY(y);
+    ms.SetLeftDown(mask & GDK_BUTTON1_MASK);
+    ms.SetMiddleDown(mask & GDK_BUTTON2_MASK);
+    ms.SetRightDown(mask & GDK_BUTTON3_MASK);
+
+    ms.SetControlDown(mask & GDK_CONTROL_MASK);
+    ms.SetShiftDown(mask & GDK_SHIFT_MASK);
+    ms.SetAltDown(mask & GDK_MOD1_MASK);
+    ms.SetMetaDown(mask & GDK_MOD2_MASK);
+    
+    return ms;
+}
 //-----------------------------------------------------------------------------
 // wxWindowGTK
 //-----------------------------------------------------------------------------
index 6c327441c279adfbeac37e499a53c4d4f45a9de1..e7eb2d80ea0f4fa13c033d6cee52b7d64c323f4f 100644 (file)
@@ -1499,6 +1499,29 @@ bool wxGetKeyState(wxKeyCode key) //virtual key code if < 10.2.x, else see below
 #endif
 
 
+wxMouseState wxGetMouseState()
+{
+    wxMouseState ms;
+
+    wxPoint pt = wxGetMousePosition();
+    ms.SetX(pt.x);
+    ms.SetY(pt.y);
+
+    UInt32 buttons = GetCurrentButtonState();
+    ms.SetLeftDown( (buttons & 0x01) != 0 );
+    ms.SetMiddleDown( (buttons & 0x04) != 0 );
+    ms.SetRightDown( (buttons & 0x02) != 0 );
+    
+    UInt32 modifiers = GetCurrentKeyModifiers();
+    ms.SetControlDown(modifiers & controlKey);
+    ms.SetShiftDown(modifiers & shiftKey);
+    ms.SetAltDown(modifiers & optionKey);
+    ms.SetMetaDown(modifiers & cmdKey);
+
+    return ms;
+}
+
+
 bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar )
 {
     if ( !focus )
index 07f84ec60e97565a3e689aa03ba532cef2e66fd5..2ee65a51cf292fbc70f004252e9d8d498f8723cd 100644 (file)
@@ -5390,6 +5390,28 @@ bool wxGetKeyState(wxKeyCode key)
 #endif
 }
 
+
+wxMouseState wxGetMouseState()
+{
+    wxMouseState ms;
+    POINT pt;
+    GetCursorPos( &pt );
+
+    ms.SetX(pt.x);
+    ms.SetY(pt.y);
+    ms.SetLeftDown( (GetAsyncKeyState(VK_LBUTTON) & (1<<15)) != 0 );
+    ms.SetMiddleDown( (GetAsyncKeyState(VK_MBUTTON) & (1<<15)) != 0 );
+    ms.SetRightDown( (GetAsyncKeyState(VK_RBUTTON) & (1<<15)) != 0 );
+    
+    ms.SetControlDown( (GetAsyncKeyState(VK_CONTROL) & (1<<15)) != 0 );
+    ms.SetShiftDown( (GetAsyncKeyState(VK_SHIFT) & (1<<15)) != 0 );
+    ms.SetAltDown( (GetAsyncKeyState(VK_MENU) & (1<<15)) != 0 );
+//    ms.SetMetaDown();
+    
+    return ms;
+}
+
+
 wxWindow *wxGetActiveWindow()
 {
     HWND hWnd = GetActiveWindow();