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 bool wxDataViewIndexListModel::HasDefaultCompare() const
508 int wxDataViewIndexListModel::Compare(const wxDataViewItem
& item1
,
509 const wxDataViewItem
& item2
,
510 unsigned int WXUNUSED(column
),
511 bool ascending
) const
515 unsigned int pos1
= wxPtrToUInt(item1
.GetID()); // -1 not needed here
516 unsigned int pos2
= wxPtrToUInt(item2
.GetID()); // -1 not needed here
525 return GetRow(item1
) - GetRow(item2
);
527 return GetRow(item2
) - GetRow(item1
);
530 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
537 return m_hash
.GetCount();
540 // ---------------------------------------------------------
541 // wxDataViewVirtualListModel
542 // ---------------------------------------------------------
546 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size
)
548 m_size
= initial_size
;
551 void wxDataViewVirtualListModel::Reset( unsigned int new_size
)
553 /* wxDataViewModel:: */ BeforeReset();
557 /* wxDataViewModel:: */ AfterReset();
560 void wxDataViewVirtualListModel::RowPrepended()
563 wxDataViewItem
item( wxUIntToPtr(1) );
564 ItemAdded( wxDataViewItem(0), item
);
567 void wxDataViewVirtualListModel::RowInserted( unsigned int before
)
570 wxDataViewItem
item( wxUIntToPtr(before
+1) );
571 ItemAdded( wxDataViewItem(0), item
);
574 void wxDataViewVirtualListModel::RowAppended()
577 wxDataViewItem
item( wxUIntToPtr(m_size
) );
578 ItemAdded( wxDataViewItem(0), item
);
581 void wxDataViewVirtualListModel::RowDeleted( unsigned int row
)
584 wxDataViewItem
item( wxUIntToPtr(row
+1) );
585 /* wxDataViewModel:: */ ItemDeleted( wxDataViewItem(0), item
);
588 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt
&rows
)
590 m_size
-= rows
.GetCount();
592 wxArrayInt sorted
= rows
;
593 sorted
.Sort( my_sort
);
595 wxDataViewItemArray array
;
597 for (i
= 0; i
< sorted
.GetCount(); i
++)
599 wxDataViewItem
item( wxUIntToPtr(sorted
[i
]+1) );
602 /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array
);
605 void wxDataViewVirtualListModel::RowChanged( unsigned int row
)
607 /* wxDataViewModel:: */ ItemChanged( GetItem(row
) );
610 void wxDataViewVirtualListModel::RowValueChanged( unsigned int row
, unsigned int col
)
612 /* wxDataViewModel:: */ ValueChanged( GetItem(row
), col
);
615 unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem
&item
) const
617 return wxPtrToUInt( item
.GetID() ) -1;
620 wxDataViewItem
wxDataViewVirtualListModel::GetItem( unsigned int row
) const
622 return wxDataViewItem( wxUIntToPtr(row
+1) );
625 bool wxDataViewVirtualListModel::HasDefaultCompare() const
630 int wxDataViewVirtualListModel::Compare(const wxDataViewItem
& item1
,
631 const wxDataViewItem
& item2
,
632 unsigned int WXUNUSED(column
),
633 bool ascending
) const
635 unsigned int pos1
= wxPtrToUInt(item1
.GetID()); // -1 not needed here
636 unsigned int pos2
= wxPtrToUInt(item2
.GetID()); // -1 not needed here
644 unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem
&WXUNUSED(item
), wxDataViewItemArray
&WXUNUSED(children
) ) const
646 return 0; // should we report an error ?
651 //-----------------------------------------------------------------------------
652 // wxDataViewIconText
653 //-----------------------------------------------------------------------------
655 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
657 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
659 // ---------------------------------------------------------
660 // wxDataViewRendererBase
661 // ---------------------------------------------------------
663 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
665 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
666 wxDataViewCellMode
WXUNUSED(mode
),
667 int WXUNUSED(align
) )
669 m_variantType
= varianttype
;
673 wxDataViewRendererBase::~wxDataViewRendererBase()
676 DestroyEditControl();
679 wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
681 return const_cast<wxDataViewRendererBase
*>(this)->GetOwner()->GetOwner();
684 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
686 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
688 // Before doing anything we send an event asking if editing of this item is really wanted.
689 wxDataViewEvent
start_event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, dv_ctrl
->GetId() );
690 start_event
.SetDataViewColumn( GetOwner() );
691 start_event
.SetModel( dv_ctrl
->GetModel() );
692 start_event
.SetItem( item
);
693 start_event
.SetEventObject( dv_ctrl
);
694 dv_ctrl
->GetEventHandler()->ProcessEvent( start_event
);
695 if( !start_event
.IsAllowed() )
698 m_item
= item
; // remember for later
700 unsigned int col
= GetOwner()->GetModelColumn();
702 dv_ctrl
->GetModel()->GetValue( value
, item
, col
);
704 m_editorCtrl
= CreateEditorCtrl( dv_ctrl
->GetMainWindow(), labelRect
, value
);
706 // there might be no editor control for the given item
710 wxDataViewEditorCtrlEvtHandler
*handler
=
711 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
713 m_editorCtrl
->PushEventHandler( handler
);
715 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
716 handler
->SetFocusOnIdle();
718 m_editorCtrl
->SetFocus();
721 // Now we should send Editing Started event
722 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, dv_ctrl
->GetId() );
723 event
.SetDataViewColumn( GetOwner() );
724 event
.SetModel( dv_ctrl
->GetModel() );
725 event
.SetItem( item
);
726 event
.SetEventObject( dv_ctrl
);
727 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
732 void wxDataViewRendererBase::DestroyEditControl()
734 // Remove our event handler first to prevent it from (recursively) calling
735 // us again as it would do via a call to FinishEditing() when the editor
736 // loses focus when we hide it below.
737 wxEvtHandler
* const handler
= m_editorCtrl
->PopEventHandler();
739 // Hide the control immediately but don't delete it yet as there could be
740 // some pending messages for it.
741 m_editorCtrl
->Hide();
743 wxPendingDelete
.Append(handler
);
744 wxPendingDelete
.Append(m_editorCtrl
);
747 void wxDataViewRendererBase::CancelEditing()
752 DestroyEditControl();
755 bool wxDataViewRendererBase::FinishEditing()
761 GetValueFromEditorCtrl( m_editorCtrl
, value
);
763 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
765 DestroyEditControl();
767 dv_ctrl
->GetMainWindow()->SetFocus();
769 bool isValid
= Validate(value
);
770 unsigned int col
= GetOwner()->GetModelColumn();
772 // Now we should send Editing Done event
773 wxDataViewEvent
event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, dv_ctrl
->GetId() );
774 event
.SetDataViewColumn( GetOwner() );
775 event
.SetModel( dv_ctrl
->GetModel() );
776 event
.SetItem( m_item
);
777 event
.SetValue( value
);
778 event
.SetColumn( col
);
779 event
.SetEditCanceled( !isValid
);
780 event
.SetEventObject( dv_ctrl
);
781 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
783 if ( isValid
&& event
.IsAllowed() )
785 dv_ctrl
->GetModel()->ChangeValue(value
, m_item
, col
);
792 void wxDataViewRendererBase::PrepareForItem(const wxDataViewModel
*model
,
793 const wxDataViewItem
& item
,
797 model
->GetValue(value
, item
, column
);
800 wxDataViewItemAttr attr
;
801 model
->GetAttr(item
, column
, attr
);
804 SetEnabled(model
->IsEnabled(item
, column
));
808 // ----------------------------------------------------------------------------
809 // wxDataViewCustomRendererBase
810 // ----------------------------------------------------------------------------
812 bool wxDataViewCustomRendererBase::ActivateCell(const wxRect
& cell
,
813 wxDataViewModel
*model
,
814 const wxDataViewItem
& item
,
816 const wxMouseEvent
* mouseEvent
)
818 // Compatibility code
820 return LeftClick(mouseEvent
->GetPosition(), cell
, model
, item
, col
);
822 return Activate(cell
, model
, item
, col
);
825 void wxDataViewCustomRendererBase::RenderBackground(wxDC
* dc
, const wxRect
& rect
)
827 if ( !m_attr
.HasBackgroundColour() )
830 const wxColour
& colour
= m_attr
.GetBackgroundColour();
831 wxDCPenChanger
changePen(*dc
, colour
);
832 wxDCBrushChanger
changeBrush(*dc
, colour
);
834 dc
->DrawRectangle(rect
);
838 wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell
, wxDC
*dc
, int state
)
840 wxCHECK_RET( dc
, "no DC to draw on in custom renderer?" );
842 // adjust the rectangle ourselves to account for the alignment
843 wxRect rectItem
= rectCell
;
844 const int align
= GetAlignment();
845 if ( align
!= wxDVR_DEFAULT_ALIGNMENT
)
847 const wxSize size
= GetSize();
849 // take alignment into account only if there is enough space, otherwise
850 // show as much contents as possible
852 // notice that many existing renderers (e.g. wxDataViewSpinRenderer)
853 // return hard-coded size which can be more than they need and if we
854 // trusted their GetSize() we'd draw the text out of cell bounds
857 if ( size
.x
>= 0 && size
.x
< rectCell
.width
)
859 if ( align
& wxALIGN_CENTER_HORIZONTAL
)
860 rectItem
.x
+= (rectCell
.width
- size
.x
)/2;
861 else if ( align
& wxALIGN_RIGHT
)
862 rectItem
.x
+= rectCell
.width
- size
.x
;
863 // else: wxALIGN_LEFT is the default
865 rectItem
.width
= size
.x
;
868 if ( size
.y
>= 0 && size
.y
< rectCell
.height
)
870 if ( align
& wxALIGN_CENTER_VERTICAL
)
871 rectItem
.y
+= (rectCell
.height
- size
.y
)/2;
872 else if ( align
& wxALIGN_BOTTOM
)
873 rectItem
.y
+= rectCell
.height
- size
.y
;
874 // else: wxALIGN_TOP is the default
876 rectItem
.height
= size
.y
;
881 // set up the DC attributes
883 // override custom foreground with the standard one for the selected items
884 // because we currently don't allow changing the selection background and
885 // custom colours may be unreadable on it
887 if ( state
& wxDATAVIEW_CELL_SELECTED
)
888 col
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
889 else if ( m_attr
.HasColour() )
890 col
= m_attr
.GetColour();
891 else // use default foreground
892 col
= GetOwner()->GetOwner()->GetForegroundColour();
894 wxDCTextColourChanger
changeFg(*dc
, col
);
896 wxDCFontChanger
changeFont(*dc
);
897 if ( m_attr
.HasFont() )
898 changeFont
.Set(m_attr
.GetEffectiveFont(dc
->GetFont()));
900 Render(rectItem
, dc
, state
);
903 wxSize
wxDataViewCustomRendererBase::GetTextExtent(const wxString
& str
) const
905 const wxDataViewCtrl
*view
= GetView();
907 if ( m_attr
.HasFont() )
909 wxFont
font(m_attr
.GetEffectiveFont(view
->GetFont()));
911 view
->GetTextExtent(str
, &size
.x
, &size
.y
, NULL
, NULL
, &font
);
916 return view
->GetTextExtent(str
);
921 wxDataViewCustomRendererBase::RenderText(const wxString
& text
,
927 wxRect rectText
= rect
;
928 rectText
.x
+= xoffset
;
929 rectText
.width
-= xoffset
;
931 // check if we want to ellipsize the text if it doesn't fit
932 wxString ellipsizedText
;
933 if ( GetEllipsizeMode() != wxELLIPSIZE_NONE
)
935 ellipsizedText
= wxControl::Ellipsize
941 wxELLIPSIZE_FLAGS_NONE
945 // get the alignment to use
946 int align
= GetAlignment();
947 if ( align
== wxDVR_DEFAULT_ALIGNMENT
)
949 // if we don't have an explicit alignment ourselves, use that of the
950 // column in horizontal direction and default vertical alignment
951 align
= GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
954 dc
->DrawLabel(ellipsizedText
.empty() ? text
: ellipsizedText
,
958 //-----------------------------------------------------------------------------
959 // wxDataViewEditorCtrlEvtHandler
960 //-----------------------------------------------------------------------------
962 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
963 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
964 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
965 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
966 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
969 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
973 m_focusOnIdle
= false;
974 if (wxWindow::FindFocus() != m_editorCtrl
)
975 m_editorCtrl
->SetFocus();
981 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
984 m_owner
->FinishEditing();
987 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
989 switch ( event
.m_keyCode
)
993 m_owner
->FinishEditing();
999 m_owner
->CancelEditing();
1007 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
1012 m_owner
->FinishEditing();
1018 // ---------------------------------------------------------
1019 // wxDataViewColumnBase
1020 // ---------------------------------------------------------
1022 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
1023 unsigned int model_column
)
1025 m_renderer
= renderer
;
1026 m_model_column
= model_column
;
1028 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
1031 wxDataViewColumnBase::~wxDataViewColumnBase()
1036 // ---------------------------------------------------------
1037 // wxDataViewCtrlBase
1038 // ---------------------------------------------------------
1040 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
1042 wxDataViewCtrlBase::wxDataViewCtrlBase()
1045 m_expander_column
= 0;
1049 wxDataViewCtrlBase::~wxDataViewCtrlBase()
1058 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
1062 m_model
->DecRef(); // discard old model, if any
1065 // add our own reference to the new model:
1075 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
1080 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
1085 void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem
& item
)
1087 if (!m_model
) return;
1089 if (!item
.IsOk()) return;
1091 wxVector
<wxDataViewItem
> parentChain
;
1093 // at first we get all the parents of the selected item
1094 wxDataViewItem parent
= m_model
->GetParent(item
);
1095 while (parent
.IsOk())
1097 parentChain
.push_back(parent
);
1098 parent
= m_model
->GetParent(parent
);
1101 // then we expand the parents, starting at the root
1102 while (!parentChain
.empty())
1104 Expand(parentChain
.back());
1105 parentChain
.pop_back();
1109 wxDataViewItem
wxDataViewCtrlBase::GetCurrentItem() const
1111 return HasFlag(wxDV_MULTIPLE
) ? DoGetCurrentItem()
1115 void wxDataViewCtrlBase::SetCurrentItem(const wxDataViewItem
& item
)
1117 wxCHECK_RET( item
.IsOk(), "Can't make current an invalid item." );
1119 if ( HasFlag(wxDV_MULTIPLE
) )
1120 DoSetCurrentItem(item
);
1125 wxDataViewItem
wxDataViewCtrlBase::GetSelection() const
1127 if ( GetSelectedItemsCount() != 1 )
1128 return wxDataViewItem();
1130 wxDataViewItemArray selections
;
1131 GetSelections(selections
);
1132 return selections
[0];
1136 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
1137 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1139 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1140 new wxDataViewTextRenderer( wxT("string"), mode
),
1141 model_column
, width
, align
, flags
);
1142 AppendColumn( ret
);
1147 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
1148 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1150 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1151 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1152 model_column
, width
, align
, flags
);
1153 AppendColumn( ret
);
1158 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
1159 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1161 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1162 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1163 model_column
, width
, align
, flags
);
1164 AppendColumn( ret
);
1169 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
1170 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1172 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1173 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1174 model_column
, width
, align
, flags
);
1175 AppendColumn( ret
);
1180 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
1181 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1183 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1184 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1185 model_column
, width
, align
, flags
);
1186 AppendColumn( ret
);
1191 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
1192 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1194 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1195 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1196 model_column
, width
, align
, flags
);
1197 AppendColumn( ret
);
1202 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1203 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1205 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1206 new wxDataViewTextRenderer( wxT("string"), mode
),
1207 model_column
, width
, align
, flags
);
1208 AppendColumn( ret
);
1213 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1214 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1216 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1217 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1218 model_column
, width
, align
, flags
);
1219 AppendColumn( ret
);
1224 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1225 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1227 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1228 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1229 model_column
, width
, align
, flags
);
1230 AppendColumn( ret
);
1235 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1236 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1238 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1239 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1240 model_column
, width
, align
, flags
);
1241 AppendColumn( ret
);
1246 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1247 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1249 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1250 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1251 model_column
, width
, align
, flags
);
1252 AppendColumn( ret
);
1257 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1258 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1260 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1261 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1262 model_column
, width
, align
, flags
);
1263 AppendColumn( ret
);
1268 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1269 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1271 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1272 new wxDataViewTextRenderer( wxT("string"), mode
),
1273 model_column
, width
, align
, flags
);
1274 PrependColumn( ret
);
1279 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1280 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1282 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1283 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1284 model_column
, width
, align
, flags
);
1285 PrependColumn( ret
);
1290 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1291 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1294 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1295 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1296 model_column
, width
, align
, flags
);
1297 PrependColumn( ret
);
1302 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1303 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1305 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1306 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1307 model_column
, width
, align
, flags
);
1308 PrependColumn( ret
);
1313 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1314 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1316 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1317 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1318 model_column
, width
, align
, flags
);
1319 PrependColumn( ret
);
1324 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1325 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1327 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1328 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1329 model_column
, width
, align
, flags
);
1330 PrependColumn( ret
);
1335 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1336 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1338 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1339 new wxDataViewTextRenderer( wxT("string"), mode
),
1340 model_column
, width
, align
, flags
);
1341 PrependColumn( ret
);
1346 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1347 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1349 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1350 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1351 model_column
, width
, align
, flags
);
1352 PrependColumn( ret
);
1357 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1358 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1360 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1361 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1362 model_column
, width
, align
, flags
);
1363 PrependColumn( ret
);
1368 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1369 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1371 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1372 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1373 model_column
, width
, align
, flags
);
1374 PrependColumn( ret
);
1379 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1380 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1382 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1383 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1384 model_column
, width
, align
, flags
);
1385 PrependColumn( ret
);
1390 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1391 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1393 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1394 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1395 model_column
, width
, align
, flags
);
1396 PrependColumn( ret
);
1401 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1403 col
->SetOwner( (wxDataViewCtrl
*) this );
1408 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1410 col
->SetOwner( (wxDataViewCtrl
*) this );
1415 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1417 col
->SetOwner( (wxDataViewCtrl
*) this );
1421 void wxDataViewCtrlBase::StartEditor(const wxDataViewItem
& item
, unsigned int column
)
1423 EditItem(item
, GetColumn(column
));
1426 // ---------------------------------------------------------
1428 // ---------------------------------------------------------
1430 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1432 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
);
1434 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
);
1435 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
);
1436 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
);
1437 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
);
1438 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
);
1439 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
);
1440 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING
, wxDataViewEvent
);
1441 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
);
1442 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
);
1444 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
);
1446 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
);
1447 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
);
1448 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
);
1449 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
);
1451 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_CACHE_HINT
, wxDataViewEvent
);
1453 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
);
1454 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE
, wxDataViewEvent
);
1455 wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP
, wxDataViewEvent
);
1459 // -------------------------------------
1460 // wxDataViewSpinRenderer
1461 // -------------------------------------
1463 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1464 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1470 wxWindow
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1473 wxSize size
= labelRect
.GetSize();
1475 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1478 str
.Printf( wxT("%d"), (int) l
);
1479 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1480 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1482 size
= sc
->GetSize();
1483 wxPoint pt
= sc
->GetPosition();
1484 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1490 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1492 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1493 long l
= sc
->GetValue();
1498 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1501 str
.Printf(wxT("%d"), (int) m_data
);
1502 RenderText( str
, 0, rect
, dc
, state
);
1506 wxSize
wxDataViewSpinRenderer::GetSize() const
1508 wxSize sz
= GetTextExtent(wxString::Format("%d", (int)m_data
));
1510 // Allow some space for the spin buttons, which is approximately the size
1511 // of a scrollbar (and getting pixel-exact value would be complicated).
1512 // Also add some whitespace between the text and the button:
1513 sz
.x
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1514 sz
.x
+= GetTextExtent("M").x
;
1519 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1521 m_data
= value
.GetLong();
1525 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1531 // -------------------------------------
1532 // wxDataViewChoiceRenderer
1533 // -------------------------------------
1535 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
1537 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1538 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1540 m_choices
= choices
;
1543 wxWindow
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1545 wxChoice
* c
= new wxChoice
1549 labelRect
.GetTopLeft(),
1550 wxSize(labelRect
.GetWidth(), -1),
1553 c
->Move(labelRect
.GetRight() - c
->GetRect().width
, wxDefaultCoord
);
1554 c
->SetStringSelection( value
.GetString() );
1558 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1560 wxChoice
*c
= (wxChoice
*) editor
;
1561 wxString s
= c
->GetStringSelection();
1566 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1568 RenderText( m_data
, 0, rect
, dc
, state
);
1572 wxSize
wxDataViewChoiceRenderer::GetSize() const
1576 for ( wxArrayString::const_iterator i
= m_choices
.begin(); i
!= m_choices
.end(); ++i
)
1577 sz
.IncTo(GetTextExtent(*i
));
1579 // Allow some space for the right-side button, which is approximately the
1580 // size of a scrollbar (and getting pixel-exact value would be complicated).
1581 // Also add some whitespace between the text and the button:
1582 sz
.x
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1583 sz
.x
+= GetTextExtent("M").x
;
1588 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1590 m_data
= value
.GetString();
1594 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1600 // ----------------------------------------------------------------------------
1601 // wxDataViewChoiceByIndexRenderer
1602 // ----------------------------------------------------------------------------
1604 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
1605 wxDataViewCellMode mode
, int alignment
) :
1606 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
1610 wxWindow
* wxDataViewChoiceByIndexRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1612 wxVariant string_value
= GetChoice( value
.GetLong() );
1614 return wxDataViewChoiceRenderer::CreateEditorCtrl( parent
, labelRect
, string_value
);
1617 bool wxDataViewChoiceByIndexRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1619 wxVariant string_value
;
1620 if (!wxDataViewChoiceRenderer::GetValueFromEditorCtrl( editor
, string_value
))
1623 value
= (long) GetChoices().Index( string_value
.GetString() );
1627 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
1629 wxVariant string_value
= GetChoice( value
.GetLong() );
1630 return wxDataViewChoiceRenderer::SetValue( string_value
);
1633 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
1635 wxVariant string_value
;
1636 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
1639 value
= (long) GetChoices().Index( string_value
.GetString() );
1645 // ---------------------------------------------------------
1646 // wxDataViewDateRenderer
1647 // ---------------------------------------------------------
1649 #if (defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)) && wxUSE_DATEPICKCTRL
1651 wxDataViewDateRenderer::wxDataViewDateRenderer(const wxString
& varianttype
,
1652 wxDataViewCellMode mode
, int align
)
1653 : wxDataViewCustomRenderer(varianttype
, mode
, align
)
1658 wxDataViewDateRenderer::CreateEditorCtrl(wxWindow
*parent
, wxRect labelRect
, const wxVariant
& value
)
1660 return new wxDatePickerCtrl
1664 value
.GetDateTime(),
1665 labelRect
.GetTopLeft(),
1670 bool wxDataViewDateRenderer::GetValueFromEditorCtrl(wxWindow
*editor
, wxVariant
& value
)
1672 wxDatePickerCtrl
*ctrl
= static_cast<wxDatePickerCtrl
*>(editor
);
1673 value
= ctrl
->GetValue();
1677 bool wxDataViewDateRenderer::SetValue(const wxVariant
& value
)
1679 m_date
= value
.GetDateTime();
1683 bool wxDataViewDateRenderer::GetValue(wxVariant
& value
) const
1689 bool wxDataViewDateRenderer::Render(wxRect cell
, wxDC
* dc
, int state
)
1691 wxString tmp
= m_date
.FormatDate();
1692 RenderText( tmp
, 0, cell
, dc
, state
);
1696 wxSize
wxDataViewDateRenderer::GetSize() const
1698 return GetTextExtent(m_date
.FormatDate());
1701 #endif // (defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)) && wxUSE_DATEPICKCTRL
1703 //-----------------------------------------------------------------------------
1704 // wxDataViewListStore
1705 //-----------------------------------------------------------------------------
1707 wxDataViewListStore::wxDataViewListStore()
1711 wxDataViewListStore::~wxDataViewListStore()
1713 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1714 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1716 wxDataViewListStoreLine
* line
= *it
;
1721 void wxDataViewListStore::PrependColumn( const wxString
&varianttype
)
1723 m_cols
.Insert( varianttype
, 0 );
1726 void wxDataViewListStore::InsertColumn( unsigned int pos
, const wxString
&varianttype
)
1728 m_cols
.Insert( varianttype
, pos
);
1731 void wxDataViewListStore::AppendColumn( const wxString
&varianttype
)
1733 m_cols
.Add( varianttype
);
1736 unsigned int wxDataViewListStore::GetColumnCount() const
1738 return m_cols
.GetCount();
1741 wxString
wxDataViewListStore::GetColumnType( unsigned int pos
) const
1746 void wxDataViewListStore::AppendItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1748 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1749 line
->m_values
= values
;
1750 m_data
.push_back( line
);
1755 void wxDataViewListStore::PrependItem( const wxVector
<wxVariant
> &values
, wxClientData
*data
)
1757 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1758 line
->m_values
= values
;
1759 m_data
.insert( m_data
.begin(), line
);
1764 void wxDataViewListStore::InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
,
1765 wxClientData
*data
)
1767 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1768 line
->m_values
= values
;
1769 m_data
.insert( m_data
.begin()+row
, line
);
1774 void wxDataViewListStore::DeleteItem( unsigned int row
)
1776 wxVector
<wxDataViewListStoreLine
*>::iterator it
= m_data
.begin() + row
;
1783 void wxDataViewListStore::DeleteAllItems()
1785 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1786 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1788 wxDataViewListStoreLine
* line
= *it
;
1797 void wxDataViewListStore::GetValueByRow( wxVariant
&value
, unsigned int row
, unsigned int col
) const
1799 wxDataViewListStoreLine
*line
= m_data
[row
];
1800 value
= line
->m_values
[col
];
1803 bool wxDataViewListStore::SetValueByRow( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1805 wxDataViewListStoreLine
*line
= m_data
[row
];
1806 line
->m_values
[col
] = value
;
1811 //-----------------------------------------------------------------------------
1812 // wxDataViewListCtrl
1813 //-----------------------------------------------------------------------------
1815 IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl
,wxDataViewCtrl
)
1817 BEGIN_EVENT_TABLE(wxDataViewListCtrl
,wxDataViewCtrl
)
1818 EVT_SIZE( wxDataViewListCtrl::OnSize
)
1821 wxDataViewListCtrl::wxDataViewListCtrl()
1825 wxDataViewListCtrl::wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
1826 const wxPoint
& pos
, const wxSize
& size
, long style
,
1827 const wxValidator
& validator
)
1829 Create( parent
, id
, pos
, size
, style
, validator
);
1832 wxDataViewListCtrl::~wxDataViewListCtrl()
1837 bool wxDataViewListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1838 const wxPoint
& pos
, const wxSize
& size
, long style
,
1839 const wxValidator
& validator
)
1841 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
1844 wxDataViewListStore
*store
= new wxDataViewListStore
;
1845 AssociateModel( store
);
1851 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1853 GetStore()->AppendColumn( varianttype
);
1854 return wxDataViewCtrl::AppendColumn( column
);
1857 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1859 GetStore()->PrependColumn( varianttype
);
1860 return wxDataViewCtrl::PrependColumn( column
);
1863 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
)
1865 GetStore()->InsertColumn( pos
, varianttype
);
1866 return wxDataViewCtrl::InsertColumn( pos
, column
);
1869 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*col
)
1871 return PrependColumn( col
, "string" );
1874 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
1876 return InsertColumn( pos
, col
, "string" );
1879 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*col
)
1881 return AppendColumn( col
, "string" );
1884 wxDataViewColumn
*wxDataViewListCtrl::AppendTextColumn( const wxString
&label
,
1885 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1887 GetStore()->AppendColumn( wxT("string") );
1889 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1890 new wxDataViewTextRenderer( wxT("string"), mode
),
1891 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1893 wxDataViewCtrl::AppendColumn( ret
);
1898 wxDataViewColumn
*wxDataViewListCtrl::AppendToggleColumn( const wxString
&label
,
1899 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1901 GetStore()->AppendColumn( wxT("bool") );
1903 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1904 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1905 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1907 wxDataViewCtrl::AppendColumn( ret
);
1912 wxDataViewColumn
*wxDataViewListCtrl::AppendProgressColumn( const wxString
&label
,
1913 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1915 GetStore()->AppendColumn( wxT("long") );
1917 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1918 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1919 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1921 wxDataViewCtrl::AppendColumn( ret
);
1926 wxDataViewColumn
*wxDataViewListCtrl::AppendIconTextColumn( const wxString
&label
,
1927 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1929 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
1931 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1932 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1933 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1935 wxDataViewCtrl::AppendColumn( ret
);
1940 void wxDataViewListCtrl::OnSize( wxSizeEvent
&event
)
1945 //-----------------------------------------------------------------------------
1946 // wxDataViewTreeStore
1947 //-----------------------------------------------------------------------------
1949 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1950 wxDataViewTreeStoreNode
*parent
,
1951 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1959 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1965 #include "wx/listimpl.cpp"
1966 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1968 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1969 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1970 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1971 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1973 m_iconExpanded
= expanded
;
1974 m_isExpanded
= false;
1975 m_children
.DeleteContents(true);
1978 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1982 //-----------------------------------------------------------------------------
1984 wxDataViewTreeStore::wxDataViewTreeStore()
1986 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1989 wxDataViewTreeStore::~wxDataViewTreeStore()
1994 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1995 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1997 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1998 if (!parent_node
) return wxDataViewItem(0);
2000 wxDataViewTreeStoreNode
*node
=
2001 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
2002 parent_node
->GetChildren().Append( node
);
2004 return node
->GetItem();
2007 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
2008 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
2010 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2011 if (!parent_node
) return wxDataViewItem(0);
2013 wxDataViewTreeStoreNode
*node
=
2014 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
2015 parent_node
->GetChildren().Insert( node
);
2017 return node
->GetItem();
2021 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& parent
,
2022 const wxDataViewItem
& previous
,
2023 const wxString
& text
,
2027 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2028 if (!parent_node
) return wxDataViewItem(0);
2030 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
2031 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
2032 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
2034 wxDataViewTreeStoreNode
*node
=
2035 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
2036 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
2038 return node
->GetItem();
2041 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
2042 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
2043 wxClientData
*data
)
2045 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2046 if (!parent_node
) return wxDataViewItem(0);
2048 wxDataViewTreeStoreContainerNode
*node
=
2049 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
2050 parent_node
->GetChildren().Insert( node
);
2052 return node
->GetItem();
2056 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
2057 const wxString
&text
,
2059 const wxIcon
& expanded
,
2060 wxClientData
* data
)
2062 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2063 if (!parent_node
) return wxDataViewItem(0);
2065 wxDataViewTreeStoreContainerNode
*node
=
2066 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
2067 parent_node
->GetChildren().Append( node
);
2069 return node
->GetItem();
2073 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& parent
,
2074 const wxDataViewItem
& previous
,
2075 const wxString
& text
,
2077 const wxIcon
& expanded
,
2078 wxClientData
* data
)
2080 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2081 if (!parent_node
) return wxDataViewItem(0);
2083 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
2084 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
2085 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
2087 wxDataViewTreeStoreContainerNode
*node
=
2088 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
2089 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
2091 return node
->GetItem();
2094 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
& item
) const
2096 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2097 if (!node
) return false;
2099 return node
->IsContainer();
2102 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
2104 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2105 if (!parent_node
) return wxDataViewItem(0);
2107 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
2109 return wxDataViewItem(node
->GetData());
2111 return wxDataViewItem(0);
2114 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
2116 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
2117 if (!node
) return -1;
2119 if (!node
->IsContainer())
2122 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
2123 return (int) container_node
->GetChildren().GetCount();
2126 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2128 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2131 node
->SetText( text
);
2134 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
2136 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2137 if (!node
) return wxEmptyString
;
2139 return node
->GetText();
2142 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2144 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2147 node
->SetIcon( icon
);
2150 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
2152 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2153 if (!node
) return wxNullIcon
;
2155 return node
->GetIcon();
2158 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2160 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2163 node
->SetExpandedIcon( icon
);
2166 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
2168 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2169 if (!node
) return wxNullIcon
;
2171 return node
->GetExpandedIcon();
2174 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
2176 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2179 node
->SetData( data
);
2182 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
2184 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2185 if (!node
) return NULL
;
2187 return node
->GetData();
2190 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
2192 if (!item
.IsOk()) return;
2194 wxDataViewItem parent_item
= GetParent( item
);
2196 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
2197 if (!parent_node
) return;
2199 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2202 parent_node
->GetChildren().DeleteObject( node
);
2205 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
2207 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2210 node
->GetChildren().clear();
2213 void wxDataViewTreeStore::DeleteAllItems()
2215 DeleteChildren(wxDataViewItem(m_root
));
2219 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
2220 const wxDataViewItem
&item
,
2221 unsigned int WXUNUSED(col
)) const
2223 // if (col != 0) return;
2225 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2228 wxIcon
icon( node
->GetIcon());
2229 if (node
->IsContainer())
2231 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
2232 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
2233 icon
= container
->GetExpandedIcon();
2236 wxDataViewIconText
data( node
->GetText(), icon
);
2242 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
2243 const wxDataViewItem
& item
,
2244 unsigned int WXUNUSED(col
))
2246 // if (col != 0) return false;
2248 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2249 if (!node
) return false;
2251 wxDataViewIconText data
;
2255 node
->SetText( data
.GetText() );
2256 node
->SetIcon( data
.GetIcon() );
2261 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
2263 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2264 if (!node
) return wxDataViewItem(0);
2266 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
2267 if (!parent
) return wxDataViewItem(0);
2269 if (parent
== m_root
)
2270 return wxDataViewItem(0);
2272 return parent
->GetItem();
2275 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
2277 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2278 if (!node
) return 0;
2280 wxDataViewTreeStoreNodeList::iterator iter
;
2281 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2283 wxDataViewTreeStoreNode
* child
= *iter
;
2284 children
.Add( child
->GetItem() );
2287 return node
->GetChildren().GetCount();
2290 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
2291 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) ) const
2293 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
2294 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
2296 if (!node1
|| !node2
)
2299 wxDataViewTreeStoreContainerNode
* parent1
=
2300 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
2301 wxDataViewTreeStoreContainerNode
* parent2
=
2302 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
2304 if (parent1
!= parent2
)
2306 wxLogError( wxT("Comparing items with different parent.") );
2310 if (node1
->IsContainer() && !node2
->IsContainer())
2313 if (node2
->IsContainer() && !node1
->IsContainer())
2316 return parent1
->GetChildren().IndexOf( node1
) - parent2
->GetChildren().IndexOf( node2
);
2319 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
2324 return (wxDataViewTreeStoreNode
*) item
.GetID();
2327 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
2330 return (wxDataViewTreeStoreContainerNode
*) m_root
;
2332 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
2334 if (!node
->IsContainer())
2337 return (wxDataViewTreeStoreContainerNode
*) node
;
2340 //-----------------------------------------------------------------------------
2341 // wxDataViewTreeCtrl
2342 //-----------------------------------------------------------------------------
2344 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2346 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2347 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
2348 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
2349 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
2352 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2353 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2355 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
2358 // create the standard model and a column in the tree
2359 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
2360 AssociateModel( store
);
2363 AppendIconTextColumn
2365 wxString(), // no label (header is not shown anyhow)
2366 0, // the only model column
2367 wxDATAVIEW_CELL_EDITABLE
,
2368 -1, // default width
2369 wxALIGN_NOT
, // and alignment
2376 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
2377 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2379 wxDataViewItem res
= GetStore()->
2380 AppendItem( parent
, text
, GetImage(iconIndex
), data
);
2382 GetStore()->ItemAdded( parent
, res
);
2387 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
2388 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2390 wxDataViewItem res
= GetStore()->
2391 PrependItem( parent
, text
, GetImage(iconIndex
), data
);
2393 GetStore()->ItemAdded( parent
, res
);
2398 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2399 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2401 wxDataViewItem res
= GetStore()->
2402 InsertItem( parent
, previous
, text
, GetImage(iconIndex
), data
);
2404 GetStore()->ItemAdded( parent
, res
);
2409 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
2410 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2412 wxDataViewItem res
= GetStore()->
2413 PrependContainer( parent
, text
,
2414 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2416 GetStore()->ItemAdded( parent
, res
);
2421 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
2422 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2424 wxDataViewItem res
= GetStore()->
2425 AppendContainer( parent
, text
,
2426 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2428 GetStore()->ItemAdded( parent
, res
);
2433 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2434 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2436 wxDataViewItem res
= GetStore()->
2437 InsertContainer( parent
, previous
, text
,
2438 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2440 GetStore()->ItemAdded( parent
, res
);
2445 void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2447 GetStore()->SetItemText(item
,text
);
2450 GetStore()->ValueChanged( item
, 0 );
2453 void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2455 GetStore()->SetItemIcon(item
,icon
);
2458 GetStore()->ValueChanged( item
, 0 );
2461 void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2463 GetStore()->SetItemExpandedIcon(item
,icon
);
2466 GetStore()->ValueChanged( item
, 0 );
2469 void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem
& item
)
2471 wxDataViewItem parent_item
= GetStore()->GetParent( item
);
2473 GetStore()->DeleteItem(item
);
2476 GetStore()->ItemDeleted( parent_item
, item
);
2479 void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem
& item
)
2481 wxDataViewTreeStoreContainerNode
*node
= GetStore()->FindContainerNode( item
);
2484 wxDataViewItemArray array
;
2485 wxDataViewTreeStoreNodeList::iterator iter
;
2486 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2488 wxDataViewTreeStoreNode
* child
= *iter
;
2489 array
.Add( child
->GetItem() );
2492 GetStore()->DeleteChildren( item
);
2495 GetStore()->ItemsDeleted( item
, array
);
2498 void wxDataViewTreeCtrl::DeleteAllItems()
2500 GetStore()->DeleteAllItems();
2502 GetStore()->Cleared();
2505 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
2507 if (HasImageList()) return;
2509 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2510 if (!container
) return;
2512 container
->SetExpanded( true );
2514 GetStore()->ItemChanged( event
.GetItem() );
2517 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
2519 if (HasImageList()) return;
2521 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2522 if (!container
) return;
2524 container
->SetExpanded( false );
2526 GetStore()->ItemChanged( event
.GetItem() );
2529 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
2531 #if defined(wxUSE_GENERICDATAVIEWCTRL)
2532 // automatically resize our only column to take the entire control width
2533 if ( GetColumnCount() )
2535 wxSize size
= GetClientSize();
2536 GetColumn(0)->SetWidth(size
.x
);
2542 #endif // wxUSE_DATAVIEWCTRL