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(wxControl
*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 wxControl
*m_editorCtrl
;
70 } // anonymous namespace
72 // ---------------------------------------------------------
73 // wxDataViewModelNotifier
74 // ---------------------------------------------------------
76 #include "wx/listimpl.cpp"
77 WX_DEFINE_LIST(wxDataViewModelNotifiers
)
79 bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
81 size_t count
= items
.GetCount();
83 for (i
= 0; i
< count
; i
++)
84 if (!ItemAdded( parent
, items
[i
] )) return false;
89 bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
91 size_t count
= items
.GetCount();
93 for (i
= 0; i
< count
; i
++)
94 if (!ItemDeleted( parent
, items
[i
] )) return false;
99 bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray
&items
)
101 size_t count
= items
.GetCount();
103 for (i
= 0; i
< count
; i
++)
104 if (!ItemChanged( items
[i
] )) return false;
109 // ---------------------------------------------------------
111 // ---------------------------------------------------------
113 wxDataViewModel::wxDataViewModel()
115 m_notifiers
.DeleteContents( true );
118 bool wxDataViewModel::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
122 wxDataViewModelNotifiers::iterator iter
;
123 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
125 wxDataViewModelNotifier
* notifier
= *iter
;
126 if (!notifier
->ItemAdded( parent
, item
))
133 bool wxDataViewModel::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
137 wxDataViewModelNotifiers::iterator iter
;
138 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
140 wxDataViewModelNotifier
* notifier
= *iter
;
141 if (!notifier
->ItemDeleted( parent
, item
))
148 bool wxDataViewModel::ItemChanged( const wxDataViewItem
&item
)
152 wxDataViewModelNotifiers::iterator iter
;
153 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
155 wxDataViewModelNotifier
* notifier
= *iter
;
156 if (!notifier
->ItemChanged( item
))
163 bool wxDataViewModel::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
167 wxDataViewModelNotifiers::iterator iter
;
168 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
170 wxDataViewModelNotifier
* notifier
= *iter
;
171 if (!notifier
->ItemsAdded( parent
, items
))
178 bool wxDataViewModel::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
182 wxDataViewModelNotifiers::iterator iter
;
183 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
185 wxDataViewModelNotifier
* notifier
= *iter
;
186 if (!notifier
->ItemsDeleted( parent
, items
))
193 bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray
&items
)
197 wxDataViewModelNotifiers::iterator iter
;
198 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
200 wxDataViewModelNotifier
* notifier
= *iter
;
201 if (!notifier
->ItemsChanged( items
))
208 bool wxDataViewModel::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
212 wxDataViewModelNotifiers::iterator iter
;
213 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
215 wxDataViewModelNotifier
* notifier
= *iter
;
216 if (!notifier
->ValueChanged( item
, col
))
223 bool wxDataViewModel::Cleared()
227 wxDataViewModelNotifiers::iterator iter
;
228 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
230 wxDataViewModelNotifier
* notifier
= *iter
;
231 if (!notifier
->Cleared())
238 bool wxDataViewModel::BeforeReset( size_t old_size
, size_t new_size
)
242 wxDataViewModelNotifiers::iterator iter
;
243 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
245 wxDataViewModelNotifier
* notifier
= *iter
;
246 if (!notifier
->BeforeReset(old_size
,new_size
))
253 bool wxDataViewModel::AfterReset()
257 wxDataViewModelNotifiers::iterator iter
;
258 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
260 wxDataViewModelNotifier
* notifier
= *iter
;
261 if (!notifier
->AfterReset())
268 void wxDataViewModel::Resort()
270 wxDataViewModelNotifiers::iterator iter
;
271 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
273 wxDataViewModelNotifier
* notifier
= *iter
;
278 void wxDataViewModel::AddNotifier( wxDataViewModelNotifier
*notifier
)
280 m_notifiers
.push_back( notifier
);
281 notifier
->SetOwner( this );
284 void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier
*notifier
)
286 m_notifiers
.DeleteObject( notifier
);
289 int wxDataViewModel::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
290 unsigned int column
, bool ascending
) const
292 // sort branches before leaves
293 bool item1_is_container
= IsContainer(item1
);
294 bool item2_is_container
= IsContainer(item2
);
296 if (item1_is_container
&& !item2_is_container
)
298 if (item2_is_container
&& !item1_is_container
)
301 wxVariant value1
,value2
;
302 GetValue( value1
, item1
, column
);
303 GetValue( value2
, item2
, column
);
307 wxVariant temp
= value1
;
312 if (value1
.GetType() == wxT("string"))
314 wxString str1
= value1
.GetString();
315 wxString str2
= value2
.GetString();
316 int res
= str1
.Cmp( str2
);
320 else if (value1
.GetType() == wxT("long"))
322 long l1
= value1
.GetLong();
323 long l2
= value2
.GetLong();
328 else if (value1
.GetType() == wxT("double"))
330 double d1
= value1
.GetDouble();
331 double d2
= value2
.GetDouble();
337 else if (value1
.GetType() == wxT("datetime"))
339 wxDateTime dt1
= value1
.GetDateTime();
340 wxDateTime dt2
= value2
.GetDateTime();
341 if (dt1
.IsEarlierThan(dt2
))
343 if (dt2
.IsEarlierThan(dt1
))
347 // items must be different
348 wxUIntPtr id1
= wxPtrToUInt(item1
.GetID()),
349 id2
= wxPtrToUInt(item2
.GetID());
351 return ascending
? id1
- id2
: id2
- id1
;
354 // ---------------------------------------------------------
355 // wxDataViewIndexListModel
356 // ---------------------------------------------------------
358 static int my_sort( int *v1
, int *v2
)
364 wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size
)
366 // IDs are ordered until an item gets deleted or inserted
369 // build initial index
371 for (i
= 1; i
< initial_size
+1; i
++)
372 m_hash
.Add( wxUIntToPtr(i
) );
373 m_nextFreeID
= initial_size
+ 1;
376 void wxDataViewIndexListModel::Reset( unsigned int new_size
)
380 // IDs are ordered until an item gets deleted or inserted
383 // build initial index
385 for (i
= 1; i
< new_size
+1; i
++)
386 m_hash
.Add( wxUIntToPtr(i
) );
388 m_nextFreeID
= new_size
+ 1;
390 /* wxDataViewModel:: */ Cleared();
393 void wxDataViewIndexListModel::RowPrepended()
397 unsigned int id
= m_nextFreeID
;
400 m_hash
.Insert( wxUIntToPtr(id
), 0 );
401 wxDataViewItem
item( wxUIntToPtr(id
) );
402 ItemAdded( wxDataViewItem(0), item
);
406 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
410 unsigned int id
= m_nextFreeID
;
413 m_hash
.Insert( wxUIntToPtr(id
), before
);
414 wxDataViewItem
item( wxUIntToPtr(id
) );
415 ItemAdded( wxDataViewItem(0), item
);
418 void wxDataViewIndexListModel::RowAppended()
420 unsigned int id
= m_nextFreeID
;
423 m_hash
.Add( wxUIntToPtr(id
) );
424 wxDataViewItem
item( wxUIntToPtr(id
) );
425 ItemAdded( wxDataViewItem(0), item
);
428 void wxDataViewIndexListModel::RowDeleted( unsigned int row
)
432 wxDataViewItem
item( m_hash
[row
] );
433 /* wxDataViewModel:: */ ItemDeleted( wxDataViewItem(0), item
);
434 m_hash
.RemoveAt( row
);
437 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt
&rows
)
439 wxArrayInt sorted
= rows
;
440 sorted
.Sort( my_sort
);
444 wxDataViewItemArray array
;
446 for (i
= 0; i
< rows
.GetCount(); i
++)
448 wxDataViewItem
item( m_hash
[rows
[i
]] );
451 /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array
);
453 for (i
= 0; i
< sorted
.GetCount(); i
++)
454 m_hash
.RemoveAt( sorted
[i
] );
457 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
459 /* wxDataViewModel:: */ ItemChanged( GetItem(row
) );
462 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
464 /* wxDataViewModel:: */ ValueChanged( GetItem(row
), col
);
467 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
470 return wxPtrToUInt(item
.GetID())-1;
472 // assert for not found
473 return (unsigned int) m_hash
.Index( item
.GetID() );
476 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
478 wxASSERT( row
< m_hash
.GetCount() );
479 return wxDataViewItem( m_hash
[row
] );
482 bool wxDataViewIndexListModel::HasDefaultCompare() const
487 int wxDataViewIndexListModel::Compare(const wxDataViewItem
& item1
,
488 const wxDataViewItem
& item2
,
489 unsigned int WXUNUSED(column
),
490 bool ascending
) const
494 unsigned int pos1
= wxPtrToUInt(item1
.GetID()); // -1 not needed here
495 unsigned int pos2
= wxPtrToUInt(item2
.GetID()); // -1 not needed here
504 return GetRow(item1
) - GetRow(item2
);
506 return GetRow(item2
) - GetRow(item1
);
509 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
516 return m_hash
.GetCount();
519 // ---------------------------------------------------------
520 // wxDataViewVirtualListModel
521 // ---------------------------------------------------------
525 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size
)
527 m_size
= initial_size
;
530 void wxDataViewVirtualListModel::Reset( unsigned int new_size
)
532 /* wxDataViewModel:: */ BeforeReset( m_size
, new_size
);
536 /* wxDataViewModel:: */ AfterReset();
539 void wxDataViewVirtualListModel::RowPrepended()
542 wxDataViewItem
item( wxUIntToPtr(1) );
543 ItemAdded( wxDataViewItem(0), item
);
546 void wxDataViewVirtualListModel::RowInserted( unsigned int before
)
549 wxDataViewItem
item( wxUIntToPtr(before
+1) );
550 ItemAdded( wxDataViewItem(0), item
);
553 void wxDataViewVirtualListModel::RowAppended()
556 wxDataViewItem
item( wxUIntToPtr(m_size
) );
557 ItemAdded( wxDataViewItem(0), item
);
560 void wxDataViewVirtualListModel::RowDeleted( unsigned int row
)
563 wxDataViewItem
item( wxUIntToPtr(row
+1) );
564 /* wxDataViewModel:: */ ItemDeleted( wxDataViewItem(0), item
);
567 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt
&rows
)
569 m_size
-= rows
.GetCount();
571 wxArrayInt sorted
= rows
;
572 sorted
.Sort( my_sort
);
574 wxDataViewItemArray array
;
576 for (i
= 0; i
< sorted
.GetCount(); i
++)
578 wxDataViewItem
item( wxUIntToPtr(sorted
[i
]+1) );
581 /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array
);
584 void wxDataViewVirtualListModel::RowChanged( unsigned int row
)
586 /* wxDataViewModel:: */ ItemChanged( GetItem(row
) );
589 void wxDataViewVirtualListModel::RowValueChanged( unsigned int row
, unsigned int col
)
591 /* wxDataViewModel:: */ ValueChanged( GetItem(row
), col
);
594 unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem
&item
) const
596 return wxPtrToUInt( item
.GetID() ) -1;
599 wxDataViewItem
wxDataViewVirtualListModel::GetItem( unsigned int row
) const
601 return wxDataViewItem( wxUIntToPtr(row
+1) );
604 bool wxDataViewVirtualListModel::HasDefaultCompare() const
609 int wxDataViewVirtualListModel::Compare(const wxDataViewItem
& item1
,
610 const wxDataViewItem
& item2
,
611 unsigned int WXUNUSED(column
),
612 bool ascending
) const
614 unsigned int pos1
= wxPtrToUInt(item1
.GetID()); // -1 not needed here
615 unsigned int pos2
= wxPtrToUInt(item2
.GetID()); // -1 not needed here
623 unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem
&WXUNUSED(item
), wxDataViewItemArray
&WXUNUSED(children
) ) const
625 return 0; // should we report an error ?
630 //-----------------------------------------------------------------------------
631 // wxDataViewIconText
632 //-----------------------------------------------------------------------------
634 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
636 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
638 // ---------------------------------------------------------
639 // wxDataViewRendererBase
640 // ---------------------------------------------------------
642 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
644 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
645 wxDataViewCellMode
WXUNUSED(mode
),
646 int WXUNUSED(align
) )
648 m_variantType
= varianttype
;
652 wxDataViewRendererBase::~wxDataViewRendererBase()
656 const wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
658 return const_cast<wxDataViewRendererBase
*>(this)->GetOwner()->GetOwner();
661 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
663 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
665 // Before doing anything we send an event asking if editing of this item is really wanted.
666 wxDataViewEvent
start_event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv_ctrl
->GetId() );
667 start_event
.SetDataViewColumn( GetOwner() );
668 start_event
.SetModel( dv_ctrl
->GetModel() );
669 start_event
.SetItem( item
);
670 start_event
.SetEventObject( dv_ctrl
);
671 dv_ctrl
->GetEventHandler()->ProcessEvent( start_event
);
672 if( !start_event
.IsAllowed() )
675 m_item
= item
; // remember for later
677 unsigned int col
= GetOwner()->GetModelColumn();
679 dv_ctrl
->GetModel()->GetValue( value
, item
, col
);
681 m_editorCtrl
= CreateEditorCtrl( dv_ctrl
->GetMainWindow(), labelRect
, value
);
683 // there might be no editor control for the given item
687 wxDataViewEditorCtrlEvtHandler
*handler
=
688 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
690 m_editorCtrl
->PushEventHandler( handler
);
692 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
693 handler
->SetFocusOnIdle();
695 m_editorCtrl
->SetFocus();
698 // Now we should send Editing Started event
699 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv_ctrl
->GetId() );
700 event
.SetDataViewColumn( GetOwner() );
701 event
.SetModel( dv_ctrl
->GetModel() );
702 event
.SetItem( item
);
703 event
.SetEventObject( dv_ctrl
);
704 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
709 void wxDataViewRendererBase::DestroyEditControl()
711 // Hide the control immediately but don't delete it yet as there could be
712 // some pending messages for it.
713 m_editorCtrl
->Hide();
715 wxEvtHandler
* const handler
= m_editorCtrl
->PopEventHandler();
717 wxPendingDelete
.Append(handler
);
718 wxPendingDelete
.Append(m_editorCtrl
);
721 void wxDataViewRendererBase::CancelEditing()
726 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
728 DestroyEditControl();
731 bool wxDataViewRendererBase::FinishEditing()
737 GetValueFromEditorCtrl( m_editorCtrl
, value
);
739 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
741 dv_ctrl
->GetMainWindow()->SetFocus();
743 DestroyEditControl();
745 if (!Validate(value
))
748 unsigned int col
= GetOwner()->GetModelColumn();
749 dv_ctrl
->GetModel()->ChangeValue(value
, m_item
, col
);
751 // Now we should send Editing Done event
752 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv_ctrl
->GetId() );
753 event
.SetDataViewColumn( GetOwner() );
754 event
.SetModel( dv_ctrl
->GetModel() );
755 event
.SetItem( m_item
);
756 event
.SetEventObject( dv_ctrl
);
757 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
762 // ----------------------------------------------------------------------------
763 // wxDataViewCustomRendererBase
764 // ----------------------------------------------------------------------------
767 wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell
, wxDC
*dc
, int state
)
769 wxCHECK_RET( dc
, "no DC to draw on in custom renderer?" );
771 // adjust the rectangle ourselves to account for the alignment
772 wxRect rectItem
= rectCell
;
773 const int align
= GetAlignment();
774 if ( align
!= wxDVR_DEFAULT_ALIGNMENT
)
776 const wxSize size
= GetSize();
778 // take alignment into account only if there is enough space, otherwise
779 // show as much contents as possible
781 // notice that many existing renderers (e.g. wxDataViewSpinRenderer)
782 // return hard-coded size which can be more than they need and if we
783 // trusted their GetSize() we'd draw the text out of cell bounds
786 if ( size
.x
>= 0 && size
.x
< rectCell
.width
)
788 if ( align
& wxALIGN_CENTER_HORIZONTAL
)
789 rectItem
.x
+= (rectCell
.width
- size
.x
)/2;
790 else if ( align
& wxALIGN_RIGHT
)
791 rectItem
.x
+= rectCell
.width
- size
.x
;
792 // else: wxALIGN_LEFT is the default
794 rectItem
.width
= size
.x
;
797 if ( size
.y
>= 0 && size
.y
< rectCell
.height
)
799 if ( align
& wxALIGN_CENTER_VERTICAL
)
800 rectItem
.y
+= (rectCell
.height
- size
.y
)/2;
801 else if ( align
& wxALIGN_BOTTOM
)
802 rectItem
.y
+= rectCell
.height
- size
.y
;
803 // else: wxALIGN_TOP is the default
805 rectItem
.height
= size
.y
;
810 // set up the DC attributes
812 // override custom foreground with the standard one for the selected items
813 // because we currently don't allow changing the selection background and
814 // custom colours may be unreadable on it
816 if ( state
& wxDATAVIEW_CELL_SELECTED
)
817 col
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
818 else if ( m_attr
.HasColour() )
819 col
= m_attr
.GetColour();
820 else // use default foreground
821 col
= GetOwner()->GetOwner()->GetForegroundColour();
823 wxDCTextColourChanger
changeFg(*dc
, col
);
825 wxDCFontChanger
changeFont(*dc
);
826 if ( m_attr
.HasFont() )
828 wxFont
font(dc
->GetFont());
829 if ( m_attr
.GetBold() )
831 if ( m_attr
.GetItalic() )
834 changeFont
.Set(font
);
837 Render(rectItem
, dc
, state
);
841 wxDataViewCustomRendererBase::RenderText(const wxString
& text
,
847 wxRect rectText
= rect
;
848 rectText
.x
+= xoffset
;
849 rectText
.width
-= xoffset
;
851 // check if we want to ellipsize the text if it doesn't fit
852 wxString ellipsizedText
;
853 if ( GetEllipsizeMode() != wxELLIPSIZE_NONE
)
855 ellipsizedText
= wxControl::Ellipsize
861 wxELLIPSIZE_FLAGS_NONE
865 // get the alignment to use
866 int align
= GetAlignment();
867 if ( align
== wxDVR_DEFAULT_ALIGNMENT
)
869 // if we don't have an explicit alignment ourselves, use that of the
870 // column in horizontal direction and default vertical alignment
871 align
= GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
874 dc
->DrawLabel(ellipsizedText
.empty() ? text
: ellipsizedText
,
878 //-----------------------------------------------------------------------------
879 // wxDataViewEditorCtrlEvtHandler
880 //-----------------------------------------------------------------------------
882 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
883 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
884 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
885 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
886 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
889 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
893 m_focusOnIdle
= false;
894 if (wxWindow::FindFocus() != m_editorCtrl
)
895 m_editorCtrl
->SetFocus();
901 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
904 m_owner
->FinishEditing();
907 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
909 switch ( event
.m_keyCode
)
913 m_owner
->FinishEditing();
919 m_owner
->CancelEditing();
927 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
932 m_owner
->FinishEditing();
938 // ---------------------------------------------------------
939 // wxDataViewColumnBase
940 // ---------------------------------------------------------
942 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
943 unsigned int model_column
)
945 m_renderer
= renderer
;
946 m_model_column
= model_column
;
948 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
951 wxDataViewColumnBase::~wxDataViewColumnBase()
956 // ---------------------------------------------------------
957 // wxDataViewCtrlBase
958 // ---------------------------------------------------------
960 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
962 wxDataViewCtrlBase::wxDataViewCtrlBase()
965 m_expander_column
= 0;
969 wxDataViewCtrlBase::~wxDataViewCtrlBase()
978 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
982 m_model
->DecRef(); // discard old model, if any
985 // add our own reference to the new model:
995 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
1000 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
1005 void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem
& item
)
1007 if (!m_model
) return;
1009 if (!item
.IsOk()) return;
1011 wxVector
<wxDataViewItem
> parentChain
;
1013 // at first we get all the parents of the selected item
1014 wxDataViewItem parent
= m_model
->GetParent(item
);
1015 while (parent
.IsOk())
1017 parentChain
.push_back(parent
);
1018 parent
= m_model
->GetParent(parent
);
1021 // then we expand the parents, starting at the root
1022 while (!parentChain
.empty())
1024 Expand(parentChain
.back());
1025 parentChain
.pop_back();
1029 wxDataViewItem
wxDataViewCtrlBase::GetCurrentItem() const
1031 return HasFlag(wxDV_MULTIPLE
) ? DoGetCurrentItem()
1035 void wxDataViewCtrlBase::SetCurrentItem(const wxDataViewItem
& item
)
1037 wxCHECK_RET( item
.IsOk(), "Can't make current an invalid item." );
1039 if ( HasFlag(wxDV_MULTIPLE
) )
1040 DoSetCurrentItem(item
);
1046 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
1047 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1049 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1050 new wxDataViewTextRenderer( wxT("string"), mode
),
1051 model_column
, width
, align
, flags
);
1052 AppendColumn( ret
);
1057 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
1058 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1060 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1061 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1062 model_column
, width
, align
, flags
);
1063 AppendColumn( ret
);
1068 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
1069 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1071 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1072 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1073 model_column
, width
, align
, flags
);
1074 AppendColumn( ret
);
1079 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
1080 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1082 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1083 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1084 model_column
, width
, align
, flags
);
1085 AppendColumn( ret
);
1090 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
1091 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1093 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1094 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1095 model_column
, width
, align
, flags
);
1096 AppendColumn( ret
);
1101 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
1102 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1104 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1105 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1106 model_column
, width
, align
, flags
);
1107 AppendColumn( ret
);
1112 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1113 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1115 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1116 new wxDataViewTextRenderer( wxT("string"), mode
),
1117 model_column
, width
, align
, flags
);
1118 AppendColumn( ret
);
1123 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1124 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1126 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1127 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1128 model_column
, width
, align
, flags
);
1129 AppendColumn( ret
);
1134 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1135 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1137 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1138 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1139 model_column
, width
, align
, flags
);
1140 AppendColumn( ret
);
1145 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1146 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1148 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1149 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1150 model_column
, width
, align
, flags
);
1151 AppendColumn( ret
);
1156 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1157 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1159 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1160 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1161 model_column
, width
, align
, flags
);
1162 AppendColumn( ret
);
1167 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1168 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1170 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1171 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1172 model_column
, width
, align
, flags
);
1173 AppendColumn( ret
);
1178 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1179 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1181 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1182 new wxDataViewTextRenderer( wxT("string"), mode
),
1183 model_column
, width
, align
, flags
);
1184 PrependColumn( ret
);
1189 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1190 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1192 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1193 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1194 model_column
, width
, align
, flags
);
1195 PrependColumn( ret
);
1200 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1201 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1204 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1205 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1206 model_column
, width
, align
, flags
);
1207 PrependColumn( ret
);
1212 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1213 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1215 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1216 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1217 model_column
, width
, align
, flags
);
1218 PrependColumn( ret
);
1223 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1224 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1226 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1227 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1228 model_column
, width
, align
, flags
);
1229 PrependColumn( ret
);
1234 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1235 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1237 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1238 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1239 model_column
, width
, align
, flags
);
1240 PrependColumn( ret
);
1245 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1246 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1248 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1249 new wxDataViewTextRenderer( wxT("string"), mode
),
1250 model_column
, width
, align
, flags
);
1251 PrependColumn( ret
);
1256 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1257 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1259 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1260 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1261 model_column
, width
, align
, flags
);
1262 PrependColumn( ret
);
1267 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1268 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1270 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1271 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1272 model_column
, width
, align
, flags
);
1273 PrependColumn( ret
);
1278 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1279 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1281 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1282 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1283 model_column
, width
, align
, flags
);
1284 PrependColumn( ret
);
1289 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1290 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1292 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1293 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1294 model_column
, width
, align
, flags
);
1295 PrependColumn( ret
);
1300 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1301 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1303 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1304 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1305 model_column
, width
, align
, flags
);
1306 PrependColumn( ret
);
1311 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1313 col
->SetOwner( (wxDataViewCtrl
*) this );
1318 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1320 col
->SetOwner( (wxDataViewCtrl
*) this );
1325 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1327 col
->SetOwner( (wxDataViewCtrl
*) this );
1331 // ---------------------------------------------------------
1333 // ---------------------------------------------------------
1335 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1337 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
);
1339 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
);
1340 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
);
1341 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
);
1342 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
);
1343 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
);
1344 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
);
1345 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, wxDataViewEvent
);
1346 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
);
1347 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
);
1349 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
);
1351 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
);
1352 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
);
1353 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
);
1354 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
);
1356 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, wxDataViewEvent
);
1358 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
);
1359 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, wxDataViewEvent
);
1360 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, wxDataViewEvent
);
1364 // -------------------------------------
1365 // wxDataViewSpinRenderer
1366 // -------------------------------------
1368 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1369 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1375 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1378 wxSize size
= labelRect
.GetSize();
1380 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1383 str
.Printf( wxT("%d"), (int) l
);
1384 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1385 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1387 size
= sc
->GetSize();
1388 wxPoint pt
= sc
->GetPosition();
1389 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1395 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1397 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1398 long l
= sc
->GetValue();
1403 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1406 str
.Printf(wxT("%d"), (int) m_data
);
1407 RenderText( str
, 0, rect
, dc
, state
);
1411 wxSize
wxDataViewSpinRenderer::GetSize() const
1413 return wxSize(80,16);
1416 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1418 m_data
= value
.GetLong();
1422 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1428 // -------------------------------------
1429 // wxDataViewChoiceRenderer
1430 // -------------------------------------
1432 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
1434 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1435 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1437 m_choices
= choices
;
1440 wxControl
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1442 wxChoice
* c
= new wxChoice(parent
, wxID_ANY
, labelRect
.GetTopLeft(), wxDefaultSize
, m_choices
);
1443 c
->Move(labelRect
.GetRight() - c
->GetRect().width
, wxDefaultCoord
);
1444 c
->SetStringSelection( value
.GetString() );
1448 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1450 wxChoice
*c
= (wxChoice
*) editor
;
1451 wxString s
= c
->GetStringSelection();
1456 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1458 RenderText( m_data
, 0, rect
, dc
, state
);
1462 wxSize
wxDataViewChoiceRenderer::GetSize() const
1464 return wxSize(80,16);
1467 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1469 m_data
= value
.GetString();
1473 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1479 // ----------------------------------------------------------------------------
1480 // wxDataViewChoiceByIndexRenderer
1481 // ----------------------------------------------------------------------------
1483 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
1484 wxDataViewCellMode mode
, int alignment
) :
1485 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
1489 wxControl
* wxDataViewChoiceByIndexRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1491 wxVariant string_value
= GetChoice( value
.GetLong() );
1493 return wxDataViewChoiceRenderer::CreateEditorCtrl( parent
, labelRect
, string_value
);
1496 bool wxDataViewChoiceByIndexRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1498 wxVariant string_value
;
1499 if (!wxDataViewChoiceRenderer::GetValueFromEditorCtrl( editor
, string_value
))
1502 value
= (long) GetChoices().Index( string_value
.GetString() );
1506 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
1508 wxVariant string_value
= GetChoice( value
.GetLong() );
1509 return wxDataViewChoiceRenderer::SetValue( string_value
);
1512 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
1514 wxVariant string_value
;
1515 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
1518 value
= (long) GetChoices().Index( string_value
.GetString() );
1524 //-----------------------------------------------------------------------------
1525 // wxDataViewListStore
1526 //-----------------------------------------------------------------------------
1528 wxDataViewListStore::wxDataViewListStore()
1532 wxDataViewListStore::~wxDataViewListStore()
1534 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1535 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1537 wxDataViewListStoreLine
* line
= *it
;
1542 void wxDataViewListStore::PrependColumn( const wxString
&varianttype
)
1544 m_cols
.Insert( varianttype
, 0 );
1547 void wxDataViewListStore::InsertColumn( unsigned int pos
, const wxString
&varianttype
)
1549 m_cols
.Insert( varianttype
, pos
);
1552 void wxDataViewListStore::AppendColumn( const wxString
&varianttype
)
1554 m_cols
.Add( varianttype
);
1557 unsigned int wxDataViewListStore::GetColumnCount() const
1559 return m_cols
.GetCount();
1562 wxString
wxDataViewListStore::GetColumnType( unsigned int pos
) const
1567 void wxDataViewListStore::AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1569 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1570 line
->m_values
= values
;
1571 m_data
.push_back( line
);
1576 void wxDataViewListStore::PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1578 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1579 line
->m_values
= values
;
1580 m_data
.insert( m_data
.begin(), line
);
1585 void wxDataViewListStore::InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
,
1586 wxClientData
*data
)
1588 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1589 line
->m_values
= values
;
1590 m_data
.insert( m_data
.begin()+row
, line
);
1595 void wxDataViewListStore::DeleteItem( unsigned int row
)
1597 wxVector
<wxDataViewListStoreLine
*>::iterator it
= m_data
.begin() + row
;
1604 void wxDataViewListStore::DeleteAllItems()
1606 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1607 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1609 wxDataViewListStoreLine
* line
= *it
;
1618 void wxDataViewListStore::GetValueByRow( wxVariant
&value
, unsigned int row
, unsigned int col
) const
1620 wxDataViewListStoreLine
*line
= m_data
[row
];
1621 value
= line
->m_values
[col
];
1624 bool wxDataViewListStore::SetValueByRow( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1626 wxDataViewListStoreLine
*line
= m_data
[row
];
1627 line
->m_values
[col
] = value
;
1632 //-----------------------------------------------------------------------------
1633 // wxDataViewListCtrl
1634 //-----------------------------------------------------------------------------
1636 IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl
,wxDataViewCtrl
)
1638 BEGIN_EVENT_TABLE(wxDataViewListCtrl
,wxDataViewCtrl
)
1639 EVT_SIZE( wxDataViewListCtrl::OnSize
)
1642 wxDataViewListCtrl::wxDataViewListCtrl()
1646 wxDataViewListCtrl::wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
1647 const wxPoint
& pos
, const wxSize
& size
, long style
,
1648 const wxValidator
& validator
)
1650 Create( parent
, id
, pos
, size
, style
, validator
);
1653 wxDataViewListCtrl::~wxDataViewListCtrl()
1658 bool wxDataViewListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1659 const wxPoint
& pos
, const wxSize
& size
, long style
,
1660 const wxValidator
& validator
)
1662 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
1665 wxDataViewListStore
*store
= new wxDataViewListStore
;
1666 AssociateModel( store
);
1672 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1674 GetStore()->AppendColumn( varianttype
);
1675 return wxDataViewCtrl::AppendColumn( column
);
1678 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1680 GetStore()->PrependColumn( varianttype
);
1681 return wxDataViewCtrl::PrependColumn( column
);
1684 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
)
1686 GetStore()->InsertColumn( pos
, varianttype
);
1687 return wxDataViewCtrl::InsertColumn( pos
, column
);
1690 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*col
)
1692 return PrependColumn( col
, "string" );
1695 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
1697 return InsertColumn( pos
, col
, "string" );
1700 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*col
)
1702 return AppendColumn( col
, "string" );
1705 wxDataViewColumn
*wxDataViewListCtrl::AppendTextColumn( const wxString
&label
,
1706 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1708 GetStore()->AppendColumn( wxT("string") );
1710 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1711 new wxDataViewTextRenderer( wxT("string"), mode
),
1712 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1714 wxDataViewCtrl::AppendColumn( ret
);
1719 wxDataViewColumn
*wxDataViewListCtrl::AppendToggleColumn( const wxString
&label
,
1720 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1722 GetStore()->AppendColumn( wxT("bool") );
1724 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1725 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1726 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1728 wxDataViewCtrl::AppendColumn( ret
);
1733 wxDataViewColumn
*wxDataViewListCtrl::AppendProgressColumn( const wxString
&label
,
1734 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1736 GetStore()->AppendColumn( wxT("long") );
1738 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1739 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1740 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1742 wxDataViewCtrl::AppendColumn( ret
);
1747 wxDataViewColumn
*wxDataViewListCtrl::AppendIconTextColumn( const wxString
&label
,
1748 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1750 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
1752 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1753 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1754 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1756 wxDataViewCtrl::AppendColumn( ret
);
1761 void wxDataViewListCtrl::OnSize( wxSizeEvent
&event
)
1766 //-----------------------------------------------------------------------------
1767 // wxDataViewTreeStore
1768 //-----------------------------------------------------------------------------
1770 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1771 wxDataViewTreeStoreNode
*parent
,
1772 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1780 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1786 #include "wx/listimpl.cpp"
1787 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1789 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1790 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1791 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1792 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1794 m_iconExpanded
= expanded
;
1795 m_isExpanded
= false;
1796 m_children
.DeleteContents(true);
1799 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1803 //-----------------------------------------------------------------------------
1805 wxDataViewTreeStore::wxDataViewTreeStore()
1807 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1810 wxDataViewTreeStore::~wxDataViewTreeStore()
1815 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1816 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1818 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1819 if (!parent_node
) return wxDataViewItem(0);
1821 wxDataViewTreeStoreNode
*node
=
1822 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1823 parent_node
->GetChildren().Append( node
);
1825 return node
->GetItem();
1828 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1829 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1831 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1832 if (!parent_node
) return wxDataViewItem(0);
1834 wxDataViewTreeStoreNode
*node
=
1835 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1836 parent_node
->GetChildren().Insert( node
);
1838 return node
->GetItem();
1842 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& parent
,
1843 const wxDataViewItem
& previous
,
1844 const wxString
& text
,
1848 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1849 if (!parent_node
) return wxDataViewItem(0);
1851 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1852 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1853 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1855 wxDataViewTreeStoreNode
*node
=
1856 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1857 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1859 return node
->GetItem();
1862 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1863 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1864 wxClientData
*data
)
1866 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1867 if (!parent_node
) return wxDataViewItem(0);
1869 wxDataViewTreeStoreContainerNode
*node
=
1870 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1871 parent_node
->GetChildren().Insert( node
);
1873 return node
->GetItem();
1877 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1878 const wxString
&text
,
1880 const wxIcon
& expanded
,
1881 wxClientData
* data
)
1883 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1884 if (!parent_node
) return wxDataViewItem(0);
1886 wxDataViewTreeStoreContainerNode
*node
=
1887 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1888 parent_node
->GetChildren().Append( node
);
1890 return node
->GetItem();
1894 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& parent
,
1895 const wxDataViewItem
& previous
,
1896 const wxString
& text
,
1898 const wxIcon
& expanded
,
1899 wxClientData
* data
)
1901 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1902 if (!parent_node
) return wxDataViewItem(0);
1904 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1905 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1906 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1908 wxDataViewTreeStoreContainerNode
*node
=
1909 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1910 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1912 return node
->GetItem();
1915 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
& item
) const
1917 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1918 if (!node
) return false;
1920 return node
->IsContainer();
1923 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1925 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1926 if (!parent_node
) return wxDataViewItem(0);
1928 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1930 return node
->GetData();
1932 return wxDataViewItem(0);
1935 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1937 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1938 if (!node
) return -1;
1940 if (!node
->IsContainer())
1943 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1944 return (int) container_node
->GetChildren().GetCount();
1947 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1949 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1952 node
->SetText( text
);
1955 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1957 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1958 if (!node
) return wxEmptyString
;
1960 return node
->GetText();
1963 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1965 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1968 node
->SetIcon( icon
);
1971 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1973 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1974 if (!node
) return wxNullIcon
;
1976 return node
->GetIcon();
1979 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1981 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1984 node
->SetExpandedIcon( icon
);
1987 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1989 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1990 if (!node
) return wxNullIcon
;
1992 return node
->GetExpandedIcon();
1995 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1997 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2000 node
->SetData( data
);
2003 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
2005 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2006 if (!node
) return NULL
;
2008 return node
->GetData();
2011 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
2013 if (!item
.IsOk()) return;
2015 wxDataViewItem parent_item
= GetParent( item
);
2017 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
2018 if (!parent_node
) return;
2020 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2023 parent_node
->GetChildren().DeleteObject( node
);
2026 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
2028 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2031 node
->GetChildren().clear();
2034 void wxDataViewTreeStore::DeleteAllItems()
2036 DeleteChildren(m_root
);
2040 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
2041 const wxDataViewItem
&item
,
2042 unsigned int WXUNUSED(col
)) const
2044 // if (col != 0) return;
2046 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2049 wxIcon
icon( node
->GetIcon());
2050 if (node
->IsContainer())
2052 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
2053 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
2054 icon
= container
->GetExpandedIcon();
2057 wxDataViewIconText
data( node
->GetText(), icon
);
2063 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
2064 const wxDataViewItem
& item
,
2065 unsigned int WXUNUSED(col
))
2067 // if (col != 0) return false;
2069 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2070 if (!node
) return false;
2072 wxDataViewIconText data
;
2076 node
->SetText( data
.GetText() );
2077 node
->SetIcon( data
.GetIcon() );
2082 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
2084 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2085 if (!node
) return wxDataViewItem(0);
2087 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
2088 if (!parent
) return wxDataViewItem(0);
2090 if (parent
== m_root
)
2091 return wxDataViewItem(0);
2093 return parent
->GetItem();
2096 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
2098 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2099 if (!node
) return 0;
2101 wxDataViewTreeStoreNodeList::iterator iter
;
2102 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2104 wxDataViewTreeStoreNode
* child
= *iter
;
2105 children
.Add( child
->GetItem() );
2108 return node
->GetChildren().GetCount();
2111 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
2112 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) ) const
2114 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
2115 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
2117 if (!node1
|| !node2
)
2120 wxDataViewTreeStoreContainerNode
* parent1
=
2121 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
2122 wxDataViewTreeStoreContainerNode
* parent2
=
2123 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
2125 if (parent1
!= parent2
)
2127 wxLogError( wxT("Comparing items with different parent.") );
2131 if (node1
->IsContainer() && !node2
->IsContainer())
2134 if (node2
->IsContainer() && !node1
->IsContainer())
2137 return parent1
->GetChildren().IndexOf( node1
) - parent2
->GetChildren().IndexOf( node2
);
2140 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
2145 return (wxDataViewTreeStoreNode
*) item
.GetID();
2148 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
2151 return (wxDataViewTreeStoreContainerNode
*) m_root
;
2153 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
2155 if (!node
->IsContainer())
2158 return (wxDataViewTreeStoreContainerNode
*) node
;
2161 //-----------------------------------------------------------------------------
2162 // wxDataViewTreeCtrl
2163 //-----------------------------------------------------------------------------
2165 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2167 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2168 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
2169 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
2170 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
2173 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
2178 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2179 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2181 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
2184 // create the standard model and a column in the tree
2185 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
2186 AssociateModel( store
);
2189 AppendIconTextColumn
2191 wxString(), // no label (header is not shown anyhow)
2192 0, // the only model column
2193 wxDATAVIEW_CELL_EDITABLE
,
2194 -1, // default width
2195 wxALIGN_NOT
, // and alignment
2202 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
2206 m_imageList
= imagelist
;
2209 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
2210 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2212 wxIcon icon
= wxNullIcon
;
2213 if (m_imageList
&& (iconIndex
!= -1))
2214 icon
= m_imageList
->GetIcon( iconIndex
);
2216 wxDataViewItem res
= GetStore()->AppendItem( parent
, text
, icon
, data
);
2218 GetStore()->ItemAdded( parent
, res
);
2223 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
2224 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2226 wxIcon icon
= wxNullIcon
;
2227 if (m_imageList
&& (iconIndex
!= -1))
2228 icon
= m_imageList
->GetIcon( iconIndex
);
2230 wxDataViewItem res
= GetStore()->PrependItem( parent
, text
, icon
, data
);
2232 GetStore()->ItemAdded( parent
, res
);
2237 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2238 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2240 wxIcon icon
= wxNullIcon
;
2241 if (m_imageList
&& (iconIndex
!= -1))
2242 icon
= m_imageList
->GetIcon( iconIndex
);
2244 wxDataViewItem res
= GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
2246 GetStore()->ItemAdded( parent
, res
);
2251 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
2252 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2254 wxIcon icon
= wxNullIcon
;
2255 if (m_imageList
&& (iconIndex
!= -1))
2256 icon
= m_imageList
->GetIcon( iconIndex
);
2258 wxIcon expanded
= wxNullIcon
;
2259 if (m_imageList
&& (expandedIndex
!= -1))
2260 expanded
= m_imageList
->GetIcon( expandedIndex
);
2262 wxDataViewItem res
= GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
2264 GetStore()->ItemAdded( parent
, res
);
2269 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
2270 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2272 wxIcon icon
= wxNullIcon
;
2273 if (m_imageList
&& (iconIndex
!= -1))
2274 icon
= m_imageList
->GetIcon( iconIndex
);
2276 wxIcon expanded
= wxNullIcon
;
2277 if (m_imageList
&& (expandedIndex
!= -1))
2278 expanded
= m_imageList
->GetIcon( expandedIndex
);
2280 wxDataViewItem res
= GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
2282 GetStore()->ItemAdded( parent
, res
);
2287 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2288 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2290 wxIcon icon
= wxNullIcon
;
2291 if (m_imageList
&& (iconIndex
!= -1))
2292 icon
= m_imageList
->GetIcon( iconIndex
);
2294 wxIcon expanded
= wxNullIcon
;
2295 if (m_imageList
&& (expandedIndex
!= -1))
2296 expanded
= m_imageList
->GetIcon( expandedIndex
);
2298 wxDataViewItem res
= GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
2300 GetStore()->ItemAdded( parent
, res
);
2305 void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2307 GetStore()->SetItemText(item
,text
);
2310 GetStore()->ValueChanged( item
, 0 );
2313 void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2315 GetStore()->SetItemIcon(item
,icon
);
2318 GetStore()->ValueChanged( item
, 0 );
2321 void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2323 GetStore()->SetItemExpandedIcon(item
,icon
);
2326 GetStore()->ValueChanged( item
, 0 );
2329 void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem
& item
)
2331 wxDataViewItem parent_item
= GetStore()->GetParent( item
);
2333 GetStore()->DeleteItem(item
);
2336 GetStore()->ItemDeleted( parent_item
, item
);
2339 void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem
& item
)
2341 wxDataViewTreeStoreContainerNode
*node
= GetStore()->FindContainerNode( item
);
2344 wxDataViewItemArray array
;
2345 wxDataViewTreeStoreNodeList::iterator iter
;
2346 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2348 wxDataViewTreeStoreNode
* child
= *iter
;
2349 array
.Add( child
->GetItem() );
2352 GetStore()->DeleteChildren( item
);
2355 GetStore()->ItemsDeleted( item
, array
);
2358 void wxDataViewTreeCtrl::DeleteAllItems()
2360 GetStore()->DeleteAllItems();
2362 GetStore()->Cleared();
2365 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
2367 if (m_imageList
) return;
2369 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2370 if (!container
) return;
2372 container
->SetExpanded( true );
2374 GetStore()->ItemChanged( event
.GetItem() );
2377 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
2379 if (m_imageList
) return;
2381 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2382 if (!container
) return;
2384 container
->SetExpanded( false );
2386 GetStore()->ItemChanged( event
.GetItem() );
2389 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
2391 #if defined(wxUSE_GENERICDATAVIEWCTRL)
2392 // automatically resize our only column to take the entire control width
2393 if ( GetColumnCount() )
2395 wxSize size
= GetClientSize();
2396 GetColumn(0)->SetWidth(size
.x
);
2402 #endif // wxUSE_DATAVIEWCTRL