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";
38 // Custom handler pushed on top of the edit control used by wxDataViewCtrl to
39 // forward some events to the main control itself.
40 class wxDataViewEditorCtrlEvtHandler
: public wxEvtHandler
43 wxDataViewEditorCtrlEvtHandler(wxWindow
*editor
, wxDataViewRenderer
*owner
)
45 m_editorCtrl
= editor
;
51 void AcceptChangesAndFinish();
52 void SetFocusOnIdle( bool focus
= true ) { m_focusOnIdle
= focus
; }
55 void OnChar( wxKeyEvent
&event
);
56 void OnTextEnter( wxCommandEvent
&event
);
57 void OnKillFocus( wxFocusEvent
&event
);
58 void OnIdle( wxIdleEvent
&event
);
61 wxDataViewRenderer
*m_owner
;
62 wxWindow
*m_editorCtrl
;
70 } // anonymous namespace
72 // ---------------------------------------------------------
74 // ---------------------------------------------------------
76 wxFont
wxDataViewItemAttr::GetEffectiveFont(const wxFont
& font
) const
90 // ---------------------------------------------------------
91 // wxDataViewModelNotifier
92 // ---------------------------------------------------------
94 #include "wx/listimpl.cpp"
95 WX_DEFINE_LIST(wxDataViewModelNotifiers
)
97 bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
99 size_t count
= items
.GetCount();
101 for (i
= 0; i
< count
; i
++)
102 if (!ItemAdded( parent
, items
[i
] )) return false;
107 bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
109 size_t count
= items
.GetCount();
111 for (i
= 0; i
< count
; i
++)
112 if (!ItemDeleted( parent
, items
[i
] )) return false;
117 bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray
&items
)
119 size_t count
= items
.GetCount();
121 for (i
= 0; i
< count
; i
++)
122 if (!ItemChanged( items
[i
] )) return false;
127 // ---------------------------------------------------------
129 // ---------------------------------------------------------
131 wxDataViewModel::wxDataViewModel()
133 m_notifiers
.DeleteContents( true );
136 bool wxDataViewModel::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
140 wxDataViewModelNotifiers::iterator iter
;
141 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
143 wxDataViewModelNotifier
* notifier
= *iter
;
144 if (!notifier
->ItemAdded( parent
, item
))
151 bool wxDataViewModel::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
155 wxDataViewModelNotifiers::iterator iter
;
156 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
158 wxDataViewModelNotifier
* notifier
= *iter
;
159 if (!notifier
->ItemDeleted( parent
, item
))
166 bool wxDataViewModel::ItemChanged( const wxDataViewItem
&item
)
170 wxDataViewModelNotifiers::iterator iter
;
171 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
173 wxDataViewModelNotifier
* notifier
= *iter
;
174 if (!notifier
->ItemChanged( item
))
181 bool wxDataViewModel::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
185 wxDataViewModelNotifiers::iterator iter
;
186 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
188 wxDataViewModelNotifier
* notifier
= *iter
;
189 if (!notifier
->ItemsAdded( parent
, items
))
196 bool wxDataViewModel::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
200 wxDataViewModelNotifiers::iterator iter
;
201 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
203 wxDataViewModelNotifier
* notifier
= *iter
;
204 if (!notifier
->ItemsDeleted( parent
, items
))
211 bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray
&items
)
215 wxDataViewModelNotifiers::iterator iter
;
216 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
218 wxDataViewModelNotifier
* notifier
= *iter
;
219 if (!notifier
->ItemsChanged( items
))
226 bool wxDataViewModel::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
230 wxDataViewModelNotifiers::iterator iter
;
231 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
233 wxDataViewModelNotifier
* notifier
= *iter
;
234 if (!notifier
->ValueChanged( item
, col
))
241 bool wxDataViewModel::Cleared()
245 wxDataViewModelNotifiers::iterator iter
;
246 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
248 wxDataViewModelNotifier
* notifier
= *iter
;
249 if (!notifier
->Cleared())
256 bool wxDataViewModel::BeforeReset()
260 wxDataViewModelNotifiers::iterator iter
;
261 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
263 wxDataViewModelNotifier
* notifier
= *iter
;
264 if (!notifier
->BeforeReset())
271 bool wxDataViewModel::AfterReset()
275 wxDataViewModelNotifiers::iterator iter
;
276 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
278 wxDataViewModelNotifier
* notifier
= *iter
;
279 if (!notifier
->AfterReset())
286 void wxDataViewModel::Resort()
288 wxDataViewModelNotifiers::iterator iter
;
289 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
291 wxDataViewModelNotifier
* notifier
= *iter
;
296 void wxDataViewModel::AddNotifier( wxDataViewModelNotifier
*notifier
)
298 m_notifiers
.push_back( notifier
);
299 notifier
->SetOwner( this );
302 void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier
*notifier
)
304 m_notifiers
.DeleteObject( notifier
);
307 int wxDataViewModel::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
308 unsigned int column
, bool ascending
) const
310 // sort branches before leaves
311 bool item1_is_container
= IsContainer(item1
);
312 bool item2_is_container
= IsContainer(item2
);
314 if (item1_is_container
&& !item2_is_container
)
316 if (item2_is_container
&& !item1_is_container
)
319 wxVariant value1
,value2
;
320 GetValue( value1
, item1
, column
);
321 GetValue( value2
, item2
, column
);
325 wxVariant temp
= value1
;
330 if (value1
.GetType() == wxT("string"))
332 wxString str1
= value1
.GetString();
333 wxString str2
= value2
.GetString();
334 int res
= str1
.Cmp( str2
);
338 else if (value1
.GetType() == wxT("long"))
340 long l1
= value1
.GetLong();
341 long l2
= value2
.GetLong();
346 else if (value1
.GetType() == wxT("double"))
348 double d1
= value1
.GetDouble();
349 double d2
= value2
.GetDouble();
355 else if (value1
.GetType() == wxT("datetime"))
357 wxDateTime dt1
= value1
.GetDateTime();
358 wxDateTime dt2
= value2
.GetDateTime();
359 if (dt1
.IsEarlierThan(dt2
))
361 if (dt2
.IsEarlierThan(dt1
))
365 // items must be different
366 wxUIntPtr id1
= wxPtrToUInt(item1
.GetID()),
367 id2
= wxPtrToUInt(item2
.GetID());
369 return ascending
? id1
- id2
: id2
- id1
;
372 // ---------------------------------------------------------
373 // wxDataViewIndexListModel
374 // ---------------------------------------------------------
376 static int my_sort( int *v1
, int *v2
)
382 wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size
)
384 // IDs are ordered until an item gets deleted or inserted
387 // build initial index
389 for (i
= 1; i
< initial_size
+1; i
++)
390 m_hash
.Add( wxDataViewItem(wxUIntToPtr(i
)) );
391 m_nextFreeID
= initial_size
+ 1;
394 void wxDataViewIndexListModel::Reset( unsigned int new_size
)
396 /* wxDataViewModel:: */ BeforeReset();
400 // IDs are ordered until an item gets deleted or inserted
403 // build initial index
405 for (i
= 1; i
< new_size
+1; i
++)
406 m_hash
.Add( wxDataViewItem(wxUIntToPtr(i
)) );
408 m_nextFreeID
= new_size
+ 1;
410 /* wxDataViewModel:: */ AfterReset();
413 void wxDataViewIndexListModel::RowPrepended()
417 unsigned int id
= m_nextFreeID
;
420 wxDataViewItem
item( wxUIntToPtr(id
) );
421 m_hash
.Insert( item
, 0 );
422 ItemAdded( wxDataViewItem(0), item
);
426 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
430 unsigned int id
= m_nextFreeID
;
433 wxDataViewItem
item( wxUIntToPtr(id
) );
434 m_hash
.Insert( item
, before
);
435 ItemAdded( wxDataViewItem(0), item
);
438 void wxDataViewIndexListModel::RowAppended()
440 unsigned int id
= m_nextFreeID
;
443 wxDataViewItem
item( wxUIntToPtr(id
) );
445 ItemAdded( wxDataViewItem(0), item
);
448 void wxDataViewIndexListModel::RowDeleted( unsigned int row
)
452 wxDataViewItem
item( m_hash
[row
] );
453 /* wxDataViewModel:: */ ItemDeleted( wxDataViewItem(0), item
);
454 m_hash
.RemoveAt( row
);
457 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt
&rows
)
459 wxArrayInt sorted
= rows
;
460 sorted
.Sort( my_sort
);
464 wxDataViewItemArray array
;
466 for (i
= 0; i
< rows
.GetCount(); i
++)
468 wxDataViewItem
item( m_hash
[rows
[i
]] );
471 /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array
);
473 for (i
= 0; i
< sorted
.GetCount(); i
++)
474 m_hash
.RemoveAt( sorted
[i
] );
477 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
479 /* wxDataViewModel:: */ ItemChanged( GetItem(row
) );
482 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
484 /* wxDataViewModel:: */ ValueChanged( GetItem(row
), col
);
487 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
490 return wxPtrToUInt(item
.GetID())-1;
492 // assert for not found
493 return (unsigned int) m_hash
.Index( item
);
496 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
498 wxASSERT( row
< m_hash
.GetCount() );
499 return wxDataViewItem( m_hash
[row
] );
502 bool wxDataViewIndexListModel::HasDefaultCompare() const
507 int wxDataViewIndexListModel::Compare(const wxDataViewItem
& item1
,
508 const wxDataViewItem
& item2
,
509 unsigned int WXUNUSED(column
),
510 bool ascending
) const
514 unsigned int pos1
= wxPtrToUInt(item1
.GetID()); // -1 not needed here
515 unsigned int pos2
= wxPtrToUInt(item2
.GetID()); // -1 not needed here
524 return GetRow(item1
) - GetRow(item2
);
526 return GetRow(item2
) - GetRow(item1
);
529 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
536 return m_hash
.GetCount();
539 // ---------------------------------------------------------
540 // wxDataViewVirtualListModel
541 // ---------------------------------------------------------
545 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size
)
547 m_size
= initial_size
;
550 void wxDataViewVirtualListModel::Reset( unsigned int new_size
)
552 /* wxDataViewModel:: */ BeforeReset();
556 /* wxDataViewModel:: */ AfterReset();
559 void wxDataViewVirtualListModel::RowPrepended()
562 wxDataViewItem
item( wxUIntToPtr(1) );
563 ItemAdded( wxDataViewItem(0), item
);
566 void wxDataViewVirtualListModel::RowInserted( unsigned int before
)
569 wxDataViewItem
item( wxUIntToPtr(before
+1) );
570 ItemAdded( wxDataViewItem(0), item
);
573 void wxDataViewVirtualListModel::RowAppended()
576 wxDataViewItem
item( wxUIntToPtr(m_size
) );
577 ItemAdded( wxDataViewItem(0), item
);
580 void wxDataViewVirtualListModel::RowDeleted( unsigned int row
)
583 wxDataViewItem
item( wxUIntToPtr(row
+1) );
584 /* wxDataViewModel:: */ ItemDeleted( wxDataViewItem(0), item
);
587 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt
&rows
)
589 m_size
-= rows
.GetCount();
591 wxArrayInt sorted
= rows
;
592 sorted
.Sort( my_sort
);
594 wxDataViewItemArray array
;
596 for (i
= 0; i
< sorted
.GetCount(); i
++)
598 wxDataViewItem
item( wxUIntToPtr(sorted
[i
]+1) );
601 /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array
);
604 void wxDataViewVirtualListModel::RowChanged( unsigned int row
)
606 /* wxDataViewModel:: */ ItemChanged( GetItem(row
) );
609 void wxDataViewVirtualListModel::RowValueChanged( unsigned int row
, unsigned int col
)
611 /* wxDataViewModel:: */ ValueChanged( GetItem(row
), col
);
614 unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem
&item
) const
616 return wxPtrToUInt( item
.GetID() ) -1;
619 wxDataViewItem
wxDataViewVirtualListModel::GetItem( unsigned int row
) const
621 return wxDataViewItem( wxUIntToPtr(row
+1) );
624 bool wxDataViewVirtualListModel::HasDefaultCompare() const
629 int wxDataViewVirtualListModel::Compare(const wxDataViewItem
& item1
,
630 const wxDataViewItem
& item2
,
631 unsigned int WXUNUSED(column
),
632 bool ascending
) const
634 unsigned int pos1
= wxPtrToUInt(item1
.GetID()); // -1 not needed here
635 unsigned int pos2
= wxPtrToUInt(item2
.GetID()); // -1 not needed here
643 unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem
&WXUNUSED(item
), wxDataViewItemArray
&WXUNUSED(children
) ) const
645 return 0; // should we report an error ?
650 //-----------------------------------------------------------------------------
651 // wxDataViewIconText
652 //-----------------------------------------------------------------------------
654 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
656 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
658 // ---------------------------------------------------------
659 // wxDataViewRendererBase
660 // ---------------------------------------------------------
662 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
664 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
665 wxDataViewCellMode
WXUNUSED(mode
),
666 int WXUNUSED(align
) )
668 m_variantType
= varianttype
;
672 wxDataViewRendererBase::~wxDataViewRendererBase()
676 wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
678 return const_cast<wxDataViewRendererBase
*>(this)->GetOwner()->GetOwner();
681 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
683 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
685 // Before doing anything we send an event asking if editing of this item is really wanted.
686 wxDataViewEvent
start_event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv_ctrl
->GetId() );
687 start_event
.SetDataViewColumn( GetOwner() );
688 start_event
.SetModel( dv_ctrl
->GetModel() );
689 start_event
.SetItem( item
);
690 start_event
.SetEventObject( dv_ctrl
);
691 dv_ctrl
->GetEventHandler()->ProcessEvent( start_event
);
692 if( !start_event
.IsAllowed() )
695 m_item
= item
; // remember for later
697 unsigned int col
= GetOwner()->GetModelColumn();
699 dv_ctrl
->GetModel()->GetValue( value
, item
, col
);
701 m_editorCtrl
= CreateEditorCtrl( dv_ctrl
->GetMainWindow(), labelRect
, value
);
703 // there might be no editor control for the given item
707 wxDataViewEditorCtrlEvtHandler
*handler
=
708 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
710 m_editorCtrl
->PushEventHandler( handler
);
712 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
713 handler
->SetFocusOnIdle();
715 m_editorCtrl
->SetFocus();
718 // Now we should send Editing Started event
719 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv_ctrl
->GetId() );
720 event
.SetDataViewColumn( GetOwner() );
721 event
.SetModel( dv_ctrl
->GetModel() );
722 event
.SetItem( item
);
723 event
.SetEventObject( dv_ctrl
);
724 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
729 void wxDataViewRendererBase::DestroyEditControl()
731 // Remove our event handler first to prevent it from (recursively) calling
732 // us again as it would do via a call to FinishEditing() when the editor
733 // loses focus when we hide it below.
734 wxEvtHandler
* const handler
= m_editorCtrl
->PopEventHandler();
736 // Hide the control immediately but don't delete it yet as there could be
737 // some pending messages for it.
738 m_editorCtrl
->Hide();
740 wxPendingDelete
.Append(handler
);
741 wxPendingDelete
.Append(m_editorCtrl
);
744 void wxDataViewRendererBase::CancelEditing()
749 DestroyEditControl();
752 bool wxDataViewRendererBase::FinishEditing()
758 GetValueFromEditorCtrl( m_editorCtrl
, value
);
760 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
762 dv_ctrl
->GetMainWindow()->SetFocus();
764 DestroyEditControl();
766 bool isValid
= Validate(value
);
767 unsigned int col
= GetOwner()->GetModelColumn();
769 // Now we should send Editing Done event
770 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv_ctrl
->GetId() );
771 event
.SetDataViewColumn( GetOwner() );
772 event
.SetModel( dv_ctrl
->GetModel() );
773 event
.SetItem( m_item
);
774 event
.SetValue( value
);
775 event
.SetColumn( col
);
776 event
.SetEditCanceled( !isValid
);
777 event
.SetEventObject( dv_ctrl
);
778 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
780 if ( isValid
&& event
.IsAllowed() )
782 dv_ctrl
->GetModel()->ChangeValue(value
, m_item
, col
);
789 void wxDataViewRendererBase::PrepareForItem(const wxDataViewModel
*model
,
790 const wxDataViewItem
& item
,
794 model
->GetValue(value
, item
, column
);
797 wxDataViewItemAttr attr
;
798 model
->GetAttr(item
, column
, attr
);
801 SetEnabled(model
->IsEnabled(item
, column
));
805 // ----------------------------------------------------------------------------
806 // wxDataViewCustomRendererBase
807 // ----------------------------------------------------------------------------
810 wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell
, wxDC
*dc
, int state
)
812 wxCHECK_RET( dc
, "no DC to draw on in custom renderer?" );
814 // adjust the rectangle ourselves to account for the alignment
815 wxRect rectItem
= rectCell
;
816 const int align
= GetAlignment();
817 if ( align
!= wxDVR_DEFAULT_ALIGNMENT
)
819 const wxSize size
= GetSize();
821 // take alignment into account only if there is enough space, otherwise
822 // show as much contents as possible
824 // notice that many existing renderers (e.g. wxDataViewSpinRenderer)
825 // return hard-coded size which can be more than they need and if we
826 // trusted their GetSize() we'd draw the text out of cell bounds
829 if ( size
.x
>= 0 && size
.x
< rectCell
.width
)
831 if ( align
& wxALIGN_CENTER_HORIZONTAL
)
832 rectItem
.x
+= (rectCell
.width
- size
.x
)/2;
833 else if ( align
& wxALIGN_RIGHT
)
834 rectItem
.x
+= rectCell
.width
- size
.x
;
835 // else: wxALIGN_LEFT is the default
837 rectItem
.width
= size
.x
;
840 if ( size
.y
>= 0 && size
.y
< rectCell
.height
)
842 if ( align
& wxALIGN_CENTER_VERTICAL
)
843 rectItem
.y
+= (rectCell
.height
- size
.y
)/2;
844 else if ( align
& wxALIGN_BOTTOM
)
845 rectItem
.y
+= rectCell
.height
- size
.y
;
846 // else: wxALIGN_TOP is the default
848 rectItem
.height
= size
.y
;
853 // set up the DC attributes
855 // override custom foreground with the standard one for the selected items
856 // because we currently don't allow changing the selection background and
857 // custom colours may be unreadable on it
859 if ( state
& wxDATAVIEW_CELL_SELECTED
)
860 col
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
861 else if ( m_attr
.HasColour() )
862 col
= m_attr
.GetColour();
863 else // use default foreground
864 col
= GetOwner()->GetOwner()->GetForegroundColour();
866 wxDCTextColourChanger
changeFg(*dc
, col
);
868 wxDCFontChanger
changeFont(*dc
);
869 if ( m_attr
.HasFont() )
870 changeFont
.Set(m_attr
.GetEffectiveFont(dc
->GetFont()));
872 Render(rectItem
, dc
, state
);
875 wxSize
wxDataViewCustomRendererBase::GetTextExtent(const wxString
& str
) const
877 const wxDataViewCtrl
*view
= GetView();
879 if ( m_attr
.HasFont() )
881 wxFont
font(m_attr
.GetEffectiveFont(view
->GetFont()));
883 view
->GetTextExtent(str
, &size
.x
, &size
.y
, NULL
, NULL
, &font
);
888 return view
->GetTextExtent(str
);
893 wxDataViewCustomRendererBase::RenderText(const wxString
& text
,
899 wxRect rectText
= rect
;
900 rectText
.x
+= xoffset
;
901 rectText
.width
-= xoffset
;
903 // check if we want to ellipsize the text if it doesn't fit
904 wxString ellipsizedText
;
905 if ( GetEllipsizeMode() != wxELLIPSIZE_NONE
)
907 ellipsizedText
= wxControl::Ellipsize
913 wxELLIPSIZE_FLAGS_NONE
917 // get the alignment to use
918 int align
= GetAlignment();
919 if ( align
== wxDVR_DEFAULT_ALIGNMENT
)
921 // if we don't have an explicit alignment ourselves, use that of the
922 // column in horizontal direction and default vertical alignment
923 align
= GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
926 dc
->DrawLabel(ellipsizedText
.empty() ? text
: ellipsizedText
,
930 //-----------------------------------------------------------------------------
931 // wxDataViewEditorCtrlEvtHandler
932 //-----------------------------------------------------------------------------
934 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
935 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
936 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
937 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
938 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
941 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
945 m_focusOnIdle
= false;
946 if (wxWindow::FindFocus() != m_editorCtrl
)
947 m_editorCtrl
->SetFocus();
953 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
956 m_owner
->FinishEditing();
959 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
961 switch ( event
.m_keyCode
)
965 m_owner
->FinishEditing();
971 m_owner
->CancelEditing();
979 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
984 m_owner
->FinishEditing();
990 // ---------------------------------------------------------
991 // wxDataViewColumnBase
992 // ---------------------------------------------------------
994 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
995 unsigned int model_column
)
997 m_renderer
= renderer
;
998 m_model_column
= model_column
;
1000 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
1003 wxDataViewColumnBase::~wxDataViewColumnBase()
1008 // ---------------------------------------------------------
1009 // wxDataViewCtrlBase
1010 // ---------------------------------------------------------
1012 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
1014 wxDataViewCtrlBase::wxDataViewCtrlBase()
1017 m_expander_column
= 0;
1021 wxDataViewCtrlBase::~wxDataViewCtrlBase()
1030 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
1034 m_model
->DecRef(); // discard old model, if any
1037 // add our own reference to the new model:
1047 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
1052 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
1057 void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem
& item
)
1059 if (!m_model
) return;
1061 if (!item
.IsOk()) return;
1063 wxVector
<wxDataViewItem
> parentChain
;
1065 // at first we get all the parents of the selected item
1066 wxDataViewItem parent
= m_model
->GetParent(item
);
1067 while (parent
.IsOk())
1069 parentChain
.push_back(parent
);
1070 parent
= m_model
->GetParent(parent
);
1073 // then we expand the parents, starting at the root
1074 while (!parentChain
.empty())
1076 Expand(parentChain
.back());
1077 parentChain
.pop_back();
1081 wxDataViewItem
wxDataViewCtrlBase::GetCurrentItem() const
1083 return HasFlag(wxDV_MULTIPLE
) ? DoGetCurrentItem()
1087 void wxDataViewCtrlBase::SetCurrentItem(const wxDataViewItem
& item
)
1089 wxCHECK_RET( item
.IsOk(), "Can't make current an invalid item." );
1091 if ( HasFlag(wxDV_MULTIPLE
) )
1092 DoSetCurrentItem(item
);
1097 wxDataViewItem
wxDataViewCtrlBase::GetSelection() const
1099 if ( GetSelectedItemsCount() != 1 )
1100 return wxDataViewItem();
1102 wxDataViewItemArray selections
;
1103 GetSelections(selections
);
1104 return selections
[0];
1108 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
1109 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1111 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1112 new wxDataViewTextRenderer( wxT("string"), mode
),
1113 model_column
, width
, align
, flags
);
1114 AppendColumn( ret
);
1119 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
1120 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1122 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1123 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1124 model_column
, width
, align
, flags
);
1125 AppendColumn( ret
);
1130 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
1131 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1133 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1134 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1135 model_column
, width
, align
, flags
);
1136 AppendColumn( ret
);
1141 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
1142 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1144 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1145 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1146 model_column
, width
, align
, flags
);
1147 AppendColumn( ret
);
1152 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
1153 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1155 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1156 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1157 model_column
, width
, align
, flags
);
1158 AppendColumn( ret
);
1163 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
1164 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1166 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1167 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1168 model_column
, width
, align
, flags
);
1169 AppendColumn( ret
);
1174 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1175 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1177 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1178 new wxDataViewTextRenderer( wxT("string"), mode
),
1179 model_column
, width
, align
, flags
);
1180 AppendColumn( ret
);
1185 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1186 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1188 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1189 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1190 model_column
, width
, align
, flags
);
1191 AppendColumn( ret
);
1196 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1197 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1199 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1200 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1201 model_column
, width
, align
, flags
);
1202 AppendColumn( ret
);
1207 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1208 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1210 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1211 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1212 model_column
, width
, align
, flags
);
1213 AppendColumn( ret
);
1218 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1219 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1221 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1222 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1223 model_column
, width
, align
, flags
);
1224 AppendColumn( ret
);
1229 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1230 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1232 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1233 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1234 model_column
, width
, align
, flags
);
1235 AppendColumn( ret
);
1240 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1241 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1243 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1244 new wxDataViewTextRenderer( wxT("string"), mode
),
1245 model_column
, width
, align
, flags
);
1246 PrependColumn( ret
);
1251 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1252 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1254 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1255 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1256 model_column
, width
, align
, flags
);
1257 PrependColumn( ret
);
1262 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1263 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1266 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1267 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1268 model_column
, width
, align
, flags
);
1269 PrependColumn( ret
);
1274 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1275 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1277 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1278 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1279 model_column
, width
, align
, flags
);
1280 PrependColumn( ret
);
1285 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1286 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1288 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1289 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1290 model_column
, width
, align
, flags
);
1291 PrependColumn( ret
);
1296 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1297 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1299 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1300 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1301 model_column
, width
, align
, flags
);
1302 PrependColumn( ret
);
1307 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1308 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1310 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1311 new wxDataViewTextRenderer( wxT("string"), mode
),
1312 model_column
, width
, align
, flags
);
1313 PrependColumn( ret
);
1318 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1319 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1321 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1322 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1323 model_column
, width
, align
, flags
);
1324 PrependColumn( ret
);
1329 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1330 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1332 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1333 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1334 model_column
, width
, align
, flags
);
1335 PrependColumn( ret
);
1340 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1341 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1343 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1344 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1345 model_column
, width
, align
, flags
);
1346 PrependColumn( ret
);
1351 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1352 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1354 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1355 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1356 model_column
, width
, align
, flags
);
1357 PrependColumn( ret
);
1362 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1363 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1365 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1366 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1367 model_column
, width
, align
, flags
);
1368 PrependColumn( ret
);
1373 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1375 col
->SetOwner( (wxDataViewCtrl
*) this );
1380 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1382 col
->SetOwner( (wxDataViewCtrl
*) this );
1387 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1389 col
->SetOwner( (wxDataViewCtrl
*) this );
1393 // ---------------------------------------------------------
1395 // ---------------------------------------------------------
1397 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1399 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
);
1401 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
);
1402 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
);
1403 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
);
1404 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
);
1405 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
);
1406 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
);
1407 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, wxDataViewEvent
);
1408 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
);
1409 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
);
1411 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
);
1413 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
);
1414 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
);
1415 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
);
1416 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
);
1418 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, wxDataViewEvent
);
1420 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
);
1421 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, wxDataViewEvent
);
1422 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, wxDataViewEvent
);
1426 // -------------------------------------
1427 // wxDataViewSpinRenderer
1428 // -------------------------------------
1430 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1431 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1437 wxWindow
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1440 wxSize size
= labelRect
.GetSize();
1442 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1445 str
.Printf( wxT("%d"), (int) l
);
1446 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1447 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1449 size
= sc
->GetSize();
1450 wxPoint pt
= sc
->GetPosition();
1451 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1457 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1459 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1460 long l
= sc
->GetValue();
1465 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1468 str
.Printf(wxT("%d"), (int) m_data
);
1469 RenderText( str
, 0, rect
, dc
, state
);
1473 wxSize
wxDataViewSpinRenderer::GetSize() const
1475 wxSize sz
= GetTextExtent(wxString::Format("%d", (int)m_data
));
1477 // Allow some space for the spin buttons, which is approximately the size
1478 // of a scrollbar (and getting pixel-exact value would be complicated).
1479 // Also add some whitespace between the text and the button:
1480 sz
.x
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1481 sz
.x
+= GetTextExtent("M").x
;
1486 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1488 m_data
= value
.GetLong();
1492 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1498 // -------------------------------------
1499 // wxDataViewChoiceRenderer
1500 // -------------------------------------
1502 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
1504 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1505 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1507 m_choices
= choices
;
1510 wxWindow
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1512 wxChoice
* c
= new wxChoice
1516 labelRect
.GetTopLeft(),
1517 wxSize(labelRect
.GetWidth(), -1),
1520 c
->Move(labelRect
.GetRight() - c
->GetRect().width
, wxDefaultCoord
);
1521 c
->SetStringSelection( value
.GetString() );
1525 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1527 wxChoice
*c
= (wxChoice
*) editor
;
1528 wxString s
= c
->GetStringSelection();
1533 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1535 RenderText( m_data
, 0, rect
, dc
, state
);
1539 wxSize
wxDataViewChoiceRenderer::GetSize() const
1543 for ( wxArrayString::const_iterator i
= m_choices
.begin(); i
!= m_choices
.end(); ++i
)
1544 sz
.IncTo(GetTextExtent(*i
));
1546 // Allow some space for the right-side button, which is approximately the
1547 // size of a scrollbar (and getting pixel-exact value would be complicated).
1548 // Also add some whitespace between the text and the button:
1549 sz
.x
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1550 sz
.x
+= GetTextExtent("M").x
;
1555 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1557 m_data
= value
.GetString();
1561 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1567 // ----------------------------------------------------------------------------
1568 // wxDataViewChoiceByIndexRenderer
1569 // ----------------------------------------------------------------------------
1571 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
1572 wxDataViewCellMode mode
, int alignment
) :
1573 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
1577 wxWindow
* wxDataViewChoiceByIndexRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1579 wxVariant string_value
= GetChoice( value
.GetLong() );
1581 return wxDataViewChoiceRenderer::CreateEditorCtrl( parent
, labelRect
, string_value
);
1584 bool wxDataViewChoiceByIndexRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1586 wxVariant string_value
;
1587 if (!wxDataViewChoiceRenderer::GetValueFromEditorCtrl( editor
, string_value
))
1590 value
= (long) GetChoices().Index( string_value
.GetString() );
1594 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
1596 wxVariant string_value
= GetChoice( value
.GetLong() );
1597 return wxDataViewChoiceRenderer::SetValue( string_value
);
1600 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
1602 wxVariant string_value
;
1603 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
1606 value
= (long) GetChoices().Index( string_value
.GetString() );
1612 //-----------------------------------------------------------------------------
1613 // wxDataViewListStore
1614 //-----------------------------------------------------------------------------
1616 wxDataViewListStore::wxDataViewListStore()
1620 wxDataViewListStore::~wxDataViewListStore()
1622 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1623 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1625 wxDataViewListStoreLine
* line
= *it
;
1630 void wxDataViewListStore::PrependColumn( const wxString
&varianttype
)
1632 m_cols
.Insert( varianttype
, 0 );
1635 void wxDataViewListStore::InsertColumn( unsigned int pos
, const wxString
&varianttype
)
1637 m_cols
.Insert( varianttype
, pos
);
1640 void wxDataViewListStore::AppendColumn( const wxString
&varianttype
)
1642 m_cols
.Add( varianttype
);
1645 unsigned int wxDataViewListStore::GetColumnCount() const
1647 return m_cols
.GetCount();
1650 wxString
wxDataViewListStore::GetColumnType( unsigned int pos
) const
1655 void wxDataViewListStore::AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1657 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1658 line
->m_values
= values
;
1659 m_data
.push_back( line
);
1664 void wxDataViewListStore::PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1666 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1667 line
->m_values
= values
;
1668 m_data
.insert( m_data
.begin(), line
);
1673 void wxDataViewListStore::InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
,
1674 wxClientData
*data
)
1676 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1677 line
->m_values
= values
;
1678 m_data
.insert( m_data
.begin()+row
, line
);
1683 void wxDataViewListStore::DeleteItem( unsigned int row
)
1685 wxVector
<wxDataViewListStoreLine
*>::iterator it
= m_data
.begin() + row
;
1692 void wxDataViewListStore::DeleteAllItems()
1694 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1695 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1697 wxDataViewListStoreLine
* line
= *it
;
1706 void wxDataViewListStore::GetValueByRow( wxVariant
&value
, unsigned int row
, unsigned int col
) const
1708 wxDataViewListStoreLine
*line
= m_data
[row
];
1709 value
= line
->m_values
[col
];
1712 bool wxDataViewListStore::SetValueByRow( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1714 wxDataViewListStoreLine
*line
= m_data
[row
];
1715 line
->m_values
[col
] = value
;
1720 //-----------------------------------------------------------------------------
1721 // wxDataViewListCtrl
1722 //-----------------------------------------------------------------------------
1724 IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl
,wxDataViewCtrl
)
1726 BEGIN_EVENT_TABLE(wxDataViewListCtrl
,wxDataViewCtrl
)
1727 EVT_SIZE( wxDataViewListCtrl::OnSize
)
1730 wxDataViewListCtrl::wxDataViewListCtrl()
1734 wxDataViewListCtrl::wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
1735 const wxPoint
& pos
, const wxSize
& size
, long style
,
1736 const wxValidator
& validator
)
1738 Create( parent
, id
, pos
, size
, style
, validator
);
1741 wxDataViewListCtrl::~wxDataViewListCtrl()
1746 bool wxDataViewListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1747 const wxPoint
& pos
, const wxSize
& size
, long style
,
1748 const wxValidator
& validator
)
1750 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
1753 wxDataViewListStore
*store
= new wxDataViewListStore
;
1754 AssociateModel( store
);
1760 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1762 GetStore()->AppendColumn( varianttype
);
1763 return wxDataViewCtrl::AppendColumn( column
);
1766 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1768 GetStore()->PrependColumn( varianttype
);
1769 return wxDataViewCtrl::PrependColumn( column
);
1772 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
)
1774 GetStore()->InsertColumn( pos
, varianttype
);
1775 return wxDataViewCtrl::InsertColumn( pos
, column
);
1778 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*col
)
1780 return PrependColumn( col
, "string" );
1783 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
1785 return InsertColumn( pos
, col
, "string" );
1788 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*col
)
1790 return AppendColumn( col
, "string" );
1793 wxDataViewColumn
*wxDataViewListCtrl::AppendTextColumn( const wxString
&label
,
1794 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1796 GetStore()->AppendColumn( wxT("string") );
1798 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1799 new wxDataViewTextRenderer( wxT("string"), mode
),
1800 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1802 wxDataViewCtrl::AppendColumn( ret
);
1807 wxDataViewColumn
*wxDataViewListCtrl::AppendToggleColumn( const wxString
&label
,
1808 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1810 GetStore()->AppendColumn( wxT("bool") );
1812 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1813 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1814 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1816 wxDataViewCtrl::AppendColumn( ret
);
1821 wxDataViewColumn
*wxDataViewListCtrl::AppendProgressColumn( const wxString
&label
,
1822 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1824 GetStore()->AppendColumn( wxT("long") );
1826 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1827 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1828 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1830 wxDataViewCtrl::AppendColumn( ret
);
1835 wxDataViewColumn
*wxDataViewListCtrl::AppendIconTextColumn( const wxString
&label
,
1836 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1838 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
1840 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1841 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1842 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1844 wxDataViewCtrl::AppendColumn( ret
);
1849 void wxDataViewListCtrl::OnSize( wxSizeEvent
&event
)
1854 //-----------------------------------------------------------------------------
1855 // wxDataViewTreeStore
1856 //-----------------------------------------------------------------------------
1858 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1859 wxDataViewTreeStoreNode
*parent
,
1860 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1868 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1874 #include "wx/listimpl.cpp"
1875 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1877 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1878 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1879 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1880 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1882 m_iconExpanded
= expanded
;
1883 m_isExpanded
= false;
1884 m_children
.DeleteContents(true);
1887 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1891 //-----------------------------------------------------------------------------
1893 wxDataViewTreeStore::wxDataViewTreeStore()
1895 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1898 wxDataViewTreeStore::~wxDataViewTreeStore()
1903 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1904 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1906 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1907 if (!parent_node
) return wxDataViewItem(0);
1909 wxDataViewTreeStoreNode
*node
=
1910 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1911 parent_node
->GetChildren().Append( node
);
1913 return node
->GetItem();
1916 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1917 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1919 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1920 if (!parent_node
) return wxDataViewItem(0);
1922 wxDataViewTreeStoreNode
*node
=
1923 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1924 parent_node
->GetChildren().Insert( node
);
1926 return node
->GetItem();
1930 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& parent
,
1931 const wxDataViewItem
& previous
,
1932 const wxString
& text
,
1936 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1937 if (!parent_node
) return wxDataViewItem(0);
1939 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1940 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1941 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1943 wxDataViewTreeStoreNode
*node
=
1944 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1945 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1947 return node
->GetItem();
1950 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1951 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1952 wxClientData
*data
)
1954 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1955 if (!parent_node
) return wxDataViewItem(0);
1957 wxDataViewTreeStoreContainerNode
*node
=
1958 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1959 parent_node
->GetChildren().Insert( node
);
1961 return node
->GetItem();
1965 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1966 const wxString
&text
,
1968 const wxIcon
& expanded
,
1969 wxClientData
* data
)
1971 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1972 if (!parent_node
) return wxDataViewItem(0);
1974 wxDataViewTreeStoreContainerNode
*node
=
1975 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1976 parent_node
->GetChildren().Append( node
);
1978 return node
->GetItem();
1982 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& parent
,
1983 const wxDataViewItem
& previous
,
1984 const wxString
& text
,
1986 const wxIcon
& expanded
,
1987 wxClientData
* data
)
1989 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1990 if (!parent_node
) return wxDataViewItem(0);
1992 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1993 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1994 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1996 wxDataViewTreeStoreContainerNode
*node
=
1997 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1998 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
2000 return node
->GetItem();
2003 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
& item
) const
2005 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2006 if (!node
) return false;
2008 return node
->IsContainer();
2011 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
2013 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2014 if (!parent_node
) return wxDataViewItem(0);
2016 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
2018 return wxDataViewItem(node
->GetData());
2020 return wxDataViewItem(0);
2023 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
2025 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
2026 if (!node
) return -1;
2028 if (!node
->IsContainer())
2031 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
2032 return (int) container_node
->GetChildren().GetCount();
2035 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2037 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2040 node
->SetText( text
);
2043 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
2045 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2046 if (!node
) return wxEmptyString
;
2048 return node
->GetText();
2051 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2053 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2056 node
->SetIcon( icon
);
2059 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
2061 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2062 if (!node
) return wxNullIcon
;
2064 return node
->GetIcon();
2067 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2069 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2072 node
->SetExpandedIcon( icon
);
2075 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
2077 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2078 if (!node
) return wxNullIcon
;
2080 return node
->GetExpandedIcon();
2083 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
2085 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2088 node
->SetData( data
);
2091 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
2093 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2094 if (!node
) return NULL
;
2096 return node
->GetData();
2099 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
2101 if (!item
.IsOk()) return;
2103 wxDataViewItem parent_item
= GetParent( item
);
2105 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
2106 if (!parent_node
) return;
2108 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2111 parent_node
->GetChildren().DeleteObject( node
);
2114 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
2116 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2119 node
->GetChildren().clear();
2122 void wxDataViewTreeStore::DeleteAllItems()
2124 DeleteChildren(wxDataViewItem(m_root
));
2128 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
2129 const wxDataViewItem
&item
,
2130 unsigned int WXUNUSED(col
)) const
2132 // if (col != 0) return;
2134 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2137 wxIcon
icon( node
->GetIcon());
2138 if (node
->IsContainer())
2140 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
2141 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
2142 icon
= container
->GetExpandedIcon();
2145 wxDataViewIconText
data( node
->GetText(), icon
);
2151 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
2152 const wxDataViewItem
& item
,
2153 unsigned int WXUNUSED(col
))
2155 // if (col != 0) return false;
2157 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2158 if (!node
) return false;
2160 wxDataViewIconText data
;
2164 node
->SetText( data
.GetText() );
2165 node
->SetIcon( data
.GetIcon() );
2170 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
2172 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2173 if (!node
) return wxDataViewItem(0);
2175 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
2176 if (!parent
) return wxDataViewItem(0);
2178 if (parent
== m_root
)
2179 return wxDataViewItem(0);
2181 return parent
->GetItem();
2184 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
2186 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2187 if (!node
) return 0;
2189 wxDataViewTreeStoreNodeList::iterator iter
;
2190 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2192 wxDataViewTreeStoreNode
* child
= *iter
;
2193 children
.Add( child
->GetItem() );
2196 return node
->GetChildren().GetCount();
2199 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
2200 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) ) const
2202 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
2203 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
2205 if (!node1
|| !node2
)
2208 wxDataViewTreeStoreContainerNode
* parent1
=
2209 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
2210 wxDataViewTreeStoreContainerNode
* parent2
=
2211 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
2213 if (parent1
!= parent2
)
2215 wxLogError( wxT("Comparing items with different parent.") );
2219 if (node1
->IsContainer() && !node2
->IsContainer())
2222 if (node2
->IsContainer() && !node1
->IsContainer())
2225 return parent1
->GetChildren().IndexOf( node1
) - parent2
->GetChildren().IndexOf( node2
);
2228 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
2233 return (wxDataViewTreeStoreNode
*) item
.GetID();
2236 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
2239 return (wxDataViewTreeStoreContainerNode
*) m_root
;
2241 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
2243 if (!node
->IsContainer())
2246 return (wxDataViewTreeStoreContainerNode
*) node
;
2249 //-----------------------------------------------------------------------------
2250 // wxDataViewTreeCtrl
2251 //-----------------------------------------------------------------------------
2253 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2255 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2256 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
2257 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
2258 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
2261 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2262 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2264 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
2267 // create the standard model and a column in the tree
2268 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
2269 AssociateModel( store
);
2272 AppendIconTextColumn
2274 wxString(), // no label (header is not shown anyhow)
2275 0, // the only model column
2276 wxDATAVIEW_CELL_EDITABLE
,
2277 -1, // default width
2278 wxALIGN_NOT
, // and alignment
2285 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
2286 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2288 wxDataViewItem res
= GetStore()->
2289 AppendItem( parent
, text
, GetImage(iconIndex
), data
);
2291 GetStore()->ItemAdded( parent
, res
);
2296 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
2297 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2299 wxDataViewItem res
= GetStore()->
2300 PrependItem( parent
, text
, GetImage(iconIndex
), data
);
2302 GetStore()->ItemAdded( parent
, res
);
2307 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2308 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2310 wxDataViewItem res
= GetStore()->
2311 InsertItem( parent
, previous
, text
, GetImage(iconIndex
), data
);
2313 GetStore()->ItemAdded( parent
, res
);
2318 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
2319 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2321 wxDataViewItem res
= GetStore()->
2322 PrependContainer( parent
, text
,
2323 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2325 GetStore()->ItemAdded( parent
, res
);
2330 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
2331 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2333 wxDataViewItem res
= GetStore()->
2334 AppendContainer( parent
, text
,
2335 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2337 GetStore()->ItemAdded( parent
, res
);
2342 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2343 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2345 wxDataViewItem res
= GetStore()->
2346 InsertContainer( parent
, previous
, text
,
2347 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2349 GetStore()->ItemAdded( parent
, res
);
2354 void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2356 GetStore()->SetItemText(item
,text
);
2359 GetStore()->ValueChanged( item
, 0 );
2362 void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2364 GetStore()->SetItemIcon(item
,icon
);
2367 GetStore()->ValueChanged( item
, 0 );
2370 void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2372 GetStore()->SetItemExpandedIcon(item
,icon
);
2375 GetStore()->ValueChanged( item
, 0 );
2378 void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem
& item
)
2380 wxDataViewItem parent_item
= GetStore()->GetParent( item
);
2382 GetStore()->DeleteItem(item
);
2385 GetStore()->ItemDeleted( parent_item
, item
);
2388 void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem
& item
)
2390 wxDataViewTreeStoreContainerNode
*node
= GetStore()->FindContainerNode( item
);
2393 wxDataViewItemArray array
;
2394 wxDataViewTreeStoreNodeList::iterator iter
;
2395 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2397 wxDataViewTreeStoreNode
* child
= *iter
;
2398 array
.Add( child
->GetItem() );
2401 GetStore()->DeleteChildren( item
);
2404 GetStore()->ItemsDeleted( item
, array
);
2407 void wxDataViewTreeCtrl::DeleteAllItems()
2409 GetStore()->DeleteAllItems();
2411 GetStore()->Cleared();
2414 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
2416 if (HasImageList()) return;
2418 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2419 if (!container
) return;
2421 container
->SetExpanded( true );
2423 GetStore()->ItemChanged( event
.GetItem() );
2426 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
2428 if (HasImageList()) return;
2430 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2431 if (!container
) return;
2433 container
->SetExpanded( false );
2435 GetStore()->ItemChanged( event
.GetItem() );
2438 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
2440 #if defined(wxUSE_GENERICDATAVIEWCTRL)
2441 // automatically resize our only column to take the entire control width
2442 if ( GetColumnCount() )
2444 wxSize size
= GetClientSize();
2445 GetColumn(0)->SetWidth(size
.x
);
2451 #endif // wxUSE_DATAVIEWCTRL