]>
Commit | Line | Data |
---|---|---|
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 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // constants | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | enum | |
21 | { | |
22 | // special value for column width meaning unspecified/default | |
23 | wxCOL_WIDTH_DEFAULT = -1 | |
24 | }; | |
25 | ||
26 | // bit masks for the various column attributes | |
27 | enum | |
28 | { | |
29 | // column can be resized (included in default flags) | |
30 | wxCOL_RESIZABLE = 1, | |
31 | ||
32 | // column can be clicked to toggle the sort order by its contents | |
33 | wxCOL_SORTABLE = 2, | |
34 | ||
35 | // column can be dragged to change its order (included in default) | |
36 | wxCOL_REORDERABLE = 4, | |
37 | ||
38 | // column is not shown at all | |
39 | wxCOL_HIDDEN = 8, | |
40 | ||
41 | // default flags for wxHeaderColumn ctor | |
42 | wxCOL_DEFAULT_FLAGS = wxCOL_RESIZABLE | wxCOL_REORDERABLE | |
43 | }; | |
44 | ||
45 | // ---------------------------------------------------------------------------- | |
dcb6cbec VZ |
46 | // wxHeaderColumn: interface for a column in a header of controls such as |
47 | // wxListCtrl, wxDataViewCtrl or wxGrid | |
56873923 VZ |
48 | // ---------------------------------------------------------------------------- |
49 | ||
dcb6cbec | 50 | class WXDLLIMPEXP_CORE wxHeaderColumn |
56873923 VZ |
51 | { |
52 | public: | |
53 | // ctors and dtor | |
54 | // -------------- | |
55 | ||
56 | /* | |
57 | Derived classes must provide ctors with the following signatures | |
58 | (notice that they shouldn't be explicit to allow passing strings/bitmaps | |
59 | directly to methods such wxHeaderCtrl::AppendColumn()): | |
60 | wxHeaderColumn(const wxString& title, | |
61 | int width = wxCOL_WIDTH_DEFAULT, | |
62 | wxAlignment align = wxALIGN_NOT, | |
63 | int flags = wxCOL_DEFAULT_FLAGS); | |
64 | wxHeaderColumn(const wxBitmap &bitmap, | |
65 | int width = wxDVC_DEFAULT_WIDTH, | |
66 | wxAlignment align = wxALIGN_CENTER, | |
67 | int flags = wxCOL_DEFAULT_FLAGS); | |
68 | */ | |
69 | ||
a7d40369 VZ |
70 | // virtual dtor for the base class to avoid gcc warnings even though we |
71 | // don't normally delete the objects of this class via a pointer to | |
dcb6cbec VZ |
72 | // wxHeaderColumn so it's not necessary, strictly speaking |
73 | virtual ~wxHeaderColumn() { } | |
a7d40369 | 74 | |
dcb6cbec VZ |
75 | // getters for various attributes |
76 | // ------------------------------ | |
56873923 | 77 | |
dcb6cbec VZ |
78 | // notice that wxHeaderColumn only provides getters as this is all the |
79 | // wxHeaderCtrl needs, various derived class must also provide some way to | |
80 | // change these attributes but this can be done either at the column level | |
81 | // (in which case they should inherit from wxSettableHeaderColumn) or via | |
82 | // the methods of the main control in which case you don't need setters in | |
83 | // the column class at all | |
56873923 VZ |
84 | |
85 | // title is the string shown for this column | |
56873923 VZ |
86 | virtual wxString GetTitle() const = 0; |
87 | ||
88 | // bitmap shown (instead of text) in the column header | |
56873923 VZ |
89 | virtual wxBitmap GetBitmap() const = 0; \ |
90 | ||
91 | // width of the column in pixels, can be set to wxCOL_WIDTH_DEFAULT meaning | |
92 | // unspecified/default | |
56873923 VZ |
93 | virtual int GetWidth() const = 0; |
94 | ||
95 | // minimal width can be set for resizeable columns to forbid resizing them | |
96 | // below the specified size (set to 0 to remove) | |
56873923 VZ |
97 | virtual int GetMinWidth() const = 0; |
98 | ||
99 | // alignment of the text: wxALIGN_CENTRE, wxALIGN_LEFT or wxALIGN_RIGHT | |
56873923 VZ |
100 | virtual wxAlignment GetAlignment() const = 0; |
101 | ||
56873923 VZ |
102 | |
103 | // flags manipulations: | |
104 | // -------------------- | |
105 | ||
dcb6cbec VZ |
106 | // notice that while we make GetFlags() pure virtual here and implement the |
107 | // individual flags access in terms of it, for some derived classes it is | |
108 | // more natural to implement access to each flag individually, in which | |
109 | // case they can use our GetFromIndividualFlags() helper below to implement | |
110 | // GetFlags() | |
56873923 | 111 | |
dcb6cbec | 112 | // retrieve all column flags at once: combination of wxCOL_XXX values above |
56873923 VZ |
113 | virtual int GetFlags() const = 0; |
114 | ||
56873923 VZ |
115 | bool HasFlag(int flag) const { return (GetFlags() & flag) != 0; } |
116 | ||
117 | ||
118 | // wxCOL_RESIZABLE | |
56873923 VZ |
119 | virtual bool IsResizeable() const |
120 | { return HasFlag(wxCOL_RESIZABLE); } | |
121 | ||
122 | // wxCOL_SORTABLE | |
56873923 VZ |
123 | virtual bool IsSortable() const |
124 | { return HasFlag(wxCOL_SORTABLE); } | |
125 | ||
126 | // wxCOL_REORDERABLE | |
56873923 VZ |
127 | virtual bool IsReorderable() const |
128 | { return HasFlag(wxCOL_REORDERABLE); } | |
129 | ||
130 | // wxCOL_HIDDEN | |
56873923 VZ |
131 | virtual bool IsHidden() const |
132 | { return HasFlag(wxCOL_HIDDEN); } | |
78fd3d12 VZ |
133 | bool IsShown() const |
134 | { return !IsHidden(); } | |
56873923 | 135 | |
e2bfe673 VZ |
136 | |
137 | // sorting | |
138 | // ------- | |
139 | ||
dcb6cbec | 140 | // return true if the column is the one currently used for sorting |
e2bfe673 VZ |
141 | virtual bool IsSortKey() const = 0; |
142 | ||
56873923 | 143 | // for sortable columns indicate whether we should sort in ascending or |
e2bfe673 | 144 | // descending order (this should only be taken into account if IsSortKey()) |
dcb6cbec VZ |
145 | virtual bool IsSortOrderAscending() const = 0; |
146 | ||
147 | protected: | |
148 | // helper for the class overriding IsXXX() | |
149 | int GetFromIndividualFlags() const; | |
150 | }; | |
151 | ||
152 | // ---------------------------------------------------------------------------- | |
153 | // wxSettableHeaderColumn: column which allows to change its fields too | |
154 | // ---------------------------------------------------------------------------- | |
155 | ||
de150f6a | 156 | class WXDLLIMPEXP_CORE wxSettableHeaderColumn : public wxHeaderColumn |
dcb6cbec VZ |
157 | { |
158 | public: | |
159 | virtual void SetTitle(const wxString& title) = 0; | |
160 | virtual void SetBitmap(const wxBitmap& bitmap) = 0; | |
161 | virtual void SetWidth(int width) = 0; | |
162 | virtual void SetMinWidth(int minWidth) = 0; | |
163 | virtual void SetAlignment(wxAlignment align) = 0; | |
164 | ||
165 | // see comment for wxHeaderColumn::GetFlags() about the relationship | |
166 | // between SetFlags() and Set{Sortable,Reorderable,...} | |
167 | ||
168 | // change, set, clear, toggle or test for any individual flag | |
169 | virtual void SetFlags(int flags) = 0; | |
170 | void ChangeFlag(int flag, bool set); | |
171 | void SetFlag(int flag); | |
172 | void ClearFlag(int flag); | |
173 | void ToggleFlag(int flag); | |
174 | ||
175 | virtual void SetResizeable(bool resizeable) | |
176 | { ChangeFlag(wxCOL_RESIZABLE, resizeable); } | |
177 | virtual void SetSortable(bool sortable) | |
178 | { ChangeFlag(wxCOL_SORTABLE, sortable); } | |
179 | virtual void SetReorderable(bool reorderable) | |
180 | { ChangeFlag(wxCOL_REORDERABLE, reorderable); } | |
181 | virtual void SetHidden(bool hidden) | |
182 | { ChangeFlag(wxCOL_HIDDEN, hidden); } | |
183 | ||
184 | virtual void SetAsSortKey(bool sort = true) = 0; | |
185 | void UnsetAsSortKey() { SetAsSortKey(false); } | |
186 | ||
56873923 VZ |
187 | virtual void SetSortOrder(bool ascending) = 0; |
188 | void ToggleSortOrder() { SetSortOrder(!IsSortOrderAscending()); } | |
56873923 VZ |
189 | |
190 | protected: | |
dcb6cbec VZ |
191 | // helper for the class overriding individual SetXXX() methods instead of |
192 | // overriding SetFlags() | |
56873923 | 193 | void SetIndividualFlags(int flags); |
56873923 VZ |
194 | }; |
195 | ||
e2bfe673 | 196 | // ---------------------------------------------------------------------------- |
dcb6cbec | 197 | // wxHeaderColumnSimple: trivial generic implementation of wxHeaderColumn |
e2bfe673 | 198 | // ---------------------------------------------------------------------------- |
56873923 | 199 | |
dcb6cbec | 200 | class wxHeaderColumnSimple : public wxSettableHeaderColumn |
e2bfe673 VZ |
201 | { |
202 | public: | |
203 | // ctors and dtor | |
204 | wxHeaderColumnSimple(const wxString& title, | |
205 | int width = wxCOL_WIDTH_DEFAULT, | |
206 | wxAlignment align = wxALIGN_NOT, | |
207 | int flags = wxCOL_DEFAULT_FLAGS) | |
208 | : m_title(title), | |
209 | m_width(width), | |
210 | m_align(align), | |
211 | m_flags(flags) | |
212 | { | |
213 | Init(); | |
214 | } | |
215 | ||
216 | wxHeaderColumnSimple(const wxBitmap& bitmap, | |
217 | int width = wxCOL_WIDTH_DEFAULT, | |
218 | wxAlignment align = wxALIGN_CENTER, | |
219 | int flags = wxCOL_DEFAULT_FLAGS) | |
220 | : m_bitmap(bitmap), | |
221 | m_width(width), | |
222 | m_align(align), | |
223 | m_flags(flags) | |
224 | { | |
225 | Init(); | |
226 | } | |
227 | ||
228 | // implement base class pure virtuals | |
229 | virtual void SetTitle(const wxString& title) { m_title = title; } | |
230 | virtual wxString GetTitle() const { return m_title; } | |
231 | ||
232 | virtual void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; } | |
233 | wxBitmap GetBitmap() const { return m_bitmap; } | |
234 | ||
235 | virtual void SetWidth(int width) { m_width = width; } | |
236 | virtual int GetWidth() const { return m_width; } | |
237 | ||
238 | virtual void SetMinWidth(int minWidth) { m_minWidth = minWidth; } | |
239 | virtual int GetMinWidth() const { return m_minWidth; } | |
240 | ||
241 | virtual void SetAlignment(wxAlignment align) { m_align = align; } | |
242 | virtual wxAlignment GetAlignment() const { return m_align; } | |
243 | ||
244 | virtual void SetFlags(int flags) { m_flags = flags; } | |
245 | virtual int GetFlags() const { return m_flags; } | |
246 | ||
247 | virtual void SetAsSortKey(bool sort = true) { m_sort = sort; } | |
248 | virtual bool IsSortKey() const { return m_sort; } | |
249 | ||
250 | virtual void SetSortOrder(bool ascending) { m_sortAscending = ascending; } | |
251 | virtual bool IsSortOrderAscending() const { return m_sortAscending; } | |
252 | ||
253 | private: | |
254 | // common part of all ctors | |
255 | void Init() | |
256 | { | |
257 | m_minWidth = 0; | |
258 | m_sort = false; | |
259 | m_sortAscending = true; | |
260 | } | |
261 | ||
262 | wxString m_title; | |
263 | wxBitmap m_bitmap; | |
264 | int m_width, | |
265 | m_minWidth; | |
266 | wxAlignment m_align; | |
267 | int m_flags; | |
268 | bool m_sort, | |
269 | m_sortAscending; | |
270 | }; | |
56873923 VZ |
271 | #endif // _WX_HEADERCOL_H_ |
272 |