1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/rearrangectrl.h
3 // Purpose: various controls for rearranging the items interactively
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_REARRANGECTRL_H_
11 #define _WX_REARRANGECTRL_H_
13 #include "wx/checklst.h"
15 #if wxUSE_REARRANGECTRL
18 #include "wx/dialog.h"
20 #include "wx/arrstr.h"
22 extern WXDLLIMPEXP_DATA_CORE(const char) wxRearrangeListNameStr
[];
23 extern WXDLLIMPEXP_DATA_CORE(const char) wxRearrangeDialogNameStr
[];
25 // ----------------------------------------------------------------------------
26 // wxRearrangeList: a (check) list box allowing to move items around
27 // ----------------------------------------------------------------------------
29 // This class works allows to change the order of the items shown in it as well
30 // as to check or uncheck them individually. The data structure used to allow
31 // this is the order array which contains the items indices indexed by their
32 // position with an added twist that the unchecked items are represented by the
33 // bitwise complement of the corresponding index (for any architecture using
34 // two's complement for negative numbers representation (i.e. just about any at
35 // all) this means that a checked item N is represented by -N-1 in unchecked
38 // So, for example, the array order [1 -3 0] used in conjunction with the items
39 // array ["first", "second", "third"] means that the items are displayed in the
40 // order "second", "third", "first" and the "third" item is unchecked while the
41 // other two are checked.
42 class WXDLLIMPEXP_CORE wxRearrangeList
: public wxCheckListBox
48 // default ctor, call Create() later
51 // ctor creating the control, the arguments are the same as for
52 // wxCheckListBox except for the extra order array which defines the
53 // (initial) display order of the items as well as their statuses, see the
55 wxRearrangeList(wxWindow
*parent
,
59 const wxArrayInt
& order
,
60 const wxArrayString
& items
,
62 const wxValidator
& validator
= wxDefaultValidator
,
63 const wxString
& name
= wxRearrangeListNameStr
)
65 Create(parent
, id
, pos
, size
, order
, items
, style
, validator
, name
);
68 // Create() function takes the same parameters as the base class one and
69 // the order array determining the initial display order
70 bool Create(wxWindow
*parent
,
74 const wxArrayInt
& order
,
75 const wxArrayString
& items
,
77 const wxValidator
& validator
= wxDefaultValidator
,
78 const wxString
& name
= wxRearrangeListNameStr
);
84 // get the current items order; the returned array uses the same convention
85 // as the one passed to the ctor
86 const wxArrayInt
& GetCurrentOrder() const { return m_order
; }
88 // return true if the current item can be moved up or down (i.e. just that
89 // it's not the first or the last one)
90 bool CanMoveCurrentUp() const;
91 bool CanMoveCurrentDown() const;
93 // move the current item one position up or down, return true if it was moved
94 // or false if the current item was the first/last one and so nothing was done
96 bool MoveCurrentDown();
99 // swap two items at the given positions in the listbox
100 void Swap(int pos1
, int pos2
);
102 // event handler for item checking/unchecking
103 void OnCheck(wxCommandEvent
& event
);
106 // the current order array
110 DECLARE_EVENT_TABLE()
111 wxDECLARE_NO_COPY_CLASS(wxRearrangeList
);
114 // ----------------------------------------------------------------------------
115 // wxRearrangeCtrl: composite control containing a wxRearrangeList and buttons
116 // ----------------------------------------------------------------------------
118 class WXDLLIMPEXP_CORE wxRearrangeCtrl
: public wxPanel
121 // ctors/Create function are the same as for wxRearrangeList
127 wxRearrangeCtrl(wxWindow
*parent
,
131 const wxArrayInt
& order
,
132 const wxArrayString
& items
,
134 const wxValidator
& validator
= wxDefaultValidator
,
135 const wxString
& name
= wxRearrangeListNameStr
)
139 Create(parent
, id
, pos
, size
, order
, items
, style
, validator
, name
);
142 bool Create(wxWindow
*parent
,
146 const wxArrayInt
& order
,
147 const wxArrayString
& items
,
149 const wxValidator
& validator
= wxDefaultValidator
,
150 const wxString
& name
= wxRearrangeListNameStr
);
152 // get the underlying listbox
153 wxRearrangeList
*GetList() const { return m_list
; }
156 // common part of all ctors
159 // event handlers for the buttons
160 void OnUpdateButtonUI(wxUpdateUIEvent
& event
);
161 void OnButton(wxCommandEvent
& event
);
164 wxRearrangeList
*m_list
;
167 DECLARE_EVENT_TABLE()
168 wxDECLARE_NO_COPY_CLASS(wxRearrangeCtrl
);
171 // ----------------------------------------------------------------------------
172 // wxRearrangeDialog: dialog containing a wxRearrangeCtrl
173 // ----------------------------------------------------------------------------
175 class WXDLLIMPEXP_CORE wxRearrangeDialog
: public wxDialog
178 // default ctor, use Create() later
179 wxRearrangeDialog() { Init(); }
181 // ctor for the dialog: message is shown inside the dialog itself, order
182 // and items are passed to wxRearrangeList used internally
183 wxRearrangeDialog(wxWindow
*parent
,
184 const wxString
& message
,
185 const wxString
& title
,
186 const wxArrayInt
& order
,
187 const wxArrayString
& items
,
188 const wxPoint
& pos
= wxDefaultPosition
,
189 const wxString
& name
= wxRearrangeDialogNameStr
)
193 Create(parent
, message
, title
, order
, items
, pos
, name
);
196 bool Create(wxWindow
*parent
,
197 const wxString
& message
,
198 const wxString
& title
,
199 const wxArrayInt
& order
,
200 const wxArrayString
& items
,
201 const wxPoint
& pos
= wxDefaultPosition
,
202 const wxString
& name
= wxRearrangeDialogNameStr
);
205 // methods for the dialog customization
207 // add extra contents to the dialog below the wxRearrangeCtrl part: the
208 // given window (usually a wxPanel containing more control inside it) must
209 // have the dialog as its parent and will be inserted into it at the right
210 // place by this method
211 void AddExtraControls(wxWindow
*win
);
213 // return the wxRearrangeList control used by the dialog
214 wxRearrangeList
*GetList() const;
217 // get the order of items after it was modified by the user
218 wxArrayInt
GetOrder() const;
221 // common part of all ctors
222 void Init() { m_ctrl
= NULL
; }
224 wxRearrangeCtrl
*m_ctrl
;
226 wxDECLARE_NO_COPY_CLASS(wxRearrangeDialog
);
229 #endif // wxUSE_REARRANGECTRL
231 #endif // _WX_REARRANGECTRL_H_