]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/datavcmn.cpp
atsu for textctrl
[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#include "wx/spinctrl.h"
23
24#ifndef WX_PRECOMP
25 #include "wx/dc.h"
26 #include "wx/settings.h"
27 #include "wx/log.h"
28 #include "wx/icon.h"
29 #include "wx/crt.h"
30#endif
31
32const wxChar wxDataViewCtrlNameStr[] = wxT("dataviewCtrl");
33
34
35bool operator == (const wxDataViewItem &left, const wxDataViewItem &right)
36{
37 return (left.GetID() == right.GetID() );
38}
39
40#ifdef __WXDEBUG__
41void wxDataViewItem::Print(const wxString& text) const
42{
43 wxPrintf("item %s: %l\n", text, (long)m_id);
44}
45#endif
46
47// ---------------------------------------------------------
48// wxDataViewModelNotifier
49// ---------------------------------------------------------
50
51#include "wx/listimpl.cpp"
52WX_DEFINE_LIST(wxDataViewModelNotifiers)
53
54bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items )
55{
56 size_t count = items.GetCount();
57 size_t i;
58 for (i = 0; i < count; i++)
59 if (!ItemAdded( parent, items[i] )) return false;
60
61 return true;
62}
63
64bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items )
65{
66 size_t count = items.GetCount();
67 size_t i;
68 for (i = 0; i < count; i++)
69 if (!ItemDeleted( parent, items[i] )) return false;
70
71 return true;
72}
73
74bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray &items )
75{
76 size_t count = items.GetCount();
77 size_t i;
78 for (i = 0; i < count; i++)
79 if (!ItemChanged( items[i] )) return false;
80
81 return true;
82}
83
84// ---------------------------------------------------------
85// wxDataViewModel
86// ---------------------------------------------------------
87
88wxDataViewModel::wxDataViewModel()
89{
90 m_notifiers.DeleteContents( true );
91}
92
93bool wxDataViewModel::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
94{
95 bool ret = true;
96
97 wxDataViewModelNotifiers::iterator iter;
98 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
99 {
100 wxDataViewModelNotifier* notifier = *iter;
101 if (!notifier->ItemAdded( parent, item ))
102 ret = false;
103 }
104
105 return ret;
106}
107
108bool wxDataViewModel::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
109{
110 bool ret = true;
111
112 wxDataViewModelNotifiers::iterator iter;
113 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
114 {
115 wxDataViewModelNotifier* notifier = *iter;
116 if (!notifier->ItemDeleted( parent, item ))
117 ret = false;
118 }
119
120 return ret;
121}
122
123bool wxDataViewModel::ItemChanged( const wxDataViewItem &item )
124{
125 bool ret = true;
126
127 wxDataViewModelNotifiers::iterator iter;
128 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
129 {
130 wxDataViewModelNotifier* notifier = *iter;
131 if (!notifier->ItemChanged( item ))
132 ret = false;
133 }
134
135 return ret;
136}
137
138bool wxDataViewModel::ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items )
139{
140 bool ret = true;
141
142 wxDataViewModelNotifiers::iterator iter;
143 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
144 {
145 wxDataViewModelNotifier* notifier = *iter;
146 if (!notifier->ItemsAdded( parent, items ))
147 ret = false;
148 }
149
150 return ret;
151}
152
153bool wxDataViewModel::ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items )
154{
155 bool ret = true;
156
157 wxDataViewModelNotifiers::iterator iter;
158 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
159 {
160 wxDataViewModelNotifier* notifier = *iter;
161 if (!notifier->ItemsDeleted( parent, items ))
162 ret = false;
163 }
164
165 return ret;
166}
167
168bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray &items )
169{
170 bool ret = true;
171
172 wxDataViewModelNotifiers::iterator iter;
173 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
174 {
175 wxDataViewModelNotifier* notifier = *iter;
176 if (!notifier->ItemsChanged( items ))
177 ret = false;
178 }
179
180 return ret;
181}
182
183bool wxDataViewModel::ValueChanged( const wxDataViewItem &item, unsigned int col )
184{
185 bool ret = true;
186
187 wxDataViewModelNotifiers::iterator iter;
188 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
189 {
190 wxDataViewModelNotifier* notifier = *iter;
191 if (!notifier->ValueChanged( item, col ))
192 ret = false;
193 }
194
195 return ret;
196}
197
198bool wxDataViewModel::Cleared()
199{
200 bool ret = true;
201
202 wxDataViewModelNotifiers::iterator iter;
203 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
204 {
205 wxDataViewModelNotifier* notifier = *iter;
206 if (!notifier->Cleared())
207 ret = false;
208 }
209
210 return ret;
211}
212
213void wxDataViewModel::Resort()
214{
215 wxDataViewModelNotifiers::iterator iter;
216 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
217 {
218 wxDataViewModelNotifier* notifier = *iter;
219 notifier->Resort();
220 }
221}
222
223void wxDataViewModel::AddNotifier( wxDataViewModelNotifier *notifier )
224{
225 m_notifiers.push_back( notifier );
226 notifier->SetOwner( this );
227}
228
229void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier *notifier )
230{
231 m_notifiers.DeleteObject( notifier );
232}
233
234int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
235 unsigned int column, bool ascending )
236{
237 // sort branches before leaves
238 bool item1_is_container = IsContainer(item1);
239 bool item2_is_container = IsContainer(item2);
240
241 if (item1_is_container && !item2_is_container)
242 return 1;
243 if (item2_is_container && !item1_is_container)
244 return -1;
245
246 wxVariant value1,value2;
247 GetValue( value1, item1, column );
248 GetValue( value2, item2, column );
249
250 if (!ascending)
251 {
252 wxVariant temp = value1;
253 value1 = value2;
254 value2 = temp;
255 }
256
257 if (value1.GetType() == wxT("string"))
258 {
259 wxString str1 = value1.GetString();
260 wxString str2 = value2.GetString();
261 int res = str1.Cmp( str2 );
262 if (res) return res;
263 } else
264 if (value1.GetType() == wxT("long"))
265 {
266 long l1 = value1.GetLong();
267 long l2 = value2.GetLong();
268 long res = l1-l2;
269 if (res) return res;
270 } else
271 if (value1.GetType() == wxT("double"))
272 {
273 double d1 = value1.GetDouble();
274 double d2 = value2.GetDouble();
275 if (d1 < d2) return 1;
276 if (d1 > d2) return -1;
277 } else
278 if (value1.GetType() == wxT("datetime"))
279 {
280 wxDateTime dt1 = value1.GetDateTime();
281 wxDateTime dt2 = value2.GetDateTime();
282 if (dt1.IsEarlierThan(dt2)) return 1;
283 if (dt2.IsEarlierThan(dt1)) return -11;
284 }
285
286 // items must be different
287 unsigned long litem1 = (unsigned long) item1.GetID();
288 unsigned long litem2 = (unsigned long) item2.GetID();
289
290 if (!ascending)
291 return litem2-litem2;
292
293 return litem1-litem2;
294}
295
296// ---------------------------------------------------------
297// wxDataViewIndexListModel
298// ---------------------------------------------------------
299
300wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size )
301{
302#ifndef __WXMAC__
303 m_useHash = false;
304#else
305 m_useHash = true;
306#endif
307
308 if (m_useHash)
309 {
310 // IDs are ordered until an item gets deleted or inserted
311 m_ordered = true;
312
313 // build initial index
314 unsigned int i;
315 for (i = 1; i < initial_size+1; i++)
316 m_hash.Add( (void*) i );
317 m_lastIndex = initial_size + 1;
318 }
319 else
320 {
321 m_lastIndex = initial_size-1;
322 }
323}
324
325wxDataViewIndexListModel::~wxDataViewIndexListModel()
326{
327}
328
329void wxDataViewIndexListModel::RowPrepended()
330{
331 if (m_useHash)
332 {
333 m_ordered = false;
334
335 unsigned int id = m_lastIndex++;
336 m_hash.Insert( (void*) id, 0 );
337 wxDataViewItem item( (void*) id );
338 ItemAdded( wxDataViewItem(0), item );
339 }
340 else
341 {
342 m_lastIndex++;
343 wxDataViewItem item( (void*) 0 );
344 ItemAdded( wxDataViewItem(0), item );
345 }
346}
347
348void wxDataViewIndexListModel::RowInserted( unsigned int before )
349{
350 if (m_useHash)
351 {
352 m_ordered = false;
353
354 unsigned int id = m_lastIndex++;
355 m_hash.Insert( (void*) id, before );
356 wxDataViewItem item( (void*) id );
357 ItemAdded( wxDataViewItem(0), item );
358 }
359 else
360 {
361 m_lastIndex++;
362 wxDataViewItem item( (void*) before );
363 ItemAdded( wxDataViewItem(0), item );
364 }
365}
366
367void wxDataViewIndexListModel::RowAppended()
368{
369 if (m_useHash)
370 {
371 unsigned int id = m_lastIndex++;
372 m_hash.Add( (void*) id );
373 wxDataViewItem item( (void*) id );
374 ItemAdded( wxDataViewItem(0), item );
375 }
376 else
377 {
378 m_lastIndex++;
379 wxDataViewItem item( (void*) m_lastIndex );
380 ItemAdded( wxDataViewItem(0), item );
381 }
382}
383
384void wxDataViewIndexListModel::RowDeleted( unsigned int row )
385{
386 if (m_useHash)
387 {
388 wxDataViewItem item( m_hash[row] );
389 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
390 m_hash.RemoveAt( row );
391 }
392 else
393 {
394 wxDataViewItem item( (void*) row );
395 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
396 m_lastIndex++;
397 }
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_useHash)
413 {
414 if (m_ordered)
415 {
416 unsigned int pos = wxPtrToUInt( item.GetID() );
417 return pos-1;
418 }
419
420 // assert for not found
421 return (unsigned int) m_hash.Index( item.GetID() );
422 }
423 else
424 {
425 return wxPtrToUInt( item.GetID() );
426 }
427}
428
429wxDataViewItem wxDataViewIndexListModel::GetItem( unsigned int row ) const
430{
431 if (m_useHash)
432 {
433 wxASSERT( row < m_hash.GetCount() );
434 return wxDataViewItem( m_hash[row] );
435 }
436 else
437 {
438 return wxDataViewItem( (void*) row );
439 }
440}
441
442bool wxDataViewIndexListModel::HasDefaultCompare() const
443{
444 return !m_ordered;
445}
446
447int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1,
448 const wxDataViewItem& item2,
449 unsigned int WXUNUSED(column),
450 bool ascending)
451{
452 if (m_ordered || !m_useHash)
453 {
454 unsigned int pos1 = wxPtrToUInt(item1.GetID());
455 unsigned int pos2 = wxPtrToUInt(item2.GetID());
456
457 if (ascending)
458 return pos1 - pos2;
459 else
460 return pos2 - pos1;
461 }
462
463 if (ascending)
464 return GetRow(item1) - GetRow(item2);
465
466 return GetRow(item2) - GetRow(item1);
467}
468
469void wxDataViewIndexListModel::GetValue( wxVariant &variant,
470 const wxDataViewItem &item, unsigned int col ) const
471{
472 GetValue( variant, GetRow(item), col );
473}
474
475bool wxDataViewIndexListModel::SetValue( const wxVariant &variant,
476 const wxDataViewItem &item, unsigned int col )
477{
478 return SetValue( variant, GetRow(item), col );
479}
480
481bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr )
482{
483 return GetAttr( GetRow(item), col, attr );
484}
485
486wxDataViewItem wxDataViewIndexListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const
487{
488 return wxDataViewItem(0);
489}
490
491bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem &item ) const
492{
493 // only the invisible root item has children
494 if (!item.IsOk())
495 return true;
496
497 return false;
498}
499
500unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const
501{
502 if (!m_useHash)
503 return 0; // error
504
505 if (item.IsOk())
506 return 0;
507
508 children = m_hash;
509
510 return m_hash.GetCount();
511}
512
513//-----------------------------------------------------------------------------
514// wxDataViewIconText
515//-----------------------------------------------------------------------------
516
517IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText,wxObject)
518
519IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV)
520
521bool operator == (const wxDataViewIconText &one, const wxDataViewIconText &two)
522{
523 if (one.GetText() != two.GetText()) return false;
524 if (one.IsSameAs(two)) return false;
525 return true;
526}
527
528// ---------------------------------------------------------
529// wxDataViewRendererBase
530// ---------------------------------------------------------
531
532IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase, wxObject)
533
534wxDataViewRendererBase::wxDataViewRendererBase( const wxString &varianttype,
535 wxDataViewCellMode WXUNUSED(mode),
536 int WXUNUSED(align) )
537{
538 m_variantType = varianttype;
539 m_editorCtrl = NULL;
540}
541
542const wxDataViewCtrl* wxDataViewRendererBase::GetView() const
543{
544 return wx_const_cast(wxDataViewRendererBase*, this)->GetOwner()->GetOwner();
545}
546
547bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect )
548{
549 m_item = item; // remember for later
550
551 unsigned int col = GetOwner()->GetModelColumn();
552 wxVariant value;
553 GetOwner()->GetOwner()->GetModel()->GetValue( value, item, col );
554
555 m_editorCtrl = CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect, value );
556
557 wxDataViewEditorCtrlEvtHandler *handler =
558 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl, (wxDataViewRenderer*) this );
559
560 m_editorCtrl->PushEventHandler( handler );
561
562#if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
563 handler->SetFocusOnIdle();
564#else
565 m_editorCtrl->SetFocus();
566#endif
567
568 // Now we should send Editing Started event
569 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, GetOwner()->GetOwner()->GetId() );
570 event.SetDataViewColumn( GetOwner() );
571 event.SetModel( GetOwner()->GetOwner()->GetModel() );
572 event.SetItem( item );
573 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event );
574
575 return true;
576}
577
578void wxDataViewRendererBase::CancelEditing()
579{
580 wxPendingDelete.Append( m_editorCtrl );
581
582 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
583
584 // m_editorCtrl->PopEventHandler( true );
585}
586
587bool wxDataViewRendererBase::FinishEditing()
588{
589 wxVariant value;
590 GetValueFromEditorCtrl( m_editorCtrl, value );
591
592 wxPendingDelete.Append( m_editorCtrl );
593
594 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
595
596 if (!Validate(value))
597 return false;
598
599 unsigned int col = GetOwner()->GetModelColumn();
600 GetOwner()->GetOwner()->GetModel()->SetValue( value, m_item, col );
601 GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item, col );
602
603 // m_editorCtrl->PopEventHandler( true );
604
605 // Now we should send Editing Done event
606 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, GetOwner()->GetOwner()->GetId() );
607 event.SetDataViewColumn( GetOwner() );
608 event.SetModel( GetOwner()->GetOwner()->GetModel() );
609 event.SetItem( m_item );
610 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event );
611
612 return true;
613}
614
615//-----------------------------------------------------------------------------
616// wxDataViewEditorCtrlEvtHandler
617//-----------------------------------------------------------------------------
618
619BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler, wxEvtHandler)
620 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar)
621 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus)
622 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle)
623END_EVENT_TABLE()
624
625wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
626 wxControl *editorCtrl,
627 wxDataViewRenderer *owner )
628{
629 m_owner = owner;
630 m_editorCtrl = editorCtrl;
631
632 m_finished = false;
633}
634
635void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent &event )
636{
637 if (m_focusOnIdle)
638 {
639 m_focusOnIdle = false;
640 if (wxWindow::FindFocus() != m_editorCtrl)
641 m_editorCtrl->SetFocus();
642 }
643
644 event.Skip();
645}
646
647void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event )
648{
649 switch ( event.m_keyCode )
650 {
651 case WXK_RETURN:
652 m_finished = true;
653 m_owner->FinishEditing();
654 break;
655
656 case WXK_ESCAPE:
657 m_finished = true;
658 m_owner->CancelEditing();
659 break;
660
661 default:
662 event.Skip();
663 }
664}
665
666void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event )
667{
668 if (!m_finished)
669 {
670 m_finished = true;
671 m_owner->FinishEditing();
672 }
673
674 event.Skip();
675}
676
677// ---------------------------------------------------------
678// wxDataViewColumnBase
679// ---------------------------------------------------------
680
681IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase, wxObject)
682
683wxDataViewColumnBase::wxDataViewColumnBase(const wxString& WXUNUSED(title),
684 wxDataViewRenderer *renderer,
685 unsigned int model_column,
686 int WXUNUSED(width),
687 wxAlignment WXUNUSED(align),
688 int WXUNUSED(flags))
689{
690 m_renderer = renderer;
691 m_model_column = model_column;
692 m_owner = NULL;
693 m_renderer->SetOwner( (wxDataViewColumn*) this );
694
695 // NOTE: the wxDataViewColumn's ctor must store the width, align, flags
696 // parameters inside the native control!
697}
698
699wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap& bitmap,
700 wxDataViewRenderer *renderer,
701 unsigned int model_column,
702 int WXUNUSED(width),
703 wxAlignment WXUNUSED(align),
704 int WXUNUSED(flags) )
705{
706 m_renderer = renderer;
707 m_model_column = model_column;
708 m_bitmap = bitmap;
709 m_owner = NULL;
710 m_renderer->SetOwner( (wxDataViewColumn*) this );
711}
712
713wxDataViewColumnBase::~wxDataViewColumnBase()
714{
715 if (m_renderer)
716 delete m_renderer;
717}
718
719int wxDataViewColumnBase::GetFlags() const
720{
721 int ret = 0;
722
723 if (IsSortable())
724 ret |= wxDATAVIEW_COL_SORTABLE;
725 if (IsResizeable())
726 ret |= wxDATAVIEW_COL_RESIZABLE;
727 if (IsHidden())
728 ret |= wxDATAVIEW_COL_HIDDEN;
729
730 return ret;
731}
732
733void wxDataViewColumnBase::SetFlags(int flags)
734{
735 SetSortable((flags & wxDATAVIEW_COL_SORTABLE) != 0);
736 SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0);
737 SetHidden((flags & wxDATAVIEW_COL_HIDDEN) != 0);
738}
739
740// ---------------------------------------------------------
741// wxDataViewCtrlBase
742// ---------------------------------------------------------
743
744IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl)
745
746wxDataViewCtrlBase::wxDataViewCtrlBase()
747{
748 m_model = NULL;
749 m_expander_column = 0;
750 m_indent = 8;
751}
752
753wxDataViewCtrlBase::~wxDataViewCtrlBase()
754{
755 if (m_model)
756 {
757 m_model->DecRef();
758 m_model = NULL;
759 }
760}
761
762bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel *model )
763{
764 if (m_model)
765 {
766 m_model->DecRef(); // discard old model, if any
767 }
768
769 // add our own reference to the new model:
770 m_model = model;
771 if (m_model)
772 {
773 m_model->IncRef();
774 }
775
776 return true;
777}
778
779wxDataViewModel* wxDataViewCtrlBase::GetModel()
780{
781 return m_model;
782}
783
784wxDataViewColumn *
785wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_column,
786 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
787{
788 wxDataViewColumn *ret = new wxDataViewColumn( label,
789 new wxDataViewTextRenderer( wxT("string"), mode, (int)align ),
790 model_column, width, align, flags );
791 AppendColumn( ret );
792 return ret;
793}
794
795wxDataViewColumn *
796wxDataViewCtrlBase::AppendIconTextColumn( const wxString &label, unsigned int model_column,
797 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
798{
799 wxDataViewColumn *ret = new wxDataViewColumn( label,
800 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ),
801 model_column, width, align, flags );
802 AppendColumn( ret );
803 return ret;
804}
805
806wxDataViewColumn *
807wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int model_column,
808 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
809{
810
811 wxDataViewColumn *ret = new wxDataViewColumn( label,
812 new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ),
813 model_column, width, align, flags );
814 AppendColumn( ret );
815 return ret;
816}
817
818wxDataViewColumn *
819wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, unsigned int model_column,
820 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
821{
822 wxDataViewColumn *ret = new wxDataViewColumn( label,
823 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ),
824 model_column, width, align, flags );
825 AppendColumn( ret );
826 return ret;
827}
828
829wxDataViewColumn *
830wxDataViewCtrlBase::AppendDateColumn( const wxString &label, unsigned int model_column,
831 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
832{
833 wxDataViewColumn *ret = new wxDataViewColumn( label,
834 new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ),
835 model_column, width, align, flags );
836 AppendColumn( ret );
837 return ret;
838}
839
840wxDataViewColumn *
841wxDataViewCtrlBase::AppendBitmapColumn( const wxString &label, unsigned int model_column,
842 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
843{
844 wxDataViewColumn *ret = new wxDataViewColumn( label,
845 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ),
846 model_column, width, align, flags );
847 AppendColumn( ret );
848 return ret;
849}
850
851wxDataViewColumn *
852wxDataViewCtrlBase::AppendTextColumn( const wxBitmap &label, unsigned int model_column,
853 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
854{
855 wxDataViewColumn *ret = new wxDataViewColumn( label,
856 new wxDataViewTextRenderer( wxT("string"), mode, (int)align ),
857 model_column, width, align, flags );
858 AppendColumn( ret );
859 return ret;
860}
861
862wxDataViewColumn *
863wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap &label, unsigned int model_column,
864 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
865{
866 wxDataViewColumn *ret = new wxDataViewColumn( label,
867 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ),
868 model_column, width, align, flags );
869 AppendColumn( ret );
870 return ret;
871}
872
873wxDataViewColumn *
874wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
875 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
876{
877 wxDataViewColumn *ret = new wxDataViewColumn( label,
878 new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ),
879 model_column, width, align, flags );
880 AppendColumn( ret );
881 return ret;
882}
883
884wxDataViewColumn *
885wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
886 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
887{
888 wxDataViewColumn *ret = new wxDataViewColumn( label,
889 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ),
890 model_column, width, align, flags );
891 AppendColumn( ret );
892 return ret;
893}
894
895wxDataViewColumn *
896wxDataViewCtrlBase::AppendDateColumn( const wxBitmap &label, unsigned int model_column,
897 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
898{
899 wxDataViewColumn *ret = new wxDataViewColumn( label,
900 new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ),
901 model_column, width, align, flags );
902 AppendColumn( ret );
903 return ret;
904}
905
906wxDataViewColumn *
907wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
908 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
909{
910 wxDataViewColumn *ret = new wxDataViewColumn( label,
911 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ),
912 model_column, width, align, flags );
913 AppendColumn( ret );
914 return ret;
915}
916
917wxDataViewColumn *
918wxDataViewCtrlBase::PrependTextColumn( const wxString &label, unsigned int model_column,
919 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
920{
921 wxDataViewColumn *ret = new wxDataViewColumn( label,
922 new wxDataViewTextRenderer( wxT("string"), mode, (int)align ),
923 model_column, width, align, flags );
924 PrependColumn( ret );
925 return ret;
926}
927
928wxDataViewColumn *
929wxDataViewCtrlBase::PrependIconTextColumn( const wxString &label, unsigned int model_column,
930 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
931{
932 wxDataViewColumn *ret = new wxDataViewColumn( label,
933 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ),
934 model_column, width, align, flags );
935 PrependColumn( ret );
936 return ret;
937}
938
939wxDataViewColumn *
940wxDataViewCtrlBase::PrependToggleColumn( const wxString &label, unsigned int model_column,
941 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
942{
943
944 wxDataViewColumn *ret = new wxDataViewColumn( label,
945 new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ),
946 model_column, width, align, flags );
947 PrependColumn( ret );
948 return ret;
949}
950
951wxDataViewColumn *
952wxDataViewCtrlBase::PrependProgressColumn( const wxString &label, unsigned int model_column,
953 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
954{
955 wxDataViewColumn *ret = new wxDataViewColumn( label,
956 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ),
957 model_column, width, align, flags );
958 PrependColumn( ret );
959 return ret;
960}
961
962wxDataViewColumn *
963wxDataViewCtrlBase::PrependDateColumn( const wxString &label, unsigned int model_column,
964 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
965{
966 wxDataViewColumn *ret = new wxDataViewColumn( label,
967 new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ),
968 model_column, width, align, flags );
969 PrependColumn( ret );
970 return ret;
971}
972
973wxDataViewColumn *
974wxDataViewCtrlBase::PrependBitmapColumn( const wxString &label, unsigned int model_column,
975 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
976{
977 wxDataViewColumn *ret = new wxDataViewColumn( label,
978 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ),
979 model_column, width, align, flags );
980 PrependColumn( ret );
981 return ret;
982}
983
984wxDataViewColumn *
985wxDataViewCtrlBase::PrependTextColumn( const wxBitmap &label, unsigned int model_column,
986 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
987{
988 wxDataViewColumn *ret = new wxDataViewColumn( label,
989 new wxDataViewTextRenderer( wxT("string"), mode, (int)align ),
990 model_column, width, align, flags );
991 PrependColumn( ret );
992 return ret;
993}
994
995wxDataViewColumn *
996wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap &label, unsigned int model_column,
997 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
998{
999 wxDataViewColumn *ret = new wxDataViewColumn( label,
1000 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ),
1001 model_column, width, align, flags );
1002 PrependColumn( ret );
1003 return ret;
1004}
1005
1006wxDataViewColumn *
1007wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap &label, unsigned int model_column,
1008 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1009{
1010 wxDataViewColumn *ret = new wxDataViewColumn( label,
1011 new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ),
1012 model_column, width, align, flags );
1013 PrependColumn( ret );
1014 return ret;
1015}
1016
1017wxDataViewColumn *
1018wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap &label, unsigned int model_column,
1019 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1020{
1021 wxDataViewColumn *ret = new wxDataViewColumn( label,
1022 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ),
1023 model_column, width, align, flags );
1024 PrependColumn( ret );
1025 return ret;
1026}
1027
1028wxDataViewColumn *
1029wxDataViewCtrlBase::PrependDateColumn( const wxBitmap &label, unsigned int model_column,
1030 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1031{
1032 wxDataViewColumn *ret = new wxDataViewColumn( label,
1033 new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ),
1034 model_column, width, align, flags );
1035 PrependColumn( ret );
1036 return ret;
1037}
1038
1039wxDataViewColumn *
1040wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap &label, unsigned int model_column,
1041 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1042{
1043 wxDataViewColumn *ret = new wxDataViewColumn( label,
1044 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ),
1045 model_column, width, align, flags );
1046 PrependColumn( ret );
1047 return ret;
1048}
1049
1050bool
1051wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col )
1052{
1053 col->SetOwner( (wxDataViewCtrl*) this );
1054 return true;
1055}
1056
1057bool
1058wxDataViewCtrlBase::PrependColumn( wxDataViewColumn *col )
1059{
1060 col->SetOwner( (wxDataViewCtrl*) this );
1061 return true;
1062}
1063
1064// ---------------------------------------------------------
1065// wxDataViewEvent
1066// ---------------------------------------------------------
1067
1068IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent)
1069
1070DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED)
1071
1072DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED)
1073DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING)
1074DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED)
1075DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING)
1076DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED)
1077DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED)
1078DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE)
1079DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED)
1080
1081DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK)
1082DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK)
1083DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED)
1084
1085
1086// -------------------------------------
1087// wxDataViewSpinRenderer
1088// -------------------------------------
1089
1090wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min, int max, wxDataViewCellMode mode, int alignment ) :
1091 wxDataViewCustomRenderer( "long", mode, alignment )
1092{
1093 m_min = min;
1094 m_max = max;
1095}
1096
1097wxControl* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
1098{
1099 long l = value;
1100 return new wxSpinCtrl( parent, wxID_ANY, wxEmptyString,
1101 labelRect.GetTopLeft(), labelRect.GetSize(), wxSP_ARROW_KEYS, m_min, m_max, l );
1102}
1103
1104bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value )
1105{
1106 wxSpinCtrl *sc = (wxSpinCtrl*) editor;
1107 long l = sc->GetValue();
1108 value = l;
1109 return true;
1110}
1111
1112bool wxDataViewSpinRenderer::Render( wxRect rect, wxDC *dc, int state )
1113{
1114 wxString str;
1115 str.Printf( "%d", (int) m_data );
1116 RenderText( str, 0, rect, dc, state );
1117 return true;
1118}
1119
1120wxSize wxDataViewSpinRenderer::GetSize() const
1121{
1122 return wxSize(80,16);
1123}
1124
1125bool wxDataViewSpinRenderer::SetValue( const wxVariant &value )
1126{
1127 m_data = value.GetLong();
1128 return true;
1129}
1130
1131bool wxDataViewSpinRenderer::GetValue( wxVariant &value ) const
1132{
1133 value = m_data;
1134 return true;
1135}
1136
1137//-----------------------------------------------------------------------------
1138// wxDataViewTreeStore
1139//-----------------------------------------------------------------------------
1140
1141wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1142 wxDataViewTreeStoreNode *parent,
1143 const wxString &text, const wxIcon &icon, wxClientData *data )
1144{
1145 m_parent = parent;
1146 m_text = text;
1147 m_icon = icon;
1148 m_data = data;
1149}
1150
1151wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1152{
1153 if (m_data)
1154 delete m_data;
1155}
1156
1157#include "wx/listimpl.cpp"
1158WX_DEFINE_LIST(wxDataViewTreeStoreNodeList)
1159
1160wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1161 wxDataViewTreeStoreNode *parent, const wxString &text,
1162 const wxIcon &icon, const wxIcon &expanded, wxClientData *data ) :
1163 wxDataViewTreeStoreNode( parent, text, icon, data )
1164{
1165 m_iconExpanded = expanded;
1166 m_children.DeleteContents(true);
1167}
1168
1169wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1170{
1171}
1172
1173//-----------------------------------------------------------------------------
1174
1175wxDataViewTreeStore::wxDataViewTreeStore()
1176{
1177 m_root = new wxDataViewTreeStoreContainerNode( NULL, wxEmptyString );
1178}
1179
1180wxDataViewTreeStore::~wxDataViewTreeStore()
1181{
1182 delete m_root;
1183}
1184
1185wxDataViewItem wxDataViewTreeStore::AppendItem( const wxDataViewItem& parent,
1186 const wxString &text, const wxIcon &icon, wxClientData *data )
1187{
1188 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1189 if (!parent_node) return wxDataViewItem(0);
1190
1191 wxDataViewTreeStoreNode *node =
1192 new wxDataViewTreeStoreNode( parent_node, text, icon, data );
1193 parent_node->GetChildren().Append( node );
1194
1195 // notify control
1196 ItemAdded( parent, node->GetItem() );
1197
1198 return node->GetItem();
1199}
1200
1201wxDataViewItem wxDataViewTreeStore::PrependItem( const wxDataViewItem& parent,
1202 const wxString &text, const wxIcon &icon, wxClientData *data )
1203{
1204 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1205 if (!parent_node) return wxDataViewItem(0);
1206
1207 wxDataViewTreeStoreNode *node =
1208 new wxDataViewTreeStoreNode( parent_node, text, icon, data );
1209 parent_node->GetChildren().Insert( node );
1210
1211 // notify control
1212 ItemAdded( parent, node->GetItem() );
1213
1214 return node->GetItem();
1215}
1216
1217wxDataViewItem
1218wxDataViewTreeStore::InsertItem(const wxDataViewItem& WXUNUSED(parent),
1219 const wxDataViewItem& WXUNUSED(previous),
1220 const wxString& WXUNUSED(text),
1221 const wxIcon& WXUNUSED(icon),
1222 wxClientData * WXUNUSED(data))
1223{
1224 return wxDataViewItem(0);
1225}
1226
1227wxDataViewItem wxDataViewTreeStore::PrependContainer( const wxDataViewItem& parent,
1228 const wxString &text, const wxIcon &icon, const wxIcon &expanded,
1229 wxClientData *data )
1230{
1231 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1232 if (!parent_node) return wxDataViewItem(0);
1233
1234 wxDataViewTreeStoreContainerNode *node =
1235 new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
1236 parent_node->GetChildren().Insert( node );
1237
1238 // notify control
1239 ItemAdded( parent, node->GetItem() );
1240
1241 return node->GetItem();
1242}
1243
1244wxDataViewItem
1245wxDataViewTreeStore::AppendContainer(const wxDataViewItem& parent,
1246 const wxString &text,
1247 const wxIcon& icon,
1248 const wxIcon& expanded,
1249 wxClientData * data)
1250{
1251 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1252 if (!parent_node) return wxDataViewItem(0);
1253
1254 wxDataViewTreeStoreContainerNode *node =
1255 new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
1256 parent_node->GetChildren().Append( node );
1257
1258 // notify control
1259 ItemAdded( parent, node->GetItem() );
1260
1261 return node->GetItem();
1262}
1263
1264wxDataViewItem
1265wxDataViewTreeStore::InsertContainer(const wxDataViewItem& WXUNUSED(parent),
1266 const wxDataViewItem& WXUNUSED(previous),
1267 const wxString& WXUNUSED(text),
1268 const wxIcon& WXUNUSED(icon),
1269 const wxIcon& WXUNUSED(expanded),
1270 wxClientData * WXUNUSED(data))
1271{
1272 return wxDataViewItem(0);
1273}
1274
1275wxDataViewItem wxDataViewTreeStore::GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const
1276{
1277 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1278 if (!parent_node) return wxDataViewItem(0);
1279
1280 wxDataViewTreeStoreNodeList::compatibility_iterator node = parent_node->GetChildren().Item( pos );
1281 if (node)
1282 return node->GetData();
1283
1284 return wxDataViewItem(0);
1285}
1286
1287int wxDataViewTreeStore::GetChildCount( const wxDataViewItem& parent ) const
1288{
1289 wxDataViewTreeStoreNode *node = FindNode( parent );
1290 if (!node) return -1;
1291
1292 if (!node->IsContainer())
1293 return 0;
1294
1295 wxDataViewTreeStoreContainerNode *container_node = (wxDataViewTreeStoreContainerNode*) node;
1296 return (int) container_node->GetChildren().GetCount();
1297}
1298
1299void wxDataViewTreeStore::SetItemText( const wxDataViewItem& item, const wxString &text )
1300{
1301 wxDataViewTreeStoreNode *node = FindNode( item );
1302 if (!node) return;
1303
1304 node->SetText( text );
1305
1306 // notify control
1307 ValueChanged( item, 0 );
1308}
1309
1310wxString wxDataViewTreeStore::GetItemText( const wxDataViewItem& item ) const
1311{
1312 wxDataViewTreeStoreNode *node = FindNode( item );
1313 if (!node) return wxEmptyString;
1314
1315 return node->GetText();
1316}
1317
1318void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem& item, const wxIcon &icon )
1319{
1320 wxDataViewTreeStoreNode *node = FindNode( item );
1321 if (!node) return;
1322
1323 node->SetIcon( icon );
1324
1325 // notify control
1326 ValueChanged( item, 0 );
1327}
1328
1329const wxIcon &wxDataViewTreeStore::GetItemIcon( const wxDataViewItem& item ) const
1330{
1331 wxDataViewTreeStoreNode *node = FindNode( item );
1332 if (!node) return wxNullIcon;
1333
1334 return node->GetIcon();
1335}
1336
1337void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon )
1338{
1339 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1340 if (!node) return;
1341
1342 node->SetExpandedIcon( icon );
1343
1344 // notify control
1345 ValueChanged( item, 0 );
1346}
1347
1348const wxIcon &wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem& item ) const
1349{
1350 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1351 if (!node) return wxNullIcon;
1352
1353 return node->GetExpandedIcon();
1354}
1355
1356void wxDataViewTreeStore::SetItemData( const wxDataViewItem& item, wxClientData *data )
1357{
1358 wxDataViewTreeStoreNode *node = FindNode( item );
1359 if (!node) return;
1360
1361 node->SetData( data );
1362
1363 // notify control? only sensible when sorting on client data
1364 // ValueChanged( item, 0 );
1365}
1366
1367wxClientData *wxDataViewTreeStore::GetItemData( const wxDataViewItem& item ) const
1368{
1369 wxDataViewTreeStoreNode *node = FindNode( item );
1370 if (!node) return NULL;
1371
1372 return node->GetData();
1373}
1374
1375void wxDataViewTreeStore::DeleteItem( const wxDataViewItem& item )
1376{
1377 if (!item.IsOk()) return;
1378
1379 wxDataViewItem parent_item = GetParent( item );
1380
1381 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent_item );
1382 if (!parent_node) return;
1383
1384 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1385 if (!node) return;
1386
1387 parent_node->GetChildren().DeleteObject( node );
1388
1389 // notify control
1390 ItemDeleted( parent_item, item );
1391}
1392
1393void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem& item )
1394{
1395 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1396 if (!node) return;
1397
1398 wxDataViewItemArray array;
1399 wxDataViewTreeStoreNodeList::iterator iter;
1400 for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++)
1401 {
1402 wxDataViewTreeStoreNode* child = *iter;
1403 array.Add( child->GetItem() );
1404 }
1405
1406 node->GetChildren().clear();
1407
1408 // notify control
1409 ItemsDeleted( item, array );
1410}
1411
1412void wxDataViewTreeStore::DeleteAllItems()
1413{
1414 // TODO
1415}
1416
1417void
1418wxDataViewTreeStore::GetValue(wxVariant &variant,
1419 const wxDataViewItem &item,
1420 unsigned int WXUNUSED(col)) const
1421{
1422 // if (col != 0) return;
1423
1424 wxDataViewTreeStoreNode *node = FindNode( item );
1425 if (!node) return;
1426
1427 wxDataViewIconText data( node->GetText(), node->GetIcon() );
1428
1429 variant << data;
1430}
1431
1432bool
1433wxDataViewTreeStore::SetValue(const wxVariant& variant,
1434 const wxDataViewItem& item,
1435 unsigned int WXUNUSED(col))
1436{
1437 // if (col != 0) return false;
1438
1439 wxDataViewTreeStoreNode *node = FindNode( item );
1440 if (!node) return false;
1441
1442 wxDataViewIconText data;
1443
1444 data << variant;
1445
1446 node->SetText( data.GetText() );
1447 node->SetIcon( data.GetIcon() );
1448
1449 return true;
1450}
1451
1452wxDataViewItem wxDataViewTreeStore::GetParent( const wxDataViewItem &item ) const
1453{
1454 wxDataViewTreeStoreNode *node = FindNode( item );
1455 if (!node) return wxDataViewItem(0);
1456
1457 wxDataViewTreeStoreNode *parent = node->GetParent();
1458 if (!parent) return wxDataViewItem(0);
1459
1460 if (parent == m_root)
1461 return wxDataViewItem(0);
1462
1463 return parent->GetItem();
1464}
1465
1466bool wxDataViewTreeStore::IsContainer( const wxDataViewItem &item ) const
1467{
1468 wxDataViewTreeStoreNode *node = FindNode( item );
1469 if (!node) return false;
1470
1471 return node->IsContainer();
1472}
1473
1474unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const
1475{
1476 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1477 if (!node) return 0;
1478
1479 wxDataViewTreeStoreNodeList::iterator iter;
1480 for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++)
1481 {
1482 wxDataViewTreeStoreNode* child = *iter;
1483 children.Add( child->GetItem() );
1484 }
1485
1486 return node->GetChildren().GetCount();
1487}
1488
1489int wxDataViewTreeStore::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
1490 unsigned int WXUNUSED(column), bool WXUNUSED(ascending) )
1491{
1492 wxDataViewTreeStoreNode *node1 = FindNode( item1 );
1493 wxDataViewTreeStoreNode *node2 = FindNode( item2 );
1494
1495 if (!node1 || !node2)
1496 return 0;
1497
1498 wxDataViewTreeStoreContainerNode* parent1 =
1499 (wxDataViewTreeStoreContainerNode*) node1->GetParent();
1500 wxDataViewTreeStoreContainerNode* parent2 =
1501 (wxDataViewTreeStoreContainerNode*) node2->GetParent();
1502
1503 if (parent1 != parent2)
1504 {
1505 wxLogError( wxT("Comparing items with different parent.") );
1506 return 0;
1507 }
1508
1509 if (node1->IsContainer() && !!node2->IsContainer())
1510 return 1;
1511
1512 if (node2->IsContainer() && !!node1->IsContainer())
1513 return -1;
1514
1515 return parent1->GetChildren().IndexOf( node1 ) - parent1->GetChildren().IndexOf( node2 );
1516}
1517
1518wxDataViewTreeStoreNode *wxDataViewTreeStore::FindNode( const wxDataViewItem &item ) const
1519{
1520 if (!item.IsOk())
1521 return m_root;
1522
1523 return (wxDataViewTreeStoreNode*) item.GetID();
1524}
1525
1526wxDataViewTreeStoreContainerNode *wxDataViewTreeStore::FindContainerNode( const wxDataViewItem &item ) const
1527{
1528 if (!item.IsOk())
1529 return (wxDataViewTreeStoreContainerNode*) m_root;
1530
1531 wxDataViewTreeStoreNode* node = (wxDataViewTreeStoreNode*) item.GetID();
1532
1533 if (!node->IsContainer())
1534 return NULL;
1535
1536 return (wxDataViewTreeStoreContainerNode*) node;
1537}
1538
1539#endif // wxUSE_DATAVIEWCTRL
1540