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()->SetValue( value
, m_item
, col
);
755 dv_ctrl
->GetModel()->ValueChanged( m_item
, col
);
757 // Now we should send Editing Done event
758 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv_ctrl
->GetId() );
759 event
.SetDataViewColumn( GetOwner() );
760 event
.SetModel( dv_ctrl
->GetModel() );
761 event
.SetItem( m_item
);
762 event
.SetEventObject( dv_ctrl
);
763 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
768 //-----------------------------------------------------------------------------
769 // wxDataViewEditorCtrlEvtHandler
770 //-----------------------------------------------------------------------------
772 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
773 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
774 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
775 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
776 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
779 wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
780 wxControl
*editorCtrl
,
781 wxDataViewRenderer
*owner
)
784 m_editorCtrl
= editorCtrl
;
789 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
793 m_focusOnIdle
= false;
794 if (wxWindow::FindFocus() != m_editorCtrl
)
795 m_editorCtrl
->SetFocus();
801 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
804 m_owner
->FinishEditing();
807 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
809 switch ( event
.m_keyCode
)
813 m_owner
->FinishEditing();
819 m_owner
->CancelEditing();
827 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
832 m_owner
->FinishEditing();
838 // ---------------------------------------------------------
839 // wxDataViewColumnBase
840 // ---------------------------------------------------------
842 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
843 unsigned int model_column
)
845 m_renderer
= renderer
;
846 m_model_column
= model_column
;
848 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
851 wxDataViewColumnBase::~wxDataViewColumnBase()
856 // ---------------------------------------------------------
857 // wxDataViewCtrlBase
858 // ---------------------------------------------------------
860 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
862 wxDataViewCtrlBase::wxDataViewCtrlBase()
865 m_expander_column
= 0;
869 wxDataViewCtrlBase::~wxDataViewCtrlBase()
878 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
882 m_model
->DecRef(); // discard old model, if any
885 // add our own reference to the new model:
895 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
900 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
905 void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem
& item
)
907 if (!m_model
) return;
909 if (!item
.IsOk()) return;
911 wxVector
<wxDataViewItem
> parentChain
;
913 // at first we get all the parents of the selected item
914 wxDataViewItem parent
= m_model
->GetParent(item
);
915 while (parent
.IsOk())
917 parentChain
.push_back(parent
);
918 parent
= m_model
->GetParent(parent
);
921 // then we expand the parents, starting at the root
922 while (!parentChain
.empty())
924 Expand(parentChain
.back());
925 parentChain
.pop_back();
930 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
931 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
933 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
934 new wxDataViewTextRenderer( wxT("string"), mode
),
935 model_column
, width
, align
, flags
);
941 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
942 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
944 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
945 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
946 model_column
, width
, align
, flags
);
952 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
953 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
955 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
956 new wxDataViewToggleRenderer( wxT("bool"), mode
),
957 model_column
, width
, align
, flags
);
963 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
964 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
966 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
967 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
968 model_column
, width
, align
, flags
);
974 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
975 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
977 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
978 new wxDataViewDateRenderer( wxT("datetime"), mode
),
979 model_column
, width
, align
, flags
);
985 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
986 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
988 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
989 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
990 model_column
, width
, align
, flags
);
996 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
997 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
999 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1000 new wxDataViewTextRenderer( wxT("string"), mode
),
1001 model_column
, width
, align
, flags
);
1002 AppendColumn( ret
);
1007 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1008 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1010 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1011 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1012 model_column
, width
, align
, flags
);
1013 AppendColumn( ret
);
1018 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1019 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1021 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1022 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1023 model_column
, width
, align
, flags
);
1024 AppendColumn( ret
);
1029 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1030 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1032 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1033 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1034 model_column
, width
, align
, flags
);
1035 AppendColumn( ret
);
1040 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1041 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1043 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1044 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1045 model_column
, width
, align
, flags
);
1046 AppendColumn( ret
);
1051 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1052 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1054 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1055 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1056 model_column
, width
, align
, flags
);
1057 AppendColumn( ret
);
1062 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1063 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1065 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1066 new wxDataViewTextRenderer( wxT("string"), mode
),
1067 model_column
, width
, align
, flags
);
1068 PrependColumn( ret
);
1073 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1074 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1076 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1077 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1078 model_column
, width
, align
, flags
);
1079 PrependColumn( ret
);
1084 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1085 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1088 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1089 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1090 model_column
, width
, align
, flags
);
1091 PrependColumn( ret
);
1096 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1097 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1099 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1100 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1101 model_column
, width
, align
, flags
);
1102 PrependColumn( ret
);
1107 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1108 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1110 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1111 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1112 model_column
, width
, align
, flags
);
1113 PrependColumn( ret
);
1118 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1119 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1121 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1122 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1123 model_column
, width
, align
, flags
);
1124 PrependColumn( ret
);
1129 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1130 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1132 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1133 new wxDataViewTextRenderer( wxT("string"), mode
),
1134 model_column
, width
, align
, flags
);
1135 PrependColumn( ret
);
1140 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1141 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1143 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1144 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1145 model_column
, width
, align
, flags
);
1146 PrependColumn( ret
);
1151 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1152 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1154 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1155 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1156 model_column
, width
, align
, flags
);
1157 PrependColumn( ret
);
1162 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1163 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1165 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1166 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1167 model_column
, width
, align
, flags
);
1168 PrependColumn( ret
);
1173 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1174 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1176 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1177 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1178 model_column
, width
, align
, flags
);
1179 PrependColumn( ret
);
1184 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1185 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1187 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1188 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1189 model_column
, width
, align
, flags
);
1190 PrependColumn( ret
);
1195 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1197 col
->SetOwner( (wxDataViewCtrl
*) this );
1202 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1204 col
->SetOwner( (wxDataViewCtrl
*) this );
1209 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1211 col
->SetOwner( (wxDataViewCtrl
*) this );
1215 // ---------------------------------------------------------
1217 // ---------------------------------------------------------
1219 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1221 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
);
1223 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
);
1224 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
);
1225 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
);
1226 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
);
1227 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
);
1228 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
);
1229 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, wxDataViewEvent
);
1230 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
);
1231 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
);
1233 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
);
1235 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
);
1236 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
);
1237 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
);
1238 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
);
1240 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, wxDataViewEvent
);
1242 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
);
1243 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, wxDataViewEvent
);
1244 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, wxDataViewEvent
);
1248 // -------------------------------------
1249 // wxDataViewSpinRenderer
1250 // -------------------------------------
1252 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1253 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1259 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1262 wxSize size
= labelRect
.GetSize();
1264 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1267 str
.Printf( wxT("%d"), (int) l
);
1268 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1269 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1271 size
= sc
->GetSize();
1272 wxPoint pt
= sc
->GetPosition();
1273 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1279 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1281 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1282 long l
= sc
->GetValue();
1287 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1290 str
.Printf(wxT("%d"), (int) m_data
);
1291 RenderText( str
, 0, rect
, dc
, state
);
1295 wxSize
wxDataViewSpinRenderer::GetSize() const
1297 return wxSize(80,16);
1300 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1302 m_data
= value
.GetLong();
1306 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1312 // -------------------------------------
1313 // wxDataViewChoiceRenderer
1314 // -------------------------------------
1316 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
1318 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1319 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1321 m_choices
= choices
;
1324 wxControl
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1327 wxSize size
= labelRect
.GetSize();
1329 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1331 wxChoice
*c
= new wxChoice( parent
, wxID_ANY
, labelRect
.GetTopLeft(), size
, m_choices
);
1332 c
->SetStringSelection( value
.GetString() );
1337 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1339 wxChoice
*c
= (wxChoice
*) editor
;
1340 wxString s
= c
->GetStringSelection();
1345 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1347 RenderText( m_data
, 0, rect
, dc
, state
);
1351 wxSize
wxDataViewChoiceRenderer::GetSize() const
1353 return wxSize(80,16);
1356 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1358 m_data
= value
.GetString();
1362 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1370 //-----------------------------------------------------------------------------
1371 // wxDataViewListStore
1372 //-----------------------------------------------------------------------------
1374 wxDataViewListStore::wxDataViewListStore()
1378 wxDataViewListStore::~wxDataViewListStore()
1380 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1381 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1383 wxDataViewListStoreLine
* line
= *it
;
1388 void wxDataViewListStore::PrependColumn( const wxString
&varianttype
)
1390 m_cols
.Insert( varianttype
, 0 );
1393 void wxDataViewListStore::InsertColumn( unsigned int pos
, const wxString
&varianttype
)
1395 m_cols
.Insert( varianttype
, pos
);
1398 void wxDataViewListStore::AppendColumn( const wxString
&varianttype
)
1400 m_cols
.Add( varianttype
);
1403 unsigned int wxDataViewListStore::GetColumnCount() const
1405 return m_cols
.GetCount();
1408 wxString
wxDataViewListStore::GetColumnType( unsigned int pos
) const
1413 void wxDataViewListStore::AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1415 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1416 line
->m_values
= values
;
1417 m_data
.push_back( line
);
1422 void wxDataViewListStore::PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1424 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1425 line
->m_values
= values
;
1426 m_data
.insert( m_data
.begin(), line
);
1431 void wxDataViewListStore::InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
,
1432 wxClientData
*data
)
1434 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1435 line
->m_values
= values
;
1436 m_data
.insert( m_data
.begin()+row
, line
);
1441 void wxDataViewListStore::DeleteItem( unsigned int row
)
1443 wxVector
<wxDataViewListStoreLine
*>::iterator it
= m_data
.begin() + row
;
1449 void wxDataViewListStore::DeleteAllItems()
1451 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1452 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1454 wxDataViewListStoreLine
* line
= *it
;
1463 void wxDataViewListStore::GetValueByRow( wxVariant
&value
, unsigned int row
, unsigned int col
) const
1465 wxDataViewListStoreLine
*line
= m_data
[row
];
1466 value
= line
->m_values
[col
];
1469 bool wxDataViewListStore::SetValueByRow( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1471 wxDataViewListStoreLine
*line
= m_data
[row
];
1472 line
->m_values
[col
] = value
;
1477 //-----------------------------------------------------------------------------
1478 // wxDataViewListCtrl
1479 //-----------------------------------------------------------------------------
1481 IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl
,wxDataViewCtrl
)
1483 BEGIN_EVENT_TABLE(wxDataViewListCtrl
,wxDataViewCtrl
)
1484 EVT_SIZE( wxDataViewListCtrl::OnSize
)
1487 wxDataViewListCtrl::wxDataViewListCtrl()
1491 wxDataViewListCtrl::wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
1492 const wxPoint
& pos
, const wxSize
& size
, long style
,
1493 const wxValidator
& validator
)
1495 Create( parent
, id
, pos
, size
, style
, validator
);
1497 wxDataViewListStore
*store
= new wxDataViewListStore
;
1498 AssociateModel( store
);
1502 wxDataViewListCtrl::~wxDataViewListCtrl()
1507 bool wxDataViewListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1508 const wxPoint
& pos
, const wxSize
& size
, long style
,
1509 const wxValidator
& validator
)
1511 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
1514 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1516 GetStore()->AppendColumn( varianttype
);
1517 return wxDataViewCtrl::AppendColumn( column
);
1520 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1522 GetStore()->PrependColumn( varianttype
);
1523 return wxDataViewCtrl::PrependColumn( column
);
1526 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
)
1528 GetStore()->InsertColumn( pos
, varianttype
);
1529 return wxDataViewCtrl::InsertColumn( pos
, column
);
1532 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*col
)
1534 return PrependColumn( col
, "string" );
1537 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
1539 return InsertColumn( pos
, col
, "string" );
1542 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*col
)
1544 return AppendColumn( col
, "string" );
1547 wxDataViewColumn
*wxDataViewListCtrl::AppendTextColumn( const wxString
&label
,
1548 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1550 GetStore()->AppendColumn( wxT("string") );
1552 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1553 new wxDataViewTextRenderer( wxT("string"), mode
),
1554 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1556 wxDataViewCtrl::AppendColumn( ret
);
1561 wxDataViewColumn
*wxDataViewListCtrl::AppendToggleColumn( const wxString
&label
,
1562 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1564 GetStore()->AppendColumn( wxT("bool") );
1566 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1567 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1568 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1570 wxDataViewCtrl::AppendColumn( ret
);
1575 wxDataViewColumn
*wxDataViewListCtrl::AppendProgressColumn( const wxString
&label
,
1576 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1578 GetStore()->AppendColumn( wxT("long") );
1580 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1581 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1582 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1584 wxDataViewCtrl::AppendColumn( ret
);
1589 wxDataViewColumn
*wxDataViewListCtrl::AppendIconTextColumn( const wxString
&label
,
1590 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1592 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
1594 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1595 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1596 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1598 wxDataViewCtrl::AppendColumn( ret
);
1603 void wxDataViewListCtrl::OnSize( wxSizeEvent
&event
)
1608 //-----------------------------------------------------------------------------
1609 // wxDataViewTreeStore
1610 //-----------------------------------------------------------------------------
1612 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1613 wxDataViewTreeStoreNode
*parent
,
1614 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1622 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1628 #include "wx/listimpl.cpp"
1629 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1631 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1632 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1633 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1634 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1636 m_iconExpanded
= expanded
;
1637 m_isExpanded
= false;
1638 m_children
.DeleteContents(true);
1641 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1645 //-----------------------------------------------------------------------------
1647 wxDataViewTreeStore::wxDataViewTreeStore()
1649 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1652 wxDataViewTreeStore::~wxDataViewTreeStore()
1657 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1658 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1660 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1661 if (!parent_node
) return wxDataViewItem(0);
1663 wxDataViewTreeStoreNode
*node
=
1664 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1665 parent_node
->GetChildren().Append( node
);
1667 return node
->GetItem();
1670 wxDataViewItem
wxDataViewTreeStore::PrependItem( 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().Insert( node
);
1680 return node
->GetItem();
1684 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& parent
,
1685 const wxDataViewItem
& previous
,
1686 const wxString
& text
,
1690 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1691 if (!parent_node
) return wxDataViewItem(0);
1693 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1694 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1695 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1697 wxDataViewTreeStoreNode
*node
=
1698 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1699 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1701 return node
->GetItem();
1704 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1705 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1706 wxClientData
*data
)
1708 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1709 if (!parent_node
) return wxDataViewItem(0);
1711 wxDataViewTreeStoreContainerNode
*node
=
1712 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1713 parent_node
->GetChildren().Insert( node
);
1715 return node
->GetItem();
1719 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1720 const wxString
&text
,
1722 const wxIcon
& expanded
,
1723 wxClientData
* data
)
1725 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1726 if (!parent_node
) return wxDataViewItem(0);
1728 wxDataViewTreeStoreContainerNode
*node
=
1729 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1730 parent_node
->GetChildren().Append( node
);
1732 return node
->GetItem();
1736 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& parent
,
1737 const wxDataViewItem
& previous
,
1738 const wxString
& text
,
1740 const wxIcon
& expanded
,
1741 wxClientData
* data
)
1743 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1744 if (!parent_node
) return wxDataViewItem(0);
1746 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1747 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1748 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1750 wxDataViewTreeStoreContainerNode
*node
=
1751 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1752 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1754 return node
->GetItem();
1757 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1759 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1760 if (!parent_node
) return wxDataViewItem(0);
1762 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1764 return node
->GetData();
1766 return wxDataViewItem(0);
1769 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1771 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1772 if (!node
) return -1;
1774 if (!node
->IsContainer())
1777 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1778 return (int) container_node
->GetChildren().GetCount();
1781 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1783 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1786 node
->SetText( text
);
1789 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1791 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1792 if (!node
) return wxEmptyString
;
1794 return node
->GetText();
1797 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1799 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1802 node
->SetIcon( icon
);
1805 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1807 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1808 if (!node
) return wxNullIcon
;
1810 return node
->GetIcon();
1813 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1815 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1818 node
->SetExpandedIcon( icon
);
1821 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1823 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1824 if (!node
) return wxNullIcon
;
1826 return node
->GetExpandedIcon();
1829 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1831 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1834 node
->SetData( data
);
1837 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
1839 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1840 if (!node
) return NULL
;
1842 return node
->GetData();
1845 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
1847 if (!item
.IsOk()) return;
1849 wxDataViewItem parent_item
= GetParent( item
);
1851 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
1852 if (!parent_node
) return;
1854 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1857 parent_node
->GetChildren().DeleteObject( node
);
1860 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
1862 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1865 node
->GetChildren().clear();
1868 void wxDataViewTreeStore::DeleteAllItems()
1870 DeleteChildren(m_root
);
1874 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
1875 const wxDataViewItem
&item
,
1876 unsigned int WXUNUSED(col
)) const
1878 // if (col != 0) return;
1880 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1883 wxIcon
icon( node
->GetIcon());
1884 if (node
->IsContainer())
1886 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
1887 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
1888 icon
= container
->GetExpandedIcon();
1891 wxDataViewIconText
data( node
->GetText(), icon
);
1897 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
1898 const wxDataViewItem
& item
,
1899 unsigned int WXUNUSED(col
))
1901 // if (col != 0) return false;
1903 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1904 if (!node
) return false;
1906 wxDataViewIconText data
;
1910 node
->SetText( data
.GetText() );
1911 node
->SetIcon( data
.GetIcon() );
1916 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
1918 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1919 if (!node
) return wxDataViewItem(0);
1921 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
1922 if (!parent
) return wxDataViewItem(0);
1924 if (parent
== m_root
)
1925 return wxDataViewItem(0);
1927 return parent
->GetItem();
1930 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
&item
) const
1932 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1933 if (!node
) return false;
1935 return node
->IsContainer();
1938 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
1940 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1941 if (!node
) return 0;
1943 wxDataViewTreeStoreNodeList::iterator iter
;
1944 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1946 wxDataViewTreeStoreNode
* child
= *iter
;
1947 children
.Add( child
->GetItem() );
1950 return node
->GetChildren().GetCount();
1953 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
1954 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) ) const
1956 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
1957 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
1959 if (!node1
|| !node2
)
1962 wxDataViewTreeStoreContainerNode
* parent1
=
1963 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
1964 wxDataViewTreeStoreContainerNode
* parent2
=
1965 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
1967 if (parent1
!= parent2
)
1969 wxLogError( wxT("Comparing items with different parent.") );
1973 if (node1
->IsContainer() && !!node2
->IsContainer())
1976 if (node2
->IsContainer() && !!node1
->IsContainer())
1979 return parent1
->GetChildren().IndexOf( node1
) - parent1
->GetChildren().IndexOf( node2
);
1982 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
1987 return (wxDataViewTreeStoreNode
*) item
.GetID();
1990 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
1993 return (wxDataViewTreeStoreContainerNode
*) m_root
;
1995 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
1997 if (!node
->IsContainer())
2000 return (wxDataViewTreeStoreContainerNode
*) node
;
2003 //-----------------------------------------------------------------------------
2004 // wxDataViewTreeCtrl
2005 //-----------------------------------------------------------------------------
2007 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2009 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2010 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
2011 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
2012 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
2015 wxDataViewTreeCtrl::wxDataViewTreeCtrl()
2020 wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow
*parent
, wxWindowID id
,
2021 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2024 Create( parent
, id
, pos
, size
, style
, validator
);
2026 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
2027 AssociateModel( store
);
2030 AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT
,-1);
2033 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
2039 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2040 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2042 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
2045 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
2050 m_imageList
= imagelist
;
2053 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
2054 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2056 wxIcon icon
= wxNullIcon
;
2057 if (m_imageList
&& (iconIndex
!= -1))
2058 icon
= m_imageList
->GetIcon( iconIndex
);
2060 wxDataViewItem res
= GetStore()->AppendItem( parent
, text
, icon
, data
);
2062 GetStore()->ItemAdded( parent
, res
);
2067 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
2068 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2070 wxIcon icon
= wxNullIcon
;
2071 if (m_imageList
&& (iconIndex
!= -1))
2072 icon
= m_imageList
->GetIcon( iconIndex
);
2074 wxDataViewItem res
= GetStore()->PrependItem( parent
, text
, icon
, data
);
2076 GetStore()->ItemAdded( parent
, res
);
2081 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2082 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2084 wxIcon icon
= wxNullIcon
;
2085 if (m_imageList
&& (iconIndex
!= -1))
2086 icon
= m_imageList
->GetIcon( iconIndex
);
2088 wxDataViewItem res
= GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
2090 GetStore()->ItemAdded( parent
, res
);
2095 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
2096 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2098 wxIcon icon
= wxNullIcon
;
2099 if (m_imageList
&& (iconIndex
!= -1))
2100 icon
= m_imageList
->GetIcon( iconIndex
);
2102 wxIcon expanded
= wxNullIcon
;
2103 if (m_imageList
&& (expandedIndex
!= -1))
2104 expanded
= m_imageList
->GetIcon( expandedIndex
);
2106 wxDataViewItem res
= GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
2108 GetStore()->ItemAdded( parent
, res
);
2113 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
2114 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2116 wxIcon icon
= wxNullIcon
;
2117 if (m_imageList
&& (iconIndex
!= -1))
2118 icon
= m_imageList
->GetIcon( iconIndex
);
2120 wxIcon expanded
= wxNullIcon
;
2121 if (m_imageList
&& (expandedIndex
!= -1))
2122 expanded
= m_imageList
->GetIcon( expandedIndex
);
2124 wxDataViewItem res
= GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
2126 GetStore()->ItemAdded( parent
, res
);
2131 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2132 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2134 wxIcon icon
= wxNullIcon
;
2135 if (m_imageList
&& (iconIndex
!= -1))
2136 icon
= m_imageList
->GetIcon( iconIndex
);
2138 wxIcon expanded
= wxNullIcon
;
2139 if (m_imageList
&& (expandedIndex
!= -1))
2140 expanded
= m_imageList
->GetIcon( expandedIndex
);
2142 wxDataViewItem res
= GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
2144 GetStore()->ItemAdded( parent
, res
);
2149 void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2151 GetStore()->SetItemText(item
,text
);
2154 GetStore()->ValueChanged( item
, 0 );
2157 void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2159 GetStore()->SetItemIcon(item
,icon
);
2162 GetStore()->ValueChanged( item
, 0 );
2165 void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2167 GetStore()->SetItemExpandedIcon(item
,icon
);
2170 GetStore()->ValueChanged( item
, 0 );
2173 void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem
& item
)
2175 wxDataViewItem parent_item
= GetStore()->GetParent( item
);
2177 GetStore()->DeleteItem(item
);
2180 GetStore()->ItemDeleted( parent_item
, item
);
2183 void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem
& item
)
2185 wxDataViewTreeStoreContainerNode
*node
= GetStore()->FindContainerNode( item
);
2188 wxDataViewItemArray array
;
2189 wxDataViewTreeStoreNodeList::iterator iter
;
2190 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2192 wxDataViewTreeStoreNode
* child
= *iter
;
2193 array
.Add( child
->GetItem() );
2196 GetStore()->DeleteChildren( item
);
2199 GetStore()->ItemsDeleted( item
, array
);
2202 void wxDataViewTreeCtrl::DeleteAllItems()
2204 GetStore()->DeleteAllItems();
2206 GetStore()->Cleared();
2209 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
2211 if (m_imageList
) return;
2213 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2214 if (!container
) return;
2216 container
->SetExpanded( true );
2218 GetStore()->ItemChanged( event
.GetItem() );
2221 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
2223 if (m_imageList
) return;
2225 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2226 if (!container
) return;
2228 container
->SetExpanded( false );
2230 GetStore()->ItemChanged( event
.GetItem() );
2233 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
2235 #if defined(wxUSE_GENERICDATAVIEWCTRL)
2236 // automatically resize our only column to take the entire control width
2237 if ( GetColumnCount() )
2239 wxSize size
= GetClientSize();
2240 GetColumn(0)->SetWidth(size
.x
);
2246 #endif // wxUSE_DATAVIEWCTRL