]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/headerctrl.h
added wxGrid::UseNativeColHeader() (column reordering doesn't work yet); more wxGrid...
[wxWidgets.git] / include / wx / headerctrl.h
... / ...
CommitLineData
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
16#include "wx/dynarray.h"
17#include "wx/vector.h"
18
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
24class WXDLLIMPEXP_FWD_CORE wxHeaderCtrlEvent;
25
26// ----------------------------------------------------------------------------
27// constants
28// ----------------------------------------------------------------------------
29
30enum
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
39extern WXDLLIMPEXP_DATA_CORE(const char) wxHeaderCtrlNameStr[];
40
41// ----------------------------------------------------------------------------
42// wxHeaderCtrlBase defines the interface of a header control
43// ----------------------------------------------------------------------------
44
45class WXDLLIMPEXP_CORE wxHeaderCtrlBase : public wxControl
46{
47public:
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,
56 long style = wxHD_DEFAULT_STYLE,
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,
63 long style = wxHD_DEFAULT_STYLE,
64 const wxString& name = wxHeaderCtrlNameStr);
65 */
66
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);
74
75 // return the number of columns in the control as set by SetColumnCount()
76 unsigned int GetColumnCount() const { return DoGetCount(); }
77
78 // return whether the control has any columns
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
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
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
113protected:
114 // this method must be implemented by the derived classes to return the
115 // information for the given column
116 virtual wxHeaderColumn& GetColumn(unsigned int idx) = 0;
117
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
127 // this method can be overridden in the derived classes to do something
128 // (e.g. update/resize some internal data structures) before the number of
129 // columns in the control changes
130 virtual void OnColumnCountChanging(unsigned int WXUNUSED(count)) { }
131
132private:
133 // methods implementing our public API and defined in platform-specific
134 // implementations
135 virtual void DoSetCount(unsigned int count) = 0;
136 virtual unsigned int DoGetCount() const = 0;
137 virtual void DoUpdate(unsigned int idx) = 0;
138
139 virtual void DoScrollHorz(int dx) = 0;
140
141 virtual void DoSetColumnsOrder(const wxArrayInt& order) = 0;
142 virtual wxArrayInt DoGetColumnsOrder() const = 0;
143
144 // this window doesn't look nice with the border so don't use it by default
145 virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
146
147 // event handlers
148 void OnSeparatorDClick(wxHeaderCtrlEvent& event);
149
150 DECLARE_EVENT_TABLE()
151};
152
153// ----------------------------------------------------------------------------
154// wxHeaderCtrl: port-specific header control implementation, notice that this
155// is still an ABC which is meant to be used as part of another
156// control, see wxHeaderCtrlSimple for a standalone version
157// ----------------------------------------------------------------------------
158
159#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
160 #include "wx/msw/headerctrl.h"
161#else
162 #define wxHAS_GENERIC_HEADERCTRL
163 #include "wx/generic/headerctrlg.h"
164#endif // platform
165
166// ----------------------------------------------------------------------------
167// wxHeaderCtrlSimple: concrete header control which can be used standalone
168// ----------------------------------------------------------------------------
169
170class WXDLLIMPEXP_CORE wxHeaderCtrlSimple : public wxHeaderCtrl
171{
172public:
173 // control creation
174 // ----------------
175
176 wxHeaderCtrlSimple() { Init(); }
177 wxHeaderCtrlSimple(wxWindow *parent,
178 wxWindowID winid = wxID_ANY,
179 const wxPoint& pos = wxDefaultPosition,
180 const wxSize& size = wxDefaultSize,
181 long style = wxHD_DEFAULT_STYLE,
182 const wxString& name = wxHeaderCtrlNameStr)
183 {
184 Init();
185
186 Create(parent, winid, pos, size, style, name);
187 }
188
189 // managing the columns
190 // --------------------
191
192 // insert the column at the given position, using GetColumnCount() as
193 // position appends it at the end
194 void InsertColumn(const wxHeaderColumnSimple& col, unsigned int idx)
195 {
196 wxCHECK_RET( idx <= GetColumnCount(), "invalid column index" );
197
198 DoInsert(col, idx);
199 }
200
201 // append the column to the end of the control
202 void AppendColumn(const wxHeaderColumnSimple& col)
203 {
204 DoInsert(col, GetColumnCount());
205 }
206
207 // delete the column at the given index
208 void DeleteColumn(unsigned int idx)
209 {
210 wxCHECK_RET( idx < GetColumnCount(), "invalid column index" );
211
212 DoDelete(idx);
213 }
214
215 // delete all the existing columns
216 void DeleteAllColumns();
217
218
219 // modifying columns
220 // -----------------
221
222 // show or hide the column, notice that even when a column is hidden we
223 // still account for it when using indices
224 void ShowColumn(unsigned int idx, bool show = true)
225 {
226 wxCHECK_RET( idx < GetColumnCount(), "invalid column index" );
227
228 DoShowColumn(idx, show);
229 }
230
231 void HideColumn(unsigned int idx)
232 {
233 ShowColumn(idx, false);
234 }
235
236 // indicate that the column is used for sorting
237 void ShowSortIndicator(unsigned int idx, bool ascending = true)
238 {
239 wxCHECK_RET( idx < GetColumnCount(), "invalid column index" );
240
241 DoShowSortIndicator(idx, ascending);
242 }
243
244 // remove the sort indicator completely
245 void RemoveSortIndicator();
246
247protected:
248 // implement/override base class methods
249 virtual wxHeaderColumn& GetColumn(unsigned int idx);
250 virtual bool UpdateColumnWidthToFit(unsigned int idx, int widthTitle);
251
252 // and define another one to be overridden in the derived classes: it
253 // should return the best width for the given column contents or -1 if not
254 // implemented, we use it to implement UpdateColumnWidthToFit()
255 virtual int GetBestFittingWidth(unsigned int WXUNUSED(idx)) const
256 {
257 return -1;
258 }
259
260private:
261 // functions implementing our public API
262 void DoInsert(const wxHeaderColumnSimple& col, unsigned int idx);
263 void DoDelete(unsigned int idx);
264 void DoShowColumn(unsigned int idx, bool show);
265 void DoShowSortIndicator(unsigned int idx, bool ascending);
266
267 // common part of all ctors
268 void Init();
269
270 // bring the column count in sync with the number of columns we store
271 void UpdateColumnCount() { SetColumnCount(m_cols.size()); }
272
273
274 // all our current columns
275 typedef wxVector<wxHeaderColumnSimple> Columns;
276 Columns m_cols;
277
278 // the column currently used for sorting or -1 if none
279 unsigned int m_sortKey;
280
281
282 DECLARE_NO_COPY_CLASS(wxHeaderCtrlSimple)
283};
284
285// ----------------------------------------------------------------------------
286// wxHeaderCtrl events
287// ----------------------------------------------------------------------------
288
289class WXDLLIMPEXP_CORE wxHeaderCtrlEvent : public wxNotifyEvent
290{
291public:
292 wxHeaderCtrlEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
293 : wxNotifyEvent(commandType, winid),
294 m_col(-1),
295 m_width(0),
296 m_order(static_cast<unsigned int>(-1))
297 {
298 }
299
300 wxHeaderCtrlEvent(const wxHeaderCtrlEvent& event)
301 : wxNotifyEvent(event),
302 m_col(event.m_col),
303 m_width(event.m_width),
304 m_order(event.m_order)
305 {
306 }
307
308 // the column which this event pertains to: valid for all header events
309 int GetColumn() const { return m_col; }
310 void SetColumn(int col) { m_col = col; }
311
312 // the width of the column: valid for column resizing/dragging events only
313 int GetWidth() const { return m_width; }
314 void SetWidth(int width) { m_width = width; }
315
316 // the new position of the column: for end reorder events only
317 unsigned int GetNewOrder() const { return m_order; }
318 void SetNewOrder(unsigned int order) { m_order = order; }
319
320 virtual wxEvent *Clone() const { return new wxHeaderCtrlEvent(*this); }
321
322protected:
323 // the column affected by the event
324 int m_col;
325
326 // the current width for the dragging events
327 int m_width;
328
329 // the new column position for end reorder event
330 unsigned int m_order;
331
332private:
333 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHeaderCtrlEvent)
334};
335
336
337extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_CLICK;
338extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_RIGHT_CLICK;
339extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_MIDDLE_CLICK;
340
341extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_DCLICK;
342extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_RIGHT_DCLICK;
343extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_MIDDLE_DCLICK;
344
345extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_SEPARATOR_DCLICK;
346
347extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_BEGIN_RESIZE;
348extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_RESIZING;
349extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_END_RESIZE;
350
351extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_BEGIN_REORDER;
352extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_END_REORDER;
353
354extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_DRAGGING_CANCELLED;
355
356typedef void (wxEvtHandler::*wxHeaderCtrlEventFunction)(wxHeaderCtrlEvent&);
357
358#define wxHeaderCtrlEventHandler(func) \
359 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent( \
360 wxHeaderCtrlEventFunction, &func)
361
362#define wx__DECLARE_HEADER_EVT(evt, id, fn) \
363 wx__DECLARE_EVT1(wxEVT_COMMAND_HEADER_ ## evt, id, wxHeaderCtrlEventHandler(fn))
364
365#define EVT_HEADER_CLICK(id, fn) wx__DECLARE_HEADER_EVT(CLICK, id, fn)
366#define EVT_HEADER_RIGHT_CLICK(id, fn) wx__DECLARE_HEADER_EVT(RIGHT_CLICK, id, fn)
367#define EVT_HEADER_MIDDLE_CLICK(id, fn) wx__DECLARE_HEADER_EVT(MIDDLE_CLICK, id, fn)
368
369#define EVT_HEADER_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(DCLICK, id, fn)
370#define EVT_HEADER_RIGHT_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(RIGHT_DCLICK, id, fn)
371#define EVT_HEADER_MIDDLE_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(MIDDLE_DCLICK, id, fn)
372
373#define EVT_HEADER_SEPARATOR_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(SEPARATOR_DCLICK, id, fn)
374
375#define EVT_HEADER_BEGIN_RESIZE(id, fn) wx__DECLARE_HEADER_EVT(BEGIN_RESIZE, id, fn)
376#define EVT_HEADER_RESIZING(id, fn) wx__DECLARE_HEADER_EVT(RESIZING, id, fn)
377#define EVT_HEADER_END_RESIZE(id, fn) wx__DECLARE_HEADER_EVT(END_RESIZE, id, fn)
378
379#define EVT_HEADER_BEGIN_REORDER(id, fn) wx__DECLARE_HEADER_EVT(BEGIN_REORDER, id, fn)
380#define EVT_HEADER_END_REORDER(id, fn) wx__DECLARE_HEADER_EVT(END_REORDER, id, fn)
381
382#define EVT_HEADER_DRAGGING_CANCELLED(id, fn) wx__DECLARE_HEADER_EVT(DRAGGING_CANCELLED, id, fn)
383
384#endif // _WX_HEADERCTRL_H_