]> git.saurik.com Git - wxWidgets.git/blob - include/wx/headerctrl.h
generic implementation of wxHeaderCtrl API so far
[wxWidgets.git] / include / wx / headerctrl.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/headerctrl.h
3 // Purpose: wxHeaderCtrlBase class: interface of wxHeaderCtrl
4 // Author: Vadim Zeitlin
5 // Created: 2008-12-01
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_HEADERCTRL_H_
12 #define _WX_HEADERCTRL_H_
13
14 #include "wx/control.h"
15
16 #include "wx/headercol.h"
17
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
21
22 // ----------------------------------------------------------------------------
23 // constants
24 // ----------------------------------------------------------------------------
25
26 enum
27 {
28 // allow column drag and drop
29 wxHD_DRAGDROP = 0x0001,
30
31 // style used by default when creating the control
32 wxHD_DEFAULT_STYLE = wxHD_DRAGDROP
33 };
34
35 extern WXDLLIMPEXP_DATA_CORE(const char) wxHeaderCtrlNameStr[];
36
37 class WXDLLIMPEXP_FWD_CORE wxHeaderColumn;
38
39 // ----------------------------------------------------------------------------
40 // wxHeaderCtrlBase defines the interface of a header control
41 // ----------------------------------------------------------------------------
42
43 class WXDLLIMPEXP_CORE wxHeaderCtrlBase : public wxControl
44 {
45 public:
46 /*
47 Derived classes must provide default ctor as well as a ctor and
48 Create() function with the following signatures:
49
50 wxHeaderCtrl(wxWindow *parent,
51 wxWindowID winid = wxID_ANY,
52 const wxPoint& pos = wxDefaultPosition,
53 const wxSize& size = wxDefaultSize,
54 long style = 0,
55 const wxString& name = wxHeaderCtrlNameStr);
56
57 bool Create(wxWindow *parent,
58 wxWindowID winid = wxID_ANY,
59 const wxPoint& pos = wxDefaultPosition,
60 const wxSize& size = wxDefaultSize,
61 long style = 0,
62 const wxString& name = wxHeaderCtrlNameStr);
63 */
64
65 // managing the columns
66 // --------------------
67
68 // return the number of columns in the control
69 unsigned int GetColumnCount() const { return DoGetCount(); }
70
71 // return whether the control has any columns
72 bool IsEmpty() const { return GetColumnCount() == 0; }
73
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)
77 {
78 wxCHECK_RET( idx <= GetColumnCount(), "invalid column index" );
79
80 DoInsert(col, idx);
81 }
82
83 // append the column to the end of the control
84 void AppendColumn(const wxHeaderColumn& col)
85 {
86 DoInsert(col, GetColumnCount());
87 }
88
89 // delete the column at the given index
90 void DeleteColumn(unsigned int idx)
91 {
92 wxCHECK_RET( idx < GetColumnCount(), "invalid column index" );
93
94 DoDelete(idx);
95 }
96
97 // delete all the existing columns
98 void DeleteAllColumns();
99
100
101 // modifying columns
102 // -----------------
103
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)
107 {
108 wxCHECK_RET( idx < GetColumnCount(), "invalid column index" );
109
110 DoShowColumn(idx, show);
111 }
112
113 void HideColumn(unsigned int idx)
114 {
115 ShowColumn(idx, false);
116 }
117
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)
122 {
123 wxCHECK_RET( sortOrder == 0 || sortOrder == 1 || sortOrder == -1,
124 "invalid sort order value" );
125
126 wxCHECK_RET( idx < GetColumnCount(), "invalid column index" );
127
128 DoShowSortIndicator(idx, sortOrder);
129 }
130
131 // remove the sort indicator from the given column
132 void RemoveSortIndicator(unsigned int idx)
133 {
134 DoShowSortIndicator(idx, -1);
135 }
136
137
138 // implementation only from now on
139 // -------------------------------
140
141 // the user doesn't need to TAB to this control
142 virtual bool AcceptsFocusFromKeyboard() const { return false; }
143
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
146 // DoScrollHorz()
147 virtual void ScrollWindow(int dx, int dy, const wxRect *rect = NULL);
148
149 private:
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;
156
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; }
159 };
160
161 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
162 #include "wx/msw/headerctrl.h"
163 #else
164 #define wxHAS_GENERIC_HEADERCTRL
165 #include "wx/generic/headerctrlg.h"
166 #endif // platform
167
168 #endif // _WX_HEADERCTRL_H_