]> git.saurik.com Git - wxWidgets.git/blame - include/wx/rearrangectrl.h
OSX adaptions
[wxWidgets.git] / include / wx / rearrangectrl.h
CommitLineData
af67f39d
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/rearrangectrl.h
3// Purpose: various controls for rearranging the items interactively
4// Author: Vadim Zeitlin
5// Created: 2008-12-15
af67f39d
VZ
6// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
7// Licence: wxWindows licence
8///////////////////////////////////////////////////////////////////////////////
9
10#ifndef _WX_REARRANGECTRL_H_
11#define _WX_REARRANGECTRL_H_
12
13#include "wx/checklst.h"
f0bb342f
VZ
14
15#if wxUSE_REARRANGECTRL
16
1d9301a9
VZ
17#include "wx/panel.h"
18#include "wx/dialog.h"
19
af67f39d
VZ
20#include "wx/arrstr.h"
21
22extern WXDLLIMPEXP_DATA_CORE(const char) wxRearrangeListNameStr[];
23extern WXDLLIMPEXP_DATA_CORE(const char) wxRearrangeDialogNameStr[];
24
25// ----------------------------------------------------------------------------
26// wxRearrangeList: a (check) list box allowing to move items around
27// ----------------------------------------------------------------------------
28
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
36// state).
37//
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.
42class WXDLLIMPEXP_CORE wxRearrangeList : public wxCheckListBox
43{
44public:
45 // ctors and such
46 // --------------
47
48 // default ctor, call Create() later
49 wxRearrangeList() { }
50
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
54 // description above
55 wxRearrangeList(wxWindow *parent,
56 wxWindowID id,
57 const wxPoint& pos,
58 const wxSize& size,
59 const wxArrayInt& order,
60 const wxArrayString& items,
61 long style = 0,
62 const wxValidator& validator = wxDefaultValidator,
63 const wxString& name = wxRearrangeListNameStr)
64 {
65 Create(parent, id, pos, size, order, items, style, validator, name);
66 }
67
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,
71 wxWindowID id,
72 const wxPoint& pos,
73 const wxSize& size,
74 const wxArrayInt& order,
75 const wxArrayString& items,
76 long style = 0,
77 const wxValidator& validator = wxDefaultValidator,
78 const wxString& name = wxRearrangeListNameStr);
79
80
81 // items order
82 // -----------
83
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; }
87
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;
92
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
95 bool MoveCurrentUp();
96 bool MoveCurrentDown();
97
98private:
99 // swap two items at the given positions in the listbox
100 void Swap(int pos1, int pos2);
101
102 // event handler for item checking/unchecking
103 void OnCheck(wxCommandEvent& event);
104
105
106 // the current order array
107 wxArrayInt m_order;
108
109
110 DECLARE_EVENT_TABLE()
c0c133e1 111 wxDECLARE_NO_COPY_CLASS(wxRearrangeList);
af67f39d
VZ
112};
113
114// ----------------------------------------------------------------------------
115// wxRearrangeCtrl: composite control containing a wxRearrangeList and buttons
116// ----------------------------------------------------------------------------
117
118class WXDLLIMPEXP_CORE wxRearrangeCtrl : public wxPanel
119{
120public:
121 // ctors/Create function are the same as for wxRearrangeList
122 wxRearrangeCtrl()
123 {
124 Init();
125 }
126
127 wxRearrangeCtrl(wxWindow *parent,
128 wxWindowID id,
129 const wxPoint& pos,
130 const wxSize& size,
131 const wxArrayInt& order,
132 const wxArrayString& items,
133 long style = 0,
134 const wxValidator& validator = wxDefaultValidator,
135 const wxString& name = wxRearrangeListNameStr)
136 {
137 Init();
138
139 Create(parent, id, pos, size, order, items, style, validator, name);
140 }
141
142 bool Create(wxWindow *parent,
143 wxWindowID id,
144 const wxPoint& pos,
145 const wxSize& size,
146 const wxArrayInt& order,
147 const wxArrayString& items,
148 long style = 0,
149 const wxValidator& validator = wxDefaultValidator,
150 const wxString& name = wxRearrangeListNameStr);
151
152 // get the underlying listbox
153 wxRearrangeList *GetList() const { return m_list; }
154
155private:
156 // common part of all ctors
157 void Init();
158
159 // event handlers for the buttons
160 void OnUpdateButtonUI(wxUpdateUIEvent& event);
161 void OnButton(wxCommandEvent& event);
162
163
164 wxRearrangeList *m_list;
165
166
167 DECLARE_EVENT_TABLE()
c0c133e1 168 wxDECLARE_NO_COPY_CLASS(wxRearrangeCtrl);
af67f39d
VZ
169};
170
171// ----------------------------------------------------------------------------
172// wxRearrangeDialog: dialog containing a wxRearrangeCtrl
173// ----------------------------------------------------------------------------
174
175class WXDLLIMPEXP_CORE wxRearrangeDialog : public wxDialog
176{
177public:
ae7e6cc9
VZ
178 // default ctor, use Create() later
179 wxRearrangeDialog() { Init(); }
180
af67f39d
VZ
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,
ae7e6cc9
VZ
189 const wxString& name = wxRearrangeDialogNameStr)
190 {
191 Init();
192
193 Create(parent, message, title, order, items, pos, name);
194 }
195
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);
af67f39d 203
5a5f305a
VZ
204
205 // methods for the dialog customization
206
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);
212
213 // return the wxRearrangeList control used by the dialog
214 wxRearrangeList *GetList() const;
215
216
af67f39d 217 // get the order of items after it was modified by the user
5a5f305a 218 wxArrayInt GetOrder() const;
af67f39d
VZ
219
220private:
ae7e6cc9
VZ
221 // common part of all ctors
222 void Init() { m_ctrl = NULL; }
223
af67f39d
VZ
224 wxRearrangeCtrl *m_ctrl;
225
c0c133e1 226 wxDECLARE_NO_COPY_CLASS(wxRearrangeDialog);
af67f39d
VZ
227};
228
f0bb342f
VZ
229#endif // wxUSE_REARRANGECTRL
230
af67f39d
VZ
231#endif // _WX_REARRANGECTRL_H_
232