implement click events in wxHeaderCtrl
[wxWidgets.git] / interface / wx / headerctrl.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/headerctrl.h
3 // Purpose: 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 license
9 /////////////////////////////////////////////////////////////////////////////
10
11 /**
12 @class wxHeaderCtrl
13
14 wxHeaderCtrl is the control containing the column headings which is usually
15 used for display of tabular data.
16
17 It is used as part of wxGrid and (will be used in the near future) in
18 in wxDataViewCtrl and report view of wxListCtrl but can be also used
19 independently. In general this class is meant to be used as part of another
20 control which already stores the column information somewhere as it can't
21 be used directly: instead you need to inherit from it and implement the
22 GetColumn() method to provide column information. See wxHeaderCtrlSimple
23 for a concrete control class which can be used directly.
24
25 In addition to labeling the columns, the control has the following
26 features:
27 - Column reordering support, either by explicitly configuring the
28 columns order and calling SetColumnsOrder() or by dragging the
29 columns interactively (if enabled).
30 - Display of the icons in the header: this is often used to display a
31 sort or reverse sort indicator when the column header is clicked.
32
33 Notice that this control itself doesn't do anything other than displaying
34 the column headers. In particular column reordering and sorting must still
35 be supported by the associated control displaying the real data under the
36 header. Also remember to call ScrollWindow() method of the control if the
37 associated data display window has a horizontal scrollbar, otherwise the
38 headers wouldn't align with the data when the window is scrolled.
39
40 This control is implemented using the native header control under MSW
41 systems and a generic implementation elsewhere.
42
43 @beginStyleTable
44 @style{wxHD_DRAGDROP}
45 If this style is specified (it is by default), the user can reorder
46 the control columns by dragging them.
47 @style{wxHD_DEFAULT_STYLE}
48 Symbolic name for the default control style, currently equal to @c
49 wxHD_DRAGDROP.
50 @endStyleTable
51
52 @beginEventTable{wxHeaderCtrlEvent}
53 @event{EVT_HEADER_CLICK(id, func)}
54 A column heading was clicked.
55 @event{EVT_HEADER_RIGHT_CLICK(id, func)}
56 A column heading was right clicked.
57 @event{EVT_HEADER_MIDDLE_CLICK(id, func)}
58 A column heading was clicked with the middle mouse button.
59
60 @event{EVT_HEADER_DCLICK(id, func)}
61 A column heading was double clicked.
62 @event{EVT_HEADER_RIGHT_DCLICK(id, func)}
63 A column heading was right double clicked.
64 @event{EVT_HEADER_MIDDLE_DCLICK(id, func)}
65 A column heading was double clicked with the middle mouse button.
66 @endEventTable
67
68 @library{wxcore}
69 @category{ctrl}
70
71 @see wxGrid, wxListCtrl, wxDataViewCtrl
72
73
74 @section headerctrl_improvements Future Improvements
75
76 Some features are supported by the native MSW control and so could be
77 easily implemented in this version of wxHeaderCtrl but need to be
78 implemented in the generic version as well to be really useful. Please let
79 us know if you need or, better, plan to work on implementing, any of them:
80 - Displaying bitmaps instead of or together with the text
81 - Custom drawn headers
82 - Filters associated with a column.
83 */
84 class wxHeaderCtrl
85 {
86 public:
87 /**
88 Default constructor not creating the underlying window.
89
90 You must use Create() after creating the object using this constructor.
91 */
92 wxHeaderCtrl();
93
94 /**
95 Constructor creating the window.
96
97 Please see Create() for the parameters documentation.
98 */
99 wxHeaderCtrl(wxWindow *parent,
100 wxWindowID winid = wxID_ANY,
101 const wxPoint& pos = wxDefaultPosition,
102 const wxSize& size = wxDefaultSize,
103 long style = wxHD_DEFAULT_STYLE,
104 const wxString& name = wxHeaderCtrlNameStr);
105
106 /**
107 Create the header control window.
108
109 @param parent
110 The parent window. The header control should be typically
111 positioned along the top edge of this window.
112 @param winid
113 Id of the control or @c wxID_ANY if you don't care.
114 @param pos
115 The initial position of the control.
116 @param size
117 The initial size of the control (usually not very useful as this
118 control will typically be resized to have the same width as the
119 associated data display control).
120 @param style
121 The control style, @c wxHD_DEFAULT_STYLE by default. Notice that
122 the default style allows the user to reorder the columns by
123 dragging them and you need to explicitly turn this feature off by
124 using @code wxHD_DEFAULT_STYLE & ~wxHD_DRAGDROP @endcode if this is
125 undesirable.
126 @param name
127 The name of the control.
128 */
129 bool Create(wxWindow *parent,
130 wxWindowID winid = wxID_ANY,
131 const wxPoint& pos = wxDefaultPosition,
132 const wxSize& size = wxDefaultSize,
133 long style = wxHD_DEFAULT_STYLE,
134 const wxString& name = wxHeaderCtrlNameStr);
135
136 /**
137 Set the number of columns in the control.
138
139 The control will use GetColumn() to get information about all the
140 new columns and refresh itself, i.e. this method also has the same
141 effect as calling UpdateColumn() for all columns but it should only be
142 used if the number of columns really changed.
143 */
144 void SetColumnCount(unsigned int count);
145
146 /**
147 Return the number of columns in the control.
148
149 @return
150 Number of columns as previously set by SetColumnCount().
151
152 @see IsEmpty()
153 */
154 unsigned int GetColumnCount() const;
155
156 /**
157 Return whether the control has any columns.
158
159 @see GetColumnCount()
160 */
161 bool IsEmpty() const;
162
163 protected:
164 /**
165 Method to be implemented by the derived classes to return the
166 information for the given column.
167
168 @param idx
169 The column index, between 0 and the value last passed to
170 SetColumnCount().
171 */
172 virtual wxHeaderColumnBase& GetColumn(unsigned int idx) = 0;
173 };
174
175
176 /**
177 @class wxHeaderCtrlSimple
178
179 wxHeaderCtrlSimple is a concrete header control which can be used directly,
180 without inheriting from it as you need to do when using wxHeaderCtrl
181 itself.
182
183 When using it, you need to use simple AppendColumn(), InsertColumn() and
184 DeleteColumn() methods instead of setting the number of columns with
185 SetColumnCount() and returning the information about them from the
186 overridden GetColumn().
187
188 @library{wxcore}
189 @category{ctrl}
190
191 @see wxHeaderCtrl
192 */
193 class wxHeaderCtrlSimple : public wxHeaderCtrl
194 {
195 public:
196 /**
197 Default constructor not creating the underlying window.
198
199 You must use Create() after creating the object using this constructor.
200 */
201 wxHeaderCtrlSimple();
202
203 /**
204 Constructor creating the window.
205
206 Please see the base class wxHeaderCtrl::Create() method for the
207 parameters description.
208 */
209 wxHeaderCtrlSimple(wxWindow *parent,
210 wxWindowID winid = wxID_ANY,
211 const wxPoint& pos = wxDefaultPosition,
212 const wxSize& size = wxDefaultSize,
213 long style = wxHD_DEFAULT_STYLE,
214 const wxString& name = wxHeaderCtrlNameStr);
215
216 /**
217 Insert the column at the given position.
218
219 @param col
220 The column to insert. Notice that because of the existence of
221 implicit conversion from wxString to wxHeaderColumn a string
222 can be passed directly here.
223 @param idx
224 The position of the new column, from 0 to GetColumnCount(). Using
225 GetColumnCount() means to append the column to the end.
226
227 @see AppendColumn()
228 */
229 void InsertColumn(const wxHeaderColumn& col, unsigned int idx);
230
231 /**
232 Append the column to the end of the control.
233
234 @see InsertColumn()
235 */
236 void AppendColumn(const wxHeaderColumn& col);
237
238 /**
239 Delete the column at the given position.
240
241 @see InsertColumn(), AppendColumn()
242 */
243 void DeleteColumn(unsigned int idx);
244
245 /**
246 Show or hide the column.
247
248 Initially the column is shown by default or hidden if it was added with
249 wxCOL_HIDDEN flag set.
250
251 When a column is hidden, it doesn't appear at all on the screen but its
252 index is still taken into account when working with other columns. E.g.
253 if there are three columns 0, 1 and 2 and the column 1 is hidden you
254 still need to use index 2 to refer to the last visible column.
255
256 @param idx
257 The index of the column to show or hide, from 0 to GetColumnCount().
258 @param show
259 Indicates whether the column should be shown (default) or hidden.
260 */
261 void ShowColumn(unsigned int idx, bool show = true);
262
263 /**
264 Hide the column with the given index.
265
266 This is the same as calling @code ShowColumn(idx, false) @endcode.
267
268 @param idx
269 The index of the column to show or hide, from 0 to GetColumnCount().
270 */
271 void HideColumn(unsigned int idx);
272
273 /**
274 Update the column sort indicator.
275
276 The sort indicator, if shown, is typically an arrow pointing upwards or
277 downwards depending on whether the control contents is sorted in
278 ascending or descending order.
279
280 @param idx
281 The column to set the sort indicator for.
282 @param sortOrder
283 If @true or @false show the sort indicator corresponding to
284 ascending or descending sort order respectively, if @c -1 remove
285 the currently shown sort indicator.
286 */
287 virtual void ShowSortIndicator(unsigned int idx, int sortOrder);
288
289 /**
290 Remove the sort indicator from the given column.
291
292 This is the same as calling ShowSortIndicator() with @c -1 argument.
293
294 @param idx
295 The column to remove sort indicator for.
296 */
297 void RemoveSortIndicator(unsigned int idx);
298 };
299
300 /**
301 @class wxHeaderCtrlEvent
302
303 Event class representing the events generated by wxHeaderCtrl.
304
305 @library{wxcore}
306 @category{ctrl}
307
308 @see wxHeaderCtrl
309 */
310 class wxHeaderCtrlEvent : public wxNotifyEvent
311 {
312 public:
313 /**
314 Return the index of the column affected by this event.
315 */
316 int GetColumn() const;
317 };