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"
28 #include "wx/settings.h"
34 const char wxDataViewCtrlNameStr
[] = "dataviewCtrl";
37 bool operator == (const wxDataViewItem
&left
, const wxDataViewItem
&right
)
39 return (left
.GetID() == right
.GetID() );
43 void wxDataViewItem::Print(const wxString
& text
) const
45 wxPrintf(wxT("item %s: %lu\n"), text
.GetData(), wxPtrToUInt(m_id
));
49 // ---------------------------------------------------------
50 // wxDataViewModelNotifier
51 // ---------------------------------------------------------
53 #include "wx/listimpl.cpp"
54 WX_DEFINE_LIST(wxDataViewModelNotifiers
)
56 bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
58 size_t count
= items
.GetCount();
60 for (i
= 0; i
< count
; i
++)
61 if (!ItemAdded( parent
, items
[i
] )) return false;
66 bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
68 size_t count
= items
.GetCount();
70 for (i
= 0; i
< count
; i
++)
71 if (!ItemDeleted( parent
, items
[i
] )) return false;
76 bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray
&items
)
78 size_t count
= items
.GetCount();
80 for (i
= 0; i
< count
; i
++)
81 if (!ItemChanged( items
[i
] )) return false;
86 // ---------------------------------------------------------
88 // ---------------------------------------------------------
90 wxDataViewModel::wxDataViewModel()
92 m_notifiers
.DeleteContents( true );
95 bool wxDataViewModel::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
99 wxDataViewModelNotifiers::iterator iter
;
100 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
102 wxDataViewModelNotifier
* notifier
= *iter
;
103 if (!notifier
->ItemAdded( parent
, item
))
110 bool wxDataViewModel::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
114 wxDataViewModelNotifiers::iterator iter
;
115 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
117 wxDataViewModelNotifier
* notifier
= *iter
;
118 if (!notifier
->ItemDeleted( parent
, item
))
125 bool wxDataViewModel::ItemChanged( const wxDataViewItem
&item
)
129 wxDataViewModelNotifiers::iterator iter
;
130 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
132 wxDataViewModelNotifier
* notifier
= *iter
;
133 if (!notifier
->ItemChanged( item
))
140 bool wxDataViewModel::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
144 wxDataViewModelNotifiers::iterator iter
;
145 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
147 wxDataViewModelNotifier
* notifier
= *iter
;
148 if (!notifier
->ItemsAdded( parent
, items
))
155 bool wxDataViewModel::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
159 wxDataViewModelNotifiers::iterator iter
;
160 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
162 wxDataViewModelNotifier
* notifier
= *iter
;
163 if (!notifier
->ItemsDeleted( parent
, items
))
170 bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray
&items
)
174 wxDataViewModelNotifiers::iterator iter
;
175 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
177 wxDataViewModelNotifier
* notifier
= *iter
;
178 if (!notifier
->ItemsChanged( items
))
185 bool wxDataViewModel::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
189 wxDataViewModelNotifiers::iterator iter
;
190 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
192 wxDataViewModelNotifier
* notifier
= *iter
;
193 if (!notifier
->ValueChanged( item
, col
))
200 bool wxDataViewModel::Cleared()
204 wxDataViewModelNotifiers::iterator iter
;
205 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
207 wxDataViewModelNotifier
* notifier
= *iter
;
208 if (!notifier
->Cleared())
215 void wxDataViewModel::Resort()
217 wxDataViewModelNotifiers::iterator iter
;
218 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
220 wxDataViewModelNotifier
* notifier
= *iter
;
225 void wxDataViewModel::AddNotifier( wxDataViewModelNotifier
*notifier
)
227 m_notifiers
.push_back( notifier
);
228 notifier
->SetOwner( this );
231 void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier
*notifier
)
233 m_notifiers
.DeleteObject( notifier
);
236 int wxDataViewModel::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
237 unsigned int column
, bool ascending
)
239 // sort branches before leaves
240 bool item1_is_container
= IsContainer(item1
);
241 bool item2_is_container
= IsContainer(item2
);
243 if (item1_is_container
&& !item2_is_container
)
245 if (item2_is_container
&& !item1_is_container
)
248 wxVariant value1
,value2
;
249 GetValue( value1
, item1
, column
);
250 GetValue( value2
, item2
, column
);
254 wxVariant temp
= value1
;
259 if (value1
.GetType() == wxT("string"))
261 wxString str1
= value1
.GetString();
262 wxString str2
= value2
.GetString();
263 int res
= str1
.Cmp( str2
);
267 else if (value1
.GetType() == wxT("long"))
269 long l1
= value1
.GetLong();
270 long l2
= value2
.GetLong();
275 else if (value1
.GetType() == wxT("double"))
277 double d1
= value1
.GetDouble();
278 double d2
= value2
.GetDouble();
284 else if (value1
.GetType() == wxT("datetime"))
286 wxDateTime dt1
= value1
.GetDateTime();
287 wxDateTime dt2
= value2
.GetDateTime();
288 if (dt1
.IsEarlierThan(dt2
))
290 if (dt2
.IsEarlierThan(dt1
))
294 // items must be different
295 wxUIntPtr id1
= wxPtrToUInt(item1
.GetID()),
296 id2
= wxPtrToUInt(item2
.GetID());
298 return ascending
? id1
- id2
: id2
- id1
;
301 // ---------------------------------------------------------
302 // wxDataViewIndexListModel
303 // ---------------------------------------------------------
305 static int my_sort( int *v1
, int *v2
)
311 wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size
)
313 // IDs are ordered until an item gets deleted or inserted
316 // build initial index
318 for (i
= 1; i
< initial_size
+1; i
++)
319 m_hash
.Add( wxUIntToPtr(i
) );
320 m_lastIndex
= initial_size
+ 1;
323 wxDataViewIndexListModel::~wxDataViewIndexListModel()
327 void wxDataViewIndexListModel::Reset( unsigned int new_size
)
331 // IDs are ordered until an item gets deleted or inserted
334 // build initial index
336 for (i
= 1; i
< new_size
+1; i
++)
337 m_hash
.Add( wxUIntToPtr(i
) );
338 m_lastIndex
= new_size
+ 1;
340 wxDataViewModel::Cleared();
343 void wxDataViewIndexListModel::RowPrepended()
347 unsigned int id
= m_lastIndex
++;
348 m_hash
.Insert( wxUIntToPtr(id
), 0 );
349 wxDataViewItem
item( wxUIntToPtr(id
) );
350 ItemAdded( wxDataViewItem(0), item
);
353 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
357 unsigned int id
= m_lastIndex
++;
358 m_hash
.Insert( wxUIntToPtr(id
), before
);
359 wxDataViewItem
item( wxUIntToPtr(id
) );
360 ItemAdded( wxDataViewItem(0), item
);
363 void wxDataViewIndexListModel::RowAppended()
365 unsigned int id
= m_lastIndex
++;
366 m_hash
.Add( wxUIntToPtr(id
) );
367 wxDataViewItem
item( wxUIntToPtr(id
) );
368 ItemAdded( wxDataViewItem(0), item
);
371 void wxDataViewIndexListModel::RowDeleted( unsigned int row
)
375 wxDataViewItem
item( m_hash
[row
] );
376 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
377 m_hash
.RemoveAt( row
);
380 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt
&rows
)
382 wxArrayInt sorted
= rows
;
383 sorted
.Sort( my_sort
);
387 wxDataViewItemArray array
;
389 for (i
= 0; i
< rows
.GetCount(); i
++)
391 wxDataViewItem
item( m_hash
[rows
[i
]] );
394 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
396 for (i
= 0; i
< sorted
.GetCount(); i
++)
397 m_hash
.RemoveAt( sorted
[i
] );
400 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
402 wxDataViewModel::ItemChanged( GetItem(row
) );
405 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
407 wxDataViewModel::ValueChanged( GetItem(row
), col
);
410 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
414 unsigned int pos
= wxPtrToUInt( item
.GetID() );
418 // assert for not found
419 return (unsigned int) m_hash
.Index( item
.GetID() );
422 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
424 wxASSERT( row
< m_hash
.GetCount() );
425 return wxDataViewItem( m_hash
[row
] );
428 bool wxDataViewIndexListModel::HasDefaultCompare() const
433 int wxDataViewIndexListModel::Compare(const wxDataViewItem
& item1
,
434 const wxDataViewItem
& item2
,
435 unsigned int WXUNUSED(column
),
440 unsigned int pos1
= wxPtrToUInt(item1
.GetID());
441 unsigned int pos2
= wxPtrToUInt(item2
.GetID());
450 return GetRow(item1
) - GetRow(item2
);
452 return GetRow(item2
) - GetRow(item1
);
455 void wxDataViewIndexListModel::GetValue( wxVariant
&variant
,
456 const wxDataViewItem
&item
, unsigned int col
) const
458 GetValue( variant
, GetRow(item
), col
);
461 bool wxDataViewIndexListModel::SetValue( const wxVariant
&variant
,
462 const wxDataViewItem
&item
, unsigned int col
)
464 return SetValue( variant
, GetRow(item
), col
);
467 bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
469 return GetAttr( GetRow(item
), col
, attr
);
472 wxDataViewItem
wxDataViewIndexListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
474 return wxDataViewItem(0);
477 bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem
&item
) const
479 // only the invisible root item has children
486 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
493 return m_hash
.GetCount();
496 // ---------------------------------------------------------
497 // wxDataViewVirtualListModel
498 // ---------------------------------------------------------
502 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size
)
504 m_lastIndex
= initial_size
-1;
507 wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
511 void wxDataViewVirtualListModel::Reset( unsigned int new_size
)
513 m_lastIndex
= new_size
-1;
515 wxDataViewModel::Cleared();
518 void wxDataViewVirtualListModel::RowPrepended()
521 wxDataViewItem
item( NULL
);
522 ItemAdded( wxDataViewItem(0), item
);
525 void wxDataViewVirtualListModel::RowInserted( unsigned int before
)
528 wxDataViewItem
item( wxUIntToPtr(before
) );
529 ItemAdded( wxDataViewItem(0), item
);
532 void wxDataViewVirtualListModel::RowAppended()
535 wxDataViewItem
item( wxUIntToPtr(m_lastIndex
) );
536 ItemAdded( wxDataViewItem(0), item
);
539 void wxDataViewVirtualListModel::RowDeleted( unsigned int row
)
541 wxDataViewItem
item( wxUIntToPtr(row
) );
542 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
546 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt
&rows
)
548 wxArrayInt sorted
= rows
;
549 sorted
.Sort( my_sort
);
551 wxDataViewItemArray array
;
553 for (i
= 0; i
< sorted
.GetCount(); i
++)
555 wxDataViewItem
item( wxUIntToPtr(sorted
[i
]) );
558 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
560 m_lastIndex
-= rows
.GetCount();
563 void wxDataViewVirtualListModel::RowChanged( unsigned int row
)
565 wxDataViewModel::ItemChanged( GetItem(row
) );
568 void wxDataViewVirtualListModel::RowValueChanged( unsigned int row
, unsigned int col
)
570 wxDataViewModel::ValueChanged( GetItem(row
), col
);
573 unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem
&item
) const
575 return wxPtrToUInt( item
.GetID() );
578 wxDataViewItem
wxDataViewVirtualListModel::GetItem( unsigned int row
) const
580 return wxDataViewItem( wxUIntToPtr(row
) );
583 bool wxDataViewVirtualListModel::HasDefaultCompare() const
588 int wxDataViewVirtualListModel::Compare(const wxDataViewItem
& item1
,
589 const wxDataViewItem
& item2
,
590 unsigned int WXUNUSED(column
),
593 unsigned int pos1
= wxPtrToUInt(item1
.GetID());
594 unsigned int pos2
= wxPtrToUInt(item2
.GetID());
602 void wxDataViewVirtualListModel::GetValue( wxVariant
&variant
,
603 const wxDataViewItem
&item
, unsigned int col
) const
605 GetValue( variant
, GetRow(item
), col
);
608 bool wxDataViewVirtualListModel::SetValue( const wxVariant
&variant
,
609 const wxDataViewItem
&item
, unsigned int col
)
611 return SetValue( variant
, GetRow(item
), col
);
614 bool wxDataViewVirtualListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
616 return GetAttr( GetRow(item
), col
, attr
);
619 wxDataViewItem
wxDataViewVirtualListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
621 return wxDataViewItem(0);
624 bool wxDataViewVirtualListModel::IsContainer( const wxDataViewItem
&item
) const
626 // only the invisible root item has children
633 unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem
&WXUNUSED(item
), wxDataViewItemArray
&WXUNUSED(children
) ) const
635 return 0; // should we report an error ?
640 //-----------------------------------------------------------------------------
641 // wxDataViewIconText
642 //-----------------------------------------------------------------------------
644 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
646 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
648 bool operator == (const wxDataViewIconText
&one
, const wxDataViewIconText
&two
)
650 if (one
.GetText() != two
.GetText()) return false;
651 if (one
.IsSameAs(two
)) return false;
655 // ---------------------------------------------------------
656 // wxDataViewRendererBase
657 // ---------------------------------------------------------
659 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
661 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
662 wxDataViewCellMode
WXUNUSED(mode
),
663 int WXUNUSED(align
) )
665 m_variantType
= varianttype
;
669 wxDataViewRendererBase::~wxDataViewRendererBase()
673 const wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
675 return const_cast<wxDataViewRendererBase
*>(this)->GetOwner()->GetOwner();
678 class wxKillRef
: public wxWindowRef
681 wxKillRef( wxWindow
*win
) : wxWindowRef( win
) { }
682 virtual void OnObjectDestroy()
684 get()->PopEventHandler( true );
690 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
692 m_item
= item
; // remember for later
694 unsigned int col
= GetOwner()->GetModelColumn();
696 GetOwner()->GetOwner()->GetModel()->GetValue( value
, item
, col
);
698 m_editorCtrl
= CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect
, value
);
699 (void) new wxKillRef( m_editorCtrl
.get() );
701 wxDataViewEditorCtrlEvtHandler
*handler
=
702 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
704 m_editorCtrl
->PushEventHandler( handler
);
706 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
707 handler
->SetFocusOnIdle();
709 m_editorCtrl
->SetFocus();
712 // Now we should send Editing Started event
713 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, GetOwner()->GetOwner()->GetId() );
714 event
.SetDataViewColumn( GetOwner() );
715 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
716 event
.SetItem( item
);
717 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
722 void wxDataViewRendererBase::CancelEditing()
724 if (!m_editorCtrl
) return;
726 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
728 m_editorCtrl
->Hide();
729 wxPendingDelete
.Append( m_editorCtrl
);
732 bool wxDataViewRendererBase::FinishEditing()
734 if (!m_editorCtrl
) return true;
737 GetValueFromEditorCtrl( m_editorCtrl
, value
);
739 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
741 m_editorCtrl
->Hide();
742 wxPendingDelete
.Append( m_editorCtrl
);
744 if (!Validate(value
))
747 unsigned int col
= GetOwner()->GetModelColumn();
748 GetOwner()->GetOwner()->GetModel()->SetValue( value
, m_item
, col
);
749 GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item
, col
);
751 // Now we should send Editing Done event
752 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, GetOwner()->GetOwner()->GetId() );
753 event
.SetDataViewColumn( GetOwner() );
754 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
755 event
.SetItem( m_item
);
756 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
761 //-----------------------------------------------------------------------------
762 // wxDataViewEditorCtrlEvtHandler
763 //-----------------------------------------------------------------------------
765 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
766 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
767 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
768 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
769 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
772 wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
773 wxControl
*editorCtrl
,
774 wxDataViewRenderer
*owner
)
777 m_editorCtrl
= editorCtrl
;
782 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
786 m_focusOnIdle
= false;
787 if (wxWindow::FindFocus() != m_editorCtrl
)
788 m_editorCtrl
->SetFocus();
794 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
797 m_owner
->FinishEditing();
800 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
802 switch ( event
.m_keyCode
)
806 m_owner
->FinishEditing();
812 m_owner
->CancelEditing();
820 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
825 m_owner
->FinishEditing();
831 // ---------------------------------------------------------
832 // wxDataViewColumnBase
833 // ---------------------------------------------------------
835 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
836 unsigned int model_column
)
838 m_renderer
= renderer
;
839 m_model_column
= model_column
;
841 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
844 wxDataViewColumnBase::~wxDataViewColumnBase()
849 // ---------------------------------------------------------
850 // wxDataViewCtrlBase
851 // ---------------------------------------------------------
853 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
855 wxDataViewCtrlBase::wxDataViewCtrlBase()
858 m_expander_column
= 0;
862 wxDataViewCtrlBase::~wxDataViewCtrlBase()
871 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
875 m_model
->DecRef(); // discard old model, if any
878 // add our own reference to the new model:
888 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
893 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
899 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
900 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
902 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
903 new wxDataViewTextRenderer( wxT("string"), mode
),
904 model_column
, width
, align
, flags
);
910 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
911 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
913 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
914 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
915 model_column
, width
, align
, flags
);
921 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
922 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
925 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
926 new wxDataViewToggleRenderer( wxT("bool"), mode
),
927 model_column
, width
, align
, flags
);
933 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
934 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
936 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
937 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
938 model_column
, width
, align
, flags
);
944 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
945 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
947 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
948 new wxDataViewDateRenderer( wxT("datetime"), mode
),
949 model_column
, width
, align
, flags
);
955 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
956 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
958 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
959 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
960 model_column
, width
, align
, flags
);
966 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
967 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
969 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
970 new wxDataViewTextRenderer( wxT("string"), mode
),
971 model_column
, width
, align
, flags
);
977 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
978 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
980 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
981 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
982 model_column
, width
, align
, flags
);
988 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
989 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
991 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
992 new wxDataViewToggleRenderer( wxT("bool"), mode
),
993 model_column
, width
, align
, flags
);
999 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1000 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1002 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1003 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1004 model_column
, width
, align
, flags
);
1005 AppendColumn( ret
);
1010 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1011 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1013 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1014 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1015 model_column
, width
, align
, flags
);
1016 AppendColumn( ret
);
1021 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1022 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1024 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1025 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1026 model_column
, width
, align
, flags
);
1027 AppendColumn( ret
);
1032 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1033 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1035 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1036 new wxDataViewTextRenderer( wxT("string"), mode
),
1037 model_column
, width
, align
, flags
);
1038 PrependColumn( ret
);
1043 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1044 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1046 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1047 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1048 model_column
, width
, align
, flags
);
1049 PrependColumn( ret
);
1054 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1055 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1058 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1059 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1060 model_column
, width
, align
, flags
);
1061 PrependColumn( ret
);
1066 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1067 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1069 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1070 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1071 model_column
, width
, align
, flags
);
1072 PrependColumn( ret
);
1077 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1078 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1080 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1081 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1082 model_column
, width
, align
, flags
);
1083 PrependColumn( ret
);
1088 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1089 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1091 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1092 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1093 model_column
, width
, align
, flags
);
1094 PrependColumn( ret
);
1099 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1100 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1102 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1103 new wxDataViewTextRenderer( wxT("string"), mode
),
1104 model_column
, width
, align
, flags
);
1105 PrependColumn( ret
);
1110 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1111 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1113 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1114 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1115 model_column
, width
, align
, flags
);
1116 PrependColumn( ret
);
1121 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1122 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1124 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1125 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1126 model_column
, width
, align
, flags
);
1127 PrependColumn( ret
);
1132 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1133 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1135 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1136 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1137 model_column
, width
, align
, flags
);
1138 PrependColumn( ret
);
1143 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1144 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1146 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1147 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1148 model_column
, width
, align
, flags
);
1149 PrependColumn( ret
);
1154 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1155 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1157 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1158 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1159 model_column
, width
, align
, flags
);
1160 PrependColumn( ret
);
1165 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1167 col
->SetOwner( (wxDataViewCtrl
*) this );
1172 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1174 col
->SetOwner( (wxDataViewCtrl
*) this );
1179 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1181 col
->SetOwner( (wxDataViewCtrl
*) this );
1185 // ---------------------------------------------------------
1187 // ---------------------------------------------------------
1189 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1191 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
)
1193 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
)
1194 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
)
1195 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
)
1196 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
)
1197 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
)
1198 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
)
1199 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
)
1200 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
)
1202 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
)
1204 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
)
1205 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
)
1206 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
)
1207 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
)
1210 // -------------------------------------
1211 // wxDataViewSpinRenderer
1212 // -------------------------------------
1214 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1215 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1221 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1224 wxSize size
= labelRect
.GetSize();
1226 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1229 str
.Printf( wxT("%d"), (int) l
);
1230 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1231 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1233 size
= sc
->GetSize();
1234 wxPoint pt
= sc
->GetPosition();
1235 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1241 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1243 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1244 long l
= sc
->GetValue();
1249 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1252 str
.Printf(wxT("%d"), (int) m_data
);
1253 RenderText( str
, 0, rect
, dc
, state
);
1257 wxSize
wxDataViewSpinRenderer::GetSize() const
1259 return wxSize(80,16);
1262 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1264 m_data
= value
.GetLong();
1268 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1274 // -------------------------------------
1275 // wxDataViewChoiceRenderer
1276 // -------------------------------------
1280 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1281 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1283 m_choices
= choices
;
1286 wxControl
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1289 wxSize size
= labelRect
.GetSize();
1291 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1293 wxChoice
*c
= new wxChoice( parent
, wxID_ANY
, labelRect
.GetTopLeft(), size
, m_choices
);
1294 c
->SetStringSelection( value
.GetString() );
1299 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1301 wxChoice
*c
= (wxChoice
*) editor
;
1302 wxString s
= c
->GetStringSelection();
1307 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1309 RenderText( m_data
, 0, rect
, dc
, state
);
1313 wxSize
wxDataViewChoiceRenderer::GetSize() const
1315 return wxSize(80,16);
1318 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1320 m_data
= value
.GetString();
1324 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1332 //-----------------------------------------------------------------------------
1333 // wxDataViewTreeStore
1334 //-----------------------------------------------------------------------------
1336 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1337 wxDataViewTreeStoreNode
*parent
,
1338 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1346 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1352 #include "wx/listimpl.cpp"
1353 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1355 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1356 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1357 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1358 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1360 m_iconExpanded
= expanded
;
1361 m_isExpanded
= false;
1362 m_children
.DeleteContents(true);
1365 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1369 //-----------------------------------------------------------------------------
1371 wxDataViewTreeStore::wxDataViewTreeStore()
1373 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1376 wxDataViewTreeStore::~wxDataViewTreeStore()
1381 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1382 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1384 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1385 if (!parent_node
) return wxDataViewItem(0);
1387 wxDataViewTreeStoreNode
*node
=
1388 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1389 parent_node
->GetChildren().Append( node
);
1392 ItemAdded( parent
, node
->GetItem() );
1394 return node
->GetItem();
1397 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1398 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1400 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1401 if (!parent_node
) return wxDataViewItem(0);
1403 wxDataViewTreeStoreNode
*node
=
1404 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1405 parent_node
->GetChildren().Insert( node
);
1408 ItemAdded( parent
, node
->GetItem() );
1410 return node
->GetItem();
1414 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& WXUNUSED(parent
),
1415 const wxDataViewItem
& WXUNUSED(previous
),
1416 const wxString
& WXUNUSED(text
),
1417 const wxIcon
& WXUNUSED(icon
),
1418 wxClientData
* WXUNUSED(data
))
1420 return wxDataViewItem(0);
1423 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1424 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1425 wxClientData
*data
)
1427 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1428 if (!parent_node
) return wxDataViewItem(0);
1430 wxDataViewTreeStoreContainerNode
*node
=
1431 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1432 parent_node
->GetChildren().Insert( node
);
1435 ItemAdded( parent
, node
->GetItem() );
1437 return node
->GetItem();
1441 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1442 const wxString
&text
,
1444 const wxIcon
& expanded
,
1445 wxClientData
* data
)
1447 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1448 if (!parent_node
) return wxDataViewItem(0);
1450 wxDataViewTreeStoreContainerNode
*node
=
1451 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1452 parent_node
->GetChildren().Append( node
);
1455 ItemAdded( parent
, node
->GetItem() );
1457 return node
->GetItem();
1461 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& WXUNUSED(parent
),
1462 const wxDataViewItem
& WXUNUSED(previous
),
1463 const wxString
& WXUNUSED(text
),
1464 const wxIcon
& WXUNUSED(icon
),
1465 const wxIcon
& WXUNUSED(expanded
),
1466 wxClientData
* WXUNUSED(data
))
1468 return wxDataViewItem(0);
1471 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1473 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1474 if (!parent_node
) return wxDataViewItem(0);
1476 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1478 return node
->GetData();
1480 return wxDataViewItem(0);
1483 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1485 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1486 if (!node
) return -1;
1488 if (!node
->IsContainer())
1491 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1492 return (int) container_node
->GetChildren().GetCount();
1495 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1497 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1500 node
->SetText( text
);
1503 ValueChanged( item
, 0 );
1506 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1508 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1509 if (!node
) return wxEmptyString
;
1511 return node
->GetText();
1514 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1516 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1519 node
->SetIcon( icon
);
1522 ValueChanged( item
, 0 );
1525 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1527 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1528 if (!node
) return wxNullIcon
;
1530 return node
->GetIcon();
1533 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1535 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1538 node
->SetExpandedIcon( icon
);
1541 ValueChanged( item
, 0 );
1544 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1546 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1547 if (!node
) return wxNullIcon
;
1549 return node
->GetExpandedIcon();
1552 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1554 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1557 node
->SetData( data
);
1559 // notify control? only sensible when sorting on client data
1560 // ValueChanged( item, 0 );
1563 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
1565 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1566 if (!node
) return NULL
;
1568 return node
->GetData();
1571 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
1573 if (!item
.IsOk()) return;
1575 wxDataViewItem parent_item
= GetParent( item
);
1577 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
1578 if (!parent_node
) return;
1580 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1583 parent_node
->GetChildren().DeleteObject( node
);
1586 ItemDeleted( parent_item
, item
);
1589 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
1591 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1594 wxDataViewItemArray array
;
1595 wxDataViewTreeStoreNodeList::iterator iter
;
1596 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1598 wxDataViewTreeStoreNode
* child
= *iter
;
1599 array
.Add( child
->GetItem() );
1602 node
->GetChildren().clear();
1605 ItemsDeleted( item
, array
);
1608 void wxDataViewTreeStore::DeleteAllItems()
1614 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
1615 const wxDataViewItem
&item
,
1616 unsigned int WXUNUSED(col
)) const
1618 // if (col != 0) return;
1620 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1623 wxIcon
icon( node
->GetIcon());
1624 if (node
->IsContainer())
1626 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
1627 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
1628 icon
= container
->GetExpandedIcon();
1631 wxDataViewIconText
data( node
->GetText(), icon
);
1637 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
1638 const wxDataViewItem
& item
,
1639 unsigned int WXUNUSED(col
))
1641 // if (col != 0) return false;
1643 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1644 if (!node
) return false;
1646 wxDataViewIconText data
;
1650 node
->SetText( data
.GetText() );
1651 node
->SetIcon( data
.GetIcon() );
1656 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
1658 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1659 if (!node
) return wxDataViewItem(0);
1661 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
1662 if (!parent
) return wxDataViewItem(0);
1664 if (parent
== m_root
)
1665 return wxDataViewItem(0);
1667 return parent
->GetItem();
1670 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
&item
) const
1672 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1673 if (!node
) return false;
1675 return node
->IsContainer();
1678 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
1680 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1681 if (!node
) return 0;
1683 wxDataViewTreeStoreNodeList::iterator iter
;
1684 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1686 wxDataViewTreeStoreNode
* child
= *iter
;
1687 children
.Add( child
->GetItem() );
1690 return node
->GetChildren().GetCount();
1693 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
1694 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) )
1696 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
1697 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
1699 if (!node1
|| !node2
)
1702 wxDataViewTreeStoreContainerNode
* parent1
=
1703 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
1704 wxDataViewTreeStoreContainerNode
* parent2
=
1705 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
1707 if (parent1
!= parent2
)
1709 wxLogError( wxT("Comparing items with different parent.") );
1713 if (node1
->IsContainer() && !!node2
->IsContainer())
1716 if (node2
->IsContainer() && !!node1
->IsContainer())
1719 return parent1
->GetChildren().IndexOf( node1
) - parent1
->GetChildren().IndexOf( node2
);
1722 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
1727 return (wxDataViewTreeStoreNode
*) item
.GetID();
1730 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
1733 return (wxDataViewTreeStoreContainerNode
*) m_root
;
1735 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
1737 if (!node
->IsContainer())
1740 return (wxDataViewTreeStoreContainerNode
*) node
;
1743 //-----------------------------------------------------------------------------
1744 // wxDataViewTreeCtrl
1745 //-----------------------------------------------------------------------------
1747 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1749 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1750 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
1751 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
1752 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
1755 wxDataViewTreeCtrl::wxDataViewTreeCtrl()
1760 wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow
*parent
, wxWindowID id
,
1761 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1764 Create( parent
, id
, pos
, size
, style
, validator
);
1766 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
1767 AssociateModel( store
);
1770 AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT
,-1);
1773 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
1779 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1780 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1782 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
1785 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
1790 m_imageList
= imagelist
;
1793 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
1794 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1796 wxIcon icon
= wxNullIcon
;
1797 if (m_imageList
&& (iconIndex
!= -1))
1798 icon
= m_imageList
->GetIcon( iconIndex
);
1800 return GetStore()->AppendItem( parent
, text
, icon
, data
);
1803 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
1804 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1806 wxIcon icon
= wxNullIcon
;
1807 if (m_imageList
&& (iconIndex
!= -1))
1808 icon
= m_imageList
->GetIcon( iconIndex
);
1810 return GetStore()->PrependItem( parent
, text
, icon
, data
);
1813 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1814 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1816 wxIcon icon
= wxNullIcon
;
1817 if (m_imageList
&& (iconIndex
!= -1))
1818 icon
= m_imageList
->GetIcon( iconIndex
);
1820 return GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
1823 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
1824 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1826 wxIcon icon
= wxNullIcon
;
1827 if (m_imageList
&& (iconIndex
!= -1))
1828 icon
= m_imageList
->GetIcon( iconIndex
);
1830 wxIcon expanded
= wxNullIcon
;
1831 if (m_imageList
&& (expandedIndex
!= -1))
1832 expanded
= m_imageList
->GetIcon( expandedIndex
);
1834 return GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
1837 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
1838 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1840 wxIcon icon
= wxNullIcon
;
1841 if (m_imageList
&& (iconIndex
!= -1))
1842 icon
= m_imageList
->GetIcon( iconIndex
);
1844 wxIcon expanded
= wxNullIcon
;
1845 if (m_imageList
&& (expandedIndex
!= -1))
1846 expanded
= m_imageList
->GetIcon( expandedIndex
);
1848 return GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
1851 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1852 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1854 wxIcon icon
= wxNullIcon
;
1855 if (m_imageList
&& (iconIndex
!= -1))
1856 icon
= m_imageList
->GetIcon( iconIndex
);
1858 wxIcon expanded
= wxNullIcon
;
1859 if (m_imageList
&& (expandedIndex
!= -1))
1860 expanded
= m_imageList
->GetIcon( expandedIndex
);
1862 return GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
1865 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
1867 if (m_imageList
) return;
1869 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
1870 if (!container
) return;
1872 container
->SetExpanded( true );
1873 GetStore()->ItemChanged( event
.GetItem() );
1876 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
1878 if (m_imageList
) return;
1880 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
1881 if (!container
) return;
1883 container
->SetExpanded( false );
1884 GetStore()->ItemChanged( event
.GetItem() );
1887 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
1889 #if defined(wxUSE_GENERICDATAVIEWCTRL)
1890 // automatically resize our only column to take the entire control width
1891 if ( GetColumnCount() )
1893 wxSize size
= GetClientSize();
1894 GetColumn(0)->SetWidth(size
.x
);
1900 #endif // wxUSE_DATAVIEWCTRL