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
)
388 wxDataViewItem
item( m_hash
[row
] );
389 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
390 m_hash
.RemoveAt( row
);
394 wxDataViewItem
item( (void*) row
);
395 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
400 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
402 wxDataViewModel::ItemChanged( GetItem(row
) );
405 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
407 wxDataViewModel::ValueChanged( GetItem(row
), col
);
410 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
416 unsigned int pos
= wxPtrToUInt( item
.GetID() );
420 // assert for not found
421 return (unsigned int) m_hash
.Index( item
.GetID() );
425 return wxPtrToUInt( item
.GetID() );
429 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
433 wxASSERT( row
< m_hash
.GetCount() );
434 return wxDataViewItem( m_hash
[row
] );
438 return wxDataViewItem( (void*) row
);
442 bool wxDataViewIndexListModel::HasDefaultCompare() const
447 int wxDataViewIndexListModel::Compare(const wxDataViewItem
& item1
,
448 const wxDataViewItem
& item2
,
449 unsigned int WXUNUSED(column
),
452 if (m_ordered
|| !m_useHash
)
454 unsigned int pos1
= wxPtrToUInt(item1
.GetID());
455 unsigned int pos2
= wxPtrToUInt(item2
.GetID());
464 return GetRow(item1
) - GetRow(item2
);
466 return GetRow(item2
) - GetRow(item1
);
469 void wxDataViewIndexListModel::GetValue( wxVariant
&variant
,
470 const wxDataViewItem
&item
, unsigned int col
) const
472 GetValue( variant
, GetRow(item
), col
);
475 bool wxDataViewIndexListModel::SetValue( const wxVariant
&variant
,
476 const wxDataViewItem
&item
, unsigned int col
)
478 return SetValue( variant
, GetRow(item
), col
);
481 bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
483 return GetAttr( GetRow(item
), col
, attr
);
486 wxDataViewItem
wxDataViewIndexListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
488 return wxDataViewItem(0);
491 bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem
&item
) const
493 // only the invisible root item has children
500 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
510 return m_hash
.GetCount();
513 //-----------------------------------------------------------------------------
514 // wxDataViewIconText
515 //-----------------------------------------------------------------------------
517 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
519 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
521 bool operator == (const wxDataViewIconText
&one
, const wxDataViewIconText
&two
)
523 if (one
.GetText() != two
.GetText()) return false;
524 if (one
.IsSameAs(two
)) return false;
528 // ---------------------------------------------------------
529 // wxDataViewRendererBase
530 // ---------------------------------------------------------
532 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
534 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
535 wxDataViewCellMode
WXUNUSED(mode
),
536 int WXUNUSED(align
) )
538 m_variantType
= varianttype
;
542 const wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
544 return wx_const_cast(wxDataViewRendererBase
*, this)->GetOwner()->GetOwner();
547 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
549 m_item
= item
; // remember for later
551 unsigned int col
= GetOwner()->GetModelColumn();
553 GetOwner()->GetOwner()->GetModel()->GetValue( value
, item
, col
);
555 m_editorCtrl
= CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect
, value
);
557 wxDataViewEditorCtrlEvtHandler
*handler
=
558 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
560 m_editorCtrl
->PushEventHandler( handler
);
562 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
563 handler
->SetFocusOnIdle();
565 m_editorCtrl
->SetFocus();
568 // Now we should send Editing Started event
569 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, GetOwner()->GetOwner()->GetId() );
570 event
.SetDataViewColumn( GetOwner() );
571 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
572 event
.SetItem( item
);
573 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
578 void wxDataViewRendererBase::CancelEditing()
580 wxPendingDelete
.Append( m_editorCtrl
);
582 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
584 // m_editorCtrl->PopEventHandler( true );
587 bool wxDataViewRendererBase::FinishEditing()
590 GetValueFromEditorCtrl( m_editorCtrl
, value
);
592 wxPendingDelete
.Append( m_editorCtrl
);
594 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
596 if (!Validate(value
))
599 unsigned int col
= GetOwner()->GetModelColumn();
600 GetOwner()->GetOwner()->GetModel()->SetValue( value
, m_item
, col
);
601 GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item
, col
);
603 // m_editorCtrl->PopEventHandler( true );
605 // Now we should send Editing Done event
606 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, GetOwner()->GetOwner()->GetId() );
607 event
.SetDataViewColumn( GetOwner() );
608 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
609 event
.SetItem( m_item
);
610 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
615 //-----------------------------------------------------------------------------
616 // wxDataViewEditorCtrlEvtHandler
617 //-----------------------------------------------------------------------------
619 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
620 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
621 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
622 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
625 wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
626 wxControl
*editorCtrl
,
627 wxDataViewRenderer
*owner
)
630 m_editorCtrl
= editorCtrl
;
635 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
639 m_focusOnIdle
= false;
640 if (wxWindow::FindFocus() != m_editorCtrl
)
641 m_editorCtrl
->SetFocus();
647 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
649 switch ( event
.m_keyCode
)
653 m_owner
->FinishEditing();
658 m_owner
->CancelEditing();
666 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
671 m_owner
->FinishEditing();
677 // ---------------------------------------------------------
678 // wxDataViewColumnBase
679 // ---------------------------------------------------------
681 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase
, wxObject
)
683 wxDataViewColumnBase::wxDataViewColumnBase(const wxString
& WXUNUSED(title
),
684 wxDataViewRenderer
*renderer
,
685 unsigned int model_column
,
687 wxAlignment
WXUNUSED(align
),
690 m_renderer
= renderer
;
691 m_model_column
= model_column
;
693 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
695 // NOTE: the wxDataViewColumn's ctor must store the width, align, flags
696 // parameters inside the native control!
699 wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap
& bitmap
,
700 wxDataViewRenderer
*renderer
,
701 unsigned int model_column
,
703 wxAlignment
WXUNUSED(align
),
704 int WXUNUSED(flags
) )
706 m_renderer
= renderer
;
707 m_model_column
= model_column
;
710 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
713 wxDataViewColumnBase::~wxDataViewColumnBase()
719 int wxDataViewColumnBase::GetFlags() const
724 ret
|= wxDATAVIEW_COL_SORTABLE
;
726 ret
|= wxDATAVIEW_COL_RESIZABLE
;
728 ret
|= wxDATAVIEW_COL_HIDDEN
;
733 void wxDataViewColumnBase::SetFlags(int flags
)
735 SetSortable((flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
736 SetResizeable((flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
737 SetHidden((flags
& wxDATAVIEW_COL_HIDDEN
) != 0);
740 // ---------------------------------------------------------
741 // wxDataViewCtrlBase
742 // ---------------------------------------------------------
744 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
746 wxDataViewCtrlBase::wxDataViewCtrlBase()
749 m_expander_column
= 0;
753 wxDataViewCtrlBase::~wxDataViewCtrlBase()
762 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
766 m_model
->DecRef(); // discard old model, if any
769 // add our own reference to the new model:
779 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
784 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
790 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
791 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
793 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
794 new wxDataViewTextRenderer( wxT("string"), mode
, (int)align
),
795 model_column
, width
, align
, flags
);
801 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
802 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
804 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
805 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
, (int)align
),
806 model_column
, width
, align
, flags
);
812 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
813 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
816 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
817 new wxDataViewToggleRenderer( wxT("bool"), mode
, (int)align
),
818 model_column
, width
, align
, flags
);
824 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
825 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
827 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
828 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
, (int)align
),
829 model_column
, width
, align
, flags
);
835 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
836 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
838 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
839 new wxDataViewDateRenderer( wxT("datetime"), mode
, (int)align
),
840 model_column
, width
, align
, flags
);
846 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
847 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
849 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
850 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
, (int)align
),
851 model_column
, width
, align
, flags
);
857 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&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 wxBitmap
&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 wxBitmap
&label
, unsigned int model_column
,
880 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
882 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
883 new wxDataViewToggleRenderer( wxT("bool"), mode
, (int)align
),
884 model_column
, width
, align
, flags
);
890 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
891 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
893 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
894 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
, (int)align
),
895 model_column
, width
, align
, flags
);
901 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
902 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
904 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
905 new wxDataViewDateRenderer( wxT("datetime"), mode
, (int)align
),
906 model_column
, width
, align
, flags
);
912 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
913 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
915 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
916 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
, (int)align
),
917 model_column
, width
, align
, flags
);
923 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
924 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
926 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
927 new wxDataViewTextRenderer( wxT("string"), mode
, (int)align
),
928 model_column
, width
, align
, flags
);
929 PrependColumn( ret
);
934 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
935 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
937 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
938 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
, (int)align
),
939 model_column
, width
, align
, flags
);
940 PrependColumn( ret
);
945 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
946 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
);
952 PrependColumn( ret
);
957 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&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
);
963 PrependColumn( ret
);
968 wxDataViewCtrlBase::PrependDateColumn( const wxString
&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
);
974 PrependColumn( ret
);
979 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&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
);
985 PrependColumn( ret
);
990 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&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 wxBitmap
&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 wxBitmap
&label
, unsigned int model_column
,
1013 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1015 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1016 new wxDataViewToggleRenderer( wxT("bool"), mode
, (int)align
),
1017 model_column
, width
, align
, flags
);
1018 PrependColumn( ret
);
1023 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1024 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1026 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1027 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
, (int)align
),
1028 model_column
, width
, align
, flags
);
1029 PrependColumn( ret
);
1034 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1035 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1037 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1038 new wxDataViewDateRenderer( wxT("datetime"), mode
, (int)align
),
1039 model_column
, width
, align
, flags
);
1040 PrependColumn( ret
);
1045 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1046 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1048 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1049 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
, (int)align
),
1050 model_column
, width
, align
, flags
);
1051 PrependColumn( ret
);
1056 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1058 col
->SetOwner( (wxDataViewCtrl
*) this );
1063 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1065 col
->SetOwner( (wxDataViewCtrl
*) this );
1069 // ---------------------------------------------------------
1071 // ---------------------------------------------------------
1073 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1075 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
)
1077 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
)
1078 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
)
1079 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
)
1080 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
)
1081 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
)
1082 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
)
1083 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
)
1084 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
)
1086 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
)
1087 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
)
1088 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
)
1091 // -------------------------------------
1092 // wxDataViewSpinRenderer
1093 // -------------------------------------
1095 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1096 wxDataViewCustomRenderer( "long", mode
, alignment
)
1102 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1105 return new wxSpinCtrl( parent
, wxID_ANY
, wxEmptyString
,
1106 labelRect
.GetTopLeft(), labelRect
.GetSize(), wxSP_ARROW_KEYS
, m_min
, m_max
, l
);
1109 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1111 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1112 long l
= sc
->GetValue();
1117 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1120 str
.Printf( "%d", (int) m_data
);
1121 RenderText( str
, 0, rect
, dc
, state
);
1125 wxSize
wxDataViewSpinRenderer::GetSize() const
1127 return wxSize(80,16);
1130 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1132 m_data
= value
.GetLong();
1136 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1142 //-----------------------------------------------------------------------------
1143 // wxDataViewTreeStore
1144 //-----------------------------------------------------------------------------
1146 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1147 wxDataViewTreeStoreNode
*parent
,
1148 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1156 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1162 #include "wx/listimpl.cpp"
1163 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1165 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1166 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1167 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1168 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1170 m_iconExpanded
= expanded
;
1171 m_isExpanded
= false;
1172 m_children
.DeleteContents(true);
1175 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1179 //-----------------------------------------------------------------------------
1181 wxDataViewTreeStore::wxDataViewTreeStore()
1183 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1186 wxDataViewTreeStore::~wxDataViewTreeStore()
1191 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1192 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1194 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1195 if (!parent_node
) return wxDataViewItem(0);
1197 wxDataViewTreeStoreNode
*node
=
1198 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1199 parent_node
->GetChildren().Append( node
);
1202 ItemAdded( parent
, node
->GetItem() );
1204 return node
->GetItem();
1207 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1208 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1210 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1211 if (!parent_node
) return wxDataViewItem(0);
1213 wxDataViewTreeStoreNode
*node
=
1214 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1215 parent_node
->GetChildren().Insert( node
);
1218 ItemAdded( parent
, node
->GetItem() );
1220 return node
->GetItem();
1224 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& WXUNUSED(parent
),
1225 const wxDataViewItem
& WXUNUSED(previous
),
1226 const wxString
& WXUNUSED(text
),
1227 const wxIcon
& WXUNUSED(icon
),
1228 wxClientData
* WXUNUSED(data
))
1230 return wxDataViewItem(0);
1233 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1234 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1235 wxClientData
*data
)
1237 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1238 if (!parent_node
) return wxDataViewItem(0);
1240 wxDataViewTreeStoreContainerNode
*node
=
1241 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1242 parent_node
->GetChildren().Insert( node
);
1245 ItemAdded( parent
, node
->GetItem() );
1247 return node
->GetItem();
1251 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1252 const wxString
&text
,
1254 const wxIcon
& expanded
,
1255 wxClientData
* data
)
1257 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1258 if (!parent_node
) return wxDataViewItem(0);
1260 wxDataViewTreeStoreContainerNode
*node
=
1261 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1262 parent_node
->GetChildren().Append( node
);
1265 ItemAdded( parent
, node
->GetItem() );
1267 return node
->GetItem();
1271 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& WXUNUSED(parent
),
1272 const wxDataViewItem
& WXUNUSED(previous
),
1273 const wxString
& WXUNUSED(text
),
1274 const wxIcon
& WXUNUSED(icon
),
1275 const wxIcon
& WXUNUSED(expanded
),
1276 wxClientData
* WXUNUSED(data
))
1278 return wxDataViewItem(0);
1281 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1283 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1284 if (!parent_node
) return wxDataViewItem(0);
1286 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1288 return node
->GetData();
1290 return wxDataViewItem(0);
1293 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1295 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1296 if (!node
) return -1;
1298 if (!node
->IsContainer())
1301 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1302 return (int) container_node
->GetChildren().GetCount();
1305 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1307 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1310 node
->SetText( text
);
1313 ValueChanged( item
, 0 );
1316 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1318 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1319 if (!node
) return wxEmptyString
;
1321 return node
->GetText();
1324 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1326 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1329 node
->SetIcon( icon
);
1332 ValueChanged( item
, 0 );
1335 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1337 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1338 if (!node
) return wxNullIcon
;
1340 return node
->GetIcon();
1343 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1345 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1348 node
->SetExpandedIcon( icon
);
1351 ValueChanged( item
, 0 );
1354 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1356 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1357 if (!node
) return wxNullIcon
;
1359 return node
->GetExpandedIcon();
1362 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1364 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1367 node
->SetData( data
);
1369 // notify control? only sensible when sorting on client data
1370 // ValueChanged( item, 0 );
1373 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
1375 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1376 if (!node
) return NULL
;
1378 return node
->GetData();
1381 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
1383 if (!item
.IsOk()) return;
1385 wxDataViewItem parent_item
= GetParent( item
);
1387 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
1388 if (!parent_node
) return;
1390 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1393 parent_node
->GetChildren().DeleteObject( node
);
1396 ItemDeleted( parent_item
, item
);
1399 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
1401 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1404 wxDataViewItemArray array
;
1405 wxDataViewTreeStoreNodeList::iterator iter
;
1406 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1408 wxDataViewTreeStoreNode
* child
= *iter
;
1409 array
.Add( child
->GetItem() );
1412 node
->GetChildren().clear();
1415 ItemsDeleted( item
, array
);
1418 void wxDataViewTreeStore::DeleteAllItems()
1424 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
1425 const wxDataViewItem
&item
,
1426 unsigned int WXUNUSED(col
)) const
1428 // if (col != 0) return;
1430 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1433 wxIcon
icon( node
->GetIcon());
1434 if (node
->IsContainer())
1436 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
1437 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
1438 icon
= container
->GetExpandedIcon();
1441 wxDataViewIconText
data( node
->GetText(), icon
);
1447 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
1448 const wxDataViewItem
& item
,
1449 unsigned int WXUNUSED(col
))
1451 // if (col != 0) return false;
1453 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1454 if (!node
) return false;
1456 wxDataViewIconText data
;
1460 node
->SetText( data
.GetText() );
1461 node
->SetIcon( data
.GetIcon() );
1466 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
1468 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1469 if (!node
) return wxDataViewItem(0);
1471 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
1472 if (!parent
) return wxDataViewItem(0);
1474 if (parent
== m_root
)
1475 return wxDataViewItem(0);
1477 return parent
->GetItem();
1480 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
&item
) const
1482 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1483 if (!node
) return false;
1485 return node
->IsContainer();
1488 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
1490 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1491 if (!node
) return 0;
1493 wxDataViewTreeStoreNodeList::iterator iter
;
1494 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1496 wxDataViewTreeStoreNode
* child
= *iter
;
1497 children
.Add( child
->GetItem() );
1500 return node
->GetChildren().GetCount();
1503 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
1504 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) )
1506 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
1507 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
1509 if (!node1
|| !node2
)
1512 wxDataViewTreeStoreContainerNode
* parent1
=
1513 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
1514 wxDataViewTreeStoreContainerNode
* parent2
=
1515 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
1517 if (parent1
!= parent2
)
1519 wxLogError( wxT("Comparing items with different parent.") );
1523 if (node1
->IsContainer() && !!node2
->IsContainer())
1526 if (node2
->IsContainer() && !!node1
->IsContainer())
1529 return parent1
->GetChildren().IndexOf( node1
) - parent1
->GetChildren().IndexOf( node2
);
1532 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
1537 return (wxDataViewTreeStoreNode
*) item
.GetID();
1540 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
1543 return (wxDataViewTreeStoreContainerNode
*) m_root
;
1545 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
1547 if (!node
->IsContainer())
1550 return (wxDataViewTreeStoreContainerNode
*) node
;
1553 //-----------------------------------------------------------------------------
1554 // wxDataViewTreeCtrl
1555 //-----------------------------------------------------------------------------
1557 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1559 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1560 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
1561 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
1562 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
1565 wxDataViewTreeCtrl::wxDataViewTreeCtrl()
1570 wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow
*parent
, wxWindowID id
,
1571 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1574 Create( parent
, id
, pos
, size
, style
, validator
);
1576 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
1577 AssociateModel( store
);
1580 wxDataViewColumn
*col
= AppendIconTextColumn( "", 0, wxDATAVIEW_CELL_INERT
, 40 );
1582 #if !defined(__WXGTK20__)
1583 wxSize cient_size
= GetClientSize();
1584 col
->SetWidth( size
.x
);
1588 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
1594 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1595 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1597 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
1600 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
1605 m_imageList
= imagelist
;
1608 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
1609 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1611 wxIcon icon
= wxNullIcon
;
1612 if (m_imageList
&& (iconIndex
!= -1))
1613 icon
= m_imageList
->GetIcon( iconIndex
);
1615 return GetStore()->AppendItem( parent
, text
, icon
, data
);
1618 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
1619 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1621 wxIcon icon
= wxNullIcon
;
1622 if (m_imageList
&& (iconIndex
!= -1))
1623 icon
= m_imageList
->GetIcon( iconIndex
);
1625 return GetStore()->PrependItem( parent
, text
, icon
, data
);
1628 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1629 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1631 wxIcon icon
= wxNullIcon
;
1632 if (m_imageList
&& (iconIndex
!= -1))
1633 icon
= m_imageList
->GetIcon( iconIndex
);
1635 return GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
1638 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
1639 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1641 wxIcon icon
= wxNullIcon
;
1642 if (m_imageList
&& (iconIndex
!= -1))
1643 icon
= m_imageList
->GetIcon( iconIndex
);
1645 wxIcon expanded
= wxNullIcon
;
1646 if (m_imageList
&& (expandedIndex
!= -1))
1647 expanded
= m_imageList
->GetIcon( expandedIndex
);
1649 return GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
1652 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
1653 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1655 wxIcon icon
= wxNullIcon
;
1656 if (m_imageList
&& (iconIndex
!= -1))
1657 icon
= m_imageList
->GetIcon( iconIndex
);
1659 wxIcon expanded
= wxNullIcon
;
1660 if (m_imageList
&& (expandedIndex
!= -1))
1661 expanded
= m_imageList
->GetIcon( expandedIndex
);
1663 return GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
1666 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1667 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1669 wxIcon icon
= wxNullIcon
;
1670 if (m_imageList
&& (iconIndex
!= -1))
1671 icon
= m_imageList
->GetIcon( iconIndex
);
1673 wxIcon expanded
= wxNullIcon
;
1674 if (m_imageList
&& (expandedIndex
!= -1))
1675 expanded
= m_imageList
->GetIcon( expandedIndex
);
1677 return GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
1680 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
1682 if (m_imageList
) return;
1684 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
1685 if (!container
) return;
1687 container
->SetExpanded( true );
1688 GetStore()->ItemChanged( event
.GetItem() );
1691 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
1693 if (m_imageList
) return;
1695 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
1696 if (!container
) return;
1698 container
->SetExpanded( false );
1699 GetStore()->ItemChanged( event
.GetItem() );
1702 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&WXUNUSED(event
) )
1704 #if !defined(__WXGTK20__)
1705 wxSize size
= GetClientSize();
1706 wxDataViewColumn
*col
= GetColumn( 0 );
1707 col
->SetWidth( size
.x
);
1711 #endif // wxUSE_DATAVIEWCTRL