]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/headercol.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/headercol.h
3 // Purpose: interface of wxHeaderColumn
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
12 Special value used for column width meaning unspecified or default.
14 enum { wxCOL_WIDTH_DEFAULT
= -1 };
17 Bit flags used as wxHeaderColumn flags.
21 /// Column can be resized (included in default flags).
24 /// Column can be clicked to toggle the sort order by its contents.
27 /// Column can be dragged to change its order (included in default).
28 wxCOL_REORDERABLE
= 4,
30 /// Column is not shown at all.
33 /// Default flags for wxHeaderColumn ctor.
34 wxCOL_DEFAULT_FLAGS
= wxCOL_RESIZABLE
| wxCOL_REORDERABLE
40 Represents a column header in controls displaying tabular data such as
41 wxDataViewCtrl or wxGrid.
43 Notice that this is an abstract base class which is implemented (usually
44 using the information stored in the associated control) by the different
45 controls using wxHeaderCtrl. You may use wxHeaderCtrlSimple which uses
46 concrete wxHeaderColumnSimple if you don't already store the column
47 information somewhere.
56 Set the text to display in the column header.
58 virtual void SetTitle(const wxString
& title
) = 0;
61 Get the text shown in the column header.
63 virtual wxString
GetTitle() const = 0;
66 Set the bitmap to be displayed in the column header.
68 Notice that the bitmaps displayed in different columns of the same
69 control must all be of the same size.
71 virtual void SetBitmap(const wxBitmap
& bitmap
) = 0;
74 Returns the bitmap in the header of the column, if any.
76 If the column has no associated bitmap, wxNullBitmap is returned.
78 virtual wxBitmap
GetBitmap() const = 0;
84 The column width in pixels or the special wxCOL_WIDTH_DEFAULT value
85 meaning to use default width.
87 virtual void SetWidth(int width
) = 0;
90 Returns the current width of the column.
93 Width of the column in pixels, never wxCOL_WIDTH_DEFAULT.
95 virtual int GetWidth() const = 0;
98 Set the minimal column width.
100 This method can be used with resizeable columns (i.e. those for which
101 wxCOL_RESIZABLE flag is set in GetFlags() or, alternatively,
102 IsResizeable() returns @true) to prevent the user from making them
103 narrower than the given width.
106 The minimal column width in pixels, may be 0 to remove any
107 previously set restrictions.
109 virtual void SetMinWidth(int minWidth
) = 0;
112 Return the minimal column width.
115 The value previously set by SetMinWidth() or 0 by default.
117 virtual int GetMinWidth() const = 0;
120 Set the alignment of the column header.
123 The text alignment in horizontal direction only or wxALIGN_NOT to
124 use the default alignment, The possible values here are
125 wxALIGN_CENTRE, wxALIGN_LEFT or wxALIGN_RIGHT with
126 wxALIGN_CENTRE_HORIZONTAL being also supported as synonym for
127 wxALIGN_CENTRE for consistency (but notice that GetAlignment()
130 virtual void SetAlignment(wxAlignment align
) = 0;
133 Returns the current column alignment.
136 One of wxALIGN_CENTRE, wxALIGN_LEFT or wxALIGN_RIGHT.
138 virtual wxAlignment
GetAlignment() const = 0;
142 Set the column flags.
144 This method allows to set all flags at once, see also generic
145 ChangeFlag(), SetFlag(), ClearFlag() and ToggleFlag() methods below as
146 well as specific SetResizeable(), SetSortable(), SetReorderable() and
150 Combination of wxCOL_RESIZABLE, wxCOL_SORTABLE, wxCOL_REORDERABLE
151 and wxCOL_HIDDEN bit flags.
153 virtual void SetFlags(int flags
) = 0;
156 Set or clear the given flag.
159 The flag to set or clear.
161 If @true, set the flag, i.e. equivalent to calling SetFlag(),
162 otherwise clear it, as ClearFlag().
166 void ChangeFlag(int flag
, bool set
);
169 Set the specified flag for the column.
173 void SetFlag(int flag
);
176 Clear the specified flag for the column.
180 void ClearFlag(int flag
);
183 Toggle the specified flag for the column.
185 If the flag is currently set, equivalent to ClearFlag(), otherwise --
190 void ToggleFlag(int flag
);
193 Get the column flags.
195 This method retrieves all the flags at once, you can also use HasFlag()
196 to test for any individual flag or IsResizeable(), IsSortable(),
197 IsReorderable() and IsHidden() to test for particular flags.
201 virtual int GetFlags() const = 0;
204 Return @true if the specified flag is currently set for this column.
206 bool HasFlag(int flag
) const;
210 Call this to enable or disable interactive resizing of the column by
213 By default, the columns are resizeable.
215 Equivalent to ChangeFlag(wxCOL_RESIZABLE, resizeable).
217 virtual void SetResizeable(bool resizeable
);
220 Return true if the column can be resized by the user.
222 Equivalent to HasFlag(wxCOL_RESIZABLE).
224 virtual bool IsResizeable() const;
227 Allow clicking the column to sort the control contents by the field in
230 By default, the columns are not sortable so you need to explicitly call
231 this function to allow sorting by the field corresponding to this
234 Equivalent to ChangeFlag(wxCOL_SORTABLE, sortable).
236 virtual void SetSortable(bool sortable
);
239 Returns @true if the column can be clicked by user to sort the control
240 contents by the field in this column.
242 This corresponds to wxCOL_SORTABLE flag which is off by default.
246 virtual bool IsSortable() const;
249 Allow changing the column order by dragging it.
251 Equivalent to ChangeFlag(wxCOL_REORDERABLE, reorderable).
253 virtual void SetReorderable(bool reorderable
);
256 Returns @true if the column can be dragged by user to change its order.
258 This corresponds to wxCOL_REORDERABLE flag which is on by default.
260 @see SetReorderable()
262 virtual bool IsReorderable() const;
265 Hide or show the column.
267 By default all columns are shown but some of them can be completely
268 hidden from view by calling this function.
270 Equivalent to ChangeFlag(wxCOL_HIDDEN, hidden).
272 virtual void SetHidden(bool hidden
);
275 Returns @true if the column is currently hidden.
277 This corresponds to wxCOL_HIDDEN flag which is off by default.
279 virtual bool IsHidden() const;
282 Returns @true if the column is currently shown.
284 This corresponds to the absence of wxCOL_HIDDEN flag.
286 bool IsShown() const;
291 Sets this column as the sort key for the associated control.
293 Calling this function with @true argument means that this column is
294 currently used for sorting the control contents and so should typically
295 display an arrow indicating it (the direction of the arrow depends on
296 IsSortOrderAscending() return value).
298 Don't confuse this function with SetSortable() which should be used to
299 indicate that the column @em may be used for sorting while this one is
300 used to indicate that it currently @em is used for sorting. Of course,
301 SetAsSortKey() can be only called for sortable columns.
304 Sort (default) or don't sort the control contents by this column.
306 virtual void SetAsSortKey(bool sort
= true) = 0;
309 Don't use this column for sorting.
311 This is equivalent to calling SetAsSortKey() with @false argument.
313 void UnsetAsSortKey();
316 Returns @true if the column is currently used for sorting.
318 Notice that this function simply returns the value last passed to
319 SetAsSortKey() (or @false if SetAsSortKey() had never been called), it
320 is up to the associated control to use this information to actually
323 virtual bool IsSortKey() const = 0;
326 Sets the sort order for this column.
328 This only makes sense for sortable columns which are currently used as
329 sort key, i.e. for which IsSortKey() returns @true and is only taken
330 into account by the control in which this column is inserted, this
331 function just stores the sort order in the wxHeaderColumn object.
334 If @true, sort in ascending order, otherwise in descending order.
336 virtual void SetSortOrder(bool ascending
) = 0;
339 Inverses the sort order.
341 This function is typically called when the user clicks on a column used
342 for sorting to change sort order from ascending to descending or vice
345 @see SetSortOrder(), IsSortOrderAscending()
347 void ToggleSortOrder();
350 Returns @true, if the sort order is ascending.
352 Notice that it only makes sense to call this function if the column is
353 used for sorting at all, i.e. if IsSortKey() returns @true.
357 virtual bool IsSortOrderAscending() const = 0;
361 @class wxHeaderColumnSimple
363 Simple container for the information about the column.
365 This is a concrete class implementing all base wxHeaderColumn class methods
366 in a trivial way, i.e. by just storing the information in the object
367 itself. It is used by and with wxHeaderCtrlSimple, e.g.
369 wxHeaderCtrlSimple * header = new wxHeaderCtrlSimple(...);
370 wxHeaderColumnSimple col("Title");
372 col.SetSortable(100);
373 header->AppendColumn(col);
379 class wxHeaderColumnSimple
: public wxHeaderColumn
384 Constructor for a column header.
386 The first constructor creates a header showing the given text @a title
387 while the second one creates one showing the specified @a bitmap image.
389 wxHeaderColumnSimple(const wxString
& title
,
390 int width
= wxCOL_WIDTH_DEFAULT
,
391 wxAlignment align
= wxALIGN_NOT
,
392 int flags
= wxCOL_DEFAULT_FLAGS
);
394 wxHeaderColumnSimple(const wxBitmap
&bitmap
,
395 int width
= wxDVC_DEFAULT_WIDTH
,
396 wxAlignment align
= wxALIGN_CENTER
,
397 int flags
= wxCOL_DEFAULT_FLAGS
);
402 /// Trivial implementations of the base class pure virtual functions.
404 virtual void SetTitle(const wxString
& title
);
405 virtual wxString
GetTitle() const;
406 virtual void SetBitmap(const wxBitmap
& bitmap
);
407 virtual wxBitmap
GetBitmap() const;
408 virtual void SetWidth(int width
);
409 virtual int GetWidth() const;
410 virtual void SetMinWidth(int minWidth
);
411 virtual int GetMinWidth() const;
412 virtual void SetAlignment(wxAlignment align
);
413 virtual wxAlignment
GetAlignment() const;
414 virtual void SetFlags(int flags
);
415 virtual int GetFlags() const;
416 virtual void SetAsSortKey(bool sort
= true);
417 virtual bool IsSortKey() const;
418 virtual void SetSortOrder(bool ascending
);
419 virtual bool IsSortOrderAscending() const;