]> git.saurik.com Git - wxWidgets.git/blob - include/wx/headercol.h
Correct alignment of menu accelerator strings in owner-drawn menus.
[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 // 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 #if wxUSE_HEADERCTRL
17
18 // ----------------------------------------------------------------------------
19 // constants
20 // ----------------------------------------------------------------------------
21
22 enum
23 {
24 // special value for column width meaning unspecified/default
25 wxCOL_WIDTH_DEFAULT = -1
26 };
27
28 // bit masks for the various column attributes
29 enum
30 {
31 // column can be resized (included in default flags)
32 wxCOL_RESIZABLE = 1,
33
34 // column can be clicked to toggle the sort order by its contents
35 wxCOL_SORTABLE = 2,
36
37 // column can be dragged to change its order (included in default)
38 wxCOL_REORDERABLE = 4,
39
40 // column is not shown at all
41 wxCOL_HIDDEN = 8,
42
43 // default flags for wxHeaderColumn ctor
44 wxCOL_DEFAULT_FLAGS = wxCOL_RESIZABLE | wxCOL_REORDERABLE
45 };
46
47 // ----------------------------------------------------------------------------
48 // wxHeaderColumn: interface for a column in a header of controls such as
49 // wxListCtrl, wxDataViewCtrl or wxGrid
50 // ----------------------------------------------------------------------------
51
52 class WXDLLIMPEXP_CORE wxHeaderColumn
53 {
54 public:
55 // ctors and dtor
56 // --------------
57
58 /*
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);
70 */
71
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() { }
76
77 // getters for various attributes
78 // ------------------------------
79
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
86
87 // title is the string shown for this column
88 virtual wxString GetTitle() const = 0;
89
90 // bitmap shown (instead of text) in the column header
91 virtual wxBitmap GetBitmap() const = 0; \
92
93 // width of the column in pixels, can be set to wxCOL_WIDTH_DEFAULT meaning
94 // unspecified/default
95 virtual int GetWidth() const = 0;
96
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;
100
101 // alignment of the text: wxALIGN_CENTRE, wxALIGN_LEFT or wxALIGN_RIGHT
102 virtual wxAlignment GetAlignment() const = 0;
103
104
105 // flags manipulations:
106 // --------------------
107
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
112 // GetFlags()
113
114 // retrieve all column flags at once: combination of wxCOL_XXX values above
115 virtual int GetFlags() const = 0;
116
117 bool HasFlag(int flag) const { return (GetFlags() & flag) != 0; }
118
119
120 // wxCOL_RESIZABLE
121 virtual bool IsResizeable() const
122 { return HasFlag(wxCOL_RESIZABLE); }
123
124 // wxCOL_SORTABLE
125 virtual bool IsSortable() const
126 { return HasFlag(wxCOL_SORTABLE); }
127
128 // wxCOL_REORDERABLE
129 virtual bool IsReorderable() const
130 { return HasFlag(wxCOL_REORDERABLE); }
131
132 // wxCOL_HIDDEN
133 virtual bool IsHidden() const
134 { return HasFlag(wxCOL_HIDDEN); }
135 bool IsShown() const
136 { return !IsHidden(); }
137
138
139 // sorting
140 // -------
141
142 // return true if the column is the one currently used for sorting
143 virtual bool IsSortKey() const = 0;
144
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;
148
149 protected:
150 // helper for the class overriding IsXXX()
151 int GetFromIndividualFlags() const;
152 };
153
154 // ----------------------------------------------------------------------------
155 // wxSettableHeaderColumn: column which allows to change its fields too
156 // ----------------------------------------------------------------------------
157
158 class WXDLLIMPEXP_CORE wxSettableHeaderColumn : public wxHeaderColumn
159 {
160 public:
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;
166
167 // see comment for wxHeaderColumn::GetFlags() about the relationship
168 // between SetFlags() and Set{Sortable,Reorderable,...}
169
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);
176
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); }
185
186 virtual void SetAsSortKey(bool sort = true) = 0;
187 void UnsetAsSortKey() { SetAsSortKey(false); }
188
189 virtual void SetSortOrder(bool ascending) = 0;
190 void ToggleSortOrder() { SetSortOrder(!IsSortOrderAscending()); }
191
192 protected:
193 // helper for the class overriding individual SetXXX() methods instead of
194 // overriding SetFlags()
195 void SetIndividualFlags(int flags);
196 };
197
198 // ----------------------------------------------------------------------------
199 // wxHeaderColumnSimple: trivial generic implementation of wxHeaderColumn
200 // ----------------------------------------------------------------------------
201
202 class wxHeaderColumnSimple : public wxSettableHeaderColumn
203 {
204 public:
205 // ctors and dtor
206 wxHeaderColumnSimple(const wxString& title,
207 int width = wxCOL_WIDTH_DEFAULT,
208 wxAlignment align = wxALIGN_NOT,
209 int flags = wxCOL_DEFAULT_FLAGS)
210 : m_title(title),
211 m_width(width),
212 m_align(align),
213 m_flags(flags)
214 {
215 Init();
216 }
217
218 wxHeaderColumnSimple(const wxBitmap& bitmap,
219 int width = wxCOL_WIDTH_DEFAULT,
220 wxAlignment align = wxALIGN_CENTER,
221 int flags = wxCOL_DEFAULT_FLAGS)
222 : m_bitmap(bitmap),
223 m_width(width),
224 m_align(align),
225 m_flags(flags)
226 {
227 Init();
228 }
229
230 // implement base class pure virtuals
231 virtual void SetTitle(const wxString& title) { m_title = title; }
232 virtual wxString GetTitle() const { return m_title; }
233
234 virtual void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; }
235 wxBitmap GetBitmap() const { return m_bitmap; }
236
237 virtual void SetWidth(int width) { m_width = width; }
238 virtual int GetWidth() const { return m_width; }
239
240 virtual void SetMinWidth(int minWidth) { m_minWidth = minWidth; }
241 virtual int GetMinWidth() const { return m_minWidth; }
242
243 virtual void SetAlignment(wxAlignment align) { m_align = align; }
244 virtual wxAlignment GetAlignment() const { return m_align; }
245
246 virtual void SetFlags(int flags) { m_flags = flags; }
247 virtual int GetFlags() const { return m_flags; }
248
249 virtual void SetAsSortKey(bool sort = true) { m_sort = sort; }
250 virtual bool IsSortKey() const { return m_sort; }
251
252 virtual void SetSortOrder(bool ascending) { m_sortAscending = ascending; }
253 virtual bool IsSortOrderAscending() const { return m_sortAscending; }
254
255 private:
256 // common part of all ctors
257 void Init()
258 {
259 m_minWidth = 0;
260 m_sort = false;
261 m_sortAscending = true;
262 }
263
264 wxString m_title;
265 wxBitmap m_bitmap;
266 int m_width,
267 m_minWidth;
268 wxAlignment m_align;
269 int m_flags;
270 bool m_sort,
271 m_sortAscending;
272 };
273
274 #endif // wxUSE_HEADERCTRL
275
276 #endif // _WX_HEADERCOL_H_
277