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
23 class WXDLLIMPEXP_FWD_CORE wxHeaderCtrlEvent
;
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
31 // allow column drag and drop
32 wxHD_DRAGDROP
= 0x0001,
34 // style used by default when creating the control
35 wxHD_DEFAULT_STYLE
= wxHD_DRAGDROP
38 extern WXDLLIMPEXP_DATA_CORE(const char) wxHeaderCtrlNameStr
[];
40 // ----------------------------------------------------------------------------
41 // wxHeaderCtrlBase defines the interface of a header control
42 // ----------------------------------------------------------------------------
44 class WXDLLIMPEXP_CORE wxHeaderCtrlBase
: public wxControl
48 Derived classes must provide default ctor as well as a ctor and
49 Create() function with the following signatures:
51 wxHeaderCtrl(wxWindow *parent,
52 wxWindowID winid = wxID_ANY,
53 const wxPoint& pos = wxDefaultPosition,
54 const wxSize& size = wxDefaultSize,
55 long style = wxHD_DEFAULT_STYLE,
56 const wxString& name = wxHeaderCtrlNameStr);
58 bool Create(wxWindow *parent,
59 wxWindowID winid = wxID_ANY,
60 const wxPoint& pos = wxDefaultPosition,
61 const wxSize& size = wxDefaultSize,
62 long style = wxHD_DEFAULT_STYLE,
63 const wxString& name = wxHeaderCtrlNameStr);
66 // column-related methods
67 // ----------------------
69 // set the number of columns in the control
71 // this also calls UpdateColumn() for all columns
72 void SetColumnCount(unsigned int count
) { DoSetCount(count
); }
74 // return the number of columns in the control as set by SetColumnCount()
75 unsigned int GetColumnCount() const { return DoGetCount(); }
77 // return whether the control has any columns
78 bool IsEmpty() const { return DoGetCount() == 0; }
80 // update the column with the given index
81 void UpdateColumn(unsigned int idx
)
83 wxCHECK_RET( idx
< GetColumnCount(), "invalid column index" );
89 // implementation only from now on
90 // -------------------------------
92 // the user doesn't need to TAB to this control
93 virtual bool AcceptsFocusFromKeyboard() const { return false; }
95 // this method is only overridden in order to synchronize the control with
96 // the main window when it is scrolled, the derived class must implement
98 virtual void ScrollWindow(int dx
, int dy
, const wxRect
*rect
= NULL
);
101 // this method must be implemented by the derived classes to return the
102 // information for the given column
103 virtual wxHeaderColumnBase
& GetColumn(unsigned int idx
) = 0;
105 // this method is called from the default EVT_HEADER_SEPARATOR_DCLICK
106 // handler to update the fitting column width of the given column, it
107 // should return true if the width was really updated
108 virtual bool UpdateColumnWidthToFit(unsigned int WXUNUSED(idx
),
109 int WXUNUSED(widthTitle
))
115 // methods implementing our public API and defined in platform-specific
117 virtual void DoSetCount(unsigned int count
) = 0;
118 virtual unsigned int DoGetCount() const = 0;
119 virtual void DoUpdate(unsigned int idx
) = 0;
121 virtual void DoScrollHorz(int dx
) = 0;
123 // this window doesn't look nice with the border so don't use it by default
124 virtual wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
127 void OnSeparatorDClick(wxHeaderCtrlEvent
& event
);
129 DECLARE_EVENT_TABLE()
132 // ----------------------------------------------------------------------------
133 // wxHeaderCtrl: port-specific header control implementation, notice that this
134 // is still an ABC which is meant to be used as part of another
135 // control, see wxHeaderCtrlSimple for a standalone version
136 // ----------------------------------------------------------------------------
138 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
139 #include "wx/msw/headerctrl.h"
141 #define wxHAS_GENERIC_HEADERCTRL
142 #include "wx/generic/headerctrlg.h"
145 // ----------------------------------------------------------------------------
146 // wxHeaderCtrlSimple: concrete header control which can be used standalone
147 // ----------------------------------------------------------------------------
149 class WXDLLIMPEXP_CORE wxHeaderCtrlSimple
: public wxHeaderCtrl
155 wxHeaderCtrlSimple() { Init(); }
156 wxHeaderCtrlSimple(wxWindow
*parent
,
157 wxWindowID winid
= wxID_ANY
,
158 const wxPoint
& pos
= wxDefaultPosition
,
159 const wxSize
& size
= wxDefaultSize
,
160 long style
= wxHD_DEFAULT_STYLE
,
161 const wxString
& name
= wxHeaderCtrlNameStr
)
165 Create(parent
, winid
, pos
, size
, style
, name
);
168 // managing the columns
169 // --------------------
171 // insert the column at the given position, using GetColumnCount() as
172 // position appends it at the end
173 void InsertColumn(const wxHeaderColumnSimple
& col
, unsigned int idx
)
175 wxCHECK_RET( idx
<= GetColumnCount(), "invalid column index" );
180 // append the column to the end of the control
181 void AppendColumn(const wxHeaderColumnSimple
& col
)
183 DoInsert(col
, GetColumnCount());
186 // delete the column at the given index
187 void DeleteColumn(unsigned int idx
)
189 wxCHECK_RET( idx
< GetColumnCount(), "invalid column index" );
194 // delete all the existing columns
195 void DeleteAllColumns();
201 // show or hide the column, notice that even when a column is hidden we
202 // still account for it when using indices
203 void ShowColumn(unsigned int idx
, bool show
= true)
205 wxCHECK_RET( idx
< GetColumnCount(), "invalid column index" );
207 DoShowColumn(idx
, show
);
210 void HideColumn(unsigned int idx
)
212 ShowColumn(idx
, false);
215 // indicate that the column is used for sorting
216 void ShowSortIndicator(unsigned int idx
, bool ascending
= true)
218 wxCHECK_RET( idx
< GetColumnCount(), "invalid column index" );
220 DoShowSortIndicator(idx
, ascending
);
223 // remove the sort indicator completely
224 void RemoveSortIndicator();
227 virtual wxHeaderColumnBase
& GetColumn(unsigned int idx
);
230 // functions implementing our public API
231 void DoInsert(const wxHeaderColumnSimple
& col
, unsigned int idx
);
232 void DoDelete(unsigned int idx
);
233 void DoShowColumn(unsigned int idx
, bool show
);
234 void DoShowSortIndicator(unsigned int idx
, bool ascending
);
236 // common part of all ctors
239 // bring the column count in sync with the number of columns we store
240 void UpdateColumnCount() { SetColumnCount(m_cols
.size()); }
243 // all our current columns
244 typedef wxVector
<wxHeaderColumnSimple
> Columns
;
247 // the column currently used for sorting or -1 if none
248 unsigned int m_sortKey
;
251 DECLARE_NO_COPY_CLASS(wxHeaderCtrlSimple
)
254 // ----------------------------------------------------------------------------
255 // wxHeaderCtrl events
256 // ----------------------------------------------------------------------------
258 class WXDLLIMPEXP_CORE wxHeaderCtrlEvent
: public wxNotifyEvent
261 wxHeaderCtrlEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
262 : wxNotifyEvent(commandType
, winid
)
266 wxHeaderCtrlEvent(const wxHeaderCtrlEvent
& event
)
267 : wxNotifyEvent(event
),
272 int GetColumn() const { return m_col
; }
273 void SetColumn(int col
) { m_col
= col
; }
275 virtual wxEvent
*Clone() const { return new wxHeaderCtrlEvent(*this); }
278 // the column affected by the event
282 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHeaderCtrlEvent
)
286 extern WXDLLIMPEXP_CORE
const wxEventType wxEVT_COMMAND_HEADER_CLICK
;
287 extern WXDLLIMPEXP_CORE
const wxEventType wxEVT_COMMAND_HEADER_RIGHT_CLICK
;
288 extern WXDLLIMPEXP_CORE
const wxEventType wxEVT_COMMAND_HEADER_MIDDLE_CLICK
;
290 extern WXDLLIMPEXP_CORE
const wxEventType wxEVT_COMMAND_HEADER_DCLICK
;
291 extern WXDLLIMPEXP_CORE
const wxEventType wxEVT_COMMAND_HEADER_RIGHT_DCLICK
;
292 extern WXDLLIMPEXP_CORE
const wxEventType wxEVT_COMMAND_HEADER_MIDDLE_DCLICK
;
294 extern WXDLLIMPEXP_CORE
const wxEventType wxEVT_COMMAND_HEADER_SEPARATOR_DCLICK
;
296 typedef void (wxEvtHandler::*wxHeaderCtrlEventFunction
)(wxHeaderCtrlEvent
&);
298 #define wxHeaderCtrlEventHandler(func) \
299 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent( \
300 wxHeaderCtrlEventFunction, &func)
302 #define wx__DECLARE_HEADER_EVT(evt, id, fn) \
303 wx__DECLARE_EVT1(wxEVT_COMMAND_HEADER_ ## evt, id, wxHeaderCtrlEventHandler(fn))
305 #define EVT_HEADER_CLICK(id, fn) wx__DECLARE_HEADER_EVT(CLICK, id, fn)
306 #define EVT_HEADER_RIGHT_CLICK(id, fn) wx__DECLARE_HEADER_EVT(RIGHT_CLICK, id, fn)
307 #define EVT_HEADER_MIDDLE_CLICK(id, fn) wx__DECLARE_HEADER_EVT(MIDDLE_CLICK, id, fn)
309 #define EVT_HEADER_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(DCLICK, id, fn)
310 #define EVT_HEADER_RIGHT_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(RIGHT_DCLICK, id, fn)
311 #define EVT_HEADER_MIDDLE_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(MIDDLE_DCLICK, id, fn)
313 #define EVT_HEADER_SEPARATOR_DCLICK(id, fn) wx__DECLARE_HEADER_EVT(SEPARATOR_DCLICK, id, fn)
315 #endif // _WX_HEADERCTRL_H_