]>
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"
27 #include "wx/window.h"
30 #include "wx/univ/scrtimer.h"
31 #include "wx/univ/scrarrow.h"
33 #include "wx/univ/renderer.h"
34 #include "wx/univ/inphand.h"
35 #include "wx/univ/theme.h"
37 // ----------------------------------------------------------------------------
38 // wxScrollArrowCaptureData: contains the data used while the arrow is being
39 // pressed by the user
40 // ----------------------------------------------------------------------------
42 struct wxScrollArrowCaptureData
44 wxScrollArrowCaptureData()
46 m_arrowPressed
= wxScrollArrows::Arrow_None
;
54 ~wxScrollArrowCaptureData()
57 m_window
->ReleaseMouse();
64 // the arrow being held pressed (may be Arrow_None)
65 wxScrollArrows::Arrow m_arrowPressed
;
67 // the mouse button which started the capture (-1 if none)
70 // the window which has captured the mouse
74 // the timer for generating the scroll events
75 wxScrollTimer
*m_timerScroll
;
79 // ----------------------------------------------------------------------------
80 // wxScrollArrowTimer: a wxScrollTimer which calls OnArrow()
81 // ----------------------------------------------------------------------------
85 class wxScrollArrowTimer
: public wxScrollTimer
88 wxScrollArrowTimer(wxControlWithArrows
*control
,
89 wxScrollArrows::Arrow arrow
)
98 virtual bool DoNotify()
100 return m_control
->OnArrow(m_arrow
);
103 wxControlWithArrows
*m_control
;
104 wxScrollArrows::Arrow m_arrow
;
107 #endif // wxUSE_TIMER
109 // ============================================================================
110 // implementation of wxScrollArrows
111 // ============================================================================
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
117 wxScrollArrows::wxScrollArrows(wxControlWithArrows
*control
)
120 m_captureData
= NULL
;
123 wxScrollArrows::~wxScrollArrows()
125 // it should have been destroyed
126 wxASSERT_MSG( !m_captureData
, wxT("memory leak in wxScrollArrows") );
129 // ----------------------------------------------------------------------------
131 // ----------------------------------------------------------------------------
133 void wxScrollArrows::DrawArrow(Arrow arrow
,
136 bool scrollbarLike
) const
138 static const wxDirection arrowDirs
[2][Arrow_Max
] =
145 m_control
->GetRenderer()->DrawScrollbarArrow(
147 arrowDirs
[m_control
->IsVertical()][arrow
],
149 m_control
->GetArrowState(arrow
));
151 m_control
->GetRenderer()->DrawArrow(
153 arrowDirs
[m_control
->IsVertical()][arrow
],
155 m_control
->GetArrowState(arrow
));
158 // ----------------------------------------------------------------------------
160 // ----------------------------------------------------------------------------
162 void wxScrollArrows::UpdateCurrentFlag(Arrow arrow
, Arrow arrowCur
) const
164 m_control
->SetArrowFlag(arrow
, wxCONTROL_CURRENT
, arrow
== arrowCur
);
167 bool wxScrollArrows::HandleMouseMove(const wxMouseEvent
& event
) const
170 if ( event
.Leaving() )
172 // no arrow has mouse if it left the window completely
175 else // Moving() or Entering(), treat them the same here
177 arrow
= m_control
->HitTestArrow(event
.GetPosition());
181 if ( m_captureData
&& m_captureData
->m_timerScroll
)
183 // the mouse is captured, we may want to pause scrolling if it goes
184 // outside the arrow or to resume it if we had paused it before
185 wxTimer
*timer
= m_captureData
->m_timerScroll
;
186 if ( !timer
->IsRunning() )
189 if ( arrow
== m_captureData
->m_arrowPressed
)
192 m_control
->SetArrowFlag(arrow
, wxCONTROL_PRESSED
, true);
198 else // if ( 1 ) FIXME: m_control->ShouldPauseScrolling() )
200 // we may want to stop it
201 if ( arrow
!= m_captureData
->m_arrowPressed
)
203 // stop as the mouse left the arrow
204 m_control
->SetArrowFlag(m_captureData
->m_arrowPressed
,
205 wxCONTROL_PRESSED
, false);
214 #endif // wxUSE_TIMER
216 // reset the wxCONTROL_CURRENT flag for the arrows which don't have the
217 // mouse and set it for the one which has
218 UpdateCurrentFlag(Arrow_First
, arrow
);
219 UpdateCurrentFlag(Arrow_Second
, arrow
);
221 // return true if it was really an event for an arrow
222 return !event
.Leaving() && arrow
!= Arrow_None
;
225 bool wxScrollArrows::HandleMouse(const wxMouseEvent
& event
) const
227 int btn
= event
.GetButton();
230 // we only care about button press/release events
234 if ( event
.ButtonDown() || event
.ButtonDClick() )
236 if ( !m_captureData
)
238 Arrow arrow
= m_control
->HitTestArrow(event
.GetPosition());
239 if ( arrow
== Arrow_None
)
241 // mouse pressed over something else
245 if ( m_control
->GetArrowState(arrow
) & wxCONTROL_DISABLED
)
247 // don't allow to press disabled arrows
251 wxConstCast(this, wxScrollArrows
)->m_captureData
=
252 new wxScrollArrowCaptureData
;
253 m_captureData
->m_arrowPressed
= arrow
;
254 m_captureData
->m_btnCapture
= btn
;
255 m_captureData
->m_window
= m_control
->GetWindow();
256 m_captureData
->m_window
->CaptureMouse();
260 wxScrollArrowTimer
*tmpTimerScroll
=
261 new wxScrollArrowTimer(m_control
, arrow
);
262 #endif // wxUSE_TIMER
264 // Because in some cases wxScrollArrowTimer can cause
265 // m_captureData to be destructed we need to test if it
266 // is still valid before using.
270 m_captureData
->m_timerScroll
= tmpTimerScroll
;
271 #endif // wxUSE_TIMER
273 m_control
->SetArrowFlag(arrow
, wxCONTROL_PRESSED
, true);
278 delete tmpTimerScroll
;
279 #endif // wxUSE_TIMER
282 //else: mouse already captured, nothing to do
284 // release mouse if the *same* button went up
285 else if ( m_captureData
&& (btn
== m_captureData
->m_btnCapture
) )
287 Arrow arrow
= m_captureData
->m_arrowPressed
;
289 delete m_captureData
;
290 wxConstCast(this, wxScrollArrows
)->m_captureData
= NULL
;
292 m_control
->SetArrowFlag(arrow
, wxCONTROL_PRESSED
, false);
296 // we don't process this