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