1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/headerctrl.h
3 // Purpose: wxHeaderCtrlBase class: interface of wxHeaderCtrl
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_HEADERCTRL_H_
12 #define _WX_HEADERCTRL_H_
14 #include "wx/control.h"
16 #include "wx/headercol.h"
18 // notice that the classes in this header are defined in the core library even
19 // although currently they're only used by wxGrid which is in wxAdv because we
20 // plan to use it in wxListCtrl which is in core too in the future
22 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
28 // allow column drag and drop
29 wxHD_DRAGDROP
= 0x0001,
31 // style used by default when creating the control
32 wxHD_DEFAULT_STYLE
= wxHD_DRAGDROP
35 extern WXDLLIMPEXP_DATA_CORE(const char) wxHeaderCtrlNameStr
[];
37 class WXDLLIMPEXP_FWD_CORE wxHeaderColumn
;
39 // ----------------------------------------------------------------------------
40 // wxHeaderCtrlBase defines the interface of a header control
41 // ----------------------------------------------------------------------------
43 class WXDLLIMPEXP_CORE wxHeaderCtrlBase
: public wxControl
47 Derived classes must provide default ctor as well as a ctor and
48 Create() function with the following signatures:
50 wxHeaderCtrl(wxWindow *parent,
51 wxWindowID winid = wxID_ANY,
52 const wxPoint& pos = wxDefaultPosition,
53 const wxSize& size = wxDefaultSize,
55 const wxString& name = wxHeaderCtrlNameStr);
57 bool Create(wxWindow *parent,
58 wxWindowID winid = wxID_ANY,
59 const wxPoint& pos = wxDefaultPosition,
60 const wxSize& size = wxDefaultSize,
62 const wxString& name = wxHeaderCtrlNameStr);
65 // managing the columns
66 // --------------------
68 // return the number of columns in the control
69 unsigned int GetColumnCount() const { return DoGetCount(); }
71 // return whether the control has any columns
72 bool IsEmpty() const { return GetColumnCount() == 0; }
74 // insert the column at the given position, using GetColumnCount() as
75 // position appends it at the end
76 void InsertColumn(const wxHeaderColumn
& col
, unsigned int idx
)
78 wxCHECK_RET( idx
<= GetColumnCount(), "invalid column index" );
83 // append the column to the end of the control
84 void AppendColumn(const wxHeaderColumn
& col
)
86 DoInsert(col
, GetColumnCount());
89 // delete the column at the given index
90 void DeleteColumn(unsigned int idx
)
92 wxCHECK_RET( idx
< GetColumnCount(), "invalid column index" );
97 // delete all the existing columns
98 void DeleteAllColumns();
104 // show or hide the column, notice that even when a column is hidden we
105 // still account for it when using indices
106 void ShowColumn(unsigned int idx
, bool show
= true)
108 wxCHECK_RET( idx
< GetColumnCount(), "invalid column index" );
110 DoShowColumn(idx
, show
);
113 void HideColumn(unsigned int idx
)
115 ShowColumn(idx
, false);
118 // indicate that the column is used for sorting in ascending order if
119 // sortOrder is true, for sorting in descending order if it is false or not
120 // used for sorting at all if it is -1
121 void ShowSortIndicator(unsigned int idx
, int sortOrder
)
123 wxCHECK_RET( sortOrder
== 0 || sortOrder
== 1 || sortOrder
== -1,
124 "invalid sort order value" );
126 wxCHECK_RET( idx
< GetColumnCount(), "invalid column index" );
128 DoShowSortIndicator(idx
, sortOrder
);
131 // remove the sort indicator from the given column
132 void RemoveSortIndicator(unsigned int idx
)
134 DoShowSortIndicator(idx
, -1);
138 // implementation only from now on
139 // -------------------------------
141 // the user doesn't need to TAB to this control
142 virtual bool AcceptsFocusFromKeyboard() const { return false; }
144 // this method is only overridden in order to synchronize the control with
145 // the main window when it is scrolled, the derived class must implement
147 virtual void ScrollWindow(int dx
, int dy
, const wxRect
*rect
= NULL
);
150 virtual unsigned int DoGetCount() const = 0;
151 virtual void DoInsert(const wxHeaderColumn
& col
, unsigned int idx
) = 0;
152 virtual void DoDelete(unsigned int idx
) = 0;
153 virtual void DoShowColumn(unsigned int idx
, bool show
) = 0;
154 virtual void DoShowSortIndicator(unsigned int idx
, int sortOrder
) = 0;
155 virtual void DoScrollHorz(int dx
) = 0;
157 // this window doesn't look nice with the border so don't use it by default
158 virtual wxBorder
GetDefaultBorder() const { return wxBORDER_NONE
; }
161 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
162 #include "wx/msw/headerctrl.h"
164 #define wxHAS_GENERIC_HEADERCTRL
165 #include "wx/generic/headerctrlg.h"
168 #endif // _WX_HEADERCTRL_H_