1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/rearrangectrl.h
3 // Purpose: various controls for rearranging the items interactively
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_REARRANGECTRL_H_
12 #define _WX_REARRANGECTRL_H_
14 #include "wx/checklst.h"
15 #include "wx/arrstr.h"
17 extern WXDLLIMPEXP_DATA_CORE(const char) wxRearrangeListNameStr
[];
18 extern WXDLLIMPEXP_DATA_CORE(const char) wxRearrangeDialogNameStr
[];
20 // ----------------------------------------------------------------------------
21 // wxRearrangeList: a (check) list box allowing to move items around
22 // ----------------------------------------------------------------------------
24 // This class works allows to change the order of the items shown in it as well
25 // as to check or uncheck them individually. The data structure used to allow
26 // this is the order array which contains the items indices indexed by their
27 // position with an added twist that the unchecked items are represented by the
28 // bitwise complement of the corresponding index (for any architecture using
29 // two's complement for negative numbers representation (i.e. just about any at
30 // all) this means that a checked item N is represented by -N-1 in unchecked
33 // So, for example, the array order [1 -3 0] used in conjunction with the items
34 // array ["first", "second", "third"] means that the items are displayed in the
35 // order "second", "third", "first" and the "third" item is unchecked while the
36 // other two are checked.
37 class WXDLLIMPEXP_CORE wxRearrangeList
: public wxCheckListBox
43 // default ctor, call Create() later
46 // ctor creating the control, the arguments are the same as for
47 // wxCheckListBox except for the extra order array which defines the
48 // (initial) display order of the items as well as their statuses, see the
50 wxRearrangeList(wxWindow
*parent
,
54 const wxArrayInt
& order
,
55 const wxArrayString
& items
,
57 const wxValidator
& validator
= wxDefaultValidator
,
58 const wxString
& name
= wxRearrangeListNameStr
)
60 Create(parent
, id
, pos
, size
, order
, items
, style
, validator
, name
);
63 // Create() function takes the same parameters as the base class one and
64 // the order array determining the initial display order
65 bool Create(wxWindow
*parent
,
69 const wxArrayInt
& order
,
70 const wxArrayString
& items
,
72 const wxValidator
& validator
= wxDefaultValidator
,
73 const wxString
& name
= wxRearrangeListNameStr
);
79 // get the current items order; the returned array uses the same convention
80 // as the one passed to the ctor
81 const wxArrayInt
& GetCurrentOrder() const { return m_order
; }
83 // return true if the current item can be moved up or down (i.e. just that
84 // it's not the first or the last one)
85 bool CanMoveCurrentUp() const;
86 bool CanMoveCurrentDown() const;
88 // move the current item one position up or down, return true if it was moved
89 // or false if the current item was the first/last one and so nothing was done
91 bool MoveCurrentDown();
94 // swap two items at the given positions in the listbox
95 void Swap(int pos1
, int pos2
);
97 // event handler for item checking/unchecking
98 void OnCheck(wxCommandEvent
& event
);
101 // the current order array
105 DECLARE_EVENT_TABLE()
106 DECLARE_NO_COPY_CLASS(wxRearrangeList
)
109 // ----------------------------------------------------------------------------
110 // wxRearrangeCtrl: composite control containing a wxRearrangeList and buttons
111 // ----------------------------------------------------------------------------
113 class WXDLLIMPEXP_CORE wxRearrangeCtrl
: public wxPanel
116 // ctors/Create function are the same as for wxRearrangeList
122 wxRearrangeCtrl(wxWindow
*parent
,
126 const wxArrayInt
& order
,
127 const wxArrayString
& items
,
129 const wxValidator
& validator
= wxDefaultValidator
,
130 const wxString
& name
= wxRearrangeListNameStr
)
134 Create(parent
, id
, pos
, size
, order
, items
, style
, validator
, name
);
137 bool Create(wxWindow
*parent
,
141 const wxArrayInt
& order
,
142 const wxArrayString
& items
,
144 const wxValidator
& validator
= wxDefaultValidator
,
145 const wxString
& name
= wxRearrangeListNameStr
);
147 // get the underlying listbox
148 wxRearrangeList
*GetList() const { return m_list
; }
151 // common part of all ctors
154 // event handlers for the buttons
155 void OnUpdateButtonUI(wxUpdateUIEvent
& event
);
156 void OnButton(wxCommandEvent
& event
);
159 wxRearrangeList
*m_list
;
162 DECLARE_EVENT_TABLE()
163 DECLARE_NO_COPY_CLASS(wxRearrangeCtrl
)
166 // ----------------------------------------------------------------------------
167 // wxRearrangeDialog: dialog containing a wxRearrangeCtrl
168 // ----------------------------------------------------------------------------
170 class WXDLLIMPEXP_CORE wxRearrangeDialog
: public wxDialog
173 // ctor for the dialog: message is shown inside the dialog itself, order
174 // and items are passed to wxRearrangeList used internally
175 wxRearrangeDialog(wxWindow
*parent
,
176 const wxString
& message
,
177 const wxString
& title
,
178 const wxArrayInt
& order
,
179 const wxArrayString
& items
,
180 const wxPoint
& pos
= wxDefaultPosition
,
181 const wxString
& name
= wxRearrangeDialogNameStr
);
183 // get the order of items after it was modified by the user
184 wxArrayInt
GetOrder() const
185 { return m_ctrl
->GetList()->GetCurrentOrder(); }
188 wxRearrangeCtrl
*m_ctrl
;
190 DECLARE_NO_COPY_CLASS(wxRearrangeDialog
)
193 #endif // _WX_REARRANGECTRL_H_