wxscrollbara wxscrollbar is a control that represents a horizontal or vertical scrollbar. it is distinct from the two scrollbars that some windows provide automatically, but the two types of scrollbar share the way events are received. derived from
wxcontrol include files <wx/scrolbar.h> remarks a scrollbar has the following main attributes: range, thumb size, page size, and position. the range is the total number of units associated with the view represented by the scrollbar. for a table with 15 columns, the range would be 15. the thumb size is the number of units that are currently visible. for the table example, the window might be sized so that only 5 columns are currently visible, in which case the application would set the thumb size to 5. when the thumb size becomes the same as or greater than the range, the scrollbar will be automatically hidden on most platforms. the page size is the number of units that the scrollbar should scroll by, when 'paging' through the data. this value is normally the same as the thumb size length, because it is natural to assume that the visible window size defines a page. the scrollbar position is the current thumb position. most applications will find it convenient to provide a function called adjustscrollbars which can be called initially, from an onsize event handler, and whenever the application data changes in size. it will adjust the view, object and page size according to the size of the window and the size of the data. window styles
see also window styles overview. event table macros to process a scroll event, use these event handler macros to direct input to member functions that take a wxscrollevent argument. you can use evt_command_scroll... macros with window ids for when intercepting scroll events from controls, or evt_scroll... macros without window ids for intercepting scroll events from the receiving window -- except for this, the macros behave exactly the same.
the difference between evt_scroll_thumbrelease and evt_scroll_changed the evt_scroll_thumbrelease event is only emitted when actually dragging the thumb using the mouse and releasing it (this evt_scroll_thumbrelease event is also followed by an evt_scroll_changed event). the evt_scroll_changed event also occurs when using the keyboard to change the thumb position, and when clicking next to the thumb (in all these cases the evt_scroll_thumbrelease event does not happen). in short, the evt_scroll_changed event is triggered when scrolling/ moving has finished independently of the way it had started. please see the widgets sample ("slider" page) to see the difference between evt_scroll_thumbrelease and evt_scroll_changed in action. see also scrolling overview, event handling overview, wxscrolledwindow members
wxscrollbar::wxscrollbar
wxscrollbar::wxscrollbarwxscrollbar() default constructor. wxscrollbar(wxwindow* parent, wxwindowid id, const wxpoint& pos = wxdefaultposition, const wxsize& size = wxdefaultsize, long style = wxsb_horizontal, const wxvalidator& validator = wxdefaultvalidator, const wxstring& name = "scrollbar") constructor, creating and showing a scrollbar. parameters parent
id
pos
size
style
validator
name
see also wxscrollbar::create, wxvalidator
wxscrollbar::~wxscrollbarvoid ~wxscrollbar() destructor, destroying the scrollbar.
wxscrollbar::createbool create(wxwindow* parent, wxwindowid id, const wxpoint& pos = wxdefaultposition, const wxsize& size = wxdefaultsize, long style = wxsb_horizontal, const wxvalidator& validator = wxdefaultvalidator, const wxstring& name = "scrollbar") scrollbar creation function called by the scrollbar constructor. see wxscrollbar::wxscrollbar for details.
wxscrollbar::getrangeint getrange() const returns the length of the scrollbar. see also
wxscrollbar::getpagesizeint getpagesize() const returns the page size of the scrollbar. this is the number of scroll units that will be scrolled when the user pages up or down. often it is the same as the thumb size. see also
wxscrollbar::getthumbpositionint getthumbposition() const returns the current position of the scrollbar thumb. see also
wxscrollbar::getthumbsizeint getthumbsize() const returns the thumb or 'view' size. see also
wxscrollbar::setthumbpositionvoid setthumbposition(int viewstart) sets the position of the scrollbar. parameters viewstart
see also
wxscrollbar::setscrollbarvirtual void setscrollbar(int position, int thumbsize, int range, int pagesize, const bool refresh = true) sets the scrollbar properties. parameters position
thumbsize
range
pagesize
refresh
remarks let's say you wish to display 50 lines of text, using the same font. the window is sized so that you can only see 16 lines at a time. you would use:
the page size is 1 less than the thumb size so that the last line of the previous page will be visible on the next page, to help orient the user. note that with the window at this size, the thumb position can never go above 50 minus 16, or 34. you can determine how many lines are currently visible by dividing the current view size by the character height in pixels. when defining your own scrollbar behaviour, you will always need to recalculate the scrollbar settings when the window size changes. you could therefore put your scrollbar calculations and setscrollbar call into a function named adjustscrollbars, which can be called initially and also from a wxsizeevent event handler function. see also scrolling overview, wxwindow::setscrollbar, wxscrolledwindow
|