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"
21 #include "wx/spinctrl.h"
22 #include "wx/choice.h"
24 #include "wx/weakref.h"
25 #include "wx/vector.h"
29 #include "wx/settings.h"
35 const char wxDataViewCtrlNameStr
[] = "dataviewCtrl";
38 bool operator == (const wxDataViewItem
&left
, const wxDataViewItem
&right
)
40 return (left
.GetID() == right
.GetID() );
44 void wxDataViewItem::Print(const wxString
& text
) const
46 wxPrintf(wxT("item %s: %lu\n"), text
.GetData(), wxPtrToUInt(m_id
));
50 // ---------------------------------------------------------
51 // wxDataViewModelNotifier
52 // ---------------------------------------------------------
54 #include "wx/listimpl.cpp"
55 WX_DEFINE_LIST(wxDataViewModelNotifiers
)
57 bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
59 size_t count
= items
.GetCount();
61 for (i
= 0; i
< count
; i
++)
62 if (!ItemAdded( parent
, items
[i
] )) return false;
67 bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
69 size_t count
= items
.GetCount();
71 for (i
= 0; i
< count
; i
++)
72 if (!ItemDeleted( parent
, items
[i
] )) return false;
77 bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray
&items
)
79 size_t count
= items
.GetCount();
81 for (i
= 0; i
< count
; i
++)
82 if (!ItemChanged( items
[i
] )) return false;
87 // ---------------------------------------------------------
89 // ---------------------------------------------------------
91 wxDataViewModel::wxDataViewModel()
93 m_notifiers
.DeleteContents( true );
96 bool wxDataViewModel::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
100 wxDataViewModelNotifiers::iterator iter
;
101 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
103 wxDataViewModelNotifier
* notifier
= *iter
;
104 if (!notifier
->ItemAdded( parent
, item
))
111 bool wxDataViewModel::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
115 wxDataViewModelNotifiers::iterator iter
;
116 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
118 wxDataViewModelNotifier
* notifier
= *iter
;
119 if (!notifier
->ItemDeleted( parent
, item
))
126 bool wxDataViewModel::ItemChanged( const wxDataViewItem
&item
)
130 wxDataViewModelNotifiers::iterator iter
;
131 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
133 wxDataViewModelNotifier
* notifier
= *iter
;
134 if (!notifier
->ItemChanged( item
))
141 bool wxDataViewModel::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
145 wxDataViewModelNotifiers::iterator iter
;
146 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
148 wxDataViewModelNotifier
* notifier
= *iter
;
149 if (!notifier
->ItemsAdded( parent
, items
))
156 bool wxDataViewModel::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
160 wxDataViewModelNotifiers::iterator iter
;
161 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
163 wxDataViewModelNotifier
* notifier
= *iter
;
164 if (!notifier
->ItemsDeleted( parent
, items
))
171 bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray
&items
)
175 wxDataViewModelNotifiers::iterator iter
;
176 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
178 wxDataViewModelNotifier
* notifier
= *iter
;
179 if (!notifier
->ItemsChanged( items
))
186 bool wxDataViewModel::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
190 wxDataViewModelNotifiers::iterator iter
;
191 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
193 wxDataViewModelNotifier
* notifier
= *iter
;
194 if (!notifier
->ValueChanged( item
, col
))
201 bool wxDataViewModel::Cleared()
205 wxDataViewModelNotifiers::iterator iter
;
206 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
208 wxDataViewModelNotifier
* notifier
= *iter
;
209 if (!notifier
->Cleared())
216 void wxDataViewModel::Resort()
218 wxDataViewModelNotifiers::iterator iter
;
219 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
221 wxDataViewModelNotifier
* notifier
= *iter
;
226 void wxDataViewModel::AddNotifier( wxDataViewModelNotifier
*notifier
)
228 m_notifiers
.push_back( notifier
);
229 notifier
->SetOwner( this );
232 void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier
*notifier
)
234 m_notifiers
.DeleteObject( notifier
);
237 int wxDataViewModel::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
238 unsigned int column
, bool ascending
)
240 // sort branches before leaves
241 bool item1_is_container
= IsContainer(item1
);
242 bool item2_is_container
= IsContainer(item2
);
244 if (item1_is_container
&& !item2_is_container
)
246 if (item2_is_container
&& !item1_is_container
)
249 wxVariant value1
,value2
;
250 GetValue( value1
, item1
, column
);
251 GetValue( value2
, item2
, column
);
255 wxVariant temp
= value1
;
260 if (value1
.GetType() == wxT("string"))
262 wxString str1
= value1
.GetString();
263 wxString str2
= value2
.GetString();
264 int res
= str1
.Cmp( str2
);
268 else if (value1
.GetType() == wxT("long"))
270 long l1
= value1
.GetLong();
271 long l2
= value2
.GetLong();
276 else if (value1
.GetType() == wxT("double"))
278 double d1
= value1
.GetDouble();
279 double d2
= value2
.GetDouble();
285 else if (value1
.GetType() == wxT("datetime"))
287 wxDateTime dt1
= value1
.GetDateTime();
288 wxDateTime dt2
= value2
.GetDateTime();
289 if (dt1
.IsEarlierThan(dt2
))
291 if (dt2
.IsEarlierThan(dt1
))
295 // items must be different
296 wxUIntPtr id1
= wxPtrToUInt(item1
.GetID()),
297 id2
= wxPtrToUInt(item2
.GetID());
299 return ascending
? id1
- id2
: id2
- id1
;
302 // ---------------------------------------------------------
303 // wxDataViewIndexListModel
304 // ---------------------------------------------------------
306 static int my_sort( int *v1
, int *v2
)
312 wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size
)
314 // IDs are ordered until an item gets deleted or inserted
317 // build initial index
319 for (i
= 1; i
< initial_size
+1; i
++)
320 m_hash
.Add( wxUIntToPtr(i
) );
321 m_lastIndex
= initial_size
+ 1;
324 wxDataViewIndexListModel::~wxDataViewIndexListModel()
328 void wxDataViewIndexListModel::Reset( unsigned int new_size
)
332 // IDs are ordered until an item gets deleted or inserted
335 // build initial index
337 for (i
= 1; i
< new_size
+1; i
++)
338 m_hash
.Add( wxUIntToPtr(i
) );
339 m_lastIndex
= new_size
+ 1;
341 wxDataViewModel::Cleared();
344 void wxDataViewIndexListModel::RowPrepended()
348 unsigned int id
= m_lastIndex
++;
349 m_hash
.Insert( wxUIntToPtr(id
), 0 );
350 wxDataViewItem
item( wxUIntToPtr(id
) );
351 ItemAdded( wxDataViewItem(0), item
);
354 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
358 unsigned int id
= m_lastIndex
++;
359 m_hash
.Insert( wxUIntToPtr(id
), before
);
360 wxDataViewItem
item( wxUIntToPtr(id
) );
361 ItemAdded( wxDataViewItem(0), item
);
364 void wxDataViewIndexListModel::RowAppended()
366 unsigned int id
= m_lastIndex
++;
367 m_hash
.Add( wxUIntToPtr(id
) );
368 wxDataViewItem
item( wxUIntToPtr(id
) );
369 ItemAdded( wxDataViewItem(0), item
);
372 void wxDataViewIndexListModel::RowDeleted( unsigned int row
)
376 wxDataViewItem
item( m_hash
[row
] );
377 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
378 m_hash
.RemoveAt( row
);
381 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt
&rows
)
383 wxArrayInt sorted
= rows
;
384 sorted
.Sort( my_sort
);
388 wxDataViewItemArray array
;
390 for (i
= 0; i
< rows
.GetCount(); i
++)
392 wxDataViewItem
item( m_hash
[rows
[i
]] );
395 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
397 for (i
= 0; i
< sorted
.GetCount(); i
++)
398 m_hash
.RemoveAt( sorted
[i
] );
401 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
403 wxDataViewModel::ItemChanged( GetItem(row
) );
406 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
408 wxDataViewModel::ValueChanged( GetItem(row
), col
);
411 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
415 unsigned int pos
= wxPtrToUInt( item
.GetID() );
419 // assert for not found
420 return (unsigned int) m_hash
.Index( item
.GetID() );
423 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
425 wxASSERT( row
< m_hash
.GetCount() );
426 return wxDataViewItem( m_hash
[row
] );
429 bool wxDataViewIndexListModel::HasDefaultCompare() const
434 int wxDataViewIndexListModel::Compare(const wxDataViewItem
& item1
,
435 const wxDataViewItem
& item2
,
436 unsigned int WXUNUSED(column
),
441 unsigned int pos1
= wxPtrToUInt(item1
.GetID());
442 unsigned int pos2
= wxPtrToUInt(item2
.GetID());
451 return GetRow(item1
) - GetRow(item2
);
453 return GetRow(item2
) - GetRow(item1
);
456 void wxDataViewIndexListModel::GetValue( wxVariant
&variant
,
457 const wxDataViewItem
&item
, unsigned int col
) const
459 GetValueByRow( variant
, GetRow(item
), col
);
462 bool wxDataViewIndexListModel::SetValue( const wxVariant
&variant
,
463 const wxDataViewItem
&item
, unsigned int col
)
465 return SetValueByRow( variant
, GetRow(item
), col
);
468 bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
470 return GetAttrByRow( GetRow(item
), col
, attr
);
473 wxDataViewItem
wxDataViewIndexListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
475 return wxDataViewItem(0);
478 bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem
&item
) const
480 // only the invisible root item has children
487 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
494 return m_hash
.GetCount();
497 // ---------------------------------------------------------
498 // wxDataViewVirtualListModel
499 // ---------------------------------------------------------
503 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size
)
505 m_lastIndex
= initial_size
-1;
508 wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
512 void wxDataViewVirtualListModel::Reset( unsigned int new_size
)
514 m_lastIndex
= new_size
-1;
516 wxDataViewModel::Cleared();
519 void wxDataViewVirtualListModel::RowPrepended()
522 wxDataViewItem
item( NULL
);
523 ItemAdded( wxDataViewItem(0), item
);
526 void wxDataViewVirtualListModel::RowInserted( unsigned int before
)
529 wxDataViewItem
item( wxUIntToPtr(before
) );
530 ItemAdded( wxDataViewItem(0), item
);
533 void wxDataViewVirtualListModel::RowAppended()
536 wxDataViewItem
item( wxUIntToPtr(m_lastIndex
) );
537 ItemAdded( wxDataViewItem(0), item
);
540 void wxDataViewVirtualListModel::RowDeleted( unsigned int row
)
542 wxDataViewItem
item( wxUIntToPtr(row
) );
543 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
547 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt
&rows
)
549 wxArrayInt sorted
= rows
;
550 sorted
.Sort( my_sort
);
552 wxDataViewItemArray array
;
554 for (i
= 0; i
< sorted
.GetCount(); i
++)
556 wxDataViewItem
item( wxUIntToPtr(sorted
[i
]) );
559 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
561 m_lastIndex
-= rows
.GetCount();
564 void wxDataViewVirtualListModel::RowChanged( unsigned int row
)
566 wxDataViewModel::ItemChanged( GetItem(row
) );
569 void wxDataViewVirtualListModel::RowValueChanged( unsigned int row
, unsigned int col
)
571 wxDataViewModel::ValueChanged( GetItem(row
), col
);
574 unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem
&item
) const
576 return wxPtrToUInt( item
.GetID() );
579 wxDataViewItem
wxDataViewVirtualListModel::GetItem( unsigned int row
) const
581 return wxDataViewItem( wxUIntToPtr(row
) );
584 bool wxDataViewVirtualListModel::HasDefaultCompare() const
589 int wxDataViewVirtualListModel::Compare(const wxDataViewItem
& item1
,
590 const wxDataViewItem
& item2
,
591 unsigned int WXUNUSED(column
),
594 unsigned int pos1
= wxPtrToUInt(item1
.GetID());
595 unsigned int pos2
= wxPtrToUInt(item2
.GetID());
603 void wxDataViewVirtualListModel::GetValue( wxVariant
&variant
,
604 const wxDataViewItem
&item
, unsigned int col
) const
606 GetValueByRow( variant
, GetRow(item
), col
);
609 bool wxDataViewVirtualListModel::SetValue( const wxVariant
&variant
,
610 const wxDataViewItem
&item
, unsigned int col
)
612 return SetValueByRow( variant
, GetRow(item
), col
);
615 bool wxDataViewVirtualListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
617 return GetAttrByRow( GetRow(item
), col
, attr
);
620 wxDataViewItem
wxDataViewVirtualListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
622 return wxDataViewItem(0);
625 bool wxDataViewVirtualListModel::IsContainer( const wxDataViewItem
&item
) const
627 // only the invisible root item has children
634 unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem
&WXUNUSED(item
), wxDataViewItemArray
&WXUNUSED(children
) ) const
636 return 0; // should we report an error ?
641 //-----------------------------------------------------------------------------
642 // wxDataViewIconText
643 //-----------------------------------------------------------------------------
645 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
647 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
649 bool operator == (const wxDataViewIconText
&one
, const wxDataViewIconText
&two
)
651 if (one
.GetText() != two
.GetText()) return false;
652 if (one
.IsSameAs(two
)) return false;
656 // ---------------------------------------------------------
657 // wxDataViewRendererBase
658 // ---------------------------------------------------------
660 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
662 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
663 wxDataViewCellMode
WXUNUSED(mode
),
664 int WXUNUSED(align
) )
666 m_variantType
= varianttype
;
670 wxDataViewRendererBase::~wxDataViewRendererBase()
674 const wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
676 return const_cast<wxDataViewRendererBase
*>(this)->GetOwner()->GetOwner();
679 class wxKillRef
: public wxWindowRef
682 wxKillRef( wxWindow
*win
) : wxWindowRef( win
) { }
683 virtual void OnObjectDestroy()
685 get()->PopEventHandler( true );
691 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
693 m_item
= item
; // remember for later
695 unsigned int col
= GetOwner()->GetModelColumn();
697 GetOwner()->GetOwner()->GetModel()->GetValue( value
, item
, col
);
699 m_editorCtrl
= CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect
, value
);
700 (void) new wxKillRef( m_editorCtrl
.get() );
702 wxDataViewEditorCtrlEvtHandler
*handler
=
703 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
705 m_editorCtrl
->PushEventHandler( handler
);
707 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
708 handler
->SetFocusOnIdle();
710 m_editorCtrl
->SetFocus();
713 // Now we should send Editing Started event
714 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, GetOwner()->GetOwner()->GetId() );
715 event
.SetDataViewColumn( GetOwner() );
716 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
717 event
.SetItem( item
);
718 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
723 void wxDataViewRendererBase::CancelEditing()
725 if (!m_editorCtrl
) return;
727 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
729 m_editorCtrl
->Hide();
730 wxPendingDelete
.Append( m_editorCtrl
);
733 bool wxDataViewRendererBase::FinishEditing()
735 if (!m_editorCtrl
) return true;
738 GetValueFromEditorCtrl( m_editorCtrl
, value
);
740 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
742 m_editorCtrl
->Hide();
743 wxPendingDelete
.Append( m_editorCtrl
);
745 if (!Validate(value
))
748 unsigned int col
= GetOwner()->GetModelColumn();
749 GetOwner()->GetOwner()->GetModel()->SetValue( value
, m_item
, col
);
750 GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item
, col
);
752 // Now we should send Editing Done event
753 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, GetOwner()->GetOwner()->GetId() );
754 event
.SetDataViewColumn( GetOwner() );
755 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
756 event
.SetItem( m_item
);
757 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
762 //-----------------------------------------------------------------------------
763 // wxDataViewEditorCtrlEvtHandler
764 //-----------------------------------------------------------------------------
766 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
767 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
768 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
769 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
770 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
773 wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
774 wxControl
*editorCtrl
,
775 wxDataViewRenderer
*owner
)
778 m_editorCtrl
= editorCtrl
;
783 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
787 m_focusOnIdle
= false;
788 if (wxWindow::FindFocus() != m_editorCtrl
)
789 m_editorCtrl
->SetFocus();
795 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
798 m_owner
->FinishEditing();
801 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
803 switch ( event
.m_keyCode
)
807 m_owner
->FinishEditing();
813 m_owner
->CancelEditing();
821 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
826 m_owner
->FinishEditing();
832 // ---------------------------------------------------------
833 // wxDataViewColumnBase
834 // ---------------------------------------------------------
836 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
837 unsigned int model_column
)
839 m_renderer
= renderer
;
840 m_model_column
= model_column
;
842 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
845 wxDataViewColumnBase::~wxDataViewColumnBase()
850 // ---------------------------------------------------------
851 // wxDataViewCtrlBase
852 // ---------------------------------------------------------
854 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
856 wxDataViewCtrlBase::wxDataViewCtrlBase()
859 m_expander_column
= 0;
863 wxDataViewCtrlBase::~wxDataViewCtrlBase()
872 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
876 m_model
->DecRef(); // discard old model, if any
879 // add our own reference to the new model:
889 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
894 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
899 void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem
& item
)
901 if (!m_model
) return;
903 if (!item
.IsOk()) return;
905 wxVector
<wxDataViewItem
> parentChain
;
907 // at first we get all the parents of the selected item
908 wxDataViewItem parent
= m_model
->GetParent(item
);
909 while (parent
.IsOk())
911 parentChain
.push_back(parent
);
912 parent
= m_model
->GetParent(parent
);
915 // then we expand the parents, starting at the root
916 while (!parentChain
.empty())
918 Expand(parentChain
.back());
919 parentChain
.pop_back();
924 wxDataViewCtrlBase::AppendTextColumn( const wxString
&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
),
929 model_column
, width
, align
, flags
);
935 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&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
),
940 model_column
, width
, align
, flags
);
946 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
947 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
950 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
951 new wxDataViewToggleRenderer( wxT("bool"), mode
),
952 model_column
, width
, align
, flags
);
958 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
959 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
961 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
962 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
963 model_column
, width
, align
, flags
);
969 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
970 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
972 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
973 new wxDataViewDateRenderer( wxT("datetime"), mode
),
974 model_column
, width
, align
, flags
);
980 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
981 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
983 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
984 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
985 model_column
, width
, align
, flags
);
991 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
992 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
994 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
995 new wxDataViewTextRenderer( wxT("string"), mode
),
996 model_column
, width
, align
, flags
);
1002 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1003 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1005 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1006 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1007 model_column
, width
, align
, flags
);
1008 AppendColumn( ret
);
1013 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1014 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1016 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1017 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1018 model_column
, width
, align
, flags
);
1019 AppendColumn( ret
);
1024 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&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
),
1029 model_column
, width
, align
, flags
);
1030 AppendColumn( ret
);
1035 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&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
),
1040 model_column
, width
, align
, flags
);
1041 AppendColumn( ret
);
1046 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&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
),
1051 model_column
, width
, align
, flags
);
1052 AppendColumn( ret
);
1057 wxDataViewCtrlBase::PrependTextColumn( const wxString
&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
),
1062 model_column
, width
, align
, flags
);
1063 PrependColumn( ret
);
1068 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&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
),
1073 model_column
, width
, align
, flags
);
1074 PrependColumn( ret
);
1079 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1080 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1083 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1084 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1085 model_column
, width
, align
, flags
);
1086 PrependColumn( ret
);
1091 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1092 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1094 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1095 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1096 model_column
, width
, align
, flags
);
1097 PrependColumn( ret
);
1102 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1103 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1105 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1106 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1107 model_column
, width
, align
, flags
);
1108 PrependColumn( ret
);
1113 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1114 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1116 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1117 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1118 model_column
, width
, align
, flags
);
1119 PrependColumn( ret
);
1124 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1125 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1127 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1128 new wxDataViewTextRenderer( wxT("string"), mode
),
1129 model_column
, width
, align
, flags
);
1130 PrependColumn( ret
);
1135 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1136 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1138 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1139 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1140 model_column
, width
, align
, flags
);
1141 PrependColumn( ret
);
1146 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1147 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1149 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1150 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1151 model_column
, width
, align
, flags
);
1152 PrependColumn( ret
);
1157 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1158 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1160 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1161 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1162 model_column
, width
, align
, flags
);
1163 PrependColumn( ret
);
1168 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1169 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1171 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1172 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1173 model_column
, width
, align
, flags
);
1174 PrependColumn( ret
);
1179 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1180 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1182 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1183 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1184 model_column
, width
, align
, flags
);
1185 PrependColumn( ret
);
1190 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1192 col
->SetOwner( (wxDataViewCtrl
*) this );
1197 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1199 col
->SetOwner( (wxDataViewCtrl
*) this );
1204 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1206 col
->SetOwner( (wxDataViewCtrl
*) this );
1210 // ---------------------------------------------------------
1212 // ---------------------------------------------------------
1214 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1216 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
)
1218 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
)
1219 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
)
1220 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
)
1221 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
)
1222 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
)
1223 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
)
1224 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
)
1225 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
)
1227 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
)
1229 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
)
1230 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
)
1231 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
)
1232 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
)
1235 // -------------------------------------
1236 // wxDataViewSpinRenderer
1237 // -------------------------------------
1239 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1240 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1246 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1249 wxSize size
= labelRect
.GetSize();
1251 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1254 str
.Printf( wxT("%d"), (int) l
);
1255 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1256 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1258 size
= sc
->GetSize();
1259 wxPoint pt
= sc
->GetPosition();
1260 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1266 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1268 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1269 long l
= sc
->GetValue();
1274 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1277 str
.Printf(wxT("%d"), (int) m_data
);
1278 RenderText( str
, 0, rect
, dc
, state
);
1282 wxSize
wxDataViewSpinRenderer::GetSize() const
1284 return wxSize(80,16);
1287 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1289 m_data
= value
.GetLong();
1293 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1299 // -------------------------------------
1300 // wxDataViewChoiceRenderer
1301 // -------------------------------------
1303 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXMAC__)
1305 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1306 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1308 m_choices
= choices
;
1311 wxControl
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1314 wxSize size
= labelRect
.GetSize();
1316 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1318 wxChoice
*c
= new wxChoice( parent
, wxID_ANY
, labelRect
.GetTopLeft(), size
, m_choices
);
1319 c
->SetStringSelection( value
.GetString() );
1324 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1326 wxChoice
*c
= (wxChoice
*) editor
;
1327 wxString s
= c
->GetStringSelection();
1332 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1334 RenderText( m_data
, 0, rect
, dc
, state
);
1338 wxSize
wxDataViewChoiceRenderer::GetSize() const
1340 return wxSize(80,16);
1343 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1345 m_data
= value
.GetString();
1349 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1357 //-----------------------------------------------------------------------------
1358 // wxDataViewListStore
1359 //-----------------------------------------------------------------------------
1361 wxDataViewListStore::wxDataViewListStore()
1365 wxDataViewListStore::~wxDataViewListStore()
1367 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1368 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1370 wxDataViewListStoreLine
* line
= *it
;
1375 void wxDataViewListStore::PrependColumn( const wxString
&varianttype
)
1377 m_cols
.Insert( varianttype
, 0 );
1380 void wxDataViewListStore::InsertColumn( unsigned int pos
, const wxString
&varianttype
)
1382 m_cols
.Insert( varianttype
, pos
);
1385 void wxDataViewListStore::AppendColumn( const wxString
&varianttype
)
1387 m_cols
.Add( varianttype
);
1390 unsigned int wxDataViewListStore::GetColumnCount() const
1392 return m_cols
.GetCount();
1395 wxString
wxDataViewListStore::GetColumnType( unsigned int pos
) const
1400 void wxDataViewListStore::AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1402 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1403 line
->m_values
= values
;
1404 m_data
.push_back( line
);
1409 void wxDataViewListStore::PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1411 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1412 line
->m_values
= values
;
1413 m_data
.insert( m_data
.begin(), line
);
1418 void wxDataViewListStore::InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1420 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1421 line
->m_values
= values
;
1422 m_data
.insert( m_data
.begin()+row
, line
);
1427 void wxDataViewListStore::DeleteItem( unsigned row
)
1429 wxVector
<wxDataViewListStoreLine
*>::iterator it
= m_data
.begin() + row
;
1435 void wxDataViewListStore::DeleteAllItems()
1437 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1438 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1440 wxDataViewListStoreLine
* line
= *it
;
1447 void wxDataViewListStore::GetValueByRow( wxVariant
&value
, unsigned int row
, unsigned int col
) const
1449 wxDataViewListStoreLine
*line
= m_data
[row
];
1450 value
= line
->m_values
[col
];
1453 bool wxDataViewListStore::SetValueByRow( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1455 wxDataViewListStoreLine
*line
= m_data
[row
];
1456 line
->m_values
[col
] = value
;
1461 //-----------------------------------------------------------------------------
1462 // wxDataViewTreeStore
1463 //-----------------------------------------------------------------------------
1465 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1466 wxDataViewTreeStoreNode
*parent
,
1467 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1475 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1481 #include "wx/listimpl.cpp"
1482 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1484 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1485 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1486 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1487 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1489 m_iconExpanded
= expanded
;
1490 m_isExpanded
= false;
1491 m_children
.DeleteContents(true);
1494 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1498 //-----------------------------------------------------------------------------
1500 wxDataViewTreeStore::wxDataViewTreeStore()
1502 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1505 wxDataViewTreeStore::~wxDataViewTreeStore()
1510 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1511 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1513 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1514 if (!parent_node
) return wxDataViewItem(0);
1516 wxDataViewTreeStoreNode
*node
=
1517 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1518 parent_node
->GetChildren().Append( node
);
1521 ItemAdded( parent
, node
->GetItem() );
1523 return node
->GetItem();
1526 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1527 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1529 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1530 if (!parent_node
) return wxDataViewItem(0);
1532 wxDataViewTreeStoreNode
*node
=
1533 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1534 parent_node
->GetChildren().Insert( node
);
1537 ItemAdded( parent
, node
->GetItem() );
1539 return node
->GetItem();
1543 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& WXUNUSED(parent
),
1544 const wxDataViewItem
& WXUNUSED(previous
),
1545 const wxString
& WXUNUSED(text
),
1546 const wxIcon
& WXUNUSED(icon
),
1547 wxClientData
* WXUNUSED(data
))
1549 return wxDataViewItem(0);
1552 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1553 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1554 wxClientData
*data
)
1556 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1557 if (!parent_node
) return wxDataViewItem(0);
1559 wxDataViewTreeStoreContainerNode
*node
=
1560 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1561 parent_node
->GetChildren().Insert( node
);
1564 ItemAdded( parent
, node
->GetItem() );
1566 return node
->GetItem();
1570 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1571 const wxString
&text
,
1573 const wxIcon
& expanded
,
1574 wxClientData
* data
)
1576 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1577 if (!parent_node
) return wxDataViewItem(0);
1579 wxDataViewTreeStoreContainerNode
*node
=
1580 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1581 parent_node
->GetChildren().Append( node
);
1584 ItemAdded( parent
, node
->GetItem() );
1586 return node
->GetItem();
1590 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& WXUNUSED(parent
),
1591 const wxDataViewItem
& WXUNUSED(previous
),
1592 const wxString
& WXUNUSED(text
),
1593 const wxIcon
& WXUNUSED(icon
),
1594 const wxIcon
& WXUNUSED(expanded
),
1595 wxClientData
* WXUNUSED(data
))
1597 return wxDataViewItem(0);
1600 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1602 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1603 if (!parent_node
) return wxDataViewItem(0);
1605 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1607 return node
->GetData();
1609 return wxDataViewItem(0);
1612 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1614 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1615 if (!node
) return -1;
1617 if (!node
->IsContainer())
1620 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1621 return (int) container_node
->GetChildren().GetCount();
1624 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1626 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1629 node
->SetText( text
);
1632 ValueChanged( item
, 0 );
1635 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1637 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1638 if (!node
) return wxEmptyString
;
1640 return node
->GetText();
1643 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1645 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1648 node
->SetIcon( icon
);
1651 ValueChanged( item
, 0 );
1654 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1656 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1657 if (!node
) return wxNullIcon
;
1659 return node
->GetIcon();
1662 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1664 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1667 node
->SetExpandedIcon( icon
);
1670 ValueChanged( item
, 0 );
1673 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1675 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1676 if (!node
) return wxNullIcon
;
1678 return node
->GetExpandedIcon();
1681 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1683 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1686 node
->SetData( data
);
1688 // notify control? only sensible when sorting on client data
1689 // ValueChanged( item, 0 );
1692 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
1694 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1695 if (!node
) return NULL
;
1697 return node
->GetData();
1700 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
1702 if (!item
.IsOk()) return;
1704 wxDataViewItem parent_item
= GetParent( item
);
1706 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
1707 if (!parent_node
) return;
1709 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1712 parent_node
->GetChildren().DeleteObject( node
);
1715 ItemDeleted( parent_item
, item
);
1718 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
1720 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1723 wxDataViewItemArray array
;
1724 wxDataViewTreeStoreNodeList::iterator iter
;
1725 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1727 wxDataViewTreeStoreNode
* child
= *iter
;
1728 array
.Add( child
->GetItem() );
1731 node
->GetChildren().clear();
1734 ItemsDeleted( item
, array
);
1737 void wxDataViewTreeStore::DeleteAllItems()
1743 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
1744 const wxDataViewItem
&item
,
1745 unsigned int WXUNUSED(col
)) const
1747 // if (col != 0) return;
1749 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1752 wxIcon
icon( node
->GetIcon());
1753 if (node
->IsContainer())
1755 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
1756 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
1757 icon
= container
->GetExpandedIcon();
1760 wxDataViewIconText
data( node
->GetText(), icon
);
1766 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
1767 const wxDataViewItem
& item
,
1768 unsigned int WXUNUSED(col
))
1770 // if (col != 0) return false;
1772 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1773 if (!node
) return false;
1775 wxDataViewIconText data
;
1779 node
->SetText( data
.GetText() );
1780 node
->SetIcon( data
.GetIcon() );
1785 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
1787 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1788 if (!node
) return wxDataViewItem(0);
1790 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
1791 if (!parent
) return wxDataViewItem(0);
1793 if (parent
== m_root
)
1794 return wxDataViewItem(0);
1796 return parent
->GetItem();
1799 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
&item
) const
1801 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1802 if (!node
) return false;
1804 return node
->IsContainer();
1807 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
1809 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1810 if (!node
) return 0;
1812 wxDataViewTreeStoreNodeList::iterator iter
;
1813 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1815 wxDataViewTreeStoreNode
* child
= *iter
;
1816 children
.Add( child
->GetItem() );
1819 return node
->GetChildren().GetCount();
1822 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
1823 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) )
1825 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
1826 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
1828 if (!node1
|| !node2
)
1831 wxDataViewTreeStoreContainerNode
* parent1
=
1832 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
1833 wxDataViewTreeStoreContainerNode
* parent2
=
1834 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
1836 if (parent1
!= parent2
)
1838 wxLogError( wxT("Comparing items with different parent.") );
1842 if (node1
->IsContainer() && !!node2
->IsContainer())
1845 if (node2
->IsContainer() && !!node1
->IsContainer())
1848 return parent1
->GetChildren().IndexOf( node1
) - parent1
->GetChildren().IndexOf( node2
);
1851 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
1856 return (wxDataViewTreeStoreNode
*) item
.GetID();
1859 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
1862 return (wxDataViewTreeStoreContainerNode
*) m_root
;
1864 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
1866 if (!node
->IsContainer())
1869 return (wxDataViewTreeStoreContainerNode
*) node
;
1872 //-----------------------------------------------------------------------------
1873 // wxDataViewTreeCtrl
1874 //-----------------------------------------------------------------------------
1876 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1878 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1879 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
1880 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
1881 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
1884 wxDataViewTreeCtrl::wxDataViewTreeCtrl()
1889 wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow
*parent
, wxWindowID id
,
1890 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1893 Create( parent
, id
, pos
, size
, style
, validator
);
1895 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
1896 AssociateModel( store
);
1899 AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT
,-1);
1902 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
1908 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1909 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1911 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
1914 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
1919 m_imageList
= imagelist
;
1922 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
1923 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1925 wxIcon icon
= wxNullIcon
;
1926 if (m_imageList
&& (iconIndex
!= -1))
1927 icon
= m_imageList
->GetIcon( iconIndex
);
1929 return GetStore()->AppendItem( parent
, text
, icon
, data
);
1932 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
1933 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1935 wxIcon icon
= wxNullIcon
;
1936 if (m_imageList
&& (iconIndex
!= -1))
1937 icon
= m_imageList
->GetIcon( iconIndex
);
1939 return GetStore()->PrependItem( parent
, text
, icon
, data
);
1942 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1943 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1945 wxIcon icon
= wxNullIcon
;
1946 if (m_imageList
&& (iconIndex
!= -1))
1947 icon
= m_imageList
->GetIcon( iconIndex
);
1949 return GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
1952 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
1953 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1955 wxIcon icon
= wxNullIcon
;
1956 if (m_imageList
&& (iconIndex
!= -1))
1957 icon
= m_imageList
->GetIcon( iconIndex
);
1959 wxIcon expanded
= wxNullIcon
;
1960 if (m_imageList
&& (expandedIndex
!= -1))
1961 expanded
= m_imageList
->GetIcon( expandedIndex
);
1963 return GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
1966 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
1967 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1969 wxIcon icon
= wxNullIcon
;
1970 if (m_imageList
&& (iconIndex
!= -1))
1971 icon
= m_imageList
->GetIcon( iconIndex
);
1973 wxIcon expanded
= wxNullIcon
;
1974 if (m_imageList
&& (expandedIndex
!= -1))
1975 expanded
= m_imageList
->GetIcon( expandedIndex
);
1977 return GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
1980 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1981 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1983 wxIcon icon
= wxNullIcon
;
1984 if (m_imageList
&& (iconIndex
!= -1))
1985 icon
= m_imageList
->GetIcon( iconIndex
);
1987 wxIcon expanded
= wxNullIcon
;
1988 if (m_imageList
&& (expandedIndex
!= -1))
1989 expanded
= m_imageList
->GetIcon( expandedIndex
);
1991 return GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
1994 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
1996 if (m_imageList
) return;
1998 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
1999 if (!container
) return;
2001 container
->SetExpanded( true );
2002 GetStore()->ItemChanged( event
.GetItem() );
2005 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
2007 if (m_imageList
) return;
2009 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2010 if (!container
) return;
2012 container
->SetExpanded( false );
2013 GetStore()->ItemChanged( event
.GetItem() );
2016 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
2018 #if defined(wxUSE_GENERICDATAVIEWCTRL)
2019 // automatically resize our only column to take the entire control width
2020 if ( GetColumnCount() )
2022 wxSize size
= GetClientSize();
2023 GetColumn(0)->SetWidth(size
.x
);
2029 #endif // wxUSE_DATAVIEWCTRL