scrolling.h 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: scrolling.h
  3. // Purpose: topic overview
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @page overview_scrolling Scrolled Windows
  9. @tableofcontents
  10. Scrollbars come in various guises in wxWidgets. All windows have the potential
  11. to show a vertical scrollbar and/or a horizontal scrollbar: it is a basic
  12. capability of a window. However, in practice, not all windows do make use of
  13. scrollbars, such as a single-line wxTextCtrl.
  14. Because any class derived from wxWindow may have scrollbars, there are
  15. functions to manipulate the scrollbars and event handlers to intercept scroll
  16. events. But just because a window generates a scroll event, doesn't mean that
  17. the window necessarily handles it and physically scrolls the window. The base
  18. class wxWindow in fact doesn't have any default functionality to handle scroll
  19. events. If you created a wxWindow object with scrollbars, and then clicked on
  20. the scrollbars, nothing at all would happen. This is deliberate, because the
  21. @e interpretation of scroll events varies from one window class to another.
  22. ::wxScrolledWindow (formerly wxCanvas) is an example of a window that adds
  23. functionality to make scrolling really work. It assumes that scrolling happens
  24. in consistent units, not different-sized jumps, and that page size is
  25. represented by the visible portion of the window. It is suited to drawing
  26. applications, but perhaps not so suitable for a sophisticated editor in which
  27. the amount scrolled may vary according to the size of text on a given line. For
  28. this, you would derive from wxWindow and implement scrolling yourself. wxGrid
  29. is an example of a class that implements its own scrolling, largely because
  30. columns and rows can vary in size.
  31. @see wxScrollBar
  32. @section overview_scrolling_model The Scrollbar Model
  33. The function wxWindow::SetScrollbar gives a clue about the way a scrollbar is
  34. modeled. This function takes the following arguments:
  35. @beginTable
  36. @row2col{ @c orientation , Which scrollbar: wxVERTICAL or wxHORIZONTAL. }
  37. @row2col{ @c position , The position of the scrollbar in scroll units. }
  38. @row2col{ @c visible , The size of the visible portion of the scrollbar,
  39. in scroll units. }
  40. @row2col{ @c range , The maximum position of the scrollbar. }
  41. @row2col{ @c refresh , Whether the scrollbar should be repainted. }
  42. @endTable
  43. @c orientation determines whether we're talking about the built-in horizontal
  44. or vertical scrollbar.
  45. @c position is simply the position of the 'thumb' (the bit you drag to scroll
  46. around). It is given in scroll units, and so is relative to the total range of
  47. the scrollbar.
  48. @c visible gives the number of scroll units that represents the portion of the
  49. window currently visible. Normally, a scrollbar is capable of indicating this
  50. visually by showing a different length of thumb.
  51. @c range is the maximum value of the scrollbar, where zero is the start
  52. position. You choose the units that suit you, so if you wanted to display text
  53. that has 100 lines, you would set this to 100. Note that this doesn't have to
  54. correspond to the number of pixels scrolled - it is up to you how you actually
  55. show the contents of the window.
  56. @c refresh just indicates whether the scrollbar should be repainted immediately
  57. or not.
  58. @section overview_scrolling_example An Example
  59. Let's say you wish to display 50 lines of text, using the same font. The window
  60. is sized so that you can only see 16 lines at a time. You would use:
  61. @code
  62. SetScrollbar(wxVERTICAL, 0, 16, 50);
  63. @endcode
  64. Note that with the window at this size, the thumb position can never go above
  65. 50 minus 16, or 34. You can determine how many lines are currently visible by
  66. dividing the current view size by the character height in pixels.
  67. When defining your own scrollbar behaviour, you will always need to recalculate
  68. the scrollbar settings when the window size changes. You could therefore put
  69. your scrollbar calculations and SetScrollbar call into a function named
  70. AdjustScrollbars, which can be called initially and also from your wxSizeEvent
  71. handler function.
  72. */