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 // sort branches before leaves
312 bool item1_is_container
= IsContainer(item1
);
313 bool item2_is_container
= IsContainer(item2
);
315 if (item1_is_container
&& !item2_is_container
)
317 if (item2_is_container
&& !item1_is_container
)
320 wxVariant value1
,value2
;
321 GetValue( value1
, item1
, column
);
322 GetValue( value2
, item2
, column
);
326 wxVariant temp
= value1
;
331 if (value1
.GetType() == wxT("string"))
333 wxString str1
= value1
.GetString();
334 wxString str2
= value2
.GetString();
335 int res
= str1
.Cmp( str2
);
339 else if (value1
.GetType() == wxT("long"))
341 long l1
= value1
.GetLong();
342 long l2
= value2
.GetLong();
347 else if (value1
.GetType() == wxT("double"))
349 double d1
= value1
.GetDouble();
350 double d2
= value2
.GetDouble();
356 else if (value1
.GetType() == wxT("datetime"))
358 wxDateTime dt1
= value1
.GetDateTime();
359 wxDateTime dt2
= value2
.GetDateTime();
360 if (dt1
.IsEarlierThan(dt2
))
362 if (dt2
.IsEarlierThan(dt1
))
366 // items must be different
367 wxUIntPtr id1
= wxPtrToUInt(item1
.GetID()),
368 id2
= wxPtrToUInt(item2
.GetID());
370 return ascending
? id1
- id2
: id2
- id1
;
373 // ---------------------------------------------------------
374 // wxDataViewIndexListModel
375 // ---------------------------------------------------------
377 static int my_sort( int *v1
, int *v2
)
383 wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size
)
385 // IDs are ordered until an item gets deleted or inserted
388 // build initial index
390 for (i
= 1; i
< initial_size
+1; i
++)
391 m_hash
.Add( wxDataViewItem(wxUIntToPtr(i
)) );
392 m_nextFreeID
= initial_size
+ 1;
395 void wxDataViewIndexListModel::Reset( unsigned int new_size
)
397 /* wxDataViewModel:: */ BeforeReset();
401 // IDs are ordered until an item gets deleted or inserted
404 // build initial index
406 for (i
= 1; i
< new_size
+1; i
++)
407 m_hash
.Add( wxDataViewItem(wxUIntToPtr(i
)) );
409 m_nextFreeID
= new_size
+ 1;
411 /* wxDataViewModel:: */ AfterReset();
414 void wxDataViewIndexListModel::RowPrepended()
418 unsigned int id
= m_nextFreeID
;
421 wxDataViewItem
item( wxUIntToPtr(id
) );
422 m_hash
.Insert( item
, 0 );
423 ItemAdded( wxDataViewItem(0), item
);
427 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
431 unsigned int id
= m_nextFreeID
;
434 wxDataViewItem
item( wxUIntToPtr(id
) );
435 m_hash
.Insert( item
, before
);
436 ItemAdded( wxDataViewItem(0), item
);
439 void wxDataViewIndexListModel::RowAppended()
441 unsigned int id
= m_nextFreeID
;
444 wxDataViewItem
item( wxUIntToPtr(id
) );
446 ItemAdded( wxDataViewItem(0), item
);
449 void wxDataViewIndexListModel::RowDeleted( unsigned int row
)
453 wxDataViewItem
item( m_hash
[row
] );
454 m_hash
.RemoveAt( row
);
455 /* wxDataViewModel:: */ ItemDeleted( wxDataViewItem(0), item
);
458 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt
&rows
)
462 wxDataViewItemArray array
;
464 for (i
= 0; i
< rows
.GetCount(); i
++)
466 wxDataViewItem
item( m_hash
[rows
[i
]] );
470 wxArrayInt sorted
= rows
;
471 sorted
.Sort( my_sort
);
472 for (i
= 0; i
< sorted
.GetCount(); i
++)
473 m_hash
.RemoveAt( sorted
[i
] );
475 /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array
);
478 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
480 /* wxDataViewModel:: */ ItemChanged( GetItem(row
) );
483 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
485 /* wxDataViewModel:: */ ValueChanged( GetItem(row
), col
);
488 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
491 return wxPtrToUInt(item
.GetID())-1;
493 // assert for not found
494 return (unsigned int) m_hash
.Index( item
);
497 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
499 wxASSERT( row
< m_hash
.GetCount() );
500 return wxDataViewItem( m_hash
[row
] );
503 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
510 return m_hash
.GetCount();
513 // ---------------------------------------------------------
514 // wxDataViewVirtualListModel
515 // ---------------------------------------------------------
519 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size
)
521 m_size
= initial_size
;
524 void wxDataViewVirtualListModel::Reset( unsigned int new_size
)
526 /* wxDataViewModel:: */ BeforeReset();
530 /* wxDataViewModel:: */ AfterReset();
533 void wxDataViewVirtualListModel::RowPrepended()
536 wxDataViewItem
item( wxUIntToPtr(1) );
537 ItemAdded( wxDataViewItem(0), item
);
540 void wxDataViewVirtualListModel::RowInserted( unsigned int before
)
543 wxDataViewItem
item( wxUIntToPtr(before
+1) );
544 ItemAdded( wxDataViewItem(0), item
);
547 void wxDataViewVirtualListModel::RowAppended()
550 wxDataViewItem
item( wxUIntToPtr(m_size
) );
551 ItemAdded( wxDataViewItem(0), item
);
554 void wxDataViewVirtualListModel::RowDeleted( unsigned int row
)
557 wxDataViewItem
item( wxUIntToPtr(row
+1) );
558 /* wxDataViewModel:: */ ItemDeleted( wxDataViewItem(0), item
);
561 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt
&rows
)
563 m_size
-= rows
.GetCount();
565 wxArrayInt sorted
= rows
;
566 sorted
.Sort( my_sort
);
568 wxDataViewItemArray array
;
570 for (i
= 0; i
< sorted
.GetCount(); i
++)
572 wxDataViewItem
item( wxUIntToPtr(sorted
[i
]+1) );
575 /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array
);
578 void wxDataViewVirtualListModel::RowChanged( unsigned int row
)
580 /* wxDataViewModel:: */ ItemChanged( GetItem(row
) );
583 void wxDataViewVirtualListModel::RowValueChanged( unsigned int row
, unsigned int col
)
585 /* wxDataViewModel:: */ ValueChanged( GetItem(row
), col
);
588 unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem
&item
) const
590 return wxPtrToUInt( item
.GetID() ) -1;
593 wxDataViewItem
wxDataViewVirtualListModel::GetItem( unsigned int row
) const
595 return wxDataViewItem( wxUIntToPtr(row
+1) );
598 bool wxDataViewVirtualListModel::HasDefaultCompare() const
603 int wxDataViewVirtualListModel::Compare(const wxDataViewItem
& item1
,
604 const wxDataViewItem
& item2
,
605 unsigned int WXUNUSED(column
),
606 bool ascending
) const
608 unsigned int pos1
= wxPtrToUInt(item1
.GetID()); // -1 not needed here
609 unsigned int pos2
= wxPtrToUInt(item2
.GetID()); // -1 not needed here
617 unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem
&WXUNUSED(item
), wxDataViewItemArray
&WXUNUSED(children
) ) const
619 return 0; // should we report an error ?
624 //-----------------------------------------------------------------------------
625 // wxDataViewIconText
626 //-----------------------------------------------------------------------------
628 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
630 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
632 // ---------------------------------------------------------
633 // wxDataViewRendererBase
634 // ---------------------------------------------------------
636 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
638 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
639 wxDataViewCellMode
WXUNUSED(mode
),
640 int WXUNUSED(align
) )
642 m_variantType
= varianttype
;
646 wxDataViewRendererBase::~wxDataViewRendererBase()
649 DestroyEditControl();
652 wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
654 return const_cast<wxDataViewRendererBase
*>(this)->GetOwner()->GetOwner();
657 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
659 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
661 // Before doing anything we send an event asking if editing of this item is really wanted.
662 wxDataViewEvent
start_event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv_ctrl
->GetId() );
663 start_event
.SetDataViewColumn( GetOwner() );
664 start_event
.SetModel( dv_ctrl
->GetModel() );
665 start_event
.SetItem( item
);
666 start_event
.SetEventObject( dv_ctrl
);
667 dv_ctrl
->GetEventHandler()->ProcessEvent( start_event
);
668 if( !start_event
.IsAllowed() )
671 m_item
= item
; // remember for later
673 unsigned int col
= GetOwner()->GetModelColumn();
675 dv_ctrl
->GetModel()->GetValue( value
, item
, col
);
677 m_editorCtrl
= CreateEditorCtrl( dv_ctrl
->GetMainWindow(), labelRect
, value
);
679 // there might be no editor control for the given item
683 wxDataViewEditorCtrlEvtHandler
*handler
=
684 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
686 m_editorCtrl
->PushEventHandler( handler
);
688 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
689 handler
->SetFocusOnIdle();
691 m_editorCtrl
->SetFocus();
694 // Now we should send Editing Started event
695 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv_ctrl
->GetId() );
696 event
.SetDataViewColumn( GetOwner() );
697 event
.SetModel( dv_ctrl
->GetModel() );
698 event
.SetItem( item
);
699 event
.SetEventObject( dv_ctrl
);
700 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
705 void wxDataViewRendererBase::DestroyEditControl()
707 // Remove our event handler first to prevent it from (recursively) calling
708 // us again as it would do via a call to FinishEditing() when the editor
709 // loses focus when we hide it below.
710 wxEvtHandler
* const handler
= m_editorCtrl
->PopEventHandler();
712 // Hide the control immediately but don't delete it yet as there could be
713 // some pending messages for it.
714 m_editorCtrl
->Hide();
716 wxPendingDelete
.Append(handler
);
717 wxPendingDelete
.Append(m_editorCtrl
);
719 // Ensure that DestroyEditControl() is not called again for this control.
720 m_editorCtrl
.Release();
723 void wxDataViewRendererBase::CancelEditing()
728 DestroyEditControl();
731 bool wxDataViewRendererBase::FinishEditing()
737 GetValueFromEditorCtrl( m_editorCtrl
, value
);
739 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
741 DestroyEditControl();
743 dv_ctrl
->GetMainWindow()->SetFocus();
745 bool isValid
= Validate(value
);
746 unsigned int col
= GetOwner()->GetModelColumn();
748 // Now we should send Editing Done event
749 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv_ctrl
->GetId() );
750 event
.SetDataViewColumn( GetOwner() );
751 event
.SetModel( dv_ctrl
->GetModel() );
752 event
.SetItem( m_item
);
753 event
.SetValue( value
);
754 event
.SetColumn( col
);
755 event
.SetEditCanceled( !isValid
);
756 event
.SetEventObject( dv_ctrl
);
757 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
759 if ( isValid
&& event
.IsAllowed() )
761 dv_ctrl
->GetModel()->ChangeValue(value
, m_item
, col
);
768 void wxDataViewRendererBase::PrepareForItem(const wxDataViewModel
*model
,
769 const wxDataViewItem
& item
,
773 model
->GetValue(value
, item
, column
);
776 wxDataViewItemAttr attr
;
777 model
->GetAttr(item
, column
, attr
);
780 SetEnabled(model
->IsEnabled(item
, column
));
784 // ----------------------------------------------------------------------------
785 // wxDataViewCustomRendererBase
786 // ----------------------------------------------------------------------------
788 bool wxDataViewCustomRendererBase::ActivateCell(const wxRect
& cell
,
789 wxDataViewModel
*model
,
790 const wxDataViewItem
& item
,
792 const wxMouseEvent
* mouseEvent
)
794 // Compatibility code
796 return LeftClick(mouseEvent
->GetPosition(), cell
, model
, item
, col
);
798 return Activate(cell
, model
, item
, col
);
801 void wxDataViewCustomRendererBase::RenderBackground(wxDC
* dc
, const wxRect
& rect
)
803 if ( !m_attr
.HasBackgroundColour() )
806 const wxColour
& colour
= m_attr
.GetBackgroundColour();
807 wxDCPenChanger
changePen(*dc
, colour
);
808 wxDCBrushChanger
changeBrush(*dc
, colour
);
810 dc
->DrawRectangle(rect
);
814 wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell
, wxDC
*dc
, int state
)
816 wxCHECK_RET( dc
, "no DC to draw on in custom renderer?" );
818 // adjust the rectangle ourselves to account for the alignment
819 wxRect rectItem
= rectCell
;
820 const int align
= GetAlignment();
821 if ( align
!= wxDVR_DEFAULT_ALIGNMENT
)
823 const wxSize size
= GetSize();
825 // take alignment into account only if there is enough space, otherwise
826 // show as much contents as possible
828 // notice that many existing renderers (e.g. wxDataViewSpinRenderer)
829 // return hard-coded size which can be more than they need and if we
830 // trusted their GetSize() we'd draw the text out of cell bounds
833 if ( size
.x
>= 0 && size
.x
< rectCell
.width
)
835 if ( align
& wxALIGN_CENTER_HORIZONTAL
)
836 rectItem
.x
+= (rectCell
.width
- size
.x
)/2;
837 else if ( align
& wxALIGN_RIGHT
)
838 rectItem
.x
+= rectCell
.width
- size
.x
;
839 // else: wxALIGN_LEFT is the default
841 rectItem
.width
= size
.x
;
844 if ( size
.y
>= 0 && size
.y
< rectCell
.height
)
846 if ( align
& wxALIGN_CENTER_VERTICAL
)
847 rectItem
.y
+= (rectCell
.height
- size
.y
)/2;
848 else if ( align
& wxALIGN_BOTTOM
)
849 rectItem
.y
+= rectCell
.height
- size
.y
;
850 // else: wxALIGN_TOP is the default
852 rectItem
.height
= size
.y
;
857 // set up the DC attributes
859 // override custom foreground with the standard one for the selected items
860 // because we currently don't allow changing the selection background and
861 // custom colours may be unreadable on it
863 if ( state
& wxDATAVIEW_CELL_SELECTED
)
864 col
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
865 else if ( m_attr
.HasColour() )
866 col
= m_attr
.GetColour();
867 else // use default foreground
868 col
= GetOwner()->GetOwner()->GetForegroundColour();
870 wxDCTextColourChanger
changeFg(*dc
, col
);
872 wxDCFontChanger
changeFont(*dc
);
873 if ( m_attr
.HasFont() )
874 changeFont
.Set(m_attr
.GetEffectiveFont(dc
->GetFont()));
876 Render(rectItem
, dc
, state
);
879 wxSize
wxDataViewCustomRendererBase::GetTextExtent(const wxString
& str
) const
881 const wxDataViewCtrl
*view
= GetView();
883 if ( m_attr
.HasFont() )
885 wxFont
font(m_attr
.GetEffectiveFont(view
->GetFont()));
887 view
->GetTextExtent(str
, &size
.x
, &size
.y
, NULL
, NULL
, &font
);
892 return view
->GetTextExtent(str
);
897 wxDataViewCustomRendererBase::RenderText(const wxString
& text
,
903 wxRect rectText
= rect
;
904 rectText
.x
+= xoffset
;
905 rectText
.width
-= xoffset
;
907 // check if we want to ellipsize the text if it doesn't fit
908 wxString ellipsizedText
;
909 if ( GetEllipsizeMode() != wxELLIPSIZE_NONE
)
911 ellipsizedText
= wxControl::Ellipsize
917 wxELLIPSIZE_FLAGS_NONE
921 // get the alignment to use
922 int align
= GetAlignment();
923 if ( align
== wxDVR_DEFAULT_ALIGNMENT
)
925 // if we don't have an explicit alignment ourselves, use that of the
926 // column in horizontal direction and default vertical alignment
927 align
= GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
930 dc
->DrawLabel(ellipsizedText
.empty() ? text
: ellipsizedText
,
934 //-----------------------------------------------------------------------------
935 // wxDataViewEditorCtrlEvtHandler
936 //-----------------------------------------------------------------------------
938 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
939 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
940 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
941 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
942 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
945 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
949 m_focusOnIdle
= false;
950 if (wxWindow::FindFocus() != m_editorCtrl
)
951 m_editorCtrl
->SetFocus();
957 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
960 m_owner
->FinishEditing();
963 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
965 switch ( event
.m_keyCode
)
969 m_owner
->FinishEditing();
975 m_owner
->CancelEditing();
983 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
988 m_owner
->FinishEditing();
994 // ---------------------------------------------------------
995 // wxDataViewColumnBase
996 // ---------------------------------------------------------
998 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
999 unsigned int model_column
)
1001 m_renderer
= renderer
;
1002 m_model_column
= model_column
;
1004 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
1007 wxDataViewColumnBase::~wxDataViewColumnBase()
1012 // ---------------------------------------------------------
1013 // wxDataViewCtrlBase
1014 // ---------------------------------------------------------
1016 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
1018 wxDataViewCtrlBase::wxDataViewCtrlBase()
1021 m_expander_column
= 0;
1025 wxDataViewCtrlBase::~wxDataViewCtrlBase()
1034 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
1038 m_model
->DecRef(); // discard old model, if any
1041 // add our own reference to the new model:
1051 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
1056 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
1061 void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem
& item
)
1063 if (!m_model
) return;
1065 if (!item
.IsOk()) return;
1067 wxVector
<wxDataViewItem
> parentChain
;
1069 // at first we get all the parents of the selected item
1070 wxDataViewItem parent
= m_model
->GetParent(item
);
1071 while (parent
.IsOk())
1073 parentChain
.push_back(parent
);
1074 parent
= m_model
->GetParent(parent
);
1077 // then we expand the parents, starting at the root
1078 while (!parentChain
.empty())
1080 Expand(parentChain
.back());
1081 parentChain
.pop_back();
1085 wxDataViewItem
wxDataViewCtrlBase::GetCurrentItem() const
1087 return HasFlag(wxDV_MULTIPLE
) ? DoGetCurrentItem()
1091 void wxDataViewCtrlBase::SetCurrentItem(const wxDataViewItem
& item
)
1093 wxCHECK_RET( item
.IsOk(), "Can't make current an invalid item." );
1095 if ( HasFlag(wxDV_MULTIPLE
) )
1096 DoSetCurrentItem(item
);
1101 wxDataViewItem
wxDataViewCtrlBase::GetSelection() const
1103 if ( GetSelectedItemsCount() != 1 )
1104 return wxDataViewItem();
1106 wxDataViewItemArray selections
;
1107 GetSelections(selections
);
1108 return selections
[0];
1112 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
1113 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1115 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1116 new wxDataViewTextRenderer( wxT("string"), mode
),
1117 model_column
, width
, align
, flags
);
1118 AppendColumn( ret
);
1123 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
1124 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1126 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1127 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1128 model_column
, width
, align
, flags
);
1129 AppendColumn( ret
);
1134 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
1135 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1137 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1138 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1139 model_column
, width
, align
, flags
);
1140 AppendColumn( ret
);
1145 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
1146 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1148 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1149 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1150 model_column
, width
, align
, flags
);
1151 AppendColumn( ret
);
1156 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
1157 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1159 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1160 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1161 model_column
, width
, align
, flags
);
1162 AppendColumn( ret
);
1167 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
1168 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1170 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1171 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1172 model_column
, width
, align
, flags
);
1173 AppendColumn( ret
);
1178 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1179 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1181 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1182 new wxDataViewTextRenderer( wxT("string"), mode
),
1183 model_column
, width
, align
, flags
);
1184 AppendColumn( ret
);
1189 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1190 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1192 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1193 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1194 model_column
, width
, align
, flags
);
1195 AppendColumn( ret
);
1200 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1201 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1203 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1204 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1205 model_column
, width
, align
, flags
);
1206 AppendColumn( ret
);
1211 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1212 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1214 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1215 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1216 model_column
, width
, align
, flags
);
1217 AppendColumn( ret
);
1222 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1223 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1225 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1226 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1227 model_column
, width
, align
, flags
);
1228 AppendColumn( ret
);
1233 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1234 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1236 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1237 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1238 model_column
, width
, align
, flags
);
1239 AppendColumn( ret
);
1244 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1245 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1247 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1248 new wxDataViewTextRenderer( wxT("string"), mode
),
1249 model_column
, width
, align
, flags
);
1250 PrependColumn( ret
);
1255 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1256 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1258 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1259 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1260 model_column
, width
, align
, flags
);
1261 PrependColumn( ret
);
1266 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1267 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1270 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1271 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1272 model_column
, width
, align
, flags
);
1273 PrependColumn( ret
);
1278 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1279 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1281 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1282 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1283 model_column
, width
, align
, flags
);
1284 PrependColumn( ret
);
1289 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1290 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1292 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1293 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1294 model_column
, width
, align
, flags
);
1295 PrependColumn( ret
);
1300 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1301 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1303 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1304 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1305 model_column
, width
, align
, flags
);
1306 PrependColumn( ret
);
1311 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1312 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1314 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1315 new wxDataViewTextRenderer( wxT("string"), mode
),
1316 model_column
, width
, align
, flags
);
1317 PrependColumn( ret
);
1322 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1323 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1325 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1326 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1327 model_column
, width
, align
, flags
);
1328 PrependColumn( ret
);
1333 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1334 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1336 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1337 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1338 model_column
, width
, align
, flags
);
1339 PrependColumn( ret
);
1344 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1345 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1347 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1348 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1349 model_column
, width
, align
, flags
);
1350 PrependColumn( ret
);
1355 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1356 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1358 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1359 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1360 model_column
, width
, align
, flags
);
1361 PrependColumn( ret
);
1366 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1367 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1369 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1370 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1371 model_column
, width
, align
, flags
);
1372 PrependColumn( ret
);
1377 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1379 col
->SetOwner( (wxDataViewCtrl
*) this );
1384 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1386 col
->SetOwner( (wxDataViewCtrl
*) this );
1391 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1393 col
->SetOwner( (wxDataViewCtrl
*) this );
1397 void wxDataViewCtrlBase::StartEditor(const wxDataViewItem
& item
, unsigned int column
)
1399 EditItem(item
, GetColumn(column
));
1402 // ---------------------------------------------------------
1404 // ---------------------------------------------------------
1406 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1408 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
);
1410 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
);
1411 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
);
1412 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
);
1413 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
);
1414 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
);
1415 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
);
1416 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, wxDataViewEvent
);
1417 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
);
1418 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
);
1420 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
);
1422 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
);
1423 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
);
1424 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
);
1425 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
);
1427 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, wxDataViewEvent
);
1429 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
);
1430 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, wxDataViewEvent
);
1431 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, wxDataViewEvent
);
1435 // -------------------------------------
1436 // wxDataViewSpinRenderer
1437 // -------------------------------------
1439 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1440 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1446 wxWindow
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1449 wxSize size
= labelRect
.GetSize();
1451 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1454 str
.Printf( wxT("%d"), (int) l
);
1455 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1456 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1458 size
= sc
->GetSize();
1459 wxPoint pt
= sc
->GetPosition();
1460 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1466 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1468 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1469 long l
= sc
->GetValue();
1474 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1477 str
.Printf(wxT("%d"), (int) m_data
);
1478 RenderText( str
, 0, rect
, dc
, state
);
1482 wxSize
wxDataViewSpinRenderer::GetSize() const
1484 wxSize sz
= GetTextExtent(wxString::Format("%d", (int)m_data
));
1486 // Allow some space for the spin buttons, which is approximately the size
1487 // of a scrollbar (and getting pixel-exact value would be complicated).
1488 // Also add some whitespace between the text and the button:
1489 sz
.x
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1490 sz
.x
+= GetTextExtent("M").x
;
1495 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1497 m_data
= value
.GetLong();
1501 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1507 // -------------------------------------
1508 // wxDataViewChoiceRenderer
1509 // -------------------------------------
1511 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
1513 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1514 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1516 m_choices
= choices
;
1519 wxWindow
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1521 wxChoice
* c
= new wxChoice
1525 labelRect
.GetTopLeft(),
1526 wxSize(labelRect
.GetWidth(), -1),
1529 c
->Move(labelRect
.GetRight() - c
->GetRect().width
, wxDefaultCoord
);
1530 c
->SetStringSelection( value
.GetString() );
1534 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1536 wxChoice
*c
= (wxChoice
*) editor
;
1537 wxString s
= c
->GetStringSelection();
1542 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1544 RenderText( m_data
, 0, rect
, dc
, state
);
1548 wxSize
wxDataViewChoiceRenderer::GetSize() const
1552 for ( wxArrayString::const_iterator i
= m_choices
.begin(); i
!= m_choices
.end(); ++i
)
1553 sz
.IncTo(GetTextExtent(*i
));
1555 // Allow some space for the right-side button, which is approximately the
1556 // size of a scrollbar (and getting pixel-exact value would be complicated).
1557 // Also add some whitespace between the text and the button:
1558 sz
.x
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1559 sz
.x
+= GetTextExtent("M").x
;
1564 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1566 m_data
= value
.GetString();
1570 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1576 // ----------------------------------------------------------------------------
1577 // wxDataViewChoiceByIndexRenderer
1578 // ----------------------------------------------------------------------------
1580 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
1581 wxDataViewCellMode mode
, int alignment
) :
1582 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
1586 wxWindow
* wxDataViewChoiceByIndexRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1588 wxVariant string_value
= GetChoice( value
.GetLong() );
1590 return wxDataViewChoiceRenderer::CreateEditorCtrl( parent
, labelRect
, string_value
);
1593 bool wxDataViewChoiceByIndexRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1595 wxVariant string_value
;
1596 if (!wxDataViewChoiceRenderer::GetValueFromEditorCtrl( editor
, string_value
))
1599 value
= (long) GetChoices().Index( string_value
.GetString() );
1603 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
1605 wxVariant string_value
= GetChoice( value
.GetLong() );
1606 return wxDataViewChoiceRenderer::SetValue( string_value
);
1609 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
1611 wxVariant string_value
;
1612 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
1615 value
= (long) GetChoices().Index( string_value
.GetString() );
1621 // ---------------------------------------------------------
1622 // wxDataViewDateRenderer
1623 // ---------------------------------------------------------
1625 #if (defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)) && wxUSE_DATEPICKCTRL
1627 wxDataViewDateRenderer::wxDataViewDateRenderer(const wxString
& varianttype
,
1628 wxDataViewCellMode mode
, int align
)
1629 : wxDataViewCustomRenderer(varianttype
, mode
, align
)
1634 wxDataViewDateRenderer::CreateEditorCtrl(wxWindow
*parent
, wxRect labelRect
, const wxVariant
& value
)
1636 return new wxDatePickerCtrl
1640 value
.GetDateTime(),
1641 labelRect
.GetTopLeft(),
1646 bool wxDataViewDateRenderer::GetValueFromEditorCtrl(wxWindow
*editor
, wxVariant
& value
)
1648 wxDatePickerCtrl
*ctrl
= static_cast<wxDatePickerCtrl
*>(editor
);
1649 value
= ctrl
->GetValue();
1653 bool wxDataViewDateRenderer::SetValue(const wxVariant
& value
)
1655 m_date
= value
.GetDateTime();
1659 bool wxDataViewDateRenderer::GetValue(wxVariant
& value
) const
1665 bool wxDataViewDateRenderer::Render(wxRect cell
, wxDC
* dc
, int state
)
1667 wxString tmp
= m_date
.FormatDate();
1668 RenderText( tmp
, 0, cell
, dc
, state
);
1672 wxSize
wxDataViewDateRenderer::GetSize() const
1674 return GetTextExtent(m_date
.FormatDate());
1677 #endif // (defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)) && wxUSE_DATEPICKCTRL
1679 //-----------------------------------------------------------------------------
1680 // wxDataViewListStore
1681 //-----------------------------------------------------------------------------
1683 wxDataViewListStore::wxDataViewListStore()
1687 wxDataViewListStore::~wxDataViewListStore()
1689 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1690 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1692 wxDataViewListStoreLine
* line
= *it
;
1697 void wxDataViewListStore::PrependColumn( const wxString
&varianttype
)
1699 m_cols
.Insert( varianttype
, 0 );
1702 void wxDataViewListStore::InsertColumn( unsigned int pos
, const wxString
&varianttype
)
1704 m_cols
.Insert( varianttype
, pos
);
1707 void wxDataViewListStore::AppendColumn( const wxString
&varianttype
)
1709 m_cols
.Add( varianttype
);
1712 unsigned int wxDataViewListStore::GetColumnCount() const
1714 return m_cols
.GetCount();
1717 wxString
wxDataViewListStore::GetColumnType( unsigned int pos
) const
1722 void wxDataViewListStore::AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1724 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1725 line
->m_values
= values
;
1726 m_data
.push_back( line
);
1731 void wxDataViewListStore::PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1733 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1734 line
->m_values
= values
;
1735 m_data
.insert( m_data
.begin(), line
);
1740 void wxDataViewListStore::InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
,
1741 wxClientData
*data
)
1743 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1744 line
->m_values
= values
;
1745 m_data
.insert( m_data
.begin()+row
, line
);
1750 void wxDataViewListStore::DeleteItem( unsigned int row
)
1752 wxVector
<wxDataViewListStoreLine
*>::iterator it
= m_data
.begin() + row
;
1759 void wxDataViewListStore::DeleteAllItems()
1761 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1762 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1764 wxDataViewListStoreLine
* line
= *it
;
1773 void wxDataViewListStore::GetValueByRow( wxVariant
&value
, unsigned int row
, unsigned int col
) const
1775 wxDataViewListStoreLine
*line
= m_data
[row
];
1776 value
= line
->m_values
[col
];
1779 bool wxDataViewListStore::SetValueByRow( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1781 wxDataViewListStoreLine
*line
= m_data
[row
];
1782 line
->m_values
[col
] = value
;
1787 //-----------------------------------------------------------------------------
1788 // wxDataViewListCtrl
1789 //-----------------------------------------------------------------------------
1791 IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl
,wxDataViewCtrl
)
1793 BEGIN_EVENT_TABLE(wxDataViewListCtrl
,wxDataViewCtrl
)
1794 EVT_SIZE( wxDataViewListCtrl::OnSize
)
1797 wxDataViewListCtrl::wxDataViewListCtrl()
1801 wxDataViewListCtrl::wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
1802 const wxPoint
& pos
, const wxSize
& size
, long style
,
1803 const wxValidator
& validator
)
1805 Create( parent
, id
, pos
, size
, style
, validator
);
1808 wxDataViewListCtrl::~wxDataViewListCtrl()
1813 bool wxDataViewListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1814 const wxPoint
& pos
, const wxSize
& size
, long style
,
1815 const wxValidator
& validator
)
1817 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
1820 wxDataViewListStore
*store
= new wxDataViewListStore
;
1821 AssociateModel( store
);
1827 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1829 GetStore()->AppendColumn( varianttype
);
1830 return wxDataViewCtrl::AppendColumn( column
);
1833 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1835 GetStore()->PrependColumn( varianttype
);
1836 return wxDataViewCtrl::PrependColumn( column
);
1839 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
)
1841 GetStore()->InsertColumn( pos
, varianttype
);
1842 return wxDataViewCtrl::InsertColumn( pos
, column
);
1845 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*col
)
1847 return PrependColumn( col
, "string" );
1850 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
1852 return InsertColumn( pos
, col
, "string" );
1855 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*col
)
1857 return AppendColumn( col
, "string" );
1860 wxDataViewColumn
*wxDataViewListCtrl::AppendTextColumn( const wxString
&label
,
1861 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1863 GetStore()->AppendColumn( wxT("string") );
1865 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1866 new wxDataViewTextRenderer( wxT("string"), mode
),
1867 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1869 wxDataViewCtrl::AppendColumn( ret
);
1874 wxDataViewColumn
*wxDataViewListCtrl::AppendToggleColumn( const wxString
&label
,
1875 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1877 GetStore()->AppendColumn( wxT("bool") );
1879 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1880 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1881 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1883 wxDataViewCtrl::AppendColumn( ret
);
1888 wxDataViewColumn
*wxDataViewListCtrl::AppendProgressColumn( const wxString
&label
,
1889 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1891 GetStore()->AppendColumn( wxT("long") );
1893 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1894 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1895 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1897 wxDataViewCtrl::AppendColumn( ret
);
1902 wxDataViewColumn
*wxDataViewListCtrl::AppendIconTextColumn( const wxString
&label
,
1903 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1905 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
1907 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1908 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1909 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1911 wxDataViewCtrl::AppendColumn( ret
);
1916 void wxDataViewListCtrl::OnSize( wxSizeEvent
&event
)
1921 //-----------------------------------------------------------------------------
1922 // wxDataViewTreeStore
1923 //-----------------------------------------------------------------------------
1925 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1926 wxDataViewTreeStoreNode
*parent
,
1927 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1935 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1941 #include "wx/listimpl.cpp"
1942 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1944 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1945 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1946 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1947 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1949 m_iconExpanded
= expanded
;
1950 m_isExpanded
= false;
1951 m_children
.DeleteContents(true);
1954 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1958 //-----------------------------------------------------------------------------
1960 wxDataViewTreeStore::wxDataViewTreeStore()
1962 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1965 wxDataViewTreeStore::~wxDataViewTreeStore()
1970 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1971 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1973 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1974 if (!parent_node
) return wxDataViewItem(0);
1976 wxDataViewTreeStoreNode
*node
=
1977 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1978 parent_node
->GetChildren().Append( node
);
1980 return node
->GetItem();
1983 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1984 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1986 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1987 if (!parent_node
) return wxDataViewItem(0);
1989 wxDataViewTreeStoreNode
*node
=
1990 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1991 parent_node
->GetChildren().Insert( node
);
1993 return node
->GetItem();
1997 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& parent
,
1998 const wxDataViewItem
& previous
,
1999 const wxString
& text
,
2003 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2004 if (!parent_node
) return wxDataViewItem(0);
2006 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
2007 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
2008 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
2010 wxDataViewTreeStoreNode
*node
=
2011 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
2012 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
2014 return node
->GetItem();
2017 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
2018 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
2019 wxClientData
*data
)
2021 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2022 if (!parent_node
) return wxDataViewItem(0);
2024 wxDataViewTreeStoreContainerNode
*node
=
2025 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
2026 parent_node
->GetChildren().Insert( node
);
2028 return node
->GetItem();
2032 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
2033 const wxString
&text
,
2035 const wxIcon
& expanded
,
2036 wxClientData
* data
)
2038 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2039 if (!parent_node
) return wxDataViewItem(0);
2041 wxDataViewTreeStoreContainerNode
*node
=
2042 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
2043 parent_node
->GetChildren().Append( node
);
2045 return node
->GetItem();
2049 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& parent
,
2050 const wxDataViewItem
& previous
,
2051 const wxString
& text
,
2053 const wxIcon
& expanded
,
2054 wxClientData
* data
)
2056 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2057 if (!parent_node
) return wxDataViewItem(0);
2059 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
2060 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
2061 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
2063 wxDataViewTreeStoreContainerNode
*node
=
2064 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
2065 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
2067 return node
->GetItem();
2070 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
& item
) const
2072 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2073 if (!node
) return false;
2075 return node
->IsContainer();
2078 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
2080 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2081 if (!parent_node
) return wxDataViewItem(0);
2083 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
2085 return wxDataViewItem(node
->GetData());
2087 return wxDataViewItem(0);
2090 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
2092 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
2093 if (!node
) return -1;
2095 if (!node
->IsContainer())
2098 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
2099 return (int) container_node
->GetChildren().GetCount();
2102 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2104 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2107 node
->SetText( text
);
2110 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
2112 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2113 if (!node
) return wxEmptyString
;
2115 return node
->GetText();
2118 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2120 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2123 node
->SetIcon( icon
);
2126 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
2128 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2129 if (!node
) return wxNullIcon
;
2131 return node
->GetIcon();
2134 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2136 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2139 node
->SetExpandedIcon( icon
);
2142 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
2144 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2145 if (!node
) return wxNullIcon
;
2147 return node
->GetExpandedIcon();
2150 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
2152 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2155 node
->SetData( data
);
2158 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
2160 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2161 if (!node
) return NULL
;
2163 return node
->GetData();
2166 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
2168 if (!item
.IsOk()) return;
2170 wxDataViewItem parent_item
= GetParent( item
);
2172 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
2173 if (!parent_node
) return;
2175 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2178 parent_node
->GetChildren().DeleteObject( node
);
2181 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
2183 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2186 node
->GetChildren().clear();
2189 void wxDataViewTreeStore::DeleteAllItems()
2191 DeleteChildren(wxDataViewItem(m_root
));
2195 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
2196 const wxDataViewItem
&item
,
2197 unsigned int WXUNUSED(col
)) const
2199 // if (col != 0) return;
2201 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2204 wxIcon
icon( node
->GetIcon());
2205 if (node
->IsContainer())
2207 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
2208 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
2209 icon
= container
->GetExpandedIcon();
2212 wxDataViewIconText
data( node
->GetText(), icon
);
2218 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
2219 const wxDataViewItem
& item
,
2220 unsigned int WXUNUSED(col
))
2222 // if (col != 0) return false;
2224 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2225 if (!node
) return false;
2227 wxDataViewIconText data
;
2231 node
->SetText( data
.GetText() );
2232 node
->SetIcon( data
.GetIcon() );
2237 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
2239 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2240 if (!node
) return wxDataViewItem(0);
2242 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
2243 if (!parent
) return wxDataViewItem(0);
2245 if (parent
== m_root
)
2246 return wxDataViewItem(0);
2248 return parent
->GetItem();
2251 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
2253 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2254 if (!node
) return 0;
2256 wxDataViewTreeStoreNodeList::iterator iter
;
2257 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2259 wxDataViewTreeStoreNode
* child
= *iter
;
2260 children
.Add( child
->GetItem() );
2263 return node
->GetChildren().GetCount();
2266 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
2267 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) ) const
2269 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
2270 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
2272 if (!node1
|| !node2
)
2275 wxDataViewTreeStoreContainerNode
* parent1
=
2276 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
2277 wxDataViewTreeStoreContainerNode
* parent2
=
2278 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
2280 if (parent1
!= parent2
)
2282 wxLogError( wxT("Comparing items with different parent.") );
2286 if (node1
->IsContainer() && !node2
->IsContainer())
2289 if (node2
->IsContainer() && !node1
->IsContainer())
2292 return parent1
->GetChildren().IndexOf( node1
) - parent2
->GetChildren().IndexOf( node2
);
2295 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
2300 return (wxDataViewTreeStoreNode
*) item
.GetID();
2303 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
2306 return (wxDataViewTreeStoreContainerNode
*) m_root
;
2308 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
2310 if (!node
->IsContainer())
2313 return (wxDataViewTreeStoreContainerNode
*) node
;
2316 //-----------------------------------------------------------------------------
2317 // wxDataViewTreeCtrl
2318 //-----------------------------------------------------------------------------
2320 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2322 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2323 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
2324 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
2325 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
2328 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2329 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2331 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
2334 // create the standard model and a column in the tree
2335 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
2336 AssociateModel( store
);
2339 AppendIconTextColumn
2341 wxString(), // no label (header is not shown anyhow)
2342 0, // the only model column
2343 wxDATAVIEW_CELL_EDITABLE
,
2344 -1, // default width
2345 wxALIGN_NOT
, // and alignment
2352 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
2353 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2355 wxDataViewItem res
= GetStore()->
2356 AppendItem( parent
, text
, GetImage(iconIndex
), data
);
2358 GetStore()->ItemAdded( parent
, res
);
2363 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
2364 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2366 wxDataViewItem res
= GetStore()->
2367 PrependItem( parent
, text
, GetImage(iconIndex
), data
);
2369 GetStore()->ItemAdded( parent
, res
);
2374 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2375 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2377 wxDataViewItem res
= GetStore()->
2378 InsertItem( parent
, previous
, text
, GetImage(iconIndex
), data
);
2380 GetStore()->ItemAdded( parent
, res
);
2385 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
2386 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2388 wxDataViewItem res
= GetStore()->
2389 PrependContainer( parent
, text
,
2390 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2392 GetStore()->ItemAdded( parent
, res
);
2397 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
2398 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2400 wxDataViewItem res
= GetStore()->
2401 AppendContainer( parent
, text
,
2402 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2404 GetStore()->ItemAdded( parent
, res
);
2409 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2410 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2412 wxDataViewItem res
= GetStore()->
2413 InsertContainer( parent
, previous
, text
,
2414 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2416 GetStore()->ItemAdded( parent
, res
);
2421 void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2423 GetStore()->SetItemText(item
,text
);
2426 GetStore()->ValueChanged( item
, 0 );
2429 void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2431 GetStore()->SetItemIcon(item
,icon
);
2434 GetStore()->ValueChanged( item
, 0 );
2437 void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2439 GetStore()->SetItemExpandedIcon(item
,icon
);
2442 GetStore()->ValueChanged( item
, 0 );
2445 void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem
& item
)
2447 wxDataViewItem parent_item
= GetStore()->GetParent( item
);
2449 GetStore()->DeleteItem(item
);
2452 GetStore()->ItemDeleted( parent_item
, item
);
2455 void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem
& item
)
2457 wxDataViewTreeStoreContainerNode
*node
= GetStore()->FindContainerNode( item
);
2460 wxDataViewItemArray array
;
2461 wxDataViewTreeStoreNodeList::iterator iter
;
2462 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2464 wxDataViewTreeStoreNode
* child
= *iter
;
2465 array
.Add( child
->GetItem() );
2468 GetStore()->DeleteChildren( item
);
2471 GetStore()->ItemsDeleted( item
, array
);
2474 void wxDataViewTreeCtrl::DeleteAllItems()
2476 GetStore()->DeleteAllItems();
2478 GetStore()->Cleared();
2481 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
2483 if (HasImageList()) return;
2485 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2486 if (!container
) return;
2488 container
->SetExpanded( true );
2490 GetStore()->ItemChanged( event
.GetItem() );
2493 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
2495 if (HasImageList()) return;
2497 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2498 if (!container
) return;
2500 container
->SetExpanded( false );
2502 GetStore()->ItemChanged( event
.GetItem() );
2505 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
2507 #if defined(wxUSE_GENERICDATAVIEWCTRL)
2508 // automatically resize our only column to take the entire control width
2509 if ( GetColumnCount() )
2511 wxSize size
= GetClientSize();
2512 GetColumn(0)->SetWidth(size
.x
);
2518 #endif // wxUSE_DATAVIEWCTRL