1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDataViewCtrl base classes
4 // Author: Robert Roebling
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_DATAVIEW_H_BASE_
13 #define _WX_DATAVIEW_H_BASE_
17 #if wxUSE_DATAVIEWCTRL
19 #include "wx/control.h"
20 #include "wx/textctrl.h"
21 #include "wx/bitmap.h"
22 #include "wx/variant.h"
25 #if defined(__WXGTK20__)
27 #define wxUSE_GENERICDATAVIEWCTRL 1
28 #elif defined(__WXMAC__)
29 #define wxUSE_GENERICDATAVIEWCTRL 1
31 #define wxUSE_GENERICDATAVIEWCTRL 1
34 // ----------------------------------------------------------------------------
35 // wxDataViewCtrl flags
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
39 // wxDataViewCtrl globals
40 // ----------------------------------------------------------------------------
42 class WXDLLIMPEXP_ADV wxDataViewModel
;
43 class WXDLLIMPEXP_ADV wxDataViewListModel
;
44 class WXDLLIMPEXP_ADV wxDataViewCtrl
;
45 class WXDLLIMPEXP_ADV wxDataViewColumn
;
46 class WXDLLIMPEXP_ADV wxDataViewCell
;
48 extern WXDLLIMPEXP_DATA_ADV(const wxChar
) wxDataViewCtrlNameStr
[];
50 // ---------------------------------------------------------
52 // ---------------------------------------------------------
54 class WXDLLIMPEXP_ADV wxDataViewModel
: public wxObject
58 virtual ~wxDataViewModel() { }
61 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewModel
)
64 // ---------------------------------------------------------
65 // wxDataViewListModelNotifier
66 // ---------------------------------------------------------
69 class WXDLLIMPEXP_ADV wxDataViewListModelNotifier
: public wxObject
72 wxDataViewListModelNotifier() { }
73 virtual ~wxDataViewListModelNotifier() { }
75 virtual bool RowAppended() = 0;
76 virtual bool RowPrepended() = 0;
77 virtual bool RowInserted( size_t before
) = 0;
78 virtual bool RowDeleted( size_t row
) = 0;
79 virtual bool RowChanged( size_t row
) = 0;
80 virtual bool ValueChanged( size_t col
, size_t row
) = 0;
81 virtual bool RowsReordered( size_t *new_order
) = 0;
82 virtual bool Cleared() = 0;
84 void SetOwner( wxDataViewListModel
*owner
) { m_owner
= owner
; }
85 wxDataViewListModel
*GetOwner() { return m_owner
; }
88 wxDataViewListModel
*m_owner
;
91 // ---------------------------------------------------------
92 // wxDataViewListModel
93 // ---------------------------------------------------------
95 class WXDLLIMPEXP_ADV wxDataViewViewingColumn
: public wxObject
98 wxDataViewViewingColumn( wxDataViewColumn
*view_column
, size_t model_column
)
100 m_viewColumn
= view_column
;
101 m_modelColumn
= model_column
;
104 wxDataViewColumn
*m_viewColumn
;
105 size_t m_modelColumn
;
108 class WXDLLIMPEXP_ADV wxDataViewListModel
: public wxDataViewModel
111 wxDataViewListModel();
112 virtual ~wxDataViewListModel();
114 virtual size_t GetNumberOfRows() = 0;
115 virtual size_t GetNumberOfCols() = 0;
116 // return type as reported by wxVariant
117 virtual wxString
GetColType( size_t col
) = 0;
118 // get value into a wxVariant
119 virtual void GetValue( wxVariant
&variant
, size_t col
, size_t row
) = 0;
120 // set value, call ValueChanged() afterwards!
121 virtual bool SetValue( wxVariant
&variant
, size_t col
, size_t row
) = 0;
123 // delegated notifiers
124 virtual bool RowAppended();
125 virtual bool RowPrepended();
126 virtual bool RowInserted( size_t before
);
127 virtual bool RowDeleted( size_t row
);
128 virtual bool RowChanged( size_t row
);
129 virtual bool ValueChanged( size_t col
, size_t row
);
130 virtual bool RowsReordered( size_t *new_order
);
131 virtual bool Cleared();
134 virtual void AddViewingColumn( wxDataViewColumn
*view_column
, size_t model_column
);
135 virtual void RemoveViewingColumn( wxDataViewColumn
*column
);
137 virtual void AddNotifier( wxDataViewListModelNotifier
*notifier
);
138 virtual void RemoveNotifier( wxDataViewListModelNotifier
*notifier
);
141 wxList m_viewingColumns
;
144 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewListModel
)
147 // ---------------------------------------------------------
148 // wxDataViewSortedListModel
149 // ---------------------------------------------------------
151 typedef int (wxCALLBACK
*wxDataViewListModelCompare
)
152 (size_t row1
, size_t row2
, size_t col
, wxDataViewListModel
* model
);
154 WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(size_t, wxDataViewSortedIndexArray
, WXDLLIMPEXP_ADV
);
156 class WXDLLIMPEXP_ADV wxDataViewSortedListModel
: public wxDataViewListModel
159 wxDataViewSortedListModel( wxDataViewListModel
*child
);
160 virtual ~wxDataViewSortedListModel();
162 virtual size_t GetNumberOfRows();
163 virtual size_t GetNumberOfCols();
164 // return type as reported by wxVariant
165 virtual wxString
GetColType( size_t col
);
166 // get value into a wxVariant
167 virtual void GetValue( wxVariant
&variant
, size_t col
, size_t row
);
168 // set value, call ValueChanged() afterwards!
169 virtual bool SetValue( wxVariant
&variant
, size_t col
, size_t row
);
171 // delegated notifiers
172 virtual bool RowAppended();
173 virtual bool RowPrepended();
174 virtual bool RowInserted( size_t before
);
175 virtual bool RowDeleted( size_t row
);
176 virtual bool RowChanged( size_t row
);
177 virtual bool ValueChanged( size_t col
, size_t row
);
178 virtual bool RowsReordered( size_t *new_order
);
179 virtual bool Cleared();
181 bool ChildValueChanged( size_t col
, size_t row
);
183 virtual void Resort();
186 wxDataViewListModel
*m_child
;
187 wxDataViewSortedIndexArray m_array
;
188 wxDataViewListModelNotifier
*m_notifierOnChild
;
191 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewSortedListModel
)
194 // ---------------------------------------------------------
195 // wxDataViewCellBase
196 // ---------------------------------------------------------
198 enum wxDataViewCellMode
200 wxDATAVIEW_CELL_INERT
,
201 wxDATAVIEW_CELL_ACTIVATABLE
,
202 wxDATAVIEW_CELL_EDITABLE
205 enum wxDataViewCellRenderState
207 wxDATAVIEW_CELL_SELECTED
= 1,
208 wxDATAVIEW_CELL_PRELIT
= 2,
209 wxDATAVIEW_CELL_INSENSITIVE
= 4,
210 wxDATAVIEW_CELL_FOCUSED
= 8
213 class WXDLLIMPEXP_ADV wxDataViewCellBase
: public wxObject
216 wxDataViewCellBase( const wxString
&varianttype
, wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
);
218 virtual bool SetValue( const wxVariant
& WXUNUSED(value
) ) { return true; }
219 virtual bool GetValue( wxVariant
& WXUNUSED(value
) ) { return true; }
220 virtual bool Validate( wxVariant
& WXUNUSED(value
) ) { return true; }
222 wxString
GetVariantType() { return m_variantType
; }
223 wxDataViewCellMode
GetMode() { return m_mode
; }
225 void SetOwner( wxDataViewColumn
*owner
) { m_owner
= owner
; }
226 wxDataViewColumn
* GetOwner() { return m_owner
; }
229 wxDataViewCellMode m_mode
;
230 wxString m_variantType
;
231 wxDataViewColumn
*m_owner
;
234 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCellBase
)
237 // ---------------------------------------------------------
238 // wxDataViewColumnBase
239 // ---------------------------------------------------------
241 enum wxDataViewColumnFlags
243 wxDATAVIEW_COL_RESIZABLE
= 1,
244 wxDATAVIEW_COL_SORTABLE
= 2,
245 wxDATAVIEW_COL_HIDDEN
= 4
248 enum wxDataViewColumnSizing
250 wxDATAVIEW_COL_WIDTH_FIXED
,
251 wxDATAVIEW_COL_WIDTH_AUTO
,
252 wxDATAVIEW_COL_WIDTH_GROW
255 class WXDLLIMPEXP_ADV wxDataViewColumnBase
: public wxObject
258 wxDataViewColumnBase( const wxString
&title
, wxDataViewCell
*cell
, size_t model_column
,
259 int fixed_width
= 80, wxDataViewColumnSizing sizing
= wxDATAVIEW_COL_WIDTH_FIXED
, int flags
= 0 );
260 virtual ~wxDataViewColumnBase();
262 virtual void SetTitle( const wxString
&title
);
263 virtual wxString
GetTitle();
265 wxDataViewCell
* GetCell() { return m_cell
; }
267 size_t GetModelColumn() { return m_model_column
; }
269 void SetOwner( wxDataViewCtrl
*owner
) { m_owner
= owner
; }
270 wxDataViewCtrl
*GetOwner() { return m_owner
; }
272 virtual int GetWidth() = 0;
274 virtual void SetFixedWidth( int width
) = 0;
275 virtual int GetFixedWidth() = 0;
278 wxDataViewCtrl
*m_ctrl
;
279 wxDataViewCell
*m_cell
;
283 wxDataViewCtrl
*m_owner
;
286 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase
)
289 // ---------------------------------------------------------
290 // wxDataViewCtrlBase
291 // ---------------------------------------------------------
293 #define wxDV_SINGLE 0x0000 // for convenience
294 #define wxDV_MULTIPLE 0x0020 // can select multiple items
296 class WXDLLIMPEXP_ADV wxDataViewCtrlBase
: public wxControl
299 wxDataViewCtrlBase();
300 virtual ~wxDataViewCtrlBase();
302 virtual bool AssociateModel( wxDataViewListModel
*model
);
303 wxDataViewListModel
* GetModel();
305 virtual bool AppendTextColumn( const wxString
&label
, size_t model_column
);
306 virtual bool AppendToggleColumn( const wxString
&label
, size_t model_column
);
307 virtual bool AppendProgressColumn( const wxString
&label
, size_t model_column
);
308 virtual bool AppendDateColumn( const wxString
&label
, size_t model_column
);
309 virtual bool AppendColumn( wxDataViewColumn
*col
);
310 virtual size_t GetNumberOfColumns();
311 virtual bool DeleteColumn( size_t pos
);
312 virtual bool ClearColumns();
313 virtual wxDataViewColumn
* GetColumn( size_t pos
);
316 wxDataViewListModel
*m_model
;
320 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase
)
323 #if defined(wxUSE_GENERICDATAVIEWCTRL)
324 #include "wx/generic/dataview.h"
325 #elif defined(__WXGTK20__)
326 #include "wx/gtk/dataview.h"
327 #elif defined(__WXMAC__)
329 // #include "wx/mac/dataview.h"
331 #include "wx/generic/dataview.h"
334 #endif // wxUSE_DATAVIEWCTRL
337 // _WX_DATAVIEW_H_BASE_