]>
git.saurik.com Git - wxWidgets.git/blob - src/univ/scrarrow.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/univ/scrarrow.cpp
3 // Purpose: wxScrollArrows class implementation
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
29 #include "wx/univ/scrtimer.h"
30 #include "wx/univ/scrarrow.h"
32 #include "wx/univ/renderer.h"
33 #include "wx/univ/inphand.h"
34 #include "wx/univ/theme.h"
36 // ----------------------------------------------------------------------------
37 // wxScrollArrowCaptureData: contains the data used while the arrow is being
38 // pressed by the user
39 // ----------------------------------------------------------------------------
41 struct wxScrollArrowCaptureData
43 wxScrollArrowCaptureData()
45 m_arrowPressed
= wxScrollArrows::Arrow_None
;
51 ~wxScrollArrowCaptureData()
54 m_window
->ReleaseMouse();
59 // the arrow being held pressed (may be Arrow_None)
60 wxScrollArrows::Arrow m_arrowPressed
;
62 // the mouse button which started the capture (-1 if none)
65 // the window which has captured the mouse
68 // the timer for generating the scroll events
69 wxScrollTimer
*m_timerScroll
;
72 // ----------------------------------------------------------------------------
73 // wxScrollArrowTimer: a wxScrollTimer which calls OnArrow()
74 // ----------------------------------------------------------------------------
76 class wxScrollArrowTimer
: public wxScrollTimer
79 wxScrollArrowTimer(wxControlWithArrows
*control
,
80 wxScrollArrows::Arrow arrow
)
89 virtual bool DoNotify()
91 return m_control
->OnArrow(m_arrow
);
94 wxControlWithArrows
*m_control
;
95 wxScrollArrows::Arrow m_arrow
;
98 // ============================================================================
99 // implementation of wxScrollArrows
100 // ============================================================================
102 // ----------------------------------------------------------------------------
104 // ----------------------------------------------------------------------------
106 wxScrollArrows::wxScrollArrows(wxControlWithArrows
*control
)
109 m_captureData
= NULL
;
112 wxScrollArrows::~wxScrollArrows()
114 // it should have been destroyed
115 wxASSERT_MSG( !m_captureData
, _T("memory leak in wxScrollArrows") );
118 // ----------------------------------------------------------------------------
120 // ----------------------------------------------------------------------------
122 void wxScrollArrows::DrawArrow(Arrow arrow
,
125 bool scrollbarLike
) const
127 static const wxDirection arrowDirs
[2][Arrow_Max
] =
134 m_control
->GetRenderer()->DrawScrollbarArrow(
136 arrowDirs
[m_control
->IsVertical()][arrow
],
138 m_control
->GetArrowState(arrow
));
140 m_control
->GetRenderer()->DrawArrow(
142 arrowDirs
[m_control
->IsVertical()][arrow
],
144 m_control
->GetArrowState(arrow
));
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
151 void wxScrollArrows::UpdateCurrentFlag(Arrow arrow
, Arrow arrowCur
) const
153 m_control
->SetArrowFlag(arrow
, wxCONTROL_CURRENT
, arrow
== arrowCur
);
156 bool wxScrollArrows::HandleMouseMove(const wxMouseEvent
& event
) const
159 if ( event
.Leaving() )
161 // no arrow has mouse if it left the window completely
164 else // Moving() or Entering(), treat them the same here
166 arrow
= m_control
->HitTest(event
.GetPosition());
169 if ( m_captureData
&& m_captureData
->m_timerScroll
)
171 // the mouse is captured, we may want to pause scrolling if it goes
172 // outside the arrow or to resume it if we had paused it before
173 wxTimer
*timer
= m_captureData
->m_timerScroll
;
174 if ( !timer
->IsRunning() )
177 if ( arrow
== m_captureData
->m_arrowPressed
)
180 m_control
->SetArrowFlag(arrow
, wxCONTROL_PRESSED
, true);
186 else // if ( 1 ) FIXME: m_control->ShouldPauseScrolling() )
188 // we may want to stop it
189 if ( arrow
!= m_captureData
->m_arrowPressed
)
191 // stop as the mouse left the arrow
192 m_control
->SetArrowFlag(m_captureData
->m_arrowPressed
,
193 wxCONTROL_PRESSED
, false);
203 // reset the wxCONTROL_CURRENT flag for the arrows which don't have the
204 // mouse and set it for the one which has
205 UpdateCurrentFlag(Arrow_First
, arrow
);
206 UpdateCurrentFlag(Arrow_Second
, arrow
);
208 // return true if it was really an event for an arrow
209 return !event
.Leaving() && arrow
!= Arrow_None
;
212 bool wxScrollArrows::HandleMouse(const wxMouseEvent
& event
) const
214 int btn
= event
.GetButton();
217 // we only care about button press/release events
221 if ( event
.ButtonDown() || event
.ButtonDClick() )
223 if ( !m_captureData
)
225 Arrow arrow
= m_control
->HitTest(event
.GetPosition());
226 if ( arrow
== Arrow_None
)
228 // mouse pressed over something else
232 if ( m_control
->GetArrowState(arrow
) & wxCONTROL_DISABLED
)
234 // don't allow to press disabled arrows
238 wxConstCast(this, wxScrollArrows
)->m_captureData
=
239 new wxScrollArrowCaptureData
;
240 m_captureData
->m_arrowPressed
= arrow
;
241 m_captureData
->m_btnCapture
= btn
;
242 m_captureData
->m_window
= m_control
->GetWindow();
243 m_captureData
->m_window
->CaptureMouse();
246 wxScrollArrowTimer
*tmpTimerScroll
=
247 new wxScrollArrowTimer(m_control
, arrow
);
249 // Because in some cases wxScrollArrowTimer can cause
250 // m_captureData to be destructed we need to test if it
251 // is still valid before using.
254 m_captureData
->m_timerScroll
= tmpTimerScroll
;
256 m_control
->SetArrowFlag(arrow
, wxCONTROL_PRESSED
, true);
260 delete tmpTimerScroll
;
263 //else: mouse already captured, nothing to do
265 // release mouse if the *same* button went up
266 else if ( m_captureData
&& (btn
== m_captureData
->m_btnCapture
) )
268 Arrow arrow
= m_captureData
->m_arrowPressed
;
270 delete m_captureData
;
271 wxConstCast(this, wxScrollArrows
)->m_captureData
= NULL
;
273 m_control
->SetArrowFlag(arrow
, wxCONTROL_PRESSED
, false);
277 // we don't process this