1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/datavcmn.cpp
3 // Purpose: wxDataViewCtrl base classes and common parts
4 // Author: Robert Roebling
7 // Copyright: (c) 2006, Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_DATAVIEWCTRL
20 #include "wx/dataview.h"
21 #include "wx/spinctrl.h"
22 #include "wx/choice.h"
24 #include "wx/weakref.h"
25 #include "wx/vector.h"
29 #include "wx/settings.h"
35 const char wxDataViewCtrlNameStr
[] = "dataviewCtrl";
38 bool operator == (const wxDataViewItem
&left
, const wxDataViewItem
&right
)
40 return (left
.GetID() == right
.GetID() );
44 void wxDataViewItem::Print(const wxString
& text
) const
46 wxPrintf(wxT("item %s: %lu\n"), text
.GetData(), wxPtrToUInt(m_id
));
50 // ---------------------------------------------------------
51 // wxDataViewModelNotifier
52 // ---------------------------------------------------------
54 #include "wx/listimpl.cpp"
55 WX_DEFINE_LIST(wxDataViewModelNotifiers
)
57 bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
59 size_t count
= items
.GetCount();
61 for (i
= 0; i
< count
; i
++)
62 if (!ItemAdded( parent
, items
[i
] )) return false;
67 bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
69 size_t count
= items
.GetCount();
71 for (i
= 0; i
< count
; i
++)
72 if (!ItemDeleted( parent
, items
[i
] )) return false;
77 bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray
&items
)
79 size_t count
= items
.GetCount();
81 for (i
= 0; i
< count
; i
++)
82 if (!ItemChanged( items
[i
] )) return false;
87 // ---------------------------------------------------------
89 // ---------------------------------------------------------
91 wxDataViewModel::wxDataViewModel()
93 m_notifiers
.DeleteContents( true );
96 bool wxDataViewModel::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
100 wxDataViewModelNotifiers::iterator iter
;
101 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
103 wxDataViewModelNotifier
* notifier
= *iter
;
104 if (!notifier
->ItemAdded( parent
, item
))
111 bool wxDataViewModel::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
115 wxDataViewModelNotifiers::iterator iter
;
116 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
118 wxDataViewModelNotifier
* notifier
= *iter
;
119 if (!notifier
->ItemDeleted( parent
, item
))
126 bool wxDataViewModel::ItemChanged( const wxDataViewItem
&item
)
130 wxDataViewModelNotifiers::iterator iter
;
131 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
133 wxDataViewModelNotifier
* notifier
= *iter
;
134 if (!notifier
->ItemChanged( item
))
141 bool wxDataViewModel::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
145 wxDataViewModelNotifiers::iterator iter
;
146 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
148 wxDataViewModelNotifier
* notifier
= *iter
;
149 if (!notifier
->ItemsAdded( parent
, items
))
156 bool wxDataViewModel::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
160 wxDataViewModelNotifiers::iterator iter
;
161 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
163 wxDataViewModelNotifier
* notifier
= *iter
;
164 if (!notifier
->ItemsDeleted( parent
, items
))
171 bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray
&items
)
175 wxDataViewModelNotifiers::iterator iter
;
176 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
178 wxDataViewModelNotifier
* notifier
= *iter
;
179 if (!notifier
->ItemsChanged( items
))
186 bool wxDataViewModel::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
190 wxDataViewModelNotifiers::iterator iter
;
191 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
193 wxDataViewModelNotifier
* notifier
= *iter
;
194 if (!notifier
->ValueChanged( item
, col
))
201 bool wxDataViewModel::Cleared()
205 wxDataViewModelNotifiers::iterator iter
;
206 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
208 wxDataViewModelNotifier
* notifier
= *iter
;
209 if (!notifier
->Cleared())
216 void wxDataViewModel::Resort()
218 wxDataViewModelNotifiers::iterator iter
;
219 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
221 wxDataViewModelNotifier
* notifier
= *iter
;
226 void wxDataViewModel::AddNotifier( wxDataViewModelNotifier
*notifier
)
228 m_notifiers
.push_back( notifier
);
229 notifier
->SetOwner( this );
232 void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier
*notifier
)
234 m_notifiers
.DeleteObject( notifier
);
237 int wxDataViewModel::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
238 unsigned int column
, bool ascending
)
240 // sort branches before leaves
241 bool item1_is_container
= IsContainer(item1
);
242 bool item2_is_container
= IsContainer(item2
);
244 if (item1_is_container
&& !item2_is_container
)
246 if (item2_is_container
&& !item1_is_container
)
249 wxVariant value1
,value2
;
250 GetValue( value1
, item1
, column
);
251 GetValue( value2
, item2
, column
);
255 wxVariant temp
= value1
;
260 if (value1
.GetType() == wxT("string"))
262 wxString str1
= value1
.GetString();
263 wxString str2
= value2
.GetString();
264 int res
= str1
.Cmp( str2
);
268 else if (value1
.GetType() == wxT("long"))
270 long l1
= value1
.GetLong();
271 long l2
= value2
.GetLong();
276 else if (value1
.GetType() == wxT("double"))
278 double d1
= value1
.GetDouble();
279 double d2
= value2
.GetDouble();
285 else if (value1
.GetType() == wxT("datetime"))
287 wxDateTime dt1
= value1
.GetDateTime();
288 wxDateTime dt2
= value2
.GetDateTime();
289 if (dt1
.IsEarlierThan(dt2
))
291 if (dt2
.IsEarlierThan(dt1
))
295 // items must be different
296 wxUIntPtr id1
= wxPtrToUInt(item1
.GetID()),
297 id2
= wxPtrToUInt(item2
.GetID());
299 return ascending
? id1
- id2
: id2
- id1
;
302 // ---------------------------------------------------------
303 // wxDataViewIndexListModel
304 // ---------------------------------------------------------
306 static int my_sort( int *v1
, int *v2
)
312 wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size
)
314 // IDs are ordered until an item gets deleted or inserted
317 // build initial index
319 for (i
= 1; i
< initial_size
+1; i
++)
320 m_hash
.Add( wxUIntToPtr(i
) );
321 m_lastIndex
= initial_size
+ 1;
324 wxDataViewIndexListModel::~wxDataViewIndexListModel()
328 void wxDataViewIndexListModel::Reset( unsigned int new_size
)
332 // IDs are ordered until an item gets deleted or inserted
335 // build initial index
337 for (i
= 1; i
< new_size
+1; i
++)
338 m_hash
.Add( wxUIntToPtr(i
) );
339 m_lastIndex
= new_size
+ 1;
341 wxDataViewModel::Cleared();
344 void wxDataViewIndexListModel::RowPrepended()
348 unsigned int id
= m_lastIndex
++;
349 m_hash
.Insert( wxUIntToPtr(id
), 0 );
350 wxDataViewItem
item( wxUIntToPtr(id
) );
351 ItemAdded( wxDataViewItem(0), item
);
354 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
358 unsigned int id
= m_lastIndex
++;
359 m_hash
.Insert( wxUIntToPtr(id
), before
);
360 wxDataViewItem
item( wxUIntToPtr(id
) );
361 ItemAdded( wxDataViewItem(0), item
);
364 void wxDataViewIndexListModel::RowAppended()
366 unsigned int id
= m_lastIndex
++;
367 m_hash
.Add( wxUIntToPtr(id
) );
368 wxDataViewItem
item( wxUIntToPtr(id
) );
369 ItemAdded( wxDataViewItem(0), item
);
372 void wxDataViewIndexListModel::RowDeleted( unsigned int row
)
376 wxDataViewItem
item( m_hash
[row
] );
377 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
378 m_hash
.RemoveAt( row
);
381 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt
&rows
)
383 wxArrayInt sorted
= rows
;
384 sorted
.Sort( my_sort
);
388 wxDataViewItemArray array
;
390 for (i
= 0; i
< rows
.GetCount(); i
++)
392 wxDataViewItem
item( m_hash
[rows
[i
]] );
395 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
397 for (i
= 0; i
< sorted
.GetCount(); i
++)
398 m_hash
.RemoveAt( sorted
[i
] );
401 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
403 wxDataViewModel::ItemChanged( GetItem(row
) );
406 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
408 wxDataViewModel::ValueChanged( GetItem(row
), col
);
411 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
415 unsigned int pos
= wxPtrToUInt( item
.GetID() );
419 // assert for not found
420 return (unsigned int) m_hash
.Index( item
.GetID() );
423 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
425 wxASSERT( row
< m_hash
.GetCount() );
426 return wxDataViewItem( m_hash
[row
] );
429 bool wxDataViewIndexListModel::HasDefaultCompare() const
434 int wxDataViewIndexListModel::Compare(const wxDataViewItem
& item1
,
435 const wxDataViewItem
& item2
,
436 unsigned int WXUNUSED(column
),
441 unsigned int pos1
= wxPtrToUInt(item1
.GetID());
442 unsigned int pos2
= wxPtrToUInt(item2
.GetID());
451 return GetRow(item1
) - GetRow(item2
);
453 return GetRow(item2
) - GetRow(item1
);
456 void wxDataViewIndexListModel::GetValue( wxVariant
&variant
,
457 const wxDataViewItem
&item
, unsigned int col
) const
459 GetValueByRow( variant
, GetRow(item
), col
);
462 bool wxDataViewIndexListModel::SetValue( const wxVariant
&variant
,
463 const wxDataViewItem
&item
, unsigned int col
)
465 return SetValueByRow( variant
, GetRow(item
), col
);
468 bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
470 return GetAttrByRow( GetRow(item
), col
, attr
);
473 wxDataViewItem
wxDataViewIndexListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
475 return wxDataViewItem(0);
478 bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem
&item
) const
480 // only the invisible root item has children
487 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
494 return m_hash
.GetCount();
497 // ---------------------------------------------------------
498 // wxDataViewVirtualListModel
499 // ---------------------------------------------------------
503 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size
)
505 m_lastIndex
= initial_size
-1;
508 wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
512 void wxDataViewVirtualListModel::Reset( unsigned int new_size
)
514 m_lastIndex
= new_size
-1;
516 wxDataViewModel::Cleared();
519 void wxDataViewVirtualListModel::RowPrepended()
522 wxDataViewItem
item( NULL
);
523 ItemAdded( wxDataViewItem(0), item
);
526 void wxDataViewVirtualListModel::RowInserted( unsigned int before
)
529 wxDataViewItem
item( wxUIntToPtr(before
) );
530 ItemAdded( wxDataViewItem(0), item
);
533 void wxDataViewVirtualListModel::RowAppended()
536 wxDataViewItem
item( wxUIntToPtr(m_lastIndex
) );
537 ItemAdded( wxDataViewItem(0), item
);
540 void wxDataViewVirtualListModel::RowDeleted( unsigned int row
)
542 wxDataViewItem
item( wxUIntToPtr(row
) );
543 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
547 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt
&rows
)
549 wxArrayInt sorted
= rows
;
550 sorted
.Sort( my_sort
);
552 wxDataViewItemArray array
;
554 for (i
= 0; i
< sorted
.GetCount(); i
++)
556 wxDataViewItem
item( wxUIntToPtr(sorted
[i
]) );
559 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
561 m_lastIndex
-= rows
.GetCount();
564 void wxDataViewVirtualListModel::RowChanged( unsigned int row
)
566 wxDataViewModel::ItemChanged( GetItem(row
) );
569 void wxDataViewVirtualListModel::RowValueChanged( unsigned int row
, unsigned int col
)
571 wxDataViewModel::ValueChanged( GetItem(row
), col
);
574 unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem
&item
) const
576 return wxPtrToUInt( item
.GetID() );
579 wxDataViewItem
wxDataViewVirtualListModel::GetItem( unsigned int row
) const
581 return wxDataViewItem( wxUIntToPtr(row
) );
584 bool wxDataViewVirtualListModel::HasDefaultCompare() const
589 int wxDataViewVirtualListModel::Compare(const wxDataViewItem
& item1
,
590 const wxDataViewItem
& item2
,
591 unsigned int WXUNUSED(column
),
594 unsigned int pos1
= wxPtrToUInt(item1
.GetID());
595 unsigned int pos2
= wxPtrToUInt(item2
.GetID());
603 void wxDataViewVirtualListModel::GetValue( wxVariant
&variant
,
604 const wxDataViewItem
&item
, unsigned int col
) const
606 GetValueByRow( variant
, GetRow(item
), col
);
609 bool wxDataViewVirtualListModel::SetValue( const wxVariant
&variant
,
610 const wxDataViewItem
&item
, unsigned int col
)
612 return SetValueByRow( variant
, GetRow(item
), col
);
615 bool wxDataViewVirtualListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
617 return GetAttrByRow( GetRow(item
), col
, attr
);
620 wxDataViewItem
wxDataViewVirtualListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
622 return wxDataViewItem(0);
625 bool wxDataViewVirtualListModel::IsContainer( const wxDataViewItem
&item
) const
627 // only the invisible root item has children
634 unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem
&WXUNUSED(item
), wxDataViewItemArray
&WXUNUSED(children
) ) const
636 return 0; // should we report an error ?
641 //-----------------------------------------------------------------------------
642 // wxDataViewIconText
643 //-----------------------------------------------------------------------------
645 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
647 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
649 bool operator == (const wxDataViewIconText
&one
, const wxDataViewIconText
&two
)
651 if (one
.GetText() != two
.GetText()) return false;
652 if (one
.IsSameAs(two
)) return false;
656 // ---------------------------------------------------------
657 // wxDataViewRendererBase
658 // ---------------------------------------------------------
660 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
662 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
663 wxDataViewCellMode
WXUNUSED(mode
),
664 int WXUNUSED(align
) )
666 m_variantType
= varianttype
;
670 wxDataViewRendererBase::~wxDataViewRendererBase()
674 const wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
676 return const_cast<wxDataViewRendererBase
*>(this)->GetOwner()->GetOwner();
679 class wxKillRef
: public wxWindowRef
682 wxKillRef( wxWindow
*win
) : wxWindowRef( win
) { }
683 virtual void OnObjectDestroy()
685 get()->PopEventHandler( true );
691 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
693 m_item
= item
; // remember for later
695 unsigned int col
= GetOwner()->GetModelColumn();
697 GetOwner()->GetOwner()->GetModel()->GetValue( value
, item
, col
);
699 m_editorCtrl
= CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect
, value
);
700 (void) new wxKillRef( m_editorCtrl
.get() );
702 wxDataViewEditorCtrlEvtHandler
*handler
=
703 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
705 m_editorCtrl
->PushEventHandler( handler
);
707 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
708 handler
->SetFocusOnIdle();
710 m_editorCtrl
->SetFocus();
713 // Now we should send Editing Started event
714 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, GetOwner()->GetOwner()->GetId() );
715 event
.SetDataViewColumn( GetOwner() );
716 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
717 event
.SetItem( item
);
718 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
723 void wxDataViewRendererBase::CancelEditing()
725 if (!m_editorCtrl
) return;
727 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
729 m_editorCtrl
->Hide();
730 wxPendingDelete
.Append( m_editorCtrl
);
733 bool wxDataViewRendererBase::FinishEditing()
735 if (!m_editorCtrl
) return true;
738 GetValueFromEditorCtrl( m_editorCtrl
, value
);
740 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
742 m_editorCtrl
->Hide();
743 wxPendingDelete
.Append( m_editorCtrl
);
745 if (!Validate(value
))
748 unsigned int col
= GetOwner()->GetModelColumn();
749 GetOwner()->GetOwner()->GetModel()->SetValue( value
, m_item
, col
);
750 GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item
, col
);
752 // Now we should send Editing Done event
753 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, GetOwner()->GetOwner()->GetId() );
754 event
.SetDataViewColumn( GetOwner() );
755 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
756 event
.SetItem( m_item
);
757 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
762 //-----------------------------------------------------------------------------
763 // wxDataViewEditorCtrlEvtHandler
764 //-----------------------------------------------------------------------------
766 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
767 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
768 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
769 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
770 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
773 wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
774 wxControl
*editorCtrl
,
775 wxDataViewRenderer
*owner
)
778 m_editorCtrl
= editorCtrl
;
783 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
787 m_focusOnIdle
= false;
788 if (wxWindow::FindFocus() != m_editorCtrl
)
789 m_editorCtrl
->SetFocus();
795 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
798 m_owner
->FinishEditing();
801 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
803 switch ( event
.m_keyCode
)
807 m_owner
->FinishEditing();
813 m_owner
->CancelEditing();
821 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
826 m_owner
->FinishEditing();
832 // ---------------------------------------------------------
833 // wxDataViewColumnBase
834 // ---------------------------------------------------------
836 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
837 unsigned int model_column
)
839 m_renderer
= renderer
;
840 m_model_column
= model_column
;
842 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
845 wxDataViewColumnBase::~wxDataViewColumnBase()
850 // ---------------------------------------------------------
851 // wxDataViewCtrlBase
852 // ---------------------------------------------------------
854 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
856 wxDataViewCtrlBase::wxDataViewCtrlBase()
859 m_expander_column
= 0;
863 wxDataViewCtrlBase::~wxDataViewCtrlBase()
872 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
876 m_model
->DecRef(); // discard old model, if any
879 // add our own reference to the new model:
889 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
894 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
899 bool wxDataViewCtrlBase::EnableDragSource( const wxDataFormat
&WXUNUSED(format
) )
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_EDITING_DONE
, wxDataViewEvent
)
1229 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
)
1231 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
)
1233 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
)
1234 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
)
1235 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
)
1236 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
)
1238 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
)
1240 // -------------------------------------
1241 // wxDataViewSpinRenderer
1242 // -------------------------------------
1244 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1245 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1251 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1254 wxSize size
= labelRect
.GetSize();
1256 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1259 str
.Printf( wxT("%d"), (int) l
);
1260 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1261 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1263 size
= sc
->GetSize();
1264 wxPoint pt
= sc
->GetPosition();
1265 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1271 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1273 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1274 long l
= sc
->GetValue();
1279 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1282 str
.Printf(wxT("%d"), (int) m_data
);
1283 RenderText( str
, 0, rect
, dc
, state
);
1287 wxSize
wxDataViewSpinRenderer::GetSize() const
1289 return wxSize(80,16);
1292 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1294 m_data
= value
.GetLong();
1298 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1304 // -------------------------------------
1305 // wxDataViewChoiceRenderer
1306 // -------------------------------------
1308 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXMAC__)
1310 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1311 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1313 m_choices
= choices
;
1316 wxControl
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1319 wxSize size
= labelRect
.GetSize();
1321 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1323 wxChoice
*c
= new wxChoice( parent
, wxID_ANY
, labelRect
.GetTopLeft(), size
, m_choices
);
1324 c
->SetStringSelection( value
.GetString() );
1329 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1331 wxChoice
*c
= (wxChoice
*) editor
;
1332 wxString s
= c
->GetStringSelection();
1337 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1339 RenderText( m_data
, 0, rect
, dc
, state
);
1343 wxSize
wxDataViewChoiceRenderer::GetSize() const
1345 return wxSize(80,16);
1348 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1350 m_data
= value
.GetString();
1354 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1362 //-----------------------------------------------------------------------------
1363 // wxDataViewListStore
1364 //-----------------------------------------------------------------------------
1366 wxDataViewListStore::wxDataViewListStore()
1370 wxDataViewListStore::~wxDataViewListStore()
1372 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1373 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1375 wxDataViewListStoreLine
* line
= *it
;
1380 void wxDataViewListStore::PrependColumn( const wxString
&varianttype
)
1382 m_cols
.Insert( varianttype
, 0 );
1385 void wxDataViewListStore::InsertColumn( unsigned int pos
, const wxString
&varianttype
)
1387 m_cols
.Insert( varianttype
, pos
);
1390 void wxDataViewListStore::AppendColumn( const wxString
&varianttype
)
1392 m_cols
.Add( varianttype
);
1395 unsigned int wxDataViewListStore::GetColumnCount() const
1397 return m_cols
.GetCount();
1400 wxString
wxDataViewListStore::GetColumnType( unsigned int pos
) const
1405 void wxDataViewListStore::AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1407 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1408 line
->m_values
= values
;
1409 m_data
.push_back( line
);
1414 void wxDataViewListStore::PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1416 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1417 line
->m_values
= values
;
1418 m_data
.insert( m_data
.begin(), line
);
1423 void wxDataViewListStore::InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1425 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1426 line
->m_values
= values
;
1427 m_data
.insert( m_data
.begin()+row
, line
);
1432 void wxDataViewListStore::DeleteItem( unsigned row
)
1434 wxVector
<wxDataViewListStoreLine
*>::iterator it
= m_data
.begin() + row
;
1440 void wxDataViewListStore::DeleteAllItems()
1442 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1443 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1445 wxDataViewListStoreLine
* line
= *it
;
1452 void wxDataViewListStore::GetValueByRow( wxVariant
&value
, unsigned int row
, unsigned int col
) const
1454 wxDataViewListStoreLine
*line
= m_data
[row
];
1455 value
= line
->m_values
[col
];
1458 bool wxDataViewListStore::SetValueByRow( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1460 wxDataViewListStoreLine
*line
= m_data
[row
];
1461 line
->m_values
[col
] = value
;
1466 //-----------------------------------------------------------------------------
1467 // wxDataViewListCtrl
1468 //-----------------------------------------------------------------------------
1470 IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl
,wxDataViewCtrl
)
1472 BEGIN_EVENT_TABLE(wxDataViewListCtrl
,wxDataViewCtrl
)
1473 EVT_SIZE( wxDataViewListCtrl::OnSize
)
1476 wxDataViewListCtrl::wxDataViewListCtrl()
1480 wxDataViewListCtrl::wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
1481 const wxPoint
& pos
, const wxSize
& size
, long style
,
1482 const wxValidator
& validator
)
1484 Create( parent
, id
, pos
, size
, style
, validator
);
1486 wxDataViewListStore
*store
= new wxDataViewListStore
;
1487 AssociateModel( store
);
1491 wxDataViewListCtrl::~wxDataViewListCtrl()
1496 bool wxDataViewListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1497 const wxPoint
& pos
, const wxSize
& size
, long style
,
1498 const wxValidator
& validator
)
1500 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
1503 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1505 GetStore()->AppendColumn( varianttype
);
1506 return wxDataViewCtrl::AppendColumn( column
);
1509 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1511 GetStore()->PrependColumn( varianttype
);
1512 return wxDataViewCtrl::PrependColumn( column
);
1515 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
)
1517 GetStore()->InsertColumn( pos
, varianttype
);
1518 return wxDataViewCtrl::InsertColumn( pos
, column
);
1521 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*col
)
1523 return PrependColumn( col
, "string" );
1526 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
1528 return InsertColumn( pos
, col
, "string" );
1531 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*col
)
1533 return AppendColumn( col
, "string" );
1536 wxDataViewColumn
*wxDataViewListCtrl::AppendTextColumn( const wxString
&label
,
1537 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1539 GetStore()->AppendColumn( wxT("string") );
1541 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1542 new wxDataViewTextRenderer( wxT("string"), mode
),
1543 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1545 wxDataViewCtrl::AppendColumn( ret
);
1550 wxDataViewColumn
*wxDataViewListCtrl::AppendToggleColumn( const wxString
&label
,
1551 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1553 GetStore()->AppendColumn( wxT("bool") );
1555 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1556 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1557 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1559 wxDataViewCtrl::AppendColumn( ret
);
1564 wxDataViewColumn
*wxDataViewListCtrl::AppendProgressColumn( const wxString
&label
,
1565 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1567 GetStore()->AppendColumn( wxT("long") );
1569 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1570 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1571 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1573 wxDataViewCtrl::AppendColumn( ret
);
1578 wxDataViewColumn
*wxDataViewListCtrl::AppendIconTextColumn( const wxString
&label
,
1579 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1581 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
1583 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1584 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1585 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1587 wxDataViewCtrl::AppendColumn( ret
);
1592 void wxDataViewListCtrl::OnSize( wxSizeEvent
&event
)
1597 //-----------------------------------------------------------------------------
1598 // wxDataViewTreeStore
1599 //-----------------------------------------------------------------------------
1601 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1602 wxDataViewTreeStoreNode
*parent
,
1603 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1611 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1617 #include "wx/listimpl.cpp"
1618 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1620 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1621 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1622 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1623 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1625 m_iconExpanded
= expanded
;
1626 m_isExpanded
= false;
1627 m_children
.DeleteContents(true);
1630 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1634 //-----------------------------------------------------------------------------
1636 wxDataViewTreeStore::wxDataViewTreeStore()
1638 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1641 wxDataViewTreeStore::~wxDataViewTreeStore()
1646 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1647 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1649 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1650 if (!parent_node
) return wxDataViewItem(0);
1652 wxDataViewTreeStoreNode
*node
=
1653 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1654 parent_node
->GetChildren().Append( node
);
1656 return node
->GetItem();
1659 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1660 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1662 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1663 if (!parent_node
) return wxDataViewItem(0);
1665 wxDataViewTreeStoreNode
*node
=
1666 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1667 parent_node
->GetChildren().Insert( node
);
1669 return node
->GetItem();
1673 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& parent
,
1674 const wxDataViewItem
& previous
,
1675 const wxString
& text
,
1679 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1680 if (!parent_node
) return wxDataViewItem(0);
1682 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1683 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1684 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1686 wxDataViewTreeStoreNode
*node
=
1687 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1688 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1690 return node
->GetItem();
1693 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1694 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1695 wxClientData
*data
)
1697 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1698 if (!parent_node
) return wxDataViewItem(0);
1700 wxDataViewTreeStoreContainerNode
*node
=
1701 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1702 parent_node
->GetChildren().Insert( node
);
1704 return node
->GetItem();
1708 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1709 const wxString
&text
,
1711 const wxIcon
& expanded
,
1712 wxClientData
* data
)
1714 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1715 if (!parent_node
) return wxDataViewItem(0);
1717 wxDataViewTreeStoreContainerNode
*node
=
1718 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1719 parent_node
->GetChildren().Append( node
);
1721 return node
->GetItem();
1725 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& parent
,
1726 const wxDataViewItem
& previous
,
1727 const wxString
& text
,
1729 const wxIcon
& expanded
,
1730 wxClientData
* data
)
1732 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1733 if (!parent_node
) return wxDataViewItem(0);
1735 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1736 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1737 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1739 wxDataViewTreeStoreContainerNode
*node
=
1740 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1741 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1743 return node
->GetItem();
1746 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1748 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1749 if (!parent_node
) return wxDataViewItem(0);
1751 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1753 return node
->GetData();
1755 return wxDataViewItem(0);
1758 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1760 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1761 if (!node
) return -1;
1763 if (!node
->IsContainer())
1766 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1767 return (int) container_node
->GetChildren().GetCount();
1770 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1772 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1775 node
->SetText( text
);
1778 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1780 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1781 if (!node
) return wxEmptyString
;
1783 return node
->GetText();
1786 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1788 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1791 node
->SetIcon( icon
);
1794 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1796 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1797 if (!node
) return wxNullIcon
;
1799 return node
->GetIcon();
1802 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1804 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1807 node
->SetExpandedIcon( icon
);
1810 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1812 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1813 if (!node
) return wxNullIcon
;
1815 return node
->GetExpandedIcon();
1818 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1820 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1823 node
->SetData( data
);
1826 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
1828 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1829 if (!node
) return NULL
;
1831 return node
->GetData();
1834 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
1836 if (!item
.IsOk()) return;
1838 wxDataViewItem parent_item
= GetParent( item
);
1840 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
1841 if (!parent_node
) return;
1843 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1846 parent_node
->GetChildren().DeleteObject( node
);
1849 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
1851 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1854 node
->GetChildren().clear();
1857 void wxDataViewTreeStore::DeleteAllItems()
1863 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
1864 const wxDataViewItem
&item
,
1865 unsigned int WXUNUSED(col
)) const
1867 // if (col != 0) return;
1869 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1872 wxIcon
icon( node
->GetIcon());
1873 if (node
->IsContainer())
1875 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
1876 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
1877 icon
= container
->GetExpandedIcon();
1880 wxDataViewIconText
data( node
->GetText(), icon
);
1886 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
1887 const wxDataViewItem
& item
,
1888 unsigned int WXUNUSED(col
))
1890 // if (col != 0) return false;
1892 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1893 if (!node
) return false;
1895 wxDataViewIconText data
;
1899 node
->SetText( data
.GetText() );
1900 node
->SetIcon( data
.GetIcon() );
1905 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
1907 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1908 if (!node
) return wxDataViewItem(0);
1910 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
1911 if (!parent
) return wxDataViewItem(0);
1913 if (parent
== m_root
)
1914 return wxDataViewItem(0);
1916 return parent
->GetItem();
1919 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
&item
) const
1921 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1922 if (!node
) return false;
1924 return node
->IsContainer();
1927 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
1929 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1930 if (!node
) return 0;
1932 wxDataViewTreeStoreNodeList::iterator iter
;
1933 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1935 wxDataViewTreeStoreNode
* child
= *iter
;
1936 children
.Add( child
->GetItem() );
1939 return node
->GetChildren().GetCount();
1942 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
1943 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) )
1945 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
1946 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
1948 if (!node1
|| !node2
)
1951 wxDataViewTreeStoreContainerNode
* parent1
=
1952 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
1953 wxDataViewTreeStoreContainerNode
* parent2
=
1954 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
1956 if (parent1
!= parent2
)
1958 wxLogError( wxT("Comparing items with different parent.") );
1962 if (node1
->IsContainer() && !!node2
->IsContainer())
1965 if (node2
->IsContainer() && !!node1
->IsContainer())
1968 return parent1
->GetChildren().IndexOf( node1
) - parent1
->GetChildren().IndexOf( node2
);
1971 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
1976 return (wxDataViewTreeStoreNode
*) item
.GetID();
1979 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
1982 return (wxDataViewTreeStoreContainerNode
*) m_root
;
1984 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
1986 if (!node
->IsContainer())
1989 return (wxDataViewTreeStoreContainerNode
*) node
;
1992 //-----------------------------------------------------------------------------
1993 // wxDataViewTreeCtrl
1994 //-----------------------------------------------------------------------------
1996 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1998 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1999 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
2000 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
2001 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
2004 wxDataViewTreeCtrl::wxDataViewTreeCtrl()
2009 wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow
*parent
, wxWindowID id
,
2010 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2013 Create( parent
, id
, pos
, size
, style
, validator
);
2015 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
2016 AssociateModel( store
);
2019 AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT
,-1);
2022 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
2028 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2029 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2031 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
2034 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
2039 m_imageList
= imagelist
;
2042 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
2043 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2045 wxIcon icon
= wxNullIcon
;
2046 if (m_imageList
&& (iconIndex
!= -1))
2047 icon
= m_imageList
->GetIcon( iconIndex
);
2049 wxDataViewItem res
= GetStore()->AppendItem( parent
, text
, icon
, data
);
2051 GetStore()->ItemAdded( parent
, res
);
2056 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
2057 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2059 wxIcon icon
= wxNullIcon
;
2060 if (m_imageList
&& (iconIndex
!= -1))
2061 icon
= m_imageList
->GetIcon( iconIndex
);
2063 wxDataViewItem res
= GetStore()->PrependItem( parent
, text
, icon
, data
);
2065 GetStore()->ItemAdded( parent
, res
);
2070 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2071 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2073 wxIcon icon
= wxNullIcon
;
2074 if (m_imageList
&& (iconIndex
!= -1))
2075 icon
= m_imageList
->GetIcon( iconIndex
);
2077 wxDataViewItem res
= GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
2079 GetStore()->ItemAdded( parent
, res
);
2084 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
2085 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2087 wxIcon icon
= wxNullIcon
;
2088 if (m_imageList
&& (iconIndex
!= -1))
2089 icon
= m_imageList
->GetIcon( iconIndex
);
2091 wxIcon expanded
= wxNullIcon
;
2092 if (m_imageList
&& (expandedIndex
!= -1))
2093 expanded
= m_imageList
->GetIcon( expandedIndex
);
2095 wxDataViewItem res
= GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
2097 GetStore()->ItemAdded( parent
, res
);
2102 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
2103 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2105 wxIcon icon
= wxNullIcon
;
2106 if (m_imageList
&& (iconIndex
!= -1))
2107 icon
= m_imageList
->GetIcon( iconIndex
);
2109 wxIcon expanded
= wxNullIcon
;
2110 if (m_imageList
&& (expandedIndex
!= -1))
2111 expanded
= m_imageList
->GetIcon( expandedIndex
);
2113 wxDataViewItem res
= GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
2115 GetStore()->ItemAdded( parent
, res
);
2120 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2121 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2123 wxIcon icon
= wxNullIcon
;
2124 if (m_imageList
&& (iconIndex
!= -1))
2125 icon
= m_imageList
->GetIcon( iconIndex
);
2127 wxIcon expanded
= wxNullIcon
;
2128 if (m_imageList
&& (expandedIndex
!= -1))
2129 expanded
= m_imageList
->GetIcon( expandedIndex
);
2131 wxDataViewItem res
= GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
2133 GetStore()->ItemAdded( parent
, res
);
2138 void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2140 GetStore()->SetItemText(item
,text
);
2143 GetStore()->ValueChanged( item
, 0 );
2146 void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2148 GetStore()->SetItemIcon(item
,icon
);
2151 GetStore()->ValueChanged( item
, 0 );
2154 void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2156 GetStore()->SetItemExpandedIcon(item
,icon
);
2159 GetStore()->ValueChanged( item
, 0 );
2162 void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem
& item
)
2164 wxDataViewItem parent_item
= GetStore()->GetParent( item
);
2166 GetStore()->DeleteItem(item
);
2169 GetStore()->ItemDeleted( parent_item
, item
);
2172 void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem
& item
)
2174 wxDataViewTreeStoreContainerNode
*node
= GetStore()->FindContainerNode( item
);
2177 wxDataViewItemArray array
;
2178 wxDataViewTreeStoreNodeList::iterator iter
;
2179 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2181 wxDataViewTreeStoreNode
* child
= *iter
;
2182 array
.Add( child
->GetItem() );
2185 GetStore()->DeleteChildren( item
);
2188 GetStore()->ItemsDeleted( item
, array
);
2191 void wxDataViewTreeCtrl::DeleteAllItems()
2193 GetStore()->DeleteAllItems();
2195 GetStore()->Cleared();
2198 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
2200 if (m_imageList
) return;
2202 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2203 if (!container
) return;
2205 container
->SetExpanded( true );
2207 GetStore()->ItemChanged( event
.GetItem() );
2210 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
2212 if (m_imageList
) return;
2214 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2215 if (!container
) return;
2217 container
->SetExpanded( false );
2219 GetStore()->ItemChanged( event
.GetItem() );
2222 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
2224 #if defined(wxUSE_GENERICDATAVIEWCTRL)
2225 // automatically resize our only column to take the entire control width
2226 if ( GetColumnCount() )
2228 wxSize size
= GetClientSize();
2229 GetColumn(0)->SetWidth(size
.x
);
2235 #endif // wxUSE_DATAVIEWCTRL