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