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