]> git.saurik.com Git - wxWidgets.git/blame - interface/scrolwin.h
pen.h depends from brush.h in compat mode
[wxWidgets.git] / interface / scrolwin.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: scrolwin.h
e54c96f1 3// Purpose: interface of wxScrolledWindow
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxScrolledWindow
11 @wxheader{scrolwin.h}
7c913512 12
23324ae1
FM
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.
7c913512 16
23324ae1
FM
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:
7c913512 20
23324ae1
FM
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.
7c913512 25
23324ae1
FM
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
7c913512 30 scrolling increments for it by calling
23324ae1
FM
31 wxScrolledWindow::SetScrollRate.
32 Scrolling in some orientation is enabled by setting a non-zero increment
33 for it.
7c913512 34
23324ae1
FM
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
7c913512 40 for them and the scrolling increment set by
23324ae1
FM
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)
7c913512 49
23324ae1
FM
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.
7c913512 55
23324ae1
FM
56 As with all windows, an application can draw onto a wxScrolledWindow using
57 a @ref overview_dcoverview "device context".
7c913512 58
23324ae1
FM
59 You have the option of handling the OnPaint handler
60 or overriding the wxScrolledWindow::OnDraw function, which is
7c913512 61 passed a pre-scrolled device context (prepared by
23324ae1 62 wxScrolledWindow::DoPrepareDC).
7c913512 63
23324ae1
FM
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.
7c913512 69
23324ae1
FM
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.
7c913512 80
23324ae1
FM
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).
7c913512 90
23324ae1
FM
91 @beginStyleTable
92 @style{wxRETAINED}:
93 Uses a backing pixmap to speed refreshes. Motif only.
94 @endStyleTable
7c913512 95
23324ae1
FM
96 @library{wxcore}
97 @category{miscwnd}
7c913512 98
e54c96f1 99 @see wxScrollBar, wxClientDC, wxPaintDC, wxVScrolledWindow
23324ae1
FM
100*/
101class wxScrolledWindow : public wxPanel
102{
103public:
104 //@{
105 /**
106 Constructor.
107
7c913512 108 @param parent
4cc4bfaf 109 Parent window.
7c913512 110 @param id
4cc4bfaf 111 Window identifier. The value wxID_ANY indicates a default value.
7c913512 112 @param pos
4cc4bfaf
FM
113 Window position. If a position of (-1, -1) is specified then a default
114 position
115 is chosen.
7c913512 116 @param size
4cc4bfaf
FM
117 Window size. If a size of (-1, -1) is specified then the window is sized
118 appropriately.
7c913512 119 @param style
4cc4bfaf 120 Window style. See wxScrolledWindow.
7c913512 121 @param name
4cc4bfaf 122 Window name.
23324ae1
FM
123
124 @remarks The window is initially created without visible scrollbars. Call
4cc4bfaf
FM
125 SetScrollbars() to specify how big the
126 virtual window size should be.
23324ae1
FM
127 */
128 wxScrolledWindow();
7c913512
FM
129 wxScrolledWindow(wxWindow* parent, wxWindowID id = -1,
130 const wxPoint& pos = wxDefaultPosition,
131 const wxSize& size = wxDefaultSize,
4cc4bfaf 132 long style = wxHSCROLL | wxVSCROLL,
7c913512 133 const wxString& name = "scrolledWindow");
23324ae1
FM
134 //@}
135
136 /**
137 Destructor.
138 */
139 ~wxScrolledWindow();
140
141 /**
142 Translates the logical coordinates to the device ones. For example, if a window
143 is
144 scrolled 10 pixels to the bottom, the device coordinates of the origin are (0,
145 0)
146 (as always), but the logical coordinates are (0, 10) and so the call to
147 CalcScrolledPosition(0, 10, xx, yy) will return 0 in yy.
148
4cc4bfaf 149 @see CalcUnscrolledPosition()
23324ae1 150 */
328f5751 151 void CalcScrolledPosition(int x, int y, int* xx, int* yy) const;
23324ae1
FM
152
153 /**
154 Translates the device coordinates to the logical ones. For example, if a window
155 is
156 scrolled 10 pixels to the bottom, the device coordinates of the origin are (0,
157 0)
158 (as always), but the logical coordinates are (0, 10) and so the call to
159 CalcUnscrolledPosition(0, 0, xx, yy) will return 10 in yy.
160
4cc4bfaf 161 @see CalcScrolledPosition()
23324ae1 162 */
328f5751 163 void CalcUnscrolledPosition(int x, int y, int* xx, int* yy) const;
23324ae1
FM
164
165 /**
166 Creates the window for two-step construction. Derived classes
167 should call or replace this function. See wxScrolledWindow()
168 for details.
169 */
170 bool Create(wxWindow* parent, wxWindowID id = -1,
171 const wxPoint& pos = wxDefaultPosition,
172 const wxSize& size = wxDefaultSize,
4cc4bfaf 173 long style = wxHSCROLL | wxVSCROLL,
23324ae1
FM
174 const wxString& name = "scrolledWindow");
175
176 /**
177 Call this function to prepare the device context for drawing a scrolled image.
178 It
179 sets the device origin according to the current scroll position.
23324ae1
FM
180 DoPrepareDC is called automatically within the default OnPaint() event
181 handler, so your OnDraw() override
182 will be passed a 'pre-scrolled' device context. However, if you wish to draw
183 from
184 outside of OnDraw (via OnPaint), or you wish to implement OnPaint yourself, you
185 must
186 call this function yourself. For example:
187 */
188 void DoPrepareDC(wxDC& dc);
189
190 /**
191 Enable or disable physical scrolling in the given direction. Physical
192 scrolling is the physical transfer of bits up or down the
193 screen when a scroll event occurs. If the application scrolls by a
194 variable amount (e.g. if there are different font sizes) then physical
195 scrolling will not work, and you should switch it off. Note that you
196 will have to reposition child windows yourself, if physical scrolling
197 is disabled.
198
7c913512 199 @param xScrolling
4cc4bfaf 200 If @true, enables physical scrolling in the x direction.
7c913512 201 @param yScrolling
4cc4bfaf 202 If @true, enables physical scrolling in the y direction.
23324ae1
FM
203
204 @remarks Physical scrolling may not be available on all platforms. Where
4cc4bfaf 205 it is available, it is enabled by default.
23324ae1
FM
206 */
207 void EnableScrolling(bool xScrolling, bool yScrolling);
208
209 /**
210 Get the number of pixels per scroll unit (line), in each direction, as set
211 by SetScrollbars(). A value of zero indicates no
212 scrolling in that direction.
213
7c913512 214 @param xUnit
4cc4bfaf 215 Receives the number of pixels per horizontal unit.
7c913512 216 @param yUnit
4cc4bfaf 217 Receives the number of pixels per vertical unit.
23324ae1 218
4cc4bfaf 219 @see SetScrollbars(), GetVirtualSize()
23324ae1 220 */
328f5751 221 void GetScrollPixelsPerUnit(int* xUnit, int* yUnit) const;
23324ae1
FM
222
223 /**
224 Get the position at which the visible portion of the window starts.
225
7c913512 226 @param x
4cc4bfaf 227 Receives the first visible x position in scroll units.
7c913512 228 @param y
4cc4bfaf 229 Receives the first visible y position in scroll units.
23324ae1
FM
230
231 @remarks If either of the scrollbars is not at the home position, x
4cc4bfaf
FM
232 and/or y will be greater than zero. Combined with
233 wxWindow::GetClientSize, the application can use this
234 function to efficiently redraw only the visible portion
235 of the window. The positions are in logical scroll
236 units, not pixels, so to convert to pixels you will
237 have to multiply by the number of pixels per scroll
238 increment.
239
240 @see SetScrollbars()
23324ae1 241 */
328f5751 242 void GetViewStart(int* x, int* y) const;
23324ae1
FM
243
244 /**
245 Gets the size in device units of the scrollable window area (as
246 opposed to the client size, which is the area of the window currently
247 visible).
248
7c913512 249 @param x
4cc4bfaf 250 Receives the length of the scrollable window, in pixels.
7c913512 251 @param y
4cc4bfaf 252 Receives the height of the scrollable window, in pixels.
23324ae1
FM
253
254 @remarks Use wxDC::DeviceToLogicalX and wxDC::DeviceToLogicalY to
4cc4bfaf 255 translate these units to logical units.
23324ae1 256
4cc4bfaf 257 @see SetScrollbars(), GetScrollPixelsPerUnit()
23324ae1 258 */
328f5751 259 void GetVirtualSize(int* x, int* y) const;
23324ae1
FM
260
261 /**
262 Motif only: @true if the window has a backing bitmap.
263 */
328f5751 264 bool IsRetained() const;
23324ae1
FM
265
266 /**
267 Called by the default paint event handler to allow the application to define
7c913512 268 painting behaviour without having to worry about calling
23324ae1 269 DoPrepareDC().
23324ae1
FM
270 Instead of overriding this function you may also just process the paint event
271 in the derived class as usual, but then you will have to call DoPrepareDC()
272 yourself.
273 */
274 virtual void OnDraw(wxDC& dc);
275
276 /**
7c913512
FM
277 This function is for backwards compatibility only and simply calls
278 DoPrepareDC() now. Notice that it is
23324ae1
FM
279 not called by the default paint event handle (DoPrepareDC() is), so
280 overriding this method in your derived class is useless.
281 */
282 void PrepareDC(wxDC& dc);
283
284 /**
285 Scrolls a window so the view start is at the given point.
286
7c913512 287 @param x
4cc4bfaf 288 The x position to scroll to, in scroll units.
7c913512 289 @param y
4cc4bfaf 290 The y position to scroll to, in scroll units.
23324ae1
FM
291
292 @remarks The positions are in scroll units, not pixels, so to convert to
4cc4bfaf
FM
293 pixels you will have to multiply by the number of
294 pixels per scroll increment. If either parameter is -1,
295 that position will be ignored (no change in that
296 direction).
23324ae1 297
4cc4bfaf 298 @see SetScrollbars(), GetScrollPixelsPerUnit()
23324ae1
FM
299 */
300 void Scroll(int x, int y);
301
302 /**
303 Set the horizontal and vertical scrolling increment only. See the pixelsPerUnit
304 parameter in SetScrollbars.
305 */
306 void SetScrollRate(int xstep, int ystep);
307
308 /**
309 Sets up vertical and/or horizontal scrollbars.
310
7c913512 311 @param pixelsPerUnitX
4cc4bfaf 312 Pixels per scroll unit in the horizontal direction.
7c913512 313 @param pixelsPerUnitY
4cc4bfaf 314 Pixels per scroll unit in the vertical direction.
7c913512 315 @param noUnitsX
4cc4bfaf 316 Number of units in the horizontal direction.
7c913512 317 @param noUnitsY
4cc4bfaf 318 Number of units in the vertical direction.
7c913512 319 @param xPos
4cc4bfaf
FM
320 Position to initialize the scrollbars in the horizontal direction, in
321 scroll units.
7c913512 322 @param yPos
4cc4bfaf 323 Position to initialize the scrollbars in the vertical direction, in scroll
23324ae1 324 units.
7c913512 325 @param noRefresh
4cc4bfaf 326 Will not refresh window if @true.
23324ae1
FM
327
328 @remarks The first pair of parameters give the number of pixels per
4cc4bfaf
FM
329 'scroll step', i.e. amount moved when the up or down
330 scroll arrows are pressed. The second pair gives the
331 length of scrollbar in scroll steps, which sets the
332 size of the virtual window.
23324ae1 333
4cc4bfaf 334 @see wxWindow::SetVirtualSize
23324ae1
FM
335 */
336 void SetScrollbars(int pixelsPerUnitX, int pixelsPerUnitY,
337 int noUnitsX,
338 int noUnitsY,
339 int xPos = 0,
340 int yPos = 0,
4cc4bfaf 341 bool noRefresh = false);
23324ae1
FM
342
343 /**
344 Call this function to tell wxScrolledWindow to perform the actual scrolling on
345 a different window (and not on itself).
346 */
347 void SetTargetWindow(wxWindow* window);
348};
e54c96f1 349