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 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase
, wxObject
)
837 wxDataViewColumnBase::wxDataViewColumnBase(const wxString
& WXUNUSED(title
),
838 wxDataViewRenderer
*renderer
,
839 unsigned int model_column
,
841 wxAlignment
WXUNUSED(align
),
844 m_renderer
= renderer
;
845 m_model_column
= model_column
;
847 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
849 // NOTE: the wxDataViewColumn's ctor must store the width, align, flags
850 // parameters inside the native control!
853 wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap
& bitmap
,
854 wxDataViewRenderer
*renderer
,
855 unsigned int model_column
,
857 wxAlignment
WXUNUSED(align
),
858 int WXUNUSED(flags
) )
860 m_renderer
= renderer
;
861 m_model_column
= model_column
;
864 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
867 wxDataViewColumnBase::~wxDataViewColumnBase()
873 int wxDataViewColumnBase::GetFlags() const
878 ret
|= wxDATAVIEW_COL_SORTABLE
;
880 ret
|= wxDATAVIEW_COL_RESIZABLE
;
882 ret
|= wxDATAVIEW_COL_HIDDEN
;
887 void wxDataViewColumnBase::SetFlags(int flags
)
889 SetSortable((flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
890 SetResizeable((flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
891 SetHidden((flags
& wxDATAVIEW_COL_HIDDEN
) != 0);
892 SetReorderable((flags
& wxDATAVIEW_COL_REORDERABLE
) != 0);
895 // ---------------------------------------------------------
896 // wxDataViewCtrlBase
897 // ---------------------------------------------------------
899 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
901 wxDataViewCtrlBase::wxDataViewCtrlBase()
904 m_expander_column
= 0;
908 wxDataViewCtrlBase::~wxDataViewCtrlBase()
917 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
921 m_model
->DecRef(); // discard old model, if any
924 // add our own reference to the new model:
934 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
939 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
945 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
946 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
948 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
949 new wxDataViewTextRenderer( wxT("string"), mode
),
950 model_column
, width
, align
, flags
);
956 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
957 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
959 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
960 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
961 model_column
, width
, align
, flags
);
967 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
968 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
971 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
972 new wxDataViewToggleRenderer( wxT("bool"), mode
),
973 model_column
, width
, align
, flags
);
979 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
980 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
982 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
983 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
984 model_column
, width
, align
, flags
);
990 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
991 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
993 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
994 new wxDataViewDateRenderer( wxT("datetime"), mode
),
995 model_column
, width
, align
, flags
);
1001 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
1002 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1004 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1005 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1006 model_column
, width
, align
, flags
);
1007 AppendColumn( ret
);
1012 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1013 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1015 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1016 new wxDataViewTextRenderer( wxT("string"), mode
),
1017 model_column
, width
, align
, flags
);
1018 AppendColumn( ret
);
1023 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1024 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1026 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1027 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1028 model_column
, width
, align
, flags
);
1029 AppendColumn( ret
);
1034 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1035 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1037 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1038 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1039 model_column
, width
, align
, flags
);
1040 AppendColumn( ret
);
1045 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1046 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1048 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1049 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1050 model_column
, width
, align
, flags
);
1051 AppendColumn( ret
);
1056 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1057 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1059 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1060 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1061 model_column
, width
, align
, flags
);
1062 AppendColumn( ret
);
1067 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1068 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1070 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1071 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1072 model_column
, width
, align
, flags
);
1073 AppendColumn( ret
);
1078 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1079 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1081 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1082 new wxDataViewTextRenderer( wxT("string"), mode
),
1083 model_column
, width
, align
, flags
);
1084 PrependColumn( ret
);
1089 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1090 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1092 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1093 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1094 model_column
, width
, align
, flags
);
1095 PrependColumn( ret
);
1100 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1101 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1104 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1105 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1106 model_column
, width
, align
, flags
);
1107 PrependColumn( ret
);
1112 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1113 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1115 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1116 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1117 model_column
, width
, align
, flags
);
1118 PrependColumn( ret
);
1123 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1124 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1126 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1127 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1128 model_column
, width
, align
, flags
);
1129 PrependColumn( ret
);
1134 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1135 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1137 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1138 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1139 model_column
, width
, align
, flags
);
1140 PrependColumn( ret
);
1145 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1146 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1148 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1149 new wxDataViewTextRenderer( wxT("string"), mode
),
1150 model_column
, width
, align
, flags
);
1151 PrependColumn( ret
);
1156 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1157 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1159 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1160 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1161 model_column
, width
, align
, flags
);
1162 PrependColumn( ret
);
1167 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1168 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1170 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1171 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1172 model_column
, width
, align
, flags
);
1173 PrependColumn( ret
);
1178 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1179 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1181 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1182 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1183 model_column
, width
, align
, flags
);
1184 PrependColumn( ret
);
1189 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1190 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1192 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1193 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1194 model_column
, width
, align
, flags
);
1195 PrependColumn( ret
);
1200 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1201 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1203 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1204 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1205 model_column
, width
, align
, flags
);
1206 PrependColumn( ret
);
1211 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1213 col
->SetOwner( (wxDataViewCtrl
*) this );
1218 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1220 col
->SetOwner( (wxDataViewCtrl
*) this );
1225 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1227 col
->SetOwner( (wxDataViewCtrl
*) this );
1231 // ---------------------------------------------------------
1233 // ---------------------------------------------------------
1235 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1237 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
)
1239 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
)
1240 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
)
1241 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
)
1242 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
)
1243 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
)
1244 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
)
1245 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
)
1246 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
)
1248 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
)
1250 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
)
1251 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
)
1252 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
)
1253 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
)
1256 // -------------------------------------
1257 // wxDataViewSpinRenderer
1258 // -------------------------------------
1260 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1261 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1267 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1270 wxSize size
= labelRect
.GetSize();
1272 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1275 str
.Printf( wxT("%d"), (int) l
);
1276 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1277 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1279 size
= sc
->GetSize();
1280 wxPoint pt
= sc
->GetPosition();
1281 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1287 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1289 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1290 long l
= sc
->GetValue();
1295 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1298 str
.Printf(wxT("%d"), (int) m_data
);
1299 RenderText( str
, 0, rect
, dc
, state
);
1303 wxSize
wxDataViewSpinRenderer::GetSize() const
1305 return wxSize(80,16);
1308 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1310 m_data
= value
.GetLong();
1314 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1320 // -------------------------------------
1321 // wxDataViewChoiceRenderer
1322 // -------------------------------------
1326 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1327 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1329 m_choices
= choices
;
1332 wxControl
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1335 wxSize size
= labelRect
.GetSize();
1337 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1339 wxChoice
*c
= new wxChoice( parent
, wxID_ANY
, labelRect
.GetTopLeft(), size
, m_choices
);
1340 c
->SetStringSelection( value
.GetString() );
1345 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1347 wxChoice
*c
= (wxChoice
*) editor
;
1348 wxString s
= c
->GetStringSelection();
1353 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1355 RenderText( m_data
, 0, rect
, dc
, state
);
1359 wxSize
wxDataViewChoiceRenderer::GetSize() const
1361 return wxSize(80,16);
1364 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1366 m_data
= value
.GetString();
1370 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1378 //-----------------------------------------------------------------------------
1379 // wxDataViewTreeStore
1380 //-----------------------------------------------------------------------------
1382 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1383 wxDataViewTreeStoreNode
*parent
,
1384 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1392 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1398 #include "wx/listimpl.cpp"
1399 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1401 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1402 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1403 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1404 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1406 m_iconExpanded
= expanded
;
1407 m_isExpanded
= false;
1408 m_children
.DeleteContents(true);
1411 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1415 //-----------------------------------------------------------------------------
1417 wxDataViewTreeStore::wxDataViewTreeStore()
1419 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1422 wxDataViewTreeStore::~wxDataViewTreeStore()
1427 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1428 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1430 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1431 if (!parent_node
) return wxDataViewItem(0);
1433 wxDataViewTreeStoreNode
*node
=
1434 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1435 parent_node
->GetChildren().Append( node
);
1438 ItemAdded( parent
, node
->GetItem() );
1440 return node
->GetItem();
1443 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1444 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1446 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1447 if (!parent_node
) return wxDataViewItem(0);
1449 wxDataViewTreeStoreNode
*node
=
1450 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1451 parent_node
->GetChildren().Insert( node
);
1454 ItemAdded( parent
, node
->GetItem() );
1456 return node
->GetItem();
1460 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& WXUNUSED(parent
),
1461 const wxDataViewItem
& WXUNUSED(previous
),
1462 const wxString
& WXUNUSED(text
),
1463 const wxIcon
& WXUNUSED(icon
),
1464 wxClientData
* WXUNUSED(data
))
1466 return wxDataViewItem(0);
1469 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1470 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1471 wxClientData
*data
)
1473 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1474 if (!parent_node
) return wxDataViewItem(0);
1476 wxDataViewTreeStoreContainerNode
*node
=
1477 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1478 parent_node
->GetChildren().Insert( node
);
1481 ItemAdded( parent
, node
->GetItem() );
1483 return node
->GetItem();
1487 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1488 const wxString
&text
,
1490 const wxIcon
& expanded
,
1491 wxClientData
* data
)
1493 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1494 if (!parent_node
) return wxDataViewItem(0);
1496 wxDataViewTreeStoreContainerNode
*node
=
1497 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1498 parent_node
->GetChildren().Append( node
);
1501 ItemAdded( parent
, node
->GetItem() );
1503 return node
->GetItem();
1507 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& WXUNUSED(parent
),
1508 const wxDataViewItem
& WXUNUSED(previous
),
1509 const wxString
& WXUNUSED(text
),
1510 const wxIcon
& WXUNUSED(icon
),
1511 const wxIcon
& WXUNUSED(expanded
),
1512 wxClientData
* WXUNUSED(data
))
1514 return wxDataViewItem(0);
1517 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1519 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1520 if (!parent_node
) return wxDataViewItem(0);
1522 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1524 return node
->GetData();
1526 return wxDataViewItem(0);
1529 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1531 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1532 if (!node
) return -1;
1534 if (!node
->IsContainer())
1537 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1538 return (int) container_node
->GetChildren().GetCount();
1541 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1543 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1546 node
->SetText( text
);
1549 ValueChanged( item
, 0 );
1552 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1554 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1555 if (!node
) return wxEmptyString
;
1557 return node
->GetText();
1560 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1562 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1565 node
->SetIcon( icon
);
1568 ValueChanged( item
, 0 );
1571 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1573 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1574 if (!node
) return wxNullIcon
;
1576 return node
->GetIcon();
1579 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1581 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1584 node
->SetExpandedIcon( icon
);
1587 ValueChanged( item
, 0 );
1590 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1592 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1593 if (!node
) return wxNullIcon
;
1595 return node
->GetExpandedIcon();
1598 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1600 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1603 node
->SetData( data
);
1605 // notify control? only sensible when sorting on client data
1606 // ValueChanged( item, 0 );
1609 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
1611 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1612 if (!node
) return NULL
;
1614 return node
->GetData();
1617 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
1619 if (!item
.IsOk()) return;
1621 wxDataViewItem parent_item
= GetParent( item
);
1623 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
1624 if (!parent_node
) return;
1626 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1629 parent_node
->GetChildren().DeleteObject( node
);
1632 ItemDeleted( parent_item
, item
);
1635 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
1637 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1640 wxDataViewItemArray array
;
1641 wxDataViewTreeStoreNodeList::iterator iter
;
1642 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1644 wxDataViewTreeStoreNode
* child
= *iter
;
1645 array
.Add( child
->GetItem() );
1648 node
->GetChildren().clear();
1651 ItemsDeleted( item
, array
);
1654 void wxDataViewTreeStore::DeleteAllItems()
1660 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
1661 const wxDataViewItem
&item
,
1662 unsigned int WXUNUSED(col
)) const
1664 // if (col != 0) return;
1666 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1669 wxIcon
icon( node
->GetIcon());
1670 if (node
->IsContainer())
1672 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
1673 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
1674 icon
= container
->GetExpandedIcon();
1677 wxDataViewIconText
data( node
->GetText(), icon
);
1683 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
1684 const wxDataViewItem
& item
,
1685 unsigned int WXUNUSED(col
))
1687 // if (col != 0) return false;
1689 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1690 if (!node
) return false;
1692 wxDataViewIconText data
;
1696 node
->SetText( data
.GetText() );
1697 node
->SetIcon( data
.GetIcon() );
1702 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
1704 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1705 if (!node
) return wxDataViewItem(0);
1707 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
1708 if (!parent
) return wxDataViewItem(0);
1710 if (parent
== m_root
)
1711 return wxDataViewItem(0);
1713 return parent
->GetItem();
1716 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
&item
) const
1718 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1719 if (!node
) return false;
1721 return node
->IsContainer();
1724 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
1726 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1727 if (!node
) return 0;
1729 wxDataViewTreeStoreNodeList::iterator iter
;
1730 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1732 wxDataViewTreeStoreNode
* child
= *iter
;
1733 children
.Add( child
->GetItem() );
1736 return node
->GetChildren().GetCount();
1739 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
1740 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) )
1742 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
1743 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
1745 if (!node1
|| !node2
)
1748 wxDataViewTreeStoreContainerNode
* parent1
=
1749 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
1750 wxDataViewTreeStoreContainerNode
* parent2
=
1751 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
1753 if (parent1
!= parent2
)
1755 wxLogError( wxT("Comparing items with different parent.") );
1759 if (node1
->IsContainer() && !!node2
->IsContainer())
1762 if (node2
->IsContainer() && !!node1
->IsContainer())
1765 return parent1
->GetChildren().IndexOf( node1
) - parent1
->GetChildren().IndexOf( node2
);
1768 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
1773 return (wxDataViewTreeStoreNode
*) item
.GetID();
1776 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
1779 return (wxDataViewTreeStoreContainerNode
*) m_root
;
1781 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
1783 if (!node
->IsContainer())
1786 return (wxDataViewTreeStoreContainerNode
*) node
;
1789 //-----------------------------------------------------------------------------
1790 // wxDataViewTreeCtrl
1791 //-----------------------------------------------------------------------------
1793 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1795 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1796 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
1797 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
1798 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
1801 wxDataViewTreeCtrl::wxDataViewTreeCtrl()
1806 wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow
*parent
, wxWindowID id
,
1807 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1810 Create( parent
, id
, pos
, size
, style
, validator
);
1812 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
1813 AssociateModel( store
);
1816 AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT
,-1);
1819 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
1825 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1826 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1828 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
1831 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
1836 m_imageList
= imagelist
;
1839 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
1840 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1842 wxIcon icon
= wxNullIcon
;
1843 if (m_imageList
&& (iconIndex
!= -1))
1844 icon
= m_imageList
->GetIcon( iconIndex
);
1846 return GetStore()->AppendItem( parent
, text
, icon
, data
);
1849 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
1850 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1852 wxIcon icon
= wxNullIcon
;
1853 if (m_imageList
&& (iconIndex
!= -1))
1854 icon
= m_imageList
->GetIcon( iconIndex
);
1856 return GetStore()->PrependItem( parent
, text
, icon
, data
);
1859 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1860 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1862 wxIcon icon
= wxNullIcon
;
1863 if (m_imageList
&& (iconIndex
!= -1))
1864 icon
= m_imageList
->GetIcon( iconIndex
);
1866 return GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
1869 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
1870 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1872 wxIcon icon
= wxNullIcon
;
1873 if (m_imageList
&& (iconIndex
!= -1))
1874 icon
= m_imageList
->GetIcon( iconIndex
);
1876 wxIcon expanded
= wxNullIcon
;
1877 if (m_imageList
&& (expandedIndex
!= -1))
1878 expanded
= m_imageList
->GetIcon( expandedIndex
);
1880 return GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
1883 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
1884 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1886 wxIcon icon
= wxNullIcon
;
1887 if (m_imageList
&& (iconIndex
!= -1))
1888 icon
= m_imageList
->GetIcon( iconIndex
);
1890 wxIcon expanded
= wxNullIcon
;
1891 if (m_imageList
&& (expandedIndex
!= -1))
1892 expanded
= m_imageList
->GetIcon( expandedIndex
);
1894 return GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
1897 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1898 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1900 wxIcon icon
= wxNullIcon
;
1901 if (m_imageList
&& (iconIndex
!= -1))
1902 icon
= m_imageList
->GetIcon( iconIndex
);
1904 wxIcon expanded
= wxNullIcon
;
1905 if (m_imageList
&& (expandedIndex
!= -1))
1906 expanded
= m_imageList
->GetIcon( expandedIndex
);
1908 return GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
1911 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
1913 if (m_imageList
) return;
1915 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
1916 if (!container
) return;
1918 container
->SetExpanded( true );
1919 GetStore()->ItemChanged( event
.GetItem() );
1922 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
1924 if (m_imageList
) return;
1926 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
1927 if (!container
) return;
1929 container
->SetExpanded( false );
1930 GetStore()->ItemChanged( event
.GetItem() );
1933 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
1935 #if defined(wxUSE_GENERICDATAVIEWCTRL)
1936 wxSize size
= GetClientSize();
1937 wxDataViewColumn
*col
= GetColumn( 0 );
1939 col
->SetWidth( size
.x
);
1944 #endif // wxUSE_DATAVIEWCTRL