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 wxDataViewRenderer
;
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( unsigned int before
) = 0;
78 virtual bool RowDeleted( unsigned int row
) = 0;
79 virtual bool RowChanged( unsigned int row
) = 0;
80 virtual bool ValueChanged( unsigned int col
, unsigned int row
) = 0;
81 virtual bool RowsReordered( unsigned int *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
, unsigned int model_column
)
100 m_viewColumn
= view_column
;
101 m_modelColumn
= model_column
;
104 wxDataViewColumn
*m_viewColumn
;
105 unsigned int m_modelColumn
;
108 class WXDLLIMPEXP_ADV wxDataViewListModel
: public wxDataViewModel
111 wxDataViewListModel();
112 virtual ~wxDataViewListModel();
114 virtual unsigned int GetNumberOfRows() = 0;
115 virtual unsigned int GetNumberOfCols() = 0;
116 // return type as reported by wxVariant
117 virtual wxString
GetColType( unsigned int col
) = 0;
118 // get value into a wxVariant
119 virtual void GetValue( wxVariant
&variant
, unsigned int col
, unsigned int row
) = 0;
120 // set value, call ValueChanged() afterwards!
121 virtual bool SetValue( wxVariant
&variant
, unsigned int col
, unsigned int row
) = 0;
123 // delegated notifiers
124 virtual bool RowAppended();
125 virtual bool RowPrepended();
126 virtual bool RowInserted( unsigned int before
);
127 virtual bool RowDeleted( unsigned int row
);
128 virtual bool RowChanged( unsigned int row
);
129 virtual bool ValueChanged( unsigned int col
, unsigned int row
);
130 virtual bool RowsReordered( unsigned int *new_order
);
131 virtual bool Cleared();
134 virtual void AddViewingColumn( wxDataViewColumn
*view_column
, unsigned int 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 (unsigned int row1
, unsigned int row2
, unsigned int col
, wxDataViewListModel
* model
);
154 WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(unsigned int, wxDataViewSortedIndexArray
, WXDLLIMPEXP_ADV
);
156 class WXDLLIMPEXP_ADV wxDataViewSortedListModel
: public wxDataViewListModel
159 wxDataViewSortedListModel( wxDataViewListModel
*child
);
160 virtual ~wxDataViewSortedListModel();
162 virtual unsigned int GetNumberOfRows();
163 virtual unsigned int GetNumberOfCols();
164 // return type as reported by wxVariant
165 virtual wxString
GetColType( unsigned int col
);
166 // get value into a wxVariant
167 virtual void GetValue( wxVariant
&variant
, unsigned int col
, unsigned int row
);
168 // set value, call ValueChanged() afterwards!
169 virtual bool SetValue( wxVariant
&variant
, unsigned int col
, unsigned int row
);
172 virtual bool RowAppended();
173 virtual bool RowPrepended();
174 virtual bool RowInserted( unsigned int before
);
175 virtual bool RowDeleted( unsigned int row
);
176 virtual bool RowChanged( unsigned int row
);
177 virtual bool ValueChanged( unsigned int col
, unsigned int row
);
178 virtual bool RowsReordered( unsigned int *new_order
);
179 virtual bool Cleared();
181 // called if child's notifiers are called
182 bool ChildRowAppended();
183 bool ChildRowPrepended();
184 bool ChildRowInserted( unsigned int before
);
185 bool ChildRowDeleted( unsigned int row
);
186 bool ChildRowChanged( unsigned int row
);
187 bool ChildValueChanged( unsigned int col
, unsigned int row
);
188 bool ChildRowsReordered( unsigned int *new_order
);
191 virtual void Resort();
194 wxDataViewListModel
*m_child
;
195 wxDataViewSortedIndexArray m_array
;
196 wxDataViewListModelNotifier
*m_notifierOnChild
;
199 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewSortedListModel
)
202 // ---------------------------------------------------------
203 // wxDataViewRendererBase
204 // ---------------------------------------------------------
206 enum wxDataViewCellMode
208 wxDATAVIEW_CELL_INERT
,
209 wxDATAVIEW_CELL_ACTIVATABLE
,
210 wxDATAVIEW_CELL_EDITABLE
213 enum wxDataViewCellRenderState
215 wxDATAVIEW_CELL_SELECTED
= 1,
216 wxDATAVIEW_CELL_PRELIT
= 2,
217 wxDATAVIEW_CELL_INSENSITIVE
= 4,
218 wxDATAVIEW_CELL_FOCUSED
= 8
221 class WXDLLIMPEXP_ADV wxDataViewRendererBase
: public wxObject
224 wxDataViewRendererBase( const wxString
&varianttype
, wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
);
226 virtual bool SetValue( const wxVariant
& WXUNUSED(value
) ) { return true; }
227 virtual bool GetValue( wxVariant
& WXUNUSED(value
) ) { return true; }
228 virtual bool Validate( wxVariant
& WXUNUSED(value
) ) { return true; }
230 wxString
GetVariantType() { return m_variantType
; }
231 wxDataViewCellMode
GetMode() { return m_mode
; }
233 void SetOwner( wxDataViewColumn
*owner
) { m_owner
= owner
; }
234 wxDataViewColumn
* GetOwner() { return m_owner
; }
237 wxDataViewCellMode m_mode
;
238 wxString m_variantType
;
239 wxDataViewColumn
*m_owner
;
242 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase
)
245 // ---------------------------------------------------------
246 // wxDataViewColumnBase
247 // ---------------------------------------------------------
249 enum wxDataViewColumnFlags
251 wxDATAVIEW_COL_RESIZABLE
= 1,
252 wxDATAVIEW_COL_SORTABLE
= 2,
253 wxDATAVIEW_COL_HIDDEN
= 4
256 class WXDLLIMPEXP_ADV wxDataViewColumnBase
: public wxObject
259 wxDataViewColumnBase( const wxString
&title
, wxDataViewRenderer
*renderer
, unsigned int model_column
,
260 int width
= 80, int flags
= wxDATAVIEW_COL_RESIZABLE
);
261 virtual ~wxDataViewColumnBase();
263 virtual void SetTitle( const wxString
&title
);
264 virtual wxString
GetTitle();
266 wxDataViewRenderer
* GetRenderer() { return m_renderer
; }
268 unsigned int GetModelColumn() { return m_model_column
; }
270 void SetOwner( wxDataViewCtrl
*owner
) { m_owner
= owner
; }
271 wxDataViewCtrl
*GetOwner() { return m_owner
; }
273 virtual int GetWidth() = 0;
276 wxDataViewCtrl
*m_ctrl
;
277 wxDataViewRenderer
*m_renderer
;
281 wxDataViewCtrl
*m_owner
;
284 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase
)
287 // ---------------------------------------------------------
288 // wxDataViewCtrlBase
289 // ---------------------------------------------------------
291 #define wxDV_SINGLE 0x0000 // for convenience
292 #define wxDV_MULTIPLE 0x0020 // can select multiple items
294 class WXDLLIMPEXP_ADV wxDataViewCtrlBase
: public wxControl
297 wxDataViewCtrlBase();
298 virtual ~wxDataViewCtrlBase();
300 virtual bool AssociateModel( wxDataViewListModel
*model
);
301 wxDataViewListModel
* GetModel();
303 virtual bool AppendTextColumn( const wxString
&label
, unsigned int model_column
);
304 virtual bool AppendToggleColumn( const wxString
&label
, unsigned int model_column
);
305 virtual bool AppendProgressColumn( const wxString
&label
, unsigned int model_column
);
306 virtual bool AppendDateColumn( const wxString
&label
, unsigned int model_column
);
307 virtual bool AppendColumn( wxDataViewColumn
*col
);
308 virtual unsigned int GetNumberOfColumns();
309 virtual bool DeleteColumn( unsigned int pos
);
310 virtual bool ClearColumns();
311 virtual wxDataViewColumn
* GetColumn( unsigned int pos
);
313 virtual void SetSelection( int row
) = 0; // -1 for unselect
314 inline void ClearSelection() { SetSelection( -1 ); }
315 virtual void Unselect( unsigned int row
) = 0;
316 virtual void SetSelectionRange( unsigned int from
, unsigned int to
) = 0;
317 virtual void SetSelections( const wxArrayInt
& aSelections
) = 0;
319 virtual bool IsSelected( unsigned int row
) const = 0;
320 virtual int GetSelection() const = 0;
321 virtual int GetSelections(wxArrayInt
& aSelections
) const = 0;
324 wxDataViewListModel
*m_model
;
328 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase
)
332 // ----------------------------------------------------------------------------
333 // wxDataViewEvent - the event class for the wxDataViewCtrl notifications
334 // ----------------------------------------------------------------------------
336 class WXDLLIMPEXP_ADV wxDataViewEvent
: public wxNotifyEvent
339 wxDataViewEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
340 : wxNotifyEvent(commandType
, winid
),
344 m_value(wxNullVariant
),
345 m_editCancelled(false)
348 wxDataViewEvent(const wxDataViewEvent
& event
)
349 : wxNotifyEvent(event
),
352 m_model(event
.m_model
),
353 m_value(event
.m_value
),
354 m_editCancelled(event
.m_editCancelled
)
357 int GetColumn() const { return m_col
; }
358 void SetColumn( int col
) { m_col
= col
; }
359 int GetRow() const { return m_row
; }
360 void SetRow( int row
) { m_row
= row
; }
361 wxDataViewModel
* GetModel() const { return m_model
; }
362 void SetModel( wxDataViewModel
*model
) { m_model
= model
; }
363 const wxVariant
&GetValue() const { return m_value
; }
364 void SetValue( const wxVariant
&value
) { m_value
= value
; }
366 // was label editing canceled? (for wxEVT_COMMAND_DATVIEW_END_LABEL_EDIT only)
367 bool IsEditCancelled() const { return m_editCancelled
; }
368 void SetEditCanceled(bool editCancelled
) { m_editCancelled
= editCancelled
; }
370 virtual wxEvent
*Clone() const { return new wxDataViewEvent(*this); }
375 wxDataViewModel
*m_model
;
377 bool m_editCancelled
;
380 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent
)
383 BEGIN_DECLARE_EVENT_TYPES()
384 DECLARE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ROW_SELECTED
, -1)
385 DECLARE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ROW_ACTIVATED
, -1)
386 END_DECLARE_EVENT_TYPES()
388 typedef void (wxEvtHandler::*wxDataViewEventFunction
)(wxDataViewEvent
&);
390 #define wxDataViewEventHandler(func) \
391 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDataViewEventFunction, &func)
393 #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
394 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
396 #define EVT_DATAVIEW_ROW_SELECTED(id, fn) wx__DECLARE_DATAVIEWEVT(ROW_SELECTED, id, fn)
397 #define EVT_DATAVIEW_ROW_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ROW_ACTIVATED, id, fn)
400 #if defined(wxUSE_GENERICDATAVIEWCTRL)
401 #include "wx/generic/dataview.h"
402 #elif defined(__WXGTK20__)
403 #include "wx/gtk/dataview.h"
404 #elif defined(__WXMAC__)
406 // #include "wx/mac/dataview.h"
408 #include "wx/generic/dataview.h"
411 #endif // wxUSE_DATAVIEWCTRL
414 // _WX_DATAVIEW_H_BASE_