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