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
);
720 void wxDataViewRendererBase::CancelEditing()
725 DestroyEditControl();
728 bool wxDataViewRendererBase::FinishEditing()
734 GetValueFromEditorCtrl( m_editorCtrl
, value
);
736 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
738 DestroyEditControl();
740 dv_ctrl
->GetMainWindow()->SetFocus();
742 bool isValid
= Validate(value
);
743 unsigned int col
= GetOwner()->GetModelColumn();
745 // Now we should send Editing Done event
746 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv_ctrl
->GetId() );
747 event
.SetDataViewColumn( GetOwner() );
748 event
.SetModel( dv_ctrl
->GetModel() );
749 event
.SetItem( m_item
);
750 event
.SetValue( value
);
751 event
.SetColumn( col
);
752 event
.SetEditCanceled( !isValid
);
753 event
.SetEventObject( dv_ctrl
);
754 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
756 if ( isValid
&& event
.IsAllowed() )
758 dv_ctrl
->GetModel()->ChangeValue(value
, m_item
, col
);
765 void wxDataViewRendererBase::PrepareForItem(const wxDataViewModel
*model
,
766 const wxDataViewItem
& item
,
770 model
->GetValue(value
, item
, column
);
773 wxDataViewItemAttr attr
;
774 model
->GetAttr(item
, column
, attr
);
777 SetEnabled(model
->IsEnabled(item
, column
));
781 // ----------------------------------------------------------------------------
782 // wxDataViewCustomRendererBase
783 // ----------------------------------------------------------------------------
785 bool wxDataViewCustomRendererBase::ActivateCell(const wxRect
& cell
,
786 wxDataViewModel
*model
,
787 const wxDataViewItem
& item
,
789 const wxMouseEvent
* mouseEvent
)
791 // Compatibility code
793 return LeftClick(mouseEvent
->GetPosition(), cell
, model
, item
, col
);
795 return Activate(cell
, model
, item
, col
);
798 void wxDataViewCustomRendererBase::RenderBackground(wxDC
* dc
, const wxRect
& rect
)
800 if ( !m_attr
.HasBackgroundColour() )
803 const wxColour
& colour
= m_attr
.GetBackgroundColour();
804 wxDCPenChanger
changePen(*dc
, colour
);
805 wxDCBrushChanger
changeBrush(*dc
, colour
);
807 dc
->DrawRectangle(rect
);
811 wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell
, wxDC
*dc
, int state
)
813 wxCHECK_RET( dc
, "no DC to draw on in custom renderer?" );
815 // adjust the rectangle ourselves to account for the alignment
816 wxRect rectItem
= rectCell
;
817 const int align
= GetAlignment();
818 if ( align
!= wxDVR_DEFAULT_ALIGNMENT
)
820 const wxSize size
= GetSize();
822 // take alignment into account only if there is enough space, otherwise
823 // show as much contents as possible
825 // notice that many existing renderers (e.g. wxDataViewSpinRenderer)
826 // return hard-coded size which can be more than they need and if we
827 // trusted their GetSize() we'd draw the text out of cell bounds
830 if ( size
.x
>= 0 && size
.x
< rectCell
.width
)
832 if ( align
& wxALIGN_CENTER_HORIZONTAL
)
833 rectItem
.x
+= (rectCell
.width
- size
.x
)/2;
834 else if ( align
& wxALIGN_RIGHT
)
835 rectItem
.x
+= rectCell
.width
- size
.x
;
836 // else: wxALIGN_LEFT is the default
838 rectItem
.width
= size
.x
;
841 if ( size
.y
>= 0 && size
.y
< rectCell
.height
)
843 if ( align
& wxALIGN_CENTER_VERTICAL
)
844 rectItem
.y
+= (rectCell
.height
- size
.y
)/2;
845 else if ( align
& wxALIGN_BOTTOM
)
846 rectItem
.y
+= rectCell
.height
- size
.y
;
847 // else: wxALIGN_TOP is the default
849 rectItem
.height
= size
.y
;
854 // set up the DC attributes
856 // override custom foreground with the standard one for the selected items
857 // because we currently don't allow changing the selection background and
858 // custom colours may be unreadable on it
860 if ( state
& wxDATAVIEW_CELL_SELECTED
)
861 col
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
862 else if ( m_attr
.HasColour() )
863 col
= m_attr
.GetColour();
864 else // use default foreground
865 col
= GetOwner()->GetOwner()->GetForegroundColour();
867 wxDCTextColourChanger
changeFg(*dc
, col
);
869 wxDCFontChanger
changeFont(*dc
);
870 if ( m_attr
.HasFont() )
871 changeFont
.Set(m_attr
.GetEffectiveFont(dc
->GetFont()));
873 Render(rectItem
, dc
, state
);
876 wxSize
wxDataViewCustomRendererBase::GetTextExtent(const wxString
& str
) const
878 const wxDataViewCtrl
*view
= GetView();
880 if ( m_attr
.HasFont() )
882 wxFont
font(m_attr
.GetEffectiveFont(view
->GetFont()));
884 view
->GetTextExtent(str
, &size
.x
, &size
.y
, NULL
, NULL
, &font
);
889 return view
->GetTextExtent(str
);
894 wxDataViewCustomRendererBase::RenderText(const wxString
& text
,
900 wxRect rectText
= rect
;
901 rectText
.x
+= xoffset
;
902 rectText
.width
-= xoffset
;
904 // check if we want to ellipsize the text if it doesn't fit
905 wxString ellipsizedText
;
906 if ( GetEllipsizeMode() != wxELLIPSIZE_NONE
)
908 ellipsizedText
= wxControl::Ellipsize
914 wxELLIPSIZE_FLAGS_NONE
918 // get the alignment to use
919 int align
= GetAlignment();
920 if ( align
== wxDVR_DEFAULT_ALIGNMENT
)
922 // if we don't have an explicit alignment ourselves, use that of the
923 // column in horizontal direction and default vertical alignment
924 align
= GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
927 dc
->DrawLabel(ellipsizedText
.empty() ? text
: ellipsizedText
,
931 //-----------------------------------------------------------------------------
932 // wxDataViewEditorCtrlEvtHandler
933 //-----------------------------------------------------------------------------
935 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
936 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
937 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
938 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
939 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
942 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
946 m_focusOnIdle
= false;
947 if (wxWindow::FindFocus() != m_editorCtrl
)
948 m_editorCtrl
->SetFocus();
954 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
957 m_owner
->FinishEditing();
960 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
962 switch ( event
.m_keyCode
)
966 m_owner
->FinishEditing();
972 m_owner
->CancelEditing();
980 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
985 m_owner
->FinishEditing();
991 // ---------------------------------------------------------
992 // wxDataViewColumnBase
993 // ---------------------------------------------------------
995 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
996 unsigned int model_column
)
998 m_renderer
= renderer
;
999 m_model_column
= model_column
;
1001 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
1004 wxDataViewColumnBase::~wxDataViewColumnBase()
1009 // ---------------------------------------------------------
1010 // wxDataViewCtrlBase
1011 // ---------------------------------------------------------
1013 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
1015 wxDataViewCtrlBase::wxDataViewCtrlBase()
1018 m_expander_column
= 0;
1022 wxDataViewCtrlBase::~wxDataViewCtrlBase()
1031 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
1035 m_model
->DecRef(); // discard old model, if any
1038 // add our own reference to the new model:
1048 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
1053 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
1058 void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem
& item
)
1060 if (!m_model
) return;
1062 if (!item
.IsOk()) return;
1064 wxVector
<wxDataViewItem
> parentChain
;
1066 // at first we get all the parents of the selected item
1067 wxDataViewItem parent
= m_model
->GetParent(item
);
1068 while (parent
.IsOk())
1070 parentChain
.push_back(parent
);
1071 parent
= m_model
->GetParent(parent
);
1074 // then we expand the parents, starting at the root
1075 while (!parentChain
.empty())
1077 Expand(parentChain
.back());
1078 parentChain
.pop_back();
1082 wxDataViewItem
wxDataViewCtrlBase::GetCurrentItem() const
1084 return HasFlag(wxDV_MULTIPLE
) ? DoGetCurrentItem()
1088 void wxDataViewCtrlBase::SetCurrentItem(const wxDataViewItem
& item
)
1090 wxCHECK_RET( item
.IsOk(), "Can't make current an invalid item." );
1092 if ( HasFlag(wxDV_MULTIPLE
) )
1093 DoSetCurrentItem(item
);
1098 wxDataViewItem
wxDataViewCtrlBase::GetSelection() const
1100 if ( GetSelectedItemsCount() != 1 )
1101 return wxDataViewItem();
1103 wxDataViewItemArray selections
;
1104 GetSelections(selections
);
1105 return selections
[0];
1109 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
1110 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1112 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1113 new wxDataViewTextRenderer( wxT("string"), mode
),
1114 model_column
, width
, align
, flags
);
1115 AppendColumn( ret
);
1120 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
1121 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1123 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1124 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1125 model_column
, width
, align
, flags
);
1126 AppendColumn( ret
);
1131 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
1132 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1134 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1135 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1136 model_column
, width
, align
, flags
);
1137 AppendColumn( ret
);
1142 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
1143 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1145 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1146 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1147 model_column
, width
, align
, flags
);
1148 AppendColumn( ret
);
1153 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
1154 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1156 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1157 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1158 model_column
, width
, align
, flags
);
1159 AppendColumn( ret
);
1164 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
1165 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1167 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1168 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1169 model_column
, width
, align
, flags
);
1170 AppendColumn( ret
);
1175 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1176 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1178 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1179 new wxDataViewTextRenderer( wxT("string"), mode
),
1180 model_column
, width
, align
, flags
);
1181 AppendColumn( ret
);
1186 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1187 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1189 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1190 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1191 model_column
, width
, align
, flags
);
1192 AppendColumn( ret
);
1197 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1198 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1200 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1201 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1202 model_column
, width
, align
, flags
);
1203 AppendColumn( ret
);
1208 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1209 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1211 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1212 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1213 model_column
, width
, align
, flags
);
1214 AppendColumn( ret
);
1219 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1220 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1222 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1223 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1224 model_column
, width
, align
, flags
);
1225 AppendColumn( ret
);
1230 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1231 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1233 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1234 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1235 model_column
, width
, align
, flags
);
1236 AppendColumn( ret
);
1241 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1242 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1244 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1245 new wxDataViewTextRenderer( wxT("string"), mode
),
1246 model_column
, width
, align
, flags
);
1247 PrependColumn( ret
);
1252 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1253 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1255 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1256 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1257 model_column
, width
, align
, flags
);
1258 PrependColumn( ret
);
1263 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1264 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1267 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1268 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1269 model_column
, width
, align
, flags
);
1270 PrependColumn( ret
);
1275 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1276 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1278 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1279 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1280 model_column
, width
, align
, flags
);
1281 PrependColumn( ret
);
1286 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1287 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1289 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1290 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1291 model_column
, width
, align
, flags
);
1292 PrependColumn( ret
);
1297 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1298 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1300 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1301 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1302 model_column
, width
, align
, flags
);
1303 PrependColumn( ret
);
1308 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1309 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1311 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1312 new wxDataViewTextRenderer( wxT("string"), mode
),
1313 model_column
, width
, align
, flags
);
1314 PrependColumn( ret
);
1319 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1320 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1322 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1323 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1324 model_column
, width
, align
, flags
);
1325 PrependColumn( ret
);
1330 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1331 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1333 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1334 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1335 model_column
, width
, align
, flags
);
1336 PrependColumn( ret
);
1341 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1342 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1344 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1345 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1346 model_column
, width
, align
, flags
);
1347 PrependColumn( ret
);
1352 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1353 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1355 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1356 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1357 model_column
, width
, align
, flags
);
1358 PrependColumn( ret
);
1363 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1364 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1366 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1367 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1368 model_column
, width
, align
, flags
);
1369 PrependColumn( ret
);
1374 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1376 col
->SetOwner( (wxDataViewCtrl
*) this );
1381 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1383 col
->SetOwner( (wxDataViewCtrl
*) this );
1388 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1390 col
->SetOwner( (wxDataViewCtrl
*) this );
1394 void wxDataViewCtrlBase::StartEditor(const wxDataViewItem
& item
, unsigned int column
)
1396 EditItem(item
, GetColumn(column
));
1399 // ---------------------------------------------------------
1401 // ---------------------------------------------------------
1403 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1405 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
);
1407 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
);
1408 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
);
1409 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
);
1410 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
);
1411 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
);
1412 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
);
1413 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, wxDataViewEvent
);
1414 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
);
1415 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
);
1417 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
);
1419 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
);
1420 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
);
1421 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
);
1422 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
);
1424 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, wxDataViewEvent
);
1426 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
);
1427 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, wxDataViewEvent
);
1428 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, wxDataViewEvent
);
1432 // -------------------------------------
1433 // wxDataViewSpinRenderer
1434 // -------------------------------------
1436 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1437 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1443 wxWindow
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1446 wxSize size
= labelRect
.GetSize();
1448 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1451 str
.Printf( wxT("%d"), (int) l
);
1452 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1453 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1455 size
= sc
->GetSize();
1456 wxPoint pt
= sc
->GetPosition();
1457 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1463 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1465 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1466 long l
= sc
->GetValue();
1471 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1474 str
.Printf(wxT("%d"), (int) m_data
);
1475 RenderText( str
, 0, rect
, dc
, state
);
1479 wxSize
wxDataViewSpinRenderer::GetSize() const
1481 wxSize sz
= GetTextExtent(wxString::Format("%d", (int)m_data
));
1483 // Allow some space for the spin buttons, which is approximately the size
1484 // of a scrollbar (and getting pixel-exact value would be complicated).
1485 // Also add some whitespace between the text and the button:
1486 sz
.x
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1487 sz
.x
+= GetTextExtent("M").x
;
1492 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1494 m_data
= value
.GetLong();
1498 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1504 // -------------------------------------
1505 // wxDataViewChoiceRenderer
1506 // -------------------------------------
1508 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
1510 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1511 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1513 m_choices
= choices
;
1516 wxWindow
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1518 wxChoice
* c
= new wxChoice
1522 labelRect
.GetTopLeft(),
1523 wxSize(labelRect
.GetWidth(), -1),
1526 c
->Move(labelRect
.GetRight() - c
->GetRect().width
, wxDefaultCoord
);
1527 c
->SetStringSelection( value
.GetString() );
1531 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1533 wxChoice
*c
= (wxChoice
*) editor
;
1534 wxString s
= c
->GetStringSelection();
1539 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1541 RenderText( m_data
, 0, rect
, dc
, state
);
1545 wxSize
wxDataViewChoiceRenderer::GetSize() const
1549 for ( wxArrayString::const_iterator i
= m_choices
.begin(); i
!= m_choices
.end(); ++i
)
1550 sz
.IncTo(GetTextExtent(*i
));
1552 // Allow some space for the right-side button, which is approximately the
1553 // size of a scrollbar (and getting pixel-exact value would be complicated).
1554 // Also add some whitespace between the text and the button:
1555 sz
.x
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1556 sz
.x
+= GetTextExtent("M").x
;
1561 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1563 m_data
= value
.GetString();
1567 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1573 // ----------------------------------------------------------------------------
1574 // wxDataViewChoiceByIndexRenderer
1575 // ----------------------------------------------------------------------------
1577 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
1578 wxDataViewCellMode mode
, int alignment
) :
1579 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
1583 wxWindow
* wxDataViewChoiceByIndexRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1585 wxVariant string_value
= GetChoice( value
.GetLong() );
1587 return wxDataViewChoiceRenderer::CreateEditorCtrl( parent
, labelRect
, string_value
);
1590 bool wxDataViewChoiceByIndexRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1592 wxVariant string_value
;
1593 if (!wxDataViewChoiceRenderer::GetValueFromEditorCtrl( editor
, string_value
))
1596 value
= (long) GetChoices().Index( string_value
.GetString() );
1600 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
1602 wxVariant string_value
= GetChoice( value
.GetLong() );
1603 return wxDataViewChoiceRenderer::SetValue( string_value
);
1606 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
1608 wxVariant string_value
;
1609 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
1612 value
= (long) GetChoices().Index( string_value
.GetString() );
1618 // ---------------------------------------------------------
1619 // wxDataViewDateRenderer
1620 // ---------------------------------------------------------
1622 #if (defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)) && wxUSE_DATEPICKCTRL
1624 wxDataViewDateRenderer::wxDataViewDateRenderer(const wxString
& varianttype
,
1625 wxDataViewCellMode mode
, int align
)
1626 : wxDataViewCustomRenderer(varianttype
, mode
, align
)
1631 wxDataViewDateRenderer::CreateEditorCtrl(wxWindow
*parent
, wxRect labelRect
, const wxVariant
& value
)
1633 return new wxDatePickerCtrl
1637 value
.GetDateTime(),
1638 labelRect
.GetTopLeft(),
1643 bool wxDataViewDateRenderer::GetValueFromEditorCtrl(wxWindow
*editor
, wxVariant
& value
)
1645 wxDatePickerCtrl
*ctrl
= static_cast<wxDatePickerCtrl
*>(editor
);
1646 value
= ctrl
->GetValue();
1650 bool wxDataViewDateRenderer::SetValue(const wxVariant
& value
)
1652 m_date
= value
.GetDateTime();
1656 bool wxDataViewDateRenderer::GetValue(wxVariant
& value
) const
1662 bool wxDataViewDateRenderer::Render(wxRect cell
, wxDC
* dc
, int state
)
1664 wxString tmp
= m_date
.FormatDate();
1665 RenderText( tmp
, 0, cell
, dc
, state
);
1669 wxSize
wxDataViewDateRenderer::GetSize() const
1671 return GetTextExtent(m_date
.FormatDate());
1674 #endif // (defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)) && wxUSE_DATEPICKCTRL
1676 //-----------------------------------------------------------------------------
1677 // wxDataViewListStore
1678 //-----------------------------------------------------------------------------
1680 wxDataViewListStore::wxDataViewListStore()
1684 wxDataViewListStore::~wxDataViewListStore()
1686 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1687 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1689 wxDataViewListStoreLine
* line
= *it
;
1694 void wxDataViewListStore::PrependColumn( const wxString
&varianttype
)
1696 m_cols
.Insert( varianttype
, 0 );
1699 void wxDataViewListStore::InsertColumn( unsigned int pos
, const wxString
&varianttype
)
1701 m_cols
.Insert( varianttype
, pos
);
1704 void wxDataViewListStore::AppendColumn( const wxString
&varianttype
)
1706 m_cols
.Add( varianttype
);
1709 unsigned int wxDataViewListStore::GetColumnCount() const
1711 return m_cols
.GetCount();
1714 wxString
wxDataViewListStore::GetColumnType( unsigned int pos
) const
1719 void wxDataViewListStore::AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1721 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1722 line
->m_values
= values
;
1723 m_data
.push_back( line
);
1728 void wxDataViewListStore::PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1730 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1731 line
->m_values
= values
;
1732 m_data
.insert( m_data
.begin(), line
);
1737 void wxDataViewListStore::InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
,
1738 wxClientData
*data
)
1740 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1741 line
->m_values
= values
;
1742 m_data
.insert( m_data
.begin()+row
, line
);
1747 void wxDataViewListStore::DeleteItem( unsigned int row
)
1749 wxVector
<wxDataViewListStoreLine
*>::iterator it
= m_data
.begin() + row
;
1756 void wxDataViewListStore::DeleteAllItems()
1758 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1759 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1761 wxDataViewListStoreLine
* line
= *it
;
1770 void wxDataViewListStore::GetValueByRow( wxVariant
&value
, unsigned int row
, unsigned int col
) const
1772 wxDataViewListStoreLine
*line
= m_data
[row
];
1773 value
= line
->m_values
[col
];
1776 bool wxDataViewListStore::SetValueByRow( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1778 wxDataViewListStoreLine
*line
= m_data
[row
];
1779 line
->m_values
[col
] = value
;
1784 //-----------------------------------------------------------------------------
1785 // wxDataViewListCtrl
1786 //-----------------------------------------------------------------------------
1788 IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl
,wxDataViewCtrl
)
1790 BEGIN_EVENT_TABLE(wxDataViewListCtrl
,wxDataViewCtrl
)
1791 EVT_SIZE( wxDataViewListCtrl::OnSize
)
1794 wxDataViewListCtrl::wxDataViewListCtrl()
1798 wxDataViewListCtrl::wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
1799 const wxPoint
& pos
, const wxSize
& size
, long style
,
1800 const wxValidator
& validator
)
1802 Create( parent
, id
, pos
, size
, style
, validator
);
1805 wxDataViewListCtrl::~wxDataViewListCtrl()
1810 bool wxDataViewListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1811 const wxPoint
& pos
, const wxSize
& size
, long style
,
1812 const wxValidator
& validator
)
1814 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
1817 wxDataViewListStore
*store
= new wxDataViewListStore
;
1818 AssociateModel( store
);
1824 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1826 GetStore()->AppendColumn( varianttype
);
1827 return wxDataViewCtrl::AppendColumn( column
);
1830 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1832 GetStore()->PrependColumn( varianttype
);
1833 return wxDataViewCtrl::PrependColumn( column
);
1836 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
)
1838 GetStore()->InsertColumn( pos
, varianttype
);
1839 return wxDataViewCtrl::InsertColumn( pos
, column
);
1842 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*col
)
1844 return PrependColumn( col
, "string" );
1847 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
1849 return InsertColumn( pos
, col
, "string" );
1852 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*col
)
1854 return AppendColumn( col
, "string" );
1857 wxDataViewColumn
*wxDataViewListCtrl::AppendTextColumn( const wxString
&label
,
1858 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1860 GetStore()->AppendColumn( wxT("string") );
1862 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1863 new wxDataViewTextRenderer( wxT("string"), mode
),
1864 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1866 wxDataViewCtrl::AppendColumn( ret
);
1871 wxDataViewColumn
*wxDataViewListCtrl::AppendToggleColumn( const wxString
&label
,
1872 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1874 GetStore()->AppendColumn( wxT("bool") );
1876 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1877 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1878 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1880 wxDataViewCtrl::AppendColumn( ret
);
1885 wxDataViewColumn
*wxDataViewListCtrl::AppendProgressColumn( const wxString
&label
,
1886 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1888 GetStore()->AppendColumn( wxT("long") );
1890 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1891 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1892 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1894 wxDataViewCtrl::AppendColumn( ret
);
1899 wxDataViewColumn
*wxDataViewListCtrl::AppendIconTextColumn( const wxString
&label
,
1900 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1902 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
1904 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1905 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1906 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1908 wxDataViewCtrl::AppendColumn( ret
);
1913 void wxDataViewListCtrl::OnSize( wxSizeEvent
&event
)
1918 //-----------------------------------------------------------------------------
1919 // wxDataViewTreeStore
1920 //-----------------------------------------------------------------------------
1922 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1923 wxDataViewTreeStoreNode
*parent
,
1924 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1932 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1938 #include "wx/listimpl.cpp"
1939 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1941 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1942 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1943 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1944 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1946 m_iconExpanded
= expanded
;
1947 m_isExpanded
= false;
1948 m_children
.DeleteContents(true);
1951 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1955 //-----------------------------------------------------------------------------
1957 wxDataViewTreeStore::wxDataViewTreeStore()
1959 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1962 wxDataViewTreeStore::~wxDataViewTreeStore()
1967 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1968 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1970 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1971 if (!parent_node
) return wxDataViewItem(0);
1973 wxDataViewTreeStoreNode
*node
=
1974 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1975 parent_node
->GetChildren().Append( node
);
1977 return node
->GetItem();
1980 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1981 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1983 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1984 if (!parent_node
) return wxDataViewItem(0);
1986 wxDataViewTreeStoreNode
*node
=
1987 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1988 parent_node
->GetChildren().Insert( node
);
1990 return node
->GetItem();
1994 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& parent
,
1995 const wxDataViewItem
& previous
,
1996 const wxString
& text
,
2000 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2001 if (!parent_node
) return wxDataViewItem(0);
2003 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
2004 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
2005 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
2007 wxDataViewTreeStoreNode
*node
=
2008 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
2009 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
2011 return node
->GetItem();
2014 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
2015 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
2016 wxClientData
*data
)
2018 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2019 if (!parent_node
) return wxDataViewItem(0);
2021 wxDataViewTreeStoreContainerNode
*node
=
2022 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
2023 parent_node
->GetChildren().Insert( node
);
2025 return node
->GetItem();
2029 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
2030 const wxString
&text
,
2032 const wxIcon
& expanded
,
2033 wxClientData
* data
)
2035 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2036 if (!parent_node
) return wxDataViewItem(0);
2038 wxDataViewTreeStoreContainerNode
*node
=
2039 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
2040 parent_node
->GetChildren().Append( node
);
2042 return node
->GetItem();
2046 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& parent
,
2047 const wxDataViewItem
& previous
,
2048 const wxString
& text
,
2050 const wxIcon
& expanded
,
2051 wxClientData
* data
)
2053 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2054 if (!parent_node
) return wxDataViewItem(0);
2056 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
2057 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
2058 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
2060 wxDataViewTreeStoreContainerNode
*node
=
2061 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
2062 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
2064 return node
->GetItem();
2067 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
& item
) const
2069 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2070 if (!node
) return false;
2072 return node
->IsContainer();
2075 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
2077 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2078 if (!parent_node
) return wxDataViewItem(0);
2080 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
2082 return wxDataViewItem(node
->GetData());
2084 return wxDataViewItem(0);
2087 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
2089 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
2090 if (!node
) return -1;
2092 if (!node
->IsContainer())
2095 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
2096 return (int) container_node
->GetChildren().GetCount();
2099 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2101 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2104 node
->SetText( text
);
2107 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
2109 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2110 if (!node
) return wxEmptyString
;
2112 return node
->GetText();
2115 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2117 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2120 node
->SetIcon( icon
);
2123 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
2125 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2126 if (!node
) return wxNullIcon
;
2128 return node
->GetIcon();
2131 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2133 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2136 node
->SetExpandedIcon( icon
);
2139 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
2141 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2142 if (!node
) return wxNullIcon
;
2144 return node
->GetExpandedIcon();
2147 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
2149 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2152 node
->SetData( data
);
2155 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
2157 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2158 if (!node
) return NULL
;
2160 return node
->GetData();
2163 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
2165 if (!item
.IsOk()) return;
2167 wxDataViewItem parent_item
= GetParent( item
);
2169 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
2170 if (!parent_node
) return;
2172 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2175 parent_node
->GetChildren().DeleteObject( node
);
2178 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
2180 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2183 node
->GetChildren().clear();
2186 void wxDataViewTreeStore::DeleteAllItems()
2188 DeleteChildren(wxDataViewItem(m_root
));
2192 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
2193 const wxDataViewItem
&item
,
2194 unsigned int WXUNUSED(col
)) const
2196 // if (col != 0) return;
2198 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2201 wxIcon
icon( node
->GetIcon());
2202 if (node
->IsContainer())
2204 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
2205 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
2206 icon
= container
->GetExpandedIcon();
2209 wxDataViewIconText
data( node
->GetText(), icon
);
2215 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
2216 const wxDataViewItem
& item
,
2217 unsigned int WXUNUSED(col
))
2219 // if (col != 0) return false;
2221 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2222 if (!node
) return false;
2224 wxDataViewIconText data
;
2228 node
->SetText( data
.GetText() );
2229 node
->SetIcon( data
.GetIcon() );
2234 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
2236 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2237 if (!node
) return wxDataViewItem(0);
2239 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
2240 if (!parent
) return wxDataViewItem(0);
2242 if (parent
== m_root
)
2243 return wxDataViewItem(0);
2245 return parent
->GetItem();
2248 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
2250 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2251 if (!node
) return 0;
2253 wxDataViewTreeStoreNodeList::iterator iter
;
2254 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2256 wxDataViewTreeStoreNode
* child
= *iter
;
2257 children
.Add( child
->GetItem() );
2260 return node
->GetChildren().GetCount();
2263 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
2264 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) ) const
2266 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
2267 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
2269 if (!node1
|| !node2
)
2272 wxDataViewTreeStoreContainerNode
* parent1
=
2273 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
2274 wxDataViewTreeStoreContainerNode
* parent2
=
2275 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
2277 if (parent1
!= parent2
)
2279 wxLogError( wxT("Comparing items with different parent.") );
2283 if (node1
->IsContainer() && !node2
->IsContainer())
2286 if (node2
->IsContainer() && !node1
->IsContainer())
2289 return parent1
->GetChildren().IndexOf( node1
) - parent2
->GetChildren().IndexOf( node2
);
2292 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
2297 return (wxDataViewTreeStoreNode
*) item
.GetID();
2300 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
2303 return (wxDataViewTreeStoreContainerNode
*) m_root
;
2305 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
2307 if (!node
->IsContainer())
2310 return (wxDataViewTreeStoreContainerNode
*) node
;
2313 //-----------------------------------------------------------------------------
2314 // wxDataViewTreeCtrl
2315 //-----------------------------------------------------------------------------
2317 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2319 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2320 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
2321 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
2322 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
2325 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2326 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2328 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
2331 // create the standard model and a column in the tree
2332 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
2333 AssociateModel( store
);
2336 AppendIconTextColumn
2338 wxString(), // no label (header is not shown anyhow)
2339 0, // the only model column
2340 wxDATAVIEW_CELL_EDITABLE
,
2341 -1, // default width
2342 wxALIGN_NOT
, // and alignment
2349 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
2350 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2352 wxDataViewItem res
= GetStore()->
2353 AppendItem( parent
, text
, GetImage(iconIndex
), data
);
2355 GetStore()->ItemAdded( parent
, res
);
2360 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
2361 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2363 wxDataViewItem res
= GetStore()->
2364 PrependItem( parent
, text
, GetImage(iconIndex
), data
);
2366 GetStore()->ItemAdded( parent
, res
);
2371 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2372 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2374 wxDataViewItem res
= GetStore()->
2375 InsertItem( parent
, previous
, text
, GetImage(iconIndex
), data
);
2377 GetStore()->ItemAdded( parent
, res
);
2382 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
2383 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2385 wxDataViewItem res
= GetStore()->
2386 PrependContainer( parent
, text
,
2387 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2389 GetStore()->ItemAdded( parent
, res
);
2394 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
2395 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2397 wxDataViewItem res
= GetStore()->
2398 AppendContainer( parent
, text
,
2399 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2401 GetStore()->ItemAdded( parent
, res
);
2406 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2407 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2409 wxDataViewItem res
= GetStore()->
2410 InsertContainer( parent
, previous
, text
,
2411 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2413 GetStore()->ItemAdded( parent
, res
);
2418 void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2420 GetStore()->SetItemText(item
,text
);
2423 GetStore()->ValueChanged( item
, 0 );
2426 void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2428 GetStore()->SetItemIcon(item
,icon
);
2431 GetStore()->ValueChanged( item
, 0 );
2434 void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2436 GetStore()->SetItemExpandedIcon(item
,icon
);
2439 GetStore()->ValueChanged( item
, 0 );
2442 void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem
& item
)
2444 wxDataViewItem parent_item
= GetStore()->GetParent( item
);
2446 GetStore()->DeleteItem(item
);
2449 GetStore()->ItemDeleted( parent_item
, item
);
2452 void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem
& item
)
2454 wxDataViewTreeStoreContainerNode
*node
= GetStore()->FindContainerNode( item
);
2457 wxDataViewItemArray array
;
2458 wxDataViewTreeStoreNodeList::iterator iter
;
2459 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2461 wxDataViewTreeStoreNode
* child
= *iter
;
2462 array
.Add( child
->GetItem() );
2465 GetStore()->DeleteChildren( item
);
2468 GetStore()->ItemsDeleted( item
, array
);
2471 void wxDataViewTreeCtrl::DeleteAllItems()
2473 GetStore()->DeleteAllItems();
2475 GetStore()->Cleared();
2478 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
2480 if (HasImageList()) return;
2482 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2483 if (!container
) return;
2485 container
->SetExpanded( true );
2487 GetStore()->ItemChanged( event
.GetItem() );
2490 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
2492 if (HasImageList()) return;
2494 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2495 if (!container
) return;
2497 container
->SetExpanded( false );
2499 GetStore()->ItemChanged( event
.GetItem() );
2502 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
2504 #if defined(wxUSE_GENERICDATAVIEWCTRL)
2505 // automatically resize our only column to take the entire control width
2506 if ( GetColumnCount() )
2508 wxSize size
= GetClientSize();
2509 GetColumn(0)->SetWidth(size
.x
);
2515 #endif // wxUSE_DATAVIEWCTRL