Version: 2.9.4
Public Member Functions | Protected Member Functions
wxVListBox Class Reference

#include </home/zeitlin/src/wx/github/interface/wx/vlbox.h>

Inheritance diagram for wxVListBox:

Detailed Description

wxVListBox is a wxListBox-like control with the following two main differences from a regular wxListBox: it can have an arbitrarily huge number of items because it doesn't store them itself but uses the OnDrawItem() callback to draw them (so it is a virtual listbox) and its items can have variable height as determined by OnMeasureItem() (so it is also a listbox with the lines of variable height).

Also, as a consequence of its virtual nature, it doesn't have any methods to append or insert items in it as it isn't necessary to do it: you just have to call SetItemCount() to tell the control how many items it should display. Of course, this also means that you will never use this class directly because it has pure virtual functions, but will need to derive your own class from it (for example, wxHtmlListBox).

However it emits the same events as wxListBox and the same event macros may be used with it. Since wxVListBox does not store its items itself, the events will only contain the index, not any contents such as the string of an item.

Library:  wxCore
Category:  Controls
参照:
wxSimpleHtmlListBox, wxHtmlListBox

Public Member Functions

 wxVListBox ()
 Default constructor, you must call Create() later.
 wxVListBox (wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxVListBoxNameStr)
 Normal constructor which calls Create() internally.
virtual ~wxVListBox ()
 Destructor.
void Clear ()
 Deletes all items from the control.
bool Create (wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxVListBoxNameStr)
 Creates the control.
bool DeselectAll ()
 Deselects all the items in the listbox.
int GetFirstSelected (unsigned long &cookie) const
 Returns the index of the first selected item in the listbox or wxNOT_FOUND if no items are currently selected.
size_t GetItemCount () const
 Get the number of items in the control.
wxPoint GetMargins () const
 Returns the margins used by the control.
wxRect GetItemRect (size_t item) const
 Returns the rectangle occupied by this item in physical coordinates.
int GetNextSelected (unsigned long &cookie) const
 Returns the index of the next selected item or wxNOT_FOUND if there are no more.
size_t GetSelectedCount () const
 Returns the number of the items currently selected.
int GetSelection () const
 Get the currently selected item or wxNOT_FOUND if there is no selection.
const wxColourGetSelectionBackground () const
 Returns the background colour used for the selected cells.
bool HasMultipleSelection () const
 Returns true if the listbox was created with wxLB_MULTIPLE style and so supports multiple selection or false if it is a single selection listbox.
bool IsCurrent (size_t item) const
 Returns true if this item is the current one, false otherwise.
bool IsSelected (size_t item) const
 Returns true if this item is selected, false otherwise.
bool Select (size_t item, bool select=true)
 Selects or deselects the specified item which must be valid (i.e.
bool SelectAll ()
 Selects all the items in the listbox.
bool SelectRange (size_t from, size_t to)
 Selects all items in the specified range which may be given in any order.
virtual void SetItemCount (size_t count)
 Set the number of items to be shown in the control.
void SetSelection (int selection)
 Set the selection to the specified item, if it is -1 the selection is unset.
void SetSelectionBackground (const wxColour &col)
 Sets the colour to be used for the selected cells background.
void Toggle (size_t item)
 Toggles the state of the specified item, i.e.
void SetMargins (const wxPoint &pt)
 Set the margins: horizontal margin is the distance between the window border and the item contents while vertical margin is half of the distance between items.
void SetMargins (wxCoord x, wxCoord y)
 Set the margins: horizontal margin is the distance between the window border and the item contents while vertical margin is half of the distance between items.

Protected Member Functions

virtual void OnDrawItem (wxDC &dc, const wxRect &rect, size_t n) const =0
 The derived class must implement this function to actually draw the item with the given index on the provided DC.
virtual void OnDrawBackground (wxDC &dc, const wxRect &rect, size_t n) const
 This method is used to draw the items background and, maybe, a border around it.
virtual void OnDrawSeparator (wxDC &dc, wxRect &rect, size_t n) const
 This method may be used to draw separators between the lines.
virtual wxCoord OnMeasureItem (size_t n) const =0
 The derived class must implement this method to return the height of the specified item (in pixels).

List of all members.


Constructor & Destructor Documentation

wxVListBox::wxVListBox ( )

Default constructor, you must call Create() later.

wxVListBox::wxVListBox ( wxWindow parent,
wxWindowID  id = wxID_ANY,
const wxPoint pos = wxDefaultPosition,
const wxSize size = wxDefaultSize,
long  style = 0,
const wxString name = wxVListBoxNameStr 
)

Normal constructor which calls Create() internally.

virtual wxVListBox::~wxVListBox ( ) [virtual]

Destructor.


Member Function Documentation

void wxVListBox::Clear ( )

Deletes all items from the control.

bool wxVListBox::Create ( wxWindow parent,
wxWindowID  id = wxID_ANY,
const wxPoint pos = wxDefaultPosition,
const wxSize size = wxDefaultSize,
long  style = 0,
const wxString name = wxVListBoxNameStr 
)

Creates the control.

To finish creating it you also should call SetItemCount() to let it know about the number of items it contains.

The only special style which may be used with wxVListBox is wxLB_MULTIPLE which indicates that the listbox should support multiple selection.

Returns:
true on success or false if the control couldn't be created.

Reimplemented from wxVScrolledWindow.

Reimplemented in wxHtmlListBox.

bool wxVListBox::DeselectAll ( )

Deselects all the items in the listbox.

This method is only valid for multi selection listboxes.

Returns:
true if any items were changed, i.e. if there had been any selected items before, or false if all the items were already deselected.
参照:
SelectAll(), Select()
int wxVListBox::GetFirstSelected ( unsigned long &  cookie) const

Returns the index of the first selected item in the listbox or wxNOT_FOUND if no items are currently selected.

cookie is an opaque parameter which should be passed to the subsequent calls to GetNextSelected(). It is needed in order to allow parallel iterations over the selected items.

Here is a typical example of using these functions:

        unsigned long cookie;
        int item = hlbox->GetFirstSelected(cookie);
        while ( item != wxNOT_FOUND )
        {
            // ... process item ...
            item = hlbox->GetNextSelected(cookie);
        }

This method is only valid for multi selection listboxes.

size_t wxVListBox::GetItemCount ( ) const

Get the number of items in the control.

参照:
SetItemCount()
wxRect wxVListBox::GetItemRect ( size_t  item) const

Returns the rectangle occupied by this item in physical coordinates.

If the item is not currently visible, returns an empty rectangle.

Since:
2.9.0
wxPoint wxVListBox::GetMargins ( ) const

Returns the margins used by the control.

The x field of the returned point is the horizontal margin and the y field is the vertical one.

参照:
SetMargins()
int wxVListBox::GetNextSelected ( unsigned long &  cookie) const

Returns the index of the next selected item or wxNOT_FOUND if there are no more.

This method is only valid for multi selection listboxes.

参照:
GetFirstSelected()
size_t wxVListBox::GetSelectedCount ( ) const

Returns the number of the items currently selected.

It is valid for both single and multi selection controls. In the former case it may only return 0 or 1 however.

参照:
IsSelected(), GetFirstSelected(), GetNextSelected()
int wxVListBox::GetSelection ( ) const

Get the currently selected item or wxNOT_FOUND if there is no selection.

const wxColour& wxVListBox::GetSelectionBackground ( ) const

Returns the background colour used for the selected cells.

By default the standard system colour is used.

参照:
wxSystemSettings::GetColour(), SetSelectionBackground()
bool wxVListBox::HasMultipleSelection ( ) const

Returns true if the listbox was created with wxLB_MULTIPLE style and so supports multiple selection or false if it is a single selection listbox.

bool wxVListBox::IsCurrent ( size_t  item) const

Returns true if this item is the current one, false otherwise.

The current item is always the same as selected one for the single selection listbox and in this case this method is equivalent to IsSelected() but they are different for multi selection listboxes where many items may be selected but only one (at most) is current.

bool wxVListBox::IsSelected ( size_t  item) const

Returns true if this item is selected, false otherwise.

virtual void wxVListBox::OnDrawBackground ( wxDC dc,
const wxRect rect,
size_t  n 
) const [protected, virtual]

This method is used to draw the items background and, maybe, a border around it.

The base class version implements a reasonable default behaviour which consists in drawing the selected item with the standard background colour and drawing a border around the item if it is either selected or current.

Todo:
Change this function signature to non-const.
virtual void wxVListBox::OnDrawItem ( wxDC dc,
const wxRect rect,
size_t  n 
) const [protected, pure virtual]

The derived class must implement this function to actually draw the item with the given index on the provided DC.

Parameters:
dcThe device context to use for drawing.
rectThe bounding rectangle for the item being drawn (DC clipping region is set to this rectangle before calling this function).
nThe index of the item to be drawn.
Todo:
Change this function signature to non-const.
virtual void wxVListBox::OnDrawSeparator ( wxDC dc,
wxRect rect,
size_t  n 
) const [protected, virtual]

This method may be used to draw separators between the lines.

The rectangle passed to it may be modified, typically to deflate it a bit before passing to OnDrawItem().

The base class version of this method doesn't do anything.

Parameters:
dcThe device context to use for drawing.
rectThe bounding rectangle for the item.
nThe index of the item.
Todo:
Change this function signature to non-const.
virtual wxCoord wxVListBox::OnMeasureItem ( size_t  n) const [protected, pure virtual]

The derived class must implement this method to return the height of the specified item (in pixels).

bool wxVListBox::Select ( size_t  item,
bool  select = true 
)

Selects or deselects the specified item which must be valid (i.e.

not equal to wxNOT_FOUND).

Returns:
true if the items selection status has changed or false otherwise.

This function is only valid for the multiple selection listboxes, use SetSelection() for the single selection ones.

bool wxVListBox::SelectAll ( )

Selects all the items in the listbox.

Returns:
true if any items were changed, i.e. if there had been any unselected items before, or false if all the items were already selected.

This method is only valid for multi selection listboxes.

参照:
DeselectAll(), Select()
bool wxVListBox::SelectRange ( size_t  from,
size_t  to 
)

Selects all items in the specified range which may be given in any order.

Returns:
true if the items selection status has changed or false otherwise.

This method is only valid for multi selection listboxes.

参照:
SelectAll(), Select()
virtual void wxVListBox::SetItemCount ( size_t  count) [virtual]

Set the number of items to be shown in the control.

This is just a synonym for wxVScrolledWindow::SetRowCount().

void wxVListBox::SetMargins ( wxCoord  x,
wxCoord  y 
)

Set the margins: horizontal margin is the distance between the window border and the item contents while vertical margin is half of the distance between items.

By default both margins are 0.

void wxVListBox::SetMargins ( const wxPoint pt)

Set the margins: horizontal margin is the distance between the window border and the item contents while vertical margin is half of the distance between items.

By default both margins are 0.

void wxVListBox::SetSelection ( int  selection)

Set the selection to the specified item, if it is -1 the selection is unset.

The selected item will be automatically scrolled into view if it isn't currently visible.

This method may be used both with single and multiple selection listboxes.

void wxVListBox::SetSelectionBackground ( const wxColour col)

Sets the colour to be used for the selected cells background.

The background of the standard cells may be changed by simply calling wxWindow::SetBackgroundColour().

注:
Using a non-default background colour may result in control having an appearance different from the similar native controls and should be avoided in general.
参照:
GetSelectionBackground()
void wxVListBox::Toggle ( size_t  item)

Toggles the state of the specified item, i.e.

selects it if it was unselected and deselects it if it was selected.

This method is only valid for multi selection listboxes.

参照:
Select()
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines