$szTitle = "wxvscrolledwindow"; include "./_header.inc"; ?>
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
wxwindow
wxevthandler
wxobject
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(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
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.
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.
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.
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
size_t getlinecount() const
get the number of lines this window contains (previously set by setlinecount())
size_t getvisiblebegin() const
returns the index of the first currently visible line.
see also
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
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.
bool isvisible(size_t line) const
returns true if the given line is (at least partially) visible or false otherwise.
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
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.
void refreshline(size_t line)
refreshes the specified line -- it will be redrawn during the next main loop iteration.
see also
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
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.
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
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
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.
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().
include "./_footer.inc"; ?>