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