]>
git.saurik.com Git - wxWidgets.git/blob - src/common/mousemanager.cpp
c37395503880e7c0f8d86848c7ea31ee6052b9d9
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"
29 #include "wx/mousemanager.h"
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 BEGIN_EVENT_TABLE(wxMouseEventsManager
, wxEvtHandler
)
36 EVT_MOUSE_CAPTURE_LOST(wxMouseEventsManager::OnCaptureLost
)
37 EVT_LEFT_DOWN(wxMouseEventsManager::OnLeftDown
)
38 EVT_LEFT_UP(wxMouseEventsManager::OnLeftUp
)
39 EVT_MOTION(wxMouseEventsManager::OnMove
)
42 // ============================================================================
43 // wxMouseEventsManager implementation
44 // ============================================================================
46 wxMouseEventsManager::wxMouseEventsManager(wxWindow
*win
)
49 m_state
= State_Normal
;
52 win
->PushEventHandler(this);
55 wxMouseEventsManager::~wxMouseEventsManager()
57 m_win
->RemoveEventHandler(this);
60 void wxMouseEventsManager::OnCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
65 wxFAIL_MSG( "mouse shouldn't be captured in normal state" );
69 MouseClickCancelled(m_item
);
73 MouseDragCancelled(m_item
);
77 m_state
= State_Normal
;
81 void wxMouseEventsManager::OnLeftDown(wxMouseEvent
& event
)
83 wxASSERT_MSG( m_state
== State_Normal
,
84 "state hasn't been reset to normal somehow" );
86 m_posLast
= event
.GetPosition();
87 m_item
= MouseHitTest(m_posLast
);
88 if ( m_item
== wxNOT_FOUND
)
94 m_state
= State_Pressed
;
95 m_win
->CaptureMouse();
96 MouseClickBegin(m_item
);
99 void wxMouseEventsManager::OnLeftUp(wxMouseEvent
& event
)
104 // ignore it, the mouse hasn't been pressed over any item initially
105 // so releasing it shouldn't do anything
108 // skip releasing the capture below
112 if ( MouseHitTest(event
.GetPosition()) == m_item
)
114 // mouse released over the same item, so it was a click
115 MouseClicked(m_item
);
120 MouseDragEnd(m_item
, event
.GetPosition());
124 m_state
= State_Normal
;
125 m_item
= wxNOT_FOUND
;
126 m_win
->ReleaseMouse();
129 void wxMouseEventsManager::OnMove(wxMouseEvent
& event
)
138 wxASSERT_MSG( event
.LeftIsDown(),
139 "should have detected mouse being released" );
142 // it's probably a bad idea to query the system for these
143 // values every time the mouse is moved so cache them on the
144 // assumption that they don't change -- which is wrong, of
145 // course, the user can change them but it doesn't happen often
147 dragMinX
= wxSystemSettings::GetMetric(wxSYS_DRAG_X
);
149 dragMinY
= wxSystemSettings::GetMetric(wxSYS_DRAG_Y
);
151 const wxPoint
& pos
= event
.GetPosition();
152 const wxPoint ofs
= pos
- m_posLast
;
153 if ( abs(ofs
.x
) > dragMinX
|| abs(ofs
.y
) > dragMinY
)
155 // the mouse left the rectangle inside which its movements
156 // are considered to be too small to constitute a start of
157 // drag operation, do [attempt to] start it now
158 if ( MouseDragBegin(m_item
, pos
) )
160 m_state
= State_Dragging
;
163 else // still didn't move far enough away
171 m_posLast
= event
.GetPosition();
172 MouseDragging(m_item
, m_posLast
);