- Rewrite wxHeaderCtrl to be virtual-like: even if we don't need an infinite
[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{wxHeaderEvent}
53 @event{EVT_HEADER_CLICK(id, func)}
54 A column heading was clicked.
55 @endEventTable
56
57 @library{wxcore}
58 @category{ctrl}
59
60 @see wxGrid, wxListCtrl, wxDataViewCtrl
61
62
63 @section headerctrl_improvements Future Improvements
64
65 Some features are supported by the native MSW control and so could be
66 easily implemented in this version of wxHeaderCtrl but need to be
67 implemented in the generic version as well to be really useful. Please let
68 us know if you need or, better, plan to work on implementing, any of them:
69 - Displaying bitmaps instead of or together with the text
70 - Custom drawn headers
71 - Filters associated with a column.
72 */
73 class wxHeaderCtrl
74 {
75 public:
76 /**
77 Default constructor not creating the underlying window.
78
79 You must use Create() after creating the object using this constructor.
80 */
81 wxHeaderCtrl();
82
83 /**
84 Constructor creating the window.
85
86 Please see Create() for the parameters documentation.
87 */
88 wxHeaderCtrl(wxWindow *parent,
89 wxWindowID winid = wxID_ANY,
90 const wxPoint& pos = wxDefaultPosition,
91 const wxSize& size = wxDefaultSize,
92 long style = wxHD_DEFAULT_STYLE,
93 const wxString& name = wxHeaderCtrlNameStr);
94
95 /**
96 Create the header control window.
97
98 @param parent
99 The parent window. The header control should be typically
100 positioned along the top edge of this window.
101 @param winid
102 Id of the control or @c wxID_ANY if you don't care.
103 @param pos
104 The initial position of the control.
105 @param size
106 The initial size of the control (usually not very useful as this
107 control will typically be resized to have the same width as the
108 associated data display control).
109 @param style
110 The control style, @c wxHD_DEFAULT_STYLE by default. Notice that
111 the default style allows the user to reorder the columns by
112 dragging them and you need to explicitly turn this feature off by
113 using @code wxHD_DEFAULT_STYLE & ~wxHD_DRAGDROP @endcode if this is
114 undesirable.
115 @param name
116 The name of the control.
117 */
118 bool Create(wxWindow *parent,
119 wxWindowID winid = wxID_ANY,
120 const wxPoint& pos = wxDefaultPosition,
121 const wxSize& size = wxDefaultSize,
122 long style = wxHD_DEFAULT_STYLE,
123 const wxString& name = wxHeaderCtrlNameStr);
124
125 /**
126 Set the number of columns in the control.
127
128 The control will use GetColumn() to get information about all the
129 new columns and refresh itself, i.e. this method also has the same
130 effect as calling UpdateColumn() for all columns but it should only be
131 used if the number of columns really changed.
132 */
133 void SetColumnCount(unsigned int count);
134
135 /**
136 Return the number of columns in the control.
137
138 @return
139 Number of columns as previously set by SetColumnCount().
140
141 @see IsEmpty()
142 */
143 unsigned int GetColumnCount() const;
144
145 /**
146 Return whether the control has any columns.
147
148 @see GetColumnCount()
149 */
150 bool IsEmpty() const;
151
152 protected:
153 /**
154 Method to be implemented by the derived classes to return the
155 information for the given column.
156
157 @param idx
158 The column index, between 0 and the value last passed to
159 SetColumnCount().
160 */
161 virtual wxHeaderColumnBase& GetColumn(unsigned int idx) = 0;
162 };
163
164
165 /**
166 @class wxHeaderCtrlSimple
167
168 wxHeaderCtrlSimple is a concrete header control which can be used directly,
169 without inheriting from it as you need to do when using wxHeaderCtrl
170 itself.
171
172 When using it, you need to use simple AppendColumn(), InsertColumn() and
173 DeleteColumn() methods instead of setting the number of columns with
174 SetColumnCount() and returning the information about them from the
175 overridden GetColumn().
176
177 @library{wxcore}
178 @category{ctrl}
179
180 @see wxHeaderCtrl
181 */
182 class wxHeaderCtrlSimple : public wxHeaderCtrl
183 {
184 public:
185 /**
186 Default constructor not creating the underlying window.
187
188 You must use Create() after creating the object using this constructor.
189 */
190 wxHeaderCtrlSimple();
191
192 /**
193 Constructor creating the window.
194
195 Please see the base class wxHeaderCtrl::Create() method for the
196 parameters description.
197 */
198 wxHeaderCtrlSimple(wxWindow *parent,
199 wxWindowID winid = wxID_ANY,
200 const wxPoint& pos = wxDefaultPosition,
201 const wxSize& size = wxDefaultSize,
202 long style = wxHD_DEFAULT_STYLE,
203 const wxString& name = wxHeaderCtrlNameStr);
204
205 /**
206 Insert the column at the given position.
207
208 @param col
209 The column to insert. Notice that because of the existence of
210 implicit conversion from wxString to wxHeaderColumn a string
211 can be passed directly here.
212 @param idx
213 The position of the new column, from 0 to GetColumnCount(). Using
214 GetColumnCount() means to append the column to the end.
215
216 @see AppendColumn()
217 */
218 void InsertColumn(const wxHeaderColumn& col, unsigned int idx);
219
220 /**
221 Append the column to the end of the control.
222
223 @see InsertColumn()
224 */
225 void AppendColumn(const wxHeaderColumn& col);
226
227 /**
228 Delete the column at the given position.
229
230 @see InsertColumn(), AppendColumn()
231 */
232 void DeleteColumn(unsigned int idx);
233
234 /**
235 Show or hide the column.
236
237 Initially the column is shown by default or hidden if it was added with
238 wxCOL_HIDDEN flag set.
239
240 When a column is hidden, it doesn't appear at all on the screen but its
241 index is still taken into account when working with other columns. E.g.
242 if there are three columns 0, 1 and 2 and the column 1 is hidden you
243 still need to use index 2 to refer to the last visible column.
244
245 @param idx
246 The index of the column to show or hide, from 0 to GetColumnCount().
247 @param show
248 Indicates whether the column should be shown (default) or hidden.
249 */
250 void ShowColumn(unsigned int idx, bool show = true);
251
252 /**
253 Hide the column with the given index.
254
255 This is the same as calling @code ShowColumn(idx, false) @endcode.
256
257 @param idx
258 The index of the column to show or hide, from 0 to GetColumnCount().
259 */
260 void HideColumn(unsigned int idx);
261
262 /**
263 Update the column sort indicator.
264
265 The sort indicator, if shown, is typically an arrow pointing upwards or
266 downwards depending on whether the control contents is sorted in
267 ascending or descending order.
268
269 @param idx
270 The column to set the sort indicator for.
271 @param sortOrder
272 If @true or @false show the sort indicator corresponding to
273 ascending or descending sort order respectively, if @c -1 remove
274 the currently shown sort indicator.
275 */
276 virtual void ShowSortIndicator(unsigned int idx, int sortOrder);
277
278 /**
279 Remove the sort indicator from the given column.
280
281 This is the same as calling ShowSortIndicator() with @c -1 argument.
282
283 @param idx
284 The column to remove sort indicator for.
285 */
286 void RemoveSortIndicator(unsigned int idx);
287 };