2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: listbox.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxListBox
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxListBox
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-10-19 08:49:07 -04:00
|
|
|
A listbox is used to select one or more of a list of strings.
|
|
|
|
|
|
|
|
The strings are displayed in a scrolling box, with the selected string(s)
|
|
|
|
marked in reverse video. A listbox can be single selection (if an item is
|
|
|
|
selected, the previous selection is removed) or multiple selection
|
2008-03-08 08:52:38 -05:00
|
|
|
(clicking an item toggles the item on or off independently of other
|
|
|
|
selections).
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2012-10-13 18:49:56 -04:00
|
|
|
List box elements are numbered from zero and while the maximal number of
|
|
|
|
elements is unlimited, it is usually better to use a virtual control, not
|
|
|
|
requiring to add all the items to it at once, such as wxDataViewCtrl or
|
|
|
|
wxListCtrl with @c wxLC_VIRTUAL style, once more than a few hundreds items
|
|
|
|
need to be displayed because this control is not optimized, neither from
|
|
|
|
performance nor from user interface point of view, for large number of
|
|
|
|
items.
|
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@beginStyleTable
|
2008-04-06 10:43:04 -04:00
|
|
|
@style{wxLB_SINGLE}
|
2009-02-18 12:58:51 -05:00
|
|
|
Single-selection list.
|
2008-04-06 10:43:04 -04:00
|
|
|
@style{wxLB_MULTIPLE}
|
2009-02-18 12:58:51 -05:00
|
|
|
Multiple-selection list: the user can toggle multiple items on and off.
|
|
|
|
This is the same as wxLB_EXTENDED in wxGTK2 port.
|
2008-04-06 10:43:04 -04:00
|
|
|
@style{wxLB_EXTENDED}
|
2009-02-18 12:58:51 -05:00
|
|
|
Extended-selection list: the user can extend the selection by using
|
|
|
|
@c SHIFT or @c CTRL keys together with the cursor movement keys or
|
|
|
|
the mouse.
|
2008-04-06 10:43:04 -04:00
|
|
|
@style{wxLB_HSCROLL}
|
2009-02-18 12:58:51 -05:00
|
|
|
Create horizontal scrollbar if contents are too wide (Windows only).
|
2008-04-06 10:43:04 -04:00
|
|
|
@style{wxLB_ALWAYS_SB}
|
2009-02-18 12:58:51 -05:00
|
|
|
Always show a vertical scrollbar.
|
2008-04-06 10:43:04 -04:00
|
|
|
@style{wxLB_NEEDED_SB}
|
2009-02-18 12:58:51 -05:00
|
|
|
Only create a vertical scrollbar if needed.
|
2009-07-17 10:36:30 -04:00
|
|
|
@style{wxLB_NO_SB}
|
|
|
|
Don't create vertical scrollbar (wxMSW only).
|
2008-04-06 10:43:04 -04:00
|
|
|
@style{wxLB_SORT}
|
2009-02-18 12:58:51 -05:00
|
|
|
The listbox contents are sorted in alphabetical order.
|
2008-03-08 08:52:38 -05:00
|
|
|
@endStyleTable
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-10-19 08:49:07 -04:00
|
|
|
Note that @c wxLB_SINGLE, @c wxLB_MULTIPLE and @c wxLB_EXTENDED styles are
|
|
|
|
mutually exclusive and you can specify at most one of them (single selection
|
|
|
|
is the default). See also @ref overview_windowstyles.
|
|
|
|
|
2009-02-18 12:58:51 -05:00
|
|
|
@beginEventEmissionTable{wxCommandEvent}
|
2008-04-06 10:43:04 -04:00
|
|
|
@event{EVT_LISTBOX(id, func)}
|
2011-01-06 14:52:14 -05:00
|
|
|
Process a @c wxEVT_COMMAND_LISTBOX_SELECTED event, when an item on the
|
2009-02-18 12:58:51 -05:00
|
|
|
list is selected or the selection changes.
|
2008-04-06 10:43:04 -04:00
|
|
|
@event{EVT_LISTBOX_DCLICK(id, func)}
|
2011-01-06 14:52:14 -05:00
|
|
|
Process a @c wxEVT_COMMAND_LISTBOX_DOUBLECLICKED event, when the listbox
|
2009-02-18 12:58:51 -05:00
|
|
|
is double-clicked.
|
2008-03-08 08:52:38 -05:00
|
|
|
@endEventTable
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
|
|
|
@category{ctrl}
|
2008-10-13 04:05:18 -04:00
|
|
|
@appearance{listbox.png}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-09-01 10:22:54 -04:00
|
|
|
@see wxEditableListBox, wxChoice, wxComboBox, wxListCtrl, wxCommandEvent
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxListBox : public wxControlWithItems
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-05-22 16:19:00 -04:00
|
|
|
Default constructor.
|
|
|
|
*/
|
|
|
|
wxListBox();
|
2008-10-19 08:49:07 -04:00
|
|
|
|
2008-05-22 16:19:00 -04:00
|
|
|
/**
|
2008-10-19 08:49:07 -04:00
|
|
|
Constructor, creating and showing a list box.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-10-19 08:49:07 -04:00
|
|
|
@param parent
|
|
|
|
The parent window.
|
|
|
|
@param id
|
|
|
|
The ID of this control. A value of @c wxID_ANY indicates a default value.
|
|
|
|
@param pos
|
|
|
|
The initial position.
|
2009-04-21 07:21:36 -04:00
|
|
|
If ::wxDefaultPosition is specified then a default position is chosen.
|
2008-10-19 08:49:07 -04:00
|
|
|
@param size
|
|
|
|
The initial size.
|
2009-04-21 07:21:36 -04:00
|
|
|
If ::wxDefaultSize is specified then the window is sized appropriately.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param n
|
2008-03-09 08:33:59 -04:00
|
|
|
Number of strings with which to initialise the control.
|
2008-10-19 08:49:07 -04:00
|
|
|
@param choices
|
|
|
|
The strings to use to initialize the control.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param style
|
2008-03-09 08:33:59 -04:00
|
|
|
Window style. See wxListBox.
|
2008-10-19 08:49:07 -04:00
|
|
|
@param validator
|
|
|
|
The validator for this control.
|
|
|
|
@param name
|
|
|
|
The name of this class.
|
2009-10-18 13:47:01 -04:00
|
|
|
|
|
|
|
@beginWxPerlOnly
|
|
|
|
Not supported by wxPerl.
|
|
|
|
@endWxPerlOnly
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-10-19 08:49:07 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
wxListBox(wxWindow* parent, wxWindowID id,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
int n = 0,
|
2008-03-09 08:33:59 -04:00
|
|
|
const wxString choices[] = NULL,
|
2008-03-08 09:43:31 -05:00
|
|
|
long style = 0,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
2008-10-19 08:49:07 -04:00
|
|
|
const wxString& name = wxListBoxNameStr);
|
|
|
|
|
2008-05-22 16:19:00 -04:00
|
|
|
/**
|
2008-10-19 08:49:07 -04:00
|
|
|
Constructor, creating and showing a list box.
|
2008-05-22 16:19:00 -04:00
|
|
|
|
2008-10-19 08:49:07 -04:00
|
|
|
See the other wxListBox() constructor; the only difference is that
|
|
|
|
this overload takes a wxArrayString instead of a pointer to an array
|
|
|
|
of wxString.
|
2009-10-18 13:47:01 -04:00
|
|
|
|
|
|
|
@beginWxPerlOnly
|
|
|
|
Use an array reference for the @a choices parameter.
|
|
|
|
@endWxPerlOnly
|
2008-05-22 16:19:00 -04:00
|
|
|
*/
|
2008-10-19 08:49:07 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
wxListBox(wxWindow* parent, wxWindowID id,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size,
|
|
|
|
const wxArrayString& choices,
|
|
|
|
long style = 0,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
2008-10-19 08:49:07 -04:00
|
|
|
const wxString& name = wxListBoxNameStr);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor, destroying the list box.
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual ~wxListBox();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
2008-10-19 08:49:07 -04:00
|
|
|
Creates the listbox for two-step construction.
|
|
|
|
See wxListBox() for further details.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-10 17:10:54 -05:00
|
|
|
bool Create(wxWindow *parent, wxWindowID id,
|
2008-03-08 08:52:38 -05:00
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
2009-01-10 17:10:54 -05:00
|
|
|
int n = 0, const wxString choices[] = NULL,
|
2008-03-08 08:52:38 -05:00
|
|
|
long style = 0,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
2009-01-10 17:10:54 -05:00
|
|
|
const wxString& name = wxListBoxNameStr);
|
|
|
|
bool Create(wxWindow *parent, wxWindowID id,
|
2008-03-08 09:43:31 -05:00
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size,
|
|
|
|
const wxArrayString& choices,
|
|
|
|
long style = 0,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
2009-01-10 17:10:54 -05:00
|
|
|
const wxString& name = wxListBoxNameStr);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Deselects an item in the list box.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param n
|
2008-03-09 08:33:59 -04:00
|
|
|
The zero-based item to deselect.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@remarks This applies to multiple selection listboxes only.
|
|
|
|
*/
|
|
|
|
void Deselect(int n);
|
|
|
|
|
2011-09-16 13:03:01 -04:00
|
|
|
virtual void SetSelection(int n);
|
|
|
|
|
|
|
|
virtual int GetSelection() const;
|
|
|
|
|
|
|
|
virtual bool SetStringSelection(const wxString& s, bool select);
|
|
|
|
virtual bool SetStringSelection(const wxString& s);
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Fill an array of ints with the positions of the currently selected items.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param selections
|
2008-03-09 08:33:59 -04:00
|
|
|
A reference to an wxArrayInt instance that is used to store the result of
|
2008-10-19 08:49:07 -04:00
|
|
|
the query.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-05-10 21:38:53 -04:00
|
|
|
@return The number of selections.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@remarks Use this with a multiple selection listbox.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2009-10-18 13:47:01 -04:00
|
|
|
@beginWxPerlOnly
|
|
|
|
In wxPerl this method takes no parameters and return the
|
|
|
|
selected items as a list.
|
|
|
|
@endWxPerlOnly
|
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see wxControlWithItems::GetSelection, wxControlWithItems::GetStringSelection,
|
|
|
|
wxControlWithItems::SetSelection
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual int GetSelections(wxArrayInt& selections) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-10-19 08:49:07 -04:00
|
|
|
Returns the item located at @a point, or @c wxNOT_FOUND if there
|
|
|
|
is no item located at @a point.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-04-21 06:34:23 -04:00
|
|
|
It is currently implemented for wxMSW, wxMac and wxGTK2 ports.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param point
|
2008-03-09 08:33:59 -04:00
|
|
|
Point of item (in client coordinates) to obtain
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-05-10 21:38:53 -04:00
|
|
|
@return Item located at point, or wxNOT_FOUND if unimplemented or the
|
2008-10-19 08:49:07 -04:00
|
|
|
item does not exist.
|
2008-04-21 06:34:23 -04:00
|
|
|
|
|
|
|
@since 2.7.0
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-10-19 08:49:07 -04:00
|
|
|
int HitTest(const wxPoint& point) const;
|
2009-01-27 19:51:55 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
@overload
|
|
|
|
*/
|
2009-01-25 13:10:24 -05:00
|
|
|
int HitTest(int x, int y) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Insert the given number of strings before the specified position.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param nItems
|
2008-03-09 08:33:59 -04:00
|
|
|
Number of items in the array items
|
2008-03-08 09:43:31 -05:00
|
|
|
@param items
|
2008-03-09 08:33:59 -04:00
|
|
|
Labels of items to be inserted
|
2008-03-08 09:43:31 -05:00
|
|
|
@param pos
|
2008-05-22 16:19:00 -04:00
|
|
|
Position before which to insert the items: if pos is 0 the
|
|
|
|
items will be inserted in the beginning of the listbox
|
2009-10-18 13:47:01 -04:00
|
|
|
|
|
|
|
@beginWxPerlOnly
|
|
|
|
Not supported by wxPerl.
|
|
|
|
@endWxPerlOnly
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-11-10 16:33:25 -05:00
|
|
|
void InsertItems(unsigned int nItems, const wxString *items,
|
2008-03-08 08:52:38 -05:00
|
|
|
unsigned int pos);
|
2008-05-22 16:19:00 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Insert the given number of strings before the specified position.
|
|
|
|
|
|
|
|
@param items
|
|
|
|
Labels of items to be inserted
|
|
|
|
@param pos
|
2008-10-19 08:49:07 -04:00
|
|
|
Position before which to insert the items: if pos is @c 0 the
|
2008-05-22 16:19:00 -04:00
|
|
|
items will be inserted in the beginning of the listbox
|
2009-10-18 13:47:01 -04:00
|
|
|
|
|
|
|
@beginWxPerlOnly
|
|
|
|
Use an array reference for the @a items parameter.
|
|
|
|
@endWxPerlOnly
|
2008-05-22 16:19:00 -04:00
|
|
|
*/
|
|
|
|
void InsertItems(const wxArrayString& items,
|
2008-03-08 09:43:31 -05:00
|
|
|
unsigned int pos);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Determines whether an item is selected.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param n
|
2008-03-09 08:33:59 -04:00
|
|
|
The zero-based item index.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-05-10 21:38:53 -04:00
|
|
|
@return @true if the given item is selected, @false otherwise.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual bool IsSelected(int n) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Set the specified item to be the first visible item.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param n
|
2008-05-22 16:19:00 -04:00
|
|
|
The zero-based item index that should be visible.
|
|
|
|
*/
|
|
|
|
void SetFirstItem(int n);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set the specified item to be the first visible item.
|
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param string
|
2008-03-09 08:33:59 -04:00
|
|
|
The string that should be visible.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
void SetFirstItem(const wxString& string);
|
2012-02-14 19:35:55 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Ensure that the item with the given index is currently shown.
|
|
|
|
|
|
|
|
Scroll the listbox if necessary.
|
|
|
|
|
|
|
|
This method is currently only implemented in wxGTK and wxOSX and does
|
|
|
|
nothing in other ports.
|
|
|
|
|
|
|
|
@see SetFirstItem()
|
|
|
|
*/
|
2011-09-16 13:03:01 -04:00
|
|
|
virtual void EnsureVisible(int n);
|
2012-02-14 19:35:55 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return true if the listbox has ::wxLB_SORT style.
|
|
|
|
|
|
|
|
This method is mostly meant for internal use only.
|
|
|
|
*/
|
2011-09-16 13:03:01 -04:00
|
|
|
virtual bool IsSorted() const;
|
2012-02-27 18:50:59 -05:00
|
|
|
|
|
|
|
|
|
|
|
// NOTE: Phoenix needs to see the implementation of pure virtuals so it
|
|
|
|
// knows that this class is not abstract.
|
|
|
|
virtual unsigned int GetCount() const;
|
|
|
|
virtual wxString GetString(unsigned int n) const;
|
|
|
|
virtual void SetString(unsigned int n, const wxString& s);
|
|
|
|
virtual int FindString(const wxString& s, bool bCase = false) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|