]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/headerctrl.h
don't access inexistent column in wxDataViewTreeCtrl::OnSize() (this bug also probabl...
[wxWidgets.git] / interface / wx / headerctrl.h
CommitLineData
56873923
VZ
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
e2bfe673
VZ
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.
56873923
VZ
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
f24f6579
VZ
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.
56873923
VZ
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
fa3d4aaf
VZ
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.
3bfaa5a7
VZ
66
67 @event{EVT_HEADER_SEPARATOR_DCLICK(id, func)}
68 Separator to the right of the specified column was double clicked
69 (this action is commonly used to resize the column to fit its
70 contents width and the control provides UpdateColumnWidthToFit() method
71 to make implementing this easier).
56873923
VZ
72 @endEventTable
73
74 @library{wxcore}
75 @category{ctrl}
76
77 @see wxGrid, wxListCtrl, wxDataViewCtrl
78
79
80 @section headerctrl_improvements Future Improvements
81
82 Some features are supported by the native MSW control and so could be
83 easily implemented in this version of wxHeaderCtrl but need to be
84 implemented in the generic version as well to be really useful. Please let
85 us know if you need or, better, plan to work on implementing, any of them:
86 - Displaying bitmaps instead of or together with the text
87 - Custom drawn headers
88 - Filters associated with a column.
89*/
90class wxHeaderCtrl
91{
92public:
93 /**
94 Default constructor not creating the underlying window.
95
96 You must use Create() after creating the object using this constructor.
97 */
98 wxHeaderCtrl();
99
100 /**
101 Constructor creating the window.
102
103 Please see Create() for the parameters documentation.
104 */
105 wxHeaderCtrl(wxWindow *parent,
106 wxWindowID winid = wxID_ANY,
107 const wxPoint& pos = wxDefaultPosition,
108 const wxSize& size = wxDefaultSize,
e2bfe673 109 long style = wxHD_DEFAULT_STYLE,
56873923
VZ
110 const wxString& name = wxHeaderCtrlNameStr);
111
112 /**
113 Create the header control window.
114
115 @param parent
116 The parent window. The header control should be typically
117 positioned along the top edge of this window.
118 @param winid
119 Id of the control or @c wxID_ANY if you don't care.
120 @param pos
121 The initial position of the control.
122 @param size
123 The initial size of the control (usually not very useful as this
124 control will typically be resized to have the same width as the
125 associated data display control).
126 @param style
127 The control style, @c wxHD_DEFAULT_STYLE by default. Notice that
128 the default style allows the user to reorder the columns by
129 dragging them and you need to explicitly turn this feature off by
130 using @code wxHD_DEFAULT_STYLE & ~wxHD_DRAGDROP @endcode if this is
131 undesirable.
132 @param name
133 The name of the control.
134 */
135 bool Create(wxWindow *parent,
136 wxWindowID winid = wxID_ANY,
137 const wxPoint& pos = wxDefaultPosition,
138 const wxSize& size = wxDefaultSize,
e2bfe673 139 long style = wxHD_DEFAULT_STYLE,
56873923
VZ
140 const wxString& name = wxHeaderCtrlNameStr);
141
e2bfe673
VZ
142 /**
143 Set the number of columns in the control.
144
145 The control will use GetColumn() to get information about all the
146 new columns and refresh itself, i.e. this method also has the same
147 effect as calling UpdateColumn() for all columns but it should only be
148 used if the number of columns really changed.
149 */
150 void SetColumnCount(unsigned int count);
151
56873923
VZ
152 /**
153 Return the number of columns in the control.
154
e2bfe673
VZ
155 @return
156 Number of columns as previously set by SetColumnCount().
157
56873923
VZ
158 @see IsEmpty()
159 */
160 unsigned int GetColumnCount() const;
161
162 /**
163 Return whether the control has any columns.
164
165 @see GetColumnCount()
166 */
167 bool IsEmpty() const;
168
e2bfe673
VZ
169protected:
170 /**
171 Method to be implemented by the derived classes to return the
172 information for the given column.
173
174 @param idx
175 The column index, between 0 and the value last passed to
176 SetColumnCount().
177 */
178 virtual wxHeaderColumnBase& GetColumn(unsigned int idx) = 0;
3bfaa5a7
VZ
179
180 /**
181 Method which may be implemented by the derived classes to allow double
182 clicking the column separator to resize the column to fit its contents.
183
184 When a separator is double clicked, the default handler of
185 EVT_HEADER_SEPARATOR_DCLICK event calls this function and refreshes the
186 column if it returns @true so to implement the resizing of the column
187 to fit its width on header double click you need to implement this
188 method using logic similar to this example:
189 @code
190 class MyHeaderCtrl : public wxHeaderColumnBase
191 {
192 public:
193 ...
194
195 void SetWidth(int width) { m_width = width; }
196 virtual int GetWidth() const { return m_width; }
197
198 private:
199 int m_width;
200 };
201
202 class MyHeaderCtrl : public wxHeaderCtrl
203 {
204 public:
205 protected:
206 virtual wxHeaderColumnBase& GetColumn(unsigned int idx)
207 {
208 return m_cols[idx];
209 }
210
211 virtual bool UpdateColumnWidthToFit(unsigned int idx, int widthTitle)
212 {
213 int widthContents = ... compute minimal width for column idx ...
214 m_cols[idx].SetWidth(wxMax(widthContents, widthTitle));
215 return true;
216 }
217
218 wxVector<MyHeaderColumn> m_cols;
219 };
220 @endcode
221
222 Base class version simply returns @false.
223
224 @param width
225 Contains minimal width needed to display the column header itself
226 and will usually be used as a starting point for the fitting width
227 calculation.
228 @return
229 @true to indicate that the column was resized, i.e. GetColumn() now
230 returns the new width value, and so must be refreshed or @false
231 meaning that the control didn't reach to the separator double click.
232 */
233 virtual bool UpdateColumnWidthToFit(unsigned int idx, int widthTitle);
e2bfe673
VZ
234};
235
236
237/**
238 @class wxHeaderCtrlSimple
239
240 wxHeaderCtrlSimple is a concrete header control which can be used directly,
241 without inheriting from it as you need to do when using wxHeaderCtrl
242 itself.
243
244 When using it, you need to use simple AppendColumn(), InsertColumn() and
245 DeleteColumn() methods instead of setting the number of columns with
246 SetColumnCount() and returning the information about them from the
247 overridden GetColumn().
248
249 @library{wxcore}
250 @category{ctrl}
251
252 @see wxHeaderCtrl
253*/
254class wxHeaderCtrlSimple : public wxHeaderCtrl
255{
256public:
257 /**
258 Default constructor not creating the underlying window.
259
260 You must use Create() after creating the object using this constructor.
261 */
262 wxHeaderCtrlSimple();
263
264 /**
265 Constructor creating the window.
266
267 Please see the base class wxHeaderCtrl::Create() method for the
268 parameters description.
269 */
270 wxHeaderCtrlSimple(wxWindow *parent,
271 wxWindowID winid = wxID_ANY,
272 const wxPoint& pos = wxDefaultPosition,
273 const wxSize& size = wxDefaultSize,
274 long style = wxHD_DEFAULT_STYLE,
275 const wxString& name = wxHeaderCtrlNameStr);
276
56873923
VZ
277 /**
278 Insert the column at the given position.
279
280 @param col
281 The column to insert. Notice that because of the existence of
282 implicit conversion from wxString to wxHeaderColumn a string
283 can be passed directly here.
284 @param idx
285 The position of the new column, from 0 to GetColumnCount(). Using
286 GetColumnCount() means to append the column to the end.
287
288 @see AppendColumn()
289 */
290 void InsertColumn(const wxHeaderColumn& col, unsigned int idx);
291
292 /**
293 Append the column to the end of the control.
294
295 @see InsertColumn()
296 */
297 void AppendColumn(const wxHeaderColumn& col);
298
299 /**
300 Delete the column at the given position.
301
302 @see InsertColumn(), AppendColumn()
303 */
304 void DeleteColumn(unsigned int idx);
305
a0009205
VZ
306 /**
307 Show or hide the column.
308
309 Initially the column is shown by default or hidden if it was added with
310 wxCOL_HIDDEN flag set.
311
312 When a column is hidden, it doesn't appear at all on the screen but its
313 index is still taken into account when working with other columns. E.g.
314 if there are three columns 0, 1 and 2 and the column 1 is hidden you
315 still need to use index 2 to refer to the last visible column.
316
317 @param idx
318 The index of the column to show or hide, from 0 to GetColumnCount().
319 @param show
320 Indicates whether the column should be shown (default) or hidden.
321 */
322 void ShowColumn(unsigned int idx, bool show = true);
323
324 /**
325 Hide the column with the given index.
326
327 This is the same as calling @code ShowColumn(idx, false) @endcode.
328
329 @param idx
330 The index of the column to show or hide, from 0 to GetColumnCount().
331 */
332 void HideColumn(unsigned int idx);
333
56873923
VZ
334 /**
335 Update the column sort indicator.
336
337 The sort indicator, if shown, is typically an arrow pointing upwards or
338 downwards depending on whether the control contents is sorted in
339 ascending or descending order.
340
341 @param idx
342 The column to set the sort indicator for.
343 @param sortOrder
344 If @true or @false show the sort indicator corresponding to
345 ascending or descending sort order respectively, if @c -1 remove
346 the currently shown sort indicator.
347 */
348 virtual void ShowSortIndicator(unsigned int idx, int sortOrder);
349
350 /**
351 Remove the sort indicator from the given column.
352
353 This is the same as calling ShowSortIndicator() with @c -1 argument.
354
355 @param idx
356 The column to remove sort indicator for.
357 */
358 void RemoveSortIndicator(unsigned int idx);
e5a16353
VZ
359
360protected:
361 /**
362 This function can be overridden in the classes deriving from this
363 control instead of overriding UpdateColumnWidthToFit().
364
365 To implement automatic column resizing to fit its contents width when
366 the column divider is double clicked, you need to simply return the
367 fitting width for the given column @a idx from this method, the control
368 will automatically use the biggest value between the one returned from
369 here and the one needed for the display of the column title itself.
370
371 The base class version returns -1 indicating that this function is not
372 implemented.
373 */
374 virtual int GetBestFittingWidth(unsigned int idx) const;
56873923 375};
fa3d4aaf
VZ
376
377/**
378 @class wxHeaderCtrlEvent
379
380 Event class representing the events generated by wxHeaderCtrl.
381
382 @library{wxcore}
383 @category{ctrl}
384
385 @see wxHeaderCtrl
386*/
387class wxHeaderCtrlEvent : public wxNotifyEvent
388{
389public:
390 /**
391 Return the index of the column affected by this event.
392 */
393 int GetColumn() const;
394};