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";
35 // ---------------------------------------------------------
36 // wxDataViewModelNotifier
37 // ---------------------------------------------------------
39 #include "wx/listimpl.cpp"
40 WX_DEFINE_LIST(wxDataViewModelNotifiers
)
42 bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
44 size_t count
= items
.GetCount();
46 for (i
= 0; i
< count
; i
++)
47 if (!ItemAdded( parent
, items
[i
] )) return false;
52 bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
54 size_t count
= items
.GetCount();
56 for (i
= 0; i
< count
; i
++)
57 if (!ItemDeleted( parent
, items
[i
] )) return false;
62 bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray
&items
)
64 size_t count
= items
.GetCount();
66 for (i
= 0; i
< count
; i
++)
67 if (!ItemChanged( items
[i
] )) return false;
72 // ---------------------------------------------------------
74 // ---------------------------------------------------------
76 wxDataViewModel::wxDataViewModel()
78 m_notifiers
.DeleteContents( true );
81 bool wxDataViewModel::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
85 wxDataViewModelNotifiers::iterator iter
;
86 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
88 wxDataViewModelNotifier
* notifier
= *iter
;
89 if (!notifier
->ItemAdded( parent
, item
))
96 bool wxDataViewModel::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
100 wxDataViewModelNotifiers::iterator iter
;
101 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
103 wxDataViewModelNotifier
* notifier
= *iter
;
104 if (!notifier
->ItemDeleted( parent
, item
))
111 bool wxDataViewModel::ItemChanged( const wxDataViewItem
&item
)
115 wxDataViewModelNotifiers::iterator iter
;
116 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
118 wxDataViewModelNotifier
* notifier
= *iter
;
119 if (!notifier
->ItemChanged( item
))
126 bool wxDataViewModel::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
130 wxDataViewModelNotifiers::iterator iter
;
131 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
133 wxDataViewModelNotifier
* notifier
= *iter
;
134 if (!notifier
->ItemsAdded( parent
, items
))
141 bool wxDataViewModel::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
145 wxDataViewModelNotifiers::iterator iter
;
146 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
148 wxDataViewModelNotifier
* notifier
= *iter
;
149 if (!notifier
->ItemsDeleted( parent
, items
))
156 bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray
&items
)
160 wxDataViewModelNotifiers::iterator iter
;
161 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
163 wxDataViewModelNotifier
* notifier
= *iter
;
164 if (!notifier
->ItemsChanged( items
))
171 bool wxDataViewModel::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
175 wxDataViewModelNotifiers::iterator iter
;
176 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
178 wxDataViewModelNotifier
* notifier
= *iter
;
179 if (!notifier
->ValueChanged( item
, col
))
186 bool wxDataViewModel::Cleared()
190 wxDataViewModelNotifiers::iterator iter
;
191 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
193 wxDataViewModelNotifier
* notifier
= *iter
;
194 if (!notifier
->Cleared())
201 void wxDataViewModel::Resort()
203 wxDataViewModelNotifiers::iterator iter
;
204 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
206 wxDataViewModelNotifier
* notifier
= *iter
;
211 void wxDataViewModel::AddNotifier( wxDataViewModelNotifier
*notifier
)
213 m_notifiers
.push_back( notifier
);
214 notifier
->SetOwner( this );
217 void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier
*notifier
)
219 m_notifiers
.DeleteObject( notifier
);
222 int wxDataViewModel::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
223 unsigned int column
, bool ascending
) const
225 // sort branches before leaves
226 bool item1_is_container
= IsContainer(item1
);
227 bool item2_is_container
= IsContainer(item2
);
229 if (item1_is_container
&& !item2_is_container
)
231 if (item2_is_container
&& !item1_is_container
)
234 wxVariant value1
,value2
;
235 GetValue( value1
, item1
, column
);
236 GetValue( value2
, item2
, column
);
240 wxVariant temp
= value1
;
245 if (value1
.GetType() == wxT("string"))
247 wxString str1
= value1
.GetString();
248 wxString str2
= value2
.GetString();
249 int res
= str1
.Cmp( str2
);
253 else if (value1
.GetType() == wxT("long"))
255 long l1
= value1
.GetLong();
256 long l2
= value2
.GetLong();
261 else if (value1
.GetType() == wxT("double"))
263 double d1
= value1
.GetDouble();
264 double d2
= value2
.GetDouble();
270 else if (value1
.GetType() == wxT("datetime"))
272 wxDateTime dt1
= value1
.GetDateTime();
273 wxDateTime dt2
= value2
.GetDateTime();
274 if (dt1
.IsEarlierThan(dt2
))
276 if (dt2
.IsEarlierThan(dt1
))
280 // items must be different
281 wxUIntPtr id1
= wxPtrToUInt(item1
.GetID()),
282 id2
= wxPtrToUInt(item2
.GetID());
284 return ascending
? id1
- id2
: id2
- id1
;
287 // ---------------------------------------------------------
288 // wxDataViewIndexListModel
289 // ---------------------------------------------------------
291 static int my_sort( int *v1
, int *v2
)
297 wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size
)
299 // IDs are ordered until an item gets deleted or inserted
302 // build initial index
304 for (i
= 1; i
< initial_size
+1; i
++)
305 m_hash
.Add( wxUIntToPtr(i
) );
306 m_nextFreeID
= initial_size
+ 1;
309 wxDataViewIndexListModel::~wxDataViewIndexListModel()
313 void wxDataViewIndexListModel::Reset( unsigned int new_size
)
317 // IDs are ordered until an item gets deleted or inserted
320 // build initial index
322 for (i
= 1; i
< new_size
+1; i
++)
323 m_hash
.Add( wxUIntToPtr(i
) );
325 m_nextFreeID
= new_size
+ 1;
327 wxDataViewModel::Cleared();
330 void wxDataViewIndexListModel::RowPrepended()
334 unsigned int id
= m_nextFreeID
;
337 m_hash
.Insert( wxUIntToPtr(id
), 0 );
338 wxDataViewItem
item( wxUIntToPtr(id
) );
339 ItemAdded( wxDataViewItem(0), item
);
343 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
347 unsigned int id
= m_nextFreeID
;
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_nextFreeID
;
360 m_hash
.Add( wxUIntToPtr(id
) );
361 wxDataViewItem
item( wxUIntToPtr(id
) );
362 ItemAdded( wxDataViewItem(0), item
);
365 void wxDataViewIndexListModel::RowDeleted( unsigned int row
)
369 wxDataViewItem
item( m_hash
[row
] );
370 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
371 m_hash
.RemoveAt( row
);
374 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt
&rows
)
376 wxArrayInt sorted
= rows
;
377 sorted
.Sort( my_sort
);
381 wxDataViewItemArray array
;
383 for (i
= 0; i
< rows
.GetCount(); i
++)
385 wxDataViewItem
item( m_hash
[rows
[i
]] );
388 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
390 for (i
= 0; i
< sorted
.GetCount(); i
++)
391 m_hash
.RemoveAt( sorted
[i
] );
394 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
396 wxDataViewModel::ItemChanged( GetItem(row
) );
399 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
401 wxDataViewModel::ValueChanged( GetItem(row
), col
);
404 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
407 return wxPtrToUInt(item
.GetID())-1;
409 // assert for not found
410 return (unsigned int) m_hash
.Index( item
.GetID() );
413 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
415 wxASSERT( row
< m_hash
.GetCount() );
416 return wxDataViewItem( m_hash
[row
] );
419 bool wxDataViewIndexListModel::HasDefaultCompare() const
424 int wxDataViewIndexListModel::Compare(const wxDataViewItem
& item1
,
425 const wxDataViewItem
& item2
,
426 unsigned int WXUNUSED(column
),
427 bool ascending
) const
431 unsigned int pos1
= wxPtrToUInt(item1
.GetID()); // -1 not needed here
432 unsigned int pos2
= wxPtrToUInt(item2
.GetID()); // -1 not needed here
441 return GetRow(item1
) - GetRow(item2
);
443 return GetRow(item2
) - GetRow(item1
);
446 void wxDataViewIndexListModel::GetValue( wxVariant
&variant
,
447 const wxDataViewItem
&item
, unsigned int col
) const
449 GetValueByRow( variant
, GetRow(item
), col
);
452 bool wxDataViewIndexListModel::SetValue( const wxVariant
&variant
,
453 const wxDataViewItem
&item
, unsigned int col
)
455 return SetValueByRow( variant
, GetRow(item
), col
);
458 bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
460 return GetAttrByRow( GetRow(item
), col
, attr
);
463 wxDataViewItem
wxDataViewIndexListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
465 return wxDataViewItem(0);
468 bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem
&item
) const
470 // only the invisible root item has children
477 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
484 return m_hash
.GetCount();
487 // ---------------------------------------------------------
488 // wxDataViewVirtualListModel
489 // ---------------------------------------------------------
493 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size
)
495 m_size
= initial_size
;
498 wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
502 void wxDataViewVirtualListModel::Reset( unsigned int new_size
)
506 wxDataViewModel::Cleared();
509 void wxDataViewVirtualListModel::RowPrepended()
512 wxDataViewItem
item( wxUIntToPtr(1) );
513 ItemAdded( wxDataViewItem(0), item
);
516 void wxDataViewVirtualListModel::RowInserted( unsigned int before
)
519 wxDataViewItem
item( wxUIntToPtr(before
+1) );
520 ItemAdded( wxDataViewItem(0), item
);
523 void wxDataViewVirtualListModel::RowAppended()
526 wxDataViewItem
item( wxUIntToPtr(m_size
) );
527 ItemAdded( wxDataViewItem(0), item
);
530 void wxDataViewVirtualListModel::RowDeleted( unsigned int row
)
533 wxDataViewItem
item( wxUIntToPtr(row
+1) );
534 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
537 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt
&rows
)
539 m_size
-= rows
.GetCount();
541 wxArrayInt sorted
= rows
;
542 sorted
.Sort( my_sort
);
544 wxDataViewItemArray array
;
546 for (i
= 0; i
< sorted
.GetCount(); i
++)
548 wxDataViewItem
item( wxUIntToPtr(sorted
[i
]+1) );
551 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
554 void wxDataViewVirtualListModel::RowChanged( unsigned int row
)
556 wxDataViewModel::ItemChanged( GetItem(row
) );
559 void wxDataViewVirtualListModel::RowValueChanged( unsigned int row
, unsigned int col
)
561 wxDataViewModel::ValueChanged( GetItem(row
), col
);
564 unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem
&item
) const
566 return wxPtrToUInt( item
.GetID() ) -1;
569 wxDataViewItem
wxDataViewVirtualListModel::GetItem( unsigned int row
) const
571 return wxDataViewItem( wxUIntToPtr(row
+1) );
574 bool wxDataViewVirtualListModel::HasDefaultCompare() const
579 int wxDataViewVirtualListModel::Compare(const wxDataViewItem
& item1
,
580 const wxDataViewItem
& item2
,
581 unsigned int WXUNUSED(column
),
582 bool ascending
) const
584 unsigned int pos1
= wxPtrToUInt(item1
.GetID()); // -1 not needed here
585 unsigned int pos2
= wxPtrToUInt(item2
.GetID()); // -1 not needed here
593 void wxDataViewVirtualListModel::GetValue( wxVariant
&variant
,
594 const wxDataViewItem
&item
, unsigned int col
) const
596 GetValueByRow( variant
, GetRow(item
), col
);
599 bool wxDataViewVirtualListModel::SetValue( const wxVariant
&variant
,
600 const wxDataViewItem
&item
, unsigned int col
)
602 return SetValueByRow( variant
, GetRow(item
), col
);
605 bool wxDataViewVirtualListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
607 return GetAttrByRow( GetRow(item
), col
, attr
);
610 wxDataViewItem
wxDataViewVirtualListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
612 return wxDataViewItem(0);
615 bool wxDataViewVirtualListModel::IsContainer( const wxDataViewItem
&item
) const
617 // only the invisible root item has children
624 unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem
&WXUNUSED(item
), wxDataViewItemArray
&WXUNUSED(children
) ) const
626 return 0; // should we report an error ?
631 //-----------------------------------------------------------------------------
632 // wxDataViewIconText
633 //-----------------------------------------------------------------------------
635 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
637 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
639 // ---------------------------------------------------------
640 // wxDataViewRendererBase
641 // ---------------------------------------------------------
643 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
645 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
646 wxDataViewCellMode
WXUNUSED(mode
),
647 int WXUNUSED(align
) )
649 m_variantType
= varianttype
;
653 wxDataViewRendererBase::~wxDataViewRendererBase()
657 const wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
659 return const_cast<wxDataViewRendererBase
*>(this)->GetOwner()->GetOwner();
662 class wxKillRef
: public wxWindowRef
665 wxKillRef( wxWindow
*win
) : wxWindowRef( win
) { }
666 virtual void OnObjectDestroy()
668 get()->PopEventHandler( true );
674 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
676 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
678 // Before doing anything we send an event asking if editing of this item is really wanted.
679 wxDataViewEvent
start_event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv_ctrl
->GetId() );
680 start_event
.SetDataViewColumn( GetOwner() );
681 start_event
.SetModel( dv_ctrl
->GetModel() );
682 start_event
.SetItem( item
);
683 start_event
.SetEventObject( dv_ctrl
);
684 dv_ctrl
->GetEventHandler()->ProcessEvent( start_event
);
685 if( !start_event
.IsAllowed() )
688 m_item
= item
; // remember for later
690 unsigned int col
= GetOwner()->GetModelColumn();
692 dv_ctrl
->GetModel()->GetValue( value
, item
, col
);
694 m_editorCtrl
= CreateEditorCtrl( dv_ctrl
->GetMainWindow(), labelRect
, value
);
696 // there might be no editor control for the given item
700 (void) new wxKillRef( m_editorCtrl
.get() );
702 wxDataViewEditorCtrlEvtHandler
*handler
=
703 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
705 m_editorCtrl
->PushEventHandler( handler
);
707 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
708 handler
->SetFocusOnIdle();
710 m_editorCtrl
->SetFocus();
713 // Now we should send Editing Started event
714 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv_ctrl
->GetId() );
715 event
.SetDataViewColumn( GetOwner() );
716 event
.SetModel( dv_ctrl
->GetModel() );
717 event
.SetItem( item
);
718 event
.SetEventObject( dv_ctrl
);
719 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
724 void wxDataViewRendererBase::CancelEditing()
729 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
731 m_editorCtrl
->Hide();
732 wxPendingDelete
.Append( m_editorCtrl
);
735 bool wxDataViewRendererBase::FinishEditing()
741 GetValueFromEditorCtrl( m_editorCtrl
, value
);
743 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
745 dv_ctrl
->GetMainWindow()->SetFocus();
747 m_editorCtrl
->Hide();
748 wxPendingDelete
.Append( m_editorCtrl
);
750 if (!Validate(value
))
753 unsigned int col
= GetOwner()->GetModelColumn();
754 dv_ctrl
->GetModel()->ChangeValue(value
, m_item
, col
);
756 // Now we should send Editing Done event
757 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv_ctrl
->GetId() );
758 event
.SetDataViewColumn( GetOwner() );
759 event
.SetModel( dv_ctrl
->GetModel() );
760 event
.SetItem( m_item
);
761 event
.SetEventObject( dv_ctrl
);
762 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
767 //-----------------------------------------------------------------------------
768 // wxDataViewEditorCtrlEvtHandler
769 //-----------------------------------------------------------------------------
771 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
772 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
773 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
774 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
775 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
778 wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
779 wxControl
*editorCtrl
,
780 wxDataViewRenderer
*owner
)
783 m_editorCtrl
= editorCtrl
;
788 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
792 m_focusOnIdle
= false;
793 if (wxWindow::FindFocus() != m_editorCtrl
)
794 m_editorCtrl
->SetFocus();
800 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
803 m_owner
->FinishEditing();
806 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
808 switch ( event
.m_keyCode
)
812 m_owner
->FinishEditing();
818 m_owner
->CancelEditing();
826 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
831 m_owner
->FinishEditing();
837 // ---------------------------------------------------------
838 // wxDataViewColumnBase
839 // ---------------------------------------------------------
841 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
842 unsigned int model_column
)
844 m_renderer
= renderer
;
845 m_model_column
= model_column
;
847 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
850 wxDataViewColumnBase::~wxDataViewColumnBase()
855 // ---------------------------------------------------------
856 // wxDataViewCtrlBase
857 // ---------------------------------------------------------
859 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
861 wxDataViewCtrlBase::wxDataViewCtrlBase()
864 m_expander_column
= 0;
868 wxDataViewCtrlBase::~wxDataViewCtrlBase()
877 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
881 m_model
->DecRef(); // discard old model, if any
884 // add our own reference to the new model:
894 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
899 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
904 void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem
& item
)
906 if (!m_model
) return;
908 if (!item
.IsOk()) return;
910 wxVector
<wxDataViewItem
> parentChain
;
912 // at first we get all the parents of the selected item
913 wxDataViewItem parent
= m_model
->GetParent(item
);
914 while (parent
.IsOk())
916 parentChain
.push_back(parent
);
917 parent
= m_model
->GetParent(parent
);
920 // then we expand the parents, starting at the root
921 while (!parentChain
.empty())
923 Expand(parentChain
.back());
924 parentChain
.pop_back();
929 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
930 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
932 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
933 new wxDataViewTextRenderer( wxT("string"), mode
),
934 model_column
, width
, align
, flags
);
940 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
941 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
943 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
944 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
945 model_column
, width
, align
, flags
);
951 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
952 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
954 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
955 new wxDataViewToggleRenderer( wxT("bool"), mode
),
956 model_column
, width
, align
, flags
);
962 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
963 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
965 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
966 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
967 model_column
, width
, align
, flags
);
973 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
974 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
976 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
977 new wxDataViewDateRenderer( wxT("datetime"), mode
),
978 model_column
, width
, align
, flags
);
984 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
985 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
987 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
988 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
989 model_column
, width
, align
, flags
);
995 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
996 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
998 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
999 new wxDataViewTextRenderer( wxT("string"), mode
),
1000 model_column
, width
, align
, flags
);
1001 AppendColumn( ret
);
1006 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1007 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1009 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1010 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1011 model_column
, width
, align
, flags
);
1012 AppendColumn( ret
);
1017 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1018 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1020 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1021 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1022 model_column
, width
, align
, flags
);
1023 AppendColumn( ret
);
1028 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1029 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1031 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1032 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1033 model_column
, width
, align
, flags
);
1034 AppendColumn( ret
);
1039 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1040 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1042 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1043 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1044 model_column
, width
, align
, flags
);
1045 AppendColumn( ret
);
1050 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1051 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1053 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1054 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1055 model_column
, width
, align
, flags
);
1056 AppendColumn( ret
);
1061 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1062 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1064 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1065 new wxDataViewTextRenderer( wxT("string"), mode
),
1066 model_column
, width
, align
, flags
);
1067 PrependColumn( ret
);
1072 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1073 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1075 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1076 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1077 model_column
, width
, align
, flags
);
1078 PrependColumn( ret
);
1083 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1084 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1087 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1088 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1089 model_column
, width
, align
, flags
);
1090 PrependColumn( ret
);
1095 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1096 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1098 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1099 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1100 model_column
, width
, align
, flags
);
1101 PrependColumn( ret
);
1106 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1107 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1109 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1110 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1111 model_column
, width
, align
, flags
);
1112 PrependColumn( ret
);
1117 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1118 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1120 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1121 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1122 model_column
, width
, align
, flags
);
1123 PrependColumn( ret
);
1128 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1129 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1131 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1132 new wxDataViewTextRenderer( wxT("string"), mode
),
1133 model_column
, width
, align
, flags
);
1134 PrependColumn( ret
);
1139 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1140 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1142 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1143 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1144 model_column
, width
, align
, flags
);
1145 PrependColumn( ret
);
1150 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1151 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1153 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1154 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1155 model_column
, width
, align
, flags
);
1156 PrependColumn( ret
);
1161 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1162 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1164 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1165 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1166 model_column
, width
, align
, flags
);
1167 PrependColumn( ret
);
1172 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1173 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1175 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1176 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1177 model_column
, width
, align
, flags
);
1178 PrependColumn( ret
);
1183 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1184 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1186 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1187 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1188 model_column
, width
, align
, flags
);
1189 PrependColumn( ret
);
1194 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1196 col
->SetOwner( (wxDataViewCtrl
*) this );
1201 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1203 col
->SetOwner( (wxDataViewCtrl
*) this );
1208 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1210 col
->SetOwner( (wxDataViewCtrl
*) this );
1214 // ---------------------------------------------------------
1216 // ---------------------------------------------------------
1218 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1220 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
);
1222 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
);
1223 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
);
1224 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
);
1225 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
);
1226 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
);
1227 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
);
1228 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, wxDataViewEvent
);
1229 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
);
1230 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
);
1232 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
);
1234 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
);
1235 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
);
1236 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
);
1237 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
);
1239 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, wxDataViewEvent
);
1241 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
);
1242 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, wxDataViewEvent
);
1243 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, wxDataViewEvent
);
1247 // -------------------------------------
1248 // wxDataViewSpinRenderer
1249 // -------------------------------------
1251 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1252 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1258 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1261 wxSize size
= labelRect
.GetSize();
1263 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1266 str
.Printf( wxT("%d"), (int) l
);
1267 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1268 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1270 size
= sc
->GetSize();
1271 wxPoint pt
= sc
->GetPosition();
1272 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1278 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1280 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1281 long l
= sc
->GetValue();
1286 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1289 str
.Printf(wxT("%d"), (int) m_data
);
1290 RenderText( str
, 0, rect
, dc
, state
);
1294 wxSize
wxDataViewSpinRenderer::GetSize() const
1296 return wxSize(80,16);
1299 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1301 m_data
= value
.GetLong();
1305 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1311 // -------------------------------------
1312 // wxDataViewChoiceRenderer
1313 // -------------------------------------
1315 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
1317 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1318 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1320 m_choices
= choices
;
1323 wxControl
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1326 wxSize size
= labelRect
.GetSize();
1328 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1330 wxChoice
*c
= new wxChoice( parent
, wxID_ANY
, labelRect
.GetTopLeft(), size
, m_choices
);
1331 c
->SetStringSelection( value
.GetString() );
1336 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1338 wxChoice
*c
= (wxChoice
*) editor
;
1339 wxString s
= c
->GetStringSelection();
1344 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1346 RenderText( m_data
, 0, rect
, dc
, state
);
1350 wxSize
wxDataViewChoiceRenderer::GetSize() const
1352 return wxSize(80,16);
1355 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1357 m_data
= value
.GetString();
1361 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1369 //-----------------------------------------------------------------------------
1370 // wxDataViewListStore
1371 //-----------------------------------------------------------------------------
1373 wxDataViewListStore::wxDataViewListStore()
1377 wxDataViewListStore::~wxDataViewListStore()
1379 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1380 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1382 wxDataViewListStoreLine
* line
= *it
;
1387 void wxDataViewListStore::PrependColumn( const wxString
&varianttype
)
1389 m_cols
.Insert( varianttype
, 0 );
1392 void wxDataViewListStore::InsertColumn( unsigned int pos
, const wxString
&varianttype
)
1394 m_cols
.Insert( varianttype
, pos
);
1397 void wxDataViewListStore::AppendColumn( const wxString
&varianttype
)
1399 m_cols
.Add( varianttype
);
1402 unsigned int wxDataViewListStore::GetColumnCount() const
1404 return m_cols
.GetCount();
1407 wxString
wxDataViewListStore::GetColumnType( unsigned int pos
) const
1412 void wxDataViewListStore::AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1414 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1415 line
->m_values
= values
;
1416 m_data
.push_back( line
);
1421 void wxDataViewListStore::PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1423 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1424 line
->m_values
= values
;
1425 m_data
.insert( m_data
.begin(), line
);
1430 void wxDataViewListStore::InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
,
1431 wxClientData
*data
)
1433 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1434 line
->m_values
= values
;
1435 m_data
.insert( m_data
.begin()+row
, line
);
1440 void wxDataViewListStore::DeleteItem( unsigned int row
)
1442 wxVector
<wxDataViewListStoreLine
*>::iterator it
= m_data
.begin() + row
;
1448 void wxDataViewListStore::DeleteAllItems()
1450 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1451 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1453 wxDataViewListStoreLine
* line
= *it
;
1462 void wxDataViewListStore::GetValueByRow( wxVariant
&value
, unsigned int row
, unsigned int col
) const
1464 wxDataViewListStoreLine
*line
= m_data
[row
];
1465 value
= line
->m_values
[col
];
1468 bool wxDataViewListStore::SetValueByRow( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1470 wxDataViewListStoreLine
*line
= m_data
[row
];
1471 line
->m_values
[col
] = value
;
1476 //-----------------------------------------------------------------------------
1477 // wxDataViewListCtrl
1478 //-----------------------------------------------------------------------------
1480 IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl
,wxDataViewCtrl
)
1482 BEGIN_EVENT_TABLE(wxDataViewListCtrl
,wxDataViewCtrl
)
1483 EVT_SIZE( wxDataViewListCtrl::OnSize
)
1486 wxDataViewListCtrl::wxDataViewListCtrl()
1490 wxDataViewListCtrl::wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
1491 const wxPoint
& pos
, const wxSize
& size
, long style
,
1492 const wxValidator
& validator
)
1494 Create( parent
, id
, pos
, size
, style
, validator
);
1496 wxDataViewListStore
*store
= new wxDataViewListStore
;
1497 AssociateModel( store
);
1501 wxDataViewListCtrl::~wxDataViewListCtrl()
1506 bool wxDataViewListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1507 const wxPoint
& pos
, const wxSize
& size
, long style
,
1508 const wxValidator
& validator
)
1510 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
1513 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1515 GetStore()->AppendColumn( varianttype
);
1516 return wxDataViewCtrl::AppendColumn( column
);
1519 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1521 GetStore()->PrependColumn( varianttype
);
1522 return wxDataViewCtrl::PrependColumn( column
);
1525 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
)
1527 GetStore()->InsertColumn( pos
, varianttype
);
1528 return wxDataViewCtrl::InsertColumn( pos
, column
);
1531 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*col
)
1533 return PrependColumn( col
, "string" );
1536 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
1538 return InsertColumn( pos
, col
, "string" );
1541 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*col
)
1543 return AppendColumn( col
, "string" );
1546 wxDataViewColumn
*wxDataViewListCtrl::AppendTextColumn( const wxString
&label
,
1547 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1549 GetStore()->AppendColumn( wxT("string") );
1551 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1552 new wxDataViewTextRenderer( wxT("string"), mode
),
1553 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1555 wxDataViewCtrl::AppendColumn( ret
);
1560 wxDataViewColumn
*wxDataViewListCtrl::AppendToggleColumn( const wxString
&label
,
1561 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1563 GetStore()->AppendColumn( wxT("bool") );
1565 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1566 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1567 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1569 wxDataViewCtrl::AppendColumn( ret
);
1574 wxDataViewColumn
*wxDataViewListCtrl::AppendProgressColumn( const wxString
&label
,
1575 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1577 GetStore()->AppendColumn( wxT("long") );
1579 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1580 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1581 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1583 wxDataViewCtrl::AppendColumn( ret
);
1588 wxDataViewColumn
*wxDataViewListCtrl::AppendIconTextColumn( const wxString
&label
,
1589 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1591 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
1593 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1594 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1595 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1597 wxDataViewCtrl::AppendColumn( ret
);
1602 void wxDataViewListCtrl::OnSize( wxSizeEvent
&event
)
1607 //-----------------------------------------------------------------------------
1608 // wxDataViewTreeStore
1609 //-----------------------------------------------------------------------------
1611 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1612 wxDataViewTreeStoreNode
*parent
,
1613 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1621 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1627 #include "wx/listimpl.cpp"
1628 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1630 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1631 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1632 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1633 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1635 m_iconExpanded
= expanded
;
1636 m_isExpanded
= false;
1637 m_children
.DeleteContents(true);
1640 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1644 //-----------------------------------------------------------------------------
1646 wxDataViewTreeStore::wxDataViewTreeStore()
1648 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1651 wxDataViewTreeStore::~wxDataViewTreeStore()
1656 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1657 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1659 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1660 if (!parent_node
) return wxDataViewItem(0);
1662 wxDataViewTreeStoreNode
*node
=
1663 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1664 parent_node
->GetChildren().Append( node
);
1666 return node
->GetItem();
1669 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1670 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1672 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1673 if (!parent_node
) return wxDataViewItem(0);
1675 wxDataViewTreeStoreNode
*node
=
1676 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1677 parent_node
->GetChildren().Insert( node
);
1679 return node
->GetItem();
1683 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& parent
,
1684 const wxDataViewItem
& previous
,
1685 const wxString
& text
,
1689 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1690 if (!parent_node
) return wxDataViewItem(0);
1692 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1693 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1694 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1696 wxDataViewTreeStoreNode
*node
=
1697 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1698 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1700 return node
->GetItem();
1703 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1704 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1705 wxClientData
*data
)
1707 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1708 if (!parent_node
) return wxDataViewItem(0);
1710 wxDataViewTreeStoreContainerNode
*node
=
1711 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1712 parent_node
->GetChildren().Insert( node
);
1714 return node
->GetItem();
1718 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1719 const wxString
&text
,
1721 const wxIcon
& expanded
,
1722 wxClientData
* data
)
1724 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1725 if (!parent_node
) return wxDataViewItem(0);
1727 wxDataViewTreeStoreContainerNode
*node
=
1728 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1729 parent_node
->GetChildren().Append( node
);
1731 return node
->GetItem();
1735 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& parent
,
1736 const wxDataViewItem
& previous
,
1737 const wxString
& text
,
1739 const wxIcon
& expanded
,
1740 wxClientData
* data
)
1742 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1743 if (!parent_node
) return wxDataViewItem(0);
1745 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1746 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1747 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1749 wxDataViewTreeStoreContainerNode
*node
=
1750 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1751 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1753 return node
->GetItem();
1756 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1758 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1759 if (!parent_node
) return wxDataViewItem(0);
1761 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1763 return node
->GetData();
1765 return wxDataViewItem(0);
1768 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1770 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1771 if (!node
) return -1;
1773 if (!node
->IsContainer())
1776 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1777 return (int) container_node
->GetChildren().GetCount();
1780 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1782 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1785 node
->SetText( text
);
1788 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1790 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1791 if (!node
) return wxEmptyString
;
1793 return node
->GetText();
1796 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1798 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1801 node
->SetIcon( icon
);
1804 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1806 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1807 if (!node
) return wxNullIcon
;
1809 return node
->GetIcon();
1812 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1814 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1817 node
->SetExpandedIcon( icon
);
1820 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1822 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1823 if (!node
) return wxNullIcon
;
1825 return node
->GetExpandedIcon();
1828 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1830 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1833 node
->SetData( data
);
1836 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
1838 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1839 if (!node
) return NULL
;
1841 return node
->GetData();
1844 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
1846 if (!item
.IsOk()) return;
1848 wxDataViewItem parent_item
= GetParent( item
);
1850 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
1851 if (!parent_node
) return;
1853 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1856 parent_node
->GetChildren().DeleteObject( node
);
1859 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
1861 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1864 node
->GetChildren().clear();
1867 void wxDataViewTreeStore::DeleteAllItems()
1869 DeleteChildren(m_root
);
1873 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
1874 const wxDataViewItem
&item
,
1875 unsigned int WXUNUSED(col
)) const
1877 // if (col != 0) return;
1879 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1882 wxIcon
icon( node
->GetIcon());
1883 if (node
->IsContainer())
1885 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
1886 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
1887 icon
= container
->GetExpandedIcon();
1890 wxDataViewIconText
data( node
->GetText(), icon
);
1896 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
1897 const wxDataViewItem
& item
,
1898 unsigned int WXUNUSED(col
))
1900 // if (col != 0) return false;
1902 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1903 if (!node
) return false;
1905 wxDataViewIconText data
;
1909 node
->SetText( data
.GetText() );
1910 node
->SetIcon( data
.GetIcon() );
1915 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
1917 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1918 if (!node
) return wxDataViewItem(0);
1920 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
1921 if (!parent
) return wxDataViewItem(0);
1923 if (parent
== m_root
)
1924 return wxDataViewItem(0);
1926 return parent
->GetItem();
1929 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
&item
) const
1931 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1932 if (!node
) return false;
1934 return node
->IsContainer();
1937 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
1939 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1940 if (!node
) return 0;
1942 wxDataViewTreeStoreNodeList::iterator iter
;
1943 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1945 wxDataViewTreeStoreNode
* child
= *iter
;
1946 children
.Add( child
->GetItem() );
1949 return node
->GetChildren().GetCount();
1952 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
1953 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) ) const
1955 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
1956 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
1958 if (!node1
|| !node2
)
1961 wxDataViewTreeStoreContainerNode
* parent1
=
1962 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
1963 wxDataViewTreeStoreContainerNode
* parent2
=
1964 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
1966 if (parent1
!= parent2
)
1968 wxLogError( wxT("Comparing items with different parent.") );
1972 if (node1
->IsContainer() && !!node2
->IsContainer())
1975 if (node2
->IsContainer() && !!node1
->IsContainer())
1978 return parent1
->GetChildren().IndexOf( node1
) - parent1
->GetChildren().IndexOf( node2
);
1981 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
1986 return (wxDataViewTreeStoreNode
*) item
.GetID();
1989 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
1992 return (wxDataViewTreeStoreContainerNode
*) m_root
;
1994 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
1996 if (!node
->IsContainer())
1999 return (wxDataViewTreeStoreContainerNode
*) node
;
2002 //-----------------------------------------------------------------------------
2003 // wxDataViewTreeCtrl
2004 //-----------------------------------------------------------------------------
2006 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2008 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2009 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
2010 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
2011 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
2014 wxDataViewTreeCtrl::wxDataViewTreeCtrl()
2019 wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow
*parent
, wxWindowID id
,
2020 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2023 Create( parent
, id
, pos
, size
, style
, validator
);
2025 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
2026 AssociateModel( store
);
2029 AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT
,-1);
2032 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
2038 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2039 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2041 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
2044 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
2049 m_imageList
= imagelist
;
2052 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
2053 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2055 wxIcon icon
= wxNullIcon
;
2056 if (m_imageList
&& (iconIndex
!= -1))
2057 icon
= m_imageList
->GetIcon( iconIndex
);
2059 wxDataViewItem res
= GetStore()->AppendItem( parent
, text
, icon
, data
);
2061 GetStore()->ItemAdded( parent
, res
);
2066 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( 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()->PrependItem( parent
, text
, icon
, data
);
2075 GetStore()->ItemAdded( parent
, res
);
2080 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
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()->InsertItem( parent
, previous
, text
, icon
, data
);
2089 GetStore()->ItemAdded( parent
, res
);
2094 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
2095 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2097 wxIcon icon
= wxNullIcon
;
2098 if (m_imageList
&& (iconIndex
!= -1))
2099 icon
= m_imageList
->GetIcon( iconIndex
);
2101 wxIcon expanded
= wxNullIcon
;
2102 if (m_imageList
&& (expandedIndex
!= -1))
2103 expanded
= m_imageList
->GetIcon( expandedIndex
);
2105 wxDataViewItem res
= GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
2107 GetStore()->ItemAdded( parent
, res
);
2112 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
2113 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2115 wxIcon icon
= wxNullIcon
;
2116 if (m_imageList
&& (iconIndex
!= -1))
2117 icon
= m_imageList
->GetIcon( iconIndex
);
2119 wxIcon expanded
= wxNullIcon
;
2120 if (m_imageList
&& (expandedIndex
!= -1))
2121 expanded
= m_imageList
->GetIcon( expandedIndex
);
2123 wxDataViewItem res
= GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
2125 GetStore()->ItemAdded( parent
, res
);
2130 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2131 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2133 wxIcon icon
= wxNullIcon
;
2134 if (m_imageList
&& (iconIndex
!= -1))
2135 icon
= m_imageList
->GetIcon( iconIndex
);
2137 wxIcon expanded
= wxNullIcon
;
2138 if (m_imageList
&& (expandedIndex
!= -1))
2139 expanded
= m_imageList
->GetIcon( expandedIndex
);
2141 wxDataViewItem res
= GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
2143 GetStore()->ItemAdded( parent
, res
);
2148 void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2150 GetStore()->SetItemText(item
,text
);
2153 GetStore()->ValueChanged( item
, 0 );
2156 void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2158 GetStore()->SetItemIcon(item
,icon
);
2161 GetStore()->ValueChanged( item
, 0 );
2164 void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2166 GetStore()->SetItemExpandedIcon(item
,icon
);
2169 GetStore()->ValueChanged( item
, 0 );
2172 void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem
& item
)
2174 wxDataViewItem parent_item
= GetStore()->GetParent( item
);
2176 GetStore()->DeleteItem(item
);
2179 GetStore()->ItemDeleted( parent_item
, item
);
2182 void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem
& item
)
2184 wxDataViewTreeStoreContainerNode
*node
= GetStore()->FindContainerNode( item
);
2187 wxDataViewItemArray array
;
2188 wxDataViewTreeStoreNodeList::iterator iter
;
2189 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2191 wxDataViewTreeStoreNode
* child
= *iter
;
2192 array
.Add( child
->GetItem() );
2195 GetStore()->DeleteChildren( item
);
2198 GetStore()->ItemsDeleted( item
, array
);
2201 void wxDataViewTreeCtrl::DeleteAllItems()
2203 GetStore()->DeleteAllItems();
2205 GetStore()->Cleared();
2208 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
2210 if (m_imageList
) return;
2212 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2213 if (!container
) return;
2215 container
->SetExpanded( true );
2217 GetStore()->ItemChanged( event
.GetItem() );
2220 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
2222 if (m_imageList
) return;
2224 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2225 if (!container
) return;
2227 container
->SetExpanded( false );
2229 GetStore()->ItemChanged( event
.GetItem() );
2232 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
2234 #if defined(wxUSE_GENERICDATAVIEWCTRL)
2235 // automatically resize our only column to take the entire control width
2236 if ( GetColumnCount() )
2238 wxSize size
= GetClientSize();
2239 GetColumn(0)->SetWidth(size
.x
);
2245 #endif // wxUSE_DATAVIEWCTRL