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 // ----------------------------------------------------------------------------
775 // wxDataViewCustomRendererBase
776 // ----------------------------------------------------------------------------
778 bool wxDataViewCustomRendererBase::ActivateCell(const wxRect
& cell
,
779 wxDataViewModel
*model
,
780 const wxDataViewItem
& item
,
782 const wxMouseEvent
* mouseEvent
)
784 // Compatibility code
786 return LeftClick(mouseEvent
->GetPosition(), cell
, model
, item
, col
);
788 return Activate(cell
, model
, item
, col
);
791 void wxDataViewCustomRendererBase::RenderBackground(wxDC
* dc
, const wxRect
& rect
)
793 if ( !m_attr
.HasBackgroundColour() )
796 const wxColour
& colour
= m_attr
.GetBackgroundColour();
797 wxDCPenChanger
changePen(*dc
, colour
);
798 wxDCBrushChanger
changeBrush(*dc
, colour
);
800 dc
->DrawRectangle(rect
);
804 wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell
, wxDC
*dc
, int state
)
806 wxCHECK_RET( dc
, "no DC to draw on in custom renderer?" );
808 // adjust the rectangle ourselves to account for the alignment
809 wxRect rectItem
= rectCell
;
810 const int align
= GetAlignment();
811 if ( align
!= wxDVR_DEFAULT_ALIGNMENT
)
813 const wxSize size
= GetSize();
815 // take alignment into account only if there is enough space, otherwise
816 // show as much contents as possible
818 // notice that many existing renderers (e.g. wxDataViewSpinRenderer)
819 // return hard-coded size which can be more than they need and if we
820 // trusted their GetSize() we'd draw the text out of cell bounds
823 if ( size
.x
>= 0 && size
.x
< rectCell
.width
)
825 if ( align
& wxALIGN_CENTER_HORIZONTAL
)
826 rectItem
.x
+= (rectCell
.width
- size
.x
)/2;
827 else if ( align
& wxALIGN_RIGHT
)
828 rectItem
.x
+= rectCell
.width
- size
.x
;
829 // else: wxALIGN_LEFT is the default
831 rectItem
.width
= size
.x
;
834 if ( size
.y
>= 0 && size
.y
< rectCell
.height
)
836 if ( align
& wxALIGN_CENTER_VERTICAL
)
837 rectItem
.y
+= (rectCell
.height
- size
.y
)/2;
838 else if ( align
& wxALIGN_BOTTOM
)
839 rectItem
.y
+= rectCell
.height
- size
.y
;
840 // else: wxALIGN_TOP is the default
842 rectItem
.height
= size
.y
;
847 // set up the DC attributes
849 // override custom foreground with the standard one for the selected items
850 // because we currently don't allow changing the selection background and
851 // custom colours may be unreadable on it
853 if ( state
& wxDATAVIEW_CELL_SELECTED
)
854 col
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
855 else if ( m_attr
.HasColour() )
856 col
= m_attr
.GetColour();
857 else // use default foreground
858 col
= GetOwner()->GetOwner()->GetForegroundColour();
860 wxDCTextColourChanger
changeFg(*dc
, col
);
862 wxDCFontChanger
changeFont(*dc
);
863 if ( m_attr
.HasFont() )
864 changeFont
.Set(m_attr
.GetEffectiveFont(dc
->GetFont()));
866 Render(rectItem
, dc
, state
);
869 wxSize
wxDataViewCustomRendererBase::GetTextExtent(const wxString
& str
) const
871 const wxDataViewCtrl
*view
= GetView();
873 if ( m_attr
.HasFont() )
875 wxFont
font(m_attr
.GetEffectiveFont(view
->GetFont()));
877 view
->GetTextExtent(str
, &size
.x
, &size
.y
, NULL
, NULL
, &font
);
882 return view
->GetTextExtent(str
);
887 wxDataViewCustomRendererBase::RenderText(const wxString
& text
,
893 wxRect rectText
= rect
;
894 rectText
.x
+= xoffset
;
895 rectText
.width
-= xoffset
;
897 // check if we want to ellipsize the text if it doesn't fit
898 wxString ellipsizedText
;
899 if ( GetEllipsizeMode() != wxELLIPSIZE_NONE
)
901 ellipsizedText
= wxControl::Ellipsize
907 wxELLIPSIZE_FLAGS_NONE
911 // get the alignment to use
912 int align
= GetAlignment();
913 if ( align
== wxDVR_DEFAULT_ALIGNMENT
)
915 // if we don't have an explicit alignment ourselves, use that of the
916 // column in horizontal direction and default vertical alignment
917 align
= GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL
;
920 dc
->DrawLabel(ellipsizedText
.empty() ? text
: ellipsizedText
,
924 //-----------------------------------------------------------------------------
925 // wxDataViewEditorCtrlEvtHandler
926 //-----------------------------------------------------------------------------
928 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
929 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
930 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
931 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
932 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter
)
935 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
939 m_focusOnIdle
= false;
940 if (wxWindow::FindFocus() != m_editorCtrl
)
941 m_editorCtrl
->SetFocus();
947 void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent
&WXUNUSED(event
) )
950 m_owner
->FinishEditing();
953 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
955 switch ( event
.m_keyCode
)
959 m_owner
->FinishEditing();
965 m_owner
->CancelEditing();
973 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
978 m_owner
->FinishEditing();
984 // ---------------------------------------------------------
985 // wxDataViewColumnBase
986 // ---------------------------------------------------------
988 void wxDataViewColumnBase::Init(wxDataViewRenderer
*renderer
,
989 unsigned int model_column
)
991 m_renderer
= renderer
;
992 m_model_column
= model_column
;
994 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
997 wxDataViewColumnBase::~wxDataViewColumnBase()
1002 // ---------------------------------------------------------
1003 // wxDataViewCtrlBase
1004 // ---------------------------------------------------------
1006 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
1008 wxDataViewCtrlBase::wxDataViewCtrlBase()
1011 m_expander_column
= 0;
1015 wxDataViewCtrlBase::~wxDataViewCtrlBase()
1024 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel
*model
)
1028 m_model
->DecRef(); // discard old model, if any
1031 // add our own reference to the new model:
1041 wxDataViewModel
* wxDataViewCtrlBase::GetModel()
1046 const wxDataViewModel
* wxDataViewCtrlBase::GetModel() const
1051 void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem
& item
)
1053 if (!m_model
) return;
1055 if (!item
.IsOk()) return;
1057 wxVector
<wxDataViewItem
> parentChain
;
1059 // at first we get all the parents of the selected item
1060 wxDataViewItem parent
= m_model
->GetParent(item
);
1061 while (parent
.IsOk())
1063 parentChain
.push_back(parent
);
1064 parent
= m_model
->GetParent(parent
);
1067 // then we expand the parents, starting at the root
1068 while (!parentChain
.empty())
1070 Expand(parentChain
.back());
1071 parentChain
.pop_back();
1075 wxDataViewItem
wxDataViewCtrlBase::GetCurrentItem() const
1077 return HasFlag(wxDV_MULTIPLE
) ? DoGetCurrentItem()
1081 void wxDataViewCtrlBase::SetCurrentItem(const wxDataViewItem
& item
)
1083 wxCHECK_RET( item
.IsOk(), "Can't make current an invalid item." );
1085 if ( HasFlag(wxDV_MULTIPLE
) )
1086 DoSetCurrentItem(item
);
1091 wxDataViewItem
wxDataViewCtrlBase::GetSelection() const
1093 if ( GetSelectedItemsCount() != 1 )
1094 return wxDataViewItem();
1096 wxDataViewItemArray selections
;
1097 GetSelections(selections
);
1098 return selections
[0];
1102 wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
1103 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1105 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1106 new wxDataViewTextRenderer( wxT("string"), mode
),
1107 model_column
, width
, align
, flags
);
1108 AppendColumn( ret
);
1113 wxDataViewCtrlBase::AppendIconTextColumn( const wxString
&label
, unsigned int model_column
,
1114 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1116 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1117 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1118 model_column
, width
, align
, flags
);
1119 AppendColumn( ret
);
1124 wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
1125 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1127 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1128 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1129 model_column
, width
, align
, flags
);
1130 AppendColumn( ret
);
1135 wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
1136 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1138 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1139 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1140 model_column
, width
, align
, flags
);
1141 AppendColumn( ret
);
1146 wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
1147 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1149 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1150 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1151 model_column
, width
, align
, flags
);
1152 AppendColumn( ret
);
1157 wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
1158 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1160 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1161 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1162 model_column
, width
, align
, flags
);
1163 AppendColumn( ret
);
1168 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1169 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1171 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1172 new wxDataViewTextRenderer( wxT("string"), mode
),
1173 model_column
, width
, align
, flags
);
1174 AppendColumn( ret
);
1179 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1180 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1182 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1183 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1184 model_column
, width
, align
, flags
);
1185 AppendColumn( ret
);
1190 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1191 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1193 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1194 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1195 model_column
, width
, align
, flags
);
1196 AppendColumn( ret
);
1201 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1202 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1204 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1205 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1206 model_column
, width
, align
, flags
);
1207 AppendColumn( ret
);
1212 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1213 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1215 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1216 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1217 model_column
, width
, align
, flags
);
1218 AppendColumn( ret
);
1223 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1224 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1226 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1227 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1228 model_column
, width
, align
, flags
);
1229 AppendColumn( ret
);
1234 wxDataViewCtrlBase::PrependTextColumn( const wxString
&label
, unsigned int model_column
,
1235 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1237 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1238 new wxDataViewTextRenderer( wxT("string"), mode
),
1239 model_column
, width
, align
, flags
);
1240 PrependColumn( ret
);
1245 wxDataViewCtrlBase::PrependIconTextColumn( const wxString
&label
, unsigned int model_column
,
1246 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1248 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1249 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1250 model_column
, width
, align
, flags
);
1251 PrependColumn( ret
);
1256 wxDataViewCtrlBase::PrependToggleColumn( const wxString
&label
, unsigned int model_column
,
1257 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1260 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1261 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1262 model_column
, width
, align
, flags
);
1263 PrependColumn( ret
);
1268 wxDataViewCtrlBase::PrependProgressColumn( const wxString
&label
, unsigned int model_column
,
1269 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1271 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1272 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1273 model_column
, width
, align
, flags
);
1274 PrependColumn( ret
);
1279 wxDataViewCtrlBase::PrependDateColumn( const wxString
&label
, unsigned int model_column
,
1280 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1282 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1283 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1284 model_column
, width
, align
, flags
);
1285 PrependColumn( ret
);
1290 wxDataViewCtrlBase::PrependBitmapColumn( const wxString
&label
, unsigned int model_column
,
1291 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1293 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1294 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1295 model_column
, width
, align
, flags
);
1296 PrependColumn( ret
);
1301 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1302 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1304 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1305 new wxDataViewTextRenderer( wxT("string"), mode
),
1306 model_column
, width
, align
, flags
);
1307 PrependColumn( ret
);
1312 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1313 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1315 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1316 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1317 model_column
, width
, align
, flags
);
1318 PrependColumn( ret
);
1323 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1324 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1326 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1327 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1328 model_column
, width
, align
, flags
);
1329 PrependColumn( ret
);
1334 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1335 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1337 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1338 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1339 model_column
, width
, align
, flags
);
1340 PrependColumn( ret
);
1345 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1346 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1348 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1349 new wxDataViewDateRenderer( wxT("datetime"), mode
),
1350 model_column
, width
, align
, flags
);
1351 PrependColumn( ret
);
1356 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1357 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1359 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1360 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
),
1361 model_column
, width
, align
, flags
);
1362 PrependColumn( ret
);
1367 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1369 col
->SetOwner( (wxDataViewCtrl
*) this );
1374 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn
*col
)
1376 col
->SetOwner( (wxDataViewCtrl
*) this );
1381 wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos
), wxDataViewColumn
*col
)
1383 col
->SetOwner( (wxDataViewCtrl
*) this );
1387 void wxDataViewCtrlBase::StartEditor(const wxDataViewItem
& item
, unsigned int column
)
1389 EditItem(item
, GetColumn(column
));
1392 // ---------------------------------------------------------
1394 // ---------------------------------------------------------
1396 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1398 wxDEFINE_EVENT( wxEVT_DATAVIEW_SELECTION_CHANGED
, wxDataViewEvent
);
1400 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_ACTIVATED
, wxDataViewEvent
);
1401 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_COLLAPSING
, wxDataViewEvent
);
1402 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_COLLAPSED
, wxDataViewEvent
);
1403 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_EXPANDING
, wxDataViewEvent
);
1404 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_EXPANDED
, wxDataViewEvent
);
1405 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_EDITING_STARTED
, wxDataViewEvent
);
1406 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_START_EDITING
, wxDataViewEvent
);
1407 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_EDITING_DONE
, wxDataViewEvent
);
1408 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_VALUE_CHANGED
, wxDataViewEvent
);
1410 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_CONTEXT_MENU
, wxDataViewEvent
);
1412 wxDEFINE_EVENT( wxEVT_DATAVIEW_COLUMN_HEADER_CLICK
, wxDataViewEvent
);
1413 wxDEFINE_EVENT( wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
, wxDataViewEvent
);
1414 wxDEFINE_EVENT( wxEVT_DATAVIEW_COLUMN_SORTED
, wxDataViewEvent
);
1415 wxDEFINE_EVENT( wxEVT_DATAVIEW_COLUMN_REORDERED
, wxDataViewEvent
);
1417 wxDEFINE_EVENT( wxEVT_DATAVIEW_CACHE_HINT
, wxDataViewEvent
);
1419 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_BEGIN_DRAG
, wxDataViewEvent
);
1420 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE
, wxDataViewEvent
);
1421 wxDEFINE_EVENT( wxEVT_DATAVIEW_ITEM_DROP
, wxDataViewEvent
);
1425 // -------------------------------------
1426 // wxDataViewSpinRenderer
1427 // -------------------------------------
1429 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min
, int max
, wxDataViewCellMode mode
, int alignment
) :
1430 wxDataViewCustomRenderer(wxT("long"), mode
, alignment
)
1436 wxWindow
* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1439 wxSize size
= labelRect
.GetSize();
1441 size
= wxSize( wxMax(70,labelRect
.width
), -1 );
1444 str
.Printf( wxT("%d"), (int) l
);
1445 wxSpinCtrl
*sc
= new wxSpinCtrl( parent
, wxID_ANY
, str
,
1446 labelRect
.GetTopLeft(), size
, wxSP_ARROW_KEYS
|wxTE_PROCESS_ENTER
, m_min
, m_max
, l
);
1448 size
= sc
->GetSize();
1449 wxPoint pt
= sc
->GetPosition();
1450 sc
->SetSize( pt
.x
- 4, pt
.y
- 4, size
.x
, size
.y
);
1456 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1458 wxSpinCtrl
*sc
= (wxSpinCtrl
*) editor
;
1459 long l
= sc
->GetValue();
1464 bool wxDataViewSpinRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1467 str
.Printf(wxT("%d"), (int) m_data
);
1468 RenderText( str
, 0, rect
, dc
, state
);
1472 wxSize
wxDataViewSpinRenderer::GetSize() const
1474 wxSize sz
= GetTextExtent(wxString::Format("%d", (int)m_data
));
1476 // Allow some space for the spin buttons, which is approximately the size
1477 // of a scrollbar (and getting pixel-exact value would be complicated).
1478 // Also add some whitespace between the text and the button:
1479 sz
.x
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1480 sz
.x
+= GetTextExtent("M").x
;
1485 bool wxDataViewSpinRenderer::SetValue( const wxVariant
&value
)
1487 m_data
= value
.GetLong();
1491 bool wxDataViewSpinRenderer::GetValue( wxVariant
&value
) const
1497 // -------------------------------------
1498 // wxDataViewChoiceRenderer
1499 // -------------------------------------
1501 #if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
1503 wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString
& choices
, wxDataViewCellMode mode
, int alignment
) :
1504 wxDataViewCustomRenderer(wxT("string"), mode
, alignment
)
1506 m_choices
= choices
;
1509 wxWindow
* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1511 wxChoice
* c
= new wxChoice
1515 labelRect
.GetTopLeft(),
1516 wxSize(labelRect
.GetWidth(), -1),
1519 c
->Move(labelRect
.GetRight() - c
->GetRect().width
, wxDefaultCoord
);
1520 c
->SetStringSelection( value
.GetString() );
1524 bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1526 wxChoice
*c
= (wxChoice
*) editor
;
1527 wxString s
= c
->GetStringSelection();
1532 bool wxDataViewChoiceRenderer::Render( wxRect rect
, wxDC
*dc
, int state
)
1534 RenderText( m_data
, 0, rect
, dc
, state
);
1538 wxSize
wxDataViewChoiceRenderer::GetSize() const
1542 for ( wxArrayString::const_iterator i
= m_choices
.begin(); i
!= m_choices
.end(); ++i
)
1543 sz
.IncTo(GetTextExtent(*i
));
1545 // Allow some space for the right-side button, which is approximately the
1546 // size of a scrollbar (and getting pixel-exact value would be complicated).
1547 // Also add some whitespace between the text and the button:
1548 sz
.x
+= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
1549 sz
.x
+= GetTextExtent("M").x
;
1554 bool wxDataViewChoiceRenderer::SetValue( const wxVariant
&value
)
1556 m_data
= value
.GetString();
1560 bool wxDataViewChoiceRenderer::GetValue( wxVariant
&value
) const
1566 // ----------------------------------------------------------------------------
1567 // wxDataViewChoiceByIndexRenderer
1568 // ----------------------------------------------------------------------------
1570 wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString
&choices
,
1571 wxDataViewCellMode mode
, int alignment
) :
1572 wxDataViewChoiceRenderer( choices
, mode
, alignment
)
1576 wxWindow
* wxDataViewChoiceByIndexRenderer::CreateEditorCtrl( wxWindow
*parent
, wxRect labelRect
, const wxVariant
&value
)
1578 wxVariant string_value
= GetChoice( value
.GetLong() );
1580 return wxDataViewChoiceRenderer::CreateEditorCtrl( parent
, labelRect
, string_value
);
1583 bool wxDataViewChoiceByIndexRenderer::GetValueFromEditorCtrl( wxWindow
* editor
, wxVariant
&value
)
1585 wxVariant string_value
;
1586 if (!wxDataViewChoiceRenderer::GetValueFromEditorCtrl( editor
, string_value
))
1589 value
= (long) GetChoices().Index( string_value
.GetString() );
1593 bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant
&value
)
1595 wxVariant string_value
= GetChoice( value
.GetLong() );
1596 return wxDataViewChoiceRenderer::SetValue( string_value
);
1599 bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant
&value
) const
1601 wxVariant string_value
;
1602 if (!wxDataViewChoiceRenderer::GetValue( string_value
))
1605 value
= (long) GetChoices().Index( string_value
.GetString() );
1611 // ---------------------------------------------------------
1612 // wxDataViewDateRenderer
1613 // ---------------------------------------------------------
1615 #if (defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)) && wxUSE_DATEPICKCTRL
1617 wxDataViewDateRenderer::wxDataViewDateRenderer(const wxString
& varianttype
,
1618 wxDataViewCellMode mode
, int align
)
1619 : wxDataViewCustomRenderer(varianttype
, mode
, align
)
1624 wxDataViewDateRenderer::CreateEditorCtrl(wxWindow
*parent
, wxRect labelRect
, const wxVariant
& value
)
1626 return new wxDatePickerCtrl
1630 value
.GetDateTime(),
1631 labelRect
.GetTopLeft(),
1636 bool wxDataViewDateRenderer::GetValueFromEditorCtrl(wxWindow
*editor
, wxVariant
& value
)
1638 wxDatePickerCtrl
*ctrl
= static_cast<wxDatePickerCtrl
*>(editor
);
1639 value
= ctrl
->GetValue();
1643 bool wxDataViewDateRenderer::SetValue(const wxVariant
& value
)
1645 m_date
= value
.GetDateTime();
1649 bool wxDataViewDateRenderer::GetValue(wxVariant
& value
) const
1655 bool wxDataViewDateRenderer::Render(wxRect cell
, wxDC
* dc
, int state
)
1657 wxString tmp
= m_date
.FormatDate();
1658 RenderText( tmp
, 0, cell
, dc
, state
);
1662 wxSize
wxDataViewDateRenderer::GetSize() const
1664 return GetTextExtent(m_date
.FormatDate());
1667 #endif // (defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXGTK__)) && wxUSE_DATEPICKCTRL
1669 //-----------------------------------------------------------------------------
1670 // wxDataViewListStore
1671 //-----------------------------------------------------------------------------
1673 wxDataViewListStore::wxDataViewListStore()
1677 wxDataViewListStore::~wxDataViewListStore()
1679 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1680 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1682 wxDataViewListStoreLine
* line
= *it
;
1687 void wxDataViewListStore::PrependColumn( const wxString
&varianttype
)
1689 m_cols
.Insert( varianttype
, 0 );
1692 void wxDataViewListStore::InsertColumn( unsigned int pos
, const wxString
&varianttype
)
1694 m_cols
.Insert( varianttype
, pos
);
1697 void wxDataViewListStore::AppendColumn( const wxString
&varianttype
)
1699 m_cols
.Add( varianttype
);
1702 unsigned int wxDataViewListStore::GetColumnCount() const
1704 return m_cols
.GetCount();
1707 unsigned int wxDataViewListStore::GetItemCount() const
1709 return m_data
.size();
1712 wxString
wxDataViewListStore::GetColumnType( unsigned int pos
) const
1717 void wxDataViewListStore::AppendItem( const wxVector
<wxVariant
> &values
, wxUIntPtr data
)
1719 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1720 line
->m_values
= values
;
1721 m_data
.push_back( line
);
1726 void wxDataViewListStore::PrependItem( const wxVector
<wxVariant
> &values
, wxUIntPtr data
)
1728 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1729 line
->m_values
= values
;
1730 m_data
.insert( m_data
.begin(), line
);
1735 void wxDataViewListStore::InsertItem( unsigned int row
, const wxVector
<wxVariant
> &values
,
1738 wxDataViewListStoreLine
*line
= new wxDataViewListStoreLine( data
);
1739 line
->m_values
= values
;
1740 m_data
.insert( m_data
.begin()+row
, line
);
1745 void wxDataViewListStore::DeleteItem( unsigned int row
)
1747 wxVector
<wxDataViewListStoreLine
*>::iterator it
= m_data
.begin() + row
;
1754 void wxDataViewListStore::DeleteAllItems()
1756 wxVector
<wxDataViewListStoreLine
*>::iterator it
;
1757 for (it
= m_data
.begin(); it
!= m_data
.end(); ++it
)
1759 wxDataViewListStoreLine
* line
= *it
;
1768 void wxDataViewListStore::SetItemData( const wxDataViewItem
& item
, wxUIntPtr data
)
1770 wxDataViewListStoreLine
* line
= m_data
[GetRow(item
)];
1773 line
->SetData( data
);
1776 wxUIntPtr
wxDataViewListStore::GetItemData( const wxDataViewItem
& item
) const
1778 wxDataViewListStoreLine
* line
= m_data
[GetRow(item
)];
1779 if (!line
) return static_cast<wxUIntPtr
>(NULL
);
1781 return line
->GetData();
1784 void wxDataViewListStore::GetValueByRow( wxVariant
&value
, unsigned int row
, unsigned int col
) const
1786 wxDataViewListStoreLine
*line
= m_data
[row
];
1787 value
= line
->m_values
[col
];
1790 bool wxDataViewListStore::SetValueByRow( const wxVariant
&value
, unsigned int row
, unsigned int col
)
1792 wxDataViewListStoreLine
*line
= m_data
[row
];
1793 line
->m_values
[col
] = value
;
1798 //-----------------------------------------------------------------------------
1799 // wxDataViewListCtrl
1800 //-----------------------------------------------------------------------------
1802 IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl
,wxDataViewCtrl
)
1804 BEGIN_EVENT_TABLE(wxDataViewListCtrl
,wxDataViewCtrl
)
1805 EVT_SIZE( wxDataViewListCtrl::OnSize
)
1808 wxDataViewListCtrl::wxDataViewListCtrl()
1812 wxDataViewListCtrl::wxDataViewListCtrl( wxWindow
*parent
, wxWindowID id
,
1813 const wxPoint
& pos
, const wxSize
& size
, long style
,
1814 const wxValidator
& validator
)
1816 Create( parent
, id
, pos
, size
, style
, validator
);
1819 wxDataViewListCtrl::~wxDataViewListCtrl()
1824 bool wxDataViewListCtrl::Create( wxWindow
*parent
, wxWindowID id
,
1825 const wxPoint
& pos
, const wxSize
& size
, long style
,
1826 const wxValidator
& validator
)
1828 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
1831 wxDataViewListStore
*store
= new wxDataViewListStore
;
1832 AssociateModel( store
);
1838 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1840 GetStore()->AppendColumn( varianttype
);
1841 return wxDataViewCtrl::AppendColumn( column
);
1844 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*column
, const wxString
&varianttype
)
1846 GetStore()->PrependColumn( varianttype
);
1847 return wxDataViewCtrl::PrependColumn( column
);
1850 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*column
, const wxString
&varianttype
)
1852 GetStore()->InsertColumn( pos
, varianttype
);
1853 return wxDataViewCtrl::InsertColumn( pos
, column
);
1856 bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn
*col
)
1858 return PrependColumn( col
, "string" );
1861 bool wxDataViewListCtrl::InsertColumn( unsigned int pos
, wxDataViewColumn
*col
)
1863 return InsertColumn( pos
, col
, "string" );
1866 bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn
*col
)
1868 return AppendColumn( col
, "string" );
1871 wxDataViewColumn
*wxDataViewListCtrl::AppendTextColumn( const wxString
&label
,
1872 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1874 GetStore()->AppendColumn( wxT("string") );
1876 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1877 new wxDataViewTextRenderer( wxT("string"), mode
),
1878 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1880 wxDataViewCtrl::AppendColumn( ret
);
1885 wxDataViewColumn
*wxDataViewListCtrl::AppendToggleColumn( const wxString
&label
,
1886 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1888 GetStore()->AppendColumn( wxT("bool") );
1890 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1891 new wxDataViewToggleRenderer( wxT("bool"), mode
),
1892 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1894 wxDataViewCtrl::AppendColumn( ret
);
1899 wxDataViewColumn
*wxDataViewListCtrl::AppendProgressColumn( const wxString
&label
,
1900 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1902 GetStore()->AppendColumn( wxT("long") );
1904 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1905 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
),
1906 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1908 wxDataViewCtrl::AppendColumn( ret
);
1913 wxDataViewColumn
*wxDataViewListCtrl::AppendIconTextColumn( const wxString
&label
,
1914 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1916 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
1918 wxDataViewColumn
*ret
= new wxDataViewColumn( label
,
1919 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode
),
1920 GetStore()->GetColumnCount()-1, width
, align
, flags
);
1922 wxDataViewCtrl::AppendColumn( ret
);
1927 void wxDataViewListCtrl::OnSize( wxSizeEvent
&event
)
1932 //-----------------------------------------------------------------------------
1933 // wxDataViewTreeStore
1934 //-----------------------------------------------------------------------------
1936 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1937 wxDataViewTreeStoreNode
*parent
,
1938 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1946 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1952 #include "wx/listimpl.cpp"
1953 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList
)
1955 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1956 wxDataViewTreeStoreNode
*parent
, const wxString
&text
,
1957 const wxIcon
&icon
, const wxIcon
&expanded
, wxClientData
*data
) :
1958 wxDataViewTreeStoreNode( parent
, text
, icon
, data
)
1960 m_iconExpanded
= expanded
;
1961 m_isExpanded
= false;
1962 m_children
.DeleteContents(true);
1965 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1969 //-----------------------------------------------------------------------------
1971 wxDataViewTreeStore::wxDataViewTreeStore()
1973 m_root
= new wxDataViewTreeStoreContainerNode( NULL
, wxEmptyString
);
1976 wxDataViewTreeStore::~wxDataViewTreeStore()
1981 wxDataViewItem
wxDataViewTreeStore::AppendItem( const wxDataViewItem
& parent
,
1982 const wxString
&text
, const wxIcon
&icon
, wxClientData
*data
)
1984 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
1985 if (!parent_node
) return wxDataViewItem(0);
1987 wxDataViewTreeStoreNode
*node
=
1988 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
1989 parent_node
->GetChildren().Append( node
);
1991 return node
->GetItem();
1994 wxDataViewItem
wxDataViewTreeStore::PrependItem( 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().Insert( node
);
2004 return node
->GetItem();
2008 wxDataViewTreeStore::InsertItem(const wxDataViewItem
& parent
,
2009 const wxDataViewItem
& previous
,
2010 const wxString
& text
,
2014 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2015 if (!parent_node
) return wxDataViewItem(0);
2017 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
2018 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
2019 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
2021 wxDataViewTreeStoreNode
*node
=
2022 new wxDataViewTreeStoreNode( parent_node
, text
, icon
, data
);
2023 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
2025 return node
->GetItem();
2028 wxDataViewItem
wxDataViewTreeStore::PrependContainer( const wxDataViewItem
& parent
,
2029 const wxString
&text
, const wxIcon
&icon
, const wxIcon
&expanded
,
2030 wxClientData
*data
)
2032 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2033 if (!parent_node
) return wxDataViewItem(0);
2035 wxDataViewTreeStoreContainerNode
*node
=
2036 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
2037 parent_node
->GetChildren().Insert( node
);
2039 return node
->GetItem();
2043 wxDataViewTreeStore::AppendContainer(const wxDataViewItem
& parent
,
2044 const wxString
&text
,
2046 const wxIcon
& expanded
,
2047 wxClientData
* data
)
2049 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2050 if (!parent_node
) return wxDataViewItem(0);
2052 wxDataViewTreeStoreContainerNode
*node
=
2053 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
2054 parent_node
->GetChildren().Append( node
);
2056 return node
->GetItem();
2060 wxDataViewTreeStore::InsertContainer(const wxDataViewItem
& parent
,
2061 const wxDataViewItem
& previous
,
2062 const wxString
& text
,
2064 const wxIcon
& expanded
,
2065 wxClientData
* data
)
2067 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2068 if (!parent_node
) return wxDataViewItem(0);
2070 wxDataViewTreeStoreNode
*previous_node
= FindNode( previous
);
2071 int pos
= parent_node
->GetChildren().IndexOf( previous_node
);
2072 if (pos
== wxNOT_FOUND
) return wxDataViewItem(0);
2074 wxDataViewTreeStoreContainerNode
*node
=
2075 new wxDataViewTreeStoreContainerNode( parent_node
, text
, icon
, expanded
, data
);
2076 parent_node
->GetChildren().Insert( (size_t) pos
, node
);
2078 return node
->GetItem();
2081 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem
& item
) const
2083 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2084 if (!node
) return false;
2086 return node
->IsContainer();
2089 wxDataViewItem
wxDataViewTreeStore::GetNthChild( const wxDataViewItem
& parent
, unsigned int pos
) const
2091 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent
);
2092 if (!parent_node
) return wxDataViewItem(0);
2094 wxDataViewTreeStoreNodeList::compatibility_iterator node
= parent_node
->GetChildren().Item( pos
);
2096 return wxDataViewItem(node
->GetData());
2098 return wxDataViewItem(0);
2101 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem
& parent
) const
2103 wxDataViewTreeStoreNode
*node
= FindNode( parent
);
2104 if (!node
) return -1;
2106 if (!node
->IsContainer())
2109 wxDataViewTreeStoreContainerNode
*container_node
= (wxDataViewTreeStoreContainerNode
*) node
;
2110 return (int) container_node
->GetChildren().GetCount();
2113 void wxDataViewTreeStore::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2115 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2118 node
->SetText( text
);
2121 wxString
wxDataViewTreeStore::GetItemText( const wxDataViewItem
& item
) const
2123 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2124 if (!node
) return wxEmptyString
;
2126 return node
->GetText();
2129 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2131 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2134 node
->SetIcon( icon
);
2137 const wxIcon
&wxDataViewTreeStore::GetItemIcon( const wxDataViewItem
& item
) const
2139 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2140 if (!node
) return wxNullIcon
;
2142 return node
->GetIcon();
2145 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2147 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2150 node
->SetExpandedIcon( icon
);
2153 const wxIcon
&wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem
& item
) const
2155 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2156 if (!node
) return wxNullIcon
;
2158 return node
->GetExpandedIcon();
2161 void wxDataViewTreeStore::SetItemData( const wxDataViewItem
& item
, wxClientData
*data
)
2163 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2166 node
->SetData( data
);
2169 wxClientData
*wxDataViewTreeStore::GetItemData( const wxDataViewItem
& item
) const
2171 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2172 if (!node
) return NULL
;
2174 return node
->GetData();
2177 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem
& item
)
2179 if (!item
.IsOk()) return;
2181 wxDataViewItem parent_item
= GetParent( item
);
2183 wxDataViewTreeStoreContainerNode
*parent_node
= FindContainerNode( parent_item
);
2184 if (!parent_node
) return;
2186 parent_node
->GetChildren().DeleteObject( FindNode(item
) );
2189 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem
& item
)
2191 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2194 node
->GetChildren().clear();
2197 void wxDataViewTreeStore::DeleteAllItems()
2199 DeleteChildren(wxDataViewItem(m_root
));
2203 wxDataViewTreeStore::GetValue(wxVariant
&variant
,
2204 const wxDataViewItem
&item
,
2205 unsigned int WXUNUSED(col
)) const
2207 // if (col != 0) return;
2209 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2212 wxIcon
icon( node
->GetIcon());
2213 if (node
->IsContainer())
2215 wxDataViewTreeStoreContainerNode
*container
= (wxDataViewTreeStoreContainerNode
*) node
;
2216 if (container
->IsExpanded() && container
->GetExpandedIcon().IsOk())
2217 icon
= container
->GetExpandedIcon();
2220 wxDataViewIconText
data( node
->GetText(), icon
);
2226 wxDataViewTreeStore::SetValue(const wxVariant
& variant
,
2227 const wxDataViewItem
& item
,
2228 unsigned int WXUNUSED(col
))
2230 // if (col != 0) return false;
2232 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2233 if (!node
) return false;
2235 wxDataViewIconText data
;
2239 node
->SetText( data
.GetText() );
2240 node
->SetIcon( data
.GetIcon() );
2245 wxDataViewItem
wxDataViewTreeStore::GetParent( const wxDataViewItem
&item
) const
2247 wxDataViewTreeStoreNode
*node
= FindNode( item
);
2248 if (!node
) return wxDataViewItem(0);
2250 wxDataViewTreeStoreNode
*parent
= node
->GetParent();
2251 if (!parent
) return wxDataViewItem(0);
2253 if (parent
== m_root
)
2254 return wxDataViewItem(0);
2256 return parent
->GetItem();
2259 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem
&item
, wxDataViewItemArray
&children
) const
2261 wxDataViewTreeStoreContainerNode
*node
= FindContainerNode( item
);
2262 if (!node
) return 0;
2264 wxDataViewTreeStoreNodeList::iterator iter
;
2265 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2267 wxDataViewTreeStoreNode
* child
= *iter
;
2268 children
.Add( child
->GetItem() );
2271 return node
->GetChildren().GetCount();
2274 int wxDataViewTreeStore::Compare( const wxDataViewItem
&item1
, const wxDataViewItem
&item2
,
2275 unsigned int WXUNUSED(column
), bool WXUNUSED(ascending
) ) const
2277 wxDataViewTreeStoreNode
*node1
= FindNode( item1
);
2278 wxDataViewTreeStoreNode
*node2
= FindNode( item2
);
2280 if (!node1
|| !node2
)
2283 wxDataViewTreeStoreContainerNode
* parent1
=
2284 (wxDataViewTreeStoreContainerNode
*) node1
->GetParent();
2285 wxDataViewTreeStoreContainerNode
* parent2
=
2286 (wxDataViewTreeStoreContainerNode
*) node2
->GetParent();
2288 if (parent1
!= parent2
)
2290 wxLogError( wxT("Comparing items with different parent.") );
2294 if (node1
->IsContainer() && !node2
->IsContainer())
2297 if (node2
->IsContainer() && !node1
->IsContainer())
2300 return parent1
->GetChildren().IndexOf( node1
) - parent2
->GetChildren().IndexOf( node2
);
2303 wxDataViewTreeStoreNode
*wxDataViewTreeStore::FindNode( const wxDataViewItem
&item
) const
2308 return (wxDataViewTreeStoreNode
*) item
.GetID();
2311 wxDataViewTreeStoreContainerNode
*wxDataViewTreeStore::FindContainerNode( const wxDataViewItem
&item
) const
2314 return (wxDataViewTreeStoreContainerNode
*) m_root
;
2316 wxDataViewTreeStoreNode
* node
= (wxDataViewTreeStoreNode
*) item
.GetID();
2318 if (!node
->IsContainer())
2321 return (wxDataViewTreeStoreContainerNode
*) node
;
2324 //-----------------------------------------------------------------------------
2325 // wxDataViewTreeCtrl
2326 //-----------------------------------------------------------------------------
2328 IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2330 BEGIN_EVENT_TABLE(wxDataViewTreeCtrl
,wxDataViewCtrl
)
2331 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded
)
2332 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed
)
2333 EVT_SIZE( wxDataViewTreeCtrl::OnSize
)
2336 bool wxDataViewTreeCtrl::Create( wxWindow
*parent
, wxWindowID id
,
2337 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxValidator
& validator
)
2339 if ( !wxDataViewCtrl::Create( parent
, id
, pos
, size
, style
, validator
) )
2342 // create the standard model and a column in the tree
2343 wxDataViewTreeStore
*store
= new wxDataViewTreeStore
;
2344 AssociateModel( store
);
2347 AppendIconTextColumn
2349 wxString(), // no label (header is not shown anyhow)
2350 0, // the only model column
2351 wxDATAVIEW_CELL_EDITABLE
,
2352 -1, // default width
2353 wxALIGN_NOT
, // and alignment
2360 wxDataViewItem
wxDataViewTreeCtrl::AppendItem( const wxDataViewItem
& parent
,
2361 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2363 wxDataViewItem res
= GetStore()->
2364 AppendItem( parent
, text
, GetImage(iconIndex
), data
);
2366 GetStore()->ItemAdded( parent
, res
);
2371 wxDataViewItem
wxDataViewTreeCtrl::PrependItem( const wxDataViewItem
& parent
,
2372 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2374 wxDataViewItem res
= GetStore()->
2375 PrependItem( parent
, text
, GetImage(iconIndex
), data
);
2377 GetStore()->ItemAdded( parent
, res
);
2382 wxDataViewItem
wxDataViewTreeCtrl::InsertItem( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2383 const wxString
&text
, int iconIndex
, wxClientData
*data
)
2385 wxDataViewItem res
= GetStore()->
2386 InsertItem( parent
, previous
, text
, GetImage(iconIndex
), data
);
2388 GetStore()->ItemAdded( parent
, res
);
2393 wxDataViewItem
wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem
& parent
,
2394 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2396 wxDataViewItem res
= GetStore()->
2397 PrependContainer( parent
, text
,
2398 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2400 GetStore()->ItemAdded( parent
, res
);
2405 wxDataViewItem
wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem
& parent
,
2406 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2408 wxDataViewItem res
= GetStore()->
2409 AppendContainer( parent
, text
,
2410 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2412 GetStore()->ItemAdded( parent
, res
);
2417 wxDataViewItem
wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem
& parent
, const wxDataViewItem
& previous
,
2418 const wxString
&text
, int iconIndex
, int expandedIndex
, wxClientData
*data
)
2420 wxDataViewItem res
= GetStore()->
2421 InsertContainer( parent
, previous
, text
,
2422 GetImage(iconIndex
), GetImage(expandedIndex
), data
);
2424 GetStore()->ItemAdded( parent
, res
);
2429 void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem
& item
, const wxString
&text
)
2431 GetStore()->SetItemText(item
,text
);
2434 GetStore()->ValueChanged( item
, 0 );
2437 void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2439 GetStore()->SetItemIcon(item
,icon
);
2442 GetStore()->ValueChanged( item
, 0 );
2445 void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem
& item
, const wxIcon
&icon
)
2447 GetStore()->SetItemExpandedIcon(item
,icon
);
2450 GetStore()->ValueChanged( item
, 0 );
2453 void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem
& item
)
2455 wxDataViewItem parent_item
= GetStore()->GetParent( item
);
2457 GetStore()->DeleteItem(item
);
2460 GetStore()->ItemDeleted( parent_item
, item
);
2463 void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem
& item
)
2465 wxDataViewTreeStoreContainerNode
*node
= GetStore()->FindContainerNode( item
);
2468 wxDataViewItemArray array
;
2469 wxDataViewTreeStoreNodeList::iterator iter
;
2470 for (iter
= node
->GetChildren().begin(); iter
!= node
->GetChildren().end(); iter
++)
2472 wxDataViewTreeStoreNode
* child
= *iter
;
2473 array
.Add( child
->GetItem() );
2476 GetStore()->DeleteChildren( item
);
2479 GetStore()->ItemsDeleted( item
, array
);
2482 void wxDataViewTreeCtrl::DeleteAllItems()
2484 GetStore()->DeleteAllItems();
2486 GetStore()->Cleared();
2489 void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent
&event
)
2491 if (HasImageList()) return;
2493 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2494 if (!container
) return;
2496 container
->SetExpanded( true );
2498 GetStore()->ItemChanged( event
.GetItem() );
2501 void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent
&event
)
2503 if (HasImageList()) return;
2505 wxDataViewTreeStoreContainerNode
* container
= GetStore()->FindContainerNode( event
.GetItem() );
2506 if (!container
) return;
2508 container
->SetExpanded( false );
2510 GetStore()->ItemChanged( event
.GetItem() );
2513 void wxDataViewTreeCtrl::OnSize( wxSizeEvent
&event
)
2515 #if defined(wxUSE_GENERICDATAVIEWCTRL)
2516 // automatically resize our only column to take the entire control width
2517 if ( GetColumnCount() )
2519 wxSize size
= GetClientSize();
2520 GetColumn(0)->SetWidth(size
.x
);
2526 #endif // wxUSE_DATAVIEWCTRL