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"
24 #include "wx/settings.h"
29 #include "wx/spinctrl.h"
30 #include "wx/choice.h"
31 #include "wx/imaglist.h"
33 const char wxDataViewCtrlNameStr
[] = "dataviewCtrl";
36 bool operator == (const wxDataViewItem
&left
, const wxDataViewItem
&right
)
38 return (left
.GetID() == right
.GetID() );
41 // ---------------------------------------------------------
42 // wxDataViewModelNotifier
43 // ---------------------------------------------------------
45 #include "wx/listimpl.cpp"
46 WX_DEFINE_LIST(wxDataViewModelNotifiers
)
48 bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
50 size_t count
= items
.GetCount();
52 for (i
= 0; i
< count
; i
++)
53 if (!ItemAdded( parent
, items
[i
] )) return false;
58 bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
60 size_t count
= items
.GetCount();
62 for (i
= 0; i
< count
; i
++)
63 if (!ItemDeleted( parent
, items
[i
] )) return false;
68 bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray
&items
)
70 size_t count
= items
.GetCount();
72 for (i
= 0; i
< count
; i
++)
73 if (!ItemChanged( items
[i
] )) return false;
78 // ---------------------------------------------------------
80 // ---------------------------------------------------------
82 wxDataViewModel::wxDataViewModel()
84 m_notifiers
.DeleteContents( true );
87 bool wxDataViewModel::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
91 wxDataViewModelNotifiers::iterator iter
;
92 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
94 wxDataViewModelNotifier
* notifier
= *iter
;
95 if (!notifier
->ItemAdded( parent
, item
))
102 bool wxDataViewModel::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
106 wxDataViewModelNotifiers::iterator iter
;
107 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
109 wxDataViewModelNotifier
* notifier
= *iter
;
110 if (!notifier
->ItemDeleted( parent
, item
))
117 bool wxDataViewModel::ItemChanged( const wxDataViewItem
&item
)
121 wxDataViewModelNotifiers::iterator iter
;
122 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
124 wxDataViewModelNotifier
* notifier
= *iter
;
125 if (!notifier
->ItemChanged( item
))
132 bool wxDataViewModel::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
136 wxDataViewModelNotifiers::iterator iter
;
137 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
139 wxDataViewModelNotifier
* notifier
= *iter
;
140 if (!notifier
->ItemsAdded( parent
, items
))
147 bool wxDataViewModel::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
151 wxDataViewModelNotifiers::iterator iter
;
152 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
154 wxDataViewModelNotifier
* notifier
= *iter
;
155 if (!notifier
->ItemsDeleted( parent
, items
))
162 bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray
&items
)
166 wxDataViewModelNotifiers::iterator iter
;
167 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
169 wxDataViewModelNotifier
* notifier
= *iter
;
170 if (!notifier
->ItemsChanged( items
))
177 bool wxDataViewModel::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
181 wxDataViewModelNotifiers::iterator iter
;
182 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
184 wxDataViewModelNotifier
* notifier
= *iter
;
185 if (!notifier
->ValueChanged( item
, col
))
192 bool wxDataViewModel::Cleared()
196 wxDataViewModelNotifiers::iterator iter
;
197 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
199 wxDataViewModelNotifier
* notifier
= *iter
;
200 if (!notifier
->Cleared())
207 void wxDataViewModel::Resort()
209 wxDataViewModelNotifiers::iterator iter
;
210 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
212 wxDataViewModelNotifier
* notifier
= *iter
;
217 void wxDataViewModel::AddNotifier( wxDataViewModelNotifier
*notifier
)
219 m_notifiers
.push_back( notifier
);
220 notifier
->SetOwner( this );
223 void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier
*notifier
)
225 m_notifiers
.DeleteObject( notifier
);
228 int wxDataViewModel::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
229 unsigned int column
, bool ascending
) const
231 // sort branches before leaves
232 bool item1_is_container
= IsContainer(item1
);
233 bool item2_is_container
= IsContainer(item2
);
235 if (item1_is_container
&& !item2_is_container
)
237 if (item2_is_container
&& !item1_is_container
)
240 wxVariant value1
,value2
;
241 GetValue( value1
, item1
, column
);
242 GetValue( value2
, item2
, column
);
246 wxVariant temp
= value1
;
251 if (value1
.GetType() == wxT("string"))
253 wxString str1
= value1
.GetString();
254 wxString str2
= value2
.GetString();
255 int res
= str1
.Cmp( str2
);
259 else if (value1
.GetType() == wxT("long"))
261 long l1
= value1
.GetLong();
262 long l2
= value2
.GetLong();
267 else if (value1
.GetType() == wxT("double"))
269 double d1
= value1
.GetDouble();
270 double d2
= value2
.GetDouble();
276 else if (value1
.GetType() == wxT("datetime"))
278 wxDateTime dt1
= value1
.GetDateTime();
279 wxDateTime dt2
= value2
.GetDateTime();
280 if (dt1
.IsEarlierThan(dt2
))
282 if (dt2
.IsEarlierThan(dt1
))
286 // items must be different
287 wxUIntPtr id1
= wxPtrToUInt(item1
.GetID()),
288 id2
= wxPtrToUInt(item2
.GetID());
290 return ascending
? id1
- id2
: id2
- id1
;
293 // ---------------------------------------------------------
294 // wxDataViewIndexListModel
295 // ---------------------------------------------------------
297 static int my_sort( int *v1
, int *v2
)
303 wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size
)
305 // IDs are ordered until an item gets deleted or inserted
308 // build initial index
310 for (i
= 1; i
< initial_size
+1; i
++)
311 m_hash
.Add( wxUIntToPtr(i
) );
312 m_lastIndex
= initial_size
+ 1;
315 wxDataViewIndexListModel::~wxDataViewIndexListModel()
319 void wxDataViewIndexListModel::Reset( unsigned int new_size
)
323 // IDs are ordered until an item gets deleted or inserted
326 // build initial index
328 for (i
= 1; i
< new_size
+1; i
++)
329 m_hash
.Add( wxUIntToPtr(i
) );
330 m_lastIndex
= new_size
+ 1;
332 wxDataViewModel::Cleared();
335 void wxDataViewIndexListModel::RowPrepended()
339 unsigned int id
= m_lastIndex
++;
340 m_hash
.Insert( wxUIntToPtr(id
), 0 );
341 wxDataViewItem
item( wxUIntToPtr(id
) );
342 ItemAdded( wxDataViewItem(0), item
);
345 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
349 unsigned int id
= m_lastIndex
++;
350 m_hash
.Insert( wxUIntToPtr(id
), before
);
351 wxDataViewItem
item( wxUIntToPtr(id
) );
352 ItemAdded( wxDataViewItem(0), item
);
355 void wxDataViewIndexListModel::RowAppended()
357 unsigned int id
= m_lastIndex
++;
358 m_hash
.Add( wxUIntToPtr(id
) );
359 wxDataViewItem
item( wxUIntToPtr(id
) );
360 ItemAdded( wxDataViewItem(0), item
);
363 void wxDataViewIndexListModel::RowDeleted( unsigned int row
)
367 wxDataViewItem
item( m_hash
[row
] );
368 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
369 m_hash
.RemoveAt( row
);
372 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt
&rows
)
374 wxArrayInt sorted
= rows
;
375 sorted
.Sort( my_sort
);
379 wxDataViewItemArray array
;
381 for (i
= 0; i
< rows
.GetCount(); i
++)
383 wxDataViewItem
item( m_hash
[rows
[i
]] );
386 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
388 for (i
= 0; i
< sorted
.GetCount(); i
++)
389 m_hash
.RemoveAt( sorted
[i
] );
392 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
394 wxDataViewModel::ItemChanged( GetItem(row
) );
397 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
399 wxDataViewModel::ValueChanged( GetItem(row
), col
);
402 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
406 unsigned int pos
= wxPtrToUInt( item
.GetID() );
410 // assert for not found
411 return (unsigned int) m_hash
.Index( item
.GetID() );
414 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
416 wxASSERT( row
< m_hash
.GetCount() );
417 return wxDataViewItem( m_hash
[row
] );
420 bool wxDataViewIndexListModel::HasDefaultCompare() const
425 int wxDataViewIndexListModel::Compare(const wxDataViewItem
& item1
,
426 const wxDataViewItem
& item2
,
427 unsigned int WXUNUSED(column
),
428 bool ascending
) const
432 unsigned int pos1
= wxPtrToUInt(item1
.GetID());
433 unsigned int pos2
= wxPtrToUInt(item2
.GetID());
442 return GetRow(item1
) - GetRow(item2
);
444 return GetRow(item2
) - GetRow(item1
);
447 void wxDataViewIndexListModel::GetValue( wxVariant
&variant
,
448 const wxDataViewItem
&item
, unsigned int col
) const
450 GetValueByRow( variant
, GetRow(item
), col
);
453 bool wxDataViewIndexListModel::SetValue( const wxVariant
&variant
,
454 const wxDataViewItem
&item
, unsigned int col
)
456 return SetValueByRow( variant
, GetRow(item
), col
);
459 bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
461 return GetAttrByRow( GetRow(item
), col
, attr
);
464 wxDataViewItem
wxDataViewIndexListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
466 return wxDataViewItem(0);
469 bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem
&item
) const
471 // only the invisible root item has children
478 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
485 return m_hash
.GetCount();
488 // ---------------------------------------------------------
489 // wxDataViewVirtualListModel
490 // ---------------------------------------------------------
494 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size
)
496 m_lastIndex
= initial_size
-1;
499 wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
503 void wxDataViewVirtualListModel::Reset( unsigned int new_size
)
505 m_lastIndex
= new_size
-1;
507 wxDataViewModel::Cleared();
510 void wxDataViewVirtualListModel::RowPrepended()
513 wxDataViewItem
item( NULL
);
514 ItemAdded( wxDataViewItem(0), item
);
517 void wxDataViewVirtualListModel::RowInserted( unsigned int before
)
520 wxDataViewItem
item( wxUIntToPtr(before
) );
521 ItemAdded( wxDataViewItem(0), item
);
524 void wxDataViewVirtualListModel::RowAppended()
527 wxDataViewItem
item( wxUIntToPtr(m_lastIndex
) );
528 ItemAdded( wxDataViewItem(0), item
);
531 void wxDataViewVirtualListModel::RowDeleted( unsigned int row
)
533 wxDataViewItem
item( wxUIntToPtr(row
) );
534 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
538 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt
&rows
)
540 wxArrayInt sorted
= rows
;
541 sorted
.Sort( my_sort
);
543 wxDataViewItemArray array
;
545 for (i
= 0; i
< sorted
.GetCount(); i
++)
547 wxDataViewItem
item( wxUIntToPtr(sorted
[i
]) );
550 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
552 m_lastIndex
-= rows
.GetCount();
555 void wxDataViewVirtualListModel::RowChanged( unsigned int row
)
557 wxDataViewModel::ItemChanged( GetItem(row
) );
560 void wxDataViewVirtualListModel::RowValueChanged( unsigned int row
, unsigned int col
)
562 wxDataViewModel::ValueChanged( GetItem(row
), col
);
565 unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem
&item
) const
567 return wxPtrToUInt( item
.GetID() );
570 wxDataViewItem
wxDataViewVirtualListModel::GetItem( unsigned int row
) const
572 return wxDataViewItem( wxUIntToPtr(row
) );
575 bool wxDataViewVirtualListModel::HasDefaultCompare() const
580 int wxDataViewVirtualListModel::Compare(const wxDataViewItem
& item1
,
581 const wxDataViewItem
& item2
,
582 unsigned int WXUNUSED(column
),
583 bool ascending
) const
585 unsigned int pos1
= wxPtrToUInt(item1
.GetID());
586 unsigned int pos2
= wxPtrToUInt(item2
.GetID());
594 void wxDataViewVirtualListModel::GetValue( wxVariant
&variant
,
595 const wxDataViewItem
&item
, unsigned int col
) const
597 GetValueByRow( variant
, GetRow(item
), col
);
600 bool wxDataViewVirtualListModel::SetValue( const wxVariant
&variant
,
601 const wxDataViewItem
&item
, unsigned int col
)
603 return SetValueByRow( variant
, GetRow(item
), col
);
606 bool wxDataViewVirtualListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
608 return GetAttrByRow( GetRow(item
), col
, attr
);
611 wxDataViewItem
wxDataViewVirtualListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
613 return wxDataViewItem(0);
616 bool wxDataViewVirtualListModel::IsContainer( const wxDataViewItem
&item
) const
618 // only the invisible root item has children
625 unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem
&WXUNUSED(item
), wxDataViewItemArray
&WXUNUSED(children
) ) const
627 return 0; // should we report an error ?
632 //-----------------------------------------------------------------------------
633 // wxDataViewIconText
634 //-----------------------------------------------------------------------------
636 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
638 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
640 bool operator == (const wxDataViewIconText
&one
, const wxDataViewIconText
&two
)
642 if (one
.GetText() != two
.GetText()) return false;
643 if (one
.IsSameAs(two
)) return false;
647 // ---------------------------------------------------------
648 // wxDataViewRendererBase
649 // ---------------------------------------------------------
651 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
653 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
654 wxDataViewCellMode
WXUNUSED(mode
),
655 int WXUNUSED(align
) )
657 m_variantType
= varianttype
;
661 wxDataViewRendererBase::~wxDataViewRendererBase()
665 const wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
667 return const_cast<wxDataViewRendererBase
*>(this)->GetOwner()->GetOwner();
670 class wxKillRef
: public wxWindowRef
673 wxKillRef( wxWindow
*win
) : wxWindowRef( win
) { }
674 virtual void OnObjectDestroy()
676 get()->PopEventHandler( true );
682 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
684 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
686 // Before doing anything we send an event asking if editing of this item is really wanted.
687 wxDataViewEvent
start_event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv_ctrl
->GetId() );
688 start_event
.SetDataViewColumn( GetOwner() );
689 start_event
.SetModel( dv_ctrl
->GetModel() );
690 start_event
.SetItem( item
);
691 start_event
.SetEventObject( dv_ctrl
);
692 dv_ctrl
->GetEventHandler()->ProcessEvent( start_event
);
693 if( !start_event
.IsAllowed() )
696 m_item
= item
; // remember for later
698 unsigned int col
= GetOwner()->GetModelColumn();
700 dv_ctrl
->GetModel()->GetValue( value
, item
, col
);
702 m_editorCtrl
= CreateEditorCtrl( dv_ctrl
->GetMainWindow(), labelRect
, value
);
704 // there might be no editor control for the given item
708 (void) new wxKillRef( m_editorCtrl
.get() );
710 wxDataViewEditorCtrlEvtHandler
*handler
=
711 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
713 m_editorCtrl
->PushEventHandler( handler
);
715 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
716 handler
->SetFocusOnIdle();
718 m_editorCtrl
->SetFocus();
721 // Now we should send Editing Started event
722 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv_ctrl
->GetId() );
723 event
.SetDataViewColumn( GetOwner() );
724 event
.SetModel( dv_ctrl
->GetModel() );
725 event
.SetItem( item
);
726 event
.SetEventObject( dv_ctrl
);
727 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
732 void wxDataViewRendererBase::CancelEditing()
737 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
739 m_editorCtrl
->Hide();
740 wxPendingDelete
.Append( m_editorCtrl
);
743 bool wxDataViewRendererBase::FinishEditing()
749 GetValueFromEditorCtrl( m_editorCtrl
, value
);
751 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
753 dv_ctrl
->GetMainWindow()->SetFocus();
755 m_editorCtrl
->Hide();
756 wxPendingDelete
.Append( m_editorCtrl
);
758 if (!Validate(value
))
761 unsigned int col
= GetOwner()->GetModelColumn();
762 dv_ctrl
->GetModel()->SetValue( value
, m_item
, col
);
763 dv_ctrl
->GetModel()->ValueChanged( m_item
, col
);
765 // Now we should send Editing Done event
766 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv_ctrl
->GetId() );
767 event
.SetDataViewColumn( GetOwner() );
768 event
.SetModel( dv_ctrl
->GetModel() );
769 event
.SetItem( m_item
);
770 event
.SetEventObject( dv_ctrl
);
771 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
776 //-----------------------------------------------------------------------------
777 // wxDataViewEditorCtrlEvtHandler
778 //-----------------------------------------------------------------------------
780 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
781 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
782 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
783 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
784 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
787 wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
788 wxControl
*editorCtrl
,
789 wxDataViewRenderer
*owner
)
792 m_editorCtrl
= editorCtrl
;
797 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
801 m_focusOnIdle
= false;
802 if (wxWindow::FindFocus() != m_editorCtrl
)
803 m_editorCtrl
->SetFocus();
809 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
812 m_owner
->FinishEditing();
815 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
817 switch ( event
.m_keyCode
)
821 m_owner
->FinishEditing();
827 m_owner
->CancelEditing();
835 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
840 m_owner
->FinishEditing();
846 // ---------------------------------------------------------
847 // wxDataViewColumnBase
848 // ---------------------------------------------------------
850 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
851 unsigned int model_column
)
853 m_renderer
= renderer
;
854 m_model_column
= model_column
;
856 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
859 wxDataViewColumnBase::~wxDataViewColumnBase()
864 // ---------------------------------------------------------
865 // wxDataViewCtrlBase
866 // ---------------------------------------------------------
868 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
870 wxDataViewCtrlBase::wxDataViewCtrlBase()
873 m_expander_column
= 0;
877 wxDataViewCtrlBase::~wxDataViewCtrlBase()
886 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
890 m_model
->DecRef(); // discard old model, if any
893 // add our own reference to the new model:
903 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
908 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
913 void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem
& item
)
915 if (!m_model
) return;
917 if (!item
.IsOk()) return;
919 wxVector
<wxDataViewItem
> parentChain
;
921 // at first we get all the parents of the selected item
922 wxDataViewItem parent
= m_model
->GetParent(item
);
923 while (parent
.IsOk())
925 parentChain
.push_back(parent
);
926 parent
= m_model
->GetParent(parent
);
929 // then we expand the parents, starting at the root
930 while (!parentChain
.empty())
932 Expand(parentChain
.back());
933 parentChain
.pop_back();
938 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
939 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
941 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
942 new wxDataViewTextRenderer( wxT("string"), mode
),
943 model_column
, width
, align
, flags
);
949 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
950 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
952 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
953 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
954 model_column
, width
, align
, flags
);
960 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
961 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
963 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
964 new wxDataViewToggleRenderer( wxT("bool"), mode
),
965 model_column
, width
, align
, flags
);
971 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
972 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
974 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
975 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
976 model_column
, width
, align
, flags
);
982 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
983 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
985 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
986 new wxDataViewDateRenderer( wxT("datetime"), mode
),
987 model_column
, width
, align
, flags
);
993 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
994 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
996 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
997 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
998 model_column
, width
, align
, flags
);
1004 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1005 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1007 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1008 new wxDataViewTextRenderer( wxT("string"), mode
),
1009 model_column
, width
, align
, flags
);
1010 AppendColumn( ret
);
1015 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1016 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1018 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1019 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1020 model_column
, width
, align
, flags
);
1021 AppendColumn( ret
);
1026 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1027 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1029 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1030 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1031 model_column
, width
, align
, flags
);
1032 AppendColumn( ret
);
1037 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1038 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1040 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1041 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1042 model_column
, width
, align
, flags
);
1043 AppendColumn( ret
);
1048 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1049 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1051 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1052 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1053 model_column
, width
, align
, flags
);
1054 AppendColumn( ret
);
1059 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1060 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1062 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1063 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1064 model_column
, width
, align
, flags
);
1065 AppendColumn( ret
);
1070 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1071 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1073 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1074 new wxDataViewTextRenderer( wxT("string"), mode
),
1075 model_column
, width
, align
, flags
);
1076 PrependColumn( ret
);
1081 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1082 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1084 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1085 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1086 model_column
, width
, align
, flags
);
1087 PrependColumn( ret
);
1092 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1093 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1096 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1097 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1098 model_column
, width
, align
, flags
);
1099 PrependColumn( ret
);
1104 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1105 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1107 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1108 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1109 model_column
, width
, align
, flags
);
1110 PrependColumn( ret
);
1115 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1116 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1118 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1119 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1120 model_column
, width
, align
, flags
);
1121 PrependColumn( ret
);
1126 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1127 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1129 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1130 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1131 model_column
, width
, align
, flags
);
1132 PrependColumn( ret
);
1137 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1138 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1140 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1141 new wxDataViewTextRenderer( wxT("string"), mode
),
1142 model_column
, width
, align
, flags
);
1143 PrependColumn( ret
);
1148 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1149 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1151 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1152 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1153 model_column
, width
, align
, flags
);
1154 PrependColumn( ret
);
1159 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1160 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1162 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1163 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1164 model_column
, width
, align
, flags
);
1165 PrependColumn( ret
);
1170 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1171 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1173 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1174 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1175 model_column
, width
, align
, flags
);
1176 PrependColumn( ret
);
1181 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1182 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1184 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1185 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1186 model_column
, width
, align
, flags
);
1187 PrependColumn( ret
);
1192 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1193 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1195 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1196 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1197 model_column
, width
, align
, flags
);
1198 PrependColumn( ret
);
1203 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1205 col
->SetOwner( (wxDataViewCtrl
*) this );
1210 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1212 col
->SetOwner( (wxDataViewCtrl
*) this );
1217 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1219 col
->SetOwner( (wxDataViewCtrl
*) this );
1223 // ---------------------------------------------------------
1225 // ---------------------------------------------------------
1227 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1229 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
);
1231 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
);
1232 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
);
1233 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
);
1234 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
);
1235 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
);
1236 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
);
1237 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, wxDataViewEvent
);
1238 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
);
1239 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
);
1241 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
);
1243 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
);
1244 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
);
1245 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
);
1246 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
);
1248 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
);
1249 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, wxDataViewEvent
);
1250 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, wxDataViewEvent
);
1252 // -------------------------------------
1253 // wxDataViewSpinRenderer
1254 // -------------------------------------
1256 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1257 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1263 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1266 wxSize size
= labelRect
.GetSize();
1268 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1271 str
.Printf( wxT("%d"), (int) l
);
1272 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1273 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1275 size
= sc
->GetSize();
1276 wxPoint pt
= sc
->GetPosition();
1277 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1283 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1285 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1286 long l
= sc
->GetValue();
1291 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1294 str
.Printf(wxT("%d"), (int) m_data
);
1295 RenderText( str
, 0, rect
, dc
, state
);
1299 wxSize
wxDataViewSpinRenderer::GetSize() const
1301 return wxSize(80,16);
1304 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1306 m_data
= value
.GetLong();
1310 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1316 // -------------------------------------
1317 // wxDataViewChoiceRenderer
1318 // -------------------------------------
1320 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
1322 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1323 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1325 m_choices
= choices
;
1328 wxControl
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1331 wxSize size
= labelRect
.GetSize();
1333 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1335 wxChoice
*c
= new wxChoice( parent
, wxID_ANY
, labelRect
.GetTopLeft(), size
, m_choices
);
1336 c
->SetStringSelection( value
.GetString() );
1341 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1343 wxChoice
*c
= (wxChoice
*) editor
;
1344 wxString s
= c
->GetStringSelection();
1349 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1351 RenderText( m_data
, 0, rect
, dc
, state
);
1355 wxSize
wxDataViewChoiceRenderer::GetSize() const
1357 return wxSize(80,16);
1360 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1362 m_data
= value
.GetString();
1366 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1374 //-----------------------------------------------------------------------------
1375 // wxDataViewListStore
1376 //-----------------------------------------------------------------------------
1378 wxDataViewListStore::wxDataViewListStore()
1382 wxDataViewListStore::~wxDataViewListStore()
1384 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1385 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1387 wxDataViewListStoreLine
* line
= *it
;
1392 void wxDataViewListStore::PrependColumn( const wxString
&varianttype
)
1394 m_cols
.Insert( varianttype
, 0 );
1397 void wxDataViewListStore::InsertColumn( unsigned int pos
, const wxString
&varianttype
)
1399 m_cols
.Insert( varianttype
, pos
);
1402 void wxDataViewListStore::AppendColumn( const wxString
&varianttype
)
1404 m_cols
.Add( varianttype
);
1407 unsigned int wxDataViewListStore::GetColumnCount() const
1409 return m_cols
.GetCount();
1412 wxString
wxDataViewListStore::GetColumnType( unsigned int pos
) const
1417 void wxDataViewListStore::AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1419 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1420 line
->m_values
= values
;
1421 m_data
.push_back( line
);
1426 void wxDataViewListStore::PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1428 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1429 line
->m_values
= values
;
1430 m_data
.insert( m_data
.begin(), line
);
1435 void wxDataViewListStore::InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
,
1436 wxClientData
*data
)
1438 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1439 line
->m_values
= values
;
1440 m_data
.insert( m_data
.begin()+row
, line
);
1445 void wxDataViewListStore::DeleteItem( unsigned int row
)
1447 wxVector
<wxDataViewListStoreLine
*>::iterator it
= m_data
.begin() + row
;
1453 void wxDataViewListStore::DeleteAllItems()
1455 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1456 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1458 wxDataViewListStoreLine
* line
= *it
;
1467 void wxDataViewListStore::GetValueByRow( wxVariant
&value
, unsigned int row
, unsigned int col
) const
1469 wxDataViewListStoreLine
*line
= m_data
[row
];
1470 value
= line
->m_values
[col
];
1473 bool wxDataViewListStore::SetValueByRow( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1475 wxDataViewListStoreLine
*line
= m_data
[row
];
1476 line
->m_values
[col
] = value
;
1481 //-----------------------------------------------------------------------------
1482 // wxDataViewListCtrl
1483 //-----------------------------------------------------------------------------
1485 IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl
,wxDataViewCtrl
)
1487 BEGIN_EVENT_TABLE(wxDataViewListCtrl
,wxDataViewCtrl
)
1488 EVT_SIZE( wxDataViewListCtrl::OnSize
)
1491 wxDataViewListCtrl::wxDataViewListCtrl()
1495 wxDataViewListCtrl::wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
1496 const wxPoint
& pos
, const wxSize
& size
, long style
,
1497 const wxValidator
& validator
)
1499 Create( parent
, id
, pos
, size
, style
, validator
);
1501 wxDataViewListStore
*store
= new wxDataViewListStore
;
1502 AssociateModel( store
);
1506 wxDataViewListCtrl::~wxDataViewListCtrl()
1511 bool wxDataViewListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1512 const wxPoint
& pos
, const wxSize
& size
, long style
,
1513 const wxValidator
& validator
)
1515 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
1518 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1520 GetStore()->AppendColumn( varianttype
);
1521 return wxDataViewCtrl::AppendColumn( column
);
1524 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1526 GetStore()->PrependColumn( varianttype
);
1527 return wxDataViewCtrl::PrependColumn( column
);
1530 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
)
1532 GetStore()->InsertColumn( pos
, varianttype
);
1533 return wxDataViewCtrl::InsertColumn( pos
, column
);
1536 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*col
)
1538 return PrependColumn( col
, "string" );
1541 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
1543 return InsertColumn( pos
, col
, "string" );
1546 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*col
)
1548 return AppendColumn( col
, "string" );
1551 wxDataViewColumn
*wxDataViewListCtrl::AppendTextColumn( const wxString
&label
,
1552 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1554 GetStore()->AppendColumn( wxT("string") );
1556 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1557 new wxDataViewTextRenderer( wxT("string"), mode
),
1558 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1560 wxDataViewCtrl::AppendColumn( ret
);
1565 wxDataViewColumn
*wxDataViewListCtrl::AppendToggleColumn( const wxString
&label
,
1566 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1568 GetStore()->AppendColumn( wxT("bool") );
1570 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1571 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1572 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1574 wxDataViewCtrl::AppendColumn( ret
);
1579 wxDataViewColumn
*wxDataViewListCtrl::AppendProgressColumn( const wxString
&label
,
1580 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1582 GetStore()->AppendColumn( wxT("long") );
1584 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1585 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1586 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1588 wxDataViewCtrl::AppendColumn( ret
);
1593 wxDataViewColumn
*wxDataViewListCtrl::AppendIconTextColumn( const wxString
&label
,
1594 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1596 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
1598 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1599 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1600 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1602 wxDataViewCtrl::AppendColumn( ret
);
1607 void wxDataViewListCtrl::OnSize( wxSizeEvent
&event
)
1612 //-----------------------------------------------------------------------------
1613 // wxDataViewTreeStore
1614 //-----------------------------------------------------------------------------
1616 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1617 wxDataViewTreeStoreNode
*parent
,
1618 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1626 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1632 #include "wx/listimpl.cpp"
1633 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1635 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1636 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1637 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1638 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1640 m_iconExpanded
= expanded
;
1641 m_isExpanded
= false;
1642 m_children
.DeleteContents(true);
1645 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1649 //-----------------------------------------------------------------------------
1651 wxDataViewTreeStore::wxDataViewTreeStore()
1653 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1656 wxDataViewTreeStore::~wxDataViewTreeStore()
1661 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1662 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1664 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1665 if (!parent_node
) return wxDataViewItem(0);
1667 wxDataViewTreeStoreNode
*node
=
1668 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1669 parent_node
->GetChildren().Append( node
);
1671 return node
->GetItem();
1674 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1675 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1677 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1678 if (!parent_node
) return wxDataViewItem(0);
1680 wxDataViewTreeStoreNode
*node
=
1681 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1682 parent_node
->GetChildren().Insert( node
);
1684 return node
->GetItem();
1688 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& parent
,
1689 const wxDataViewItem
& previous
,
1690 const wxString
& text
,
1694 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1695 if (!parent_node
) return wxDataViewItem(0);
1697 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1698 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1699 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1701 wxDataViewTreeStoreNode
*node
=
1702 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1703 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1705 return node
->GetItem();
1708 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1709 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1710 wxClientData
*data
)
1712 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1713 if (!parent_node
) return wxDataViewItem(0);
1715 wxDataViewTreeStoreContainerNode
*node
=
1716 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1717 parent_node
->GetChildren().Insert( node
);
1719 return node
->GetItem();
1723 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1724 const wxString
&text
,
1726 const wxIcon
& expanded
,
1727 wxClientData
* data
)
1729 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1730 if (!parent_node
) return wxDataViewItem(0);
1732 wxDataViewTreeStoreContainerNode
*node
=
1733 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1734 parent_node
->GetChildren().Append( node
);
1736 return node
->GetItem();
1740 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& parent
,
1741 const wxDataViewItem
& previous
,
1742 const wxString
& text
,
1744 const wxIcon
& expanded
,
1745 wxClientData
* data
)
1747 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1748 if (!parent_node
) return wxDataViewItem(0);
1750 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1751 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1752 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1754 wxDataViewTreeStoreContainerNode
*node
=
1755 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1756 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1758 return node
->GetItem();
1761 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1763 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1764 if (!parent_node
) return wxDataViewItem(0);
1766 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1768 return node
->GetData();
1770 return wxDataViewItem(0);
1773 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1775 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1776 if (!node
) return -1;
1778 if (!node
->IsContainer())
1781 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1782 return (int) container_node
->GetChildren().GetCount();
1785 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1787 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1790 node
->SetText( text
);
1793 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1795 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1796 if (!node
) return wxEmptyString
;
1798 return node
->GetText();
1801 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1803 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1806 node
->SetIcon( icon
);
1809 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1811 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1812 if (!node
) return wxNullIcon
;
1814 return node
->GetIcon();
1817 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1819 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1822 node
->SetExpandedIcon( icon
);
1825 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1827 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1828 if (!node
) return wxNullIcon
;
1830 return node
->GetExpandedIcon();
1833 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1835 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1838 node
->SetData( data
);
1841 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
1843 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1844 if (!node
) return NULL
;
1846 return node
->GetData();
1849 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
1851 if (!item
.IsOk()) return;
1853 wxDataViewItem parent_item
= GetParent( item
);
1855 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
1856 if (!parent_node
) return;
1858 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1861 parent_node
->GetChildren().DeleteObject( node
);
1864 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
1866 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1869 node
->GetChildren().clear();
1872 void wxDataViewTreeStore::DeleteAllItems()
1878 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
1879 const wxDataViewItem
&item
,
1880 unsigned int WXUNUSED(col
)) const
1882 // if (col != 0) return;
1884 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1887 wxIcon
icon( node
->GetIcon());
1888 if (node
->IsContainer())
1890 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
1891 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
1892 icon
= container
->GetExpandedIcon();
1895 wxDataViewIconText
data( node
->GetText(), icon
);
1901 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
1902 const wxDataViewItem
& item
,
1903 unsigned int WXUNUSED(col
))
1905 // if (col != 0) return false;
1907 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1908 if (!node
) return false;
1910 wxDataViewIconText data
;
1914 node
->SetText( data
.GetText() );
1915 node
->SetIcon( data
.GetIcon() );
1920 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
1922 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1923 if (!node
) return wxDataViewItem(0);
1925 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
1926 if (!parent
) return wxDataViewItem(0);
1928 if (parent
== m_root
)
1929 return wxDataViewItem(0);
1931 return parent
->GetItem();
1934 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
&item
) const
1936 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1937 if (!node
) return false;
1939 return node
->IsContainer();
1942 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
1944 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1945 if (!node
) return 0;
1947 wxDataViewTreeStoreNodeList::iterator iter
;
1948 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1950 wxDataViewTreeStoreNode
* child
= *iter
;
1951 children
.Add( child
->GetItem() );
1954 return node
->GetChildren().GetCount();
1957 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
1958 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) ) const
1960 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
1961 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
1963 if (!node1
|| !node2
)
1966 wxDataViewTreeStoreContainerNode
* parent1
=
1967 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
1968 wxDataViewTreeStoreContainerNode
* parent2
=
1969 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
1971 if (parent1
!= parent2
)
1973 wxLogError( wxT("Comparing items with different parent.") );
1977 if (node1
->IsContainer() && !!node2
->IsContainer())
1980 if (node2
->IsContainer() && !!node1
->IsContainer())
1983 return parent1
->GetChildren().IndexOf( node1
) - parent1
->GetChildren().IndexOf( node2
);
1986 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
1991 return (wxDataViewTreeStoreNode
*) item
.GetID();
1994 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
1997 return (wxDataViewTreeStoreContainerNode
*) m_root
;
1999 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
2001 if (!node
->IsContainer())
2004 return (wxDataViewTreeStoreContainerNode
*) node
;
2007 //-----------------------------------------------------------------------------
2008 // wxDataViewTreeCtrl
2009 //-----------------------------------------------------------------------------
2011 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2013 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2014 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
2015 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
2016 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
2019 wxDataViewTreeCtrl::wxDataViewTreeCtrl()
2024 wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow
*parent
, wxWindowID id
,
2025 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2028 Create( parent
, id
, pos
, size
, style
, validator
);
2030 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
2031 AssociateModel( store
);
2034 AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT
,-1);
2037 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
2043 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2044 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2046 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
2049 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
2054 m_imageList
= imagelist
;
2057 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
2058 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2060 wxIcon icon
= wxNullIcon
;
2061 if (m_imageList
&& (iconIndex
!= -1))
2062 icon
= m_imageList
->GetIcon( iconIndex
);
2064 wxDataViewItem res
= GetStore()->AppendItem( parent
, text
, icon
, data
);
2066 GetStore()->ItemAdded( parent
, res
);
2071 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
2072 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2074 wxIcon icon
= wxNullIcon
;
2075 if (m_imageList
&& (iconIndex
!= -1))
2076 icon
= m_imageList
->GetIcon( iconIndex
);
2078 wxDataViewItem res
= GetStore()->PrependItem( parent
, text
, icon
, data
);
2080 GetStore()->ItemAdded( parent
, res
);
2085 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2086 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2088 wxIcon icon
= wxNullIcon
;
2089 if (m_imageList
&& (iconIndex
!= -1))
2090 icon
= m_imageList
->GetIcon( iconIndex
);
2092 wxDataViewItem res
= GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
2094 GetStore()->ItemAdded( parent
, res
);
2099 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
2100 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2102 wxIcon icon
= wxNullIcon
;
2103 if (m_imageList
&& (iconIndex
!= -1))
2104 icon
= m_imageList
->GetIcon( iconIndex
);
2106 wxIcon expanded
= wxNullIcon
;
2107 if (m_imageList
&& (expandedIndex
!= -1))
2108 expanded
= m_imageList
->GetIcon( expandedIndex
);
2110 wxDataViewItem res
= GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
2112 GetStore()->ItemAdded( parent
, res
);
2117 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
2118 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2120 wxIcon icon
= wxNullIcon
;
2121 if (m_imageList
&& (iconIndex
!= -1))
2122 icon
= m_imageList
->GetIcon( iconIndex
);
2124 wxIcon expanded
= wxNullIcon
;
2125 if (m_imageList
&& (expandedIndex
!= -1))
2126 expanded
= m_imageList
->GetIcon( expandedIndex
);
2128 wxDataViewItem res
= GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
2130 GetStore()->ItemAdded( parent
, res
);
2135 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2136 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2138 wxIcon icon
= wxNullIcon
;
2139 if (m_imageList
&& (iconIndex
!= -1))
2140 icon
= m_imageList
->GetIcon( iconIndex
);
2142 wxIcon expanded
= wxNullIcon
;
2143 if (m_imageList
&& (expandedIndex
!= -1))
2144 expanded
= m_imageList
->GetIcon( expandedIndex
);
2146 wxDataViewItem res
= GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
2148 GetStore()->ItemAdded( parent
, res
);
2153 void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2155 GetStore()->SetItemText(item
,text
);
2158 GetStore()->ValueChanged( item
, 0 );
2161 void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2163 GetStore()->SetItemIcon(item
,icon
);
2166 GetStore()->ValueChanged( item
, 0 );
2169 void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2171 GetStore()->SetItemExpandedIcon(item
,icon
);
2174 GetStore()->ValueChanged( item
, 0 );
2177 void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem
& item
)
2179 wxDataViewItem parent_item
= GetStore()->GetParent( item
);
2181 GetStore()->DeleteItem(item
);
2184 GetStore()->ItemDeleted( parent_item
, item
);
2187 void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem
& item
)
2189 wxDataViewTreeStoreContainerNode
*node
= GetStore()->FindContainerNode( item
);
2192 wxDataViewItemArray array
;
2193 wxDataViewTreeStoreNodeList::iterator iter
;
2194 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2196 wxDataViewTreeStoreNode
* child
= *iter
;
2197 array
.Add( child
->GetItem() );
2200 GetStore()->DeleteChildren( item
);
2203 GetStore()->ItemsDeleted( item
, array
);
2206 void wxDataViewTreeCtrl::DeleteAllItems()
2208 GetStore()->DeleteAllItems();
2210 GetStore()->Cleared();
2213 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
2215 if (m_imageList
) return;
2217 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2218 if (!container
) return;
2220 container
->SetExpanded( true );
2222 GetStore()->ItemChanged( event
.GetItem() );
2225 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
2227 if (m_imageList
) return;
2229 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2230 if (!container
) return;
2232 container
->SetExpanded( false );
2234 GetStore()->ItemChanged( event
.GetItem() );
2237 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
2239 #if defined(wxUSE_GENERICDATAVIEWCTRL)
2240 // automatically resize our only column to take the entire control width
2241 if ( GetColumnCount() )
2243 wxSize size
= GetClientSize();
2244 GetColumn(0)->SetWidth(size
.x
);
2250 #endif // wxUSE_DATAVIEWCTRL