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(wxT("item %s: %l\n"), text
.GetData(), (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::Reset( unsigned int new_size
)
335 // IDs are ordered until an item gets deleted or inserted
338 // build initial index
340 for (i
= 1; i
< new_size
+1; i
++)
341 m_hash
.Add( (void*) i
);
342 m_lastIndex
= new_size
+ 1;
346 m_lastIndex
= new_size
-1;
349 wxDataViewModel::Cleared();
352 void wxDataViewIndexListModel::RowPrepended()
358 unsigned int id
= m_lastIndex
++;
359 m_hash
.Insert( (void*) id
, 0 );
360 wxDataViewItem
item( (void*) id
);
361 ItemAdded( wxDataViewItem(0), item
);
366 wxDataViewItem
item( (void*) 0 );
367 ItemAdded( wxDataViewItem(0), item
);
371 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
377 unsigned int id
= m_lastIndex
++;
378 m_hash
.Insert( (void*) id
, before
);
379 wxDataViewItem
item( (void*) id
);
380 ItemAdded( wxDataViewItem(0), item
);
385 wxDataViewItem
item( (void*) before
);
386 ItemAdded( wxDataViewItem(0), item
);
390 void wxDataViewIndexListModel::RowAppended()
394 unsigned int id
= m_lastIndex
++;
395 m_hash
.Add( (void*) id
);
396 wxDataViewItem
item( (void*) id
);
397 ItemAdded( wxDataViewItem(0), item
);
402 wxDataViewItem
item( (void*) m_lastIndex
);
403 ItemAdded( wxDataViewItem(0), item
);
407 void wxDataViewIndexListModel::RowDeleted( unsigned int row
)
413 wxDataViewItem
item( m_hash
[row
] );
414 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
415 m_hash
.RemoveAt( row
);
419 wxDataViewItem
item( (void*) row
);
420 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
425 static int my_sort( int *v1
, int *v2
)
430 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt
&rows
)
432 wxArrayInt sorted
= rows
;
433 sorted
.Sort( my_sort
);
439 wxDataViewItemArray array
;
441 for (i
= 0; i
< rows
.GetCount(); i
++)
443 wxDataViewItem
item( m_hash
[rows
[i
]] );
446 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
448 for (i
= 0; i
< sorted
.GetCount(); i
++)
449 m_hash
.RemoveAt( sorted
[i
] );
453 wxDataViewItemArray array
;
455 for (i
= 0; i
< sorted
.GetCount(); i
++)
457 wxDataViewItem
item( (void*) sorted
[i
] );
460 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
462 m_lastIndex
-= rows
.GetCount();
466 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
468 wxDataViewModel::ItemChanged( GetItem(row
) );
471 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
473 wxDataViewModel::ValueChanged( GetItem(row
), col
);
476 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
482 unsigned int pos
= wxPtrToUInt( item
.GetID() );
486 // assert for not found
487 return (unsigned int) m_hash
.Index( item
.GetID() );
491 return wxPtrToUInt( item
.GetID() );
495 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
499 wxASSERT( row
< m_hash
.GetCount() );
500 return wxDataViewItem( m_hash
[row
] );
504 return wxDataViewItem( (void*) row
);
508 bool wxDataViewIndexListModel::HasDefaultCompare() const
513 int wxDataViewIndexListModel::Compare(const wxDataViewItem
& item1
,
514 const wxDataViewItem
& item2
,
515 unsigned int WXUNUSED(column
),
518 if (m_ordered
|| !m_useHash
)
520 unsigned int pos1
= wxPtrToUInt(item1
.GetID());
521 unsigned int pos2
= wxPtrToUInt(item2
.GetID());
530 return GetRow(item1
) - GetRow(item2
);
532 return GetRow(item2
) - GetRow(item1
);
535 void wxDataViewIndexListModel::GetValue( wxVariant
&variant
,
536 const wxDataViewItem
&item
, unsigned int col
) const
538 GetValue( variant
, GetRow(item
), col
);
541 bool wxDataViewIndexListModel::SetValue( const wxVariant
&variant
,
542 const wxDataViewItem
&item
, unsigned int col
)
544 return SetValue( variant
, GetRow(item
), col
);
547 bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
549 return GetAttr( GetRow(item
), col
, attr
);
552 wxDataViewItem
wxDataViewIndexListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
554 return wxDataViewItem(0);
557 bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem
&item
) const
559 // only the invisible root item has children
566 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
576 return m_hash
.GetCount();
579 //-----------------------------------------------------------------------------
580 // wxDataViewIconText
581 //-----------------------------------------------------------------------------
583 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
585 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
587 bool operator == (const wxDataViewIconText
&one
, const wxDataViewIconText
&two
)
589 if (one
.GetText() != two
.GetText()) return false;
590 if (one
.IsSameAs(two
)) return false;
594 // ---------------------------------------------------------
595 // wxDataViewRendererBase
596 // ---------------------------------------------------------
598 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
600 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
601 wxDataViewCellMode
WXUNUSED(mode
),
602 int WXUNUSED(align
) )
604 m_variantType
= varianttype
;
608 const wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
610 return wx_const_cast(wxDataViewRendererBase
*, this)->GetOwner()->GetOwner();
613 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
615 m_item
= item
; // remember for later
617 unsigned int col
= GetOwner()->GetModelColumn();
619 GetOwner()->GetOwner()->GetModel()->GetValue( value
, item
, col
);
621 m_editorCtrl
= CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect
, value
);
623 wxDataViewEditorCtrlEvtHandler
*handler
=
624 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
626 m_editorCtrl
->PushEventHandler( handler
);
628 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
629 handler
->SetFocusOnIdle();
631 m_editorCtrl
->SetFocus();
634 // Now we should send Editing Started event
635 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, GetOwner()->GetOwner()->GetId() );
636 event
.SetDataViewColumn( GetOwner() );
637 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
638 event
.SetItem( item
);
639 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
644 void wxDataViewRendererBase::CancelEditing()
646 wxPendingDelete
.Append( m_editorCtrl
);
648 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
650 // m_editorCtrl->PopEventHandler( true );
653 bool wxDataViewRendererBase::FinishEditing()
656 GetValueFromEditorCtrl( m_editorCtrl
, value
);
658 wxPendingDelete
.Append( m_editorCtrl
);
660 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
662 if (!Validate(value
))
665 unsigned int col
= GetOwner()->GetModelColumn();
666 GetOwner()->GetOwner()->GetModel()->SetValue( value
, m_item
, col
);
667 GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item
, col
);
669 // m_editorCtrl->PopEventHandler( true );
671 // Now we should send Editing Done event
672 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, GetOwner()->GetOwner()->GetId() );
673 event
.SetDataViewColumn( GetOwner() );
674 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
675 event
.SetItem( m_item
);
676 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
681 //-----------------------------------------------------------------------------
682 // wxDataViewEditorCtrlEvtHandler
683 //-----------------------------------------------------------------------------
685 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
686 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
687 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
688 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
691 wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
692 wxControl
*editorCtrl
,
693 wxDataViewRenderer
*owner
)
696 m_editorCtrl
= editorCtrl
;
701 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
705 m_focusOnIdle
= false;
706 if (wxWindow::FindFocus() != m_editorCtrl
)
707 m_editorCtrl
->SetFocus();
713 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
715 switch ( event
.m_keyCode
)
719 m_owner
->FinishEditing();
724 m_owner
->CancelEditing();
732 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
737 m_owner
->FinishEditing();
743 // ---------------------------------------------------------
744 // wxDataViewColumnBase
745 // ---------------------------------------------------------
747 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase
, wxObject
)
749 wxDataViewColumnBase::wxDataViewColumnBase(const wxString
& WXUNUSED(title
),
750 wxDataViewRenderer
*renderer
,
751 unsigned int model_column
,
753 wxAlignment
WXUNUSED(align
),
756 m_renderer
= renderer
;
757 m_model_column
= model_column
;
759 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
761 // NOTE: the wxDataViewColumn's ctor must store the width, align, flags
762 // parameters inside the native control!
765 wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap
& bitmap
,
766 wxDataViewRenderer
*renderer
,
767 unsigned int model_column
,
769 wxAlignment
WXUNUSED(align
),
770 int WXUNUSED(flags
) )
772 m_renderer
= renderer
;
773 m_model_column
= model_column
;
776 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
779 wxDataViewColumnBase::~wxDataViewColumnBase()
785 int wxDataViewColumnBase::GetFlags() const
790 ret
|= wxDATAVIEW_COL_SORTABLE
;
792 ret
|= wxDATAVIEW_COL_RESIZABLE
;
794 ret
|= wxDATAVIEW_COL_HIDDEN
;
799 void wxDataViewColumnBase::SetFlags(int flags
)
801 SetSortable((flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
802 SetResizeable((flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
803 SetHidden((flags
& wxDATAVIEW_COL_HIDDEN
) != 0);
804 SetReorderable((flags
& wxDATAVIEW_COL_REORDERABLE
) != 0);
807 // ---------------------------------------------------------
808 // wxDataViewCtrlBase
809 // ---------------------------------------------------------
811 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
813 wxDataViewCtrlBase::wxDataViewCtrlBase()
816 m_expander_column
= 0;
820 wxDataViewCtrlBase::~wxDataViewCtrlBase()
829 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
833 m_model
->DecRef(); // discard old model, if any
836 // add our own reference to the new model:
846 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
851 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
857 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
858 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
860 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
861 new wxDataViewTextRenderer( wxT("string"), mode
, (int)align
),
862 model_column
, width
, align
, flags
);
868 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
869 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
871 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
872 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
, (int)align
),
873 model_column
, width
, align
, flags
);
879 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
880 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
883 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
884 new wxDataViewToggleRenderer( wxT("bool"), mode
, (int)align
),
885 model_column
, width
, align
, flags
);
891 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
892 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
894 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
895 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
, (int)align
),
896 model_column
, width
, align
, flags
);
902 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
903 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
905 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
906 new wxDataViewDateRenderer( wxT("datetime"), mode
, (int)align
),
907 model_column
, width
, align
, flags
);
913 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
914 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
916 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
917 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
, (int)align
),
918 model_column
, width
, align
, flags
);
924 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
925 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
927 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
928 new wxDataViewTextRenderer( wxT("string"), mode
, (int)align
),
929 model_column
, width
, align
, flags
);
935 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
936 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
938 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
939 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
, (int)align
),
940 model_column
, width
, align
, flags
);
946 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
947 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
949 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
950 new wxDataViewToggleRenderer( wxT("bool"), mode
, (int)align
),
951 model_column
, width
, align
, flags
);
957 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
958 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
960 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
961 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
, (int)align
),
962 model_column
, width
, align
, flags
);
968 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
969 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
971 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
972 new wxDataViewDateRenderer( wxT("datetime"), mode
, (int)align
),
973 model_column
, width
, align
, flags
);
979 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
980 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
982 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
983 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
, (int)align
),
984 model_column
, width
, align
, flags
);
990 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
991 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
993 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
994 new wxDataViewTextRenderer( wxT("string"), mode
, (int)align
),
995 model_column
, width
, align
, flags
);
996 PrependColumn( ret
);
1001 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1002 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1004 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1005 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
, (int)align
),
1006 model_column
, width
, align
, flags
);
1007 PrependColumn( ret
);
1012 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1013 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1016 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1017 new wxDataViewToggleRenderer( wxT("bool"), mode
, (int)align
),
1018 model_column
, width
, align
, flags
);
1019 PrependColumn( ret
);
1024 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1025 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1027 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1028 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
, (int)align
),
1029 model_column
, width
, align
, flags
);
1030 PrependColumn( ret
);
1035 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1036 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1038 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1039 new wxDataViewDateRenderer( wxT("datetime"), mode
, (int)align
),
1040 model_column
, width
, align
, flags
);
1041 PrependColumn( ret
);
1046 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1047 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1049 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1050 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
, (int)align
),
1051 model_column
, width
, align
, flags
);
1052 PrependColumn( ret
);
1057 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1058 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1060 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1061 new wxDataViewTextRenderer( wxT("string"), mode
, (int)align
),
1062 model_column
, width
, align
, flags
);
1063 PrependColumn( ret
);
1068 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1069 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1071 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1072 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
, (int)align
),
1073 model_column
, width
, align
, flags
);
1074 PrependColumn( ret
);
1079 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1080 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1082 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1083 new wxDataViewToggleRenderer( wxT("bool"), mode
, (int)align
),
1084 model_column
, width
, align
, flags
);
1085 PrependColumn( ret
);
1090 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1091 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1093 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1094 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
, (int)align
),
1095 model_column
, width
, align
, flags
);
1096 PrependColumn( ret
);
1101 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1102 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1104 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1105 new wxDataViewDateRenderer( wxT("datetime"), mode
, (int)align
),
1106 model_column
, width
, align
, flags
);
1107 PrependColumn( ret
);
1112 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1113 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1115 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1116 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
, (int)align
),
1117 model_column
, width
, align
, flags
);
1118 PrependColumn( ret
);
1123 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1125 col
->SetOwner( (wxDataViewCtrl
*) this );
1130 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1132 col
->SetOwner( (wxDataViewCtrl
*) this );
1136 // ---------------------------------------------------------
1138 // ---------------------------------------------------------
1140 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1142 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
)
1144 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
)
1145 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
)
1146 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
)
1147 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
)
1148 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
)
1149 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
)
1150 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
)
1151 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
)
1153 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
)
1155 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
)
1156 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
)
1157 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
)
1158 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
)
1161 // -------------------------------------
1162 // wxDataViewSpinRenderer
1163 // -------------------------------------
1165 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1166 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1172 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1175 wxSize size
= labelRect
.GetSize();
1177 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1180 str
.Printf( wxT("%d\n"), (int) l
);
1181 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1182 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
, m_min
, m_max
, l
);
1184 size
= sc
->GetSize();
1185 wxPoint pt
= sc
->GetPosition();
1186 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1192 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1194 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1195 long l
= sc
->GetValue();
1200 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1203 str
.Printf(wxT("%d"), (int) m_data
);
1204 RenderText( str
, 0, rect
, dc
, state
);
1208 wxSize
wxDataViewSpinRenderer::GetSize() const
1210 return wxSize(80,16);
1213 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1215 m_data
= value
.GetLong();
1219 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1225 //-----------------------------------------------------------------------------
1226 // wxDataViewTreeStore
1227 //-----------------------------------------------------------------------------
1229 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1230 wxDataViewTreeStoreNode
*parent
,
1231 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1239 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1245 #include "wx/listimpl.cpp"
1246 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1248 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1249 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1250 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1251 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1253 m_iconExpanded
= expanded
;
1254 m_isExpanded
= false;
1255 m_children
.DeleteContents(true);
1258 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1262 //-----------------------------------------------------------------------------
1264 wxDataViewTreeStore::wxDataViewTreeStore()
1266 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1269 wxDataViewTreeStore::~wxDataViewTreeStore()
1274 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1275 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1277 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1278 if (!parent_node
) return wxDataViewItem(0);
1280 wxDataViewTreeStoreNode
*node
=
1281 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1282 parent_node
->GetChildren().Append( node
);
1285 ItemAdded( parent
, node
->GetItem() );
1287 return node
->GetItem();
1290 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1291 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1293 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1294 if (!parent_node
) return wxDataViewItem(0);
1296 wxDataViewTreeStoreNode
*node
=
1297 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1298 parent_node
->GetChildren().Insert( node
);
1301 ItemAdded( parent
, node
->GetItem() );
1303 return node
->GetItem();
1307 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& WXUNUSED(parent
),
1308 const wxDataViewItem
& WXUNUSED(previous
),
1309 const wxString
& WXUNUSED(text
),
1310 const wxIcon
& WXUNUSED(icon
),
1311 wxClientData
* WXUNUSED(data
))
1313 return wxDataViewItem(0);
1316 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1317 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1318 wxClientData
*data
)
1320 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1321 if (!parent_node
) return wxDataViewItem(0);
1323 wxDataViewTreeStoreContainerNode
*node
=
1324 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1325 parent_node
->GetChildren().Insert( node
);
1328 ItemAdded( parent
, node
->GetItem() );
1330 return node
->GetItem();
1334 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1335 const wxString
&text
,
1337 const wxIcon
& expanded
,
1338 wxClientData
* data
)
1340 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1341 if (!parent_node
) return wxDataViewItem(0);
1343 wxDataViewTreeStoreContainerNode
*node
=
1344 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1345 parent_node
->GetChildren().Append( node
);
1348 ItemAdded( parent
, node
->GetItem() );
1350 return node
->GetItem();
1354 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& WXUNUSED(parent
),
1355 const wxDataViewItem
& WXUNUSED(previous
),
1356 const wxString
& WXUNUSED(text
),
1357 const wxIcon
& WXUNUSED(icon
),
1358 const wxIcon
& WXUNUSED(expanded
),
1359 wxClientData
* WXUNUSED(data
))
1361 return wxDataViewItem(0);
1364 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1366 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1367 if (!parent_node
) return wxDataViewItem(0);
1369 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1371 return node
->GetData();
1373 return wxDataViewItem(0);
1376 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1378 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1379 if (!node
) return -1;
1381 if (!node
->IsContainer())
1384 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1385 return (int) container_node
->GetChildren().GetCount();
1388 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1390 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1393 node
->SetText( text
);
1396 ValueChanged( item
, 0 );
1399 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1401 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1402 if (!node
) return wxEmptyString
;
1404 return node
->GetText();
1407 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1409 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1412 node
->SetIcon( icon
);
1415 ValueChanged( item
, 0 );
1418 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1420 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1421 if (!node
) return wxNullIcon
;
1423 return node
->GetIcon();
1426 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1428 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1431 node
->SetExpandedIcon( icon
);
1434 ValueChanged( item
, 0 );
1437 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1439 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1440 if (!node
) return wxNullIcon
;
1442 return node
->GetExpandedIcon();
1445 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1447 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1450 node
->SetData( data
);
1452 // notify control? only sensible when sorting on client data
1453 // ValueChanged( item, 0 );
1456 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
1458 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1459 if (!node
) return NULL
;
1461 return node
->GetData();
1464 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
1466 if (!item
.IsOk()) return;
1468 wxDataViewItem parent_item
= GetParent( item
);
1470 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
1471 if (!parent_node
) return;
1473 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1476 parent_node
->GetChildren().DeleteObject( node
);
1479 ItemDeleted( parent_item
, item
);
1482 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
1484 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1487 wxDataViewItemArray array
;
1488 wxDataViewTreeStoreNodeList::iterator iter
;
1489 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1491 wxDataViewTreeStoreNode
* child
= *iter
;
1492 array
.Add( child
->GetItem() );
1495 node
->GetChildren().clear();
1498 ItemsDeleted( item
, array
);
1501 void wxDataViewTreeStore::DeleteAllItems()
1507 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
1508 const wxDataViewItem
&item
,
1509 unsigned int WXUNUSED(col
)) const
1511 // if (col != 0) return;
1513 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1516 wxIcon
icon( node
->GetIcon());
1517 if (node
->IsContainer())
1519 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
1520 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
1521 icon
= container
->GetExpandedIcon();
1524 wxDataViewIconText
data( node
->GetText(), icon
);
1530 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
1531 const wxDataViewItem
& item
,
1532 unsigned int WXUNUSED(col
))
1534 // if (col != 0) return false;
1536 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1537 if (!node
) return false;
1539 wxDataViewIconText data
;
1543 node
->SetText( data
.GetText() );
1544 node
->SetIcon( data
.GetIcon() );
1549 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
1551 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1552 if (!node
) return wxDataViewItem(0);
1554 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
1555 if (!parent
) return wxDataViewItem(0);
1557 if (parent
== m_root
)
1558 return wxDataViewItem(0);
1560 return parent
->GetItem();
1563 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
&item
) const
1565 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1566 if (!node
) return false;
1568 return node
->IsContainer();
1571 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
1573 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1574 if (!node
) return 0;
1576 wxDataViewTreeStoreNodeList::iterator iter
;
1577 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1579 wxDataViewTreeStoreNode
* child
= *iter
;
1580 children
.Add( child
->GetItem() );
1583 return node
->GetChildren().GetCount();
1586 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
1587 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) )
1589 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
1590 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
1592 if (!node1
|| !node2
)
1595 wxDataViewTreeStoreContainerNode
* parent1
=
1596 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
1597 wxDataViewTreeStoreContainerNode
* parent2
=
1598 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
1600 if (parent1
!= parent2
)
1602 wxLogError( wxT("Comparing items with different parent.") );
1606 if (node1
->IsContainer() && !!node2
->IsContainer())
1609 if (node2
->IsContainer() && !!node1
->IsContainer())
1612 return parent1
->GetChildren().IndexOf( node1
) - parent1
->GetChildren().IndexOf( node2
);
1615 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
1620 return (wxDataViewTreeStoreNode
*) item
.GetID();
1623 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
1626 return (wxDataViewTreeStoreContainerNode
*) m_root
;
1628 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
1630 if (!node
->IsContainer())
1633 return (wxDataViewTreeStoreContainerNode
*) node
;
1636 //-----------------------------------------------------------------------------
1637 // wxDataViewTreeCtrl
1638 //-----------------------------------------------------------------------------
1640 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1642 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1643 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
1644 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
1645 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
1648 wxDataViewTreeCtrl::wxDataViewTreeCtrl()
1653 wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow
*parent
, wxWindowID id
,
1654 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1657 Create( parent
, id
, pos
, size
, style
, validator
);
1659 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
1660 AssociateModel( store
);
1663 AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT
,-1);
1666 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
1672 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1673 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1675 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
1678 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
1683 m_imageList
= imagelist
;
1686 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
1687 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1689 wxIcon icon
= wxNullIcon
;
1690 if (m_imageList
&& (iconIndex
!= -1))
1691 icon
= m_imageList
->GetIcon( iconIndex
);
1693 return GetStore()->AppendItem( parent
, text
, icon
, data
);
1696 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
1697 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1699 wxIcon icon
= wxNullIcon
;
1700 if (m_imageList
&& (iconIndex
!= -1))
1701 icon
= m_imageList
->GetIcon( iconIndex
);
1703 return GetStore()->PrependItem( parent
, text
, icon
, data
);
1706 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1707 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1709 wxIcon icon
= wxNullIcon
;
1710 if (m_imageList
&& (iconIndex
!= -1))
1711 icon
= m_imageList
->GetIcon( iconIndex
);
1713 return GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
1716 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
1717 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1719 wxIcon icon
= wxNullIcon
;
1720 if (m_imageList
&& (iconIndex
!= -1))
1721 icon
= m_imageList
->GetIcon( iconIndex
);
1723 wxIcon expanded
= wxNullIcon
;
1724 if (m_imageList
&& (expandedIndex
!= -1))
1725 expanded
= m_imageList
->GetIcon( expandedIndex
);
1727 return GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
1730 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
1731 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1733 wxIcon icon
= wxNullIcon
;
1734 if (m_imageList
&& (iconIndex
!= -1))
1735 icon
= m_imageList
->GetIcon( iconIndex
);
1737 wxIcon expanded
= wxNullIcon
;
1738 if (m_imageList
&& (expandedIndex
!= -1))
1739 expanded
= m_imageList
->GetIcon( expandedIndex
);
1741 return GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
1744 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1745 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1747 wxIcon icon
= wxNullIcon
;
1748 if (m_imageList
&& (iconIndex
!= -1))
1749 icon
= m_imageList
->GetIcon( iconIndex
);
1751 wxIcon expanded
= wxNullIcon
;
1752 if (m_imageList
&& (expandedIndex
!= -1))
1753 expanded
= m_imageList
->GetIcon( expandedIndex
);
1755 return GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
1758 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
1760 if (m_imageList
) return;
1762 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
1763 if (!container
) return;
1765 container
->SetExpanded( true );
1766 GetStore()->ItemChanged( event
.GetItem() );
1769 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
1771 if (m_imageList
) return;
1773 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
1774 if (!container
) return;
1776 container
->SetExpanded( false );
1777 GetStore()->ItemChanged( event
.GetItem() );
1780 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
1782 #if defined(wxUSE_GENERICDATAVIEWCTRL)
1783 wxSize size
= GetClientSize();
1784 wxDataViewColumn
*col
= GetColumn( 0 );
1786 col
->SetWidth( size
.x
);
1791 #endif // wxUSE_DATAVIEWCTRL