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/datectrl.h"
30 #include "wx/spinctrl.h"
31 #include "wx/choice.h"
32 #include "wx/imaglist.h"
34 const char wxDataViewCtrlNameStr
[] = "dataviewCtrl";
39 // Custom handler pushed on top of the edit control used by wxDataViewCtrl to
40 // forward some events to the main control itself.
41 class wxDataViewEditorCtrlEvtHandler
: public wxEvtHandler
44 wxDataViewEditorCtrlEvtHandler(wxWindow
*editor
, wxDataViewRenderer
*owner
)
46 m_editorCtrl
= editor
;
52 void AcceptChangesAndFinish();
53 void SetFocusOnIdle( bool focus
= true ) { m_focusOnIdle
= focus
; }
56 void OnChar( wxKeyEvent
&event
);
57 void OnTextEnter( wxCommandEvent
&event
);
58 void OnKillFocus( wxFocusEvent
&event
);
59 void OnIdle( wxIdleEvent
&event
);
62 wxDataViewRenderer
*m_owner
;
63 wxWindow
*m_editorCtrl
;
71 } // anonymous namespace
73 // ---------------------------------------------------------
75 // ---------------------------------------------------------
77 wxFont
wxDataViewItemAttr::GetEffectiveFont(const wxFont
& font
) const
91 // ---------------------------------------------------------
92 // wxDataViewModelNotifier
93 // ---------------------------------------------------------
95 #include "wx/listimpl.cpp"
96 WX_DEFINE_LIST(wxDataViewModelNotifiers
)
98 bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
100 size_t count
= items
.GetCount();
102 for (i
= 0; i
< count
; i
++)
103 if (!ItemAdded( parent
, items
[i
] )) return false;
108 bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
110 size_t count
= items
.GetCount();
112 for (i
= 0; i
< count
; i
++)
113 if (!ItemDeleted( parent
, items
[i
] )) return false;
118 bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray
&items
)
120 size_t count
= items
.GetCount();
122 for (i
= 0; i
< count
; i
++)
123 if (!ItemChanged( items
[i
] )) return false;
128 // ---------------------------------------------------------
130 // ---------------------------------------------------------
132 wxDataViewModel::wxDataViewModel()
134 m_notifiers
.DeleteContents( true );
137 bool wxDataViewModel::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
141 wxDataViewModelNotifiers::iterator iter
;
142 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
144 wxDataViewModelNotifier
* notifier
= *iter
;
145 if (!notifier
->ItemAdded( parent
, item
))
152 bool wxDataViewModel::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
156 wxDataViewModelNotifiers::iterator iter
;
157 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
159 wxDataViewModelNotifier
* notifier
= *iter
;
160 if (!notifier
->ItemDeleted( parent
, item
))
167 bool wxDataViewModel::ItemChanged( const wxDataViewItem
&item
)
171 wxDataViewModelNotifiers::iterator iter
;
172 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
174 wxDataViewModelNotifier
* notifier
= *iter
;
175 if (!notifier
->ItemChanged( item
))
182 bool wxDataViewModel::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
186 wxDataViewModelNotifiers::iterator iter
;
187 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
189 wxDataViewModelNotifier
* notifier
= *iter
;
190 if (!notifier
->ItemsAdded( parent
, items
))
197 bool wxDataViewModel::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
201 wxDataViewModelNotifiers::iterator iter
;
202 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
204 wxDataViewModelNotifier
* notifier
= *iter
;
205 if (!notifier
->ItemsDeleted( parent
, items
))
212 bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray
&items
)
216 wxDataViewModelNotifiers::iterator iter
;
217 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
219 wxDataViewModelNotifier
* notifier
= *iter
;
220 if (!notifier
->ItemsChanged( items
))
227 bool wxDataViewModel::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
231 wxDataViewModelNotifiers::iterator iter
;
232 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
234 wxDataViewModelNotifier
* notifier
= *iter
;
235 if (!notifier
->ValueChanged( item
, col
))
242 bool wxDataViewModel::Cleared()
246 wxDataViewModelNotifiers::iterator iter
;
247 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
249 wxDataViewModelNotifier
* notifier
= *iter
;
250 if (!notifier
->Cleared())
257 bool wxDataViewModel::BeforeReset()
261 wxDataViewModelNotifiers::iterator iter
;
262 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
264 wxDataViewModelNotifier
* notifier
= *iter
;
265 if (!notifier
->BeforeReset())
272 bool wxDataViewModel::AfterReset()
276 wxDataViewModelNotifiers::iterator iter
;
277 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
279 wxDataViewModelNotifier
* notifier
= *iter
;
280 if (!notifier
->AfterReset())
287 void wxDataViewModel::Resort()
289 wxDataViewModelNotifiers::iterator iter
;
290 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
292 wxDataViewModelNotifier
* notifier
= *iter
;
297 void wxDataViewModel::AddNotifier( wxDataViewModelNotifier
*notifier
)
299 m_notifiers
.push_back( notifier
);
300 notifier
->SetOwner( this );
303 void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier
*notifier
)
305 m_notifiers
.DeleteObject( notifier
);
308 int wxDataViewModel::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
309 unsigned int column
, bool ascending
) const
311 wxVariant value1
,value2
;
312 GetValue( value1
, item1
, column
);
313 GetValue( value2
, item2
, column
);
317 wxVariant temp
= value1
;
322 if (value1
.GetType() == wxT("string"))
324 wxString str1
= value1
.GetString();
325 wxString str2
= value2
.GetString();
326 int res
= str1
.Cmp( str2
);
330 else if (value1
.GetType() == wxT("long"))
332 long l1
= value1
.GetLong();
333 long l2
= value2
.GetLong();
338 else if (value1
.GetType() == wxT("double"))
340 double d1
= value1
.GetDouble();
341 double d2
= value2
.GetDouble();
347 else if (value1
.GetType() == wxT("datetime"))
349 wxDateTime dt1
= value1
.GetDateTime();
350 wxDateTime dt2
= value2
.GetDateTime();
351 if (dt1
.IsEarlierThan(dt2
))
353 if (dt2
.IsEarlierThan(dt1
))
357 // items must be different
358 wxUIntPtr id1
= wxPtrToUInt(item1
.GetID()),
359 id2
= wxPtrToUInt(item2
.GetID());
361 return ascending
? id1
- id2
: id2
- id1
;
364 // ---------------------------------------------------------
365 // wxDataViewIndexListModel
366 // ---------------------------------------------------------
368 static int my_sort( int *v1
, int *v2
)
374 wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size
)
376 // IDs are ordered until an item gets deleted or inserted
379 // build initial index
381 for (i
= 1; i
< initial_size
+1; i
++)
382 m_hash
.Add( wxDataViewItem(wxUIntToPtr(i
)) );
383 m_nextFreeID
= initial_size
+ 1;
386 void wxDataViewIndexListModel::Reset( unsigned int new_size
)
388 /* wxDataViewModel:: */ BeforeReset();
392 // IDs are ordered until an item gets deleted or inserted
395 // build initial index
397 for (i
= 1; i
< new_size
+1; i
++)
398 m_hash
.Add( wxDataViewItem(wxUIntToPtr(i
)) );
400 m_nextFreeID
= new_size
+ 1;
402 /* wxDataViewModel:: */ AfterReset();
405 void wxDataViewIndexListModel::RowPrepended()
409 unsigned int id
= m_nextFreeID
;
412 wxDataViewItem
item( wxUIntToPtr(id
) );
413 m_hash
.Insert( item
, 0 );
414 ItemAdded( wxDataViewItem(0), item
);
418 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
422 unsigned int id
= m_nextFreeID
;
425 wxDataViewItem
item( wxUIntToPtr(id
) );
426 m_hash
.Insert( item
, before
);
427 ItemAdded( wxDataViewItem(0), item
);
430 void wxDataViewIndexListModel::RowAppended()
432 unsigned int id
= m_nextFreeID
;
435 wxDataViewItem
item( wxUIntToPtr(id
) );
437 ItemAdded( wxDataViewItem(0), item
);
440 void wxDataViewIndexListModel::RowDeleted( unsigned int row
)
444 wxDataViewItem
item( m_hash
[row
] );
445 m_hash
.RemoveAt( row
);
446 /* wxDataViewModel:: */ ItemDeleted( wxDataViewItem(0), item
);
449 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt
&rows
)
453 wxDataViewItemArray array
;
455 for (i
= 0; i
< rows
.GetCount(); i
++)
457 wxDataViewItem
item( m_hash
[rows
[i
]] );
461 wxArrayInt sorted
= rows
;
462 sorted
.Sort( my_sort
);
463 for (i
= 0; i
< sorted
.GetCount(); i
++)
464 m_hash
.RemoveAt( sorted
[i
] );
466 /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array
);
469 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
471 /* wxDataViewModel:: */ ItemChanged( GetItem(row
) );
474 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
476 /* wxDataViewModel:: */ ValueChanged( GetItem(row
), col
);
479 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
482 return wxPtrToUInt(item
.GetID())-1;
484 // assert for not found
485 return (unsigned int) m_hash
.Index( item
);
488 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
490 wxASSERT( row
< m_hash
.GetCount() );
491 return wxDataViewItem( m_hash
[row
] );
494 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
501 return m_hash
.GetCount();
504 // ---------------------------------------------------------
505 // wxDataViewVirtualListModel
506 // ---------------------------------------------------------
510 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size
)
512 m_size
= initial_size
;
515 void wxDataViewVirtualListModel::Reset( unsigned int new_size
)
517 /* wxDataViewModel:: */ BeforeReset();
521 /* wxDataViewModel:: */ AfterReset();
524 void wxDataViewVirtualListModel::RowPrepended()
527 wxDataViewItem
item( wxUIntToPtr(1) );
528 ItemAdded( wxDataViewItem(0), item
);
531 void wxDataViewVirtualListModel::RowInserted( unsigned int before
)
534 wxDataViewItem
item( wxUIntToPtr(before
+1) );
535 ItemAdded( wxDataViewItem(0), item
);
538 void wxDataViewVirtualListModel::RowAppended()
541 wxDataViewItem
item( wxUIntToPtr(m_size
) );
542 ItemAdded( wxDataViewItem(0), item
);
545 void wxDataViewVirtualListModel::RowDeleted( unsigned int row
)
548 wxDataViewItem
item( wxUIntToPtr(row
+1) );
549 /* wxDataViewModel:: */ ItemDeleted( wxDataViewItem(0), item
);
552 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt
&rows
)
554 m_size
-= rows
.GetCount();
556 wxArrayInt sorted
= rows
;
557 sorted
.Sort( my_sort
);
559 wxDataViewItemArray array
;
561 for (i
= 0; i
< sorted
.GetCount(); i
++)
563 wxDataViewItem
item( wxUIntToPtr(sorted
[i
]+1) );
566 /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array
);
569 void wxDataViewVirtualListModel::RowChanged( unsigned int row
)
571 /* wxDataViewModel:: */ ItemChanged( GetItem(row
) );
574 void wxDataViewVirtualListModel::RowValueChanged( unsigned int row
, unsigned int col
)
576 /* wxDataViewModel:: */ ValueChanged( GetItem(row
), col
);
579 unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem
&item
) const
581 return wxPtrToUInt( item
.GetID() ) -1;
584 wxDataViewItem
wxDataViewVirtualListModel::GetItem( unsigned int row
) const
586 return wxDataViewItem( wxUIntToPtr(row
+1) );
589 bool wxDataViewVirtualListModel::HasDefaultCompare() const
594 int wxDataViewVirtualListModel::Compare(const wxDataViewItem
& item1
,
595 const wxDataViewItem
& item2
,
596 unsigned int WXUNUSED(column
),
597 bool ascending
) const
599 unsigned int pos1
= wxPtrToUInt(item1
.GetID()); // -1 not needed here
600 unsigned int pos2
= wxPtrToUInt(item2
.GetID()); // -1 not needed here
608 unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem
&WXUNUSED(item
), wxDataViewItemArray
&WXUNUSED(children
) ) const
610 return 0; // should we report an error ?
615 //-----------------------------------------------------------------------------
616 // wxDataViewIconText
617 //-----------------------------------------------------------------------------
619 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
621 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
623 // ---------------------------------------------------------
624 // wxDataViewRendererBase
625 // ---------------------------------------------------------
627 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
629 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
630 wxDataViewCellMode
WXUNUSED(mode
),
631 int WXUNUSED(align
) )
633 m_variantType
= varianttype
;
637 wxDataViewRendererBase::~wxDataViewRendererBase()
640 DestroyEditControl();
643 wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
645 return const_cast<wxDataViewRendererBase
*>(this)->GetOwner()->GetOwner();
648 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
650 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
652 // Before doing anything we send an event asking if editing of this item is really wanted.
653 wxDataViewEvent
start_event( wxEVT_DATAVIEW_ITEM_START_EDITING
, dv_ctrl
->GetId() );
654 start_event
.SetDataViewColumn( GetOwner() );
655 start_event
.SetModel( dv_ctrl
->GetModel() );
656 start_event
.SetItem( item
);
657 start_event
.SetEventObject( dv_ctrl
);
658 dv_ctrl
->GetEventHandler()->ProcessEvent( start_event
);
659 if( !start_event
.IsAllowed() )
662 m_item
= item
; // remember for later
664 unsigned int col
= GetOwner()->GetModelColumn();
666 dv_ctrl
->GetModel()->GetValue( value
, item
, col
);
668 m_editorCtrl
= CreateEditorCtrl( dv_ctrl
->GetMainWindow(), labelRect
, value
);
670 // there might be no editor control for the given item
674 wxDataViewEditorCtrlEvtHandler
*handler
=
675 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
677 m_editorCtrl
->PushEventHandler( handler
);
679 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
680 handler
->SetFocusOnIdle();
682 m_editorCtrl
->SetFocus();
685 // Now we should send Editing Started event
686 wxDataViewEvent
event( wxEVT_DATAVIEW_ITEM_EDITING_STARTED
, dv_ctrl
->GetId() );
687 event
.SetDataViewColumn( GetOwner() );
688 event
.SetModel( dv_ctrl
->GetModel() );
689 event
.SetItem( item
);
690 event
.SetEventObject( dv_ctrl
);
691 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
696 void wxDataViewRendererBase::DestroyEditControl()
698 // Remove our event handler first to prevent it from (recursively) calling
699 // us again as it would do via a call to FinishEditing() when the editor
700 // loses focus when we hide it below.
701 wxEvtHandler
* const handler
= m_editorCtrl
->PopEventHandler();
703 // Hide the control immediately but don't delete it yet as there could be
704 // some pending messages for it.
705 m_editorCtrl
->Hide();
707 wxPendingDelete
.Append(handler
);
708 wxPendingDelete
.Append(m_editorCtrl
);
710 // Ensure that DestroyEditControl() is not called again for this control.
711 m_editorCtrl
.Release();
714 void wxDataViewRendererBase::CancelEditing()
719 DestroyEditControl();
722 bool wxDataViewRendererBase::FinishEditing()
728 GetValueFromEditorCtrl( m_editorCtrl
, value
);
730 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
732 DestroyEditControl();
734 dv_ctrl
->GetMainWindow()->SetFocus();
736 bool isValid
= Validate(value
);
737 unsigned int col
= GetOwner()->GetModelColumn();
739 // Now we should send Editing Done event
740 wxDataViewEvent
event( wxEVT_DATAVIEW_ITEM_EDITING_DONE
, dv_ctrl
->GetId() );
741 event
.SetDataViewColumn( GetOwner() );
742 event
.SetModel( dv_ctrl
->GetModel() );
743 event
.SetItem( m_item
);
744 event
.SetValue( value
);
745 event
.SetColumn( col
);
746 event
.SetEditCanceled( !isValid
);
747 event
.SetEventObject( dv_ctrl
);
748 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
750 if ( isValid
&& event
.IsAllowed() )
752 dv_ctrl
->GetModel()->ChangeValue(value
, m_item
, col
);
759 void wxDataViewRendererBase::PrepareForItem(const wxDataViewModel
*model
,
760 const wxDataViewItem
& item
,
764 model
->GetValue(value
, item
, column
);
767 wxDataViewItemAttr attr
;
768 model
->GetAttr(item
, column
, attr
);
771 SetEnabled(model
->IsEnabled(item
, column
));
775 // ----------------------------------------------------------------------------
776 // wxDataViewCustomRendererBase
777 // ----------------------------------------------------------------------------
779 bool wxDataViewCustomRendererBase::ActivateCell(const wxRect
& cell
,
780 wxDataViewModel
*model
,
781 const wxDataViewItem
& item
,
783 const wxMouseEvent
* mouseEvent
)
785 // Compatibility code
787 return LeftClick(mouseEvent
->GetPosition(), cell
, model
, item
, col
);
789 return Activate(cell
, model
, item
, col
);
792 void wxDataViewCustomRendererBase::RenderBackground(wxDC
* dc
, const wxRect
& rect
)
794 if ( !m_attr
.HasBackgroundColour() )
797 const wxColour
& colour
= m_attr
.GetBackgroundColour();
798 wxDCPenChanger
changePen(*dc
, colour
);
799 wxDCBrushChanger
changeBrush(*dc
, colour
);
801 dc
->DrawRectangle(rect
);
805 wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell
, wxDC
*dc
, int state
)
807 wxCHECK_RET( dc
, "no DC to draw on in custom renderer?" );
809 // adjust the rectangle ourselves to account for the alignment
810 wxRect rectItem
= rectCell
;
811 const int align
= GetAlignment();
812 if ( align
!= wxDVR_DEFAULT_ALIGNMENT
)
814 const wxSize size
= GetSize();
816 // take alignment into account only if there is enough space, otherwise
817 // show as much contents as possible
819 // notice that many existing renderers (e.g. wxDataViewSpinRenderer)
820 // return hard-coded size which can be more than they need and if we
821 // trusted their GetSize() we'd draw the text out of cell bounds
824 if ( size
.x
>= 0 && size
.x
< rectCell
.width
)
826 if ( align
& wxALIGN_CENTER_HORIZONTAL
)
827 rectItem
.x
+= (rectCell
.width
- size
.x
)/2;
828 else if ( align
& wxALIGN_RIGHT
)
829 rectItem
.x
+= rectCell
.width
- size
.x
;
830 // else: wxALIGN_LEFT is the default
832 rectItem
.width
= size
.x
;
835 if ( size
.y
>= 0 && size
.y
< rectCell
.height
)
837 if ( align
& wxALIGN_CENTER_VERTICAL
)
838 rectItem
.y
+= (rectCell
.height
- size
.y
)/2;
839 else if ( align
& wxALIGN_BOTTOM
)
840 rectItem
.y
+= rectCell
.height
- size
.y
;
841 // else: wxALIGN_TOP is the default
843 rectItem
.height
= size
.y
;
848 // set up the DC attributes
850 // override custom foreground with the standard one for the selected items
851 // because we currently don't allow changing the selection background and
852 // custom colours may be unreadable on it
854 if ( state
& wxDATAVIEW_CELL_SELECTED
)
855 col
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
856 else if ( m_attr
.HasColour() )
857 col
= m_attr
.GetColour();
858 else // use default foreground
859 col
= GetOwner()->GetOwner()->GetForegroundColour();
861 wxDCTextColourChanger
changeFg(*dc
, col
);
863 wxDCFontChanger
changeFont(*dc
);
864 if ( m_attr
.HasFont() )
865 changeFont
.Set(m_attr
.GetEffectiveFont(dc
->GetFont()));
867 Render(rectItem
, dc
, state
);
870 wxSize
wxDataViewCustomRendererBase::GetTextExtent(const wxString
& str
) const
872 const wxDataViewCtrl
*view
= GetView();
874 if ( m_attr
.HasFont() )
876 wxFont
font(m_attr
.GetEffectiveFont(view
->GetFont()));
878 view
->GetTextExtent(str
, &size
.x
, &size
.y
, NULL
, NULL
, &font
);
883 return view
->GetTextExtent(str
);
888 wxDataViewCustomRendererBase::RenderText(const wxString
& text
,
894 wxRect rectText
= rect
;
895 rectText
.x
+= xoffset
;
896 rectText
.width
-= xoffset
;
898 // check if we want to ellipsize the text if it doesn't fit
899 wxString ellipsizedText
;
900 if ( GetEllipsizeMode() != wxELLIPSIZE_NONE
)
902 ellipsizedText
= wxControl::Ellipsize
908 wxELLIPSIZE_FLAGS_NONE
912 // get the alignment to use
913 int align
= GetAlignment();
914 if ( align
== wxDVR_DEFAULT_ALIGNMENT
)
916 // if we don't have an explicit alignment ourselves, use that of the
917 // column in horizontal direction and default vertical alignment
918 align
= GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
921 dc
->DrawLabel(ellipsizedText
.empty() ? text
: ellipsizedText
,
925 //-----------------------------------------------------------------------------
926 // wxDataViewEditorCtrlEvtHandler
927 //-----------------------------------------------------------------------------
929 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
930 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
931 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
932 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
933 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
936 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
940 m_focusOnIdle
= false;
941 if (wxWindow::FindFocus() != m_editorCtrl
)
942 m_editorCtrl
->SetFocus();
948 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
951 m_owner
->FinishEditing();
954 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
956 switch ( event
.m_keyCode
)
960 m_owner
->FinishEditing();
966 m_owner
->CancelEditing();
974 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
979 m_owner
->FinishEditing();
985 // ---------------------------------------------------------
986 // wxDataViewColumnBase
987 // ---------------------------------------------------------
989 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
990 unsigned int model_column
)
992 m_renderer
= renderer
;
993 m_model_column
= model_column
;
995 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
998 wxDataViewColumnBase::~wxDataViewColumnBase()
1003 // ---------------------------------------------------------
1004 // wxDataViewCtrlBase
1005 // ---------------------------------------------------------
1007 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
1009 wxDataViewCtrlBase::wxDataViewCtrlBase()
1012 m_expander_column
= 0;
1016 wxDataViewCtrlBase::~wxDataViewCtrlBase()
1025 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
1029 m_model
->DecRef(); // discard old model, if any
1032 // add our own reference to the new model:
1042 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
1047 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
1052 void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem
& item
)
1054 if (!m_model
) return;
1056 if (!item
.IsOk()) return;
1058 wxVector
<wxDataViewItem
> parentChain
;
1060 // at first we get all the parents of the selected item
1061 wxDataViewItem parent
= m_model
->GetParent(item
);
1062 while (parent
.IsOk())
1064 parentChain
.push_back(parent
);
1065 parent
= m_model
->GetParent(parent
);
1068 // then we expand the parents, starting at the root
1069 while (!parentChain
.empty())
1071 Expand(parentChain
.back());
1072 parentChain
.pop_back();
1076 wxDataViewItem
wxDataViewCtrlBase::GetCurrentItem() const
1078 return HasFlag(wxDV_MULTIPLE
) ? DoGetCurrentItem()
1082 void wxDataViewCtrlBase::SetCurrentItem(const wxDataViewItem
& item
)
1084 wxCHECK_RET( item
.IsOk(), "Can't make current an invalid item." );
1086 if ( HasFlag(wxDV_MULTIPLE
) )
1087 DoSetCurrentItem(item
);
1092 wxDataViewItem
wxDataViewCtrlBase::GetSelection() const
1094 if ( GetSelectedItemsCount() != 1 )
1095 return wxDataViewItem();
1097 wxDataViewItemArray selections
;
1098 GetSelections(selections
);
1099 return selections
[0];
1103 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
1104 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1106 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1107 new wxDataViewTextRenderer( wxT("string"), mode
),
1108 model_column
, width
, align
, flags
);
1109 AppendColumn( ret
);
1114 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
1115 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1117 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1118 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1119 model_column
, width
, align
, flags
);
1120 AppendColumn( ret
);
1125 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
1126 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1128 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1129 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1130 model_column
, width
, align
, flags
);
1131 AppendColumn( ret
);
1136 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
1137 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1139 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1140 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1141 model_column
, width
, align
, flags
);
1142 AppendColumn( ret
);
1147 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
1148 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1150 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1151 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1152 model_column
, width
, align
, flags
);
1153 AppendColumn( ret
);
1158 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
1159 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1161 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1162 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1163 model_column
, width
, align
, flags
);
1164 AppendColumn( ret
);
1169 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1170 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1172 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1173 new wxDataViewTextRenderer( wxT("string"), mode
),
1174 model_column
, width
, align
, flags
);
1175 AppendColumn( ret
);
1180 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1181 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1183 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1184 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1185 model_column
, width
, align
, flags
);
1186 AppendColumn( ret
);
1191 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1192 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1194 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1195 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1196 model_column
, width
, align
, flags
);
1197 AppendColumn( ret
);
1202 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1203 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1205 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1206 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1207 model_column
, width
, align
, flags
);
1208 AppendColumn( ret
);
1213 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1214 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1216 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1217 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1218 model_column
, width
, align
, flags
);
1219 AppendColumn( ret
);
1224 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1225 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1227 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1228 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1229 model_column
, width
, align
, flags
);
1230 AppendColumn( ret
);
1235 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1236 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1238 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1239 new wxDataViewTextRenderer( wxT("string"), mode
),
1240 model_column
, width
, align
, flags
);
1241 PrependColumn( ret
);
1246 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1247 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1249 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1250 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1251 model_column
, width
, align
, flags
);
1252 PrependColumn( ret
);
1257 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1258 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1261 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1262 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1263 model_column
, width
, align
, flags
);
1264 PrependColumn( ret
);
1269 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1270 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1272 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1273 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1274 model_column
, width
, align
, flags
);
1275 PrependColumn( ret
);
1280 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1281 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1283 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1284 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1285 model_column
, width
, align
, flags
);
1286 PrependColumn( ret
);
1291 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1292 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1294 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1295 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1296 model_column
, width
, align
, flags
);
1297 PrependColumn( ret
);
1302 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1303 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1305 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1306 new wxDataViewTextRenderer( wxT("string"), mode
),
1307 model_column
, width
, align
, flags
);
1308 PrependColumn( ret
);
1313 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1314 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1316 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1317 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1318 model_column
, width
, align
, flags
);
1319 PrependColumn( ret
);
1324 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1325 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1327 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1328 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1329 model_column
, width
, align
, flags
);
1330 PrependColumn( ret
);
1335 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1336 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1338 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1339 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1340 model_column
, width
, align
, flags
);
1341 PrependColumn( ret
);
1346 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1347 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1349 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1350 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1351 model_column
, width
, align
, flags
);
1352 PrependColumn( ret
);
1357 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1358 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1360 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1361 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1362 model_column
, width
, align
, flags
);
1363 PrependColumn( ret
);
1368 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1370 col
->SetOwner( (wxDataViewCtrl
*) this );
1375 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1377 col
->SetOwner( (wxDataViewCtrl
*) this );
1382 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1384 col
->SetOwner( (wxDataViewCtrl
*) this );
1388 void wxDataViewCtrlBase::StartEditor(const wxDataViewItem
& item
, unsigned int column
)
1390 EditItem(item
, GetColumn(column
));
1393 // ---------------------------------------------------------
1395 // ---------------------------------------------------------
1397 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1399 wxDEFINE_EVENT( wxEVT_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
);
1401 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
);
1402 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
);
1403 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
);
1404 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
);
1405 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
);
1406 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
);
1407 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_START_EDITING
, wxDataViewEvent
);
1408 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
);
1409 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
);
1411 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
);
1413 wxDEFINE_EVENT( wxEVT_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
);
1414 wxDEFINE_EVENT( wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED
, wxDataViewEvent
);
1415 wxDEFINE_EVENT( wxEVT_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
);
1416 wxDEFINE_EVENT( wxEVT_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
);
1418 wxDEFINE_EVENT( wxEVT_DATAVIEW_CACHE_HINT
, wxDataViewEvent
);
1420 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
);
1421 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE
, wxDataViewEvent
);
1422 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_DROP
, wxDataViewEvent
);
1426 // -------------------------------------
1427 // wxDataViewSpinRenderer
1428 // -------------------------------------
1430 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1431 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1437 wxWindow
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1440 wxSize size
= labelRect
.GetSize();
1442 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1445 str
.Printf( wxT("%d"), (int) l
);
1446 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1447 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1449 size
= sc
->GetSize();
1450 wxPoint pt
= sc
->GetPosition();
1451 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1457 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1459 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1460 long l
= sc
->GetValue();
1465 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1468 str
.Printf(wxT("%d"), (int) m_data
);
1469 RenderText( str
, 0, rect
, dc
, state
);
1473 wxSize
wxDataViewSpinRenderer::GetSize() const
1475 wxSize sz
= GetTextExtent(wxString::Format("%d", (int)m_data
));
1477 // Allow some space for the spin buttons, which is approximately the size
1478 // of a scrollbar (and getting pixel-exact value would be complicated).
1479 // Also add some whitespace between the text and the button:
1480 sz
.x
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1481 sz
.x
+= GetTextExtent("M").x
;
1486 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1488 m_data
= value
.GetLong();
1492 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1498 // -------------------------------------
1499 // wxDataViewChoiceRenderer
1500 // -------------------------------------
1502 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
1504 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1505 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1507 m_choices
= choices
;
1510 wxWindow
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1512 wxChoice
* c
= new wxChoice
1516 labelRect
.GetTopLeft(),
1517 wxSize(labelRect
.GetWidth(), -1),
1520 c
->Move(labelRect
.GetRight() - c
->GetRect().width
, wxDefaultCoord
);
1521 c
->SetStringSelection( value
.GetString() );
1525 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1527 wxChoice
*c
= (wxChoice
*) editor
;
1528 wxString s
= c
->GetStringSelection();
1533 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1535 RenderText( m_data
, 0, rect
, dc
, state
);
1539 wxSize
wxDataViewChoiceRenderer::GetSize() const
1543 for ( wxArrayString::const_iterator i
= m_choices
.begin(); i
!= m_choices
.end(); ++i
)
1544 sz
.IncTo(GetTextExtent(*i
));
1546 // Allow some space for the right-side button, which is approximately the
1547 // size of a scrollbar (and getting pixel-exact value would be complicated).
1548 // Also add some whitespace between the text and the button:
1549 sz
.x
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1550 sz
.x
+= GetTextExtent("M").x
;
1555 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1557 m_data
= value
.GetString();
1561 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1567 // ----------------------------------------------------------------------------
1568 // wxDataViewChoiceByIndexRenderer
1569 // ----------------------------------------------------------------------------
1571 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
1572 wxDataViewCellMode mode
, int alignment
) :
1573 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
1577 wxWindow
* wxDataViewChoiceByIndexRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1579 wxVariant string_value
= GetChoice( value
.GetLong() );
1581 return wxDataViewChoiceRenderer::CreateEditorCtrl( parent
, labelRect
, string_value
);
1584 bool wxDataViewChoiceByIndexRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1586 wxVariant string_value
;
1587 if (!wxDataViewChoiceRenderer::GetValueFromEditorCtrl( editor
, string_value
))
1590 value
= (long) GetChoices().Index( string_value
.GetString() );
1594 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
1596 wxVariant string_value
= GetChoice( value
.GetLong() );
1597 return wxDataViewChoiceRenderer::SetValue( string_value
);
1600 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
1602 wxVariant string_value
;
1603 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
1606 value
= (long) GetChoices().Index( string_value
.GetString() );
1612 // ---------------------------------------------------------
1613 // wxDataViewDateRenderer
1614 // ---------------------------------------------------------
1616 #if (defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)) && wxUSE_DATEPICKCTRL
1618 wxDataViewDateRenderer::wxDataViewDateRenderer(const wxString
& varianttype
,
1619 wxDataViewCellMode mode
, int align
)
1620 : wxDataViewCustomRenderer(varianttype
, mode
, align
)
1625 wxDataViewDateRenderer::CreateEditorCtrl(wxWindow
*parent
, wxRect labelRect
, const wxVariant
& value
)
1627 return new wxDatePickerCtrl
1631 value
.GetDateTime(),
1632 labelRect
.GetTopLeft(),
1637 bool wxDataViewDateRenderer::GetValueFromEditorCtrl(wxWindow
*editor
, wxVariant
& value
)
1639 wxDatePickerCtrl
*ctrl
= static_cast<wxDatePickerCtrl
*>(editor
);
1640 value
= ctrl
->GetValue();
1644 bool wxDataViewDateRenderer::SetValue(const wxVariant
& value
)
1646 m_date
= value
.GetDateTime();
1650 bool wxDataViewDateRenderer::GetValue(wxVariant
& value
) const
1656 bool wxDataViewDateRenderer::Render(wxRect cell
, wxDC
* dc
, int state
)
1658 wxString tmp
= m_date
.FormatDate();
1659 RenderText( tmp
, 0, cell
, dc
, state
);
1663 wxSize
wxDataViewDateRenderer::GetSize() const
1665 return GetTextExtent(m_date
.FormatDate());
1668 #endif // (defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)) && wxUSE_DATEPICKCTRL
1670 //-----------------------------------------------------------------------------
1671 // wxDataViewListStore
1672 //-----------------------------------------------------------------------------
1674 wxDataViewListStore::wxDataViewListStore()
1678 wxDataViewListStore::~wxDataViewListStore()
1680 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1681 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1683 wxDataViewListStoreLine
* line
= *it
;
1688 void wxDataViewListStore::PrependColumn( const wxString
&varianttype
)
1690 m_cols
.Insert( varianttype
, 0 );
1693 void wxDataViewListStore::InsertColumn( unsigned int pos
, const wxString
&varianttype
)
1695 m_cols
.Insert( varianttype
, pos
);
1698 void wxDataViewListStore::AppendColumn( const wxString
&varianttype
)
1700 m_cols
.Add( varianttype
);
1703 unsigned int wxDataViewListStore::GetColumnCount() const
1705 return m_cols
.GetCount();
1708 unsigned int wxDataViewListStore::GetItemCount() const
1710 return m_data
.size();
1713 wxString
wxDataViewListStore::GetColumnType( unsigned int pos
) const
1718 void wxDataViewListStore::AppendItem( const wxVector
<wxVariant
> &values
, wxUIntPtr data
)
1720 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1721 line
->m_values
= values
;
1722 m_data
.push_back( line
);
1727 void wxDataViewListStore::PrependItem( const wxVector
<wxVariant
> &values
, wxUIntPtr data
)
1729 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1730 line
->m_values
= values
;
1731 m_data
.insert( m_data
.begin(), line
);
1736 void wxDataViewListStore::InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
,
1739 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1740 line
->m_values
= values
;
1741 m_data
.insert( m_data
.begin()+row
, line
);
1746 void wxDataViewListStore::DeleteItem( unsigned int row
)
1748 wxVector
<wxDataViewListStoreLine
*>::iterator it
= m_data
.begin() + row
;
1755 void wxDataViewListStore::DeleteAllItems()
1757 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1758 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1760 wxDataViewListStoreLine
* line
= *it
;
1769 void wxDataViewListStore::SetItemData( const wxDataViewItem
& item
, wxUIntPtr data
)
1771 wxDataViewListStoreLine
* line
= m_data
[GetRow(item
)];
1774 line
->SetData( data
);
1777 wxUIntPtr
wxDataViewListStore::GetItemData( const wxDataViewItem
& item
) const
1779 wxDataViewListStoreLine
* line
= m_data
[GetRow(item
)];
1780 if (!line
) return static_cast<wxUIntPtr
>(NULL
);
1782 return line
->GetData();
1785 void wxDataViewListStore::GetValueByRow( wxVariant
&value
, unsigned int row
, unsigned int col
) const
1787 wxDataViewListStoreLine
*line
= m_data
[row
];
1788 value
= line
->m_values
[col
];
1791 bool wxDataViewListStore::SetValueByRow( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1793 wxDataViewListStoreLine
*line
= m_data
[row
];
1794 line
->m_values
[col
] = value
;
1799 //-----------------------------------------------------------------------------
1800 // wxDataViewListCtrl
1801 //-----------------------------------------------------------------------------
1803 IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl
,wxDataViewCtrl
)
1805 BEGIN_EVENT_TABLE(wxDataViewListCtrl
,wxDataViewCtrl
)
1806 EVT_SIZE( wxDataViewListCtrl::OnSize
)
1809 wxDataViewListCtrl::wxDataViewListCtrl()
1813 wxDataViewListCtrl::wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
1814 const wxPoint
& pos
, const wxSize
& size
, long style
,
1815 const wxValidator
& validator
)
1817 Create( parent
, id
, pos
, size
, style
, validator
);
1820 wxDataViewListCtrl::~wxDataViewListCtrl()
1825 bool wxDataViewListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1826 const wxPoint
& pos
, const wxSize
& size
, long style
,
1827 const wxValidator
& validator
)
1829 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
1832 wxDataViewListStore
*store
= new wxDataViewListStore
;
1833 AssociateModel( store
);
1839 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1841 GetStore()->AppendColumn( varianttype
);
1842 return wxDataViewCtrl::AppendColumn( column
);
1845 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1847 GetStore()->PrependColumn( varianttype
);
1848 return wxDataViewCtrl::PrependColumn( column
);
1851 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
)
1853 GetStore()->InsertColumn( pos
, varianttype
);
1854 return wxDataViewCtrl::InsertColumn( pos
, column
);
1857 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*col
)
1859 return PrependColumn( col
, "string" );
1862 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
1864 return InsertColumn( pos
, col
, "string" );
1867 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*col
)
1869 return AppendColumn( col
, "string" );
1872 wxDataViewColumn
*wxDataViewListCtrl::AppendTextColumn( const wxString
&label
,
1873 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1875 GetStore()->AppendColumn( wxT("string") );
1877 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1878 new wxDataViewTextRenderer( wxT("string"), mode
),
1879 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1881 wxDataViewCtrl::AppendColumn( ret
);
1886 wxDataViewColumn
*wxDataViewListCtrl::AppendToggleColumn( const wxString
&label
,
1887 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1889 GetStore()->AppendColumn( wxT("bool") );
1891 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1892 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1893 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1895 wxDataViewCtrl::AppendColumn( ret
);
1900 wxDataViewColumn
*wxDataViewListCtrl::AppendProgressColumn( const wxString
&label
,
1901 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1903 GetStore()->AppendColumn( wxT("long") );
1905 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1906 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1907 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1909 wxDataViewCtrl::AppendColumn( ret
);
1914 wxDataViewColumn
*wxDataViewListCtrl::AppendIconTextColumn( const wxString
&label
,
1915 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1917 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
1919 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1920 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1921 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1923 wxDataViewCtrl::AppendColumn( ret
);
1928 void wxDataViewListCtrl::OnSize( wxSizeEvent
&event
)
1933 //-----------------------------------------------------------------------------
1934 // wxDataViewTreeStore
1935 //-----------------------------------------------------------------------------
1937 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1938 wxDataViewTreeStoreNode
*parent
,
1939 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1947 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1953 #include "wx/listimpl.cpp"
1954 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1956 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1957 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1958 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1959 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1961 m_iconExpanded
= expanded
;
1962 m_isExpanded
= false;
1963 m_children
.DeleteContents(true);
1966 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1970 //-----------------------------------------------------------------------------
1972 wxDataViewTreeStore::wxDataViewTreeStore()
1974 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1977 wxDataViewTreeStore::~wxDataViewTreeStore()
1982 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1983 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1985 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1986 if (!parent_node
) return wxDataViewItem(0);
1988 wxDataViewTreeStoreNode
*node
=
1989 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1990 parent_node
->GetChildren().Append( node
);
1992 return node
->GetItem();
1995 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1996 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1998 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1999 if (!parent_node
) return wxDataViewItem(0);
2001 wxDataViewTreeStoreNode
*node
=
2002 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
2003 parent_node
->GetChildren().Insert( node
);
2005 return node
->GetItem();
2009 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& parent
,
2010 const wxDataViewItem
& previous
,
2011 const wxString
& text
,
2015 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2016 if (!parent_node
) return wxDataViewItem(0);
2018 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
2019 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
2020 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
2022 wxDataViewTreeStoreNode
*node
=
2023 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
2024 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
2026 return node
->GetItem();
2029 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
2030 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
2031 wxClientData
*data
)
2033 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2034 if (!parent_node
) return wxDataViewItem(0);
2036 wxDataViewTreeStoreContainerNode
*node
=
2037 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
2038 parent_node
->GetChildren().Insert( node
);
2040 return node
->GetItem();
2044 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
2045 const wxString
&text
,
2047 const wxIcon
& expanded
,
2048 wxClientData
* data
)
2050 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2051 if (!parent_node
) return wxDataViewItem(0);
2053 wxDataViewTreeStoreContainerNode
*node
=
2054 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
2055 parent_node
->GetChildren().Append( node
);
2057 return node
->GetItem();
2061 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& parent
,
2062 const wxDataViewItem
& previous
,
2063 const wxString
& text
,
2065 const wxIcon
& expanded
,
2066 wxClientData
* data
)
2068 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2069 if (!parent_node
) return wxDataViewItem(0);
2071 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
2072 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
2073 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
2075 wxDataViewTreeStoreContainerNode
*node
=
2076 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
2077 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
2079 return node
->GetItem();
2082 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
& item
) const
2084 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2085 if (!node
) return false;
2087 return node
->IsContainer();
2090 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
2092 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2093 if (!parent_node
) return wxDataViewItem(0);
2095 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
2097 return wxDataViewItem(node
->GetData());
2099 return wxDataViewItem(0);
2102 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
2104 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
2105 if (!node
) return -1;
2107 if (!node
->IsContainer())
2110 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
2111 return (int) container_node
->GetChildren().GetCount();
2114 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2116 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2119 node
->SetText( text
);
2122 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
2124 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2125 if (!node
) return wxEmptyString
;
2127 return node
->GetText();
2130 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2132 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2135 node
->SetIcon( icon
);
2138 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
2140 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2141 if (!node
) return wxNullIcon
;
2143 return node
->GetIcon();
2146 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2148 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2151 node
->SetExpandedIcon( icon
);
2154 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
2156 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2157 if (!node
) return wxNullIcon
;
2159 return node
->GetExpandedIcon();
2162 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
2164 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2167 node
->SetData( data
);
2170 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
2172 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2173 if (!node
) return NULL
;
2175 return node
->GetData();
2178 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
2180 if (!item
.IsOk()) return;
2182 wxDataViewItem parent_item
= GetParent( item
);
2184 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
2185 if (!parent_node
) return;
2187 parent_node
->GetChildren().DeleteObject( FindNode(item
) );
2190 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
2192 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2195 node
->GetChildren().clear();
2198 void wxDataViewTreeStore::DeleteAllItems()
2200 DeleteChildren(wxDataViewItem(m_root
));
2204 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
2205 const wxDataViewItem
&item
,
2206 unsigned int WXUNUSED(col
)) const
2208 // if (col != 0) return;
2210 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2213 wxIcon
icon( node
->GetIcon());
2214 if (node
->IsContainer())
2216 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
2217 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
2218 icon
= container
->GetExpandedIcon();
2221 wxDataViewIconText
data( node
->GetText(), icon
);
2227 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
2228 const wxDataViewItem
& item
,
2229 unsigned int WXUNUSED(col
))
2231 // if (col != 0) return false;
2233 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2234 if (!node
) return false;
2236 wxDataViewIconText data
;
2240 node
->SetText( data
.GetText() );
2241 node
->SetIcon( data
.GetIcon() );
2246 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
2248 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2249 if (!node
) return wxDataViewItem(0);
2251 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
2252 if (!parent
) return wxDataViewItem(0);
2254 if (parent
== m_root
)
2255 return wxDataViewItem(0);
2257 return parent
->GetItem();
2260 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
2262 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2263 if (!node
) return 0;
2265 wxDataViewTreeStoreNodeList::iterator iter
;
2266 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2268 wxDataViewTreeStoreNode
* child
= *iter
;
2269 children
.Add( child
->GetItem() );
2272 return node
->GetChildren().GetCount();
2275 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
2276 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) ) const
2278 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
2279 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
2281 if (!node1
|| !node2
)
2284 wxDataViewTreeStoreContainerNode
* parent1
=
2285 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
2286 wxDataViewTreeStoreContainerNode
* parent2
=
2287 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
2289 if (parent1
!= parent2
)
2291 wxLogError( wxT("Comparing items with different parent.") );
2295 if (node1
->IsContainer() && !node2
->IsContainer())
2298 if (node2
->IsContainer() && !node1
->IsContainer())
2301 return parent1
->GetChildren().IndexOf( node1
) - parent2
->GetChildren().IndexOf( node2
);
2304 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
2309 return (wxDataViewTreeStoreNode
*) item
.GetID();
2312 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
2315 return (wxDataViewTreeStoreContainerNode
*) m_root
;
2317 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
2319 if (!node
->IsContainer())
2322 return (wxDataViewTreeStoreContainerNode
*) node
;
2325 //-----------------------------------------------------------------------------
2326 // wxDataViewTreeCtrl
2327 //-----------------------------------------------------------------------------
2329 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2331 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2332 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
2333 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
2334 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
2337 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2338 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2340 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
2343 // create the standard model and a column in the tree
2344 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
2345 AssociateModel( store
);
2348 AppendIconTextColumn
2350 wxString(), // no label (header is not shown anyhow)
2351 0, // the only model column
2352 wxDATAVIEW_CELL_EDITABLE
,
2353 -1, // default width
2354 wxALIGN_NOT
, // and alignment
2361 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
2362 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2364 wxDataViewItem res
= GetStore()->
2365 AppendItem( parent
, text
, GetImage(iconIndex
), data
);
2367 GetStore()->ItemAdded( parent
, res
);
2372 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
2373 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2375 wxDataViewItem res
= GetStore()->
2376 PrependItem( parent
, text
, GetImage(iconIndex
), data
);
2378 GetStore()->ItemAdded( parent
, res
);
2383 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2384 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2386 wxDataViewItem res
= GetStore()->
2387 InsertItem( parent
, previous
, text
, GetImage(iconIndex
), data
);
2389 GetStore()->ItemAdded( parent
, res
);
2394 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
2395 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2397 wxDataViewItem res
= GetStore()->
2398 PrependContainer( parent
, text
,
2399 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2401 GetStore()->ItemAdded( parent
, res
);
2406 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
2407 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2409 wxDataViewItem res
= GetStore()->
2410 AppendContainer( parent
, text
,
2411 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2413 GetStore()->ItemAdded( parent
, res
);
2418 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2419 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2421 wxDataViewItem res
= GetStore()->
2422 InsertContainer( parent
, previous
, text
,
2423 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2425 GetStore()->ItemAdded( parent
, res
);
2430 void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2432 GetStore()->SetItemText(item
,text
);
2435 GetStore()->ValueChanged( item
, 0 );
2438 void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2440 GetStore()->SetItemIcon(item
,icon
);
2443 GetStore()->ValueChanged( item
, 0 );
2446 void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2448 GetStore()->SetItemExpandedIcon(item
,icon
);
2451 GetStore()->ValueChanged( item
, 0 );
2454 void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem
& item
)
2456 wxDataViewItem parent_item
= GetStore()->GetParent( item
);
2458 GetStore()->DeleteItem(item
);
2461 GetStore()->ItemDeleted( parent_item
, item
);
2464 void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem
& item
)
2466 wxDataViewTreeStoreContainerNode
*node
= GetStore()->FindContainerNode( item
);
2469 wxDataViewItemArray array
;
2470 wxDataViewTreeStoreNodeList::iterator iter
;
2471 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2473 wxDataViewTreeStoreNode
* child
= *iter
;
2474 array
.Add( child
->GetItem() );
2477 GetStore()->DeleteChildren( item
);
2480 GetStore()->ItemsDeleted( item
, array
);
2483 void wxDataViewTreeCtrl::DeleteAllItems()
2485 GetStore()->DeleteAllItems();
2487 GetStore()->Cleared();
2490 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
2492 if (HasImageList()) return;
2494 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2495 if (!container
) return;
2497 container
->SetExpanded( true );
2499 GetStore()->ItemChanged( event
.GetItem() );
2502 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
2504 if (HasImageList()) return;
2506 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2507 if (!container
) return;
2509 container
->SetExpanded( false );
2511 GetStore()->ItemChanged( event
.GetItem() );
2514 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
2516 #if defined(wxUSE_GENERICDATAVIEWCTRL)
2517 // automatically resize our only column to take the entire control width
2518 if ( GetColumnCount() )
2520 wxSize size
= GetClientSize();
2521 GetColumn(0)->SetWidth(size
.x
);
2527 #endif // wxUSE_DATAVIEWCTRL