]> git.saurik.com Git - wxWidgets.git/blame - src/common/datavcmn.cpp
fix memory leak in wxScreenDC, fixes #13249
[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"
c232dfe5 21
f554a14b 22#ifndef WX_PRECOMP
c3c62822
PC
23 #include "wx/dc.h"
24 #include "wx/settings.h"
f554a14b 25 #include "wx/log.h"
c3c62822 26 #include "wx/crt.h"
f554a14b
WS
27#endif
28
8c2654ce 29#include "wx/spinctrl.h"
0cdbed4c 30#include "wx/choice.h"
8c2654ce
PC
31#include "wx/imaglist.h"
32
23318a53 33const char wxDataViewCtrlNameStr[] = "dataviewCtrl";
239eaa41 34
fd61f684
VZ
35namespace
36{
37
38// Custom handler pushed on top of the edit control used by wxDataViewCtrl to
39// forward some events to the main control itself.
40class wxDataViewEditorCtrlEvtHandler: public wxEvtHandler
41{
42public:
64c70359 43 wxDataViewEditorCtrlEvtHandler(wxWindow *editor, wxDataViewRenderer *owner)
fd61f684
VZ
44 {
45 m_editorCtrl = editor;
46 m_owner = owner;
47
48 m_finished = false;
49 }
50
51 void AcceptChangesAndFinish();
52 void SetFocusOnIdle( bool focus = true ) { m_focusOnIdle = focus; }
53
54protected:
55 void OnChar( wxKeyEvent &event );
56 void OnTextEnter( wxCommandEvent &event );
57 void OnKillFocus( wxFocusEvent &event );
58 void OnIdle( wxIdleEvent &event );
59
60private:
61 wxDataViewRenderer *m_owner;
64c70359 62 wxWindow *m_editorCtrl;
fd61f684
VZ
63 bool m_finished;
64 bool m_focusOnIdle;
65
66private:
67 DECLARE_EVENT_TABLE()
68};
69
70} // anonymous namespace
71
86755098
VS
72// ---------------------------------------------------------
73// wxDataViewItemAttr
74// ---------------------------------------------------------
75
76wxFont wxDataViewItemAttr::GetEffectiveFont(const wxFont& font) const
77{
78 if ( !HasFont() )
79 return font;
80
81 wxFont f(font);
82 if ( GetBold() )
83 f.MakeBold();
84 if ( GetItalic() )
85 f.MakeItalic();
86 return f;
87}
88
89
f554a14b 90// ---------------------------------------------------------
854cdb09 91// wxDataViewModelNotifier
f554a14b 92// ---------------------------------------------------------
239eaa41 93
8ab03001 94#include "wx/listimpl.cpp"
a76c2f37 95WX_DEFINE_LIST(wxDataViewModelNotifiers)
9d8fe14a 96
854cdb09
RR
97bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items )
98{
99 size_t count = items.GetCount();
100 size_t i;
101 for (i = 0; i < count; i++)
102 if (!ItemAdded( parent, items[i] )) return false;
b5ec7dd6 103
854cdb09
RR
104 return true;
105}
106
107bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items )
108{
109 size_t count = items.GetCount();
110 size_t i;
111 for (i = 0; i < count; i++)
112 if (!ItemDeleted( parent, items[i] )) return false;
b5ec7dd6 113
854cdb09
RR
114 return true;
115}
116
117bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray &items )
118{
119 size_t count = items.GetCount();
120 size_t i;
121 for (i = 0; i < count; i++)
122 if (!ItemChanged( items[i] )) return false;
b5ec7dd6 123
854cdb09
RR
124 return true;
125}
126
127// ---------------------------------------------------------
128// wxDataViewModel
129// ---------------------------------------------------------
130
e0062c04 131wxDataViewModel::wxDataViewModel()
239eaa41 132{
8f850e28 133 m_notifiers.DeleteContents( true );
239eaa41
RR
134}
135
e0062c04 136bool wxDataViewModel::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
239eaa41 137{
8f850e28
RR
138 bool ret = true;
139
9d8fe14a
RR
140 wxDataViewModelNotifiers::iterator iter;
141 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
8f850e28 142 {
9d8fe14a 143 wxDataViewModelNotifier* notifier = *iter;
e0062c04 144 if (!notifier->ItemAdded( parent, item ))
8f850e28 145 ret = false;
8f850e28 146 }
f554a14b 147
8f850e28 148 return ret;
239eaa41
RR
149}
150
469d3e9b 151bool wxDataViewModel::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
239eaa41 152{
8f850e28
RR
153 bool ret = true;
154
9d8fe14a
RR
155 wxDataViewModelNotifiers::iterator iter;
156 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
8f850e28 157 {
9d8fe14a 158 wxDataViewModelNotifier* notifier = *iter;
469d3e9b 159 if (!notifier->ItemDeleted( parent, item ))
8f850e28 160 ret = false;
8f850e28 161 }
f554a14b 162
8f850e28 163 return ret;
239eaa41
RR
164}
165
e0062c04 166bool wxDataViewModel::ItemChanged( const wxDataViewItem &item )
239eaa41 167{
8f850e28
RR
168 bool ret = true;
169
9d8fe14a
RR
170 wxDataViewModelNotifiers::iterator iter;
171 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
8f850e28 172 {
9d8fe14a 173 wxDataViewModelNotifier* notifier = *iter;
e0062c04 174 if (!notifier->ItemChanged( item ))
8f850e28 175 ret = false;
8f850e28 176 }
f554a14b 177
8f850e28 178 return ret;
239eaa41
RR
179}
180
854cdb09
RR
181bool wxDataViewModel::ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items )
182{
183 bool ret = true;
184
185 wxDataViewModelNotifiers::iterator iter;
186 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
187 {
188 wxDataViewModelNotifier* notifier = *iter;
189 if (!notifier->ItemsAdded( parent, items ))
190 ret = false;
191 }
192
193 return ret;
194}
195
196bool wxDataViewModel::ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items )
197{
198 bool ret = true;
199
200 wxDataViewModelNotifiers::iterator iter;
201 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
202 {
203 wxDataViewModelNotifier* notifier = *iter;
204 if (!notifier->ItemsDeleted( parent, items ))
205 ret = false;
206 }
207
208 return ret;
209}
210
211bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray &items )
212{
213 bool ret = true;
214
215 wxDataViewModelNotifiers::iterator iter;
216 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
217 {
218 wxDataViewModelNotifier* notifier = *iter;
219 if (!notifier->ItemsChanged( items ))
220 ret = false;
221 }
222
223 return ret;
224}
225
e0062c04 226bool wxDataViewModel::ValueChanged( const wxDataViewItem &item, unsigned int col )
239eaa41 227{
8f850e28 228 bool ret = true;
b5d777c7 229
9d8fe14a
RR
230 wxDataViewModelNotifiers::iterator iter;
231 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
b5d777c7 232 {
9d8fe14a 233 wxDataViewModelNotifier* notifier = *iter;
e0062c04 234 if (!notifier->ValueChanged( item, col ))
8f850e28 235 ret = false;
b5d777c7 236 }
f554a14b 237
b5d777c7 238 return ret;
239eaa41
RR
239}
240
e0062c04 241bool wxDataViewModel::Cleared()
4eccd3a1
RR
242{
243 bool ret = true;
244
9d8fe14a
RR
245 wxDataViewModelNotifiers::iterator iter;
246 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
4eccd3a1 247 {
9d8fe14a 248 wxDataViewModelNotifier* notifier = *iter;
8f850e28
RR
249 if (!notifier->Cleared())
250 ret = false;
8f850e28 251 }
f554a14b 252
8f850e28 253 return ret;
239eaa41
RR
254}
255
d8090b5e 256bool wxDataViewModel::BeforeReset()
673810ee
RR
257{
258 bool ret = true;
259
260 wxDataViewModelNotifiers::iterator iter;
261 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
262 {
263 wxDataViewModelNotifier* notifier = *iter;
d8090b5e 264 if (!notifier->BeforeReset())
673810ee
RR
265 ret = false;
266 }
267
268 return ret;
269}
270
271bool wxDataViewModel::AfterReset()
272{
273 bool ret = true;
274
275 wxDataViewModelNotifiers::iterator iter;
276 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
277 {
278 wxDataViewModelNotifier* notifier = *iter;
279 if (!notifier->AfterReset())
280 ret = false;
281 }
282
283 return ret;
284}
285
ef427989
RR
286void wxDataViewModel::Resort()
287{
9d8fe14a
RR
288 wxDataViewModelNotifiers::iterator iter;
289 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
ef427989 290 {
9d8fe14a 291 wxDataViewModelNotifier* notifier = *iter;
ef427989 292 notifier->Resort();
ef427989
RR
293 }
294}
295
e0062c04 296void wxDataViewModel::AddNotifier( wxDataViewModelNotifier *notifier )
239eaa41 297{
9d8fe14a 298 m_notifiers.push_back( notifier );
8f850e28 299 notifier->SetOwner( this );
239eaa41
RR
300}
301
e0062c04 302void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier *notifier )
239eaa41 303{
8f850e28 304 m_notifiers.DeleteObject( notifier );
239eaa41
RR
305}
306
7ee7191c 307int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
862de7b3 308 unsigned int column, bool ascending ) const
ef427989 309{
cf283a47 310 // sort branches before leaves
ed903e42
RR
311 bool item1_is_container = IsContainer(item1);
312 bool item2_is_container = IsContainer(item2);
900af470 313
ed903e42 314 if (item1_is_container && !item2_is_container)
cf283a47 315 return 1;
ed903e42 316 if (item2_is_container && !item1_is_container)
cf283a47 317 return -1;
900af470 318
ef427989 319 wxVariant value1,value2;
7ee7191c
RR
320 GetValue( value1, item1, column );
321 GetValue( value2, item2, column );
322
323 if (!ascending)
324 {
325 wxVariant temp = value1;
326 value1 = value2;
327 value2 = temp;
328 }
cf283a47 329
ef427989
RR
330 if (value1.GetType() == wxT("string"))
331 {
332 wxString str1 = value1.GetString();
333 wxString str2 = value2.GetString();
0be79c8a 334 int res = str1.Cmp( str2 );
777f9cef
VZ
335 if (res)
336 return res;
337 }
338 else if (value1.GetType() == wxT("long"))
ef427989
RR
339 {
340 long l1 = value1.GetLong();
341 long l2 = value2.GetLong();
cf283a47 342 long res = l1-l2;
777f9cef
VZ
343 if (res)
344 return res;
345 }
346 else if (value1.GetType() == wxT("double"))
ef427989
RR
347 {
348 double d1 = value1.GetDouble();
349 double d2 = value2.GetDouble();
777f9cef
VZ
350 if (d1 < d2)
351 return 1;
352 if (d1 > d2)
353 return -1;
354 }
355 else if (value1.GetType() == wxT("datetime"))
ef427989
RR
356 {
357 wxDateTime dt1 = value1.GetDateTime();
358 wxDateTime dt2 = value2.GetDateTime();
777f9cef
VZ
359 if (dt1.IsEarlierThan(dt2))
360 return 1;
361 if (dt2.IsEarlierThan(dt1))
0ead57d5 362 return -1;
ef427989
RR
363 }
364
cf283a47 365 // items must be different
777f9cef
VZ
366 wxUIntPtr id1 = wxPtrToUInt(item1.GetID()),
367 id2 = wxPtrToUInt(item2.GetID());
b7fe2261 368
777f9cef 369 return ascending ? id1 - id2 : id2 - id1;
ef427989
RR
370}
371
c534e696
RR
372// ---------------------------------------------------------
373// wxDataViewIndexListModel
374// ---------------------------------------------------------
375
e39de702 376static int my_sort( int *v1, int *v2 )
c534e696 377{
e39de702
RR
378 return *v2-*v1;
379}
517166e6 380
e39de702
RR
381
382wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size )
383{
384 // IDs are ordered until an item gets deleted or inserted
385 m_ordered = true;
777f9cef 386
e39de702
RR
387 // build initial index
388 unsigned int i;
389 for (i = 1; i < initial_size+1; i++)
777f9cef 390 m_hash.Add( wxUIntToPtr(i) );
9330d5af 391 m_nextFreeID = initial_size + 1;
c534e696
RR
392}
393
33ba5a05
RR
394void wxDataViewIndexListModel::Reset( unsigned int new_size )
395{
d8090b5e 396 /* wxDataViewModel:: */ BeforeReset();
ce00f59b 397
e39de702 398 m_hash.Clear();
777f9cef 399
e39de702
RR
400 // IDs are ordered until an item gets deleted or inserted
401 m_ordered = true;
777f9cef 402
e39de702
RR
403 // build initial index
404 unsigned int i;
405 for (i = 1; i < new_size+1; i++)
777f9cef 406 m_hash.Add( wxUIntToPtr(i) );
3569e0d0 407
9330d5af 408 m_nextFreeID = new_size + 1;
777f9cef 409
d8090b5e 410 /* wxDataViewModel:: */ AfterReset();
33ba5a05
RR
411}
412
c534e696
RR
413void wxDataViewIndexListModel::RowPrepended()
414{
e39de702 415 m_ordered = false;
777f9cef 416
9330d5af
RR
417 unsigned int id = m_nextFreeID;
418 m_nextFreeID++;
3569e0d0 419
777f9cef
VZ
420 m_hash.Insert( wxUIntToPtr(id), 0 );
421 wxDataViewItem item( wxUIntToPtr(id) );
e39de702 422 ItemAdded( wxDataViewItem(0), item );
3569e0d0 423
c534e696
RR
424}
425
426void wxDataViewIndexListModel::RowInserted( unsigned int before )
427{
e39de702 428 m_ordered = false;
777f9cef 429
9330d5af
RR
430 unsigned int id = m_nextFreeID;
431 m_nextFreeID++;
3569e0d0 432
777f9cef
VZ
433 m_hash.Insert( wxUIntToPtr(id), before );
434 wxDataViewItem item( wxUIntToPtr(id) );
e39de702 435 ItemAdded( wxDataViewItem(0), item );
c534e696
RR
436}
437
438void wxDataViewIndexListModel::RowAppended()
439{
9330d5af
RR
440 unsigned int id = m_nextFreeID;
441 m_nextFreeID++;
3569e0d0 442
777f9cef
VZ
443 m_hash.Add( wxUIntToPtr(id) );
444 wxDataViewItem item( wxUIntToPtr(id) );
e39de702 445 ItemAdded( wxDataViewItem(0), item );
c534e696
RR
446}
447
448void wxDataViewIndexListModel::RowDeleted( unsigned int row )
449{
e39de702 450 m_ordered = false;
777f9cef 451
e39de702 452 wxDataViewItem item( m_hash[row] );
0bddfd41 453 /* wxDataViewModel:: */ ItemDeleted( wxDataViewItem(0), item );
e39de702 454 m_hash.RemoveAt( row );
8b6cf9bf
RR
455}
456
457void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt &rows )
458{
459 wxArrayInt sorted = rows;
460 sorted.Sort( my_sort );
777f9cef 461
e39de702 462 m_ordered = false;
777f9cef 463
e39de702
RR
464 wxDataViewItemArray array;
465 unsigned int i;
466 for (i = 0; i < rows.GetCount(); i++)
467 {
8b6cf9bf
RR
468 wxDataViewItem item( m_hash[rows[i]] );
469 array.Add( item );
e39de702 470 }
0bddfd41 471 /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array );
777f9cef 472
e39de702 473 for (i = 0; i < sorted.GetCount(); i++)
8b6cf9bf 474 m_hash.RemoveAt( sorted[i] );
8b6cf9bf
RR
475}
476
c534e696
RR
477void wxDataViewIndexListModel::RowChanged( unsigned int row )
478{
0bddfd41 479 /* wxDataViewModel:: */ ItemChanged( GetItem(row) );
c534e696
RR
480}
481
482void wxDataViewIndexListModel::RowValueChanged( unsigned int row, unsigned int col )
483{
0bddfd41 484 /* wxDataViewModel:: */ ValueChanged( GetItem(row), col );
c534e696
RR
485}
486
487unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) const
488{
e39de702 489 if (m_ordered)
9330d5af 490 return wxPtrToUInt(item.GetID())-1;
777f9cef 491
e39de702
RR
492 // assert for not found
493 return (unsigned int) m_hash.Index( item.GetID() );
c534e696
RR
494}
495
496wxDataViewItem wxDataViewIndexListModel::GetItem( unsigned int row ) const
497{
e39de702
RR
498 wxASSERT( row < m_hash.GetCount() );
499 return wxDataViewItem( m_hash[row] );
c534e696
RR
500}
501
517166e6 502bool wxDataViewIndexListModel::HasDefaultCompare() const
777f9cef 503{
517166e6
RR
504 return !m_ordered;
505}
506
b7fe2261
VZ
507int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1,
508 const wxDataViewItem& item2,
509 unsigned int WXUNUSED(column),
862de7b3 510 bool ascending) const
c534e696 511{
e39de702 512 if (m_ordered)
517166e6 513 {
9330d5af
RR
514 unsigned int pos1 = wxPtrToUInt(item1.GetID()); // -1 not needed here
515 unsigned int pos2 = wxPtrToUInt(item2.GetID()); // -1 not needed here
777f9cef 516
517166e6
RR
517 if (ascending)
518 return pos1 - pos2;
777f9cef 519 else
517166e6
RR
520 return pos2 - pos1;
521 }
777f9cef 522
7ee7191c
RR
523 if (ascending)
524 return GetRow(item1) - GetRow(item2);
b7fe2261 525
7ee7191c 526 return GetRow(item2) - GetRow(item1);
c534e696
RR
527}
528
74fe973b 529unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const
c534e696 530{
74fe973b
RR
531 if (item.IsOk())
532 return 0;
c534e696 533
74fe973b 534 children = m_hash;
777f9cef 535
74fe973b 536 return m_hash.GetCount();
c534e696
RR
537}
538
e39de702
RR
539// ---------------------------------------------------------
540// wxDataViewVirtualListModel
541// ---------------------------------------------------------
542
543#ifndef __WXMAC__
544
545wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size )
546{
9330d5af 547 m_size = initial_size;
e39de702
RR
548}
549
e39de702
RR
550void wxDataViewVirtualListModel::Reset( unsigned int new_size )
551{
d8090b5e 552 /* wxDataViewModel:: */ BeforeReset();
777f9cef 553
673810ee 554 m_size = new_size;
ce00f59b 555
673810ee 556 /* wxDataViewModel:: */ AfterReset();
e39de702
RR
557}
558
559void wxDataViewVirtualListModel::RowPrepended()
560{
9330d5af 561 m_size++;
b879becf 562 wxDataViewItem item( wxUIntToPtr(1) );
e39de702
RR
563 ItemAdded( wxDataViewItem(0), item );
564}
565
566void wxDataViewVirtualListModel::RowInserted( unsigned int before )
567{
9330d5af 568 m_size++;
86ba79ed 569 wxDataViewItem item( wxUIntToPtr(before+1) );
e39de702
RR
570 ItemAdded( wxDataViewItem(0), item );
571}
572
573void wxDataViewVirtualListModel::RowAppended()
574{
9330d5af
RR
575 m_size++;
576 wxDataViewItem item( wxUIntToPtr(m_size) );
e39de702
RR
577 ItemAdded( wxDataViewItem(0), item );
578}
579
580void wxDataViewVirtualListModel::RowDeleted( unsigned int row )
581{
ca21a4e7 582 m_size--;
86ba79ed 583 wxDataViewItem item( wxUIntToPtr(row+1) );
0bddfd41 584 /* wxDataViewModel:: */ ItemDeleted( wxDataViewItem(0), item );
e39de702
RR
585}
586
587void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt &rows )
588{
ca21a4e7 589 m_size -= rows.GetCount();
3569e0d0 590
e39de702
RR
591 wxArrayInt sorted = rows;
592 sorted.Sort( my_sort );
777f9cef 593
e39de702
RR
594 wxDataViewItemArray array;
595 unsigned int i;
596 for (i = 0; i < sorted.GetCount(); i++)
597 {
559c42a5
RR
598 wxDataViewItem item( wxUIntToPtr(sorted[i]+1) );
599 array.Add( item );
e39de702 600 }
0bddfd41 601 /* wxDataViewModel:: */ ItemsDeleted( wxDataViewItem(0), array );
e39de702
RR
602}
603
604void wxDataViewVirtualListModel::RowChanged( unsigned int row )
605{
0bddfd41 606 /* wxDataViewModel:: */ ItemChanged( GetItem(row) );
e39de702
RR
607}
608
609void wxDataViewVirtualListModel::RowValueChanged( unsigned int row, unsigned int col )
610{
0bddfd41 611 /* wxDataViewModel:: */ ValueChanged( GetItem(row), col );
e39de702
RR
612}
613
614unsigned int wxDataViewVirtualListModel::GetRow( const wxDataViewItem &item ) const
615{
86ba79ed 616 return wxPtrToUInt( item.GetID() ) -1;
e39de702
RR
617}
618
619wxDataViewItem wxDataViewVirtualListModel::GetItem( unsigned int row ) const
620{
86ba79ed 621 return wxDataViewItem( wxUIntToPtr(row+1) );
e39de702
RR
622}
623
624bool wxDataViewVirtualListModel::HasDefaultCompare() const
777f9cef 625{
e39de702
RR
626 return true;
627}
628
629int wxDataViewVirtualListModel::Compare(const wxDataViewItem& item1,
630 const wxDataViewItem& item2,
631 unsigned int WXUNUSED(column),
862de7b3 632 bool ascending) const
e39de702 633{
9330d5af
RR
634 unsigned int pos1 = wxPtrToUInt(item1.GetID()); // -1 not needed here
635 unsigned int pos2 = wxPtrToUInt(item2.GetID()); // -1 not needed here
777f9cef 636
e39de702
RR
637 if (ascending)
638 return pos1 - pos2;
777f9cef 639 else
e39de702
RR
640 return pos2 - pos1;
641}
642
e39de702
RR
643unsigned int wxDataViewVirtualListModel::GetChildren( const wxDataViewItem &WXUNUSED(item), wxDataViewItemArray &WXUNUSED(children) ) const
644{
645 return 0; // should we report an error ?
646}
647
648#endif // __WXMAC__
649
89352653
RR
650//-----------------------------------------------------------------------------
651// wxDataViewIconText
652//-----------------------------------------------------------------------------
653
654IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText,wxObject)
655
d350fbec 656IMPLEMENT_VARIANT_OBJECT_EXPORTED(wxDataViewIconText, WXDLLIMPEXP_ADV)
89352653 657
f554a14b 658// ---------------------------------------------------------
baa9ebc4 659// wxDataViewRendererBase
f554a14b 660// ---------------------------------------------------------
6842a71a 661
baa9ebc4 662IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase, wxObject)
6842a71a 663
900af470 664wxDataViewRendererBase::wxDataViewRendererBase( const wxString &varianttype,
9861f022
RR
665 wxDataViewCellMode WXUNUSED(mode),
666 int WXUNUSED(align) )
6842a71a
RR
667{
668 m_variantType = varianttype;
f2b7492a 669 m_owner = NULL;
9861f022
RR
670}
671
c232dfe5
RR
672wxDataViewRendererBase::~wxDataViewRendererBase()
673{
674}
675
9861f022
RR
676const wxDataViewCtrl* wxDataViewRendererBase::GetView() const
677{
5c33522f 678 return const_cast<wxDataViewRendererBase*>(this)->GetOwner()->GetOwner();
6842a71a 679}
f554a14b 680
e0062c04 681bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect )
1e510b1e 682{
0a807957
RR
683 wxDataViewCtrl* dv_ctrl = GetOwner()->GetOwner();
684
685 // Before doing anything we send an event asking if editing of this item is really wanted.
686 wxDataViewEvent start_event( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING, dv_ctrl->GetId() );
687 start_event.SetDataViewColumn( GetOwner() );
688 start_event.SetModel( dv_ctrl->GetModel() );
689 start_event.SetItem( item );
690 start_event.SetEventObject( dv_ctrl );
691 dv_ctrl->GetEventHandler()->ProcessEvent( start_event );
692 if( !start_event.IsAllowed() )
693 return false;
694
e0062c04 695 m_item = item; // remember for later
900af470 696
1e510b1e
RR
697 unsigned int col = GetOwner()->GetModelColumn();
698 wxVariant value;
0a807957
RR
699 dv_ctrl->GetModel()->GetValue( value, item, col );
700
701 m_editorCtrl = CreateEditorCtrl( dv_ctrl->GetMainWindow(), labelRect, value );
702
03647350 703 // there might be no editor control for the given item
0a807957
RR
704 if(!m_editorCtrl)
705 return false;
900af470 706
900af470 707 wxDataViewEditorCtrlEvtHandler *handler =
30715fa1 708 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl, (wxDataViewRenderer*) this );
900af470 709
30715fa1 710 m_editorCtrl->PushEventHandler( handler );
900af470 711
30715fa1
RR
712#if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
713 handler->SetFocusOnIdle();
714#else
1e510b1e 715 m_editorCtrl->SetFocus();
30715fa1
RR
716#endif
717
afebb87b 718 // Now we should send Editing Started event
0a807957 719 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, dv_ctrl->GetId() );
afebb87b 720 event.SetDataViewColumn( GetOwner() );
0a807957 721 event.SetModel( dv_ctrl->GetModel() );
afebb87b 722 event.SetItem( item );
0a807957
RR
723 event.SetEventObject( dv_ctrl );
724 dv_ctrl->GetEventHandler()->ProcessEvent( event );
afebb87b 725
1e510b1e
RR
726 return true;
727}
728
66c02e6e
VZ
729void wxDataViewRendererBase::DestroyEditControl()
730{
b2fd3bea
VZ
731 // Remove our event handler first to prevent it from (recursively) calling
732 // us again as it would do via a call to FinishEditing() when the editor
733 // loses focus when we hide it below.
734 wxEvtHandler * const handler = m_editorCtrl->PopEventHandler();
735
66c02e6e
VZ
736 // Hide the control immediately but don't delete it yet as there could be
737 // some pending messages for it.
738 m_editorCtrl->Hide();
739
66c02e6e
VZ
740 wxPendingDelete.Append(handler);
741 wxPendingDelete.Append(m_editorCtrl);
742}
743
1e510b1e
RR
744void wxDataViewRendererBase::CancelEditing()
745{
0a807957
RR
746 if (!m_editorCtrl)
747 return;
23318a53 748
66c02e6e 749 DestroyEditControl();
1e510b1e
RR
750}
751
752bool wxDataViewRendererBase::FinishEditing()
753{
0a807957
RR
754 if (!m_editorCtrl)
755 return true;
33a1719a 756
1e510b1e
RR
757 wxVariant value;
758 GetValueFromEditorCtrl( m_editorCtrl, value );
759
0a807957
RR
760 wxDataViewCtrl* dv_ctrl = GetOwner()->GetOwner();
761
762 dv_ctrl->GetMainWindow()->SetFocus();
900af470 763
66c02e6e 764 DestroyEditControl();
777f9cef 765
1e510b1e
RR
766 if (!Validate(value))
767 return false;
900af470 768
1e510b1e 769 unsigned int col = GetOwner()->GetModelColumn();
795dac4c 770 dv_ctrl->GetModel()->ChangeValue(value, m_item, col);
900af470 771
afebb87b 772 // Now we should send Editing Done event
0a807957 773 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, dv_ctrl->GetId() );
afebb87b 774 event.SetDataViewColumn( GetOwner() );
0a807957 775 event.SetModel( dv_ctrl->GetModel() );
8fdaf7de 776 event.SetItem( m_item );
0a807957
RR
777 event.SetEventObject( dv_ctrl );
778 dv_ctrl->GetEventHandler()->ProcessEvent( event );
900af470 779
1e510b1e
RR
780 return true;
781}
782
f0ccd2cb
VS
783void wxDataViewRendererBase::PrepareForItem(const wxDataViewModel *model,
784 const wxDataViewItem& item,
785 unsigned column)
786{
787 wxVariant value;
788 model->GetValue(value, item, column);
789 SetValue(value);
790
791 wxDataViewItemAttr attr;
792 model->GetAttr(item, column, attr);
793 SetAttr(attr);
98f8e666
VZ
794
795 SetEnabled(model->IsEnabled(item, column));
f0ccd2cb
VS
796}
797
798
62265c2c
VZ
799// ----------------------------------------------------------------------------
800// wxDataViewCustomRendererBase
801// ----------------------------------------------------------------------------
802
803void
804wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell, wxDC *dc, int state)
805{
806 wxCHECK_RET( dc, "no DC to draw on in custom renderer?" );
807
808 // adjust the rectangle ourselves to account for the alignment
809 wxRect rectItem = rectCell;
810 const int align = GetAlignment();
811 if ( align != wxDVR_DEFAULT_ALIGNMENT )
812 {
813 const wxSize size = GetSize();
814
815 // take alignment into account only if there is enough space, otherwise
816 // show as much contents as possible
817 //
818 // notice that many existing renderers (e.g. wxDataViewSpinRenderer)
819 // return hard-coded size which can be more than they need and if we
820 // trusted their GetSize() we'd draw the text out of cell bounds
821 // entirely
822
823 if ( size.x >= 0 && size.x < rectCell.width )
824 {
825 if ( align & wxALIGN_CENTER_HORIZONTAL )
826 rectItem.x += (rectCell.width - size.x)/2;
827 else if ( align & wxALIGN_RIGHT )
828 rectItem.x += rectCell.width - size.x;
829 // else: wxALIGN_LEFT is the default
830
831 rectItem.width = size.x;
832 }
833
834 if ( size.y >= 0 && size.y < rectCell.height )
835 {
836 if ( align & wxALIGN_CENTER_VERTICAL )
837 rectItem.y += (rectCell.height - size.y)/2;
838 else if ( align & wxALIGN_BOTTOM )
839 rectItem.y += rectCell.height - size.y;
840 // else: wxALIGN_TOP is the default
841
842 rectItem.height = size.y;
843 }
844 }
845
846
847 // set up the DC attributes
848
849 // override custom foreground with the standard one for the selected items
850 // because we currently don't allow changing the selection background and
851 // custom colours may be unreadable on it
852 wxColour col;
853 if ( state & wxDATAVIEW_CELL_SELECTED )
854 col = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
855 else if ( m_attr.HasColour() )
856 col = m_attr.GetColour();
857 else // use default foreground
858 col = GetOwner()->GetOwner()->GetForegroundColour();
859
860 wxDCTextColourChanger changeFg(*dc, col);
861
862 wxDCFontChanger changeFont(*dc);
863 if ( m_attr.HasFont() )
86755098 864 changeFont.Set(m_attr.GetEffectiveFont(dc->GetFont()));
62265c2c
VZ
865
866 Render(rectItem, dc, state);
867}
868
86755098
VS
869wxSize wxDataViewCustomRendererBase::GetTextExtent(const wxString& str) const
870{
871 const wxDataViewCtrl *view = GetView();
872
873 if ( m_attr.HasFont() )
874 {
875 wxFont font(m_attr.GetEffectiveFont(view->GetFont()));
876 wxSize size;
877 view->GetTextExtent(str, &size.x, &size.y, NULL, NULL, &font);
878 return size;
879 }
880 else
881 {
882 return view->GetTextExtent(str);
883 }
884}
885
62265c2c
VZ
886void
887wxDataViewCustomRendererBase::RenderText(const wxString& text,
888 int xoffset,
889 wxRect rect,
890 wxDC *dc,
891 int WXUNUSED(state))
892{
893 wxRect rectText = rect;
894 rectText.x += xoffset;
895 rectText.width -= xoffset;
896
897 // check if we want to ellipsize the text if it doesn't fit
898 wxString ellipsizedText;
899 if ( GetEllipsizeMode() != wxELLIPSIZE_NONE )
900 {
901 ellipsizedText = wxControl::Ellipsize
902 (
903 text,
904 *dc,
905 GetEllipsizeMode(),
c3fe02e9 906 rectText.width,
62265c2c
VZ
907 wxELLIPSIZE_FLAGS_NONE
908 );
909 }
910
9e9cfb91
VZ
911 // get the alignment to use
912 int align = GetAlignment();
913 if ( align == wxDVR_DEFAULT_ALIGNMENT )
914 {
915 // if we don't have an explicit alignment ourselves, use that of the
916 // column in horizontal direction and default vertical alignment
917 align = GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL;
918 }
919
62265c2c 920 dc->DrawLabel(ellipsizedText.empty() ? text : ellipsizedText,
9e9cfb91 921 rectText, align);
62265c2c
VZ
922}
923
1e510b1e
RR
924//-----------------------------------------------------------------------------
925// wxDataViewEditorCtrlEvtHandler
926//-----------------------------------------------------------------------------
927
928BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler, wxEvtHandler)
929 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar)
930 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus)
30715fa1 931 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle)
724852da 932 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter)
1e510b1e
RR
933END_EVENT_TABLE()
934
30715fa1
RR
935void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent &event )
936{
937 if (m_focusOnIdle)
938 {
939 m_focusOnIdle = false;
940 if (wxWindow::FindFocus() != m_editorCtrl)
941 m_editorCtrl->SetFocus();
942 }
900af470 943
30715fa1
RR
944 event.Skip();
945}
946
724852da
RR
947void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent &WXUNUSED(event) )
948{
949 m_finished = true;
950 m_owner->FinishEditing();
951}
952
1e510b1e
RR
953void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event )
954{
955 switch ( event.m_keyCode )
956 {
957 case WXK_RETURN:
958 m_finished = true;
959 m_owner->FinishEditing();
960 break;
961
962 case WXK_ESCAPE:
724852da 963 {
1e510b1e
RR
964 m_finished = true;
965 m_owner->CancelEditing();
966 break;
724852da 967 }
1e510b1e
RR
968 default:
969 event.Skip();
970 }
971}
972
973void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event )
974{
975 if (!m_finished)
976 {
977 m_finished = true;
978 m_owner->FinishEditing();
979 }
980
1e510b1e
RR
981 event.Skip();
982}
983
f554a14b 984// ---------------------------------------------------------
fa28826d 985// wxDataViewColumnBase
f554a14b 986// ---------------------------------------------------------
fa28826d 987
e2bfe673
VZ
988void wxDataViewColumnBase::Init(wxDataViewRenderer *renderer,
989 unsigned int model_column)
07a84e7b
RR
990{
991 m_renderer = renderer;
992 m_model_column = model_column;
07a84e7b
RR
993 m_owner = NULL;
994 m_renderer->SetOwner( (wxDataViewColumn*) this );
995}
996
6842a71a
RR
997wxDataViewColumnBase::~wxDataViewColumnBase()
998{
56873923 999 delete m_renderer;
07a84e7b
RR
1000}
1001
f554a14b 1002// ---------------------------------------------------------
239eaa41 1003// wxDataViewCtrlBase
f554a14b 1004// ---------------------------------------------------------
239eaa41
RR
1005
1006IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl)
1007
1008wxDataViewCtrlBase::wxDataViewCtrlBase()
1009{
1010 m_model = NULL;
3b6280be
RR
1011 m_expander_column = 0;
1012 m_indent = 8;
239eaa41
RR
1013}
1014
1015wxDataViewCtrlBase::~wxDataViewCtrlBase()
1016{
87f0efe2
RR
1017 if (m_model)
1018 {
1019 m_model->DecRef();
1020 m_model = NULL;
1021 }
239eaa41
RR
1022}
1023
e0062c04 1024bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel *model )
239eaa41 1025{
1821abd1
RR
1026 if (m_model)
1027 {
87f0efe2 1028 m_model->DecRef(); // discard old model, if any
1821abd1 1029 }
87f0efe2
RR
1030
1031 // add our own reference to the new model:
239eaa41 1032 m_model = model;
1821abd1
RR
1033 if (m_model)
1034 {
900af470 1035 m_model->IncRef();
1821abd1 1036 }
f554a14b 1037
239eaa41
RR
1038 return true;
1039}
1040
e0062c04 1041wxDataViewModel* wxDataViewCtrlBase::GetModel()
239eaa41
RR
1042{
1043 return m_model;
1044}
1045
a75124d0
RR
1046const wxDataViewModel* wxDataViewCtrlBase::GetModel() const
1047{
1048 return m_model;
1049}
1050
4219d8b0 1051void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem & item )
a881f34e
RR
1052{
1053 if (!m_model) return;
8c2654ce 1054
4219d8b0 1055 if (!item.IsOk()) return;
a881f34e
RR
1056
1057 wxVector<wxDataViewItem> parentChain;
8c2654ce 1058
a881f34e
RR
1059 // at first we get all the parents of the selected item
1060 wxDataViewItem parent = m_model->GetParent(item);
1061 while (parent.IsOk())
1062 {
1063 parentChain.push_back(parent);
1064 parent = m_model->GetParent(parent);
1065 }
8c2654ce 1066
a881f34e
RR
1067 // then we expand the parents, starting at the root
1068 while (!parentChain.empty())
1069 {
1070 Expand(parentChain.back());
1071 parentChain.pop_back();
1072 }
1073}
1074
80ce465c
VZ
1075wxDataViewItem wxDataViewCtrlBase::GetCurrentItem() const
1076{
1077 return HasFlag(wxDV_MULTIPLE) ? DoGetCurrentItem()
1078 : GetSelection();
1079}
1080
1081void wxDataViewCtrlBase::SetCurrentItem(const wxDataViewItem& item)
1082{
1083 wxCHECK_RET( item.IsOk(), "Can't make current an invalid item." );
1084
1085 if ( HasFlag(wxDV_MULTIPLE) )
1086 DoSetCurrentItem(item);
1087 else
1088 Select(item);
1089}
1090
c7074d44
RR
1091wxDataViewColumn *
1092wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_column,
87f0efe2 1093 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
fa28826d 1094{
c7074d44 1095 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1096 new wxDataViewTextRenderer( wxT("string"), mode ),
c7074d44
RR
1097 model_column, width, align, flags );
1098 AppendColumn( ret );
1099 return ret;
fa28826d
RR
1100}
1101
b04fcede
RR
1102wxDataViewColumn *
1103wxDataViewCtrlBase::AppendIconTextColumn( const wxString &label, unsigned int model_column,
1104 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1105{
1106 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1107 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
b04fcede
RR
1108 model_column, width, align, flags );
1109 AppendColumn( ret );
1110 return ret;
1111}
1112
c7074d44
RR
1113wxDataViewColumn *
1114wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int model_column,
87f0efe2 1115 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
605c2c4a 1116{
c7074d44 1117 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1118 new wxDataViewToggleRenderer( wxT("bool"), mode ),
c7074d44
RR
1119 model_column, width, align, flags );
1120 AppendColumn( ret );
1121 return ret;
605c2c4a
RR
1122}
1123
c7074d44
RR
1124wxDataViewColumn *
1125wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, unsigned int model_column,
87f0efe2 1126 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
ad63bf41 1127{
c7074d44 1128 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1129 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
c7074d44
RR
1130 model_column, width, align, flags );
1131 AppendColumn( ret );
1132 return ret;
ad63bf41
RR
1133}
1134
c7074d44
RR
1135wxDataViewColumn *
1136wxDataViewCtrlBase::AppendDateColumn( const wxString &label, unsigned int model_column,
87f0efe2 1137 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
4d496ecb 1138{
c7074d44 1139 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1140 new wxDataViewDateRenderer( wxT("datetime"), mode ),
c7074d44
RR
1141 model_column, width, align, flags );
1142 AppendColumn( ret );
1143 return ret;
4d496ecb
RR
1144}
1145
c7074d44
RR
1146wxDataViewColumn *
1147wxDataViewCtrlBase::AppendBitmapColumn( const wxString &label, unsigned int model_column,
87f0efe2 1148 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1149{
c7074d44 1150 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1151 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
c7074d44
RR
1152 model_column, width, align, flags );
1153 AppendColumn( ret );
1154 return ret;
07a84e7b
RR
1155}
1156
c7074d44
RR
1157wxDataViewColumn *
1158wxDataViewCtrlBase::AppendTextColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 1159 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1160{
c7074d44 1161 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1162 new wxDataViewTextRenderer( wxT("string"), mode ),
c7074d44
RR
1163 model_column, width, align, flags );
1164 AppendColumn( ret );
1165 return ret;
b04fcede
RR
1166}
1167
1168wxDataViewColumn *
1169wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap &label, unsigned int model_column,
1170 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1171{
1172 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1173 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
b04fcede
RR
1174 model_column, width, align, flags );
1175 AppendColumn( ret );
1176 return ret;
07a84e7b
RR
1177}
1178
c7074d44
RR
1179wxDataViewColumn *
1180wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 1181 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1182{
c7074d44 1183 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1184 new wxDataViewToggleRenderer( wxT("bool"), mode ),
c7074d44
RR
1185 model_column, width, align, flags );
1186 AppendColumn( ret );
1187 return ret;
07a84e7b
RR
1188}
1189
c7074d44
RR
1190wxDataViewColumn *
1191wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 1192 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1193{
c7074d44 1194 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1195 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
c7074d44
RR
1196 model_column, width, align, flags );
1197 AppendColumn( ret );
1198 return ret;
07a84e7b
RR
1199}
1200
c7074d44
RR
1201wxDataViewColumn *
1202wxDataViewCtrlBase::AppendDateColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 1203 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1204{
c7074d44 1205 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1206 new wxDataViewDateRenderer( wxT("datetime"), mode ),
c7074d44
RR
1207 model_column, width, align, flags );
1208 AppendColumn( ret );
1209 return ret;
07a84e7b
RR
1210}
1211
c7074d44
RR
1212wxDataViewColumn *
1213wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 1214 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1215{
c7074d44 1216 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1217 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
c7074d44
RR
1218 model_column, width, align, flags );
1219 AppendColumn( ret );
1220 return ret;
07a84e7b
RR
1221}
1222
736fe67c
RR
1223wxDataViewColumn *
1224wxDataViewCtrlBase::PrependTextColumn( const wxString &label, unsigned int model_column,
1225 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1226{
1227 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1228 new wxDataViewTextRenderer( wxT("string"), mode ),
736fe67c
RR
1229 model_column, width, align, flags );
1230 PrependColumn( ret );
1231 return ret;
1232}
1233
1234wxDataViewColumn *
1235wxDataViewCtrlBase::PrependIconTextColumn( const wxString &label, unsigned int model_column,
1236 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1237{
1238 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1239 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
736fe67c
RR
1240 model_column, width, align, flags );
1241 PrependColumn( ret );
1242 return ret;
1243}
1244
1245wxDataViewColumn *
1246wxDataViewCtrlBase::PrependToggleColumn( const wxString &label, unsigned int model_column,
1247 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1248{
1249
1250 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1251 new wxDataViewToggleRenderer( wxT("bool"), mode ),
736fe67c
RR
1252 model_column, width, align, flags );
1253 PrependColumn( ret );
1254 return ret;
1255}
1256
1257wxDataViewColumn *
1258wxDataViewCtrlBase::PrependProgressColumn( const wxString &label, unsigned int model_column,
1259 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1260{
1261 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1262 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
736fe67c
RR
1263 model_column, width, align, flags );
1264 PrependColumn( ret );
1265 return ret;
1266}
1267
1268wxDataViewColumn *
1269wxDataViewCtrlBase::PrependDateColumn( const wxString &label, unsigned int model_column,
1270 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1271{
1272 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1273 new wxDataViewDateRenderer( wxT("datetime"), mode ),
736fe67c
RR
1274 model_column, width, align, flags );
1275 PrependColumn( ret );
1276 return ret;
1277}
1278
1279wxDataViewColumn *
1280wxDataViewCtrlBase::PrependBitmapColumn( const wxString &label, unsigned int model_column,
1281 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1282{
1283 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1284 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
736fe67c
RR
1285 model_column, width, align, flags );
1286 PrependColumn( ret );
1287 return ret;
1288}
1289
1290wxDataViewColumn *
1291wxDataViewCtrlBase::PrependTextColumn( const wxBitmap &label, unsigned int model_column,
1292 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1293{
1294 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1295 new wxDataViewTextRenderer( wxT("string"), mode ),
736fe67c
RR
1296 model_column, width, align, flags );
1297 PrependColumn( ret );
1298 return ret;
1299}
1300
1301wxDataViewColumn *
1302wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap &label, unsigned int model_column,
1303 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1304{
1305 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1306 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
736fe67c
RR
1307 model_column, width, align, flags );
1308 PrependColumn( ret );
1309 return ret;
1310}
1311
1312wxDataViewColumn *
1313wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap &label, unsigned int model_column,
1314 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1315{
1316 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1317 new wxDataViewToggleRenderer( wxT("bool"), mode ),
736fe67c
RR
1318 model_column, width, align, flags );
1319 PrependColumn( ret );
1320 return ret;
1321}
1322
1323wxDataViewColumn *
1324wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap &label, unsigned int model_column,
1325 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1326{
1327 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1328 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
736fe67c
RR
1329 model_column, width, align, flags );
1330 PrependColumn( ret );
1331 return ret;
1332}
1333
1334wxDataViewColumn *
1335wxDataViewCtrlBase::PrependDateColumn( const wxBitmap &label, unsigned int model_column,
1336 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1337{
1338 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1339 new wxDataViewDateRenderer( wxT("datetime"), mode ),
736fe67c
RR
1340 model_column, width, align, flags );
1341 PrependColumn( ret );
1342 return ret;
1343}
1344
1345wxDataViewColumn *
1346wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap &label, unsigned int model_column,
1347 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1348{
1349 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1350 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
736fe67c
RR
1351 model_column, width, align, flags );
1352 PrependColumn( ret );
1353 return ret;
1354}
1355
c7074d44
RR
1356bool
1357wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col )
fa28826d 1358{
6842a71a 1359 col->SetOwner( (wxDataViewCtrl*) this );
fa28826d
RR
1360 return true;
1361}
1362
736fe67c
RR
1363bool
1364wxDataViewCtrlBase::PrependColumn( wxDataViewColumn *col )
1365{
1366 col->SetOwner( (wxDataViewCtrl*) this );
1367 return true;
1368}
1369
23318a53 1370bool
19723525
RR
1371wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos), wxDataViewColumn *col )
1372{
1373 col->SetOwner( (wxDataViewCtrl*) this );
1374 return true;
1375}
1376
eb7f97f8
RR
1377// ---------------------------------------------------------
1378// wxDataViewEvent
1379// ---------------------------------------------------------
1380
1381IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent)
1382
9b11752c
VZ
1383wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEvent );
1384
1385wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, wxDataViewEvent );
1386wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, wxDataViewEvent );
1387wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, wxDataViewEvent );
1388wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, wxDataViewEvent );
1389wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, wxDataViewEvent );
1390wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, wxDataViewEvent );
3e978cf7 1391wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING, wxDataViewEvent );
9b11752c
VZ
1392wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, wxDataViewEvent );
1393wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEvent );
1394
1395wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, wxDataViewEvent );
1396
1397wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, wxDataViewEvent );
1398wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, wxDataViewEvent );
1399wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, wxDataViewEvent );
1400wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED, wxDataViewEvent );
1401
47a8b1e1
VZ
1402wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_CACHE_HINT, wxDataViewEvent );
1403
9b11752c
VZ
1404wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG, wxDataViewEvent );
1405wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE, wxDataViewEvent );
1406wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP, wxDataViewEvent );
52e750fc 1407
47a8b1e1
VZ
1408
1409
52e750fc
RR
1410// -------------------------------------
1411// wxDataViewSpinRenderer
1412// -------------------------------------
1413
1414wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min, int max, wxDataViewCellMode mode, int alignment ) :
99c75ebc 1415 wxDataViewCustomRenderer(wxT("long"), mode, alignment )
b5ec7dd6 1416{
52e750fc
RR
1417 m_min = min;
1418 m_max = max;
1419}
b5ec7dd6 1420
64c70359 1421wxWindow* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
b5ec7dd6 1422{
52e750fc 1423 long l = value;
659fb68d
RR
1424 wxSize size = labelRect.GetSize();
1425#ifdef __WXMAC__
1426 size = wxSize( wxMax(70,labelRect.width ), -1 );
1427#endif
1428 wxString str;
2ddfe921 1429 str.Printf( wxT("%d"), (int) l );
659fb68d 1430 wxSpinCtrl *sc = new wxSpinCtrl( parent, wxID_ANY, str,
724852da 1431 labelRect.GetTopLeft(), size, wxSP_ARROW_KEYS|wxTE_PROCESS_ENTER, m_min, m_max, l );
659fb68d
RR
1432#ifdef __WXMAC__
1433 size = sc->GetSize();
1434 wxPoint pt = sc->GetPosition();
1435 sc->SetSize( pt.x - 4, pt.y - 4, size.x, size.y );
1436#endif
777f9cef 1437
659fb68d 1438 return sc;
52e750fc 1439}
b5ec7dd6 1440
64c70359 1441bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxWindow* editor, wxVariant &value )
b5ec7dd6 1442{
52e750fc
RR
1443 wxSpinCtrl *sc = (wxSpinCtrl*) editor;
1444 long l = sc->GetValue();
1445 value = l;
1446 return true;
1447}
b5ec7dd6 1448
52e750fc
RR
1449bool wxDataViewSpinRenderer::Render( wxRect rect, wxDC *dc, int state )
1450{
1451 wxString str;
99c75ebc 1452 str.Printf(wxT("%d"), (int) m_data );
52e750fc
RR
1453 RenderText( str, 0, rect, dc, state );
1454 return true;
1455}
b5ec7dd6 1456
52e750fc
RR
1457wxSize wxDataViewSpinRenderer::GetSize() const
1458{
1459 return wxSize(80,16);
1460}
b5ec7dd6 1461
52e750fc
RR
1462bool wxDataViewSpinRenderer::SetValue( const wxVariant &value )
1463{
1464 m_data = value.GetLong();
1465 return true;
1466}
b5ec7dd6 1467
52e750fc
RR
1468bool wxDataViewSpinRenderer::GetValue( wxVariant &value ) const
1469{
1470 value = m_data;
1471 return true;
1472}
1473
7448d67c
RR
1474// -------------------------------------
1475// wxDataViewChoiceRenderer
1476// -------------------------------------
1477
e86edab0 1478#if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
7448d67c
RR
1479
1480wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString& choices, wxDataViewCellMode mode, int alignment ) :
1481 wxDataViewCustomRenderer(wxT("string"), mode, alignment )
1482{
1483 m_choices = choices;
1484}
1485
64c70359 1486wxWindow* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
7448d67c 1487{
34b239ec
VS
1488 wxChoice* c = new wxChoice
1489 (
1490 parent,
1491 wxID_ANY,
1492 labelRect.GetTopLeft(),
1493 wxSize(labelRect.GetWidth(), -1),
1494 m_choices
1495 );
a3669fa9 1496 c->Move(labelRect.GetRight() - c->GetRect().width, wxDefaultCoord);
7448d67c 1497 c->SetStringSelection( value.GetString() );
7448d67c
RR
1498 return c;
1499}
1500
64c70359 1501bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxWindow* editor, wxVariant &value )
7448d67c
RR
1502{
1503 wxChoice *c = (wxChoice*) editor;
1504 wxString s = c->GetStringSelection();
1505 value = s;
1506 return true;
1507}
1508
1509bool wxDataViewChoiceRenderer::Render( wxRect rect, wxDC *dc, int state )
1510{
1511 RenderText( m_data, 0, rect, dc, state );
1512 return true;
1513}
1514
1515wxSize wxDataViewChoiceRenderer::GetSize() const
1516{
1517 return wxSize(80,16);
1518}
1519
1520bool wxDataViewChoiceRenderer::SetValue( const wxVariant &value )
1521{
1522 m_data = value.GetString();
1523 return true;
1524}
1525
1526bool wxDataViewChoiceRenderer::GetValue( wxVariant &value ) const
1527{
1528 value = m_data;
1529 return true;
1530}
1531
65887bd0
RR
1532// ----------------------------------------------------------------------------
1533// wxDataViewChoiceByIndexRenderer
1534// ----------------------------------------------------------------------------
1535
1536wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString &choices,
1537 wxDataViewCellMode mode, int alignment ) :
1538 wxDataViewChoiceRenderer( choices, mode, alignment )
1539{
1540}
ce00f59b 1541
64c70359 1542wxWindow* wxDataViewChoiceByIndexRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
65887bd0
RR
1543{
1544 wxVariant string_value = GetChoice( value.GetLong() );
ce00f59b 1545
65887bd0
RR
1546 return wxDataViewChoiceRenderer::CreateEditorCtrl( parent, labelRect, string_value );
1547}
1548
64c70359 1549bool wxDataViewChoiceByIndexRenderer::GetValueFromEditorCtrl( wxWindow* editor, wxVariant &value )
65887bd0
RR
1550{
1551 wxVariant string_value;
1552 if (!wxDataViewChoiceRenderer::GetValueFromEditorCtrl( editor, string_value ))
1553 return false;
1554
1555 value = (long) GetChoices().Index( string_value.GetString() );
1556 return true;
1557}
1558
1559bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant &value )
1560{
1561 wxVariant string_value = GetChoice( value.GetLong() );
1562 return wxDataViewChoiceRenderer::SetValue( string_value );
1563}
ce00f59b 1564
65887bd0
RR
1565bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant &value ) const
1566{
1567 wxVariant string_value;
1568 if (!wxDataViewChoiceRenderer::GetValue( string_value ))
1569 return false;
ce00f59b 1570
65887bd0
RR
1571 value = (long) GetChoices().Index( string_value.GetString() );
1572 return true;
1573}
1574
7448d67c
RR
1575#endif
1576
8eff6c56
RR
1577//-----------------------------------------------------------------------------
1578// wxDataViewListStore
1579//-----------------------------------------------------------------------------
1580
1581wxDataViewListStore::wxDataViewListStore()
1582{
1583}
1584
1585wxDataViewListStore::~wxDataViewListStore()
1586{
1587 wxVector<wxDataViewListStoreLine*>::iterator it;
1588 for (it = m_data.begin(); it != m_data.end(); ++it)
1589 {
1590 wxDataViewListStoreLine* line = *it;
1591 delete line;
1592 }
1593}
1594
1595void wxDataViewListStore::PrependColumn( const wxString &varianttype )
1596{
1597 m_cols.Insert( varianttype, 0 );
1598}
1599
1600void wxDataViewListStore::InsertColumn( unsigned int pos, const wxString &varianttype )
1601{
1602 m_cols.Insert( varianttype, pos );
1603}
1604
1605void wxDataViewListStore::AppendColumn( const wxString &varianttype )
1606{
1607 m_cols.Add( varianttype );
1608}
1609
1610unsigned int wxDataViewListStore::GetColumnCount() const
1611{
1612 return m_cols.GetCount();
1613}
1614
1615wxString wxDataViewListStore::GetColumnType( unsigned int pos ) const
1616{
1617 return m_cols[pos];
1618}
8c2654ce 1619
8eff6c56
RR
1620void wxDataViewListStore::AppendItem( const wxVector<wxVariant> &values, wxClientData *data )
1621{
1622 wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data );
1623 line->m_values = values;
1624 m_data.push_back( line );
8c2654ce 1625
8eff6c56
RR
1626 RowAppended();
1627}
1628
1629void wxDataViewListStore::PrependItem( const wxVector<wxVariant> &values, wxClientData *data )
1630{
1631 wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data );
1632 line->m_values = values;
1633 m_data.insert( m_data.begin(), line );
8c2654ce 1634
8eff6c56
RR
1635 RowPrepended();
1636}
1637
3569e0d0 1638void wxDataViewListStore::InsertItem( unsigned int row, const wxVector<wxVariant> &values,
8af28fab 1639 wxClientData *data )
8eff6c56
RR
1640{
1641 wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data );
1642 line->m_values = values;
1643 m_data.insert( m_data.begin()+row, line );
8c2654ce 1644
8eff6c56
RR
1645 RowInserted( row );
1646}
1647
8af28fab 1648void wxDataViewListStore::DeleteItem( unsigned int row )
8eff6c56
RR
1649{
1650 wxVector<wxDataViewListStoreLine*>::iterator it = m_data.begin() + row;
2d6bba41 1651 delete *it;
8eff6c56 1652 m_data.erase( it );
8c2654ce 1653
8eff6c56
RR
1654 RowDeleted( row );
1655}
1656
1657void wxDataViewListStore::DeleteAllItems()
1658{
1659 wxVector<wxDataViewListStoreLine*>::iterator it;
1660 for (it = m_data.begin(); it != m_data.end(); ++it)
1661 {
1662 wxDataViewListStoreLine* line = *it;
1663 delete line;
1664 }
8c2654ce 1665
8af28fab
FM
1666 m_data.clear();
1667
8eff6c56
RR
1668 Reset( 0 );
1669}
1670
1671void wxDataViewListStore::GetValueByRow( wxVariant &value, unsigned int row, unsigned int col ) const
1672{
1673 wxDataViewListStoreLine *line = m_data[row];
1674 value = line->m_values[col];
1675}
1676
1677bool wxDataViewListStore::SetValueByRow( const wxVariant &value, unsigned int row, unsigned int col )
1678{
1679 wxDataViewListStoreLine *line = m_data[row];
1680 line->m_values[col] = value;
8c2654ce 1681
8eff6c56
RR
1682 return true;
1683}
1684
dc813e6c
RR
1685//-----------------------------------------------------------------------------
1686// wxDataViewListCtrl
1687//-----------------------------------------------------------------------------
1688
1689IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl,wxDataViewCtrl)
1690
1691BEGIN_EVENT_TABLE(wxDataViewListCtrl,wxDataViewCtrl)
1692 EVT_SIZE( wxDataViewListCtrl::OnSize )
1693END_EVENT_TABLE()
1694
1695wxDataViewListCtrl::wxDataViewListCtrl()
1696{
1697}
1698
1699wxDataViewListCtrl::wxDataViewListCtrl( wxWindow *parent, wxWindowID id,
1700 const wxPoint& pos, const wxSize& size, long style,
1701 const wxValidator& validator )
1702{
1703 Create( parent, id, pos, size, style, validator );
dc813e6c
RR
1704}
1705
1706wxDataViewListCtrl::~wxDataViewListCtrl()
1707{
1708}
1709
1710
1711bool wxDataViewListCtrl::Create( wxWindow *parent, wxWindowID id,
1712 const wxPoint& pos, const wxSize& size, long style,
1713 const wxValidator& validator )
1714{
9ba38914
VS
1715 if ( !wxDataViewCtrl::Create( parent, id, pos, size, style, validator ) )
1716 return false;
1717
1718 wxDataViewListStore *store = new wxDataViewListStore;
1719 AssociateModel( store );
1720 store->DecRef();
1721
1722 return true;
dc813e6c
RR
1723}
1724
95b20f41 1725bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn *column, const wxString &varianttype )
dc813e6c
RR
1726{
1727 GetStore()->AppendColumn( varianttype );
95b20f41 1728 return wxDataViewCtrl::AppendColumn( column );
dc813e6c
RR
1729}
1730
95b20f41 1731bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn *column, const wxString &varianttype )
dc813e6c
RR
1732{
1733 GetStore()->PrependColumn( varianttype );
95b20f41 1734 return wxDataViewCtrl::PrependColumn( column );
dc813e6c
RR
1735}
1736
95b20f41 1737bool wxDataViewListCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *column, const wxString &varianttype )
dc813e6c
RR
1738{
1739 GetStore()->InsertColumn( pos, varianttype );
95b20f41
RR
1740 return wxDataViewCtrl::InsertColumn( pos, column );
1741}
1742
1743bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn *col )
1744{
1745 return PrependColumn( col, "string" );
1746}
1747
1748bool wxDataViewListCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *col )
1749{
1750 return InsertColumn( pos, col, "string" );
1751}
1752
1753bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn *col )
1754{
1755 return AppendColumn( col, "string" );
dc813e6c 1756}
8c2654ce 1757
3569e0d0 1758wxDataViewColumn *wxDataViewListCtrl::AppendTextColumn( const wxString &label,
dc813e6c
RR
1759 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1760{
1761 GetStore()->AppendColumn( wxT("string") );
8c2654ce 1762
95b20f41
RR
1763 wxDataViewColumn *ret = new wxDataViewColumn( label,
1764 new wxDataViewTextRenderer( wxT("string"), mode ),
1765 GetStore()->GetColumnCount()-1, width, align, flags );
8c2654ce 1766
95b20f41 1767 wxDataViewCtrl::AppendColumn( ret );
8c2654ce 1768
95b20f41 1769 return ret;
dc813e6c
RR
1770}
1771
3569e0d0 1772wxDataViewColumn *wxDataViewListCtrl::AppendToggleColumn( const wxString &label,
dc813e6c
RR
1773 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1774{
1775 GetStore()->AppendColumn( wxT("bool") );
8c2654ce 1776
95b20f41
RR
1777 wxDataViewColumn *ret = new wxDataViewColumn( label,
1778 new wxDataViewToggleRenderer( wxT("bool"), mode ),
1779 GetStore()->GetColumnCount()-1, width, align, flags );
8c2654ce 1780
95b20f41 1781 wxDataViewCtrl::AppendColumn( ret );
8c2654ce 1782
95b20f41 1783 return ret;
dc813e6c
RR
1784}
1785
3569e0d0 1786wxDataViewColumn *wxDataViewListCtrl::AppendProgressColumn( const wxString &label,
dc813e6c
RR
1787 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1788{
1789 GetStore()->AppendColumn( wxT("long") );
8c2654ce 1790
95b20f41
RR
1791 wxDataViewColumn *ret = new wxDataViewColumn( label,
1792 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
1793 GetStore()->GetColumnCount()-1, width, align, flags );
8c2654ce 1794
95b20f41 1795 wxDataViewCtrl::AppendColumn( ret );
8c2654ce 1796
95b20f41 1797 return ret;
dc813e6c
RR
1798}
1799
3569e0d0 1800wxDataViewColumn *wxDataViewListCtrl::AppendIconTextColumn( const wxString &label,
dc813e6c
RR
1801 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1802{
1803 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
8c2654ce 1804
95b20f41
RR
1805 wxDataViewColumn *ret = new wxDataViewColumn( label,
1806 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
1807 GetStore()->GetColumnCount()-1, width, align, flags );
8c2654ce 1808
95b20f41 1809 wxDataViewCtrl::AppendColumn( ret );
8c2654ce 1810
95b20f41 1811 return ret;
dc813e6c
RR
1812}
1813
1814void wxDataViewListCtrl::OnSize( wxSizeEvent &event )
1815{
1816 event.Skip( true );
1817}
1818
e94d0c1e
RR
1819//-----------------------------------------------------------------------------
1820// wxDataViewTreeStore
1821//-----------------------------------------------------------------------------
1822
b5ec7dd6
VZ
1823wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1824 wxDataViewTreeStoreNode *parent,
e94d0c1e
RR
1825 const wxString &text, const wxIcon &icon, wxClientData *data )
1826{
1827 m_parent = parent;
1828 m_text = text;
1829 m_icon = icon;
1830 m_data = data;
1831}
1832
1833wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1834{
1835 if (m_data)
1836 delete m_data;
1837}
b5ec7dd6 1838
e94d0c1e 1839#include "wx/listimpl.cpp"
a76c2f37 1840WX_DEFINE_LIST(wxDataViewTreeStoreNodeList)
e94d0c1e 1841
b5ec7dd6
VZ
1842wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1843 wxDataViewTreeStoreNode *parent, const wxString &text,
e94d0c1e
RR
1844 const wxIcon &icon, const wxIcon &expanded, wxClientData *data ) :
1845 wxDataViewTreeStoreNode( parent, text, icon, data )
1846{
1847 m_iconExpanded = expanded;
a75124d0 1848 m_isExpanded = false;
e94d0c1e
RR
1849 m_children.DeleteContents(true);
1850}
1851
1852wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1853{
1854}
1855
1856//-----------------------------------------------------------------------------
1857
1858wxDataViewTreeStore::wxDataViewTreeStore()
1859{
1860 m_root = new wxDataViewTreeStoreContainerNode( NULL, wxEmptyString );
1861}
1862
1863wxDataViewTreeStore::~wxDataViewTreeStore()
1864{
1865 delete m_root;
1866}
1867
b5ec7dd6 1868wxDataViewItem wxDataViewTreeStore::AppendItem( const wxDataViewItem& parent,
e94d0c1e
RR
1869 const wxString &text, const wxIcon &icon, wxClientData *data )
1870{
1871 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1872 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6
VZ
1873
1874 wxDataViewTreeStoreNode *node =
e94d0c1e
RR
1875 new wxDataViewTreeStoreNode( parent_node, text, icon, data );
1876 parent_node->GetChildren().Append( node );
b5ec7dd6 1877
e94d0c1e
RR
1878 return node->GetItem();
1879}
1880
1881wxDataViewItem wxDataViewTreeStore::PrependItem( const wxDataViewItem& parent,
1882 const wxString &text, const wxIcon &icon, wxClientData *data )
1883{
1884 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1885 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6
VZ
1886
1887 wxDataViewTreeStoreNode *node =
e94d0c1e
RR
1888 new wxDataViewTreeStoreNode( parent_node, text, icon, data );
1889 parent_node->GetChildren().Insert( node );
b5ec7dd6 1890
e94d0c1e
RR
1891 return node->GetItem();
1892}
1893
b5ec7dd6 1894wxDataViewItem
e700e296
RR
1895wxDataViewTreeStore::InsertItem(const wxDataViewItem& parent,
1896 const wxDataViewItem& previous,
1897 const wxString& text,
1898 const wxIcon& icon,
1899 wxClientData *data)
e94d0c1e 1900{
e700e296
RR
1901 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1902 if (!parent_node) return wxDataViewItem(0);
1903
1904 wxDataViewTreeStoreNode *previous_node = FindNode( previous );
1905 int pos = parent_node->GetChildren().IndexOf( previous_node );
1906 if (pos == wxNOT_FOUND) return wxDataViewItem(0);
1907
1908 wxDataViewTreeStoreNode *node =
1909 new wxDataViewTreeStoreNode( parent_node, text, icon, data );
1910 parent_node->GetChildren().Insert( (size_t) pos, node );
1911
1912 return node->GetItem();
e94d0c1e
RR
1913}
1914
b5ec7dd6
VZ
1915wxDataViewItem wxDataViewTreeStore::PrependContainer( const wxDataViewItem& parent,
1916 const wxString &text, const wxIcon &icon, const wxIcon &expanded,
e94d0c1e
RR
1917 wxClientData *data )
1918{
1919 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1920 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6
VZ
1921
1922 wxDataViewTreeStoreContainerNode *node =
e94d0c1e
RR
1923 new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
1924 parent_node->GetChildren().Insert( node );
b5ec7dd6 1925
e94d0c1e
RR
1926 return node->GetItem();
1927}
1928
b5ec7dd6
VZ
1929wxDataViewItem
1930wxDataViewTreeStore::AppendContainer(const wxDataViewItem& parent,
1931 const wxString &text,
1932 const wxIcon& icon,
1933 const wxIcon& expanded,
1934 wxClientData * data)
e94d0c1e
RR
1935{
1936 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1937 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6
VZ
1938
1939 wxDataViewTreeStoreContainerNode *node =
e94d0c1e
RR
1940 new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
1941 parent_node->GetChildren().Append( node );
b5ec7dd6 1942
e94d0c1e
RR
1943 return node->GetItem();
1944}
1945
b5ec7dd6 1946wxDataViewItem
e700e296
RR
1947wxDataViewTreeStore::InsertContainer(const wxDataViewItem& parent,
1948 const wxDataViewItem& previous,
1949 const wxString& text,
1950 const wxIcon& icon,
1951 const wxIcon& expanded,
1952 wxClientData * data)
e94d0c1e 1953{
e700e296
RR
1954 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1955 if (!parent_node) return wxDataViewItem(0);
8c2654ce 1956
e700e296
RR
1957 wxDataViewTreeStoreNode *previous_node = FindNode( previous );
1958 int pos = parent_node->GetChildren().IndexOf( previous_node );
1959 if (pos == wxNOT_FOUND) return wxDataViewItem(0);
8c2654ce 1960
e700e296
RR
1961 wxDataViewTreeStoreContainerNode *node =
1962 new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
1963 parent_node->GetChildren().Insert( (size_t) pos, node );
1964
1965 return node->GetItem();
e94d0c1e
RR
1966}
1967
8ddda15b
RR
1968bool wxDataViewTreeStore::IsContainer( const wxDataViewItem& item ) const
1969{
1970 wxDataViewTreeStoreNode *node = FindNode( item );
1971 if (!node) return false;
1972
1973 return node->IsContainer();
1974}
1975
e94d0c1e
RR
1976wxDataViewItem wxDataViewTreeStore::GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const
1977{
1978 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1979 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6 1980
e94d0c1e
RR
1981 wxDataViewTreeStoreNodeList::compatibility_iterator node = parent_node->GetChildren().Item( pos );
1982 if (node)
1983 return node->GetData();
b5ec7dd6 1984
e94d0c1e
RR
1985 return wxDataViewItem(0);
1986}
1987
1988int wxDataViewTreeStore::GetChildCount( const wxDataViewItem& parent ) const
1989{
1990 wxDataViewTreeStoreNode *node = FindNode( parent );
1991 if (!node) return -1;
b5ec7dd6 1992
e94d0c1e
RR
1993 if (!node->IsContainer())
1994 return 0;
b5ec7dd6 1995
e94d0c1e 1996 wxDataViewTreeStoreContainerNode *container_node = (wxDataViewTreeStoreContainerNode*) node;
b5ec7dd6 1997 return (int) container_node->GetChildren().GetCount();
e94d0c1e
RR
1998}
1999
2000void wxDataViewTreeStore::SetItemText( const wxDataViewItem& item, const wxString &text )
2001{
2002 wxDataViewTreeStoreNode *node = FindNode( item );
2003 if (!node) return;
b5ec7dd6 2004
e94d0c1e 2005 node->SetText( text );
e94d0c1e
RR
2006}
2007
2008wxString wxDataViewTreeStore::GetItemText( const wxDataViewItem& item ) const
2009{
2010 wxDataViewTreeStoreNode *node = FindNode( item );
2011 if (!node) return wxEmptyString;
b5ec7dd6 2012
e94d0c1e
RR
2013 return node->GetText();
2014}
2015
2016void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem& item, const wxIcon &icon )
2017{
2018 wxDataViewTreeStoreNode *node = FindNode( item );
2019 if (!node) return;
b5ec7dd6 2020
e94d0c1e 2021 node->SetIcon( icon );
e94d0c1e
RR
2022}
2023
2024const wxIcon &wxDataViewTreeStore::GetItemIcon( const wxDataViewItem& item ) const
2025{
2026 wxDataViewTreeStoreNode *node = FindNode( item );
2027 if (!node) return wxNullIcon;
b5ec7dd6 2028
e94d0c1e
RR
2029 return node->GetIcon();
2030}
2031
2032void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon )
2033{
2034 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
2035 if (!node) return;
b5ec7dd6 2036
e94d0c1e 2037 node->SetExpandedIcon( icon );
e94d0c1e
RR
2038}
2039
2040const wxIcon &wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem& item ) const
2041{
2042 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
2043 if (!node) return wxNullIcon;
b5ec7dd6 2044
e94d0c1e
RR
2045 return node->GetExpandedIcon();
2046}
2047
2048void wxDataViewTreeStore::SetItemData( const wxDataViewItem& item, wxClientData *data )
2049{
2050 wxDataViewTreeStoreNode *node = FindNode( item );
2051 if (!node) return;
b5ec7dd6 2052
e94d0c1e 2053 node->SetData( data );
e94d0c1e
RR
2054}
2055
2056wxClientData *wxDataViewTreeStore::GetItemData( const wxDataViewItem& item ) const
2057{
2058 wxDataViewTreeStoreNode *node = FindNode( item );
2059 if (!node) return NULL;
b5ec7dd6 2060
e94d0c1e
RR
2061 return node->GetData();
2062}
2063
2064void wxDataViewTreeStore::DeleteItem( const wxDataViewItem& item )
2065{
2066 if (!item.IsOk()) return;
2067
2068 wxDataViewItem parent_item = GetParent( item );
2069
2070 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent_item );
2071 if (!parent_node) return;
b5ec7dd6 2072
e94d0c1e
RR
2073 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
2074 if (!node) return;
b5ec7dd6 2075
e94d0c1e 2076 parent_node->GetChildren().DeleteObject( node );
e94d0c1e
RR
2077}
2078
2079void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem& item )
2080{
2081 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
2082 if (!node) return;
b5ec7dd6 2083
e94d0c1e 2084 node->GetChildren().clear();
e94d0c1e
RR
2085}
2086
2087void wxDataViewTreeStore::DeleteAllItems()
2088{
3569e0d0 2089 DeleteChildren(m_root);
e94d0c1e
RR
2090}
2091
b5ec7dd6
VZ
2092void
2093wxDataViewTreeStore::GetValue(wxVariant &variant,
2094 const wxDataViewItem &item,
2095 unsigned int WXUNUSED(col)) const
e94d0c1e
RR
2096{
2097 // if (col != 0) return;
b5ec7dd6 2098
e94d0c1e
RR
2099 wxDataViewTreeStoreNode *node = FindNode( item );
2100 if (!node) return;
b5ec7dd6 2101
a75124d0
RR
2102 wxIcon icon( node->GetIcon());
2103 if (node->IsContainer())
2104 {
2105 wxDataViewTreeStoreContainerNode *container = (wxDataViewTreeStoreContainerNode*) node;
2106 if (container->IsExpanded() && container->GetExpandedIcon().IsOk())
2107 icon = container->GetExpandedIcon();
2108 }
777f9cef 2109
a75124d0 2110 wxDataViewIconText data( node->GetText(), icon );
b5ec7dd6 2111
e94d0c1e
RR
2112 variant << data;
2113}
2114
b5ec7dd6
VZ
2115bool
2116wxDataViewTreeStore::SetValue(const wxVariant& variant,
2117 const wxDataViewItem& item,
2118 unsigned int WXUNUSED(col))
e94d0c1e
RR
2119{
2120 // if (col != 0) return false;
b5ec7dd6 2121
e94d0c1e
RR
2122 wxDataViewTreeStoreNode *node = FindNode( item );
2123 if (!node) return false;
b5ec7dd6 2124
e94d0c1e 2125 wxDataViewIconText data;
b5ec7dd6 2126
e94d0c1e 2127 data << variant;
b5ec7dd6 2128
e94d0c1e
RR
2129 node->SetText( data.GetText() );
2130 node->SetIcon( data.GetIcon() );
b5ec7dd6 2131
e94d0c1e
RR
2132 return true;
2133}
2134
2135wxDataViewItem wxDataViewTreeStore::GetParent( const wxDataViewItem &item ) const
2136{
2137 wxDataViewTreeStoreNode *node = FindNode( item );
2138 if (!node) return wxDataViewItem(0);
b5ec7dd6 2139
e94d0c1e
RR
2140 wxDataViewTreeStoreNode *parent = node->GetParent();
2141 if (!parent) return wxDataViewItem(0);
b5ec7dd6 2142
e94d0c1e
RR
2143 if (parent == m_root)
2144 return wxDataViewItem(0);
b5ec7dd6 2145
e94d0c1e
RR
2146 return parent->GetItem();
2147}
2148
e94d0c1e
RR
2149unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const
2150{
2151 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
2152 if (!node) return 0;
2153
2154 wxDataViewTreeStoreNodeList::iterator iter;
2155 for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++)
2156 {
2157 wxDataViewTreeStoreNode* child = *iter;
2158 children.Add( child->GetItem() );
2159 }
b5ec7dd6 2160
e94d0c1e
RR
2161 return node->GetChildren().GetCount();
2162}
2163
b5ec7dd6 2164int wxDataViewTreeStore::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
862de7b3 2165 unsigned int WXUNUSED(column), bool WXUNUSED(ascending) ) const
e94d0c1e
RR
2166{
2167 wxDataViewTreeStoreNode *node1 = FindNode( item1 );
2168 wxDataViewTreeStoreNode *node2 = FindNode( item2 );
b5ec7dd6 2169
e94d0c1e
RR
2170 if (!node1 || !node2)
2171 return 0;
b5ec7dd6
VZ
2172
2173 wxDataViewTreeStoreContainerNode* parent1 =
e94d0c1e 2174 (wxDataViewTreeStoreContainerNode*) node1->GetParent();
b5ec7dd6 2175 wxDataViewTreeStoreContainerNode* parent2 =
e94d0c1e 2176 (wxDataViewTreeStoreContainerNode*) node2->GetParent();
b5ec7dd6 2177
e94d0c1e
RR
2178 if (parent1 != parent2)
2179 {
2180 wxLogError( wxT("Comparing items with different parent.") );
2181 return 0;
2182 }
b5ec7dd6 2183
9c205231 2184 if (node1->IsContainer() && !node2->IsContainer())
e94d0c1e 2185 return -1;
b5ec7dd6 2186
9c205231
RR
2187 if (node2->IsContainer() && !node1->IsContainer())
2188 return 1;
2189
2190 return parent1->GetChildren().IndexOf( node1 ) - parent2->GetChildren().IndexOf( node2 );
e94d0c1e
RR
2191}
2192
2193wxDataViewTreeStoreNode *wxDataViewTreeStore::FindNode( const wxDataViewItem &item ) const
2194{
2195 if (!item.IsOk())
2196 return m_root;
b5ec7dd6 2197
e94d0c1e
RR
2198 return (wxDataViewTreeStoreNode*) item.GetID();
2199}
2200
2201wxDataViewTreeStoreContainerNode *wxDataViewTreeStore::FindContainerNode( const wxDataViewItem &item ) const
2202{
2203 if (!item.IsOk())
2204 return (wxDataViewTreeStoreContainerNode*) m_root;
2205
2206 wxDataViewTreeStoreNode* node = (wxDataViewTreeStoreNode*) item.GetID();
b5ec7dd6 2207
e94d0c1e
RR
2208 if (!node->IsContainer())
2209 return NULL;
b5ec7dd6 2210
e94d0c1e
RR
2211 return (wxDataViewTreeStoreContainerNode*) node;
2212}
2213
a75124d0
RR
2214//-----------------------------------------------------------------------------
2215// wxDataViewTreeCtrl
2216//-----------------------------------------------------------------------------
2217
2218IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl,wxDataViewCtrl)
2219
2220BEGIN_EVENT_TABLE(wxDataViewTreeCtrl,wxDataViewCtrl)
2221 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded)
2222 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed)
9c150d5f 2223 EVT_SIZE( wxDataViewTreeCtrl::OnSize )
a75124d0
RR
2224END_EVENT_TABLE()
2225
43c64cc6 2226wxDataViewTreeCtrl::~wxDataViewTreeCtrl()
a75124d0 2227{
43c64cc6 2228 delete m_imageList;
a75124d0
RR
2229}
2230
43c64cc6 2231bool wxDataViewTreeCtrl::Create( wxWindow *parent, wxWindowID id,
777f9cef 2232 const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
a75124d0 2233{
43c64cc6
VZ
2234 if ( !wxDataViewCtrl::Create( parent, id, pos, size, style, validator ) )
2235 return false;
777f9cef 2236
43c64cc6 2237 // create the standard model and a column in the tree
a75124d0
RR
2238 wxDataViewTreeStore *store = new wxDataViewTreeStore;
2239 AssociateModel( store );
2240 store->DecRef();
777f9cef 2241
0e17930f
VZ
2242 AppendIconTextColumn
2243 (
2244 wxString(), // no label (header is not shown anyhow)
2245 0, // the only model column
2246 wxDATAVIEW_CELL_EDITABLE,
2247 -1, // default width
2248 wxALIGN_NOT, // and alignment
d13b34d3 2249 0 // not resizable
0e17930f 2250 );
a75124d0 2251
43c64cc6 2252 return true;
a75124d0
RR
2253}
2254
2255void wxDataViewTreeCtrl::SetImageList( wxImageList *imagelist )
2256{
43c64cc6 2257 delete m_imageList;
a75124d0 2258
777f9cef 2259 m_imageList = imagelist;
a75124d0 2260}
777f9cef 2261
a75124d0
RR
2262wxDataViewItem wxDataViewTreeCtrl::AppendItem( const wxDataViewItem& parent,
2263 const wxString &text, int iconIndex, wxClientData *data )
2264{
2265 wxIcon icon = wxNullIcon;
2266 if (m_imageList && (iconIndex != -1))
2267 icon = m_imageList->GetIcon( iconIndex );
777f9cef 2268
e700e296 2269 wxDataViewItem res = GetStore()->AppendItem( parent, text, icon, data );
8c2654ce 2270
e700e296 2271 GetStore()->ItemAdded( parent, res );
8c2654ce 2272
e700e296 2273 return res;
a75124d0
RR
2274}
2275
2276wxDataViewItem wxDataViewTreeCtrl::PrependItem( const wxDataViewItem& parent,
2277 const wxString &text, int iconIndex, wxClientData *data )
2278{
2279 wxIcon icon = wxNullIcon;
2280 if (m_imageList && (iconIndex != -1))
2281 icon = m_imageList->GetIcon( iconIndex );
777f9cef 2282
e700e296 2283 wxDataViewItem res = GetStore()->PrependItem( parent, text, icon, data );
8c2654ce 2284
e700e296 2285 GetStore()->ItemAdded( parent, res );
8c2654ce 2286
e700e296 2287 return res;
a75124d0
RR
2288}
2289
2290wxDataViewItem wxDataViewTreeCtrl::InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
2291 const wxString &text, int iconIndex, wxClientData *data )
2292{
2293 wxIcon icon = wxNullIcon;
2294 if (m_imageList && (iconIndex != -1))
2295 icon = m_imageList->GetIcon( iconIndex );
777f9cef 2296
e700e296 2297 wxDataViewItem res = GetStore()->InsertItem( parent, previous, text, icon, data );
8c2654ce 2298
e700e296 2299 GetStore()->ItemAdded( parent, res );
8c2654ce 2300
e700e296 2301 return res;
a75124d0
RR
2302}
2303
2304wxDataViewItem wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem& parent,
2305 const wxString &text, int iconIndex, int expandedIndex, wxClientData *data )
2306{
2307 wxIcon icon = wxNullIcon;
2308 if (m_imageList && (iconIndex != -1))
2309 icon = m_imageList->GetIcon( iconIndex );
777f9cef 2310
a75124d0
RR
2311 wxIcon expanded = wxNullIcon;
2312 if (m_imageList && (expandedIndex != -1))
2313 expanded = m_imageList->GetIcon( expandedIndex );
777f9cef 2314
e700e296 2315 wxDataViewItem res = GetStore()->PrependContainer( parent, text, icon, expanded, data );
8c2654ce 2316
e700e296 2317 GetStore()->ItemAdded( parent, res );
8c2654ce 2318
e700e296 2319 return res;
a75124d0
RR
2320}
2321
2322wxDataViewItem wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem& parent,
2323 const wxString &text, int iconIndex, int expandedIndex, wxClientData *data )
2324{
2325 wxIcon icon = wxNullIcon;
2326 if (m_imageList && (iconIndex != -1))
2327 icon = m_imageList->GetIcon( iconIndex );
777f9cef 2328
a75124d0
RR
2329 wxIcon expanded = wxNullIcon;
2330 if (m_imageList && (expandedIndex != -1))
2331 expanded = m_imageList->GetIcon( expandedIndex );
777f9cef 2332
e700e296 2333 wxDataViewItem res = GetStore()->AppendContainer( parent, text, icon, expanded, data );
8c2654ce 2334
e700e296 2335 GetStore()->ItemAdded( parent, res );
8c2654ce 2336
e700e296 2337 return res;
a75124d0
RR
2338}
2339
2340wxDataViewItem wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
2341 const wxString &text, int iconIndex, int expandedIndex, wxClientData *data )
2342{
2343 wxIcon icon = wxNullIcon;
2344 if (m_imageList && (iconIndex != -1))
2345 icon = m_imageList->GetIcon( iconIndex );
777f9cef 2346
a75124d0
RR
2347 wxIcon expanded = wxNullIcon;
2348 if (m_imageList && (expandedIndex != -1))
2349 expanded = m_imageList->GetIcon( expandedIndex );
777f9cef 2350
e700e296 2351 wxDataViewItem res = GetStore()->InsertContainer( parent, previous, text, icon, expanded, data );
8c2654ce 2352
e700e296 2353 GetStore()->ItemAdded( parent, res );
8c2654ce 2354
e700e296
RR
2355 return res;
2356}
2357
2358void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem& item, const wxString &text )
3569e0d0 2359{
e700e296 2360 GetStore()->SetItemText(item,text);
8c2654ce 2361
e700e296
RR
2362 // notify control
2363 GetStore()->ValueChanged( item, 0 );
2364}
2365
2366void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem& item, const wxIcon &icon )
3569e0d0 2367{
e700e296 2368 GetStore()->SetItemIcon(item,icon);
8c2654ce 2369
e700e296
RR
2370 // notify control
2371 GetStore()->ValueChanged( item, 0 );
2372}
2373
2374void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon )
3569e0d0 2375{
e700e296 2376 GetStore()->SetItemExpandedIcon(item,icon);
8c2654ce 2377
e700e296
RR
2378 // notify control
2379 GetStore()->ValueChanged( item, 0 );
2380}
2381
2382void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem& item )
3569e0d0 2383{
e700e296
RR
2384 wxDataViewItem parent_item = GetStore()->GetParent( item );
2385
2386 GetStore()->DeleteItem(item);
8c2654ce 2387
e700e296
RR
2388 // notify control
2389 GetStore()->ItemDeleted( parent_item, item );
2390}
2391
2392void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem& item )
3569e0d0 2393{
2f21b2be
RR
2394 wxDataViewTreeStoreContainerNode *node = GetStore()->FindContainerNode( item );
2395 if (!node) return;
2396
2397 wxDataViewItemArray array;
2398 wxDataViewTreeStoreNodeList::iterator iter;
2399 for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++)
2400 {
2401 wxDataViewTreeStoreNode* child = *iter;
2402 array.Add( child->GetItem() );
2403 }
2404
2405 GetStore()->DeleteChildren( item );
2406
2407 // notify control
2408 GetStore()->ItemsDeleted( item, array );
e700e296
RR
2409}
2410
2411void wxDataViewTreeCtrl::DeleteAllItems()
3569e0d0 2412{
e700e296 2413 GetStore()->DeleteAllItems();
8c2654ce 2414
e700e296 2415 GetStore()->Cleared();
a75124d0
RR
2416}
2417
a75124d0
RR
2418void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent &event )
2419{
2420 if (m_imageList) return;
777f9cef 2421
a75124d0
RR
2422 wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() );
2423 if (!container) return;
777f9cef 2424
a75124d0 2425 container->SetExpanded( true );
8c2654ce 2426
a75124d0
RR
2427 GetStore()->ItemChanged( event.GetItem() );
2428}
2429
2430void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent &event )
2431{
2432 if (m_imageList) return;
777f9cef 2433
a75124d0
RR
2434 wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() );
2435 if (!container) return;
777f9cef 2436
a75124d0 2437 container->SetExpanded( false );
8c2654ce 2438
a75124d0
RR
2439 GetStore()->ItemChanged( event.GetItem() );
2440}
2441
a6aaf49f 2442void wxDataViewTreeCtrl::OnSize( wxSizeEvent &event )
1a07a730 2443{
ad386793 2444#if defined(wxUSE_GENERICDATAVIEWCTRL)
4bfd0ed5
VZ
2445 // automatically resize our only column to take the entire control width
2446 if ( GetColumnCount() )
2447 {
2448 wxSize size = GetClientSize();
2449 GetColumn(0)->SetWidth(size.x);
2450 }
1a07a730 2451#endif
a6aaf49f 2452 event.Skip( true );
1a07a730 2453}
a75124d0 2454
b5ec7dd6 2455#endif // wxUSE_DATAVIEWCTRL
e0000f94 2456