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