Version: 3.0.5
Loading...
Searching...
No Matches
wxRearrangeList Class Reference

#include <wx/rearrangectrl.h>

+ Inheritance diagram for wxRearrangeList:

Detailed Description

A listbox-like control allowing the user to rearrange the items and to enable or disable them.

This class allows changing the order of the items shown in it as well as checking or unchecking them individually. The data structure used to allow this is the order array which contains the items indices indexed by their position with an added twist that the unchecked items are represented by the bitwise complement of the corresponding index (for any architecture using two's complement for negative numbers representation (i.e. just about any at all) this means that a checked item N is represented by -N-1 in unchecked state). In practice this means that you must apply the C bitwise complement operator when constructing the order array, e.g.

wxArrayInt order;
order.push_back(0); // checked item #0
order.push_back(~1); // unchecked item #1
wxArray< int > wxArrayInt
Predefined specialization of wxArray<T> for standard types.
Definition dynarray.h:808

So, for example, the array order [1 -3 0] used in conjunction with the items array ["first", "second", "third"] means that the items order is "second", "third", "first" and the "third" item is unchecked while the other two are checked.

This convention is used both for the order argument of the control ctor or Create() and for the array returned from GetCurrentOrder().

Usually this control will be used together with other controls allowing to move the items around in it interactively. The simplest possible solution is to use wxRearrangeCtrl which combines it with two standard buttons to move the current item up or down.

Since
2.9.0

Library:  wxCore

<>< =''>:</>&;&;< =''>\ </></>

Public Member Functions

 wxRearrangeList ()
 Default constructor.
 
 wxRearrangeList (wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayInt &order, const wxArrayString &items, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxRearrangeListNameStr)
 Constructor really creating the control.
 
bool Create (wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxArrayInt &order, const wxArrayString &items, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxRearrangeListNameStr)
 Effectively creates the window for an object created using the default constructor.
 
const wxArrayIntGetCurrentOrder () const
 Return the current order of the items.
 
bool CanMoveCurrentUp () const
 Return true if the currently selected item can be moved up.
 
bool CanMoveCurrentDown () const
 Return true if the currently selected item can be moved down.
 
bool MoveCurrentUp ()
 Move the currently selected item one position above.
 
bool MoveCurrentDown ()
 Move the currently selected item one position below.
 

Constructor & Destructor Documentation

◆ wxRearrangeList() [1/2]

wxRearrangeList::wxRearrangeList ( )

Default constructor.

Create() must be called later to effectively create the control.

◆ wxRearrangeList() [2/2]

wxRearrangeList::wxRearrangeList ( wxWindow parent,
wxWindowID  id,
const wxPoint pos,
const wxSize size,
const wxArrayInt order,
const wxArrayString items,
long  style = 0,
const wxValidator validator = wxDefaultValidator,
const wxString name = wxRearrangeListNameStr 
)

Constructor really creating the control.

Please see Create() for the parameters description.

Member Function Documentation

◆ CanMoveCurrentDown()

bool wxRearrangeList::CanMoveCurrentDown ( ) const

Return true if the currently selected item can be moved down.

See also
CanMoveCurrentUp()

◆ CanMoveCurrentUp()

bool wxRearrangeList::CanMoveCurrentUp ( ) const

Return true if the currently selected item can be moved up.

This function is useful for EVT_UPDATE_UI handler for the standard "Up" button often used together with this control and wxRearrangeCtrl uses it in this way.

Returns
true if the currently selected item can be moved up in the listbox, false if there is no selection or the current item is the first one.
See also
CanMoveCurrentDown()

◆ Create()

bool wxRearrangeList::Create ( wxWindow parent,
wxWindowID  id,
const wxPoint pos,
const wxSize size,
const wxArrayInt order,
const wxArrayString items,
long  style = 0,
const wxValidator validator = wxDefaultValidator,
const wxString name = wxRearrangeListNameStr 
)

Effectively creates the window for an object created using the default constructor.

This function is very similar to wxCheckListBox::Create() except that it has an additional parameter specifying the initial order of the items. Please see the class documentation for the explanation of the conventions used by the order argument.

Parameters
parentThe parent window, must be non-NULL.
idThe window identifier.
posThe initial window position.
sizeThe initial window size.
orderArray specifying the initial order of the items in items array.
itemsThe items to display in the list.
styleThe control style, there are no special styles for this class but the base class styles can be used here.
validatorOptional window validator.
nameOptional window name.

◆ GetCurrentOrder()

const wxArrayInt & wxRearrangeList::GetCurrentOrder ( ) const

Return the current order of the items.

The order may be different from the one passed to the constructor if MoveCurrentUp() or MoveCurrentDown() were called.

◆ MoveCurrentDown()

bool wxRearrangeList::MoveCurrentDown ( )

Move the currently selected item one position below.

See also
MoveCurrentUp()

◆ MoveCurrentUp()

bool wxRearrangeList::MoveCurrentUp ( )

Move the currently selected item one position above.

This method is useful to implement the standard "Up" button behaviour and wxRearrangeCtrl uses it for this.

Returns
true if the item was moved or false if this couldn't be done.
See also
MoveCurrentDown()