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