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