+#include "wx/panel.h"
+#include "wx/position.h"
+
+class WXDLLIMPEXP_FWD_CORE wxVarScrollHelperEvtHandler;
+
+
+// Using the same techniques as the wxScrolledWindow class |
+// hierarchy, the wx[V/H/HV]ScrolledWindow classes are slightly |
+// more complex (compare with the diagram outlined in |
+// scrolwin.h) for the purpose of reducing code duplication |
+// through the use of mix-in classes. |
+// |
+// wxVarScrollHelperBase |
+// / \ |
+// / \ |
+// V V |
+// wxVarHScrollHelper wxVarVScrollHelper |
+// | \ / | |
+// | \ / | |
+// | V V | |
+// | wxVarHVScrollHelper | |
+// | | | |
+// | | V |
+// | wxPanel | wxVarVScrollLegacyAdaptor |
+// | / \ \ | | |
+// | / \ `-----|----------. | |
+// | / \ | \ | |
+// | / \ | \ | |
+// V V \ | V V |
+// wxHScrolledWindow \ | wxVScrolledWindow |
+// V V |
+// wxHVScrolledWindow |
+// |
+// |
+// Border added to suppress GCC multi-line comment warnings ->|
+
+
+// ===========================================================================
+// wxVarScrollHelperBase
+// ===========================================================================
+
+// Provides all base common scroll calculations needed for either orientation,
+// automatic scrollbar functionality, saved scroll positions, functionality
+// for changing the target window to be scrolled, as well as defining all
+// required virtual functions that need to be implemented for any orientation
+// specific work.
+
+class WXDLLEXPORT wxVarScrollHelperBase
+{
+public:
+ // constructors and such
+ // ---------------------
+
+ wxVarScrollHelperBase(wxWindow *winToScroll);
+ virtual ~wxVarScrollHelperBase();
+
+ // operations
+ // ----------
+
+ // with physical scrolling on, the device origin is changed properly when
+ // a wxPaintDC is prepared, children are actually moved and laid out
+ // properly, and the contents of the window (pixels) are actually moved
+ void EnablePhysicalScrolling(bool scrolling = true)
+ { m_physicalScrolling = scrolling; }
+
+ // wxNOT_FOUND if none, i.e. if it is below the last item
+ int VirtualHitTest(wxCoord coord) const;
+
+ // recalculate all our parameters and redisplay all units
+ virtual void RefreshAll();
+
+ // accessors
+ // ---------
+
+ // get the first currently visible unit
+ size_t GetVisibleBegin() const { return m_unitFirst; }
+
+ // get the last currently visible unit
+ size_t GetVisibleEnd() const
+ { return m_unitFirst + m_nUnitsVisible; }
+
+ // is this unit currently visible?
+ bool IsVisible(size_t unit) const
+ { return unit >= m_unitFirst && unit < GetVisibleEnd(); }
+
+ // translate between scrolled and unscrolled coordinates
+ int CalcScrolledPosition(int coord) const
+ { return DoCalcScrolledPosition(coord); }
+ int CalcUnscrolledPosition(int coord) const
+ { return DoCalcUnscrolledPosition(coord); }
+
+ virtual int DoCalcScrolledPosition(int coord) const;
+ virtual int DoCalcUnscrolledPosition(int coord) const;
+
+ // update the thumb size shown by the scrollbar
+ virtual void UpdateScrollbar();
+ void RemoveScrollbar();
+
+ // Normally the wxScrolledWindow will scroll itself, but in some rare
+ // occasions you might want it to scroll [part of] another window (e.g. a
+ // 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)) { }
+
+ // change the DC origin according to the scroll position. To properly
+ // forward calls to wxWindow::Layout use WX_FORWARD_TO_SCROLL_HELPER()
+ // derived class
+ virtual void DoPrepareDC(wxDC& dc);
+
+ // the methods to be called from the window event handlers
+ void HandleOnScroll(wxScrollWinEvent& event);
+ void HandleOnSize(wxSizeEvent& event);
+#if wxUSE_MOUSEWHEEL
+ void HandleOnMouseWheel(wxMouseEvent& event);
+#endif // wxUSE_MOUSEWHEEL
+
+ // these functions must be overidden in the derived class to return
+ // orientation specific data (e.g. the width for vertically scrolling
+ // derivatives in the case of GetOrientationTargetSize())
+ virtual int GetOrientationTargetSize() const = 0;
+ virtual int GetNonOrientationTargetSize() const = 0;
+ virtual wxOrientation GetOrientation() const = 0;
+
+protected:
+ // all *Unit* functions are protected to be exposed by
+ // wxVarScrollHelperBase implementations (with appropriate names)
+
+ // get the number of units this window contains (previously set by
+ // SetUnitCount())
+ size_t GetUnitCount() const { return m_unitMax; }
+
+ // set the number of units the helper contains: the derived class must
+ // provide the sizes for all units with indices up to the one given here
+ // in its OnGetUnitSize()
+ void SetUnitCount(size_t count);
+
+ // redraw the specified unit
+ virtual void RefreshUnit(size_t unit);
+
+ // redraw all units in the specified range (inclusive)
+ virtual void RefreshUnits(size_t from, size_t to);
+
+ // scroll to the specified unit: it will become the first visible unit in
+ // the window
+ //
+ // return true if we scrolled the window, false if nothing was done
+ bool DoScrollToUnit(size_t unit);
+
+ // scroll by the specified number of units/pages
+ virtual bool DoScrollUnits(int units);
+ virtual bool DoScrollPages(int pages);
+
+ // this function must be overridden in the derived class and it should
+ // return the size of the given unit in pixels
+ virtual wxCoord OnGetUnitSize(size_t n) const = 0;
+
+ // this function doesn't have to be overridden but it may be useful to do
+ // it if calculating the units' sizes is a relatively expensive operation
+ // as it gives the user code a possibility to calculate several of them at
+ // once
+ //
+ // OnGetUnitsSizeHint() is normally called just before OnGetUnitSize() but
+ // you shouldn't rely on the latter being called for all units in the
+ // interval specified here. It is also possible that OnGetUnitHeight() will
+ // be called for the units outside of this interval, so this is really just
+ // a hint, not a promise.
+ //
+ // finally note that unitMin is inclusive, while unitMax is exclusive, as
+ // usual
+ virtual void OnGetUnitsSizeHint(size_t WXUNUSED(unitMin),
+ size_t WXUNUSED(unitMax)) const
+ { }
+
+ // when the number of units changes, we try to estimate the total size
+ // of all units which is a rather expensive operation in terms of unit
+ // access, so if the user code may estimate the average size
+ // better/faster than we do, it should override this function to implement
+ // its own logic
+ //
+ // this function should return the best guess for the total size it may
+ // make
+ virtual wxCoord EstimateTotalSize() const { return DoEstimateTotalSize(); }
+
+ wxCoord DoEstimateTotalSize() const;
+
+ // find the index of the unit we need to show to fit the specified unit on
+ // the opposite side either fully or partially (depending on fullyVisible)
+ size_t FindFirstVisibleFromLast(size_t last,
+ bool fullyVisible = false) const;
+
+ // get the total size of the units between unitMin (inclusive) and
+ // unitMax (exclusive)
+ wxCoord GetUnitsSize(size_t unitMin, size_t unitMax) const;
+
+ // get the offset of the first visible unit
+ wxCoord GetScrollOffset() const
+ { return GetUnitsSize(0, GetVisibleBegin()); }
+
+ // get the size of the target window
+ wxSize GetTargetSize() const { return m_targetWindow->GetClientSize(); }
+
+ void GetTargetSize(int *w, int *h)
+ {
+ wxSize size = GetTargetSize();
+ if ( w )
+ *w = size.x;
+ if ( h )
+ *h = size.y;
+ }
+
+ // calculate the new scroll position based on scroll event type
+ size_t GetNewScrollPosition(wxScrollWinEvent& event) const;
+
+ // replacement implementation of wxWindow::Layout virtual method. To
+ // properly forward calls to wxWindow::Layout use
+ // WX_FORWARD_TO_SCROLL_HELPER() derived class
+ bool ScrollLayout();
+
+#ifdef __WXMAC__
+ // queue mac window update after handling scroll event
+ virtual void UpdateMacScrollWindow() = 0;
+#endif // __WXMAC__
+
+ // change the target window
+ void DoSetTargetWindow(wxWindow *target);
+
+ // delete the event handler we installed
+ void DeleteEvtHandler();
+
+ // helper function abstracting the orientation test: with vertical
+ // orientation, it assigns the first value to x and the second one to y,
+ // with horizontal orientation it reverses them, i.e. the first value is
+ // assigned to y and the second one to x
+ void AssignOrient(wxCoord& x, wxCoord& y, wxCoord first, wxCoord second);
+
+ // similar to "oriented assignment" above but does "oriented increment":
+ // for vertical orientation, y is incremented by the given value and x if
+ // left unchanged, for horizontal orientation x is incremented
+ 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;
+
+ // the total (estimated) size
+ wxCoord m_sizeTotal;
+
+ // the first currently visible unit
+ size_t m_unitFirst;
+
+ // the number of currently visible units (including the last, possibly only
+ // partly, visible one)
+ size_t m_nUnitsVisible;
+
+ // accumulated mouse wheel rotation
+#if wxUSE_MOUSEWHEEL
+ int m_sumWheelRotation;