]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxAnyScrollHelperBase to reduce code duplication in wxVarScrollHelperBase.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 15 Sep 2013 00:15:07 +0000 (00:15 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 15 Sep 2013 00:15:07 +0000 (00:15 +0000)
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
include/wx/vscroll.h
src/generic/scrlwing.cpp
src/generic/vscroll.cpp

index 9c3f1eebbf3151a42fdef917153f567b28099248..3e22eb59c2775a02bd56a9f14d79c48d260e7228 100644 (file)
@@ -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;
index 9b72d97376ab790717f18b9082406aedd6e91cc6..51e2b0b58c31412e1ac35004eb11b74a35545afd 100644 (file)
@@ -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;
 
index ee49a9c6a1cd793c0482fef7ae51bf11978871fd..1323e450608d0cf251ec47852d13ab57ecfd685e 100644 (file)
@@ -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<wxScrollHelper *>(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
 // ----------------------------------------------------------------------------
index 3a66aa34b53bf79dd787e02245f61b688e4bc77b..905d7cc4d0048d92d559f295ed0abe0fcd0eb123 100644 (file)
@@ -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()