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 static int my_sort( int *v1
, int *v2
)
306 wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size
)
308 // IDs are ordered until an item gets deleted or inserted
311 // build initial index
313 for (i
= 1; i
< initial_size
+1; i
++)
314 m_hash
.Add( (void*) i
);
315 m_lastIndex
= initial_size
+ 1;
318 wxDataViewIndexListModel::~wxDataViewIndexListModel()
322 void wxDataViewIndexListModel::Reset( unsigned int new_size
)
326 // IDs are ordered until an item gets deleted or inserted
329 // build initial index
331 for (i
= 1; i
< new_size
+1; i
++)
332 m_hash
.Add( (void*) i
);
333 m_lastIndex
= new_size
+ 1;
335 wxDataViewModel::Cleared();
338 void wxDataViewIndexListModel::RowPrepended()
342 unsigned int id
= m_lastIndex
++;
343 m_hash
.Insert( (void*) id
, 0 );
344 wxDataViewItem
item( (void*) id
);
345 ItemAdded( wxDataViewItem(0), item
);
348 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
352 unsigned int id
= m_lastIndex
++;
353 m_hash
.Insert( (void*) id
, before
);
354 wxDataViewItem
item( (void*) id
);
355 ItemAdded( wxDataViewItem(0), item
);
358 void wxDataViewIndexListModel::RowAppended()
360 unsigned int id
= m_lastIndex
++;
361 m_hash
.Add( (void*) id
);
362 wxDataViewItem
item( (void*) id
);
363 ItemAdded( wxDataViewItem(0), item
);
366 void wxDataViewIndexListModel::RowDeleted( unsigned int row
)
370 wxDataViewItem
item( m_hash
[row
] );
371 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
372 m_hash
.RemoveAt( row
);
375 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt
&rows
)
377 wxArrayInt sorted
= rows
;
378 sorted
.Sort( my_sort
);
382 wxDataViewItemArray array
;
384 for (i
= 0; i
< rows
.GetCount(); i
++)
386 wxDataViewItem
item( m_hash
[rows
[i
]] );
389 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
391 for (i
= 0; i
< sorted
.GetCount(); i
++)
392 m_hash
.RemoveAt( sorted
[i
] );
395 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
397 wxDataViewModel::ItemChanged( GetItem(row
) );
400 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
402 wxDataViewModel::ValueChanged( GetItem(row
), col
);
405 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
409 unsigned int pos
= wxPtrToUInt( item
.GetID() );
413 // assert for not found
414 return (unsigned int) m_hash
.Index( item
.GetID() );
417 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
419 wxASSERT( row
< m_hash
.GetCount() );
420 return wxDataViewItem( m_hash
[row
] );
423 bool wxDataViewIndexListModel::HasDefaultCompare() const
428 int wxDataViewIndexListModel::Compare(const wxDataViewItem
& item1
,
429 const wxDataViewItem
& item2
,
430 unsigned int WXUNUSED(column
),
435 unsigned int pos1
= wxPtrToUInt(item1
.GetID());
436 unsigned int pos2
= wxPtrToUInt(item2
.GetID());
445 return GetRow(item1
) - GetRow(item2
);
447 return GetRow(item2
) - GetRow(item1
);
450 void wxDataViewIndexListModel::GetValue( wxVariant
&variant
,
451 const wxDataViewItem
&item
, unsigned int col
) const
453 GetValue( variant
, GetRow(item
), col
);
456 bool wxDataViewIndexListModel::SetValue( const wxVariant
&variant
,
457 const wxDataViewItem
&item
, unsigned int col
)
459 return SetValue( variant
, GetRow(item
), col
);
462 bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
464 return GetAttr( GetRow(item
), col
, attr
);
467 wxDataViewItem
wxDataViewIndexListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
469 return wxDataViewItem(0);
472 bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem
&item
) const
474 // only the invisible root item has children
481 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
488 return m_hash
.GetCount();
491 // ---------------------------------------------------------
492 // wxDataViewVirtualListModel
493 // ---------------------------------------------------------
497 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size
)
499 m_lastIndex
= initial_size
-1;
502 wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
506 void wxDataViewVirtualListModel::Reset( unsigned int new_size
)
508 m_lastIndex
= new_size
-1;
510 wxDataViewModel::Cleared();
513 void wxDataViewVirtualListModel::RowPrepended()
516 wxDataViewItem
item( (void*) 0 );
517 ItemAdded( wxDataViewItem(0), item
);
520 void wxDataViewVirtualListModel::RowInserted( unsigned int before
)
523 wxDataViewItem
item( (void*) before
);
524 ItemAdded( wxDataViewItem(0), item
);
527 void wxDataViewVirtualListModel::RowAppended()
530 wxDataViewItem
item( (void*) m_lastIndex
);
531 ItemAdded( wxDataViewItem(0), item
);
534 void wxDataViewVirtualListModel::RowDeleted( unsigned int row
)
536 wxDataViewItem
item( (void*) row
);
537 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
541 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt
&rows
)
543 wxArrayInt sorted
= rows
;
544 sorted
.Sort( my_sort
);
546 wxDataViewItemArray array
;
548 for (i
= 0; i
< sorted
.GetCount(); i
++)
550 wxDataViewItem
item( (void*) sorted
[i
] );
553 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
555 m_lastIndex
-= rows
.GetCount();
558 void wxDataViewVirtualListModel::RowChanged( unsigned int row
)
560 wxDataViewModel::ItemChanged( GetItem(row
) );
563 void wxDataViewVirtualListModel::RowValueChanged( unsigned int row
, unsigned int col
)
565 wxDataViewModel::ValueChanged( GetItem(row
), col
);
568 unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem
&item
) const
570 return wxPtrToUInt( item
.GetID() );
573 wxDataViewItem
wxDataViewVirtualListModel::GetItem( unsigned int row
) const
575 return wxDataViewItem( (void*) row
);
578 bool wxDataViewVirtualListModel::HasDefaultCompare() const
583 int wxDataViewVirtualListModel::Compare(const wxDataViewItem
& item1
,
584 const wxDataViewItem
& item2
,
585 unsigned int WXUNUSED(column
),
588 unsigned int pos1
= wxPtrToUInt(item1
.GetID());
589 unsigned int pos2
= wxPtrToUInt(item2
.GetID());
597 void wxDataViewVirtualListModel::GetValue( wxVariant
&variant
,
598 const wxDataViewItem
&item
, unsigned int col
) const
600 GetValue( variant
, GetRow(item
), col
);
603 bool wxDataViewVirtualListModel::SetValue( const wxVariant
&variant
,
604 const wxDataViewItem
&item
, unsigned int col
)
606 return SetValue( variant
, GetRow(item
), col
);
609 bool wxDataViewVirtualListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
611 return GetAttr( GetRow(item
), col
, attr
);
614 wxDataViewItem
wxDataViewVirtualListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
616 return wxDataViewItem(0);
619 bool wxDataViewVirtualListModel::IsContainer( const wxDataViewItem
&item
) const
621 // only the invisible root item has children
628 unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem
&WXUNUSED(item
), wxDataViewItemArray
&WXUNUSED(children
) ) const
630 return 0; // should we report an error ?
635 //-----------------------------------------------------------------------------
636 // wxDataViewIconText
637 //-----------------------------------------------------------------------------
639 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
641 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
643 bool operator == (const wxDataViewIconText
&one
, const wxDataViewIconText
&two
)
645 if (one
.GetText() != two
.GetText()) return false;
646 if (one
.IsSameAs(two
)) return false;
650 // ---------------------------------------------------------
651 // wxDataViewRendererBase
652 // ---------------------------------------------------------
654 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
656 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
657 wxDataViewCellMode
WXUNUSED(mode
),
658 int WXUNUSED(align
) )
660 m_variantType
= varianttype
;
664 const wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
666 return wx_const_cast(wxDataViewRendererBase
*, this)->GetOwner()->GetOwner();
669 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
671 m_item
= item
; // remember for later
673 unsigned int col
= GetOwner()->GetModelColumn();
675 GetOwner()->GetOwner()->GetModel()->GetValue( value
, item
, col
);
677 m_editorCtrl
= CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect
, value
);
679 wxDataViewEditorCtrlEvtHandler
*handler
=
680 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
682 m_editorCtrl
->PushEventHandler( handler
);
684 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
685 handler
->SetFocusOnIdle();
687 m_editorCtrl
->SetFocus();
690 // Now we should send Editing Started event
691 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, GetOwner()->GetOwner()->GetId() );
692 event
.SetDataViewColumn( GetOwner() );
693 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
694 event
.SetItem( item
);
695 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
700 void wxDataViewRendererBase::CancelEditing()
702 wxPendingDelete
.Append( m_editorCtrl
);
704 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
706 // m_editorCtrl->PopEventHandler( true );
709 bool wxDataViewRendererBase::FinishEditing()
712 GetValueFromEditorCtrl( m_editorCtrl
, value
);
714 wxPendingDelete
.Append( m_editorCtrl
);
716 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
718 if (!Validate(value
))
721 unsigned int col
= GetOwner()->GetModelColumn();
722 GetOwner()->GetOwner()->GetModel()->SetValue( value
, m_item
, col
);
723 GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item
, col
);
725 // m_editorCtrl->PopEventHandler( true );
727 // Now we should send Editing Done event
728 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, GetOwner()->GetOwner()->GetId() );
729 event
.SetDataViewColumn( GetOwner() );
730 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
731 event
.SetItem( m_item
);
732 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
737 //-----------------------------------------------------------------------------
738 // wxDataViewEditorCtrlEvtHandler
739 //-----------------------------------------------------------------------------
741 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
742 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
743 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
744 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
747 wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
748 wxControl
*editorCtrl
,
749 wxDataViewRenderer
*owner
)
752 m_editorCtrl
= editorCtrl
;
757 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
761 m_focusOnIdle
= false;
762 if (wxWindow::FindFocus() != m_editorCtrl
)
763 m_editorCtrl
->SetFocus();
769 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
771 switch ( event
.m_keyCode
)
775 m_owner
->FinishEditing();
780 m_owner
->CancelEditing();
788 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
793 m_owner
->FinishEditing();
799 // ---------------------------------------------------------
800 // wxDataViewColumnBase
801 // ---------------------------------------------------------
803 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase
, wxObject
)
805 wxDataViewColumnBase::wxDataViewColumnBase(const wxString
& WXUNUSED(title
),
806 wxDataViewRenderer
*renderer
,
807 unsigned int model_column
,
809 wxAlignment
WXUNUSED(align
),
812 m_renderer
= renderer
;
813 m_model_column
= model_column
;
815 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
817 // NOTE: the wxDataViewColumn's ctor must store the width, align, flags
818 // parameters inside the native control!
821 wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap
& bitmap
,
822 wxDataViewRenderer
*renderer
,
823 unsigned int model_column
,
825 wxAlignment
WXUNUSED(align
),
826 int WXUNUSED(flags
) )
828 m_renderer
= renderer
;
829 m_model_column
= model_column
;
832 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
835 wxDataViewColumnBase::~wxDataViewColumnBase()
841 int wxDataViewColumnBase::GetFlags() const
846 ret
|= wxDATAVIEW_COL_SORTABLE
;
848 ret
|= wxDATAVIEW_COL_RESIZABLE
;
850 ret
|= wxDATAVIEW_COL_HIDDEN
;
855 void wxDataViewColumnBase::SetFlags(int flags
)
857 SetSortable((flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
858 SetResizeable((flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
859 SetHidden((flags
& wxDATAVIEW_COL_HIDDEN
) != 0);
860 SetReorderable((flags
& wxDATAVIEW_COL_REORDERABLE
) != 0);
863 // ---------------------------------------------------------
864 // wxDataViewCtrlBase
865 // ---------------------------------------------------------
867 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
869 wxDataViewCtrlBase::wxDataViewCtrlBase()
872 m_expander_column
= 0;
876 wxDataViewCtrlBase::~wxDataViewCtrlBase()
885 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
889 m_model
->DecRef(); // discard old model, if any
892 // add our own reference to the new model:
902 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
907 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
913 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
914 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
916 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
917 new wxDataViewTextRenderer( wxT("string"), mode
, (int)align
),
918 model_column
, width
, align
, flags
);
924 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
925 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
927 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
928 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
, (int)align
),
929 model_column
, width
, align
, flags
);
935 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
936 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
939 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
940 new wxDataViewToggleRenderer( wxT("bool"), mode
, (int)align
),
941 model_column
, width
, align
, flags
);
947 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
948 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
950 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
951 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
, (int)align
),
952 model_column
, width
, align
, flags
);
958 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
959 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
961 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
962 new wxDataViewDateRenderer( wxT("datetime"), mode
, (int)align
),
963 model_column
, width
, align
, flags
);
969 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
970 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
972 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
973 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
, (int)align
),
974 model_column
, width
, align
, flags
);
980 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
981 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
983 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
984 new wxDataViewTextRenderer( wxT("string"), mode
, (int)align
),
985 model_column
, width
, align
, flags
);
991 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
992 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
994 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
995 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
, (int)align
),
996 model_column
, width
, align
, flags
);
1002 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1003 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1005 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1006 new wxDataViewToggleRenderer( wxT("bool"), mode
, (int)align
),
1007 model_column
, width
, align
, flags
);
1008 AppendColumn( ret
);
1013 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1014 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1016 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1017 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
, (int)align
),
1018 model_column
, width
, align
, flags
);
1019 AppendColumn( ret
);
1024 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1025 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1027 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1028 new wxDataViewDateRenderer( wxT("datetime"), mode
, (int)align
),
1029 model_column
, width
, align
, flags
);
1030 AppendColumn( ret
);
1035 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1036 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1038 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1039 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
, (int)align
),
1040 model_column
, width
, align
, flags
);
1041 AppendColumn( ret
);
1046 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1047 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1049 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1050 new wxDataViewTextRenderer( wxT("string"), mode
, (int)align
),
1051 model_column
, width
, align
, flags
);
1052 PrependColumn( ret
);
1057 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1058 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1060 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1061 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
, (int)align
),
1062 model_column
, width
, align
, flags
);
1063 PrependColumn( ret
);
1068 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1069 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1072 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1073 new wxDataViewToggleRenderer( wxT("bool"), mode
, (int)align
),
1074 model_column
, width
, align
, flags
);
1075 PrependColumn( ret
);
1080 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1081 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1083 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1084 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
, (int)align
),
1085 model_column
, width
, align
, flags
);
1086 PrependColumn( ret
);
1091 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1092 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1094 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1095 new wxDataViewDateRenderer( wxT("datetime"), mode
, (int)align
),
1096 model_column
, width
, align
, flags
);
1097 PrependColumn( ret
);
1102 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1103 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1105 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1106 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
, (int)align
),
1107 model_column
, width
, align
, flags
);
1108 PrependColumn( ret
);
1113 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1114 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1116 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1117 new wxDataViewTextRenderer( wxT("string"), mode
, (int)align
),
1118 model_column
, width
, align
, flags
);
1119 PrependColumn( ret
);
1124 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1125 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1127 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1128 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
, (int)align
),
1129 model_column
, width
, align
, flags
);
1130 PrependColumn( ret
);
1135 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1136 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1138 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1139 new wxDataViewToggleRenderer( wxT("bool"), mode
, (int)align
),
1140 model_column
, width
, align
, flags
);
1141 PrependColumn( ret
);
1146 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1147 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1149 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1150 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
, (int)align
),
1151 model_column
, width
, align
, flags
);
1152 PrependColumn( ret
);
1157 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1158 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1160 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1161 new wxDataViewDateRenderer( wxT("datetime"), mode
, (int)align
),
1162 model_column
, width
, align
, flags
);
1163 PrependColumn( ret
);
1168 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1169 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1171 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1172 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
, (int)align
),
1173 model_column
, width
, align
, flags
);
1174 PrependColumn( ret
);
1179 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1181 col
->SetOwner( (wxDataViewCtrl
*) this );
1186 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1188 col
->SetOwner( (wxDataViewCtrl
*) this );
1192 // ---------------------------------------------------------
1194 // ---------------------------------------------------------
1196 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1198 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
)
1200 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
)
1201 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
)
1202 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
)
1203 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
)
1204 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
)
1205 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
)
1206 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
)
1207 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
)
1209 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
)
1211 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
)
1212 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
)
1213 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
)
1214 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
)
1217 // -------------------------------------
1218 // wxDataViewSpinRenderer
1219 // -------------------------------------
1221 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1222 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1228 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1231 wxSize size
= labelRect
.GetSize();
1233 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1236 str
.Printf( wxT("%d"), (int) l
);
1237 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1238 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
, m_min
, m_max
, l
);
1240 size
= sc
->GetSize();
1241 wxPoint pt
= sc
->GetPosition();
1242 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1248 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1250 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1251 long l
= sc
->GetValue();
1256 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1259 str
.Printf(wxT("%d"), (int) m_data
);
1260 RenderText( str
, 0, rect
, dc
, state
);
1264 wxSize
wxDataViewSpinRenderer::GetSize() const
1266 return wxSize(80,16);
1269 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1271 m_data
= value
.GetLong();
1275 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1281 //-----------------------------------------------------------------------------
1282 // wxDataViewTreeStore
1283 //-----------------------------------------------------------------------------
1285 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1286 wxDataViewTreeStoreNode
*parent
,
1287 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1295 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1301 #include "wx/listimpl.cpp"
1302 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1304 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1305 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1306 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1307 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1309 m_iconExpanded
= expanded
;
1310 m_isExpanded
= false;
1311 m_children
.DeleteContents(true);
1314 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1318 //-----------------------------------------------------------------------------
1320 wxDataViewTreeStore::wxDataViewTreeStore()
1322 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1325 wxDataViewTreeStore::~wxDataViewTreeStore()
1330 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1331 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1333 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1334 if (!parent_node
) return wxDataViewItem(0);
1336 wxDataViewTreeStoreNode
*node
=
1337 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1338 parent_node
->GetChildren().Append( node
);
1341 ItemAdded( parent
, node
->GetItem() );
1343 return node
->GetItem();
1346 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1347 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1349 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1350 if (!parent_node
) return wxDataViewItem(0);
1352 wxDataViewTreeStoreNode
*node
=
1353 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1354 parent_node
->GetChildren().Insert( node
);
1357 ItemAdded( parent
, node
->GetItem() );
1359 return node
->GetItem();
1363 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& WXUNUSED(parent
),
1364 const wxDataViewItem
& WXUNUSED(previous
),
1365 const wxString
& WXUNUSED(text
),
1366 const wxIcon
& WXUNUSED(icon
),
1367 wxClientData
* WXUNUSED(data
))
1369 return wxDataViewItem(0);
1372 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1373 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1374 wxClientData
*data
)
1376 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1377 if (!parent_node
) return wxDataViewItem(0);
1379 wxDataViewTreeStoreContainerNode
*node
=
1380 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1381 parent_node
->GetChildren().Insert( node
);
1384 ItemAdded( parent
, node
->GetItem() );
1386 return node
->GetItem();
1390 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1391 const wxString
&text
,
1393 const wxIcon
& expanded
,
1394 wxClientData
* data
)
1396 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1397 if (!parent_node
) return wxDataViewItem(0);
1399 wxDataViewTreeStoreContainerNode
*node
=
1400 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1401 parent_node
->GetChildren().Append( node
);
1404 ItemAdded( parent
, node
->GetItem() );
1406 return node
->GetItem();
1410 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& WXUNUSED(parent
),
1411 const wxDataViewItem
& WXUNUSED(previous
),
1412 const wxString
& WXUNUSED(text
),
1413 const wxIcon
& WXUNUSED(icon
),
1414 const wxIcon
& WXUNUSED(expanded
),
1415 wxClientData
* WXUNUSED(data
))
1417 return wxDataViewItem(0);
1420 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1422 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1423 if (!parent_node
) return wxDataViewItem(0);
1425 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1427 return node
->GetData();
1429 return wxDataViewItem(0);
1432 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1434 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1435 if (!node
) return -1;
1437 if (!node
->IsContainer())
1440 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1441 return (int) container_node
->GetChildren().GetCount();
1444 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1446 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1449 node
->SetText( text
);
1452 ValueChanged( item
, 0 );
1455 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1457 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1458 if (!node
) return wxEmptyString
;
1460 return node
->GetText();
1463 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1465 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1468 node
->SetIcon( icon
);
1471 ValueChanged( item
, 0 );
1474 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1476 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1477 if (!node
) return wxNullIcon
;
1479 return node
->GetIcon();
1482 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1484 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1487 node
->SetExpandedIcon( icon
);
1490 ValueChanged( item
, 0 );
1493 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1495 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1496 if (!node
) return wxNullIcon
;
1498 return node
->GetExpandedIcon();
1501 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1503 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1506 node
->SetData( data
);
1508 // notify control? only sensible when sorting on client data
1509 // ValueChanged( item, 0 );
1512 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
1514 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1515 if (!node
) return NULL
;
1517 return node
->GetData();
1520 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
1522 if (!item
.IsOk()) return;
1524 wxDataViewItem parent_item
= GetParent( item
);
1526 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
1527 if (!parent_node
) return;
1529 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1532 parent_node
->GetChildren().DeleteObject( node
);
1535 ItemDeleted( parent_item
, item
);
1538 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
1540 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1543 wxDataViewItemArray array
;
1544 wxDataViewTreeStoreNodeList::iterator iter
;
1545 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1547 wxDataViewTreeStoreNode
* child
= *iter
;
1548 array
.Add( child
->GetItem() );
1551 node
->GetChildren().clear();
1554 ItemsDeleted( item
, array
);
1557 void wxDataViewTreeStore::DeleteAllItems()
1563 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
1564 const wxDataViewItem
&item
,
1565 unsigned int WXUNUSED(col
)) const
1567 // if (col != 0) return;
1569 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1572 wxIcon
icon( node
->GetIcon());
1573 if (node
->IsContainer())
1575 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
1576 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
1577 icon
= container
->GetExpandedIcon();
1580 wxDataViewIconText
data( node
->GetText(), icon
);
1586 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
1587 const wxDataViewItem
& item
,
1588 unsigned int WXUNUSED(col
))
1590 // if (col != 0) return false;
1592 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1593 if (!node
) return false;
1595 wxDataViewIconText data
;
1599 node
->SetText( data
.GetText() );
1600 node
->SetIcon( data
.GetIcon() );
1605 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
1607 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1608 if (!node
) return wxDataViewItem(0);
1610 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
1611 if (!parent
) return wxDataViewItem(0);
1613 if (parent
== m_root
)
1614 return wxDataViewItem(0);
1616 return parent
->GetItem();
1619 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
&item
) const
1621 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1622 if (!node
) return false;
1624 return node
->IsContainer();
1627 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
1629 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1630 if (!node
) return 0;
1632 wxDataViewTreeStoreNodeList::iterator iter
;
1633 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1635 wxDataViewTreeStoreNode
* child
= *iter
;
1636 children
.Add( child
->GetItem() );
1639 return node
->GetChildren().GetCount();
1642 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
1643 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) )
1645 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
1646 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
1648 if (!node1
|| !node2
)
1651 wxDataViewTreeStoreContainerNode
* parent1
=
1652 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
1653 wxDataViewTreeStoreContainerNode
* parent2
=
1654 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
1656 if (parent1
!= parent2
)
1658 wxLogError( wxT("Comparing items with different parent.") );
1662 if (node1
->IsContainer() && !!node2
->IsContainer())
1665 if (node2
->IsContainer() && !!node1
->IsContainer())
1668 return parent1
->GetChildren().IndexOf( node1
) - parent1
->GetChildren().IndexOf( node2
);
1671 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
1676 return (wxDataViewTreeStoreNode
*) item
.GetID();
1679 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
1682 return (wxDataViewTreeStoreContainerNode
*) m_root
;
1684 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
1686 if (!node
->IsContainer())
1689 return (wxDataViewTreeStoreContainerNode
*) node
;
1692 //-----------------------------------------------------------------------------
1693 // wxDataViewTreeCtrl
1694 //-----------------------------------------------------------------------------
1696 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1698 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1699 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
1700 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
1701 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
1704 wxDataViewTreeCtrl::wxDataViewTreeCtrl()
1709 wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow
*parent
, wxWindowID id
,
1710 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1713 Create( parent
, id
, pos
, size
, style
, validator
);
1715 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
1716 AssociateModel( store
);
1719 AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT
,-1);
1722 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
1728 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1729 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1731 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
1734 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
1739 m_imageList
= imagelist
;
1742 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
1743 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1745 wxIcon icon
= wxNullIcon
;
1746 if (m_imageList
&& (iconIndex
!= -1))
1747 icon
= m_imageList
->GetIcon( iconIndex
);
1749 return GetStore()->AppendItem( parent
, text
, icon
, data
);
1752 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
1753 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1755 wxIcon icon
= wxNullIcon
;
1756 if (m_imageList
&& (iconIndex
!= -1))
1757 icon
= m_imageList
->GetIcon( iconIndex
);
1759 return GetStore()->PrependItem( parent
, text
, icon
, data
);
1762 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1763 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1765 wxIcon icon
= wxNullIcon
;
1766 if (m_imageList
&& (iconIndex
!= -1))
1767 icon
= m_imageList
->GetIcon( iconIndex
);
1769 return GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
1772 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
1773 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1775 wxIcon icon
= wxNullIcon
;
1776 if (m_imageList
&& (iconIndex
!= -1))
1777 icon
= m_imageList
->GetIcon( iconIndex
);
1779 wxIcon expanded
= wxNullIcon
;
1780 if (m_imageList
&& (expandedIndex
!= -1))
1781 expanded
= m_imageList
->GetIcon( expandedIndex
);
1783 return GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
1786 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
1787 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1789 wxIcon icon
= wxNullIcon
;
1790 if (m_imageList
&& (iconIndex
!= -1))
1791 icon
= m_imageList
->GetIcon( iconIndex
);
1793 wxIcon expanded
= wxNullIcon
;
1794 if (m_imageList
&& (expandedIndex
!= -1))
1795 expanded
= m_imageList
->GetIcon( expandedIndex
);
1797 return GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
1800 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1801 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1803 wxIcon icon
= wxNullIcon
;
1804 if (m_imageList
&& (iconIndex
!= -1))
1805 icon
= m_imageList
->GetIcon( iconIndex
);
1807 wxIcon expanded
= wxNullIcon
;
1808 if (m_imageList
&& (expandedIndex
!= -1))
1809 expanded
= m_imageList
->GetIcon( expandedIndex
);
1811 return GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
1814 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
1816 if (m_imageList
) return;
1818 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
1819 if (!container
) return;
1821 container
->SetExpanded( true );
1822 GetStore()->ItemChanged( event
.GetItem() );
1825 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
1827 if (m_imageList
) return;
1829 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
1830 if (!container
) return;
1832 container
->SetExpanded( false );
1833 GetStore()->ItemChanged( event
.GetItem() );
1836 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
1838 #if defined(wxUSE_GENERICDATAVIEWCTRL)
1839 wxSize size
= GetClientSize();
1840 wxDataViewColumn
*col
= GetColumn( 0 );
1842 col
->SetWidth( size
.x
);
1847 #endif // wxUSE_DATAVIEWCTRL