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_nextFreeID
= 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
) );
331 m_nextFreeID
= new_size
+ 1;
333 wxDataViewModel::Cleared();
336 void wxDataViewIndexListModel::RowPrepended()
340 unsigned int id
= m_nextFreeID
;
343 m_hash
.Insert( wxUIntToPtr(id
), 0 );
344 wxDataViewItem
item( wxUIntToPtr(id
) );
345 ItemAdded( wxDataViewItem(0), item
);
349 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
353 unsigned int id
= m_nextFreeID
;
356 m_hash
.Insert( wxUIntToPtr(id
), before
);
357 wxDataViewItem
item( wxUIntToPtr(id
) );
358 ItemAdded( wxDataViewItem(0), item
);
361 void wxDataViewIndexListModel::RowAppended()
363 unsigned int id
= m_nextFreeID
;
366 m_hash
.Add( wxUIntToPtr(id
) );
367 wxDataViewItem
item( wxUIntToPtr(id
) );
368 ItemAdded( wxDataViewItem(0), item
);
371 void wxDataViewIndexListModel::RowDeleted( unsigned int row
)
375 wxDataViewItem
item( m_hash
[row
] );
376 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
377 m_hash
.RemoveAt( row
);
380 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt
&rows
)
382 wxArrayInt sorted
= rows
;
383 sorted
.Sort( my_sort
);
387 wxDataViewItemArray array
;
389 for (i
= 0; i
< rows
.GetCount(); i
++)
391 wxDataViewItem
item( m_hash
[rows
[i
]] );
394 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
396 for (i
= 0; i
< sorted
.GetCount(); i
++)
397 m_hash
.RemoveAt( sorted
[i
] );
400 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
402 wxDataViewModel::ItemChanged( GetItem(row
) );
405 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
407 wxDataViewModel::ValueChanged( GetItem(row
), col
);
410 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
413 return wxPtrToUInt(item
.GetID())-1;
415 // assert for not found
416 return (unsigned int) m_hash
.Index( item
.GetID() );
419 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
421 wxASSERT( row
< m_hash
.GetCount() );
422 return wxDataViewItem( m_hash
[row
] );
425 bool wxDataViewIndexListModel::HasDefaultCompare() const
430 int wxDataViewIndexListModel::Compare(const wxDataViewItem
& item1
,
431 const wxDataViewItem
& item2
,
432 unsigned int WXUNUSED(column
),
433 bool ascending
) const
437 unsigned int pos1
= wxPtrToUInt(item1
.GetID()); // -1 not needed here
438 unsigned int pos2
= wxPtrToUInt(item2
.GetID()); // -1 not needed here
447 return GetRow(item1
) - GetRow(item2
);
449 return GetRow(item2
) - GetRow(item1
);
452 void wxDataViewIndexListModel::GetValue( wxVariant
&variant
,
453 const wxDataViewItem
&item
, unsigned int col
) const
455 GetValueByRow( variant
, GetRow(item
), col
);
458 bool wxDataViewIndexListModel::SetValue( const wxVariant
&variant
,
459 const wxDataViewItem
&item
, unsigned int col
)
461 return SetValueByRow( variant
, GetRow(item
), col
);
464 bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
466 return GetAttrByRow( GetRow(item
), col
, attr
);
469 wxDataViewItem
wxDataViewIndexListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
471 return wxDataViewItem(0);
474 bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem
&item
) const
476 // only the invisible root item has children
483 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
490 return m_hash
.GetCount();
493 // ---------------------------------------------------------
494 // wxDataViewVirtualListModel
495 // ---------------------------------------------------------
499 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size
)
501 m_size
= initial_size
;
504 wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
508 void wxDataViewVirtualListModel::Reset( unsigned int new_size
)
512 wxDataViewModel::Cleared();
515 void wxDataViewVirtualListModel::RowPrepended()
518 wxDataViewItem
item( wxUIntToPtr(1) );
519 ItemAdded( wxDataViewItem(0), item
);
522 void wxDataViewVirtualListModel::RowInserted( unsigned int before
)
525 wxDataViewItem
item( wxUIntToPtr(before
+1) );
526 ItemAdded( wxDataViewItem(0), item
);
529 void wxDataViewVirtualListModel::RowAppended()
532 wxDataViewItem
item( wxUIntToPtr(m_size
) );
533 ItemAdded( wxDataViewItem(0), item
);
536 void wxDataViewVirtualListModel::RowDeleted( unsigned int row
)
539 wxDataViewItem
item( wxUIntToPtr(row
+1) );
540 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
543 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt
&rows
)
545 m_size
-= rows
.GetCount();
547 wxArrayInt sorted
= rows
;
548 sorted
.Sort( my_sort
);
550 wxDataViewItemArray array
;
552 for (i
= 0; i
< sorted
.GetCount(); i
++)
554 wxDataViewItem
item( wxUIntToPtr(sorted
[i
]+1) );
557 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
560 void wxDataViewVirtualListModel::RowChanged( unsigned int row
)
562 wxDataViewModel::ItemChanged( GetItem(row
) );
565 void wxDataViewVirtualListModel::RowValueChanged( unsigned int row
, unsigned int col
)
567 wxDataViewModel::ValueChanged( GetItem(row
), col
);
570 unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem
&item
) const
572 return wxPtrToUInt( item
.GetID() ) -1;
575 wxDataViewItem
wxDataViewVirtualListModel::GetItem( unsigned int row
) const
577 return wxDataViewItem( wxUIntToPtr(row
+1) );
580 bool wxDataViewVirtualListModel::HasDefaultCompare() const
585 int wxDataViewVirtualListModel::Compare(const wxDataViewItem
& item1
,
586 const wxDataViewItem
& item2
,
587 unsigned int WXUNUSED(column
),
588 bool ascending
) const
590 unsigned int pos1
= wxPtrToUInt(item1
.GetID()); // -1 not needed here
591 unsigned int pos2
= wxPtrToUInt(item2
.GetID()); // -1 not needed here
599 void wxDataViewVirtualListModel::GetValue( wxVariant
&variant
,
600 const wxDataViewItem
&item
, unsigned int col
) const
602 GetValueByRow( variant
, GetRow(item
), col
);
605 bool wxDataViewVirtualListModel::SetValue( const wxVariant
&variant
,
606 const wxDataViewItem
&item
, unsigned int col
)
608 return SetValueByRow( variant
, GetRow(item
), col
);
611 bool wxDataViewVirtualListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
613 return GetAttrByRow( GetRow(item
), col
, attr
);
616 wxDataViewItem
wxDataViewVirtualListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
618 return wxDataViewItem(0);
621 bool wxDataViewVirtualListModel::IsContainer( const wxDataViewItem
&item
) const
623 // only the invisible root item has children
630 unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem
&WXUNUSED(item
), wxDataViewItemArray
&WXUNUSED(children
) ) const
632 return 0; // should we report an error ?
637 //-----------------------------------------------------------------------------
638 // wxDataViewIconText
639 //-----------------------------------------------------------------------------
641 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
643 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
645 bool operator == (const wxDataViewIconText
&one
, const wxDataViewIconText
&two
)
647 if (one
.GetText() != two
.GetText()) return false;
648 if (one
.IsSameAs(two
)) return false;
652 // ---------------------------------------------------------
653 // wxDataViewRendererBase
654 // ---------------------------------------------------------
656 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
658 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
659 wxDataViewCellMode
WXUNUSED(mode
),
660 int WXUNUSED(align
) )
662 m_variantType
= varianttype
;
666 wxDataViewRendererBase::~wxDataViewRendererBase()
670 const wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
672 return const_cast<wxDataViewRendererBase
*>(this)->GetOwner()->GetOwner();
675 class wxKillRef
: public wxWindowRef
678 wxKillRef( wxWindow
*win
) : wxWindowRef( win
) { }
679 virtual void OnObjectDestroy()
681 get()->PopEventHandler( true );
687 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
689 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
691 // Before doing anything we send an event asking if editing of this item is really wanted.
692 wxDataViewEvent
start_event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv_ctrl
->GetId() );
693 start_event
.SetDataViewColumn( GetOwner() );
694 start_event
.SetModel( dv_ctrl
->GetModel() );
695 start_event
.SetItem( item
);
696 start_event
.SetEventObject( dv_ctrl
);
697 dv_ctrl
->GetEventHandler()->ProcessEvent( start_event
);
698 if( !start_event
.IsAllowed() )
701 m_item
= item
; // remember for later
703 unsigned int col
= GetOwner()->GetModelColumn();
705 dv_ctrl
->GetModel()->GetValue( value
, item
, col
);
707 m_editorCtrl
= CreateEditorCtrl( dv_ctrl
->GetMainWindow(), labelRect
, value
);
709 // there might be no editor control for the given item
713 (void) new wxKillRef( m_editorCtrl
.get() );
715 wxDataViewEditorCtrlEvtHandler
*handler
=
716 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
718 m_editorCtrl
->PushEventHandler( handler
);
720 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
721 handler
->SetFocusOnIdle();
723 m_editorCtrl
->SetFocus();
726 // Now we should send Editing Started event
727 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv_ctrl
->GetId() );
728 event
.SetDataViewColumn( GetOwner() );
729 event
.SetModel( dv_ctrl
->GetModel() );
730 event
.SetItem( item
);
731 event
.SetEventObject( dv_ctrl
);
732 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
737 void wxDataViewRendererBase::CancelEditing()
742 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
744 m_editorCtrl
->Hide();
745 wxPendingDelete
.Append( m_editorCtrl
);
748 bool wxDataViewRendererBase::FinishEditing()
754 GetValueFromEditorCtrl( m_editorCtrl
, value
);
756 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
758 dv_ctrl
->GetMainWindow()->SetFocus();
760 m_editorCtrl
->Hide();
761 wxPendingDelete
.Append( m_editorCtrl
);
763 if (!Validate(value
))
766 unsigned int col
= GetOwner()->GetModelColumn();
767 dv_ctrl
->GetModel()->SetValue( value
, m_item
, col
);
768 dv_ctrl
->GetModel()->ValueChanged( m_item
, col
);
770 // Now we should send Editing Done event
771 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv_ctrl
->GetId() );
772 event
.SetDataViewColumn( GetOwner() );
773 event
.SetModel( dv_ctrl
->GetModel() );
774 event
.SetItem( m_item
);
775 event
.SetEventObject( dv_ctrl
);
776 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
781 //-----------------------------------------------------------------------------
782 // wxDataViewEditorCtrlEvtHandler
783 //-----------------------------------------------------------------------------
785 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
786 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
787 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
788 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
789 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
792 wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
793 wxControl
*editorCtrl
,
794 wxDataViewRenderer
*owner
)
797 m_editorCtrl
= editorCtrl
;
802 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
806 m_focusOnIdle
= false;
807 if (wxWindow::FindFocus() != m_editorCtrl
)
808 m_editorCtrl
->SetFocus();
814 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
817 m_owner
->FinishEditing();
820 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
822 switch ( event
.m_keyCode
)
826 m_owner
->FinishEditing();
832 m_owner
->CancelEditing();
840 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
845 m_owner
->FinishEditing();
851 // ---------------------------------------------------------
852 // wxDataViewColumnBase
853 // ---------------------------------------------------------
855 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
856 unsigned int model_column
)
858 m_renderer
= renderer
;
859 m_model_column
= model_column
;
861 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
864 wxDataViewColumnBase::~wxDataViewColumnBase()
869 // ---------------------------------------------------------
870 // wxDataViewCtrlBase
871 // ---------------------------------------------------------
873 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
875 wxDataViewCtrlBase::wxDataViewCtrlBase()
878 m_expander_column
= 0;
882 wxDataViewCtrlBase::~wxDataViewCtrlBase()
891 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
895 m_model
->DecRef(); // discard old model, if any
898 // add our own reference to the new model:
908 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
913 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
918 void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem
& item
)
920 if (!m_model
) return;
922 if (!item
.IsOk()) return;
924 wxVector
<wxDataViewItem
> parentChain
;
926 // at first we get all the parents of the selected item
927 wxDataViewItem parent
= m_model
->GetParent(item
);
928 while (parent
.IsOk())
930 parentChain
.push_back(parent
);
931 parent
= m_model
->GetParent(parent
);
934 // then we expand the parents, starting at the root
935 while (!parentChain
.empty())
937 Expand(parentChain
.back());
938 parentChain
.pop_back();
943 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
944 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
946 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
947 new wxDataViewTextRenderer( wxT("string"), mode
),
948 model_column
, width
, align
, flags
);
954 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
955 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
957 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
958 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
959 model_column
, width
, align
, flags
);
965 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
966 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
968 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
969 new wxDataViewToggleRenderer( wxT("bool"), mode
),
970 model_column
, width
, align
, flags
);
976 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
977 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
979 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
980 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
981 model_column
, width
, align
, flags
);
987 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
988 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
990 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
991 new wxDataViewDateRenderer( wxT("datetime"), mode
),
992 model_column
, width
, align
, flags
);
998 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
999 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1001 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1002 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1003 model_column
, width
, align
, flags
);
1004 AppendColumn( ret
);
1009 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1010 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1012 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1013 new wxDataViewTextRenderer( wxT("string"), mode
),
1014 model_column
, width
, align
, flags
);
1015 AppendColumn( ret
);
1020 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1021 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1023 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1024 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1025 model_column
, width
, align
, flags
);
1026 AppendColumn( ret
);
1031 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1032 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1034 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1035 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1036 model_column
, width
, align
, flags
);
1037 AppendColumn( ret
);
1042 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1043 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1045 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1046 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1047 model_column
, width
, align
, flags
);
1048 AppendColumn( ret
);
1053 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1054 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1056 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1057 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1058 model_column
, width
, align
, flags
);
1059 AppendColumn( ret
);
1064 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1065 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1067 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1068 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1069 model_column
, width
, align
, flags
);
1070 AppendColumn( ret
);
1075 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1076 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1078 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1079 new wxDataViewTextRenderer( wxT("string"), mode
),
1080 model_column
, width
, align
, flags
);
1081 PrependColumn( ret
);
1086 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1087 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1089 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1090 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1091 model_column
, width
, align
, flags
);
1092 PrependColumn( ret
);
1097 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1098 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1101 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1102 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1103 model_column
, width
, align
, flags
);
1104 PrependColumn( ret
);
1109 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1110 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1112 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1113 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1114 model_column
, width
, align
, flags
);
1115 PrependColumn( ret
);
1120 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1121 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1123 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1124 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1125 model_column
, width
, align
, flags
);
1126 PrependColumn( ret
);
1131 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1132 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1134 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1135 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1136 model_column
, width
, align
, flags
);
1137 PrependColumn( ret
);
1142 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1143 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1145 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1146 new wxDataViewTextRenderer( wxT("string"), mode
),
1147 model_column
, width
, align
, flags
);
1148 PrependColumn( ret
);
1153 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1154 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1156 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1157 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1158 model_column
, width
, align
, flags
);
1159 PrependColumn( ret
);
1164 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1165 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1167 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1168 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1169 model_column
, width
, align
, flags
);
1170 PrependColumn( ret
);
1175 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1176 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1178 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1179 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1180 model_column
, width
, align
, flags
);
1181 PrependColumn( ret
);
1186 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1187 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1189 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1190 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1191 model_column
, width
, align
, flags
);
1192 PrependColumn( ret
);
1197 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1198 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1200 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1201 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1202 model_column
, width
, align
, flags
);
1203 PrependColumn( ret
);
1208 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1210 col
->SetOwner( (wxDataViewCtrl
*) this );
1215 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1217 col
->SetOwner( (wxDataViewCtrl
*) this );
1222 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1224 col
->SetOwner( (wxDataViewCtrl
*) this );
1228 // ---------------------------------------------------------
1230 // ---------------------------------------------------------
1232 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1234 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
);
1236 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
);
1237 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
);
1238 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
);
1239 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
);
1240 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
);
1241 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
);
1242 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, wxDataViewEvent
);
1243 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
);
1244 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
);
1246 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
);
1248 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
);
1249 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
);
1250 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
);
1251 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
);
1253 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, wxDataViewEvent
);
1255 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
);
1256 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, wxDataViewEvent
);
1257 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, wxDataViewEvent
);
1261 // -------------------------------------
1262 // wxDataViewSpinRenderer
1263 // -------------------------------------
1265 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1266 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1272 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1275 wxSize size
= labelRect
.GetSize();
1277 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1280 str
.Printf( wxT("%d"), (int) l
);
1281 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1282 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1284 size
= sc
->GetSize();
1285 wxPoint pt
= sc
->GetPosition();
1286 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1292 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1294 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1295 long l
= sc
->GetValue();
1300 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1303 str
.Printf(wxT("%d"), (int) m_data
);
1304 RenderText( str
, 0, rect
, dc
, state
);
1308 wxSize
wxDataViewSpinRenderer::GetSize() const
1310 return wxSize(80,16);
1313 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1315 m_data
= value
.GetLong();
1319 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1325 // -------------------------------------
1326 // wxDataViewChoiceRenderer
1327 // -------------------------------------
1329 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
1331 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1332 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1334 m_choices
= choices
;
1337 wxControl
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1340 wxSize size
= labelRect
.GetSize();
1342 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1344 wxChoice
*c
= new wxChoice( parent
, wxID_ANY
, labelRect
.GetTopLeft(), size
, m_choices
);
1345 c
->SetStringSelection( value
.GetString() );
1350 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1352 wxChoice
*c
= (wxChoice
*) editor
;
1353 wxString s
= c
->GetStringSelection();
1358 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1360 RenderText( m_data
, 0, rect
, dc
, state
);
1364 wxSize
wxDataViewChoiceRenderer::GetSize() const
1366 return wxSize(80,16);
1369 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1371 m_data
= value
.GetString();
1375 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1383 //-----------------------------------------------------------------------------
1384 // wxDataViewListStore
1385 //-----------------------------------------------------------------------------
1387 wxDataViewListStore::wxDataViewListStore()
1391 wxDataViewListStore::~wxDataViewListStore()
1393 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1394 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1396 wxDataViewListStoreLine
* line
= *it
;
1401 void wxDataViewListStore::PrependColumn( const wxString
&varianttype
)
1403 m_cols
.Insert( varianttype
, 0 );
1406 void wxDataViewListStore::InsertColumn( unsigned int pos
, const wxString
&varianttype
)
1408 m_cols
.Insert( varianttype
, pos
);
1411 void wxDataViewListStore::AppendColumn( const wxString
&varianttype
)
1413 m_cols
.Add( varianttype
);
1416 unsigned int wxDataViewListStore::GetColumnCount() const
1418 return m_cols
.GetCount();
1421 wxString
wxDataViewListStore::GetColumnType( unsigned int pos
) const
1426 void wxDataViewListStore::AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1428 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1429 line
->m_values
= values
;
1430 m_data
.push_back( line
);
1435 void wxDataViewListStore::PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1437 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1438 line
->m_values
= values
;
1439 m_data
.insert( m_data
.begin(), line
);
1444 void wxDataViewListStore::InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
,
1445 wxClientData
*data
)
1447 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1448 line
->m_values
= values
;
1449 m_data
.insert( m_data
.begin()+row
, line
);
1454 void wxDataViewListStore::DeleteItem( unsigned int row
)
1456 wxVector
<wxDataViewListStoreLine
*>::iterator it
= m_data
.begin() + row
;
1462 void wxDataViewListStore::DeleteAllItems()
1464 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1465 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1467 wxDataViewListStoreLine
* line
= *it
;
1476 void wxDataViewListStore::GetValueByRow( wxVariant
&value
, unsigned int row
, unsigned int col
) const
1478 wxDataViewListStoreLine
*line
= m_data
[row
];
1479 value
= line
->m_values
[col
];
1482 bool wxDataViewListStore::SetValueByRow( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1484 wxDataViewListStoreLine
*line
= m_data
[row
];
1485 line
->m_values
[col
] = value
;
1490 //-----------------------------------------------------------------------------
1491 // wxDataViewListCtrl
1492 //-----------------------------------------------------------------------------
1494 IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl
,wxDataViewCtrl
)
1496 BEGIN_EVENT_TABLE(wxDataViewListCtrl
,wxDataViewCtrl
)
1497 EVT_SIZE( wxDataViewListCtrl::OnSize
)
1500 wxDataViewListCtrl::wxDataViewListCtrl()
1504 wxDataViewListCtrl::wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
1505 const wxPoint
& pos
, const wxSize
& size
, long style
,
1506 const wxValidator
& validator
)
1508 Create( parent
, id
, pos
, size
, style
, validator
);
1510 wxDataViewListStore
*store
= new wxDataViewListStore
;
1511 AssociateModel( store
);
1515 wxDataViewListCtrl::~wxDataViewListCtrl()
1520 bool wxDataViewListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1521 const wxPoint
& pos
, const wxSize
& size
, long style
,
1522 const wxValidator
& validator
)
1524 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
1527 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1529 GetStore()->AppendColumn( varianttype
);
1530 return wxDataViewCtrl::AppendColumn( column
);
1533 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1535 GetStore()->PrependColumn( varianttype
);
1536 return wxDataViewCtrl::PrependColumn( column
);
1539 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
)
1541 GetStore()->InsertColumn( pos
, varianttype
);
1542 return wxDataViewCtrl::InsertColumn( pos
, column
);
1545 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*col
)
1547 return PrependColumn( col
, "string" );
1550 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
1552 return InsertColumn( pos
, col
, "string" );
1555 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*col
)
1557 return AppendColumn( col
, "string" );
1560 wxDataViewColumn
*wxDataViewListCtrl::AppendTextColumn( const wxString
&label
,
1561 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1563 GetStore()->AppendColumn( wxT("string") );
1565 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1566 new wxDataViewTextRenderer( wxT("string"), mode
),
1567 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1569 wxDataViewCtrl::AppendColumn( ret
);
1574 wxDataViewColumn
*wxDataViewListCtrl::AppendToggleColumn( const wxString
&label
,
1575 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1577 GetStore()->AppendColumn( wxT("bool") );
1579 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1580 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1581 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1583 wxDataViewCtrl::AppendColumn( ret
);
1588 wxDataViewColumn
*wxDataViewListCtrl::AppendProgressColumn( const wxString
&label
,
1589 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1591 GetStore()->AppendColumn( wxT("long") );
1593 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1594 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1595 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1597 wxDataViewCtrl::AppendColumn( ret
);
1602 wxDataViewColumn
*wxDataViewListCtrl::AppendIconTextColumn( const wxString
&label
,
1603 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1605 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
1607 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1608 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1609 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1611 wxDataViewCtrl::AppendColumn( ret
);
1616 void wxDataViewListCtrl::OnSize( wxSizeEvent
&event
)
1621 //-----------------------------------------------------------------------------
1622 // wxDataViewTreeStore
1623 //-----------------------------------------------------------------------------
1625 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1626 wxDataViewTreeStoreNode
*parent
,
1627 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1635 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1641 #include "wx/listimpl.cpp"
1642 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1644 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1645 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1646 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1647 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1649 m_iconExpanded
= expanded
;
1650 m_isExpanded
= false;
1651 m_children
.DeleteContents(true);
1654 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1658 //-----------------------------------------------------------------------------
1660 wxDataViewTreeStore::wxDataViewTreeStore()
1662 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1665 wxDataViewTreeStore::~wxDataViewTreeStore()
1670 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1671 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1673 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1674 if (!parent_node
) return wxDataViewItem(0);
1676 wxDataViewTreeStoreNode
*node
=
1677 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1678 parent_node
->GetChildren().Append( node
);
1680 return node
->GetItem();
1683 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1684 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1686 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1687 if (!parent_node
) return wxDataViewItem(0);
1689 wxDataViewTreeStoreNode
*node
=
1690 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1691 parent_node
->GetChildren().Insert( node
);
1693 return node
->GetItem();
1697 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& parent
,
1698 const wxDataViewItem
& previous
,
1699 const wxString
& text
,
1703 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1704 if (!parent_node
) return wxDataViewItem(0);
1706 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1707 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1708 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1710 wxDataViewTreeStoreNode
*node
=
1711 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1712 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1714 return node
->GetItem();
1717 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1718 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1719 wxClientData
*data
)
1721 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1722 if (!parent_node
) return wxDataViewItem(0);
1724 wxDataViewTreeStoreContainerNode
*node
=
1725 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1726 parent_node
->GetChildren().Insert( node
);
1728 return node
->GetItem();
1732 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1733 const wxString
&text
,
1735 const wxIcon
& expanded
,
1736 wxClientData
* data
)
1738 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1739 if (!parent_node
) return wxDataViewItem(0);
1741 wxDataViewTreeStoreContainerNode
*node
=
1742 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1743 parent_node
->GetChildren().Append( node
);
1745 return node
->GetItem();
1749 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& parent
,
1750 const wxDataViewItem
& previous
,
1751 const wxString
& text
,
1753 const wxIcon
& expanded
,
1754 wxClientData
* data
)
1756 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1757 if (!parent_node
) return wxDataViewItem(0);
1759 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1760 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1761 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1763 wxDataViewTreeStoreContainerNode
*node
=
1764 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1765 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1767 return node
->GetItem();
1770 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1772 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1773 if (!parent_node
) return wxDataViewItem(0);
1775 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1777 return node
->GetData();
1779 return wxDataViewItem(0);
1782 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1784 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1785 if (!node
) return -1;
1787 if (!node
->IsContainer())
1790 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1791 return (int) container_node
->GetChildren().GetCount();
1794 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1796 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1799 node
->SetText( text
);
1802 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1804 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1805 if (!node
) return wxEmptyString
;
1807 return node
->GetText();
1810 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1812 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1815 node
->SetIcon( icon
);
1818 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1820 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1821 if (!node
) return wxNullIcon
;
1823 return node
->GetIcon();
1826 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1828 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1831 node
->SetExpandedIcon( icon
);
1834 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1836 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1837 if (!node
) return wxNullIcon
;
1839 return node
->GetExpandedIcon();
1842 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1844 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1847 node
->SetData( data
);
1850 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
1852 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1853 if (!node
) return NULL
;
1855 return node
->GetData();
1858 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
1860 if (!item
.IsOk()) return;
1862 wxDataViewItem parent_item
= GetParent( item
);
1864 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
1865 if (!parent_node
) return;
1867 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1870 parent_node
->GetChildren().DeleteObject( node
);
1873 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
1875 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1878 node
->GetChildren().clear();
1881 void wxDataViewTreeStore::DeleteAllItems()
1883 DeleteChildren(m_root
);
1887 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
1888 const wxDataViewItem
&item
,
1889 unsigned int WXUNUSED(col
)) const
1891 // if (col != 0) return;
1893 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1896 wxIcon
icon( node
->GetIcon());
1897 if (node
->IsContainer())
1899 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
1900 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
1901 icon
= container
->GetExpandedIcon();
1904 wxDataViewIconText
data( node
->GetText(), icon
);
1910 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
1911 const wxDataViewItem
& item
,
1912 unsigned int WXUNUSED(col
))
1914 // if (col != 0) return false;
1916 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1917 if (!node
) return false;
1919 wxDataViewIconText data
;
1923 node
->SetText( data
.GetText() );
1924 node
->SetIcon( data
.GetIcon() );
1929 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
1931 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1932 if (!node
) return wxDataViewItem(0);
1934 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
1935 if (!parent
) return wxDataViewItem(0);
1937 if (parent
== m_root
)
1938 return wxDataViewItem(0);
1940 return parent
->GetItem();
1943 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
&item
) const
1945 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1946 if (!node
) return false;
1948 return node
->IsContainer();
1951 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
1953 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1954 if (!node
) return 0;
1956 wxDataViewTreeStoreNodeList::iterator iter
;
1957 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1959 wxDataViewTreeStoreNode
* child
= *iter
;
1960 children
.Add( child
->GetItem() );
1963 return node
->GetChildren().GetCount();
1966 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
1967 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) ) const
1969 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
1970 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
1972 if (!node1
|| !node2
)
1975 wxDataViewTreeStoreContainerNode
* parent1
=
1976 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
1977 wxDataViewTreeStoreContainerNode
* parent2
=
1978 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
1980 if (parent1
!= parent2
)
1982 wxLogError( wxT("Comparing items with different parent.") );
1986 if (node1
->IsContainer() && !!node2
->IsContainer())
1989 if (node2
->IsContainer() && !!node1
->IsContainer())
1992 return parent1
->GetChildren().IndexOf( node1
) - parent1
->GetChildren().IndexOf( node2
);
1995 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
2000 return (wxDataViewTreeStoreNode
*) item
.GetID();
2003 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
2006 return (wxDataViewTreeStoreContainerNode
*) m_root
;
2008 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
2010 if (!node
->IsContainer())
2013 return (wxDataViewTreeStoreContainerNode
*) node
;
2016 //-----------------------------------------------------------------------------
2017 // wxDataViewTreeCtrl
2018 //-----------------------------------------------------------------------------
2020 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2022 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2023 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
2024 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
2025 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
2028 wxDataViewTreeCtrl::wxDataViewTreeCtrl()
2033 wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow
*parent
, wxWindowID id
,
2034 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2037 Create( parent
, id
, pos
, size
, style
, validator
);
2039 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
2040 AssociateModel( store
);
2043 AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT
,-1);
2046 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
2052 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2053 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2055 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
2058 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
2063 m_imageList
= imagelist
;
2066 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
2067 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2069 wxIcon icon
= wxNullIcon
;
2070 if (m_imageList
&& (iconIndex
!= -1))
2071 icon
= m_imageList
->GetIcon( iconIndex
);
2073 wxDataViewItem res
= GetStore()->AppendItem( parent
, text
, icon
, data
);
2075 GetStore()->ItemAdded( parent
, res
);
2080 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
2081 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2083 wxIcon icon
= wxNullIcon
;
2084 if (m_imageList
&& (iconIndex
!= -1))
2085 icon
= m_imageList
->GetIcon( iconIndex
);
2087 wxDataViewItem res
= GetStore()->PrependItem( parent
, text
, icon
, data
);
2089 GetStore()->ItemAdded( parent
, res
);
2094 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2095 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2097 wxIcon icon
= wxNullIcon
;
2098 if (m_imageList
&& (iconIndex
!= -1))
2099 icon
= m_imageList
->GetIcon( iconIndex
);
2101 wxDataViewItem res
= GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
2103 GetStore()->ItemAdded( parent
, res
);
2108 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
2109 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2111 wxIcon icon
= wxNullIcon
;
2112 if (m_imageList
&& (iconIndex
!= -1))
2113 icon
= m_imageList
->GetIcon( iconIndex
);
2115 wxIcon expanded
= wxNullIcon
;
2116 if (m_imageList
&& (expandedIndex
!= -1))
2117 expanded
= m_imageList
->GetIcon( expandedIndex
);
2119 wxDataViewItem res
= GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
2121 GetStore()->ItemAdded( parent
, res
);
2126 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
2127 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2129 wxIcon icon
= wxNullIcon
;
2130 if (m_imageList
&& (iconIndex
!= -1))
2131 icon
= m_imageList
->GetIcon( iconIndex
);
2133 wxIcon expanded
= wxNullIcon
;
2134 if (m_imageList
&& (expandedIndex
!= -1))
2135 expanded
= m_imageList
->GetIcon( expandedIndex
);
2137 wxDataViewItem res
= GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
2139 GetStore()->ItemAdded( parent
, res
);
2144 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2145 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2147 wxIcon icon
= wxNullIcon
;
2148 if (m_imageList
&& (iconIndex
!= -1))
2149 icon
= m_imageList
->GetIcon( iconIndex
);
2151 wxIcon expanded
= wxNullIcon
;
2152 if (m_imageList
&& (expandedIndex
!= -1))
2153 expanded
= m_imageList
->GetIcon( expandedIndex
);
2155 wxDataViewItem res
= GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
2157 GetStore()->ItemAdded( parent
, res
);
2162 void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2164 GetStore()->SetItemText(item
,text
);
2167 GetStore()->ValueChanged( item
, 0 );
2170 void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2172 GetStore()->SetItemIcon(item
,icon
);
2175 GetStore()->ValueChanged( item
, 0 );
2178 void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2180 GetStore()->SetItemExpandedIcon(item
,icon
);
2183 GetStore()->ValueChanged( item
, 0 );
2186 void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem
& item
)
2188 wxDataViewItem parent_item
= GetStore()->GetParent( item
);
2190 GetStore()->DeleteItem(item
);
2193 GetStore()->ItemDeleted( parent_item
, item
);
2196 void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem
& item
)
2198 wxDataViewTreeStoreContainerNode
*node
= GetStore()->FindContainerNode( item
);
2201 wxDataViewItemArray array
;
2202 wxDataViewTreeStoreNodeList::iterator iter
;
2203 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2205 wxDataViewTreeStoreNode
* child
= *iter
;
2206 array
.Add( child
->GetItem() );
2209 GetStore()->DeleteChildren( item
);
2212 GetStore()->ItemsDeleted( item
, array
);
2215 void wxDataViewTreeCtrl::DeleteAllItems()
2217 GetStore()->DeleteAllItems();
2219 GetStore()->Cleared();
2222 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
2224 if (m_imageList
) return;
2226 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2227 if (!container
) return;
2229 container
->SetExpanded( true );
2231 GetStore()->ItemChanged( event
.GetItem() );
2234 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
2236 if (m_imageList
) return;
2238 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2239 if (!container
) return;
2241 container
->SetExpanded( false );
2243 GetStore()->ItemChanged( event
.GetItem() );
2246 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
2248 #if defined(wxUSE_GENERICDATAVIEWCTRL)
2249 // automatically resize our only column to take the entire control width
2250 if ( GetColumnCount() )
2252 wxSize size
= GetClientSize();
2253 GetColumn(0)->SetWidth(size
.x
);
2259 #endif // wxUSE_DATAVIEWCTRL