]> git.saurik.com Git - wxWidgets.git/blob - src/common/datavcmn.cpp
cleanup
[wxWidgets.git] / src / common / datavcmn.cpp
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
32 const wxChar wxDataViewCtrlNameStr[] = wxT("dataviewCtrl");
33
34
35 bool operator == (const wxDataViewItem &left, const wxDataViewItem &right)
36 {
37 return (left.GetID() == right.GetID() );
38 }
39
40 #ifdef __WXDEBUG__
41 void 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"
52 WX_DEFINE_LIST(wxDataViewModelNotifiers)
53
54 bool 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
64 bool 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
74 bool 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
88 wxDataViewModel::wxDataViewModel()
89 {
90 m_notifiers.DeleteContents( true );
91 }
92
93 bool 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
108 bool 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
123 bool 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
138 bool 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
153 bool 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
168 bool 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
183 bool 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
198 bool 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
213 void 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
223 void wxDataViewModel::AddNotifier( wxDataViewModelNotifier *notifier )
224 {
225 m_notifiers.push_back( notifier );
226 notifier->SetOwner( this );
227 }
228
229 void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier *notifier )
230 {
231 m_notifiers.DeleteObject( notifier );
232 }
233
234 int 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
300 wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size )
301 {
302 m_ordered = true;
303
304 // build initial index
305 unsigned int i;
306 for (i = 1; i < initial_size+1; i++)
307 m_hash.Add( (void*) i );
308 m_lastIndex = initial_size + 1;
309 }
310
311 wxDataViewIndexListModel::~wxDataViewIndexListModel()
312 {
313 }
314
315 void wxDataViewIndexListModel::RowPrepended()
316 {
317 m_ordered = false;
318
319 unsigned int id = m_lastIndex++;
320 m_hash.Insert( (void*) id, 0 );
321 wxDataViewItem item( (void*) id );
322 ItemAdded( wxDataViewItem(0), item );
323 }
324
325 void wxDataViewIndexListModel::RowInserted( unsigned int before )
326 {
327 m_ordered = false;
328
329 unsigned int id = m_lastIndex++;
330 m_hash.Insert( (void*) id, before );
331 wxDataViewItem item( (void*) id );
332 ItemAdded( wxDataViewItem(0), item );
333 }
334
335 void wxDataViewIndexListModel::RowAppended()
336 {
337 unsigned int id = m_lastIndex++;
338 m_hash.Add( (void*) id );
339 wxDataViewItem item( (void*) id );
340 ItemAdded( wxDataViewItem(0), item );
341 }
342
343 void wxDataViewIndexListModel::RowDeleted( unsigned int row )
344 {
345 wxDataViewItem item( m_hash[row] );
346 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
347 m_hash.RemoveAt( row );
348 }
349
350 void wxDataViewIndexListModel::RowChanged( unsigned int row )
351 {
352 wxDataViewModel::ItemChanged( GetItem(row) );
353 }
354
355 void wxDataViewIndexListModel::RowValueChanged( unsigned int row, unsigned int col )
356 {
357 wxDataViewModel::ValueChanged( GetItem(row), col );
358 }
359
360 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) const
361 {
362 if (m_ordered)
363 {
364 unsigned int pos = wxPtrToUInt(item.GetID());
365 return pos-1;
366 }
367
368 // assert for not found
369 return (unsigned int) m_hash.Index( item.GetID() );
370 }
371
372 wxDataViewItem wxDataViewIndexListModel::GetItem( unsigned int row ) const
373 {
374 wxASSERT( row < m_hash.GetCount() );
375 return wxDataViewItem( m_hash[row] );
376 }
377
378 bool wxDataViewIndexListModel::HasDefaultCompare() const
379 {
380 return !m_ordered;
381 }
382
383 int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1,
384 const wxDataViewItem& item2,
385 unsigned int WXUNUSED(column),
386 bool ascending)
387 {
388 if (m_ordered)
389 {
390 unsigned int pos1 = wxPtrToUInt(item1.GetID());
391 unsigned int pos2 = wxPtrToUInt(item2.GetID());
392
393 if (ascending)
394 return pos1 - pos2;
395 else
396 return pos2 - pos1;
397 }
398
399 if (ascending)
400 return GetRow(item1) - GetRow(item2);
401
402 return GetRow(item2) - GetRow(item1);
403 }
404
405 void wxDataViewIndexListModel::GetValue( wxVariant &variant,
406 const wxDataViewItem &item, unsigned int col ) const
407 {
408 GetValue( variant, GetRow(item), col );
409 }
410
411 bool wxDataViewIndexListModel::SetValue( const wxVariant &variant,
412 const wxDataViewItem &item, unsigned int col )
413 {
414 return SetValue( variant, GetRow(item), col );
415 }
416
417 bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr )
418 {
419 return GetAttr( GetRow(item), col, attr );
420 }
421
422 wxDataViewItem wxDataViewIndexListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const
423 {
424 return wxDataViewItem(0);
425 }
426
427 bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem &item ) const
428 {
429 // only the invisible root item has children
430 if (!item.IsOk())
431 return true;
432
433 return false;
434 }
435
436 unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const
437 {
438 if (item.IsOk())
439 return 0;
440
441 children = m_hash;
442
443 return m_hash.GetCount();
444 }
445
446 //-----------------------------------------------------------------------------
447 // wxDataViewIconText
448 //-----------------------------------------------------------------------------
449
450 IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText,wxObject)
451
452 IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV)
453
454 bool operator == (const wxDataViewIconText &one, const wxDataViewIconText &two)
455 {
456 if (one.GetText() != two.GetText()) return false;
457 if (one.IsSameAs(two)) return false;
458 return true;
459 }
460
461 // ---------------------------------------------------------
462 // wxDataViewRendererBase
463 // ---------------------------------------------------------
464
465 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase, wxObject)
466
467 wxDataViewRendererBase::wxDataViewRendererBase( const wxString &varianttype,
468 wxDataViewCellMode WXUNUSED(mode),
469 int WXUNUSED(align) )
470 {
471 m_variantType = varianttype;
472 m_editorCtrl = NULL;
473 }
474
475 const wxDataViewCtrl* wxDataViewRendererBase::GetView() const
476 {
477 return wx_const_cast(wxDataViewRendererBase*, this)->GetOwner()->GetOwner();
478 }
479
480 bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect )
481 {
482 m_item = item; // remember for later
483
484 unsigned int col = GetOwner()->GetModelColumn();
485 wxVariant value;
486 GetOwner()->GetOwner()->GetModel()->GetValue( value, item, col );
487
488 m_editorCtrl = CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect, value );
489
490 wxDataViewEditorCtrlEvtHandler *handler =
491 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl, (wxDataViewRenderer*) this );
492
493 m_editorCtrl->PushEventHandler( handler );
494
495 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
496 handler->SetFocusOnIdle();
497 #else
498 m_editorCtrl->SetFocus();
499 #endif
500
501 // Now we should send Editing Started event
502 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, GetOwner()->GetOwner()->GetId() );
503 event.SetDataViewColumn( GetOwner() );
504 event.SetModel( GetOwner()->GetOwner()->GetModel() );
505 event.SetItem( item );
506 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event );
507
508 return true;
509 }
510
511 void wxDataViewRendererBase::CancelEditing()
512 {
513 wxPendingDelete.Append( m_editorCtrl );
514
515 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
516
517 // m_editorCtrl->PopEventHandler( true );
518 }
519
520 bool wxDataViewRendererBase::FinishEditing()
521 {
522 wxVariant value;
523 GetValueFromEditorCtrl( m_editorCtrl, value );
524
525 wxPendingDelete.Append( m_editorCtrl );
526
527 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
528
529 if (!Validate(value))
530 return false;
531
532 unsigned int col = GetOwner()->GetModelColumn();
533 GetOwner()->GetOwner()->GetModel()->SetValue( value, m_item, col );
534 GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item, col );
535
536 // m_editorCtrl->PopEventHandler( true );
537
538 // Now we should send Editing Done event
539 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, GetOwner()->GetOwner()->GetId() );
540 event.SetDataViewColumn( GetOwner() );
541 event.SetModel( GetOwner()->GetOwner()->GetModel() );
542 event.SetItem( m_item );
543 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event );
544
545 return true;
546 }
547
548 //-----------------------------------------------------------------------------
549 // wxDataViewEditorCtrlEvtHandler
550 //-----------------------------------------------------------------------------
551
552 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler, wxEvtHandler)
553 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar)
554 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus)
555 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle)
556 END_EVENT_TABLE()
557
558 wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
559 wxControl *editorCtrl,
560 wxDataViewRenderer *owner )
561 {
562 m_owner = owner;
563 m_editorCtrl = editorCtrl;
564
565 m_finished = false;
566 }
567
568 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent &event )
569 {
570 if (m_focusOnIdle)
571 {
572 m_focusOnIdle = false;
573 if (wxWindow::FindFocus() != m_editorCtrl)
574 m_editorCtrl->SetFocus();
575 }
576
577 event.Skip();
578 }
579
580 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event )
581 {
582 switch ( event.m_keyCode )
583 {
584 case WXK_RETURN:
585 m_finished = true;
586 m_owner->FinishEditing();
587 break;
588
589 case WXK_ESCAPE:
590 m_finished = true;
591 m_owner->CancelEditing();
592 break;
593
594 default:
595 event.Skip();
596 }
597 }
598
599 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event )
600 {
601 if (!m_finished)
602 {
603 m_finished = true;
604 m_owner->FinishEditing();
605 }
606
607 event.Skip();
608 }
609
610 // ---------------------------------------------------------
611 // wxDataViewColumnBase
612 // ---------------------------------------------------------
613
614 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase, wxObject)
615
616 wxDataViewColumnBase::wxDataViewColumnBase(const wxString& WXUNUSED(title),
617 wxDataViewRenderer *renderer,
618 unsigned int model_column,
619 int WXUNUSED(width),
620 wxAlignment WXUNUSED(align),
621 int WXUNUSED(flags))
622 {
623 m_renderer = renderer;
624 m_model_column = model_column;
625 m_owner = NULL;
626 m_renderer->SetOwner( (wxDataViewColumn*) this );
627
628 // NOTE: the wxDataViewColumn's ctor must store the width, align, flags
629 // parameters inside the native control!
630 }
631
632 wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap& bitmap,
633 wxDataViewRenderer *renderer,
634 unsigned int model_column,
635 int WXUNUSED(width),
636 wxAlignment WXUNUSED(align),
637 int WXUNUSED(flags) )
638 {
639 m_renderer = renderer;
640 m_model_column = model_column;
641 m_bitmap = bitmap;
642 m_owner = NULL;
643 m_renderer->SetOwner( (wxDataViewColumn*) this );
644 }
645
646 wxDataViewColumnBase::~wxDataViewColumnBase()
647 {
648 if (m_renderer)
649 delete m_renderer;
650 }
651
652 int wxDataViewColumnBase::GetFlags() const
653 {
654 int ret = 0;
655
656 if (IsSortable())
657 ret |= wxDATAVIEW_COL_SORTABLE;
658 if (IsResizeable())
659 ret |= wxDATAVIEW_COL_RESIZABLE;
660 if (IsHidden())
661 ret |= wxDATAVIEW_COL_HIDDEN;
662
663 return ret;
664 }
665
666 void wxDataViewColumnBase::SetFlags(int flags)
667 {
668 SetSortable((flags & wxDATAVIEW_COL_SORTABLE) != 0);
669 SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0);
670 SetHidden((flags & wxDATAVIEW_COL_HIDDEN) != 0);
671 }
672
673 // ---------------------------------------------------------
674 // wxDataViewCtrlBase
675 // ---------------------------------------------------------
676
677 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl)
678
679 wxDataViewCtrlBase::wxDataViewCtrlBase()
680 {
681 m_model = NULL;
682 m_expander_column = 0;
683 m_indent = 8;
684 }
685
686 wxDataViewCtrlBase::~wxDataViewCtrlBase()
687 {
688 if (m_model)
689 {
690 m_model->DecRef();
691 m_model = NULL;
692 }
693 }
694
695 bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel *model )
696 {
697 if (m_model)
698 {
699 m_model->DecRef(); // discard old model, if any
700 }
701
702 // add our own reference to the new model:
703 m_model = model;
704 if (m_model)
705 {
706 m_model->IncRef();
707 }
708
709 return true;
710 }
711
712 wxDataViewModel* wxDataViewCtrlBase::GetModel()
713 {
714 return m_model;
715 }
716
717 wxDataViewColumn *
718 wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_column,
719 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
720 {
721 wxDataViewColumn *ret = new wxDataViewColumn( label,
722 new wxDataViewTextRenderer( wxT("string"), mode, (int)align ),
723 model_column, width, align, flags );
724 AppendColumn( ret );
725 return ret;
726 }
727
728 wxDataViewColumn *
729 wxDataViewCtrlBase::AppendIconTextColumn( const wxString &label, unsigned int model_column,
730 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
731 {
732 wxDataViewColumn *ret = new wxDataViewColumn( label,
733 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ),
734 model_column, width, align, flags );
735 AppendColumn( ret );
736 return ret;
737 }
738
739 wxDataViewColumn *
740 wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int model_column,
741 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
742 {
743
744 wxDataViewColumn *ret = new wxDataViewColumn( label,
745 new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ),
746 model_column, width, align, flags );
747 AppendColumn( ret );
748 return ret;
749 }
750
751 wxDataViewColumn *
752 wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, unsigned int model_column,
753 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
754 {
755 wxDataViewColumn *ret = new wxDataViewColumn( label,
756 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ),
757 model_column, width, align, flags );
758 AppendColumn( ret );
759 return ret;
760 }
761
762 wxDataViewColumn *
763 wxDataViewCtrlBase::AppendDateColumn( const wxString &label, unsigned int model_column,
764 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
765 {
766 wxDataViewColumn *ret = new wxDataViewColumn( label,
767 new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ),
768 model_column, width, align, flags );
769 AppendColumn( ret );
770 return ret;
771 }
772
773 wxDataViewColumn *
774 wxDataViewCtrlBase::AppendBitmapColumn( const wxString &label, unsigned int model_column,
775 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
776 {
777 wxDataViewColumn *ret = new wxDataViewColumn( label,
778 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ),
779 model_column, width, align, flags );
780 AppendColumn( ret );
781 return ret;
782 }
783
784 wxDataViewColumn *
785 wxDataViewCtrlBase::AppendTextColumn( const wxBitmap &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
795 wxDataViewColumn *
796 wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap &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
806 wxDataViewColumn *
807 wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
808 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
809 {
810 wxDataViewColumn *ret = new wxDataViewColumn( label,
811 new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ),
812 model_column, width, align, flags );
813 AppendColumn( ret );
814 return ret;
815 }
816
817 wxDataViewColumn *
818 wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
819 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
820 {
821 wxDataViewColumn *ret = new wxDataViewColumn( label,
822 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ),
823 model_column, width, align, flags );
824 AppendColumn( ret );
825 return ret;
826 }
827
828 wxDataViewColumn *
829 wxDataViewCtrlBase::AppendDateColumn( const wxBitmap &label, unsigned int model_column,
830 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
831 {
832 wxDataViewColumn *ret = new wxDataViewColumn( label,
833 new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ),
834 model_column, width, align, flags );
835 AppendColumn( ret );
836 return ret;
837 }
838
839 wxDataViewColumn *
840 wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
841 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
842 {
843 wxDataViewColumn *ret = new wxDataViewColumn( label,
844 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ),
845 model_column, width, align, flags );
846 AppendColumn( ret );
847 return ret;
848 }
849
850 wxDataViewColumn *
851 wxDataViewCtrlBase::PrependTextColumn( const wxString &label, unsigned int model_column,
852 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
853 {
854 wxDataViewColumn *ret = new wxDataViewColumn( label,
855 new wxDataViewTextRenderer( wxT("string"), mode, (int)align ),
856 model_column, width, align, flags );
857 PrependColumn( ret );
858 return ret;
859 }
860
861 wxDataViewColumn *
862 wxDataViewCtrlBase::PrependIconTextColumn( const wxString &label, unsigned int model_column,
863 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
864 {
865 wxDataViewColumn *ret = new wxDataViewColumn( label,
866 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ),
867 model_column, width, align, flags );
868 PrependColumn( ret );
869 return ret;
870 }
871
872 wxDataViewColumn *
873 wxDataViewCtrlBase::PrependToggleColumn( const wxString &label, unsigned int model_column,
874 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
875 {
876
877 wxDataViewColumn *ret = new wxDataViewColumn( label,
878 new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ),
879 model_column, width, align, flags );
880 PrependColumn( ret );
881 return ret;
882 }
883
884 wxDataViewColumn *
885 wxDataViewCtrlBase::PrependProgressColumn( const wxString &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 PrependColumn( ret );
892 return ret;
893 }
894
895 wxDataViewColumn *
896 wxDataViewCtrlBase::PrependDateColumn( const wxString &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 PrependColumn( ret );
903 return ret;
904 }
905
906 wxDataViewColumn *
907 wxDataViewCtrlBase::PrependBitmapColumn( const wxString &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 PrependColumn( ret );
914 return ret;
915 }
916
917 wxDataViewColumn *
918 wxDataViewCtrlBase::PrependTextColumn( const wxBitmap &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
928 wxDataViewColumn *
929 wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap &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
939 wxDataViewColumn *
940 wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap &label, unsigned int model_column,
941 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
942 {
943 wxDataViewColumn *ret = new wxDataViewColumn( label,
944 new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ),
945 model_column, width, align, flags );
946 PrependColumn( ret );
947 return ret;
948 }
949
950 wxDataViewColumn *
951 wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap &label, unsigned int model_column,
952 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
953 {
954 wxDataViewColumn *ret = new wxDataViewColumn( label,
955 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ),
956 model_column, width, align, flags );
957 PrependColumn( ret );
958 return ret;
959 }
960
961 wxDataViewColumn *
962 wxDataViewCtrlBase::PrependDateColumn( const wxBitmap &label, unsigned int model_column,
963 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
964 {
965 wxDataViewColumn *ret = new wxDataViewColumn( label,
966 new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ),
967 model_column, width, align, flags );
968 PrependColumn( ret );
969 return ret;
970 }
971
972 wxDataViewColumn *
973 wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap &label, unsigned int model_column,
974 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
975 {
976 wxDataViewColumn *ret = new wxDataViewColumn( label,
977 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ),
978 model_column, width, align, flags );
979 PrependColumn( ret );
980 return ret;
981 }
982
983 bool
984 wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col )
985 {
986 col->SetOwner( (wxDataViewCtrl*) this );
987 return true;
988 }
989
990 bool
991 wxDataViewCtrlBase::PrependColumn( wxDataViewColumn *col )
992 {
993 col->SetOwner( (wxDataViewCtrl*) this );
994 return true;
995 }
996
997 // ---------------------------------------------------------
998 // wxDataViewEvent
999 // ---------------------------------------------------------
1000
1001 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent)
1002
1003 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED)
1004
1005 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED)
1006 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING)
1007 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED)
1008 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING)
1009 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED)
1010 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED)
1011 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE)
1012 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED)
1013
1014 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK)
1015 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK)
1016 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED)
1017
1018
1019 // -------------------------------------
1020 // wxDataViewSpinRenderer
1021 // -------------------------------------
1022
1023 wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min, int max, wxDataViewCellMode mode, int alignment ) :
1024 wxDataViewCustomRenderer( "long", mode, alignment )
1025 {
1026 m_min = min;
1027 m_max = max;
1028 }
1029
1030 wxControl* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
1031 {
1032 long l = value;
1033 return new wxSpinCtrl( parent, wxID_ANY, wxEmptyString,
1034 labelRect.GetTopLeft(), labelRect.GetSize(), wxSP_ARROW_KEYS, m_min, m_max, l );
1035 }
1036
1037 bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value )
1038 {
1039 wxSpinCtrl *sc = (wxSpinCtrl*) editor;
1040 long l = sc->GetValue();
1041 value = l;
1042 return true;
1043 }
1044
1045 bool wxDataViewSpinRenderer::Render( wxRect rect, wxDC *dc, int state )
1046 {
1047 wxString str;
1048 str.Printf( "%d", (int) m_data );
1049 RenderText( str, 0, rect, dc, state );
1050 return true;
1051 }
1052
1053 wxSize wxDataViewSpinRenderer::GetSize() const
1054 {
1055 return wxSize(80,16);
1056 }
1057
1058 bool wxDataViewSpinRenderer::SetValue( const wxVariant &value )
1059 {
1060 m_data = value.GetLong();
1061 return true;
1062 }
1063
1064 bool wxDataViewSpinRenderer::GetValue( wxVariant &value ) const
1065 {
1066 value = m_data;
1067 return true;
1068 }
1069
1070 //-----------------------------------------------------------------------------
1071 // wxDataViewTreeStore
1072 //-----------------------------------------------------------------------------
1073
1074 wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1075 wxDataViewTreeStoreNode *parent,
1076 const wxString &text, const wxIcon &icon, wxClientData *data )
1077 {
1078 m_parent = parent;
1079 m_text = text;
1080 m_icon = icon;
1081 m_data = data;
1082 }
1083
1084 wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1085 {
1086 if (m_data)
1087 delete m_data;
1088 }
1089
1090 #include "wx/listimpl.cpp"
1091 WX_DEFINE_LIST(wxDataViewTreeStoreNodeList)
1092
1093 wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1094 wxDataViewTreeStoreNode *parent, const wxString &text,
1095 const wxIcon &icon, const wxIcon &expanded, wxClientData *data ) :
1096 wxDataViewTreeStoreNode( parent, text, icon, data )
1097 {
1098 m_iconExpanded = expanded;
1099 m_children.DeleteContents(true);
1100 }
1101
1102 wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1103 {
1104 }
1105
1106 //-----------------------------------------------------------------------------
1107
1108 wxDataViewTreeStore::wxDataViewTreeStore()
1109 {
1110 m_root = new wxDataViewTreeStoreContainerNode( NULL, wxEmptyString );
1111 }
1112
1113 wxDataViewTreeStore::~wxDataViewTreeStore()
1114 {
1115 delete m_root;
1116 }
1117
1118 wxDataViewItem wxDataViewTreeStore::AppendItem( const wxDataViewItem& parent,
1119 const wxString &text, const wxIcon &icon, wxClientData *data )
1120 {
1121 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1122 if (!parent_node) return wxDataViewItem(0);
1123
1124 wxDataViewTreeStoreNode *node =
1125 new wxDataViewTreeStoreNode( parent_node, text, icon, data );
1126 parent_node->GetChildren().Append( node );
1127
1128 // notify control
1129 ItemAdded( parent, node->GetItem() );
1130
1131 return node->GetItem();
1132 }
1133
1134 wxDataViewItem wxDataViewTreeStore::PrependItem( const wxDataViewItem& parent,
1135 const wxString &text, const wxIcon &icon, wxClientData *data )
1136 {
1137 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1138 if (!parent_node) return wxDataViewItem(0);
1139
1140 wxDataViewTreeStoreNode *node =
1141 new wxDataViewTreeStoreNode( parent_node, text, icon, data );
1142 parent_node->GetChildren().Insert( node );
1143
1144 // notify control
1145 ItemAdded( parent, node->GetItem() );
1146
1147 return node->GetItem();
1148 }
1149
1150 wxDataViewItem
1151 wxDataViewTreeStore::InsertItem(const wxDataViewItem& WXUNUSED(parent),
1152 const wxDataViewItem& WXUNUSED(previous),
1153 const wxString& WXUNUSED(text),
1154 const wxIcon& WXUNUSED(icon),
1155 wxClientData * WXUNUSED(data))
1156 {
1157 return wxDataViewItem(0);
1158 }
1159
1160 wxDataViewItem wxDataViewTreeStore::PrependContainer( const wxDataViewItem& parent,
1161 const wxString &text, const wxIcon &icon, const wxIcon &expanded,
1162 wxClientData *data )
1163 {
1164 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1165 if (!parent_node) return wxDataViewItem(0);
1166
1167 wxDataViewTreeStoreContainerNode *node =
1168 new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
1169 parent_node->GetChildren().Insert( node );
1170
1171 // notify control
1172 ItemAdded( parent, node->GetItem() );
1173
1174 return node->GetItem();
1175 }
1176
1177 wxDataViewItem
1178 wxDataViewTreeStore::AppendContainer(const wxDataViewItem& parent,
1179 const wxString &text,
1180 const wxIcon& icon,
1181 const wxIcon& expanded,
1182 wxClientData * data)
1183 {
1184 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1185 if (!parent_node) return wxDataViewItem(0);
1186
1187 wxDataViewTreeStoreContainerNode *node =
1188 new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
1189 parent_node->GetChildren().Append( node );
1190
1191 // notify control
1192 ItemAdded( parent, node->GetItem() );
1193
1194 return node->GetItem();
1195 }
1196
1197 wxDataViewItem
1198 wxDataViewTreeStore::InsertContainer(const wxDataViewItem& WXUNUSED(parent),
1199 const wxDataViewItem& WXUNUSED(previous),
1200 const wxString& WXUNUSED(text),
1201 const wxIcon& WXUNUSED(icon),
1202 const wxIcon& WXUNUSED(expanded),
1203 wxClientData * WXUNUSED(data))
1204 {
1205 return wxDataViewItem(0);
1206 }
1207
1208 wxDataViewItem wxDataViewTreeStore::GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const
1209 {
1210 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1211 if (!parent_node) return wxDataViewItem(0);
1212
1213 wxDataViewTreeStoreNodeList::compatibility_iterator node = parent_node->GetChildren().Item( pos );
1214 if (node)
1215 return node->GetData();
1216
1217 return wxDataViewItem(0);
1218 }
1219
1220 int wxDataViewTreeStore::GetChildCount( const wxDataViewItem& parent ) const
1221 {
1222 wxDataViewTreeStoreNode *node = FindNode( parent );
1223 if (!node) return -1;
1224
1225 if (!node->IsContainer())
1226 return 0;
1227
1228 wxDataViewTreeStoreContainerNode *container_node = (wxDataViewTreeStoreContainerNode*) node;
1229 return (int) container_node->GetChildren().GetCount();
1230 }
1231
1232 void wxDataViewTreeStore::SetItemText( const wxDataViewItem& item, const wxString &text )
1233 {
1234 wxDataViewTreeStoreNode *node = FindNode( item );
1235 if (!node) return;
1236
1237 node->SetText( text );
1238
1239 // notify control
1240 ValueChanged( item, 0 );
1241 }
1242
1243 wxString wxDataViewTreeStore::GetItemText( const wxDataViewItem& item ) const
1244 {
1245 wxDataViewTreeStoreNode *node = FindNode( item );
1246 if (!node) return wxEmptyString;
1247
1248 return node->GetText();
1249 }
1250
1251 void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem& item, const wxIcon &icon )
1252 {
1253 wxDataViewTreeStoreNode *node = FindNode( item );
1254 if (!node) return;
1255
1256 node->SetIcon( icon );
1257
1258 // notify control
1259 ValueChanged( item, 0 );
1260 }
1261
1262 const wxIcon &wxDataViewTreeStore::GetItemIcon( const wxDataViewItem& item ) const
1263 {
1264 wxDataViewTreeStoreNode *node = FindNode( item );
1265 if (!node) return wxNullIcon;
1266
1267 return node->GetIcon();
1268 }
1269
1270 void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon )
1271 {
1272 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1273 if (!node) return;
1274
1275 node->SetExpandedIcon( icon );
1276
1277 // notify control
1278 ValueChanged( item, 0 );
1279 }
1280
1281 const wxIcon &wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem& item ) const
1282 {
1283 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1284 if (!node) return wxNullIcon;
1285
1286 return node->GetExpandedIcon();
1287 }
1288
1289 void wxDataViewTreeStore::SetItemData( const wxDataViewItem& item, wxClientData *data )
1290 {
1291 wxDataViewTreeStoreNode *node = FindNode( item );
1292 if (!node) return;
1293
1294 node->SetData( data );
1295
1296 // notify control? only sensible when sorting on client data
1297 // ValueChanged( item, 0 );
1298 }
1299
1300 wxClientData *wxDataViewTreeStore::GetItemData( const wxDataViewItem& item ) const
1301 {
1302 wxDataViewTreeStoreNode *node = FindNode( item );
1303 if (!node) return NULL;
1304
1305 return node->GetData();
1306 }
1307
1308 void wxDataViewTreeStore::DeleteItem( const wxDataViewItem& item )
1309 {
1310 if (!item.IsOk()) return;
1311
1312 wxDataViewItem parent_item = GetParent( item );
1313
1314 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent_item );
1315 if (!parent_node) return;
1316
1317 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1318 if (!node) return;
1319
1320 parent_node->GetChildren().DeleteObject( node );
1321
1322 // notify control
1323 ItemDeleted( parent_item, item );
1324 }
1325
1326 void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem& item )
1327 {
1328 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1329 if (!node) return;
1330
1331 wxDataViewItemArray array;
1332 wxDataViewTreeStoreNodeList::iterator iter;
1333 for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++)
1334 {
1335 wxDataViewTreeStoreNode* child = *iter;
1336 array.Add( child->GetItem() );
1337 }
1338
1339 node->GetChildren().clear();
1340
1341 // notify control
1342 ItemsDeleted( item, array );
1343 }
1344
1345 void wxDataViewTreeStore::DeleteAllItems()
1346 {
1347 // TODO
1348 }
1349
1350 void
1351 wxDataViewTreeStore::GetValue(wxVariant &variant,
1352 const wxDataViewItem &item,
1353 unsigned int WXUNUSED(col)) const
1354 {
1355 // if (col != 0) return;
1356
1357 wxDataViewTreeStoreNode *node = FindNode( item );
1358 if (!node) return;
1359
1360 wxDataViewIconText data( node->GetText(), node->GetIcon() );
1361
1362 variant << data;
1363 }
1364
1365 bool
1366 wxDataViewTreeStore::SetValue(const wxVariant& variant,
1367 const wxDataViewItem& item,
1368 unsigned int WXUNUSED(col))
1369 {
1370 // if (col != 0) return false;
1371
1372 wxDataViewTreeStoreNode *node = FindNode( item );
1373 if (!node) return false;
1374
1375 wxDataViewIconText data;
1376
1377 data << variant;
1378
1379 node->SetText( data.GetText() );
1380 node->SetIcon( data.GetIcon() );
1381
1382 return true;
1383 }
1384
1385 wxDataViewItem wxDataViewTreeStore::GetParent( const wxDataViewItem &item ) const
1386 {
1387 wxDataViewTreeStoreNode *node = FindNode( item );
1388 if (!node) return wxDataViewItem(0);
1389
1390 wxDataViewTreeStoreNode *parent = node->GetParent();
1391 if (!parent) return wxDataViewItem(0);
1392
1393 if (parent == m_root)
1394 return wxDataViewItem(0);
1395
1396 return parent->GetItem();
1397 }
1398
1399 bool wxDataViewTreeStore::IsContainer( const wxDataViewItem &item ) const
1400 {
1401 wxDataViewTreeStoreNode *node = FindNode( item );
1402 if (!node) return false;
1403
1404 return node->IsContainer();
1405 }
1406
1407 unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const
1408 {
1409 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1410 if (!node) return 0;
1411
1412 wxDataViewTreeStoreNodeList::iterator iter;
1413 for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++)
1414 {
1415 wxDataViewTreeStoreNode* child = *iter;
1416 children.Add( child->GetItem() );
1417 }
1418
1419 return node->GetChildren().GetCount();
1420 }
1421
1422 int wxDataViewTreeStore::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
1423 unsigned int WXUNUSED(column), bool WXUNUSED(ascending) )
1424 {
1425 wxDataViewTreeStoreNode *node1 = FindNode( item1 );
1426 wxDataViewTreeStoreNode *node2 = FindNode( item2 );
1427
1428 if (!node1 || !node2)
1429 return 0;
1430
1431 wxDataViewTreeStoreContainerNode* parent1 =
1432 (wxDataViewTreeStoreContainerNode*) node1->GetParent();
1433 wxDataViewTreeStoreContainerNode* parent2 =
1434 (wxDataViewTreeStoreContainerNode*) node2->GetParent();
1435
1436 if (parent1 != parent2)
1437 {
1438 wxLogError( wxT("Comparing items with different parent.") );
1439 return 0;
1440 }
1441
1442 if (node1->IsContainer() && !!node2->IsContainer())
1443 return 1;
1444
1445 if (node2->IsContainer() && !!node1->IsContainer())
1446 return -1;
1447
1448 return parent1->GetChildren().IndexOf( node1 ) - parent1->GetChildren().IndexOf( node2 );
1449 }
1450
1451 wxDataViewTreeStoreNode *wxDataViewTreeStore::FindNode( const wxDataViewItem &item ) const
1452 {
1453 if (!item.IsOk())
1454 return m_root;
1455
1456 return (wxDataViewTreeStoreNode*) item.GetID();
1457 }
1458
1459 wxDataViewTreeStoreContainerNode *wxDataViewTreeStore::FindContainerNode( const wxDataViewItem &item ) const
1460 {
1461 if (!item.IsOk())
1462 return (wxDataViewTreeStoreContainerNode*) m_root;
1463
1464 wxDataViewTreeStoreNode* node = (wxDataViewTreeStoreNode*) item.GetID();
1465
1466 if (!node->IsContainer())
1467 return NULL;
1468
1469 return (wxDataViewTreeStoreContainerNode*) node;
1470 }
1471
1472 #endif // wxUSE_DATAVIEWCTRL
1473