]> git.saurik.com Git - wxWidgets.git/blob - include/wx/rearrangectrl.h
abstract VC6 workaround inside a WX_CPPUNIT_ALLOW_EQUALS_TO_INT() macro
[wxWidgets.git] / include / wx / rearrangectrl.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/rearrangectrl.h
3 // Purpose: various controls for rearranging the items interactively
4 // Author: Vadim Zeitlin
5 // Created: 2008-12-15
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_REARRANGECTRL_H_
12 #define _WX_REARRANGECTRL_H_
13
14 #include "wx/checklst.h"
15 #include "wx/panel.h"
16 #include "wx/dialog.h"
17
18 #include "wx/arrstr.h"
19
20 extern WXDLLIMPEXP_DATA_CORE(const char) wxRearrangeListNameStr[];
21 extern WXDLLIMPEXP_DATA_CORE(const char) wxRearrangeDialogNameStr[];
22
23 // ----------------------------------------------------------------------------
24 // wxRearrangeList: a (check) list box allowing to move items around
25 // ----------------------------------------------------------------------------
26
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
34 // state).
35 //
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
41 {
42 public:
43 // ctors and such
44 // --------------
45
46 // default ctor, call Create() later
47 wxRearrangeList() { }
48
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
52 // description above
53 wxRearrangeList(wxWindow *parent,
54 wxWindowID id,
55 const wxPoint& pos,
56 const wxSize& size,
57 const wxArrayInt& order,
58 const wxArrayString& items,
59 long style = 0,
60 const wxValidator& validator = wxDefaultValidator,
61 const wxString& name = wxRearrangeListNameStr)
62 {
63 Create(parent, id, pos, size, order, items, style, validator, name);
64 }
65
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,
69 wxWindowID id,
70 const wxPoint& pos,
71 const wxSize& size,
72 const wxArrayInt& order,
73 const wxArrayString& items,
74 long style = 0,
75 const wxValidator& validator = wxDefaultValidator,
76 const wxString& name = wxRearrangeListNameStr);
77
78
79 // items order
80 // -----------
81
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; }
85
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;
90
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
93 bool MoveCurrentUp();
94 bool MoveCurrentDown();
95
96 private:
97 // swap two items at the given positions in the listbox
98 void Swap(int pos1, int pos2);
99
100 // event handler for item checking/unchecking
101 void OnCheck(wxCommandEvent& event);
102
103
104 // the current order array
105 wxArrayInt m_order;
106
107
108 DECLARE_EVENT_TABLE()
109 DECLARE_NO_COPY_CLASS(wxRearrangeList)
110 };
111
112 // ----------------------------------------------------------------------------
113 // wxRearrangeCtrl: composite control containing a wxRearrangeList and buttons
114 // ----------------------------------------------------------------------------
115
116 class WXDLLIMPEXP_CORE wxRearrangeCtrl : public wxPanel
117 {
118 public:
119 // ctors/Create function are the same as for wxRearrangeList
120 wxRearrangeCtrl()
121 {
122 Init();
123 }
124
125 wxRearrangeCtrl(wxWindow *parent,
126 wxWindowID id,
127 const wxPoint& pos,
128 const wxSize& size,
129 const wxArrayInt& order,
130 const wxArrayString& items,
131 long style = 0,
132 const wxValidator& validator = wxDefaultValidator,
133 const wxString& name = wxRearrangeListNameStr)
134 {
135 Init();
136
137 Create(parent, id, pos, size, order, items, style, validator, name);
138 }
139
140 bool Create(wxWindow *parent,
141 wxWindowID id,
142 const wxPoint& pos,
143 const wxSize& size,
144 const wxArrayInt& order,
145 const wxArrayString& items,
146 long style = 0,
147 const wxValidator& validator = wxDefaultValidator,
148 const wxString& name = wxRearrangeListNameStr);
149
150 // get the underlying listbox
151 wxRearrangeList *GetList() const { return m_list; }
152
153 private:
154 // common part of all ctors
155 void Init();
156
157 // event handlers for the buttons
158 void OnUpdateButtonUI(wxUpdateUIEvent& event);
159 void OnButton(wxCommandEvent& event);
160
161
162 wxRearrangeList *m_list;
163
164
165 DECLARE_EVENT_TABLE()
166 DECLARE_NO_COPY_CLASS(wxRearrangeCtrl)
167 };
168
169 // ----------------------------------------------------------------------------
170 // wxRearrangeDialog: dialog containing a wxRearrangeCtrl
171 // ----------------------------------------------------------------------------
172
173 class WXDLLIMPEXP_CORE wxRearrangeDialog : public wxDialog
174 {
175 public:
176 // default ctor, use Create() later
177 wxRearrangeDialog() { Init(); }
178
179 // ctor for the dialog: message is shown inside the dialog itself, order
180 // and items are passed to wxRearrangeList used internally
181 wxRearrangeDialog(wxWindow *parent,
182 const wxString& message,
183 const wxString& title,
184 const wxArrayInt& order,
185 const wxArrayString& items,
186 const wxPoint& pos = wxDefaultPosition,
187 const wxString& name = wxRearrangeDialogNameStr)
188 {
189 Init();
190
191 Create(parent, message, title, order, items, pos, name);
192 }
193
194 bool Create(wxWindow *parent,
195 const wxString& message,
196 const wxString& title,
197 const wxArrayInt& order,
198 const wxArrayString& items,
199 const wxPoint& pos = wxDefaultPosition,
200 const wxString& name = wxRearrangeDialogNameStr);
201
202
203 // methods for the dialog customization
204
205 // add extra contents to the dialog below the wxRearrangeCtrl part: the
206 // given window (usually a wxPanel containing more control inside it) must
207 // have the dialog as its parent and will be inserted into it at the right
208 // place by this method
209 void AddExtraControls(wxWindow *win);
210
211 // return the wxRearrangeList control used by the dialog
212 wxRearrangeList *GetList() const;
213
214
215 // get the order of items after it was modified by the user
216 wxArrayInt GetOrder() const;
217
218 private:
219 // common part of all ctors
220 void Init() { m_ctrl = NULL; }
221
222 wxRearrangeCtrl *m_ctrl;
223
224 DECLARE_NO_COPY_CLASS(wxRearrangeDialog)
225 };
226
227 #endif // _WX_REARRANGECTRL_H_
228