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