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