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
This commit is contained in:
@@ -36,6 +36,10 @@ enum wxScrollbarVisibility
|
|||||||
//
|
//
|
||||||
// So we have
|
// So we have
|
||||||
//
|
//
|
||||||
|
// wxAnyScrollHelperBase
|
||||||
|
// |
|
||||||
|
// |
|
||||||
|
// \|/
|
||||||
// wxScrollHelperBase
|
// 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:
|
public:
|
||||||
// ctor must be given the associated window
|
// 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
|
// child of it in order to scroll only a portion the area between the
|
||||||
// scrollbars (spreadsheet: only cell area will move).
|
// scrollbars (spreadsheet: only cell area will move).
|
||||||
void SetTargetWindow(wxWindow *target);
|
void SetTargetWindow(wxWindow *target);
|
||||||
wxWindow *GetTargetWindow() const;
|
|
||||||
|
|
||||||
void SetTargetRect(const wxRect& rect) { m_rectToScroll = rect; }
|
void SetTargetRect(const wxRect& rect) { m_rectToScroll = rect; }
|
||||||
wxRect GetTargetRect() const { return m_rectToScroll; }
|
wxRect GetTargetRect() const { return m_rectToScroll; }
|
||||||
@@ -278,9 +299,6 @@ protected:
|
|||||||
double m_scaleX;
|
double m_scaleX;
|
||||||
double m_scaleY;
|
double m_scaleY;
|
||||||
|
|
||||||
wxWindow *m_win,
|
|
||||||
*m_targetWindow;
|
|
||||||
|
|
||||||
wxRect m_rectToScroll;
|
wxRect m_rectToScroll;
|
||||||
|
|
||||||
wxTimer *m_timerAutoScroll;
|
wxTimer *m_timerAutoScroll;
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "wx/panel.h"
|
#include "wx/panel.h"
|
||||||
#include "wx/position.h"
|
#include "wx/position.h"
|
||||||
|
#include "wx/scrolwin.h"
|
||||||
|
|
||||||
class WXDLLIMPEXP_FWD_CORE wxVarScrollHelperEvtHandler;
|
class WXDLLIMPEXP_FWD_CORE wxVarScrollHelperEvtHandler;
|
||||||
|
|
||||||
@@ -23,6 +24,11 @@ class WXDLLIMPEXP_FWD_CORE wxVarScrollHelperEvtHandler;
|
|||||||
// scrolwin.h) for the purpose of reducing code duplication |
|
// scrolwin.h) for the purpose of reducing code duplication |
|
||||||
// through the use of mix-in classes. |
|
// through the use of mix-in classes. |
|
||||||
// |
|
// |
|
||||||
|
// wxAnyScrollHelperBase |
|
||||||
|
// | |
|
||||||
|
// | |
|
||||||
|
// | |
|
||||||
|
// V |
|
||||||
// wxVarScrollHelperBase |
|
// wxVarScrollHelperBase |
|
||||||
// / \ |
|
// / \ |
|
||||||
// / \ |
|
// / \ |
|
||||||
@@ -58,7 +64,7 @@ class WXDLLIMPEXP_FWD_CORE wxVarScrollHelperEvtHandler;
|
|||||||
// required virtual functions that need to be implemented for any orientation
|
// required virtual functions that need to be implemented for any orientation
|
||||||
// specific work.
|
// specific work.
|
||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxVarScrollHelperBase
|
class WXDLLIMPEXP_CORE wxVarScrollHelperBase : public wxAnyScrollHelperBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// constructors and such
|
// constructors and such
|
||||||
@@ -114,7 +120,6 @@ public:
|
|||||||
// child of it in order to scroll only a portion the area between the
|
// child of it in order to scroll only a portion the area between the
|
||||||
// scrollbars (spreadsheet: only cell area will move).
|
// scrollbars (spreadsheet: only cell area will move).
|
||||||
virtual void SetTargetWindow(wxWindow *target);
|
virtual void SetTargetWindow(wxWindow *target);
|
||||||
virtual wxWindow *GetTargetWindow() const { return m_targetWindow; }
|
|
||||||
|
|
||||||
// Override this function to draw the graphic (or just process EVT_PAINT)
|
// Override this function to draw the graphic (or just process EVT_PAINT)
|
||||||
//virtual void OnDraw(wxDC& WXUNUSED(dc)) { }
|
//virtual void OnDraw(wxDC& WXUNUSED(dc)) { }
|
||||||
@@ -256,12 +261,6 @@ protected:
|
|||||||
void IncOrient(wxCoord& x, wxCoord& y, wxCoord inc);
|
void IncOrient(wxCoord& x, wxCoord& y, wxCoord inc);
|
||||||
|
|
||||||
private:
|
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
|
// the total number of (logical) units
|
||||||
size_t m_unitMax;
|
size_t m_unitMax;
|
||||||
|
|
||||||
|
@@ -310,17 +310,28 @@ bool wxScrollHelperEvtHandler::ProcessEvent(wxEvent& event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// wxScrollHelperBase implementation
|
// wxAnyScrollHelperBase and wxScrollHelperBase implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxAnyScrollHelperBase
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
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 construction
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxScrollHelperBase::wxScrollHelperBase(wxWindow *win)
|
wxScrollHelperBase::wxScrollHelperBase(wxWindow *win)
|
||||||
|
: wxAnyScrollHelperBase(win)
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( win, wxT("associated window can't be NULL in wxScrollHelper") );
|
|
||||||
|
|
||||||
m_xScrollPixelsPerLine =
|
m_xScrollPixelsPerLine =
|
||||||
m_yScrollPixelsPerLine =
|
m_yScrollPixelsPerLine =
|
||||||
m_xScrollPosition =
|
m_xScrollPosition =
|
||||||
@@ -341,15 +352,10 @@ wxScrollHelperBase::wxScrollHelperBase(wxWindow *win)
|
|||||||
m_wheelRotation = 0;
|
m_wheelRotation = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_win =
|
|
||||||
m_targetWindow = NULL;
|
|
||||||
|
|
||||||
m_timerAutoScroll = NULL;
|
m_timerAutoScroll = NULL;
|
||||||
|
|
||||||
m_handler = NULL;
|
m_handler = NULL;
|
||||||
|
|
||||||
m_win = win;
|
|
||||||
|
|
||||||
m_win->SetScrollHelper(static_cast<wxScrollHelper *>(this));
|
m_win->SetScrollHelper(static_cast<wxScrollHelper *>(this));
|
||||||
|
|
||||||
// by default, the associated window is also the target window
|
// by default, the associated window is also the target window
|
||||||
@@ -481,11 +487,6 @@ void wxScrollHelperBase::SetTargetWindow(wxWindow *target)
|
|||||||
DoSetTargetWindow(target);
|
DoSetTargetWindow(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxWindow *wxScrollHelperBase::GetTargetWindow() const
|
|
||||||
{
|
|
||||||
return m_targetWindow;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// scrolling implementation itself
|
// scrolling implementation itself
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -139,9 +139,8 @@ bool wxVarScrollHelperEvtHandler::ProcessEvent(wxEvent& event)
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxVarScrollHelperBase::wxVarScrollHelperBase(wxWindow *win)
|
wxVarScrollHelperBase::wxVarScrollHelperBase(wxWindow *win)
|
||||||
|
: wxAnyScrollHelperBase(win)
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( win, wxT("associated window can't be NULL in wxVarScrollHelperBase") );
|
|
||||||
|
|
||||||
#if wxUSE_MOUSEWHEEL
|
#if wxUSE_MOUSEWHEEL
|
||||||
m_sumWheelRotation = 0;
|
m_sumWheelRotation = 0;
|
||||||
#endif
|
#endif
|
||||||
@@ -150,17 +149,11 @@ wxVarScrollHelperBase::wxVarScrollHelperBase(wxWindow *win)
|
|||||||
m_sizeTotal = 0;
|
m_sizeTotal = 0;
|
||||||
m_unitFirst = 0;
|
m_unitFirst = 0;
|
||||||
|
|
||||||
m_win =
|
|
||||||
m_targetWindow = NULL;
|
|
||||||
|
|
||||||
m_physicalScrolling = true;
|
m_physicalScrolling = true;
|
||||||
m_handler = NULL;
|
m_handler = NULL;
|
||||||
|
|
||||||
m_win = win;
|
|
||||||
|
|
||||||
// by default, the associated window is also the target window
|
// by default, the associated window is also the target window
|
||||||
DoSetTargetWindow(win);
|
DoSetTargetWindow(win);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxVarScrollHelperBase::~wxVarScrollHelperBase()
|
wxVarScrollHelperBase::~wxVarScrollHelperBase()
|
||||||
|
Reference in New Issue
Block a user