]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dataview.h
native implementation of wxDirDialog for wxCocoa (patch 1403780)
[wxWidgets.git] / include / wx / dataview.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/dataview.h
3 // Purpose: wxDataViewCtrl base classes
4 // Author: Robert Roebling
5 // Modified by:
6 // Created: 08.01.06
7 // RCS-ID: $Id$
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DATAVIEW_H_BASE_
13 #define _WX_DATAVIEW_H_BASE_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_DATAVIEWCTRL
18
19 #include "wx/control.h"
20 #include "wx/textctrl.h"
21 #include "wx/bitmap.h"
22 #include "wx/variant.h"
23
24 // ----------------------------------------------------------------------------
25 // wxDataViewCtrl flags
26 // ----------------------------------------------------------------------------
27
28 // ----------------------------------------------------------------------------
29 // wxDataViewCtrl globals
30 // ----------------------------------------------------------------------------
31
32 class WXDLLIMPEXP_CORE wxDataViewModel;
33 class WXDLLIMPEXP_CORE wxDataViewListModel;
34 class WXDLLIMPEXP_CORE wxDataViewCtrl;
35 class WXDLLIMPEXP_CORE wxDataViewColumn;
36 class WXDLLIMPEXP_CORE wxDataViewCell;
37
38 extern WXDLLEXPORT_DATA(const wxChar) wxDataViewCtrlNameStr[];
39
40 // ---------------------------------------------------------
41 // wxDataViewModel
42 // ---------------------------------------------------------
43
44 class wxDataViewModel: public wxObject
45 {
46 public:
47 wxDataViewModel() { }
48 virtual ~wxDataViewModel() { }
49
50 protected:
51 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewModel)
52 };
53
54 // ---------------------------------------------------------
55 // wxDataViewListModelNotifier
56 // ---------------------------------------------------------
57
58
59 class wxDataViewListModelNotifier: public wxObject
60 {
61 public:
62 wxDataViewListModelNotifier() { }
63 virtual ~wxDataViewListModelNotifier() { }
64
65 virtual bool RowAppended() = 0;
66 virtual bool RowPrepended() = 0;
67 virtual bool RowInserted( size_t before ) = 0;
68 virtual bool RowDeleted( size_t row ) = 0;
69 virtual bool RowChanged( size_t row ) = 0;
70 virtual bool ValueChanged( size_t col, size_t row ) = 0;
71 virtual bool RowsReordered( size_t *new_order ) = 0;
72 virtual bool Cleared() = 0;
73
74 void SetOwner( wxDataViewListModel *owner ) { m_owner = owner; }
75 wxDataViewListModel *GetOwner() { return m_owner; }
76
77 private:
78 wxDataViewListModel *m_owner;
79 };
80
81 // ---------------------------------------------------------
82 // wxDataViewListModel
83 // ---------------------------------------------------------
84
85 class wxDataViewViewingColumn: public wxObject
86 {
87 public:
88 wxDataViewViewingColumn( wxDataViewColumn *view_column, size_t model_column )
89 {
90 m_viewColumn = view_column;
91 m_modelColumn = model_column;
92 }
93
94 wxDataViewColumn *m_viewColumn;
95 size_t m_modelColumn;
96 };
97
98 class wxDataViewListModel: public wxDataViewModel
99 {
100 public:
101 wxDataViewListModel();
102 virtual ~wxDataViewListModel();
103
104 virtual size_t GetNumberOfRows() = 0;
105 virtual size_t GetNumberOfCols() = 0;
106 // return type as reported by wxVariant
107 virtual wxString GetColType( size_t col ) = 0;
108 // get value into a wxVariant
109 virtual void GetValue( wxVariant &variant, size_t col, size_t row ) = 0;
110 // set value, call ValueChanged() afterwards!
111 virtual bool SetValue( wxVariant &variant, size_t col, size_t row ) = 0;
112
113 // delegated notifiers
114 virtual bool RowAppended();
115 virtual bool RowPrepended();
116 virtual bool RowInserted( size_t before );
117 virtual bool RowDeleted( size_t row );
118 virtual bool RowChanged( size_t row );
119 virtual bool ValueChanged( size_t col, size_t row );
120 virtual bool RowsReordered( size_t *new_order );
121 virtual bool Cleared();
122
123 // Used internally
124 virtual void AddViewingColumn( wxDataViewColumn *view_column, size_t model_column );
125 virtual void RemoveViewingColumn( wxDataViewColumn *column );
126
127 virtual void AddNotifier( wxDataViewListModelNotifier *notifier );
128 virtual void RemoveNotifier( wxDataViewListModelNotifier *notifier );
129
130 wxList m_notifiers;
131 wxList m_viewingColumns;
132
133 protected:
134 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewListModel)
135 };
136
137 // ---------------------------------------------------------
138 // wxDataViewSortedListModel
139 // ---------------------------------------------------------
140
141 typedef int (wxCALLBACK *wxDataViewListModelCompare)
142 (size_t row1, size_t row2, size_t col, wxDataViewListModel* model );
143
144 WX_DEFINE_SORTED_EXPORTED_ARRAY_SIZE_T(size_t, wxDataViewSortedIndexArray );
145
146 class wxDataViewSortedListModel: public wxDataViewListModel
147 {
148 public:
149 wxDataViewSortedListModel( wxDataViewListModel *child );
150 virtual ~wxDataViewSortedListModel();
151
152 virtual size_t GetNumberOfRows();
153 virtual size_t GetNumberOfCols();
154 // return type as reported by wxVariant
155 virtual wxString GetColType( size_t col );
156 // get value into a wxVariant
157 virtual void GetValue( wxVariant &variant, size_t col, size_t row );
158 // set value, call ValueChanged() afterwards!
159 virtual bool SetValue( wxVariant &variant, size_t col, size_t row );
160
161 // delegated notifiers
162 virtual bool RowAppended();
163 virtual bool RowPrepended();
164 virtual bool RowInserted( size_t before );
165 virtual bool RowDeleted( size_t row );
166 virtual bool RowChanged( size_t row );
167 virtual bool ValueChanged( size_t col, size_t row );
168 virtual bool RowsReordered( size_t *new_order );
169 virtual bool Cleared();
170
171 bool ChildValueChanged( size_t col, size_t row );
172
173 virtual void Resort();
174
175 private:
176 wxDataViewListModel *m_child;
177 wxDataViewSortedIndexArray m_array;
178 wxDataViewListModelNotifier *m_notifierOnChild;
179
180 protected:
181 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewSortedListModel)
182 };
183
184 // ---------------------------------------------------------
185 // wxDataViewCellBase
186 // ---------------------------------------------------------
187
188 enum wxDataViewCellMode
189 {
190 wxDATAVIEW_CELL_INERT,
191 wxDATAVIEW_CELL_ACTIVATABLE,
192 wxDATAVIEW_CELL_EDITABLE
193 };
194
195 enum wxDataViewCellRenderState
196 {
197 wxDATAVIEW_CELL_SELECTED = 1,
198 wxDATAVIEW_CELL_PRELIT = 2,
199 wxDATAVIEW_CELL_INSENSITIVE = 4,
200 wxDATAVIEW_CELL_FOCUSED = 8
201 };
202
203 class wxDataViewCellBase: public wxObject
204 {
205 public:
206 wxDataViewCellBase( const wxString &varianttype, wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT );
207
208 virtual bool SetValue( const wxVariant &value ) { return true; }
209 virtual bool GetValue( wxVariant &value ) { return true; }
210 virtual bool Validate( wxVariant &value ) { return true; }
211
212 wxString GetVariantType() { return m_variantType; }
213
214 void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; }
215 wxDataViewColumn* GetOwner() { return m_owner; }
216
217 protected:
218 wxDataViewCellMode m_mode;
219 wxString m_variantType;
220 wxDataViewColumn *m_owner;
221
222 protected:
223 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCellBase)
224 };
225
226 // ---------------------------------------------------------
227 // wxDataViewColumnBase
228 // ---------------------------------------------------------
229
230 enum wxDataViewColumnFlags
231 {
232 wxDATAVIEW_COL_RESIZABLE = 1,
233 wxDATAVIEW_COL_SORTABLE = 2,
234 wxDATAVIEW_COL_HIDDEN = 4
235 };
236
237 class wxDataViewColumnBase: public wxObject
238 {
239 public:
240 wxDataViewColumnBase( const wxString &title, wxDataViewCell *cell, size_t model_column, int flags = 0 );
241 ~wxDataViewColumnBase();
242
243 virtual void SetTitle( const wxString &title );
244 virtual wxString GetTitle();
245
246 wxDataViewCell* GetCell() { return m_cell; }
247
248 size_t GetModelColumn() { return m_model_column; }
249
250 void SetOwner( wxDataViewCtrl *owner ) { m_owner = owner; }
251 wxDataViewCtrl *GetOwner() { return m_owner; }
252
253 private:
254 wxDataViewCtrl *m_ctrl;
255 wxDataViewCell *m_cell;
256 int m_model_column;
257 int m_flags;
258 wxString m_title;
259 wxDataViewCtrl *m_owner;
260
261 protected:
262 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase)
263 };
264
265 // ---------------------------------------------------------
266 // wxDataViewCtrlBase
267 // ---------------------------------------------------------
268
269 class wxDataViewCtrlBase: public wxControl
270 {
271 public:
272 wxDataViewCtrlBase();
273 ~wxDataViewCtrlBase();
274
275 virtual bool AssociateModel( wxDataViewListModel *model );
276 wxDataViewListModel* GetModel();
277
278 virtual bool AppendTextColumn( const wxString &label, size_t model_column );
279 virtual bool AppendToggleColumn( const wxString &label, size_t model_column );
280 virtual bool AppendProgressColumn( const wxString &label, size_t model_column );
281 virtual bool AppendDateColumn( const wxString &label, size_t model_column );
282 virtual bool AppendColumn( wxDataViewColumn *col );
283 virtual size_t GetNumberOfColumns();
284 virtual bool DeleteColumn( size_t pos );
285 virtual bool ClearColumns();
286 virtual wxDataViewColumn* GetColumn( size_t pos );
287
288 private:
289 wxDataViewListModel *m_model;
290 wxList m_cols;
291
292 protected:
293 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase)
294 };
295
296 #if defined(__WXGTK20__)
297 #include "wx/gtk/dataview.h"
298 #elif defined(__WXMAC__)
299 #include "wx/mac/dataview.h"
300 #else
301 #include "wx/generic/dataview.h"
302 #endif
303
304 #endif // wxUSE_DATAVIEWCTRL
305
306 #endif
307 // _WX_DATAVIEW_H_BASE_