]> git.saurik.com Git - wxWidgets.git/blame - src/common/datavcmn.cpp
don't compile in wx hash code unless we really use it (#9532:12)
[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{
674 return wx_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{
1e510b1e 723 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
777f9cef 724
c232dfe5
RR
725 m_editorCtrl->Hide();
726 wxPendingDelete.Append( m_editorCtrl );
1e510b1e
RR
727}
728
729bool wxDataViewRendererBase::FinishEditing()
730{
1e510b1e
RR
731 wxVariant value;
732 GetValueFromEditorCtrl( m_editorCtrl, value );
733
1e510b1e 734 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
900af470 735
c232dfe5
RR
736 m_editorCtrl->Hide();
737 wxPendingDelete.Append( m_editorCtrl );
777f9cef 738
1e510b1e
RR
739 if (!Validate(value))
740 return false;
900af470 741
1e510b1e 742 unsigned int col = GetOwner()->GetModelColumn();
e0062c04
RR
743 GetOwner()->GetOwner()->GetModel()->SetValue( value, m_item, col );
744 GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item, col );
900af470 745
afebb87b
RR
746 // Now we should send Editing Done event
747 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, GetOwner()->GetOwner()->GetId() );
748 event.SetDataViewColumn( GetOwner() );
749 event.SetModel( GetOwner()->GetOwner()->GetModel() );
8fdaf7de 750 event.SetItem( m_item );
afebb87b 751 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event );
900af470 752
1e510b1e
RR
753 return true;
754}
755
756//-----------------------------------------------------------------------------
757// wxDataViewEditorCtrlEvtHandler
758//-----------------------------------------------------------------------------
759
760BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler, wxEvtHandler)
761 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar)
762 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus)
30715fa1 763 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle)
1e510b1e
RR
764END_EVENT_TABLE()
765
766wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
767 wxControl *editorCtrl,
768 wxDataViewRenderer *owner )
769{
770 m_owner = owner;
771 m_editorCtrl = editorCtrl;
772
773 m_finished = false;
774}
775
30715fa1
RR
776void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent &event )
777{
778 if (m_focusOnIdle)
779 {
780 m_focusOnIdle = false;
781 if (wxWindow::FindFocus() != m_editorCtrl)
782 m_editorCtrl->SetFocus();
783 }
900af470 784
30715fa1
RR
785 event.Skip();
786}
787
1e510b1e
RR
788void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event )
789{
790 switch ( event.m_keyCode )
791 {
792 case WXK_RETURN:
793 m_finished = true;
794 m_owner->FinishEditing();
795 break;
796
797 case WXK_ESCAPE:
798 m_finished = true;
799 m_owner->CancelEditing();
800 break;
801
802 default:
803 event.Skip();
804 }
805}
806
807void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event )
808{
809 if (!m_finished)
810 {
811 m_finished = true;
812 m_owner->FinishEditing();
813 }
814
1e510b1e
RR
815 event.Skip();
816}
817
f554a14b 818// ---------------------------------------------------------
fa28826d 819// wxDataViewColumnBase
f554a14b 820// ---------------------------------------------------------
fa28826d
RR
821
822IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase, wxObject)
823
9861f022 824wxDataViewColumnBase::wxDataViewColumnBase(const wxString& WXUNUSED(title),
baa9ebc4 825 wxDataViewRenderer *renderer,
0a71f9e9 826 unsigned int model_column,
008b5a66 827 int WXUNUSED(width),
87f0efe2 828 wxAlignment WXUNUSED(align),
900af470 829 int WXUNUSED(flags))
fa28826d 830{
baa9ebc4 831 m_renderer = renderer;
6842a71a 832 m_model_column = model_column;
6842a71a 833 m_owner = NULL;
baa9ebc4 834 m_renderer->SetOwner( (wxDataViewColumn*) this );
9861f022
RR
835
836 // NOTE: the wxDataViewColumn's ctor must store the width, align, flags
837 // parameters inside the native control!
6842a71a
RR
838}
839
07a84e7b
RR
840wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap& bitmap,
841 wxDataViewRenderer *renderer,
842 unsigned int model_column,
843 int WXUNUSED(width),
87f0efe2 844 wxAlignment WXUNUSED(align),
900af470 845 int WXUNUSED(flags) )
07a84e7b
RR
846{
847 m_renderer = renderer;
848 m_model_column = model_column;
07a84e7b
RR
849 m_bitmap = bitmap;
850 m_owner = NULL;
851 m_renderer->SetOwner( (wxDataViewColumn*) this );
852}
853
6842a71a
RR
854wxDataViewColumnBase::~wxDataViewColumnBase()
855{
baa9ebc4
RR
856 if (m_renderer)
857 delete m_renderer;
fa28826d
RR
858}
859
9861f022 860int wxDataViewColumnBase::GetFlags() const
fa28826d 861{
9861f022 862 int ret = 0;
fa28826d 863
9861f022
RR
864 if (IsSortable())
865 ret |= wxDATAVIEW_COL_SORTABLE;
866 if (IsResizeable())
867 ret |= wxDATAVIEW_COL_RESIZABLE;
868 if (IsHidden())
869 ret |= wxDATAVIEW_COL_HIDDEN;
fa28826d 870
9861f022 871 return ret;
07a84e7b
RR
872}
873
9861f022 874void wxDataViewColumnBase::SetFlags(int flags)
07a84e7b 875{
9861f022
RR
876 SetSortable((flags & wxDATAVIEW_COL_SORTABLE) != 0);
877 SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0);
878 SetHidden((flags & wxDATAVIEW_COL_HIDDEN) != 0);
99c75ebc 879 SetReorderable((flags & wxDATAVIEW_COL_REORDERABLE) != 0);
07a84e7b
RR
880}
881
f554a14b 882// ---------------------------------------------------------
239eaa41 883// wxDataViewCtrlBase
f554a14b 884// ---------------------------------------------------------
239eaa41
RR
885
886IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl)
887
888wxDataViewCtrlBase::wxDataViewCtrlBase()
889{
890 m_model = NULL;
3b6280be
RR
891 m_expander_column = 0;
892 m_indent = 8;
239eaa41
RR
893}
894
895wxDataViewCtrlBase::~wxDataViewCtrlBase()
896{
87f0efe2
RR
897 if (m_model)
898 {
899 m_model->DecRef();
900 m_model = NULL;
901 }
239eaa41
RR
902}
903
e0062c04 904bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel *model )
239eaa41 905{
1821abd1
RR
906 if (m_model)
907 {
87f0efe2 908 m_model->DecRef(); // discard old model, if any
1821abd1 909 }
87f0efe2
RR
910
911 // add our own reference to the new model:
239eaa41 912 m_model = model;
1821abd1
RR
913 if (m_model)
914 {
900af470 915 m_model->IncRef();
1821abd1 916 }
f554a14b 917
239eaa41
RR
918 return true;
919}
920
e0062c04 921wxDataViewModel* wxDataViewCtrlBase::GetModel()
239eaa41
RR
922{
923 return m_model;
924}
925
a75124d0
RR
926const wxDataViewModel* wxDataViewCtrlBase::GetModel() const
927{
928 return m_model;
929}
930
c7074d44
RR
931wxDataViewColumn *
932wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_column,
87f0efe2 933 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
fa28826d 934{
c7074d44 935 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 936 new wxDataViewTextRenderer( wxT("string"), mode ),
c7074d44
RR
937 model_column, width, align, flags );
938 AppendColumn( ret );
939 return ret;
fa28826d
RR
940}
941
b04fcede
RR
942wxDataViewColumn *
943wxDataViewCtrlBase::AppendIconTextColumn( const wxString &label, unsigned int model_column,
944 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
945{
946 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 947 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
b04fcede
RR
948 model_column, width, align, flags );
949 AppendColumn( ret );
950 return ret;
951}
952
c7074d44
RR
953wxDataViewColumn *
954wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int model_column,
87f0efe2 955 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
605c2c4a 956{
b7fe2261 957
c7074d44 958 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 959 new wxDataViewToggleRenderer( wxT("bool"), mode ),
c7074d44
RR
960 model_column, width, align, flags );
961 AppendColumn( ret );
962 return ret;
605c2c4a
RR
963}
964
c7074d44
RR
965wxDataViewColumn *
966wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, unsigned int model_column,
87f0efe2 967 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
ad63bf41 968{
c7074d44 969 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 970 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
c7074d44
RR
971 model_column, width, align, flags );
972 AppendColumn( ret );
973 return ret;
ad63bf41
RR
974}
975
c7074d44
RR
976wxDataViewColumn *
977wxDataViewCtrlBase::AppendDateColumn( const wxString &label, unsigned int model_column,
87f0efe2 978 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
4d496ecb 979{
c7074d44 980 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 981 new wxDataViewDateRenderer( wxT("datetime"), mode ),
c7074d44
RR
982 model_column, width, align, flags );
983 AppendColumn( ret );
984 return ret;
4d496ecb
RR
985}
986
c7074d44
RR
987wxDataViewColumn *
988wxDataViewCtrlBase::AppendBitmapColumn( const wxString &label, unsigned int model_column,
87f0efe2 989 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 990{
c7074d44 991 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 992 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
c7074d44
RR
993 model_column, width, align, flags );
994 AppendColumn( ret );
995 return ret;
07a84e7b
RR
996}
997
c7074d44
RR
998wxDataViewColumn *
999wxDataViewCtrlBase::AppendTextColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 1000 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1001{
c7074d44 1002 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1003 new wxDataViewTextRenderer( wxT("string"), mode ),
c7074d44
RR
1004 model_column, width, align, flags );
1005 AppendColumn( ret );
1006 return ret;
b04fcede
RR
1007}
1008
1009wxDataViewColumn *
1010wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap &label, unsigned int model_column,
1011 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1012{
1013 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1014 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
b04fcede
RR
1015 model_column, width, align, flags );
1016 AppendColumn( ret );
1017 return ret;
07a84e7b
RR
1018}
1019
c7074d44
RR
1020wxDataViewColumn *
1021wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 1022 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1023{
c7074d44 1024 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1025 new wxDataViewToggleRenderer( wxT("bool"), mode ),
c7074d44
RR
1026 model_column, width, align, flags );
1027 AppendColumn( ret );
1028 return ret;
07a84e7b
RR
1029}
1030
c7074d44
RR
1031wxDataViewColumn *
1032wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 1033 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1034{
c7074d44 1035 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1036 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
c7074d44
RR
1037 model_column, width, align, flags );
1038 AppendColumn( ret );
1039 return ret;
07a84e7b
RR
1040}
1041
c7074d44
RR
1042wxDataViewColumn *
1043wxDataViewCtrlBase::AppendDateColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 1044 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1045{
c7074d44 1046 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1047 new wxDataViewDateRenderer( wxT("datetime"), mode ),
c7074d44
RR
1048 model_column, width, align, flags );
1049 AppendColumn( ret );
1050 return ret;
07a84e7b
RR
1051}
1052
c7074d44
RR
1053wxDataViewColumn *
1054wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 1055 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1056{
c7074d44 1057 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1058 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
c7074d44
RR
1059 model_column, width, align, flags );
1060 AppendColumn( ret );
1061 return ret;
07a84e7b
RR
1062}
1063
736fe67c
RR
1064wxDataViewColumn *
1065wxDataViewCtrlBase::PrependTextColumn( const wxString &label, unsigned int model_column,
1066 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1067{
1068 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1069 new wxDataViewTextRenderer( wxT("string"), mode ),
736fe67c
RR
1070 model_column, width, align, flags );
1071 PrependColumn( ret );
1072 return ret;
1073}
1074
1075wxDataViewColumn *
1076wxDataViewCtrlBase::PrependIconTextColumn( const wxString &label, unsigned int model_column,
1077 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1078{
1079 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1080 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
736fe67c
RR
1081 model_column, width, align, flags );
1082 PrependColumn( ret );
1083 return ret;
1084}
1085
1086wxDataViewColumn *
1087wxDataViewCtrlBase::PrependToggleColumn( const wxString &label, unsigned int model_column,
1088 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1089{
1090
1091 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1092 new wxDataViewToggleRenderer( wxT("bool"), mode ),
736fe67c
RR
1093 model_column, width, align, flags );
1094 PrependColumn( ret );
1095 return ret;
1096}
1097
1098wxDataViewColumn *
1099wxDataViewCtrlBase::PrependProgressColumn( const wxString &label, unsigned int model_column,
1100 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1101{
1102 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1103 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
736fe67c
RR
1104 model_column, width, align, flags );
1105 PrependColumn( ret );
1106 return ret;
1107}
1108
1109wxDataViewColumn *
1110wxDataViewCtrlBase::PrependDateColumn( const wxString &label, unsigned int model_column,
1111 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1112{
1113 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1114 new wxDataViewDateRenderer( wxT("datetime"), mode ),
736fe67c
RR
1115 model_column, width, align, flags );
1116 PrependColumn( ret );
1117 return ret;
1118}
1119
1120wxDataViewColumn *
1121wxDataViewCtrlBase::PrependBitmapColumn( const wxString &label, unsigned int model_column,
1122 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1123{
1124 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1125 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
736fe67c
RR
1126 model_column, width, align, flags );
1127 PrependColumn( ret );
1128 return ret;
1129}
1130
1131wxDataViewColumn *
1132wxDataViewCtrlBase::PrependTextColumn( const wxBitmap &label, unsigned int model_column,
1133 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1134{
1135 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1136 new wxDataViewTextRenderer( wxT("string"), mode ),
736fe67c
RR
1137 model_column, width, align, flags );
1138 PrependColumn( ret );
1139 return ret;
1140}
1141
1142wxDataViewColumn *
1143wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap &label, unsigned int model_column,
1144 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1145{
1146 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1147 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
736fe67c
RR
1148 model_column, width, align, flags );
1149 PrependColumn( ret );
1150 return ret;
1151}
1152
1153wxDataViewColumn *
1154wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap &label, unsigned int model_column,
1155 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1156{
1157 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1158 new wxDataViewToggleRenderer( wxT("bool"), mode ),
736fe67c
RR
1159 model_column, width, align, flags );
1160 PrependColumn( ret );
1161 return ret;
1162}
1163
1164wxDataViewColumn *
1165wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap &label, unsigned int model_column,
1166 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1167{
1168 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1169 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
736fe67c
RR
1170 model_column, width, align, flags );
1171 PrependColumn( ret );
1172 return ret;
1173}
1174
1175wxDataViewColumn *
1176wxDataViewCtrlBase::PrependDateColumn( const wxBitmap &label, unsigned int model_column,
1177 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1178{
1179 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1180 new wxDataViewDateRenderer( wxT("datetime"), mode ),
736fe67c
RR
1181 model_column, width, align, flags );
1182 PrependColumn( ret );
1183 return ret;
1184}
1185
1186wxDataViewColumn *
1187wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap &label, unsigned int model_column,
1188 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1189{
1190 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1191 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
736fe67c
RR
1192 model_column, width, align, flags );
1193 PrependColumn( ret );
1194 return ret;
1195}
1196
c7074d44
RR
1197bool
1198wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col )
fa28826d 1199{
6842a71a 1200 col->SetOwner( (wxDataViewCtrl*) this );
fa28826d
RR
1201 return true;
1202}
1203
736fe67c
RR
1204bool
1205wxDataViewCtrlBase::PrependColumn( wxDataViewColumn *col )
1206{
1207 col->SetOwner( (wxDataViewCtrl*) this );
1208 return true;
1209}
1210
19723525
RR
1211bool
1212wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos), wxDataViewColumn *col )
1213{
1214 col->SetOwner( (wxDataViewCtrl*) this );
1215 return true;
1216}
1217
eb7f97f8
RR
1218// ---------------------------------------------------------
1219// wxDataViewEvent
1220// ---------------------------------------------------------
1221
1222IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent)
1223
d86c1870
RR
1224DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED)
1225
e0062c04 1226DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED)
6977c3bf 1227DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING)
3ecb8a53 1228DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED)
6977c3bf 1229DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING)
3ecb8a53 1230DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED)
e0000f94
RR
1231DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED)
1232DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE)
6608fdab 1233DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED)
e0000f94 1234
63779a3d
RR
1235DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU)
1236
31fb32e1
RR
1237DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK)
1238DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK)
c0a66d92 1239DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED)
e483dfcb 1240DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED)
eb7f97f8 1241
52e750fc
RR
1242
1243// -------------------------------------
1244// wxDataViewSpinRenderer
1245// -------------------------------------
1246
1247wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min, int max, wxDataViewCellMode mode, int alignment ) :
99c75ebc 1248 wxDataViewCustomRenderer(wxT("long"), mode, alignment )
b5ec7dd6 1249{
52e750fc
RR
1250 m_min = min;
1251 m_max = max;
1252}
b5ec7dd6 1253
52e750fc 1254wxControl* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
b5ec7dd6 1255{
52e750fc 1256 long l = value;
659fb68d
RR
1257 wxSize size = labelRect.GetSize();
1258#ifdef __WXMAC__
1259 size = wxSize( wxMax(70,labelRect.width ), -1 );
1260#endif
1261 wxString str;
2ddfe921 1262 str.Printf( wxT("%d"), (int) l );
659fb68d
RR
1263 wxSpinCtrl *sc = new wxSpinCtrl( parent, wxID_ANY, str,
1264 labelRect.GetTopLeft(), size, wxSP_ARROW_KEYS, m_min, m_max, l );
1265#ifdef __WXMAC__
1266 size = sc->GetSize();
1267 wxPoint pt = sc->GetPosition();
1268 sc->SetSize( pt.x - 4, pt.y - 4, size.x, size.y );
1269#endif
777f9cef 1270
659fb68d 1271 return sc;
52e750fc 1272}
b5ec7dd6 1273
52e750fc 1274bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value )
b5ec7dd6 1275{
52e750fc
RR
1276 wxSpinCtrl *sc = (wxSpinCtrl*) editor;
1277 long l = sc->GetValue();
1278 value = l;
1279 return true;
1280}
b5ec7dd6 1281
52e750fc
RR
1282bool wxDataViewSpinRenderer::Render( wxRect rect, wxDC *dc, int state )
1283{
1284 wxString str;
99c75ebc 1285 str.Printf(wxT("%d"), (int) m_data );
52e750fc
RR
1286 RenderText( str, 0, rect, dc, state );
1287 return true;
1288}
b5ec7dd6 1289
52e750fc
RR
1290wxSize wxDataViewSpinRenderer::GetSize() const
1291{
1292 return wxSize(80,16);
1293}
b5ec7dd6 1294
52e750fc
RR
1295bool wxDataViewSpinRenderer::SetValue( const wxVariant &value )
1296{
1297 m_data = value.GetLong();
1298 return true;
1299}
b5ec7dd6 1300
52e750fc
RR
1301bool wxDataViewSpinRenderer::GetValue( wxVariant &value ) const
1302{
1303 value = m_data;
1304 return true;
1305}
1306
e94d0c1e
RR
1307//-----------------------------------------------------------------------------
1308// wxDataViewTreeStore
1309//-----------------------------------------------------------------------------
1310
b5ec7dd6
VZ
1311wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1312 wxDataViewTreeStoreNode *parent,
e94d0c1e
RR
1313 const wxString &text, const wxIcon &icon, wxClientData *data )
1314{
1315 m_parent = parent;
1316 m_text = text;
1317 m_icon = icon;
1318 m_data = data;
1319}
1320
1321wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1322{
1323 if (m_data)
1324 delete m_data;
1325}
b5ec7dd6 1326
e94d0c1e 1327#include "wx/listimpl.cpp"
a76c2f37 1328WX_DEFINE_LIST(wxDataViewTreeStoreNodeList)
e94d0c1e 1329
b5ec7dd6
VZ
1330wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1331 wxDataViewTreeStoreNode *parent, const wxString &text,
e94d0c1e
RR
1332 const wxIcon &icon, const wxIcon &expanded, wxClientData *data ) :
1333 wxDataViewTreeStoreNode( parent, text, icon, data )
1334{
1335 m_iconExpanded = expanded;
a75124d0 1336 m_isExpanded = false;
e94d0c1e
RR
1337 m_children.DeleteContents(true);
1338}
1339
1340wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1341{
1342}
1343
1344//-----------------------------------------------------------------------------
1345
1346wxDataViewTreeStore::wxDataViewTreeStore()
1347{
1348 m_root = new wxDataViewTreeStoreContainerNode( NULL, wxEmptyString );
1349}
1350
1351wxDataViewTreeStore::~wxDataViewTreeStore()
1352{
1353 delete m_root;
1354}
1355
b5ec7dd6 1356wxDataViewItem wxDataViewTreeStore::AppendItem( const wxDataViewItem& parent,
e94d0c1e
RR
1357 const wxString &text, const wxIcon &icon, wxClientData *data )
1358{
1359 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1360 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6
VZ
1361
1362 wxDataViewTreeStoreNode *node =
e94d0c1e
RR
1363 new wxDataViewTreeStoreNode( parent_node, text, icon, data );
1364 parent_node->GetChildren().Append( node );
b5ec7dd6 1365
e94d0c1e
RR
1366 // notify control
1367 ItemAdded( parent, node->GetItem() );
b5ec7dd6 1368
e94d0c1e
RR
1369 return node->GetItem();
1370}
1371
1372wxDataViewItem wxDataViewTreeStore::PrependItem( const wxDataViewItem& parent,
1373 const wxString &text, const wxIcon &icon, wxClientData *data )
1374{
1375 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1376 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6
VZ
1377
1378 wxDataViewTreeStoreNode *node =
e94d0c1e
RR
1379 new wxDataViewTreeStoreNode( parent_node, text, icon, data );
1380 parent_node->GetChildren().Insert( node );
b5ec7dd6 1381
e94d0c1e
RR
1382 // notify control
1383 ItemAdded( parent, node->GetItem() );
b5ec7dd6 1384
e94d0c1e
RR
1385 return node->GetItem();
1386}
1387
b5ec7dd6
VZ
1388wxDataViewItem
1389wxDataViewTreeStore::InsertItem(const wxDataViewItem& WXUNUSED(parent),
1390 const wxDataViewItem& WXUNUSED(previous),
1391 const wxString& WXUNUSED(text),
1392 const wxIcon& WXUNUSED(icon),
1393 wxClientData * WXUNUSED(data))
e94d0c1e
RR
1394{
1395 return wxDataViewItem(0);
1396}
1397
b5ec7dd6
VZ
1398wxDataViewItem wxDataViewTreeStore::PrependContainer( const wxDataViewItem& parent,
1399 const wxString &text, const wxIcon &icon, const wxIcon &expanded,
e94d0c1e
RR
1400 wxClientData *data )
1401{
1402 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1403 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6
VZ
1404
1405 wxDataViewTreeStoreContainerNode *node =
e94d0c1e
RR
1406 new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
1407 parent_node->GetChildren().Insert( node );
b5ec7dd6 1408
e94d0c1e
RR
1409 // notify control
1410 ItemAdded( parent, node->GetItem() );
b5ec7dd6 1411
e94d0c1e
RR
1412 return node->GetItem();
1413}
1414
b5ec7dd6
VZ
1415wxDataViewItem
1416wxDataViewTreeStore::AppendContainer(const wxDataViewItem& parent,
1417 const wxString &text,
1418 const wxIcon& icon,
1419 const wxIcon& expanded,
1420 wxClientData * data)
e94d0c1e
RR
1421{
1422 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1423 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6
VZ
1424
1425 wxDataViewTreeStoreContainerNode *node =
e94d0c1e
RR
1426 new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
1427 parent_node->GetChildren().Append( node );
b5ec7dd6 1428
e94d0c1e
RR
1429 // notify control
1430 ItemAdded( parent, node->GetItem() );
b5ec7dd6 1431
e94d0c1e
RR
1432 return node->GetItem();
1433}
1434
b5ec7dd6
VZ
1435wxDataViewItem
1436wxDataViewTreeStore::InsertContainer(const wxDataViewItem& WXUNUSED(parent),
1437 const wxDataViewItem& WXUNUSED(previous),
1438 const wxString& WXUNUSED(text),
1439 const wxIcon& WXUNUSED(icon),
1440 const wxIcon& WXUNUSED(expanded),
1441 wxClientData * WXUNUSED(data))
e94d0c1e
RR
1442{
1443 return wxDataViewItem(0);
1444}
1445
1446wxDataViewItem wxDataViewTreeStore::GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const
1447{
1448 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1449 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6 1450
e94d0c1e
RR
1451 wxDataViewTreeStoreNodeList::compatibility_iterator node = parent_node->GetChildren().Item( pos );
1452 if (node)
1453 return node->GetData();
b5ec7dd6 1454
e94d0c1e
RR
1455 return wxDataViewItem(0);
1456}
1457
1458int wxDataViewTreeStore::GetChildCount( const wxDataViewItem& parent ) const
1459{
1460 wxDataViewTreeStoreNode *node = FindNode( parent );
1461 if (!node) return -1;
b5ec7dd6 1462
e94d0c1e
RR
1463 if (!node->IsContainer())
1464 return 0;
b5ec7dd6 1465
e94d0c1e 1466 wxDataViewTreeStoreContainerNode *container_node = (wxDataViewTreeStoreContainerNode*) node;
b5ec7dd6 1467 return (int) container_node->GetChildren().GetCount();
e94d0c1e
RR
1468}
1469
1470void wxDataViewTreeStore::SetItemText( const wxDataViewItem& item, const wxString &text )
1471{
1472 wxDataViewTreeStoreNode *node = FindNode( item );
1473 if (!node) return;
b5ec7dd6 1474
e94d0c1e 1475 node->SetText( text );
b5ec7dd6 1476
e94d0c1e
RR
1477 // notify control
1478 ValueChanged( item, 0 );
1479}
1480
1481wxString wxDataViewTreeStore::GetItemText( const wxDataViewItem& item ) const
1482{
1483 wxDataViewTreeStoreNode *node = FindNode( item );
1484 if (!node) return wxEmptyString;
b5ec7dd6 1485
e94d0c1e
RR
1486 return node->GetText();
1487}
1488
1489void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem& item, const wxIcon &icon )
1490{
1491 wxDataViewTreeStoreNode *node = FindNode( item );
1492 if (!node) return;
b5ec7dd6 1493
e94d0c1e 1494 node->SetIcon( icon );
b5ec7dd6 1495
e94d0c1e
RR
1496 // notify control
1497 ValueChanged( item, 0 );
1498}
1499
1500const wxIcon &wxDataViewTreeStore::GetItemIcon( const wxDataViewItem& item ) const
1501{
1502 wxDataViewTreeStoreNode *node = FindNode( item );
1503 if (!node) return wxNullIcon;
b5ec7dd6 1504
e94d0c1e
RR
1505 return node->GetIcon();
1506}
1507
1508void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon )
1509{
1510 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1511 if (!node) return;
b5ec7dd6 1512
e94d0c1e 1513 node->SetExpandedIcon( icon );
b5ec7dd6 1514
e94d0c1e
RR
1515 // notify control
1516 ValueChanged( item, 0 );
1517}
1518
1519const wxIcon &wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem& item ) const
1520{
1521 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1522 if (!node) return wxNullIcon;
b5ec7dd6 1523
e94d0c1e
RR
1524 return node->GetExpandedIcon();
1525}
1526
1527void wxDataViewTreeStore::SetItemData( const wxDataViewItem& item, wxClientData *data )
1528{
1529 wxDataViewTreeStoreNode *node = FindNode( item );
1530 if (!node) return;
b5ec7dd6 1531
e94d0c1e 1532 node->SetData( data );
b5ec7dd6 1533
e94d0c1e
RR
1534 // notify control? only sensible when sorting on client data
1535 // ValueChanged( item, 0 );
1536}
1537
1538wxClientData *wxDataViewTreeStore::GetItemData( const wxDataViewItem& item ) const
1539{
1540 wxDataViewTreeStoreNode *node = FindNode( item );
1541 if (!node) return NULL;
b5ec7dd6 1542
e94d0c1e
RR
1543 return node->GetData();
1544}
1545
1546void wxDataViewTreeStore::DeleteItem( const wxDataViewItem& item )
1547{
1548 if (!item.IsOk()) return;
1549
1550 wxDataViewItem parent_item = GetParent( item );
1551
1552 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent_item );
1553 if (!parent_node) return;
b5ec7dd6 1554
e94d0c1e
RR
1555 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1556 if (!node) return;
b5ec7dd6 1557
e94d0c1e 1558 parent_node->GetChildren().DeleteObject( node );
b5ec7dd6 1559
e94d0c1e
RR
1560 // notify control
1561 ItemDeleted( parent_item, item );
1562}
1563
1564void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem& item )
1565{
1566 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1567 if (!node) return;
b5ec7dd6 1568
e94d0c1e
RR
1569 wxDataViewItemArray array;
1570 wxDataViewTreeStoreNodeList::iterator iter;
1571 for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++)
1572 {
1573 wxDataViewTreeStoreNode* child = *iter;
1574 array.Add( child->GetItem() );
1575 }
b5ec7dd6 1576
e94d0c1e 1577 node->GetChildren().clear();
b5ec7dd6 1578
e94d0c1e
RR
1579 // notify control
1580 ItemsDeleted( item, array );
1581}
1582
1583void wxDataViewTreeStore::DeleteAllItems()
1584{
1585 // TODO
1586}
1587
b5ec7dd6
VZ
1588void
1589wxDataViewTreeStore::GetValue(wxVariant &variant,
1590 const wxDataViewItem &item,
1591 unsigned int WXUNUSED(col)) const
e94d0c1e
RR
1592{
1593 // if (col != 0) return;
b5ec7dd6 1594
e94d0c1e
RR
1595 wxDataViewTreeStoreNode *node = FindNode( item );
1596 if (!node) return;
b5ec7dd6 1597
a75124d0
RR
1598 wxIcon icon( node->GetIcon());
1599 if (node->IsContainer())
1600 {
1601 wxDataViewTreeStoreContainerNode *container = (wxDataViewTreeStoreContainerNode*) node;
1602 if (container->IsExpanded() && container->GetExpandedIcon().IsOk())
1603 icon = container->GetExpandedIcon();
1604 }
777f9cef 1605
a75124d0 1606 wxDataViewIconText data( node->GetText(), icon );
b5ec7dd6 1607
e94d0c1e
RR
1608 variant << data;
1609}
1610
b5ec7dd6
VZ
1611bool
1612wxDataViewTreeStore::SetValue(const wxVariant& variant,
1613 const wxDataViewItem& item,
1614 unsigned int WXUNUSED(col))
e94d0c1e
RR
1615{
1616 // if (col != 0) return false;
b5ec7dd6 1617
e94d0c1e
RR
1618 wxDataViewTreeStoreNode *node = FindNode( item );
1619 if (!node) return false;
b5ec7dd6 1620
e94d0c1e 1621 wxDataViewIconText data;
b5ec7dd6 1622
e94d0c1e 1623 data << variant;
b5ec7dd6 1624
e94d0c1e
RR
1625 node->SetText( data.GetText() );
1626 node->SetIcon( data.GetIcon() );
b5ec7dd6 1627
e94d0c1e
RR
1628 return true;
1629}
1630
1631wxDataViewItem wxDataViewTreeStore::GetParent( const wxDataViewItem &item ) const
1632{
1633 wxDataViewTreeStoreNode *node = FindNode( item );
1634 if (!node) return wxDataViewItem(0);
b5ec7dd6 1635
e94d0c1e
RR
1636 wxDataViewTreeStoreNode *parent = node->GetParent();
1637 if (!parent) return wxDataViewItem(0);
b5ec7dd6 1638
e94d0c1e
RR
1639 if (parent == m_root)
1640 return wxDataViewItem(0);
b5ec7dd6 1641
e94d0c1e
RR
1642 return parent->GetItem();
1643}
1644
1645bool wxDataViewTreeStore::IsContainer( const wxDataViewItem &item ) const
1646{
1647 wxDataViewTreeStoreNode *node = FindNode( item );
1648 if (!node) return false;
b5ec7dd6 1649
e94d0c1e
RR
1650 return node->IsContainer();
1651}
1652
1653unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const
1654{
1655 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
1656 if (!node) return 0;
1657
1658 wxDataViewTreeStoreNodeList::iterator iter;
1659 for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++)
1660 {
1661 wxDataViewTreeStoreNode* child = *iter;
1662 children.Add( child->GetItem() );
1663 }
b5ec7dd6 1664
e94d0c1e
RR
1665 return node->GetChildren().GetCount();
1666}
1667
b5ec7dd6 1668int wxDataViewTreeStore::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
e94d0c1e
RR
1669 unsigned int WXUNUSED(column), bool WXUNUSED(ascending) )
1670{
1671 wxDataViewTreeStoreNode *node1 = FindNode( item1 );
1672 wxDataViewTreeStoreNode *node2 = FindNode( item2 );
b5ec7dd6 1673
e94d0c1e
RR
1674 if (!node1 || !node2)
1675 return 0;
b5ec7dd6
VZ
1676
1677 wxDataViewTreeStoreContainerNode* parent1 =
e94d0c1e 1678 (wxDataViewTreeStoreContainerNode*) node1->GetParent();
b5ec7dd6 1679 wxDataViewTreeStoreContainerNode* parent2 =
e94d0c1e 1680 (wxDataViewTreeStoreContainerNode*) node2->GetParent();
b5ec7dd6 1681
e94d0c1e
RR
1682 if (parent1 != parent2)
1683 {
1684 wxLogError( wxT("Comparing items with different parent.") );
1685 return 0;
1686 }
b5ec7dd6 1687
e94d0c1e
RR
1688 if (node1->IsContainer() && !!node2->IsContainer())
1689 return 1;
b5ec7dd6 1690
e94d0c1e
RR
1691 if (node2->IsContainer() && !!node1->IsContainer())
1692 return -1;
b5ec7dd6 1693
e94d0c1e
RR
1694 return parent1->GetChildren().IndexOf( node1 ) - parent1->GetChildren().IndexOf( node2 );
1695}
1696
1697wxDataViewTreeStoreNode *wxDataViewTreeStore::FindNode( const wxDataViewItem &item ) const
1698{
1699 if (!item.IsOk())
1700 return m_root;
b5ec7dd6 1701
e94d0c1e
RR
1702 return (wxDataViewTreeStoreNode*) item.GetID();
1703}
1704
1705wxDataViewTreeStoreContainerNode *wxDataViewTreeStore::FindContainerNode( const wxDataViewItem &item ) const
1706{
1707 if (!item.IsOk())
1708 return (wxDataViewTreeStoreContainerNode*) m_root;
1709
1710 wxDataViewTreeStoreNode* node = (wxDataViewTreeStoreNode*) item.GetID();
b5ec7dd6 1711
e94d0c1e
RR
1712 if (!node->IsContainer())
1713 return NULL;
b5ec7dd6 1714
e94d0c1e
RR
1715 return (wxDataViewTreeStoreContainerNode*) node;
1716}
1717
a75124d0
RR
1718//-----------------------------------------------------------------------------
1719// wxDataViewTreeCtrl
1720//-----------------------------------------------------------------------------
1721
1722IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl,wxDataViewCtrl)
1723
1724BEGIN_EVENT_TABLE(wxDataViewTreeCtrl,wxDataViewCtrl)
1725 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded)
1726 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed)
9c150d5f 1727 EVT_SIZE( wxDataViewTreeCtrl::OnSize )
a75124d0
RR
1728END_EVENT_TABLE()
1729
1730wxDataViewTreeCtrl::wxDataViewTreeCtrl()
1731{
1732 m_imageList = NULL;
1733}
1734
1735wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow *parent, wxWindowID id,
777f9cef 1736 const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
a75124d0
RR
1737{
1738 m_imageList = NULL;
1739 Create( parent, id, pos, size, style, validator );
777f9cef 1740
a75124d0
RR
1741 wxDataViewTreeStore *store = new wxDataViewTreeStore;
1742 AssociateModel( store );
1743 store->DecRef();
777f9cef 1744
ad386793 1745 AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT,-1);
a75124d0
RR
1746}
1747
1748wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
1749{
1750 if (m_imageList)
1751 delete m_imageList;
1752}
1753
1754bool wxDataViewTreeCtrl::Create( wxWindow *parent, wxWindowID id,
1755 const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
1756{
1757 return wxDataViewCtrl::Create( parent, id, pos, size, style, validator );
1758}
1759
1760void wxDataViewTreeCtrl::SetImageList( wxImageList *imagelist )
1761{
1762 if (m_imageList)
1763 delete m_imageList;
1764
777f9cef 1765 m_imageList = imagelist;
a75124d0 1766}
777f9cef 1767
a75124d0
RR
1768wxDataViewItem wxDataViewTreeCtrl::AppendItem( 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 );
777f9cef 1774
a75124d0
RR
1775 return GetStore()->AppendItem( parent, text, icon, data );
1776}
1777
1778wxDataViewItem wxDataViewTreeCtrl::PrependItem( const wxDataViewItem& parent,
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 );
777f9cef 1784
a75124d0
RR
1785 return GetStore()->PrependItem( parent, text, icon, data );
1786}
1787
1788wxDataViewItem wxDataViewTreeCtrl::InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
1789 const wxString &text, int iconIndex, wxClientData *data )
1790{
1791 wxIcon icon = wxNullIcon;
1792 if (m_imageList && (iconIndex != -1))
1793 icon = m_imageList->GetIcon( iconIndex );
777f9cef 1794
a75124d0
RR
1795 return GetStore()->InsertItem( parent, previous, text, icon, data );
1796}
1797
1798wxDataViewItem wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem& parent,
1799 const wxString &text, int iconIndex, int expandedIndex, wxClientData *data )
1800{
1801 wxIcon icon = wxNullIcon;
1802 if (m_imageList && (iconIndex != -1))
1803 icon = m_imageList->GetIcon( iconIndex );
777f9cef 1804
a75124d0
RR
1805 wxIcon expanded = wxNullIcon;
1806 if (m_imageList && (expandedIndex != -1))
1807 expanded = m_imageList->GetIcon( expandedIndex );
777f9cef 1808
a75124d0
RR
1809 return GetStore()->PrependContainer( parent, text, icon, expanded, data );
1810}
1811
1812wxDataViewItem wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem& parent,
1813 const wxString &text, int iconIndex, int expandedIndex, wxClientData *data )
1814{
1815 wxIcon icon = wxNullIcon;
1816 if (m_imageList && (iconIndex != -1))
1817 icon = m_imageList->GetIcon( iconIndex );
777f9cef 1818
a75124d0
RR
1819 wxIcon expanded = wxNullIcon;
1820 if (m_imageList && (expandedIndex != -1))
1821 expanded = m_imageList->GetIcon( expandedIndex );
777f9cef 1822
a75124d0
RR
1823 return GetStore()->AppendContainer( parent, text, icon, expanded, data );
1824}
1825
1826wxDataViewItem wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
1827 const wxString &text, int iconIndex, int expandedIndex, wxClientData *data )
1828{
1829 wxIcon icon = wxNullIcon;
1830 if (m_imageList && (iconIndex != -1))
1831 icon = m_imageList->GetIcon( iconIndex );
777f9cef 1832
a75124d0
RR
1833 wxIcon expanded = wxNullIcon;
1834 if (m_imageList && (expandedIndex != -1))
1835 expanded = m_imageList->GetIcon( expandedIndex );
777f9cef 1836
a75124d0
RR
1837 return GetStore()->InsertContainer( parent, previous, text, icon, expanded, data );
1838}
1839
a75124d0
RR
1840void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent &event )
1841{
1842 if (m_imageList) return;
777f9cef 1843
a75124d0
RR
1844 wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() );
1845 if (!container) return;
777f9cef 1846
a75124d0
RR
1847 container->SetExpanded( true );
1848 GetStore()->ItemChanged( event.GetItem() );
1849}
1850
1851void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent &event )
1852{
1853 if (m_imageList) return;
777f9cef 1854
a75124d0
RR
1855 wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() );
1856 if (!container) return;
777f9cef 1857
a75124d0
RR
1858 container->SetExpanded( false );
1859 GetStore()->ItemChanged( event.GetItem() );
1860}
1861
a6aaf49f 1862void wxDataViewTreeCtrl::OnSize( wxSizeEvent &event )
1a07a730 1863{
ad386793 1864#if defined(wxUSE_GENERICDATAVIEWCTRL)
9c150d5f
RR
1865 wxSize size = GetClientSize();
1866 wxDataViewColumn *col = GetColumn( 0 );
777f9cef 1867 if (col)
ad386793 1868 col->SetWidth( size.x );
1a07a730 1869#endif
a6aaf49f 1870 event.Skip( true );
1a07a730 1871}
a75124d0 1872
b5ec7dd6 1873#endif // wxUSE_DATAVIEWCTRL
e0000f94 1874