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"
24 // ----------------------------------------------------------------------------
25 // wxDataViewCtrl flags
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
29 // wxDataViewCtrl globals
30 // ----------------------------------------------------------------------------
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
;
38 extern WXDLLEXPORT_DATA(const wxChar
) wxDataViewCtrlNameStr
[];
40 // ---------------------------------------------------------
42 // ---------------------------------------------------------
44 class wxDataViewModel
: public wxObject
48 virtual ~wxDataViewModel() { }
51 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewModel
)
54 // ---------------------------------------------------------
55 // wxDataViewListModelNotifier
56 // ---------------------------------------------------------
59 class wxDataViewListModelNotifier
: public wxObject
62 wxDataViewListModelNotifier() { }
63 virtual ~wxDataViewListModelNotifier() { }
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;
74 void SetOwner( wxDataViewListModel
*owner
) { m_owner
= owner
; }
75 wxDataViewListModel
*GetOwner() { return m_owner
; }
78 wxDataViewListModel
*m_owner
;
81 // ---------------------------------------------------------
82 // wxDataViewListModel
83 // ---------------------------------------------------------
85 class wxDataViewViewingColumn
: public wxObject
88 wxDataViewViewingColumn( wxDataViewColumn
*view_column
, size_t model_column
)
90 m_viewColumn
= view_column
;
91 m_modelColumn
= model_column
;
94 wxDataViewColumn
*m_viewColumn
;
98 class wxDataViewListModel
: public wxDataViewModel
101 wxDataViewListModel();
102 virtual ~wxDataViewListModel();
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;
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();
124 virtual void AddViewingColumn( wxDataViewColumn
*view_column
, size_t model_column
);
125 virtual void RemoveViewingColumn( wxDataViewColumn
*column
);
127 virtual void AddNotifier( wxDataViewListModelNotifier
*notifier
);
128 virtual void RemoveNotifier( wxDataViewListModelNotifier
*notifier
);
131 wxList m_viewingColumns
;
134 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewListModel
)
137 // ---------------------------------------------------------
138 // wxDataViewSortedListModel
139 // ---------------------------------------------------------
141 typedef int (wxCALLBACK
*wxDataViewListModelCompare
)
142 (size_t row1
, size_t row2
, size_t col
, wxDataViewListModel
* model
);
144 WX_DEFINE_SORTED_EXPORTED_ARRAY_SIZE_T(size_t, wxDataViewSortedIndexArray
);
146 class wxDataViewSortedListModel
: public wxDataViewListModel
149 wxDataViewSortedListModel( wxDataViewListModel
*child
);
150 virtual ~wxDataViewSortedListModel();
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
);
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();
171 bool ChildValueChanged( size_t col
, size_t row
);
173 virtual void Resort();
176 wxDataViewListModel
*m_child
;
177 wxDataViewSortedIndexArray m_array
;
178 wxDataViewListModelNotifier
*m_notifierOnChild
;
181 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewSortedListModel
)
184 // ---------------------------------------------------------
185 // wxDataViewCellBase
186 // ---------------------------------------------------------
188 enum wxDataViewCellMode
190 wxDATAVIEW_CELL_INERT
,
191 wxDATAVIEW_CELL_ACTIVATABLE
,
192 wxDATAVIEW_CELL_EDITABLE
195 enum wxDataViewCellRenderState
197 wxDATAVIEW_CELL_SELECTED
= 1,
198 wxDATAVIEW_CELL_PRELIT
= 2,
199 wxDATAVIEW_CELL_INSENSITIVE
= 4,
200 wxDATAVIEW_CELL_FOCUSED
= 8
203 class wxDataViewCellBase
: public wxObject
206 wxDataViewCellBase( const wxString
&varianttype
, wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
);
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; }
212 wxString
GetVariantType() { return m_variantType
; }
214 void SetOwner( wxDataViewColumn
*owner
) { m_owner
= owner
; }
215 wxDataViewColumn
* GetOwner() { return m_owner
; }
218 wxDataViewCellMode m_mode
;
219 wxString m_variantType
;
220 wxDataViewColumn
*m_owner
;
223 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCellBase
)
226 // ---------------------------------------------------------
227 // wxDataViewColumnBase
228 // ---------------------------------------------------------
230 enum wxDataViewColumnFlags
232 wxDATAVIEW_COL_RESIZABLE
= 1,
233 wxDATAVIEW_COL_SORTABLE
= 2,
234 wxDATAVIEW_COL_HIDDEN
= 4
237 class wxDataViewColumnBase
: public wxObject
240 wxDataViewColumnBase( const wxString
&title
, wxDataViewCell
*cell
, size_t model_column
, int flags
= 0 );
241 ~wxDataViewColumnBase();
243 virtual void SetTitle( const wxString
&title
);
244 virtual wxString
GetTitle();
246 wxDataViewCell
* GetCell() { return m_cell
; }
248 size_t GetModelColumn() { return m_model_column
; }
250 void SetOwner( wxDataViewCtrl
*owner
) { m_owner
= owner
; }
251 wxDataViewCtrl
*GetOwner() { return m_owner
; }
254 wxDataViewCtrl
*m_ctrl
;
255 wxDataViewCell
*m_cell
;
259 wxDataViewCtrl
*m_owner
;
262 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase
)
265 // ---------------------------------------------------------
266 // wxDataViewCtrlBase
267 // ---------------------------------------------------------
269 class wxDataViewCtrlBase
: public wxControl
272 wxDataViewCtrlBase();
273 ~wxDataViewCtrlBase();
275 virtual bool AssociateModel( wxDataViewListModel
*model
);
276 wxDataViewListModel
* GetModel();
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
);
289 wxDataViewListModel
*m_model
;
293 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase
)
296 #if defined(__WXGTK20__)
297 #include "wx/gtk/dataview.h"
298 #elif defined(__WXMAC__)
299 #include "wx/mac/dataview.h"
301 #include "wx/generic/dataview.h"
304 #endif // wxUSE_DATAVIEWCTRL
307 // _WX_DATAVIEW_H_BASE_