]> git.saurik.com Git - wxWidgets.git/blob - interface/scrolwin.h
acaf77d2f18b454ce6f652792f672f65d18efa6c
[wxWidgets.git] / interface / scrolwin.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: scrolwin.h
3 // Purpose: documentation for wxScrolledWindow class
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10 @class wxScrolledWindow
11 @wxheader{scrolwin.h}
12
13 The wxScrolledWindow class manages scrolling for its client area, transforming
14 the coordinates according to the scrollbar positions, and setting the
15 scroll positions, thumb sizes and ranges according to the area in view.
16
17 Starting from version 2.4 of wxWidgets, there are several ways to use a
18 wxScrolledWindow. In particular, there are now three ways to set the
19 size of the scrolling area:
20
21 One way is to set the scrollbars directly using a call to
22 wxScrolledWindow::SetScrollbars.
23 This is the way it used to be in any previous version of wxWidgets
24 and it will be kept for backwards compatibility.
25
26 An additional method of manual control, which requires a little less
27 computation of your own, is to set the total size of the scrolling area by
28 calling either wxWindow::SetVirtualSize,
29 or wxWindow::FitInside, and setting the
30 scrolling increments for it by calling
31 wxScrolledWindow::SetScrollRate.
32 Scrolling in some orientation is enabled by setting a non-zero increment
33 for it.
34
35 The most automatic and newest way is to simply let sizers determine the
36 scrolling area. This is now the default when you set an interior sizer
37 into a wxScrolledWindow with wxWindow::SetSizer.
38 The scrolling area will be set to the size requested by the sizer and
39 the scrollbars will be assigned for each orientation according to the need
40 for them and the scrolling increment set by
41 wxScrolledWindow::SetScrollRate.
42 As above, scrolling is only enabled in orientations with a non-zero
43 increment. You can influence the minimum size of the scrolled area
44 controlled by a sizer by calling
45 wxWindow::SetVirtualSizeHints.
46 (calling wxScrolledWindow::SetScrollbars
47 has analogous effects in wxWidgets 2.4 -- in later versions it may not continue
48 to override the sizer)
49
50 Note: if Maximum size hints are still supported by SetVirtualSizeHints, use
51 them at your own dire risk. They may or may not have been removed for 2.4,
52 but it really only makes sense to set minimum size hints here. We should
53 probably replace SetVirtualSizeHints with SetMinVirtualSize or similar
54 and remove it entirely in future.
55
56 As with all windows, an application can draw onto a wxScrolledWindow using
57 a @ref overview_dcoverview "device context".
58
59 You have the option of handling the OnPaint handler
60 or overriding the wxScrolledWindow::OnDraw function, which is
61 passed a pre-scrolled device context (prepared by
62 wxScrolledWindow::DoPrepareDC).
63
64 If you don't wish to calculate your own scrolling, you must call DoPrepareDC
65 when not drawing from
66 within OnDraw, to set the device origin for the device context according to the
67 current
68 scroll position.
69
70 A wxScrolledWindow will normally scroll itself and therefore its child windows
71 as well. It
72 might however be desired to scroll a different window than itself: e.g. when
73 designing a
74 spreadsheet, you will normally only have to scroll the (usually white) cell
75 area, whereas the
76 (usually grey) label area will scroll very differently. For this special
77 purpose, you can
78 call wxScrolledWindow::SetTargetWindow which means that pressing
79 the scrollbars will scroll a different window.
80
81 Note that the underlying system knows nothing about scrolling coordinates, so
82 that all system
83 functions (mouse events, expose events, refresh calls etc) as well as the
84 position of subwindows
85 are relative to the "physical" origin of the scrolled window. If the user
86 insert a child window at
87 position (10,10) and scrolls the window down 100 pixels (moving the child
88 window out of the visible
89 area), the child window will report a position of (10,-90).
90
91 @beginStyleTable
92 @style{wxRETAINED}:
93 Uses a backing pixmap to speed refreshes. Motif only.
94 @endStyleTable
95
96 @library{wxcore}
97 @category{miscwnd}
98
99 @seealso
100 wxScrollBar, wxClientDC, wxPaintDC, wxVScrolledWindow
101 */
102 class wxScrolledWindow : public wxPanel
103 {
104 public:
105 //@{
106 /**
107 Constructor.
108
109 @param parent
110 Parent window.
111 @param id
112 Window identifier. The value wxID_ANY indicates a default value.
113 @param pos
114 Window position. If a position of (-1, -1) is specified then a default
115 position
116 is chosen.
117 @param size
118 Window size. If a size of (-1, -1) is specified then the window is sized
119 appropriately.
120 @param style
121 Window style. See wxScrolledWindow.
122 @param name
123 Window name.
124
125 @remarks The window is initially created without visible scrollbars. Call
126 SetScrollbars() to specify how big the
127 virtual window size should be.
128 */
129 wxScrolledWindow();
130 wxScrolledWindow(wxWindow* parent, wxWindowID id = -1,
131 const wxPoint& pos = wxDefaultPosition,
132 const wxSize& size = wxDefaultSize,
133 long style = wxHSCROLL | wxVSCROLL,
134 const wxString& name = "scrolledWindow");
135 //@}
136
137 /**
138 Destructor.
139 */
140 ~wxScrolledWindow();
141
142 /**
143 Translates the logical coordinates to the device ones. For example, if a window
144 is
145 scrolled 10 pixels to the bottom, the device coordinates of the origin are (0,
146 0)
147 (as always), but the logical coordinates are (0, 10) and so the call to
148 CalcScrolledPosition(0, 10, xx, yy) will return 0 in yy.
149
150 @see CalcUnscrolledPosition()
151 */
152 void CalcScrolledPosition(int x, int y, int* xx, int* yy);
153
154 /**
155 Translates the device coordinates to the logical ones. For example, if a window
156 is
157 scrolled 10 pixels to the bottom, the device coordinates of the origin are (0,
158 0)
159 (as always), but the logical coordinates are (0, 10) and so the call to
160 CalcUnscrolledPosition(0, 0, xx, yy) will return 10 in yy.
161
162 @see CalcScrolledPosition()
163 */
164 void CalcUnscrolledPosition(int x, int y, int* xx, int* yy);
165
166 /**
167 Creates the window for two-step construction. Derived classes
168 should call or replace this function. See wxScrolledWindow()
169 for details.
170 */
171 bool Create(wxWindow* parent, wxWindowID id = -1,
172 const wxPoint& pos = wxDefaultPosition,
173 const wxSize& size = wxDefaultSize,
174 long style = wxHSCROLL | wxVSCROLL,
175 const wxString& name = "scrolledWindow");
176
177 /**
178 Call this function to prepare the device context for drawing a scrolled image.
179 It
180 sets the device origin according to the current scroll position.
181 DoPrepareDC is called automatically within the default OnPaint() event
182 handler, so your OnDraw() override
183 will be passed a 'pre-scrolled' device context. However, if you wish to draw
184 from
185 outside of OnDraw (via OnPaint), or you wish to implement OnPaint yourself, you
186 must
187 call this function yourself. For example:
188 */
189 void DoPrepareDC(wxDC& dc);
190
191 /**
192 Enable or disable physical scrolling in the given direction. Physical
193 scrolling is the physical transfer of bits up or down the
194 screen when a scroll event occurs. If the application scrolls by a
195 variable amount (e.g. if there are different font sizes) then physical
196 scrolling will not work, and you should switch it off. Note that you
197 will have to reposition child windows yourself, if physical scrolling
198 is disabled.
199
200 @param xScrolling
201 If @true, enables physical scrolling in the x direction.
202 @param yScrolling
203 If @true, enables physical scrolling in the y direction.
204
205 @remarks Physical scrolling may not be available on all platforms. Where
206 it is available, it is enabled by default.
207 */
208 void EnableScrolling(bool xScrolling, bool yScrolling);
209
210 /**
211 Get the number of pixels per scroll unit (line), in each direction, as set
212 by SetScrollbars(). A value of zero indicates no
213 scrolling in that direction.
214
215 @param xUnit
216 Receives the number of pixels per horizontal unit.
217 @param yUnit
218 Receives the number of pixels per vertical unit.
219
220 @see SetScrollbars(), GetVirtualSize()
221 */
222 void GetScrollPixelsPerUnit(int* xUnit, int* yUnit);
223
224 /**
225 Get the position at which the visible portion of the window starts.
226
227 @param x
228 Receives the first visible x position in scroll units.
229 @param y
230 Receives the first visible y position in scroll units.
231
232 @remarks If either of the scrollbars is not at the home position, x
233 and/or y will be greater than zero. Combined with
234 wxWindow::GetClientSize, the application can use this
235 function to efficiently redraw only the visible portion
236 of the window. The positions are in logical scroll
237 units, not pixels, so to convert to pixels you will
238 have to multiply by the number of pixels per scroll
239 increment.
240
241 @see SetScrollbars()
242 */
243 void GetViewStart(int* x, int* y);
244
245 /**
246 Gets the size in device units of the scrollable window area (as
247 opposed to the client size, which is the area of the window currently
248 visible).
249
250 @param x
251 Receives the length of the scrollable window, in pixels.
252 @param y
253 Receives the height of the scrollable window, in pixels.
254
255 @remarks Use wxDC::DeviceToLogicalX and wxDC::DeviceToLogicalY to
256 translate these units to logical units.
257
258 @see SetScrollbars(), GetScrollPixelsPerUnit()
259 */
260 void GetVirtualSize(int* x, int* y);
261
262 /**
263 Motif only: @true if the window has a backing bitmap.
264 */
265 bool IsRetained();
266
267 /**
268 Called by the default paint event handler to allow the application to define
269 painting behaviour without having to worry about calling
270 DoPrepareDC().
271 Instead of overriding this function you may also just process the paint event
272 in the derived class as usual, but then you will have to call DoPrepareDC()
273 yourself.
274 */
275 virtual void OnDraw(wxDC& dc);
276
277 /**
278 This function is for backwards compatibility only and simply calls
279 DoPrepareDC() now. Notice that it is
280 not called by the default paint event handle (DoPrepareDC() is), so
281 overriding this method in your derived class is useless.
282 */
283 void PrepareDC(wxDC& dc);
284
285 /**
286 Scrolls a window so the view start is at the given point.
287
288 @param x
289 The x position to scroll to, in scroll units.
290 @param y
291 The y position to scroll to, in scroll units.
292
293 @remarks The positions are in scroll units, not pixels, so to convert to
294 pixels you will have to multiply by the number of
295 pixels per scroll increment. If either parameter is -1,
296 that position will be ignored (no change in that
297 direction).
298
299 @see SetScrollbars(), GetScrollPixelsPerUnit()
300 */
301 void Scroll(int x, int y);
302
303 /**
304 Set the horizontal and vertical scrolling increment only. See the pixelsPerUnit
305 parameter in SetScrollbars.
306 */
307 void SetScrollRate(int xstep, int ystep);
308
309 /**
310 Sets up vertical and/or horizontal scrollbars.
311
312 @param pixelsPerUnitX
313 Pixels per scroll unit in the horizontal direction.
314 @param pixelsPerUnitY
315 Pixels per scroll unit in the vertical direction.
316 @param noUnitsX
317 Number of units in the horizontal direction.
318 @param noUnitsY
319 Number of units in the vertical direction.
320 @param xPos
321 Position to initialize the scrollbars in the horizontal direction, in
322 scroll units.
323 @param yPos
324 Position to initialize the scrollbars in the vertical direction, in scroll
325 units.
326 @param noRefresh
327 Will not refresh window if @true.
328
329 @remarks The first pair of parameters give the number of pixels per
330 'scroll step', i.e. amount moved when the up or down
331 scroll arrows are pressed. The second pair gives the
332 length of scrollbar in scroll steps, which sets the
333 size of the virtual window.
334
335 @see wxWindow::SetVirtualSize
336 */
337 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
338 int noUnitsX,
339 int noUnitsY,
340 int xPos = 0,
341 int yPos = 0,
342 bool noRefresh = false);
343
344 /**
345 Call this function to tell wxScrolledWindow to perform the actual scrolling on
346 a different window (and not on itself).
347 */
348 void SetTargetWindow(wxWindow* window);
349 };