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,
27 // size the column automatically to fit all values
28 wxCOL_WIDTH_AUTOSIZE
= -2
31 // bit masks for the various column attributes
34 // column can be resized (included in default flags)
37 // column can be clicked to toggle the sort order by its contents
40 // column can be dragged to change its order (included in default)
41 wxCOL_REORDERABLE
= 4,
43 // column is not shown at all
46 // default flags for wxHeaderColumn ctor
47 wxCOL_DEFAULT_FLAGS
= wxCOL_RESIZABLE
| wxCOL_REORDERABLE
50 // ----------------------------------------------------------------------------
51 // wxHeaderColumn: interface for a column in a header of controls such as
52 // wxListCtrl, wxDataViewCtrl or wxGrid
53 // ----------------------------------------------------------------------------
55 class WXDLLIMPEXP_CORE wxHeaderColumn
62 Derived classes must provide ctors with the following signatures
63 (notice that they shouldn't be explicit to allow passing strings/bitmaps
64 directly to methods such wxHeaderCtrl::AppendColumn()):
65 wxHeaderColumn(const wxString& title,
66 int width = wxCOL_WIDTH_DEFAULT,
67 wxAlignment align = wxALIGN_NOT,
68 int flags = wxCOL_DEFAULT_FLAGS);
69 wxHeaderColumn(const wxBitmap &bitmap,
70 int width = wxDVC_DEFAULT_WIDTH,
71 wxAlignment align = wxALIGN_CENTER,
72 int flags = wxCOL_DEFAULT_FLAGS);
75 // virtual dtor for the base class to avoid gcc warnings even though we
76 // don't normally delete the objects of this class via a pointer to
77 // wxHeaderColumn so it's not necessary, strictly speaking
78 virtual ~wxHeaderColumn() { }
80 // getters for various attributes
81 // ------------------------------
83 // notice that wxHeaderColumn only provides getters as this is all the
84 // wxHeaderCtrl needs, various derived class must also provide some way to
85 // change these attributes but this can be done either at the column level
86 // (in which case they should inherit from wxSettableHeaderColumn) or via
87 // the methods of the main control in which case you don't need setters in
88 // the column class at all
90 // title is the string shown for this column
91 virtual wxString
GetTitle() const = 0;
93 // bitmap shown (instead of text) in the column header
94 virtual wxBitmap
GetBitmap() const = 0; \
96 // width of the column in pixels, can be set to wxCOL_WIDTH_DEFAULT meaning
97 // unspecified/default
98 virtual int GetWidth() const = 0;
100 // minimal width can be set for resizable columns to forbid resizing them
101 // below the specified size (set to 0 to remove)
102 virtual int GetMinWidth() const = 0;
104 // alignment of the text: wxALIGN_CENTRE, wxALIGN_LEFT or wxALIGN_RIGHT
105 virtual wxAlignment
GetAlignment() const = 0;
108 // flags manipulations:
109 // --------------------
111 // notice that while we make GetFlags() pure virtual here and implement the
112 // individual flags access in terms of it, for some derived classes it is
113 // more natural to implement access to each flag individually, in which
114 // case they can use our GetFromIndividualFlags() helper below to implement
117 // retrieve all column flags at once: combination of wxCOL_XXX values above
118 virtual int GetFlags() const = 0;
120 bool HasFlag(int flag
) const { return (GetFlags() & flag
) != 0; }
124 virtual bool IsResizeable() const
125 { return HasFlag(wxCOL_RESIZABLE
); }
128 virtual bool IsSortable() const
129 { return HasFlag(wxCOL_SORTABLE
); }
132 virtual bool IsReorderable() const
133 { return HasFlag(wxCOL_REORDERABLE
); }
136 virtual bool IsHidden() const
137 { return HasFlag(wxCOL_HIDDEN
); }
139 { return !IsHidden(); }
145 // return true if the column is the one currently used for sorting
146 virtual bool IsSortKey() const = 0;
148 // for sortable columns indicate whether we should sort in ascending or
149 // descending order (this should only be taken into account if IsSortKey())
150 virtual bool IsSortOrderAscending() const = 0;
153 // helper for the class overriding IsXXX()
154 int GetFromIndividualFlags() const;
157 // ----------------------------------------------------------------------------
158 // wxSettableHeaderColumn: column which allows to change its fields too
159 // ----------------------------------------------------------------------------
161 class WXDLLIMPEXP_CORE wxSettableHeaderColumn
: public wxHeaderColumn
164 virtual void SetTitle(const wxString
& title
) = 0;
165 virtual void SetBitmap(const wxBitmap
& bitmap
) = 0;
166 virtual void SetWidth(int width
) = 0;
167 virtual void SetMinWidth(int minWidth
) = 0;
168 virtual void SetAlignment(wxAlignment align
) = 0;
170 // see comment for wxHeaderColumn::GetFlags() about the relationship
171 // between SetFlags() and Set{Sortable,Reorderable,...}
173 // change, set, clear, toggle or test for any individual flag
174 virtual void SetFlags(int flags
) = 0;
175 void ChangeFlag(int flag
, bool set
);
176 void SetFlag(int flag
);
177 void ClearFlag(int flag
);
178 void ToggleFlag(int flag
);
180 virtual void SetResizeable(bool resizable
)
181 { ChangeFlag(wxCOL_RESIZABLE
, resizable
); }
182 virtual void SetSortable(bool sortable
)
183 { ChangeFlag(wxCOL_SORTABLE
, sortable
); }
184 virtual void SetReorderable(bool reorderable
)
185 { ChangeFlag(wxCOL_REORDERABLE
, reorderable
); }
186 virtual void SetHidden(bool hidden
)
187 { ChangeFlag(wxCOL_HIDDEN
, hidden
); }
189 // This function can be called to indicate that this column is not used for
190 // sorting any more. Under some platforms it's not necessary to do anything
191 // in this case as just setting another column as a sort key takes care of
192 // everything but under MSW we currently need to call this explicitly to
193 // reset the sort indicator displayed on the column.
194 virtual void UnsetAsSortKey() { }
196 virtual void SetSortOrder(bool ascending
) = 0;
197 void ToggleSortOrder() { SetSortOrder(!IsSortOrderAscending()); }
200 // helper for the class overriding individual SetXXX() methods instead of
201 // overriding SetFlags()
202 void SetIndividualFlags(int flags
);
205 // ----------------------------------------------------------------------------
206 // wxHeaderColumnSimple: trivial generic implementation of wxHeaderColumn
207 // ----------------------------------------------------------------------------
209 class wxHeaderColumnSimple
: public wxSettableHeaderColumn
213 wxHeaderColumnSimple(const wxString
& title
,
214 int width
= wxCOL_WIDTH_DEFAULT
,
215 wxAlignment align
= wxALIGN_NOT
,
216 int flags
= wxCOL_DEFAULT_FLAGS
)
225 wxHeaderColumnSimple(const wxBitmap
& bitmap
,
226 int width
= wxCOL_WIDTH_DEFAULT
,
227 wxAlignment align
= wxALIGN_CENTER
,
228 int flags
= wxCOL_DEFAULT_FLAGS
)
237 // implement base class pure virtuals
238 virtual void SetTitle(const wxString
& title
) { m_title
= title
; }
239 virtual wxString
GetTitle() const { return m_title
; }
241 virtual void SetBitmap(const wxBitmap
& bitmap
) { m_bitmap
= bitmap
; }
242 wxBitmap
GetBitmap() const { return m_bitmap
; }
244 virtual void SetWidth(int width
) { m_width
= width
; }
245 virtual int GetWidth() const { return m_width
; }
247 virtual void SetMinWidth(int minWidth
) { m_minWidth
= minWidth
; }
248 virtual int GetMinWidth() const { return m_minWidth
; }
250 virtual void SetAlignment(wxAlignment align
) { m_align
= align
; }
251 virtual wxAlignment
GetAlignment() const { return m_align
; }
253 virtual void SetFlags(int flags
) { m_flags
= flags
; }
254 virtual int GetFlags() const { return m_flags
; }
256 virtual bool IsSortKey() const { return m_sort
; }
257 virtual void UnsetAsSortKey() { m_sort
= false; }
259 virtual void SetSortOrder(bool ascending
)
262 m_sortAscending
= ascending
;
265 virtual bool IsSortOrderAscending() const { return m_sortAscending
; }
268 // common part of all ctors
273 m_sortAscending
= true;
286 #endif // wxUSE_HEADERCTRL
288 #endif // _WX_HEADERCOL_H_