vscroll.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/vscroll.h
  3. // Purpose: Variable scrolled windows (wx[V/H/HV]ScrolledWindow)
  4. // Author: Vadim Zeitlin
  5. // Modified by: Brad Anderson, Bryan Petty
  6. // Created: 30.05.03
  7. // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_VSCROLL_H_
  11. #define _WX_VSCROLL_H_
  12. #include "wx/panel.h"
  13. #include "wx/position.h"
  14. #include "wx/scrolwin.h"
  15. class WXDLLIMPEXP_FWD_CORE wxVarScrollHelperEvtHandler;
  16. // Using the same techniques as the wxScrolledWindow class |
  17. // hierarchy, the wx[V/H/HV]ScrolledWindow classes are slightly |
  18. // more complex (compare with the diagram outlined in |
  19. // scrolwin.h) for the purpose of reducing code duplication |
  20. // through the use of mix-in classes. |
  21. // |
  22. // wxAnyScrollHelperBase |
  23. // | |
  24. // | |
  25. // | |
  26. // V |
  27. // wxVarScrollHelperBase |
  28. // / \ |
  29. // / \ |
  30. // V V |
  31. // wxVarHScrollHelper wxVarVScrollHelper |
  32. // | \ / | |
  33. // | \ / | |
  34. // | V V | |
  35. // | wxVarHVScrollHelper | |
  36. // | | | |
  37. // | | V |
  38. // | wxPanel | wxVarVScrollLegacyAdaptor |
  39. // | / \ \ | | |
  40. // | / \ `-----|----------. | |
  41. // | / \ | \ | |
  42. // | / \ | \ | |
  43. // V V \ | V V |
  44. // wxHScrolledWindow \ | wxVScrolledWindow |
  45. // V V |
  46. // wxHVScrolledWindow |
  47. // |
  48. // |
  49. // Border added to suppress GCC multi-line comment warnings ->|
  50. // ===========================================================================
  51. // wxVarScrollHelperBase
  52. // ===========================================================================
  53. // Provides all base common scroll calculations needed for either orientation,
  54. // automatic scrollbar functionality, saved scroll positions, functionality
  55. // for changing the target window to be scrolled, as well as defining all
  56. // required virtual functions that need to be implemented for any orientation
  57. // specific work.
  58. class WXDLLIMPEXP_CORE wxVarScrollHelperBase : public wxAnyScrollHelperBase
  59. {
  60. public:
  61. // constructors and such
  62. // ---------------------
  63. wxVarScrollHelperBase(wxWindow *winToScroll);
  64. virtual ~wxVarScrollHelperBase();
  65. // operations
  66. // ----------
  67. // with physical scrolling on, the device origin is changed properly when
  68. // a wxPaintDC is prepared, children are actually moved and laid out
  69. // properly, and the contents of the window (pixels) are actually moved
  70. void EnablePhysicalScrolling(bool scrolling = true)
  71. { m_physicalScrolling = scrolling; }
  72. // wxNOT_FOUND if none, i.e. if it is below the last item
  73. int VirtualHitTest(wxCoord coord) const;
  74. // recalculate all our parameters and redisplay all units
  75. virtual void RefreshAll();
  76. // accessors
  77. // ---------
  78. // get the first currently visible unit
  79. size_t GetVisibleBegin() const { return m_unitFirst; }
  80. // get the last currently visible unit
  81. size_t GetVisibleEnd() const
  82. { return m_unitFirst + m_nUnitsVisible; }
  83. // is this unit currently visible?
  84. bool IsVisible(size_t unit) const
  85. { return unit >= m_unitFirst && unit < GetVisibleEnd(); }
  86. // translate between scrolled and unscrolled coordinates
  87. int CalcScrolledPosition(int coord) const
  88. { return DoCalcScrolledPosition(coord); }
  89. int CalcUnscrolledPosition(int coord) const
  90. { return DoCalcUnscrolledPosition(coord); }
  91. virtual int DoCalcScrolledPosition(int coord) const;
  92. virtual int DoCalcUnscrolledPosition(int coord) const;
  93. // update the thumb size shown by the scrollbar
  94. virtual void UpdateScrollbar();
  95. void RemoveScrollbar();
  96. // Normally the wxScrolledWindow will scroll itself, but in some rare
  97. // occasions you might want it to scroll [part of] another window (e.g. a
  98. // child of it in order to scroll only a portion the area between the
  99. // scrollbars (spreadsheet: only cell area will move).
  100. virtual void SetTargetWindow(wxWindow *target);
  101. // change the DC origin according to the scroll position. To properly
  102. // forward calls to wxWindow::Layout use WX_FORWARD_TO_SCROLL_HELPER()
  103. // derived class
  104. virtual void DoPrepareDC(wxDC& dc);
  105. // the methods to be called from the window event handlers
  106. void HandleOnScroll(wxScrollWinEvent& event);
  107. void HandleOnSize(wxSizeEvent& event);
  108. #if wxUSE_MOUSEWHEEL
  109. void HandleOnMouseWheel(wxMouseEvent& event);
  110. #endif // wxUSE_MOUSEWHEEL
  111. // these functions must be overidden in the derived class to return
  112. // orientation specific data (e.g. the width for vertically scrolling
  113. // derivatives in the case of GetOrientationTargetSize())
  114. virtual int GetOrientationTargetSize() const = 0;
  115. virtual int GetNonOrientationTargetSize() const = 0;
  116. virtual wxOrientation GetOrientation() const = 0;
  117. protected:
  118. // all *Unit* functions are protected to be exposed by
  119. // wxVarScrollHelperBase implementations (with appropriate names)
  120. // get the number of units this window contains (previously set by
  121. // SetUnitCount())
  122. size_t GetUnitCount() const { return m_unitMax; }
  123. // set the number of units the helper contains: the derived class must
  124. // provide the sizes for all units with indices up to the one given here
  125. // in its OnGetUnitSize()
  126. void SetUnitCount(size_t count);
  127. // redraw the specified unit
  128. virtual void RefreshUnit(size_t unit);
  129. // redraw all units in the specified range (inclusive)
  130. virtual void RefreshUnits(size_t from, size_t to);
  131. // scroll to the specified unit: it will become the first visible unit in
  132. // the window
  133. //
  134. // return true if we scrolled the window, false if nothing was done
  135. bool DoScrollToUnit(size_t unit);
  136. // scroll by the specified number of units/pages
  137. virtual bool DoScrollUnits(int units);
  138. virtual bool DoScrollPages(int pages);
  139. // this function must be overridden in the derived class and it should
  140. // return the size of the given unit in pixels
  141. virtual wxCoord OnGetUnitSize(size_t n) const = 0;
  142. // this function doesn't have to be overridden but it may be useful to do
  143. // it if calculating the units' sizes is a relatively expensive operation
  144. // as it gives the user code a possibility to calculate several of them at
  145. // once
  146. //
  147. // OnGetUnitsSizeHint() is normally called just before OnGetUnitSize() but
  148. // you shouldn't rely on the latter being called for all units in the
  149. // interval specified here. It is also possible that OnGetUnitHeight() will
  150. // be called for the units outside of this interval, so this is really just
  151. // a hint, not a promise.
  152. //
  153. // finally note that unitMin is inclusive, while unitMax is exclusive, as
  154. // usual
  155. virtual void OnGetUnitsSizeHint(size_t WXUNUSED(unitMin),
  156. size_t WXUNUSED(unitMax)) const
  157. { }
  158. // when the number of units changes, we try to estimate the total size
  159. // of all units which is a rather expensive operation in terms of unit
  160. // access, so if the user code may estimate the average size
  161. // better/faster than we do, it should override this function to implement
  162. // its own logic
  163. //
  164. // this function should return the best guess for the total size it may
  165. // make
  166. virtual wxCoord EstimateTotalSize() const { return DoEstimateTotalSize(); }
  167. wxCoord DoEstimateTotalSize() const;
  168. // find the index of the unit we need to show to fit the specified unit on
  169. // the opposite side either fully or partially (depending on fullyVisible)
  170. size_t FindFirstVisibleFromLast(size_t last,
  171. bool fullyVisible = false) const;
  172. // get the total size of the units between unitMin (inclusive) and
  173. // unitMax (exclusive)
  174. wxCoord GetUnitsSize(size_t unitMin, size_t unitMax) const;
  175. // get the offset of the first visible unit
  176. wxCoord GetScrollOffset() const
  177. { return GetUnitsSize(0, GetVisibleBegin()); }
  178. // get the size of the target window
  179. wxSize GetTargetSize() const { return m_targetWindow->GetClientSize(); }
  180. void GetTargetSize(int *w, int *h)
  181. {
  182. wxSize size = GetTargetSize();
  183. if ( w )
  184. *w = size.x;
  185. if ( h )
  186. *h = size.y;
  187. }
  188. // calculate the new scroll position based on scroll event type
  189. size_t GetNewScrollPosition(wxScrollWinEvent& event) const;
  190. // replacement implementation of wxWindow::Layout virtual method. To
  191. // properly forward calls to wxWindow::Layout use
  192. // WX_FORWARD_TO_SCROLL_HELPER() derived class
  193. bool ScrollLayout();
  194. #ifdef __WXMAC__
  195. // queue mac window update after handling scroll event
  196. virtual void UpdateMacScrollWindow() { }
  197. #endif // __WXMAC__
  198. // change the target window
  199. void DoSetTargetWindow(wxWindow *target);
  200. // delete the event handler we installed
  201. void DeleteEvtHandler();
  202. // helper function abstracting the orientation test: with vertical
  203. // orientation, it assigns the first value to x and the second one to y,
  204. // with horizontal orientation it reverses them, i.e. the first value is
  205. // assigned to y and the second one to x
  206. void AssignOrient(wxCoord& x, wxCoord& y, wxCoord first, wxCoord second);
  207. // similar to "oriented assignment" above but does "oriented increment":
  208. // for vertical orientation, y is incremented by the given value and x if
  209. // left unchanged, for horizontal orientation x is incremented
  210. void IncOrient(wxCoord& x, wxCoord& y, wxCoord inc);
  211. private:
  212. // the total number of (logical) units
  213. size_t m_unitMax;
  214. // the total (estimated) size
  215. wxCoord m_sizeTotal;
  216. // the first currently visible unit
  217. size_t m_unitFirst;
  218. // the number of currently visible units (including the last, possibly only
  219. // partly, visible one)
  220. size_t m_nUnitsVisible;
  221. // accumulated mouse wheel rotation
  222. #if wxUSE_MOUSEWHEEL
  223. int m_sumWheelRotation;
  224. #endif
  225. // do child scrolling (used in DoPrepareDC())
  226. bool m_physicalScrolling;
  227. // handler injected into target window to forward some useful events to us
  228. wxVarScrollHelperEvtHandler *m_handler;
  229. };
  230. // ===========================================================================
  231. // wxVarVScrollHelper
  232. // ===========================================================================
  233. // Provides public API functions targeted for vertical-specific scrolling,
  234. // wrapping the functionality of wxVarScrollHelperBase.
  235. class WXDLLIMPEXP_CORE wxVarVScrollHelper : public wxVarScrollHelperBase
  236. {
  237. public:
  238. // constructors and such
  239. // ---------------------
  240. // ctor must be given the associated window
  241. wxVarVScrollHelper(wxWindow *winToScroll)
  242. : wxVarScrollHelperBase(winToScroll)
  243. {
  244. }
  245. // operators
  246. void SetRowCount(size_t rowCount) { SetUnitCount(rowCount); }
  247. bool ScrollToRow(size_t row) { return DoScrollToUnit(row); }
  248. virtual bool ScrollRows(int rows)
  249. { return DoScrollUnits(rows); }
  250. virtual bool ScrollRowPages(int pages)
  251. { return DoScrollPages(pages); }
  252. virtual void RefreshRow(size_t row)
  253. { RefreshUnit(row); }
  254. virtual void RefreshRows(size_t from, size_t to)
  255. { RefreshUnits(from, to); }
  256. // accessors
  257. size_t GetRowCount() const { return GetUnitCount(); }
  258. size_t GetVisibleRowsBegin() const { return GetVisibleBegin(); }
  259. size_t GetVisibleRowsEnd() const { return GetVisibleEnd(); }
  260. bool IsRowVisible(size_t row) const { return IsVisible(row); }
  261. virtual int GetOrientationTargetSize() const
  262. { return GetTargetWindow()->GetClientSize().y; }
  263. virtual int GetNonOrientationTargetSize() const
  264. { return GetTargetWindow()->GetClientSize().x; }
  265. virtual wxOrientation GetOrientation() const { return wxVERTICAL; }
  266. protected:
  267. // this function must be overridden in the derived class and it should
  268. // return the size of the given row in pixels
  269. virtual wxCoord OnGetRowHeight(size_t n) const = 0;
  270. wxCoord OnGetUnitSize(size_t n) const { return OnGetRowHeight(n); }
  271. virtual void OnGetRowsHeightHint(size_t WXUNUSED(rowMin),
  272. size_t WXUNUSED(rowMax)) const { }
  273. // forward calls to OnGetRowsHeightHint()
  274. virtual void OnGetUnitsSizeHint(size_t unitMin, size_t unitMax) const
  275. { OnGetRowsHeightHint(unitMin, unitMax); }
  276. // again, if not overridden, it will fall back on default method
  277. virtual wxCoord EstimateTotalHeight() const
  278. { return DoEstimateTotalSize(); }
  279. // forward calls to EstimateTotalHeight()
  280. virtual wxCoord EstimateTotalSize() const { return EstimateTotalHeight(); }
  281. wxCoord GetRowsHeight(size_t rowMin, size_t rowMax) const
  282. { return GetUnitsSize(rowMin, rowMax); }
  283. };
  284. // ===========================================================================
  285. // wxVarHScrollHelper
  286. // ===========================================================================
  287. // Provides public API functions targeted for horizontal-specific scrolling,
  288. // wrapping the functionality of wxVarScrollHelperBase.
  289. class WXDLLIMPEXP_CORE wxVarHScrollHelper : public wxVarScrollHelperBase
  290. {
  291. public:
  292. // constructors and such
  293. // ---------------------
  294. // ctor must be given the associated window
  295. wxVarHScrollHelper(wxWindow *winToScroll)
  296. : wxVarScrollHelperBase(winToScroll)
  297. {
  298. }
  299. // operators
  300. void SetColumnCount(size_t columnCount)
  301. { SetUnitCount(columnCount); }
  302. bool ScrollToColumn(size_t column)
  303. { return DoScrollToUnit(column); }
  304. virtual bool ScrollColumns(int columns)
  305. { return DoScrollUnits(columns); }
  306. virtual bool ScrollColumnPages(int pages)
  307. { return DoScrollPages(pages); }
  308. virtual void RefreshColumn(size_t column)
  309. { RefreshUnit(column); }
  310. virtual void RefreshColumns(size_t from, size_t to)
  311. { RefreshUnits(from, to); }
  312. // accessors
  313. size_t GetColumnCount() const
  314. { return GetUnitCount(); }
  315. size_t GetVisibleColumnsBegin() const
  316. { return GetVisibleBegin(); }
  317. size_t GetVisibleColumnsEnd() const
  318. { return GetVisibleEnd(); }
  319. bool IsColumnVisible(size_t column) const
  320. { return IsVisible(column); }
  321. virtual int GetOrientationTargetSize() const
  322. { return GetTargetWindow()->GetClientSize().x; }
  323. virtual int GetNonOrientationTargetSize() const
  324. { return GetTargetWindow()->GetClientSize().y; }
  325. virtual wxOrientation GetOrientation() const { return wxHORIZONTAL; }
  326. protected:
  327. // this function must be overridden in the derived class and it should
  328. // return the size of the given column in pixels
  329. virtual wxCoord OnGetColumnWidth(size_t n) const = 0;
  330. wxCoord OnGetUnitSize(size_t n) const { return OnGetColumnWidth(n); }
  331. virtual void OnGetColumnsWidthHint(size_t WXUNUSED(columnMin),
  332. size_t WXUNUSED(columnMax)) const
  333. { }
  334. // forward calls to OnGetColumnsWidthHint()
  335. virtual void OnGetUnitsSizeHint(size_t unitMin, size_t unitMax) const
  336. { OnGetColumnsWidthHint(unitMin, unitMax); }
  337. // again, if not overridden, it will fall back on default method
  338. virtual wxCoord EstimateTotalWidth() const { return DoEstimateTotalSize(); }
  339. // forward calls to EstimateTotalWidth()
  340. virtual wxCoord EstimateTotalSize() const { return EstimateTotalWidth(); }
  341. wxCoord GetColumnsWidth(size_t columnMin, size_t columnMax) const
  342. { return GetUnitsSize(columnMin, columnMax); }
  343. };
  344. // ===========================================================================
  345. // wxVarHVScrollHelper
  346. // ===========================================================================
  347. // Provides public API functions targeted at functions with similar names in
  348. // both wxVScrollHelper and wxHScrollHelper so class scope doesn't need to be
  349. // specified (since we are using multiple inheritance). It also provides
  350. // functions to make changing values for both orientations at the same time
  351. // easier.
  352. class WXDLLIMPEXP_CORE wxVarHVScrollHelper : public wxVarVScrollHelper,
  353. public wxVarHScrollHelper
  354. {
  355. public:
  356. // constructors and such
  357. // ---------------------
  358. // ctor must be given the associated window
  359. wxVarHVScrollHelper(wxWindow *winToScroll)
  360. : wxVarVScrollHelper(winToScroll), wxVarHScrollHelper(winToScroll) { }
  361. // operators
  362. // ---------
  363. // set the number of units the window contains for each axis: the derived
  364. // class must provide the widths and heights for all units with indices up
  365. // to each of the one given here in its OnGetColumnWidth() and
  366. // OnGetRowHeight()
  367. void SetRowColumnCount(size_t rowCount, size_t columnCount);
  368. // with physical scrolling on, the device origin is changed properly when
  369. // a wxPaintDC is prepared, children are actually moved and laid out
  370. // properly, and the contents of the window (pixels) are actually moved
  371. void EnablePhysicalScrolling(bool vscrolling = true, bool hscrolling = true)
  372. {
  373. wxVarVScrollHelper::EnablePhysicalScrolling(vscrolling);
  374. wxVarHScrollHelper::EnablePhysicalScrolling(hscrolling);
  375. }
  376. // scroll to the specified row/column: it will become the first visible
  377. // cell in the window
  378. //
  379. // return true if we scrolled the window, false if nothing was done
  380. bool ScrollToRowColumn(size_t row, size_t column);
  381. bool ScrollToRowColumn(const wxPosition &pos)
  382. { return ScrollToRowColumn(pos.GetRow(), pos.GetColumn()); }
  383. // redraw the specified cell
  384. virtual void RefreshRowColumn(size_t row, size_t column);
  385. virtual void RefreshRowColumn(const wxPosition &pos)
  386. { RefreshRowColumn(pos.GetRow(), pos.GetColumn()); }
  387. // redraw the specified regions (inclusive). If the target window for
  388. // both orientations is the same the rectangle of cells is refreshed; if
  389. // the target windows differ the entire client size opposite the
  390. // orientation direction is refreshed between the specified limits
  391. virtual void RefreshRowsColumns(size_t fromRow, size_t toRow,
  392. size_t fromColumn, size_t toColumn);
  393. virtual void RefreshRowsColumns(const wxPosition& from,
  394. const wxPosition& to)
  395. {
  396. RefreshRowsColumns(from.GetRow(), to.GetRow(),
  397. from.GetColumn(), to.GetColumn());
  398. }
  399. // locate the virtual position from the given device coordinates
  400. wxPosition VirtualHitTest(wxCoord x, wxCoord y) const;
  401. wxPosition VirtualHitTest(const wxPoint &pos) const
  402. { return VirtualHitTest(pos.x, pos.y); }
  403. // change the DC origin according to the scroll position. To properly
  404. // forward calls to wxWindow::Layout use WX_FORWARD_TO_SCROLL_HELPER()
  405. // derived class. We use this version to call both base classes'
  406. // DoPrepareDC()
  407. virtual void DoPrepareDC(wxDC& dc);
  408. // replacement implementation of wxWindow::Layout virtual method. To
  409. // properly forward calls to wxWindow::Layout use
  410. // WX_FORWARD_TO_SCROLL_HELPER() derived class. We use this version to
  411. // call both base classes' ScrollLayout()
  412. bool ScrollLayout();
  413. // accessors
  414. // ---------
  415. // get the number of units this window contains (previously set by
  416. // Set[Column/Row/RowColumn/Unit]Count())
  417. wxSize GetRowColumnCount() const;
  418. // get the first currently visible units
  419. wxPosition GetVisibleBegin() const;
  420. wxPosition GetVisibleEnd() const;
  421. // is this cell currently visible?
  422. bool IsVisible(size_t row, size_t column) const;
  423. bool IsVisible(const wxPosition &pos) const
  424. { return IsVisible(pos.GetRow(), pos.GetColumn()); }
  425. };
  426. #if WXWIN_COMPATIBILITY_2_8
  427. // ===========================================================================
  428. // wxVarVScrollLegacyAdaptor
  429. // ===========================================================================
  430. // Provides backwards compatible API for applications originally built using
  431. // wxVScrolledWindow in 2.6 or 2.8. Originally, wxVScrolledWindow referred
  432. // to scrolling "lines". We use "units" in wxVarScrollHelperBase to avoid
  433. // implying any orientation (since the functions are used for both horizontal
  434. // and vertical scrolling in derived classes). And in the new
  435. // wxVScrolledWindow and wxHScrolledWindow classes, we refer to them as
  436. // "rows" and "columns", respectively. This is to help clear some confusion
  437. // in not only those classes, but also in wxHVScrolledWindow where functions
  438. // are inherited from both.
  439. class WXDLLIMPEXP_CORE wxVarVScrollLegacyAdaptor : public wxVarVScrollHelper
  440. {
  441. public:
  442. // constructors and such
  443. // ---------------------
  444. wxVarVScrollLegacyAdaptor(wxWindow *winToScroll)
  445. : wxVarVScrollHelper(winToScroll)
  446. {
  447. }
  448. // accessors
  449. // ---------
  450. // this is the same as GetVisibleRowsBegin(), exists to match
  451. // GetLastVisibleLine() and for backwards compatibility only
  452. wxDEPRECATED( size_t GetFirstVisibleLine() const );
  453. // get the last currently visible line
  454. //
  455. // this function is unsafe as it returns (size_t)-1 (i.e. a huge positive
  456. // number) if the control is empty, use GetVisibleRowsEnd() instead, this
  457. // one is kept for backwards compatibility
  458. wxDEPRECATED( size_t GetLastVisibleLine() const );
  459. // "line" to "unit" compatibility functions
  460. // ----------------------------------------
  461. // get the number of lines this window contains (set by SetLineCount())
  462. wxDEPRECATED( size_t GetLineCount() const );
  463. // set the number of lines the helper contains: the derived class must
  464. // provide the sizes for all lines with indices up to the one given here
  465. // in its OnGetLineHeight()
  466. wxDEPRECATED( void SetLineCount(size_t count) );
  467. // redraw the specified line
  468. wxDEPRECATED( virtual void RefreshLine(size_t line) );
  469. // redraw all lines in the specified range (inclusive)
  470. wxDEPRECATED( virtual void RefreshLines(size_t from, size_t to) );
  471. // scroll to the specified line: it will become the first visible line in
  472. // the window
  473. //
  474. // return true if we scrolled the window, false if nothing was done
  475. wxDEPRECATED( bool ScrollToLine(size_t line) );
  476. // scroll by the specified number of lines/pages
  477. wxDEPRECATED( virtual bool ScrollLines(int lines) );
  478. wxDEPRECATED( virtual bool ScrollPages(int pages) );
  479. protected:
  480. // unless the code has been updated to override OnGetRowHeight() instead,
  481. // this function must be overridden in the derived class and it should
  482. // return the height of the given row in pixels
  483. wxDEPRECATED_BUT_USED_INTERNALLY(
  484. virtual wxCoord OnGetLineHeight(size_t n) const );
  485. // forwards the calls from base class pure virtual function to pure virtual
  486. // OnGetLineHeight instead (backwards compatible name)
  487. // note that we don't need to forward OnGetUnitSize() as it is already
  488. // forwarded to OnGetRowHeight() in wxVarVScrollHelper
  489. virtual wxCoord OnGetRowHeight(size_t n) const;
  490. // this function doesn't have to be overridden but it may be useful to do
  491. // it if calculating the lines heights is a relatively expensive operation
  492. // as it gives the user code a possibility to calculate several of them at
  493. // once
  494. //
  495. // OnGetLinesHint() is normally called just before OnGetLineHeight() but you
  496. // shouldn't rely on the latter being called for all lines in the interval
  497. // specified here. It is also possible that OnGetLineHeight() will be
  498. // called for the lines outside of this interval, so this is really just a
  499. // hint, not a promise.
  500. //
  501. // finally note that lineMin is inclusive, while lineMax is exclusive, as
  502. // usual
  503. wxDEPRECATED_BUT_USED_INTERNALLY( virtual void OnGetLinesHint(
  504. size_t lineMin, size_t lineMax) const );
  505. // forwards the calls from base class pure virtual function to pure virtual
  506. // OnGetLinesHint instead (backwards compatible name)
  507. void OnGetRowsHeightHint(size_t rowMin, size_t rowMax) const;
  508. };
  509. #else // !WXWIN_COMPATIBILITY_2_8
  510. // shortcut to avoid checking compatibility modes later
  511. // remove this and all references to wxVarVScrollLegacyAdaptor once
  512. // wxWidgets 2.6 and 2.8 compatibility is removed
  513. typedef wxVarVScrollHelper wxVarVScrollLegacyAdaptor;
  514. #endif // WXWIN_COMPATIBILITY_2_8/!WXWIN_COMPATIBILITY_2_8
  515. // this macro must be used in declaration of wxVarScrollHelperBase-derived
  516. // classes
  517. #define WX_FORWARD_TO_VAR_SCROLL_HELPER() \
  518. public: \
  519. virtual void PrepareDC(wxDC& dc) { DoPrepareDC(dc); } \
  520. virtual bool Layout() { return ScrollLayout(); }
  521. // ===========================================================================
  522. // wxVScrolledWindow
  523. // ===========================================================================
  524. // In the name of this class, "V" may stand for "variable" because it can be
  525. // used for scrolling rows of variable heights; "virtual", because it is not
  526. // necessary to know the heights of all rows in advance -- only those which
  527. // are shown on the screen need to be measured; or even "vertical", because
  528. // this class only supports scrolling vertically.
  529. // In any case, this is a generalization of the wxScrolledWindow class which
  530. // can be only used when all rows have the same heights. It lacks some other
  531. // wxScrolledWindow features however, notably it can't scroll only a rectangle
  532. // of the window and not its entire client area.
  533. class WXDLLIMPEXP_CORE wxVScrolledWindow : public wxPanel,
  534. public wxVarVScrollLegacyAdaptor
  535. {
  536. public:
  537. // constructors and such
  538. // ---------------------
  539. // default ctor, you must call Create() later
  540. wxVScrolledWindow() : wxVarVScrollLegacyAdaptor(this) { }
  541. // normal ctor, no need to call Create() after this one
  542. //
  543. // note that wxVSCROLL is always automatically added to our style, there is
  544. // no need to specify it explicitly
  545. wxVScrolledWindow(wxWindow *parent,
  546. wxWindowID id = wxID_ANY,
  547. const wxPoint& pos = wxDefaultPosition,
  548. const wxSize& size = wxDefaultSize,
  549. long style = 0,
  550. const wxString& name = wxPanelNameStr)
  551. : wxVarVScrollLegacyAdaptor(this)
  552. {
  553. (void)Create(parent, id, pos, size, style, name);
  554. }
  555. // same as the previous ctor but returns status code: true if ok
  556. //
  557. // just as with the ctor above, wxVSCROLL style is always used, there is no
  558. // need to specify it
  559. bool Create(wxWindow *parent,
  560. wxWindowID id = wxID_ANY,
  561. const wxPoint& pos = wxDefaultPosition,
  562. const wxSize& size = wxDefaultSize,
  563. long style = 0,
  564. const wxString& name = wxPanelNameStr)
  565. {
  566. return wxPanel::Create(parent, id, pos, size, style | wxVSCROLL, name);
  567. }
  568. #if WXWIN_COMPATIBILITY_2_8
  569. // Make sure we prefer our version of HitTest rather than wxWindow's
  570. // These functions should no longer be masked in favor of VirtualHitTest()
  571. int HitTest(wxCoord WXUNUSED(x), wxCoord y) const
  572. { return wxVarVScrollHelper::VirtualHitTest(y); }
  573. int HitTest(const wxPoint& pt) const
  574. { return HitTest(pt.x, pt.y); }
  575. #endif // WXWIN_COMPATIBILITY_2_8
  576. WX_FORWARD_TO_VAR_SCROLL_HELPER()
  577. #ifdef __WXMAC__
  578. protected:
  579. virtual void UpdateMacScrollWindow() { Update(); }
  580. #endif // __WXMAC__
  581. private:
  582. wxDECLARE_NO_COPY_CLASS(wxVScrolledWindow);
  583. DECLARE_ABSTRACT_CLASS(wxVScrolledWindow)
  584. };
  585. // ===========================================================================
  586. // wxHScrolledWindow
  587. // ===========================================================================
  588. // In the name of this class, "H" stands for "horizontal" because it can be
  589. // used for scrolling columns of variable widths. It is not necessary to know
  590. // the widths of all columns in advance -- only those which are shown on the
  591. // screen need to be measured.
  592. // This is a generalization of the wxScrolledWindow class which can be only
  593. // used when all columns have the same width. It lacks some other
  594. // wxScrolledWindow features however, notably it can't scroll only a rectangle
  595. // of the window and not its entire client area.
  596. class WXDLLIMPEXP_CORE wxHScrolledWindow : public wxPanel,
  597. public wxVarHScrollHelper
  598. {
  599. public:
  600. // constructors and such
  601. // ---------------------
  602. // default ctor, you must call Create() later
  603. wxHScrolledWindow() : wxVarHScrollHelper(this) { }
  604. // normal ctor, no need to call Create() after this one
  605. //
  606. // note that wxHSCROLL is always automatically added to our style, there is
  607. // no need to specify it explicitly
  608. wxHScrolledWindow(wxWindow *parent,
  609. wxWindowID id = wxID_ANY,
  610. const wxPoint& pos = wxDefaultPosition,
  611. const wxSize& size = wxDefaultSize,
  612. long style = 0,
  613. const wxString& name = wxPanelNameStr)
  614. : wxVarHScrollHelper(this)
  615. {
  616. (void)Create(parent, id, pos, size, style, name);
  617. }
  618. // same as the previous ctor but returns status code: true if ok
  619. //
  620. // just as with the ctor above, wxHSCROLL style is always used, there is no
  621. // need to specify it
  622. bool Create(wxWindow *parent,
  623. wxWindowID id = wxID_ANY,
  624. const wxPoint& pos = wxDefaultPosition,
  625. const wxSize& size = wxDefaultSize,
  626. long style = 0,
  627. const wxString& name = wxPanelNameStr)
  628. {
  629. return wxPanel::Create(parent, id, pos, size, style | wxHSCROLL, name);
  630. }
  631. WX_FORWARD_TO_VAR_SCROLL_HELPER()
  632. #ifdef __WXMAC__
  633. protected:
  634. virtual void UpdateMacScrollWindow() { Update(); }
  635. #endif // __WXMAC__
  636. private:
  637. wxDECLARE_NO_COPY_CLASS(wxHScrolledWindow);
  638. DECLARE_ABSTRACT_CLASS(wxHScrolledWindow)
  639. };
  640. // ===========================================================================
  641. // wxHVScrolledWindow
  642. // ===========================================================================
  643. // This window inherits all functionality of both vertical and horizontal
  644. // scrolled windows automatically handling everything needed to scroll both
  645. // axis simultaneously.
  646. class WXDLLIMPEXP_CORE wxHVScrolledWindow : public wxPanel,
  647. public wxVarHVScrollHelper
  648. {
  649. public:
  650. // constructors and such
  651. // ---------------------
  652. // default ctor, you must call Create() later
  653. wxHVScrolledWindow()
  654. : wxPanel(),
  655. wxVarHVScrollHelper(this) { }
  656. // normal ctor, no need to call Create() after this one
  657. //
  658. // note that wxVSCROLL and wxHSCROLL are always automatically added to our
  659. // style, there is no need to specify them explicitly
  660. wxHVScrolledWindow(wxWindow *parent,
  661. wxWindowID id = wxID_ANY,
  662. const wxPoint& pos = wxDefaultPosition,
  663. const wxSize& size = wxDefaultSize,
  664. long style = 0,
  665. const wxString& name = wxPanelNameStr)
  666. : wxPanel(),
  667. wxVarHVScrollHelper(this)
  668. {
  669. (void)Create(parent, id, pos, size, style, name);
  670. }
  671. // same as the previous ctor but returns status code: true if ok
  672. //
  673. // just as with the ctor above, wxVSCROLL and wxHSCROLL styles are always
  674. // used, there is no need to specify them
  675. bool Create(wxWindow *parent,
  676. wxWindowID id = wxID_ANY,
  677. const wxPoint& pos = wxDefaultPosition,
  678. const wxSize& size = wxDefaultSize,
  679. long style = 0,
  680. const wxString& name = wxPanelNameStr)
  681. {
  682. return wxPanel::Create(parent, id, pos, size,
  683. style | wxVSCROLL | wxHSCROLL, name);
  684. }
  685. WX_FORWARD_TO_VAR_SCROLL_HELPER()
  686. #ifdef __WXMAC__
  687. protected:
  688. virtual void UpdateMacScrollWindow() { Update(); }
  689. #endif // __WXMAC__
  690. private:
  691. wxDECLARE_NO_COPY_CLASS(wxHVScrolledWindow);
  692. DECLARE_ABSTRACT_CLASS(wxHVScrolledWindow)
  693. };
  694. #endif // _WX_VSCROLL_H_