]> git.saurik.com Git - wxWidgets.git/blame - include/wx/headercol.h
Ensure that we have an available backend for wxWebView compilation.
[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
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
e721a2a2
VZ
16#if wxUSE_HEADERCTRL
17
56873923
VZ
18// ----------------------------------------------------------------------------
19// constants
20// ----------------------------------------------------------------------------
21
22enum
23{
24 // special value for column width meaning unspecified/default
d0154e3a
VS
25 wxCOL_WIDTH_DEFAULT = -1,
26
27 // size the column automatically to fit all values
28 wxCOL_WIDTH_AUTOSIZE = -2
56873923
VZ
29};
30
31// bit masks for the various column attributes
32enum
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// ----------------------------------------------------------------------------
dcb6cbec
VZ
51// wxHeaderColumn: interface for a column in a header of controls such as
52// wxListCtrl, wxDataViewCtrl or wxGrid
56873923
VZ
53// ----------------------------------------------------------------------------
54
dcb6cbec 55class WXDLLIMPEXP_CORE wxHeaderColumn
56873923
VZ
56{
57public:
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
a7d40369
VZ
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
dcb6cbec
VZ
77 // wxHeaderColumn so it's not necessary, strictly speaking
78 virtual ~wxHeaderColumn() { }
a7d40369 79
dcb6cbec
VZ
80 // getters for various attributes
81 // ------------------------------
56873923 82
dcb6cbec
VZ
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
56873923
VZ
89
90 // title is the string shown for this column
56873923
VZ
91 virtual wxString GetTitle() const = 0;
92
93 // bitmap shown (instead of text) in the column header
56873923
VZ
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
56873923
VZ
98 virtual int GetWidth() const = 0;
99
d13b34d3 100 // minimal width can be set for resizable columns to forbid resizing them
56873923 101 // below the specified size (set to 0 to remove)
56873923
VZ
102 virtual int GetMinWidth() const = 0;
103
104 // alignment of the text: wxALIGN_CENTRE, wxALIGN_LEFT or wxALIGN_RIGHT
56873923
VZ
105 virtual wxAlignment GetAlignment() const = 0;
106
56873923
VZ
107
108 // flags manipulations:
109 // --------------------
110
dcb6cbec
VZ
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()
56873923 116
dcb6cbec 117 // retrieve all column flags at once: combination of wxCOL_XXX values above
56873923
VZ
118 virtual int GetFlags() const = 0;
119
56873923
VZ
120 bool HasFlag(int flag) const { return (GetFlags() & flag) != 0; }
121
122
123 // wxCOL_RESIZABLE
56873923
VZ
124 virtual bool IsResizeable() const
125 { return HasFlag(wxCOL_RESIZABLE); }
126
127 // wxCOL_SORTABLE
56873923
VZ
128 virtual bool IsSortable() const
129 { return HasFlag(wxCOL_SORTABLE); }
130
131 // wxCOL_REORDERABLE
56873923
VZ
132 virtual bool IsReorderable() const
133 { return HasFlag(wxCOL_REORDERABLE); }
134
135 // wxCOL_HIDDEN
56873923
VZ
136 virtual bool IsHidden() const
137 { return HasFlag(wxCOL_HIDDEN); }
78fd3d12
VZ
138 bool IsShown() const
139 { return !IsHidden(); }
56873923 140
e2bfe673
VZ
141
142 // sorting
143 // -------
144
dcb6cbec 145 // return true if the column is the one currently used for sorting
e2bfe673
VZ
146 virtual bool IsSortKey() const = 0;
147
56873923 148 // for sortable columns indicate whether we should sort in ascending or
e2bfe673 149 // descending order (this should only be taken into account if IsSortKey())
dcb6cbec
VZ
150 virtual bool IsSortOrderAscending() const = 0;
151
152protected:
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
de150f6a 161class WXDLLIMPEXP_CORE wxSettableHeaderColumn : public wxHeaderColumn
dcb6cbec
VZ
162{
163public:
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
d13b34d3
DS
180 virtual void SetResizeable(bool resizable)
181 { ChangeFlag(wxCOL_RESIZABLE, resizable); }
dcb6cbec
VZ
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
56873923
VZ
192 virtual void SetSortOrder(bool ascending) = 0;
193 void ToggleSortOrder() { SetSortOrder(!IsSortOrderAscending()); }
56873923
VZ
194
195protected:
dcb6cbec
VZ
196 // helper for the class overriding individual SetXXX() methods instead of
197 // overriding SetFlags()
56873923 198 void SetIndividualFlags(int flags);
56873923
VZ
199};
200
e2bfe673 201// ----------------------------------------------------------------------------
dcb6cbec 202// wxHeaderColumnSimple: trivial generic implementation of wxHeaderColumn
e2bfe673 203// ----------------------------------------------------------------------------
56873923 204
dcb6cbec 205class wxHeaderColumnSimple : public wxSettableHeaderColumn
e2bfe673
VZ
206{
207public:
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
258private:
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};
e721a2a2
VZ
276
277#endif // wxUSE_HEADERCTRL
278
56873923
VZ
279#endif // _WX_HEADERCOL_H_
280