]> git.saurik.com Git - wxWidgets.git/blame - include/wx/headerctrl.h
disable UI updating during GetPopupMenuSelectionFromUser() execution to avoid unexpec...
[wxWidgets.git] / include / wx / headerctrl.h
CommitLineData
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 24class WXDLLIMPEXP_FWD_CORE wxHeaderCtrlEvent;
56873923
VZ
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
56873923
VZ
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,
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
4635abac 73 void SetColumnCount(unsigned int 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
da5a641f
VZ
101 // reset the columns order to the natural one
102 void ResetColumnsOrder();
103
1bb74626
VZ
104 // helper function used by the generic version of this control and also
105 // wxGrid: reshuffles the array of column indices indexed by positions
106 // (i.e. using the same convention as for SetColumnsOrder()) so that the
107 // column with the given index is found at the specified position
108 static void MoveColumnInOrderArray(wxArrayInt& order,
109 unsigned int idx,
110 unsigned int pos);
111
e2bfe673
VZ
112
113 // implementation only from now on
114 // -------------------------------
115
116 // the user doesn't need to TAB to this control
117 virtual bool AcceptsFocusFromKeyboard() const { return false; }
118
119 // this method is only overridden in order to synchronize the control with
120 // the main window when it is scrolled, the derived class must implement
121 // DoScrollHorz()
122 virtual void ScrollWindow(int dx, int dy, const wxRect *rect = NULL);
123
124protected:
125 // this method must be implemented by the derived classes to return the
126 // information for the given column
dcb6cbec 127 virtual wxHeaderColumn& GetColumn(unsigned int idx) = 0;
e2bfe673 128
3bfaa5a7
VZ
129 // this method is called from the default EVT_HEADER_SEPARATOR_DCLICK
130 // handler to update the fitting column width of the given column, it
131 // should return true if the width was really updated
132 virtual bool UpdateColumnWidthToFit(unsigned int WXUNUSED(idx),
133 int WXUNUSED(widthTitle))
134 {
135 return false;
136 }
137
4635abac
VZ
138 // this method can be overridden in the derived classes to do something
139 // (e.g. update/resize some internal data structures) before the number of
140 // columns in the control changes
141 virtual void OnColumnCountChanging(unsigned int WXUNUSED(count)) { }
142
f6655391
VZ
143
144 // helper function for the derived classes: update the array of column
145 // indices after the number of columns changed
146 void DoResizeColumnIndices(wxArrayInt& colIndices, unsigned int count);
147
e2bfe673
VZ
148private:
149 // methods implementing our public API and defined in platform-specific
150 // implementations
151 virtual void DoSetCount(unsigned int count) = 0;
152 virtual unsigned int DoGetCount() const = 0;
153 virtual void DoUpdate(unsigned int idx) = 0;
154
155 virtual void DoScrollHorz(int dx) = 0;
156
702f5349
VZ
157 virtual void DoSetColumnsOrder(const wxArrayInt& order) = 0;
158 virtual wxArrayInt DoGetColumnsOrder() const = 0;
159
e2bfe673
VZ
160 // this window doesn't look nice with the border so don't use it by default
161 virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
3bfaa5a7
VZ
162
163 // event handlers
164 void OnSeparatorDClick(wxHeaderCtrlEvent& event);
165
166 DECLARE_EVENT_TABLE()
e2bfe673
VZ
167};
168
169// ----------------------------------------------------------------------------
170// wxHeaderCtrl: port-specific header control implementation, notice that this
171// is still an ABC which is meant to be used as part of another
172// control, see wxHeaderCtrlSimple for a standalone version
173// ----------------------------------------------------------------------------
174
70405f7e 175#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
e2bfe673
VZ
176 #include "wx/msw/headerctrl.h"
177#else
178 #define wxHAS_GENERIC_HEADERCTRL
179 #include "wx/generic/headerctrlg.h"
180#endif // platform
181
182// ----------------------------------------------------------------------------
183// wxHeaderCtrlSimple: concrete header control which can be used standalone
184// ----------------------------------------------------------------------------
185
186class WXDLLIMPEXP_CORE wxHeaderCtrlSimple : public wxHeaderCtrl
187{
188public:
189 // control creation
190 // ----------------
191
192 wxHeaderCtrlSimple() { Init(); }
193 wxHeaderCtrlSimple(wxWindow *parent,
194 wxWindowID winid = wxID_ANY,
195 const wxPoint& pos = wxDefaultPosition,
196 const wxSize& size = wxDefaultSize,
197 long style = wxHD_DEFAULT_STYLE,
198 const wxString& name = wxHeaderCtrlNameStr)
199 {
200 Init();
201
202 Create(parent, winid, pos, size, style, name);
203 }
204
205 // managing the columns
206 // --------------------
56873923
VZ
207
208 // insert the column at the given position, using GetColumnCount() as
209 // position appends it at the end
e2bfe673 210 void InsertColumn(const wxHeaderColumnSimple& col, unsigned int idx)
56873923
VZ
211 {
212 wxCHECK_RET( idx <= GetColumnCount(), "invalid column index" );
213
214 DoInsert(col, idx);
215 }
216
217 // append the column to the end of the control
e2bfe673 218 void AppendColumn(const wxHeaderColumnSimple& col)
56873923
VZ
219 {
220 DoInsert(col, GetColumnCount());
221 }
222
223 // delete the column at the given index
224 void DeleteColumn(unsigned int idx)
225 {
226 wxCHECK_RET( idx < GetColumnCount(), "invalid column index" );
227
228 DoDelete(idx);
229 }
230
231 // delete all the existing columns
232 void DeleteAllColumns();
233
234
235 // modifying columns
236 // -----------------
237
a0009205
VZ
238 // show or hide the column, notice that even when a column is hidden we
239 // still account for it when using indices
240 void ShowColumn(unsigned int idx, bool show = true)
241 {
242 wxCHECK_RET( idx < GetColumnCount(), "invalid column index" );
243
244 DoShowColumn(idx, show);
245 }
246
247 void HideColumn(unsigned int idx)
248 {
249 ShowColumn(idx, false);
250 }
251
e2bfe673
VZ
252 // indicate that the column is used for sorting
253 void ShowSortIndicator(unsigned int idx, bool ascending = true)
56873923 254 {
a0009205
VZ
255 wxCHECK_RET( idx < GetColumnCount(), "invalid column index" );
256
e2bfe673 257 DoShowSortIndicator(idx, ascending);
56873923
VZ
258 }
259
e2bfe673
VZ
260 // remove the sort indicator completely
261 void RemoveSortIndicator();
56873923 262
e2bfe673 263protected:
e5a16353 264 // implement/override base class methods
dcb6cbec 265 virtual wxHeaderColumn& GetColumn(unsigned int idx);
e5a16353
VZ
266 virtual bool UpdateColumnWidthToFit(unsigned int idx, int widthTitle);
267
268 // and define another one to be overridden in the derived classes: it
269 // should return the best width for the given column contents or -1 if not
270 // implemented, we use it to implement UpdateColumnWidthToFit()
271 virtual int GetBestFittingWidth(unsigned int WXUNUSED(idx)) const
272 {
273 return -1;
274 }
56873923 275
e2bfe673
VZ
276private:
277 // functions implementing our public API
278 void DoInsert(const wxHeaderColumnSimple& col, unsigned int idx);
279 void DoDelete(unsigned int idx);
280 void DoShowColumn(unsigned int idx, bool show);
281 void DoShowSortIndicator(unsigned int idx, bool ascending);
56873923 282
e2bfe673
VZ
283 // common part of all ctors
284 void Init();
56873923 285
e2bfe673
VZ
286 // bring the column count in sync with the number of columns we store
287 void UpdateColumnCount() { SetColumnCount(m_cols.size()); }
d8fc3398 288
a3e0efb6 289
e2bfe673
VZ
290 // all our current columns
291 typedef wxVector<wxHeaderColumnSimple> Columns;
292 Columns m_cols;
56873923 293
e2bfe673
VZ
294 // the column currently used for sorting or -1 if none
295 unsigned int m_sortKey;
296
297
298 DECLARE_NO_COPY_CLASS(wxHeaderCtrlSimple)
299};
56873923 300
fa3d4aaf
VZ
301// ----------------------------------------------------------------------------
302// wxHeaderCtrl events
303// ----------------------------------------------------------------------------
304
305class WXDLLIMPEXP_CORE wxHeaderCtrlEvent : public wxNotifyEvent
306{
307public:
308 wxHeaderCtrlEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
aef252d9
VZ
309 : wxNotifyEvent(commandType, winid),
310 m_col(-1),
311 m_width(0),
565804f2 312 m_order(static_cast<unsigned int>(-1))
fa3d4aaf
VZ
313 {
314 }
315
316 wxHeaderCtrlEvent(const wxHeaderCtrlEvent& event)
317 : wxNotifyEvent(event),
aef252d9
VZ
318 m_col(event.m_col),
319 m_width(event.m_width),
565804f2 320 m_order(event.m_order)
fa3d4aaf
VZ
321 {
322 }
323
aef252d9 324 // the column which this event pertains to: valid for all header events
fa3d4aaf
VZ
325 int GetColumn() const { return m_col; }
326 void SetColumn(int col) { m_col = col; }
327
aef252d9
VZ
328 // the width of the column: valid for column resizing/dragging events only
329 int GetWidth() const { return m_width; }
330 void SetWidth(int width) { m_width = width; }
331
702f5349
VZ
332 // the new position of the column: for end reorder events only
333 unsigned int GetNewOrder() const { return m_order; }
334 void SetNewOrder(unsigned int order) { m_order = order; }
335
fa3d4aaf
VZ
336 virtual wxEvent *Clone() const { return new wxHeaderCtrlEvent(*this); }
337
338protected:
339 // the column affected by the event
340 int m_col;
341
aef252d9
VZ
342 // the current width for the dragging events
343 int m_width;
344
702f5349
VZ
345 // the new column position for end reorder event
346 unsigned int m_order;
347
fa3d4aaf
VZ
348private:
349 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHeaderCtrlEvent)
350};
351
352
056d5a89
VZ
353extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_CLICK;
354extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_RIGHT_CLICK;
355extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_MIDDLE_CLICK;
fa3d4aaf 356
056d5a89
VZ
357extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_DCLICK;
358extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_RIGHT_DCLICK;
359extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_MIDDLE_DCLICK;
fa3d4aaf 360
3bfaa5a7
VZ
361extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_SEPARATOR_DCLICK;
362
396825dc
VZ
363extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_BEGIN_RESIZE;
364extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_RESIZING;
365extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_END_RESIZE;
aef252d9 366
702f5349
VZ
367extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_BEGIN_REORDER;
368extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_END_REORDER;
369
565804f2
VZ
370extern WXDLLIMPEXP_CORE const wxEventType wxEVT_COMMAND_HEADER_DRAGGING_CANCELLED;
371
fa3d4aaf
VZ
372typedef void (wxEvtHandler::*wxHeaderCtrlEventFunction)(wxHeaderCtrlEvent&);
373
374#define wxHeaderCtrlEventHandler(func) \
375 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent( \
376 wxHeaderCtrlEventFunction, &func)
377
378#define wx__DECLARE_HEADER_EVT(evt, id, fn) \
379 wx__DECLARE_EVT1(wxEVT_COMMAND_HEADER_ ## evt, id, wxHeaderCtrlEventHandler(fn))
380
381#define EVT_HEADER_CLICK(id, fn) wx__DECLARE_HEADER_EVT(CLICK, id, fn)
382#define EVT_HEADER_RIGHT_CLICK(id, fn) wx__DECLARE_HEADER_EVT(RIGHT_CLICK, id, fn)
383#define EVT_HEADER_MIDDLE_CLICK(id, fn) wx__DECLARE_HEADER_EVT(MIDDLE_CLICK, id, fn)
384
385#define EVT_HEADER_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(DCLICK, id, fn)
386#define EVT_HEADER_RIGHT_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(RIGHT_DCLICK, id, fn)
387#define EVT_HEADER_MIDDLE_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(MIDDLE_DCLICK, id, fn)
388
3bfaa5a7
VZ
389#define EVT_HEADER_SEPARATOR_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(SEPARATOR_DCLICK, id, fn)
390
396825dc
VZ
391#define EVT_HEADER_BEGIN_RESIZE(id, fn) wx__DECLARE_HEADER_EVT(BEGIN_RESIZE, id, fn)
392#define EVT_HEADER_RESIZING(id, fn) wx__DECLARE_HEADER_EVT(RESIZING, id, fn)
393#define EVT_HEADER_END_RESIZE(id, fn) wx__DECLARE_HEADER_EVT(END_RESIZE, id, fn)
aef252d9 394
702f5349
VZ
395#define EVT_HEADER_BEGIN_REORDER(id, fn) wx__DECLARE_HEADER_EVT(BEGIN_REORDER, id, fn)
396#define EVT_HEADER_END_REORDER(id, fn) wx__DECLARE_HEADER_EVT(END_REORDER, id, fn)
397
565804f2
VZ
398#define EVT_HEADER_DRAGGING_CANCELLED(id, fn) wx__DECLARE_HEADER_EVT(DRAGGING_CANCELLED, id, fn)
399
56873923 400#endif // _WX_HEADERCTRL_H_