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