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