1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/headercol.h
3 // Purpose: declaration of wxHeaderColumn class
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_HEADERCOL_H_
12 #define _WX_HEADERCOL_H_
14 #include "wx/bitmap.h"
18 // ----------------------------------------------------------------------------
20 // ----------------------------------------------------------------------------
24 // special value for column width meaning unspecified/default
25 wxCOL_WIDTH_DEFAULT
= -1
28 // bit masks for the various column attributes
31 // column can be resized (included in default flags)
34 // column can be clicked to toggle the sort order by its contents
37 // column can be dragged to change its order (included in default)
38 wxCOL_REORDERABLE
= 4,
40 // column is not shown at all
43 // default flags for wxHeaderColumn ctor
44 wxCOL_DEFAULT_FLAGS
= wxCOL_RESIZABLE
| wxCOL_REORDERABLE
47 // ----------------------------------------------------------------------------
48 // wxHeaderColumn: interface for a column in a header of controls such as
49 // wxListCtrl, wxDataViewCtrl or wxGrid
50 // ----------------------------------------------------------------------------
52 class WXDLLIMPEXP_CORE wxHeaderColumn
59 Derived classes must provide ctors with the following signatures
60 (notice that they shouldn't be explicit to allow passing strings/bitmaps
61 directly to methods such wxHeaderCtrl::AppendColumn()):
62 wxHeaderColumn(const wxString& title,
63 int width = wxCOL_WIDTH_DEFAULT,
64 wxAlignment align = wxALIGN_NOT,
65 int flags = wxCOL_DEFAULT_FLAGS);
66 wxHeaderColumn(const wxBitmap &bitmap,
67 int width = wxDVC_DEFAULT_WIDTH,
68 wxAlignment align = wxALIGN_CENTER,
69 int flags = wxCOL_DEFAULT_FLAGS);
72 // virtual dtor for the base class to avoid gcc warnings even though we
73 // don't normally delete the objects of this class via a pointer to
74 // wxHeaderColumn so it's not necessary, strictly speaking
75 virtual ~wxHeaderColumn() { }
77 // getters for various attributes
78 // ------------------------------
80 // notice that wxHeaderColumn only provides getters as this is all the
81 // wxHeaderCtrl needs, various derived class must also provide some way to
82 // change these attributes but this can be done either at the column level
83 // (in which case they should inherit from wxSettableHeaderColumn) or via
84 // the methods of the main control in which case you don't need setters in
85 // the column class at all
87 // title is the string shown for this column
88 virtual wxString
GetTitle() const = 0;
90 // bitmap shown (instead of text) in the column header
91 virtual wxBitmap
GetBitmap() const = 0; \
93 // width of the column in pixels, can be set to wxCOL_WIDTH_DEFAULT meaning
94 // unspecified/default
95 virtual int GetWidth() const = 0;
97 // minimal width can be set for resizeable columns to forbid resizing them
98 // below the specified size (set to 0 to remove)
99 virtual int GetMinWidth() const = 0;
101 // alignment of the text: wxALIGN_CENTRE, wxALIGN_LEFT or wxALIGN_RIGHT
102 virtual wxAlignment
GetAlignment() const = 0;
105 // flags manipulations:
106 // --------------------
108 // notice that while we make GetFlags() pure virtual here and implement the
109 // individual flags access in terms of it, for some derived classes it is
110 // more natural to implement access to each flag individually, in which
111 // case they can use our GetFromIndividualFlags() helper below to implement
114 // retrieve all column flags at once: combination of wxCOL_XXX values above
115 virtual int GetFlags() const = 0;
117 bool HasFlag(int flag
) const { return (GetFlags() & flag
) != 0; }
121 virtual bool IsResizeable() const
122 { return HasFlag(wxCOL_RESIZABLE
); }
125 virtual bool IsSortable() const
126 { return HasFlag(wxCOL_SORTABLE
); }
129 virtual bool IsReorderable() const
130 { return HasFlag(wxCOL_REORDERABLE
); }
133 virtual bool IsHidden() const
134 { return HasFlag(wxCOL_HIDDEN
); }
136 { return !IsHidden(); }
142 // return true if the column is the one currently used for sorting
143 virtual bool IsSortKey() const = 0;
145 // for sortable columns indicate whether we should sort in ascending or
146 // descending order (this should only be taken into account if IsSortKey())
147 virtual bool IsSortOrderAscending() const = 0;
150 // helper for the class overriding IsXXX()
151 int GetFromIndividualFlags() const;
154 // ----------------------------------------------------------------------------
155 // wxSettableHeaderColumn: column which allows to change its fields too
156 // ----------------------------------------------------------------------------
158 class WXDLLIMPEXP_CORE wxSettableHeaderColumn
: public wxHeaderColumn
161 virtual void SetTitle(const wxString
& title
) = 0;
162 virtual void SetBitmap(const wxBitmap
& bitmap
) = 0;
163 virtual void SetWidth(int width
) = 0;
164 virtual void SetMinWidth(int minWidth
) = 0;
165 virtual void SetAlignment(wxAlignment align
) = 0;
167 // see comment for wxHeaderColumn::GetFlags() about the relationship
168 // between SetFlags() and Set{Sortable,Reorderable,...}
170 // change, set, clear, toggle or test for any individual flag
171 virtual void SetFlags(int flags
) = 0;
172 void ChangeFlag(int flag
, bool set
);
173 void SetFlag(int flag
);
174 void ClearFlag(int flag
);
175 void ToggleFlag(int flag
);
177 virtual void SetResizeable(bool resizeable
)
178 { ChangeFlag(wxCOL_RESIZABLE
, resizeable
); }
179 virtual void SetSortable(bool sortable
)
180 { ChangeFlag(wxCOL_SORTABLE
, sortable
); }
181 virtual void SetReorderable(bool reorderable
)
182 { ChangeFlag(wxCOL_REORDERABLE
, reorderable
); }
183 virtual void SetHidden(bool hidden
)
184 { ChangeFlag(wxCOL_HIDDEN
, hidden
); }
186 virtual void SetAsSortKey(bool sort
= true) = 0;
187 void UnsetAsSortKey() { SetAsSortKey(false); }
189 virtual void SetSortOrder(bool ascending
) = 0;
190 void ToggleSortOrder() { SetSortOrder(!IsSortOrderAscending()); }
193 // helper for the class overriding individual SetXXX() methods instead of
194 // overriding SetFlags()
195 void SetIndividualFlags(int flags
);
198 // ----------------------------------------------------------------------------
199 // wxHeaderColumnSimple: trivial generic implementation of wxHeaderColumn
200 // ----------------------------------------------------------------------------
202 class wxHeaderColumnSimple
: public wxSettableHeaderColumn
206 wxHeaderColumnSimple(const wxString
& title
,
207 int width
= wxCOL_WIDTH_DEFAULT
,
208 wxAlignment align
= wxALIGN_NOT
,
209 int flags
= wxCOL_DEFAULT_FLAGS
)
218 wxHeaderColumnSimple(const wxBitmap
& bitmap
,
219 int width
= wxCOL_WIDTH_DEFAULT
,
220 wxAlignment align
= wxALIGN_CENTER
,
221 int flags
= wxCOL_DEFAULT_FLAGS
)
230 // implement base class pure virtuals
231 virtual void SetTitle(const wxString
& title
) { m_title
= title
; }
232 virtual wxString
GetTitle() const { return m_title
; }
234 virtual void SetBitmap(const wxBitmap
& bitmap
) { m_bitmap
= bitmap
; }
235 wxBitmap
GetBitmap() const { return m_bitmap
; }
237 virtual void SetWidth(int width
) { m_width
= width
; }
238 virtual int GetWidth() const { return m_width
; }
240 virtual void SetMinWidth(int minWidth
) { m_minWidth
= minWidth
; }
241 virtual int GetMinWidth() const { return m_minWidth
; }
243 virtual void SetAlignment(wxAlignment align
) { m_align
= align
; }
244 virtual wxAlignment
GetAlignment() const { return m_align
; }
246 virtual void SetFlags(int flags
) { m_flags
= flags
; }
247 virtual int GetFlags() const { return m_flags
; }
249 virtual void SetAsSortKey(bool sort
= true) { m_sort
= sort
; }
250 virtual bool IsSortKey() const { return m_sort
; }
252 virtual void SetSortOrder(bool ascending
) { m_sortAscending
= ascending
; }
253 virtual bool IsSortOrderAscending() const { return m_sortAscending
; }
256 // common part of all ctors
261 m_sortAscending
= true;
274 #endif // wxUSE_HEADERCTRL
276 #endif // _WX_HEADERCOL_H_