]>
Commit | Line | Data |
---|---|---|
56873923 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/headerctrl.h | |
3 | // Purpose: wxHeaderCtrlBase class: interface of wxHeaderCtrl | |
4 | // Author: Vadim Zeitlin | |
5 | // Created: 2008-12-01 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org> | |
8 | // Licence: wxWindows licence | |
9 | /////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef _WX_HEADERCTRL_H_ | |
12 | #define _WX_HEADERCTRL_H_ | |
13 | ||
14 | #include "wx/control.h" | |
15 | ||
702f5349 | 16 | #include "wx/dynarray.h" |
e2bfe673 VZ |
17 | #include "wx/vector.h" |
18 | ||
56873923 VZ |
19 | #include "wx/headercol.h" |
20 | ||
21 | // notice that the classes in this header are defined in the core library even | |
22 | // although currently they're only used by wxGrid which is in wxAdv because we | |
23 | // plan to use it in wxListCtrl which is in core too in the future | |
3bfaa5a7 | 24 | class WXDLLIMPEXP_FWD_CORE wxHeaderCtrlEvent; |
56873923 VZ |
25 | |
26 | // ---------------------------------------------------------------------------- | |
27 | // constants | |
28 | // ---------------------------------------------------------------------------- | |
29 | ||
30 | enum | |
31 | { | |
32 | // allow column drag and drop | |
33 | wxHD_DRAGDROP = 0x0001, | |
34 | ||
35 | // style used by default when creating the control | |
36 | wxHD_DEFAULT_STYLE = wxHD_DRAGDROP | |
37 | }; | |
38 | ||
39 | extern WXDLLIMPEXP_DATA_CORE(const char) wxHeaderCtrlNameStr[]; | |
40 | ||
56873923 VZ |
41 | // ---------------------------------------------------------------------------- |
42 | // wxHeaderCtrlBase defines the interface of a header control | |
43 | // ---------------------------------------------------------------------------- | |
44 | ||
45 | class WXDLLIMPEXP_CORE wxHeaderCtrlBase : public wxControl | |
46 | { | |
47 | public: | |
48 | /* | |
49 | Derived classes must provide default ctor as well as a ctor and | |
50 | Create() function with the following signatures: | |
51 | ||
52 | wxHeaderCtrl(wxWindow *parent, | |
53 | wxWindowID winid = wxID_ANY, | |
54 | const wxPoint& pos = wxDefaultPosition, | |
55 | const wxSize& size = wxDefaultSize, | |
e2bfe673 | 56 | long style = wxHD_DEFAULT_STYLE, |
56873923 VZ |
57 | const wxString& name = wxHeaderCtrlNameStr); |
58 | ||
59 | bool Create(wxWindow *parent, | |
60 | wxWindowID winid = wxID_ANY, | |
61 | const wxPoint& pos = wxDefaultPosition, | |
62 | const wxSize& size = wxDefaultSize, | |
e2bfe673 | 63 | long style = wxHD_DEFAULT_STYLE, |
56873923 VZ |
64 | const wxString& name = wxHeaderCtrlNameStr); |
65 | */ | |
66 | ||
e2bfe673 VZ |
67 | // column-related methods |
68 | // ---------------------- | |
69 | ||
70 | // set the number of columns in the control | |
71 | // | |
72 | // this also calls UpdateColumn() for all columns | |
73 | void SetColumnCount(unsigned int count) { DoSetCount(count); } | |
56873923 | 74 | |
e2bfe673 | 75 | // return the number of columns in the control as set by SetColumnCount() |
56873923 VZ |
76 | unsigned int GetColumnCount() const { return DoGetCount(); } |
77 | ||
78 | // return whether the control has any columns | |
e2bfe673 VZ |
79 | bool IsEmpty() const { return DoGetCount() == 0; } |
80 | ||
81 | // update the column with the given index | |
82 | void UpdateColumn(unsigned int idx) | |
83 | { | |
84 | wxCHECK_RET( idx < GetColumnCount(), "invalid column index" ); | |
85 | ||
86 | DoUpdate(idx); | |
87 | } | |
88 | ||
702f5349 VZ |
89 | // set the columns order: the array defines the column index which appears |
90 | // the given position, it must have GetColumnCount() elements and contain | |
91 | // all indices exactly once | |
92 | void SetColumnsOrder(const wxArrayInt& order); | |
93 | wxArrayInt GetColumnsOrder() const; | |
94 | ||
95 | // get the index of the column at the given display position | |
96 | unsigned int GetColumnAt(unsigned int pos) const; | |
97 | ||
98 | // get the position at which this column is currently displayed | |
99 | unsigned int GetColumnPos(unsigned int idx) const; | |
100 | ||
e2bfe673 VZ |
101 | |
102 | // implementation only from now on | |
103 | // ------------------------------- | |
104 | ||
105 | // the user doesn't need to TAB to this control | |
106 | virtual bool AcceptsFocusFromKeyboard() const { return false; } | |
107 | ||
108 | // this method is only overridden in order to synchronize the control with | |
109 | // the main window when it is scrolled, the derived class must implement | |
110 | // DoScrollHorz() | |
111 | virtual void ScrollWindow(int dx, int dy, const wxRect *rect = NULL); | |
112 | ||
113 | protected: | |
114 | // this method must be implemented by the derived classes to return the | |
115 | // information for the given column | |
dcb6cbec | 116 | virtual wxHeaderColumn& GetColumn(unsigned int idx) = 0; |
e2bfe673 | 117 | |
3bfaa5a7 VZ |
118 | // this method is called from the default EVT_HEADER_SEPARATOR_DCLICK |
119 | // handler to update the fitting column width of the given column, it | |
120 | // should return true if the width was really updated | |
121 | virtual bool UpdateColumnWidthToFit(unsigned int WXUNUSED(idx), | |
122 | int WXUNUSED(widthTitle)) | |
123 | { | |
124 | return false; | |
125 | } | |
126 | ||
e2bfe673 VZ |
127 | private: |
128 | // methods implementing our public API and defined in platform-specific | |
129 | // implementations | |
130 | virtual void DoSetCount(unsigned int count) = 0; | |
131 | virtual unsigned int DoGetCount() const = 0; | |
132 | virtual void DoUpdate(unsigned int idx) = 0; | |
133 | ||
134 | virtual void DoScrollHorz(int dx) = 0; | |
135 | ||
702f5349 VZ |
136 | virtual void DoSetColumnsOrder(const wxArrayInt& order) = 0; |
137 | virtual wxArrayInt DoGetColumnsOrder() const = 0; | |
138 | ||
e2bfe673 VZ |
139 | // this window doesn't look nice with the border so don't use it by default |
140 | virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } | |
3bfaa5a7 VZ |
141 | |
142 | // event handlers | |
143 | void OnSeparatorDClick(wxHeaderCtrlEvent& event); | |
144 | ||
145 | DECLARE_EVENT_TABLE() | |
e2bfe673 VZ |
146 | }; |
147 | ||
148 | // ---------------------------------------------------------------------------- | |
149 | // wxHeaderCtrl: port-specific header control implementation, notice that this | |
150 | // is still an ABC which is meant to be used as part of another | |
151 | // control, see wxHeaderCtrlSimple for a standalone version | |
152 | // ---------------------------------------------------------------------------- | |
153 | ||
70405f7e | 154 | #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) |
e2bfe673 VZ |
155 | #include "wx/msw/headerctrl.h" |
156 | #else | |
157 | #define wxHAS_GENERIC_HEADERCTRL | |
158 | #include "wx/generic/headerctrlg.h" | |
159 | #endif // platform | |
160 | ||
161 | // ---------------------------------------------------------------------------- | |
162 | // wxHeaderCtrlSimple: concrete header control which can be used standalone | |
163 | // ---------------------------------------------------------------------------- | |
164 | ||
165 | class WXDLLIMPEXP_CORE wxHeaderCtrlSimple : public wxHeaderCtrl | |
166 | { | |
167 | public: | |
168 | // control creation | |
169 | // ---------------- | |
170 | ||
171 | wxHeaderCtrlSimple() { Init(); } | |
172 | wxHeaderCtrlSimple(wxWindow *parent, | |
173 | wxWindowID winid = wxID_ANY, | |
174 | const wxPoint& pos = wxDefaultPosition, | |
175 | const wxSize& size = wxDefaultSize, | |
176 | long style = wxHD_DEFAULT_STYLE, | |
177 | const wxString& name = wxHeaderCtrlNameStr) | |
178 | { | |
179 | Init(); | |
180 | ||
181 | Create(parent, winid, pos, size, style, name); | |
182 | } | |
183 | ||
184 | // managing the columns | |
185 | // -------------------- | |
56873923 VZ |
186 | |
187 | // insert the column at the given position, using GetColumnCount() as | |
188 | // position appends it at the end | |
e2bfe673 | 189 | void InsertColumn(const wxHeaderColumnSimple& col, unsigned int idx) |
56873923 VZ |
190 | { |
191 | wxCHECK_RET( idx <= GetColumnCount(), "invalid column index" ); | |
192 | ||
193 | DoInsert(col, idx); | |
194 | } | |
195 | ||
196 | // append the column to the end of the control | |
e2bfe673 | 197 | void AppendColumn(const wxHeaderColumnSimple& col) |
56873923 VZ |
198 | { |
199 | DoInsert(col, GetColumnCount()); | |
200 | } | |
201 | ||
202 | // delete the column at the given index | |
203 | void DeleteColumn(unsigned int idx) | |
204 | { | |
205 | wxCHECK_RET( idx < GetColumnCount(), "invalid column index" ); | |
206 | ||
207 | DoDelete(idx); | |
208 | } | |
209 | ||
210 | // delete all the existing columns | |
211 | void DeleteAllColumns(); | |
212 | ||
213 | ||
214 | // modifying columns | |
215 | // ----------------- | |
216 | ||
a0009205 VZ |
217 | // show or hide the column, notice that even when a column is hidden we |
218 | // still account for it when using indices | |
219 | void ShowColumn(unsigned int idx, bool show = true) | |
220 | { | |
221 | wxCHECK_RET( idx < GetColumnCount(), "invalid column index" ); | |
222 | ||
223 | DoShowColumn(idx, show); | |
224 | } | |
225 | ||
226 | void HideColumn(unsigned int idx) | |
227 | { | |
228 | ShowColumn(idx, false); | |
229 | } | |
230 | ||
e2bfe673 VZ |
231 | // indicate that the column is used for sorting |
232 | void ShowSortIndicator(unsigned int idx, bool ascending = true) | |
56873923 | 233 | { |
a0009205 VZ |
234 | wxCHECK_RET( idx < GetColumnCount(), "invalid column index" ); |
235 | ||
e2bfe673 | 236 | DoShowSortIndicator(idx, ascending); |
56873923 VZ |
237 | } |
238 | ||
e2bfe673 VZ |
239 | // remove the sort indicator completely |
240 | void RemoveSortIndicator(); | |
56873923 | 241 | |
e2bfe673 | 242 | protected: |
e5a16353 | 243 | // implement/override base class methods |
dcb6cbec | 244 | virtual wxHeaderColumn& GetColumn(unsigned int idx); |
e5a16353 VZ |
245 | virtual bool UpdateColumnWidthToFit(unsigned int idx, int widthTitle); |
246 | ||
247 | // and define another one to be overridden in the derived classes: it | |
248 | // should return the best width for the given column contents or -1 if not | |
249 | // implemented, we use it to implement UpdateColumnWidthToFit() | |
250 | virtual int GetBestFittingWidth(unsigned int WXUNUSED(idx)) const | |
251 | { | |
252 | return -1; | |
253 | } | |
56873923 | 254 | |
e2bfe673 VZ |
255 | private: |
256 | // functions implementing our public API | |
257 | void DoInsert(const wxHeaderColumnSimple& col, unsigned int idx); | |
258 | void DoDelete(unsigned int idx); | |
259 | void DoShowColumn(unsigned int idx, bool show); | |
260 | void DoShowSortIndicator(unsigned int idx, bool ascending); | |
56873923 | 261 | |
e2bfe673 VZ |
262 | // common part of all ctors |
263 | void Init(); | |
56873923 | 264 | |
e2bfe673 VZ |
265 | // bring the column count in sync with the number of columns we store |
266 | void UpdateColumnCount() { SetColumnCount(m_cols.size()); } | |
d8fc3398 | 267 | |
a3e0efb6 | 268 | |
e2bfe673 VZ |
269 | // all our current columns |
270 | typedef wxVector<wxHeaderColumnSimple> Columns; | |
271 | Columns m_cols; | |
56873923 | 272 | |
e2bfe673 VZ |
273 | // the column currently used for sorting or -1 if none |
274 | unsigned int m_sortKey; | |
275 | ||
276 | ||
277 | DECLARE_NO_COPY_CLASS(wxHeaderCtrlSimple) | |
278 | }; | |
56873923 | 279 | |
fa3d4aaf VZ |
280 | // ---------------------------------------------------------------------------- |
281 | // wxHeaderCtrl events | |
282 | // ---------------------------------------------------------------------------- | |
283 | ||
284 | class WXDLLIMPEXP_CORE wxHeaderCtrlEvent : public wxNotifyEvent | |
285 | { | |
286 | public: | |
287 | wxHeaderCtrlEvent(wxEventType commandType = wxEVT_NULL, int winid = 0) | |
aef252d9 VZ |
288 | : wxNotifyEvent(commandType, winid), |
289 | m_col(-1), | |
290 | m_width(0), | |
565804f2 | 291 | m_order(static_cast<unsigned int>(-1)) |
fa3d4aaf VZ |
292 | { |
293 | } | |
294 | ||
295 | wxHeaderCtrlEvent(const wxHeaderCtrlEvent& event) | |
296 | : wxNotifyEvent(event), | |
aef252d9 VZ |
297 | m_col(event.m_col), |
298 | m_width(event.m_width), | |
565804f2 | 299 | m_order(event.m_order) |
fa3d4aaf VZ |
300 | { |
301 | } | |
302 | ||
aef252d9 | 303 | // the column which this event pertains to: valid for all header events |
fa3d4aaf VZ |
304 | int GetColumn() const { return m_col; } |
305 | void SetColumn(int col) { m_col = col; } | |
306 | ||
aef252d9 VZ |
307 | // the width of the column: valid for column resizing/dragging events only |
308 | int GetWidth() const { return m_width; } | |
309 | void SetWidth(int width) { m_width = width; } | |
310 | ||
702f5349 VZ |
311 | // the new position of the column: for end reorder events only |
312 | unsigned int GetNewOrder() const { return m_order; } | |
313 | void SetNewOrder(unsigned int order) { m_order = order; } | |
314 | ||
fa3d4aaf VZ |
315 | virtual wxEvent *Clone() const { return new wxHeaderCtrlEvent(*this); } |
316 | ||
317 | protected: | |
318 | // the column affected by the event | |
319 | int m_col; | |
320 | ||
aef252d9 VZ |
321 | // the current width for the dragging events |
322 | int m_width; | |
323 | ||
702f5349 VZ |
324 | // the new column position for end reorder event |
325 | unsigned int m_order; | |
326 | ||
fa3d4aaf VZ |
327 | private: |
328 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHeaderCtrlEvent) | |
329 | }; | |
330 | ||
331 | ||
056d5a89 VZ |
332 | extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_CLICK; |
333 | extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_RIGHT_CLICK; | |
334 | extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_MIDDLE_CLICK; | |
fa3d4aaf | 335 | |
056d5a89 VZ |
336 | extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_DCLICK; |
337 | extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_RIGHT_DCLICK; | |
338 | extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_MIDDLE_DCLICK; | |
fa3d4aaf | 339 | |
3bfaa5a7 VZ |
340 | extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_SEPARATOR_DCLICK; |
341 | ||
396825dc VZ |
342 | extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_BEGIN_RESIZE; |
343 | extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_RESIZING; | |
344 | extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_END_RESIZE; | |
aef252d9 | 345 | |
702f5349 VZ |
346 | extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_BEGIN_REORDER; |
347 | extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_END_REORDER; | |
348 | ||
565804f2 VZ |
349 | extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_DRAGGING_CANCELLED; |
350 | ||
fa3d4aaf VZ |
351 | typedef void (wxEvtHandler::*wxHeaderCtrlEventFunction)(wxHeaderCtrlEvent&); |
352 | ||
353 | #define wxHeaderCtrlEventHandler(func) \ | |
354 | (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent( \ | |
355 | wxHeaderCtrlEventFunction, &func) | |
356 | ||
357 | #define wx__DECLARE_HEADER_EVT(evt, id, fn) \ | |
358 | wx__DECLARE_EVT1(wxEVT_COMMAND_HEADER_ ## evt, id, wxHeaderCtrlEventHandler(fn)) | |
359 | ||
360 | #define EVT_HEADER_CLICK(id, fn) wx__DECLARE_HEADER_EVT(CLICK, id, fn) | |
361 | #define EVT_HEADER_RIGHT_CLICK(id, fn) wx__DECLARE_HEADER_EVT(RIGHT_CLICK, id, fn) | |
362 | #define EVT_HEADER_MIDDLE_CLICK(id, fn) wx__DECLARE_HEADER_EVT(MIDDLE_CLICK, id, fn) | |
363 | ||
364 | #define EVT_HEADER_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(DCLICK, id, fn) | |
365 | #define EVT_HEADER_RIGHT_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(RIGHT_DCLICK, id, fn) | |
366 | #define EVT_HEADER_MIDDLE_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(MIDDLE_DCLICK, id, fn) | |
367 | ||
3bfaa5a7 VZ |
368 | #define EVT_HEADER_SEPARATOR_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(SEPARATOR_DCLICK, id, fn) |
369 | ||
396825dc VZ |
370 | #define EVT_HEADER_BEGIN_RESIZE(id, fn) wx__DECLARE_HEADER_EVT(BEGIN_RESIZE, id, fn) |
371 | #define EVT_HEADER_RESIZING(id, fn) wx__DECLARE_HEADER_EVT(RESIZING, id, fn) | |
372 | #define EVT_HEADER_END_RESIZE(id, fn) wx__DECLARE_HEADER_EVT(END_RESIZE, id, fn) | |
aef252d9 | 373 | |
702f5349 VZ |
374 | #define EVT_HEADER_BEGIN_REORDER(id, fn) wx__DECLARE_HEADER_EVT(BEGIN_REORDER, id, fn) |
375 | #define EVT_HEADER_END_REORDER(id, fn) wx__DECLARE_HEADER_EVT(END_REORDER, id, fn) | |
376 | ||
565804f2 VZ |
377 | #define EVT_HEADER_DRAGGING_CANCELLED(id, fn) wx__DECLARE_HEADER_EVT(DRAGGING_CANCELLED, id, fn) |
378 | ||
56873923 | 379 | #endif // _WX_HEADERCTRL_H_ |