1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/headerctrl.h
3 // Purpose: wxHeaderCtrlBase class: interface of wxHeaderCtrl
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_HEADERCTRL_H_
12 #define _WX_HEADERCTRL_H_
14 #include "wx/control.h"
16 #include "wx/vector.h"
18 #include "wx/headercol.h"
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
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
30 // allow column drag and drop
31 wxHD_DRAGDROP
= 0x0001,
33 // style used by default when creating the control
34 wxHD_DEFAULT_STYLE
= wxHD_DRAGDROP
37 extern WXDLLIMPEXP_DATA_CORE(const char) wxHeaderCtrlNameStr
[];
39 // ----------------------------------------------------------------------------
40 // wxHeaderCtrlBase defines the interface of a header control
41 // ----------------------------------------------------------------------------
43 class WXDLLIMPEXP_CORE wxHeaderCtrlBase
: public wxControl
47 Derived classes must provide default ctor as well as a ctor and
48 Create() function with the following signatures:
50 wxHeaderCtrl(wxWindow *parent,
51 wxWindowID winid = wxID_ANY,
52 const wxPoint& pos = wxDefaultPosition,
53 const wxSize& size = wxDefaultSize,
54 long style = wxHD_DEFAULT_STYLE,
55 const wxString& name = wxHeaderCtrlNameStr);
57 bool Create(wxWindow *parent,
58 wxWindowID winid = wxID_ANY,
59 const wxPoint& pos = wxDefaultPosition,
60 const wxSize& size = wxDefaultSize,
61 long style = wxHD_DEFAULT_STYLE,
62 const wxString& name = wxHeaderCtrlNameStr);
65 // column-related methods
66 // ----------------------
68 // set the number of columns in the control
70 // this also calls UpdateColumn() for all columns
71 void SetColumnCount(unsigned int count
) { DoSetCount(count
); }
73 // return the number of columns in the control as set by SetColumnCount()
74 unsigned int GetColumnCount() const { return DoGetCount(); }
76 // return whether the control has any columns
77 bool IsEmpty() const { return DoGetCount() == 0; }
79 // update the column with the given index
80 void UpdateColumn(unsigned int idx
)
82 wxCHECK_RET( idx
< GetColumnCount(), "invalid column index" );
88 // implementation only from now on
89 // -------------------------------
91 // the user doesn't need to TAB to this control
92 virtual bool AcceptsFocusFromKeyboard() const { return false; }
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
97 virtual void ScrollWindow(int dx
, int dy
, const wxRect
*rect
= NULL
);
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;
105 // methods implementing our public API and defined in platform-specific
107 virtual void DoSetCount(unsigned int count
) = 0;
108 virtual unsigned int DoGetCount() const = 0;
109 virtual void DoUpdate(unsigned int idx
) = 0;
111 virtual void DoScrollHorz(int dx
) = 0;
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
; }
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 // ----------------------------------------------------------------------------
123 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
124 #include "wx/msw/headerctrl.h"
126 #define wxHAS_GENERIC_HEADERCTRL
127 #include "wx/generic/headerctrlg.h"
130 // ----------------------------------------------------------------------------
131 // wxHeaderCtrlSimple: concrete header control which can be used standalone
132 // ----------------------------------------------------------------------------
134 class WXDLLIMPEXP_CORE wxHeaderCtrlSimple
: public wxHeaderCtrl
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
)
150 Create(parent
, winid
, pos
, size
, style
, name
);
153 // managing the columns
154 // --------------------
156 // insert the column at the given position, using GetColumnCount() as
157 // position appends it at the end
158 void InsertColumn(const wxHeaderColumnSimple
& col
, unsigned int idx
)
160 wxCHECK_RET( idx
<= GetColumnCount(), "invalid column index" );
165 // append the column to the end of the control
166 void AppendColumn(const wxHeaderColumnSimple
& col
)
168 DoInsert(col
, GetColumnCount());
171 // delete the column at the given index
172 void DeleteColumn(unsigned int idx
)
174 wxCHECK_RET( idx
< GetColumnCount(), "invalid column index" );
179 // delete all the existing columns
180 void DeleteAllColumns();
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)
190 wxCHECK_RET( idx
< GetColumnCount(), "invalid column index" );
192 DoShowColumn(idx
, show
);
195 void HideColumn(unsigned int idx
)
197 ShowColumn(idx
, false);
200 // indicate that the column is used for sorting
201 void ShowSortIndicator(unsigned int idx
, bool ascending
= true)
203 wxCHECK_RET( idx
< GetColumnCount(), "invalid column index" );
205 DoShowSortIndicator(idx
, ascending
);
208 // remove the sort indicator completely
209 void RemoveSortIndicator();
212 virtual wxHeaderColumnBase
& GetColumn(unsigned int idx
);
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
);
221 // common part of all ctors
224 // bring the column count in sync with the number of columns we store
225 void UpdateColumnCount() { SetColumnCount(m_cols
.size()); }
228 // all our current columns
229 typedef wxVector
<wxHeaderColumnSimple
> Columns
;
232 // the column currently used for sorting or -1 if none
233 unsigned int m_sortKey
;
236 DECLARE_NO_COPY_CLASS(wxHeaderCtrlSimple
)
239 // ----------------------------------------------------------------------------
240 // wxHeaderCtrl events
241 // ----------------------------------------------------------------------------
243 class WXDLLIMPEXP_CORE wxHeaderCtrlEvent
: public wxNotifyEvent
246 wxHeaderCtrlEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
247 : wxNotifyEvent(commandType
, winid
)
251 wxHeaderCtrlEvent(const wxHeaderCtrlEvent
& event
)
252 : wxNotifyEvent(event
),
257 int GetColumn() const { return m_col
; }
258 void SetColumn(int col
) { m_col
= col
; }
260 virtual wxEvent
*Clone() const { return new wxHeaderCtrlEvent(*this); }
263 // the column affected by the event
267 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHeaderCtrlEvent
)
271 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_COMMAND_HEADER_CLICK
;
272 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_COMMAND_HEADER_RIGHT_CLICK
;
273 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_COMMAND_HEADER_MIDDLE_CLICK
;
275 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_COMMAND_HEADER_DCLICK
;
276 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_COMMAND_HEADER_RIGHT_DCLICK
;
277 extern WXDLLIMPEXP_ADV
const wxEventType wxEVT_COMMAND_HEADER_MIDDLE_DCLICK
;
279 typedef void (wxEvtHandler::*wxHeaderCtrlEventFunction
)(wxHeaderCtrlEvent
&);
281 #define wxHeaderCtrlEventHandler(func) \
282 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent( \
283 wxHeaderCtrlEventFunction, &func)
285 #define wx__DECLARE_HEADER_EVT(evt, id, fn) \
286 wx__DECLARE_EVT1(wxEVT_COMMAND_HEADER_ ## evt, id, wxHeaderCtrlEventHandler(fn))
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)
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)
296 #endif // _WX_HEADERCTRL_H_