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