]>
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "univscrarrow.h"
24 #include "wx/wxprec.h"
33 #include "wx/univ/scrtimer.h"
34 #include "wx/univ/scrarrow.h"
36 #include "wx/univ/renderer.h"
37 #include "wx/univ/inphand.h"
38 #include "wx/univ/theme.h"
40 // ----------------------------------------------------------------------------
41 // wxScrollArrowCaptureData: contains the data used while the arrow is being
42 // pressed by the user
43 // ----------------------------------------------------------------------------
45 struct wxScrollArrowCaptureData
47 wxScrollArrowCaptureData()
49 m_arrowPressed
= wxScrollArrows::Arrow_None
;
55 ~wxScrollArrowCaptureData()
58 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
72 // the timer for generating the scroll events
73 wxScrollTimer
*m_timerScroll
;
76 // ----------------------------------------------------------------------------
77 // wxScrollArrowTimer: a wxScrollTimer which calls OnArrow()
78 // ----------------------------------------------------------------------------
80 class wxScrollArrowTimer
: public wxScrollTimer
83 wxScrollArrowTimer(wxControlWithArrows
*control
,
84 wxScrollArrows::Arrow arrow
)
93 virtual bool DoNotify()
95 return m_control
->OnArrow(m_arrow
);
98 wxControlWithArrows
*m_control
;
99 wxScrollArrows::Arrow m_arrow
;
102 // ============================================================================
103 // implementation of wxScrollArrows
104 // ============================================================================
106 // ----------------------------------------------------------------------------
108 // ----------------------------------------------------------------------------
110 wxScrollArrows::wxScrollArrows(wxControlWithArrows
*control
)
113 m_captureData
= NULL
;
116 wxScrollArrows::~wxScrollArrows()
118 // it should have been destroyed
119 wxASSERT_MSG( !m_captureData
, _T("memory leak in wxScrollArrows") );
122 // ----------------------------------------------------------------------------
124 // ----------------------------------------------------------------------------
126 void wxScrollArrows::DrawArrow(Arrow arrow
,
129 bool scrollbarLike
) const
131 static const wxDirection arrowDirs
[2][Arrow_Max
] =
138 m_control
->GetRenderer()->DrawScrollbarArrow(
140 arrowDirs
[m_control
->IsVertical()][arrow
],
142 m_control
->GetArrowState(arrow
));
144 m_control
->GetRenderer()->DrawArrow(
146 arrowDirs
[m_control
->IsVertical()][arrow
],
148 m_control
->GetArrowState(arrow
));
151 // ----------------------------------------------------------------------------
153 // ----------------------------------------------------------------------------
155 void wxScrollArrows::UpdateCurrentFlag(Arrow arrow
, Arrow arrowCur
) const
157 m_control
->SetArrowFlag(arrow
, wxCONTROL_CURRENT
, arrow
== arrowCur
);
160 bool wxScrollArrows::HandleMouseMove(const wxMouseEvent
& event
) const
163 if ( event
.Leaving() )
165 // no arrow has mouse if it left the window completely
168 else // Moving() or Entering(), treat them the same here
170 arrow
= m_control
->HitTest(event
.GetPosition());
173 if ( m_captureData
&& m_captureData
->m_timerScroll
)
175 // the mouse is captured, we may want to pause scrolling if it goes
176 // outside the arrow or to resume it if we had paused it before
177 wxTimer
*timer
= m_captureData
->m_timerScroll
;
178 if ( !timer
->IsRunning() )
181 if ( arrow
== m_captureData
->m_arrowPressed
)
184 m_control
->SetArrowFlag(arrow
, wxCONTROL_PRESSED
, true);
190 else // if ( 1 ) FIXME: m_control->ShouldPauseScrolling() )
192 // we may want to stop it
193 if ( arrow
!= m_captureData
->m_arrowPressed
)
195 // stop as the mouse left the arrow
196 m_control
->SetArrowFlag(m_captureData
->m_arrowPressed
,
197 wxCONTROL_PRESSED
, false);
207 // reset the wxCONTROL_CURRENT flag for the arrows which don't have the
208 // mouse and set it for the one which has
209 UpdateCurrentFlag(Arrow_First
, arrow
);
210 UpdateCurrentFlag(Arrow_Second
, arrow
);
212 // return true if it was really an event for an arrow
213 return !event
.Leaving() && arrow
!= Arrow_None
;
216 bool wxScrollArrows::HandleMouse(const wxMouseEvent
& event
) const
218 int btn
= event
.GetButton();
221 // we only care about button press/release events
225 if ( event
.ButtonDown() || event
.ButtonDClick() )
227 if ( !m_captureData
)
229 Arrow arrow
= m_control
->HitTest(event
.GetPosition());
230 if ( arrow
== Arrow_None
)
232 // mouse pressed over something else
236 if ( m_control
->GetArrowState(arrow
) & wxCONTROL_DISABLED
)
238 // don't allow to press disabled arrows
242 wxConstCast(this, wxScrollArrows
)->m_captureData
=
243 new wxScrollArrowCaptureData
;
244 m_captureData
->m_arrowPressed
= arrow
;
245 m_captureData
->m_btnCapture
= btn
;
246 m_captureData
->m_window
= m_control
->GetWindow();
247 m_captureData
->m_window
->CaptureMouse();
250 wxScrollArrowTimer
*tmpTimerScroll
=
251 new wxScrollArrowTimer(m_control
, arrow
);
253 // Because in some cases wxScrollArrowTimer can cause
254 // m_captureData to be destructed we need to test if it
255 // is still valid before using.
258 m_captureData
->m_timerScroll
= tmpTimerScroll
;
260 m_control
->SetArrowFlag(arrow
, wxCONTROL_PRESSED
, true);
264 delete tmpTimerScroll
;
267 //else: mouse already captured, nothing to do
269 // release mouse if the *same* button went up
270 else if ( m_captureData
&& (btn
== m_captureData
->m_btnCapture
) )
272 Arrow arrow
= m_captureData
->m_arrowPressed
;
274 delete m_captureData
;
275 wxConstCast(this, wxScrollArrows
)->m_captureData
= NULL
;
277 m_control
->SetArrowFlag(arrow
, wxCONTROL_PRESSED
, false);
281 // we don't process this