]> git.saurik.com Git - wxWidgets.git/blame - include/wx/headercol.h
Generate tags for ribbon headers and sources too.
[wxWidgets.git] / include / wx / headercol.h
CommitLineData
56873923
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/headercol.h
3// Purpose: declaration of wxHeaderColumn class
4// Author: Vadim Zeitlin
5// Created: 2008-12-02
6// RCS-ID: $Id$
7// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_HEADERCOL_H_
12#define _WX_HEADERCOL_H_
13
14#include "wx/bitmap.h"
15
e721a2a2
VZ
16#if wxUSE_HEADERCTRL
17
56873923
VZ
18// ----------------------------------------------------------------------------
19// constants
20// ----------------------------------------------------------------------------
21
22enum
23{
24 // special value for column width meaning unspecified/default
d0154e3a
VS
25 wxCOL_WIDTH_DEFAULT = -1,
26
27 // size the column automatically to fit all values
28 wxCOL_WIDTH_AUTOSIZE = -2
56873923
VZ
29};
30
31// bit masks for the various column attributes
32enum
33{
34 // column can be resized (included in default flags)
35 wxCOL_RESIZABLE = 1,
36
37 // column can be clicked to toggle the sort order by its contents
38 wxCOL_SORTABLE = 2,
39
40 // column can be dragged to change its order (included in default)
41 wxCOL_REORDERABLE = 4,
42
43 // column is not shown at all
44 wxCOL_HIDDEN = 8,
45
46 // default flags for wxHeaderColumn ctor
47 wxCOL_DEFAULT_FLAGS = wxCOL_RESIZABLE | wxCOL_REORDERABLE
48};
49
50// ----------------------------------------------------------------------------
dcb6cbec
VZ
51// wxHeaderColumn: interface for a column in a header of controls such as
52// wxListCtrl, wxDataViewCtrl or wxGrid
56873923
VZ
53// ----------------------------------------------------------------------------
54
dcb6cbec 55class WXDLLIMPEXP_CORE wxHeaderColumn
56873923
VZ
56{
57public:
58 // ctors and dtor
59 // --------------
60
61 /*
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);
73 */
74
a7d40369
VZ
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
dcb6cbec
VZ
77 // wxHeaderColumn so it's not necessary, strictly speaking
78 virtual ~wxHeaderColumn() { }
a7d40369 79
dcb6cbec
VZ
80 // getters for various attributes
81 // ------------------------------
56873923 82
dcb6cbec
VZ
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
56873923
VZ
89
90 // title is the string shown for this column
56873923
VZ
91 virtual wxString GetTitle() const = 0;
92
93 // bitmap shown (instead of text) in the column header
56873923
VZ
94 virtual wxBitmap GetBitmap() const = 0; \
95
96 // width of the column in pixels, can be set to wxCOL_WIDTH_DEFAULT meaning
97 // unspecified/default
56873923
VZ
98 virtual int GetWidth() const = 0;
99
d13b34d3 100 // minimal width can be set for resizable columns to forbid resizing them
56873923 101 // below the specified size (set to 0 to remove)
56873923
VZ
102 virtual int GetMinWidth() const = 0;
103
104 // alignment of the text: wxALIGN_CENTRE, wxALIGN_LEFT or wxALIGN_RIGHT
56873923
VZ
105 virtual wxAlignment GetAlignment() const = 0;
106
56873923
VZ
107
108 // flags manipulations:
109 // --------------------
110
dcb6cbec
VZ
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
115 // GetFlags()
56873923 116
dcb6cbec 117 // retrieve all column flags at once: combination of wxCOL_XXX values above
56873923
VZ
118 virtual int GetFlags() const = 0;
119
56873923
VZ
120 bool HasFlag(int flag) const { return (GetFlags() & flag) != 0; }
121
122
123 // wxCOL_RESIZABLE
56873923
VZ
124 virtual bool IsResizeable() const
125 { return HasFlag(wxCOL_RESIZABLE); }
126
127 // wxCOL_SORTABLE
56873923
VZ
128 virtual bool IsSortable() const
129 { return HasFlag(wxCOL_SORTABLE); }
130
131 // wxCOL_REORDERABLE
56873923
VZ
132 virtual bool IsReorderable() const
133 { return HasFlag(wxCOL_REORDERABLE); }
134
135 // wxCOL_HIDDEN
56873923
VZ
136 virtual bool IsHidden() const
137 { return HasFlag(wxCOL_HIDDEN); }
78fd3d12
VZ
138 bool IsShown() const
139 { return !IsHidden(); }
56873923 140
e2bfe673
VZ
141
142 // sorting
143 // -------
144
dcb6cbec 145 // return true if the column is the one currently used for sorting
e2bfe673
VZ
146 virtual bool IsSortKey() const = 0;
147
56873923 148 // for sortable columns indicate whether we should sort in ascending or
e2bfe673 149 // descending order (this should only be taken into account if IsSortKey())
dcb6cbec
VZ
150 virtual bool IsSortOrderAscending() const = 0;
151
152protected:
153 // helper for the class overriding IsXXX()
154 int GetFromIndividualFlags() const;
155};
156
157// ----------------------------------------------------------------------------
158// wxSettableHeaderColumn: column which allows to change its fields too
159// ----------------------------------------------------------------------------
160
de150f6a 161class WXDLLIMPEXP_CORE wxSettableHeaderColumn : public wxHeaderColumn
dcb6cbec
VZ
162{
163public:
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;
169
170 // see comment for wxHeaderColumn::GetFlags() about the relationship
171 // between SetFlags() and Set{Sortable,Reorderable,...}
172
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);
179
d13b34d3
DS
180 virtual void SetResizeable(bool resizable)
181 { ChangeFlag(wxCOL_RESIZABLE, resizable); }
dcb6cbec
VZ
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); }
188
aadbdd16
VZ
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() { }
dcb6cbec 195
56873923
VZ
196 virtual void SetSortOrder(bool ascending) = 0;
197 void ToggleSortOrder() { SetSortOrder(!IsSortOrderAscending()); }
56873923
VZ
198
199protected:
dcb6cbec
VZ
200 // helper for the class overriding individual SetXXX() methods instead of
201 // overriding SetFlags()
56873923 202 void SetIndividualFlags(int flags);
56873923
VZ
203};
204
e2bfe673 205// ----------------------------------------------------------------------------
dcb6cbec 206// wxHeaderColumnSimple: trivial generic implementation of wxHeaderColumn
e2bfe673 207// ----------------------------------------------------------------------------
56873923 208
dcb6cbec 209class wxHeaderColumnSimple : public wxSettableHeaderColumn
e2bfe673
VZ
210{
211public:
212 // ctors and dtor
213 wxHeaderColumnSimple(const wxString& title,
214 int width = wxCOL_WIDTH_DEFAULT,
215 wxAlignment align = wxALIGN_NOT,
216 int flags = wxCOL_DEFAULT_FLAGS)
217 : m_title(title),
218 m_width(width),
219 m_align(align),
220 m_flags(flags)
221 {
222 Init();
223 }
224
225 wxHeaderColumnSimple(const wxBitmap& bitmap,
226 int width = wxCOL_WIDTH_DEFAULT,
227 wxAlignment align = wxALIGN_CENTER,
228 int flags = wxCOL_DEFAULT_FLAGS)
229 : m_bitmap(bitmap),
230 m_width(width),
231 m_align(align),
232 m_flags(flags)
233 {
234 Init();
235 }
236
237 // implement base class pure virtuals
238 virtual void SetTitle(const wxString& title) { m_title = title; }
239 virtual wxString GetTitle() const { return m_title; }
240
241 virtual void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; }
242 wxBitmap GetBitmap() const { return m_bitmap; }
243
244 virtual void SetWidth(int width) { m_width = width; }
245 virtual int GetWidth() const { return m_width; }
246
247 virtual void SetMinWidth(int minWidth) { m_minWidth = minWidth; }
248 virtual int GetMinWidth() const { return m_minWidth; }
249
250 virtual void SetAlignment(wxAlignment align) { m_align = align; }
251 virtual wxAlignment GetAlignment() const { return m_align; }
252
253 virtual void SetFlags(int flags) { m_flags = flags; }
254 virtual int GetFlags() const { return m_flags; }
255
e2bfe673 256 virtual bool IsSortKey() const { return m_sort; }
aadbdd16
VZ
257 virtual void UnsetAsSortKey() { m_sort = false; }
258
259 virtual void SetSortOrder(bool ascending)
260 {
261 m_sort = true;
262 m_sortAscending = ascending;
263 }
e2bfe673 264
e2bfe673
VZ
265 virtual bool IsSortOrderAscending() const { return m_sortAscending; }
266
267private:
268 // common part of all ctors
269 void Init()
270 {
271 m_minWidth = 0;
272 m_sort = false;
273 m_sortAscending = true;
274 }
275
276 wxString m_title;
277 wxBitmap m_bitmap;
278 int m_width,
279 m_minWidth;
280 wxAlignment m_align;
281 int m_flags;
282 bool m_sort,
283 m_sortAscending;
284};
e721a2a2
VZ
285
286#endif // wxUSE_HEADERCTRL
287
56873923
VZ
288#endif // _WX_HEADERCOL_H_
289