1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDataViewCtrl base classes
4 // Author: Robert Roebling
5 // Modified by: Bo Yang
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"
23 #include "wx/listctrl.h"
24 #include "wx/dynarray.h"
27 #if defined(__WXGTK20__)
29 // #define wxUSE_GENERICDATAVIEWCTRL 1
30 #elif defined(__WXMAC__)
32 #define wxUSE_GENERICDATAVIEWCTRL 1
35 // ----------------------------------------------------------------------------
36 // wxDataViewCtrl flags
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
40 // wxDataViewCtrl globals
41 // ----------------------------------------------------------------------------
43 class WXDLLIMPEXP_FWD_ADV wxDataViewItem
;
44 class WXDLLIMPEXP_FWD_ADV wxDataViewModel
;
45 class WXDLLIMPEXP_FWD_ADV wxDataViewCtrl
;
46 class WXDLLIMPEXP_FWD_ADV wxDataViewColumn
;
47 class WXDLLIMPEXP_FWD_ADV wxDataViewRenderer
;
48 class WXDLLIMPEXP_FWD_ADV wxDataViewModelNotifier
;
50 extern WXDLLIMPEXP_DATA_ADV(const wxChar
) wxDataViewCtrlNameStr
[];
52 // the default width of new (text) columns:
53 #define wxDVC_DEFAULT_WIDTH 80
55 // the default width of new toggle columns:
56 #define wxDVC_TOGGLE_DEFAULT_WIDTH 30
58 // the default minimal width of the columns:
59 #define wxDVC_DEFAULT_MINWIDTH 30
61 // the default alignment of wxDataViewRenderers:
62 #define wxDVR_DEFAULT_ALIGNMENT (wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL)
65 // ---------------------------------------------------------
67 // ---------------------------------------------------------
69 class WXDLLIMPEXP_ADV wxDataViewItem
72 wxDataViewItem( void* id
= NULL
)
74 wxDataViewItem( const wxDataViewItem
&item
)
76 bool IsOk() const { return m_id
!= NULL
; }
77 void* GetID() const { return m_id
; }
78 operator const void* () const { return m_id
; }
81 void Print( const wxString
&text
) const { wxPrintf( "item %s: %d\n", text
, (int) m_id
); }
88 bool operator == (const wxDataViewItem
&left
, const wxDataViewItem
&right
);
90 WX_DEFINE_ARRAY(wxDataViewItem
, wxDataViewItemArray
);
92 // ---------------------------------------------------------
93 // wxDataViewModelNotifier
94 // ---------------------------------------------------------
96 class WXDLLIMPEXP_ADV wxDataViewModelNotifier
99 wxDataViewModelNotifier() { }
100 virtual ~wxDataViewModelNotifier() { m_owner
= NULL
; }
102 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
) = 0;
103 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
) = 0;
104 virtual bool ItemChanged( const wxDataViewItem
&item
) = 0;
105 virtual bool ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
106 virtual bool ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
107 virtual bool ItemsChanged( const wxDataViewItemArray
&items
);
108 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
) = 0;
109 virtual bool Cleared() = 0;
111 virtual void Resort() = 0;
113 void SetOwner( wxDataViewModel
*owner
) { m_owner
= owner
; }
114 wxDataViewModel
*GetOwner() { return m_owner
; }
117 wxDataViewModel
*m_owner
;
121 // ---------------------------------------------------------
123 // ---------------------------------------------------------
125 WX_DECLARE_LIST_WITH_DECL(wxDataViewModelNotifier
, wxDataViewModelNotifiers
,
126 class WXDLLIMPEXP_ADV
);
128 class WXDLLIMPEXP_ADV wxDataViewModel
: public wxObjectRefData
133 virtual unsigned int GetColumnCount() const = 0;
135 // return type as reported by wxVariant
136 virtual wxString
GetColumnType( unsigned int col
) const = 0;
138 // get value into a wxVariant
139 virtual void GetValue( wxVariant
&variant
,
140 const wxDataViewItem
&item
, unsigned int col
) const = 0;
142 // set value, call ValueChanged() afterwards!
143 virtual bool SetValue( const wxVariant
&variant
,
144 const wxDataViewItem
&item
, unsigned int col
) = 0;
147 virtual wxDataViewItem
GetParent( const wxDataViewItem
&item
) const = 0;
148 virtual bool IsContainer( const wxDataViewItem
&item
) const = 0;
149 // Is the container just a header or an item with all columns
150 virtual bool HasContainerColumns( const wxDataViewItem
&item
) const { return false; }
151 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const = 0;
153 // delegated notifiers
154 virtual bool ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
155 virtual bool ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
156 virtual bool ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
);
157 virtual bool ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
);
158 virtual bool ItemChanged( const wxDataViewItem
&item
);
159 virtual bool ItemsChanged( const wxDataViewItemArray
&items
);
160 virtual bool ValueChanged( const wxDataViewItem
&item
, unsigned int col
);
161 virtual bool Cleared();
164 virtual void Resort();
166 void AddNotifier( wxDataViewModelNotifier
*notifier
);
167 void RemoveNotifier( wxDataViewModelNotifier
*notifier
);
169 // default compare function
170 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
171 unsigned int column
, bool ascending
);
172 virtual bool HasDefaultCompare() const { return false; }
175 // the user should not delete this class directly: he should use DecRef() instead!
176 virtual ~wxDataViewModel() { }
178 wxDataViewModelNotifiers m_notifiers
;
181 // ---------------------------------------------------------
182 // wxDataViewIndexListModel
183 // ---------------------------------------------------------
185 class WXDLLIMPEXP_ADV wxDataViewIndexListModel
: public wxDataViewModel
188 wxDataViewIndexListModel( unsigned int initial_size
= 0 );
189 ~wxDataViewIndexListModel();
191 virtual unsigned int GetRowCount() = 0;
193 virtual void GetValue( wxVariant
&variant
,
194 unsigned int row
, unsigned int col
) const = 0;
196 virtual bool SetValue( const wxVariant
&variant
,
197 unsigned int row
, unsigned int col
) = 0;
200 void RowInserted( unsigned int before
);
202 void RowDeleted( unsigned int row
);
203 void RowChanged( unsigned int row
);
204 void RowValueChanged( unsigned int row
, unsigned int col
);
206 // convert to/from row/wxDataViewItem
208 unsigned int GetRow( const wxDataViewItem
&item
) const;
209 wxDataViewItem
GetItem( unsigned int row
) const;
211 // compare based on index
213 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
214 unsigned int column
, bool ascending
);
215 virtual bool HasDefaultCompare() const { return true; }
217 // implement base methods
219 virtual void GetValue( wxVariant
&variant
,
220 const wxDataViewItem
&item
, unsigned int col
) const;
221 virtual bool SetValue( const wxVariant
&variant
,
222 const wxDataViewItem
&item
, unsigned int col
);
223 virtual wxDataViewItem
GetParent( const wxDataViewItem
&item
) const;
224 virtual bool IsContainer( const wxDataViewItem
&item
) const;
225 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const;
228 wxDataViewItemArray m_hash
;
229 unsigned int m_lastIndex
;
233 //-----------------------------------------------------------------------------
234 // wxDataViewEditorCtrlEvtHandler
235 //-----------------------------------------------------------------------------
237 class wxDataViewEditorCtrlEvtHandler
: public wxEvtHandler
240 wxDataViewEditorCtrlEvtHandler( wxControl
*editor
, wxDataViewRenderer
*owner
);
242 void AcceptChangesAndFinish();
243 void SetFocusOnIdle( bool focus
= true ) { m_focusOnIdle
= focus
; }
246 void OnChar( wxKeyEvent
&event
);
247 void OnKillFocus( wxFocusEvent
&event
);
248 void OnIdle( wxIdleEvent
&event
);
251 wxDataViewRenderer
*m_owner
;
252 wxControl
*m_editorCtrl
;
257 DECLARE_EVENT_TABLE()
260 // ---------------------------------------------------------
261 // wxDataViewRendererBase
262 // ---------------------------------------------------------
264 enum wxDataViewCellMode
266 wxDATAVIEW_CELL_INERT
,
267 wxDATAVIEW_CELL_ACTIVATABLE
,
268 wxDATAVIEW_CELL_EDITABLE
271 enum wxDataViewCellRenderState
273 wxDATAVIEW_CELL_SELECTED
= 1,
274 wxDATAVIEW_CELL_PRELIT
= 2,
275 wxDATAVIEW_CELL_INSENSITIVE
= 4,
276 wxDATAVIEW_CELL_FOCUSED
= 8
279 class WXDLLIMPEXP_ADV wxDataViewRendererBase
: public wxObject
282 wxDataViewRendererBase( const wxString
&varianttype
,
283 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
,
284 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
286 virtual bool Validate( wxVariant
& WXUNUSED(value
) )
289 void SetOwner( wxDataViewColumn
*owner
) { m_owner
= owner
; }
290 wxDataViewColumn
* GetOwner() { return m_owner
; }
292 // renderer properties:
294 virtual bool SetValue( const wxVariant
& WXUNUSED(value
) ) = 0;
295 virtual bool GetValue( wxVariant
& WXUNUSED(value
) ) const = 0;
297 wxString
GetVariantType() const { return m_variantType
; }
299 virtual void SetMode( wxDataViewCellMode mode
) = 0;
300 virtual wxDataViewCellMode
GetMode() const = 0;
302 // NOTE: Set/GetAlignment do not take/return a wxAlignment enum but
303 // rather an "int"; that's because for rendering cells it's allowed
304 // to combine alignment flags (e.g. wxALIGN_LEFT|wxALIGN_BOTTOM)
305 virtual void SetAlignment( int align
) = 0;
306 virtual int GetAlignment() const = 0;
309 virtual bool HasEditorCtrl()
311 virtual wxControl
* CreateEditorCtrl(wxWindow
* WXUNUSED(parent
),
312 wxRect
WXUNUSED(labelRect
),
313 const wxVariant
& WXUNUSED(value
))
315 virtual bool GetValueFromEditorCtrl(wxControl
* WXUNUSED(editor
),
316 wxVariant
& WXUNUSED(value
))
319 virtual bool StartEditing( const wxDataViewItem
&item
, wxRect labelRect
);
320 virtual void CancelEditing();
321 virtual bool FinishEditing();
323 wxControl
*GetEditorCtrl() { return m_editorCtrl
; }
326 wxString m_variantType
;
327 wxDataViewColumn
*m_owner
;
328 wxControl
*m_editorCtrl
;
329 wxDataViewItem m_item
; // for m_editorCtrl
332 const wxDataViewCtrl
* GetView() const;
335 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRendererBase
)
338 //-----------------------------------------------------------------------------
339 // wxDataViewIconText
340 //-----------------------------------------------------------------------------
342 class WXDLLIMPEXP_ADV wxDataViewIconText
: public wxObject
345 wxDataViewIconText( const wxString
&text
= wxEmptyString
, const wxIcon
& icon
= wxNullIcon
)
346 { m_icon
= icon
; m_text
= text
; }
347 wxDataViewIconText( const wxDataViewIconText
&other
)
348 { m_icon
= other
.m_icon
; m_text
= other
.m_text
; }
350 void SetText( const wxString
&text
) { m_text
= text
; }
351 wxString
GetText() const { return m_text
; }
352 void SetIcon( const wxIcon
&icon
) { m_icon
= icon
; }
353 const wxIcon
&GetIcon() const { return m_icon
; }
360 DECLARE_DYNAMIC_CLASS(wxDataViewIconText
)
363 bool operator == (const wxDataViewIconText
&one
, const wxDataViewIconText
&two
);
365 DECLARE_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
367 // ---------------------------------------------------------
368 // wxDataViewColumnBase
369 // ---------------------------------------------------------
371 enum wxDataViewColumnFlags
373 wxDATAVIEW_COL_RESIZABLE
= 1,
374 wxDATAVIEW_COL_SORTABLE
= 2,
375 wxDATAVIEW_COL_HIDDEN
= 4
378 class WXDLLIMPEXP_ADV wxDataViewColumnBase
: public wxObject
381 wxDataViewColumnBase( const wxString
&title
, wxDataViewRenderer
*renderer
,
382 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
383 wxAlignment align
= wxALIGN_CENTER
,
384 int flags
= wxDATAVIEW_COL_RESIZABLE
);
385 wxDataViewColumnBase( const wxBitmap
&bitmap
, wxDataViewRenderer
*renderer
,
386 unsigned int model_column
, int width
= wxDVC_DEFAULT_WIDTH
,
387 wxAlignment align
= wxALIGN_CENTER
,
388 int flags
= wxDATAVIEW_COL_RESIZABLE
);
389 virtual ~wxDataViewColumnBase();
393 virtual void SetTitle( const wxString
&title
) = 0;
394 virtual void SetAlignment( wxAlignment align
) = 0;
395 virtual void SetSortable( bool sortable
) = 0;
396 virtual void SetResizeable( bool resizeable
) = 0;
397 virtual void SetHidden( bool hidden
) = 0;
398 virtual void SetSortOrder( bool ascending
) = 0;
399 virtual void SetFlags( int flags
);
400 virtual void SetOwner( wxDataViewCtrl
*owner
)
402 virtual void SetBitmap( const wxBitmap
&bitmap
)
405 virtual void SetMinWidth( int minWidth
) = 0;
406 virtual void SetWidth( int width
) = 0;
411 virtual wxString
GetTitle() const = 0;
412 virtual wxAlignment
GetAlignment() const = 0;
413 virtual int GetWidth() const = 0;
414 virtual int GetMinWidth() const = 0;
416 virtual int GetFlags() const;
418 virtual bool IsSortable() const = 0;
419 virtual bool IsResizeable() const = 0;
420 virtual bool IsHidden() const = 0;
421 virtual bool IsSortOrderAscending() const = 0;
423 const wxBitmap
&GetBitmap() const { return m_bitmap
; }
424 unsigned int GetModelColumn() const { return static_cast<unsigned int>(m_model_column
); }
426 wxDataViewCtrl
*GetOwner() { return m_owner
; }
427 wxDataViewRenderer
* GetRenderer() { return m_renderer
; }
430 wxDataViewRenderer
*m_renderer
;
433 wxDataViewCtrl
*m_owner
;
436 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase
)
439 // ---------------------------------------------------------
440 // wxDataViewCtrlBase
441 // ---------------------------------------------------------
443 #define wxDV_SINGLE 0x0000 // for convenience
444 #define wxDV_MULTIPLE 0x0001 // can select multiple items
446 #define wxDV_NO_HEADER 0x0002 // column titles not visible
447 #define wxDV_HORIZ_RULES 0x0004 // light horizontal rules between rows
448 #define wxDV_VERT_RULES 0x0008 // light vertical rules between columns
450 class WXDLLIMPEXP_ADV wxDataViewCtrlBase
: public wxControl
453 wxDataViewCtrlBase();
454 virtual ~wxDataViewCtrlBase();
456 virtual bool AssociateModel( wxDataViewModel
*model
);
457 wxDataViewModel
* GetModel();
460 wxDataViewColumn
*PrependTextColumn( const wxString
&label
, unsigned int model_column
,
461 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
462 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
463 int flags
= wxDATAVIEW_COL_RESIZABLE
);
464 wxDataViewColumn
*PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
465 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
466 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
467 int flags
= wxDATAVIEW_COL_RESIZABLE
);
468 wxDataViewColumn
*PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
469 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
470 wxAlignment align
= wxALIGN_CENTER
,
471 int flags
= wxDATAVIEW_COL_RESIZABLE
);
472 wxDataViewColumn
*PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
473 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
474 wxAlignment align
= wxALIGN_CENTER
,
475 int flags
= wxDATAVIEW_COL_RESIZABLE
);
476 wxDataViewColumn
*PrependDateColumn( const wxString
&label
, unsigned int model_column
,
477 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
478 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
479 int flags
= wxDATAVIEW_COL_RESIZABLE
);
480 wxDataViewColumn
*PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
481 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
482 wxAlignment align
= wxALIGN_CENTER
,
483 int flags
= wxDATAVIEW_COL_RESIZABLE
);
484 wxDataViewColumn
*PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
485 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
486 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
487 int flags
= wxDATAVIEW_COL_RESIZABLE
);
488 wxDataViewColumn
*PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
489 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
490 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
491 int flags
= wxDATAVIEW_COL_RESIZABLE
);
492 wxDataViewColumn
*PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
493 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
494 wxAlignment align
= wxALIGN_CENTER
,
495 int flags
= wxDATAVIEW_COL_RESIZABLE
);
496 wxDataViewColumn
*PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
497 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
498 wxAlignment align
= wxALIGN_CENTER
,
499 int flags
= wxDATAVIEW_COL_RESIZABLE
);
500 wxDataViewColumn
*PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
501 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
502 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
503 int flags
= wxDATAVIEW_COL_RESIZABLE
);
504 wxDataViewColumn
*PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
505 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
506 wxAlignment align
= wxALIGN_CENTER
,
507 int flags
= wxDATAVIEW_COL_RESIZABLE
);
509 wxDataViewColumn
*AppendTextColumn( const wxString
&label
, unsigned int model_column
,
510 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
511 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
512 int flags
= wxDATAVIEW_COL_RESIZABLE
);
513 wxDataViewColumn
*AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
514 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
515 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
516 int flags
= wxDATAVIEW_COL_RESIZABLE
);
517 wxDataViewColumn
*AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
518 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
519 wxAlignment align
= wxALIGN_CENTER
,
520 int flags
= wxDATAVIEW_COL_RESIZABLE
);
521 wxDataViewColumn
*AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
522 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
523 wxAlignment align
= wxALIGN_CENTER
,
524 int flags
= wxDATAVIEW_COL_RESIZABLE
);
525 wxDataViewColumn
*AppendDateColumn( const wxString
&label
, unsigned int model_column
,
526 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
527 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
528 int flags
= wxDATAVIEW_COL_RESIZABLE
);
529 wxDataViewColumn
*AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
530 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
531 wxAlignment align
= wxALIGN_CENTER
,
532 int flags
= wxDATAVIEW_COL_RESIZABLE
);
533 wxDataViewColumn
*AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
534 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
535 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
536 int flags
= wxDATAVIEW_COL_RESIZABLE
);
537 wxDataViewColumn
*AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
538 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
539 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
540 int flags
= wxDATAVIEW_COL_RESIZABLE
);
541 wxDataViewColumn
*AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
542 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_TOGGLE_DEFAULT_WIDTH
,
543 wxAlignment align
= wxALIGN_CENTER
,
544 int flags
= wxDATAVIEW_COL_RESIZABLE
);
545 wxDataViewColumn
*AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
546 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= wxDVC_DEFAULT_WIDTH
,
547 wxAlignment align
= wxALIGN_CENTER
,
548 int flags
= wxDATAVIEW_COL_RESIZABLE
);
549 wxDataViewColumn
*AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
550 wxDataViewCellMode mode
= wxDATAVIEW_CELL_ACTIVATABLE
, int width
= -1,
551 wxAlignment align
= (wxAlignment
)(wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
),
552 int flags
= wxDATAVIEW_COL_RESIZABLE
);
553 wxDataViewColumn
*AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
554 wxDataViewCellMode mode
= wxDATAVIEW_CELL_INERT
, int width
= -1,
555 wxAlignment align
= wxALIGN_CENTER
,
556 int flags
= wxDATAVIEW_COL_RESIZABLE
);
559 virtual bool PrependColumn( wxDataViewColumn
*col
);
560 virtual bool AppendColumn( wxDataViewColumn
*col
);
562 virtual unsigned int GetColumnCount() const = 0;
563 virtual wxDataViewColumn
* GetColumn( unsigned int pos
) const = 0;
564 virtual int GetColumnPosition( const wxDataViewColumn
*column
) const = 0;
566 virtual bool DeleteColumn( wxDataViewColumn
*column
) = 0;
567 virtual bool ClearColumns() = 0;
569 void SetExpanderColumn( wxDataViewColumn
*col
)
570 { m_expander_column
= col
; DoSetExpanderColumn(); }
571 wxDataViewColumn
*GetExpanderColumn() const
572 { return m_expander_column
; }
574 virtual wxDataViewColumn
*GetSortingColumn() const = 0;
576 void SetIndent( int indent
)
577 { m_indent
= indent
; DoSetIndent(); }
578 int GetIndent() const
581 virtual wxDataViewItem
GetSelection() const = 0;
582 virtual int GetSelections( wxDataViewItemArray
& sel
) const = 0;
583 virtual void SetSelections( const wxDataViewItemArray
& sel
) = 0;
584 virtual void Select( const wxDataViewItem
& item
) = 0;
585 virtual void Unselect( const wxDataViewItem
& item
) = 0;
586 virtual bool IsSelected( const wxDataViewItem
& item
) const = 0;
588 virtual void SelectAll() = 0;
589 virtual void UnselectAll() = 0;
591 virtual void Expand( const wxDataViewItem
& item
) = 0;
592 virtual void Collapse( const wxDataViewItem
& item
) = 0;
594 virtual void EnsureVisible( const wxDataViewItem
& item
,
595 const wxDataViewColumn
*column
= NULL
) = 0;
596 virtual void HitTest( const wxPoint
& point
, wxDataViewItem
&item
, wxDataViewColumn
* &column
) const = 0;
597 virtual wxRect
GetItemRect( const wxDataViewItem
& item
, const wxDataViewColumn
*column
= NULL
) const = 0;
600 virtual void DoSetExpanderColumn() = 0 ;
601 virtual void DoSetIndent() = 0;
604 wxDataViewModel
*m_model
;
605 wxDataViewColumn
*m_expander_column
;
609 DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase
)
612 // ----------------------------------------------------------------------------
613 // wxDataViewEvent - the event class for the wxDataViewCtrl notifications
614 // ----------------------------------------------------------------------------
616 class WXDLLIMPEXP_ADV wxDataViewEvent
: public wxNotifyEvent
619 wxDataViewEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0)
620 : wxNotifyEvent(commandType
, winid
),
624 m_value(wxNullVariant
),
628 wxDataViewEvent(const wxDataViewEvent
& event
)
629 : wxNotifyEvent(event
),
630 m_item(event
.m_item
),
632 m_model(event
.m_model
),
633 m_value(event
.m_value
),
634 m_column(event
.m_column
)
637 wxDataViewItem
GetItem() const { return m_item
; }
638 void SetItem( const wxDataViewItem
&item
) { m_item
= item
; }
640 int GetColumn() const { return m_col
; }
641 void SetColumn( int col
) { m_col
= col
; }
643 wxDataViewModel
* GetModel() const { return m_model
; }
644 void SetModel( wxDataViewModel
*model
) { m_model
= model
; }
646 const wxVariant
&GetValue() const { return m_value
; }
647 void SetValue( const wxVariant
&value
) { m_value
= value
; }
649 // for wxEVT_DATAVIEW_COLUMN_HEADER_CLICKED only
650 void SetDataViewColumn( wxDataViewColumn
*col
) { m_column
= col
; }
651 wxDataViewColumn
*GetDataViewColumn() const { return m_column
; }
653 virtual wxEvent
*Clone() const { return new wxDataViewEvent(*this); }
656 wxDataViewItem m_item
;
658 wxDataViewModel
*m_model
;
660 wxDataViewColumn
*m_column
;
663 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewEvent
)
666 BEGIN_DECLARE_EVENT_TYPES()
667 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, -1)
669 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, -1)
670 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, -1)
671 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, -1)
672 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, -1)
673 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, -1)
674 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, -1)
675 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, -1)
676 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, -1)
678 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, -1)
679 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, -1)
680 DECLARE_EXPORTED_EVENT_TYPE(WXDLLIMPEXP_ADV
, wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, -1)
681 END_DECLARE_EVENT_TYPES()
683 typedef void (wxEvtHandler::*wxDataViewEventFunction
)(wxDataViewEvent
&);
685 #define wxDataViewEventHandler(func) \
686 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(wxDataViewEventFunction, &func)
688 #define wx__DECLARE_DATAVIEWEVT(evt, id, fn) \
689 wx__DECLARE_EVT1(wxEVT_COMMAND_DATAVIEW_ ## evt, id, wxDataViewEventHandler(fn))
691 #define EVT_DATAVIEW_SELECTION_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(SELECTION_CHANGED, id, fn)
693 #define EVT_DATAVIEW_ITEM_ACTIVATED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_ACTIVATED, id, fn)
694 #define EVT_DATAVIEW_ITEM_COLLAPSING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSING, id, fn)
695 #define EVT_DATAVIEW_ITEM_COLLAPSED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_COLLAPSED, id, fn)
696 #define EVT_DATAVIEW_ITEM_EXPANDING(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDING, id, fn)
697 #define EVT_DATAVIEW_ITEM_EXPANDED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EXPANDED, id, fn)
698 #define EVT_DATAVIEW_ITEM_EDITING_STARTED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_STARTED, id, fn)
699 #define EVT_DATAVIEW_ITEM_EDITING_DONE(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_EDITING_DONE, id, fn)
700 #define EVT_DATAVIEW_ITEM_VALUE_CHANGED(id, fn) wx__DECLARE_DATAVIEWEVT(ITEM_VALUE_CHANGED, id, fn)
702 #define EVT_DATAVIEW_COLUMN_HEADER_CLICK(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_CLICK, id, fn)
703 #define EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_HEADER_RIGHT_CLICK, id, fn)
704 #define EVT_DATAVIEW_COLUMN_SORTED(id, fn) wx__DECLARE_DATAVIEWEVT(COLUMN_SORTED, id, fn)
706 #if defined(wxUSE_GENERICDATAVIEWCTRL)
707 #include "wx/generic/dataview.h"
708 #elif defined(__WXGTK20__)
709 #include "wx/gtk/dataview.h"
710 #elif defined(__WXMAC__)
711 #include "wx/mac/dataview.h"
713 #include "wx/generic/dataview.h"
716 // -------------------------------------
717 // wxDataViewSpinRenderer
718 // -------------------------------------
720 class wxDataViewSpinRenderer
: public wxDataViewCustomRenderer
723 wxDataViewSpinRenderer( int min
, int max
,
724 wxDataViewCellMode mode
= wxDATAVIEW_CELL_EDITABLE
,
725 int alignment
= wxDVR_DEFAULT_ALIGNMENT
);
726 virtual bool HasEditorCtrl() { return true; }
727 virtual wxControl
* CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
);
728 virtual bool GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
);
729 virtual bool Render( wxRect rect
, wxDC
*dc
, int state
);
730 virtual wxSize
GetSize() const;
731 virtual bool SetValue( const wxVariant
&value
);
732 virtual bool GetValue( wxVariant
&value
) const;
739 //-----------------------------------------------------------------------------
740 // wxDataViewTreeStore
741 //-----------------------------------------------------------------------------
743 class WXDLLIMPEXP_ADV wxDataViewTreeStoreNode
746 wxDataViewTreeStoreNode( wxDataViewTreeStoreNode
*parent
,
747 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
748 virtual ~wxDataViewTreeStoreNode();
750 void SetText( const wxString
&text
)
752 wxString
GetText() const
754 void SetIcon( const wxIcon
&icon
)
756 const wxIcon
&GetIcon() const
758 void SetData( wxClientData
*data
)
759 { if (m_data
) delete m_data
; m_data
= data
; }
760 wxClientData
*GetData() const
763 wxDataViewItem
GetItem() const
764 { return wxDataViewItem( (void*) this ); }
766 virtual bool IsContainer()
769 wxDataViewTreeStoreNode
*GetParent()
773 wxDataViewTreeStoreNode
*m_parent
;
776 wxClientData
*m_data
;
779 WX_DECLARE_LIST_WITH_DECL(wxDataViewTreeStoreNode
, wxDataViewTreeStoreNodeList
,
780 class WXDLLIMPEXP_ADV
);
782 class WXDLLIMPEXP_ADV wxDataViewTreeStoreContainerNode
: public wxDataViewTreeStoreNode
785 wxDataViewTreeStoreContainerNode( wxDataViewTreeStoreNode
*parent
,
786 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
787 wxClientData
*data
= NULL
);
788 virtual ~wxDataViewTreeStoreContainerNode();
790 const wxDataViewTreeStoreNodeList
&GetChildren() const
791 { return m_children
; }
792 wxDataViewTreeStoreNodeList
&GetChildren()
793 { return m_children
; }
795 void SetExpandedIcon( const wxIcon
&icon
)
796 { m_iconExpanded
= icon
; }
797 const wxIcon
&GetExpandedIcon() const
798 { return m_iconExpanded
; }
800 virtual bool IsContainer()
804 wxDataViewTreeStoreNodeList m_children
;
805 wxIcon m_iconExpanded
;
808 //-----------------------------------------------------------------------------
810 class WXDLLIMPEXP_ADV wxDataViewTreeStore
: public wxDataViewModel
813 wxDataViewTreeStore();
814 ~wxDataViewTreeStore();
816 wxDataViewItem
AppendItem( const wxDataViewItem
& parent
,
817 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
818 wxDataViewItem
PrependItem( const wxDataViewItem
& parent
,
819 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
820 wxDataViewItem
InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
821 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, wxClientData
*data
= NULL
);
823 wxDataViewItem
PrependContainer( const wxDataViewItem
& parent
,
824 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
825 wxClientData
*data
= NULL
);
826 wxDataViewItem
AppendContainer( const wxDataViewItem
& parent
,
827 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
828 wxClientData
*data
= NULL
);
829 wxDataViewItem
InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
830 const wxString
&text
, const wxIcon
&icon
= wxNullIcon
, const wxIcon
&expanded
= wxNullIcon
,
831 wxClientData
*data
= NULL
);
833 wxDataViewItem
GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const;
834 int GetChildCount( const wxDataViewItem
& parent
) const;
836 void SetItemText( const wxDataViewItem
& item
, const wxString
&text
);
837 wxString
GetItemText( const wxDataViewItem
& item
) const;
838 void SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
839 const wxIcon
&GetItemIcon( const wxDataViewItem
& item
) const;
840 void SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
);
841 const wxIcon
&GetItemExpandedIcon( const wxDataViewItem
& item
) const;
842 void SetItemData( const wxDataViewItem
& item
, wxClientData
*data
);
843 wxClientData
*GetItemData( const wxDataViewItem
& item
) const;
845 void DeleteItem( const wxDataViewItem
& item
);
846 void DeleteChildren( const wxDataViewItem
& item
);
847 void DeleteAllItems();
849 // implement base methods
851 virtual void GetValue( wxVariant
&variant
,
852 const wxDataViewItem
&item
, unsigned int col
) const;
853 virtual bool SetValue( const wxVariant
&variant
,
854 const wxDataViewItem
&item
, unsigned int col
);
855 virtual wxDataViewItem
GetParent( const wxDataViewItem
&item
) const;
856 virtual bool IsContainer( const wxDataViewItem
&item
) const;
857 virtual unsigned int GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const;
859 virtual int Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
860 unsigned int column
, bool ascending
);
862 virtual bool HasDefaultCompare() const
864 virtual unsigned int GetColumnCount() const
866 virtual wxString
GetColumnType( unsigned int WXUNUSED(col
) ) const
867 { return "wxDataViewIconText"; }
869 wxDataViewTreeStoreNode
*FindNode( const wxDataViewItem
&item
) const;
870 wxDataViewTreeStoreContainerNode
*FindContainerNode( const wxDataViewItem
&item
) const;
871 wxDataViewTreeStoreNode
*GetRoot() const { return m_root
; }
874 wxDataViewTreeStoreNode
*m_root
;
878 class WXDLLIMPEXP_ADV wxDataViewTreeCtrl
: public wxDataViewCtrl
881 wxDataViewCtrl( wxWindow
*parent
, wxWindowID id
,
882 const wxPoint
& pos
= wxDefaultPosition
,
883 const wxSize
& size
= wxDefaultSize
, long style
= wxDV_NO_HEADER
,
884 const wxValidator
& validator
= wxDefaultValidator
);
886 bool Create( wxWindow
*parent
, wxWindowID id
,
887 const wxPoint
& pos
= wxDefaultPosition
,
888 const wxSize
& size
= wxDefaultSize
, long style
= wxDV_NO_HEADER
,
889 const wxValidator
& validator
= wxDefaultValidator
);
891 wxDataViewTreeStore
*GetStore()
892 { return (wxDataViewTreeStore
*) GetModel(); }
894 void OnExpand( wxDataViewCtrl
&event
);
895 void OnCollapse( wxDataViewCtrl
&event
);
898 DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxDataViewTreeCtrl
)
902 #endif // wxUSE_DATAVIEWCTRL
905 // _WX_DATAVIEW_H_BASE_