2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: vlbox.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxVListBox
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxVListBox
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-05-01 01:38:05 -04:00
|
|
|
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.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
|
|
|
@category{ctrl}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxSimpleHtmlListBox, wxHtmlListBox
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxVListBox : public wxVScrolledWindow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Default constructor, you must call Create() later.
|
|
|
|
*/
|
2008-05-01 01:38:05 -04:00
|
|
|
wxVListBox();
|
|
|
|
/**
|
|
|
|
Normal constructor which calls Create() internally.
|
|
|
|
*/
|
2008-03-08 08:52:38 -05:00
|
|
|
wxVListBox(wxWindow* parent, wxWindowID id = wxID_ANY,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
2008-05-02 11:46:26 -04:00
|
|
|
long style = 0, const wxString& name = wxVListBoxNameStr);
|
2008-05-01 01:38:05 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
|
|
|
virtual ~wxVListBox();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Deletes all items from the control.
|
|
|
|
*/
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Creates the control. To finish creating it you also should call
|
2008-05-01 01:38:05 -04:00
|
|
|
SetItemCount() to let it know about the number of items it contains.
|
|
|
|
|
|
|
|
The only special style which may be used with wxVListBox is
|
|
|
|
@c wxLB_MULTIPLE which indicates that the listbox should support
|
|
|
|
multiple selection.
|
|
|
|
|
2008-05-10 21:38:53 -04:00
|
|
|
@return @true on success or @false if the control couldn't be created.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool Create(wxWindow* parent, wxWindowID id = wxID_ANY,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
2008-05-01 01:38:05 -04:00
|
|
|
const wxSize& size = wxDefaultSize, long style = 0,
|
2008-03-08 08:52:38 -05:00
|
|
|
const wxString& name = wxVListBoxNameStr);
|
|
|
|
|
|
|
|
/**
|
2008-05-01 01:38:05 -04:00
|
|
|
Deselects all the items in the listbox. This method is only valid for
|
|
|
|
multi selection listboxes.
|
|
|
|
|
2008-05-10 21:38:53 -04:00
|
|
|
@return @true if any items were changed, i.e. if there had been any
|
2008-05-01 01:38:05 -04:00
|
|
|
selected items before, or @false if all the items were already
|
|
|
|
deselected.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see SelectAll(), Select()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool DeselectAll();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the index of the first selected item in the listbox or
|
|
|
|
@c wxNOT_FOUND if no items are currently selected.
|
2008-05-01 01:38:05 -04:00
|
|
|
|
|
|
|
@a 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.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Here is a typical example of using these functions:
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-05-01 01:38:05 -04:00
|
|
|
@code
|
|
|
|
unsigned long cookie;
|
|
|
|
int item = hlbox->GetFirstSelected(cookie);
|
|
|
|
while ( item != wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
// ... process item ...
|
|
|
|
item = hlbox->GetNextSelected(cookie);
|
|
|
|
}
|
|
|
|
@endcode
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This method is only valid for multi selection listboxes.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
int GetFirstSelected(unsigned long& cookie) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Get the number of items in the control.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see SetItemCount()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
size_t GetItemCount() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the margins used by the control. The @c x field of the returned
|
|
|
|
point is the horizontal margin and the @c y field is the vertical one.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see SetMargins()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxPoint GetMargins() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-07-13 13:28:31 -04:00
|
|
|
/**
|
|
|
|
Returns the rectangle occupied by this item in physical coordinates.
|
|
|
|
|
|
|
|
If the item is not currently visible, returns an empty rectangle.
|
2008-07-13 14:02:38 -04:00
|
|
|
|
|
|
|
@since 2.9.0
|
2008-07-13 13:28:31 -04:00
|
|
|
*/
|
|
|
|
wxRect GetItemRect(size_t item) const;
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2008-05-01 01:38:05 -04:00
|
|
|
Returns the index of the next selected item or @c wxNOT_FOUND if there
|
|
|
|
are no more.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This method is only valid for multi selection listboxes.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see GetFirstSelected()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
int GetNextSelected(unsigned long& cookie) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the number of the items currently selected.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-05-01 01:38:05 -04:00
|
|
|
It is valid for both single and multi selection controls. In the former
|
|
|
|
case it may only return 0 or 1 however.
|
|
|
|
|
|
|
|
@see IsSelected(), GetFirstSelected(), GetNextSelected()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
size_t GetSelectedCount() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-05-01 01:38:05 -04:00
|
|
|
Get the currently selected item or @c wxNOT_FOUND if there is no
|
|
|
|
selection.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
int GetSelection() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-05-01 01:38:05 -04:00
|
|
|
Returns the background colour used for the selected cells. By default
|
|
|
|
the standard system colour is used.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-05-01 01:38:05 -04:00
|
|
|
@see wxSystemSettings::GetColour(), SetSelectionBackground()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-05-01 01:38:05 -04:00
|
|
|
const wxColour& GetSelectionBackground() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the listbox was created with @c wxLB_MULTIPLE style
|
2008-05-01 01:38:05 -04:00
|
|
|
and so supports multiple selection or @false if it is a single
|
|
|
|
selection listbox.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool HasMultipleSelection() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if this item is the current one, @false otherwise.
|
2008-05-01 01:38:05 -04:00
|
|
|
|
|
|
|
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.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool IsCurrent(size_t item) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if this item is selected, @false otherwise.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool IsSelected(size_t item) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2012-11-30 19:14:07 -05:00
|
|
|
Selects or deselects the specified item which must be valid (i.e.\ not
|
2008-03-08 08:52:38 -05:00
|
|
|
equal to @c wxNOT_FOUND).
|
2008-05-01 01:38:05 -04:00
|
|
|
|
2008-05-10 21:38:53 -04:00
|
|
|
@return @true if the items selection status has changed or @false
|
2008-05-01 01:38:05 -04:00
|
|
|
otherwise.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This function is only valid for the multiple selection listboxes, use
|
|
|
|
SetSelection() for the single selection ones.
|
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
bool Select(size_t item, bool select = true);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Selects all the items in the listbox.
|
2008-05-01 01:38:05 -04:00
|
|
|
|
2008-05-10 21:38:53 -04:00
|
|
|
@return @true if any items were changed, i.e. if there had been any
|
2008-05-01 01:38:05 -04:00
|
|
|
unselected items before, or @false if all the items were
|
|
|
|
already selected.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This method is only valid for multi selection listboxes.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see DeselectAll(), Select()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool SelectAll();
|
|
|
|
|
|
|
|
/**
|
2008-05-01 01:38:05 -04:00
|
|
|
Selects all items in the specified range which may be given in any
|
|
|
|
order.
|
|
|
|
|
2008-05-10 21:38:53 -04:00
|
|
|
@return @true if the items selection status has changed or @false
|
2008-05-01 01:38:05 -04:00
|
|
|
otherwise.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This method is only valid for multi selection listboxes.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see SelectAll(), Select()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool SelectRange(size_t from, size_t to);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set the number of items to be shown in the control.
|
2008-05-01 01:38:05 -04:00
|
|
|
|
|
|
|
This is just a synonym for wxVScrolledWindow::SetRowCount().
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual void SetItemCount(size_t count);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
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.
|
2008-05-01 01:38:05 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
By default both margins are 0.
|
|
|
|
*/
|
|
|
|
void SetMargins(const wxPoint& pt);
|
2008-03-08 09:43:31 -05:00
|
|
|
void SetMargins(wxCoord x, wxCoord y);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set the selection to the specified item, if it is -1 the selection is
|
2008-05-01 01:38:05 -04:00
|
|
|
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.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void SetSelection(int selection);
|
|
|
|
|
|
|
|
/**
|
2008-05-01 01:38:05 -04:00
|
|
|
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().
|
|
|
|
|
|
|
|
@note 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.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see GetSelectionBackground()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void SetSelectionBackground(const wxColour& col);
|
|
|
|
|
|
|
|
/**
|
2012-11-30 19:14:07 -05:00
|
|
|
Toggles the state of the specified @a item, i.e.\ selects it if it was
|
2008-03-08 08:52:38 -05:00
|
|
|
unselected and deselects it if it was selected.
|
2008-05-01 01:38:05 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This method is only valid for multi selection listboxes.
|
2008-05-01 01:38:05 -04:00
|
|
|
|
|
|
|
@see Select()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void Toggle(size_t item);
|
2008-10-13 07:29:37 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
/**
|
|
|
|
The derived class must implement this function to actually draw the
|
|
|
|
item with the given index on the provided DC.
|
|
|
|
|
|
|
|
@param dc
|
|
|
|
The device context to use for drawing.
|
|
|
|
@param rect
|
|
|
|
The bounding rectangle for the item being drawn (DC clipping
|
|
|
|
region is set to this rectangle before calling this function).
|
|
|
|
@param n
|
|
|
|
The index of the item to be drawn.
|
|
|
|
|
|
|
|
@todo Change this function signature to non-const.
|
|
|
|
*/
|
2008-10-13 09:24:43 -04:00
|
|
|
virtual void OnDrawItem(wxDC& dc, const wxRect& rect, size_t n) const = 0;
|
2008-10-13 07:29:37 -04:00
|
|
|
|
2008-10-29 14:55:57 -04:00
|
|
|
/**
|
2012-08-15 20:42:40 -04:00
|
|
|
This method is used to draw the item's background and, maybe, a border
|
2008-10-29 14:55:57 -04:00
|
|
|
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 OnDrawBackground(wxDC& dc, const wxRect& rect, size_t n) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
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.
|
|
|
|
|
|
|
|
@param dc
|
|
|
|
The device context to use for drawing.
|
|
|
|
@param rect
|
|
|
|
The bounding rectangle for the item.
|
|
|
|
@param n
|
|
|
|
The index of the item.
|
|
|
|
|
|
|
|
@todo Change this function signature to non-const.
|
|
|
|
*/
|
|
|
|
virtual void OnDrawSeparator(wxDC& dc, wxRect& rect, size_t n) const;
|
|
|
|
|
2008-10-13 07:29:37 -04:00
|
|
|
/**
|
|
|
|
The derived class must implement this method to return the height of
|
|
|
|
the specified item (in pixels).
|
|
|
|
*/
|
2008-10-13 09:24:43 -04:00
|
|
|
virtual wxCoord OnMeasureItem(size_t n) const = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|