+ // 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;
+#endif
+
+ // do child scrolling (used in DoPrepareDC())
+ bool m_physicalScrolling;
+
+ // handler injected into target window to forward some useful events to us
+ wxVarScrollHelperEvtHandler *m_handler;
+};
+
+
+
+// ===========================================================================
+// wxVarVScrollHelper
+// ===========================================================================
+
+// Provides public API functions targeted for vertical-specific scrolling,
+// wrapping the functionality of wxVarScrollHelperBase.
+
+class WXDLLIMPEXP_CORE wxVarVScrollHelper : public wxVarScrollHelperBase
+{
+public:
+ // constructors and such
+ // ---------------------
+
+ // ctor must be given the associated window
+ wxVarVScrollHelper(wxWindow *winToScroll)
+ : wxVarScrollHelperBase(winToScroll)
+ {
+ }
+
+ // operators
+
+ void SetRowCount(size_t rowCount) { SetUnitCount(rowCount); }
+ bool ScrollToRow(size_t row) { return DoScrollToUnit(row); }
+
+ virtual bool ScrollRows(int rows)
+ { return DoScrollUnits(rows); }
+ virtual bool ScrollRowPages(int pages)
+ { return DoScrollPages(pages); }
+
+ virtual void RefreshRow(size_t row)
+ { RefreshUnit(row); }
+ virtual void RefreshRows(size_t from, size_t to)
+ { RefreshUnits(from, to); }
+
+ // accessors
+
+ size_t GetRowCount() const { return GetUnitCount(); }
+ size_t GetVisibleRowsBegin() const { return GetVisibleBegin(); }
+ size_t GetVisibleRowsEnd() const { return GetVisibleEnd(); }
+ bool IsRowVisible(size_t row) const { return IsVisible(row); }
+
+ virtual int GetOrientationTargetSize() const
+ { return GetTargetWindow()->GetClientSize().y; }
+ virtual int GetNonOrientationTargetSize() const
+ { return GetTargetWindow()->GetClientSize().x; }
+ virtual wxOrientation GetOrientation() const { return wxVERTICAL; }
+
+protected:
+ // this function must be overridden in the derived class and it should
+ // return the size of the given row in pixels
+ virtual wxCoord OnGetRowHeight(size_t n) const = 0;
+ wxCoord OnGetUnitSize(size_t n) const { return OnGetRowHeight(n); }
+
+ virtual void OnGetRowsHeightHint(size_t WXUNUSED(rowMin),
+ size_t WXUNUSED(rowMax)) const { }
+
+ // forward calls to OnGetRowsHeightHint()
+ virtual void OnGetUnitsSizeHint(size_t unitMin, size_t unitMax) const
+ { OnGetRowsHeightHint(unitMin, unitMax); }
+
+ // again, if not overridden, it will fall back on default method
+ virtual wxCoord EstimateTotalHeight() const
+ { return DoEstimateTotalSize(); }
+
+ // forward calls to EstimateTotalHeight()
+ virtual wxCoord EstimateTotalSize() const { return EstimateTotalHeight(); }
+
+ wxCoord GetRowsHeight(size_t rowMin, size_t rowMax) const
+ { return GetUnitsSize(rowMin, rowMax); }
+};
+
+
+
+// ===========================================================================
+// wxVarHScrollHelper
+// ===========================================================================
+
+// Provides public API functions targeted for horizontal-specific scrolling,
+// wrapping the functionality of wxVarScrollHelperBase.
+
+class WXDLLIMPEXP_CORE wxVarHScrollHelper : public wxVarScrollHelperBase
+{
+public:
+ // constructors and such
+ // ---------------------
+
+ // ctor must be given the associated window
+ wxVarHScrollHelper(wxWindow *winToScroll)
+ : wxVarScrollHelperBase(winToScroll)
+ {
+ }
+
+ // operators
+
+ void SetColumnCount(size_t columnCount)
+ { SetUnitCount(columnCount); }
+
+ bool ScrollToColumn(size_t column)
+ { return DoScrollToUnit(column); }
+ virtual bool ScrollColumns(int columns)
+ { return DoScrollUnits(columns); }
+ virtual bool ScrollColumnPages(int pages)
+ { return DoScrollPages(pages); }
+
+ virtual void RefreshColumn(size_t column)
+ { RefreshUnit(column); }
+ virtual void RefreshColumns(size_t from, size_t to)
+ { RefreshUnits(from, to); }
+
+ // accessors
+
+ size_t GetColumnCount() const
+ { return GetUnitCount(); }
+ size_t GetVisibleColumnsBegin() const
+ { return GetVisibleBegin(); }
+ size_t GetVisibleColumnsEnd() const
+ { return GetVisibleEnd(); }
+ bool IsColumnVisible(size_t column) const
+ { return IsVisible(column); }
+
+
+ virtual int GetOrientationTargetSize() const
+ { return GetTargetWindow()->GetClientSize().x; }
+ virtual int GetNonOrientationTargetSize() const
+ { return GetTargetWindow()->GetClientSize().y; }
+ virtual wxOrientation GetOrientation() const { return wxHORIZONTAL; }
+
+protected:
+ // this function must be overridden in the derived class and it should
+ // return the size of the given column in pixels
+ virtual wxCoord OnGetColumnWidth(size_t n) const = 0;
+ wxCoord OnGetUnitSize(size_t n) const { return OnGetColumnWidth(n); }
+
+ virtual void OnGetColumnsWidthHint(size_t WXUNUSED(columnMin),
+ size_t WXUNUSED(columnMax)) const
+ { }
+
+ // forward calls to OnGetColumnsWidthHint()
+ virtual void OnGetUnitsSizeHint(size_t unitMin, size_t unitMax) const
+ { OnGetColumnsWidthHint(unitMin, unitMax); }
+
+ // again, if not overridden, it will fall back on default method
+ virtual wxCoord EstimateTotalWidth() const { return DoEstimateTotalSize(); }
+
+ // forward calls to EstimateTotalWidth()
+ virtual wxCoord EstimateTotalSize() const { return EstimateTotalWidth(); }
+
+ wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const
+ { return GetUnitsSize(columnMin, columnMax); }
+};
+
+
+
+// ===========================================================================
+// wxVarHVScrollHelper
+// ===========================================================================
+
+// Provides public API functions targeted at functions with similar names in
+// both wxVScrollHelper and wxHScrollHelper so class scope doesn't need to be
+// specified (since we are using multiple inheritance). It also provides
+// functions to make changing values for both orientations at the same time
+// easier.
+
+class WXDLLIMPEXP_CORE wxVarHVScrollHelper : public wxVarVScrollHelper,
+ public wxVarHScrollHelper
+{
+public:
+ // constructors and such
+ // ---------------------
+
+ // ctor must be given the associated window
+ wxVarHVScrollHelper(wxWindow *winToScroll)
+ : wxVarVScrollHelper(winToScroll), wxVarHScrollHelper(winToScroll) { }
+
+ // operators
+ // ---------
+
+ // set the number of units the window contains for each axis: the derived
+ // class must provide the widths and heights for all units with indices up
+ // to each of the one given here in its OnGetColumnWidth() and
+ // OnGetRowHeight()
+ void SetRowColumnCount(size_t rowCount, size_t columnCount);
+
+
+ // 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 vscrolling = true, bool hscrolling = true)
+ {
+ wxVarVScrollHelper::EnablePhysicalScrolling(vscrolling);
+ wxVarHScrollHelper::EnablePhysicalScrolling(hscrolling);
+ }
+
+ // scroll to the specified row/column: it will become the first visible
+ // cell in the window
+ //
+ // return true if we scrolled the window, false if nothing was done
+ bool ScrollToRowColumn(size_t row, size_t column);
+ bool ScrollToRowColumn(const wxPosition &pos)
+ { return ScrollToRowColumn(pos.GetRow(), pos.GetColumn()); }
+
+ // redraw the specified cell
+ virtual void RefreshRowColumn(size_t row, size_t column);
+ virtual void RefreshRowColumn(const wxPosition &pos)
+ { RefreshRowColumn(pos.GetRow(), pos.GetColumn()); }
+
+ // redraw the specified regions (inclusive). If the target window for
+ // both orientations is the same the rectangle of cells is refreshed; if
+ // the target windows differ the entire client size opposite the
+ // orientation direction is refreshed between the specified limits
+ virtual void RefreshRowsColumns(size_t fromRow, size_t toRow,
+ size_t fromColumn, size_t toColumn);
+ virtual void RefreshRowsColumns(const wxPosition& from,
+ const wxPosition& to)
+ {
+ RefreshRowsColumns(from.GetRow(), to.GetRow(),
+ from.GetColumn(), to.GetColumn());
+ }
+
+ // locate the virtual position from the given device coordinates
+ wxPosition VirtualHitTest(wxCoord x, wxCoord y) const;
+ wxPosition VirtualHitTest(const wxPoint &pos) const
+ { return VirtualHitTest(pos.x, pos.y); }
+
+ // change the DC origin according to the scroll position. To properly
+ // forward calls to wxWindow::Layout use WX_FORWARD_TO_SCROLL_HELPER()
+ // derived class. We use this version to call both base classes'
+ // DoPrepareDC()
+ virtual void DoPrepareDC(wxDC& dc);
+
+ // replacement implementation of wxWindow::Layout virtual method. To
+ // properly forward calls to wxWindow::Layout use
+ // WX_FORWARD_TO_SCROLL_HELPER() derived class. We use this version to
+ // call both base classes' ScrollLayout()
+ bool ScrollLayout();
+
+ // accessors
+ // ---------
+
+ // get the number of units this window contains (previously set by
+ // Set[Column/Row/RowColumn/Unit]Count())
+ wxSize GetRowColumnCount() const;
+
+ // get the first currently visible units
+ wxPosition GetVisibleBegin() const;
+ wxPosition GetVisibleEnd() const;
+
+ // is this cell currently visible?
+ bool IsVisible(size_t row, size_t column) const;
+ bool IsVisible(const wxPosition &pos) const
+ { return IsVisible(pos.GetRow(), pos.GetColumn()); }
+};
+
+
+
+#if WXWIN_COMPATIBILITY_2_8
+
+// ===========================================================================
+// wxVarVScrollLegacyAdaptor
+// ===========================================================================
+
+// Provides backwards compatible API for applications originally built using
+// wxVScrolledWindow in 2.6 or 2.8. Originally, wxVScrolledWindow referred
+// to scrolling "lines". We use "units" in wxVarScrollHelperBase to avoid
+// implying any orientation (since the functions are used for both horizontal
+// and vertical scrolling in derived classes). And in the new
+// wxVScrolledWindow and wxHScrolledWindow classes, we refer to them as
+// "rows" and "columns", respectively. This is to help clear some confusion
+// in not only those classes, but also in wxHVScrolledWindow where functions
+// are inherited from both.
+
+class WXDLLIMPEXP_CORE wxVarVScrollLegacyAdaptor : public wxVarVScrollHelper
+{
+public:
+ // constructors and such
+ // ---------------------
+ wxVarVScrollLegacyAdaptor(wxWindow *winToScroll)
+ : wxVarVScrollHelper(winToScroll)
+ {
+ }
+
+ // accessors
+ // ---------
+
+ // this is the same as GetVisibleRowsBegin(), exists to match
+ // GetLastVisibleLine() and for backwards compatibility only
+ wxDEPRECATED( size_t GetFirstVisibleLine() const );
+
+ // get the last currently visible line
+ //
+ // this function is unsafe as it returns (size_t)-1 (i.e. a huge positive
+ // number) if the control is empty, use GetVisibleRowsEnd() instead, this
+ // one is kept for backwards compatibility
+ wxDEPRECATED( size_t GetLastVisibleLine() const );
+
+ // "line" to "unit" compatibility functions
+ // ----------------------------------------
+
+ // get the number of lines this window contains (set by SetLineCount())
+ wxDEPRECATED( size_t GetLineCount() const );
+
+ // set the number of lines the helper contains: the derived class must
+ // provide the sizes for all lines with indices up to the one given here
+ // in its OnGetLineHeight()
+ wxDEPRECATED( void SetLineCount(size_t count) );
+
+ // redraw the specified line
+ wxDEPRECATED( virtual void RefreshLine(size_t line) );
+
+ // redraw all lines in the specified range (inclusive)
+ wxDEPRECATED( virtual void RefreshLines(size_t from, size_t to) );
+
+ // scroll to the specified line: it will become the first visible line in
+ // the window
+ //
+ // return true if we scrolled the window, false if nothing was done
+ wxDEPRECATED( bool ScrollToLine(size_t line) );
+
+ // scroll by the specified number of lines/pages
+ wxDEPRECATED( virtual bool ScrollLines(int lines) );
+ wxDEPRECATED( virtual bool ScrollPages(int pages) );
+
+protected:
+ // unless the code has been updated to override OnGetRowHeight() instead,
+ // this function must be overridden in the derived class and it should
+ // return the height of the given row in pixels
+ wxDEPRECATED_BUT_USED_INTERNALLY(
+ virtual wxCoord OnGetLineHeight(size_t n) const );
+
+ // forwards the calls from base class pure virtual function to pure virtual
+ // OnGetLineHeight instead (backwards compatible name)
+ // note that we don't need to forward OnGetUnitSize() as it is already
+ // forwarded to OnGetRowHeight() in wxVarVScrollHelper
+ virtual wxCoord OnGetRowHeight(size_t n) const;
+
+ // this function doesn't have to be overridden but it may be useful to do
+ // it if calculating the lines heights is a relatively expensive operation
+ // as it gives the user code a possibility to calculate several of them at
+ // once
+ //
+ // OnGetLinesHint() is normally called just before OnGetLineHeight() but you
+ // shouldn't rely on the latter being called for all lines in the interval
+ // specified here. It is also possible that OnGetLineHeight() will be
+ // called for the lines outside of this interval, so this is really just a
+ // hint, not a promise.
+ //
+ // finally note that lineMin is inclusive, while lineMax is exclusive, as
+ // usual
+ wxDEPRECATED_BUT_USED_INTERNALLY( virtual void OnGetLinesHint(
+ size_t lineMin, size_t lineMax) const );
+
+ // forwards the calls from base class pure virtual function to pure virtual
+ // OnGetLinesHint instead (backwards compatible name)
+ void OnGetRowsHeightHint(size_t rowMin, size_t rowMax) const;
+};
+
+#else // !WXWIN_COMPATIBILITY_2_8
+
+// shortcut to avoid checking compatibility modes later
+// remove this and all references to wxVarVScrollLegacyAdaptor once
+// wxWidgets 2.6 and 2.8 compatibility is removed
+typedef wxVarVScrollHelper wxVarVScrollLegacyAdaptor;
+
+#endif // WXWIN_COMPATIBILITY_2_8/!WXWIN_COMPATIBILITY_2_8
+
+
+// this macro must be used in declaration of wxVarScrollHelperBase-derived
+// classes
+#define WX_FORWARD_TO_VAR_SCROLL_HELPER() \
+public: \
+ virtual void PrepareDC(wxDC& dc) { DoPrepareDC(dc); } \
+ virtual bool Layout() { return ScrollLayout(); }
+
+
+
+// ===========================================================================