1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/headercol.h
3 // Purpose: declaration of wxHeaderColumn class
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_HEADERCOL_H_
11 #define _WX_HEADERCOL_H_
13 #include "wx/bitmap.h"
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
23 // special value for column width meaning unspecified/default
24 wxCOL_WIDTH_DEFAULT
= -1,
26 // size the column automatically to fit all values
27 wxCOL_WIDTH_AUTOSIZE
= -2
30 // bit masks for the various column attributes
33 // column can be resized (included in default flags)
36 // column can be clicked to toggle the sort order by its contents
39 // column can be dragged to change its order (included in default)
40 wxCOL_REORDERABLE
= 4,
42 // column is not shown at all
45 // default flags for wxHeaderColumn ctor
46 wxCOL_DEFAULT_FLAGS
= wxCOL_RESIZABLE
| wxCOL_REORDERABLE
49 // ----------------------------------------------------------------------------
50 // wxHeaderColumn: interface for a column in a header of controls such as
51 // wxListCtrl, wxDataViewCtrl or wxGrid
52 // ----------------------------------------------------------------------------
54 class WXDLLIMPEXP_CORE wxHeaderColumn
61 Derived classes must provide ctors with the following signatures
62 (notice that they shouldn't be explicit to allow passing strings/bitmaps
63 directly to methods such wxHeaderCtrl::AppendColumn()):
64 wxHeaderColumn(const wxString& title,
65 int width = wxCOL_WIDTH_DEFAULT,
66 wxAlignment align = wxALIGN_NOT,
67 int flags = wxCOL_DEFAULT_FLAGS);
68 wxHeaderColumn(const wxBitmap &bitmap,
69 int width = wxDVC_DEFAULT_WIDTH,
70 wxAlignment align = wxALIGN_CENTER,
71 int flags = wxCOL_DEFAULT_FLAGS);
74 // virtual dtor for the base class to avoid gcc warnings even though we
75 // don't normally delete the objects of this class via a pointer to
76 // wxHeaderColumn so it's not necessary, strictly speaking
77 virtual ~wxHeaderColumn() { }
79 // getters for various attributes
80 // ------------------------------
82 // notice that wxHeaderColumn only provides getters as this is all the
83 // wxHeaderCtrl needs, various derived class must also provide some way to
84 // change these attributes but this can be done either at the column level
85 // (in which case they should inherit from wxSettableHeaderColumn) or via
86 // the methods of the main control in which case you don't need setters in
87 // the column class at all
89 // title is the string shown for this column
90 virtual wxString
GetTitle() const = 0;
92 // bitmap shown (instead of text) in the column header
93 virtual wxBitmap
GetBitmap() const = 0; \
95 // width of the column in pixels, can be set to wxCOL_WIDTH_DEFAULT meaning
96 // unspecified/default
97 virtual int GetWidth() const = 0;
99 // minimal width can be set for resizable columns to forbid resizing them
100 // below the specified size (set to 0 to remove)
101 virtual int GetMinWidth() const = 0;
103 // alignment of the text: wxALIGN_CENTRE, wxALIGN_LEFT or wxALIGN_RIGHT
104 virtual wxAlignment
GetAlignment() const = 0;
107 // flags manipulations:
108 // --------------------
110 // notice that while we make GetFlags() pure virtual here and implement the
111 // individual flags access in terms of it, for some derived classes it is
112 // more natural to implement access to each flag individually, in which
113 // case they can use our GetFromIndividualFlags() helper below to implement
116 // retrieve all column flags at once: combination of wxCOL_XXX values above
117 virtual int GetFlags() const = 0;
119 bool HasFlag(int flag
) const { return (GetFlags() & flag
) != 0; }
123 virtual bool IsResizeable() const
124 { return HasFlag(wxCOL_RESIZABLE
); }
127 virtual bool IsSortable() const
128 { return HasFlag(wxCOL_SORTABLE
); }
131 virtual bool IsReorderable() const
132 { return HasFlag(wxCOL_REORDERABLE
); }
135 virtual bool IsHidden() const
136 { return HasFlag(wxCOL_HIDDEN
); }
138 { return !IsHidden(); }
144 // return true if the column is the one currently used for sorting
145 virtual bool IsSortKey() const = 0;
147 // for sortable columns indicate whether we should sort in ascending or
148 // descending order (this should only be taken into account if IsSortKey())
149 virtual bool IsSortOrderAscending() const = 0;
152 // helper for the class overriding IsXXX()
153 int GetFromIndividualFlags() const;
156 // ----------------------------------------------------------------------------
157 // wxSettableHeaderColumn: column which allows to change its fields too
158 // ----------------------------------------------------------------------------
160 class WXDLLIMPEXP_CORE wxSettableHeaderColumn
: public wxHeaderColumn
163 virtual void SetTitle(const wxString
& title
) = 0;
164 virtual void SetBitmap(const wxBitmap
& bitmap
) = 0;
165 virtual void SetWidth(int width
) = 0;
166 virtual void SetMinWidth(int minWidth
) = 0;
167 virtual void SetAlignment(wxAlignment align
) = 0;
169 // see comment for wxHeaderColumn::GetFlags() about the relationship
170 // between SetFlags() and Set{Sortable,Reorderable,...}
172 // change, set, clear, toggle or test for any individual flag
173 virtual void SetFlags(int flags
) = 0;
174 void ChangeFlag(int flag
, bool set
);
175 void SetFlag(int flag
);
176 void ClearFlag(int flag
);
177 void ToggleFlag(int flag
);
179 virtual void SetResizeable(bool resizable
)
180 { ChangeFlag(wxCOL_RESIZABLE
, resizable
); }
181 virtual void SetSortable(bool sortable
)
182 { ChangeFlag(wxCOL_SORTABLE
, sortable
); }
183 virtual void SetReorderable(bool reorderable
)
184 { ChangeFlag(wxCOL_REORDERABLE
, reorderable
); }
185 virtual void SetHidden(bool hidden
)
186 { ChangeFlag(wxCOL_HIDDEN
, hidden
); }
188 // This function can be called to indicate that this column is not used for
189 // sorting any more. Under some platforms it's not necessary to do anything
190 // in this case as just setting another column as a sort key takes care of
191 // everything but under MSW we currently need to call this explicitly to
192 // reset the sort indicator displayed on the column.
193 virtual void UnsetAsSortKey() { }
195 virtual void SetSortOrder(bool ascending
) = 0;
196 void ToggleSortOrder() { SetSortOrder(!IsSortOrderAscending()); }
199 // helper for the class overriding individual SetXXX() methods instead of
200 // overriding SetFlags()
201 void SetIndividualFlags(int flags
);
204 // ----------------------------------------------------------------------------
205 // wxHeaderColumnSimple: trivial generic implementation of wxHeaderColumn
206 // ----------------------------------------------------------------------------
208 class wxHeaderColumnSimple
: public wxSettableHeaderColumn
212 wxHeaderColumnSimple(const wxString
& title
,
213 int width
= wxCOL_WIDTH_DEFAULT
,
214 wxAlignment align
= wxALIGN_NOT
,
215 int flags
= wxCOL_DEFAULT_FLAGS
)
224 wxHeaderColumnSimple(const wxBitmap
& bitmap
,
225 int width
= wxCOL_WIDTH_DEFAULT
,
226 wxAlignment align
= wxALIGN_CENTER
,
227 int flags
= wxCOL_DEFAULT_FLAGS
)
236 // implement base class pure virtuals
237 virtual void SetTitle(const wxString
& title
) { m_title
= title
; }
238 virtual wxString
GetTitle() const { return m_title
; }
240 virtual void SetBitmap(const wxBitmap
& bitmap
) { m_bitmap
= bitmap
; }
241 wxBitmap
GetBitmap() const { return m_bitmap
; }
243 virtual void SetWidth(int width
) { m_width
= width
; }
244 virtual int GetWidth() const { return m_width
; }
246 virtual void SetMinWidth(int minWidth
) { m_minWidth
= minWidth
; }
247 virtual int GetMinWidth() const { return m_minWidth
; }
249 virtual void SetAlignment(wxAlignment align
) { m_align
= align
; }
250 virtual wxAlignment
GetAlignment() const { return m_align
; }
252 virtual void SetFlags(int flags
) { m_flags
= flags
; }
253 virtual int GetFlags() const { return m_flags
; }
255 virtual bool IsSortKey() const { return m_sort
; }
256 virtual void UnsetAsSortKey() { m_sort
= false; }
258 virtual void SetSortOrder(bool ascending
)
261 m_sortAscending
= ascending
;
264 virtual bool IsSortOrderAscending() const { return m_sortAscending
; }
267 // common part of all ctors
272 m_sortAscending
= true;
285 #endif // wxUSE_HEADERCTRL
287 #endif // _WX_HEADERCOL_H_