]>
git.saurik.com Git - wxWidgets.git/blob - src/common/mousemanager.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/mousemanager.cpp
3 // Purpose: implementation of wxMouseEventsManager class
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
27 #include "wx/settings.h"
28 #include "wx/window.h"
31 #include "wx/mousemanager.h"
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 BEGIN_EVENT_TABLE(wxMouseEventsManager
, wxEvtHandler
)
38 EVT_MOUSE_CAPTURE_LOST(wxMouseEventsManager::OnCaptureLost
)
39 EVT_LEFT_DOWN(wxMouseEventsManager::OnLeftDown
)
40 EVT_LEFT_UP(wxMouseEventsManager::OnLeftUp
)
41 EVT_MOTION(wxMouseEventsManager::OnMove
)
44 // ============================================================================
45 // wxMouseEventsManager implementation
46 // ============================================================================
48 wxMouseEventsManager::wxMouseEventsManager(wxWindow
*win
)
51 m_state
= State_Normal
;
54 win
->PushEventHandler(this);
57 wxMouseEventsManager::~wxMouseEventsManager()
59 m_win
->RemoveEventHandler(this);
62 void wxMouseEventsManager::OnCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
67 wxFAIL_MSG( "mouse shouldn't be captured in normal state" );
71 MouseClickCancelled(m_item
);
75 MouseDragCancelled(m_item
);
79 m_state
= State_Normal
;
83 void wxMouseEventsManager::OnLeftDown(wxMouseEvent
& event
)
85 wxASSERT_MSG( m_state
== State_Normal
,
86 "state hasn't been reset to normal somehow" );
88 m_posLast
= event
.GetPosition();
89 m_item
= MouseHitTest(m_posLast
);
90 if ( m_item
== wxNOT_FOUND
)
96 m_state
= State_Pressed
;
97 m_win
->CaptureMouse();
98 MouseClickBegin(m_item
);
101 void wxMouseEventsManager::OnLeftUp(wxMouseEvent
& event
)
106 // ignore it, the mouse hasn't been pressed over any item initially
107 // so releasing it shouldn't do anything
110 // skip releasing the capture below
114 if ( MouseHitTest(event
.GetPosition()) == m_item
)
116 // mouse released over the same item, so it was a click
117 MouseClicked(m_item
);
122 MouseDragEnd(m_item
, event
.GetPosition());
126 m_state
= State_Normal
;
127 m_item
= wxNOT_FOUND
;
128 m_win
->ReleaseMouse();
131 void wxMouseEventsManager::OnMove(wxMouseEvent
& event
)
140 wxASSERT_MSG( event
.LeftIsDown(),
141 "should have detected mouse being released" );
144 // it's probably a bad idea to query the system for these
145 // values every time the mouse is moved so cache them on the
146 // assumption that they don't change -- which is wrong, of
147 // course, the user can change them but it doesn't happen often
149 dragMinX
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
151 dragMinY
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
153 const wxPoint
& pos
= event
.GetPosition();
154 const wxPoint ofs
= pos
- m_posLast
;
155 if ( abs(ofs
.x
) > dragMinX
|| abs(ofs
.y
) > dragMinY
)
157 // the mouse left the rectangle inside which its movements
158 // are considered to be too small to constitute a start of
159 // drag operation, do [attempt to] start it now
160 if ( MouseDragBegin(m_item
, pos
) )
162 m_state
= State_Dragging
;
165 else // still didn't move far enough away
173 m_posLast
= event
.GetPosition();
174 MouseDragging(m_item
, m_posLast
);