1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/datavcmn.cpp
3 // Purpose: wxDataViewCtrl base classes and common parts
4 // Author: Robert Roebling
7 // Copyright: (c) 2006, Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_DATAVIEWCTRL
20 #include "wx/dataview.h"
22 #include "wx/spinctrl.h"
26 #include "wx/settings.h"
32 const wxChar wxDataViewCtrlNameStr
[] = wxT("dataviewCtrl");
35 bool operator == (const wxDataViewItem
&left
, const wxDataViewItem
&right
)
37 return (left
.GetID() == right
.GetID() );
41 void wxDataViewItem::Print(const wxString
& text
) const
43 wxPrintf("item %s: %l\n", text
, (long)m_id
);
47 // ---------------------------------------------------------
48 // wxDataViewModelNotifier
49 // ---------------------------------------------------------
51 #include "wx/listimpl.cpp"
52 WX_DEFINE_LIST(wxDataViewModelNotifiers
)
54 bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
56 size_t count
= items
.GetCount();
58 for (i
= 0; i
< count
; i
++)
59 if (!ItemAdded( parent
, items
[i
] )) return false;
64 bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
66 size_t count
= items
.GetCount();
68 for (i
= 0; i
< count
; i
++)
69 if (!ItemDeleted( parent
, items
[i
] )) return false;
74 bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray
&items
)
76 size_t count
= items
.GetCount();
78 for (i
= 0; i
< count
; i
++)
79 if (!ItemChanged( items
[i
] )) return false;
84 // ---------------------------------------------------------
86 // ---------------------------------------------------------
88 wxDataViewModel::wxDataViewModel()
90 m_notifiers
.DeleteContents( true );
93 bool wxDataViewModel::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
97 wxDataViewModelNotifiers::iterator iter
;
98 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
100 wxDataViewModelNotifier
* notifier
= *iter
;
101 if (!notifier
->ItemAdded( parent
, item
))
108 bool wxDataViewModel::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
112 wxDataViewModelNotifiers::iterator iter
;
113 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
115 wxDataViewModelNotifier
* notifier
= *iter
;
116 if (!notifier
->ItemDeleted( parent
, item
))
123 bool wxDataViewModel::ItemChanged( const wxDataViewItem
&item
)
127 wxDataViewModelNotifiers::iterator iter
;
128 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
130 wxDataViewModelNotifier
* notifier
= *iter
;
131 if (!notifier
->ItemChanged( item
))
138 bool wxDataViewModel::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
142 wxDataViewModelNotifiers::iterator iter
;
143 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
145 wxDataViewModelNotifier
* notifier
= *iter
;
146 if (!notifier
->ItemsAdded( parent
, items
))
153 bool wxDataViewModel::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
157 wxDataViewModelNotifiers::iterator iter
;
158 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
160 wxDataViewModelNotifier
* notifier
= *iter
;
161 if (!notifier
->ItemsDeleted( parent
, items
))
168 bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray
&items
)
172 wxDataViewModelNotifiers::iterator iter
;
173 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
175 wxDataViewModelNotifier
* notifier
= *iter
;
176 if (!notifier
->ItemsChanged( items
))
183 bool wxDataViewModel::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
187 wxDataViewModelNotifiers::iterator iter
;
188 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
190 wxDataViewModelNotifier
* notifier
= *iter
;
191 if (!notifier
->ValueChanged( item
, col
))
198 bool wxDataViewModel::Cleared()
202 wxDataViewModelNotifiers::iterator iter
;
203 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
205 wxDataViewModelNotifier
* notifier
= *iter
;
206 if (!notifier
->Cleared())
213 void wxDataViewModel::Resort()
215 wxDataViewModelNotifiers::iterator iter
;
216 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
218 wxDataViewModelNotifier
* notifier
= *iter
;
223 void wxDataViewModel::AddNotifier( wxDataViewModelNotifier
*notifier
)
225 m_notifiers
.push_back( notifier
);
226 notifier
->SetOwner( this );
229 void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier
*notifier
)
231 m_notifiers
.DeleteObject( notifier
);
234 int wxDataViewModel::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
235 unsigned int column
, bool ascending
)
237 // sort branches before leaves
238 bool item1_is_container
= IsContainer(item1
);
239 bool item2_is_container
= IsContainer(item2
);
241 if (item1_is_container
&& !item2_is_container
)
243 if (item2_is_container
&& !item1_is_container
)
246 wxVariant value1
,value2
;
247 GetValue( value1
, item1
, column
);
248 GetValue( value2
, item2
, column
);
252 wxVariant temp
= value1
;
257 if (value1
.GetType() == wxT("string"))
259 wxString str1
= value1
.GetString();
260 wxString str2
= value2
.GetString();
261 int res
= str1
.Cmp( str2
);
264 if (value1
.GetType() == wxT("long"))
266 long l1
= value1
.GetLong();
267 long l2
= value2
.GetLong();
271 if (value1
.GetType() == wxT("double"))
273 double d1
= value1
.GetDouble();
274 double d2
= value2
.GetDouble();
275 if (d1
< d2
) return 1;
276 if (d1
> d2
) return -1;
278 if (value1
.GetType() == wxT("datetime"))
280 wxDateTime dt1
= value1
.GetDateTime();
281 wxDateTime dt2
= value2
.GetDateTime();
282 if (dt1
.IsEarlierThan(dt2
)) return 1;
283 if (dt2
.IsEarlierThan(dt1
)) return -11;
286 // items must be different
287 unsigned long litem1
= (unsigned long) item1
.GetID();
288 unsigned long litem2
= (unsigned long) item2
.GetID();
291 return litem2
-litem2
;
293 return litem1
-litem2
;
296 // ---------------------------------------------------------
297 // wxDataViewIndexListModel
298 // ---------------------------------------------------------
300 wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size
)
310 // IDs are ordered until an item gets deleted or inserted
313 // build initial index
315 for (i
= 1; i
< initial_size
+1; i
++)
316 m_hash
.Add( (void*) i
);
317 m_lastIndex
= initial_size
+ 1;
321 m_lastIndex
= initial_size
-1;
325 wxDataViewIndexListModel::~wxDataViewIndexListModel()
329 void wxDataViewIndexListModel::RowPrepended()
335 unsigned int id
= m_lastIndex
++;
336 m_hash
.Insert( (void*) id
, 0 );
337 wxDataViewItem
item( (void*) id
);
338 ItemAdded( wxDataViewItem(0), item
);
343 wxDataViewItem
item( (void*) 0 );
344 ItemAdded( wxDataViewItem(0), item
);
348 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
354 unsigned int id
= m_lastIndex
++;
355 m_hash
.Insert( (void*) id
, before
);
356 wxDataViewItem
item( (void*) id
);
357 ItemAdded( wxDataViewItem(0), item
);
362 wxDataViewItem
item( (void*) before
);
363 ItemAdded( wxDataViewItem(0), item
);
367 void wxDataViewIndexListModel::RowAppended()
371 unsigned int id
= m_lastIndex
++;
372 m_hash
.Add( (void*) id
);
373 wxDataViewItem
item( (void*) id
);
374 ItemAdded( wxDataViewItem(0), item
);
379 wxDataViewItem
item( (void*) m_lastIndex
);
380 ItemAdded( wxDataViewItem(0), item
);
384 void wxDataViewIndexListModel::RowDeleted( unsigned int row
)
390 wxDataViewItem
item( m_hash
[row
] );
391 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
392 m_hash
.RemoveAt( row
);
396 wxDataViewItem
item( (void*) row
);
397 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
402 static int my_sort( int *v1
, int *v2
)
407 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt
&rows
)
409 wxArrayInt sorted
= rows
;
410 sorted
.Sort( my_sort
);
416 wxDataViewItemArray array
;
418 for (i
= 0; i
< rows
.GetCount(); i
++)
420 wxDataViewItem
item( m_hash
[rows
[i
]] );
423 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
425 for (i
= 0; i
< sorted
.GetCount(); i
++)
426 m_hash
.RemoveAt( sorted
[i
] );
430 wxDataViewItemArray array
;
432 for (i
= 0; i
< sorted
.GetCount(); i
++)
434 wxDataViewItem
item( (void*) sorted
[i
] );
437 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
439 m_lastIndex
-= rows
.GetCount();
443 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
445 wxDataViewModel::ItemChanged( GetItem(row
) );
448 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
450 wxDataViewModel::ValueChanged( GetItem(row
), col
);
453 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
459 unsigned int pos
= wxPtrToUInt( item
.GetID() );
463 // assert for not found
464 return (unsigned int) m_hash
.Index( item
.GetID() );
468 return wxPtrToUInt( item
.GetID() );
472 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
476 wxASSERT( row
< m_hash
.GetCount() );
477 return wxDataViewItem( m_hash
[row
] );
481 return wxDataViewItem( (void*) row
);
485 bool wxDataViewIndexListModel::HasDefaultCompare() const
490 int wxDataViewIndexListModel::Compare(const wxDataViewItem
& item1
,
491 const wxDataViewItem
& item2
,
492 unsigned int WXUNUSED(column
),
495 if (m_ordered
|| !m_useHash
)
497 unsigned int pos1
= wxPtrToUInt(item1
.GetID());
498 unsigned int pos2
= wxPtrToUInt(item2
.GetID());
507 return GetRow(item1
) - GetRow(item2
);
509 return GetRow(item2
) - GetRow(item1
);
512 void wxDataViewIndexListModel::GetValue( wxVariant
&variant
,
513 const wxDataViewItem
&item
, unsigned int col
) const
515 GetValue( variant
, GetRow(item
), col
);
518 bool wxDataViewIndexListModel::SetValue( const wxVariant
&variant
,
519 const wxDataViewItem
&item
, unsigned int col
)
521 return SetValue( variant
, GetRow(item
), col
);
524 bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
526 return GetAttr( GetRow(item
), col
, attr
);
529 wxDataViewItem
wxDataViewIndexListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
531 return wxDataViewItem(0);
534 bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem
&item
) const
536 // only the invisible root item has children
543 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
553 return m_hash
.GetCount();
556 //-----------------------------------------------------------------------------
557 // wxDataViewIconText
558 //-----------------------------------------------------------------------------
560 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
562 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
564 bool operator == (const wxDataViewIconText
&one
, const wxDataViewIconText
&two
)
566 if (one
.GetText() != two
.GetText()) return false;
567 if (one
.IsSameAs(two
)) return false;
571 // ---------------------------------------------------------
572 // wxDataViewRendererBase
573 // ---------------------------------------------------------
575 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
577 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
578 wxDataViewCellMode
WXUNUSED(mode
),
579 int WXUNUSED(align
) )
581 m_variantType
= varianttype
;
585 const wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
587 return wx_const_cast(wxDataViewRendererBase
*, this)->GetOwner()->GetOwner();
590 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
592 m_item
= item
; // remember for later
594 unsigned int col
= GetOwner()->GetModelColumn();
596 GetOwner()->GetOwner()->GetModel()->GetValue( value
, item
, col
);
598 m_editorCtrl
= CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect
, value
);
600 wxDataViewEditorCtrlEvtHandler
*handler
=
601 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
603 m_editorCtrl
->PushEventHandler( handler
);
605 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
606 handler
->SetFocusOnIdle();
608 m_editorCtrl
->SetFocus();
611 // Now we should send Editing Started event
612 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, GetOwner()->GetOwner()->GetId() );
613 event
.SetDataViewColumn( GetOwner() );
614 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
615 event
.SetItem( item
);
616 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
621 void wxDataViewRendererBase::CancelEditing()
623 wxPendingDelete
.Append( m_editorCtrl
);
625 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
627 // m_editorCtrl->PopEventHandler( true );
630 bool wxDataViewRendererBase::FinishEditing()
633 GetValueFromEditorCtrl( m_editorCtrl
, value
);
635 wxPendingDelete
.Append( m_editorCtrl
);
637 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
639 if (!Validate(value
))
642 unsigned int col
= GetOwner()->GetModelColumn();
643 GetOwner()->GetOwner()->GetModel()->SetValue( value
, m_item
, col
);
644 GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item
, col
);
646 // m_editorCtrl->PopEventHandler( true );
648 // Now we should send Editing Done event
649 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, GetOwner()->GetOwner()->GetId() );
650 event
.SetDataViewColumn( GetOwner() );
651 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
652 event
.SetItem( m_item
);
653 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
658 //-----------------------------------------------------------------------------
659 // wxDataViewEditorCtrlEvtHandler
660 //-----------------------------------------------------------------------------
662 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
663 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
664 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
665 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
668 wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
669 wxControl
*editorCtrl
,
670 wxDataViewRenderer
*owner
)
673 m_editorCtrl
= editorCtrl
;
678 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
682 m_focusOnIdle
= false;
683 if (wxWindow::FindFocus() != m_editorCtrl
)
684 m_editorCtrl
->SetFocus();
690 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
692 switch ( event
.m_keyCode
)
696 m_owner
->FinishEditing();
701 m_owner
->CancelEditing();
709 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
714 m_owner
->FinishEditing();
720 // ---------------------------------------------------------
721 // wxDataViewColumnBase
722 // ---------------------------------------------------------
724 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase
, wxObject
)
726 wxDataViewColumnBase::wxDataViewColumnBase(const wxString
& WXUNUSED(title
),
727 wxDataViewRenderer
*renderer
,
728 unsigned int model_column
,
730 wxAlignment
WXUNUSED(align
),
733 m_renderer
= renderer
;
734 m_model_column
= model_column
;
736 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
738 // NOTE: the wxDataViewColumn's ctor must store the width, align, flags
739 // parameters inside the native control!
742 wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap
& bitmap
,
743 wxDataViewRenderer
*renderer
,
744 unsigned int model_column
,
746 wxAlignment
WXUNUSED(align
),
747 int WXUNUSED(flags
) )
749 m_renderer
= renderer
;
750 m_model_column
= model_column
;
753 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
756 wxDataViewColumnBase::~wxDataViewColumnBase()
762 int wxDataViewColumnBase::GetFlags() const
767 ret
|= wxDATAVIEW_COL_SORTABLE
;
769 ret
|= wxDATAVIEW_COL_RESIZABLE
;
771 ret
|= wxDATAVIEW_COL_HIDDEN
;
776 void wxDataViewColumnBase::SetFlags(int flags
)
778 SetSortable((flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
779 SetResizeable((flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
780 SetHidden((flags
& wxDATAVIEW_COL_HIDDEN
) != 0);
783 // ---------------------------------------------------------
784 // wxDataViewCtrlBase
785 // ---------------------------------------------------------
787 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
789 wxDataViewCtrlBase::wxDataViewCtrlBase()
792 m_expander_column
= 0;
796 wxDataViewCtrlBase::~wxDataViewCtrlBase()
805 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
809 m_model
->DecRef(); // discard old model, if any
812 // add our own reference to the new model:
822 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
827 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
833 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
834 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
836 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
837 new wxDataViewTextRenderer( wxT("string"), mode
, (int)align
),
838 model_column
, width
, align
, flags
);
844 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
845 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
847 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
848 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
, (int)align
),
849 model_column
, width
, align
, flags
);
855 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
856 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
859 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
860 new wxDataViewToggleRenderer( wxT("bool"), mode
, (int)align
),
861 model_column
, width
, align
, flags
);
867 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
868 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
870 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
871 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
, (int)align
),
872 model_column
, width
, align
, flags
);
878 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
879 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
881 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
882 new wxDataViewDateRenderer( wxT("datetime"), mode
, (int)align
),
883 model_column
, width
, align
, flags
);
889 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
890 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
892 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
893 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
, (int)align
),
894 model_column
, width
, align
, flags
);
900 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
901 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
903 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
904 new wxDataViewTextRenderer( wxT("string"), mode
, (int)align
),
905 model_column
, width
, align
, flags
);
911 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
912 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
914 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
915 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
, (int)align
),
916 model_column
, width
, align
, flags
);
922 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
923 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
925 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
926 new wxDataViewToggleRenderer( wxT("bool"), mode
, (int)align
),
927 model_column
, width
, align
, flags
);
933 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
934 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
936 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
937 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
, (int)align
),
938 model_column
, width
, align
, flags
);
944 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
945 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
947 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
948 new wxDataViewDateRenderer( wxT("datetime"), mode
, (int)align
),
949 model_column
, width
, align
, flags
);
955 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
956 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
958 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
959 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
, (int)align
),
960 model_column
, width
, align
, flags
);
966 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
967 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
969 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
970 new wxDataViewTextRenderer( wxT("string"), mode
, (int)align
),
971 model_column
, width
, align
, flags
);
972 PrependColumn( ret
);
977 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
978 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
980 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
981 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
, (int)align
),
982 model_column
, width
, align
, flags
);
983 PrependColumn( ret
);
988 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
989 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
992 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
993 new wxDataViewToggleRenderer( wxT("bool"), mode
, (int)align
),
994 model_column
, width
, align
, flags
);
995 PrependColumn( ret
);
1000 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1001 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1003 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1004 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
, (int)align
),
1005 model_column
, width
, align
, flags
);
1006 PrependColumn( ret
);
1011 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1012 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1014 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1015 new wxDataViewDateRenderer( wxT("datetime"), mode
, (int)align
),
1016 model_column
, width
, align
, flags
);
1017 PrependColumn( ret
);
1022 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1023 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1025 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1026 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
, (int)align
),
1027 model_column
, width
, align
, flags
);
1028 PrependColumn( ret
);
1033 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1034 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1036 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1037 new wxDataViewTextRenderer( wxT("string"), mode
, (int)align
),
1038 model_column
, width
, align
, flags
);
1039 PrependColumn( ret
);
1044 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1045 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1047 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1048 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
, (int)align
),
1049 model_column
, width
, align
, flags
);
1050 PrependColumn( ret
);
1055 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1056 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1058 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1059 new wxDataViewToggleRenderer( wxT("bool"), mode
, (int)align
),
1060 model_column
, width
, align
, flags
);
1061 PrependColumn( ret
);
1066 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1067 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1069 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1070 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
, (int)align
),
1071 model_column
, width
, align
, flags
);
1072 PrependColumn( ret
);
1077 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1078 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1080 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1081 new wxDataViewDateRenderer( wxT("datetime"), mode
, (int)align
),
1082 model_column
, width
, align
, flags
);
1083 PrependColumn( ret
);
1088 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1089 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1091 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1092 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
, (int)align
),
1093 model_column
, width
, align
, flags
);
1094 PrependColumn( ret
);
1099 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1101 col
->SetOwner( (wxDataViewCtrl
*) this );
1106 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1108 col
->SetOwner( (wxDataViewCtrl
*) this );
1112 // ---------------------------------------------------------
1114 // ---------------------------------------------------------
1116 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1118 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
)
1120 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
)
1121 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
)
1122 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
)
1123 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
)
1124 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
)
1125 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
)
1126 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
)
1127 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
)
1129 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
)
1131 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
)
1132 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
)
1133 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
)
1136 // -------------------------------------
1137 // wxDataViewSpinRenderer
1138 // -------------------------------------
1140 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1141 wxDataViewCustomRenderer( "long", mode
, alignment
)
1147 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1150 return new wxSpinCtrl( parent
, wxID_ANY
, wxEmptyString
,
1151 labelRect
.GetTopLeft(), labelRect
.GetSize(), wxSP_ARROW_KEYS
, m_min
, m_max
, l
);
1154 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1156 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1157 long l
= sc
->GetValue();
1162 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1165 str
.Printf( "%d", (int) m_data
);
1166 RenderText( str
, 0, rect
, dc
, state
);
1170 wxSize
wxDataViewSpinRenderer::GetSize() const
1172 return wxSize(80,16);
1175 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1177 m_data
= value
.GetLong();
1181 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1187 //-----------------------------------------------------------------------------
1188 // wxDataViewTreeStore
1189 //-----------------------------------------------------------------------------
1191 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1192 wxDataViewTreeStoreNode
*parent
,
1193 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1201 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1207 #include "wx/listimpl.cpp"
1208 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1210 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1211 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1212 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1213 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1215 m_iconExpanded
= expanded
;
1216 m_isExpanded
= false;
1217 m_children
.DeleteContents(true);
1220 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1224 //-----------------------------------------------------------------------------
1226 wxDataViewTreeStore::wxDataViewTreeStore()
1228 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1231 wxDataViewTreeStore::~wxDataViewTreeStore()
1236 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1237 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1239 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1240 if (!parent_node
) return wxDataViewItem(0);
1242 wxDataViewTreeStoreNode
*node
=
1243 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1244 parent_node
->GetChildren().Append( node
);
1247 ItemAdded( parent
, node
->GetItem() );
1249 return node
->GetItem();
1252 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1253 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1255 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1256 if (!parent_node
) return wxDataViewItem(0);
1258 wxDataViewTreeStoreNode
*node
=
1259 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1260 parent_node
->GetChildren().Insert( node
);
1263 ItemAdded( parent
, node
->GetItem() );
1265 return node
->GetItem();
1269 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& WXUNUSED(parent
),
1270 const wxDataViewItem
& WXUNUSED(previous
),
1271 const wxString
& WXUNUSED(text
),
1272 const wxIcon
& WXUNUSED(icon
),
1273 wxClientData
* WXUNUSED(data
))
1275 return wxDataViewItem(0);
1278 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1279 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1280 wxClientData
*data
)
1282 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1283 if (!parent_node
) return wxDataViewItem(0);
1285 wxDataViewTreeStoreContainerNode
*node
=
1286 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1287 parent_node
->GetChildren().Insert( node
);
1290 ItemAdded( parent
, node
->GetItem() );
1292 return node
->GetItem();
1296 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1297 const wxString
&text
,
1299 const wxIcon
& expanded
,
1300 wxClientData
* data
)
1302 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1303 if (!parent_node
) return wxDataViewItem(0);
1305 wxDataViewTreeStoreContainerNode
*node
=
1306 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1307 parent_node
->GetChildren().Append( node
);
1310 ItemAdded( parent
, node
->GetItem() );
1312 return node
->GetItem();
1316 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& WXUNUSED(parent
),
1317 const wxDataViewItem
& WXUNUSED(previous
),
1318 const wxString
& WXUNUSED(text
),
1319 const wxIcon
& WXUNUSED(icon
),
1320 const wxIcon
& WXUNUSED(expanded
),
1321 wxClientData
* WXUNUSED(data
))
1323 return wxDataViewItem(0);
1326 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1328 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1329 if (!parent_node
) return wxDataViewItem(0);
1331 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1333 return node
->GetData();
1335 return wxDataViewItem(0);
1338 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1340 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1341 if (!node
) return -1;
1343 if (!node
->IsContainer())
1346 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1347 return (int) container_node
->GetChildren().GetCount();
1350 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1352 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1355 node
->SetText( text
);
1358 ValueChanged( item
, 0 );
1361 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1363 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1364 if (!node
) return wxEmptyString
;
1366 return node
->GetText();
1369 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1371 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1374 node
->SetIcon( icon
);
1377 ValueChanged( item
, 0 );
1380 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1382 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1383 if (!node
) return wxNullIcon
;
1385 return node
->GetIcon();
1388 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1390 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1393 node
->SetExpandedIcon( icon
);
1396 ValueChanged( item
, 0 );
1399 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1401 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1402 if (!node
) return wxNullIcon
;
1404 return node
->GetExpandedIcon();
1407 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1409 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1412 node
->SetData( data
);
1414 // notify control? only sensible when sorting on client data
1415 // ValueChanged( item, 0 );
1418 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
1420 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1421 if (!node
) return NULL
;
1423 return node
->GetData();
1426 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
1428 if (!item
.IsOk()) return;
1430 wxDataViewItem parent_item
= GetParent( item
);
1432 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
1433 if (!parent_node
) return;
1435 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1438 parent_node
->GetChildren().DeleteObject( node
);
1441 ItemDeleted( parent_item
, item
);
1444 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
1446 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1449 wxDataViewItemArray array
;
1450 wxDataViewTreeStoreNodeList::iterator iter
;
1451 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1453 wxDataViewTreeStoreNode
* child
= *iter
;
1454 array
.Add( child
->GetItem() );
1457 node
->GetChildren().clear();
1460 ItemsDeleted( item
, array
);
1463 void wxDataViewTreeStore::DeleteAllItems()
1469 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
1470 const wxDataViewItem
&item
,
1471 unsigned int WXUNUSED(col
)) const
1473 // if (col != 0) return;
1475 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1478 wxIcon
icon( node
->GetIcon());
1479 if (node
->IsContainer())
1481 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
1482 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
1483 icon
= container
->GetExpandedIcon();
1486 wxDataViewIconText
data( node
->GetText(), icon
);
1492 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
1493 const wxDataViewItem
& item
,
1494 unsigned int WXUNUSED(col
))
1496 // if (col != 0) return false;
1498 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1499 if (!node
) return false;
1501 wxDataViewIconText data
;
1505 node
->SetText( data
.GetText() );
1506 node
->SetIcon( data
.GetIcon() );
1511 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
1513 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1514 if (!node
) return wxDataViewItem(0);
1516 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
1517 if (!parent
) return wxDataViewItem(0);
1519 if (parent
== m_root
)
1520 return wxDataViewItem(0);
1522 return parent
->GetItem();
1525 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
&item
) const
1527 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1528 if (!node
) return false;
1530 return node
->IsContainer();
1533 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
1535 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1536 if (!node
) return 0;
1538 wxDataViewTreeStoreNodeList::iterator iter
;
1539 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1541 wxDataViewTreeStoreNode
* child
= *iter
;
1542 children
.Add( child
->GetItem() );
1545 return node
->GetChildren().GetCount();
1548 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
1549 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) )
1551 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
1552 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
1554 if (!node1
|| !node2
)
1557 wxDataViewTreeStoreContainerNode
* parent1
=
1558 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
1559 wxDataViewTreeStoreContainerNode
* parent2
=
1560 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
1562 if (parent1
!= parent2
)
1564 wxLogError( wxT("Comparing items with different parent.") );
1568 if (node1
->IsContainer() && !!node2
->IsContainer())
1571 if (node2
->IsContainer() && !!node1
->IsContainer())
1574 return parent1
->GetChildren().IndexOf( node1
) - parent1
->GetChildren().IndexOf( node2
);
1577 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
1582 return (wxDataViewTreeStoreNode
*) item
.GetID();
1585 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
1588 return (wxDataViewTreeStoreContainerNode
*) m_root
;
1590 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
1592 if (!node
->IsContainer())
1595 return (wxDataViewTreeStoreContainerNode
*) node
;
1598 //-----------------------------------------------------------------------------
1599 // wxDataViewTreeCtrl
1600 //-----------------------------------------------------------------------------
1602 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1604 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1605 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
1606 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
1607 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
1610 wxDataViewTreeCtrl::wxDataViewTreeCtrl()
1615 wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow
*parent
, wxWindowID id
,
1616 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1619 Create( parent
, id
, pos
, size
, style
, validator
);
1621 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
1622 AssociateModel( store
);
1625 #if !defined(__WXGTK20__) || defined(wxUSE_GENERICDATAVIEWCTRL)
1626 wxDataViewColumn
*col
= AppendIconTextColumn( "", 0, wxDATAVIEW_CELL_INERT
, 40 );
1628 wxSize cient_size
= GetClientSize();
1629 col
->SetWidth( size
.x
);
1631 AppendIconTextColumn( "", 0, wxDATAVIEW_CELL_INERT
, 40 );
1635 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
1641 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1642 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1644 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
1647 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
1652 m_imageList
= imagelist
;
1655 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
1656 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1658 wxIcon icon
= wxNullIcon
;
1659 if (m_imageList
&& (iconIndex
!= -1))
1660 icon
= m_imageList
->GetIcon( iconIndex
);
1662 return GetStore()->AppendItem( parent
, text
, icon
, data
);
1665 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
1666 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1668 wxIcon icon
= wxNullIcon
;
1669 if (m_imageList
&& (iconIndex
!= -1))
1670 icon
= m_imageList
->GetIcon( iconIndex
);
1672 return GetStore()->PrependItem( parent
, text
, icon
, data
);
1675 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1676 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1678 wxIcon icon
= wxNullIcon
;
1679 if (m_imageList
&& (iconIndex
!= -1))
1680 icon
= m_imageList
->GetIcon( iconIndex
);
1682 return GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
1685 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
1686 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1688 wxIcon icon
= wxNullIcon
;
1689 if (m_imageList
&& (iconIndex
!= -1))
1690 icon
= m_imageList
->GetIcon( iconIndex
);
1692 wxIcon expanded
= wxNullIcon
;
1693 if (m_imageList
&& (expandedIndex
!= -1))
1694 expanded
= m_imageList
->GetIcon( expandedIndex
);
1696 return GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
1699 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
1700 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1702 wxIcon icon
= wxNullIcon
;
1703 if (m_imageList
&& (iconIndex
!= -1))
1704 icon
= m_imageList
->GetIcon( iconIndex
);
1706 wxIcon expanded
= wxNullIcon
;
1707 if (m_imageList
&& (expandedIndex
!= -1))
1708 expanded
= m_imageList
->GetIcon( expandedIndex
);
1710 return GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
1713 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1714 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1716 wxIcon icon
= wxNullIcon
;
1717 if (m_imageList
&& (iconIndex
!= -1))
1718 icon
= m_imageList
->GetIcon( iconIndex
);
1720 wxIcon expanded
= wxNullIcon
;
1721 if (m_imageList
&& (expandedIndex
!= -1))
1722 expanded
= m_imageList
->GetIcon( expandedIndex
);
1724 return GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
1727 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
1729 if (m_imageList
) return;
1731 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
1732 if (!container
) return;
1734 container
->SetExpanded( true );
1735 GetStore()->ItemChanged( event
.GetItem() );
1738 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
1740 if (m_imageList
) return;
1742 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
1743 if (!container
) return;
1745 container
->SetExpanded( false );
1746 GetStore()->ItemChanged( event
.GetItem() );
1749 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
1751 #if !defined(__WXGTK20__) || defined(wxUSE_GENERICDATAVIEWCTRL)
1752 wxSize size
= GetClientSize();
1753 wxDataViewColumn
*col
= GetColumn( 0 );
1754 if (col
) col
->SetWidth( size
.x
);
1759 #endif // wxUSE_DATAVIEWCTRL