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"
16 #if wxUSE_REARRANGECTRL
19 #include "wx/dialog.h"
21 #include "wx/arrstr.h"
23 extern WXDLLIMPEXP_DATA_CORE(const char) wxRearrangeListNameStr
[];
24 extern WXDLLIMPEXP_DATA_CORE(const char) wxRearrangeDialogNameStr
[];
26 // ----------------------------------------------------------------------------
27 // wxRearrangeList: a (check) list box allowing to move items around
28 // ----------------------------------------------------------------------------
30 // This class works allows to change the order of the items shown in it as well
31 // as to check or uncheck them individually. The data structure used to allow
32 // this is the order array which contains the items indices indexed by their
33 // position with an added twist that the unchecked items are represented by the
34 // bitwise complement of the corresponding index (for any architecture using
35 // two's complement for negative numbers representation (i.e. just about any at
36 // all) this means that a checked item N is represented by -N-1 in unchecked
39 // So, for example, the array order [1 -3 0] used in conjunction with the items
40 // array ["first", "second", "third"] means that the items are displayed in the
41 // order "second", "third", "first" and the "third" item is unchecked while the
42 // other two are checked.
43 class WXDLLIMPEXP_CORE wxRearrangeList
: public wxCheckListBox
49 // default ctor, call Create() later
52 // ctor creating the control, the arguments are the same as for
53 // wxCheckListBox except for the extra order array which defines the
54 // (initial) display order of the items as well as their statuses, see the
56 wxRearrangeList(wxWindow
*parent
,
60 const wxArrayInt
& order
,
61 const wxArrayString
& items
,
63 const wxValidator
& validator
= wxDefaultValidator
,
64 const wxString
& name
= wxRearrangeListNameStr
)
66 Create(parent
, id
, pos
, size
, order
, items
, style
, validator
, name
);
69 // Create() function takes the same parameters as the base class one and
70 // the order array determining the initial display order
71 bool Create(wxWindow
*parent
,
75 const wxArrayInt
& order
,
76 const wxArrayString
& items
,
78 const wxValidator
& validator
= wxDefaultValidator
,
79 const wxString
& name
= wxRearrangeListNameStr
);
85 // get the current items order; the returned array uses the same convention
86 // as the one passed to the ctor
87 const wxArrayInt
& GetCurrentOrder() const { return m_order
; }
89 // return true if the current item can be moved up or down (i.e. just that
90 // it's not the first or the last one)
91 bool CanMoveCurrentUp() const;
92 bool CanMoveCurrentDown() const;
94 // move the current item one position up or down, return true if it was moved
95 // or false if the current item was the first/last one and so nothing was done
97 bool MoveCurrentDown();
100 // swap two items at the given positions in the listbox
101 void Swap(int pos1
, int pos2
);
103 // event handler for item checking/unchecking
104 void OnCheck(wxCommandEvent
& event
);
107 // the current order array
111 DECLARE_EVENT_TABLE()
112 wxDECLARE_NO_COPY_CLASS(wxRearrangeList
);
115 // ----------------------------------------------------------------------------
116 // wxRearrangeCtrl: composite control containing a wxRearrangeList and buttons
117 // ----------------------------------------------------------------------------
119 class WXDLLIMPEXP_CORE wxRearrangeCtrl
: public wxPanel
122 // ctors/Create function are the same as for wxRearrangeList
128 wxRearrangeCtrl(wxWindow
*parent
,
132 const wxArrayInt
& order
,
133 const wxArrayString
& items
,
135 const wxValidator
& validator
= wxDefaultValidator
,
136 const wxString
& name
= wxRearrangeListNameStr
)
140 Create(parent
, id
, pos
, size
, order
, items
, style
, validator
, name
);
143 bool Create(wxWindow
*parent
,
147 const wxArrayInt
& order
,
148 const wxArrayString
& items
,
150 const wxValidator
& validator
= wxDefaultValidator
,
151 const wxString
& name
= wxRearrangeListNameStr
);
153 // get the underlying listbox
154 wxRearrangeList
*GetList() const { return m_list
; }
157 // common part of all ctors
160 // event handlers for the buttons
161 void OnUpdateButtonUI(wxUpdateUIEvent
& event
);
162 void OnButton(wxCommandEvent
& event
);
165 wxRearrangeList
*m_list
;
168 DECLARE_EVENT_TABLE()
169 wxDECLARE_NO_COPY_CLASS(wxRearrangeCtrl
);
172 // ----------------------------------------------------------------------------
173 // wxRearrangeDialog: dialog containing a wxRearrangeCtrl
174 // ----------------------------------------------------------------------------
176 class WXDLLIMPEXP_CORE wxRearrangeDialog
: public wxDialog
179 // default ctor, use Create() later
180 wxRearrangeDialog() { Init(); }
182 // ctor for the dialog: message is shown inside the dialog itself, order
183 // and items are passed to wxRearrangeList used internally
184 wxRearrangeDialog(wxWindow
*parent
,
185 const wxString
& message
,
186 const wxString
& title
,
187 const wxArrayInt
& order
,
188 const wxArrayString
& items
,
189 const wxPoint
& pos
= wxDefaultPosition
,
190 const wxString
& name
= wxRearrangeDialogNameStr
)
194 Create(parent
, message
, title
, order
, items
, pos
, name
);
197 bool Create(wxWindow
*parent
,
198 const wxString
& message
,
199 const wxString
& title
,
200 const wxArrayInt
& order
,
201 const wxArrayString
& items
,
202 const wxPoint
& pos
= wxDefaultPosition
,
203 const wxString
& name
= wxRearrangeDialogNameStr
);
206 // methods for the dialog customization
208 // add extra contents to the dialog below the wxRearrangeCtrl part: the
209 // given window (usually a wxPanel containing more control inside it) must
210 // have the dialog as its parent and will be inserted into it at the right
211 // place by this method
212 void AddExtraControls(wxWindow
*win
);
214 // return the wxRearrangeList control used by the dialog
215 wxRearrangeList
*GetList() const;
218 // get the order of items after it was modified by the user
219 wxArrayInt
GetOrder() const;
222 // common part of all ctors
223 void Init() { m_ctrl
= NULL
; }
225 wxRearrangeCtrl
*m_ctrl
;
227 wxDECLARE_NO_COPY_CLASS(wxRearrangeDialog
);
230 #endif // wxUSE_REARRANGECTRL
232 #endif // _WX_REARRANGECTRL_H_