1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/headercol.h
3 // Purpose: declaration of wxHeaderColumn class
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_HEADERCOL_H_
12 #define _WX_HEADERCOL_H_
14 #include "wx/bitmap.h"
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
22 // special value for column width meaning unspecified/default
23 wxCOL_WIDTH_DEFAULT
= -1
26 // bit masks for the various column attributes
29 // column can be resized (included in default flags)
32 // column can be clicked to toggle the sort order by its contents
35 // column can be dragged to change its order (included in default)
36 wxCOL_REORDERABLE
= 4,
38 // column is not shown at all
41 // default flags for wxHeaderColumn ctor
42 wxCOL_DEFAULT_FLAGS
= wxCOL_RESIZABLE
| wxCOL_REORDERABLE
45 // ----------------------------------------------------------------------------
46 // wxHeaderColumnBase: interface for a column in a header of controls such as
47 // wxListCtrl, wxDataViewCtrl or wxGrid
48 // ----------------------------------------------------------------------------
50 class WXDLLIMPEXP_CORE wxHeaderColumnBase
: public wxObject
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);
71 // setters and getters for various attributes
72 // ------------------------------------------
74 // title is the string shown for this column
75 virtual void SetTitle(const wxString
& title
) = 0;
76 virtual wxString
GetTitle() const = 0;
78 // bitmap shown (instead of text) in the column header
79 virtual void SetBitmap(const wxBitmap
& bitmap
) = 0;
80 virtual wxBitmap
GetBitmap() const = 0; \
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;
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;
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;
96 // arbitrary client data associated with the column (currently only
97 // implemented in MSW because it is used in MSW wxDataViewCtrl
99 virtual void SetClientData(wxUIntPtr
WXUNUSED(data
))
100 { wxFAIL_MSG("not implemented"); }
101 virtual wxUIntPtr
GetClientData() const
105 // flags manipulations:
106 // --------------------
108 // notice that while we make Set/GetFlags() pure virtual here and implement
109 // the individual flags access in terms of them, for some derived classes
110 // it is more natural to implement access to each flag individually, in
111 // which case they can use SetIndividualFlags() and GetFromIndividualFlags()
112 // below to implement Set/GetFlags()
114 // set or retrieve all column flags at once: combination of wxCOL_XXX
116 virtual void SetFlags(int flags
) = 0;
117 virtual int GetFlags() const = 0;
119 // change, set, clear, toggle or test for any individual flag
120 void ChangeFlag(int flag
, bool set
);
121 void SetFlag(int flag
);
122 void ClearFlag(int flag
);
123 void ToggleFlag(int flag
);
125 bool HasFlag(int flag
) const { return (GetFlags() & flag
) != 0; }
129 virtual void SetResizeable(bool resizeable
)
130 { ChangeFlag(wxCOL_RESIZABLE
, resizeable
); }
131 virtual bool IsResizeable() const
132 { return HasFlag(wxCOL_RESIZABLE
); }
135 virtual void SetSortable(bool sortable
)
136 { ChangeFlag(wxCOL_SORTABLE
, sortable
); }
137 virtual bool IsSortable() const
138 { return HasFlag(wxCOL_SORTABLE
); }
141 virtual void SetReorderable(bool reorderable
)
142 { ChangeFlag(wxCOL_REORDERABLE
, reorderable
); }
143 virtual bool IsReorderable() const
144 { return HasFlag(wxCOL_REORDERABLE
); }
147 virtual void SetHidden(bool hidden
)
148 { ChangeFlag(wxCOL_HIDDEN
, hidden
); }
149 virtual bool IsHidden() const
150 { return HasFlag(wxCOL_HIDDEN
); }
152 { return !IsHidden(); }
154 // for sortable columns indicate whether we should sort in ascending or
156 virtual void SetSortOrder(bool ascending
) = 0;
157 void ToggleSortOrder() { SetSortOrder(!IsSortOrderAscending()); }
158 virtual bool IsSortOrderAscending() const = 0;
161 // helpers for the class overriding Set/IsXXX()
162 void SetIndividualFlags(int flags
);
163 int GetFromIndividualFlags() const;
166 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
167 #include "wx/msw/headercol.h"
169 #define wxHAS_GENERIC_HEADERCOL
170 #include "wx/generic/headercolg.h"
173 #endif // _WX_HEADERCOL_H_