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