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() );
41 // ---------------------------------------------------------
42 // wxDataViewModelNotifier
43 // ---------------------------------------------------------
45 #include "wx/listimpl.cpp"
46 WX_DEFINE_LIST(wxDataViewModelNotifiers
)
48 bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
50 size_t count
= items
.GetCount();
52 for (i
= 0; i
< count
; i
++)
53 if (!ItemAdded( parent
, items
[i
] )) return false;
58 bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
60 size_t count
= items
.GetCount();
62 for (i
= 0; i
< count
; i
++)
63 if (!ItemDeleted( parent
, items
[i
] )) return false;
68 bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray
&items
)
70 size_t count
= items
.GetCount();
72 for (i
= 0; i
< count
; i
++)
73 if (!ItemChanged( items
[i
] )) return false;
78 // ---------------------------------------------------------
80 // ---------------------------------------------------------
82 wxDataViewModel::wxDataViewModel()
84 m_notifiers
.DeleteContents( true );
87 bool wxDataViewModel::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
91 wxDataViewModelNotifiers::iterator iter
;
92 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
94 wxDataViewModelNotifier
* notifier
= *iter
;
95 if (!notifier
->ItemAdded( parent
, item
))
102 bool wxDataViewModel::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
106 wxDataViewModelNotifiers::iterator iter
;
107 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
109 wxDataViewModelNotifier
* notifier
= *iter
;
110 if (!notifier
->ItemDeleted( parent
, item
))
117 bool wxDataViewModel::ItemChanged( const wxDataViewItem
&item
)
121 wxDataViewModelNotifiers::iterator iter
;
122 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
124 wxDataViewModelNotifier
* notifier
= *iter
;
125 if (!notifier
->ItemChanged( item
))
132 bool wxDataViewModel::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
136 wxDataViewModelNotifiers::iterator iter
;
137 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
139 wxDataViewModelNotifier
* notifier
= *iter
;
140 if (!notifier
->ItemsAdded( parent
, items
))
147 bool wxDataViewModel::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
151 wxDataViewModelNotifiers::iterator iter
;
152 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
154 wxDataViewModelNotifier
* notifier
= *iter
;
155 if (!notifier
->ItemsDeleted( parent
, items
))
162 bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray
&items
)
166 wxDataViewModelNotifiers::iterator iter
;
167 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
169 wxDataViewModelNotifier
* notifier
= *iter
;
170 if (!notifier
->ItemsChanged( items
))
177 bool wxDataViewModel::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
181 wxDataViewModelNotifiers::iterator iter
;
182 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
184 wxDataViewModelNotifier
* notifier
= *iter
;
185 if (!notifier
->ValueChanged( item
, col
))
192 bool wxDataViewModel::Cleared()
196 wxDataViewModelNotifiers::iterator iter
;
197 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
199 wxDataViewModelNotifier
* notifier
= *iter
;
200 if (!notifier
->Cleared())
207 void wxDataViewModel::Resort()
209 wxDataViewModelNotifiers::iterator iter
;
210 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
212 wxDataViewModelNotifier
* notifier
= *iter
;
217 void wxDataViewModel::AddNotifier( wxDataViewModelNotifier
*notifier
)
219 m_notifiers
.push_back( notifier
);
220 notifier
->SetOwner( this );
223 void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier
*notifier
)
225 m_notifiers
.DeleteObject( notifier
);
228 int wxDataViewModel::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
229 unsigned int column
, bool ascending
) const
231 // sort branches before leaves
232 bool item1_is_container
= IsContainer(item1
);
233 bool item2_is_container
= IsContainer(item2
);
235 if (item1_is_container
&& !item2_is_container
)
237 if (item2_is_container
&& !item1_is_container
)
240 wxVariant value1
,value2
;
241 GetValue( value1
, item1
, column
);
242 GetValue( value2
, item2
, column
);
246 wxVariant temp
= value1
;
251 if (value1
.GetType() == wxT("string"))
253 wxString str1
= value1
.GetString();
254 wxString str2
= value2
.GetString();
255 int res
= str1
.Cmp( str2
);
259 else if (value1
.GetType() == wxT("long"))
261 long l1
= value1
.GetLong();
262 long l2
= value2
.GetLong();
267 else if (value1
.GetType() == wxT("double"))
269 double d1
= value1
.GetDouble();
270 double d2
= value2
.GetDouble();
276 else if (value1
.GetType() == wxT("datetime"))
278 wxDateTime dt1
= value1
.GetDateTime();
279 wxDateTime dt2
= value2
.GetDateTime();
280 if (dt1
.IsEarlierThan(dt2
))
282 if (dt2
.IsEarlierThan(dt1
))
286 // items must be different
287 wxUIntPtr id1
= wxPtrToUInt(item1
.GetID()),
288 id2
= wxPtrToUInt(item2
.GetID());
290 return ascending
? id1
- id2
: id2
- id1
;
293 // ---------------------------------------------------------
294 // wxDataViewIndexListModel
295 // ---------------------------------------------------------
297 static int my_sort( int *v1
, int *v2
)
303 wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size
)
305 // IDs are ordered until an item gets deleted or inserted
308 // build initial index
310 for (i
= 1; i
< initial_size
+1; i
++)
311 m_hash
.Add( wxUIntToPtr(i
) );
312 m_lastIndex
= initial_size
+ 1;
315 wxDataViewIndexListModel::~wxDataViewIndexListModel()
319 void wxDataViewIndexListModel::Reset( unsigned int new_size
)
323 // IDs are ordered until an item gets deleted or inserted
326 // build initial index
328 for (i
= 1; i
< new_size
+1; i
++)
329 m_hash
.Add( wxUIntToPtr(i
) );
330 m_lastIndex
= new_size
+ 1;
332 wxDataViewModel::Cleared();
335 void wxDataViewIndexListModel::RowPrepended()
339 unsigned int id
= m_lastIndex
++;
340 m_hash
.Insert( wxUIntToPtr(id
), 0 );
341 wxDataViewItem
item( wxUIntToPtr(id
) );
342 ItemAdded( wxDataViewItem(0), item
);
345 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
349 unsigned int id
= m_lastIndex
++;
350 m_hash
.Insert( wxUIntToPtr(id
), before
);
351 wxDataViewItem
item( wxUIntToPtr(id
) );
352 ItemAdded( wxDataViewItem(0), item
);
355 void wxDataViewIndexListModel::RowAppended()
357 unsigned int id
= m_lastIndex
++;
358 m_hash
.Add( wxUIntToPtr(id
) );
359 wxDataViewItem
item( wxUIntToPtr(id
) );
360 ItemAdded( wxDataViewItem(0), item
);
363 void wxDataViewIndexListModel::RowDeleted( unsigned int row
)
367 wxDataViewItem
item( m_hash
[row
] );
368 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
369 m_hash
.RemoveAt( row
);
372 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt
&rows
)
374 wxArrayInt sorted
= rows
;
375 sorted
.Sort( my_sort
);
379 wxDataViewItemArray array
;
381 for (i
= 0; i
< rows
.GetCount(); i
++)
383 wxDataViewItem
item( m_hash
[rows
[i
]] );
386 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
388 for (i
= 0; i
< sorted
.GetCount(); i
++)
389 m_hash
.RemoveAt( sorted
[i
] );
392 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
394 wxDataViewModel::ItemChanged( GetItem(row
) );
397 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
399 wxDataViewModel::ValueChanged( GetItem(row
), col
);
402 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
406 unsigned int pos
= wxPtrToUInt( item
.GetID() );
410 // assert for not found
411 return (unsigned int) m_hash
.Index( item
.GetID() );
414 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
416 wxASSERT( row
< m_hash
.GetCount() );
417 return wxDataViewItem( m_hash
[row
] );
420 bool wxDataViewIndexListModel::HasDefaultCompare() const
425 int wxDataViewIndexListModel::Compare(const wxDataViewItem
& item1
,
426 const wxDataViewItem
& item2
,
427 unsigned int WXUNUSED(column
),
428 bool ascending
) const
432 unsigned int pos1
= wxPtrToUInt(item1
.GetID());
433 unsigned int pos2
= wxPtrToUInt(item2
.GetID());
442 return GetRow(item1
) - GetRow(item2
);
444 return GetRow(item2
) - GetRow(item1
);
447 void wxDataViewIndexListModel::GetValue( wxVariant
&variant
,
448 const wxDataViewItem
&item
, unsigned int col
) const
450 GetValueByRow( variant
, GetRow(item
), col
);
453 bool wxDataViewIndexListModel::SetValue( const wxVariant
&variant
,
454 const wxDataViewItem
&item
, unsigned int col
)
456 return SetValueByRow( variant
, GetRow(item
), col
);
459 bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
461 return GetAttrByRow( GetRow(item
), col
, attr
);
464 wxDataViewItem
wxDataViewIndexListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
466 return wxDataViewItem(0);
469 bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem
&item
) const
471 // only the invisible root item has children
478 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
485 return m_hash
.GetCount();
488 // ---------------------------------------------------------
489 // wxDataViewVirtualListModel
490 // ---------------------------------------------------------
494 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size
)
496 m_lastIndex
= initial_size
-1;
499 wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
503 void wxDataViewVirtualListModel::Reset( unsigned int new_size
)
505 m_lastIndex
= new_size
-1;
507 wxDataViewModel::Cleared();
510 void wxDataViewVirtualListModel::RowPrepended()
513 wxDataViewItem
item( NULL
);
514 ItemAdded( wxDataViewItem(0), item
);
517 void wxDataViewVirtualListModel::RowInserted( unsigned int before
)
520 wxDataViewItem
item( wxUIntToPtr(before
) );
521 ItemAdded( wxDataViewItem(0), item
);
524 void wxDataViewVirtualListModel::RowAppended()
527 wxDataViewItem
item( wxUIntToPtr(m_lastIndex
) );
528 ItemAdded( wxDataViewItem(0), item
);
531 void wxDataViewVirtualListModel::RowDeleted( unsigned int row
)
533 wxDataViewItem
item( wxUIntToPtr(row
) );
534 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item
);
538 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt
&rows
)
540 wxArrayInt sorted
= rows
;
541 sorted
.Sort( my_sort
);
543 wxDataViewItemArray array
;
545 for (i
= 0; i
< sorted
.GetCount(); i
++)
547 wxDataViewItem
item( wxUIntToPtr(sorted
[i
]) );
550 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array
);
552 m_lastIndex
-= rows
.GetCount();
555 void wxDataViewVirtualListModel::RowChanged( unsigned int row
)
557 wxDataViewModel::ItemChanged( GetItem(row
) );
560 void wxDataViewVirtualListModel::RowValueChanged( unsigned int row
, unsigned int col
)
562 wxDataViewModel::ValueChanged( GetItem(row
), col
);
565 unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem
&item
) const
567 return wxPtrToUInt( item
.GetID() );
570 wxDataViewItem
wxDataViewVirtualListModel::GetItem( unsigned int row
) const
572 return wxDataViewItem( wxUIntToPtr(row
) );
575 bool wxDataViewVirtualListModel::HasDefaultCompare() const
580 int wxDataViewVirtualListModel::Compare(const wxDataViewItem
& item1
,
581 const wxDataViewItem
& item2
,
582 unsigned int WXUNUSED(column
),
583 bool ascending
) const
585 unsigned int pos1
= wxPtrToUInt(item1
.GetID());
586 unsigned int pos2
= wxPtrToUInt(item2
.GetID());
594 void wxDataViewVirtualListModel::GetValue( wxVariant
&variant
,
595 const wxDataViewItem
&item
, unsigned int col
) const
597 GetValueByRow( variant
, GetRow(item
), col
);
600 bool wxDataViewVirtualListModel::SetValue( const wxVariant
&variant
,
601 const wxDataViewItem
&item
, unsigned int col
)
603 return SetValueByRow( variant
, GetRow(item
), col
);
606 bool wxDataViewVirtualListModel::GetAttr( const wxDataViewItem
&item
, unsigned int col
, wxDataViewItemAttr
&attr
)
608 return GetAttrByRow( GetRow(item
), col
, attr
);
611 wxDataViewItem
wxDataViewVirtualListModel::GetParent( const wxDataViewItem
& WXUNUSED(item
) ) const
613 return wxDataViewItem(0);
616 bool wxDataViewVirtualListModel::IsContainer( const wxDataViewItem
&item
) const
618 // only the invisible root item has children
625 unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem
&WXUNUSED(item
), wxDataViewItemArray
&WXUNUSED(children
) ) const
627 return 0; // should we report an error ?
632 //-----------------------------------------------------------------------------
633 // wxDataViewIconText
634 //-----------------------------------------------------------------------------
636 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
638 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
640 bool operator == (const wxDataViewIconText
&one
, const wxDataViewIconText
&two
)
642 if (one
.GetText() != two
.GetText()) return false;
643 if (one
.IsSameAs(two
)) return false;
647 // ---------------------------------------------------------
648 // wxDataViewRendererBase
649 // ---------------------------------------------------------
651 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
653 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
654 wxDataViewCellMode
WXUNUSED(mode
),
655 int WXUNUSED(align
) )
657 m_variantType
= varianttype
;
661 wxDataViewRendererBase::~wxDataViewRendererBase()
665 const wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
667 return const_cast<wxDataViewRendererBase
*>(this)->GetOwner()->GetOwner();
670 class wxKillRef
: public wxWindowRef
673 wxKillRef( wxWindow
*win
) : wxWindowRef( win
) { }
674 virtual void OnObjectDestroy()
676 get()->PopEventHandler( true );
682 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
684 m_item
= item
; // remember for later
686 unsigned int col
= GetOwner()->GetModelColumn();
688 GetOwner()->GetOwner()->GetModel()->GetValue( value
, item
, col
);
690 m_editorCtrl
= CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect
, value
);
691 (void) new wxKillRef( m_editorCtrl
.get() );
693 wxDataViewEditorCtrlEvtHandler
*handler
=
694 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
696 m_editorCtrl
->PushEventHandler( handler
);
698 // there might be no editor control for the given item
702 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
703 handler
->SetFocusOnIdle();
705 m_editorCtrl
->SetFocus();
708 // Now we should send Editing Started event
709 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, GetOwner()->GetOwner()->GetId() );
710 event
.SetDataViewColumn( GetOwner() );
711 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
712 event
.SetItem( item
);
713 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
718 void wxDataViewRendererBase::CancelEditing()
720 if (!m_editorCtrl
) return;
722 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
724 m_editorCtrl
->Hide();
725 wxPendingDelete
.Append( m_editorCtrl
);
728 bool wxDataViewRendererBase::FinishEditing()
730 if (!m_editorCtrl
) return true;
733 GetValueFromEditorCtrl( m_editorCtrl
, value
);
735 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
737 m_editorCtrl
->Hide();
738 wxPendingDelete
.Append( m_editorCtrl
);
740 if (!Validate(value
))
743 unsigned int col
= GetOwner()->GetModelColumn();
744 GetOwner()->GetOwner()->GetModel()->SetValue( value
, m_item
, col
);
745 GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item
, col
);
747 // Now we should send Editing Done event
748 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, GetOwner()->GetOwner()->GetId() );
749 event
.SetDataViewColumn( GetOwner() );
750 event
.SetModel( GetOwner()->GetOwner()->GetModel() );
751 event
.SetItem( m_item
);
752 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event
);
757 //-----------------------------------------------------------------------------
758 // wxDataViewEditorCtrlEvtHandler
759 //-----------------------------------------------------------------------------
761 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
762 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
763 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
764 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
765 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
768 wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
769 wxControl
*editorCtrl
,
770 wxDataViewRenderer
*owner
)
773 m_editorCtrl
= editorCtrl
;
778 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
782 m_focusOnIdle
= false;
783 if (wxWindow::FindFocus() != m_editorCtrl
)
784 m_editorCtrl
->SetFocus();
790 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
793 m_owner
->FinishEditing();
796 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
798 switch ( event
.m_keyCode
)
802 m_owner
->FinishEditing();
808 m_owner
->CancelEditing();
816 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
821 m_owner
->FinishEditing();
827 // ---------------------------------------------------------
828 // wxDataViewColumnBase
829 // ---------------------------------------------------------
831 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
832 unsigned int model_column
)
834 m_renderer
= renderer
;
835 m_model_column
= model_column
;
837 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
840 wxDataViewColumnBase::~wxDataViewColumnBase()
845 // ---------------------------------------------------------
846 // wxDataViewCtrlBase
847 // ---------------------------------------------------------
849 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
851 wxDataViewCtrlBase::wxDataViewCtrlBase()
854 m_expander_column
= 0;
858 wxDataViewCtrlBase::~wxDataViewCtrlBase()
867 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
871 m_model
->DecRef(); // discard old model, if any
874 // add our own reference to the new model:
884 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
889 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
894 void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem
& item
)
896 if (!m_model
) return;
898 if (!item
.IsOk()) return;
900 wxVector
<wxDataViewItem
> parentChain
;
902 // at first we get all the parents of the selected item
903 wxDataViewItem parent
= m_model
->GetParent(item
);
904 while (parent
.IsOk())
906 parentChain
.push_back(parent
);
907 parent
= m_model
->GetParent(parent
);
910 // then we expand the parents, starting at the root
911 while (!parentChain
.empty())
913 Expand(parentChain
.back());
914 parentChain
.pop_back();
919 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
920 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
922 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
923 new wxDataViewTextRenderer( wxT("string"), mode
),
924 model_column
, width
, align
, flags
);
930 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
931 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
933 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
934 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
935 model_column
, width
, align
, flags
);
941 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
942 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
944 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
945 new wxDataViewToggleRenderer( wxT("bool"), mode
),
946 model_column
, width
, align
, flags
);
952 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
953 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
955 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
956 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
957 model_column
, width
, align
, flags
);
963 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
964 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
966 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
967 new wxDataViewDateRenderer( wxT("datetime"), mode
),
968 model_column
, width
, align
, flags
);
974 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
975 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
977 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
978 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
979 model_column
, width
, align
, flags
);
985 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
986 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
988 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
989 new wxDataViewTextRenderer( wxT("string"), mode
),
990 model_column
, width
, align
, flags
);
996 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
997 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
999 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1000 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1001 model_column
, width
, align
, flags
);
1002 AppendColumn( ret
);
1007 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1008 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1010 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1011 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1012 model_column
, width
, align
, flags
);
1013 AppendColumn( ret
);
1018 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1019 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1021 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1022 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1023 model_column
, width
, align
, flags
);
1024 AppendColumn( ret
);
1029 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1030 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1032 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1033 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1034 model_column
, width
, align
, flags
);
1035 AppendColumn( ret
);
1040 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1041 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1043 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1044 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1045 model_column
, width
, align
, flags
);
1046 AppendColumn( ret
);
1051 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1052 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1054 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1055 new wxDataViewTextRenderer( wxT("string"), mode
),
1056 model_column
, width
, align
, flags
);
1057 PrependColumn( ret
);
1062 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1063 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1065 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1066 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1067 model_column
, width
, align
, flags
);
1068 PrependColumn( ret
);
1073 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1074 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1077 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1078 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1079 model_column
, width
, align
, flags
);
1080 PrependColumn( ret
);
1085 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1086 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1088 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1089 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1090 model_column
, width
, align
, flags
);
1091 PrependColumn( ret
);
1096 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1097 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1099 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1100 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1101 model_column
, width
, align
, flags
);
1102 PrependColumn( ret
);
1107 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1108 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1110 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1111 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1112 model_column
, width
, align
, flags
);
1113 PrependColumn( ret
);
1118 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1119 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1121 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1122 new wxDataViewTextRenderer( wxT("string"), mode
),
1123 model_column
, width
, align
, flags
);
1124 PrependColumn( ret
);
1129 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1130 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1132 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1133 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1134 model_column
, width
, align
, flags
);
1135 PrependColumn( ret
);
1140 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1141 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1143 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1144 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1145 model_column
, width
, align
, flags
);
1146 PrependColumn( ret
);
1151 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1152 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1154 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1155 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1156 model_column
, width
, align
, flags
);
1157 PrependColumn( ret
);
1162 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1163 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1165 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1166 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1167 model_column
, width
, align
, flags
);
1168 PrependColumn( ret
);
1173 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1174 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1176 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1177 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1178 model_column
, width
, align
, flags
);
1179 PrependColumn( ret
);
1184 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1186 col
->SetOwner( (wxDataViewCtrl
*) this );
1191 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1193 col
->SetOwner( (wxDataViewCtrl
*) this );
1198 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1200 col
->SetOwner( (wxDataViewCtrl
*) this );
1204 // ---------------------------------------------------------
1206 // ---------------------------------------------------------
1208 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1210 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
);
1212 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
);
1213 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
);
1214 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
);
1215 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
);
1216 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
);
1217 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
);
1218 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, wxDataViewEvent
);
1219 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
);
1220 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
);
1222 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
);
1224 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
);
1225 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
);
1226 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
);
1227 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
);
1229 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
);
1230 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, wxDataViewEvent
);
1231 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, wxDataViewEvent
);
1233 // -------------------------------------
1234 // wxDataViewSpinRenderer
1235 // -------------------------------------
1237 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1238 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1244 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1247 wxSize size
= labelRect
.GetSize();
1249 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1252 str
.Printf( wxT("%d"), (int) l
);
1253 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1254 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1256 size
= sc
->GetSize();
1257 wxPoint pt
= sc
->GetPosition();
1258 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1264 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1266 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1267 long l
= sc
->GetValue();
1272 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1275 str
.Printf(wxT("%d"), (int) m_data
);
1276 RenderText( str
, 0, rect
, dc
, state
);
1280 wxSize
wxDataViewSpinRenderer::GetSize() const
1282 return wxSize(80,16);
1285 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1287 m_data
= value
.GetLong();
1291 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1297 // -------------------------------------
1298 // wxDataViewChoiceRenderer
1299 // -------------------------------------
1301 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
1303 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1304 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1306 m_choices
= choices
;
1309 wxControl
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1312 wxSize size
= labelRect
.GetSize();
1314 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1316 wxChoice
*c
= new wxChoice( parent
, wxID_ANY
, labelRect
.GetTopLeft(), size
, m_choices
);
1317 c
->SetStringSelection( value
.GetString() );
1322 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1324 wxChoice
*c
= (wxChoice
*) editor
;
1325 wxString s
= c
->GetStringSelection();
1330 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1332 RenderText( m_data
, 0, rect
, dc
, state
);
1336 wxSize
wxDataViewChoiceRenderer::GetSize() const
1338 return wxSize(80,16);
1341 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1343 m_data
= value
.GetString();
1347 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1355 //-----------------------------------------------------------------------------
1356 // wxDataViewListStore
1357 //-----------------------------------------------------------------------------
1359 wxDataViewListStore::wxDataViewListStore()
1363 wxDataViewListStore::~wxDataViewListStore()
1365 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1366 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1368 wxDataViewListStoreLine
* line
= *it
;
1373 void wxDataViewListStore::PrependColumn( const wxString
&varianttype
)
1375 m_cols
.Insert( varianttype
, 0 );
1378 void wxDataViewListStore::InsertColumn( unsigned int pos
, const wxString
&varianttype
)
1380 m_cols
.Insert( varianttype
, pos
);
1383 void wxDataViewListStore::AppendColumn( const wxString
&varianttype
)
1385 m_cols
.Add( varianttype
);
1388 unsigned int wxDataViewListStore::GetColumnCount() const
1390 return m_cols
.GetCount();
1393 wxString
wxDataViewListStore::GetColumnType( unsigned int pos
) const
1398 void wxDataViewListStore::AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1400 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1401 line
->m_values
= values
;
1402 m_data
.push_back( line
);
1407 void wxDataViewListStore::PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1409 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1410 line
->m_values
= values
;
1411 m_data
.insert( m_data
.begin(), line
);
1416 void wxDataViewListStore::InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
,
1417 wxClientData
*data
)
1419 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1420 line
->m_values
= values
;
1421 m_data
.insert( m_data
.begin()+row
, line
);
1426 void wxDataViewListStore::DeleteItem( unsigned int row
)
1428 wxVector
<wxDataViewListStoreLine
*>::iterator it
= m_data
.begin() + row
;
1434 void wxDataViewListStore::DeleteAllItems()
1436 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1437 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1439 wxDataViewListStoreLine
* line
= *it
;
1448 void wxDataViewListStore::GetValueByRow( wxVariant
&value
, unsigned int row
, unsigned int col
) const
1450 wxDataViewListStoreLine
*line
= m_data
[row
];
1451 value
= line
->m_values
[col
];
1454 bool wxDataViewListStore::SetValueByRow( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1456 wxDataViewListStoreLine
*line
= m_data
[row
];
1457 line
->m_values
[col
] = value
;
1462 //-----------------------------------------------------------------------------
1463 // wxDataViewListCtrl
1464 //-----------------------------------------------------------------------------
1466 IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl
,wxDataViewCtrl
)
1468 BEGIN_EVENT_TABLE(wxDataViewListCtrl
,wxDataViewCtrl
)
1469 EVT_SIZE( wxDataViewListCtrl::OnSize
)
1472 wxDataViewListCtrl::wxDataViewListCtrl()
1476 wxDataViewListCtrl::wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
1477 const wxPoint
& pos
, const wxSize
& size
, long style
,
1478 const wxValidator
& validator
)
1480 Create( parent
, id
, pos
, size
, style
, validator
);
1482 wxDataViewListStore
*store
= new wxDataViewListStore
;
1483 AssociateModel( store
);
1487 wxDataViewListCtrl::~wxDataViewListCtrl()
1492 bool wxDataViewListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1493 const wxPoint
& pos
, const wxSize
& size
, long style
,
1494 const wxValidator
& validator
)
1496 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
1499 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1501 GetStore()->AppendColumn( varianttype
);
1502 return wxDataViewCtrl::AppendColumn( column
);
1505 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1507 GetStore()->PrependColumn( varianttype
);
1508 return wxDataViewCtrl::PrependColumn( column
);
1511 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
)
1513 GetStore()->InsertColumn( pos
, varianttype
);
1514 return wxDataViewCtrl::InsertColumn( pos
, column
);
1517 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*col
)
1519 return PrependColumn( col
, "string" );
1522 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
1524 return InsertColumn( pos
, col
, "string" );
1527 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*col
)
1529 return AppendColumn( col
, "string" );
1532 wxDataViewColumn
*wxDataViewListCtrl::AppendTextColumn( const wxString
&label
,
1533 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1535 GetStore()->AppendColumn( wxT("string") );
1537 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1538 new wxDataViewTextRenderer( wxT("string"), mode
),
1539 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1541 wxDataViewCtrl::AppendColumn( ret
);
1546 wxDataViewColumn
*wxDataViewListCtrl::AppendToggleColumn( const wxString
&label
,
1547 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1549 GetStore()->AppendColumn( wxT("bool") );
1551 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1552 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1553 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1555 wxDataViewCtrl::AppendColumn( ret
);
1560 wxDataViewColumn
*wxDataViewListCtrl::AppendProgressColumn( const wxString
&label
,
1561 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1563 GetStore()->AppendColumn( wxT("long") );
1565 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1566 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1567 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1569 wxDataViewCtrl::AppendColumn( ret
);
1574 wxDataViewColumn
*wxDataViewListCtrl::AppendIconTextColumn( const wxString
&label
,
1575 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1577 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
1579 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1580 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1581 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1583 wxDataViewCtrl::AppendColumn( ret
);
1588 void wxDataViewListCtrl::OnSize( wxSizeEvent
&event
)
1593 //-----------------------------------------------------------------------------
1594 // wxDataViewTreeStore
1595 //-----------------------------------------------------------------------------
1597 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1598 wxDataViewTreeStoreNode
*parent
,
1599 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1607 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1613 #include "wx/listimpl.cpp"
1614 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1616 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1617 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1618 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1619 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1621 m_iconExpanded
= expanded
;
1622 m_isExpanded
= false;
1623 m_children
.DeleteContents(true);
1626 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1630 //-----------------------------------------------------------------------------
1632 wxDataViewTreeStore::wxDataViewTreeStore()
1634 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1637 wxDataViewTreeStore::~wxDataViewTreeStore()
1642 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1643 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1645 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1646 if (!parent_node
) return wxDataViewItem(0);
1648 wxDataViewTreeStoreNode
*node
=
1649 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1650 parent_node
->GetChildren().Append( node
);
1652 return node
->GetItem();
1655 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1656 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1658 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1659 if (!parent_node
) return wxDataViewItem(0);
1661 wxDataViewTreeStoreNode
*node
=
1662 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1663 parent_node
->GetChildren().Insert( node
);
1665 return node
->GetItem();
1669 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& parent
,
1670 const wxDataViewItem
& previous
,
1671 const wxString
& text
,
1675 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1676 if (!parent_node
) return wxDataViewItem(0);
1678 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1679 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1680 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1682 wxDataViewTreeStoreNode
*node
=
1683 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1684 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1686 return node
->GetItem();
1689 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1690 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1691 wxClientData
*data
)
1693 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1694 if (!parent_node
) return wxDataViewItem(0);
1696 wxDataViewTreeStoreContainerNode
*node
=
1697 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1698 parent_node
->GetChildren().Insert( node
);
1700 return node
->GetItem();
1704 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1705 const wxString
&text
,
1707 const wxIcon
& expanded
,
1708 wxClientData
* data
)
1710 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1711 if (!parent_node
) return wxDataViewItem(0);
1713 wxDataViewTreeStoreContainerNode
*node
=
1714 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1715 parent_node
->GetChildren().Append( node
);
1717 return node
->GetItem();
1721 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& parent
,
1722 const wxDataViewItem
& previous
,
1723 const wxString
& text
,
1725 const wxIcon
& expanded
,
1726 wxClientData
* data
)
1728 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1729 if (!parent_node
) return wxDataViewItem(0);
1731 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1732 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1733 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1735 wxDataViewTreeStoreContainerNode
*node
=
1736 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1737 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1739 return node
->GetItem();
1742 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1744 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1745 if (!parent_node
) return wxDataViewItem(0);
1747 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1749 return node
->GetData();
1751 return wxDataViewItem(0);
1754 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1756 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1757 if (!node
) return -1;
1759 if (!node
->IsContainer())
1762 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1763 return (int) container_node
->GetChildren().GetCount();
1766 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1768 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1771 node
->SetText( text
);
1774 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1776 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1777 if (!node
) return wxEmptyString
;
1779 return node
->GetText();
1782 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1784 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1787 node
->SetIcon( icon
);
1790 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1792 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1793 if (!node
) return wxNullIcon
;
1795 return node
->GetIcon();
1798 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1800 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1803 node
->SetExpandedIcon( icon
);
1806 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1808 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1809 if (!node
) return wxNullIcon
;
1811 return node
->GetExpandedIcon();
1814 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1816 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1819 node
->SetData( data
);
1822 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
1824 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1825 if (!node
) return NULL
;
1827 return node
->GetData();
1830 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
1832 if (!item
.IsOk()) return;
1834 wxDataViewItem parent_item
= GetParent( item
);
1836 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
1837 if (!parent_node
) return;
1839 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1842 parent_node
->GetChildren().DeleteObject( node
);
1845 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
1847 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1850 node
->GetChildren().clear();
1853 void wxDataViewTreeStore::DeleteAllItems()
1859 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
1860 const wxDataViewItem
&item
,
1861 unsigned int WXUNUSED(col
)) const
1863 // if (col != 0) return;
1865 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1868 wxIcon
icon( node
->GetIcon());
1869 if (node
->IsContainer())
1871 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
1872 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
1873 icon
= container
->GetExpandedIcon();
1876 wxDataViewIconText
data( node
->GetText(), icon
);
1882 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
1883 const wxDataViewItem
& item
,
1884 unsigned int WXUNUSED(col
))
1886 // if (col != 0) return false;
1888 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1889 if (!node
) return false;
1891 wxDataViewIconText data
;
1895 node
->SetText( data
.GetText() );
1896 node
->SetIcon( data
.GetIcon() );
1901 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
1903 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1904 if (!node
) return wxDataViewItem(0);
1906 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
1907 if (!parent
) return wxDataViewItem(0);
1909 if (parent
== m_root
)
1910 return wxDataViewItem(0);
1912 return parent
->GetItem();
1915 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
&item
) const
1917 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1918 if (!node
) return false;
1920 return node
->IsContainer();
1923 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
1925 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1926 if (!node
) return 0;
1928 wxDataViewTreeStoreNodeList::iterator iter
;
1929 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
1931 wxDataViewTreeStoreNode
* child
= *iter
;
1932 children
.Add( child
->GetItem() );
1935 return node
->GetChildren().GetCount();
1938 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
1939 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) ) const
1941 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
1942 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
1944 if (!node1
|| !node2
)
1947 wxDataViewTreeStoreContainerNode
* parent1
=
1948 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
1949 wxDataViewTreeStoreContainerNode
* parent2
=
1950 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
1952 if (parent1
!= parent2
)
1954 wxLogError( wxT("Comparing items with different parent.") );
1958 if (node1
->IsContainer() && !!node2
->IsContainer())
1961 if (node2
->IsContainer() && !!node1
->IsContainer())
1964 return parent1
->GetChildren().IndexOf( node1
) - parent1
->GetChildren().IndexOf( node2
);
1967 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
1972 return (wxDataViewTreeStoreNode
*) item
.GetID();
1975 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
1978 return (wxDataViewTreeStoreContainerNode
*) m_root
;
1980 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
1982 if (!node
->IsContainer())
1985 return (wxDataViewTreeStoreContainerNode
*) node
;
1988 //-----------------------------------------------------------------------------
1989 // wxDataViewTreeCtrl
1990 //-----------------------------------------------------------------------------
1992 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1994 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
1995 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
1996 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
1997 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
2000 wxDataViewTreeCtrl::wxDataViewTreeCtrl()
2005 wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow
*parent
, wxWindowID id
,
2006 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2009 Create( parent
, id
, pos
, size
, style
, validator
);
2011 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
2012 AssociateModel( store
);
2015 AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT
,-1);
2018 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
2024 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2025 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2027 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
2030 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
2035 m_imageList
= imagelist
;
2038 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
2039 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2041 wxIcon icon
= wxNullIcon
;
2042 if (m_imageList
&& (iconIndex
!= -1))
2043 icon
= m_imageList
->GetIcon( iconIndex
);
2045 wxDataViewItem res
= GetStore()->AppendItem( parent
, text
, icon
, data
);
2047 GetStore()->ItemAdded( parent
, res
);
2052 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
2053 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2055 wxIcon icon
= wxNullIcon
;
2056 if (m_imageList
&& (iconIndex
!= -1))
2057 icon
= m_imageList
->GetIcon( iconIndex
);
2059 wxDataViewItem res
= GetStore()->PrependItem( parent
, text
, icon
, data
);
2061 GetStore()->ItemAdded( parent
, res
);
2066 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2067 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2069 wxIcon icon
= wxNullIcon
;
2070 if (m_imageList
&& (iconIndex
!= -1))
2071 icon
= m_imageList
->GetIcon( iconIndex
);
2073 wxDataViewItem res
= GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
2075 GetStore()->ItemAdded( parent
, res
);
2080 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
2081 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2083 wxIcon icon
= wxNullIcon
;
2084 if (m_imageList
&& (iconIndex
!= -1))
2085 icon
= m_imageList
->GetIcon( iconIndex
);
2087 wxIcon expanded
= wxNullIcon
;
2088 if (m_imageList
&& (expandedIndex
!= -1))
2089 expanded
= m_imageList
->GetIcon( expandedIndex
);
2091 wxDataViewItem res
= GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
2093 GetStore()->ItemAdded( parent
, res
);
2098 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
2099 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2101 wxIcon icon
= wxNullIcon
;
2102 if (m_imageList
&& (iconIndex
!= -1))
2103 icon
= m_imageList
->GetIcon( iconIndex
);
2105 wxIcon expanded
= wxNullIcon
;
2106 if (m_imageList
&& (expandedIndex
!= -1))
2107 expanded
= m_imageList
->GetIcon( expandedIndex
);
2109 wxDataViewItem res
= GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
2111 GetStore()->ItemAdded( parent
, res
);
2116 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2117 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2119 wxIcon icon
= wxNullIcon
;
2120 if (m_imageList
&& (iconIndex
!= -1))
2121 icon
= m_imageList
->GetIcon( iconIndex
);
2123 wxIcon expanded
= wxNullIcon
;
2124 if (m_imageList
&& (expandedIndex
!= -1))
2125 expanded
= m_imageList
->GetIcon( expandedIndex
);
2127 wxDataViewItem res
= GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
2129 GetStore()->ItemAdded( parent
, res
);
2134 void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2136 GetStore()->SetItemText(item
,text
);
2139 GetStore()->ValueChanged( item
, 0 );
2142 void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2144 GetStore()->SetItemIcon(item
,icon
);
2147 GetStore()->ValueChanged( item
, 0 );
2150 void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2152 GetStore()->SetItemExpandedIcon(item
,icon
);
2155 GetStore()->ValueChanged( item
, 0 );
2158 void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem
& item
)
2160 wxDataViewItem parent_item
= GetStore()->GetParent( item
);
2162 GetStore()->DeleteItem(item
);
2165 GetStore()->ItemDeleted( parent_item
, item
);
2168 void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem
& item
)
2170 wxDataViewTreeStoreContainerNode
*node
= GetStore()->FindContainerNode( item
);
2173 wxDataViewItemArray array
;
2174 wxDataViewTreeStoreNodeList::iterator iter
;
2175 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2177 wxDataViewTreeStoreNode
* child
= *iter
;
2178 array
.Add( child
->GetItem() );
2181 GetStore()->DeleteChildren( item
);
2184 GetStore()->ItemsDeleted( item
, array
);
2187 void wxDataViewTreeCtrl::DeleteAllItems()
2189 GetStore()->DeleteAllItems();
2191 GetStore()->Cleared();
2194 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
2196 if (m_imageList
) return;
2198 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2199 if (!container
) return;
2201 container
->SetExpanded( true );
2203 GetStore()->ItemChanged( event
.GetItem() );
2206 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
2208 if (m_imageList
) return;
2210 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2211 if (!container
) return;
2213 container
->SetExpanded( false );
2215 GetStore()->ItemChanged( event
.GetItem() );
2218 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
2220 #if defined(wxUSE_GENERICDATAVIEWCTRL)
2221 // automatically resize our only column to take the entire control width
2222 if ( GetColumnCount() )
2224 wxSize size
= GetClientSize();
2225 GetColumn(0)->SetWidth(size
.x
);
2231 #endif // wxUSE_DATAVIEWCTRL