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()
242 wxDataViewModelNotifiers::iterator iter
;
243 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
245 wxDataViewModelNotifier
* notifier
= *iter
;
246 if (!notifier
->BeforeReset())
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
)
378 /* wxDataViewModel:: */ BeforeReset();
382 // IDs are ordered until an item gets deleted or inserted
385 // build initial index
387 for (i
= 1; i
< new_size
+1; i
++)
388 m_hash
.Add( wxUIntToPtr(i
) );
390 m_nextFreeID
= new_size
+ 1;
392 /* wxDataViewModel:: */ AfterReset();
395 void wxDataViewIndexListModel::RowPrepended()
399 unsigned int id
= m_nextFreeID
;
402 m_hash
.Insert( wxUIntToPtr(id
), 0 );
403 wxDataViewItem
item( wxUIntToPtr(id
) );
404 ItemAdded( wxDataViewItem(0), item
);
408 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
412 unsigned int id
= m_nextFreeID
;
415 m_hash
.Insert( wxUIntToPtr(id
), before
);
416 wxDataViewItem
item( wxUIntToPtr(id
) );
417 ItemAdded( wxDataViewItem(0), item
);
420 void wxDataViewIndexListModel::RowAppended()
422 unsigned int id
= m_nextFreeID
;
425 m_hash
.Add( wxUIntToPtr(id
) );
426 wxDataViewItem
item( wxUIntToPtr(id
) );
427 ItemAdded( wxDataViewItem(0), item
);
430 void wxDataViewIndexListModel::RowDeleted( unsigned int row
)
434 wxDataViewItem
item( m_hash
[row
] );
435 /* wxDataViewModel:: */ ItemDeleted( wxDataViewItem(0), item
);
436 m_hash
.RemoveAt( row
);
439 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt
&rows
)
441 wxArrayInt sorted
= rows
;
442 sorted
.Sort( my_sort
);
446 wxDataViewItemArray array
;
448 for (i
= 0; i
< rows
.GetCount(); i
++)
450 wxDataViewItem
item( m_hash
[rows
[i
]] );
453 /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array
);
455 for (i
= 0; i
< sorted
.GetCount(); i
++)
456 m_hash
.RemoveAt( sorted
[i
] );
459 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
461 /* wxDataViewModel:: */ ItemChanged( GetItem(row
) );
464 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
466 /* wxDataViewModel:: */ ValueChanged( GetItem(row
), col
);
469 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
472 return wxPtrToUInt(item
.GetID())-1;
474 // assert for not found
475 return (unsigned int) m_hash
.Index( item
.GetID() );
478 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
480 wxASSERT( row
< m_hash
.GetCount() );
481 return wxDataViewItem( m_hash
[row
] );
484 bool wxDataViewIndexListModel::HasDefaultCompare() const
489 int wxDataViewIndexListModel::Compare(const wxDataViewItem
& item1
,
490 const wxDataViewItem
& item2
,
491 unsigned int WXUNUSED(column
),
492 bool ascending
) const
496 unsigned int pos1
= wxPtrToUInt(item1
.GetID()); // -1 not needed here
497 unsigned int pos2
= wxPtrToUInt(item2
.GetID()); // -1 not needed here
506 return GetRow(item1
) - GetRow(item2
);
508 return GetRow(item2
) - GetRow(item1
);
511 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
518 return m_hash
.GetCount();
521 // ---------------------------------------------------------
522 // wxDataViewVirtualListModel
523 // ---------------------------------------------------------
527 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size
)
529 m_size
= initial_size
;
532 void wxDataViewVirtualListModel::Reset( unsigned int new_size
)
534 /* wxDataViewModel:: */ BeforeReset();
538 /* wxDataViewModel:: */ AfterReset();
541 void wxDataViewVirtualListModel::RowPrepended()
544 wxDataViewItem
item( wxUIntToPtr(1) );
545 ItemAdded( wxDataViewItem(0), item
);
548 void wxDataViewVirtualListModel::RowInserted( unsigned int before
)
551 wxDataViewItem
item( wxUIntToPtr(before
+1) );
552 ItemAdded( wxDataViewItem(0), item
);
555 void wxDataViewVirtualListModel::RowAppended()
558 wxDataViewItem
item( wxUIntToPtr(m_size
) );
559 ItemAdded( wxDataViewItem(0), item
);
562 void wxDataViewVirtualListModel::RowDeleted( unsigned int row
)
565 wxDataViewItem
item( wxUIntToPtr(row
+1) );
566 /* wxDataViewModel:: */ ItemDeleted( wxDataViewItem(0), item
);
569 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt
&rows
)
571 m_size
-= rows
.GetCount();
573 wxArrayInt sorted
= rows
;
574 sorted
.Sort( my_sort
);
576 wxDataViewItemArray array
;
578 for (i
= 0; i
< sorted
.GetCount(); i
++)
580 wxDataViewItem
item( wxUIntToPtr(sorted
[i
]+1) );
583 /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array
);
586 void wxDataViewVirtualListModel::RowChanged( unsigned int row
)
588 /* wxDataViewModel:: */ ItemChanged( GetItem(row
) );
591 void wxDataViewVirtualListModel::RowValueChanged( unsigned int row
, unsigned int col
)
593 /* wxDataViewModel:: */ ValueChanged( GetItem(row
), col
);
596 unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem
&item
) const
598 return wxPtrToUInt( item
.GetID() ) -1;
601 wxDataViewItem
wxDataViewVirtualListModel::GetItem( unsigned int row
) const
603 return wxDataViewItem( wxUIntToPtr(row
+1) );
606 bool wxDataViewVirtualListModel::HasDefaultCompare() const
611 int wxDataViewVirtualListModel::Compare(const wxDataViewItem
& item1
,
612 const wxDataViewItem
& item2
,
613 unsigned int WXUNUSED(column
),
614 bool ascending
) const
616 unsigned int pos1
= wxPtrToUInt(item1
.GetID()); // -1 not needed here
617 unsigned int pos2
= wxPtrToUInt(item2
.GetID()); // -1 not needed here
625 unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem
&WXUNUSED(item
), wxDataViewItemArray
&WXUNUSED(children
) ) const
627 return 0; // should we report an error ?
632 //-----------------------------------------------------------------------------
633 // wxDataViewIconText
634 //-----------------------------------------------------------------------------
636 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
638 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
640 // ---------------------------------------------------------
641 // wxDataViewRendererBase
642 // ---------------------------------------------------------
644 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
646 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
647 wxDataViewCellMode
WXUNUSED(mode
),
648 int WXUNUSED(align
) )
650 m_variantType
= varianttype
;
654 wxDataViewRendererBase::~wxDataViewRendererBase()
658 const wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
660 return const_cast<wxDataViewRendererBase
*>(this)->GetOwner()->GetOwner();
663 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
665 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
667 // Before doing anything we send an event asking if editing of this item is really wanted.
668 wxDataViewEvent
start_event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv_ctrl
->GetId() );
669 start_event
.SetDataViewColumn( GetOwner() );
670 start_event
.SetModel( dv_ctrl
->GetModel() );
671 start_event
.SetItem( item
);
672 start_event
.SetEventObject( dv_ctrl
);
673 dv_ctrl
->GetEventHandler()->ProcessEvent( start_event
);
674 if( !start_event
.IsAllowed() )
677 m_item
= item
; // remember for later
679 unsigned int col
= GetOwner()->GetModelColumn();
681 dv_ctrl
->GetModel()->GetValue( value
, item
, col
);
683 m_editorCtrl
= CreateEditorCtrl( dv_ctrl
->GetMainWindow(), labelRect
, value
);
685 // there might be no editor control for the given item
689 wxDataViewEditorCtrlEvtHandler
*handler
=
690 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
692 m_editorCtrl
->PushEventHandler( handler
);
694 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
695 handler
->SetFocusOnIdle();
697 m_editorCtrl
->SetFocus();
700 // Now we should send Editing Started event
701 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv_ctrl
->GetId() );
702 event
.SetDataViewColumn( GetOwner() );
703 event
.SetModel( dv_ctrl
->GetModel() );
704 event
.SetItem( item
);
705 event
.SetEventObject( dv_ctrl
);
706 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
711 void wxDataViewRendererBase::DestroyEditControl()
713 // Hide the control immediately but don't delete it yet as there could be
714 // some pending messages for it.
715 m_editorCtrl
->Hide();
717 wxEvtHandler
* const handler
= m_editorCtrl
->PopEventHandler();
719 wxPendingDelete
.Append(handler
);
720 wxPendingDelete
.Append(m_editorCtrl
);
723 void wxDataViewRendererBase::CancelEditing()
728 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
730 DestroyEditControl();
733 bool wxDataViewRendererBase::FinishEditing()
739 GetValueFromEditorCtrl( m_editorCtrl
, value
);
741 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
743 dv_ctrl
->GetMainWindow()->SetFocus();
745 DestroyEditControl();
747 if (!Validate(value
))
750 unsigned int col
= GetOwner()->GetModelColumn();
751 dv_ctrl
->GetModel()->ChangeValue(value
, m_item
, col
);
753 // Now we should send Editing Done event
754 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv_ctrl
->GetId() );
755 event
.SetDataViewColumn( GetOwner() );
756 event
.SetModel( dv_ctrl
->GetModel() );
757 event
.SetItem( m_item
);
758 event
.SetEventObject( dv_ctrl
);
759 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
764 // ----------------------------------------------------------------------------
765 // wxDataViewCustomRendererBase
766 // ----------------------------------------------------------------------------
769 wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell
, wxDC
*dc
, int state
)
771 wxCHECK_RET( dc
, "no DC to draw on in custom renderer?" );
773 // adjust the rectangle ourselves to account for the alignment
774 wxRect rectItem
= rectCell
;
775 const int align
= GetAlignment();
776 if ( align
!= wxDVR_DEFAULT_ALIGNMENT
)
778 const wxSize size
= GetSize();
780 // take alignment into account only if there is enough space, otherwise
781 // show as much contents as possible
783 // notice that many existing renderers (e.g. wxDataViewSpinRenderer)
784 // return hard-coded size which can be more than they need and if we
785 // trusted their GetSize() we'd draw the text out of cell bounds
788 if ( size
.x
>= 0 && size
.x
< rectCell
.width
)
790 if ( align
& wxALIGN_CENTER_HORIZONTAL
)
791 rectItem
.x
+= (rectCell
.width
- size
.x
)/2;
792 else if ( align
& wxALIGN_RIGHT
)
793 rectItem
.x
+= rectCell
.width
- size
.x
;
794 // else: wxALIGN_LEFT is the default
796 rectItem
.width
= size
.x
;
799 if ( size
.y
>= 0 && size
.y
< rectCell
.height
)
801 if ( align
& wxALIGN_CENTER_VERTICAL
)
802 rectItem
.y
+= (rectCell
.height
- size
.y
)/2;
803 else if ( align
& wxALIGN_BOTTOM
)
804 rectItem
.y
+= rectCell
.height
- size
.y
;
805 // else: wxALIGN_TOP is the default
807 rectItem
.height
= size
.y
;
812 // set up the DC attributes
814 // override custom foreground with the standard one for the selected items
815 // because we currently don't allow changing the selection background and
816 // custom colours may be unreadable on it
818 if ( state
& wxDATAVIEW_CELL_SELECTED
)
819 col
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
820 else if ( m_attr
.HasColour() )
821 col
= m_attr
.GetColour();
822 else // use default foreground
823 col
= GetOwner()->GetOwner()->GetForegroundColour();
825 wxDCTextColourChanger
changeFg(*dc
, col
);
827 wxDCFontChanger
changeFont(*dc
);
828 if ( m_attr
.HasFont() )
830 wxFont
font(dc
->GetFont());
831 if ( m_attr
.GetBold() )
833 if ( m_attr
.GetItalic() )
836 changeFont
.Set(font
);
839 Render(rectItem
, dc
, state
);
843 wxDataViewCustomRendererBase::RenderText(const wxString
& text
,
849 wxRect rectText
= rect
;
850 rectText
.x
+= xoffset
;
851 rectText
.width
-= xoffset
;
853 // check if we want to ellipsize the text if it doesn't fit
854 wxString ellipsizedText
;
855 if ( GetEllipsizeMode() != wxELLIPSIZE_NONE
)
857 ellipsizedText
= wxControl::Ellipsize
863 wxELLIPSIZE_FLAGS_NONE
867 // get the alignment to use
868 int align
= GetAlignment();
869 if ( align
== wxDVR_DEFAULT_ALIGNMENT
)
871 // if we don't have an explicit alignment ourselves, use that of the
872 // column in horizontal direction and default vertical alignment
873 align
= GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
876 dc
->DrawLabel(ellipsizedText
.empty() ? text
: ellipsizedText
,
880 //-----------------------------------------------------------------------------
881 // wxDataViewEditorCtrlEvtHandler
882 //-----------------------------------------------------------------------------
884 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
885 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
886 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
887 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
888 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
891 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
895 m_focusOnIdle
= false;
896 if (wxWindow::FindFocus() != m_editorCtrl
)
897 m_editorCtrl
->SetFocus();
903 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
906 m_owner
->FinishEditing();
909 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
911 switch ( event
.m_keyCode
)
915 m_owner
->FinishEditing();
921 m_owner
->CancelEditing();
929 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
934 m_owner
->FinishEditing();
940 // ---------------------------------------------------------
941 // wxDataViewColumnBase
942 // ---------------------------------------------------------
944 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
945 unsigned int model_column
)
947 m_renderer
= renderer
;
948 m_model_column
= model_column
;
950 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
953 wxDataViewColumnBase::~wxDataViewColumnBase()
958 // ---------------------------------------------------------
959 // wxDataViewCtrlBase
960 // ---------------------------------------------------------
962 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
964 wxDataViewCtrlBase::wxDataViewCtrlBase()
967 m_expander_column
= 0;
971 wxDataViewCtrlBase::~wxDataViewCtrlBase()
980 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
984 m_model
->DecRef(); // discard old model, if any
987 // add our own reference to the new model:
997 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
1002 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
1007 void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem
& item
)
1009 if (!m_model
) return;
1011 if (!item
.IsOk()) return;
1013 wxVector
<wxDataViewItem
> parentChain
;
1015 // at first we get all the parents of the selected item
1016 wxDataViewItem parent
= m_model
->GetParent(item
);
1017 while (parent
.IsOk())
1019 parentChain
.push_back(parent
);
1020 parent
= m_model
->GetParent(parent
);
1023 // then we expand the parents, starting at the root
1024 while (!parentChain
.empty())
1026 Expand(parentChain
.back());
1027 parentChain
.pop_back();
1031 wxDataViewItem
wxDataViewCtrlBase::GetCurrentItem() const
1033 return HasFlag(wxDV_MULTIPLE
) ? DoGetCurrentItem()
1037 void wxDataViewCtrlBase::SetCurrentItem(const wxDataViewItem
& item
)
1039 wxCHECK_RET( item
.IsOk(), "Can't make current an invalid item." );
1041 if ( HasFlag(wxDV_MULTIPLE
) )
1042 DoSetCurrentItem(item
);
1048 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
1049 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1051 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1052 new wxDataViewTextRenderer( wxT("string"), mode
),
1053 model_column
, width
, align
, flags
);
1054 AppendColumn( ret
);
1059 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
1060 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1062 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1063 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1064 model_column
, width
, align
, flags
);
1065 AppendColumn( ret
);
1070 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
1071 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1073 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1074 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1075 model_column
, width
, align
, flags
);
1076 AppendColumn( ret
);
1081 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
1082 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1084 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1085 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1086 model_column
, width
, align
, flags
);
1087 AppendColumn( ret
);
1092 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
1093 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1095 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1096 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1097 model_column
, width
, align
, flags
);
1098 AppendColumn( ret
);
1103 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
1104 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1106 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1107 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1108 model_column
, width
, align
, flags
);
1109 AppendColumn( ret
);
1114 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1115 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1117 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1118 new wxDataViewTextRenderer( wxT("string"), mode
),
1119 model_column
, width
, align
, flags
);
1120 AppendColumn( ret
);
1125 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1126 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1128 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1129 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1130 model_column
, width
, align
, flags
);
1131 AppendColumn( ret
);
1136 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1137 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1139 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1140 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1141 model_column
, width
, align
, flags
);
1142 AppendColumn( ret
);
1147 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1148 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1150 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1151 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1152 model_column
, width
, align
, flags
);
1153 AppendColumn( ret
);
1158 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1159 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1161 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1162 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1163 model_column
, width
, align
, flags
);
1164 AppendColumn( ret
);
1169 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1170 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1172 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1173 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1174 model_column
, width
, align
, flags
);
1175 AppendColumn( ret
);
1180 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1181 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1183 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1184 new wxDataViewTextRenderer( wxT("string"), mode
),
1185 model_column
, width
, align
, flags
);
1186 PrependColumn( ret
);
1191 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1192 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1194 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1195 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1196 model_column
, width
, align
, flags
);
1197 PrependColumn( ret
);
1202 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1203 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1206 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1207 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1208 model_column
, width
, align
, flags
);
1209 PrependColumn( ret
);
1214 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1215 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1217 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1218 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1219 model_column
, width
, align
, flags
);
1220 PrependColumn( ret
);
1225 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1226 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1228 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1229 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1230 model_column
, width
, align
, flags
);
1231 PrependColumn( ret
);
1236 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1237 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1239 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1240 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1241 model_column
, width
, align
, flags
);
1242 PrependColumn( ret
);
1247 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1248 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1250 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1251 new wxDataViewTextRenderer( wxT("string"), mode
),
1252 model_column
, width
, align
, flags
);
1253 PrependColumn( ret
);
1258 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1259 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1261 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1262 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1263 model_column
, width
, align
, flags
);
1264 PrependColumn( ret
);
1269 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1270 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1272 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1273 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1274 model_column
, width
, align
, flags
);
1275 PrependColumn( ret
);
1280 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1281 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1283 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1284 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1285 model_column
, width
, align
, flags
);
1286 PrependColumn( ret
);
1291 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1292 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1294 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1295 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1296 model_column
, width
, align
, flags
);
1297 PrependColumn( ret
);
1302 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1303 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1305 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1306 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1307 model_column
, width
, align
, flags
);
1308 PrependColumn( ret
);
1313 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1315 col
->SetOwner( (wxDataViewCtrl
*) this );
1320 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1322 col
->SetOwner( (wxDataViewCtrl
*) this );
1327 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1329 col
->SetOwner( (wxDataViewCtrl
*) this );
1333 // ---------------------------------------------------------
1335 // ---------------------------------------------------------
1337 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1339 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
);
1341 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
);
1342 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
);
1343 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
);
1344 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
);
1345 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
);
1346 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
);
1347 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, wxDataViewEvent
);
1348 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
);
1349 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
);
1351 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
);
1353 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
);
1354 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
);
1355 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
);
1356 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
);
1358 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, wxDataViewEvent
);
1360 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
);
1361 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, wxDataViewEvent
);
1362 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, wxDataViewEvent
);
1366 // -------------------------------------
1367 // wxDataViewSpinRenderer
1368 // -------------------------------------
1370 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1371 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1377 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1380 wxSize size
= labelRect
.GetSize();
1382 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1385 str
.Printf( wxT("%d"), (int) l
);
1386 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1387 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1389 size
= sc
->GetSize();
1390 wxPoint pt
= sc
->GetPosition();
1391 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1397 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1399 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1400 long l
= sc
->GetValue();
1405 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1408 str
.Printf(wxT("%d"), (int) m_data
);
1409 RenderText( str
, 0, rect
, dc
, state
);
1413 wxSize
wxDataViewSpinRenderer::GetSize() const
1415 return wxSize(80,16);
1418 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1420 m_data
= value
.GetLong();
1424 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1430 // -------------------------------------
1431 // wxDataViewChoiceRenderer
1432 // -------------------------------------
1434 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
1436 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1437 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1439 m_choices
= choices
;
1442 wxControl
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1444 wxChoice
* c
= new wxChoice(parent
, wxID_ANY
, labelRect
.GetTopLeft(), wxDefaultSize
, m_choices
);
1445 c
->Move(labelRect
.GetRight() - c
->GetRect().width
, wxDefaultCoord
);
1446 c
->SetStringSelection( value
.GetString() );
1450 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1452 wxChoice
*c
= (wxChoice
*) editor
;
1453 wxString s
= c
->GetStringSelection();
1458 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1460 RenderText( m_data
, 0, rect
, dc
, state
);
1464 wxSize
wxDataViewChoiceRenderer::GetSize() const
1466 return wxSize(80,16);
1469 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1471 m_data
= value
.GetString();
1475 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1481 // ----------------------------------------------------------------------------
1482 // wxDataViewChoiceByIndexRenderer
1483 // ----------------------------------------------------------------------------
1485 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
1486 wxDataViewCellMode mode
, int alignment
) :
1487 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
1491 wxControl
* wxDataViewChoiceByIndexRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1493 wxVariant string_value
= GetChoice( value
.GetLong() );
1495 return wxDataViewChoiceRenderer::CreateEditorCtrl( parent
, labelRect
, string_value
);
1498 bool wxDataViewChoiceByIndexRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1500 wxVariant string_value
;
1501 if (!wxDataViewChoiceRenderer::GetValueFromEditorCtrl( editor
, string_value
))
1504 value
= (long) GetChoices().Index( string_value
.GetString() );
1508 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
1510 wxVariant string_value
= GetChoice( value
.GetLong() );
1511 return wxDataViewChoiceRenderer::SetValue( string_value
);
1514 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
1516 wxVariant string_value
;
1517 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
1520 value
= (long) GetChoices().Index( string_value
.GetString() );
1526 //-----------------------------------------------------------------------------
1527 // wxDataViewListStore
1528 //-----------------------------------------------------------------------------
1530 wxDataViewListStore::wxDataViewListStore()
1534 wxDataViewListStore::~wxDataViewListStore()
1536 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1537 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1539 wxDataViewListStoreLine
* line
= *it
;
1544 void wxDataViewListStore::PrependColumn( const wxString
&varianttype
)
1546 m_cols
.Insert( varianttype
, 0 );
1549 void wxDataViewListStore::InsertColumn( unsigned int pos
, const wxString
&varianttype
)
1551 m_cols
.Insert( varianttype
, pos
);
1554 void wxDataViewListStore::AppendColumn( const wxString
&varianttype
)
1556 m_cols
.Add( varianttype
);
1559 unsigned int wxDataViewListStore::GetColumnCount() const
1561 return m_cols
.GetCount();
1564 wxString
wxDataViewListStore::GetColumnType( unsigned int pos
) const
1569 void wxDataViewListStore::AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1571 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1572 line
->m_values
= values
;
1573 m_data
.push_back( line
);
1578 void wxDataViewListStore::PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1580 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1581 line
->m_values
= values
;
1582 m_data
.insert( m_data
.begin(), line
);
1587 void wxDataViewListStore::InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
,
1588 wxClientData
*data
)
1590 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1591 line
->m_values
= values
;
1592 m_data
.insert( m_data
.begin()+row
, line
);
1597 void wxDataViewListStore::DeleteItem( unsigned int row
)
1599 wxVector
<wxDataViewListStoreLine
*>::iterator it
= m_data
.begin() + row
;
1606 void wxDataViewListStore::DeleteAllItems()
1608 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1609 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1611 wxDataViewListStoreLine
* line
= *it
;
1620 void wxDataViewListStore::GetValueByRow( wxVariant
&value
, unsigned int row
, unsigned int col
) const
1622 wxDataViewListStoreLine
*line
= m_data
[row
];
1623 value
= line
->m_values
[col
];
1626 bool wxDataViewListStore::SetValueByRow( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1628 wxDataViewListStoreLine
*line
= m_data
[row
];
1629 line
->m_values
[col
] = value
;
1634 //-----------------------------------------------------------------------------
1635 // wxDataViewListCtrl
1636 //-----------------------------------------------------------------------------
1638 IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl
,wxDataViewCtrl
)
1640 BEGIN_EVENT_TABLE(wxDataViewListCtrl
,wxDataViewCtrl
)
1641 EVT_SIZE( wxDataViewListCtrl::OnSize
)
1644 wxDataViewListCtrl::wxDataViewListCtrl()
1648 wxDataViewListCtrl::wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
1649 const wxPoint
& pos
, const wxSize
& size
, long style
,
1650 const wxValidator
& validator
)
1652 Create( parent
, id
, pos
, size
, style
, validator
);
1655 wxDataViewListCtrl::~wxDataViewListCtrl()
1660 bool wxDataViewListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1661 const wxPoint
& pos
, const wxSize
& size
, long style
,
1662 const wxValidator
& validator
)
1664 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
1667 wxDataViewListStore
*store
= new wxDataViewListStore
;
1668 AssociateModel( store
);
1674 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1676 GetStore()->AppendColumn( varianttype
);
1677 return wxDataViewCtrl::AppendColumn( column
);
1680 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1682 GetStore()->PrependColumn( varianttype
);
1683 return wxDataViewCtrl::PrependColumn( column
);
1686 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
)
1688 GetStore()->InsertColumn( pos
, varianttype
);
1689 return wxDataViewCtrl::InsertColumn( pos
, column
);
1692 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*col
)
1694 return PrependColumn( col
, "string" );
1697 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
1699 return InsertColumn( pos
, col
, "string" );
1702 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*col
)
1704 return AppendColumn( col
, "string" );
1707 wxDataViewColumn
*wxDataViewListCtrl::AppendTextColumn( const wxString
&label
,
1708 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1710 GetStore()->AppendColumn( wxT("string") );
1712 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1713 new wxDataViewTextRenderer( wxT("string"), mode
),
1714 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1716 wxDataViewCtrl::AppendColumn( ret
);
1721 wxDataViewColumn
*wxDataViewListCtrl::AppendToggleColumn( const wxString
&label
,
1722 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1724 GetStore()->AppendColumn( wxT("bool") );
1726 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1727 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1728 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1730 wxDataViewCtrl::AppendColumn( ret
);
1735 wxDataViewColumn
*wxDataViewListCtrl::AppendProgressColumn( const wxString
&label
,
1736 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1738 GetStore()->AppendColumn( wxT("long") );
1740 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1741 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1742 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1744 wxDataViewCtrl::AppendColumn( ret
);
1749 wxDataViewColumn
*wxDataViewListCtrl::AppendIconTextColumn( const wxString
&label
,
1750 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1752 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
1754 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1755 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1756 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1758 wxDataViewCtrl::AppendColumn( ret
);
1763 void wxDataViewListCtrl::OnSize( wxSizeEvent
&event
)
1768 //-----------------------------------------------------------------------------
1769 // wxDataViewTreeStore
1770 //-----------------------------------------------------------------------------
1772 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1773 wxDataViewTreeStoreNode
*parent
,
1774 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1782 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1788 #include "wx/listimpl.cpp"
1789 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1791 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1792 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1793 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1794 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1796 m_iconExpanded
= expanded
;
1797 m_isExpanded
= false;
1798 m_children
.DeleteContents(true);
1801 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1805 //-----------------------------------------------------------------------------
1807 wxDataViewTreeStore::wxDataViewTreeStore()
1809 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1812 wxDataViewTreeStore::~wxDataViewTreeStore()
1817 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1818 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1820 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1821 if (!parent_node
) return wxDataViewItem(0);
1823 wxDataViewTreeStoreNode
*node
=
1824 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1825 parent_node
->GetChildren().Append( node
);
1827 return node
->GetItem();
1830 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1831 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1833 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1834 if (!parent_node
) return wxDataViewItem(0);
1836 wxDataViewTreeStoreNode
*node
=
1837 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1838 parent_node
->GetChildren().Insert( node
);
1840 return node
->GetItem();
1844 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& parent
,
1845 const wxDataViewItem
& previous
,
1846 const wxString
& text
,
1850 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1851 if (!parent_node
) return wxDataViewItem(0);
1853 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1854 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1855 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1857 wxDataViewTreeStoreNode
*node
=
1858 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1859 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1861 return node
->GetItem();
1864 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1865 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1866 wxClientData
*data
)
1868 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1869 if (!parent_node
) return wxDataViewItem(0);
1871 wxDataViewTreeStoreContainerNode
*node
=
1872 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1873 parent_node
->GetChildren().Insert( node
);
1875 return node
->GetItem();
1879 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1880 const wxString
&text
,
1882 const wxIcon
& expanded
,
1883 wxClientData
* data
)
1885 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1886 if (!parent_node
) return wxDataViewItem(0);
1888 wxDataViewTreeStoreContainerNode
*node
=
1889 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1890 parent_node
->GetChildren().Append( node
);
1892 return node
->GetItem();
1896 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& parent
,
1897 const wxDataViewItem
& previous
,
1898 const wxString
& text
,
1900 const wxIcon
& expanded
,
1901 wxClientData
* data
)
1903 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1904 if (!parent_node
) return wxDataViewItem(0);
1906 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1907 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1908 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1910 wxDataViewTreeStoreContainerNode
*node
=
1911 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1912 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1914 return node
->GetItem();
1917 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
& item
) const
1919 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1920 if (!node
) return false;
1922 return node
->IsContainer();
1925 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1927 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1928 if (!parent_node
) return wxDataViewItem(0);
1930 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1932 return node
->GetData();
1934 return wxDataViewItem(0);
1937 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1939 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1940 if (!node
) return -1;
1942 if (!node
->IsContainer())
1945 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1946 return (int) container_node
->GetChildren().GetCount();
1949 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1951 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1954 node
->SetText( text
);
1957 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1959 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1960 if (!node
) return wxEmptyString
;
1962 return node
->GetText();
1965 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1967 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1970 node
->SetIcon( icon
);
1973 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1975 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1976 if (!node
) return wxNullIcon
;
1978 return node
->GetIcon();
1981 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1983 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1986 node
->SetExpandedIcon( icon
);
1989 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1991 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1992 if (!node
) return wxNullIcon
;
1994 return node
->GetExpandedIcon();
1997 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1999 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2002 node
->SetData( data
);
2005 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
2007 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2008 if (!node
) return NULL
;
2010 return node
->GetData();
2013 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
2015 if (!item
.IsOk()) return;
2017 wxDataViewItem parent_item
= GetParent( item
);
2019 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
2020 if (!parent_node
) return;
2022 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2025 parent_node
->GetChildren().DeleteObject( node
);
2028 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
2030 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2033 node
->GetChildren().clear();
2036 void wxDataViewTreeStore::DeleteAllItems()
2038 DeleteChildren(m_root
);
2042 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
2043 const wxDataViewItem
&item
,
2044 unsigned int WXUNUSED(col
)) const
2046 // if (col != 0) return;
2048 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2051 wxIcon
icon( node
->GetIcon());
2052 if (node
->IsContainer())
2054 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
2055 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
2056 icon
= container
->GetExpandedIcon();
2059 wxDataViewIconText
data( node
->GetText(), icon
);
2065 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
2066 const wxDataViewItem
& item
,
2067 unsigned int WXUNUSED(col
))
2069 // if (col != 0) return false;
2071 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2072 if (!node
) return false;
2074 wxDataViewIconText data
;
2078 node
->SetText( data
.GetText() );
2079 node
->SetIcon( data
.GetIcon() );
2084 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
2086 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2087 if (!node
) return wxDataViewItem(0);
2089 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
2090 if (!parent
) return wxDataViewItem(0);
2092 if (parent
== m_root
)
2093 return wxDataViewItem(0);
2095 return parent
->GetItem();
2098 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
2100 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2101 if (!node
) return 0;
2103 wxDataViewTreeStoreNodeList::iterator iter
;
2104 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2106 wxDataViewTreeStoreNode
* child
= *iter
;
2107 children
.Add( child
->GetItem() );
2110 return node
->GetChildren().GetCount();
2113 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
2114 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) ) const
2116 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
2117 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
2119 if (!node1
|| !node2
)
2122 wxDataViewTreeStoreContainerNode
* parent1
=
2123 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
2124 wxDataViewTreeStoreContainerNode
* parent2
=
2125 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
2127 if (parent1
!= parent2
)
2129 wxLogError( wxT("Comparing items with different parent.") );
2133 if (node1
->IsContainer() && !node2
->IsContainer())
2136 if (node2
->IsContainer() && !node1
->IsContainer())
2139 return parent1
->GetChildren().IndexOf( node1
) - parent2
->GetChildren().IndexOf( node2
);
2142 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
2147 return (wxDataViewTreeStoreNode
*) item
.GetID();
2150 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
2153 return (wxDataViewTreeStoreContainerNode
*) m_root
;
2155 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
2157 if (!node
->IsContainer())
2160 return (wxDataViewTreeStoreContainerNode
*) node
;
2163 //-----------------------------------------------------------------------------
2164 // wxDataViewTreeCtrl
2165 //-----------------------------------------------------------------------------
2167 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2169 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2170 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
2171 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
2172 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
2175 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
2180 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2181 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2183 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
2186 // create the standard model and a column in the tree
2187 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
2188 AssociateModel( store
);
2191 AppendIconTextColumn
2193 wxString(), // no label (header is not shown anyhow)
2194 0, // the only model column
2195 wxDATAVIEW_CELL_EDITABLE
,
2196 -1, // default width
2197 wxALIGN_NOT
, // and alignment
2204 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
2208 m_imageList
= imagelist
;
2211 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
2212 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2214 wxIcon icon
= wxNullIcon
;
2215 if (m_imageList
&& (iconIndex
!= -1))
2216 icon
= m_imageList
->GetIcon( iconIndex
);
2218 wxDataViewItem res
= GetStore()->AppendItem( parent
, text
, icon
, data
);
2220 GetStore()->ItemAdded( parent
, res
);
2225 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
2226 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2228 wxIcon icon
= wxNullIcon
;
2229 if (m_imageList
&& (iconIndex
!= -1))
2230 icon
= m_imageList
->GetIcon( iconIndex
);
2232 wxDataViewItem res
= GetStore()->PrependItem( parent
, text
, icon
, data
);
2234 GetStore()->ItemAdded( parent
, res
);
2239 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2240 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2242 wxIcon icon
= wxNullIcon
;
2243 if (m_imageList
&& (iconIndex
!= -1))
2244 icon
= m_imageList
->GetIcon( iconIndex
);
2246 wxDataViewItem res
= GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
2248 GetStore()->ItemAdded( parent
, res
);
2253 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
2254 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2256 wxIcon icon
= wxNullIcon
;
2257 if (m_imageList
&& (iconIndex
!= -1))
2258 icon
= m_imageList
->GetIcon( iconIndex
);
2260 wxIcon expanded
= wxNullIcon
;
2261 if (m_imageList
&& (expandedIndex
!= -1))
2262 expanded
= m_imageList
->GetIcon( expandedIndex
);
2264 wxDataViewItem res
= GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
2266 GetStore()->ItemAdded( parent
, res
);
2271 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
2272 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2274 wxIcon icon
= wxNullIcon
;
2275 if (m_imageList
&& (iconIndex
!= -1))
2276 icon
= m_imageList
->GetIcon( iconIndex
);
2278 wxIcon expanded
= wxNullIcon
;
2279 if (m_imageList
&& (expandedIndex
!= -1))
2280 expanded
= m_imageList
->GetIcon( expandedIndex
);
2282 wxDataViewItem res
= GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
2284 GetStore()->ItemAdded( parent
, res
);
2289 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2290 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2292 wxIcon icon
= wxNullIcon
;
2293 if (m_imageList
&& (iconIndex
!= -1))
2294 icon
= m_imageList
->GetIcon( iconIndex
);
2296 wxIcon expanded
= wxNullIcon
;
2297 if (m_imageList
&& (expandedIndex
!= -1))
2298 expanded
= m_imageList
->GetIcon( expandedIndex
);
2300 wxDataViewItem res
= GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
2302 GetStore()->ItemAdded( parent
, res
);
2307 void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2309 GetStore()->SetItemText(item
,text
);
2312 GetStore()->ValueChanged( item
, 0 );
2315 void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2317 GetStore()->SetItemIcon(item
,icon
);
2320 GetStore()->ValueChanged( item
, 0 );
2323 void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2325 GetStore()->SetItemExpandedIcon(item
,icon
);
2328 GetStore()->ValueChanged( item
, 0 );
2331 void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem
& item
)
2333 wxDataViewItem parent_item
= GetStore()->GetParent( item
);
2335 GetStore()->DeleteItem(item
);
2338 GetStore()->ItemDeleted( parent_item
, item
);
2341 void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem
& item
)
2343 wxDataViewTreeStoreContainerNode
*node
= GetStore()->FindContainerNode( item
);
2346 wxDataViewItemArray array
;
2347 wxDataViewTreeStoreNodeList::iterator iter
;
2348 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2350 wxDataViewTreeStoreNode
* child
= *iter
;
2351 array
.Add( child
->GetItem() );
2354 GetStore()->DeleteChildren( item
);
2357 GetStore()->ItemsDeleted( item
, array
);
2360 void wxDataViewTreeCtrl::DeleteAllItems()
2362 GetStore()->DeleteAllItems();
2364 GetStore()->Cleared();
2367 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
2369 if (m_imageList
) return;
2371 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2372 if (!container
) return;
2374 container
->SetExpanded( true );
2376 GetStore()->ItemChanged( event
.GetItem() );
2379 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
2381 if (m_imageList
) return;
2383 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2384 if (!container
) return;
2386 container
->SetExpanded( false );
2388 GetStore()->ItemChanged( event
.GetItem() );
2391 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
2393 #if defined(wxUSE_GENERICDATAVIEWCTRL)
2394 // automatically resize our only column to take the entire control width
2395 if ( GetColumnCount() )
2397 wxSize size
= GetClientSize();
2398 GetColumn(0)->SetWidth(size
.x
);
2404 #endif // wxUSE_DATAVIEWCTRL