]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/datavcmn.cpp
Add component-level filtering to wxLog.
[wxWidgets.git] / src / common / datavcmn.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/common/datavcmn.cpp
3// Purpose: wxDataViewCtrl base classes and common parts
4// Author: Robert Roebling
5// Created: 2006/02/20
6// RCS-ID: $Id$
7// Copyright: (c) 2006, Robert Roebling
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
18#if wxUSE_DATAVIEWCTRL
19
20#include "wx/dataview.h"
21
22#ifndef WX_PRECOMP
23 #include "wx/dc.h"
24 #include "wx/settings.h"
25 #include "wx/log.h"
26 #include "wx/crt.h"
27#endif
28
29#include "wx/spinctrl.h"
30#include "wx/choice.h"
31#include "wx/imaglist.h"
32
33const char wxDataViewCtrlNameStr[] = "dataviewCtrl";
34
35
36bool operator == (const wxDataViewItem &left, const wxDataViewItem &right)
37{
38 return (left.GetID() == right.GetID() );
39}
40
41// ---------------------------------------------------------
42// wxDataViewModelNotifier
43// ---------------------------------------------------------
44
45#include "wx/listimpl.cpp"
46WX_DEFINE_LIST(wxDataViewModelNotifiers)
47
48bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items )
49{
50 size_t count = items.GetCount();
51 size_t i;
52 for (i = 0; i < count; i++)
53 if (!ItemAdded( parent, items[i] )) return false;
54
55 return true;
56}
57
58bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items )
59{
60 size_t count = items.GetCount();
61 size_t i;
62 for (i = 0; i < count; i++)
63 if (!ItemDeleted( parent, items[i] )) return false;
64
65 return true;
66}
67
68bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray &items )
69{
70 size_t count = items.GetCount();
71 size_t i;
72 for (i = 0; i < count; i++)
73 if (!ItemChanged( items[i] )) return false;
74
75 return true;
76}
77
78// ---------------------------------------------------------
79// wxDataViewModel
80// ---------------------------------------------------------
81
82wxDataViewModel::wxDataViewModel()
83{
84 m_notifiers.DeleteContents( true );
85}
86
87bool wxDataViewModel::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
88{
89 bool ret = true;
90
91 wxDataViewModelNotifiers::iterator iter;
92 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
93 {
94 wxDataViewModelNotifier* notifier = *iter;
95 if (!notifier->ItemAdded( parent, item ))
96 ret = false;
97 }
98
99 return ret;
100}
101
102bool wxDataViewModel::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
103{
104 bool ret = true;
105
106 wxDataViewModelNotifiers::iterator iter;
107 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
108 {
109 wxDataViewModelNotifier* notifier = *iter;
110 if (!notifier->ItemDeleted( parent, item ))
111 ret = false;
112 }
113
114 return ret;
115}
116
117bool wxDataViewModel::ItemChanged( const wxDataViewItem &item )
118{
119 bool ret = true;
120
121 wxDataViewModelNotifiers::iterator iter;
122 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
123 {
124 wxDataViewModelNotifier* notifier = *iter;
125 if (!notifier->ItemChanged( item ))
126 ret = false;
127 }
128
129 return ret;
130}
131
132bool wxDataViewModel::ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items )
133{
134 bool ret = true;
135
136 wxDataViewModelNotifiers::iterator iter;
137 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
138 {
139 wxDataViewModelNotifier* notifier = *iter;
140 if (!notifier->ItemsAdded( parent, items ))
141 ret = false;
142 }
143
144 return ret;
145}
146
147bool wxDataViewModel::ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items )
148{
149 bool ret = true;
150
151 wxDataViewModelNotifiers::iterator iter;
152 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
153 {
154 wxDataViewModelNotifier* notifier = *iter;
155 if (!notifier->ItemsDeleted( parent, items ))
156 ret = false;
157 }
158
159 return ret;
160}
161
162bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray &items )
163{
164 bool ret = true;
165
166 wxDataViewModelNotifiers::iterator iter;
167 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
168 {
169 wxDataViewModelNotifier* notifier = *iter;
170 if (!notifier->ItemsChanged( items ))
171 ret = false;
172 }
173
174 return ret;
175}
176
177bool wxDataViewModel::ValueChanged( const wxDataViewItem &item, unsigned int col )
178{
179 bool ret = true;
180
181 wxDataViewModelNotifiers::iterator iter;
182 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
183 {
184 wxDataViewModelNotifier* notifier = *iter;
185 if (!notifier->ValueChanged( item, col ))
186 ret = false;
187 }
188
189 return ret;
190}
191
192bool wxDataViewModel::Cleared()
193{
194 bool ret = true;
195
196 wxDataViewModelNotifiers::iterator iter;
197 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
198 {
199 wxDataViewModelNotifier* notifier = *iter;
200 if (!notifier->Cleared())
201 ret = false;
202 }
203
204 return ret;
205}
206
207void wxDataViewModel::Resort()
208{
209 wxDataViewModelNotifiers::iterator iter;
210 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
211 {
212 wxDataViewModelNotifier* notifier = *iter;
213 notifier->Resort();
214 }
215}
216
217void wxDataViewModel::AddNotifier( wxDataViewModelNotifier *notifier )
218{
219 m_notifiers.push_back( notifier );
220 notifier->SetOwner( this );
221}
222
223void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier *notifier )
224{
225 m_notifiers.DeleteObject( notifier );
226}
227
228int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
229 unsigned int column, bool ascending ) const
230{
231 // sort branches before leaves
232 bool item1_is_container = IsContainer(item1);
233 bool item2_is_container = IsContainer(item2);
234
235 if (item1_is_container && !item2_is_container)
236 return 1;
237 if (item2_is_container && !item1_is_container)
238 return -1;
239
240 wxVariant value1,value2;
241 GetValue( value1, item1, column );
242 GetValue( value2, item2, column );
243
244 if (!ascending)
245 {
246 wxVariant temp = value1;
247 value1 = value2;
248 value2 = temp;
249 }
250
251 if (value1.GetType() == wxT("string"))
252 {
253 wxString str1 = value1.GetString();
254 wxString str2 = value2.GetString();
255 int res = str1.Cmp( str2 );
256 if (res)
257 return res;
258 }
259 else if (value1.GetType() == wxT("long"))
260 {
261 long l1 = value1.GetLong();
262 long l2 = value2.GetLong();
263 long res = l1-l2;
264 if (res)
265 return res;
266 }
267 else if (value1.GetType() == wxT("double"))
268 {
269 double d1 = value1.GetDouble();
270 double d2 = value2.GetDouble();
271 if (d1 < d2)
272 return 1;
273 if (d1 > d2)
274 return -1;
275 }
276 else if (value1.GetType() == wxT("datetime"))
277 {
278 wxDateTime dt1 = value1.GetDateTime();
279 wxDateTime dt2 = value2.GetDateTime();
280 if (dt1.IsEarlierThan(dt2))
281 return 1;
282 if (dt2.IsEarlierThan(dt1))
283 return -11;
284 }
285
286 // items must be different
287 wxUIntPtr id1 = wxPtrToUInt(item1.GetID()),
288 id2 = wxPtrToUInt(item2.GetID());
289
290 return ascending ? id1 - id2 : id2 - id1;
291}
292
293// ---------------------------------------------------------
294// wxDataViewIndexListModel
295// ---------------------------------------------------------
296
297static int my_sort( int *v1, int *v2 )
298{
299 return *v2-*v1;
300}
301
302
303wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size )
304{
305 // IDs are ordered until an item gets deleted or inserted
306 m_ordered = true;
307
308 // build initial index
309 unsigned int i;
310 for (i = 1; i < initial_size+1; i++)
311 m_hash.Add( wxUIntToPtr(i) );
312 m_nextFreeID = initial_size + 1;
313}
314
315wxDataViewIndexListModel::~wxDataViewIndexListModel()
316{
317}
318
319void wxDataViewIndexListModel::Reset( unsigned int new_size )
320{
321 m_hash.Clear();
322
323 // IDs are ordered until an item gets deleted or inserted
324 m_ordered = true;
325
326 // build initial index
327 unsigned int i;
328 for (i = 1; i < new_size+1; i++)
329 m_hash.Add( wxUIntToPtr(i) );
330
331 m_nextFreeID = new_size + 1;
332
333 wxDataViewModel::Cleared();
334}
335
336void wxDataViewIndexListModel::RowPrepended()
337{
338 m_ordered = false;
339
340 unsigned int id = m_nextFreeID;
341 m_nextFreeID++;
342
343 m_hash.Insert( wxUIntToPtr(id), 0 );
344 wxDataViewItem item( wxUIntToPtr(id) );
345 ItemAdded( wxDataViewItem(0), item );
346
347}
348
349void wxDataViewIndexListModel::RowInserted( unsigned int before )
350{
351 m_ordered = false;
352
353 unsigned int id = m_nextFreeID;
354 m_nextFreeID++;
355
356 m_hash.Insert( wxUIntToPtr(id), before );
357 wxDataViewItem item( wxUIntToPtr(id) );
358 ItemAdded( wxDataViewItem(0), item );
359}
360
361void wxDataViewIndexListModel::RowAppended()
362{
363 unsigned int id = m_nextFreeID;
364 m_nextFreeID++;
365
366 m_hash.Add( wxUIntToPtr(id) );
367 wxDataViewItem item( wxUIntToPtr(id) );
368 ItemAdded( wxDataViewItem(0), item );
369}
370
371void wxDataViewIndexListModel::RowDeleted( unsigned int row )
372{
373 m_ordered = false;
374
375 wxDataViewItem item( m_hash[row] );
376 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
377 m_hash.RemoveAt( row );
378}
379
380void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt &rows )
381{
382 wxArrayInt sorted = rows;
383 sorted.Sort( my_sort );
384
385 m_ordered = false;
386
387 wxDataViewItemArray array;
388 unsigned int i;
389 for (i = 0; i < rows.GetCount(); i++)
390 {
391 wxDataViewItem item( m_hash[rows[i]] );
392 array.Add( item );
393 }
394 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array );
395
396 for (i = 0; i < sorted.GetCount(); i++)
397 m_hash.RemoveAt( sorted[i] );
398}
399
400void wxDataViewIndexListModel::RowChanged( unsigned int row )
401{
402 wxDataViewModel::ItemChanged( GetItem(row) );
403}
404
405void wxDataViewIndexListModel::RowValueChanged( unsigned int row, unsigned int col )
406{
407 wxDataViewModel::ValueChanged( GetItem(row), col );
408}
409
410unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) const
411{
412 if (m_ordered)
413 return wxPtrToUInt(item.GetID())-1;
414
415 // assert for not found
416 return (unsigned int) m_hash.Index( item.GetID() );
417}
418
419wxDataViewItem wxDataViewIndexListModel::GetItem( unsigned int row ) const
420{
421 wxASSERT( row < m_hash.GetCount() );
422 return wxDataViewItem( m_hash[row] );
423}
424
425bool wxDataViewIndexListModel::HasDefaultCompare() const
426{
427 return !m_ordered;
428}
429
430int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1,
431 const wxDataViewItem& item2,
432 unsigned int WXUNUSED(column),
433 bool ascending) const
434{
435 if (m_ordered)
436 {
437 unsigned int pos1 = wxPtrToUInt(item1.GetID()); // -1 not needed here
438 unsigned int pos2 = wxPtrToUInt(item2.GetID()); // -1 not needed here
439
440 if (ascending)
441 return pos1 - pos2;
442 else
443 return pos2 - pos1;
444 }
445
446 if (ascending)
447 return GetRow(item1) - GetRow(item2);
448
449 return GetRow(item2) - GetRow(item1);
450}
451
452void wxDataViewIndexListModel::GetValue( wxVariant &variant,
453 const wxDataViewItem &item, unsigned int col ) const
454{
455 GetValueByRow( variant, GetRow(item), col );
456}
457
458bool wxDataViewIndexListModel::SetValue( const wxVariant &variant,
459 const wxDataViewItem &item, unsigned int col )
460{
461 return SetValueByRow( variant, GetRow(item), col );
462}
463
464bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr )
465{
466 return GetAttrByRow( GetRow(item), col, attr );
467}
468
469wxDataViewItem wxDataViewIndexListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const
470{
471 return wxDataViewItem(0);
472}
473
474bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem &item ) const
475{
476 // only the invisible root item has children
477 if (!item.IsOk())
478 return true;
479
480 return false;
481}
482
483unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const
484{
485 if (item.IsOk())
486 return 0;
487
488 children = m_hash;
489
490 return m_hash.GetCount();
491}
492
493// ---------------------------------------------------------
494// wxDataViewVirtualListModel
495// ---------------------------------------------------------
496
497#ifndef __WXMAC__
498
499wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size )
500{
501 m_size = initial_size;
502}
503
504wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
505{
506}
507
508void wxDataViewVirtualListModel::Reset( unsigned int new_size )
509{
510 m_size = new_size;
511
512 wxDataViewModel::Cleared();
513}
514
515void wxDataViewVirtualListModel::RowPrepended()
516{
517 m_size++;
518 wxDataViewItem item( wxUIntToPtr(1) );
519 ItemAdded( wxDataViewItem(0), item );
520}
521
522void wxDataViewVirtualListModel::RowInserted( unsigned int before )
523{
524 m_size++;
525 wxDataViewItem item( wxUIntToPtr(before+1) );
526 ItemAdded( wxDataViewItem(0), item );
527}
528
529void wxDataViewVirtualListModel::RowAppended()
530{
531 m_size++;
532 wxDataViewItem item( wxUIntToPtr(m_size) );
533 ItemAdded( wxDataViewItem(0), item );
534}
535
536void wxDataViewVirtualListModel::RowDeleted( unsigned int row )
537{
538 m_size--;
539 wxDataViewItem item( wxUIntToPtr(row+1) );
540 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
541}
542
543void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt &rows )
544{
545 m_size -= rows.GetCount();
546
547 wxArrayInt sorted = rows;
548 sorted.Sort( my_sort );
549
550 wxDataViewItemArray array;
551 unsigned int i;
552 for (i = 0; i < sorted.GetCount(); i++)
553 {
554 wxDataViewItem item( wxUIntToPtr(sorted[i]+1) );
555 array.Add( item );
556 }
557 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array );
558}
559
560void wxDataViewVirtualListModel::RowChanged( unsigned int row )
561{
562 wxDataViewModel::ItemChanged( GetItem(row) );
563}
564
565void wxDataViewVirtualListModel::RowValueChanged( unsigned int row, unsigned int col )
566{
567 wxDataViewModel::ValueChanged( GetItem(row), col );
568}
569
570unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem &item ) const
571{
572 return wxPtrToUInt( item.GetID() ) -1;
573}
574
575wxDataViewItem wxDataViewVirtualListModel::GetItem( unsigned int row ) const
576{
577 return wxDataViewItem( wxUIntToPtr(row+1) );
578}
579
580bool wxDataViewVirtualListModel::HasDefaultCompare() const
581{
582 return true;
583}
584
585int wxDataViewVirtualListModel::Compare(const wxDataViewItem& item1,
586 const wxDataViewItem& item2,
587 unsigned int WXUNUSED(column),
588 bool ascending) const
589{
590 unsigned int pos1 = wxPtrToUInt(item1.GetID()); // -1 not needed here
591 unsigned int pos2 = wxPtrToUInt(item2.GetID()); // -1 not needed here
592
593 if (ascending)
594 return pos1 - pos2;
595 else
596 return pos2 - pos1;
597}
598
599void wxDataViewVirtualListModel::GetValue( wxVariant &variant,
600 const wxDataViewItem &item, unsigned int col ) const
601{
602 GetValueByRow( variant, GetRow(item), col );
603}
604
605bool wxDataViewVirtualListModel::SetValue( const wxVariant &variant,
606 const wxDataViewItem &item, unsigned int col )
607{
608 return SetValueByRow( variant, GetRow(item), col );
609}
610
611bool wxDataViewVirtualListModel::GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr )
612{
613 return GetAttrByRow( GetRow(item), col, attr );
614}
615
616wxDataViewItem wxDataViewVirtualListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const
617{
618 return wxDataViewItem(0);
619}
620
621bool wxDataViewVirtualListModel::IsContainer( const wxDataViewItem &item ) const
622{
623 // only the invisible root item has children
624 if (!item.IsOk())
625 return true;
626
627 return false;
628}
629
630unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem &WXUNUSED(item), wxDataViewItemArray &WXUNUSED(children) ) const
631{
632 return 0; // should we report an error ?
633}
634
635#endif // __WXMAC__
636
637//-----------------------------------------------------------------------------
638// wxDataViewIconText
639//-----------------------------------------------------------------------------
640
641IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText,wxObject)
642
643IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV)
644
645bool operator == (const wxDataViewIconText &one, const wxDataViewIconText &two)
646{
647 if (one.GetText() != two.GetText()) return false;
648 if (one.IsSameAs(two)) return false;
649 return true;
650}
651
652// ---------------------------------------------------------
653// wxDataViewRendererBase
654// ---------------------------------------------------------
655
656IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase, wxObject)
657
658wxDataViewRendererBase::wxDataViewRendererBase( const wxString &varianttype,
659 wxDataViewCellMode WXUNUSED(mode),
660 int WXUNUSED(align) )
661{
662 m_variantType = varianttype;
663 m_owner = NULL;
664}
665
666wxDataViewRendererBase::~wxDataViewRendererBase()
667{
668}
669
670const wxDataViewCtrl* wxDataViewRendererBase::GetView() const
671{
672 return const_cast<wxDataViewRendererBase*>(this)->GetOwner()->GetOwner();
673}
674
675class wxKillRef: public wxWindowRef
676{
677public:
678 wxKillRef( wxWindow *win ) : wxWindowRef( win ) { }
679 virtual void OnObjectDestroy()
680 {
681 get()->PopEventHandler( true );
682 m_pobj = NULL;
683 delete this;
684 }
685};
686
687bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect )
688{
689 wxDataViewCtrl* dv_ctrl = GetOwner()->GetOwner();
690
691 // Before doing anything we send an event asking if editing of this item is really wanted.
692 wxDataViewEvent start_event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING, dv_ctrl->GetId() );
693 start_event.SetDataViewColumn( GetOwner() );
694 start_event.SetModel( dv_ctrl->GetModel() );
695 start_event.SetItem( item );
696 start_event.SetEventObject( dv_ctrl );
697 dv_ctrl->GetEventHandler()->ProcessEvent( start_event );
698 if( !start_event.IsAllowed() )
699 return false;
700
701 m_item = item; // remember for later
702
703 unsigned int col = GetOwner()->GetModelColumn();
704 wxVariant value;
705 dv_ctrl->GetModel()->GetValue( value, item, col );
706
707 m_editorCtrl = CreateEditorCtrl( dv_ctrl->GetMainWindow(), labelRect, value );
708
709 // there might be no editor control for the given item
710 if(!m_editorCtrl)
711 return false;
712
713 (void) new wxKillRef( m_editorCtrl.get() );
714
715 wxDataViewEditorCtrlEvtHandler *handler =
716 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl, (wxDataViewRenderer*) this );
717
718 m_editorCtrl->PushEventHandler( handler );
719
720#if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
721 handler->SetFocusOnIdle();
722#else
723 m_editorCtrl->SetFocus();
724#endif
725
726 // Now we should send Editing Started event
727 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, dv_ctrl->GetId() );
728 event.SetDataViewColumn( GetOwner() );
729 event.SetModel( dv_ctrl->GetModel() );
730 event.SetItem( item );
731 event.SetEventObject( dv_ctrl );
732 dv_ctrl->GetEventHandler()->ProcessEvent( event );
733
734 return true;
735}
736
737void wxDataViewRendererBase::CancelEditing()
738{
739 if (!m_editorCtrl)
740 return;
741
742 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
743
744 m_editorCtrl->Hide();
745 wxPendingDelete.Append( m_editorCtrl );
746}
747
748bool wxDataViewRendererBase::FinishEditing()
749{
750 if (!m_editorCtrl)
751 return true;
752
753 wxVariant value;
754 GetValueFromEditorCtrl( m_editorCtrl, value );
755
756 wxDataViewCtrl* dv_ctrl = GetOwner()->GetOwner();
757
758 dv_ctrl->GetMainWindow()->SetFocus();
759
760 m_editorCtrl->Hide();
761 wxPendingDelete.Append( m_editorCtrl );
762
763 if (!Validate(value))
764 return false;
765
766 unsigned int col = GetOwner()->GetModelColumn();
767 dv_ctrl->GetModel()->SetValue( value, m_item, col );
768 dv_ctrl->GetModel()->ValueChanged( m_item, col );
769
770 // Now we should send Editing Done event
771 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, dv_ctrl->GetId() );
772 event.SetDataViewColumn( GetOwner() );
773 event.SetModel( dv_ctrl->GetModel() );
774 event.SetItem( m_item );
775 event.SetEventObject( dv_ctrl );
776 dv_ctrl->GetEventHandler()->ProcessEvent( event );
777
778 return true;
779}
780
781//-----------------------------------------------------------------------------
782// wxDataViewEditorCtrlEvtHandler
783//-----------------------------------------------------------------------------
784
785BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler, wxEvtHandler)
786 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar)
787 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus)
788 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle)
789 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter)
790END_EVENT_TABLE()
791
792wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
793 wxControl *editorCtrl,
794 wxDataViewRenderer *owner )
795{
796 m_owner = owner;
797 m_editorCtrl = editorCtrl;
798
799 m_finished = false;
800}
801
802void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent &event )
803{
804 if (m_focusOnIdle)
805 {
806 m_focusOnIdle = false;
807 if (wxWindow::FindFocus() != m_editorCtrl)
808 m_editorCtrl->SetFocus();
809 }
810
811 event.Skip();
812}
813
814void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent &WXUNUSED(event) )
815{
816 m_finished = true;
817 m_owner->FinishEditing();
818}
819
820void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event )
821{
822 switch ( event.m_keyCode )
823 {
824 case WXK_RETURN:
825 m_finished = true;
826 m_owner->FinishEditing();
827 break;
828
829 case WXK_ESCAPE:
830 {
831 m_finished = true;
832 m_owner->CancelEditing();
833 break;
834 }
835 default:
836 event.Skip();
837 }
838}
839
840void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event )
841{
842 if (!m_finished)
843 {
844 m_finished = true;
845 m_owner->FinishEditing();
846 }
847
848 event.Skip();
849}
850
851// ---------------------------------------------------------
852// wxDataViewColumnBase
853// ---------------------------------------------------------
854
855void wxDataViewColumnBase::Init(wxDataViewRenderer *renderer,
856 unsigned int model_column)
857{
858 m_renderer = renderer;
859 m_model_column = model_column;
860 m_owner = NULL;
861 m_renderer->SetOwner( (wxDataViewColumn*) this );
862}
863
864wxDataViewColumnBase::~wxDataViewColumnBase()
865{
866 delete m_renderer;
867}
868
869// ---------------------------------------------------------
870// wxDataViewCtrlBase
871// ---------------------------------------------------------
872
873IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl)
874
875wxDataViewCtrlBase::wxDataViewCtrlBase()
876{
877 m_model = NULL;
878 m_expander_column = 0;
879 m_indent = 8;
880}
881
882wxDataViewCtrlBase::~wxDataViewCtrlBase()
883{
884 if (m_model)
885 {
886 m_model->DecRef();
887 m_model = NULL;
888 }
889}
890
891bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel *model )
892{
893 if (m_model)
894 {
895 m_model->DecRef(); // discard old model, if any
896 }
897
898 // add our own reference to the new model:
899 m_model = model;
900 if (m_model)
901 {
902 m_model->IncRef();
903 }
904
905 return true;
906}
907
908wxDataViewModel* wxDataViewCtrlBase::GetModel()
909{
910 return m_model;
911}
912
913const wxDataViewModel* wxDataViewCtrlBase::GetModel() const
914{
915 return m_model;
916}
917
918void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem & item )
919{
920 if (!m_model) return;
921
922 if (!item.IsOk()) return;
923
924 wxVector<wxDataViewItem> parentChain;
925
926 // at first we get all the parents of the selected item
927 wxDataViewItem parent = m_model->GetParent(item);
928 while (parent.IsOk())
929 {
930 parentChain.push_back(parent);
931 parent = m_model->GetParent(parent);
932 }
933
934 // then we expand the parents, starting at the root
935 while (!parentChain.empty())
936 {
937 Expand(parentChain.back());
938 parentChain.pop_back();
939 }
940}
941
942wxDataViewColumn *
943wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_column,
944 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
945{
946 wxDataViewColumn *ret = new wxDataViewColumn( label,
947 new wxDataViewTextRenderer( wxT("string"), mode ),
948 model_column, width, align, flags );
949 AppendColumn( ret );
950 return ret;
951}
952
953wxDataViewColumn *
954wxDataViewCtrlBase::AppendIconTextColumn( const wxString &label, unsigned int model_column,
955 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
956{
957 wxDataViewColumn *ret = new wxDataViewColumn( label,
958 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
959 model_column, width, align, flags );
960 AppendColumn( ret );
961 return ret;
962}
963
964wxDataViewColumn *
965wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int model_column,
966 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
967{
968 wxDataViewColumn *ret = new wxDataViewColumn( label,
969 new wxDataViewToggleRenderer( wxT("bool"), mode ),
970 model_column, width, align, flags );
971 AppendColumn( ret );
972 return ret;
973}
974
975wxDataViewColumn *
976wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, unsigned int model_column,
977 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
978{
979 wxDataViewColumn *ret = new wxDataViewColumn( label,
980 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
981 model_column, width, align, flags );
982 AppendColumn( ret );
983 return ret;
984}
985
986wxDataViewColumn *
987wxDataViewCtrlBase::AppendDateColumn( const wxString &label, unsigned int model_column,
988 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
989{
990 wxDataViewColumn *ret = new wxDataViewColumn( label,
991 new wxDataViewDateRenderer( wxT("datetime"), mode ),
992 model_column, width, align, flags );
993 AppendColumn( ret );
994 return ret;
995}
996
997wxDataViewColumn *
998wxDataViewCtrlBase::AppendBitmapColumn( const wxString &label, unsigned int model_column,
999 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1000{
1001 wxDataViewColumn *ret = new wxDataViewColumn( label,
1002 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
1003 model_column, width, align, flags );
1004 AppendColumn( ret );
1005 return ret;
1006}
1007
1008wxDataViewColumn *
1009wxDataViewCtrlBase::AppendTextColumn( const wxBitmap &label, unsigned int model_column,
1010 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1011{
1012 wxDataViewColumn *ret = new wxDataViewColumn( label,
1013 new wxDataViewTextRenderer( wxT("string"), mode ),
1014 model_column, width, align, flags );
1015 AppendColumn( ret );
1016 return ret;
1017}
1018
1019wxDataViewColumn *
1020wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap &label, unsigned int model_column,
1021 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1022{
1023 wxDataViewColumn *ret = new wxDataViewColumn( label,
1024 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
1025 model_column, width, align, flags );
1026 AppendColumn( ret );
1027 return ret;
1028}
1029
1030wxDataViewColumn *
1031wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
1032 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1033{
1034 wxDataViewColumn *ret = new wxDataViewColumn( label,
1035 new wxDataViewToggleRenderer( wxT("bool"), mode ),
1036 model_column, width, align, flags );
1037 AppendColumn( ret );
1038 return ret;
1039}
1040
1041wxDataViewColumn *
1042wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
1043 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1044{
1045 wxDataViewColumn *ret = new wxDataViewColumn( label,
1046 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
1047 model_column, width, align, flags );
1048 AppendColumn( ret );
1049 return ret;
1050}
1051
1052wxDataViewColumn *
1053wxDataViewCtrlBase::AppendDateColumn( const wxBitmap &label, unsigned int model_column,
1054 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1055{
1056 wxDataViewColumn *ret = new wxDataViewColumn( label,
1057 new wxDataViewDateRenderer( wxT("datetime"), mode ),
1058 model_column, width, align, flags );
1059 AppendColumn( ret );
1060 return ret;
1061}
1062
1063wxDataViewColumn *
1064wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
1065 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1066{
1067 wxDataViewColumn *ret = new wxDataViewColumn( label,
1068 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
1069 model_column, width, align, flags );
1070 AppendColumn( ret );
1071 return ret;
1072}
1073
1074wxDataViewColumn *
1075wxDataViewCtrlBase::PrependTextColumn( const wxString &label, unsigned int model_column,
1076 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1077{
1078 wxDataViewColumn *ret = new wxDataViewColumn( label,
1079 new wxDataViewTextRenderer( wxT("string"), mode ),
1080 model_column, width, align, flags );
1081 PrependColumn( ret );
1082 return ret;
1083}
1084
1085wxDataViewColumn *
1086wxDataViewCtrlBase::PrependIconTextColumn( const wxString &label, unsigned int model_column,
1087 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1088{
1089 wxDataViewColumn *ret = new wxDataViewColumn( label,
1090 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
1091 model_column, width, align, flags );
1092 PrependColumn( ret );
1093 return ret;
1094}
1095
1096wxDataViewColumn *
1097wxDataViewCtrlBase::PrependToggleColumn( const wxString &label, unsigned int model_column,
1098 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1099{
1100
1101 wxDataViewColumn *ret = new wxDataViewColumn( label,
1102 new wxDataViewToggleRenderer( wxT("bool"), mode ),
1103 model_column, width, align, flags );
1104 PrependColumn( ret );
1105 return ret;
1106}
1107
1108wxDataViewColumn *
1109wxDataViewCtrlBase::PrependProgressColumn( const wxString &label, unsigned int model_column,
1110 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1111{
1112 wxDataViewColumn *ret = new wxDataViewColumn( label,
1113 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
1114 model_column, width, align, flags );
1115 PrependColumn( ret );
1116 return ret;
1117}
1118
1119wxDataViewColumn *
1120wxDataViewCtrlBase::PrependDateColumn( const wxString &label, unsigned int model_column,
1121 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1122{
1123 wxDataViewColumn *ret = new wxDataViewColumn( label,
1124 new wxDataViewDateRenderer( wxT("datetime"), mode ),
1125 model_column, width, align, flags );
1126 PrependColumn( ret );
1127 return ret;
1128}
1129
1130wxDataViewColumn *
1131wxDataViewCtrlBase::PrependBitmapColumn( const wxString &label, unsigned int model_column,
1132 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1133{
1134 wxDataViewColumn *ret = new wxDataViewColumn( label,
1135 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
1136 model_column, width, align, flags );
1137 PrependColumn( ret );
1138 return ret;
1139}
1140
1141wxDataViewColumn *
1142wxDataViewCtrlBase::PrependTextColumn( const wxBitmap &label, unsigned int model_column,
1143 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1144{
1145 wxDataViewColumn *ret = new wxDataViewColumn( label,
1146 new wxDataViewTextRenderer( wxT("string"), mode ),
1147 model_column, width, align, flags );
1148 PrependColumn( ret );
1149 return ret;
1150}
1151
1152wxDataViewColumn *
1153wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap &label, unsigned int model_column,
1154 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1155{
1156 wxDataViewColumn *ret = new wxDataViewColumn( label,
1157 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
1158 model_column, width, align, flags );
1159 PrependColumn( ret );
1160 return ret;
1161}
1162
1163wxDataViewColumn *
1164wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap &label, unsigned int model_column,
1165 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1166{
1167 wxDataViewColumn *ret = new wxDataViewColumn( label,
1168 new wxDataViewToggleRenderer( wxT("bool"), mode ),
1169 model_column, width, align, flags );
1170 PrependColumn( ret );
1171 return ret;
1172}
1173
1174wxDataViewColumn *
1175wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap &label, unsigned int model_column,
1176 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1177{
1178 wxDataViewColumn *ret = new wxDataViewColumn( label,
1179 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
1180 model_column, width, align, flags );
1181 PrependColumn( ret );
1182 return ret;
1183}
1184
1185wxDataViewColumn *
1186wxDataViewCtrlBase::PrependDateColumn( const wxBitmap &label, unsigned int model_column,
1187 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1188{
1189 wxDataViewColumn *ret = new wxDataViewColumn( label,
1190 new wxDataViewDateRenderer( wxT("datetime"), mode ),
1191 model_column, width, align, flags );
1192 PrependColumn( ret );
1193 return ret;
1194}
1195
1196wxDataViewColumn *
1197wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap &label, unsigned int model_column,
1198 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1199{
1200 wxDataViewColumn *ret = new wxDataViewColumn( label,
1201 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
1202 model_column, width, align, flags );
1203 PrependColumn( ret );
1204 return ret;
1205}
1206
1207bool
1208wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col )
1209{
1210 col->SetOwner( (wxDataViewCtrl*) this );
1211 return true;
1212}
1213
1214bool
1215wxDataViewCtrlBase::PrependColumn( wxDataViewColumn *col )
1216{
1217 col->SetOwner( (wxDataViewCtrl*) this );
1218 return true;
1219}
1220
1221bool
1222wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos), wxDataViewColumn *col )
1223{
1224 col->SetOwner( (wxDataViewCtrl*) this );
1225 return true;
1226}
1227
1228// ---------------------------------------------------------
1229// wxDataViewEvent
1230// ---------------------------------------------------------
1231
1232IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent)
1233
1234wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEvent );
1235
1236wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, wxDataViewEvent );
1237wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, wxDataViewEvent );
1238wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, wxDataViewEvent );
1239wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, wxDataViewEvent );
1240wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, wxDataViewEvent );
1241wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, wxDataViewEvent );
1242wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING, wxDataViewEvent );
1243wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, wxDataViewEvent );
1244wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEvent );
1245
1246wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, wxDataViewEvent );
1247
1248wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, wxDataViewEvent );
1249wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, wxDataViewEvent );
1250wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, wxDataViewEvent );
1251wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED, wxDataViewEvent );
1252
1253wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_CACHE_HINT, wxDataViewEvent );
1254
1255wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG, wxDataViewEvent );
1256wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE, wxDataViewEvent );
1257wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP, wxDataViewEvent );
1258
1259
1260
1261// -------------------------------------
1262// wxDataViewSpinRenderer
1263// -------------------------------------
1264
1265wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min, int max, wxDataViewCellMode mode, int alignment ) :
1266 wxDataViewCustomRenderer(wxT("long"), mode, alignment )
1267{
1268 m_min = min;
1269 m_max = max;
1270}
1271
1272wxControl* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
1273{
1274 long l = value;
1275 wxSize size = labelRect.GetSize();
1276#ifdef __WXMAC__
1277 size = wxSize( wxMax(70,labelRect.width ), -1 );
1278#endif
1279 wxString str;
1280 str.Printf( wxT("%d"), (int) l );
1281 wxSpinCtrl *sc = new wxSpinCtrl( parent, wxID_ANY, str,
1282 labelRect.GetTopLeft(), size, wxSP_ARROW_KEYS|wxTE_PROCESS_ENTER, m_min, m_max, l );
1283#ifdef __WXMAC__
1284 size = sc->GetSize();
1285 wxPoint pt = sc->GetPosition();
1286 sc->SetSize( pt.x - 4, pt.y - 4, size.x, size.y );
1287#endif
1288
1289 return sc;
1290}
1291
1292bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value )
1293{
1294 wxSpinCtrl *sc = (wxSpinCtrl*) editor;
1295 long l = sc->GetValue();
1296 value = l;
1297 return true;
1298}
1299
1300bool wxDataViewSpinRenderer::Render( wxRect rect, wxDC *dc, int state )
1301{
1302 wxString str;
1303 str.Printf(wxT("%d"), (int) m_data );
1304 RenderText( str, 0, rect, dc, state );
1305 return true;
1306}
1307
1308wxSize wxDataViewSpinRenderer::GetSize() const
1309{
1310 return wxSize(80,16);
1311}
1312
1313bool wxDataViewSpinRenderer::SetValue( const wxVariant &value )
1314{
1315 m_data = value.GetLong();
1316 return true;
1317}
1318
1319bool wxDataViewSpinRenderer::GetValue( wxVariant &value ) const
1320{
1321 value = m_data;
1322 return true;
1323}
1324
1325// -------------------------------------
1326// wxDataViewChoiceRenderer
1327// -------------------------------------
1328
1329#if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
1330
1331wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString& choices, wxDataViewCellMode mode, int alignment ) :
1332 wxDataViewCustomRenderer(wxT("string"), mode, alignment )
1333{
1334 m_choices = choices;
1335}
1336
1337wxControl* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
1338{
1339 wxString s = value;
1340 wxSize size = labelRect.GetSize();
1341#ifdef __WXMAC__
1342 size = wxSize( wxMax(70,labelRect.width ), -1 );
1343#endif
1344 wxChoice *c = new wxChoice( parent, wxID_ANY, labelRect.GetTopLeft(), size, m_choices );
1345 c->SetStringSelection( value.GetString() );
1346
1347 return c;
1348}
1349
1350bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value )
1351{
1352 wxChoice *c = (wxChoice*) editor;
1353 wxString s = c->GetStringSelection();
1354 value = s;
1355 return true;
1356}
1357
1358bool wxDataViewChoiceRenderer::Render( wxRect rect, wxDC *dc, int state )
1359{
1360 RenderText( m_data, 0, rect, dc, state );
1361 return true;
1362}
1363
1364wxSize wxDataViewChoiceRenderer::GetSize() const
1365{
1366 return wxSize(80,16);
1367}
1368
1369bool wxDataViewChoiceRenderer::SetValue( const wxVariant &value )
1370{
1371 m_data = value.GetString();
1372 return true;
1373}
1374
1375bool wxDataViewChoiceRenderer::GetValue( wxVariant &value ) const
1376{
1377 value = m_data;
1378 return true;
1379}
1380
1381#endif
1382
1383//-----------------------------------------------------------------------------
1384// wxDataViewListStore
1385//-----------------------------------------------------------------------------
1386
1387wxDataViewListStore::wxDataViewListStore()
1388{
1389}
1390
1391wxDataViewListStore::~wxDataViewListStore()
1392{
1393 wxVector<wxDataViewListStoreLine*>::iterator it;
1394 for (it = m_data.begin(); it != m_data.end(); ++it)
1395 {
1396 wxDataViewListStoreLine* line = *it;
1397 delete line;
1398 }
1399}
1400
1401void wxDataViewListStore::PrependColumn( const wxString &varianttype )
1402{
1403 m_cols.Insert( varianttype, 0 );
1404}
1405
1406void wxDataViewListStore::InsertColumn( unsigned int pos, const wxString &varianttype )
1407{
1408 m_cols.Insert( varianttype, pos );
1409}
1410
1411void wxDataViewListStore::AppendColumn( const wxString &varianttype )
1412{
1413 m_cols.Add( varianttype );
1414}
1415
1416unsigned int wxDataViewListStore::GetColumnCount() const
1417{
1418 return m_cols.GetCount();
1419}
1420
1421wxString wxDataViewListStore::GetColumnType( unsigned int pos ) const
1422{
1423 return m_cols[pos];
1424}
1425
1426void wxDataViewListStore::AppendItem( const wxVector<wxVariant> &values, wxClientData *data )
1427{
1428 wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data );
1429 line->m_values = values;
1430 m_data.push_back( line );
1431
1432 RowAppended();
1433}
1434
1435void wxDataViewListStore::PrependItem( const wxVector<wxVariant> &values, wxClientData *data )
1436{
1437 wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data );
1438 line->m_values = values;
1439 m_data.insert( m_data.begin(), line );
1440
1441 RowPrepended();
1442}
1443
1444void wxDataViewListStore::InsertItem( unsigned int row, const wxVector<wxVariant> &values,
1445 wxClientData *data )
1446{
1447 wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data );
1448 line->m_values = values;
1449 m_data.insert( m_data.begin()+row, line );
1450
1451 RowInserted( row );
1452}
1453
1454void wxDataViewListStore::DeleteItem( unsigned int row )
1455{
1456 wxVector<wxDataViewListStoreLine*>::iterator it = m_data.begin() + row;
1457 m_data.erase( it );
1458
1459 RowDeleted( row );
1460}
1461
1462void wxDataViewListStore::DeleteAllItems()
1463{
1464 wxVector<wxDataViewListStoreLine*>::iterator it;
1465 for (it = m_data.begin(); it != m_data.end(); ++it)
1466 {
1467 wxDataViewListStoreLine* line = *it;
1468 delete line;
1469 }
1470
1471 m_data.clear();
1472
1473 Reset( 0 );
1474}
1475
1476void wxDataViewListStore::GetValueByRow( wxVariant &value, unsigned int row, unsigned int col ) const
1477{
1478 wxDataViewListStoreLine *line = m_data[row];
1479 value = line->m_values[col];
1480}
1481
1482bool wxDataViewListStore::SetValueByRow( const wxVariant &value, unsigned int row, unsigned int col )
1483{
1484 wxDataViewListStoreLine *line = m_data[row];
1485 line->m_values[col] = value;
1486
1487 return true;
1488}
1489
1490//-----------------------------------------------------------------------------
1491// wxDataViewListCtrl
1492//-----------------------------------------------------------------------------
1493
1494IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl,wxDataViewCtrl)
1495
1496BEGIN_EVENT_TABLE(wxDataViewListCtrl,wxDataViewCtrl)
1497 EVT_SIZE( wxDataViewListCtrl::OnSize )
1498END_EVENT_TABLE()
1499
1500wxDataViewListCtrl::wxDataViewListCtrl()
1501{
1502}
1503
1504wxDataViewListCtrl::wxDataViewListCtrl( wxWindow *parent, wxWindowID id,
1505 const wxPoint& pos, const wxSize& size, long style,
1506 const wxValidator& validator )
1507{
1508 Create( parent, id, pos, size, style, validator );
1509
1510 wxDataViewListStore *store = new wxDataViewListStore;
1511 AssociateModel( store );
1512 store->DecRef();
1513}
1514
1515wxDataViewListCtrl::~wxDataViewListCtrl()
1516{
1517}
1518
1519
1520bool wxDataViewListCtrl::Create( wxWindow *parent, wxWindowID id,
1521 const wxPoint& pos, const wxSize& size, long style,
1522 const wxValidator& validator )
1523{
1524 return wxDataViewCtrl::Create( parent, id, pos, size, style, validator );
1525}
1526
1527bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn *column, const wxString &varianttype )
1528{
1529 GetStore()->AppendColumn( varianttype );
1530 return wxDataViewCtrl::AppendColumn( column );
1531}
1532
1533bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn *column, const wxString &varianttype )
1534{
1535 GetStore()->PrependColumn( varianttype );
1536 return wxDataViewCtrl::PrependColumn( column );
1537}
1538
1539bool wxDataViewListCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *column, const wxString &varianttype )
1540{
1541 GetStore()->InsertColumn( pos, varianttype );
1542 return wxDataViewCtrl::InsertColumn( pos, column );
1543}
1544
1545bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn *col )
1546{
1547 return PrependColumn( col, "string" );
1548}
1549
1550bool wxDataViewListCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *col )
1551{
1552 return InsertColumn( pos, col, "string" );
1553}
1554
1555bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn *col )
1556{
1557 return AppendColumn( col, "string" );
1558}
1559
1560wxDataViewColumn *wxDataViewListCtrl::AppendTextColumn( const wxString &label,
1561 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1562{
1563 GetStore()->AppendColumn( wxT("string") );
1564
1565 wxDataViewColumn *ret = new wxDataViewColumn( label,
1566 new wxDataViewTextRenderer( wxT("string"), mode ),
1567 GetStore()->GetColumnCount()-1, width, align, flags );
1568
1569 wxDataViewCtrl::AppendColumn( ret );
1570
1571 return ret;
1572}
1573
1574wxDataViewColumn *wxDataViewListCtrl::AppendToggleColumn( const wxString &label,
1575 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1576{
1577 GetStore()->AppendColumn( wxT("bool") );
1578
1579 wxDataViewColumn *ret = new wxDataViewColumn( label,
1580 new wxDataViewToggleRenderer( wxT("bool"), mode ),
1581 GetStore()->GetColumnCount()-1, width, align, flags );
1582
1583 wxDataViewCtrl::AppendColumn( ret );
1584
1585 return ret;
1586}
1587
1588wxDataViewColumn *wxDataViewListCtrl::AppendProgressColumn( const wxString &label,
1589 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1590{
1591 GetStore()->AppendColumn( wxT("long") );
1592
1593 wxDataViewColumn *ret = new wxDataViewColumn( label,
1594 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
1595 GetStore()->GetColumnCount()-1, width, align, flags );
1596
1597 wxDataViewCtrl::AppendColumn( ret );
1598
1599 return ret;
1600}
1601
1602wxDataViewColumn *wxDataViewListCtrl::AppendIconTextColumn( const wxString &label,
1603 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1604{
1605 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
1606
1607 wxDataViewColumn *ret = new wxDataViewColumn( label,
1608 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
1609 GetStore()->GetColumnCount()-1, width, align, flags );
1610
1611 wxDataViewCtrl::AppendColumn( ret );
1612
1613 return ret;
1614}
1615
1616void wxDataViewListCtrl::OnSize( wxSizeEvent &event )
1617{
1618 event.Skip( true );
1619}
1620
1621//-----------------------------------------------------------------------------
1622// wxDataViewTreeStore
1623//-----------------------------------------------------------------------------
1624
1625wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1626 wxDataViewTreeStoreNode *parent,
1627 const wxString &text, const wxIcon &icon, wxClientData *data )
1628{
1629 m_parent = parent;
1630 m_text = text;
1631 m_icon = icon;
1632 m_data = data;
1633}
1634
1635wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1636{
1637 if (m_data)
1638 delete m_data;
1639}
1640
1641#include "wx/listimpl.cpp"
1642WX_DEFINE_LIST(wxDataViewTreeStoreNodeList)
1643
1644wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1645 wxDataViewTreeStoreNode *parent, const wxString &text,
1646 const wxIcon &icon, const wxIcon &expanded, wxClientData *data ) :
1647 wxDataViewTreeStoreNode( parent, text, icon, data )
1648{
1649 m_iconExpanded = expanded;
1650 m_isExpanded = false;
1651 m_children.DeleteContents(true);
1652}
1653
1654wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1655{
1656}
1657
1658//-----------------------------------------------------------------------------
1659
1660wxDataViewTreeStore::wxDataViewTreeStore()
1661{
1662 m_root = new wxDataViewTreeStoreContainerNode( NULL, wxEmptyString );
1663}
1664
1665wxDataViewTreeStore::~wxDataViewTreeStore()
1666{
1667 delete m_root;
1668}
1669
1670wxDataViewItem wxDataViewTreeStore::AppendItem( const wxDataViewItem& parent,
1671 const wxString &text, const wxIcon &icon, wxClientData *data )
1672{
1673 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1674 if (!parent_node) return wxDataViewItem(0);
1675
1676 wxDataViewTreeStoreNode *node =
1677 new wxDataViewTreeStoreNode( parent_node, text, icon, data );
1678 parent_node->GetChildren().Append( node );
1679
1680 return node->GetItem();
1681}
1682
1683wxDataViewItem wxDataViewTreeStore::PrependItem( const wxDataViewItem& parent,
1684 const wxString &text, const wxIcon &icon, wxClientData *data )
1685{
1686 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1687 if (!parent_node) return wxDataViewItem(0);
1688
1689 wxDataViewTreeStoreNode *node =
1690 new wxDataViewTreeStoreNode( parent_node, text, icon, data );
1691 parent_node->GetChildren().Insert( node );
1692
1693 return node->GetItem();
1694}
1695
1696wxDataViewItem
1697wxDataViewTreeStore::InsertItem(const wxDataViewItem& parent,
1698 const wxDataViewItem& previous,
1699 const wxString& text,
1700 const wxIcon& icon,
1701 wxClientData *data)
1702{
1703 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1704 if (!parent_node) return wxDataViewItem(0);
1705
1706 wxDataViewTreeStoreNode *previous_node = FindNode( previous );
1707 int pos = parent_node->GetChildren().IndexOf( previous_node );
1708 if (pos == wxNOT_FOUND) return wxDataViewItem(0);
1709
1710 wxDataViewTreeStoreNode *node =
1711 new wxDataViewTreeStoreNode( parent_node, text, icon, data );
1712 parent_node->GetChildren().Insert( (size_t) pos, node );
1713
1714 return node->GetItem();
1715}
1716
1717wxDataViewItem wxDataViewTreeStore::PrependContainer( const wxDataViewItem& parent,
1718 const wxString &text, const wxIcon &icon, const wxIcon &expanded,
1719 wxClientData *data )
1720{
1721 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1722 if (!parent_node) return wxDataViewItem(0);
1723
1724 wxDataViewTreeStoreContainerNode *node =
1725 new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
1726 parent_node->GetChildren().Insert( node );
1727
1728 return node->GetItem();
1729}
1730
1731wxDataViewItem
1732wxDataViewTreeStore::AppendContainer(const wxDataViewItem& parent,
1733 const wxString &text,
1734 const wxIcon& icon,
1735 const wxIcon& expanded,
1736 wxClientData * data)
1737{
1738 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1739 if (!parent_node) return wxDataViewItem(0);
1740
1741 wxDataViewTreeStoreContainerNode *node =
1742 new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
1743 parent_node->GetChildren().Append( node );
1744
1745 return node->GetItem();
1746}
1747
1748wxDataViewItem
1749wxDataViewTreeStore::InsertContainer(const wxDataViewItem& parent,
1750 const wxDataViewItem& previous,
1751 const wxString& text,
1752 const wxIcon& icon,
1753 const wxIcon& expanded,
1754 wxClientData * data)
1755{
1756 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1757 if (!parent_node) return wxDataViewItem(0);
1758
1759 wxDataViewTreeStoreNode *previous_node = FindNode( previous );
1760 int pos = parent_node->GetChildren().IndexOf( previous_node );
1761 if (pos == wxNOT_FOUND) return wxDataViewItem(0);
1762
1763 wxDataViewTreeStoreContainerNode *node =
1764 new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
1765 parent_node->GetChildren().Insert( (size_t) pos, node );
1766
1767 return node->GetItem();
1768}
1769
1770wxDataViewItem wxDataViewTreeStore::GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const
1771{
1772 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1773 if (!parent_node) return wxDataViewItem(0);
1774
1775 wxDataViewTreeStoreNodeList::compatibility_iterator node = parent_node->GetChildren().Item( pos );
1776 if (node)
1777 return node->GetData();
1778
1779 return wxDataViewItem(0);
1780}
1781
1782int wxDataViewTreeStore::GetChildCount( const wxDataViewItem& parent ) const
1783{
1784 wxDataViewTreeStoreNode *node = FindNode( parent );
1785 if (!node) return -1;
1786
1787 if (!node->IsContainer())
1788 return 0;
1789
1790 wxDataViewTreeStoreContainerNode *container_node = (wxDataViewTreeStoreContainerNode*) node;
1791 return (int) container_node->GetChildren().GetCount();
1792}
1793
1794void wxDataViewTreeStore::SetItemText( const wxDataViewItem& item, const wxString &text )
1795{
1796 wxDataViewTreeStoreNode *node = FindNode( item );
1797 if (!node) return;
1798
1799 node->SetText( text );
1800}
1801
1802wxString wxDataViewTreeStore::GetItemText( const wxDataViewItem& item ) const
1803{
1804 wxDataViewTreeStoreNode *node = FindNode( item );
1805 if (!node) return wxEmptyString;
1806
1807 return node->GetText();
1808}
1809
1810void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem& item, const wxIcon &icon )
1811{
1812 wxDataViewTreeStoreNode *node = FindNode( item );
1813 if (!node) return;
1814
1815 node->SetIcon( icon );
1816}
1817
1818const wxIcon &wxDataViewTreeStore::GetItemIcon( const wxDataViewItem& item ) const
1819{
1820 wxDataViewTreeStoreNode *node = FindNode( item );
1821 if (!node) return wxNullIcon;
1822
1823 return node->GetIcon();
1824}
1825
1826void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon )
1827{
1828 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1829 if (!node) return;
1830
1831 node->SetExpandedIcon( icon );
1832}
1833
1834const wxIcon &wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem& item ) const
1835{
1836 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1837 if (!node) return wxNullIcon;
1838
1839 return node->GetExpandedIcon();
1840}
1841
1842void wxDataViewTreeStore::SetItemData( const wxDataViewItem& item, wxClientData *data )
1843{
1844 wxDataViewTreeStoreNode *node = FindNode( item );
1845 if (!node) return;
1846
1847 node->SetData( data );
1848}
1849
1850wxClientData *wxDataViewTreeStore::GetItemData( const wxDataViewItem& item ) const
1851{
1852 wxDataViewTreeStoreNode *node = FindNode( item );
1853 if (!node) return NULL;
1854
1855 return node->GetData();
1856}
1857
1858void wxDataViewTreeStore::DeleteItem( const wxDataViewItem& item )
1859{
1860 if (!item.IsOk()) return;
1861
1862 wxDataViewItem parent_item = GetParent( item );
1863
1864 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent_item );
1865 if (!parent_node) return;
1866
1867 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1868 if (!node) return;
1869
1870 parent_node->GetChildren().DeleteObject( node );
1871}
1872
1873void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem& item )
1874{
1875 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1876 if (!node) return;
1877
1878 node->GetChildren().clear();
1879}
1880
1881void wxDataViewTreeStore::DeleteAllItems()
1882{
1883 // TODO
1884}
1885
1886void
1887wxDataViewTreeStore::GetValue(wxVariant &variant,
1888 const wxDataViewItem &item,
1889 unsigned int WXUNUSED(col)) const
1890{
1891 // if (col != 0) return;
1892
1893 wxDataViewTreeStoreNode *node = FindNode( item );
1894 if (!node) return;
1895
1896 wxIcon icon( node->GetIcon());
1897 if (node->IsContainer())
1898 {
1899 wxDataViewTreeStoreContainerNode *container = (wxDataViewTreeStoreContainerNode*) node;
1900 if (container->IsExpanded() && container->GetExpandedIcon().IsOk())
1901 icon = container->GetExpandedIcon();
1902 }
1903
1904 wxDataViewIconText data( node->GetText(), icon );
1905
1906 variant << data;
1907}
1908
1909bool
1910wxDataViewTreeStore::SetValue(const wxVariant& variant,
1911 const wxDataViewItem& item,
1912 unsigned int WXUNUSED(col))
1913{
1914 // if (col != 0) return false;
1915
1916 wxDataViewTreeStoreNode *node = FindNode( item );
1917 if (!node) return false;
1918
1919 wxDataViewIconText data;
1920
1921 data << variant;
1922
1923 node->SetText( data.GetText() );
1924 node->SetIcon( data.GetIcon() );
1925
1926 return true;
1927}
1928
1929wxDataViewItem wxDataViewTreeStore::GetParent( const wxDataViewItem &item ) const
1930{
1931 wxDataViewTreeStoreNode *node = FindNode( item );
1932 if (!node) return wxDataViewItem(0);
1933
1934 wxDataViewTreeStoreNode *parent = node->GetParent();
1935 if (!parent) return wxDataViewItem(0);
1936
1937 if (parent == m_root)
1938 return wxDataViewItem(0);
1939
1940 return parent->GetItem();
1941}
1942
1943bool wxDataViewTreeStore::IsContainer( const wxDataViewItem &item ) const
1944{
1945 wxDataViewTreeStoreNode *node = FindNode( item );
1946 if (!node) return false;
1947
1948 return node->IsContainer();
1949}
1950
1951unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const
1952{
1953 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1954 if (!node) return 0;
1955
1956 wxDataViewTreeStoreNodeList::iterator iter;
1957 for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++)
1958 {
1959 wxDataViewTreeStoreNode* child = *iter;
1960 children.Add( child->GetItem() );
1961 }
1962
1963 return node->GetChildren().GetCount();
1964}
1965
1966int wxDataViewTreeStore::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
1967 unsigned int WXUNUSED(column), bool WXUNUSED(ascending) ) const
1968{
1969 wxDataViewTreeStoreNode *node1 = FindNode( item1 );
1970 wxDataViewTreeStoreNode *node2 = FindNode( item2 );
1971
1972 if (!node1 || !node2)
1973 return 0;
1974
1975 wxDataViewTreeStoreContainerNode* parent1 =
1976 (wxDataViewTreeStoreContainerNode*) node1->GetParent();
1977 wxDataViewTreeStoreContainerNode* parent2 =
1978 (wxDataViewTreeStoreContainerNode*) node2->GetParent();
1979
1980 if (parent1 != parent2)
1981 {
1982 wxLogError( wxT("Comparing items with different parent.") );
1983 return 0;
1984 }
1985
1986 if (node1->IsContainer() && !!node2->IsContainer())
1987 return 1;
1988
1989 if (node2->IsContainer() && !!node1->IsContainer())
1990 return -1;
1991
1992 return parent1->GetChildren().IndexOf( node1 ) - parent1->GetChildren().IndexOf( node2 );
1993}
1994
1995wxDataViewTreeStoreNode *wxDataViewTreeStore::FindNode( const wxDataViewItem &item ) const
1996{
1997 if (!item.IsOk())
1998 return m_root;
1999
2000 return (wxDataViewTreeStoreNode*) item.GetID();
2001}
2002
2003wxDataViewTreeStoreContainerNode *wxDataViewTreeStore::FindContainerNode( const wxDataViewItem &item ) const
2004{
2005 if (!item.IsOk())
2006 return (wxDataViewTreeStoreContainerNode*) m_root;
2007
2008 wxDataViewTreeStoreNode* node = (wxDataViewTreeStoreNode*) item.GetID();
2009
2010 if (!node->IsContainer())
2011 return NULL;
2012
2013 return (wxDataViewTreeStoreContainerNode*) node;
2014}
2015
2016//-----------------------------------------------------------------------------
2017// wxDataViewTreeCtrl
2018//-----------------------------------------------------------------------------
2019
2020IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl,wxDataViewCtrl)
2021
2022BEGIN_EVENT_TABLE(wxDataViewTreeCtrl,wxDataViewCtrl)
2023 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded)
2024 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed)
2025 EVT_SIZE( wxDataViewTreeCtrl::OnSize )
2026END_EVENT_TABLE()
2027
2028wxDataViewTreeCtrl::wxDataViewTreeCtrl()
2029{
2030 m_imageList = NULL;
2031}
2032
2033wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow *parent, wxWindowID id,
2034 const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
2035{
2036 m_imageList = NULL;
2037 Create( parent, id, pos, size, style, validator );
2038
2039 wxDataViewTreeStore *store = new wxDataViewTreeStore;
2040 AssociateModel( store );
2041 store->DecRef();
2042
2043 AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT,-1);
2044}
2045
2046wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
2047{
2048 if (m_imageList)
2049 delete m_imageList;
2050}
2051
2052bool wxDataViewTreeCtrl::Create( wxWindow *parent, wxWindowID id,
2053 const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
2054{
2055 return wxDataViewCtrl::Create( parent, id, pos, size, style, validator );
2056}
2057
2058void wxDataViewTreeCtrl::SetImageList( wxImageList *imagelist )
2059{
2060 if (m_imageList)
2061 delete m_imageList;
2062
2063 m_imageList = imagelist;
2064}
2065
2066wxDataViewItem wxDataViewTreeCtrl::AppendItem( const wxDataViewItem& parent,
2067 const wxString &text, int iconIndex, wxClientData *data )
2068{
2069 wxIcon icon = wxNullIcon;
2070 if (m_imageList && (iconIndex != -1))
2071 icon = m_imageList->GetIcon( iconIndex );
2072
2073 wxDataViewItem res = GetStore()->AppendItem( parent, text, icon, data );
2074
2075 GetStore()->ItemAdded( parent, res );
2076
2077 return res;
2078}
2079
2080wxDataViewItem wxDataViewTreeCtrl::PrependItem( const wxDataViewItem& parent,
2081 const wxString &text, int iconIndex, wxClientData *data )
2082{
2083 wxIcon icon = wxNullIcon;
2084 if (m_imageList && (iconIndex != -1))
2085 icon = m_imageList->GetIcon( iconIndex );
2086
2087 wxDataViewItem res = GetStore()->PrependItem( parent, text, icon, data );
2088
2089 GetStore()->ItemAdded( parent, res );
2090
2091 return res;
2092}
2093
2094wxDataViewItem wxDataViewTreeCtrl::InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
2095 const wxString &text, int iconIndex, wxClientData *data )
2096{
2097 wxIcon icon = wxNullIcon;
2098 if (m_imageList && (iconIndex != -1))
2099 icon = m_imageList->GetIcon( iconIndex );
2100
2101 wxDataViewItem res = GetStore()->InsertItem( parent, previous, text, icon, data );
2102
2103 GetStore()->ItemAdded( parent, res );
2104
2105 return res;
2106}
2107
2108wxDataViewItem wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem& parent,
2109 const wxString &text, int iconIndex, int expandedIndex, wxClientData *data )
2110{
2111 wxIcon icon = wxNullIcon;
2112 if (m_imageList && (iconIndex != -1))
2113 icon = m_imageList->GetIcon( iconIndex );
2114
2115 wxIcon expanded = wxNullIcon;
2116 if (m_imageList && (expandedIndex != -1))
2117 expanded = m_imageList->GetIcon( expandedIndex );
2118
2119 wxDataViewItem res = GetStore()->PrependContainer( parent, text, icon, expanded, data );
2120
2121 GetStore()->ItemAdded( parent, res );
2122
2123 return res;
2124}
2125
2126wxDataViewItem wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem& parent,
2127 const wxString &text, int iconIndex, int expandedIndex, wxClientData *data )
2128{
2129 wxIcon icon = wxNullIcon;
2130 if (m_imageList && (iconIndex != -1))
2131 icon = m_imageList->GetIcon( iconIndex );
2132
2133 wxIcon expanded = wxNullIcon;
2134 if (m_imageList && (expandedIndex != -1))
2135 expanded = m_imageList->GetIcon( expandedIndex );
2136
2137 wxDataViewItem res = GetStore()->AppendContainer( parent, text, icon, expanded, data );
2138
2139 GetStore()->ItemAdded( parent, res );
2140
2141 return res;
2142}
2143
2144wxDataViewItem wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
2145 const wxString &text, int iconIndex, int expandedIndex, wxClientData *data )
2146{
2147 wxIcon icon = wxNullIcon;
2148 if (m_imageList && (iconIndex != -1))
2149 icon = m_imageList->GetIcon( iconIndex );
2150
2151 wxIcon expanded = wxNullIcon;
2152 if (m_imageList && (expandedIndex != -1))
2153 expanded = m_imageList->GetIcon( expandedIndex );
2154
2155 wxDataViewItem res = GetStore()->InsertContainer( parent, previous, text, icon, expanded, data );
2156
2157 GetStore()->ItemAdded( parent, res );
2158
2159 return res;
2160}
2161
2162void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem& item, const wxString &text )
2163{
2164 GetStore()->SetItemText(item,text);
2165
2166 // notify control
2167 GetStore()->ValueChanged( item, 0 );
2168}
2169
2170void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem& item, const wxIcon &icon )
2171{
2172 GetStore()->SetItemIcon(item,icon);
2173
2174 // notify control
2175 GetStore()->ValueChanged( item, 0 );
2176}
2177
2178void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon )
2179{
2180 GetStore()->SetItemExpandedIcon(item,icon);
2181
2182 // notify control
2183 GetStore()->ValueChanged( item, 0 );
2184}
2185
2186void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem& item )
2187{
2188 wxDataViewItem parent_item = GetStore()->GetParent( item );
2189
2190 GetStore()->DeleteItem(item);
2191
2192 // notify control
2193 GetStore()->ItemDeleted( parent_item, item );
2194}
2195
2196void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem& item )
2197{
2198 wxDataViewTreeStoreContainerNode *node = GetStore()->FindContainerNode( item );
2199 if (!node) return;
2200
2201 wxDataViewItemArray array;
2202 wxDataViewTreeStoreNodeList::iterator iter;
2203 for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++)
2204 {
2205 wxDataViewTreeStoreNode* child = *iter;
2206 array.Add( child->GetItem() );
2207 }
2208
2209 GetStore()->DeleteChildren( item );
2210
2211 // notify control
2212 GetStore()->ItemsDeleted( item, array );
2213}
2214
2215void wxDataViewTreeCtrl::DeleteAllItems()
2216{
2217 GetStore()->DeleteAllItems();
2218
2219 GetStore()->Cleared();
2220}
2221
2222void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent &event )
2223{
2224 if (m_imageList) return;
2225
2226 wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() );
2227 if (!container) return;
2228
2229 container->SetExpanded( true );
2230
2231 GetStore()->ItemChanged( event.GetItem() );
2232}
2233
2234void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent &event )
2235{
2236 if (m_imageList) return;
2237
2238 wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() );
2239 if (!container) return;
2240
2241 container->SetExpanded( false );
2242
2243 GetStore()->ItemChanged( event.GetItem() );
2244}
2245
2246void wxDataViewTreeCtrl::OnSize( wxSizeEvent &event )
2247{
2248#if defined(wxUSE_GENERICDATAVIEWCTRL)
2249 // automatically resize our only column to take the entire control width
2250 if ( GetColumnCount() )
2251 {
2252 wxSize size = GetClientSize();
2253 GetColumn(0)->SetWidth(size.x);
2254 }
2255#endif
2256 event.Skip( true );
2257}
2258
2259#endif // wxUSE_DATAVIEWCTRL
2260