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