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