Contents Up Previous Next

wxVScrolledWindow

In the name of this class, "V" may stand for "variable" because it can be used for scrolling lines of variable heights; "virtual" because it is not necessary to know the heights of all lines in advance -- only those which are shown on the screen need to be measured; or, even, "vertical" because this class only supports scrolling in one direction currently (this could and probably will change in the future however).

In any case, this is a generalization of the wxScrolledWindow class which can be only used when all lines have the same height. It lacks some other wxScrolledWindow features however, notably there is currently no support for horizontal scrolling; it can't scroll another window nor only a rectangle of the window and not its entire client area. To use this class, you need to derive from it and implement OnGetLineHeight() pure virtual method. You also must call SetLineCount to let the base class know how many lines it should display but from that moment on the scrolling is handled entirely by wxVScrolledWindow, you only need to draw the visible part of contents in your OnPaint() method as usual. You should use GetFirstVisibleLine() and GetLastVisibleLine() to select the lines to display. Note that the device context origin is not shifted so the first visible line always appears at the point (0, 0) in physical as well as logical coordinates.

Derived from

wxPanel

Include files

<wx/vscroll.h>

Members

wxVScrolledWindow::wxVScrolledWindow
wxVScrolledWindow::Create
wxVScrolledWindow::EstimateTotalHeight
wxVScrolledWindow::GetFirstVisibleLine
wxVScrolledWindow::GetLastVisibleLine
wxVScrolledWindow::GetLineCount
wxVScrolledWindow::GetVisibleBegin
wxVScrolledWindow::GetVisibleEnd
wxVScrolledWindow::HitTest
wxVScrolledWindow::IsVisible
wxVScrolledWindow::OnGetLineHeight
wxVScrolledWindow::OnGetLinesHint
wxVScrolledWindow::RefreshLine
wxVScrolledWindow::RefreshLines
wxVScrolledWindow::RefreshAll
wxVScrolledWindow::ScrollLines
wxVScrolledWindow::ScrollPages
wxVScrolledWindow::ScrollToLine
wxVScrolledWindow::SetLineCount


wxVScrolledWindow::wxVScrolledWindow

wxVScrolledWindow(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxPanelNameStr)

This is the normal constructor, no need to call Create() after using this one.

Note that wxVSCROLL is always automatically added to our style, there is no need to specify it explicitly.

wxVScrolledWindow()

Default constructor, you must call Create() later.

Parameters

parent

id

pos

size

style

name


wxVScrolledWindow::Create

bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxPanelNameStr)

Same as the non default ctor but returns status code: true if ok, false if the window couldn't have been created.

Just as with the ctor above, wxVSCROLL style is always used, there is no need to specify it explicitly.


wxVScrolledWindow::EstimateTotalHeight

virtual wxCoord EstimateTotalHeight() const

This protected function is used internally by wxVScrolledWindow to estimate the total height of the window when SetLineCount is called. The default implementation uses the brute force approach if the number of the items in the control is small enough. Otherwise, it tries to find the average line height using some lines in the beginning, middle and the end.

If it is undesirable to access all these lines (some of which might be never shown) just for the total height calculation, you may override the function and provide your own guess better and/or faster.

Note that although returning a totally wrong value would still work, it risks to result in very strange scrollbar behaviour so this function should really try to make the best guess possible.


wxVScrolledWindow::GetFirstVisibleLine

size_t GetFirstVisibleLine() const

Returns the index of the first currently visible line.

This is same as GetVisibleBegin and exists only for symmetry with GetLastVisibleLine.


wxVScrolledWindow::GetLastVisibleLine

size_t GetLastVisibleLine() const

Returns the index of the last currently visible line. Note that this method returns (size_t)-1 (i.e. a huge positive number) if the control is empty so if this is possible you should use GetVisibleEnd instead.

See also

GetFirstVisibleLine


wxVScrolledWindow::GetLineCount

size_t GetLineCount() const

Get the number of lines this window contains (previously set by SetLineCount())


wxVScrolledWindow::GetVisibleBegin

size_t GetVisibleBegin() const

Returns the index of the first currently visible line.

See also

GetVisibleEnd


wxVScrolledWindow::GetVisibleEnd

size_t GetVisibleEnd() const

Returns the index of the first line after the currently visible one. If the return value is 0 it means that no lines are currently shown (which only happens if the control is empty). Note that the index returned by this method is not always a valid index as it may be equal to GetLineCount.

See also

GetVisibleBegin


wxVScrolledWindow::HitTest

int HitTest(wxCoord x, wxCoord y) const

int HitTest(const wxPoint& pt) const

Return the item at the specified (in physical coordinates) position or wxNOT_FOUND if none, i.e. if it is below the last item.


wxVScrolledWindow::IsVisible

bool IsVisible(size_t line) const

Returns true if the given line is (at least partially) visible or false otherwise.


wxVScrolledWindow::OnGetLineHeight

virtual wxCoord OnGetLineHeight(size_t n) const

This protected virtual function must be overridden in the derived class and it should return the height of the given line in pixels.

See also

OnGetLinesHint


wxVScrolledWindow::OnGetLinesHint

virtual void OnGetLinesHint(size_t lineMin, size_t lineMax) const

This function doesn't have to be overridden but it may be useful to do it if calculating the lines heights is a relatively expensive operation as it gives the user code a possibility to calculate several of them at once.

OnGetLinesHint() is normally called just before OnGetLineHeight() but you shouldn't rely on the latter being called for all lines in the interval specified here. It is also possible that OnGetLineHeight() will be called for the lines outside of this interval, so this is really just a hint, not a promise.

Finally note that lineMin is inclusive, while lineMax is exclusive, as usual.


wxVScrolledWindow::RefreshLine

void RefreshLine(size_t line)

Refreshes the specified line -- it will be redrawn during the next main loop iteration.

See also

RefreshLines


wxVScrolledWindow::RefreshLines

void RefreshLines(size_t from, size_t to)

Refreshes all lines between from and to, inclusive. from should be less than or equal to to.

See also

RefreshLine


wxVScrolledWindow::RefreshAll

void RefreshAll()

This function completely refreshes the control, recalculating the number of items shown on screen and repainting them. It should be called when the values returned by OnGetLineHeight change for some reason and the window must be updated to reflect this.


wxVScrolledWindow::ScrollLines

bool ScrollLines(int lines)

Scroll by the specified number of lines which may be positive (to scroll down) or negative (to scroll up).

Returns true if the window was scrolled, false otherwise (for example if we're trying to scroll down but we are already showing the last line).

See also

LineUp, LineDown


wxVScrolledWindow::ScrollPages

bool ScrollPages(int pages)

Scroll by the specified number of pages which may be positive (to scroll down) or negative (to scroll up).

See also

ScrollLines,
PageUp, PageDown


wxVScrolledWindow::ScrollToLine

bool ScrollToLine(size_t line)

Scroll to the specified line: it will become the first visible line in the window.

Return true if we scrolled the window, false if nothing was done.


wxVScrolledWindow::SetLineCount

void SetLineCount(size_t count)

Set the number of lines the window contains: the derived class must provide the heights for all lines with indices up to the one given here in its OnGetLineHeight().