emulate scrolling in wxMSW header control; document the need to call ScrollWindow...
[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.
20
21 In addition to labeling the columns, the control has the following
22 features:
23 - Column reordering support, either by explicitly configuring the
24 columns order and calling SetColumnsOrder() or by dragging the
25 columns interactively (if enabled).
26 - Display of the icons in the header: this is often used to display a
27 sort or reverse sort indicator when the column header is clicked.
28
29 Notice that this control itself doesn't do anything other than displaying
30 the column headers. In particular column reordering and sorting must still
31 be supported by the associated control displaying the real data under the
32 header. Also remember to call ScrollWindow() method of the control if the
33 associated data display window has a horizontal scrollbar, otherwise the
34 headers wouldn't align with the data when the window is scrolled.
35
36 This control is implemented using the native header control under MSW
37 systems and a generic implementation elsewhere.
38
39 @beginStyleTable
40 @style{wxHD_DRAGDROP}
41 If this style is specified (it is by default), the user can reorder
42 the control columns by dragging them.
43 @style{wxHD_DEFAULT_STYLE}
44 Symbolic name for the default control style, currently equal to @c
45 wxHD_DRAGDROP.
46 @endStyleTable
47
48 @beginEventTable{wxHeaderEvent}
49 @event{EVT_HEADER_CLICK(id, func)}
50 A column heading was clicked.
51 @endEventTable
52
53 @library{wxcore}
54 @category{ctrl}
55
56 @see wxGrid, wxListCtrl, wxDataViewCtrl
57
58
59 @section headerctrl_improvements Future Improvements
60
61 Some features are supported by the native MSW control and so could be
62 easily implemented in this version of wxHeaderCtrl but need to be
63 implemented in the generic version as well to be really useful. Please let
64 us know if you need or, better, plan to work on implementing, any of them:
65 - Displaying bitmaps instead of or together with the text
66 - Custom drawn headers
67 - Filters associated with a column.
68 */
69 class wxHeaderCtrl
70 {
71 public:
72 /**
73 Default constructor not creating the underlying window.
74
75 You must use Create() after creating the object using this constructor.
76 */
77 wxHeaderCtrl();
78
79 /**
80 Constructor creating the window.
81
82 Please see Create() for the parameters documentation.
83 */
84 wxHeaderCtrl(wxWindow *parent,
85 wxWindowID winid = wxID_ANY,
86 const wxPoint& pos = wxDefaultPosition,
87 const wxSize& size = wxDefaultSize,
88 long style = 0,
89 const wxString& name = wxHeaderCtrlNameStr);
90
91 /**
92 Create the header control window.
93
94 @param parent
95 The parent window. The header control should be typically
96 positioned along the top edge of this window.
97 @param winid
98 Id of the control or @c wxID_ANY if you don't care.
99 @param pos
100 The initial position of the control.
101 @param size
102 The initial size of the control (usually not very useful as this
103 control will typically be resized to have the same width as the
104 associated data display control).
105 @param style
106 The control style, @c wxHD_DEFAULT_STYLE by default. Notice that
107 the default style allows the user to reorder the columns by
108 dragging them and you need to explicitly turn this feature off by
109 using @code wxHD_DEFAULT_STYLE & ~wxHD_DRAGDROP @endcode if this is
110 undesirable.
111 @param name
112 The name of the control.
113 */
114 bool Create(wxWindow *parent,
115 wxWindowID winid = wxID_ANY,
116 const wxPoint& pos = wxDefaultPosition,
117 const wxSize& size = wxDefaultSize,
118 long style = 0,
119 const wxString& name = wxHeaderCtrlNameStr);
120
121 /**
122 Return the number of columns in the control.
123
124 @see IsEmpty()
125 */
126 unsigned int GetColumnCount() const;
127
128 /**
129 Return whether the control has any columns.
130
131 @see GetColumnCount()
132 */
133 bool IsEmpty() const;
134
135 /**
136 Insert the column at the given position.
137
138 @param col
139 The column to insert. Notice that because of the existence of
140 implicit conversion from wxString to wxHeaderColumn a string
141 can be passed directly here.
142 @param idx
143 The position of the new column, from 0 to GetColumnCount(). Using
144 GetColumnCount() means to append the column to the end.
145
146 @see AppendColumn()
147 */
148 void InsertColumn(const wxHeaderColumn& col, unsigned int idx);
149
150 /**
151 Append the column to the end of the control.
152
153 @see InsertColumn()
154 */
155 void AppendColumn(const wxHeaderColumn& col);
156
157 /**
158 Delete the column at the given position.
159
160 @see InsertColumn(), AppendColumn()
161 */
162 void DeleteColumn(unsigned int idx);
163
164 /**
165 Show or hide the column.
166
167 Initially the column is shown by default or hidden if it was added with
168 wxCOL_HIDDEN flag set.
169
170 When a column is hidden, it doesn't appear at all on the screen but its
171 index is still taken into account when working with other columns. E.g.
172 if there are three columns 0, 1 and 2 and the column 1 is hidden you
173 still need to use index 2 to refer to the last visible column.
174
175 @param idx
176 The index of the column to show or hide, from 0 to GetColumnCount().
177 @param show
178 Indicates whether the column should be shown (default) or hidden.
179 */
180 void ShowColumn(unsigned int idx, bool show = true);
181
182 /**
183 Hide the column with the given index.
184
185 This is the same as calling @code ShowColumn(idx, false) @endcode.
186
187 @param idx
188 The index of the column to show or hide, from 0 to GetColumnCount().
189 */
190 void HideColumn(unsigned int idx);
191
192 /**
193 Update the column sort indicator.
194
195 The sort indicator, if shown, is typically an arrow pointing upwards or
196 downwards depending on whether the control contents is sorted in
197 ascending or descending order.
198
199 @param idx
200 The column to set the sort indicator for.
201 @param sortOrder
202 If @true or @false show the sort indicator corresponding to
203 ascending or descending sort order respectively, if @c -1 remove
204 the currently shown sort indicator.
205 */
206 virtual void ShowSortIndicator(unsigned int idx, int sortOrder);
207
208 /**
209 Remove the sort indicator from the given column.
210
211 This is the same as calling ShowSortIndicator() with @c -1 argument.
212
213 @param idx
214 The column to remove sort indicator for.
215 */
216 void RemoveSortIndicator(unsigned int idx);
217 };