]> git.saurik.com Git - wxWidgets.git/blob - include/wx/headercol.h
deprecate wxStringEq
[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 // ----------------------------------------------------------------------------
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 // ----------------------------------------------------------------------------
46 // wxHeaderColumnBase: interface for a column in a header of controls such as
47 // wxListCtrl, wxDataViewCtrl or wxGrid
48 // ----------------------------------------------------------------------------
49
50 class WXDLLIMPEXP_CORE wxHeaderColumnBase
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
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
72 // wxHeaderColumnBase so it's not necessary, strictly speaking
73 virtual ~wxHeaderColumnBase() { }
74
75
76 // setters and getters for various attributes
77 // ------------------------------------------
78
79 // title is the string shown for this column
80 virtual void SetTitle(const wxString& title) = 0;
81 virtual wxString GetTitle() const = 0;
82
83 // bitmap shown (instead of text) in the column header
84 virtual void SetBitmap(const wxBitmap& bitmap) = 0;
85 virtual wxBitmap GetBitmap() const = 0; \
86
87 // width of the column in pixels, can be set to wxCOL_WIDTH_DEFAULT meaning
88 // unspecified/default
89 virtual void SetWidth(int width) = 0;
90 virtual int GetWidth() const = 0;
91
92 // minimal width can be set for resizeable columns to forbid resizing them
93 // below the specified size (set to 0 to remove)
94 virtual void SetMinWidth(int minWidth) = 0;
95 virtual int GetMinWidth() const = 0;
96
97 // alignment of the text: wxALIGN_CENTRE, wxALIGN_LEFT or wxALIGN_RIGHT
98 virtual void SetAlignment(wxAlignment align) = 0;
99 virtual wxAlignment GetAlignment() const = 0;
100
101
102 // flags manipulations:
103 // --------------------
104
105 // notice that while we make Set/GetFlags() pure virtual here and implement
106 // the individual flags access in terms of them, for some derived classes
107 // it is more natural to implement access to each flag individually, in
108 // which case they can use SetIndividualFlags() and GetFromIndividualFlags()
109 // below to implement Set/GetFlags()
110
111 // set or retrieve all column flags at once: combination of wxCOL_XXX
112 // values above
113 virtual void SetFlags(int flags) = 0;
114 virtual int GetFlags() const = 0;
115
116 // change, set, clear, toggle or test for any individual flag
117 void ChangeFlag(int flag, bool set);
118 void SetFlag(int flag);
119 void ClearFlag(int flag);
120 void ToggleFlag(int flag);
121
122 bool HasFlag(int flag) const { return (GetFlags() & flag) != 0; }
123
124
125 // wxCOL_RESIZABLE
126 virtual void SetResizeable(bool resizeable)
127 { ChangeFlag(wxCOL_RESIZABLE, resizeable); }
128 virtual bool IsResizeable() const
129 { return HasFlag(wxCOL_RESIZABLE); }
130
131 // wxCOL_SORTABLE
132 virtual void SetSortable(bool sortable)
133 { ChangeFlag(wxCOL_SORTABLE, sortable); }
134 virtual bool IsSortable() const
135 { return HasFlag(wxCOL_SORTABLE); }
136
137 // wxCOL_REORDERABLE
138 virtual void SetReorderable(bool reorderable)
139 { ChangeFlag(wxCOL_REORDERABLE, reorderable); }
140 virtual bool IsReorderable() const
141 { return HasFlag(wxCOL_REORDERABLE); }
142
143 // wxCOL_HIDDEN
144 virtual void SetHidden(bool hidden)
145 { ChangeFlag(wxCOL_HIDDEN, hidden); }
146 virtual bool IsHidden() const
147 { return HasFlag(wxCOL_HIDDEN); }
148 bool IsShown() const
149 { return !IsHidden(); }
150
151
152 // sorting
153 // -------
154
155 // set this column as the one used to sort the control
156 virtual void SetAsSortKey(bool sort = true) = 0;
157 void UnsetAsSortKey() { SetAsSortKey(false); }
158
159 // return true if the column is used for sorting
160 virtual bool IsSortKey() const = 0;
161
162 // for sortable columns indicate whether we should sort in ascending or
163 // descending order (this should only be taken into account if IsSortKey())
164 virtual void SetSortOrder(bool ascending) = 0;
165 void ToggleSortOrder() { SetSortOrder(!IsSortOrderAscending()); }
166 virtual bool IsSortOrderAscending() const = 0;
167
168 protected:
169 // helpers for the class overriding Set/IsXXX()
170 void SetIndividualFlags(int flags);
171 int GetFromIndividualFlags() const;
172 };
173
174 // ----------------------------------------------------------------------------
175 // wxHeaderColumnSimple: trivial generic implementation of wxHeaderColumnBase
176 // ----------------------------------------------------------------------------
177
178 class wxHeaderColumnSimple : public wxHeaderColumnBase
179 {
180 public:
181 // ctors and dtor
182 wxHeaderColumnSimple(const wxString& title,
183 int width = wxCOL_WIDTH_DEFAULT,
184 wxAlignment align = wxALIGN_NOT,
185 int flags = wxCOL_DEFAULT_FLAGS)
186 : m_title(title),
187 m_width(width),
188 m_align(align),
189 m_flags(flags)
190 {
191 Init();
192 }
193
194 wxHeaderColumnSimple(const wxBitmap& bitmap,
195 int width = wxCOL_WIDTH_DEFAULT,
196 wxAlignment align = wxALIGN_CENTER,
197 int flags = wxCOL_DEFAULT_FLAGS)
198 : m_bitmap(bitmap),
199 m_width(width),
200 m_align(align),
201 m_flags(flags)
202 {
203 Init();
204 }
205
206 // implement base class pure virtuals
207 virtual void SetTitle(const wxString& title) { m_title = title; }
208 virtual wxString GetTitle() const { return m_title; }
209
210 virtual void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; }
211 wxBitmap GetBitmap() const { return m_bitmap; }
212
213 virtual void SetWidth(int width) { m_width = width; }
214 virtual int GetWidth() const { return m_width; }
215
216 virtual void SetMinWidth(int minWidth) { m_minWidth = minWidth; }
217 virtual int GetMinWidth() const { return m_minWidth; }
218
219 virtual void SetAlignment(wxAlignment align) { m_align = align; }
220 virtual wxAlignment GetAlignment() const { return m_align; }
221
222 virtual void SetFlags(int flags) { m_flags = flags; }
223 virtual int GetFlags() const { return m_flags; }
224
225 virtual void SetAsSortKey(bool sort = true) { m_sort = sort; }
226 virtual bool IsSortKey() const { return m_sort; }
227
228 virtual void SetSortOrder(bool ascending) { m_sortAscending = ascending; }
229 virtual bool IsSortOrderAscending() const { return m_sortAscending; }
230
231 private:
232 // common part of all ctors
233 void Init()
234 {
235 m_minWidth = 0;
236 m_sort = false;
237 m_sortAscending = true;
238 }
239
240 wxString m_title;
241 wxBitmap m_bitmap;
242 int m_width,
243 m_minWidth;
244 wxAlignment m_align;
245 int m_flags;
246 bool m_sort,
247 m_sortAscending;
248 };
249 #endif // _WX_HEADERCOL_H_
250