]>
Commit | Line | Data |
---|---|---|
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 |
14 | Scrollbars come in various guises in wxWidgets. All windows have the potential |
15 | to show a vertical scrollbar and/or a horizontal scrollbar: it is a basic | |
16 | capability of a window. However, in practice, not all windows do make use of | |
17 | scrollbars, such as a single-line wxTextCtrl. | |
18 | ||
19 | Because any class derived from wxWindow may have scrollbars, there are | |
20 | functions to manipulate the scrollbars and event handlers to intercept scroll | |
21 | events. But just because a window generates a scroll event, doesn't mean that | |
22 | the window necessarily handles it and physically scrolls the window. The base | |
23 | class wxWindow in fact doesn't have any default functionality to handle scroll | |
24 | events. If you created a wxWindow object with scrollbars, and then clicked on | |
25 | the 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 |
29 | functionality to make scrolling really work. It assumes that scrolling happens |
30 | in consistent units, not different-sized jumps, and that page size is | |
31 | represented by the visible portion of the window. It is suited to drawing | |
32 | applications, but perhaps not so suitable for a sophisticated editor in which | |
33 | the amount scrolled may vary according to the size of text on a given line. For | |
34 | this, you would derive from wxWindow and implement scrolling yourself. wxGrid | |
35 | is an example of a class that implements its own scrolling, largely because | |
36 | columns 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 | ||
43 | The function wxWindow::SetScrollbar gives a clue about the way a scrollbar is | |
44 | modeled. 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 | |
56 | or vertical scrollbar. | |
57 | ||
58 | @c position is simply the position of the 'thumb' (the bit you drag to scroll | |
59 | around). It is given in scroll units, and so is relative to the total range of | |
60 | the scrollbar. | |
61 | ||
62 | @c visible gives the number of scroll units that represents the portion of the | |
63 | window currently visible. Normally, a scrollbar is capable of indicating this | |
64 | visually by showing a different length of thumb. | |
65 | ||
66 | @c range is the maximum value of the scrollbar, where zero is the start | |
67 | position. You choose the units that suit you, so if you wanted to display text | |
68 | that has 100 lines, you would set this to 100. Note that this doesn't have to | |
69 | correspond to the number of pixels scrolled - it is up to you how you actually | |
70 | show the contents of the window. | |
71 | ||
72 | @c refresh just indicates whether the scrollbar should be repainted immediately | |
73 | or not. | |
74 | ||
75 | ||
76 | @section overview_scrolling_example An Example | |
77 | ||
78 | Let's say you wish to display 50 lines of text, using the same font. The window | |
79 | is sized so that you can only see 16 lines at a time. You would use: | |
80 | ||
81 | @code | |
82 | SetScrollbar(wxVERTICAL, 0, 16, 50); | |
83 | @endcode | |
84 | ||
85 | Note that with the window at this size, the thumb position can never go above | |
86 | 50 minus 16, or 34. You can determine how many lines are currently visible by | |
87 | dividing the current view size by the character height in pixels. | |
88 | ||
89 | When defining your own scrollbar behaviour, you will always need to recalculate | |
90 | the scrollbar settings when the window size changes. You could therefore put | |
91 | your scrollbar calculations and SetScrollbar call into a function named | |
92 | AdjustScrollbars, which can be called initially and also from your wxSizeEvent | |
93 | handler function. | |
94 | ||
95 | */ |