📄 scrolwin.tex
字号:
\section{\class{wxScrolledWindow}}\label{wxscrolledwindow}The wxScrolledWindow class manages scrolling for its client area, transformingthe coordinates according to the scrollbar positions, and setting thescroll positions, thumb sizes and ranges according to the area in view.Starting from version 2.4 of wxWidgets, there are several ways to use awxScrolledWindow. In particular, there are now three ways to set thesize of the scrolling area:One way is to set the scrollbars directly using a call to\helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars}.This is the way it used to be in any previous version of wxWidgetsand it will be kept for backwards compatibility.An additional method of manual control, which requires a little lesscomputation of your own, is to set the total size of the scrolling area bycalling either \helpref{wxWindow::SetVirtualSize}{wxwindowsetvirtualsize},or \helpref{wxWindow::FitInside}{wxwindowfitinside}, and setting thescrolling increments for it by calling \helpref{wxScrolledWindow::SetScrollRate}{wxscrolledwindowsetscrollrate}.Scrolling in some orientation is enabled by setting a non-zero incrementfor it.The most automatic and newest way is to simply let sizers determine thescrolling area. This is now the default when you set an interior sizerinto a wxScrolledWindow with \helpref{wxWindow::SetSizer}{wxwindowsetsizer}.The scrolling area will be set to the size requested by the sizer andthe scrollbars will be assigned for each orientation according to the needfor them and the scrolling increment set by \helpref{wxScrolledWindow::SetScrollRate}{wxscrolledwindowsetscrollrate}.As above, scrolling is only enabled in orientations with a non-zeroincrement. You can influence the minimum size of the scrolled areacontrolled by a sizer by calling\helpref{wxWindow::SetVirtualSizeHints}{wxwindowsetvirtualsizehints}.(calling \helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars} has analogous effects in wxWidgets 2.4 -- in later versions it may not continue to override the sizer)Note: if Maximum size hints are still supported by SetVirtualSizeHints, usethem 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 shouldprobably replace SetVirtualSizeHints with SetMinVirtualSize or similarand remove it entirely in future.As with all windows, an application can draw onto a wxScrolledWindow usinga \helpref{device context}{dcoverview}.You have the option of handling the OnPaint handleror overriding the \helpref{OnDraw}{wxscrolledwindowondraw} function, which ispassed a pre-scrolled device context (prepared by \helpref{DoPrepareDC}{wxscrolledwindowdopreparedc}).If you don't wish to calculate your own scrolling, you must call DoPrepareDC when not drawing fromwithin OnDraw, to set the device origin for the device context according to the currentscroll position.A wxScrolledWindow will normally scroll itself and therefore its child windows as well. Itmight however be desired to scroll a different window than itself: e.g. when designing aspreadsheet, 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 cancall \helpref{SetTargetWindow}{wxscrolledwindowsettargetwindow} which means that pressingthe scrollbars will scroll a different window.Note that the underlying system knows nothing about scrolling coordinates, so that all systemfunctions (mouse events, expose events, refresh calls etc) as well as the position of subwindowsare relative to the "physical" origin of the scrolled window. If the user insert a child window atposition (10,10) and scrolls the window down 100 pixels (moving the child window out of the visiblearea), the child window will report a position of (10,-90).\wxheading{Derived from}\helpref{wxPanel}{wxpanel}\\\helpref{wxWindow}{wxwindow}\\\helpref{wxEvtHandler}{wxevthandler}\\\helpref{wxObject}{wxobject}\wxheading{Include files}<wx/scrolwin.h>\wxheading{Window styles}\twocolwidtha{5cm}\begin{twocollist}\itemsep=0pt\twocolitem{\windowstyle{wxRETAINED}}{Uses a backing pixmap to speed refreshes. Motif only.}\end{twocollist}See also \helpref{window styles overview}{windowstyles}.\wxheading{Remarks}Use wxScrolledWindow for applications where the user scrolls by a fixed amount, andwhere a `page' can be interpreted to be the current visible portion of the window. Formore sophisticated applications, use the wxScrolledWindow implementation as a guideto build your own scroll behaviour.\wxheading{See also}\helpref{wxScrollBar}{wxscrollbar}, \helpref{wxClientDC}{wxclientdc},\\\helpref{wxPaintDC}{wxpaintdc}, \helpref{wxVScrolledWindow}{wxvscrolledwindow}\latexignore{\rtfignore{\wxheading{Members}}}\membersection{wxScrolledWindow::wxScrolledWindow}\label{wxscrolledwindowctor}\func{}{wxScrolledWindow}{\void}Default constructor.\func{}{wxScrolledWindow}{\param{wxWindow*}{ parent}, \param{wxWindowID }{id = -1},\rtfsp\param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp\param{long}{ style = wxHSCROLL \pipe wxVSCROLL}, \param{const wxString\& }{name = ``scrolledWindow"}}Constructor.\wxheading{Parameters}\docparam{parent}{Parent window.}\docparam{id}{Window identifier. A value of -1 indicates a default value.}\docparam{pos}{Window position. If a position of (-1, -1) is specified then a default positionis chosen.}\docparam{size}{Window size. If a size of (-1, -1) is specified then the window is sizedappropriately.}\docparam{style}{Window style. See \helpref{wxScrolledWindow}{wxscrolledwindow}.}\docparam{name}{Window name.}\wxheading{Remarks}The window is initially created without visible scrollbars.Call \helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars} tospecify how big the virtual window size should be.\membersection{wxScrolledWindow::\destruct{wxScrolledWindow}}\label{wxscrolledwindowdtor}\func{}{\destruct{wxScrolledWindow}}{\void}Destructor.\membersection{wxScrolledWindow::CalcScrolledPosition}\label{wxscrolledwindowcalcscrolledposition}\constfunc{void}{CalcScrolledPosition}{ \param{int }{x}, \param{int }{y}, \param{int *}{xx} \param{int *}{yy}}Translates the logical coordinates to the device ones. For example, if a window isscrolled 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 toCalcScrolledPosition(0, 10, \&xx, \&yy) will return 0 in yy.\wxheading{See also}\helpref{CalcUnscrolledPosition}{wxscrolledwindowcalcunscrolledposition}\pythonnote{The wxPython version of this methods accepts only twoparameters and returns xx and yy as a tuple of values.}\perlnote{In wxPerl this method takes two parameters and returns a2-element list {\tt ( xx, yy )}.}\membersection{wxScrolledWindow::CalcUnscrolledPosition}\label{wxscrolledwindowcalcunscrolledposition}\constfunc{void}{CalcUnscrolledPosition}{ \param{int }{x}, \param{int }{y}, \param{int *}{xx} \param{int *}{yy}}Translates the device coordinates to the logical ones. For example, if a window isscrolled 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 toCalcUnscrolledPosition(0, 0, \&xx, \&yy) will return 10 in yy.\wxheading{See also}\helpref{CalcScrolledPosition}{wxscrolledwindowcalcscrolledposition}\pythonnote{The wxPython version of this methods accepts only twoparameters and returns xx and yy as a tuple of values.}\perlnote{In wxPerl this method takes two parameters and returns a2-element list {\tt ( xx, yy )}.}\membersection{wxScrolledWindow::Create}\label{wxscrolledwindowcreate}\func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID }{id = -1},\rtfsp\param{const wxPoint\& }{pos = wxDefaultPosition}, \param{const wxSize\& }{size = wxDefaultSize},\rtfsp\param{long}{ style = wxHSCROLL \pipe wxVSCROLL}, \param{const wxString\& }{name = ``scrolledWindow"}}Creates the window for two-step construction. Derived classesshould call or replace this function. See \helpref{wxScrolledWindow::wxScrolledWindow}{wxscrolledwindowctor}\rtfspfor details.\membersection{wxScrolledWindow::EnableScrolling}\label{wxscrolledwindowenablescrolling}\func{void}{EnableScrolling}{\param{const bool}{ xScrolling}, \param{const bool}{ yScrolling}}Enable or disable physical scrolling in the given direction. Physicalscrolling is the physical transfer of bits up or down thescreen when a scroll event occurs. If the application scrolls by avariable amount (e.g. if there are different font sizes) then physicalscrolling will not work, and you should switch it off. Note that youwill have to reposition child windows yourself, if physical scrollingis disabled.\wxheading{Parameters}\docparam{xScrolling}{If true, enables physical scrolling in the x direction.}\docparam{yScrolling}{If true, enables physical scrolling in the y direction.}\wxheading{Remarks}Physical scrolling may not be available on all platforms. Where it is available, it is enabledby default.\membersection{wxScrolledWindow::GetScrollPixelsPerUnit}\label{wxscrolledwindowgetscrollpixelsperunit}\constfunc{void}{GetScrollPixelsPerUnit}{\param{int* }{xUnit}, \param{int* }{yUnit}}Get the number of pixels per scroll unit (line), in each direction, as setby \helpref{wxScrolledWindow::SetScrollbars}{wxscrolledwindowsetscrollbars}. A value of zero indicates noscrolling in that direction.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -