2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: ctrlsub.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxControlWithItems
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxControlWithItems
|
|
|
|
@wxheader{ctrlsub.h}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This class is an abstract base class for some wxWidgets controls which contain
|
2008-04-10 09:36:51 -04:00
|
|
|
several items such as wxListBox, wxCheckListBox, wxChoice and wxComboBox derive
|
|
|
|
from it.
|
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
It defines the methods for accessing the controls items and although each of
|
|
|
|
the derived classes implements them differently, they still all conform to the
|
|
|
|
same interface.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
The items in a wxControlWithItems have (non-empty) string labels and,
|
|
|
|
optionally, client data associated with them. Client data may be of two
|
|
|
|
different kinds: either simple untyped (@c void *) pointers which are simply
|
|
|
|
stored by the control but not used in any way by it, or typed pointers
|
|
|
|
(@c wxClientData *) which are owned by the control meaning that the typed
|
2008-04-10 09:36:51 -04:00
|
|
|
client data (and only it) will be deleted when an item is deleted
|
|
|
|
(using wxControlWithItems::Delete) or the entire control is cleared
|
|
|
|
(using wxControlWithItems::Clear) which also happens when it is
|
|
|
|
destroyed.
|
|
|
|
|
|
|
|
Finally note that in the same control all items must have client data of the
|
|
|
|
same type (typed or untyped), if any. This type is determined by
|
2008-03-08 08:52:38 -05:00
|
|
|
the first call to wxControlWithItems::Append (the version with
|
|
|
|
client data pointer) or wxControlWithItems::SetClientData.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
2008-04-10 09:36:51 -04:00
|
|
|
@category{controls}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxControlWithItems::Clear
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxControlWithItems : public wxControl
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Appends several items at once to the control. Notice that calling this method
|
|
|
|
is usually much faster than appending them one by one if you need to add a lot
|
|
|
|
of items.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param item
|
2008-03-09 08:33:59 -04:00
|
|
|
String to add.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param stringsArray
|
2008-03-09 08:33:59 -04:00
|
|
|
Contains items to append to the control.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param strings
|
2008-03-09 08:33:59 -04:00
|
|
|
Array of strings of size n.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param n
|
2008-03-09 08:33:59 -04:00
|
|
|
Number of items in the strings array.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param clientData
|
2008-03-09 08:33:59 -04:00
|
|
|
Array of client data pointers of size n to associate with the new items.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@returns When appending a single item, the return value is the index of
|
2008-03-09 08:33:59 -04:00
|
|
|
the newly added item which may be different from the
|
|
|
|
last one if the control is sorted (e.g. has wxLB_SORT
|
|
|
|
or wxCB_SORT style).
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
int Append(const wxString& item);
|
2008-03-09 08:33:59 -04:00
|
|
|
int Append(const wxString& item, void* clientData);
|
|
|
|
int Append(const wxString& item, wxClientData* clientData);
|
2008-03-08 09:43:31 -05:00
|
|
|
void Append(const wxArrayString& strings);
|
|
|
|
void Append(unsigned int n, const wxString* strings);
|
|
|
|
void Append(unsigned int n, const wxString* strings,
|
2008-03-09 08:33:59 -04:00
|
|
|
void** clientData);
|
2008-03-08 09:43:31 -05:00
|
|
|
void Append(unsigned int n, const wxString* strings,
|
2008-03-09 08:33:59 -04:00
|
|
|
wxClientData** clientData);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Removes all items from the control.
|
|
|
|
@e Clear() also deletes the client data of the existing items if it is owned
|
|
|
|
by the control.
|
|
|
|
*/
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Deletes an item from the control. The client data associated with the item
|
|
|
|
will be also deleted if it is owned by the control.
|
|
|
|
Note that it is an error (signalled by an assert failure in debug builds) to
|
|
|
|
remove an item with the index negative or greater or equal than the number of
|
|
|
|
items in the control.
|
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-03-09 08:33:59 -04:00
|
|
|
@see Clear()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void Delete(unsigned int n);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Finds an item whose label matches the given string.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param string
|
2008-03-09 08:33:59 -04:00
|
|
|
String to find.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param caseSensitive
|
2008-03-09 08:33:59 -04:00
|
|
|
Whether search is case sensitive (default is not).
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@returns The zero-based position of the item, or wxNOT_FOUND if the
|
2008-03-09 08:33:59 -04:00
|
|
|
string was not found.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
int FindString(const wxString& string,
|
2008-03-09 08:33:59 -04:00
|
|
|
bool caseSensitive = false);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a pointer to the client data associated with the given item (if any).
|
|
|
|
It is an error to call this function for a control which doesn't have untyped
|
|
|
|
client data at all although it is ok to call it even if the given item doesn't
|
|
|
|
have any client data associated with it (but other items do).
|
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 position of the item.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@returns A pointer to the client data, or @NULL if not present.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
void* GetClientData(unsigned int n) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a pointer to the client data associated with the given item (if any).
|
|
|
|
It is an error to call this function for a control which doesn't have typed
|
|
|
|
client data at all although it is ok to call it even if the given item doesn't
|
|
|
|
have any client data associated with it (but other items do).
|
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 position of the item.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@returns A pointer to the client data, or @NULL if not present.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxClientData* GetClientObject(unsigned int n) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the number of items in the control.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see IsEmpty()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
unsigned int GetCount() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the index of the selected item or @c wxNOT_FOUND if no item is
|
|
|
|
selected.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@returns The position of the current selection.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@remarks This method can be used with single selection list boxes only,
|
2008-03-09 08:33:59 -04:00
|
|
|
you should use wxListBox::GetSelections for the list
|
|
|
|
boxes with wxLB_MULTIPLE style.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see SetSelection(), GetStringSelection()
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the label of the item with the given index.
|
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 index.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@returns The label of the item or an empty string if the position was
|
2008-03-09 08:33:59 -04:00
|
|
|
invalid.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxString GetString(unsigned int n) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the label of the selected item or an empty string if no item is
|
|
|
|
selected.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see GetSelection()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxString GetStringSelection() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the array of the labels of all items in the control.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxArrayString GetStrings() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Inserts several items at once into the control. Notice that calling this method
|
|
|
|
is usually much faster than inserting them one by one if you need to insert a
|
|
|
|
lot
|
|
|
|
of items.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param item
|
2008-03-09 08:33:59 -04:00
|
|
|
String to add.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param pos
|
2008-03-09 08:33:59 -04:00
|
|
|
Position to insert item before, zero based.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param stringsArray
|
2008-03-09 08:33:59 -04:00
|
|
|
Contains items to insert into the control content
|
2008-03-08 09:43:31 -05:00
|
|
|
@param strings
|
2008-03-09 08:33:59 -04:00
|
|
|
Array of strings of size n.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param n
|
2008-03-09 08:33:59 -04:00
|
|
|
Number of items in the strings array.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param clientData
|
2008-03-09 08:33:59 -04:00
|
|
|
Array of client data pointers of size n to associate with the new items.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@returns The return value is the index of the newly inserted item. If the
|
2008-03-09 08:33:59 -04:00
|
|
|
insertion failed for some reason, -1 is returned.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
int Insert(const wxString& item, unsigned int pos);
|
2008-03-08 09:43:31 -05:00
|
|
|
int Insert(const wxString& item, unsigned int pos,
|
2008-03-09 08:33:59 -04:00
|
|
|
void* clientData);
|
2008-03-08 09:43:31 -05:00
|
|
|
int Insert(const wxString& item, unsigned int pos,
|
2008-03-09 08:33:59 -04:00
|
|
|
wxClientData* clientData);
|
2008-03-08 09:43:31 -05:00
|
|
|
void Insert(const wxArrayString& strings, unsigned int pos);
|
|
|
|
void Insert(const wxArrayString& strings, unsigned int pos);
|
|
|
|
void Insert(unsigned int n, const wxString* strings,
|
|
|
|
unsigned int pos);
|
|
|
|
void Insert(unsigned int n, const wxString* strings,
|
|
|
|
unsigned int pos,
|
2008-03-09 08:33:59 -04:00
|
|
|
void** clientData);
|
2008-03-08 09:43:31 -05:00
|
|
|
void Insert(unsigned int n, const wxString* strings,
|
|
|
|
unsigned int pos,
|
2008-03-09 08:33:59 -04:00
|
|
|
wxClientData** clientData);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the control is empty or @false if it has some items.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see GetCount()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool IsEmpty() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
This is the same as SetSelection() and
|
|
|
|
exists only because it is slightly more natural for controls which support
|
|
|
|
multiple selection.
|
|
|
|
*/
|
|
|
|
void Select(int n);
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Replaces the current control contents with the given items. Notice that calling
|
|
|
|
this method is much faster than appending the items one by one if you need to
|
|
|
|
append a lot of them.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param item
|
2008-03-09 08:33:59 -04:00
|
|
|
The single item to insert into the control.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param stringsArray
|
2008-03-09 08:33:59 -04:00
|
|
|
Contains items to set as control content.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param strings
|
2008-03-09 08:33:59 -04:00
|
|
|
Raw C++ array of strings. Only used in conjunction with 'n'.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param n
|
2008-03-09 08:33:59 -04:00
|
|
|
Number of items passed in 'strings'. Only used in conjunction with
|
|
|
|
'strings'.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param clientData
|
2008-03-09 08:33:59 -04:00
|
|
|
Client data to associate with the item(s).
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@returns When the control is sorted (e.g. has wxLB_SORT or wxCB_SORT
|
2008-03-09 08:33:59 -04:00
|
|
|
style) the return value could be different from
|
|
|
|
(GetCount() - 1). When setting a single item to the
|
|
|
|
container, the return value is the index of the newly
|
|
|
|
added item which may be different from the last one if
|
|
|
|
the control is sorted (e.g. has wxLB_SORT or wxCB_SORT
|
|
|
|
style).
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
int Set(const wxString& item);
|
2008-03-09 08:33:59 -04:00
|
|
|
int Set(const wxString& item, void* clientData);
|
|
|
|
int Set(const wxString& item, wxClientData* clientData);
|
2008-03-08 09:43:31 -05:00
|
|
|
void Set(const wxArrayString& stringsArray);
|
|
|
|
void Set(unsigned int n, const wxString* strings);
|
|
|
|
void Set(unsigned int n, const wxString* strings,
|
2008-03-09 08:33:59 -04:00
|
|
|
void** clientData);
|
2008-03-08 09:43:31 -05:00
|
|
|
void Set(unsigned int n, const wxString* strings,
|
2008-03-09 08:33:59 -04:00
|
|
|
wxClientData** clientData);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Associates the given untyped client data pointer with the given item. Note that
|
|
|
|
it is an error to call this function if any typed client data pointers had been
|
|
|
|
associated with the control items before.
|
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-08 09:43:31 -05:00
|
|
|
@param data
|
2008-03-09 08:33:59 -04:00
|
|
|
The client data to associate with the item.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
void SetClientData(unsigned int n, void* data);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Associates the given typed client data pointer with the given item: the
|
2008-03-09 08:33:59 -04:00
|
|
|
@a data object will be deleted when the item is deleted (either explicitly
|
2008-03-08 08:52:38 -05:00
|
|
|
by using @ref delete() Deletes or implicitly when the
|
|
|
|
control itself is destroyed).
|
|
|
|
Note that it is an error to call this function if any untyped client data
|
|
|
|
pointers had been associated with the control items before.
|
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-08 09:43:31 -05:00
|
|
|
@param data
|
2008-03-09 08:33:59 -04:00
|
|
|
The client data to associate with the item.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
void SetClientObject(unsigned int n, wxClientData* data);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
Sets the selection to the given item @a n or removes the selection entirely
|
|
|
|
if @a n == @c wxNOT_FOUND.
|
2008-03-08 08:52:38 -05:00
|
|
|
Note that this does not cause any command events to be emitted nor does it
|
|
|
|
deselect any other items in the controls which support multiple selections.
|
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 string position to select, starting from zero.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-09 08:33:59 -04:00
|
|
|
@see SetString(), SetStringSelection()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void SetSelection(int n);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the label for the given item.
|
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-08 09:43:31 -05:00
|
|
|
@param string
|
2008-03-09 08:33:59 -04:00
|
|
|
The label to set.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void SetString(unsigned int n, const wxString& string);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Selects the item with the specified string in the control. This doesn't cause
|
|
|
|
any command events to be emitted.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param string
|
2008-03-09 08:33:59 -04:00
|
|
|
The string to select.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@returns @true if the specified string has been selected, @false if it
|
2008-03-09 08:33:59 -04:00
|
|
|
wasn't found in the control.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool SetStringSelection(const wxString& string);
|
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|