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