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 #include "wx/dialog.h"
18 #include "wx/arrstr.h"
20 extern WXDLLIMPEXP_DATA_CORE(const char) wxRearrangeListNameStr
[];
21 extern WXDLLIMPEXP_DATA_CORE(const char) wxRearrangeDialogNameStr
[];
23 // ----------------------------------------------------------------------------
24 // wxRearrangeList: a (check) list box allowing to move items around
25 // ----------------------------------------------------------------------------
27 // This class works allows to change the order of the items shown in it as well
28 // as to check or uncheck them individually. The data structure used to allow
29 // this is the order array which contains the items indices indexed by their
30 // position with an added twist that the unchecked items are represented by the
31 // bitwise complement of the corresponding index (for any architecture using
32 // two's complement for negative numbers representation (i.e. just about any at
33 // all) this means that a checked item N is represented by -N-1 in unchecked
36 // So, for example, the array order [1 -3 0] used in conjunction with the items
37 // array ["first", "second", "third"] means that the items are displayed in the
38 // order "second", "third", "first" and the "third" item is unchecked while the
39 // other two are checked.
40 class WXDLLIMPEXP_CORE wxRearrangeList
: public wxCheckListBox
46 // default ctor, call Create() later
49 // ctor creating the control, the arguments are the same as for
50 // wxCheckListBox except for the extra order array which defines the
51 // (initial) display order of the items as well as their statuses, see the
53 wxRearrangeList(wxWindow
*parent
,
57 const wxArrayInt
& order
,
58 const wxArrayString
& items
,
60 const wxValidator
& validator
= wxDefaultValidator
,
61 const wxString
& name
= wxRearrangeListNameStr
)
63 Create(parent
, id
, pos
, size
, order
, items
, style
, validator
, name
);
66 // Create() function takes the same parameters as the base class one and
67 // the order array determining the initial display order
68 bool Create(wxWindow
*parent
,
72 const wxArrayInt
& order
,
73 const wxArrayString
& items
,
75 const wxValidator
& validator
= wxDefaultValidator
,
76 const wxString
& name
= wxRearrangeListNameStr
);
82 // get the current items order; the returned array uses the same convention
83 // as the one passed to the ctor
84 const wxArrayInt
& GetCurrentOrder() const { return m_order
; }
86 // return true if the current item can be moved up or down (i.e. just that
87 // it's not the first or the last one)
88 bool CanMoveCurrentUp() const;
89 bool CanMoveCurrentDown() const;
91 // move the current item one position up or down, return true if it was moved
92 // or false if the current item was the first/last one and so nothing was done
94 bool MoveCurrentDown();
97 // swap two items at the given positions in the listbox
98 void Swap(int pos1
, int pos2
);
100 // event handler for item checking/unchecking
101 void OnCheck(wxCommandEvent
& event
);
104 // the current order array
108 DECLARE_EVENT_TABLE()
109 DECLARE_NO_COPY_CLASS(wxRearrangeList
)
112 // ----------------------------------------------------------------------------
113 // wxRearrangeCtrl: composite control containing a wxRearrangeList and buttons
114 // ----------------------------------------------------------------------------
116 class WXDLLIMPEXP_CORE wxRearrangeCtrl
: public wxPanel
119 // ctors/Create function are the same as for wxRearrangeList
125 wxRearrangeCtrl(wxWindow
*parent
,
129 const wxArrayInt
& order
,
130 const wxArrayString
& items
,
132 const wxValidator
& validator
= wxDefaultValidator
,
133 const wxString
& name
= wxRearrangeListNameStr
)
137 Create(parent
, id
, pos
, size
, order
, items
, style
, validator
, name
);
140 bool Create(wxWindow
*parent
,
144 const wxArrayInt
& order
,
145 const wxArrayString
& items
,
147 const wxValidator
& validator
= wxDefaultValidator
,
148 const wxString
& name
= wxRearrangeListNameStr
);
150 // get the underlying listbox
151 wxRearrangeList
*GetList() const { return m_list
; }
154 // common part of all ctors
157 // event handlers for the buttons
158 void OnUpdateButtonUI(wxUpdateUIEvent
& event
);
159 void OnButton(wxCommandEvent
& event
);
162 wxRearrangeList
*m_list
;
165 DECLARE_EVENT_TABLE()
166 DECLARE_NO_COPY_CLASS(wxRearrangeCtrl
)
169 // ----------------------------------------------------------------------------
170 // wxRearrangeDialog: dialog containing a wxRearrangeCtrl
171 // ----------------------------------------------------------------------------
173 class WXDLLIMPEXP_CORE wxRearrangeDialog
: public wxDialog
176 // ctor for the dialog: message is shown inside the dialog itself, order
177 // and items are passed to wxRearrangeList used internally
178 wxRearrangeDialog(wxWindow
*parent
,
179 const wxString
& message
,
180 const wxString
& title
,
181 const wxArrayInt
& order
,
182 const wxArrayString
& items
,
183 const wxPoint
& pos
= wxDefaultPosition
,
184 const wxString
& name
= wxRearrangeDialogNameStr
);
186 // get the order of items after it was modified by the user
187 wxArrayInt
GetOrder() const
188 { return m_ctrl
->GetList()->GetCurrentOrder(); }
191 wxRearrangeCtrl
*m_ctrl
;
193 DECLARE_NO_COPY_CLASS(wxRearrangeDialog
)
196 #endif // _WX_REARRANGECTRL_H_