From 010d821b3138ae39c43403da64eb0bcde9af82ae Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 15 Sep 2013 00:15:07 +0000 Subject: [PATCH] Add wxAnyScrollHelperBase to reduce code duplication in wxVarScrollHelperBase. This is just a small refactoring to move some trivially common parts of wxScrollHelperBase and wxVarScrollHelperBase in a new common base class. This will make it possible to apply other corrections to wxVarScrollHelperBase without having to physically duplicate the code from wxScrollHelperBase in it. See #15357. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74813 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/scrolwin.h | 28 +++++++++++++++++++++++----- include/wx/vscroll.h | 15 +++++++-------- src/generic/scrlwing.cpp | 27 ++++++++++++++------------- src/generic/vscroll.cpp | 9 +-------- 4 files changed, 45 insertions(+), 34 deletions(-) diff --git a/include/wx/scrolwin.h b/include/wx/scrolwin.h index 9c3f1ee..3e22eb5 100644 --- a/include/wx/scrolwin.h +++ b/include/wx/scrolwin.h @@ -36,6 +36,10 @@ enum wxScrollbarVisibility // // So we have // +// wxAnyScrollHelperBase +// | +// | +// \|/ // wxScrollHelperBase // | // | @@ -55,7 +59,25 @@ enum wxScrollbarVisibility // // ---------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxScrollHelperBase +// This class allows reusing some of wxScrollHelperBase functionality in +// wxVarScrollHelperBase in wx/vscroll.h without duplicating its code. +class WXDLLIMPEXP_CORE wxAnyScrollHelperBase +{ +public: + wxEXPLICIT wxAnyScrollHelperBase(wxWindow* win); + + // Simple accessor for the window that is really being scrolled. + wxWindow *GetTargetWindow() const { return m_targetWindow; } + +protected: + // the window that receives the scroll events and the window to actually + // scroll, respectively + wxWindow *m_win, + *m_targetWindow; +}; + +// This is the class containing the guts of (uniform) scrolling logic. +class WXDLLIMPEXP_CORE wxScrollHelperBase : public wxAnyScrollHelperBase { public: // ctor must be given the associated window @@ -173,7 +195,6 @@ public: // child of it in order to scroll only a portion the area between the // scrollbars (spreadsheet: only cell area will move). void SetTargetWindow(wxWindow *target); - wxWindow *GetTargetWindow() const; void SetTargetRect(const wxRect& rect) { m_rectToScroll = rect; } wxRect GetTargetRect() const { return m_rectToScroll; } @@ -278,9 +299,6 @@ protected: double m_scaleX; double m_scaleY; - wxWindow *m_win, - *m_targetWindow; - wxRect m_rectToScroll; wxTimer *m_timerAutoScroll; diff --git a/include/wx/vscroll.h b/include/wx/vscroll.h index 9b72d97..51e2b0b 100644 --- a/include/wx/vscroll.h +++ b/include/wx/vscroll.h @@ -13,6 +13,7 @@ #include "wx/panel.h" #include "wx/position.h" +#include "wx/scrolwin.h" class WXDLLIMPEXP_FWD_CORE wxVarScrollHelperEvtHandler; @@ -23,6 +24,11 @@ class WXDLLIMPEXP_FWD_CORE wxVarScrollHelperEvtHandler; // scrolwin.h) for the purpose of reducing code duplication | // through the use of mix-in classes. | // | +// wxAnyScrollHelperBase | +// | | +// | | +// | | +// V | // wxVarScrollHelperBase | // / \ | // / \ | @@ -58,7 +64,7 @@ class WXDLLIMPEXP_FWD_CORE wxVarScrollHelperEvtHandler; // required virtual functions that need to be implemented for any orientation // specific work. -class WXDLLIMPEXP_CORE wxVarScrollHelperBase +class WXDLLIMPEXP_CORE wxVarScrollHelperBase : public wxAnyScrollHelperBase { public: // constructors and such @@ -114,7 +120,6 @@ public: // child of it in order to scroll only a portion the area between the // scrollbars (spreadsheet: only cell area will move). virtual void SetTargetWindow(wxWindow *target); - virtual wxWindow *GetTargetWindow() const { return m_targetWindow; } // Override this function to draw the graphic (or just process EVT_PAINT) //virtual void OnDraw(wxDC& WXUNUSED(dc)) { } @@ -256,12 +261,6 @@ protected: void IncOrient(wxCoord& x, wxCoord& y, wxCoord inc); private: - - // the window that receives the scroll events and the window to actually - // scroll, respectively - wxWindow *m_win, - *m_targetWindow; - // the total number of (logical) units size_t m_unitMax; diff --git a/src/generic/scrlwing.cpp b/src/generic/scrlwing.cpp index ee49a9c..1323e45 100644 --- a/src/generic/scrlwing.cpp +++ b/src/generic/scrlwing.cpp @@ -310,17 +310,28 @@ bool wxScrollHelperEvtHandler::ProcessEvent(wxEvent& event) } // ============================================================================ -// wxScrollHelperBase implementation +// wxAnyScrollHelperBase and wxScrollHelperBase implementation // ============================================================================ // ---------------------------------------------------------------------------- -// wxScrollHelperBase construction +// wxAnyScrollHelperBase // ---------------------------------------------------------------------------- -wxScrollHelperBase::wxScrollHelperBase(wxWindow *win) +wxAnyScrollHelperBase::wxAnyScrollHelperBase(wxWindow* win) { wxASSERT_MSG( win, wxT("associated window can't be NULL in wxScrollHelper") ); + m_win = win; + m_targetWindow = NULL; +} + +// ---------------------------------------------------------------------------- +// wxScrollHelperBase construction +// ---------------------------------------------------------------------------- + +wxScrollHelperBase::wxScrollHelperBase(wxWindow *win) + : wxAnyScrollHelperBase(win) +{ m_xScrollPixelsPerLine = m_yScrollPixelsPerLine = m_xScrollPosition = @@ -341,15 +352,10 @@ wxScrollHelperBase::wxScrollHelperBase(wxWindow *win) m_wheelRotation = 0; #endif - m_win = - m_targetWindow = NULL; - m_timerAutoScroll = NULL; m_handler = NULL; - m_win = win; - m_win->SetScrollHelper(static_cast(this)); // by default, the associated window is also the target window @@ -481,11 +487,6 @@ void wxScrollHelperBase::SetTargetWindow(wxWindow *target) DoSetTargetWindow(target); } -wxWindow *wxScrollHelperBase::GetTargetWindow() const -{ - return m_targetWindow; -} - // ---------------------------------------------------------------------------- // scrolling implementation itself // ---------------------------------------------------------------------------- diff --git a/src/generic/vscroll.cpp b/src/generic/vscroll.cpp index 3a66aa3..905d7cc 100644 --- a/src/generic/vscroll.cpp +++ b/src/generic/vscroll.cpp @@ -139,9 +139,8 @@ bool wxVarScrollHelperEvtHandler::ProcessEvent(wxEvent& event) // ---------------------------------------------------------------------------- wxVarScrollHelperBase::wxVarScrollHelperBase(wxWindow *win) + : wxAnyScrollHelperBase(win) { - wxASSERT_MSG( win, wxT("associated window can't be NULL in wxVarScrollHelperBase") ); - #if wxUSE_MOUSEWHEEL m_sumWheelRotation = 0; #endif @@ -150,17 +149,11 @@ wxVarScrollHelperBase::wxVarScrollHelperBase(wxWindow *win) m_sizeTotal = 0; m_unitFirst = 0; - m_win = - m_targetWindow = NULL; - m_physicalScrolling = true; m_handler = NULL; - m_win = win; - // by default, the associated window is also the target window DoSetTargetWindow(win); - } wxVarScrollHelperBase::~wxVarScrollHelperBase() -- 2.7.4