]> git.saurik.com Git - wxWidgets.git/blame - include/wx/headerctrl.h
undo accidental change to always use generic version in r57178
[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
e2bfe673
VZ
16#include "wx/vector.h"
17
56873923
VZ
18#include "wx/headercol.h"
19
20// notice that the classes in this header are defined in the core library even
21// although currently they're only used by wxGrid which is in wxAdv because we
22// plan to use it in wxListCtrl which is in core too in the future
23
24// ----------------------------------------------------------------------------
25// constants
26// ----------------------------------------------------------------------------
27
28enum
29{
30 // allow column drag and drop
31 wxHD_DRAGDROP = 0x0001,
32
33 // style used by default when creating the control
34 wxHD_DEFAULT_STYLE = wxHD_DRAGDROP
35};
36
37extern WXDLLIMPEXP_DATA_CORE(const char) wxHeaderCtrlNameStr[];
38
56873923
VZ
39// ----------------------------------------------------------------------------
40// wxHeaderCtrlBase defines the interface of a header control
41// ----------------------------------------------------------------------------
42
43class WXDLLIMPEXP_CORE wxHeaderCtrlBase : public wxControl
44{
45public:
46 /*
47 Derived classes must provide default ctor as well as a ctor and
48 Create() function with the following signatures:
49
50 wxHeaderCtrl(wxWindow *parent,
51 wxWindowID winid = wxID_ANY,
52 const wxPoint& pos = wxDefaultPosition,
53 const wxSize& size = wxDefaultSize,
e2bfe673 54 long style = wxHD_DEFAULT_STYLE,
56873923
VZ
55 const wxString& name = wxHeaderCtrlNameStr);
56
57 bool Create(wxWindow *parent,
58 wxWindowID winid = wxID_ANY,
59 const wxPoint& pos = wxDefaultPosition,
60 const wxSize& size = wxDefaultSize,
e2bfe673 61 long style = wxHD_DEFAULT_STYLE,
56873923
VZ
62 const wxString& name = wxHeaderCtrlNameStr);
63 */
64
e2bfe673
VZ
65 // column-related methods
66 // ----------------------
67
68 // set the number of columns in the control
69 //
70 // this also calls UpdateColumn() for all columns
71 void SetColumnCount(unsigned int count) { DoSetCount(count); }
56873923 72
e2bfe673 73 // return the number of columns in the control as set by SetColumnCount()
56873923
VZ
74 unsigned int GetColumnCount() const { return DoGetCount(); }
75
76 // return whether the control has any columns
e2bfe673
VZ
77 bool IsEmpty() const { return DoGetCount() == 0; }
78
79 // update the column with the given index
80 void UpdateColumn(unsigned int idx)
81 {
82 wxCHECK_RET( idx < GetColumnCount(), "invalid column index" );
83
84 DoUpdate(idx);
85 }
86
87
88 // implementation only from now on
89 // -------------------------------
90
91 // the user doesn't need to TAB to this control
92 virtual bool AcceptsFocusFromKeyboard() const { return false; }
93
94 // this method is only overridden in order to synchronize the control with
95 // the main window when it is scrolled, the derived class must implement
96 // DoScrollHorz()
97 virtual void ScrollWindow(int dx, int dy, const wxRect *rect = NULL);
98
99protected:
100 // this method must be implemented by the derived classes to return the
101 // information for the given column
102 virtual wxHeaderColumnBase& GetColumn(unsigned int idx) = 0;
103
104private:
105 // methods implementing our public API and defined in platform-specific
106 // implementations
107 virtual void DoSetCount(unsigned int count) = 0;
108 virtual unsigned int DoGetCount() const = 0;
109 virtual void DoUpdate(unsigned int idx) = 0;
110
111 virtual void DoScrollHorz(int dx) = 0;
112
113 // this window doesn't look nice with the border so don't use it by default
114 virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
115};
116
117// ----------------------------------------------------------------------------
118// wxHeaderCtrl: port-specific header control implementation, notice that this
119// is still an ABC which is meant to be used as part of another
120// control, see wxHeaderCtrlSimple for a standalone version
121// ----------------------------------------------------------------------------
122
0c02fc77 123#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
e2bfe673
VZ
124 #include "wx/msw/headerctrl.h"
125#else
126 #define wxHAS_GENERIC_HEADERCTRL
127 #include "wx/generic/headerctrlg.h"
128#endif // platform
129
130// ----------------------------------------------------------------------------
131// wxHeaderCtrlSimple: concrete header control which can be used standalone
132// ----------------------------------------------------------------------------
133
134class WXDLLIMPEXP_CORE wxHeaderCtrlSimple : public wxHeaderCtrl
135{
136public:
137 // control creation
138 // ----------------
139
140 wxHeaderCtrlSimple() { Init(); }
141 wxHeaderCtrlSimple(wxWindow *parent,
142 wxWindowID winid = wxID_ANY,
143 const wxPoint& pos = wxDefaultPosition,
144 const wxSize& size = wxDefaultSize,
145 long style = wxHD_DEFAULT_STYLE,
146 const wxString& name = wxHeaderCtrlNameStr)
147 {
148 Init();
149
150 Create(parent, winid, pos, size, style, name);
151 }
152
153 // managing the columns
154 // --------------------
56873923
VZ
155
156 // insert the column at the given position, using GetColumnCount() as
157 // position appends it at the end
e2bfe673 158 void InsertColumn(const wxHeaderColumnSimple& col, unsigned int idx)
56873923
VZ
159 {
160 wxCHECK_RET( idx <= GetColumnCount(), "invalid column index" );
161
162 DoInsert(col, idx);
163 }
164
165 // append the column to the end of the control
e2bfe673 166 void AppendColumn(const wxHeaderColumnSimple& col)
56873923
VZ
167 {
168 DoInsert(col, GetColumnCount());
169 }
170
171 // delete the column at the given index
172 void DeleteColumn(unsigned int idx)
173 {
174 wxCHECK_RET( idx < GetColumnCount(), "invalid column index" );
175
176 DoDelete(idx);
177 }
178
179 // delete all the existing columns
180 void DeleteAllColumns();
181
182
183 // modifying columns
184 // -----------------
185
a0009205
VZ
186 // show or hide the column, notice that even when a column is hidden we
187 // still account for it when using indices
188 void ShowColumn(unsigned int idx, bool show = true)
189 {
190 wxCHECK_RET( idx < GetColumnCount(), "invalid column index" );
191
192 DoShowColumn(idx, show);
193 }
194
195 void HideColumn(unsigned int idx)
196 {
197 ShowColumn(idx, false);
198 }
199
e2bfe673
VZ
200 // indicate that the column is used for sorting
201 void ShowSortIndicator(unsigned int idx, bool ascending = true)
56873923 202 {
a0009205
VZ
203 wxCHECK_RET( idx < GetColumnCount(), "invalid column index" );
204
e2bfe673 205 DoShowSortIndicator(idx, ascending);
56873923
VZ
206 }
207
e2bfe673
VZ
208 // remove the sort indicator completely
209 void RemoveSortIndicator();
56873923 210
e2bfe673
VZ
211protected:
212 virtual wxHeaderColumnBase& GetColumn(unsigned int idx);
56873923 213
e2bfe673
VZ
214private:
215 // functions implementing our public API
216 void DoInsert(const wxHeaderColumnSimple& col, unsigned int idx);
217 void DoDelete(unsigned int idx);
218 void DoShowColumn(unsigned int idx, bool show);
219 void DoShowSortIndicator(unsigned int idx, bool ascending);
56873923 220
e2bfe673
VZ
221 // common part of all ctors
222 void Init();
56873923 223
e2bfe673
VZ
224 // bring the column count in sync with the number of columns we store
225 void UpdateColumnCount() { SetColumnCount(m_cols.size()); }
d8fc3398 226
a3e0efb6 227
e2bfe673
VZ
228 // all our current columns
229 typedef wxVector<wxHeaderColumnSimple> Columns;
230 Columns m_cols;
56873923 231
e2bfe673
VZ
232 // the column currently used for sorting or -1 if none
233 unsigned int m_sortKey;
234
235
236 DECLARE_NO_COPY_CLASS(wxHeaderCtrlSimple)
237};
56873923 238
fa3d4aaf
VZ
239// ----------------------------------------------------------------------------
240// wxHeaderCtrl events
241// ----------------------------------------------------------------------------
242
243class WXDLLIMPEXP_CORE wxHeaderCtrlEvent : public wxNotifyEvent
244{
245public:
246 wxHeaderCtrlEvent(wxEventType commandType = wxEVT_NULL, int winid = 0)
247 : wxNotifyEvent(commandType, winid)
248 {
249 }
250
251 wxHeaderCtrlEvent(const wxHeaderCtrlEvent& event)
252 : wxNotifyEvent(event),
253 m_col(event.m_col)
254 {
255 }
256
257 int GetColumn() const { return m_col; }
258 void SetColumn(int col) { m_col = col; }
259
260 virtual wxEvent *Clone() const { return new wxHeaderCtrlEvent(*this); }
261
262protected:
263 // the column affected by the event
264 int m_col;
265
266private:
267 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHeaderCtrlEvent)
268};
269
270
271extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_HEADER_CLICK;
272extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_HEADER_RIGHT_CLICK;
273extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_HEADER_MIDDLE_CLICK;
274
275extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_HEADER_DCLICK;
276extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_HEADER_RIGHT_DCLICK;
277extern WXDLLIMPEXP_ADV const wxEventType wxEVT_COMMAND_HEADER_MIDDLE_DCLICK;
278
279typedef void (wxEvtHandler::*wxHeaderCtrlEventFunction)(wxHeaderCtrlEvent&);
280
281#define wxHeaderCtrlEventHandler(func) \
282 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent( \
283 wxHeaderCtrlEventFunction, &func)
284
285#define wx__DECLARE_HEADER_EVT(evt, id, fn) \
286 wx__DECLARE_EVT1(wxEVT_COMMAND_HEADER_ ## evt, id, wxHeaderCtrlEventHandler(fn))
287
288#define EVT_HEADER_CLICK(id, fn) wx__DECLARE_HEADER_EVT(CLICK, id, fn)
289#define EVT_HEADER_RIGHT_CLICK(id, fn) wx__DECLARE_HEADER_EVT(RIGHT_CLICK, id, fn)
290#define EVT_HEADER_MIDDLE_CLICK(id, fn) wx__DECLARE_HEADER_EVT(MIDDLE_CLICK, id, fn)
291
292#define EVT_HEADER_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(DCLICK, id, fn)
293#define EVT_HEADER_RIGHT_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(RIGHT_DCLICK, id, fn)
294#define EVT_HEADER_MIDDLE_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(MIDDLE_DCLICK, id, fn)
295
56873923 296#endif // _WX_HEADERCTRL_H_