1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/datavcmn.cpp
3 // Purpose: wxDataViewCtrl base classes and common parts
4 // Author: Robert Roebling
6 // Copyright: (c) 2006, Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
17 #if wxUSE_DATAVIEWCTRL
19 #include "wx/dataview.h"
23 #include "wx/settings.h"
28 #include "wx/datectrl.h"
29 #include "wx/spinctrl.h"
30 #include "wx/choice.h"
31 #include "wx/imaglist.h"
33 const char wxDataViewCtrlNameStr
[] = "dataviewCtrl";
38 // Custom handler pushed on top of the edit control used by wxDataViewCtrl to
39 // forward some events to the main control itself.
40 class wxDataViewEditorCtrlEvtHandler
: public wxEvtHandler
43 wxDataViewEditorCtrlEvtHandler(wxWindow
*editor
, wxDataViewRenderer
*owner
)
45 m_editorCtrl
= editor
;
51 void AcceptChangesAndFinish();
52 void SetFocusOnIdle( bool focus
= true ) { m_focusOnIdle
= focus
; }
55 void OnChar( wxKeyEvent
&event
);
56 void OnTextEnter( wxCommandEvent
&event
);
57 void OnKillFocus( wxFocusEvent
&event
);
58 void OnIdle( wxIdleEvent
&event
);
61 wxDataViewRenderer
*m_owner
;
62 wxWindow
*m_editorCtrl
;
70 } // anonymous namespace
72 // ---------------------------------------------------------
74 // ---------------------------------------------------------
76 wxFont
wxDataViewItemAttr::GetEffectiveFont(const wxFont
& font
) const
90 // ---------------------------------------------------------
91 // wxDataViewModelNotifier
92 // ---------------------------------------------------------
94 #include "wx/listimpl.cpp"
95 WX_DEFINE_LIST(wxDataViewModelNotifiers
)
97 bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
99 size_t count
= items
.GetCount();
101 for (i
= 0; i
< count
; i
++)
102 if (!ItemAdded( parent
, items
[i
] )) return false;
107 bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
109 size_t count
= items
.GetCount();
111 for (i
= 0; i
< count
; i
++)
112 if (!ItemDeleted( parent
, items
[i
] )) return false;
117 bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray
&items
)
119 size_t count
= items
.GetCount();
121 for (i
= 0; i
< count
; i
++)
122 if (!ItemChanged( items
[i
] )) return false;
127 // ---------------------------------------------------------
129 // ---------------------------------------------------------
131 wxDataViewModel::wxDataViewModel()
133 m_notifiers
.DeleteContents( true );
136 bool wxDataViewModel::ItemAdded( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
140 wxDataViewModelNotifiers::iterator iter
;
141 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
143 wxDataViewModelNotifier
* notifier
= *iter
;
144 if (!notifier
->ItemAdded( parent
, item
))
151 bool wxDataViewModel::ItemDeleted( const wxDataViewItem
&parent
, const wxDataViewItem
&item
)
155 wxDataViewModelNotifiers::iterator iter
;
156 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
158 wxDataViewModelNotifier
* notifier
= *iter
;
159 if (!notifier
->ItemDeleted( parent
, item
))
166 bool wxDataViewModel::ItemChanged( const wxDataViewItem
&item
)
170 wxDataViewModelNotifiers::iterator iter
;
171 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
173 wxDataViewModelNotifier
* notifier
= *iter
;
174 if (!notifier
->ItemChanged( item
))
181 bool wxDataViewModel::ItemsAdded( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
185 wxDataViewModelNotifiers::iterator iter
;
186 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
188 wxDataViewModelNotifier
* notifier
= *iter
;
189 if (!notifier
->ItemsAdded( parent
, items
))
196 bool wxDataViewModel::ItemsDeleted( const wxDataViewItem
&parent
, const wxDataViewItemArray
&items
)
200 wxDataViewModelNotifiers::iterator iter
;
201 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
203 wxDataViewModelNotifier
* notifier
= *iter
;
204 if (!notifier
->ItemsDeleted( parent
, items
))
211 bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray
&items
)
215 wxDataViewModelNotifiers::iterator iter
;
216 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
218 wxDataViewModelNotifier
* notifier
= *iter
;
219 if (!notifier
->ItemsChanged( items
))
226 bool wxDataViewModel::ValueChanged( const wxDataViewItem
&item
, unsigned int col
)
230 wxDataViewModelNotifiers::iterator iter
;
231 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
233 wxDataViewModelNotifier
* notifier
= *iter
;
234 if (!notifier
->ValueChanged( item
, col
))
241 bool wxDataViewModel::Cleared()
245 wxDataViewModelNotifiers::iterator iter
;
246 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
248 wxDataViewModelNotifier
* notifier
= *iter
;
249 if (!notifier
->Cleared())
256 bool wxDataViewModel::BeforeReset()
260 wxDataViewModelNotifiers::iterator iter
;
261 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
263 wxDataViewModelNotifier
* notifier
= *iter
;
264 if (!notifier
->BeforeReset())
271 bool wxDataViewModel::AfterReset()
275 wxDataViewModelNotifiers::iterator iter
;
276 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
278 wxDataViewModelNotifier
* notifier
= *iter
;
279 if (!notifier
->AfterReset())
286 void wxDataViewModel::Resort()
288 wxDataViewModelNotifiers::iterator iter
;
289 for (iter
= m_notifiers
.begin(); iter
!= m_notifiers
.end(); ++iter
)
291 wxDataViewModelNotifier
* notifier
= *iter
;
296 void wxDataViewModel::AddNotifier( wxDataViewModelNotifier
*notifier
)
298 m_notifiers
.push_back( notifier
);
299 notifier
->SetOwner( this );
302 void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier
*notifier
)
304 m_notifiers
.DeleteObject( notifier
);
307 int wxDataViewModel::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
308 unsigned int column
, bool ascending
) const
310 wxVariant value1
,value2
;
311 GetValue( value1
, item1
, column
);
312 GetValue( value2
, item2
, column
);
316 wxVariant temp
= value1
;
321 if (value1
.GetType() == wxT("string"))
323 wxString str1
= value1
.GetString();
324 wxString str2
= value2
.GetString();
325 int res
= str1
.Cmp( str2
);
329 else if (value1
.GetType() == wxT("long"))
331 long l1
= value1
.GetLong();
332 long l2
= value2
.GetLong();
337 else if (value1
.GetType() == wxT("double"))
339 double d1
= value1
.GetDouble();
340 double d2
= value2
.GetDouble();
346 else if (value1
.GetType() == wxT("datetime"))
348 wxDateTime dt1
= value1
.GetDateTime();
349 wxDateTime dt2
= value2
.GetDateTime();
350 if (dt1
.IsEarlierThan(dt2
))
352 if (dt2
.IsEarlierThan(dt1
))
356 // items must be different
357 wxUIntPtr id1
= wxPtrToUInt(item1
.GetID()),
358 id2
= wxPtrToUInt(item2
.GetID());
360 return ascending
? id1
- id2
: id2
- id1
;
363 // ---------------------------------------------------------
364 // wxDataViewIndexListModel
365 // ---------------------------------------------------------
367 static int my_sort( int *v1
, int *v2
)
373 wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size
)
375 // IDs are ordered until an item gets deleted or inserted
378 // build initial index
380 for (i
= 1; i
< initial_size
+1; i
++)
381 m_hash
.Add( wxDataViewItem(wxUIntToPtr(i
)) );
382 m_nextFreeID
= initial_size
+ 1;
385 void wxDataViewIndexListModel::Reset( unsigned int new_size
)
387 /* wxDataViewModel:: */ BeforeReset();
391 // IDs are ordered until an item gets deleted or inserted
394 // build initial index
396 for (i
= 1; i
< new_size
+1; i
++)
397 m_hash
.Add( wxDataViewItem(wxUIntToPtr(i
)) );
399 m_nextFreeID
= new_size
+ 1;
401 /* wxDataViewModel:: */ AfterReset();
404 void wxDataViewIndexListModel::RowPrepended()
408 unsigned int id
= m_nextFreeID
;
411 wxDataViewItem
item( wxUIntToPtr(id
) );
412 m_hash
.Insert( item
, 0 );
413 ItemAdded( wxDataViewItem(0), item
);
417 void wxDataViewIndexListModel::RowInserted( unsigned int before
)
421 unsigned int id
= m_nextFreeID
;
424 wxDataViewItem
item( wxUIntToPtr(id
) );
425 m_hash
.Insert( item
, before
);
426 ItemAdded( wxDataViewItem(0), item
);
429 void wxDataViewIndexListModel::RowAppended()
431 unsigned int id
= m_nextFreeID
;
434 wxDataViewItem
item( wxUIntToPtr(id
) );
436 ItemAdded( wxDataViewItem(0), item
);
439 void wxDataViewIndexListModel::RowDeleted( unsigned int row
)
443 wxDataViewItem
item( m_hash
[row
] );
444 m_hash
.RemoveAt( row
);
445 /* wxDataViewModel:: */ ItemDeleted( wxDataViewItem(0), item
);
448 void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt
&rows
)
452 wxDataViewItemArray array
;
454 for (i
= 0; i
< rows
.GetCount(); i
++)
456 wxDataViewItem
item( m_hash
[rows
[i
]] );
460 wxArrayInt sorted
= rows
;
461 sorted
.Sort( my_sort
);
462 for (i
= 0; i
< sorted
.GetCount(); i
++)
463 m_hash
.RemoveAt( sorted
[i
] );
465 /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array
);
468 void wxDataViewIndexListModel::RowChanged( unsigned int row
)
470 /* wxDataViewModel:: */ ItemChanged( GetItem(row
) );
473 void wxDataViewIndexListModel::RowValueChanged( unsigned int row
, unsigned int col
)
475 /* wxDataViewModel:: */ ValueChanged( GetItem(row
), col
);
478 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem
&item
) const
481 return wxPtrToUInt(item
.GetID())-1;
483 // assert for not found
484 return (unsigned int) m_hash
.Index( item
);
487 wxDataViewItem
wxDataViewIndexListModel::GetItem( unsigned int row
) const
489 wxASSERT( row
< m_hash
.GetCount() );
490 return wxDataViewItem( m_hash
[row
] );
493 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
500 return m_hash
.GetCount();
503 // ---------------------------------------------------------
504 // wxDataViewVirtualListModel
505 // ---------------------------------------------------------
509 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size
)
511 m_size
= initial_size
;
514 void wxDataViewVirtualListModel::Reset( unsigned int new_size
)
516 /* wxDataViewModel:: */ BeforeReset();
520 /* wxDataViewModel:: */ AfterReset();
523 void wxDataViewVirtualListModel::RowPrepended()
526 wxDataViewItem
item( wxUIntToPtr(1) );
527 ItemAdded( wxDataViewItem(0), item
);
530 void wxDataViewVirtualListModel::RowInserted( unsigned int before
)
533 wxDataViewItem
item( wxUIntToPtr(before
+1) );
534 ItemAdded( wxDataViewItem(0), item
);
537 void wxDataViewVirtualListModel::RowAppended()
540 wxDataViewItem
item( wxUIntToPtr(m_size
) );
541 ItemAdded( wxDataViewItem(0), item
);
544 void wxDataViewVirtualListModel::RowDeleted( unsigned int row
)
547 wxDataViewItem
item( wxUIntToPtr(row
+1) );
548 /* wxDataViewModel:: */ ItemDeleted( wxDataViewItem(0), item
);
551 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt
&rows
)
553 m_size
-= rows
.GetCount();
555 wxArrayInt sorted
= rows
;
556 sorted
.Sort( my_sort
);
558 wxDataViewItemArray array
;
560 for (i
= 0; i
< sorted
.GetCount(); i
++)
562 wxDataViewItem
item( wxUIntToPtr(sorted
[i
]+1) );
565 /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array
);
568 void wxDataViewVirtualListModel::RowChanged( unsigned int row
)
570 /* wxDataViewModel:: */ ItemChanged( GetItem(row
) );
573 void wxDataViewVirtualListModel::RowValueChanged( unsigned int row
, unsigned int col
)
575 /* wxDataViewModel:: */ ValueChanged( GetItem(row
), col
);
578 unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem
&item
) const
580 return wxPtrToUInt( item
.GetID() ) -1;
583 wxDataViewItem
wxDataViewVirtualListModel::GetItem( unsigned int row
) const
585 return wxDataViewItem( wxUIntToPtr(row
+1) );
588 bool wxDataViewVirtualListModel::HasDefaultCompare() const
593 int wxDataViewVirtualListModel::Compare(const wxDataViewItem
& item1
,
594 const wxDataViewItem
& item2
,
595 unsigned int WXUNUSED(column
),
596 bool ascending
) const
598 unsigned int pos1
= wxPtrToUInt(item1
.GetID()); // -1 not needed here
599 unsigned int pos2
= wxPtrToUInt(item2
.GetID()); // -1 not needed here
607 unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem
&WXUNUSED(item
), wxDataViewItemArray
&WXUNUSED(children
) ) const
609 return 0; // should we report an error ?
614 //-----------------------------------------------------------------------------
615 // wxDataViewIconText
616 //-----------------------------------------------------------------------------
618 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText
,wxObject
)
620 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText
, WXDLLIMPEXP_ADV
)
622 // ---------------------------------------------------------
623 // wxDataViewRendererBase
624 // ---------------------------------------------------------
626 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
628 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
629 wxDataViewCellMode
WXUNUSED(mode
),
630 int WXUNUSED(align
) )
632 m_variantType
= varianttype
;
636 wxDataViewRendererBase::~wxDataViewRendererBase()
639 DestroyEditControl();
642 wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
644 return const_cast<wxDataViewRendererBase
*>(this)->GetOwner()->GetOwner();
647 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem
&item
, wxRect labelRect
)
649 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
651 // Before doing anything we send an event asking if editing of this item is really wanted.
652 wxDataViewEvent
start_event( wxEVT_DATAVIEW_ITEM_START_EDITING
, dv_ctrl
->GetId() );
653 start_event
.SetDataViewColumn( GetOwner() );
654 start_event
.SetModel( dv_ctrl
->GetModel() );
655 start_event
.SetItem( item
);
656 start_event
.SetEventObject( dv_ctrl
);
657 dv_ctrl
->GetEventHandler()->ProcessEvent( start_event
);
658 if( !start_event
.IsAllowed() )
661 m_item
= item
; // remember for later
663 unsigned int col
= GetOwner()->GetModelColumn();
665 dv_ctrl
->GetModel()->GetValue( value
, item
, col
);
667 m_editorCtrl
= CreateEditorCtrl( dv_ctrl
->GetMainWindow(), labelRect
, value
);
669 // there might be no editor control for the given item
673 wxDataViewEditorCtrlEvtHandler
*handler
=
674 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
676 m_editorCtrl
->PushEventHandler( handler
);
678 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
679 handler
->SetFocusOnIdle();
681 m_editorCtrl
->SetFocus();
684 // Now we should send Editing Started event
685 wxDataViewEvent
event( wxEVT_DATAVIEW_ITEM_EDITING_STARTED
, dv_ctrl
->GetId() );
686 event
.SetDataViewColumn( GetOwner() );
687 event
.SetModel( dv_ctrl
->GetModel() );
688 event
.SetItem( item
);
689 event
.SetEventObject( dv_ctrl
);
690 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
695 void wxDataViewRendererBase::DestroyEditControl()
697 // Remove our event handler first to prevent it from (recursively) calling
698 // us again as it would do via a call to FinishEditing() when the editor
699 // loses focus when we hide it below.
700 wxEvtHandler
* const handler
= m_editorCtrl
->PopEventHandler();
702 // Hide the control immediately but don't delete it yet as there could be
703 // some pending messages for it.
704 m_editorCtrl
->Hide();
706 wxPendingDelete
.Append(handler
);
707 wxPendingDelete
.Append(m_editorCtrl
);
709 // Ensure that DestroyEditControl() is not called again for this control.
710 m_editorCtrl
.Release();
713 void wxDataViewRendererBase::CancelEditing()
718 DestroyEditControl();
721 bool wxDataViewRendererBase::FinishEditing()
727 GetValueFromEditorCtrl( m_editorCtrl
, value
);
729 wxDataViewCtrl
* dv_ctrl
= GetOwner()->GetOwner();
731 DestroyEditControl();
733 dv_ctrl
->GetMainWindow()->SetFocus();
735 bool isValid
= Validate(value
);
736 unsigned int col
= GetOwner()->GetModelColumn();
738 // Now we should send Editing Done event
739 wxDataViewEvent
event( wxEVT_DATAVIEW_ITEM_EDITING_DONE
, dv_ctrl
->GetId() );
740 event
.SetDataViewColumn( GetOwner() );
741 event
.SetModel( dv_ctrl
->GetModel() );
742 event
.SetItem( m_item
);
743 event
.SetValue( value
);
744 event
.SetColumn( col
);
745 event
.SetEditCanceled( !isValid
);
746 event
.SetEventObject( dv_ctrl
);
747 dv_ctrl
->GetEventHandler()->ProcessEvent( event
);
749 if ( isValid
&& event
.IsAllowed() )
751 dv_ctrl
->GetModel()->ChangeValue(value
, m_item
, col
);
758 void wxDataViewRendererBase::PrepareForItem(const wxDataViewModel
*model
,
759 const wxDataViewItem
& item
,
763 model
->GetValue(value
, item
, column
);
766 wxDataViewItemAttr attr
;
767 model
->GetAttr(item
, column
, attr
);
770 SetEnabled(model
->IsEnabled(item
, column
));
774 int wxDataViewRendererBase::GetEffectiveAlignment() const
776 int alignment
= GetAlignment();
778 if ( alignment
== wxDVR_DEFAULT_ALIGNMENT
)
780 // if we don't have an explicit alignment ourselves, use that of the
781 // column in horizontal direction and default vertical alignment
782 alignment
= GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
788 // ----------------------------------------------------------------------------
789 // wxDataViewCustomRendererBase
790 // ----------------------------------------------------------------------------
792 bool wxDataViewCustomRendererBase::ActivateCell(const wxRect
& cell
,
793 wxDataViewModel
*model
,
794 const wxDataViewItem
& item
,
796 const wxMouseEvent
* mouseEvent
)
798 // Compatibility code
800 return LeftClick(mouseEvent
->GetPosition(), cell
, model
, item
, col
);
802 return Activate(cell
, model
, item
, col
);
805 void wxDataViewCustomRendererBase::RenderBackground(wxDC
* dc
, const wxRect
& rect
)
807 if ( !m_attr
.HasBackgroundColour() )
810 const wxColour
& colour
= m_attr
.GetBackgroundColour();
811 wxDCPenChanger
changePen(*dc
, colour
);
812 wxDCBrushChanger
changeBrush(*dc
, colour
);
814 dc
->DrawRectangle(rect
);
818 wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell
, wxDC
*dc
, int state
)
820 wxCHECK_RET( dc
, "no DC to draw on in custom renderer?" );
822 // adjust the rectangle ourselves to account for the alignment
823 wxRect rectItem
= rectCell
;
824 const int align
= GetEffectiveAlignment();
826 const wxSize size
= GetSize();
828 // take alignment into account only if there is enough space, otherwise
829 // show as much contents as possible
831 // notice that many existing renderers (e.g. wxDataViewSpinRenderer)
832 // return hard-coded size which can be more than they need and if we
833 // trusted their GetSize() we'd draw the text out of cell bounds
836 if ( size
.x
>= 0 && size
.x
< rectCell
.width
)
838 if ( align
& wxALIGN_CENTER_HORIZONTAL
)
839 rectItem
.x
+= (rectCell
.width
- size
.x
)/2;
840 else if ( align
& wxALIGN_RIGHT
)
841 rectItem
.x
+= rectCell
.width
- size
.x
;
842 // else: wxALIGN_LEFT is the default
844 rectItem
.width
= size
.x
;
847 if ( size
.y
>= 0 && size
.y
< rectCell
.height
)
849 if ( align
& wxALIGN_CENTER_VERTICAL
)
850 rectItem
.y
+= (rectCell
.height
- size
.y
)/2;
851 else if ( align
& wxALIGN_BOTTOM
)
852 rectItem
.y
+= rectCell
.height
- size
.y
;
853 // else: wxALIGN_TOP is the default
855 rectItem
.height
= size
.y
;
859 // set up the DC attributes
861 // override custom foreground with the standard one for the selected items
862 // because we currently don't allow changing the selection background and
863 // custom colours may be unreadable on it
865 if ( state
& wxDATAVIEW_CELL_SELECTED
)
866 col
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
867 else if ( m_attr
.HasColour() )
868 col
= m_attr
.GetColour();
869 else // use default foreground
870 col
= GetOwner()->GetOwner()->GetForegroundColour();
872 wxDCTextColourChanger
changeFg(*dc
, col
);
874 wxDCFontChanger
changeFont(*dc
);
875 if ( m_attr
.HasFont() )
876 changeFont
.Set(m_attr
.GetEffectiveFont(dc
->GetFont()));
878 Render(rectItem
, dc
, state
);
881 wxSize
wxDataViewCustomRendererBase::GetTextExtent(const wxString
& str
) const
883 const wxDataViewCtrl
*view
= GetView();
885 if ( m_attr
.HasFont() )
887 wxFont
font(m_attr
.GetEffectiveFont(view
->GetFont()));
889 view
->GetTextExtent(str
, &size
.x
, &size
.y
, NULL
, NULL
, &font
);
894 return view
->GetTextExtent(str
);
899 wxDataViewCustomRendererBase::RenderText(const wxString
& text
,
905 wxRect rectText
= rect
;
906 rectText
.x
+= xoffset
;
907 rectText
.width
-= xoffset
;
909 // check if we want to ellipsize the text if it doesn't fit
910 wxString ellipsizedText
;
911 if ( GetEllipsizeMode() != wxELLIPSIZE_NONE
)
913 ellipsizedText
= wxControl::Ellipsize
919 wxELLIPSIZE_FLAGS_NONE
923 // get the alignment to use
924 dc
->DrawLabel(ellipsizedText
.empty() ? text
: ellipsizedText
,
925 rectText
, GetEffectiveAlignment());
928 //-----------------------------------------------------------------------------
929 // wxDataViewEditorCtrlEvtHandler
930 //-----------------------------------------------------------------------------
932 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
933 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
934 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
935 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
936 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
939 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
943 m_focusOnIdle
= false;
944 if (wxWindow::FindFocus() != m_editorCtrl
)
945 m_editorCtrl
->SetFocus();
951 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
954 m_owner
->FinishEditing();
957 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
959 switch ( event
.m_keyCode
)
963 m_owner
->FinishEditing();
969 m_owner
->CancelEditing();
977 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
982 m_owner
->FinishEditing();
988 // ---------------------------------------------------------
989 // wxDataViewColumnBase
990 // ---------------------------------------------------------
992 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
993 unsigned int model_column
)
995 m_renderer
= renderer
;
996 m_model_column
= model_column
;
998 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
1001 wxDataViewColumnBase::~wxDataViewColumnBase()
1006 // ---------------------------------------------------------
1007 // wxDataViewCtrlBase
1008 // ---------------------------------------------------------
1010 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
1012 wxDataViewCtrlBase::wxDataViewCtrlBase()
1015 m_expander_column
= 0;
1019 wxDataViewCtrlBase::~wxDataViewCtrlBase()
1028 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
1032 m_model
->DecRef(); // discard old model, if any
1035 // add our own reference to the new model:
1045 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
1050 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
1055 void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem
& item
)
1057 if (!m_model
) return;
1059 if (!item
.IsOk()) return;
1061 wxVector
<wxDataViewItem
> parentChain
;
1063 // at first we get all the parents of the selected item
1064 wxDataViewItem parent
= m_model
->GetParent(item
);
1065 while (parent
.IsOk())
1067 parentChain
.push_back(parent
);
1068 parent
= m_model
->GetParent(parent
);
1071 // then we expand the parents, starting at the root
1072 while (!parentChain
.empty())
1074 Expand(parentChain
.back());
1075 parentChain
.pop_back();
1079 wxDataViewItem
wxDataViewCtrlBase::GetCurrentItem() const
1081 return HasFlag(wxDV_MULTIPLE
) ? DoGetCurrentItem()
1085 void wxDataViewCtrlBase::SetCurrentItem(const wxDataViewItem
& item
)
1087 wxCHECK_RET( item
.IsOk(), "Can't make current an invalid item." );
1089 if ( HasFlag(wxDV_MULTIPLE
) )
1090 DoSetCurrentItem(item
);
1095 wxDataViewItem
wxDataViewCtrlBase::GetSelection() const
1097 if ( GetSelectedItemsCount() != 1 )
1098 return wxDataViewItem();
1100 wxDataViewItemArray selections
;
1101 GetSelections(selections
);
1102 return selections
[0];
1106 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
1107 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1109 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1110 new wxDataViewTextRenderer( wxT("string"), mode
),
1111 model_column
, width
, align
, flags
);
1112 AppendColumn( ret
);
1117 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
1118 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1120 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1121 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1122 model_column
, width
, align
, flags
);
1123 AppendColumn( ret
);
1128 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
1129 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1131 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1132 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1133 model_column
, width
, align
, flags
);
1134 AppendColumn( ret
);
1139 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
1140 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1142 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1143 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1144 model_column
, width
, align
, flags
);
1145 AppendColumn( ret
);
1150 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
1151 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1153 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1154 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1155 model_column
, width
, align
, flags
);
1156 AppendColumn( ret
);
1161 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
1162 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1164 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1165 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1166 model_column
, width
, align
, flags
);
1167 AppendColumn( ret
);
1172 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1173 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1175 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1176 new wxDataViewTextRenderer( wxT("string"), mode
),
1177 model_column
, width
, align
, flags
);
1178 AppendColumn( ret
);
1183 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1184 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1186 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1187 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1188 model_column
, width
, align
, flags
);
1189 AppendColumn( ret
);
1194 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1195 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1197 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1198 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1199 model_column
, width
, align
, flags
);
1200 AppendColumn( ret
);
1205 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1206 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1208 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1209 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1210 model_column
, width
, align
, flags
);
1211 AppendColumn( ret
);
1216 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1217 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1219 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1220 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1221 model_column
, width
, align
, flags
);
1222 AppendColumn( ret
);
1227 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1228 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1230 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1231 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1232 model_column
, width
, align
, flags
);
1233 AppendColumn( ret
);
1238 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1239 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1241 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1242 new wxDataViewTextRenderer( wxT("string"), mode
),
1243 model_column
, width
, align
, flags
);
1244 PrependColumn( ret
);
1249 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1250 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1252 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1253 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1254 model_column
, width
, align
, flags
);
1255 PrependColumn( ret
);
1260 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1261 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1264 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1265 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1266 model_column
, width
, align
, flags
);
1267 PrependColumn( ret
);
1272 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1273 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1275 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1276 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1277 model_column
, width
, align
, flags
);
1278 PrependColumn( ret
);
1283 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1284 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1286 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1287 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1288 model_column
, width
, align
, flags
);
1289 PrependColumn( ret
);
1294 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1295 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1297 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1298 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1299 model_column
, width
, align
, flags
);
1300 PrependColumn( ret
);
1305 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1306 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1308 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1309 new wxDataViewTextRenderer( wxT("string"), mode
),
1310 model_column
, width
, align
, flags
);
1311 PrependColumn( ret
);
1316 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1317 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1319 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1320 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1321 model_column
, width
, align
, flags
);
1322 PrependColumn( ret
);
1327 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1328 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1330 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1331 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1332 model_column
, width
, align
, flags
);
1333 PrependColumn( ret
);
1338 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1339 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1341 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1342 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1343 model_column
, width
, align
, flags
);
1344 PrependColumn( ret
);
1349 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1350 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1352 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1353 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1354 model_column
, width
, align
, flags
);
1355 PrependColumn( ret
);
1360 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1361 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1363 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1364 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1365 model_column
, width
, align
, flags
);
1366 PrependColumn( ret
);
1371 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1373 col
->SetOwner( (wxDataViewCtrl
*) this );
1378 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1380 col
->SetOwner( (wxDataViewCtrl
*) this );
1385 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1387 col
->SetOwner( (wxDataViewCtrl
*) this );
1391 void wxDataViewCtrlBase::StartEditor(const wxDataViewItem
& item
, unsigned int column
)
1393 EditItem(item
, GetColumn(column
));
1396 // ---------------------------------------------------------
1398 // ---------------------------------------------------------
1400 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1402 wxDEFINE_EVENT( wxEVT_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
);
1404 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
);
1405 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
);
1406 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
);
1407 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
);
1408 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
);
1409 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
);
1410 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_START_EDITING
, wxDataViewEvent
);
1411 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
);
1412 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
);
1414 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
);
1416 wxDEFINE_EVENT( wxEVT_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
);
1417 wxDEFINE_EVENT( wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
);
1418 wxDEFINE_EVENT( wxEVT_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
);
1419 wxDEFINE_EVENT( wxEVT_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
);
1421 wxDEFINE_EVENT( wxEVT_DATAVIEW_CACHE_HINT
, wxDataViewEvent
);
1423 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
);
1424 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE
, wxDataViewEvent
);
1425 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_DROP
, wxDataViewEvent
);
1429 // -------------------------------------
1430 // wxDataViewSpinRenderer
1431 // -------------------------------------
1433 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1434 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1440 wxWindow
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1443 wxSize size
= labelRect
.GetSize();
1445 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1448 str
.Printf( wxT("%d"), (int) l
);
1449 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1450 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1452 size
= sc
->GetSize();
1453 wxPoint pt
= sc
->GetPosition();
1454 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1460 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1462 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1463 long l
= sc
->GetValue();
1468 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1471 str
.Printf(wxT("%d"), (int) m_data
);
1472 RenderText( str
, 0, rect
, dc
, state
);
1476 wxSize
wxDataViewSpinRenderer::GetSize() const
1478 wxSize sz
= GetTextExtent(wxString::Format("%d", (int)m_data
));
1480 // Allow some space for the spin buttons, which is approximately the size
1481 // of a scrollbar (and getting pixel-exact value would be complicated).
1482 // Also add some whitespace between the text and the button:
1483 sz
.x
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1484 sz
.x
+= GetTextExtent("M").x
;
1489 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1491 m_data
= value
.GetLong();
1495 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1501 // -------------------------------------
1502 // wxDataViewChoiceRenderer
1503 // -------------------------------------
1505 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
1507 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1508 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1510 m_choices
= choices
;
1513 wxWindow
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1515 wxChoice
* c
= new wxChoice
1519 labelRect
.GetTopLeft(),
1520 wxSize(labelRect
.GetWidth(), -1),
1523 c
->Move(labelRect
.GetRight() - c
->GetRect().width
, wxDefaultCoord
);
1524 c
->SetStringSelection( value
.GetString() );
1528 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1530 wxChoice
*c
= (wxChoice
*) editor
;
1531 wxString s
= c
->GetStringSelection();
1536 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1538 RenderText( m_data
, 0, rect
, dc
, state
);
1542 wxSize
wxDataViewChoiceRenderer::GetSize() const
1546 for ( wxArrayString::const_iterator i
= m_choices
.begin(); i
!= m_choices
.end(); ++i
)
1547 sz
.IncTo(GetTextExtent(*i
));
1549 // Allow some space for the right-side button, which is approximately the
1550 // size of a scrollbar (and getting pixel-exact value would be complicated).
1551 // Also add some whitespace between the text and the button:
1552 sz
.x
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1553 sz
.x
+= GetTextExtent("M").x
;
1558 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1560 m_data
= value
.GetString();
1564 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1570 // ----------------------------------------------------------------------------
1571 // wxDataViewChoiceByIndexRenderer
1572 // ----------------------------------------------------------------------------
1574 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
1575 wxDataViewCellMode mode
, int alignment
) :
1576 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
1580 wxWindow
* wxDataViewChoiceByIndexRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1582 wxVariant string_value
= GetChoice( value
.GetLong() );
1584 return wxDataViewChoiceRenderer::CreateEditorCtrl( parent
, labelRect
, string_value
);
1587 bool wxDataViewChoiceByIndexRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1589 wxVariant string_value
;
1590 if (!wxDataViewChoiceRenderer::GetValueFromEditorCtrl( editor
, string_value
))
1593 value
= (long) GetChoices().Index( string_value
.GetString() );
1597 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
1599 wxVariant string_value
= GetChoice( value
.GetLong() );
1600 return wxDataViewChoiceRenderer::SetValue( string_value
);
1603 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
1605 wxVariant string_value
;
1606 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
1609 value
= (long) GetChoices().Index( string_value
.GetString() );
1615 // ---------------------------------------------------------
1616 // wxDataViewDateRenderer
1617 // ---------------------------------------------------------
1619 #if (defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)) && wxUSE_DATEPICKCTRL
1621 wxDataViewDateRenderer::wxDataViewDateRenderer(const wxString
& varianttype
,
1622 wxDataViewCellMode mode
, int align
)
1623 : wxDataViewCustomRenderer(varianttype
, mode
, align
)
1628 wxDataViewDateRenderer::CreateEditorCtrl(wxWindow
*parent
, wxRect labelRect
, const wxVariant
& value
)
1630 return new wxDatePickerCtrl
1634 value
.GetDateTime(),
1635 labelRect
.GetTopLeft(),
1640 bool wxDataViewDateRenderer::GetValueFromEditorCtrl(wxWindow
*editor
, wxVariant
& value
)
1642 wxDatePickerCtrl
*ctrl
= static_cast<wxDatePickerCtrl
*>(editor
);
1643 value
= ctrl
->GetValue();
1647 bool wxDataViewDateRenderer::SetValue(const wxVariant
& value
)
1649 m_date
= value
.GetDateTime();
1653 bool wxDataViewDateRenderer::GetValue(wxVariant
& value
) const
1659 bool wxDataViewDateRenderer::Render(wxRect cell
, wxDC
* dc
, int state
)
1661 wxString tmp
= m_date
.FormatDate();
1662 RenderText( tmp
, 0, cell
, dc
, state
);
1666 wxSize
wxDataViewDateRenderer::GetSize() const
1668 return GetTextExtent(m_date
.FormatDate());
1671 #endif // (defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)) && wxUSE_DATEPICKCTRL
1673 //-----------------------------------------------------------------------------
1674 // wxDataViewListStore
1675 //-----------------------------------------------------------------------------
1677 wxDataViewListStore::wxDataViewListStore()
1681 wxDataViewListStore::~wxDataViewListStore()
1683 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1684 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1686 wxDataViewListStoreLine
* line
= *it
;
1691 void wxDataViewListStore::PrependColumn( const wxString
&varianttype
)
1693 m_cols
.Insert( varianttype
, 0 );
1696 void wxDataViewListStore::InsertColumn( unsigned int pos
, const wxString
&varianttype
)
1698 m_cols
.Insert( varianttype
, pos
);
1701 void wxDataViewListStore::AppendColumn( const wxString
&varianttype
)
1703 m_cols
.Add( varianttype
);
1706 unsigned int wxDataViewListStore::GetColumnCount() const
1708 return m_cols
.GetCount();
1711 unsigned int wxDataViewListStore::GetItemCount() const
1713 return m_data
.size();
1716 wxString
wxDataViewListStore::GetColumnType( unsigned int pos
) const
1721 void wxDataViewListStore::AppendItem( const wxVector
<wxVariant
> &values
, wxUIntPtr data
)
1723 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1724 line
->m_values
= values
;
1725 m_data
.push_back( line
);
1730 void wxDataViewListStore::PrependItem( const wxVector
<wxVariant
> &values
, wxUIntPtr data
)
1732 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1733 line
->m_values
= values
;
1734 m_data
.insert( m_data
.begin(), line
);
1739 void wxDataViewListStore::InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
,
1742 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1743 line
->m_values
= values
;
1744 m_data
.insert( m_data
.begin()+row
, line
);
1749 void wxDataViewListStore::DeleteItem( unsigned int row
)
1751 wxVector
<wxDataViewListStoreLine
*>::iterator it
= m_data
.begin() + row
;
1758 void wxDataViewListStore::DeleteAllItems()
1760 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1761 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1763 wxDataViewListStoreLine
* line
= *it
;
1772 void wxDataViewListStore::SetItemData( const wxDataViewItem
& item
, wxUIntPtr data
)
1774 wxDataViewListStoreLine
* line
= m_data
[GetRow(item
)];
1777 line
->SetData( data
);
1780 wxUIntPtr
wxDataViewListStore::GetItemData( const wxDataViewItem
& item
) const
1782 wxDataViewListStoreLine
* line
= m_data
[GetRow(item
)];
1783 if (!line
) return static_cast<wxUIntPtr
>(NULL
);
1785 return line
->GetData();
1788 void wxDataViewListStore::GetValueByRow( wxVariant
&value
, unsigned int row
, unsigned int col
) const
1790 wxDataViewListStoreLine
*line
= m_data
[row
];
1791 value
= line
->m_values
[col
];
1794 bool wxDataViewListStore::SetValueByRow( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1796 wxDataViewListStoreLine
*line
= m_data
[row
];
1797 line
->m_values
[col
] = value
;
1802 //-----------------------------------------------------------------------------
1803 // wxDataViewListCtrl
1804 //-----------------------------------------------------------------------------
1806 IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl
,wxDataViewCtrl
)
1808 BEGIN_EVENT_TABLE(wxDataViewListCtrl
,wxDataViewCtrl
)
1809 EVT_SIZE( wxDataViewListCtrl::OnSize
)
1812 wxDataViewListCtrl::wxDataViewListCtrl()
1816 wxDataViewListCtrl::wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
1817 const wxPoint
& pos
, const wxSize
& size
, long style
,
1818 const wxValidator
& validator
)
1820 Create( parent
, id
, pos
, size
, style
, validator
);
1823 wxDataViewListCtrl::~wxDataViewListCtrl()
1828 bool wxDataViewListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1829 const wxPoint
& pos
, const wxSize
& size
, long style
,
1830 const wxValidator
& validator
)
1832 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
1835 wxDataViewListStore
*store
= new wxDataViewListStore
;
1836 AssociateModel( store
);
1842 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1844 GetStore()->AppendColumn( varianttype
);
1845 return wxDataViewCtrl::AppendColumn( column
);
1848 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1850 GetStore()->PrependColumn( varianttype
);
1851 return wxDataViewCtrl::PrependColumn( column
);
1854 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
)
1856 GetStore()->InsertColumn( pos
, varianttype
);
1857 return wxDataViewCtrl::InsertColumn( pos
, column
);
1860 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*col
)
1862 return PrependColumn( col
, "string" );
1865 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
1867 return InsertColumn( pos
, col
, "string" );
1870 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*col
)
1872 return AppendColumn( col
, "string" );
1875 wxDataViewColumn
*wxDataViewListCtrl::AppendTextColumn( const wxString
&label
,
1876 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1878 GetStore()->AppendColumn( wxT("string") );
1880 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1881 new wxDataViewTextRenderer( wxT("string"), mode
),
1882 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1884 wxDataViewCtrl::AppendColumn( ret
);
1889 wxDataViewColumn
*wxDataViewListCtrl::AppendToggleColumn( const wxString
&label
,
1890 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1892 GetStore()->AppendColumn( wxT("bool") );
1894 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1895 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1896 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1898 wxDataViewCtrl::AppendColumn( ret
);
1903 wxDataViewColumn
*wxDataViewListCtrl::AppendProgressColumn( const wxString
&label
,
1904 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1906 GetStore()->AppendColumn( wxT("long") );
1908 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1909 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1910 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1912 wxDataViewCtrl::AppendColumn( ret
);
1917 wxDataViewColumn
*wxDataViewListCtrl::AppendIconTextColumn( const wxString
&label
,
1918 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1920 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
1922 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1923 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1924 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1926 wxDataViewCtrl::AppendColumn( ret
);
1931 void wxDataViewListCtrl::OnSize( wxSizeEvent
&event
)
1936 //-----------------------------------------------------------------------------
1937 // wxDataViewTreeStore
1938 //-----------------------------------------------------------------------------
1940 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1941 wxDataViewTreeStoreNode
*parent
,
1942 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1950 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1956 #include "wx/listimpl.cpp"
1957 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1959 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1960 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1961 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1962 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1964 m_iconExpanded
= expanded
;
1965 m_isExpanded
= false;
1966 m_children
.DeleteContents(true);
1969 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1973 //-----------------------------------------------------------------------------
1975 wxDataViewTreeStore::wxDataViewTreeStore()
1977 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1980 wxDataViewTreeStore::~wxDataViewTreeStore()
1985 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1986 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1988 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1989 if (!parent_node
) return wxDataViewItem(0);
1991 wxDataViewTreeStoreNode
*node
=
1992 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1993 parent_node
->GetChildren().Append( node
);
1995 return node
->GetItem();
1998 wxDataViewItem
wxDataViewTreeStore::PrependItem( const wxDataViewItem
& parent
,
1999 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
2001 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2002 if (!parent_node
) return wxDataViewItem(0);
2004 wxDataViewTreeStoreNode
*node
=
2005 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
2006 parent_node
->GetChildren().Insert( node
);
2008 return node
->GetItem();
2012 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& parent
,
2013 const wxDataViewItem
& previous
,
2014 const wxString
& text
,
2018 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2019 if (!parent_node
) return wxDataViewItem(0);
2021 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
2022 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
2023 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
2025 wxDataViewTreeStoreNode
*node
=
2026 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
2027 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
2029 return node
->GetItem();
2032 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
2033 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
2034 wxClientData
*data
)
2036 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2037 if (!parent_node
) return wxDataViewItem(0);
2039 wxDataViewTreeStoreContainerNode
*node
=
2040 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
2041 parent_node
->GetChildren().Insert( node
);
2043 return node
->GetItem();
2047 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
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 wxDataViewTreeStoreContainerNode
*node
=
2057 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
2058 parent_node
->GetChildren().Append( node
);
2060 return node
->GetItem();
2064 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& parent
,
2065 const wxDataViewItem
& previous
,
2066 const wxString
& text
,
2068 const wxIcon
& expanded
,
2069 wxClientData
* data
)
2071 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2072 if (!parent_node
) return wxDataViewItem(0);
2074 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
2075 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
2076 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
2078 wxDataViewTreeStoreContainerNode
*node
=
2079 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
2080 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
2082 return node
->GetItem();
2085 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
& item
) const
2087 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2088 if (!node
) return false;
2090 return node
->IsContainer();
2093 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
2095 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2096 if (!parent_node
) return wxDataViewItem(0);
2098 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
2100 return wxDataViewItem(node
->GetData());
2102 return wxDataViewItem(0);
2105 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
2107 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
2108 if (!node
) return -1;
2110 if (!node
->IsContainer())
2113 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
2114 return (int) container_node
->GetChildren().GetCount();
2117 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2119 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2122 node
->SetText( text
);
2125 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
2127 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2128 if (!node
) return wxEmptyString
;
2130 return node
->GetText();
2133 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2135 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2138 node
->SetIcon( icon
);
2141 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
2143 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2144 if (!node
) return wxNullIcon
;
2146 return node
->GetIcon();
2149 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2151 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2154 node
->SetExpandedIcon( icon
);
2157 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
2159 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2160 if (!node
) return wxNullIcon
;
2162 return node
->GetExpandedIcon();
2165 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
2167 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2170 node
->SetData( data
);
2173 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
2175 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2176 if (!node
) return NULL
;
2178 return node
->GetData();
2181 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
2183 if (!item
.IsOk()) return;
2185 wxDataViewItem parent_item
= GetParent( item
);
2187 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
2188 if (!parent_node
) return;
2190 parent_node
->GetChildren().DeleteObject( FindNode(item
) );
2193 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
2195 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2198 node
->GetChildren().clear();
2201 void wxDataViewTreeStore::DeleteAllItems()
2203 DeleteChildren(wxDataViewItem(m_root
));
2207 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
2208 const wxDataViewItem
&item
,
2209 unsigned int WXUNUSED(col
)) const
2211 // if (col != 0) return;
2213 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2216 wxIcon
icon( node
->GetIcon());
2217 if (node
->IsContainer())
2219 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
2220 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
2221 icon
= container
->GetExpandedIcon();
2224 wxDataViewIconText
data( node
->GetText(), icon
);
2230 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
2231 const wxDataViewItem
& item
,
2232 unsigned int WXUNUSED(col
))
2234 // if (col != 0) return false;
2236 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2237 if (!node
) return false;
2239 wxDataViewIconText data
;
2243 node
->SetText( data
.GetText() );
2244 node
->SetIcon( data
.GetIcon() );
2249 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
2251 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2252 if (!node
) return wxDataViewItem(0);
2254 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
2255 if (!parent
) return wxDataViewItem(0);
2257 if (parent
== m_root
)
2258 return wxDataViewItem(0);
2260 return parent
->GetItem();
2263 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
2265 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2266 if (!node
) return 0;
2268 wxDataViewTreeStoreNodeList::iterator iter
;
2269 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2271 wxDataViewTreeStoreNode
* child
= *iter
;
2272 children
.Add( child
->GetItem() );
2275 return node
->GetChildren().GetCount();
2278 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
2279 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) ) const
2281 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
2282 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
2284 if (!node1
|| !node2
)
2287 wxDataViewTreeStoreContainerNode
* parent1
=
2288 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
2289 wxDataViewTreeStoreContainerNode
* parent2
=
2290 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
2292 if (parent1
!= parent2
)
2294 wxLogError( wxT("Comparing items with different parent.") );
2298 if (node1
->IsContainer() && !node2
->IsContainer())
2301 if (node2
->IsContainer() && !node1
->IsContainer())
2304 return parent1
->GetChildren().IndexOf( node1
) - parent2
->GetChildren().IndexOf( node2
);
2307 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
2312 return (wxDataViewTreeStoreNode
*) item
.GetID();
2315 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
2318 return (wxDataViewTreeStoreContainerNode
*) m_root
;
2320 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
2322 if (!node
->IsContainer())
2325 return (wxDataViewTreeStoreContainerNode
*) node
;
2328 //-----------------------------------------------------------------------------
2329 // wxDataViewTreeCtrl
2330 //-----------------------------------------------------------------------------
2332 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2334 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2335 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
2336 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
2337 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
2340 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2341 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2343 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
2346 // create the standard model and a column in the tree
2347 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
2348 AssociateModel( store
);
2351 AppendIconTextColumn
2353 wxString(), // no label (header is not shown anyhow)
2354 0, // the only model column
2355 wxDATAVIEW_CELL_EDITABLE
,
2356 -1, // default width
2357 wxALIGN_NOT
, // and alignment
2364 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
2365 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2367 wxDataViewItem res
= GetStore()->
2368 AppendItem( parent
, text
, GetImage(iconIndex
), data
);
2370 GetStore()->ItemAdded( parent
, res
);
2375 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
2376 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2378 wxDataViewItem res
= GetStore()->
2379 PrependItem( parent
, text
, GetImage(iconIndex
), data
);
2381 GetStore()->ItemAdded( parent
, res
);
2386 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2387 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2389 wxDataViewItem res
= GetStore()->
2390 InsertItem( parent
, previous
, text
, GetImage(iconIndex
), data
);
2392 GetStore()->ItemAdded( parent
, res
);
2397 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
2398 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2400 wxDataViewItem res
= GetStore()->
2401 PrependContainer( parent
, text
,
2402 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2404 GetStore()->ItemAdded( parent
, res
);
2409 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
2410 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2412 wxDataViewItem res
= GetStore()->
2413 AppendContainer( parent
, text
,
2414 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2416 GetStore()->ItemAdded( parent
, res
);
2421 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2422 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2424 wxDataViewItem res
= GetStore()->
2425 InsertContainer( parent
, previous
, text
,
2426 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2428 GetStore()->ItemAdded( parent
, res
);
2433 void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2435 GetStore()->SetItemText(item
,text
);
2438 GetStore()->ValueChanged( item
, 0 );
2441 void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2443 GetStore()->SetItemIcon(item
,icon
);
2446 GetStore()->ValueChanged( item
, 0 );
2449 void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2451 GetStore()->SetItemExpandedIcon(item
,icon
);
2454 GetStore()->ValueChanged( item
, 0 );
2457 void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem
& item
)
2459 wxDataViewItem parent_item
= GetStore()->GetParent( item
);
2461 GetStore()->DeleteItem(item
);
2464 GetStore()->ItemDeleted( parent_item
, item
);
2467 void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem
& item
)
2469 wxDataViewTreeStoreContainerNode
*node
= GetStore()->FindContainerNode( item
);
2472 wxDataViewItemArray array
;
2473 wxDataViewTreeStoreNodeList::iterator iter
;
2474 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2476 wxDataViewTreeStoreNode
* child
= *iter
;
2477 array
.Add( child
->GetItem() );
2480 GetStore()->DeleteChildren( item
);
2483 GetStore()->ItemsDeleted( item
, array
);
2486 void wxDataViewTreeCtrl::DeleteAllItems()
2488 GetStore()->DeleteAllItems();
2490 GetStore()->Cleared();
2493 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
2495 if (HasImageList()) return;
2497 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2498 if (!container
) return;
2500 container
->SetExpanded( true );
2502 GetStore()->ItemChanged( event
.GetItem() );
2505 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
2507 if (HasImageList()) return;
2509 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2510 if (!container
) return;
2512 container
->SetExpanded( false );
2514 GetStore()->ItemChanged( event
.GetItem() );
2517 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
2519 #if defined(wxUSE_GENERICDATAVIEWCTRL)
2520 // automatically resize our only column to take the entire control width
2521 if ( GetColumnCount() )
2523 wxSize size
= GetClientSize();
2524 GetColumn(0)->SetWidth(size
.x
);
2530 #endif // wxUSE_DATAVIEWCTRL