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 void wxDataViewModel::Resort()
240 wxDataViewModelNotifiers::iterator iter
;
241 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
243 wxDataViewModelNotifier
* notifier
= *iter
;
248 void wxDataViewModel::AddNotifier( wxDataViewModelNotifier
*notifier
)
250 m_notifiers
.push_back( notifier
);
251 notifier
->SetOwner( this );
254 void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier
*notifier
)
256 m_notifiers
.DeleteObject( notifier
);
259 int wxDataViewModel::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
260 unsigned int column
, bool ascending
) const
262 // sort branches before leaves
263 bool item1_is_container
= IsContainer(item1
);
264 bool item2_is_container
= IsContainer(item2
);
266 if (item1_is_container
&& !item2_is_container
)
268 if (item2_is_container
&& !item1_is_container
)
271 wxVariant value1
,value2
;
272 GetValue( value1
, item1
, column
);
273 GetValue( value2
, item2
, column
);
277 wxVariant temp
= value1
;
282 if (value1
.GetType() == wxT("string"))
284 wxString str1
= value1
.GetString();
285 wxString str2
= value2
.GetString();
286 int res
= str1
.Cmp( str2
);
290 else if (value1
.GetType() == wxT("long"))
292 long l1
= value1
.GetLong();
293 long l2
= value2
.GetLong();
298 else if (value1
.GetType() == wxT("double"))
300 double d1
= value1
.GetDouble();
301 double d2
= value2
.GetDouble();
307 else if (value1
.GetType() == wxT("datetime"))
309 wxDateTime dt1
= value1
.GetDateTime();
310 wxDateTime dt2
= value2
.GetDateTime();
311 if (dt1
.IsEarlierThan(dt2
))
313 if (dt2
.IsEarlierThan(dt1
))
317 // items must be different
318 wxUIntPtr id1
= wxPtrToUInt(item1
.GetID()),
319 id2
= wxPtrToUInt(item2
.GetID());
321 return ascending
? id1
- id2
: id2
- id1
;
324 // ---------------------------------------------------------
325 // wxDataViewIndexListModel
326 // ---------------------------------------------------------
328 static int my_sort( int *v1
, int *v2
)
334 wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size
)
336 // IDs are ordered until an item gets deleted or inserted
339 // build initial index
341 for (i
= 1; i
< initial_size
+1; i
++)
342 m_hash
.Add( wxUIntToPtr(i
) );
343 m_nextFreeID
= initial_size
+ 1;
346 void wxDataViewIndexListModel::Reset( unsigned int new_size
)
350 // IDs are ordered until an item gets deleted or inserted
353 // build initial index
355 for (i
= 1; i
< new_size
+1; i
++)
356 m_hash
.Add( wxUIntToPtr(i
) );
358 m_nextFreeID
= new_size
+ 1;
360 /* wxDataViewModel:: */ Cleared();
363 void wxDataViewIndexListModel::RowPrepended()
367 unsigned int id
= m_nextFreeID
;
370 m_hash
.Insert( wxUIntToPtr(id
), 0 );
371 wxDataViewItem
item( wxUIntToPtr(id
) );
372 ItemAdded( wxDataViewItem(0), item
);
376 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
380 unsigned int id
= m_nextFreeID
;
383 m_hash
.Insert( wxUIntToPtr(id
), before
);
384 wxDataViewItem
item( wxUIntToPtr(id
) );
385 ItemAdded( wxDataViewItem(0), item
);
388 void wxDataViewIndexListModel::RowAppended()
390 unsigned int id
= m_nextFreeID
;
393 m_hash
.Add( wxUIntToPtr(id
) );
394 wxDataViewItem
item( wxUIntToPtr(id
) );
395 ItemAdded( wxDataViewItem(0), item
);
398 void wxDataViewIndexListModel::RowDeleted( unsigned int row
)
402 wxDataViewItem
item( m_hash
[row
] );
403 /* wxDataViewModel:: */ ItemDeleted( wxDataViewItem(0), item
);
404 m_hash
.RemoveAt( row
);
407 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt
&rows
)
409 wxArrayInt sorted
= rows
;
410 sorted
.Sort( my_sort
);
414 wxDataViewItemArray array
;
416 for (i
= 0; i
< rows
.GetCount(); i
++)
418 wxDataViewItem
item( m_hash
[rows
[i
]] );
421 /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array
);
423 for (i
= 0; i
< sorted
.GetCount(); i
++)
424 m_hash
.RemoveAt( sorted
[i
] );
427 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
429 /* wxDataViewModel:: */ ItemChanged( GetItem(row
) );
432 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
434 /* wxDataViewModel:: */ ValueChanged( GetItem(row
), col
);
437 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
440 return wxPtrToUInt(item
.GetID())-1;
442 // assert for not found
443 return (unsigned int) m_hash
.Index( item
.GetID() );
446 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
448 wxASSERT( row
< m_hash
.GetCount() );
449 return wxDataViewItem( m_hash
[row
] );
452 bool wxDataViewIndexListModel::HasDefaultCompare() const
457 int wxDataViewIndexListModel::Compare(const wxDataViewItem
& item1
,
458 const wxDataViewItem
& item2
,
459 unsigned int WXUNUSED(column
),
460 bool ascending
) const
464 unsigned int pos1
= wxPtrToUInt(item1
.GetID()); // -1 not needed here
465 unsigned int pos2
= wxPtrToUInt(item2
.GetID()); // -1 not needed here
474 return GetRow(item1
) - GetRow(item2
);
476 return GetRow(item2
) - GetRow(item1
);
479 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
486 return m_hash
.GetCount();
489 // ---------------------------------------------------------
490 // wxDataViewVirtualListModel
491 // ---------------------------------------------------------
495 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size
)
497 m_size
= initial_size
;
500 void wxDataViewVirtualListModel::Reset( unsigned int new_size
)
504 /* wxDataViewModel:: */ Cleared();
507 void wxDataViewVirtualListModel::RowPrepended()
510 wxDataViewItem
item( wxUIntToPtr(1) );
511 ItemAdded( wxDataViewItem(0), item
);
514 void wxDataViewVirtualListModel::RowInserted( unsigned int before
)
517 wxDataViewItem
item( wxUIntToPtr(before
+1) );
518 ItemAdded( wxDataViewItem(0), item
);
521 void wxDataViewVirtualListModel::RowAppended()
524 wxDataViewItem
item( wxUIntToPtr(m_size
) );
525 ItemAdded( wxDataViewItem(0), item
);
528 void wxDataViewVirtualListModel::RowDeleted( unsigned int row
)
531 wxDataViewItem
item( wxUIntToPtr(row
+1) );
532 /* wxDataViewModel:: */ ItemDeleted( wxDataViewItem(0), item
);
535 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt
&rows
)
537 m_size
-= rows
.GetCount();
539 wxArrayInt sorted
= rows
;
540 sorted
.Sort( my_sort
);
542 wxDataViewItemArray array
;
544 for (i
= 0; i
< sorted
.GetCount(); i
++)
546 wxDataViewItem
item( wxUIntToPtr(sorted
[i
]+1) );
549 /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array
);
552 void wxDataViewVirtualListModel::RowChanged( unsigned int row
)
554 /* wxDataViewModel:: */ ItemChanged( GetItem(row
) );
557 void wxDataViewVirtualListModel::RowValueChanged( unsigned int row
, unsigned int col
)
559 /* wxDataViewModel:: */ ValueChanged( GetItem(row
), col
);
562 unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem
&item
) const
564 return wxPtrToUInt( item
.GetID() ) -1;
567 wxDataViewItem
wxDataViewVirtualListModel::GetItem( unsigned int row
) const
569 return wxDataViewItem( wxUIntToPtr(row
+1) );
572 bool wxDataViewVirtualListModel::HasDefaultCompare() const
577 int wxDataViewVirtualListModel::Compare(const wxDataViewItem
& item1
,
578 const wxDataViewItem
& item2
,
579 unsigned int WXUNUSED(column
),
580 bool ascending
) const
582 unsigned int pos1
= wxPtrToUInt(item1
.GetID()); // -1 not needed here
583 unsigned int pos2
= wxPtrToUInt(item2
.GetID()); // -1 not needed here
591 unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem
&WXUNUSED(item
), wxDataViewItemArray
&WXUNUSED(children
) ) const
593 return 0; // should we report an error ?
598 //-----------------------------------------------------------------------------
599 // wxDataViewIconText
600 //-----------------------------------------------------------------------------
602 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
604 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
606 // ---------------------------------------------------------
607 // wxDataViewRendererBase
608 // ---------------------------------------------------------
610 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
612 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
613 wxDataViewCellMode
WXUNUSED(mode
),
614 int WXUNUSED(align
) )
616 m_variantType
= varianttype
;
620 wxDataViewRendererBase::~wxDataViewRendererBase()
624 const wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
626 return const_cast<wxDataViewRendererBase
*>(this)->GetOwner()->GetOwner();
629 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
631 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
633 // Before doing anything we send an event asking if editing of this item is really wanted.
634 wxDataViewEvent
start_event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv_ctrl
->GetId() );
635 start_event
.SetDataViewColumn( GetOwner() );
636 start_event
.SetModel( dv_ctrl
->GetModel() );
637 start_event
.SetItem( item
);
638 start_event
.SetEventObject( dv_ctrl
);
639 dv_ctrl
->GetEventHandler()->ProcessEvent( start_event
);
640 if( !start_event
.IsAllowed() )
643 m_item
= item
; // remember for later
645 unsigned int col
= GetOwner()->GetModelColumn();
647 dv_ctrl
->GetModel()->GetValue( value
, item
, col
);
649 m_editorCtrl
= CreateEditorCtrl( dv_ctrl
->GetMainWindow(), labelRect
, value
);
651 // there might be no editor control for the given item
655 wxDataViewEditorCtrlEvtHandler
*handler
=
656 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
658 m_editorCtrl
->PushEventHandler( handler
);
660 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
661 handler
->SetFocusOnIdle();
663 m_editorCtrl
->SetFocus();
666 // Now we should send Editing Started event
667 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv_ctrl
->GetId() );
668 event
.SetDataViewColumn( GetOwner() );
669 event
.SetModel( dv_ctrl
->GetModel() );
670 event
.SetItem( item
);
671 event
.SetEventObject( dv_ctrl
);
672 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
677 void wxDataViewRendererBase::DestroyEditControl()
679 // Hide the control immediately but don't delete it yet as there could be
680 // some pending messages for it.
681 m_editorCtrl
->Hide();
683 wxEvtHandler
* const handler
= m_editorCtrl
->PopEventHandler();
685 wxPendingDelete
.Append(handler
);
686 wxPendingDelete
.Append(m_editorCtrl
);
689 void wxDataViewRendererBase::CancelEditing()
694 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
696 DestroyEditControl();
699 bool wxDataViewRendererBase::FinishEditing()
705 GetValueFromEditorCtrl( m_editorCtrl
, value
);
707 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
709 dv_ctrl
->GetMainWindow()->SetFocus();
711 DestroyEditControl();
713 if (!Validate(value
))
716 unsigned int col
= GetOwner()->GetModelColumn();
717 dv_ctrl
->GetModel()->ChangeValue(value
, m_item
, col
);
719 // Now we should send Editing Done event
720 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv_ctrl
->GetId() );
721 event
.SetDataViewColumn( GetOwner() );
722 event
.SetModel( dv_ctrl
->GetModel() );
723 event
.SetItem( m_item
);
724 event
.SetEventObject( dv_ctrl
);
725 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
730 // ----------------------------------------------------------------------------
731 // wxDataViewCustomRendererBase
732 // ----------------------------------------------------------------------------
735 wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell
, wxDC
*dc
, int state
)
737 wxCHECK_RET( dc
, "no DC to draw on in custom renderer?" );
739 // adjust the rectangle ourselves to account for the alignment
740 wxRect rectItem
= rectCell
;
741 const int align
= GetAlignment();
742 if ( align
!= wxDVR_DEFAULT_ALIGNMENT
)
744 const wxSize size
= GetSize();
746 // take alignment into account only if there is enough space, otherwise
747 // show as much contents as possible
749 // notice that many existing renderers (e.g. wxDataViewSpinRenderer)
750 // return hard-coded size which can be more than they need and if we
751 // trusted their GetSize() we'd draw the text out of cell bounds
754 if ( size
.x
>= 0 && size
.x
< rectCell
.width
)
756 if ( align
& wxALIGN_CENTER_HORIZONTAL
)
757 rectItem
.x
+= (rectCell
.width
- size
.x
)/2;
758 else if ( align
& wxALIGN_RIGHT
)
759 rectItem
.x
+= rectCell
.width
- size
.x
;
760 // else: wxALIGN_LEFT is the default
762 rectItem
.width
= size
.x
;
765 if ( size
.y
>= 0 && size
.y
< rectCell
.height
)
767 if ( align
& wxALIGN_CENTER_VERTICAL
)
768 rectItem
.y
+= (rectCell
.height
- size
.y
)/2;
769 else if ( align
& wxALIGN_BOTTOM
)
770 rectItem
.y
+= rectCell
.height
- size
.y
;
771 // else: wxALIGN_TOP is the default
773 rectItem
.height
= size
.y
;
778 // set up the DC attributes
780 // override custom foreground with the standard one for the selected items
781 // because we currently don't allow changing the selection background and
782 // custom colours may be unreadable on it
784 if ( state
& wxDATAVIEW_CELL_SELECTED
)
785 col
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
786 else if ( m_attr
.HasColour() )
787 col
= m_attr
.GetColour();
788 else // use default foreground
789 col
= GetOwner()->GetOwner()->GetForegroundColour();
791 wxDCTextColourChanger
changeFg(*dc
, col
);
793 wxDCFontChanger
changeFont(*dc
);
794 if ( m_attr
.HasFont() )
796 wxFont
font(dc
->GetFont());
797 if ( m_attr
.GetBold() )
799 if ( m_attr
.GetItalic() )
802 changeFont
.Set(font
);
805 Render(rectItem
, dc
, state
);
809 wxDataViewCustomRendererBase::RenderText(const wxString
& text
,
815 wxRect rectText
= rect
;
816 rectText
.x
+= xoffset
;
817 rectText
.width
-= xoffset
;
819 // check if we want to ellipsize the text if it doesn't fit
820 wxString ellipsizedText
;
821 if ( GetEllipsizeMode() != wxELLIPSIZE_NONE
)
823 ellipsizedText
= wxControl::Ellipsize
829 wxELLIPSIZE_FLAGS_NONE
833 // get the alignment to use
834 int align
= GetAlignment();
835 if ( align
== wxDVR_DEFAULT_ALIGNMENT
)
837 // if we don't have an explicit alignment ourselves, use that of the
838 // column in horizontal direction and default vertical alignment
839 align
= GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
842 dc
->DrawLabel(ellipsizedText
.empty() ? text
: ellipsizedText
,
846 //-----------------------------------------------------------------------------
847 // wxDataViewEditorCtrlEvtHandler
848 //-----------------------------------------------------------------------------
850 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
851 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
852 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
853 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
854 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
857 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
861 m_focusOnIdle
= false;
862 if (wxWindow::FindFocus() != m_editorCtrl
)
863 m_editorCtrl
->SetFocus();
869 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
872 m_owner
->FinishEditing();
875 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
877 switch ( event
.m_keyCode
)
881 m_owner
->FinishEditing();
887 m_owner
->CancelEditing();
895 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
900 m_owner
->FinishEditing();
906 // ---------------------------------------------------------
907 // wxDataViewColumnBase
908 // ---------------------------------------------------------
910 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
911 unsigned int model_column
)
913 m_renderer
= renderer
;
914 m_model_column
= model_column
;
916 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
919 wxDataViewColumnBase::~wxDataViewColumnBase()
924 // ---------------------------------------------------------
925 // wxDataViewCtrlBase
926 // ---------------------------------------------------------
928 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
930 wxDataViewCtrlBase::wxDataViewCtrlBase()
933 m_expander_column
= 0;
937 wxDataViewCtrlBase::~wxDataViewCtrlBase()
946 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
950 m_model
->DecRef(); // discard old model, if any
953 // add our own reference to the new model:
963 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
968 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
973 void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem
& item
)
975 if (!m_model
) return;
977 if (!item
.IsOk()) return;
979 wxVector
<wxDataViewItem
> parentChain
;
981 // at first we get all the parents of the selected item
982 wxDataViewItem parent
= m_model
->GetParent(item
);
983 while (parent
.IsOk())
985 parentChain
.push_back(parent
);
986 parent
= m_model
->GetParent(parent
);
989 // then we expand the parents, starting at the root
990 while (!parentChain
.empty())
992 Expand(parentChain
.back());
993 parentChain
.pop_back();
998 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
999 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1001 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1002 new wxDataViewTextRenderer( wxT("string"), mode
),
1003 model_column
, width
, align
, flags
);
1004 AppendColumn( ret
);
1009 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
1010 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1012 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1013 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1014 model_column
, width
, align
, flags
);
1015 AppendColumn( ret
);
1020 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
1021 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1023 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1024 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1025 model_column
, width
, align
, flags
);
1026 AppendColumn( ret
);
1031 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
1032 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1034 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1035 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1036 model_column
, width
, align
, flags
);
1037 AppendColumn( ret
);
1042 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
1043 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1045 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1046 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1047 model_column
, width
, align
, flags
);
1048 AppendColumn( ret
);
1053 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
1054 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1056 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1057 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1058 model_column
, width
, align
, flags
);
1059 AppendColumn( ret
);
1064 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1065 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1067 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1068 new wxDataViewTextRenderer( wxT("string"), mode
),
1069 model_column
, width
, align
, flags
);
1070 AppendColumn( ret
);
1075 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1076 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1078 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1079 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1080 model_column
, width
, align
, flags
);
1081 AppendColumn( ret
);
1086 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1087 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1089 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1090 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1091 model_column
, width
, align
, flags
);
1092 AppendColumn( ret
);
1097 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1098 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1100 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1101 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1102 model_column
, width
, align
, flags
);
1103 AppendColumn( ret
);
1108 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1109 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1111 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1112 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1113 model_column
, width
, align
, flags
);
1114 AppendColumn( ret
);
1119 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1120 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1122 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1123 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1124 model_column
, width
, align
, flags
);
1125 AppendColumn( ret
);
1130 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1131 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1133 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1134 new wxDataViewTextRenderer( wxT("string"), mode
),
1135 model_column
, width
, align
, flags
);
1136 PrependColumn( ret
);
1141 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1142 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1144 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1145 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1146 model_column
, width
, align
, flags
);
1147 PrependColumn( ret
);
1152 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1153 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1156 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1157 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1158 model_column
, width
, align
, flags
);
1159 PrependColumn( ret
);
1164 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1165 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1167 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1168 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1169 model_column
, width
, align
, flags
);
1170 PrependColumn( ret
);
1175 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1176 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1178 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1179 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1180 model_column
, width
, align
, flags
);
1181 PrependColumn( ret
);
1186 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1187 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1189 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1190 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1191 model_column
, width
, align
, flags
);
1192 PrependColumn( ret
);
1197 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1198 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1200 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1201 new wxDataViewTextRenderer( wxT("string"), mode
),
1202 model_column
, width
, align
, flags
);
1203 PrependColumn( ret
);
1208 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1209 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1211 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1212 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1213 model_column
, width
, align
, flags
);
1214 PrependColumn( ret
);
1219 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1220 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1222 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1223 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1224 model_column
, width
, align
, flags
);
1225 PrependColumn( ret
);
1230 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1231 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1233 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1234 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1235 model_column
, width
, align
, flags
);
1236 PrependColumn( ret
);
1241 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1242 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1244 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1245 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1246 model_column
, width
, align
, flags
);
1247 PrependColumn( ret
);
1252 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1253 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1255 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1256 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1257 model_column
, width
, align
, flags
);
1258 PrependColumn( ret
);
1263 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1265 col
->SetOwner( (wxDataViewCtrl
*) this );
1270 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1272 col
->SetOwner( (wxDataViewCtrl
*) this );
1277 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1279 col
->SetOwner( (wxDataViewCtrl
*) this );
1283 // ---------------------------------------------------------
1285 // ---------------------------------------------------------
1287 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1289 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
);
1291 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
);
1292 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
);
1293 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
);
1294 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
);
1295 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
);
1296 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
);
1297 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, wxDataViewEvent
);
1298 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
);
1299 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
);
1301 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
);
1303 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
);
1304 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
);
1305 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
);
1306 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
);
1308 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, wxDataViewEvent
);
1310 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
);
1311 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, wxDataViewEvent
);
1312 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, wxDataViewEvent
);
1316 // -------------------------------------
1317 // wxDataViewSpinRenderer
1318 // -------------------------------------
1320 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1321 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1327 wxControl
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1330 wxSize size
= labelRect
.GetSize();
1332 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1335 str
.Printf( wxT("%d"), (int) l
);
1336 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1337 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1339 size
= sc
->GetSize();
1340 wxPoint pt
= sc
->GetPosition();
1341 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1347 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1349 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1350 long l
= sc
->GetValue();
1355 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1358 str
.Printf(wxT("%d"), (int) m_data
);
1359 RenderText( str
, 0, rect
, dc
, state
);
1363 wxSize
wxDataViewSpinRenderer::GetSize() const
1365 return wxSize(80,16);
1368 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1370 m_data
= value
.GetLong();
1374 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1380 // -------------------------------------
1381 // wxDataViewChoiceRenderer
1382 // -------------------------------------
1384 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
1386 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1387 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1389 m_choices
= choices
;
1392 wxControl
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1395 wxSize size
= labelRect
.GetSize();
1397 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1399 wxChoice
*c
= new wxChoice( parent
, wxID_ANY
, labelRect
.GetTopLeft(), size
, m_choices
);
1400 c
->SetStringSelection( value
.GetString() );
1405 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1407 wxChoice
*c
= (wxChoice
*) editor
;
1408 wxString s
= c
->GetStringSelection();
1413 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1415 RenderText( m_data
, 0, rect
, dc
, state
);
1419 wxSize
wxDataViewChoiceRenderer::GetSize() const
1421 return wxSize(80,16);
1424 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1426 m_data
= value
.GetString();
1430 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1436 // ----------------------------------------------------------------------------
1437 // wxDataViewChoiceByIndexRenderer
1438 // ----------------------------------------------------------------------------
1440 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
1441 wxDataViewCellMode mode
, int alignment
) :
1442 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
1446 wxControl
* wxDataViewChoiceByIndexRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1448 wxVariant string_value
= GetChoice( value
.GetLong() );
1450 return wxDataViewChoiceRenderer::CreateEditorCtrl( parent
, labelRect
, string_value
);
1453 bool wxDataViewChoiceByIndexRenderer::GetValueFromEditorCtrl( wxControl
* editor
, wxVariant
&value
)
1455 wxVariant string_value
;
1456 if (!wxDataViewChoiceRenderer::GetValueFromEditorCtrl( editor
, string_value
))
1459 value
= (long) GetChoices().Index( string_value
.GetString() );
1463 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
1465 wxVariant string_value
= GetChoice( value
.GetLong() );
1466 return wxDataViewChoiceRenderer::SetValue( string_value
);
1469 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
1471 wxVariant string_value
;
1472 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
1475 value
= (long) GetChoices().Index( string_value
.GetString() );
1481 //-----------------------------------------------------------------------------
1482 // wxDataViewListStore
1483 //-----------------------------------------------------------------------------
1485 wxDataViewListStore::wxDataViewListStore()
1489 wxDataViewListStore::~wxDataViewListStore()
1491 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1492 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1494 wxDataViewListStoreLine
* line
= *it
;
1499 void wxDataViewListStore::PrependColumn( const wxString
&varianttype
)
1501 m_cols
.Insert( varianttype
, 0 );
1504 void wxDataViewListStore::InsertColumn( unsigned int pos
, const wxString
&varianttype
)
1506 m_cols
.Insert( varianttype
, pos
);
1509 void wxDataViewListStore::AppendColumn( const wxString
&varianttype
)
1511 m_cols
.Add( varianttype
);
1514 unsigned int wxDataViewListStore::GetColumnCount() const
1516 return m_cols
.GetCount();
1519 wxString
wxDataViewListStore::GetColumnType( unsigned int pos
) const
1524 void wxDataViewListStore::AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1526 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1527 line
->m_values
= values
;
1528 m_data
.push_back( line
);
1533 void wxDataViewListStore::PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1535 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1536 line
->m_values
= values
;
1537 m_data
.insert( m_data
.begin(), line
);
1542 void wxDataViewListStore::InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
,
1543 wxClientData
*data
)
1545 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1546 line
->m_values
= values
;
1547 m_data
.insert( m_data
.begin()+row
, line
);
1552 void wxDataViewListStore::DeleteItem( unsigned int row
)
1554 wxVector
<wxDataViewListStoreLine
*>::iterator it
= m_data
.begin() + row
;
1561 void wxDataViewListStore::DeleteAllItems()
1563 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1564 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1566 wxDataViewListStoreLine
* line
= *it
;
1575 void wxDataViewListStore::GetValueByRow( wxVariant
&value
, unsigned int row
, unsigned int col
) const
1577 wxDataViewListStoreLine
*line
= m_data
[row
];
1578 value
= line
->m_values
[col
];
1581 bool wxDataViewListStore::SetValueByRow( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1583 wxDataViewListStoreLine
*line
= m_data
[row
];
1584 line
->m_values
[col
] = value
;
1589 //-----------------------------------------------------------------------------
1590 // wxDataViewListCtrl
1591 //-----------------------------------------------------------------------------
1593 IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl
,wxDataViewCtrl
)
1595 BEGIN_EVENT_TABLE(wxDataViewListCtrl
,wxDataViewCtrl
)
1596 EVT_SIZE( wxDataViewListCtrl::OnSize
)
1599 wxDataViewListCtrl::wxDataViewListCtrl()
1603 wxDataViewListCtrl::wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
1604 const wxPoint
& pos
, const wxSize
& size
, long style
,
1605 const wxValidator
& validator
)
1607 Create( parent
, id
, pos
, size
, style
, validator
);
1609 wxDataViewListStore
*store
= new wxDataViewListStore
;
1610 AssociateModel( store
);
1614 wxDataViewListCtrl::~wxDataViewListCtrl()
1619 bool wxDataViewListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1620 const wxPoint
& pos
, const wxSize
& size
, long style
,
1621 const wxValidator
& validator
)
1623 return wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
);
1626 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1628 GetStore()->AppendColumn( varianttype
);
1629 return wxDataViewCtrl::AppendColumn( column
);
1632 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1634 GetStore()->PrependColumn( varianttype
);
1635 return wxDataViewCtrl::PrependColumn( column
);
1638 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
)
1640 GetStore()->InsertColumn( pos
, varianttype
);
1641 return wxDataViewCtrl::InsertColumn( pos
, column
);
1644 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*col
)
1646 return PrependColumn( col
, "string" );
1649 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
1651 return InsertColumn( pos
, col
, "string" );
1654 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*col
)
1656 return AppendColumn( col
, "string" );
1659 wxDataViewColumn
*wxDataViewListCtrl::AppendTextColumn( const wxString
&label
,
1660 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1662 GetStore()->AppendColumn( wxT("string") );
1664 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1665 new wxDataViewTextRenderer( wxT("string"), mode
),
1666 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1668 wxDataViewCtrl::AppendColumn( ret
);
1673 wxDataViewColumn
*wxDataViewListCtrl::AppendToggleColumn( const wxString
&label
,
1674 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1676 GetStore()->AppendColumn( wxT("bool") );
1678 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1679 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1680 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1682 wxDataViewCtrl::AppendColumn( ret
);
1687 wxDataViewColumn
*wxDataViewListCtrl::AppendProgressColumn( const wxString
&label
,
1688 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1690 GetStore()->AppendColumn( wxT("long") );
1692 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1693 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1694 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1696 wxDataViewCtrl::AppendColumn( ret
);
1701 wxDataViewColumn
*wxDataViewListCtrl::AppendIconTextColumn( const wxString
&label
,
1702 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1704 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
1706 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1707 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1708 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1710 wxDataViewCtrl::AppendColumn( ret
);
1715 void wxDataViewListCtrl::OnSize( wxSizeEvent
&event
)
1720 //-----------------------------------------------------------------------------
1721 // wxDataViewTreeStore
1722 //-----------------------------------------------------------------------------
1724 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1725 wxDataViewTreeStoreNode
*parent
,
1726 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1734 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1740 #include "wx/listimpl.cpp"
1741 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1743 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1744 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1745 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1746 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1748 m_iconExpanded
= expanded
;
1749 m_isExpanded
= false;
1750 m_children
.DeleteContents(true);
1753 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1757 //-----------------------------------------------------------------------------
1759 wxDataViewTreeStore::wxDataViewTreeStore()
1761 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1764 wxDataViewTreeStore::~wxDataViewTreeStore()
1769 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1770 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1772 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1773 if (!parent_node
) return wxDataViewItem(0);
1775 wxDataViewTreeStoreNode
*node
=
1776 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1777 parent_node
->GetChildren().Append( node
);
1779 return node
->GetItem();
1782 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1783 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1785 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1786 if (!parent_node
) return wxDataViewItem(0);
1788 wxDataViewTreeStoreNode
*node
=
1789 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1790 parent_node
->GetChildren().Insert( node
);
1792 return node
->GetItem();
1796 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& parent
,
1797 const wxDataViewItem
& previous
,
1798 const wxString
& text
,
1802 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1803 if (!parent_node
) return wxDataViewItem(0);
1805 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1806 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1807 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1809 wxDataViewTreeStoreNode
*node
=
1810 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1811 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1813 return node
->GetItem();
1816 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
1817 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
1818 wxClientData
*data
)
1820 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1821 if (!parent_node
) return wxDataViewItem(0);
1823 wxDataViewTreeStoreContainerNode
*node
=
1824 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1825 parent_node
->GetChildren().Insert( node
);
1827 return node
->GetItem();
1831 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
1832 const wxString
&text
,
1834 const wxIcon
& expanded
,
1835 wxClientData
* data
)
1837 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1838 if (!parent_node
) return wxDataViewItem(0);
1840 wxDataViewTreeStoreContainerNode
*node
=
1841 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1842 parent_node
->GetChildren().Append( node
);
1844 return node
->GetItem();
1848 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& parent
,
1849 const wxDataViewItem
& previous
,
1850 const wxString
& text
,
1852 const wxIcon
& expanded
,
1853 wxClientData
* data
)
1855 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1856 if (!parent_node
) return wxDataViewItem(0);
1858 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
1859 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
1860 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
1862 wxDataViewTreeStoreContainerNode
*node
=
1863 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
1864 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
1866 return node
->GetItem();
1869 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
& item
) const
1871 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1872 if (!node
) return false;
1874 return node
->IsContainer();
1877 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
1879 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1880 if (!parent_node
) return wxDataViewItem(0);
1882 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
1884 return node
->GetData();
1886 return wxDataViewItem(0);
1889 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
1891 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
1892 if (!node
) return -1;
1894 if (!node
->IsContainer())
1897 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
1898 return (int) container_node
->GetChildren().GetCount();
1901 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
1903 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1906 node
->SetText( text
);
1909 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
1911 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1912 if (!node
) return wxEmptyString
;
1914 return node
->GetText();
1917 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1919 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1922 node
->SetIcon( icon
);
1925 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
1927 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1928 if (!node
) return wxNullIcon
;
1930 return node
->GetIcon();
1933 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
1935 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1938 node
->SetExpandedIcon( icon
);
1941 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
1943 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1944 if (!node
) return wxNullIcon
;
1946 return node
->GetExpandedIcon();
1949 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
1951 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1954 node
->SetData( data
);
1957 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
1959 wxDataViewTreeStoreNode
*node
= FindNode( item
);
1960 if (!node
) return NULL
;
1962 return node
->GetData();
1965 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
1967 if (!item
.IsOk()) return;
1969 wxDataViewItem parent_item
= GetParent( item
);
1971 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
1972 if (!parent_node
) return;
1974 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1977 parent_node
->GetChildren().DeleteObject( node
);
1980 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
1982 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
1985 node
->GetChildren().clear();
1988 void wxDataViewTreeStore::DeleteAllItems()
1990 DeleteChildren(m_root
);
1994 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
1995 const wxDataViewItem
&item
,
1996 unsigned int WXUNUSED(col
)) const
1998 // if (col != 0) return;
2000 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2003 wxIcon
icon( node
->GetIcon());
2004 if (node
->IsContainer())
2006 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
2007 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
2008 icon
= container
->GetExpandedIcon();
2011 wxDataViewIconText
data( node
->GetText(), icon
);
2017 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
2018 const wxDataViewItem
& item
,
2019 unsigned int WXUNUSED(col
))
2021 // if (col != 0) return false;
2023 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2024 if (!node
) return false;
2026 wxDataViewIconText data
;
2030 node
->SetText( data
.GetText() );
2031 node
->SetIcon( data
.GetIcon() );
2036 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
2038 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2039 if (!node
) return wxDataViewItem(0);
2041 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
2042 if (!parent
) return wxDataViewItem(0);
2044 if (parent
== m_root
)
2045 return wxDataViewItem(0);
2047 return parent
->GetItem();
2050 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
2052 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2053 if (!node
) return 0;
2055 wxDataViewTreeStoreNodeList::iterator iter
;
2056 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2058 wxDataViewTreeStoreNode
* child
= *iter
;
2059 children
.Add( child
->GetItem() );
2062 return node
->GetChildren().GetCount();
2065 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
2066 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) ) const
2068 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
2069 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
2071 if (!node1
|| !node2
)
2074 wxDataViewTreeStoreContainerNode
* parent1
=
2075 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
2076 wxDataViewTreeStoreContainerNode
* parent2
=
2077 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
2079 if (parent1
!= parent2
)
2081 wxLogError( wxT("Comparing items with different parent.") );
2085 if (node1
->IsContainer() && !node2
->IsContainer())
2088 if (node2
->IsContainer() && !node1
->IsContainer())
2091 return parent1
->GetChildren().IndexOf( node1
) - parent2
->GetChildren().IndexOf( node2
);
2094 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
2099 return (wxDataViewTreeStoreNode
*) item
.GetID();
2102 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
2105 return (wxDataViewTreeStoreContainerNode
*) m_root
;
2107 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
2109 if (!node
->IsContainer())
2112 return (wxDataViewTreeStoreContainerNode
*) node
;
2115 //-----------------------------------------------------------------------------
2116 // wxDataViewTreeCtrl
2117 //-----------------------------------------------------------------------------
2119 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2121 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2122 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
2123 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
2124 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
2127 wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
2132 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2133 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2135 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
2138 // create the standard model and a column in the tree
2139 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
2140 AssociateModel( store
);
2143 AppendIconTextColumn
2145 wxString(), // no label (header is not shown anyhow)
2146 0, // the only model column
2147 wxDATAVIEW_CELL_EDITABLE
,
2148 -1, // default width
2149 wxALIGN_NOT
, // and alignment
2156 void wxDataViewTreeCtrl::SetImageList( wxImageList
*imagelist
)
2160 m_imageList
= imagelist
;
2163 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
2164 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2166 wxIcon icon
= wxNullIcon
;
2167 if (m_imageList
&& (iconIndex
!= -1))
2168 icon
= m_imageList
->GetIcon( iconIndex
);
2170 wxDataViewItem res
= GetStore()->AppendItem( parent
, text
, icon
, data
);
2172 GetStore()->ItemAdded( parent
, res
);
2177 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
2178 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2180 wxIcon icon
= wxNullIcon
;
2181 if (m_imageList
&& (iconIndex
!= -1))
2182 icon
= m_imageList
->GetIcon( iconIndex
);
2184 wxDataViewItem res
= GetStore()->PrependItem( parent
, text
, icon
, data
);
2186 GetStore()->ItemAdded( parent
, res
);
2191 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2192 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2194 wxIcon icon
= wxNullIcon
;
2195 if (m_imageList
&& (iconIndex
!= -1))
2196 icon
= m_imageList
->GetIcon( iconIndex
);
2198 wxDataViewItem res
= GetStore()->InsertItem( parent
, previous
, text
, icon
, data
);
2200 GetStore()->ItemAdded( parent
, res
);
2205 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
2206 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2208 wxIcon icon
= wxNullIcon
;
2209 if (m_imageList
&& (iconIndex
!= -1))
2210 icon
= m_imageList
->GetIcon( iconIndex
);
2212 wxIcon expanded
= wxNullIcon
;
2213 if (m_imageList
&& (expandedIndex
!= -1))
2214 expanded
= m_imageList
->GetIcon( expandedIndex
);
2216 wxDataViewItem res
= GetStore()->PrependContainer( parent
, text
, icon
, expanded
, data
);
2218 GetStore()->ItemAdded( parent
, res
);
2223 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
2224 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2226 wxIcon icon
= wxNullIcon
;
2227 if (m_imageList
&& (iconIndex
!= -1))
2228 icon
= m_imageList
->GetIcon( iconIndex
);
2230 wxIcon expanded
= wxNullIcon
;
2231 if (m_imageList
&& (expandedIndex
!= -1))
2232 expanded
= m_imageList
->GetIcon( expandedIndex
);
2234 wxDataViewItem res
= GetStore()->AppendContainer( parent
, text
, icon
, expanded
, data
);
2236 GetStore()->ItemAdded( parent
, res
);
2241 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2242 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2244 wxIcon icon
= wxNullIcon
;
2245 if (m_imageList
&& (iconIndex
!= -1))
2246 icon
= m_imageList
->GetIcon( iconIndex
);
2248 wxIcon expanded
= wxNullIcon
;
2249 if (m_imageList
&& (expandedIndex
!= -1))
2250 expanded
= m_imageList
->GetIcon( expandedIndex
);
2252 wxDataViewItem res
= GetStore()->InsertContainer( parent
, previous
, text
, icon
, expanded
, data
);
2254 GetStore()->ItemAdded( parent
, res
);
2259 void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2261 GetStore()->SetItemText(item
,text
);
2264 GetStore()->ValueChanged( item
, 0 );
2267 void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2269 GetStore()->SetItemIcon(item
,icon
);
2272 GetStore()->ValueChanged( item
, 0 );
2275 void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2277 GetStore()->SetItemExpandedIcon(item
,icon
);
2280 GetStore()->ValueChanged( item
, 0 );
2283 void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem
& item
)
2285 wxDataViewItem parent_item
= GetStore()->GetParent( item
);
2287 GetStore()->DeleteItem(item
);
2290 GetStore()->ItemDeleted( parent_item
, item
);
2293 void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem
& item
)
2295 wxDataViewTreeStoreContainerNode
*node
= GetStore()->FindContainerNode( item
);
2298 wxDataViewItemArray array
;
2299 wxDataViewTreeStoreNodeList::iterator iter
;
2300 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2302 wxDataViewTreeStoreNode
* child
= *iter
;
2303 array
.Add( child
->GetItem() );
2306 GetStore()->DeleteChildren( item
);
2309 GetStore()->ItemsDeleted( item
, array
);
2312 void wxDataViewTreeCtrl::DeleteAllItems()
2314 GetStore()->DeleteAllItems();
2316 GetStore()->Cleared();
2319 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
2321 if (m_imageList
) return;
2323 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2324 if (!container
) return;
2326 container
->SetExpanded( true );
2328 GetStore()->ItemChanged( event
.GetItem() );
2331 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
2333 if (m_imageList
) return;
2335 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2336 if (!container
) return;
2338 container
->SetExpanded( false );
2340 GetStore()->ItemChanged( event
.GetItem() );
2343 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
2345 #if defined(wxUSE_GENERICDATAVIEWCTRL)
2346 // automatically resize our only column to take the entire control width
2347 if ( GetColumnCount() )
2349 wxSize size
= GetClientSize();
2350 GetColumn(0)->SetWidth(size
.x
);
2356 #endif // wxUSE_DATAVIEWCTRL