]> git.saurik.com Git - wxWidgets.git/blob - include/wx/headercol.h
Add undo / redo support to OSX WebKit.
[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 // size the column automatically to fit all values
28 wxCOL_WIDTH_AUTOSIZE = -2
29 };
30
31 // bit masks for the various column attributes
32 enum
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 // ----------------------------------------------------------------------------
51 // wxHeaderColumn: interface for a column in a header of controls such as
52 // wxListCtrl, wxDataViewCtrl or wxGrid
53 // ----------------------------------------------------------------------------
54
55 class WXDLLIMPEXP_CORE wxHeaderColumn
56 {
57 public:
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
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() { }
79
80 // getters for various attributes
81 // ------------------------------
82
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
89
90 // title is the string shown for this column
91 virtual wxString GetTitle() const = 0;
92
93 // bitmap shown (instead of text) in the column header
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
98 virtual int GetWidth() const = 0;
99
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;
103
104 // alignment of the text: wxALIGN_CENTRE, wxALIGN_LEFT or wxALIGN_RIGHT
105 virtual wxAlignment GetAlignment() const = 0;
106
107
108 // flags manipulations:
109 // --------------------
110
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()
116
117 // retrieve all column flags at once: combination of wxCOL_XXX values above
118 virtual int GetFlags() const = 0;
119
120 bool HasFlag(int flag) const { return (GetFlags() & flag) != 0; }
121
122
123 // wxCOL_RESIZABLE
124 virtual bool IsResizeable() const
125 { return HasFlag(wxCOL_RESIZABLE); }
126
127 // wxCOL_SORTABLE
128 virtual bool IsSortable() const
129 { return HasFlag(wxCOL_SORTABLE); }
130
131 // wxCOL_REORDERABLE
132 virtual bool IsReorderable() const
133 { return HasFlag(wxCOL_REORDERABLE); }
134
135 // wxCOL_HIDDEN
136 virtual bool IsHidden() const
137 { return HasFlag(wxCOL_HIDDEN); }
138 bool IsShown() const
139 { return !IsHidden(); }
140
141
142 // sorting
143 // -------
144
145 // return true if the column is the one currently used for sorting
146 virtual bool IsSortKey() const = 0;
147
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;
151
152 protected:
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
161 class WXDLLIMPEXP_CORE wxSettableHeaderColumn : public wxHeaderColumn
162 {
163 public:
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
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); }
188
189 virtual void SetAsSortKey(bool sort = true) = 0;
190 void UnsetAsSortKey() { SetAsSortKey(false); }
191
192 virtual void SetSortOrder(bool ascending) = 0;
193 void ToggleSortOrder() { SetSortOrder(!IsSortOrderAscending()); }
194
195 protected:
196 // helper for the class overriding individual SetXXX() methods instead of
197 // overriding SetFlags()
198 void SetIndividualFlags(int flags);
199 };
200
201 // ----------------------------------------------------------------------------
202 // wxHeaderColumnSimple: trivial generic implementation of wxHeaderColumn
203 // ----------------------------------------------------------------------------
204
205 class wxHeaderColumnSimple : public wxSettableHeaderColumn
206 {
207 public:
208 // ctors and dtor
209 wxHeaderColumnSimple(const wxString& title,
210 int width = wxCOL_WIDTH_DEFAULT,
211 wxAlignment align = wxALIGN_NOT,
212 int flags = wxCOL_DEFAULT_FLAGS)
213 : m_title(title),
214 m_width(width),
215 m_align(align),
216 m_flags(flags)
217 {
218 Init();
219 }
220
221 wxHeaderColumnSimple(const wxBitmap& bitmap,
222 int width = wxCOL_WIDTH_DEFAULT,
223 wxAlignment align = wxALIGN_CENTER,
224 int flags = wxCOL_DEFAULT_FLAGS)
225 : m_bitmap(bitmap),
226 m_width(width),
227 m_align(align),
228 m_flags(flags)
229 {
230 Init();
231 }
232
233 // implement base class pure virtuals
234 virtual void SetTitle(const wxString& title) { m_title = title; }
235 virtual wxString GetTitle() const { return m_title; }
236
237 virtual void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; }
238 wxBitmap GetBitmap() const { return m_bitmap; }
239
240 virtual void SetWidth(int width) { m_width = width; }
241 virtual int GetWidth() const { return m_width; }
242
243 virtual void SetMinWidth(int minWidth) { m_minWidth = minWidth; }
244 virtual int GetMinWidth() const { return m_minWidth; }
245
246 virtual void SetAlignment(wxAlignment align) { m_align = align; }
247 virtual wxAlignment GetAlignment() const { return m_align; }
248
249 virtual void SetFlags(int flags) { m_flags = flags; }
250 virtual int GetFlags() const { return m_flags; }
251
252 virtual void SetAsSortKey(bool sort = true) { m_sort = sort; }
253 virtual bool IsSortKey() const { return m_sort; }
254
255 virtual void SetSortOrder(bool ascending) { m_sortAscending = ascending; }
256 virtual bool IsSortOrderAscending() const { return m_sortAscending; }
257
258 private:
259 // common part of all ctors
260 void Init()
261 {
262 m_minWidth = 0;
263 m_sort = false;
264 m_sortAscending = true;
265 }
266
267 wxString m_title;
268 wxBitmap m_bitmap;
269 int m_width,
270 m_minWidth;
271 wxAlignment m_align;
272 int m_flags;
273 bool m_sort,
274 m_sortAscending;
275 };
276
277 #endif // wxUSE_HEADERCTRL
278
279 #endif // _WX_HEADERCOL_H_
280