wxArrayString is an efficient container for storing wxString objects. It has the same features as all wxArray classes, i.e. it dynamically expands when new items are added to it (so it is as easy to use as a linked list), but the access time to the elements is constant, instead of being linear in number of elements as in the case of linked lists. It is also very size efficient and doesn't take more space than a C array wxString[] type (wxArrayString uses its knowledge of internals of wxString class to achieve this).
This class is used in the same way as other dynamic arrays, except that no WX_DEFINE_ARRAY declaration is needed for it. When a string is added or inserted in the array, a copy of the string is created, so the original string may be safely deleted (e.g. if it was a char * pointer the memory it was using can be freed immediately after this). In general, there is no need to worry about string memory deallocation when using this class - it will always free the memory it uses itself.
The references returned by Item, Last or operator[] are not constant, so the array elements may be modified in place like this
array.Last().MakeUpper();
There is also a variant of wxArrayString called wxSortedArrayString which has
exactly the same methods as wxArrayString, but which always keeps the string
in it in (alphabetical) order. wxSortedArrayString uses binary search in its
Index function (instead of linear search for
wxArrayString::Index) which makes it much more efficient if you add strings to
the array rarely (because, of course, you have to pay for Index() efficiency
by having Add() be slower) but search for them often. Several methods should
not be used with sorted array (basically, all which break the order of items)
which is mentioned in their description.Final word: none of the mearamet menuString
itemString
Return value
The menu item identifier, or wxNOT_FOUND if none was found.
Remarks
Any special menu codes are stripped out of source and target strings before matching.
wxMenuItem * FindItem(int id, wxMenu **menu = NULL) const
Finds the menu item object associated with the given menu item identifier.
Parameters
id
menu
Return value
The found menu item object, or NULL if one was not found.
wxString GetHelpString(int id) const
Gets the help string associated with the menu item identifier.
Parameters
id
Return value
The help string, or the empty string if there was no help string or the menu item was not found.
See also
wxString GetLabel(int id) const
Gets the label associated with a menu item.
Parameters
id
Return value
The menu item label, or the empty string if the item was not found.
Remarks
Use only after the menubar has been associated with a frame.
wxString GetLabelTop(int pos) const
Returns the label of a top-level menu. Note that the returned string does not include the accelerator characters which could have been specified in the menu title string during its construction.
Parameters
pos
Return value
The menu label, or the empty string if the menu was not found.
Remarks
Use only after the menubar has been associated with a frame.
See also
wxMenu* GetMenu(int menuIndex) const
Returns the menu at menuIndex (zero-based).
int GetMenuCount() const
Returns the number of menus in this menubar.
bool Insert(size_t pos, wxMenu *menu, const wxString& title)
Inserts the menu at the given position into the menu bar. Inserting menu at position 0 will insert it in the very beginning of it, inserting at position GetMenuCount() is the same as calling Append().
Parameters
pos
menu
title
Return value
true on success, false if an error occurred.
See also
bool IsChecked(int id) const
Determines whether an item is checked.
Parameters
id
Return value
true if the item was found and is checked, false otherwise.
bool IsEnabled(int id) const
Determines whether an item is enabled.
Parameters
id
Return value
true if the item was found and is enabled, false otherwise.
void Refresh()
Redraw the menu bar
wxMenu * Remove(size_t pos)
Removes the menu from the menu bar and returns the menu object - the caller is responsible for deleting it. This function may be used together with wxMenuBar::Insert to change the menubar dynamically.
See also
wxMenu * Replace(size_t pos, wxMenu *menu, const wxString& title)
Replaces the menu at the given position with another one.
Parameters
pos
menu
title
Return value
The menu which was previously at position pos. The caller is responsible for deleting it.
See also
wxMenuBar::Insert, wxMenuBar::Remove
void SetHelpString(int id, const wxString& helpString)
Sets the help string associated with a menu item.
Parameters
id
helpString
See also
void SetLabel(int id, const wxString& label)
Sets the label of a menu item.
Parameters
id
label
Remarks
Use only after the menubar has been associated with a frame.
See also
void SetLabelTop(int pos, const wxString& label)
Sets the label of a top-level menu.
Parameters
pos
label
Remarks
Use only after the menubar has been associated with a frame.
See also