]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/rearrangectrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/rearrangectrl.h
3 // Purpose: interface of wxRearrangeList
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 @class wxRearrangeList
13 A listbox-like control allowing the user to rearrange the items and to
14 enable or disable them.
16 This class allows to change the order of the items shown in it as well as
17 to check or uncheck them individually. The data structure used to allow
18 this is the order array which contains the items indices indexed by their
19 position with an added twist that the unchecked items are represented by
20 the bitwise complement of the corresponding index (for any architecture
21 using two's complement for negative numbers representation (i.e. just about
22 any at all) this means that a checked item N is represented by -N-1 in
23 unchecked state). In practice this means that you must apply the C bitwise
24 complement operator when constructing the order array, e.g.
27 order.push_back(0); // checked item #0
28 order.push_back(~1); // unchecked item #1
31 So, for example, the array order [1 -3 0] used in conjunction with the
32 items array ["first", "second", "third"] means that the items order is
33 "second", "third", "first" and the "third" item is unchecked while the
34 other two are checked.
36 This convention is used both for the order argument of the control ctor or
37 Create() and for the array returned from GetCurrentOrder().
39 Usually this control will be used together with other controls allowing to
40 move the items around in it interactively. The simplest possible solution
41 is to use wxRearrangeCtrl which combines it with two standard buttons to
42 move the current item up or down.
49 class wxRearrangeList
: public wxCheckListBox
55 Create() must be called later to effectively create the control.
60 Constructor really creating the control.
62 Please see Create() for the parameters description.
64 wxRearrangeList(wxWindow
*parent
,
68 const wxArrayInt
& order
,
69 const wxArrayString
& items
,
71 const wxValidator
& validator
= wxDefaultValidator
,
72 const wxString
& name
= wxRearrangeListNameStr
);
75 Effectively creates the window for an object created using the default
78 This function is very similar to wxCheckListBox::Create() except that
79 it has an additional parameter specifying the initial order of the
80 items. Please see the class documentation for the explanation of the
81 conventions used by the @a order argument.
84 The parent window, must be non-@NULL.
86 The window identifier.
88 The initial window position.
90 The initial window size.
92 Array specifying the initial order of the items in @a items array.
94 The items to display in the list.
96 The control style, there are no special styles for this class but
97 the base class styles can be used here.
99 Optional window validator.
101 Optional window name.
103 bool Create(wxWindow
*parent
,
107 const wxArrayInt
& order
,
108 const wxArrayString
& items
,
110 const wxValidator
& validator
= wxDefaultValidator
,
111 const wxString
& name
= wxRearrangeListNameStr
);
115 Return the current order of the items.
117 The order may be different from the one passed to the constructor if
118 MoveCurrentUp() or MoveCurrentDown() were called.
120 const wxArrayInt
& GetCurrentOrder() const;
123 Return @true if the currently selected item can be moved up.
125 This function is useful for EVT_UPDATE_UI handler for the standard "Up"
126 button often used together with this control and wxRearrangeCtrl uses
130 @true if the currently selected item can be moved up in the
131 listbox, @false if there is no selection or the current item is the
134 @see CanMoveCurrentDown()
136 bool CanMoveCurrentUp() const;
139 Return @true if the currently selected item can be moved down.
141 @see CanMoveCurrentUp()
143 bool CanMoveCurrentDown() const;
146 Move the currently selected item one position above.
148 This method is useful to implement the standard "Up" button behaviour
149 and wxRearrangeCtrl uses it for this.
152 @true if the item was moved or @false if this couldn't be done.
154 @see MoveCurrentDown()
156 bool MoveCurrentUp();
159 Move the currently selected item one position below.
163 bool MoveCurrentDown();
168 @class wxRearrangeCtrl
170 A composite control containing a wxRearrangeList and the buttons allowing
171 to move the items in it.
173 This control is in fact a panel containing the wxRearrangeList control and
174 the "Up" and "Down" buttons to move the currently selected item up or down.
175 It is used as the main part of a wxRearrangeDialog.
182 class wxRearrangeCtrl
: public wxPanel
188 Create() must be called later to effectively create the control.
193 Constructor really creating the control.
195 Please see Create() for the parameters description.
197 wxRearrangeCtrl(wxWindow
*parent
,
201 const wxArrayInt
& order
,
202 const wxArrayString
& items
,
204 const wxValidator
& validator
= wxDefaultValidator
,
205 const wxString
& name
= wxRearrangeListNameStr
);
208 Effectively creates the window for an object created using the default
211 The parameters of this method are the same as for
212 wxRearrangeList::Create().
214 bool Create(wxWindow
*parent
,
218 const wxArrayInt
& order
,
219 const wxArrayString
& items
,
221 const wxValidator
& validator
= wxDefaultValidator
,
222 const wxString
& name
= wxRearrangeListNameStr
);
225 Return the listbox which is the main part of this control.
227 wxRearrangeList
*GetList() const;
231 @class wxRearrangeDialog
233 A dialog allowing the user to rearrange the specified items.
235 This dialog can be used to allow the user to modify the order of the items
236 and to enable or disable them individually. For example:
239 items.push_back("meat");
240 items.push_back("fish");
241 items.push_back("fruits");
242 items.push_back("beer");
249 wxRearrangeDialog dlg(NULL,
250 "You can also uncheck the items you don't like "
252 "Sort the items in order of preference",
254 if ( dlg.ShowModal() == wxID_OK ) {
255 order = dlg.GetOrder();
256 for ( size_t n = 0; n < order.size(); n++ ) {
257 if ( order[n] >= 0 ) {
258 wxLogMessage("Your most preferred item is \"%s\"",
271 class wxRearrangeDialog
: public wxDialog
277 Create() must be called later to effectively create the control.
282 Constructor creating the dialog.
284 Please see Create() for the parameters description.
286 wxRearrangeDialog(wxWindow
*parent
,
287 const wxString
& message
,
288 const wxString
& title
,
289 const wxArrayInt
& order
,
290 const wxArrayString
& items
,
291 const wxPoint
& pos
= wxDefaultPosition
,
292 const wxString
& name
= wxRearrangeDialogNameStr
);
295 Effectively creates the dialog for an object created using the default
299 The dialog parent, possibly @NULL.
301 The message shown inside the dialog itself, above the items list.
303 The title of the dialog.
305 The initial order of the items in the convention used by
308 The items to show in the dialog.
310 Optional dialog position.
312 Optional dialog name.
314 @true if the dialog was successfully created or @false if creation
317 bool Create(wxWindow
*parent
,
318 const wxString
& message
,
319 const wxString
& title
,
320 const wxArrayInt
& order
,
321 const wxArrayString
& items
,
322 const wxPoint
& pos
= wxDefaultPosition
,
323 const wxString
& name
= wxRearrangeDialogNameStr
);
326 Customize the dialog by adding extra controls to it.
328 This function adds the given @a win to the dialog, putting it just
329 below the part occupied by wxRearrangeCtrl. It must be called after
330 creating the dialog and you will typically need to process the events
331 generated by the extra controls for them to do something useful.
335 class MyRearrangeDialog : public wxRearrangeDialog
338 MyRearrangeDialog(wxWindow *parent, ...)
339 : wxRearrangeDialog(parent, ...)
341 wxPanel *panel = new wxPanel(this);
342 wxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
343 sizer->Add(new wxStaticText(panel, wxID_ANY,
344 "Column width in pixels:"));
345 sizer->Add(new wxTextCtrl(panel, wxID_ANY, ""));
346 panel->SetSizer(sizer);
347 AddExtraControls(panel);
350 ... code to update the text control with the currently selected
351 item width and to react to its changes omitted ...
355 See also the complete example of a custom rearrange dialog in the
359 The window containing the extra controls. It must have this dialog
362 void AddExtraControls(wxWindow
*win
);
365 Return the list control used by the dialog.
367 @see wxRearrangeCtrl::GetList()
369 wxRearrangeList
*GetList() const;
372 Return the array describing the order of items after it was modified by
375 Please notice that the array will contain negative items if any items
376 were unchecked. See wxRearrangeList for more information about the
377 convention used for this array.
379 wxArrayInt
GetOrder() const;