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( 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( wxUIntToPtr(i
) );
408 m_nextFreeID
= new_size
+ 1;
410 /* wxDataViewModel:: */ AfterReset();
413 void wxDataViewIndexListModel::RowPrepended()
417 unsigned int id
= m_nextFreeID
;
420 m_hash
.Insert( wxUIntToPtr(id
), 0 );
421 wxDataViewItem
item( wxUIntToPtr(id
) );
422 ItemAdded( wxDataViewItem(0), item
);
426 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
430 unsigned int id
= m_nextFreeID
;
433 m_hash
.Insert( wxUIntToPtr(id
), before
);
434 wxDataViewItem
item( wxUIntToPtr(id
) );
435 ItemAdded( wxDataViewItem(0), item
);
438 void wxDataViewIndexListModel::RowAppended()
440 unsigned int id
= m_nextFreeID
;
443 m_hash
.Add( wxUIntToPtr(id
) );
444 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
.GetID() );
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 const 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 // Hide the control immediately but don't delete it yet as there could be
732 // some pending messages for it.
733 m_editorCtrl
->Hide();
735 wxEvtHandler
* const handler
= m_editorCtrl
->PopEventHandler();
737 wxPendingDelete
.Append(handler
);
738 wxPendingDelete
.Append(m_editorCtrl
);
741 void wxDataViewRendererBase::CancelEditing()
746 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
748 DestroyEditControl();
751 bool wxDataViewRendererBase::FinishEditing()
757 GetValueFromEditorCtrl( m_editorCtrl
, value
);
759 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
761 dv_ctrl
->GetMainWindow()->SetFocus();
763 DestroyEditControl();
765 if (!Validate(value
))
768 unsigned int col
= GetOwner()->GetModelColumn();
769 dv_ctrl
->GetModel()->ChangeValue(value
, m_item
, col
);
771 // Now we should send Editing Done event
772 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv_ctrl
->GetId() );
773 event
.SetDataViewColumn( GetOwner() );
774 event
.SetModel( dv_ctrl
->GetModel() );
775 event
.SetItem( m_item
);
776 event
.SetEventObject( dv_ctrl
);
777 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
782 void wxDataViewRendererBase::PrepareForItem(const wxDataViewModel
*model
,
783 const wxDataViewItem
& item
,
787 model
->GetValue(value
, item
, column
);
790 wxDataViewItemAttr attr
;
791 model
->GetAttr(item
, column
, attr
);
794 SetEnabled(model
->IsEnabled(item
, column
));
798 // ----------------------------------------------------------------------------
799 // wxDataViewCustomRendererBase
800 // ----------------------------------------------------------------------------
803 wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell
, wxDC
*dc
, int state
)
805 wxCHECK_RET( dc
, "no DC to draw on in custom renderer?" );
807 // adjust the rectangle ourselves to account for the alignment
808 wxRect rectItem
= rectCell
;
809 const int align
= GetAlignment();
810 if ( align
!= wxDVR_DEFAULT_ALIGNMENT
)
812 const wxSize size
= GetSize();
814 // take alignment into account only if there is enough space, otherwise
815 // show as much contents as possible
817 // notice that many existing renderers (e.g. wxDataViewSpinRenderer)
818 // return hard-coded size which can be more than they need and if we
819 // trusted their GetSize() we'd draw the text out of cell bounds
822 if ( size
.x
>= 0 && size
.x
< rectCell
.width
)
824 if ( align
& wxALIGN_CENTER_HORIZONTAL
)
825 rectItem
.x
+= (rectCell
.width
- size
.x
)/2;
826 else if ( align
& wxALIGN_RIGHT
)
827 rectItem
.x
+= rectCell
.width
- size
.x
;
828 // else: wxALIGN_LEFT is the default
830 rectItem
.width
= size
.x
;
833 if ( size
.y
>= 0 && size
.y
< rectCell
.height
)
835 if ( align
& wxALIGN_CENTER_VERTICAL
)
836 rectItem
.y
+= (rectCell
.height
- size
.y
)/2;
837 else if ( align
& wxALIGN_BOTTOM
)
838 rectItem
.y
+= rectCell
.height
- size
.y
;
839 // else: wxALIGN_TOP is the default
841 rectItem
.height
= size
.y
;
846 // set up the DC attributes
848 // override custom foreground with the standard one for the selected items
849 // because we currently don't allow changing the selection background and
850 // custom colours may be unreadable on it
852 if ( state
& wxDATAVIEW_CELL_SELECTED
)
853 col
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
854 else if ( m_attr
.HasColour() )
855 col
= m_attr
.GetColour();
856 else // use default foreground
857 col
= GetOwner()->GetOwner()->GetForegroundColour();
859 wxDCTextColourChanger
changeFg(*dc
, col
);
861 wxDCFontChanger
changeFont(*dc
);
862 if ( m_attr
.HasFont() )
863 changeFont
.Set(m_attr
.GetEffectiveFont(dc
->GetFont()));
865 Render(rectItem
, dc
, state
);
868 wxSize
wxDataViewCustomRendererBase::GetTextExtent(const wxString
& str
) const
870 const wxDataViewCtrl
*view
= GetView();
872 if ( m_attr
.HasFont() )
874 wxFont
font(m_attr
.GetEffectiveFont(view
->GetFont()));
876 view
->GetTextExtent(str
, &size
.x
, &size
.y
, NULL
, NULL
, &font
);
881 return view
->GetTextExtent(str
);
886 wxDataViewCustomRendererBase::RenderText(const wxString
& text
,
892 wxRect rectText
= rect
;
893 rectText
.x
+= xoffset
;
894 rectText
.width
-= xoffset
;
896 // check if we want to ellipsize the text if it doesn't fit
897 wxString ellipsizedText
;
898 if ( GetEllipsizeMode() != wxELLIPSIZE_NONE
)
900 ellipsizedText
= wxControl::Ellipsize
906 wxELLIPSIZE_FLAGS_NONE
910 // get the alignment to use
911 int align
= GetAlignment();
912 if ( align
== wxDVR_DEFAULT_ALIGNMENT
)
914 // if we don't have an explicit alignment ourselves, use that of the
915 // column in horizontal direction and default vertical alignment
916 align
= GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
919 dc
->DrawLabel(ellipsizedText
.empty() ? text
: ellipsizedText
,
923 //-----------------------------------------------------------------------------
924 // wxDataViewEditorCtrlEvtHandler
925 //-----------------------------------------------------------------------------
927 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
928 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
929 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
930 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
931 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
934 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
938 m_focusOnIdle
= false;
939 if (wxWindow::FindFocus() != m_editorCtrl
)
940 m_editorCtrl
->SetFocus();
946 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
949 m_owner
->FinishEditing();
952 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
954 switch ( event
.m_keyCode
)
958 m_owner
->FinishEditing();
964 m_owner
->CancelEditing();
972 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
977 m_owner
->FinishEditing();
983 // ---------------------------------------------------------
984 // wxDataViewColumnBase
985 // ---------------------------------------------------------
987 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
988 unsigned int model_column
)
990 m_renderer
= renderer
;
991 m_model_column
= model_column
;
993 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
996 wxDataViewColumnBase::~wxDataViewColumnBase()
1001 // ---------------------------------------------------------
1002 // wxDataViewCtrlBase
1003 // ---------------------------------------------------------
1005 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
1007 wxDataViewCtrlBase::wxDataViewCtrlBase()
1010 m_expander_column
= 0;
1014 wxDataViewCtrlBase::~wxDataViewCtrlBase()
1023 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
1027 m_model
->DecRef(); // discard old model, if any
1030 // add our own reference to the new model:
1040 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
1045 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
1050 void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem
& item
)
1052 if (!m_model
) return;
1054 if (!item
.IsOk()) return;
1056 wxVector
<wxDataViewItem
> parentChain
;
1058 // at first we get all the parents of the selected item
1059 wxDataViewItem parent
= m_model
->GetParent(item
);
1060 while (parent
.IsOk())
1062 parentChain
.push_back(parent
);
1063 parent
= m_model
->GetParent(parent
);
1066 // then we expand the parents, starting at the root
1067 while (!parentChain
.empty())
1069 Expand(parentChain
.back());
1070 parentChain
.pop_back();
1074 wxDataViewItem
wxDataViewCtrlBase::GetCurrentItem() const
1076 return HasFlag(wxDV_MULTIPLE
) ? DoGetCurrentItem()
1080 void wxDataViewCtrlBase::SetCurrentItem(const wxDataViewItem
& item
)
1082 wxCHECK_RET( item
.IsOk(), "Can't make current an invalid item." );
1084 if ( HasFlag(wxDV_MULTIPLE
) )
1085 DoSetCurrentItem(item
);
1091 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
1092 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1094 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1095 new wxDataViewTextRenderer( wxT("string"), mode
),
1096 model_column
, width
, align
, flags
);
1097 AppendColumn( ret
);
1102 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
1103 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1105 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1106 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1107 model_column
, width
, align
, flags
);
1108 AppendColumn( ret
);
1113 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
1114 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1116 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1117 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1118 model_column
, width
, align
, flags
);
1119 AppendColumn( ret
);
1124 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
1125 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1127 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1128 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1129 model_column
, width
, align
, flags
);
1130 AppendColumn( ret
);
1135 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
1136 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1138 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1139 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1140 model_column
, width
, align
, flags
);
1141 AppendColumn( ret
);
1146 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
1147 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1149 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1150 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1151 model_column
, width
, align
, flags
);
1152 AppendColumn( ret
);
1157 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1158 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1160 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1161 new wxDataViewTextRenderer( wxT("string"), mode
),
1162 model_column
, width
, align
, flags
);
1163 AppendColumn( ret
);
1168 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1169 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1171 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1172 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1173 model_column
, width
, align
, flags
);
1174 AppendColumn( ret
);
1179 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1180 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1182 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1183 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1184 model_column
, width
, align
, flags
);
1185 AppendColumn( ret
);
1190 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1191 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1193 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1194 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1195 model_column
, width
, align
, flags
);
1196 AppendColumn( ret
);
1201 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1202 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1204 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1205 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1206 model_column
, width
, align
, flags
);
1207 AppendColumn( ret
);
1212 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1213 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1215 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1216 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1217 model_column
, width
, align
, flags
);
1218 AppendColumn( ret
);
1223 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1224 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1226 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1227 new wxDataViewTextRenderer( wxT("string"), mode
),
1228 model_column
, width
, align
, flags
);
1229 PrependColumn( ret
);
1234 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1235 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1237 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1238 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1239 model_column
, width
, align
, flags
);
1240 PrependColumn( ret
);
1245 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1246 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1249 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1250 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1251 model_column
, width
, align
, flags
);
1252 PrependColumn( ret
);
1257 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1258 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1260 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1261 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1262 model_column
, width
, align
, flags
);
1263 PrependColumn( ret
);
1268 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1269 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1271 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1272 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1273 model_column
, width
, align
, flags
);
1274 PrependColumn( ret
);
1279 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1280 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1282 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1283 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1284 model_column
, width
, align
, flags
);
1285 PrependColumn( ret
);
1290 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1291 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1293 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1294 new wxDataViewTextRenderer( wxT("string"), mode
),
1295 model_column
, width
, align
, flags
);
1296 PrependColumn( ret
);
1301 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1302 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1304 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1305 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1306 model_column
, width
, align
, flags
);
1307 PrependColumn( ret
);
1312 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1313 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1315 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1316 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1317 model_column
, width
, align
, flags
);
1318 PrependColumn( ret
);
1323 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1324 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1326 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1327 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1328 model_column
, width
, align
, flags
);
1329 PrependColumn( ret
);
1334 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1335 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1337 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1338 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1339 model_column
, width
, align
, flags
);
1340 PrependColumn( ret
);
1345 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1346 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1348 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1349 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1350 model_column
, width
, align
, flags
);
1351 PrependColumn( ret
);
1356 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1358 col
->SetOwner( (wxDataViewCtrl
*) this );
1363 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1365 col
->SetOwner( (wxDataViewCtrl
*) this );
1370 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1372 col
->SetOwner( (wxDataViewCtrl
*) this );
1376 // ---------------------------------------------------------
1378 // ---------------------------------------------------------
1380 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1382 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
);
1384 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
);
1385 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
);
1386 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
);
1387 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
);
1388 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
);
1389 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
);
1390 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, wxDataViewEvent
);
1391 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
);
1392 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
);
1394 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
);
1396 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
);
1397 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
);
1398 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
);
1399 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
);
1401 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, wxDataViewEvent
);
1403 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
);
1404 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, wxDataViewEvent
);
1405 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, wxDataViewEvent
);
1409 // -------------------------------------
1410 // wxDataViewSpinRenderer
1411 // -------------------------------------
1413 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1414 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1420 wxWindow
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1423 wxSize size
= labelRect
.GetSize();
1425 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1428 str
.Printf( wxT("%d"), (int) l
);
1429 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1430 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1432 size
= sc
->GetSize();
1433 wxPoint pt
= sc
->GetPosition();
1434 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1440 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1442 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1443 long l
= sc
->GetValue();
1448 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1451 str
.Printf(wxT("%d"), (int) m_data
);
1452 RenderText( str
, 0, rect
, dc
, state
);
1456 wxSize
wxDataViewSpinRenderer::GetSize() const
1458 return wxSize(80,16);
1461 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1463 m_data
= value
.GetLong();
1467 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1473 // -------------------------------------
1474 // wxDataViewChoiceRenderer
1475 // -------------------------------------
1477 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
1479 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1480 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1482 m_choices
= choices
;
1485 wxWindow
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1487 wxChoice
* c
= new wxChoice
1491 labelRect
.GetTopLeft(),
1492 wxSize(labelRect
.GetWidth(), -1),
1495 c
->Move(labelRect
.GetRight() - c
->GetRect().width
, wxDefaultCoord
);
1496 c
->SetStringSelection( value
.GetString() );
1500 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1502 wxChoice
*c
= (wxChoice
*) editor
;
1503 wxString s
= c
->GetStringSelection();
1508 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1510 RenderText( m_data
, 0, rect
, dc
, state
);
1514 wxSize
wxDataViewChoiceRenderer::GetSize() const
1516 return wxSize(80,16);
1519 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1521 m_data
= value
.GetString();
1525 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1531 // ----------------------------------------------------------------------------
1532 // wxDataViewChoiceByIndexRenderer
1533 // ----------------------------------------------------------------------------
1535 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
1536 wxDataViewCellMode mode
, int alignment
) :
1537 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
1541 wxWindow
* wxDataViewChoiceByIndexRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1543 wxVariant string_value
= GetChoice( value
.GetLong() );
1545 return wxDataViewChoiceRenderer::CreateEditorCtrl( parent
, labelRect
, string_value
);
1548 bool wxDataViewChoiceByIndexRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1550 wxVariant string_value
;
1551 if (!wxDataViewChoiceRenderer::GetValueFromEditorCtrl( editor
, string_value
))
1554 value
= (long) GetChoices().Index( string_value
.GetString() );
1558 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
1560 wxVariant string_value
= GetChoice( value
.GetLong() );
1561 return wxDataViewChoiceRenderer::SetValue( string_value
);
1564 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
1566 wxVariant string_value
;
1567 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
1570 value
= (long) GetChoices().Index( string_value
.GetString() );
1576 //-----------------------------------------------------------------------------
1577 // wxDataViewListStore
1578 //-----------------------------------------------------------------------------
1580 wxDataViewListStore::wxDataViewListStore()
1584 wxDataViewListStore::~wxDataViewListStore()
1586 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1587 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1589 wxDataViewListStoreLine
* line
= *it
;
1594 void wxDataViewListStore::PrependColumn( const wxString
&varianttype
)
1596 m_cols
.Insert( varianttype
, 0 );
1599 void wxDataViewListStore::InsertColumn( unsigned int pos
, const wxString
&varianttype
)
1601 m_cols
.Insert( varianttype
, pos
);
1604 void wxDataViewListStore::AppendColumn( const wxString
&varianttype
)
1606 m_cols
.Add( varianttype
);
1609 unsigned int wxDataViewListStore::GetColumnCount() const
1611 return m_cols
.GetCount();
1614 wxString
wxDataViewListStore::GetColumnType( unsigned int pos
) const
1619 void wxDataViewListStore::AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1621 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1622 line
->m_values
= values
;
1623 m_data
.push_back( line
);
1628 void wxDataViewListStore::PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1630 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1631 line
->m_values
= values
;
1632 m_data
.insert( m_data
.begin(), line
);
1637 void wxDataViewListStore::InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
,
1638 wxClientData
*data
)
1640 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1641 line
->m_values
= values
;
1642 m_data
.insert( m_data
.begin()+row
, line
);
1647 void wxDataViewListStore::DeleteItem( unsigned int row
)
1649 wxVector
<wxDataViewListStoreLine
*>::iterator it
= m_data
.begin() + row
;
1656 void wxDataViewListStore::DeleteAllItems()
1658 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1659 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1661 wxDataViewListStoreLine
* line
= *it
;
1670 void wxDataViewListStore::GetValueByRow( wxVariant
&value
, unsigned int row
, unsigned int col
) const
1672 wxDataViewListStoreLine
*line
= m_data
[row
];
1673 value
= line
->m_values
[col
];
1676 bool wxDataViewListStore::SetValueByRow( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1678 wxDataViewListStoreLine
*line
= m_data
[row
];
1679 line
->m_values
[col
] = value
;
1684 //-----------------------------------------------------------------------------
1685 // wxDataViewListCtrl
1686 //-----------------------------------------------------------------------------
1688 IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl
,wxDataViewCtrl
)
1690 BEGIN_EVENT_TABLE(wxDataViewListCtrl
,wxDataViewCtrl
)
1691 EVT_SIZE( wxDataViewListCtrl::OnSize
)
1694 wxDataViewListCtrl::wxDataViewListCtrl()
1698 wxDataViewListCtrl::wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
1699 const wxPoint
& pos
, const wxSize
& size
, long style
,
1700 const wxValidator
& validator
)
1702 Create( parent
, id
, pos
, size
, style
, validator
);
1705 wxDataViewListCtrl::~wxDataViewListCtrl()
1710 bool wxDataViewListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1711 const wxPoint
& pos
, const wxSize
& size
, long style
,
1712 const wxValidator
& validator
)
1714 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
1717 wxDataViewListStore
*store
= new wxDataViewListStore
;
1718 AssociateModel( store
);
1724 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1726 GetStore()->AppendColumn( varianttype
);
1727 return wxDataViewCtrl::AppendColumn( column
);
1730 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1732 GetStore()->PrependColumn( varianttype
);
1733 return wxDataViewCtrl::PrependColumn( column
);
1736 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
)
1738 GetStore()->InsertColumn( pos
, varianttype
);
1739 return wxDataViewCtrl::InsertColumn( pos
, column
);
1742 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*col
)
1744 return PrependColumn( col
, "string" );
1747 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
1749 return InsertColumn( pos
, col
, "string" );
1752 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*col
)
1754 return AppendColumn( col
, "string" );
1757 wxDataViewColumn
*wxDataViewListCtrl::AppendTextColumn( const wxString
&label
,
1758 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1760 GetStore()->AppendColumn( wxT("string") );
1762 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1763 new wxDataViewTextRenderer( wxT("string"), mode
),
1764 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1766 wxDataViewCtrl::AppendColumn( ret
);
1771 wxDataViewColumn
*wxDataViewListCtrl::AppendToggleColumn( const wxString
&label
,
1772 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1774 GetStore()->AppendColumn( wxT("bool") );
1776 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1777 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1778 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1780 wxDataViewCtrl::AppendColumn( ret
);
1785 wxDataViewColumn
*wxDataViewListCtrl::AppendProgressColumn( const wxString
&label
,
1786 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1788 GetStore()->AppendColumn( wxT("long") );
1790 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1791 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1792 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1794 wxDataViewCtrl::AppendColumn( ret
);
1799 wxDataViewColumn
*wxDataViewListCtrl::AppendIconTextColumn( const wxString
&label
,
1800 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1802 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
1804 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1805 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1806 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1808 wxDataViewCtrl::AppendColumn( ret
);
1813 void wxDataViewListCtrl::OnSize( wxSizeEvent
&event
)
1818 //-----------------------------------------------------------------------------
1819 // wxDataViewTreeStore
1820 //-----------------------------------------------------------------------------
1822 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1823 wxDataViewTreeStoreNode
*parent
,
1824 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1832 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1838 #include "wx/listimpl.cpp"
1839 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1841 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1842 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1843 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1844 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1846 m_iconExpanded
= expanded
;
1847 m_isExpanded
= false;
1848 m_children
.DeleteContents(true);
1851 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1855 //-----------------------------------------------------------------------------
1857 wxDataViewTreeStore::wxDataViewTreeStore()
1859 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1862 wxDataViewTreeStore::~wxDataViewTreeStore()
1867 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1868 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1870 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1871 if (!parent_node
) return wxDataViewItem(0);
1873 wxDataViewTreeStoreNode
*node
=
1874 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1875 parent_node
->GetChildren().Append( node
);
1877 return node
->GetItem();
1880 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1881 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1883 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1884 if (!parent_node
) return wxDataViewItem(0);
1886 wxDataViewTreeStoreNode
*node
=
1887 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1888 parent_node
->GetChildren().Insert( node
);
1890 return node
->GetItem();
1894 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& parent
,
1895 const wxDataViewItem
& previous
,
1896 const wxString
& text
,
1900 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1901 if (!parent_node
) return wxDataViewItem(0);
1903 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1904 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1905 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1907 wxDataViewTreeStoreNode
*node
=
1908 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1909 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1911 return node
->GetItem();
1914 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1915 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1916 wxClientData
*data
)
1918 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1919 if (!parent_node
) return wxDataViewItem(0);
1921 wxDataViewTreeStoreContainerNode
*node
=
1922 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1923 parent_node
->GetChildren().Insert( node
);
1925 return node
->GetItem();
1929 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1930 const wxString
&text
,
1932 const wxIcon
& expanded
,
1933 wxClientData
* data
)
1935 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1936 if (!parent_node
) return wxDataViewItem(0);
1938 wxDataViewTreeStoreContainerNode
*node
=
1939 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1940 parent_node
->GetChildren().Append( node
);
1942 return node
->GetItem();
1946 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& parent
,
1947 const wxDataViewItem
& previous
,
1948 const wxString
& text
,
1950 const wxIcon
& expanded
,
1951 wxClientData
* data
)
1953 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1954 if (!parent_node
) return wxDataViewItem(0);
1956 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1957 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1958 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1960 wxDataViewTreeStoreContainerNode
*node
=
1961 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1962 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1964 return node
->GetItem();
1967 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
& item
) const
1969 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1970 if (!node
) return false;
1972 return node
->IsContainer();
1975 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1977 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1978 if (!parent_node
) return wxDataViewItem(0);
1980 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1982 return node
->GetData();
1984 return wxDataViewItem(0);
1987 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1989 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1990 if (!node
) return -1;
1992 if (!node
->IsContainer())
1995 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1996 return (int) container_node
->GetChildren().GetCount();
1999 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2001 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2004 node
->SetText( text
);
2007 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
2009 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2010 if (!node
) return wxEmptyString
;
2012 return node
->GetText();
2015 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2017 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2020 node
->SetIcon( icon
);
2023 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
2025 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2026 if (!node
) return wxNullIcon
;
2028 return node
->GetIcon();
2031 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2033 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2036 node
->SetExpandedIcon( icon
);
2039 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
2041 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2042 if (!node
) return wxNullIcon
;
2044 return node
->GetExpandedIcon();
2047 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
2049 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2052 node
->SetData( data
);
2055 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
2057 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2058 if (!node
) return NULL
;
2060 return node
->GetData();
2063 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
2065 if (!item
.IsOk()) return;
2067 wxDataViewItem parent_item
= GetParent( item
);
2069 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
2070 if (!parent_node
) return;
2072 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2075 parent_node
->GetChildren().DeleteObject( node
);
2078 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
2080 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2083 node
->GetChildren().clear();
2086 void wxDataViewTreeStore::DeleteAllItems()
2088 DeleteChildren(m_root
);
2092 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
2093 const wxDataViewItem
&item
,
2094 unsigned int WXUNUSED(col
)) const
2096 // if (col != 0) return;
2098 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2101 wxIcon
icon( node
->GetIcon());
2102 if (node
->IsContainer())
2104 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
2105 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
2106 icon
= container
->GetExpandedIcon();
2109 wxDataViewIconText
data( node
->GetText(), icon
);
2115 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
2116 const wxDataViewItem
& item
,
2117 unsigned int WXUNUSED(col
))
2119 // if (col != 0) return false;
2121 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2122 if (!node
) return false;
2124 wxDataViewIconText data
;
2128 node
->SetText( data
.GetText() );
2129 node
->SetIcon( data
.GetIcon() );
2134 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
2136 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2137 if (!node
) return wxDataViewItem(0);
2139 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
2140 if (!parent
) return wxDataViewItem(0);
2142 if (parent
== m_root
)
2143 return wxDataViewItem(0);
2145 return parent
->GetItem();
2148 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
2150 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2151 if (!node
) return 0;
2153 wxDataViewTreeStoreNodeList::iterator iter
;
2154 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2156 wxDataViewTreeStoreNode
* child
= *iter
;
2157 children
.Add( child
->GetItem() );
2160 return node
->GetChildren().GetCount();
2163 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
2164 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) ) const
2166 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
2167 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
2169 if (!node1
|| !node2
)
2172 wxDataViewTreeStoreContainerNode
* parent1
=
2173 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
2174 wxDataViewTreeStoreContainerNode
* parent2
=
2175 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
2177 if (parent1
!= parent2
)
2179 wxLogError( wxT("Comparing items with different parent.") );
2183 if (node1
->IsContainer() && !node2
->IsContainer())
2186 if (node2
->IsContainer() && !node1
->IsContainer())
2189 return parent1
->GetChildren().IndexOf( node1
) - parent2
->GetChildren().IndexOf( node2
);
2192 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
2197 return (wxDataViewTreeStoreNode
*) item
.GetID();
2200 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
2203 return (wxDataViewTreeStoreContainerNode
*) m_root
;
2205 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
2207 if (!node
->IsContainer())
2210 return (wxDataViewTreeStoreContainerNode
*) node
;
2213 //-----------------------------------------------------------------------------
2214 // wxDataViewTreeCtrl
2215 //-----------------------------------------------------------------------------
2217 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2219 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2220 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
2221 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
2222 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
2225 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
2230 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2231 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2233 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
2236 // create the standard model and a column in the tree
2237 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
2238 AssociateModel( store
);
2241 AppendIconTextColumn
2243 wxString(), // no label (header is not shown anyhow)
2244 0, // the only model column
2245 wxDATAVIEW_CELL_EDITABLE
,
2246 -1, // default width
2247 wxALIGN_NOT
, // and alignment
2254 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
2258 m_imageList
= imagelist
;
2261 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
2262 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2264 wxIcon icon
= wxNullIcon
;
2265 if (m_imageList
&& (iconIndex
!= -1))
2266 icon
= m_imageList
->GetIcon( iconIndex
);
2268 wxDataViewItem res
= GetStore()->AppendItem( parent
, text
, icon
, data
);
2270 GetStore()->ItemAdded( parent
, res
);
2275 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
2276 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2278 wxIcon icon
= wxNullIcon
;
2279 if (m_imageList
&& (iconIndex
!= -1))
2280 icon
= m_imageList
->GetIcon( iconIndex
);
2282 wxDataViewItem res
= GetStore()->PrependItem( parent
, text
, icon
, data
);
2284 GetStore()->ItemAdded( parent
, res
);
2289 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2290 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2292 wxIcon icon
= wxNullIcon
;
2293 if (m_imageList
&& (iconIndex
!= -1))
2294 icon
= m_imageList
->GetIcon( iconIndex
);
2296 wxDataViewItem res
= GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
2298 GetStore()->ItemAdded( parent
, res
);
2303 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
2304 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2306 wxIcon icon
= wxNullIcon
;
2307 if (m_imageList
&& (iconIndex
!= -1))
2308 icon
= m_imageList
->GetIcon( iconIndex
);
2310 wxIcon expanded
= wxNullIcon
;
2311 if (m_imageList
&& (expandedIndex
!= -1))
2312 expanded
= m_imageList
->GetIcon( expandedIndex
);
2314 wxDataViewItem res
= GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
2316 GetStore()->ItemAdded( parent
, res
);
2321 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
2322 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2324 wxIcon icon
= wxNullIcon
;
2325 if (m_imageList
&& (iconIndex
!= -1))
2326 icon
= m_imageList
->GetIcon( iconIndex
);
2328 wxIcon expanded
= wxNullIcon
;
2329 if (m_imageList
&& (expandedIndex
!= -1))
2330 expanded
= m_imageList
->GetIcon( expandedIndex
);
2332 wxDataViewItem res
= GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
2334 GetStore()->ItemAdded( parent
, res
);
2339 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2340 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2342 wxIcon icon
= wxNullIcon
;
2343 if (m_imageList
&& (iconIndex
!= -1))
2344 icon
= m_imageList
->GetIcon( iconIndex
);
2346 wxIcon expanded
= wxNullIcon
;
2347 if (m_imageList
&& (expandedIndex
!= -1))
2348 expanded
= m_imageList
->GetIcon( expandedIndex
);
2350 wxDataViewItem res
= GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
2352 GetStore()->ItemAdded( parent
, res
);
2357 void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2359 GetStore()->SetItemText(item
,text
);
2362 GetStore()->ValueChanged( item
, 0 );
2365 void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2367 GetStore()->SetItemIcon(item
,icon
);
2370 GetStore()->ValueChanged( item
, 0 );
2373 void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2375 GetStore()->SetItemExpandedIcon(item
,icon
);
2378 GetStore()->ValueChanged( item
, 0 );
2381 void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem
& item
)
2383 wxDataViewItem parent_item
= GetStore()->GetParent( item
);
2385 GetStore()->DeleteItem(item
);
2388 GetStore()->ItemDeleted( parent_item
, item
);
2391 void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem
& item
)
2393 wxDataViewTreeStoreContainerNode
*node
= GetStore()->FindContainerNode( item
);
2396 wxDataViewItemArray array
;
2397 wxDataViewTreeStoreNodeList::iterator iter
;
2398 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2400 wxDataViewTreeStoreNode
* child
= *iter
;
2401 array
.Add( child
->GetItem() );
2404 GetStore()->DeleteChildren( item
);
2407 GetStore()->ItemsDeleted( item
, array
);
2410 void wxDataViewTreeCtrl::DeleteAllItems()
2412 GetStore()->DeleteAllItems();
2414 GetStore()->Cleared();
2417 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
2419 if (m_imageList
) return;
2421 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2422 if (!container
) return;
2424 container
->SetExpanded( true );
2426 GetStore()->ItemChanged( event
.GetItem() );
2429 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
2431 if (m_imageList
) return;
2433 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2434 if (!container
) return;
2436 container
->SetExpanded( false );
2438 GetStore()->ItemChanged( event
.GetItem() );
2441 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
2443 #if defined(wxUSE_GENERICDATAVIEWCTRL)
2444 // automatically resize our only column to take the entire control width
2445 if ( GetColumnCount() )
2447 wxSize size
= GetClientSize();
2448 GetColumn(0)->SetWidth(size
.x
);
2454 #endif // wxUSE_DATAVIEWCTRL