wx.ScrolledWindow Class Reference

Inheritance diagram for wx.ScrolledWindow:

wx.Panel wx.Window wx.EvtHandler wx.Object wx.GridCtrl.Grid wx.Html.HtmlWindow wx.PreviewCanvas

List of all members.

Public Member Functions

Point CalcScrolledPosition (Point unscrolledPosition)
void CalcScrolledPosition (int x, int y, ref int xx, ref int yy)
Point CalcUnscrolledPosition (Point scrolledPosition)
void CalcUnscrolledPosition (int x, int y, ref int xx, ref int yy)
void GetScrollPixelsPerUnit (ref int xUnit, ref int yUnit)
void GetViewStart (ref int x, ref int y)
virtual void OnDraw (DC dc)
override void PrepareDC (DC dc)
void Scroll (Point pos)
void Scroll (int x, int y)
 ScrolledWindow (Window parent, int id, Point pos, Size size, wx.WindowStyles style)
 ScrolledWindow (Window parent, int id, Point pos, Size size)
 ScrolledWindow (Window parent, int id, Point pos)
 ScrolledWindow (Window parent, int id)
 ScrolledWindow (Window parent)
 ScrolledWindow (IntPtr wxObject)
void SetScrollbars (int pixelsPerUnitX, int pixelsPerUnitY, int noUnitsX, int noUnitsY, int x, int y, bool noRefresh)
void SetScrollbars (int pixelsPerUnitX, int pixelsPerUnitY, int noUnitsX, int noUnitsY, int x, int y)
void SetScrollbars (int pixelsPerUnitX, int pixelsPerUnitY, int noUnitsX, int noUnitsY)
void SetScrollRate (int pixelsPerUnitX, int pixelsPerUnitY)
void SetTargetWindow (Window window)

Properties

Size ScrollPixelsPerUnit [get]
Point ViewStart [get]


Detailed Description

The wx.ScrolledWindow class manages scrolling for its client area, transforming the coordinates according to the scrollbar positions, and setting the scroll positions, thumb sizes and ranges according to the area in view. Starting from version 2.4 of wxWidgets, there are several ways to use a wx.ScrolledWindow. In particular, there are now three ways to set the size of the scrolling area: One way is to set the scrollbars directly using a call to wx.ScrolledWindow.SetScrollbars(). This is the way it used to be in any previous version of wxWidgets and it will be kept for backwards compatibility.

An additional method of manual control, which requires a little less computation of your own, is to set the total size of the scrolling area by calling either wx.Window.VirtualSize, or wx.Window.FitInside(), and setting the scrolling increments for it by calling wx.ScrolledWindow.SetScrollRate(). Scrolling in some orientation is enabled by setting a non-zero increment for it.

The most automatic and newest way is to simply let sizers determine the scrolling area. This is now the default when you set an interior sizer into a wx.ScrolledWindow with wx.Window.SetSizer. The scrolling area will be set to the size requested by the sizer and the scrollbars will be assigned for each orientation according to the need for them and the scrolling increment set by wx.Scrolled.Window.SetScrollRate. As above, scrolling is only enabled in orientations with a non-zero increment. You can influence the minimum size of the scrolled area controlled by a sizer by calling wx.Window.SetVirtualSizeHints().

Note: if Maximum size hints are still supported by SetVirtualSizeHints(), use them at your own dire risk. They may or may not have been removed for 2.4, but it really only makes sense to set minimum size hints here. We should probably replace SetVirtualSizeHints() with SetMinVirtualSize() or similar and remove it entirely in future.

As with all windows, an application can draw onto a wx.ScrolledWindow using a device context.

You have the option of handling the OnPaint handler or overriding the OnDraw() function, which is passed a pre-scrolled device context (prepared by DoPrepareDC).

If you don't wish to calculate your own scrolling, you must call DoPrepareDC when not drawing from within OnDraw, to set the device origin for the device context according to the current scroll position.

A wx.ScrolledWindow will normally scroll itself and therefore its child windows as well. It might however be desired to scroll a different window than itself: e.g. when designing a spreadsheet, you will normally only have to scroll the (usually white) cell area, whereas the (usually grey) label area will scroll very differently. For this special purpose, you can call SetTargetWindow which means that pressing the scrollbars will scroll a different window.

Note that the underlying system knows nothing about scrolling coordinates, so that all system functions (mouse events, expose events, refresh calls etc) as well as the position of subwindows are relative to the "physical" origin of the scrolled window. If the user insert a child window at position (10,10) and scrolls the window down 100 pixels (moving the child window out of the visible area), the child window will report a position of (10,-90).

Remarks: Use wx.ScrolledWindow for applications where the user scrolls by a fixed amount, and where a 'page' can be interpreted to be the current visible portion of the window. For more sophisticated applications, use the wx.ScrolledWindow implementation as a guide to build your own scroll behaviour.

See also wx.ScrollBar, wx.ClientDC, wx.PaintDC, and wx.VScrolledWindow.


Constructor & Destructor Documentation

wx.ScrolledWindow.ScrolledWindow ( IntPtr  wxObject  ) 

wx.ScrolledWindow.ScrolledWindow ( Window  parent  ) 

wx.ScrolledWindow.ScrolledWindow ( Window  parent,
int  id 
)

wx.ScrolledWindow.ScrolledWindow ( Window  parent,
int  id,
Point  pos 
)

wx.ScrolledWindow.ScrolledWindow ( Window  parent,
int  id,
Point  pos,
Size  size 
)

wx.ScrolledWindow.ScrolledWindow ( Window  parent,
int  id,
Point  pos,
Size  size,
wx.WindowStyles  style 
)


Member Function Documentation

Point wx.ScrolledWindow.CalcScrolledPosition ( Point  unscrolledPosition  ) 

Translates the logical coordinates to the device ones. For example, if a window is scrolled 10 pixels to the bottom, the device coordinates of the origin are (0, 0) (as always), but the logical coordinates are (0, 10) and so the call to CalcScrolledPosition(0,10,&xx,&yy) will return 0 in yy. See also CalcUnscrolledPosition().

void wx.ScrolledWindow.CalcScrolledPosition ( int  x,
int  y,
ref int  xx,
ref int  yy 
)

Translates the logical coordinates to the device ones. For example, if a window is scrolled 10 pixels to the bottom, the device coordinates of the origin are (0, 0) (as always), but the logical coordinates are (0, 10) and so the call to CalcScrolledPosition(0, 10, &xx, &yy) will return 0 in yy. See also CalcUnscrolledPosition().

Point wx.ScrolledWindow.CalcUnscrolledPosition ( Point  scrolledPosition  ) 

Translates the device coordinates to the logical ones. For example, if a window is scrolled 10 pixels to the bottom, the device coordinates of the origin are (0, 0) (as always), but the logical coordinates are (0, 10) and so the call to CalcUnscrolledPosition(0,0,&xx,&yy) will return 10 in yy. See also CalcScrolledPosition()

void wx.ScrolledWindow.CalcUnscrolledPosition ( int  x,
int  y,
ref int  xx,
ref int  yy 
)

Translates the device coordinates to the logical ones. For example, if a window is scrolled 10 pixels to the bottom, the device coordinates of the origin are (0, 0) (as always), but the logical coordinates are (0, 10) and so the call to CalcUnscrolledPosition(0,0,&xx,&yy) will return 10 in yy.

See also:
CalcScrolledPosition

void wx.ScrolledWindow.GetScrollPixelsPerUnit ( ref int  xUnit,
ref int  yUnit 
)

Get the number of pixels per scroll unit (line), in each direction, as set by wx.ScrolledWindow.SetScrollbars(). A value of zero indicates no scrolling in that direction.
xUnitReceives the number of pixels per horizontal unit.
yUnitReceives the number of pixels per vertical unit.

See also wx.ScrolledWindow.SetScrollbars(), wx.ScrolledWindow.GetVirtualSize()

void wx.ScrolledWindow.GetViewStart ( ref int  x,
ref int  y 
)

Get the position at which the visible portion of the window starts. x Receives the first visible x position in scroll units. y Receives the first visible y position in scroll units.

If either of the scrollbars is not at the home position, x and/or y will be greater than zero. Combined with wx.Window.ClientSize, the application can use this function to efficiently redraw only the visible portion of the window. The positions are in logical scroll units, not pixels, so to convert to pixels you will have to multiply by the number of pixels per scroll increment. See also wx.ScrolledWindow.SetScrollbars()

virtual void wx.ScrolledWindow.OnDraw ( DC  dc  )  [virtual]

Called by the default paint event handler to allow the application to define painting behaviour without having to worry about calling DoPrepareDC.

Instead of overriding this function you may also just process the paint event in the derived class as usual, but then you will have to call DoPrepareDC() yourself.

override void wx.ScrolledWindow.PrepareDC ( DC  dc  )  [virtual]

Call this function to prepare the device context for drawing a scrolled image. It sets the device origin according to the current scroll position.

Parameters:
dc The device context that shall be prepared.

DoPrepareDC is called automatically within the default wxScrolledWindow.OnPaint event handler, so your wxScrolledWindow.OnDraw override will be passed a 'pre-scrolled' device context. However, if you wish to draw from outside of OnDraw (via OnPaint), or you wish to implement OnPaint yourself, you must call this function yourself. For example:

            class MyWindow : wx.ScrolledWindow
            {
            ...
            }
void OnEvent(wx.MouseEvent& evt) { using (wx.ClientDC dc(this)) { PrepareDC(dc);

dc.Pen=wx.Pen.ThePenList.FindOrCreatePen(wx.Colour.wxBLACK, 1, wx.Pen.Styles.SOLID); Size pos=evt.Position; if (pos.X > -1 && pos.Y > -1 && evt.Dragging) { dc.DrawLine(xpos, ypos, x, y); } } }

Reimplemented from wx.Window.

void wx.ScrolledWindow.Scroll ( Point  pos  ) 

Scrolls to the designated virtual position in points. This will do the translation via GetScrollPixelsPerUnit() for you.

void wx.ScrolledWindow.Scroll ( int  x,
int  y 
)

Scrolls to the designated virtual position in scroll units.

void wx.ScrolledWindow.SetScrollbars ( int  pixelsPerUnitX,
int  pixelsPerUnitY,
int  noUnitsX,
int  noUnitsY,
int  x,
int  y,
bool  noRefresh 
)

Sets up vertical and/or horizontal scrollbars.

Parameters:
pixelsPerUnitX Pixels per scroll unit in the horizontal direction.
pixelsPerUnitY Pixels per scroll unit in the vertical direction.
noUnitsX Number of units in the horizontal direction.
noUnitsY Number of units in the vertical direction.
x Position to initialize the scrollbars in the horizontal direction, in scroll units.
y Position to initialize the scrollbars in the vertical direction, in scroll units.
noRefresh Will not refresh window if true.

The first pair of parameters give the number of pixels per 'scroll step', i.e. amount moved when the up or down scroll arrows are pressed. The second pair gives the length of scrollbar in scroll steps, which sets the size of the virtual window.

xPos and yPos optionally specify a position to scroll to immediately.

For example, the following gives a window horizontal and vertical scrollbars with 20 pixels per scroll step, and a size of 50 steps (1000 pixels) in each direction.

   window->SetScrollbars(20, 20, 50, 50);
wxScrolledWindow manages the page size itself, using the current client window size as the page size. Note that for more sophisticated scrolling applications, for example where scroll steps may be variable according to the position in the document, it will be necessary to derive a new class from wxWindow, overriding OnSize and adjusting the scrollbars appropriately.

See also:
SetVirtualSize

void wx.ScrolledWindow.SetScrollbars ( int  pixelsPerUnitX,
int  pixelsPerUnitY,
int  noUnitsX,
int  noUnitsY,
int  x,
int  y 
)

Sets up vertical and/or horizontal scrollbars.

Parameters:
pixelsPerUnitX Pixels per scroll unit in the horizontal direction.
pixelsPerUnitY Pixels per scroll unit in the vertical direction.
noUnitsX Number of units in the horizontal direction.
noUnitsY Number of units in the vertical direction.
x Position to initialize the scrollbars in the horizontal direction, in scroll units.
y Position to initialize the scrollbars in the vertical direction, in scroll units.

The first pair of parameters give the number of pixels per 'scroll step', i.e. amount moved when the up or down scroll arrows are pressed. The second pair gives the length of scrollbar in scroll steps, which sets the size of the virtual window.

xPos and yPos optionally specify a position to scroll to immediately.

For example, the following gives a window horizontal and vertical scrollbars with 20 pixels per scroll step, and a size of 50 steps (1000 pixels) in each direction.

   window->SetScrollbars(20, 20, 50, 50);
wxScrolledWindow manages the page size itself, using the current client window size as the page size. Note that for more sophisticated scrolling applications, for example where scroll steps may be variable according to the position in the document, it will be necessary to derive a new class from wxWindow, overriding OnSize and adjusting the scrollbars appropriately.

See also:
SetVirtualSize

void wx.ScrolledWindow.SetScrollbars ( int  pixelsPerUnitX,
int  pixelsPerUnitY,
int  noUnitsX,
int  noUnitsY 
)

Sets up vertical and/or horizontal scrollbars.

Parameters:
pixelsPerUnitX Pixels per scroll unit in the horizontal direction.
pixelsPerUnitY Pixels per scroll unit in the vertical direction.
noUnitsX Number of units in the horizontal direction.
noUnitsY Number of units in the vertical direction.

The first pair of parameters give the number of pixels per 'scroll step', i.e. amount moved when the up or down scroll arrows are pressed. The second pair gives the length of scrollbar in scroll steps, which sets the size of the virtual window.

xPos and yPos optionally specify a position to scroll to immediately.

For example, the following gives a window horizontal and vertical scrollbars with 20 pixels per scroll step, and a size of 50 steps (1000 pixels) in each direction.

   window->SetScrollbars(20, 20, 50, 50);
wxScrolledWindow manages the page size itself, using the current client window size as the page size. Note that for more sophisticated scrolling applications, for example where scroll steps may be variable according to the position in the document, it will be necessary to derive a new class from wxWindow, overriding OnSize and adjusting the scrollbars appropriately.

See also:
SetVirtualSize

void wx.ScrolledWindow.SetScrollRate ( int  pixelsPerUnitX,
int  pixelsPerUnitY 
)

Set the horizontal and vertical scrolling increment only. See the pixelsPerUnit parameter in SetScrollbars.

Parameters:
pixelsPerUnitX Pixels per scroll unit in the horizontal direction.
pixelsPerUnitY Pixels per scroll unit in the vertical direction.

void wx.ScrolledWindow.SetTargetWindow ( Window  window  ) 

Call this function to tell wxScrolledWindow to perform the actual scrolling on a different window (and not on itself).


Property Documentation

Size wx.ScrolledWindow.ScrollPixelsPerUnit [get]

The result of GetScrollPixelsPerUnit() as size. This returns the size of a square defining the scroll unit.

Point wx.ScrolledWindow.ViewStart [get]

Get the position at which the visible portion of the window starts. If either of the scrollbars is not at the home position, x and/or y will be greater than zero. Combined with wx.Window.ClientSize, the application can use this function to efficiently redraw only the visible portion of the window. The positions are in logical pixels, so this is the result of GetViewStart() multiplied by the number of pixels per scroll increment.


Manual of the wx.NET   (c) 2003-2011 the wx.NET project at   Get wx.NET at SourceForge.net. Fast, secure and Free Open Source software downloads