X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/19193a2c85987b595932957e73013e7ea100f0e8..f239a20092359e3c914adb79bd39f3f5d2b2e06f:/src/univ/scrarrow.cpp diff --git a/src/univ/scrarrow.cpp b/src/univ/scrarrow.cpp index c3db2abdf8..988ecbc957 100644 --- a/src/univ/scrarrow.cpp +++ b/src/univ/scrarrow.cpp @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ - #pragma implementation "univscrarrow.h" -#endif - #include "wx/wxprec.h" #ifdef __BORLANDC__ @@ -28,6 +24,7 @@ #endif #ifndef WX_PRECOMP + #include "wx/window.h" #endif #include "wx/univ/scrtimer.h" @@ -49,7 +46,9 @@ struct wxScrollArrowCaptureData m_arrowPressed = wxScrollArrows::Arrow_None; m_window = NULL; m_btnCapture = -1; +#if wxUSE_TIMER m_timerScroll = NULL; +#endif // wxUSE_TIMER } ~wxScrollArrowCaptureData() @@ -57,7 +56,9 @@ struct wxScrollArrowCaptureData if ( m_window ) m_window->ReleaseMouse(); +#if wxUSE_TIMER delete m_timerScroll; +#endif // wxUSE_TIMER } // the arrow being held pressed (may be Arrow_None) @@ -69,14 +70,18 @@ struct wxScrollArrowCaptureData // the window which has captured the mouse wxWindow *m_window; +#if wxUSE_TIMER // the timer for generating the scroll events wxScrollTimer *m_timerScroll; +#endif }; // ---------------------------------------------------------------------------- // wxScrollArrowTimer: a wxScrollTimer which calls OnArrow() // ---------------------------------------------------------------------------- +#if wxUSE_TIMER + class wxScrollArrowTimer : public wxScrollTimer { public: @@ -99,6 +104,8 @@ protected: wxScrollArrows::Arrow m_arrow; }; +#endif // wxUSE_TIMER + // ============================================================================ // implementation of wxScrollArrows // ============================================================================ @@ -116,7 +123,7 @@ wxScrollArrows::wxScrollArrows(wxControlWithArrows *control) wxScrollArrows::~wxScrollArrows() { // it should have been destroyed - wxASSERT_MSG( !m_captureData, _T("memory leak in wxScrollArrows") ); + wxASSERT_MSG( !m_captureData, wxT("memory leak in wxScrollArrows") ); } // ---------------------------------------------------------------------------- @@ -134,17 +141,18 @@ void wxScrollArrows::DrawArrow(Arrow arrow, { wxUP, wxDOWN } }; - void (wxRenderer::*pfn)(wxDC&, wxDirection, const wxRect&, int) = - scrollbarLike ? wxRenderer::DrawScrollbarArrow - : wxRenderer::DrawArrow; - - (m_control->GetRenderer()->*pfn) - ( - dc, - arrowDirs[m_control->IsVertical()][arrow], - rect, - m_control->GetArrowState(arrow) - ); + if ( scrollbarLike ) + m_control->GetRenderer()->DrawScrollbarArrow( + dc, + arrowDirs[m_control->IsVertical()][arrow], + rect, + m_control->GetArrowState(arrow)); + else + m_control->GetRenderer()->DrawArrow( + dc, + arrowDirs[m_control->IsVertical()][arrow], + rect, + m_control->GetArrowState(arrow)); } // ---------------------------------------------------------------------------- @@ -166,10 +174,11 @@ bool wxScrollArrows::HandleMouseMove(const wxMouseEvent& event) const } else // Moving() or Entering(), treat them the same here { - arrow = m_control->HitTest(event.GetPosition()); + arrow = m_control->HitTestArrow(event.GetPosition()); } - if ( m_captureData ) +#if wxUSE_TIMER + if ( m_captureData && m_captureData->m_timerScroll) { // the mouse is captured, we may want to pause scrolling if it goes // outside the arrow or to resume it if we had paused it before @@ -180,35 +189,36 @@ bool wxScrollArrows::HandleMouseMove(const wxMouseEvent& event) const if ( arrow == m_captureData->m_arrowPressed ) { // resume now - m_control->SetArrowFlag(arrow, wxCONTROL_PRESSED, TRUE); + m_control->SetArrowFlag(arrow, wxCONTROL_PRESSED, true); timer->Start(); - return TRUE; + return true; } } - else if ( 1 ) //FIXME: m_control->ShouldPauseScrolling() ) + else // if ( 1 ) FIXME: m_control->ShouldPauseScrolling() ) { // we may want to stop it if ( arrow != m_captureData->m_arrowPressed ) { // stop as the mouse left the arrow m_control->SetArrowFlag(m_captureData->m_arrowPressed, - wxCONTROL_PRESSED, FALSE); + wxCONTROL_PRESSED, false); timer->Stop(); - return TRUE; + return true; } } - return FALSE; + return false; } +#endif // wxUSE_TIMER // reset the wxCONTROL_CURRENT flag for the arrows which don't have the // mouse and set it for the one which has UpdateCurrentFlag(Arrow_First, arrow); UpdateCurrentFlag(Arrow_Second, arrow); - // return TRUE if it was really an event for an arrow + // return true if it was really an event for an arrow return !event.Leaving() && arrow != Arrow_None; } @@ -218,24 +228,24 @@ bool wxScrollArrows::HandleMouse(const wxMouseEvent& event) const if ( btn == -1 ) { // we only care about button press/release events - return FALSE; + return false; } if ( event.ButtonDown() || event.ButtonDClick() ) { if ( !m_captureData ) { - Arrow arrow = m_control->HitTest(event.GetPosition()); + Arrow arrow = m_control->HitTestArrow(event.GetPosition()); if ( arrow == Arrow_None ) { // mouse pressed over something else - return FALSE; + return false; } if ( m_control->GetArrowState(arrow) & wxCONTROL_DISABLED ) { // don't allow to press disabled arrows - return TRUE; + return true; } wxConstCast(this, wxScrollArrows)->m_captureData = @@ -245,11 +255,29 @@ bool wxScrollArrows::HandleMouse(const wxMouseEvent& event) const m_captureData->m_window = m_control->GetWindow(); m_captureData->m_window->CaptureMouse(); +#if wxUSE_TIMER // start scrolling - m_captureData->m_timerScroll = + wxScrollArrowTimer *tmpTimerScroll = new wxScrollArrowTimer(m_control, arrow); +#endif // wxUSE_TIMER - m_control->SetArrowFlag(arrow, wxCONTROL_PRESSED, TRUE); + // Because in some cases wxScrollArrowTimer can cause + // m_captureData to be destructed we need to test if it + // is still valid before using. + if (m_captureData) + { +#if wxUSE_TIMER + m_captureData->m_timerScroll = tmpTimerScroll; +#endif // wxUSE_TIMER + + m_control->SetArrowFlag(arrow, wxCONTROL_PRESSED, true); + } + else + { +#if wxUSE_TIMER + delete tmpTimerScroll; +#endif // wxUSE_TIMER + } } //else: mouse already captured, nothing to do } @@ -261,14 +289,13 @@ bool wxScrollArrows::HandleMouse(const wxMouseEvent& event) const delete m_captureData; wxConstCast(this, wxScrollArrows)->m_captureData = NULL; - m_control->SetArrowFlag(arrow, wxCONTROL_PRESSED, FALSE); + m_control->SetArrowFlag(arrow, wxCONTROL_PRESSED, false); } else { // we don't process this - return FALSE; + return false; } - return TRUE; + return true; } -