]>
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
;
53 ~wxScrollArrowCaptureData()
56 m_window
->ReleaseMouse();
63 // the arrow being held pressed (may be Arrow_None)
64 wxScrollArrows::Arrow m_arrowPressed
;
66 // the mouse button which started the capture (-1 if none)
69 // the window which has captured the mouse
73 // the timer for generating the scroll events
74 wxScrollTimer
*m_timerScroll
;
78 // ----------------------------------------------------------------------------
79 // wxScrollArrowTimer: a wxScrollTimer which calls OnArrow()
80 // ----------------------------------------------------------------------------
84 class wxScrollArrowTimer
: public wxScrollTimer
87 wxScrollArrowTimer(wxControlWithArrows
*control
,
88 wxScrollArrows::Arrow arrow
)
97 virtual bool DoNotify()
99 return m_control
->OnArrow(m_arrow
);
102 wxControlWithArrows
*m_control
;
103 wxScrollArrows::Arrow m_arrow
;
106 #endif // wxUSE_TIMER
108 // ============================================================================
109 // implementation of wxScrollArrows
110 // ============================================================================
112 // ----------------------------------------------------------------------------
114 // ----------------------------------------------------------------------------
116 wxScrollArrows::wxScrollArrows(wxControlWithArrows
*control
)
119 m_captureData
= NULL
;
122 wxScrollArrows::~wxScrollArrows()
124 // it should have been destroyed
125 wxASSERT_MSG( !m_captureData
, _T("memory leak in wxScrollArrows") );
128 // ----------------------------------------------------------------------------
130 // ----------------------------------------------------------------------------
132 void wxScrollArrows::DrawArrow(Arrow arrow
,
135 bool scrollbarLike
) const
137 static const wxDirection arrowDirs
[2][Arrow_Max
] =
144 m_control
->GetRenderer()->DrawScrollbarArrow(
146 arrowDirs
[m_control
->IsVertical()][arrow
],
148 m_control
->GetArrowState(arrow
));
150 m_control
->GetRenderer()->DrawArrow(
152 arrowDirs
[m_control
->IsVertical()][arrow
],
154 m_control
->GetArrowState(arrow
));
157 // ----------------------------------------------------------------------------
159 // ----------------------------------------------------------------------------
161 void wxScrollArrows::UpdateCurrentFlag(Arrow arrow
, Arrow arrowCur
) const
163 m_control
->SetArrowFlag(arrow
, wxCONTROL_CURRENT
, arrow
== arrowCur
);
166 bool wxScrollArrows::HandleMouseMove(const wxMouseEvent
& event
) const
169 if ( event
.Leaving() )
171 // no arrow has mouse if it left the window completely
174 else // Moving() or Entering(), treat them the same here
176 arrow
= m_control
->HitTest(event
.GetPosition());
180 if ( m_captureData
&& m_captureData
->m_timerScroll
)
182 // the mouse is captured, we may want to pause scrolling if it goes
183 // outside the arrow or to resume it if we had paused it before
184 wxTimer
*timer
= m_captureData
->m_timerScroll
;
185 if ( !timer
->IsRunning() )
188 if ( arrow
== m_captureData
->m_arrowPressed
)
191 m_control
->SetArrowFlag(arrow
, wxCONTROL_PRESSED
, true);
197 else // if ( 1 ) FIXME: m_control->ShouldPauseScrolling() )
199 // we may want to stop it
200 if ( arrow
!= m_captureData
->m_arrowPressed
)
202 // stop as the mouse left the arrow
203 m_control
->SetArrowFlag(m_captureData
->m_arrowPressed
,
204 wxCONTROL_PRESSED
, false);
213 #endif // wxUSE_TIMER
215 // reset the wxCONTROL_CURRENT flag for the arrows which don't have the
216 // mouse and set it for the one which has
217 UpdateCurrentFlag(Arrow_First
, arrow
);
218 UpdateCurrentFlag(Arrow_Second
, arrow
);
220 // return true if it was really an event for an arrow
221 return !event
.Leaving() && arrow
!= Arrow_None
;
224 bool wxScrollArrows::HandleMouse(const wxMouseEvent
& event
) const
226 int btn
= event
.GetButton();
229 // we only care about button press/release events
233 if ( event
.ButtonDown() || event
.ButtonDClick() )
235 if ( !m_captureData
)
237 Arrow arrow
= m_control
->HitTest(event
.GetPosition());
238 if ( arrow
== Arrow_None
)
240 // mouse pressed over something else
244 if ( m_control
->GetArrowState(arrow
) & wxCONTROL_DISABLED
)
246 // don't allow to press disabled arrows
250 wxConstCast(this, wxScrollArrows
)->m_captureData
=
251 new wxScrollArrowCaptureData
;
252 m_captureData
->m_arrowPressed
= arrow
;
253 m_captureData
->m_btnCapture
= btn
;
254 m_captureData
->m_window
= m_control
->GetWindow();
255 m_captureData
->m_window
->CaptureMouse();
259 wxScrollArrowTimer
*tmpTimerScroll
=
260 new wxScrollArrowTimer(m_control
, arrow
);
261 #endif // wxUSE_TIMER
263 // Because in some cases wxScrollArrowTimer can cause
264 // m_captureData to be destructed we need to test if it
265 // is still valid before using.
269 m_captureData
->m_timerScroll
= tmpTimerScroll
;
270 #endif // wxUSE_TIMER
272 m_control
->SetArrowFlag(arrow
, wxCONTROL_PRESSED
, true);
277 delete tmpTimerScroll
;
278 #endif // wxUSE_TIMER
281 //else: mouse already captured, nothing to do
283 // release mouse if the *same* button went up
284 else if ( m_captureData
&& (btn
== m_captureData
->m_btnCapture
) )
286 Arrow arrow
= m_captureData
->m_arrowPressed
;
288 delete m_captureData
;
289 wxConstCast(this, wxScrollArrows
)->m_captureData
= NULL
;
291 m_control
->SetArrowFlag(arrow
, wxCONTROL_PRESSED
, false);
295 // we don't process this