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"
23 #include "wx/weakref.h"
27 #include "wx/settings.h"
33 const wxChar wxDataViewCtrlNameStr
[] = wxT("dataviewCtrl");
36 bool operator == (const wxDataViewItem
&left
, const wxDataViewItem
&right
)
38 return (left
.GetID() == right
.GetID() );
42 void wxDataViewItem::Print(const wxString
& text
) const
44 wxPrintf(wxT("item %s: %lu\n"), text
.GetData(), wxPtrToUInt(m_id
));
48 // ---------------------------------------------------------
49 // wxDataViewModelNotifier
50 // ---------------------------------------------------------
52 #include "wx/listimpl.cpp"
53 WX_DEFINE_LIST(wxDataViewModelNotifiers
)
55 bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
57 size_t count
= items
.GetCount();
59 for (i
= 0; i
< count
; i
++)
60 if (!ItemAdded( parent
, items
[i
] )) return false;
65 bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
67 size_t count
= items
.GetCount();
69 for (i
= 0; i
< count
; i
++)
70 if (!ItemDeleted( parent
, items
[i
] )) return false;
75 bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray
&items
)
77 size_t count
= items
.GetCount();
79 for (i
= 0; i
< count
; i
++)
80 if (!ItemChanged( items
[i
] )) return false;
85 // ---------------------------------------------------------
87 // ---------------------------------------------------------
89 wxDataViewModel::wxDataViewModel()
91 m_notifiers
.DeleteContents( true );
94 bool wxDataViewModel::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
98 wxDataViewModelNotifiers::iterator iter
;
99 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
101 wxDataViewModelNotifier
* notifier
= *iter
;
102 if (!notifier
->ItemAdded( parent
, item
))
109 bool wxDataViewModel::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
113 wxDataViewModelNotifiers::iterator iter
;
114 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
116 wxDataViewModelNotifier
* notifier
= *iter
;
117 if (!notifier
->ItemDeleted( parent
, item
))
124 bool wxDataViewModel::ItemChanged( const wxDataViewItem
&item
)
128 wxDataViewModelNotifiers::iterator iter
;
129 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
131 wxDataViewModelNotifier
* notifier
= *iter
;
132 if (!notifier
->ItemChanged( item
))
139 bool wxDataViewModel::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
143 wxDataViewModelNotifiers::iterator iter
;
144 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
146 wxDataViewModelNotifier
* notifier
= *iter
;
147 if (!notifier
->ItemsAdded( parent
, items
))
154 bool wxDataViewModel::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
158 wxDataViewModelNotifiers::iterator iter
;
159 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
161 wxDataViewModelNotifier
* notifier
= *iter
;
162 if (!notifier
->ItemsDeleted( parent
, items
))
169 bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray
&items
)
173 wxDataViewModelNotifiers::iterator iter
;
174 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
176 wxDataViewModelNotifier
* notifier
= *iter
;
177 if (!notifier
->ItemsChanged( items
))
184 bool wxDataViewModel::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
188 wxDataViewModelNotifiers::iterator iter
;
189 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
191 wxDataViewModelNotifier
* notifier
= *iter
;
192 if (!notifier
->ValueChanged( item
, col
))
199 bool wxDataViewModel::Cleared()
203 wxDataViewModelNotifiers::iterator iter
;
204 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
206 wxDataViewModelNotifier
* notifier
= *iter
;
207 if (!notifier
->Cleared())
214 void wxDataViewModel::Resort()
216 wxDataViewModelNotifiers::iterator iter
;
217 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
219 wxDataViewModelNotifier
* notifier
= *iter
;
224 void wxDataViewModel::AddNotifier( wxDataViewModelNotifier
*notifier
)
226 m_notifiers
.push_back( notifier
);
227 notifier
->SetOwner( this );
230 void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier
*notifier
)
232 m_notifiers
.DeleteObject( notifier
);
235 int wxDataViewModel::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
236 unsigned int column
, bool ascending
)
238 // sort branches before leaves
239 bool item1_is_container
= IsContainer(item1
);
240 bool item2_is_container
= IsContainer(item2
);
242 if (item1_is_container
&& !item2_is_container
)
244 if (item2_is_container
&& !item1_is_container
)
247 wxVariant value1
,value2
;
248 GetValue( value1
, item1
, column
);
249 GetValue( value2
, item2
, column
);
253 wxVariant temp
= value1
;
258 if (value1
.GetType() == wxT("string"))
260 wxString str1
= value1
.GetString();
261 wxString str2
= value2
.GetString();
262 int res
= str1
.Cmp( str2
);
266 else if (value1
.GetType() == wxT("long"))
268 long l1
= value1
.GetLong();
269 long l2
= value2
.GetLong();
274 else if (value1
.GetType() == wxT("double"))
276 double d1
= value1
.GetDouble();
277 double d2
= value2
.GetDouble();
283 else if (value1
.GetType() == wxT("datetime"))
285 wxDateTime dt1
= value1
.GetDateTime();
286 wxDateTime dt2
= value2
.GetDateTime();
287 if (dt1
.IsEarlierThan(dt2
))
289 if (dt2
.IsEarlierThan(dt1
))
293 // items must be different
294 wxUIntPtr id1
= wxPtrToUInt(item1
.GetID()),
295 id2
= wxPtrToUInt(item2
.GetID());
297 return ascending
? id1
- id2
: id2
- id1
;
300 // ---------------------------------------------------------
301 // wxDataViewIndexListModel
302 // ---------------------------------------------------------
304 static int my_sort( int *v1
, int *v2
)
310 wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size
)
312 // IDs are ordered until an item gets deleted or inserted
315 // build initial index
317 for (i
= 1; i
< initial_size
+1; i
++)
318 m_hash
.Add( wxUIntToPtr(i
) );
319 m_lastIndex
= initial_size
+ 1;
322 wxDataViewIndexListModel::~wxDataViewIndexListModel()
326 void wxDataViewIndexListModel::Reset( unsigned int new_size
)
330 // IDs are ordered until an item gets deleted or inserted
333 // build initial index
335 for (i
= 1; i
< new_size
+1; i
++)
336 m_hash
.Add( wxUIntToPtr(i
) );
337 m_lastIndex
= new_size
+ 1;
339 wxDataViewModel::Cleared();
342 void wxDataViewIndexListModel::RowPrepended()
346 unsigned int id
= m_lastIndex
++;
347 m_hash
.Insert( wxUIntToPtr(id
), 0 );
348 wxDataViewItem
item( wxUIntToPtr(id
) );
349 ItemAdded( wxDataViewItem(0), item
);
352 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
356 unsigned int id
= m_lastIndex
++;
357 m_hash
.Insert( wxUIntToPtr(id
), before
);
358 wxDataViewItem
item( wxUIntToPtr(id
) );
359 ItemAdded( wxDataViewItem(0), item
);
362 void wxDataViewIndexListModel::RowAppended()
364 unsigned int id
= m_lastIndex
++;
365 m_hash
.Add( wxUIntToPtr(id
) );
366 wxDataViewItem
item( wxUIntToPtr(id
) );
367 ItemAdded( wxDataViewItem(0), item
);
370 void wxDataViewIndexListModel::RowDeleted( unsigned int row
)
374 wxDataViewItem
item( m_hash
[row
] );
375 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
376 m_hash
.RemoveAt( row
);
379 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt
&rows
)
381 wxArrayInt sorted
= rows
;
382 sorted
.Sort( my_sort
);
386 wxDataViewItemArray array
;
388 for (i
= 0; i
< rows
.GetCount(); i
++)
390 wxDataViewItem
item( m_hash
[rows
[i
]] );
393 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
395 for (i
= 0; i
< sorted
.GetCount(); i
++)
396 m_hash
.RemoveAt( sorted
[i
] );
399 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
401 wxDataViewModel::ItemChanged( GetItem(row
) );
404 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
406 wxDataViewModel::ValueChanged( GetItem(row
), col
);
409 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
413 unsigned int pos
= wxPtrToUInt( item
.GetID() );
417 // assert for not found
418 return (unsigned int) m_hash
.Index( item
.GetID() );
421 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
423 wxASSERT( row
< m_hash
.GetCount() );
424 return wxDataViewItem( m_hash
[row
] );
427 bool wxDataViewIndexListModel::HasDefaultCompare() const
432 int wxDataViewIndexListModel::Compare(const wxDataViewItem
& item1
,
433 const wxDataViewItem
& item2
,
434 unsigned int WXUNUSED(column
),
439 unsigned int pos1
= wxPtrToUInt(item1
.GetID());
440 unsigned int pos2
= wxPtrToUInt(item2
.GetID());
449 return GetRow(item1
) - GetRow(item2
);
451 return GetRow(item2
) - GetRow(item1
);
454 void wxDataViewIndexListModel::GetValue( wxVariant
&variant
,
455 const wxDataViewItem
&item
, unsigned int col
) const
457 GetValue( variant
, GetRow(item
), col
);
460 bool wxDataViewIndexListModel::SetValue( const wxVariant
&variant
,
461 const wxDataViewItem
&item
, unsigned int col
)
463 return SetValue( variant
, GetRow(item
), col
);
466 bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
468 return GetAttr( GetRow(item
), col
, attr
);
471 wxDataViewItem
wxDataViewIndexListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
473 return wxDataViewItem(0);
476 bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem
&item
) const
478 // only the invisible root item has children
485 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
492 return m_hash
.GetCount();
495 // ---------------------------------------------------------
496 // wxDataViewVirtualListModel
497 // ---------------------------------------------------------
501 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size
)
503 m_lastIndex
= initial_size
-1;
506 wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
510 void wxDataViewVirtualListModel::Reset( unsigned int new_size
)
512 m_lastIndex
= new_size
-1;
514 wxDataViewModel::Cleared();
517 void wxDataViewVirtualListModel::RowPrepended()
520 wxDataViewItem
item( NULL
);
521 ItemAdded( wxDataViewItem(0), item
);
524 void wxDataViewVirtualListModel::RowInserted( unsigned int before
)
527 wxDataViewItem
item( wxUIntToPtr(before
) );
528 ItemAdded( wxDataViewItem(0), item
);
531 void wxDataViewVirtualListModel::RowAppended()
534 wxDataViewItem
item( wxUIntToPtr(m_lastIndex
) );
535 ItemAdded( wxDataViewItem(0), item
);
538 void wxDataViewVirtualListModel::RowDeleted( unsigned int row
)
540 wxDataViewItem
item( wxUIntToPtr(row
) );
541 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
545 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt
&rows
)
547 wxArrayInt sorted
= rows
;
548 sorted
.Sort( my_sort
);
550 wxDataViewItemArray array
;
552 for (i
= 0; i
< sorted
.GetCount(); i
++)
554 wxDataViewItem
item( wxUIntToPtr(sorted
[i
]) );
557 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
559 m_lastIndex
-= rows
.GetCount();
562 void wxDataViewVirtualListModel::RowChanged( unsigned int row
)
564 wxDataViewModel::ItemChanged( GetItem(row
) );
567 void wxDataViewVirtualListModel::RowValueChanged( unsigned int row
, unsigned int col
)
569 wxDataViewModel::ValueChanged( GetItem(row
), col
);
572 unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem
&item
) const
574 return wxPtrToUInt( item
.GetID() );
577 wxDataViewItem
wxDataViewVirtualListModel::GetItem( unsigned int row
) const
579 return wxDataViewItem( wxUIntToPtr(row
) );
582 bool wxDataViewVirtualListModel::HasDefaultCompare() const
587 int wxDataViewVirtualListModel::Compare(const wxDataViewItem
& item1
,
588 const wxDataViewItem
& item2
,
589 unsigned int WXUNUSED(column
),
592 unsigned int pos1
= wxPtrToUInt(item1
.GetID());
593 unsigned int pos2
= wxPtrToUInt(item2
.GetID());
601 void wxDataViewVirtualListModel::GetValue( wxVariant
&variant
,
602 const wxDataViewItem
&item
, unsigned int col
) const
604 GetValue( variant
, GetRow(item
), col
);
607 bool wxDataViewVirtualListModel::SetValue( const wxVariant
&variant
,
608 const wxDataViewItem
&item
, unsigned int col
)
610 return SetValue( variant
, GetRow(item
), col
);
613 bool wxDataViewVirtualListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
615 return GetAttr( GetRow(item
), col
, attr
);
618 wxDataViewItem
wxDataViewVirtualListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
620 return wxDataViewItem(0);
623 bool wxDataViewVirtualListModel::IsContainer( const wxDataViewItem
&item
) const
625 // only the invisible root item has children
632 unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem
&WXUNUSED(item
), wxDataViewItemArray
&WXUNUSED(children
) ) const
634 return 0; // should we report an error ?
639 //-----------------------------------------------------------------------------
640 // wxDataViewIconText
641 //-----------------------------------------------------------------------------
643 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
645 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
647 bool operator == (const wxDataViewIconText
&one
, const wxDataViewIconText
&two
)
649 if (one
.GetText() != two
.GetText()) return false;
650 if (one
.IsSameAs(two
)) return false;
654 // ---------------------------------------------------------
655 // wxDataViewRendererBase
656 // ---------------------------------------------------------
658 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
660 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
661 wxDataViewCellMode
WXUNUSED(mode
),
662 int WXUNUSED(align
) )
664 m_variantType
= varianttype
;
668 wxDataViewRendererBase::~wxDataViewRendererBase()
672 const wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
674 return const_cast<wxDataViewRendererBase
*>(this)->GetOwner()->GetOwner();
677 class wxKillRef
: public wxWindowRef
680 wxKillRef( wxWindow
*win
) : wxWindowRef( win
) { }
681 virtual void OnObjectDestroy()
683 get()->PopEventHandler( true );
689 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
691 m_item
= item
; // remember for later
693 unsigned int col
= GetOwner()->GetModelColumn();
695 GetOwner()->GetOwner()->GetModel()->GetValue( value
, item
, col
);
697 m_editorCtrl
= CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect
, value
);
698 (void) new wxKillRef( m_editorCtrl
.get() );
700 wxDataViewEditorCtrlEvtHandler
*handler
=
701 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
703 m_editorCtrl
->PushEventHandler( handler
);
705 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
706 handler
->SetFocusOnIdle();
708 m_editorCtrl
->SetFocus();
711 // Now we should send Editing Started event
712 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, GetOwner()->GetOwner()->GetId() );
713 event
.SetDataViewColumn( GetOwner() );
714 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
715 event
.SetItem( item
);
716 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
721 void wxDataViewRendererBase::CancelEditing()
723 if (!m_editorCtrl
) return;
725 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
727 m_editorCtrl
->Hide();
728 wxPendingDelete
.Append( m_editorCtrl
);
731 bool wxDataViewRendererBase::FinishEditing()
733 if (!m_editorCtrl
) return true;
736 GetValueFromEditorCtrl( m_editorCtrl
, value
);
738 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
740 m_editorCtrl
->Hide();
741 wxPendingDelete
.Append( m_editorCtrl
);
743 if (!Validate(value
))
746 unsigned int col
= GetOwner()->GetModelColumn();
747 GetOwner()->GetOwner()->GetModel()->SetValue( value
, m_item
, col
);
748 GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item
, col
);
750 // Now we should send Editing Done event
751 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, GetOwner()->GetOwner()->GetId() );
752 event
.SetDataViewColumn( GetOwner() );
753 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
754 event
.SetItem( m_item
);
755 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
760 //-----------------------------------------------------------------------------
761 // wxDataViewEditorCtrlEvtHandler
762 //-----------------------------------------------------------------------------
764 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
765 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
766 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
767 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
768 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
771 wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
772 wxControl
*editorCtrl
,
773 wxDataViewRenderer
*owner
)
776 m_editorCtrl
= editorCtrl
;
781 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
785 m_focusOnIdle
= false;
786 if (wxWindow::FindFocus() != m_editorCtrl
)
787 m_editorCtrl
->SetFocus();
793 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
796 m_owner
->FinishEditing();
799 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
801 switch ( event
.m_keyCode
)
805 m_owner
->FinishEditing();
811 m_owner
->CancelEditing();
819 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
824 m_owner
->FinishEditing();
830 // ---------------------------------------------------------
831 // wxDataViewColumnBase
832 // ---------------------------------------------------------
834 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase
, wxObject
)
836 wxDataViewColumnBase::wxDataViewColumnBase(const wxString
& WXUNUSED(title
),
837 wxDataViewRenderer
*renderer
,
838 unsigned int model_column
,
840 wxAlignment
WXUNUSED(align
),
843 m_renderer
= renderer
;
844 m_model_column
= model_column
;
846 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
848 // NOTE: the wxDataViewColumn's ctor must store the width, align, flags
849 // parameters inside the native control!
852 wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap
& bitmap
,
853 wxDataViewRenderer
*renderer
,
854 unsigned int model_column
,
856 wxAlignment
WXUNUSED(align
),
857 int WXUNUSED(flags
) )
859 m_renderer
= renderer
;
860 m_model_column
= model_column
;
863 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
866 wxDataViewColumnBase::~wxDataViewColumnBase()
872 int wxDataViewColumnBase::GetFlags() const
877 ret
|= wxDATAVIEW_COL_SORTABLE
;
879 ret
|= wxDATAVIEW_COL_RESIZABLE
;
881 ret
|= wxDATAVIEW_COL_HIDDEN
;
886 void wxDataViewColumnBase::SetFlags(int flags
)
888 SetSortable((flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
889 SetResizeable((flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
890 SetHidden((flags
& wxDATAVIEW_COL_HIDDEN
) != 0);
891 SetReorderable((flags
& wxDATAVIEW_COL_REORDERABLE
) != 0);
894 // ---------------------------------------------------------
895 // wxDataViewCtrlBase
896 // ---------------------------------------------------------
898 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
900 wxDataViewCtrlBase::wxDataViewCtrlBase()
903 m_expander_column
= 0;
907 wxDataViewCtrlBase::~wxDataViewCtrlBase()
916 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
920 m_model
->DecRef(); // discard old model, if any
923 // add our own reference to the new model:
933 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
938 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
944 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
945 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
947 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
948 new wxDataViewTextRenderer( wxT("string"), mode
),
949 model_column
, width
, align
, flags
);
955 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
956 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
958 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
959 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
960 model_column
, width
, align
, flags
);
966 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
967 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
970 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
971 new wxDataViewToggleRenderer( wxT("bool"), mode
),
972 model_column
, width
, align
, flags
);
978 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
979 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
981 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
982 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
983 model_column
, width
, align
, flags
);
989 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
990 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
992 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
993 new wxDataViewDateRenderer( wxT("datetime"), mode
),
994 model_column
, width
, align
, flags
);
1000 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
1001 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1003 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1004 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1005 model_column
, width
, align
, flags
);
1006 AppendColumn( ret
);
1011 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1012 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1014 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1015 new wxDataViewTextRenderer( wxT("string"), mode
),
1016 model_column
, width
, align
, flags
);
1017 AppendColumn( ret
);
1022 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1023 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1025 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1026 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1027 model_column
, width
, align
, flags
);
1028 AppendColumn( ret
);
1033 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1034 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1036 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1037 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1038 model_column
, width
, align
, flags
);
1039 AppendColumn( ret
);
1044 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1045 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1047 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1048 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1049 model_column
, width
, align
, flags
);
1050 AppendColumn( ret
);
1055 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1056 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1058 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1059 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1060 model_column
, width
, align
, flags
);
1061 AppendColumn( ret
);
1066 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1067 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1069 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1070 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1071 model_column
, width
, align
, flags
);
1072 AppendColumn( ret
);
1077 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1078 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1080 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1081 new wxDataViewTextRenderer( wxT("string"), mode
),
1082 model_column
, width
, align
, flags
);
1083 PrependColumn( ret
);
1088 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1089 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1091 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1092 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1093 model_column
, width
, align
, flags
);
1094 PrependColumn( ret
);
1099 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1100 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1103 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1104 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1105 model_column
, width
, align
, flags
);
1106 PrependColumn( ret
);
1111 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1112 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1114 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1115 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1116 model_column
, width
, align
, flags
);
1117 PrependColumn( ret
);
1122 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1123 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1125 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1126 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1127 model_column
, width
, align
, flags
);
1128 PrependColumn( ret
);
1133 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1134 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1136 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1137 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1138 model_column
, width
, align
, flags
);
1139 PrependColumn( ret
);
1144 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1145 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1147 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1148 new wxDataViewTextRenderer( wxT("string"), mode
),
1149 model_column
, width
, align
, flags
);
1150 PrependColumn( ret
);
1155 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1156 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1158 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1159 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1160 model_column
, width
, align
, flags
);
1161 PrependColumn( ret
);
1166 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1167 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1169 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1170 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1171 model_column
, width
, align
, flags
);
1172 PrependColumn( ret
);
1177 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1178 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1180 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1181 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1182 model_column
, width
, align
, flags
);
1183 PrependColumn( ret
);
1188 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1189 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1191 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1192 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1193 model_column
, width
, align
, flags
);
1194 PrependColumn( ret
);
1199 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1200 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1202 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1203 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1204 model_column
, width
, align
, flags
);
1205 PrependColumn( ret
);
1210 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1212 col
->SetOwner( (wxDataViewCtrl
*) this );
1217 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1219 col
->SetOwner( (wxDataViewCtrl
*) this );
1224 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1226 col
->SetOwner( (wxDataViewCtrl
*) this );
1230 // ---------------------------------------------------------
1232 // ---------------------------------------------------------
1234 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1236 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
)
1238 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
)
1239 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
)
1240 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
)
1241 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
)
1242 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
)
1243 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
)
1244 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
)
1245 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
)
1247 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
)
1249 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
)
1250 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
)
1251 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
)
1252 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
)
1255 // -------------------------------------
1256 // wxDataViewSpinRenderer
1257 // -------------------------------------
1259 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1260 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1266 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1269 wxSize size
= labelRect
.GetSize();
1271 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1274 str
.Printf( wxT("%d"), (int) l
);
1275 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1276 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1278 size
= sc
->GetSize();
1279 wxPoint pt
= sc
->GetPosition();
1280 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1286 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1288 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1289 long l
= sc
->GetValue();
1294 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1297 str
.Printf(wxT("%d"), (int) m_data
);
1298 RenderText( str
, 0, rect
, dc
, state
);
1302 wxSize
wxDataViewSpinRenderer::GetSize() const
1304 return wxSize(80,16);
1307 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1309 m_data
= value
.GetLong();
1313 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1319 //-----------------------------------------------------------------------------
1320 // wxDataViewTreeStore
1321 //-----------------------------------------------------------------------------
1323 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1324 wxDataViewTreeStoreNode
*parent
,
1325 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1333 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1339 #include "wx/listimpl.cpp"
1340 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1342 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1343 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1344 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1345 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1347 m_iconExpanded
= expanded
;
1348 m_isExpanded
= false;
1349 m_children
.DeleteContents(true);
1352 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1356 //-----------------------------------------------------------------------------
1358 wxDataViewTreeStore::wxDataViewTreeStore()
1360 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1363 wxDataViewTreeStore::~wxDataViewTreeStore()
1368 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1369 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1371 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1372 if (!parent_node
) return wxDataViewItem(0);
1374 wxDataViewTreeStoreNode
*node
=
1375 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1376 parent_node
->GetChildren().Append( node
);
1379 ItemAdded( parent
, node
->GetItem() );
1381 return node
->GetItem();
1384 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1385 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1387 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1388 if (!parent_node
) return wxDataViewItem(0);
1390 wxDataViewTreeStoreNode
*node
=
1391 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1392 parent_node
->GetChildren().Insert( node
);
1395 ItemAdded( parent
, node
->GetItem() );
1397 return node
->GetItem();
1401 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& WXUNUSED(parent
),
1402 const wxDataViewItem
& WXUNUSED(previous
),
1403 const wxString
& WXUNUSED(text
),
1404 const wxIcon
& WXUNUSED(icon
),
1405 wxClientData
* WXUNUSED(data
))
1407 return wxDataViewItem(0);
1410 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1411 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1412 wxClientData
*data
)
1414 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1415 if (!parent_node
) return wxDataViewItem(0);
1417 wxDataViewTreeStoreContainerNode
*node
=
1418 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1419 parent_node
->GetChildren().Insert( node
);
1422 ItemAdded( parent
, node
->GetItem() );
1424 return node
->GetItem();
1428 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1429 const wxString
&text
,
1431 const wxIcon
& expanded
,
1432 wxClientData
* data
)
1434 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1435 if (!parent_node
) return wxDataViewItem(0);
1437 wxDataViewTreeStoreContainerNode
*node
=
1438 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1439 parent_node
->GetChildren().Append( node
);
1442 ItemAdded( parent
, node
->GetItem() );
1444 return node
->GetItem();
1448 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& WXUNUSED(parent
),
1449 const wxDataViewItem
& WXUNUSED(previous
),
1450 const wxString
& WXUNUSED(text
),
1451 const wxIcon
& WXUNUSED(icon
),
1452 const wxIcon
& WXUNUSED(expanded
),
1453 wxClientData
* WXUNUSED(data
))
1455 return wxDataViewItem(0);
1458 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1460 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1461 if (!parent_node
) return wxDataViewItem(0);
1463 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1465 return node
->GetData();
1467 return wxDataViewItem(0);
1470 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1472 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1473 if (!node
) return -1;
1475 if (!node
->IsContainer())
1478 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1479 return (int) container_node
->GetChildren().GetCount();
1482 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1484 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1487 node
->SetText( text
);
1490 ValueChanged( item
, 0 );
1493 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1495 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1496 if (!node
) return wxEmptyString
;
1498 return node
->GetText();
1501 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1503 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1506 node
->SetIcon( icon
);
1509 ValueChanged( item
, 0 );
1512 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1514 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1515 if (!node
) return wxNullIcon
;
1517 return node
->GetIcon();
1520 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1522 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1525 node
->SetExpandedIcon( icon
);
1528 ValueChanged( item
, 0 );
1531 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1533 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1534 if (!node
) return wxNullIcon
;
1536 return node
->GetExpandedIcon();
1539 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1541 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1544 node
->SetData( data
);
1546 // notify control? only sensible when sorting on client data
1547 // ValueChanged( item, 0 );
1550 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
1552 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1553 if (!node
) return NULL
;
1555 return node
->GetData();
1558 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
1560 if (!item
.IsOk()) return;
1562 wxDataViewItem parent_item
= GetParent( item
);
1564 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
1565 if (!parent_node
) return;
1567 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1570 parent_node
->GetChildren().DeleteObject( node
);
1573 ItemDeleted( parent_item
, item
);
1576 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
1578 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1581 wxDataViewItemArray array
;
1582 wxDataViewTreeStoreNodeList::iterator iter
;
1583 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1585 wxDataViewTreeStoreNode
* child
= *iter
;
1586 array
.Add( child
->GetItem() );
1589 node
->GetChildren().clear();
1592 ItemsDeleted( item
, array
);
1595 void wxDataViewTreeStore::DeleteAllItems()
1601 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
1602 const wxDataViewItem
&item
,
1603 unsigned int WXUNUSED(col
)) const
1605 // if (col != 0) return;
1607 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1610 wxIcon
icon( node
->GetIcon());
1611 if (node
->IsContainer())
1613 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
1614 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
1615 icon
= container
->GetExpandedIcon();
1618 wxDataViewIconText
data( node
->GetText(), icon
);
1624 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
1625 const wxDataViewItem
& item
,
1626 unsigned int WXUNUSED(col
))
1628 // if (col != 0) return false;
1630 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1631 if (!node
) return false;
1633 wxDataViewIconText data
;
1637 node
->SetText( data
.GetText() );
1638 node
->SetIcon( data
.GetIcon() );
1643 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
1645 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1646 if (!node
) return wxDataViewItem(0);
1648 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
1649 if (!parent
) return wxDataViewItem(0);
1651 if (parent
== m_root
)
1652 return wxDataViewItem(0);
1654 return parent
->GetItem();
1657 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
&item
) const
1659 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1660 if (!node
) return false;
1662 return node
->IsContainer();
1665 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
1667 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1668 if (!node
) return 0;
1670 wxDataViewTreeStoreNodeList::iterator iter
;
1671 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1673 wxDataViewTreeStoreNode
* child
= *iter
;
1674 children
.Add( child
->GetItem() );
1677 return node
->GetChildren().GetCount();
1680 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
1681 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) )
1683 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
1684 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
1686 if (!node1
|| !node2
)
1689 wxDataViewTreeStoreContainerNode
* parent1
=
1690 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
1691 wxDataViewTreeStoreContainerNode
* parent2
=
1692 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
1694 if (parent1
!= parent2
)
1696 wxLogError( wxT("Comparing items with different parent.") );
1700 if (node1
->IsContainer() && !!node2
->IsContainer())
1703 if (node2
->IsContainer() && !!node1
->IsContainer())
1706 return parent1
->GetChildren().IndexOf( node1
) - parent1
->GetChildren().IndexOf( node2
);
1709 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
1714 return (wxDataViewTreeStoreNode
*) item
.GetID();
1717 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
1720 return (wxDataViewTreeStoreContainerNode
*) m_root
;
1722 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
1724 if (!node
->IsContainer())
1727 return (wxDataViewTreeStoreContainerNode
*) node
;
1730 //-----------------------------------------------------------------------------
1731 // wxDataViewTreeCtrl
1732 //-----------------------------------------------------------------------------
1734 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1736 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1737 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
1738 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
1739 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
1742 wxDataViewTreeCtrl::wxDataViewTreeCtrl()
1747 wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow
*parent
, wxWindowID id
,
1748 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1751 Create( parent
, id
, pos
, size
, style
, validator
);
1753 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
1754 AssociateModel( store
);
1757 AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT
,-1);
1760 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
1766 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1767 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
1769 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
1772 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
1777 m_imageList
= imagelist
;
1780 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
1781 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1783 wxIcon icon
= wxNullIcon
;
1784 if (m_imageList
&& (iconIndex
!= -1))
1785 icon
= m_imageList
->GetIcon( iconIndex
);
1787 return GetStore()->AppendItem( parent
, text
, icon
, data
);
1790 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
1791 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1793 wxIcon icon
= wxNullIcon
;
1794 if (m_imageList
&& (iconIndex
!= -1))
1795 icon
= m_imageList
->GetIcon( iconIndex
);
1797 return GetStore()->PrependItem( parent
, text
, icon
, data
);
1800 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1801 const wxString
&text
, int iconIndex
, wxClientData
*data
)
1803 wxIcon icon
= wxNullIcon
;
1804 if (m_imageList
&& (iconIndex
!= -1))
1805 icon
= m_imageList
->GetIcon( iconIndex
);
1807 return GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
1810 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
1811 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1813 wxIcon icon
= wxNullIcon
;
1814 if (m_imageList
&& (iconIndex
!= -1))
1815 icon
= m_imageList
->GetIcon( iconIndex
);
1817 wxIcon expanded
= wxNullIcon
;
1818 if (m_imageList
&& (expandedIndex
!= -1))
1819 expanded
= m_imageList
->GetIcon( expandedIndex
);
1821 return GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
1824 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
1825 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1827 wxIcon icon
= wxNullIcon
;
1828 if (m_imageList
&& (iconIndex
!= -1))
1829 icon
= m_imageList
->GetIcon( iconIndex
);
1831 wxIcon expanded
= wxNullIcon
;
1832 if (m_imageList
&& (expandedIndex
!= -1))
1833 expanded
= m_imageList
->GetIcon( expandedIndex
);
1835 return GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
1838 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
1839 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
1841 wxIcon icon
= wxNullIcon
;
1842 if (m_imageList
&& (iconIndex
!= -1))
1843 icon
= m_imageList
->GetIcon( iconIndex
);
1845 wxIcon expanded
= wxNullIcon
;
1846 if (m_imageList
&& (expandedIndex
!= -1))
1847 expanded
= m_imageList
->GetIcon( expandedIndex
);
1849 return GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
1852 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
1854 if (m_imageList
) return;
1856 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
1857 if (!container
) return;
1859 container
->SetExpanded( true );
1860 GetStore()->ItemChanged( event
.GetItem() );
1863 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
1865 if (m_imageList
) return;
1867 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
1868 if (!container
) return;
1870 container
->SetExpanded( false );
1871 GetStore()->ItemChanged( event
.GetItem() );
1874 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
1876 #if defined(wxUSE_GENERICDATAVIEWCTRL)
1877 wxSize size
= GetClientSize();
1878 wxDataViewColumn
*col
= GetColumn( 0 );
1880 col
->SetWidth( size
.x
);
1885 #endif // wxUSE_DATAVIEWCTRL