1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/datavcmn.cpp
3 // Purpose: wxDataViewCtrl base classes and common parts
4 // Author: Robert Roebling
7 // Copyright: (c) 2006, Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_DATAVIEWCTRL
20 #include "wx/dataview.h"
24 #include "wx/settings.h"
29 #include "wx/spinctrl.h"
30 #include "wx/choice.h"
31 #include "wx/imaglist.h"
33 const char wxDataViewCtrlNameStr
[] = "dataviewCtrl";
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 GetValueByRow( variant
, GetRow(item
), col
);
460 bool wxDataViewIndexListModel::SetValue( const wxVariant
&variant
,
461 const wxDataViewItem
&item
, unsigned int col
)
463 return SetValueByRow( variant
, GetRow(item
), col
);
466 bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
468 return GetAttrByRow( 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 GetValueByRow( variant
, GetRow(item
), col
);
607 bool wxDataViewVirtualListModel::SetValue( const wxVariant
&variant
,
608 const wxDataViewItem
&item
, unsigned int col
)
610 return SetValueByRow( variant
, GetRow(item
), col
);
613 bool wxDataViewVirtualListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
615 return GetAttrByRow( 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 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
835 unsigned int model_column
)
837 m_renderer
= renderer
;
838 m_model_column
= model_column
;
840 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
843 wxDataViewColumnBase::~wxDataViewColumnBase()
848 // ---------------------------------------------------------
849 // wxDataViewCtrlBase
850 // ---------------------------------------------------------
852 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
854 wxDataViewCtrlBase::wxDataViewCtrlBase()
857 m_expander_column
= 0;
861 wxDataViewCtrlBase::~wxDataViewCtrlBase()
870 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
874 m_model
->DecRef(); // discard old model, if any
877 // add our own reference to the new model:
887 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
892 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
897 void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem
& item
)
899 if (!m_model
) return;
901 if (!item
.IsOk()) return;
903 wxVector
<wxDataViewItem
> parentChain
;
905 // at first we get all the parents of the selected item
906 wxDataViewItem parent
= m_model
->GetParent(item
);
907 while (parent
.IsOk())
909 parentChain
.push_back(parent
);
910 parent
= m_model
->GetParent(parent
);
913 // then we expand the parents, starting at the root
914 while (!parentChain
.empty())
916 Expand(parentChain
.back());
917 parentChain
.pop_back();
922 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
923 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
925 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
926 new wxDataViewTextRenderer( wxT("string"), mode
),
927 model_column
, width
, align
, flags
);
933 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
934 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
936 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
937 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
938 model_column
, width
, align
, flags
);
944 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
945 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
947 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
948 new wxDataViewToggleRenderer( wxT("bool"), mode
),
949 model_column
, width
, align
, flags
);
955 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
956 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
958 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
959 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
960 model_column
, width
, align
, flags
);
966 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
967 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
969 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
970 new wxDataViewDateRenderer( wxT("datetime"), mode
),
971 model_column
, width
, align
, flags
);
977 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
978 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
980 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
981 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
982 model_column
, width
, align
, flags
);
988 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
989 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
991 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
992 new wxDataViewTextRenderer( wxT("string"), mode
),
993 model_column
, width
, align
, flags
);
999 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1000 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1002 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1003 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1004 model_column
, width
, align
, flags
);
1005 AppendColumn( ret
);
1010 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1011 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1013 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1014 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1015 model_column
, width
, align
, flags
);
1016 AppendColumn( ret
);
1021 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1022 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1024 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1025 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1026 model_column
, width
, align
, flags
);
1027 AppendColumn( ret
);
1032 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1033 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1035 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1036 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1037 model_column
, width
, align
, flags
);
1038 AppendColumn( ret
);
1043 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1044 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1046 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1047 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1048 model_column
, width
, align
, flags
);
1049 AppendColumn( ret
);
1054 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1055 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1057 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1058 new wxDataViewTextRenderer( wxT("string"), mode
),
1059 model_column
, width
, align
, flags
);
1060 PrependColumn( ret
);
1065 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1066 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1068 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1069 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1070 model_column
, width
, align
, flags
);
1071 PrependColumn( ret
);
1076 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1077 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1080 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1081 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1082 model_column
, width
, align
, flags
);
1083 PrependColumn( ret
);
1088 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1089 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1091 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1092 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1093 model_column
, width
, align
, flags
);
1094 PrependColumn( ret
);
1099 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1100 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1102 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1103 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1104 model_column
, width
, align
, flags
);
1105 PrependColumn( ret
);
1110 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1111 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1113 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1114 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1115 model_column
, width
, align
, flags
);
1116 PrependColumn( ret
);
1121 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1122 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1124 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1125 new wxDataViewTextRenderer( wxT("string"), mode
),
1126 model_column
, width
, align
, flags
);
1127 PrependColumn( ret
);
1132 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1133 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1135 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1136 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1137 model_column
, width
, align
, flags
);
1138 PrependColumn( ret
);
1143 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1144 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1146 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1147 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1148 model_column
, width
, align
, flags
);
1149 PrependColumn( ret
);
1154 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1155 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1157 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1158 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1159 model_column
, width
, align
, flags
);
1160 PrependColumn( ret
);
1165 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1166 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1168 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1169 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1170 model_column
, width
, align
, flags
);
1171 PrependColumn( ret
);
1176 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1177 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1179 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1180 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1181 model_column
, width
, align
, flags
);
1182 PrependColumn( ret
);
1187 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1189 col
->SetOwner( (wxDataViewCtrl
*) this );
1194 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1196 col
->SetOwner( (wxDataViewCtrl
*) this );
1201 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1203 col
->SetOwner( (wxDataViewCtrl
*) this );
1207 // ---------------------------------------------------------
1209 // ---------------------------------------------------------
1211 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1213 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
);
1215 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
);
1216 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
);
1217 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
);
1218 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
);
1219 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
);
1220 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
);
1221 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
);
1222 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
);
1224 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
);
1226 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
);
1227 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
);
1228 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
);
1229 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
);
1231 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
);
1232 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, wxDataViewEvent
);
1233 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, wxDataViewEvent
);
1235 // -------------------------------------
1236 // wxDataViewSpinRenderer
1237 // -------------------------------------
1239 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1240 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1246 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1249 wxSize size
= labelRect
.GetSize();
1251 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1254 str
.Printf( wxT("%d"), (int) l
);
1255 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1256 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1258 size
= sc
->GetSize();
1259 wxPoint pt
= sc
->GetPosition();
1260 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1266 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1268 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1269 long l
= sc
->GetValue();
1274 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1277 str
.Printf(wxT("%d"), (int) m_data
);
1278 RenderText( str
, 0, rect
, dc
, state
);
1282 wxSize
wxDataViewSpinRenderer::GetSize() const
1284 return wxSize(80,16);
1287 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1289 m_data
= value
.GetLong();
1293 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1299 // -------------------------------------
1300 // wxDataViewChoiceRenderer
1301 // -------------------------------------
1303 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXMAC__)
1305 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1306 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1308 m_choices
= choices
;
1311 wxControl
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1314 wxSize size
= labelRect
.GetSize();
1316 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1318 wxChoice
*c
= new wxChoice( parent
, wxID_ANY
, labelRect
.GetTopLeft(), size
, m_choices
);
1319 c
->SetStringSelection( value
.GetString() );
1324 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1326 wxChoice
*c
= (wxChoice
*) editor
;
1327 wxString s
= c
->GetStringSelection();
1332 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1334 RenderText( m_data
, 0, rect
, dc
, state
);
1338 wxSize
wxDataViewChoiceRenderer::GetSize() const
1340 return wxSize(80,16);
1343 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1345 m_data
= value
.GetString();
1349 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1357 //-----------------------------------------------------------------------------
1358 // wxDataViewListStore
1359 //-----------------------------------------------------------------------------
1361 wxDataViewListStore::wxDataViewListStore()
1365 wxDataViewListStore::~wxDataViewListStore()
1367 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1368 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1370 wxDataViewListStoreLine
* line
= *it
;
1375 void wxDataViewListStore::PrependColumn( const wxString
&varianttype
)
1377 m_cols
.Insert( varianttype
, 0 );
1380 void wxDataViewListStore::InsertColumn( unsigned int pos
, const wxString
&varianttype
)
1382 m_cols
.Insert( varianttype
, pos
);
1385 void wxDataViewListStore::AppendColumn( const wxString
&varianttype
)
1387 m_cols
.Add( varianttype
);
1390 unsigned int wxDataViewListStore::GetColumnCount() const
1392 return m_cols
.GetCount();
1395 wxString
wxDataViewListStore::GetColumnType( unsigned int pos
) const
1400 void wxDataViewListStore::AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1402 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1403 line
->m_values
= values
;
1404 m_data
.push_back( line
);
1409 void wxDataViewListStore::PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1411 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1412 line
->m_values
= values
;
1413 m_data
.insert( m_data
.begin(), line
);
1418 void wxDataViewListStore::InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1420 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1421 line
->m_values
= values
;
1422 m_data
.insert( m_data
.begin()+row
, line
);
1427 void wxDataViewListStore::DeleteItem( unsigned row
)
1429 wxVector
<wxDataViewListStoreLine
*>::iterator it
= m_data
.begin() + row
;
1435 void wxDataViewListStore::DeleteAllItems()
1437 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1438 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1440 wxDataViewListStoreLine
* line
= *it
;
1447 void wxDataViewListStore::GetValueByRow( wxVariant
&value
, unsigned int row
, unsigned int col
) const
1449 wxDataViewListStoreLine
*line
= m_data
[row
];
1450 value
= line
->m_values
[col
];
1453 bool wxDataViewListStore::SetValueByRow( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1455 wxDataViewListStoreLine
*line
= m_data
[row
];
1456 line
->m_values
[col
] = value
;
1461 //-----------------------------------------------------------------------------
1462 // wxDataViewListCtrl
1463 //-----------------------------------------------------------------------------
1465 IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl
,wxDataViewCtrl
)
1467 BEGIN_EVENT_TABLE(wxDataViewListCtrl
,wxDataViewCtrl
)
1468 EVT_SIZE( wxDataViewListCtrl::OnSize
)
1471 wxDataViewListCtrl::wxDataViewListCtrl()
1475 wxDataViewListCtrl::wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
1476 const wxPoint
& pos
, const wxSize
& size
, long style
,
1477 const wxValidator
& validator
)
1479 Create( parent
, id
, pos
, size
, style
, validator
);
1481 wxDataViewListStore
*store
= new wxDataViewListStore
;
1482 AssociateModel( store
);
1486 wxDataViewListCtrl::~wxDataViewListCtrl()
1491 bool wxDataViewListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1492 const wxPoint
& pos
, const wxSize
& size
, long style
,
1493 const wxValidator
& validator
)
1495 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
1498 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1500 GetStore()->AppendColumn( varianttype
);
1501 return wxDataViewCtrl::AppendColumn( column
);
1504 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1506 GetStore()->PrependColumn( varianttype
);
1507 return wxDataViewCtrl::PrependColumn( column
);
1510 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
)
1512 GetStore()->InsertColumn( pos
, varianttype
);
1513 return wxDataViewCtrl::InsertColumn( pos
, column
);
1516 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*col
)
1518 return PrependColumn( col
, "string" );
1521 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
1523 return InsertColumn( pos
, col
, "string" );
1526 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*col
)
1528 return AppendColumn( col
, "string" );
1531 wxDataViewColumn
*wxDataViewListCtrl::AppendTextColumn( const wxString
&label
,
1532 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1534 GetStore()->AppendColumn( wxT("string") );
1536 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1537 new wxDataViewTextRenderer( wxT("string"), mode
),
1538 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1540 wxDataViewCtrl::AppendColumn( ret
);
1545 wxDataViewColumn
*wxDataViewListCtrl::AppendToggleColumn( const wxString
&label
,
1546 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1548 GetStore()->AppendColumn( wxT("bool") );
1550 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1551 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1552 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1554 wxDataViewCtrl::AppendColumn( ret
);
1559 wxDataViewColumn
*wxDataViewListCtrl::AppendProgressColumn( const wxString
&label
,
1560 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1562 GetStore()->AppendColumn( wxT("long") );
1564 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1565 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1566 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1568 wxDataViewCtrl::AppendColumn( ret
);
1573 wxDataViewColumn
*wxDataViewListCtrl::AppendIconTextColumn( const wxString
&label
,
1574 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1576 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
1578 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1579 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1580 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1582 wxDataViewCtrl::AppendColumn( ret
);
1587 void wxDataViewListCtrl::OnSize( wxSizeEvent
&event
)
1592 //-----------------------------------------------------------------------------
1593 // wxDataViewTreeStore
1594 //-----------------------------------------------------------------------------
1596 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1597 wxDataViewTreeStoreNode
*parent
,
1598 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1606 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1612 #include "wx/listimpl.cpp"
1613 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1615 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1616 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1617 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1618 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1620 m_iconExpanded
= expanded
;
1621 m_isExpanded
= false;
1622 m_children
.DeleteContents(true);
1625 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1629 //-----------------------------------------------------------------------------
1631 wxDataViewTreeStore::wxDataViewTreeStore()
1633 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1636 wxDataViewTreeStore::~wxDataViewTreeStore()
1641 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1642 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1644 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1645 if (!parent_node
) return wxDataViewItem(0);
1647 wxDataViewTreeStoreNode
*node
=
1648 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1649 parent_node
->GetChildren().Append( node
);
1651 return node
->GetItem();
1654 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1655 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1657 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1658 if (!parent_node
) return wxDataViewItem(0);
1660 wxDataViewTreeStoreNode
*node
=
1661 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1662 parent_node
->GetChildren().Insert( node
);
1664 return node
->GetItem();
1668 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& parent
,
1669 const wxDataViewItem
& previous
,
1670 const wxString
& text
,
1674 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1675 if (!parent_node
) return wxDataViewItem(0);
1677 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1678 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1679 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1681 wxDataViewTreeStoreNode
*node
=
1682 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1683 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1685 return node
->GetItem();
1688 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1689 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1690 wxClientData
*data
)
1692 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1693 if (!parent_node
) return wxDataViewItem(0);
1695 wxDataViewTreeStoreContainerNode
*node
=
1696 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1697 parent_node
->GetChildren().Insert( node
);
1699 return node
->GetItem();
1703 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1704 const wxString
&text
,
1706 const wxIcon
& expanded
,
1707 wxClientData
* data
)
1709 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1710 if (!parent_node
) return wxDataViewItem(0);
1712 wxDataViewTreeStoreContainerNode
*node
=
1713 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1714 parent_node
->GetChildren().Append( node
);
1716 return node
->GetItem();
1720 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& parent
,
1721 const wxDataViewItem
& previous
,
1722 const wxString
& text
,
1724 const wxIcon
& expanded
,
1725 wxClientData
* data
)
1727 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1728 if (!parent_node
) return wxDataViewItem(0);
1730 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1731 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1732 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1734 wxDataViewTreeStoreContainerNode
*node
=
1735 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1736 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1738 return node
->GetItem();
1741 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1743 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1744 if (!parent_node
) return wxDataViewItem(0);
1746 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1748 return node
->GetData();
1750 return wxDataViewItem(0);
1753 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1755 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1756 if (!node
) return -1;
1758 if (!node
->IsContainer())
1761 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1762 return (int) container_node
->GetChildren().GetCount();
1765 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1767 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1770 node
->SetText( text
);
1773 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1775 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1776 if (!node
) return wxEmptyString
;
1778 return node
->GetText();
1781 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1783 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1786 node
->SetIcon( icon
);
1789 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1791 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1792 if (!node
) return wxNullIcon
;
1794 return node
->GetIcon();
1797 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1799 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1802 node
->SetExpandedIcon( icon
);
1805 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1807 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1808 if (!node
) return wxNullIcon
;
1810 return node
->GetExpandedIcon();
1813 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1815 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1818 node
->SetData( data
);
1821 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
1823 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1824 if (!node
) return NULL
;
1826 return node
->GetData();
1829 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
1831 if (!item
.IsOk()) return;
1833 wxDataViewItem parent_item
= GetParent( item
);
1835 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
1836 if (!parent_node
) return;
1838 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1841 parent_node
->GetChildren().DeleteObject( node
);
1844 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
1846 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1849 node
->GetChildren().clear();
1852 void wxDataViewTreeStore::DeleteAllItems()
1858 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
1859 const wxDataViewItem
&item
,
1860 unsigned int WXUNUSED(col
)) const
1862 // if (col != 0) return;
1864 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1867 wxIcon
icon( node
->GetIcon());
1868 if (node
->IsContainer())
1870 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
1871 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
1872 icon
= container
->GetExpandedIcon();
1875 wxDataViewIconText
data( node
->GetText(), icon
);
1881 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
1882 const wxDataViewItem
& item
,
1883 unsigned int WXUNUSED(col
))
1885 // if (col != 0) return false;
1887 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1888 if (!node
) return false;
1890 wxDataViewIconText data
;
1894 node
->SetText( data
.GetText() );
1895 node
->SetIcon( data
.GetIcon() );
1900 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
1902 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1903 if (!node
) return wxDataViewItem(0);
1905 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
1906 if (!parent
) return wxDataViewItem(0);
1908 if (parent
== m_root
)
1909 return wxDataViewItem(0);
1911 return parent
->GetItem();
1914 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
&item
) const
1916 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1917 if (!node
) return false;
1919 return node
->IsContainer();
1922 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
1924 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1925 if (!node
) return 0;
1927 wxDataViewTreeStoreNodeList::iterator iter
;
1928 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1930 wxDataViewTreeStoreNode
* child
= *iter
;
1931 children
.Add( child
->GetItem() );
1934 return node
->GetChildren().GetCount();
1937 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
1938 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) )
1940 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
1941 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
1943 if (!node1
|| !node2
)
1946 wxDataViewTreeStoreContainerNode
* parent1
=
1947 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
1948 wxDataViewTreeStoreContainerNode
* parent2
=
1949 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
1951 if (parent1
!= parent2
)
1953 wxLogError( wxT("Comparing items with different parent.") );
1957 if (node1
->IsContainer() && !!node2
->IsContainer())
1960 if (node2
->IsContainer() && !!node1
->IsContainer())
1963 return parent1
->GetChildren().IndexOf( node1
) - parent1
->GetChildren().IndexOf( node2
);
1966 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
1971 return (wxDataViewTreeStoreNode
*) item
.GetID();
1974 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
1977 return (wxDataViewTreeStoreContainerNode
*) m_root
;
1979 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
1981 if (!node
->IsContainer())
1984 return (wxDataViewTreeStoreContainerNode
*) node
;
1987 //-----------------------------------------------------------------------------
1988 // wxDataViewTreeCtrl
1989 //-----------------------------------------------------------------------------
1991 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1993 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1994 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
1995 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
1996 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
1999 wxDataViewTreeCtrl::wxDataViewTreeCtrl()
2004 wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow
*parent
, wxWindowID id
,
2005 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2008 Create( parent
, id
, pos
, size
, style
, validator
);
2010 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
2011 AssociateModel( store
);
2014 AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT
,-1);
2017 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
2023 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2024 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2026 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
2029 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
2034 m_imageList
= imagelist
;
2037 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
2038 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2040 wxIcon icon
= wxNullIcon
;
2041 if (m_imageList
&& (iconIndex
!= -1))
2042 icon
= m_imageList
->GetIcon( iconIndex
);
2044 wxDataViewItem res
= GetStore()->AppendItem( parent
, text
, icon
, data
);
2046 GetStore()->ItemAdded( parent
, res
);
2051 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
2052 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2054 wxIcon icon
= wxNullIcon
;
2055 if (m_imageList
&& (iconIndex
!= -1))
2056 icon
= m_imageList
->GetIcon( iconIndex
);
2058 wxDataViewItem res
= GetStore()->PrependItem( parent
, text
, icon
, data
);
2060 GetStore()->ItemAdded( parent
, res
);
2065 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2066 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2068 wxIcon icon
= wxNullIcon
;
2069 if (m_imageList
&& (iconIndex
!= -1))
2070 icon
= m_imageList
->GetIcon( iconIndex
);
2072 wxDataViewItem res
= GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
2074 GetStore()->ItemAdded( parent
, res
);
2079 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
2080 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2082 wxIcon icon
= wxNullIcon
;
2083 if (m_imageList
&& (iconIndex
!= -1))
2084 icon
= m_imageList
->GetIcon( iconIndex
);
2086 wxIcon expanded
= wxNullIcon
;
2087 if (m_imageList
&& (expandedIndex
!= -1))
2088 expanded
= m_imageList
->GetIcon( expandedIndex
);
2090 wxDataViewItem res
= GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
2092 GetStore()->ItemAdded( parent
, res
);
2097 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
2098 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2100 wxIcon icon
= wxNullIcon
;
2101 if (m_imageList
&& (iconIndex
!= -1))
2102 icon
= m_imageList
->GetIcon( iconIndex
);
2104 wxIcon expanded
= wxNullIcon
;
2105 if (m_imageList
&& (expandedIndex
!= -1))
2106 expanded
= m_imageList
->GetIcon( expandedIndex
);
2108 wxDataViewItem res
= GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
2110 GetStore()->ItemAdded( parent
, res
);
2115 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2116 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2118 wxIcon icon
= wxNullIcon
;
2119 if (m_imageList
&& (iconIndex
!= -1))
2120 icon
= m_imageList
->GetIcon( iconIndex
);
2122 wxIcon expanded
= wxNullIcon
;
2123 if (m_imageList
&& (expandedIndex
!= -1))
2124 expanded
= m_imageList
->GetIcon( expandedIndex
);
2126 wxDataViewItem res
= GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
2128 GetStore()->ItemAdded( parent
, res
);
2133 void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2135 GetStore()->SetItemText(item
,text
);
2138 GetStore()->ValueChanged( item
, 0 );
2141 void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2143 GetStore()->SetItemIcon(item
,icon
);
2146 GetStore()->ValueChanged( item
, 0 );
2149 void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2151 GetStore()->SetItemExpandedIcon(item
,icon
);
2154 GetStore()->ValueChanged( item
, 0 );
2157 void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem
& item
)
2159 wxDataViewItem parent_item
= GetStore()->GetParent( item
);
2161 GetStore()->DeleteItem(item
);
2164 GetStore()->ItemDeleted( parent_item
, item
);
2167 void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem
& item
)
2169 wxDataViewTreeStoreContainerNode
*node
= GetStore()->FindContainerNode( item
);
2172 wxDataViewItemArray array
;
2173 wxDataViewTreeStoreNodeList::iterator iter
;
2174 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2176 wxDataViewTreeStoreNode
* child
= *iter
;
2177 array
.Add( child
->GetItem() );
2180 GetStore()->DeleteChildren( item
);
2183 GetStore()->ItemsDeleted( item
, array
);
2186 void wxDataViewTreeCtrl::DeleteAllItems()
2188 GetStore()->DeleteAllItems();
2190 GetStore()->Cleared();
2193 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
2195 if (m_imageList
) return;
2197 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2198 if (!container
) return;
2200 container
->SetExpanded( true );
2202 GetStore()->ItemChanged( event
.GetItem() );
2205 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
2207 if (m_imageList
) return;
2209 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2210 if (!container
) return;
2212 container
->SetExpanded( false );
2214 GetStore()->ItemChanged( event
.GetItem() );
2217 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
2219 #if defined(wxUSE_GENERICDATAVIEWCTRL)
2220 // automatically resize our only column to take the entire control width
2221 if ( GetColumnCount() )
2223 wxSize size
= GetClientSize();
2224 GetColumn(0)->SetWidth(size
.x
);
2230 #endif // wxUSE_DATAVIEWCTRL