]> git.saurik.com Git - wxWidgets.git/blame - src/common/datavcmn.cpp
fix some unused variables warnings reported by Borland
[wxWidgets.git] / src / common / datavcmn.cpp
CommitLineData
239eaa41
RR
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
8045736e
RR
18#if wxUSE_DATAVIEWCTRL
19
e7445ff8 20#include "wx/dataview.h"
52e750fc 21#include "wx/spinctrl.h"
52e750fc 22
c232dfe5
RR
23#include "wx/weakref.h"
24
f554a14b 25#ifndef WX_PRECOMP
c3c62822
PC
26 #include "wx/dc.h"
27 #include "wx/settings.h"
f554a14b 28 #include "wx/log.h"
e94d0c1e 29 #include "wx/icon.h"
c3c62822 30 #include "wx/crt.h"
f554a14b
WS
31#endif
32
4a2e5ee8 33const wxChar wxDataViewCtrlNameStr[] = wxT("dataviewCtrl");
239eaa41 34
239eaa41 35
d5025dc0
RR
36bool operator == (const wxDataViewItem &left, const wxDataViewItem &right)
37{
38 return (left.GetID() == right.GetID() );
39}
40
c3c62822
PC
41#ifdef __WXDEBUG__
42void wxDataViewItem::Print(const wxString& text) const
43{
99c75ebc 44 wxPrintf(wxT("item %s: %l\n"), text.GetData(), (long)m_id);
c3c62822
PC
45}
46#endif
d5025dc0 47
f554a14b 48// ---------------------------------------------------------
854cdb09 49// wxDataViewModelNotifier
f554a14b 50// ---------------------------------------------------------
239eaa41 51
8ab03001 52#include "wx/listimpl.cpp"
a76c2f37 53WX_DEFINE_LIST(wxDataViewModelNotifiers)
9d8fe14a 54
854cdb09
RR
55bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items )
56{
57 size_t count = items.GetCount();
58 size_t i;
59 for (i = 0; i < count; i++)
60 if (!ItemAdded( parent, items[i] )) return false;
b5ec7dd6 61
854cdb09
RR
62 return true;
63}
64
65bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items )
66{
67 size_t count = items.GetCount();
68 size_t i;
69 for (i = 0; i < count; i++)
70 if (!ItemDeleted( parent, items[i] )) return false;
b5ec7dd6 71
854cdb09
RR
72 return true;
73}
74
75bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray &items )
76{
77 size_t count = items.GetCount();
78 size_t i;
79 for (i = 0; i < count; i++)
80 if (!ItemChanged( items[i] )) return false;
b5ec7dd6 81
854cdb09
RR
82 return true;
83}
84
85// ---------------------------------------------------------
86// wxDataViewModel
87// ---------------------------------------------------------
88
e0062c04 89wxDataViewModel::wxDataViewModel()
239eaa41 90{
8f850e28 91 m_notifiers.DeleteContents( true );
239eaa41
RR
92}
93
e0062c04 94bool wxDataViewModel::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
239eaa41 95{
8f850e28
RR
96 bool ret = true;
97
9d8fe14a
RR
98 wxDataViewModelNotifiers::iterator iter;
99 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
8f850e28 100 {
9d8fe14a 101 wxDataViewModelNotifier* notifier = *iter;
e0062c04 102 if (!notifier->ItemAdded( parent, item ))
8f850e28 103 ret = false;
8f850e28 104 }
f554a14b 105
8f850e28 106 return ret;
239eaa41
RR
107}
108
469d3e9b 109bool wxDataViewModel::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
239eaa41 110{
8f850e28
RR
111 bool ret = true;
112
9d8fe14a
RR
113 wxDataViewModelNotifiers::iterator iter;
114 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
8f850e28 115 {
9d8fe14a 116 wxDataViewModelNotifier* notifier = *iter;
469d3e9b 117 if (!notifier->ItemDeleted( parent, item ))
8f850e28 118 ret = false;
8f850e28 119 }
f554a14b 120
8f850e28 121 return ret;
239eaa41
RR
122}
123
e0062c04 124bool wxDataViewModel::ItemChanged( const wxDataViewItem &item )
239eaa41 125{
8f850e28
RR
126 bool ret = true;
127
9d8fe14a
RR
128 wxDataViewModelNotifiers::iterator iter;
129 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
8f850e28 130 {
9d8fe14a 131 wxDataViewModelNotifier* notifier = *iter;
e0062c04 132 if (!notifier->ItemChanged( item ))
8f850e28 133 ret = false;
8f850e28 134 }
f554a14b 135
8f850e28 136 return ret;
239eaa41
RR
137}
138
854cdb09
RR
139bool wxDataViewModel::ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items )
140{
141 bool ret = true;
142
143 wxDataViewModelNotifiers::iterator iter;
144 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
145 {
146 wxDataViewModelNotifier* notifier = *iter;
147 if (!notifier->ItemsAdded( parent, items ))
148 ret = false;
149 }
150
151 return ret;
152}
153
154bool wxDataViewModel::ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items )
155{
156 bool ret = true;
157
158 wxDataViewModelNotifiers::iterator iter;
159 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
160 {
161 wxDataViewModelNotifier* notifier = *iter;
162 if (!notifier->ItemsDeleted( parent, items ))
163 ret = false;
164 }
165
166 return ret;
167}
168
169bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray &items )
170{
171 bool ret = true;
172
173 wxDataViewModelNotifiers::iterator iter;
174 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
175 {
176 wxDataViewModelNotifier* notifier = *iter;
177 if (!notifier->ItemsChanged( items ))
178 ret = false;
179 }
180
181 return ret;
182}
183
e0062c04 184bool wxDataViewModel::ValueChanged( const wxDataViewItem &item, unsigned int col )
239eaa41 185{
8f850e28 186 bool ret = true;
b5d777c7 187
9d8fe14a
RR
188 wxDataViewModelNotifiers::iterator iter;
189 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
b5d777c7 190 {
9d8fe14a 191 wxDataViewModelNotifier* notifier = *iter;
e0062c04 192 if (!notifier->ValueChanged( item, col ))
8f850e28 193 ret = false;
b5d777c7 194 }
f554a14b 195
b5d777c7 196 return ret;
239eaa41
RR
197}
198
e0062c04 199bool wxDataViewModel::Cleared()
4eccd3a1
RR
200{
201 bool ret = true;
202
9d8fe14a
RR
203 wxDataViewModelNotifiers::iterator iter;
204 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
4eccd3a1 205 {
9d8fe14a 206 wxDataViewModelNotifier* notifier = *iter;
8f850e28
RR
207 if (!notifier->Cleared())
208 ret = false;
8f850e28 209 }
f554a14b 210
8f850e28 211 return ret;
239eaa41
RR
212}
213
ef427989
RR
214void wxDataViewModel::Resort()
215{
9d8fe14a
RR
216 wxDataViewModelNotifiers::iterator iter;
217 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
ef427989 218 {
9d8fe14a 219 wxDataViewModelNotifier* notifier = *iter;
ef427989 220 notifier->Resort();
ef427989
RR
221 }
222}
223
e0062c04 224void wxDataViewModel::AddNotifier( wxDataViewModelNotifier *notifier )
239eaa41 225{
9d8fe14a 226 m_notifiers.push_back( notifier );
8f850e28 227 notifier->SetOwner( this );
239eaa41
RR
228}
229
e0062c04 230void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier *notifier )
239eaa41 231{
8f850e28 232 m_notifiers.DeleteObject( notifier );
239eaa41
RR
233}
234
7ee7191c
RR
235int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
236 unsigned int column, bool ascending )
ef427989 237{
cf283a47 238 // sort branches before leaves
ed903e42
RR
239 bool item1_is_container = IsContainer(item1);
240 bool item2_is_container = IsContainer(item2);
900af470 241
ed903e42 242 if (item1_is_container && !item2_is_container)
cf283a47 243 return 1;
ed903e42 244 if (item2_is_container && !item1_is_container)
cf283a47 245 return -1;
900af470 246
ef427989 247 wxVariant value1,value2;
7ee7191c
RR
248 GetValue( value1, item1, column );
249 GetValue( value2, item2, column );
250
251 if (!ascending)
252 {
253 wxVariant temp = value1;
254 value1 = value2;
255 value2 = temp;
256 }
cf283a47 257
ef427989
RR
258 if (value1.GetType() == wxT("string"))
259 {
260 wxString str1 = value1.GetString();
261 wxString str2 = value2.GetString();
0be79c8a 262 int res = str1.Cmp( str2 );
cf283a47
RR
263 if (res) return res;
264 } else
ef427989
RR
265 if (value1.GetType() == wxT("long"))
266 {
267 long l1 = value1.GetLong();
268 long l2 = value2.GetLong();
cf283a47
RR
269 long res = l1-l2;
270 if (res) return res;
271 } else
ef427989
RR
272 if (value1.GetType() == wxT("double"))
273 {
274 double d1 = value1.GetDouble();
275 double d2 = value2.GetDouble();
ef427989 276 if (d1 < d2) return 1;
cf283a47
RR
277 if (d1 > d2) return -1;
278 } else
ef427989
RR
279 if (value1.GetType() == wxT("datetime"))
280 {
281 wxDateTime dt1 = value1.GetDateTime();
282 wxDateTime dt2 = value2.GetDateTime();
ef427989 283 if (dt1.IsEarlierThan(dt2)) return 1;
cf283a47 284 if (dt2.IsEarlierThan(dt1)) return -11;
ef427989
RR
285 }
286
cf283a47 287 // items must be different
900af470
JS
288 unsigned long litem1 = (unsigned long) item1.GetID();
289 unsigned long litem2 = (unsigned long) item2.GetID();
b7fe2261 290
7ee7191c
RR
291 if (!ascending)
292 return litem2-litem2;
cf283a47 293
cf283a47 294 return litem1-litem2;
ef427989
RR
295}
296
c534e696
RR
297// ---------------------------------------------------------
298// wxDataViewIndexListModel
299// ---------------------------------------------------------
300
e39de702 301static int my_sort( int *v1, int *v2 )
c534e696 302{
e39de702
RR
303 return *v2-*v1;
304}
517166e6 305
e39de702
RR
306
307wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size )
308{
309 // IDs are ordered until an item gets deleted or inserted
310 m_ordered = true;
311
312 // build initial index
313 unsigned int i;
314 for (i = 1; i < initial_size+1; i++)
2056dede 315 m_hash.Add( (void*) i );
e39de702 316 m_lastIndex = initial_size + 1;
c534e696
RR
317}
318
319wxDataViewIndexListModel::~wxDataViewIndexListModel()
320{
321}
322
33ba5a05
RR
323void wxDataViewIndexListModel::Reset( unsigned int new_size )
324{
e39de702 325 m_hash.Clear();
33ba5a05 326
e39de702
RR
327 // IDs are ordered until an item gets deleted or inserted
328 m_ordered = true;
33ba5a05 329
e39de702
RR
330 // build initial index
331 unsigned int i;
332 for (i = 1; i < new_size+1; i++)
33ba5a05 333 m_hash.Add( (void*) i );
e39de702 334 m_lastIndex = new_size + 1;
33ba5a05
RR
335
336 wxDataViewModel::Cleared();
337}
338
c534e696
RR
339void wxDataViewIndexListModel::RowPrepended()
340{
e39de702 341 m_ordered = false;
f8cad1a1 342
e39de702
RR
343 unsigned int id = m_lastIndex++;
344 m_hash.Insert( (void*) id, 0 );
345 wxDataViewItem item( (void*) id );
346 ItemAdded( wxDataViewItem(0), item );
c534e696
RR
347}
348
349void wxDataViewIndexListModel::RowInserted( unsigned int before )
350{
e39de702 351 m_ordered = false;
f8cad1a1 352
e39de702
RR
353 unsigned int id = m_lastIndex++;
354 m_hash.Insert( (void*) id, before );
355 wxDataViewItem item( (void*) id );
356 ItemAdded( wxDataViewItem(0), item );
c534e696
RR
357}
358
359void wxDataViewIndexListModel::RowAppended()
360{
e39de702
RR
361 unsigned int id = m_lastIndex++;
362 m_hash.Add( (void*) id );
363 wxDataViewItem item( (void*) id );
364 ItemAdded( wxDataViewItem(0), item );
c534e696
RR
365}
366
367void wxDataViewIndexListModel::RowDeleted( unsigned int row )
368{
e39de702 369 m_ordered = false;
8b6cf9bf 370
e39de702
RR
371 wxDataViewItem item( m_hash[row] );
372 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
373 m_hash.RemoveAt( row );
8b6cf9bf
RR
374}
375
376void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt &rows )
377{
378 wxArrayInt sorted = rows;
379 sorted.Sort( my_sort );
380
e39de702 381 m_ordered = false;
8b6cf9bf 382
e39de702
RR
383 wxDataViewItemArray array;
384 unsigned int i;
385 for (i = 0; i < rows.GetCount(); i++)
386 {
8b6cf9bf
RR
387 wxDataViewItem item( m_hash[rows[i]] );
388 array.Add( item );
e39de702
RR
389 }
390 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array );
8b6cf9bf 391
e39de702 392 for (i = 0; i < sorted.GetCount(); i++)
8b6cf9bf 393 m_hash.RemoveAt( sorted[i] );
8b6cf9bf
RR
394}
395
c534e696
RR
396void wxDataViewIndexListModel::RowChanged( unsigned int row )
397{
398 wxDataViewModel::ItemChanged( GetItem(row) );
399}
400
401void wxDataViewIndexListModel::RowValueChanged( unsigned int row, unsigned int col )
402{
403 wxDataViewModel::ValueChanged( GetItem(row), col );
404}
405
406unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) const
407{
e39de702 408 if (m_ordered)
517166e6 409 {
2056dede
RR
410 unsigned int pos = wxPtrToUInt( item.GetID() );
411 return pos-1;
2056dede 412 }
e39de702
RR
413
414 // assert for not found
415 return (unsigned int) m_hash.Index( item.GetID() );
c534e696
RR
416}
417
418wxDataViewItem wxDataViewIndexListModel::GetItem( unsigned int row ) const
419{
e39de702
RR
420 wxASSERT( row < m_hash.GetCount() );
421 return wxDataViewItem( m_hash[row] );
c534e696
RR
422}
423
517166e6
RR
424bool wxDataViewIndexListModel::HasDefaultCompare() const
425{
426 return !m_ordered;
427}
428
b7fe2261
VZ
429int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1,
430 const wxDataViewItem& item2,
431 unsigned int WXUNUSED(column),
432 bool ascending)
c534e696 433{
e39de702 434 if (m_ordered)
517166e6 435 {
ec935ba8
PC
436 unsigned int pos1 = wxPtrToUInt(item1.GetID());
437 unsigned int pos2 = wxPtrToUInt(item2.GetID());
517166e6
RR
438
439 if (ascending)
440 return pos1 - pos2;
441 else
442 return pos2 - pos1;
443 }
444
7ee7191c
RR
445 if (ascending)
446 return GetRow(item1) - GetRow(item2);
b7fe2261 447
7ee7191c 448 return GetRow(item2) - GetRow(item1);
c534e696
RR
449}
450
900af470 451void wxDataViewIndexListModel::GetValue( wxVariant &variant,
c534e696
RR
452 const wxDataViewItem &item, unsigned int col ) const
453{
900af470 454 GetValue( variant, GetRow(item), col );
c534e696
RR
455}
456
900af470 457bool wxDataViewIndexListModel::SetValue( const wxVariant &variant,
c534e696
RR
458 const wxDataViewItem &item, unsigned int col )
459{
460 return SetValue( variant, GetRow(item), col );
461}
462
4264606e
RR
463bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr )
464{
465 return GetAttr( GetRow(item), col, attr );
466}
467
900af470 468wxDataViewItem wxDataViewIndexListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const
c534e696
RR
469{
470 return wxDataViewItem(0);
471}
472
473bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem &item ) const
474{
475 // only the invisible root item has children
476 if (!item.IsOk())
477 return true;
900af470 478
c534e696
RR
479 return false;
480}
481
74fe973b 482unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const
c534e696 483{
74fe973b
RR
484 if (item.IsOk())
485 return 0;
c534e696 486
74fe973b 487 children = m_hash;
33ba5a05 488
74fe973b 489 return m_hash.GetCount();
c534e696
RR
490}
491
e39de702
RR
492// ---------------------------------------------------------
493// wxDataViewVirtualListModel
494// ---------------------------------------------------------
495
496#ifndef __WXMAC__
497
498wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size )
499{
500 m_lastIndex = initial_size-1;
501}
502
503wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
504{
505}
506
507void wxDataViewVirtualListModel::Reset( unsigned int new_size )
508{
509 m_lastIndex = new_size-1;
510
511 wxDataViewModel::Cleared();
512}
513
514void wxDataViewVirtualListModel::RowPrepended()
515{
516 m_lastIndex++;
517 wxDataViewItem item( (void*) 0 );
518 ItemAdded( wxDataViewItem(0), item );
519}
520
521void wxDataViewVirtualListModel::RowInserted( unsigned int before )
522{
523 m_lastIndex++;
524 wxDataViewItem item( (void*) before );
525 ItemAdded( wxDataViewItem(0), item );
526}
527
528void wxDataViewVirtualListModel::RowAppended()
529{
530 m_lastIndex++;
531 wxDataViewItem item( (void*) m_lastIndex );
532 ItemAdded( wxDataViewItem(0), item );
533}
534
535void wxDataViewVirtualListModel::RowDeleted( unsigned int row )
536{
537 wxDataViewItem item( (void*) row );
538 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
539 m_lastIndex++;
540}
541
542void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt &rows )
543{
544 wxArrayInt sorted = rows;
545 sorted.Sort( my_sort );
546
547 wxDataViewItemArray array;
548 unsigned int i;
549 for (i = 0; i < sorted.GetCount(); i++)
550 {
551 wxDataViewItem item( (void*) sorted[i] );
552 array.Add( item );
553 }
554 wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array );
555
556 m_lastIndex -= rows.GetCount();
557}
558
559void wxDataViewVirtualListModel::RowChanged( unsigned int row )
560{
561 wxDataViewModel::ItemChanged( GetItem(row) );
562}
563
564void wxDataViewVirtualListModel::RowValueChanged( unsigned int row, unsigned int col )
565{
566 wxDataViewModel::ValueChanged( GetItem(row), col );
567}
568
569unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem &item ) const
570{
571 return wxPtrToUInt( item.GetID() );
572}
573
574wxDataViewItem wxDataViewVirtualListModel::GetItem( unsigned int row ) const
575{
576 return wxDataViewItem( (void*) row );
577}
578
579bool wxDataViewVirtualListModel::HasDefaultCompare() const
580{
581 return true;
582}
583
584int wxDataViewVirtualListModel::Compare(const wxDataViewItem& item1,
585 const wxDataViewItem& item2,
586 unsigned int WXUNUSED(column),
587 bool ascending)
588{
589 unsigned int pos1 = wxPtrToUInt(item1.GetID());
590 unsigned int pos2 = wxPtrToUInt(item2.GetID());
591
592 if (ascending)
593 return pos1 - pos2;
594 else
595 return pos2 - pos1;
596}
597
598void wxDataViewVirtualListModel::GetValue( wxVariant &variant,
599 const wxDataViewItem &item, unsigned int col ) const
600{
601 GetValue( variant, GetRow(item), col );
602}
603
604bool wxDataViewVirtualListModel::SetValue( const wxVariant &variant,
605 const wxDataViewItem &item, unsigned int col )
606{
607 return SetValue( variant, GetRow(item), col );
608}
609
610bool wxDataViewVirtualListModel::GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr )
611{
612 return GetAttr( GetRow(item), col, attr );
613}
614
615wxDataViewItem wxDataViewVirtualListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const
616{
617 return wxDataViewItem(0);
618}
619
620bool wxDataViewVirtualListModel::IsContainer( const wxDataViewItem &item ) const
621{
622 // only the invisible root item has children
623 if (!item.IsOk())
624 return true;
625
626 return false;
627}
628
629unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem &WXUNUSED(item), wxDataViewItemArray &WXUNUSED(children) ) const
630{
631 return 0; // should we report an error ?
632}
633
634#endif // __WXMAC__
635
89352653
RR
636//-----------------------------------------------------------------------------
637// wxDataViewIconText
638//-----------------------------------------------------------------------------
639
640IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText,wxObject)
641
d350fbec 642IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV)
89352653
RR
643
644bool operator == (const wxDataViewIconText &one, const wxDataViewIconText &two)
645{
646 if (one.GetText() != two.GetText()) return false;
647 if (one.IsSameAs(two)) return false;
648 return true;
649}
650
f554a14b 651// ---------------------------------------------------------
baa9ebc4 652// wxDataViewRendererBase
f554a14b 653// ---------------------------------------------------------
6842a71a 654
baa9ebc4 655IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase, wxObject)
6842a71a 656
900af470 657wxDataViewRendererBase::wxDataViewRendererBase( const wxString &varianttype,
9861f022
RR
658 wxDataViewCellMode WXUNUSED(mode),
659 int WXUNUSED(align) )
6842a71a
RR
660{
661 m_variantType = varianttype;
f2b7492a 662 m_owner = NULL;
9861f022
RR
663}
664
c232dfe5
RR
665wxDataViewRendererBase::~wxDataViewRendererBase()
666{
667}
668
9861f022
RR
669const wxDataViewCtrl* wxDataViewRendererBase::GetView() const
670{
671 return wx_const_cast(wxDataViewRendererBase*, this)->GetOwner()->GetOwner();
6842a71a 672}
f554a14b 673
c232dfe5
RR
674class wxKillRef: public wxWindowRef
675{
676public:
677 wxKillRef( wxWindow *win ) : wxWindowRef( win ) { }
678 virtual void OnObjectDestroy()
679 {
680 get()->PopEventHandler( true );
095a3221 681 m_pobj = NULL;
c232dfe5
RR
682 delete this;
683 }
684};
685
e0062c04 686bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect )
1e510b1e 687{
e0062c04 688 m_item = item; // remember for later
900af470 689
1e510b1e
RR
690 unsigned int col = GetOwner()->GetModelColumn();
691 wxVariant value;
e0062c04 692 GetOwner()->GetOwner()->GetModel()->GetValue( value, item, col );
900af470 693
1e510b1e 694 m_editorCtrl = CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect, value );
c232dfe5 695 (void) new wxKillRef( m_editorCtrl.get() );
900af470
JS
696
697 wxDataViewEditorCtrlEvtHandler *handler =
30715fa1 698 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl, (wxDataViewRenderer*) this );
900af470 699
30715fa1 700 m_editorCtrl->PushEventHandler( handler );
900af470 701
30715fa1
RR
702#if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
703 handler->SetFocusOnIdle();
704#else
1e510b1e 705 m_editorCtrl->SetFocus();
30715fa1
RR
706#endif
707
afebb87b
RR
708 // Now we should send Editing Started event
709 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, GetOwner()->GetOwner()->GetId() );
710 event.SetDataViewColumn( GetOwner() );
711 event.SetModel( GetOwner()->GetOwner()->GetModel() );
712 event.SetItem( item );
afebb87b
RR
713 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event );
714
1e510b1e
RR
715 return true;
716}
717
718void wxDataViewRendererBase::CancelEditing()
719{
1e510b1e 720 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
c232dfe5
RR
721
722 m_editorCtrl->Hide();
723 wxPendingDelete.Append( m_editorCtrl );
1e510b1e
RR
724}
725
726bool wxDataViewRendererBase::FinishEditing()
727{
1e510b1e
RR
728 wxVariant value;
729 GetValueFromEditorCtrl( m_editorCtrl, value );
730
1e510b1e 731 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
900af470 732
c232dfe5
RR
733 m_editorCtrl->Hide();
734 wxPendingDelete.Append( m_editorCtrl );
735
1e510b1e
RR
736 if (!Validate(value))
737 return false;
900af470 738
1e510b1e 739 unsigned int col = GetOwner()->GetModelColumn();
e0062c04
RR
740 GetOwner()->GetOwner()->GetModel()->SetValue( value, m_item, col );
741 GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item, col );
900af470 742
afebb87b
RR
743 // Now we should send Editing Done event
744 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, GetOwner()->GetOwner()->GetId() );
745 event.SetDataViewColumn( GetOwner() );
746 event.SetModel( GetOwner()->GetOwner()->GetModel() );
8fdaf7de 747 event.SetItem( m_item );
afebb87b 748 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event );
900af470 749
1e510b1e
RR
750 return true;
751}
752
753//-----------------------------------------------------------------------------
754// wxDataViewEditorCtrlEvtHandler
755//-----------------------------------------------------------------------------
756
757BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler, wxEvtHandler)
758 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar)
759 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus)
30715fa1 760 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle)
1e510b1e
RR
761END_EVENT_TABLE()
762
763wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
764 wxControl *editorCtrl,
765 wxDataViewRenderer *owner )
766{
767 m_owner = owner;
768 m_editorCtrl = editorCtrl;
769
770 m_finished = false;
771}
772
30715fa1
RR
773void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent &event )
774{
775 if (m_focusOnIdle)
776 {
777 m_focusOnIdle = false;
778 if (wxWindow::FindFocus() != m_editorCtrl)
779 m_editorCtrl->SetFocus();
780 }
900af470 781
30715fa1
RR
782 event.Skip();
783}
784
1e510b1e
RR
785void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event )
786{
787 switch ( event.m_keyCode )
788 {
789 case WXK_RETURN:
790 m_finished = true;
791 m_owner->FinishEditing();
792 break;
793
794 case WXK_ESCAPE:
795 m_finished = true;
796 m_owner->CancelEditing();
797 break;
798
799 default:
800 event.Skip();
801 }
802}
803
804void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event )
805{
806 if (!m_finished)
807 {
808 m_finished = true;
809 m_owner->FinishEditing();
810 }
811
1e510b1e
RR
812 event.Skip();
813}
814
f554a14b 815// ---------------------------------------------------------
fa28826d 816// wxDataViewColumnBase
f554a14b 817// ---------------------------------------------------------
fa28826d
RR
818
819IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase, wxObject)
820
9861f022 821wxDataViewColumnBase::wxDataViewColumnBase(const wxString& WXUNUSED(title),
baa9ebc4 822 wxDataViewRenderer *renderer,
0a71f9e9 823 unsigned int model_column,
008b5a66 824 int WXUNUSED(width),
87f0efe2 825 wxAlignment WXUNUSED(align),
900af470 826 int WXUNUSED(flags))
fa28826d 827{
baa9ebc4 828 m_renderer = renderer;
6842a71a 829 m_model_column = model_column;
6842a71a 830 m_owner = NULL;
baa9ebc4 831 m_renderer->SetOwner( (wxDataViewColumn*) this );
9861f022
RR
832
833 // NOTE: the wxDataViewColumn's ctor must store the width, align, flags
834 // parameters inside the native control!
6842a71a
RR
835}
836
07a84e7b
RR
837wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap& bitmap,
838 wxDataViewRenderer *renderer,
839 unsigned int model_column,
840 int WXUNUSED(width),
87f0efe2 841 wxAlignment WXUNUSED(align),
900af470 842 int WXUNUSED(flags) )
07a84e7b
RR
843{
844 m_renderer = renderer;
845 m_model_column = model_column;
07a84e7b
RR
846 m_bitmap = bitmap;
847 m_owner = NULL;
848 m_renderer->SetOwner( (wxDataViewColumn*) this );
849}
850
6842a71a
RR
851wxDataViewColumnBase::~wxDataViewColumnBase()
852{
baa9ebc4
RR
853 if (m_renderer)
854 delete m_renderer;
fa28826d
RR
855}
856
9861f022 857int wxDataViewColumnBase::GetFlags() const
fa28826d 858{
9861f022 859 int ret = 0;
fa28826d 860
9861f022
RR
861 if (IsSortable())
862 ret |= wxDATAVIEW_COL_SORTABLE;
863 if (IsResizeable())
864 ret |= wxDATAVIEW_COL_RESIZABLE;
865 if (IsHidden())
866 ret |= wxDATAVIEW_COL_HIDDEN;
fa28826d 867
9861f022 868 return ret;
07a84e7b
RR
869}
870
9861f022 871void wxDataViewColumnBase::SetFlags(int flags)
07a84e7b 872{
9861f022
RR
873 SetSortable((flags & wxDATAVIEW_COL_SORTABLE) != 0);
874 SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0);
875 SetHidden((flags & wxDATAVIEW_COL_HIDDEN) != 0);
99c75ebc 876 SetReorderable((flags & wxDATAVIEW_COL_REORDERABLE) != 0);
07a84e7b
RR
877}
878
f554a14b 879// ---------------------------------------------------------
239eaa41 880// wxDataViewCtrlBase
f554a14b 881// ---------------------------------------------------------
239eaa41
RR
882
883IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl)
884
885wxDataViewCtrlBase::wxDataViewCtrlBase()
886{
887 m_model = NULL;
3b6280be
RR
888 m_expander_column = 0;
889 m_indent = 8;
239eaa41
RR
890}
891
892wxDataViewCtrlBase::~wxDataViewCtrlBase()
893{
87f0efe2
RR
894 if (m_model)
895 {
896 m_model->DecRef();
897 m_model = NULL;
898 }
239eaa41
RR
899}
900
e0062c04 901bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel *model )
239eaa41 902{
1821abd1
RR
903 if (m_model)
904 {
87f0efe2 905 m_model->DecRef(); // discard old model, if any
1821abd1 906 }
87f0efe2
RR
907
908 // add our own reference to the new model:
239eaa41 909 m_model = model;
1821abd1
RR
910 if (m_model)
911 {
900af470 912 m_model->IncRef();
1821abd1 913 }
f554a14b 914
239eaa41
RR
915 return true;
916}
917
e0062c04 918wxDataViewModel* wxDataViewCtrlBase::GetModel()
239eaa41
RR
919{
920 return m_model;
921}
922
a75124d0
RR
923const wxDataViewModel* wxDataViewCtrlBase::GetModel() const
924{
925 return m_model;
926}
927
c7074d44
RR
928wxDataViewColumn *
929wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_column,
87f0efe2 930 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
fa28826d 931{
c7074d44 932 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 933 new wxDataViewTextRenderer( wxT("string"), mode ),
c7074d44
RR
934 model_column, width, align, flags );
935 AppendColumn( ret );
936 return ret;
fa28826d
RR
937}
938
b04fcede
RR
939wxDataViewColumn *
940wxDataViewCtrlBase::AppendIconTextColumn( const wxString &label, unsigned int model_column,
941 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
942{
943 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 944 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
b04fcede
RR
945 model_column, width, align, flags );
946 AppendColumn( ret );
947 return ret;
948}
949
c7074d44
RR
950wxDataViewColumn *
951wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int model_column,
87f0efe2 952 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
605c2c4a 953{
b7fe2261 954
c7074d44 955 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 956 new wxDataViewToggleRenderer( wxT("bool"), mode ),
c7074d44
RR
957 model_column, width, align, flags );
958 AppendColumn( ret );
959 return ret;
605c2c4a
RR
960}
961
c7074d44
RR
962wxDataViewColumn *
963wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, unsigned int model_column,
87f0efe2 964 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
ad63bf41 965{
c7074d44 966 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 967 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
c7074d44
RR
968 model_column, width, align, flags );
969 AppendColumn( ret );
970 return ret;
ad63bf41
RR
971}
972
c7074d44
RR
973wxDataViewColumn *
974wxDataViewCtrlBase::AppendDateColumn( const wxString &label, unsigned int model_column,
87f0efe2 975 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
4d496ecb 976{
c7074d44 977 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 978 new wxDataViewDateRenderer( wxT("datetime"), mode ),
c7074d44
RR
979 model_column, width, align, flags );
980 AppendColumn( ret );
981 return ret;
4d496ecb
RR
982}
983
c7074d44
RR
984wxDataViewColumn *
985wxDataViewCtrlBase::AppendBitmapColumn( const wxString &label, unsigned int model_column,
87f0efe2 986 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 987{
c7074d44 988 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 989 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
c7074d44
RR
990 model_column, width, align, flags );
991 AppendColumn( ret );
992 return ret;
07a84e7b
RR
993}
994
c7074d44
RR
995wxDataViewColumn *
996wxDataViewCtrlBase::AppendTextColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 997 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 998{
c7074d44 999 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1000 new wxDataViewTextRenderer( wxT("string"), mode ),
c7074d44
RR
1001 model_column, width, align, flags );
1002 AppendColumn( ret );
1003 return ret;
b04fcede
RR
1004}
1005
1006wxDataViewColumn *
1007wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap &label, unsigned int model_column,
1008 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1009{
1010 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1011 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
b04fcede
RR
1012 model_column, width, align, flags );
1013 AppendColumn( ret );
1014 return ret;
07a84e7b
RR
1015}
1016
c7074d44
RR
1017wxDataViewColumn *
1018wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 1019 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1020{
c7074d44 1021 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1022 new wxDataViewToggleRenderer( wxT("bool"), mode ),
c7074d44
RR
1023 model_column, width, align, flags );
1024 AppendColumn( ret );
1025 return ret;
07a84e7b
RR
1026}
1027
c7074d44
RR
1028wxDataViewColumn *
1029wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 1030 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1031{
c7074d44 1032 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1033 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
c7074d44
RR
1034 model_column, width, align, flags );
1035 AppendColumn( ret );
1036 return ret;
07a84e7b
RR
1037}
1038
c7074d44
RR
1039wxDataViewColumn *
1040wxDataViewCtrlBase::AppendDateColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 1041 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1042{
c7074d44 1043 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1044 new wxDataViewDateRenderer( wxT("datetime"), mode ),
c7074d44
RR
1045 model_column, width, align, flags );
1046 AppendColumn( ret );
1047 return ret;
07a84e7b
RR
1048}
1049
c7074d44
RR
1050wxDataViewColumn *
1051wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 1052 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1053{
c7074d44 1054 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1055 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
c7074d44
RR
1056 model_column, width, align, flags );
1057 AppendColumn( ret );
1058 return ret;
07a84e7b
RR
1059}
1060
736fe67c
RR
1061wxDataViewColumn *
1062wxDataViewCtrlBase::PrependTextColumn( const wxString &label, unsigned int model_column,
1063 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1064{
1065 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1066 new wxDataViewTextRenderer( wxT("string"), mode ),
736fe67c
RR
1067 model_column, width, align, flags );
1068 PrependColumn( ret );
1069 return ret;
1070}
1071
1072wxDataViewColumn *
1073wxDataViewCtrlBase::PrependIconTextColumn( const wxString &label, unsigned int model_column,
1074 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1075{
1076 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1077 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
736fe67c
RR
1078 model_column, width, align, flags );
1079 PrependColumn( ret );
1080 return ret;
1081}
1082
1083wxDataViewColumn *
1084wxDataViewCtrlBase::PrependToggleColumn( const wxString &label, unsigned int model_column,
1085 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1086{
1087
1088 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1089 new wxDataViewToggleRenderer( wxT("bool"), mode ),
736fe67c
RR
1090 model_column, width, align, flags );
1091 PrependColumn( ret );
1092 return ret;
1093}
1094
1095wxDataViewColumn *
1096wxDataViewCtrlBase::PrependProgressColumn( const wxString &label, unsigned int model_column,
1097 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1098{
1099 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1100 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
736fe67c
RR
1101 model_column, width, align, flags );
1102 PrependColumn( ret );
1103 return ret;
1104}
1105
1106wxDataViewColumn *
1107wxDataViewCtrlBase::PrependDateColumn( const wxString &label, unsigned int model_column,
1108 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1109{
1110 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1111 new wxDataViewDateRenderer( wxT("datetime"), mode ),
736fe67c
RR
1112 model_column, width, align, flags );
1113 PrependColumn( ret );
1114 return ret;
1115}
1116
1117wxDataViewColumn *
1118wxDataViewCtrlBase::PrependBitmapColumn( const wxString &label, unsigned int model_column,
1119 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1120{
1121 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1122 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
736fe67c
RR
1123 model_column, width, align, flags );
1124 PrependColumn( ret );
1125 return ret;
1126}
1127
1128wxDataViewColumn *
1129wxDataViewCtrlBase::PrependTextColumn( const wxBitmap &label, unsigned int model_column,
1130 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1131{
1132 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1133 new wxDataViewTextRenderer( wxT("string"), mode ),
736fe67c
RR
1134 model_column, width, align, flags );
1135 PrependColumn( ret );
1136 return ret;
1137}
1138
1139wxDataViewColumn *
1140wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap &label, unsigned int model_column,
1141 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1142{
1143 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1144 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
736fe67c
RR
1145 model_column, width, align, flags );
1146 PrependColumn( ret );
1147 return ret;
1148}
1149
1150wxDataViewColumn *
1151wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap &label, unsigned int model_column,
1152 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1153{
1154 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1155 new wxDataViewToggleRenderer( wxT("bool"), mode ),
736fe67c
RR
1156 model_column, width, align, flags );
1157 PrependColumn( ret );
1158 return ret;
1159}
1160
1161wxDataViewColumn *
1162wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap &label, unsigned int model_column,
1163 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1164{
1165 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1166 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
736fe67c
RR
1167 model_column, width, align, flags );
1168 PrependColumn( ret );
1169 return ret;
1170}
1171
1172wxDataViewColumn *
1173wxDataViewCtrlBase::PrependDateColumn( const wxBitmap &label, unsigned int model_column,
1174 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1175{
1176 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1177 new wxDataViewDateRenderer( wxT("datetime"), mode ),
736fe67c
RR
1178 model_column, width, align, flags );
1179 PrependColumn( ret );
1180 return ret;
1181}
1182
1183wxDataViewColumn *
1184wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap &label, unsigned int model_column,
1185 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1186{
1187 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1188 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
736fe67c
RR
1189 model_column, width, align, flags );
1190 PrependColumn( ret );
1191 return ret;
1192}
1193
c7074d44
RR
1194bool
1195wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col )
fa28826d 1196{
6842a71a 1197 col->SetOwner( (wxDataViewCtrl*) this );
fa28826d
RR
1198 return true;
1199}
1200
736fe67c
RR
1201bool
1202wxDataViewCtrlBase::PrependColumn( wxDataViewColumn *col )
1203{
1204 col->SetOwner( (wxDataViewCtrl*) this );
1205 return true;
1206}
1207
eb7f97f8
RR
1208// ---------------------------------------------------------
1209// wxDataViewEvent
1210// ---------------------------------------------------------
1211
1212IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent)
1213
d86c1870
RR
1214DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED)
1215
e0062c04 1216DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED)
6977c3bf 1217DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING)
3ecb8a53 1218DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED)
6977c3bf 1219DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING)
3ecb8a53 1220DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED)
e0000f94
RR
1221DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED)
1222DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE)
6608fdab 1223DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED)
e0000f94 1224
63779a3d
RR
1225DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU)
1226
31fb32e1
RR
1227DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK)
1228DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK)
c0a66d92 1229DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED)
e483dfcb 1230DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED)
eb7f97f8 1231
52e750fc
RR
1232
1233// -------------------------------------
1234// wxDataViewSpinRenderer
1235// -------------------------------------
1236
1237wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min, int max, wxDataViewCellMode mode, int alignment ) :
99c75ebc 1238 wxDataViewCustomRenderer(wxT("long"), mode, alignment )
b5ec7dd6 1239{
52e750fc
RR
1240 m_min = min;
1241 m_max = max;
1242}
b5ec7dd6 1243
52e750fc 1244wxControl* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
b5ec7dd6 1245{
52e750fc 1246 long l = value;
659fb68d
RR
1247 wxSize size = labelRect.GetSize();
1248#ifdef __WXMAC__
1249 size = wxSize( wxMax(70,labelRect.width ), -1 );
1250#endif
1251 wxString str;
2ddfe921 1252 str.Printf( wxT("%d"), (int) l );
659fb68d
RR
1253 wxSpinCtrl *sc = new wxSpinCtrl( parent, wxID_ANY, str,
1254 labelRect.GetTopLeft(), size, wxSP_ARROW_KEYS, m_min, m_max, l );
1255#ifdef __WXMAC__
1256 size = sc->GetSize();
1257 wxPoint pt = sc->GetPosition();
1258 sc->SetSize( pt.x - 4, pt.y - 4, size.x, size.y );
1259#endif
1260
1261 return sc;
52e750fc 1262}
b5ec7dd6 1263
52e750fc 1264bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value )
b5ec7dd6 1265{
52e750fc
RR
1266 wxSpinCtrl *sc = (wxSpinCtrl*) editor;
1267 long l = sc->GetValue();
1268 value = l;
1269 return true;
1270}
b5ec7dd6 1271
52e750fc
RR
1272bool wxDataViewSpinRenderer::Render( wxRect rect, wxDC *dc, int state )
1273{
1274 wxString str;
99c75ebc 1275 str.Printf(wxT("%d"), (int) m_data );
52e750fc
RR
1276 RenderText( str, 0, rect, dc, state );
1277 return true;
1278}
b5ec7dd6 1279
52e750fc
RR
1280wxSize wxDataViewSpinRenderer::GetSize() const
1281{
1282 return wxSize(80,16);
1283}
b5ec7dd6 1284
52e750fc
RR
1285bool wxDataViewSpinRenderer::SetValue( const wxVariant &value )
1286{
1287 m_data = value.GetLong();
1288 return true;
1289}
b5ec7dd6 1290
52e750fc
RR
1291bool wxDataViewSpinRenderer::GetValue( wxVariant &value ) const
1292{
1293 value = m_data;
1294 return true;
1295}
1296
e94d0c1e
RR
1297//-----------------------------------------------------------------------------
1298// wxDataViewTreeStore
1299//-----------------------------------------------------------------------------
1300
b5ec7dd6
VZ
1301wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1302 wxDataViewTreeStoreNode *parent,
e94d0c1e
RR
1303 const wxString &text, const wxIcon &icon, wxClientData *data )
1304{
1305 m_parent = parent;
1306 m_text = text;
1307 m_icon = icon;
1308 m_data = data;
1309}
1310
1311wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1312{
1313 if (m_data)
1314 delete m_data;
1315}
b5ec7dd6 1316
e94d0c1e 1317#include "wx/listimpl.cpp"
a76c2f37 1318WX_DEFINE_LIST(wxDataViewTreeStoreNodeList)
e94d0c1e 1319
b5ec7dd6
VZ
1320wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1321 wxDataViewTreeStoreNode *parent, const wxString &text,
e94d0c1e
RR
1322 const wxIcon &icon, const wxIcon &expanded, wxClientData *data ) :
1323 wxDataViewTreeStoreNode( parent, text, icon, data )
1324{
1325 m_iconExpanded = expanded;
a75124d0 1326 m_isExpanded = false;
e94d0c1e
RR
1327 m_children.DeleteContents(true);
1328}
1329
1330wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1331{
1332}
1333
1334//-----------------------------------------------------------------------------
1335
1336wxDataViewTreeStore::wxDataViewTreeStore()
1337{
1338 m_root = new wxDataViewTreeStoreContainerNode( NULL, wxEmptyString );
1339}
1340
1341wxDataViewTreeStore::~wxDataViewTreeStore()
1342{
1343 delete m_root;
1344}
1345
b5ec7dd6 1346wxDataViewItem wxDataViewTreeStore::AppendItem( const wxDataViewItem& parent,
e94d0c1e
RR
1347 const wxString &text, const wxIcon &icon, wxClientData *data )
1348{
1349 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1350 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6
VZ
1351
1352 wxDataViewTreeStoreNode *node =
e94d0c1e
RR
1353 new wxDataViewTreeStoreNode( parent_node, text, icon, data );
1354 parent_node->GetChildren().Append( node );
b5ec7dd6 1355
e94d0c1e
RR
1356 // notify control
1357 ItemAdded( parent, node->GetItem() );
b5ec7dd6 1358
e94d0c1e
RR
1359 return node->GetItem();
1360}
1361
1362wxDataViewItem wxDataViewTreeStore::PrependItem( const wxDataViewItem& parent,
1363 const wxString &text, const wxIcon &icon, wxClientData *data )
1364{
1365 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1366 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6
VZ
1367
1368 wxDataViewTreeStoreNode *node =
e94d0c1e
RR
1369 new wxDataViewTreeStoreNode( parent_node, text, icon, data );
1370 parent_node->GetChildren().Insert( node );
b5ec7dd6 1371
e94d0c1e
RR
1372 // notify control
1373 ItemAdded( parent, node->GetItem() );
b5ec7dd6 1374
e94d0c1e
RR
1375 return node->GetItem();
1376}
1377
b5ec7dd6
VZ
1378wxDataViewItem
1379wxDataViewTreeStore::InsertItem(const wxDataViewItem& WXUNUSED(parent),
1380 const wxDataViewItem& WXUNUSED(previous),
1381 const wxString& WXUNUSED(text),
1382 const wxIcon& WXUNUSED(icon),
1383 wxClientData * WXUNUSED(data))
e94d0c1e
RR
1384{
1385 return wxDataViewItem(0);
1386}
1387
b5ec7dd6
VZ
1388wxDataViewItem wxDataViewTreeStore::PrependContainer( const wxDataViewItem& parent,
1389 const wxString &text, const wxIcon &icon, const wxIcon &expanded,
e94d0c1e
RR
1390 wxClientData *data )
1391{
1392 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1393 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6
VZ
1394
1395 wxDataViewTreeStoreContainerNode *node =
e94d0c1e
RR
1396 new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
1397 parent_node->GetChildren().Insert( node );
b5ec7dd6 1398
e94d0c1e
RR
1399 // notify control
1400 ItemAdded( parent, node->GetItem() );
b5ec7dd6 1401
e94d0c1e
RR
1402 return node->GetItem();
1403}
1404
b5ec7dd6
VZ
1405wxDataViewItem
1406wxDataViewTreeStore::AppendContainer(const wxDataViewItem& parent,
1407 const wxString &text,
1408 const wxIcon& icon,
1409 const wxIcon& expanded,
1410 wxClientData * data)
e94d0c1e
RR
1411{
1412 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1413 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6
VZ
1414
1415 wxDataViewTreeStoreContainerNode *node =
e94d0c1e
RR
1416 new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
1417 parent_node->GetChildren().Append( node );
b5ec7dd6 1418
e94d0c1e
RR
1419 // notify control
1420 ItemAdded( parent, node->GetItem() );
b5ec7dd6 1421
e94d0c1e
RR
1422 return node->GetItem();
1423}
1424
b5ec7dd6
VZ
1425wxDataViewItem
1426wxDataViewTreeStore::InsertContainer(const wxDataViewItem& WXUNUSED(parent),
1427 const wxDataViewItem& WXUNUSED(previous),
1428 const wxString& WXUNUSED(text),
1429 const wxIcon& WXUNUSED(icon),
1430 const wxIcon& WXUNUSED(expanded),
1431 wxClientData * WXUNUSED(data))
e94d0c1e
RR
1432{
1433 return wxDataViewItem(0);
1434}
1435
1436wxDataViewItem wxDataViewTreeStore::GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const
1437{
1438 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1439 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6 1440
e94d0c1e
RR
1441 wxDataViewTreeStoreNodeList::compatibility_iterator node = parent_node->GetChildren().Item( pos );
1442 if (node)
1443 return node->GetData();
b5ec7dd6 1444
e94d0c1e
RR
1445 return wxDataViewItem(0);
1446}
1447
1448int wxDataViewTreeStore::GetChildCount( const wxDataViewItem& parent ) const
1449{
1450 wxDataViewTreeStoreNode *node = FindNode( parent );
1451 if (!node) return -1;
b5ec7dd6 1452
e94d0c1e
RR
1453 if (!node->IsContainer())
1454 return 0;
b5ec7dd6 1455
e94d0c1e 1456 wxDataViewTreeStoreContainerNode *container_node = (wxDataViewTreeStoreContainerNode*) node;
b5ec7dd6 1457 return (int) container_node->GetChildren().GetCount();
e94d0c1e
RR
1458}
1459
1460void wxDataViewTreeStore::SetItemText( const wxDataViewItem& item, const wxString &text )
1461{
1462 wxDataViewTreeStoreNode *node = FindNode( item );
1463 if (!node) return;
b5ec7dd6 1464
e94d0c1e 1465 node->SetText( text );
b5ec7dd6 1466
e94d0c1e
RR
1467 // notify control
1468 ValueChanged( item, 0 );
1469}
1470
1471wxString wxDataViewTreeStore::GetItemText( const wxDataViewItem& item ) const
1472{
1473 wxDataViewTreeStoreNode *node = FindNode( item );
1474 if (!node) return wxEmptyString;
b5ec7dd6 1475
e94d0c1e
RR
1476 return node->GetText();
1477}
1478
1479void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem& item, const wxIcon &icon )
1480{
1481 wxDataViewTreeStoreNode *node = FindNode( item );
1482 if (!node) return;
b5ec7dd6 1483
e94d0c1e 1484 node->SetIcon( icon );
b5ec7dd6 1485
e94d0c1e
RR
1486 // notify control
1487 ValueChanged( item, 0 );
1488}
1489
1490const wxIcon &wxDataViewTreeStore::GetItemIcon( const wxDataViewItem& item ) const
1491{
1492 wxDataViewTreeStoreNode *node = FindNode( item );
1493 if (!node) return wxNullIcon;
b5ec7dd6 1494
e94d0c1e
RR
1495 return node->GetIcon();
1496}
1497
1498void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon )
1499{
1500 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1501 if (!node) return;
b5ec7dd6 1502
e94d0c1e 1503 node->SetExpandedIcon( icon );
b5ec7dd6 1504
e94d0c1e
RR
1505 // notify control
1506 ValueChanged( item, 0 );
1507}
1508
1509const wxIcon &wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem& item ) const
1510{
1511 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1512 if (!node) return wxNullIcon;
b5ec7dd6 1513
e94d0c1e
RR
1514 return node->GetExpandedIcon();
1515}
1516
1517void wxDataViewTreeStore::SetItemData( const wxDataViewItem& item, wxClientData *data )
1518{
1519 wxDataViewTreeStoreNode *node = FindNode( item );
1520 if (!node) return;
b5ec7dd6 1521
e94d0c1e 1522 node->SetData( data );
b5ec7dd6 1523
e94d0c1e
RR
1524 // notify control? only sensible when sorting on client data
1525 // ValueChanged( item, 0 );
1526}
1527
1528wxClientData *wxDataViewTreeStore::GetItemData( const wxDataViewItem& item ) const
1529{
1530 wxDataViewTreeStoreNode *node = FindNode( item );
1531 if (!node) return NULL;
b5ec7dd6 1532
e94d0c1e
RR
1533 return node->GetData();
1534}
1535
1536void wxDataViewTreeStore::DeleteItem( const wxDataViewItem& item )
1537{
1538 if (!item.IsOk()) return;
1539
1540 wxDataViewItem parent_item = GetParent( item );
1541
1542 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent_item );
1543 if (!parent_node) return;
b5ec7dd6 1544
e94d0c1e
RR
1545 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1546 if (!node) return;
b5ec7dd6 1547
e94d0c1e 1548 parent_node->GetChildren().DeleteObject( node );
b5ec7dd6 1549
e94d0c1e
RR
1550 // notify control
1551 ItemDeleted( parent_item, item );
1552}
1553
1554void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem& item )
1555{
1556 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1557 if (!node) return;
b5ec7dd6 1558
e94d0c1e
RR
1559 wxDataViewItemArray array;
1560 wxDataViewTreeStoreNodeList::iterator iter;
1561 for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++)
1562 {
1563 wxDataViewTreeStoreNode* child = *iter;
1564 array.Add( child->GetItem() );
1565 }
b5ec7dd6 1566
e94d0c1e 1567 node->GetChildren().clear();
b5ec7dd6 1568
e94d0c1e
RR
1569 // notify control
1570 ItemsDeleted( item, array );
1571}
1572
1573void wxDataViewTreeStore::DeleteAllItems()
1574{
1575 // TODO
1576}
1577
b5ec7dd6
VZ
1578void
1579wxDataViewTreeStore::GetValue(wxVariant &variant,
1580 const wxDataViewItem &item,
1581 unsigned int WXUNUSED(col)) const
e94d0c1e
RR
1582{
1583 // if (col != 0) return;
b5ec7dd6 1584
e94d0c1e
RR
1585 wxDataViewTreeStoreNode *node = FindNode( item );
1586 if (!node) return;
b5ec7dd6 1587
a75124d0
RR
1588 wxIcon icon( node->GetIcon());
1589 if (node->IsContainer())
1590 {
1591 wxDataViewTreeStoreContainerNode *container = (wxDataViewTreeStoreContainerNode*) node;
1592 if (container->IsExpanded() && container->GetExpandedIcon().IsOk())
1593 icon = container->GetExpandedIcon();
1594 }
1595
1596 wxDataViewIconText data( node->GetText(), icon );
b5ec7dd6 1597
e94d0c1e
RR
1598 variant << data;
1599}
1600
b5ec7dd6
VZ
1601bool
1602wxDataViewTreeStore::SetValue(const wxVariant& variant,
1603 const wxDataViewItem& item,
1604 unsigned int WXUNUSED(col))
e94d0c1e
RR
1605{
1606 // if (col != 0) return false;
b5ec7dd6 1607
e94d0c1e
RR
1608 wxDataViewTreeStoreNode *node = FindNode( item );
1609 if (!node) return false;
b5ec7dd6 1610
e94d0c1e 1611 wxDataViewIconText data;
b5ec7dd6 1612
e94d0c1e 1613 data << variant;
b5ec7dd6 1614
e94d0c1e
RR
1615 node->SetText( data.GetText() );
1616 node->SetIcon( data.GetIcon() );
b5ec7dd6 1617
e94d0c1e
RR
1618 return true;
1619}
1620
1621wxDataViewItem wxDataViewTreeStore::GetParent( const wxDataViewItem &item ) const
1622{
1623 wxDataViewTreeStoreNode *node = FindNode( item );
1624 if (!node) return wxDataViewItem(0);
b5ec7dd6 1625
e94d0c1e
RR
1626 wxDataViewTreeStoreNode *parent = node->GetParent();
1627 if (!parent) return wxDataViewItem(0);
b5ec7dd6 1628
e94d0c1e
RR
1629 if (parent == m_root)
1630 return wxDataViewItem(0);
b5ec7dd6 1631
e94d0c1e
RR
1632 return parent->GetItem();
1633}
1634
1635bool wxDataViewTreeStore::IsContainer( const wxDataViewItem &item ) const
1636{
1637 wxDataViewTreeStoreNode *node = FindNode( item );
1638 if (!node) return false;
b5ec7dd6 1639
e94d0c1e
RR
1640 return node->IsContainer();
1641}
1642
1643unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const
1644{
1645 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1646 if (!node) return 0;
1647
1648 wxDataViewTreeStoreNodeList::iterator iter;
1649 for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++)
1650 {
1651 wxDataViewTreeStoreNode* child = *iter;
1652 children.Add( child->GetItem() );
1653 }
b5ec7dd6 1654
e94d0c1e
RR
1655 return node->GetChildren().GetCount();
1656}
1657
b5ec7dd6 1658int wxDataViewTreeStore::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
e94d0c1e
RR
1659 unsigned int WXUNUSED(column), bool WXUNUSED(ascending) )
1660{
1661 wxDataViewTreeStoreNode *node1 = FindNode( item1 );
1662 wxDataViewTreeStoreNode *node2 = FindNode( item2 );
b5ec7dd6 1663
e94d0c1e
RR
1664 if (!node1 || !node2)
1665 return 0;
b5ec7dd6
VZ
1666
1667 wxDataViewTreeStoreContainerNode* parent1 =
e94d0c1e 1668 (wxDataViewTreeStoreContainerNode*) node1->GetParent();
b5ec7dd6 1669 wxDataViewTreeStoreContainerNode* parent2 =
e94d0c1e 1670 (wxDataViewTreeStoreContainerNode*) node2->GetParent();
b5ec7dd6 1671
e94d0c1e
RR
1672 if (parent1 != parent2)
1673 {
1674 wxLogError( wxT("Comparing items with different parent.") );
1675 return 0;
1676 }
b5ec7dd6 1677
e94d0c1e
RR
1678 if (node1->IsContainer() && !!node2->IsContainer())
1679 return 1;
b5ec7dd6 1680
e94d0c1e
RR
1681 if (node2->IsContainer() && !!node1->IsContainer())
1682 return -1;
b5ec7dd6 1683
e94d0c1e
RR
1684 return parent1->GetChildren().IndexOf( node1 ) - parent1->GetChildren().IndexOf( node2 );
1685}
1686
1687wxDataViewTreeStoreNode *wxDataViewTreeStore::FindNode( const wxDataViewItem &item ) const
1688{
1689 if (!item.IsOk())
1690 return m_root;
b5ec7dd6 1691
e94d0c1e
RR
1692 return (wxDataViewTreeStoreNode*) item.GetID();
1693}
1694
1695wxDataViewTreeStoreContainerNode *wxDataViewTreeStore::FindContainerNode( const wxDataViewItem &item ) const
1696{
1697 if (!item.IsOk())
1698 return (wxDataViewTreeStoreContainerNode*) m_root;
1699
1700 wxDataViewTreeStoreNode* node = (wxDataViewTreeStoreNode*) item.GetID();
b5ec7dd6 1701
e94d0c1e
RR
1702 if (!node->IsContainer())
1703 return NULL;
b5ec7dd6 1704
e94d0c1e
RR
1705 return (wxDataViewTreeStoreContainerNode*) node;
1706}
1707
a75124d0
RR
1708//-----------------------------------------------------------------------------
1709// wxDataViewTreeCtrl
1710//-----------------------------------------------------------------------------
1711
1712IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl,wxDataViewCtrl)
1713
1714BEGIN_EVENT_TABLE(wxDataViewTreeCtrl,wxDataViewCtrl)
1715 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded)
1716 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed)
9c150d5f 1717 EVT_SIZE( wxDataViewTreeCtrl::OnSize )
a75124d0
RR
1718END_EVENT_TABLE()
1719
1720wxDataViewTreeCtrl::wxDataViewTreeCtrl()
1721{
1722 m_imageList = NULL;
1723}
1724
1725wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow *parent, wxWindowID id,
1726 const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
1727{
1728 m_imageList = NULL;
1729 Create( parent, id, pos, size, style, validator );
1730
1731 wxDataViewTreeStore *store = new wxDataViewTreeStore;
1732 AssociateModel( store );
1733 store->DecRef();
9c150d5f 1734
ad386793 1735 AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT,-1);
a75124d0
RR
1736}
1737
1738wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
1739{
1740 if (m_imageList)
1741 delete m_imageList;
1742}
1743
1744bool wxDataViewTreeCtrl::Create( wxWindow *parent, wxWindowID id,
1745 const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
1746{
1747 return wxDataViewCtrl::Create( parent, id, pos, size, style, validator );
1748}
1749
1750void wxDataViewTreeCtrl::SetImageList( wxImageList *imagelist )
1751{
1752 if (m_imageList)
1753 delete m_imageList;
1754
1755 m_imageList = imagelist;
1756}
1757
1758wxDataViewItem wxDataViewTreeCtrl::AppendItem( const wxDataViewItem& parent,
1759 const wxString &text, int iconIndex, wxClientData *data )
1760{
1761 wxIcon icon = wxNullIcon;
1762 if (m_imageList && (iconIndex != -1))
1763 icon = m_imageList->GetIcon( iconIndex );
1764
1765 return GetStore()->AppendItem( parent, text, icon, data );
1766}
1767
1768wxDataViewItem wxDataViewTreeCtrl::PrependItem( const wxDataViewItem& parent,
1769 const wxString &text, int iconIndex, wxClientData *data )
1770{
1771 wxIcon icon = wxNullIcon;
1772 if (m_imageList && (iconIndex != -1))
1773 icon = m_imageList->GetIcon( iconIndex );
1774
1775 return GetStore()->PrependItem( parent, text, icon, data );
1776}
1777
1778wxDataViewItem wxDataViewTreeCtrl::InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
1779 const wxString &text, int iconIndex, wxClientData *data )
1780{
1781 wxIcon icon = wxNullIcon;
1782 if (m_imageList && (iconIndex != -1))
1783 icon = m_imageList->GetIcon( iconIndex );
1784
1785 return GetStore()->InsertItem( parent, previous, text, icon, data );
1786}
1787
1788wxDataViewItem wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem& parent,
1789 const wxString &text, int iconIndex, int expandedIndex, wxClientData *data )
1790{
1791 wxIcon icon = wxNullIcon;
1792 if (m_imageList && (iconIndex != -1))
1793 icon = m_imageList->GetIcon( iconIndex );
1794
1795 wxIcon expanded = wxNullIcon;
1796 if (m_imageList && (expandedIndex != -1))
1797 expanded = m_imageList->GetIcon( expandedIndex );
1798
1799 return GetStore()->PrependContainer( parent, text, icon, expanded, data );
1800}
1801
1802wxDataViewItem wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem& parent,
1803 const wxString &text, int iconIndex, int expandedIndex, wxClientData *data )
1804{
1805 wxIcon icon = wxNullIcon;
1806 if (m_imageList && (iconIndex != -1))
1807 icon = m_imageList->GetIcon( iconIndex );
1808
1809 wxIcon expanded = wxNullIcon;
1810 if (m_imageList && (expandedIndex != -1))
1811 expanded = m_imageList->GetIcon( expandedIndex );
1812
1813 return GetStore()->AppendContainer( parent, text, icon, expanded, data );
1814}
1815
1816wxDataViewItem wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
1817 const wxString &text, int iconIndex, int expandedIndex, wxClientData *data )
1818{
1819 wxIcon icon = wxNullIcon;
1820 if (m_imageList && (iconIndex != -1))
1821 icon = m_imageList->GetIcon( iconIndex );
1822
1823 wxIcon expanded = wxNullIcon;
1824 if (m_imageList && (expandedIndex != -1))
1825 expanded = m_imageList->GetIcon( expandedIndex );
1826
1827 return GetStore()->InsertContainer( parent, previous, text, icon, expanded, data );
1828}
1829
a75124d0
RR
1830void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent &event )
1831{
1832 if (m_imageList) return;
1833
1834 wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() );
1835 if (!container) return;
1836
1837 container->SetExpanded( true );
1838 GetStore()->ItemChanged( event.GetItem() );
1839}
1840
1841void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent &event )
1842{
1843 if (m_imageList) return;
1844
1845 wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() );
1846 if (!container) return;
1847
1848 container->SetExpanded( false );
1849 GetStore()->ItemChanged( event.GetItem() );
1850}
1851
a6aaf49f 1852void wxDataViewTreeCtrl::OnSize( wxSizeEvent &event )
1a07a730 1853{
ad386793 1854#if defined(wxUSE_GENERICDATAVIEWCTRL)
9c150d5f
RR
1855 wxSize size = GetClientSize();
1856 wxDataViewColumn *col = GetColumn( 0 );
ad386793
RR
1857 if (col)
1858 col->SetWidth( size.x );
1a07a730 1859#endif
a6aaf49f 1860 event.Skip( true );
1a07a730 1861}
a75124d0 1862
b5ec7dd6 1863#endif // wxUSE_DATAVIEWCTRL
e0000f94 1864