]> git.saurik.com Git - wxWidgets.git/blame - src/common/datavcmn.cpp
Allow creating wxGraphicsBitmap and wxGraphicsContext from wxImage.
[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++)
d5c4a81f 390 m_hash.Add( wxDataViewItem(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++)
d5c4a81f 406 m_hash.Add( wxDataViewItem(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 420 wxDataViewItem item( wxUIntToPtr(id) );
d5c4a81f 421 m_hash.Insert( item, 0 );
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 433 wxDataViewItem item( wxUIntToPtr(id) );
d5c4a81f 434 m_hash.Insert( item, before );
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 443 wxDataViewItem item( wxUIntToPtr(id) );
d5c4a81f 444 m_hash.Add( item );
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 492 // assert for not found
d5c4a81f 493 return (unsigned int) m_hash.Index( item );
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
dbab29b9 676wxDataViewCtrl* wxDataViewRendererBase::GetView() const
9861f022 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
2a648479 766 bool isValid = Validate(value);
1e510b1e 767 unsigned int col = GetOwner()->GetModelColumn();
900af470 768
afebb87b 769 // Now we should send Editing Done event
0a807957 770 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, dv_ctrl->GetId() );
afebb87b 771 event.SetDataViewColumn( GetOwner() );
0a807957 772 event.SetModel( dv_ctrl->GetModel() );
8fdaf7de 773 event.SetItem( m_item );
2a648479
VZ
774 event.SetValue( value );
775 event.SetColumn( col );
776 event.SetEditCanceled( !isValid );
0a807957
RR
777 event.SetEventObject( dv_ctrl );
778 dv_ctrl->GetEventHandler()->ProcessEvent( event );
900af470 779
2a648479
VZ
780 if ( isValid && event.IsAllowed() )
781 {
782 dv_ctrl->GetModel()->ChangeValue(value, m_item, col);
783 return true;
784 }
785
786 return false;
1e510b1e
RR
787}
788
f0ccd2cb
VS
789void wxDataViewRendererBase::PrepareForItem(const wxDataViewModel *model,
790 const wxDataViewItem& item,
791 unsigned column)
792{
793 wxVariant value;
794 model->GetValue(value, item, column);
795 SetValue(value);
796
797 wxDataViewItemAttr attr;
798 model->GetAttr(item, column, attr);
799 SetAttr(attr);
98f8e666
VZ
800
801 SetEnabled(model->IsEnabled(item, column));
f0ccd2cb
VS
802}
803
804
62265c2c
VZ
805// ----------------------------------------------------------------------------
806// wxDataViewCustomRendererBase
807// ----------------------------------------------------------------------------
808
809void
810wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell, wxDC *dc, int state)
811{
812 wxCHECK_RET( dc, "no DC to draw on in custom renderer?" );
813
814 // adjust the rectangle ourselves to account for the alignment
815 wxRect rectItem = rectCell;
816 const int align = GetAlignment();
817 if ( align != wxDVR_DEFAULT_ALIGNMENT )
818 {
819 const wxSize size = GetSize();
820
821 // take alignment into account only if there is enough space, otherwise
822 // show as much contents as possible
823 //
824 // notice that many existing renderers (e.g. wxDataViewSpinRenderer)
825 // return hard-coded size which can be more than they need and if we
826 // trusted their GetSize() we'd draw the text out of cell bounds
827 // entirely
828
829 if ( size.x >= 0 && size.x < rectCell.width )
830 {
831 if ( align & wxALIGN_CENTER_HORIZONTAL )
832 rectItem.x += (rectCell.width - size.x)/2;
833 else if ( align & wxALIGN_RIGHT )
834 rectItem.x += rectCell.width - size.x;
835 // else: wxALIGN_LEFT is the default
836
837 rectItem.width = size.x;
838 }
839
840 if ( size.y >= 0 && size.y < rectCell.height )
841 {
842 if ( align & wxALIGN_CENTER_VERTICAL )
843 rectItem.y += (rectCell.height - size.y)/2;
844 else if ( align & wxALIGN_BOTTOM )
845 rectItem.y += rectCell.height - size.y;
846 // else: wxALIGN_TOP is the default
847
848 rectItem.height = size.y;
849 }
850 }
851
852
853 // set up the DC attributes
854
855 // override custom foreground with the standard one for the selected items
856 // because we currently don't allow changing the selection background and
857 // custom colours may be unreadable on it
858 wxColour col;
859 if ( state & wxDATAVIEW_CELL_SELECTED )
860 col = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
861 else if ( m_attr.HasColour() )
862 col = m_attr.GetColour();
863 else // use default foreground
864 col = GetOwner()->GetOwner()->GetForegroundColour();
865
866 wxDCTextColourChanger changeFg(*dc, col);
867
868 wxDCFontChanger changeFont(*dc);
869 if ( m_attr.HasFont() )
86755098 870 changeFont.Set(m_attr.GetEffectiveFont(dc->GetFont()));
62265c2c
VZ
871
872 Render(rectItem, dc, state);
873}
874
86755098
VS
875wxSize wxDataViewCustomRendererBase::GetTextExtent(const wxString& str) const
876{
877 const wxDataViewCtrl *view = GetView();
878
879 if ( m_attr.HasFont() )
880 {
881 wxFont font(m_attr.GetEffectiveFont(view->GetFont()));
882 wxSize size;
883 view->GetTextExtent(str, &size.x, &size.y, NULL, NULL, &font);
884 return size;
885 }
886 else
887 {
888 return view->GetTextExtent(str);
889 }
890}
891
62265c2c
VZ
892void
893wxDataViewCustomRendererBase::RenderText(const wxString& text,
894 int xoffset,
895 wxRect rect,
896 wxDC *dc,
897 int WXUNUSED(state))
898{
899 wxRect rectText = rect;
900 rectText.x += xoffset;
901 rectText.width -= xoffset;
902
903 // check if we want to ellipsize the text if it doesn't fit
904 wxString ellipsizedText;
905 if ( GetEllipsizeMode() != wxELLIPSIZE_NONE )
906 {
907 ellipsizedText = wxControl::Ellipsize
908 (
909 text,
910 *dc,
911 GetEllipsizeMode(),
c3fe02e9 912 rectText.width,
62265c2c
VZ
913 wxELLIPSIZE_FLAGS_NONE
914 );
915 }
916
9e9cfb91
VZ
917 // get the alignment to use
918 int align = GetAlignment();
919 if ( align == wxDVR_DEFAULT_ALIGNMENT )
920 {
921 // if we don't have an explicit alignment ourselves, use that of the
922 // column in horizontal direction and default vertical alignment
923 align = GetOwner()->GetAlignment() | wxALIGN_CENTRE_VERTICAL;
924 }
925
62265c2c 926 dc->DrawLabel(ellipsizedText.empty() ? text : ellipsizedText,
9e9cfb91 927 rectText, align);
62265c2c
VZ
928}
929
1e510b1e
RR
930//-----------------------------------------------------------------------------
931// wxDataViewEditorCtrlEvtHandler
932//-----------------------------------------------------------------------------
933
934BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler, wxEvtHandler)
935 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar)
936 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus)
30715fa1 937 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle)
724852da 938 EVT_TEXT_ENTER (-1, wxDataViewEditorCtrlEvtHandler::OnTextEnter)
1e510b1e
RR
939END_EVENT_TABLE()
940
30715fa1
RR
941void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent &event )
942{
943 if (m_focusOnIdle)
944 {
945 m_focusOnIdle = false;
946 if (wxWindow::FindFocus() != m_editorCtrl)
947 m_editorCtrl->SetFocus();
948 }
900af470 949
30715fa1
RR
950 event.Skip();
951}
952
724852da
RR
953void wxDataViewEditorCtrlEvtHandler::OnTextEnter( wxCommandEvent &WXUNUSED(event) )
954{
955 m_finished = true;
956 m_owner->FinishEditing();
957}
958
1e510b1e
RR
959void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event )
960{
961 switch ( event.m_keyCode )
962 {
963 case WXK_RETURN:
964 m_finished = true;
965 m_owner->FinishEditing();
966 break;
967
968 case WXK_ESCAPE:
724852da 969 {
1e510b1e
RR
970 m_finished = true;
971 m_owner->CancelEditing();
972 break;
724852da 973 }
1e510b1e
RR
974 default:
975 event.Skip();
976 }
977}
978
979void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event )
980{
981 if (!m_finished)
982 {
983 m_finished = true;
984 m_owner->FinishEditing();
985 }
986
1e510b1e
RR
987 event.Skip();
988}
989
f554a14b 990// ---------------------------------------------------------
fa28826d 991// wxDataViewColumnBase
f554a14b 992// ---------------------------------------------------------
fa28826d 993
e2bfe673
VZ
994void wxDataViewColumnBase::Init(wxDataViewRenderer *renderer,
995 unsigned int model_column)
07a84e7b
RR
996{
997 m_renderer = renderer;
998 m_model_column = model_column;
07a84e7b
RR
999 m_owner = NULL;
1000 m_renderer->SetOwner( (wxDataViewColumn*) this );
1001}
1002
6842a71a
RR
1003wxDataViewColumnBase::~wxDataViewColumnBase()
1004{
56873923 1005 delete m_renderer;
07a84e7b
RR
1006}
1007
f554a14b 1008// ---------------------------------------------------------
239eaa41 1009// wxDataViewCtrlBase
f554a14b 1010// ---------------------------------------------------------
239eaa41
RR
1011
1012IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl)
1013
1014wxDataViewCtrlBase::wxDataViewCtrlBase()
1015{
1016 m_model = NULL;
3b6280be
RR
1017 m_expander_column = 0;
1018 m_indent = 8;
239eaa41
RR
1019}
1020
1021wxDataViewCtrlBase::~wxDataViewCtrlBase()
1022{
87f0efe2
RR
1023 if (m_model)
1024 {
1025 m_model->DecRef();
1026 m_model = NULL;
1027 }
239eaa41
RR
1028}
1029
e0062c04 1030bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel *model )
239eaa41 1031{
1821abd1
RR
1032 if (m_model)
1033 {
87f0efe2 1034 m_model->DecRef(); // discard old model, if any
1821abd1 1035 }
87f0efe2
RR
1036
1037 // add our own reference to the new model:
239eaa41 1038 m_model = model;
1821abd1
RR
1039 if (m_model)
1040 {
900af470 1041 m_model->IncRef();
1821abd1 1042 }
f554a14b 1043
239eaa41
RR
1044 return true;
1045}
1046
e0062c04 1047wxDataViewModel* wxDataViewCtrlBase::GetModel()
239eaa41
RR
1048{
1049 return m_model;
1050}
1051
a75124d0
RR
1052const wxDataViewModel* wxDataViewCtrlBase::GetModel() const
1053{
1054 return m_model;
1055}
1056
4219d8b0 1057void wxDataViewCtrlBase::ExpandAncestors( const wxDataViewItem & item )
a881f34e
RR
1058{
1059 if (!m_model) return;
8c2654ce 1060
4219d8b0 1061 if (!item.IsOk()) return;
a881f34e
RR
1062
1063 wxVector<wxDataViewItem> parentChain;
8c2654ce 1064
a881f34e
RR
1065 // at first we get all the parents of the selected item
1066 wxDataViewItem parent = m_model->GetParent(item);
1067 while (parent.IsOk())
1068 {
1069 parentChain.push_back(parent);
1070 parent = m_model->GetParent(parent);
1071 }
8c2654ce 1072
a881f34e
RR
1073 // then we expand the parents, starting at the root
1074 while (!parentChain.empty())
1075 {
1076 Expand(parentChain.back());
1077 parentChain.pop_back();
1078 }
1079}
1080
80ce465c
VZ
1081wxDataViewItem wxDataViewCtrlBase::GetCurrentItem() const
1082{
1083 return HasFlag(wxDV_MULTIPLE) ? DoGetCurrentItem()
1084 : GetSelection();
1085}
1086
1087void wxDataViewCtrlBase::SetCurrentItem(const wxDataViewItem& item)
1088{
1089 wxCHECK_RET( item.IsOk(), "Can't make current an invalid item." );
1090
1091 if ( HasFlag(wxDV_MULTIPLE) )
1092 DoSetCurrentItem(item);
1093 else
1094 Select(item);
1095}
1096
fa93d732
VZ
1097wxDataViewItem wxDataViewCtrlBase::GetSelection() const
1098{
1099 if ( GetSelectedItemsCount() != 1 )
1100 return wxDataViewItem();
1101
1102 wxDataViewItemArray selections;
1103 GetSelections(selections);
1104 return selections[0];
1105}
1106
c7074d44
RR
1107wxDataViewColumn *
1108wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_column,
87f0efe2 1109 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
fa28826d 1110{
c7074d44 1111 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1112 new wxDataViewTextRenderer( wxT("string"), mode ),
c7074d44
RR
1113 model_column, width, align, flags );
1114 AppendColumn( ret );
1115 return ret;
fa28826d
RR
1116}
1117
b04fcede
RR
1118wxDataViewColumn *
1119wxDataViewCtrlBase::AppendIconTextColumn( const wxString &label, unsigned int model_column,
1120 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1121{
1122 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1123 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
b04fcede
RR
1124 model_column, width, align, flags );
1125 AppendColumn( ret );
1126 return ret;
1127}
1128
c7074d44
RR
1129wxDataViewColumn *
1130wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int model_column,
87f0efe2 1131 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
605c2c4a 1132{
c7074d44 1133 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1134 new wxDataViewToggleRenderer( wxT("bool"), mode ),
c7074d44
RR
1135 model_column, width, align, flags );
1136 AppendColumn( ret );
1137 return ret;
605c2c4a
RR
1138}
1139
c7074d44
RR
1140wxDataViewColumn *
1141wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, unsigned int model_column,
87f0efe2 1142 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
ad63bf41 1143{
c7074d44 1144 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1145 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
c7074d44
RR
1146 model_column, width, align, flags );
1147 AppendColumn( ret );
1148 return ret;
ad63bf41
RR
1149}
1150
c7074d44
RR
1151wxDataViewColumn *
1152wxDataViewCtrlBase::AppendDateColumn( const wxString &label, unsigned int model_column,
87f0efe2 1153 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
4d496ecb 1154{
c7074d44 1155 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1156 new wxDataViewDateRenderer( wxT("datetime"), mode ),
c7074d44
RR
1157 model_column, width, align, flags );
1158 AppendColumn( ret );
1159 return ret;
4d496ecb
RR
1160}
1161
c7074d44
RR
1162wxDataViewColumn *
1163wxDataViewCtrlBase::AppendBitmapColumn( const wxString &label, unsigned int model_column,
87f0efe2 1164 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1165{
c7074d44 1166 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1167 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
c7074d44
RR
1168 model_column, width, align, flags );
1169 AppendColumn( ret );
1170 return ret;
07a84e7b
RR
1171}
1172
c7074d44
RR
1173wxDataViewColumn *
1174wxDataViewCtrlBase::AppendTextColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 1175 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1176{
c7074d44 1177 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1178 new wxDataViewTextRenderer( wxT("string"), mode ),
c7074d44
RR
1179 model_column, width, align, flags );
1180 AppendColumn( ret );
1181 return ret;
b04fcede
RR
1182}
1183
1184wxDataViewColumn *
1185wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap &label, unsigned int model_column,
1186 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1187{
1188 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1189 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
b04fcede
RR
1190 model_column, width, align, flags );
1191 AppendColumn( ret );
1192 return ret;
07a84e7b
RR
1193}
1194
c7074d44
RR
1195wxDataViewColumn *
1196wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 1197 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1198{
c7074d44 1199 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1200 new wxDataViewToggleRenderer( wxT("bool"), mode ),
c7074d44
RR
1201 model_column, width, align, flags );
1202 AppendColumn( ret );
1203 return ret;
07a84e7b
RR
1204}
1205
c7074d44
RR
1206wxDataViewColumn *
1207wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 1208 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1209{
c7074d44 1210 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1211 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
c7074d44
RR
1212 model_column, width, align, flags );
1213 AppendColumn( ret );
1214 return ret;
07a84e7b
RR
1215}
1216
c7074d44
RR
1217wxDataViewColumn *
1218wxDataViewCtrlBase::AppendDateColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 1219 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1220{
c7074d44 1221 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1222 new wxDataViewDateRenderer( wxT("datetime"), mode ),
c7074d44
RR
1223 model_column, width, align, flags );
1224 AppendColumn( ret );
1225 return ret;
07a84e7b
RR
1226}
1227
c7074d44
RR
1228wxDataViewColumn *
1229wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 1230 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 1231{
c7074d44 1232 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1233 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
c7074d44
RR
1234 model_column, width, align, flags );
1235 AppendColumn( ret );
1236 return ret;
07a84e7b
RR
1237}
1238
736fe67c
RR
1239wxDataViewColumn *
1240wxDataViewCtrlBase::PrependTextColumn( const wxString &label, unsigned int model_column,
1241 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1242{
1243 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1244 new wxDataViewTextRenderer( wxT("string"), mode ),
736fe67c
RR
1245 model_column, width, align, flags );
1246 PrependColumn( ret );
1247 return ret;
1248}
1249
1250wxDataViewColumn *
1251wxDataViewCtrlBase::PrependIconTextColumn( const wxString &label, unsigned int model_column,
1252 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1253{
1254 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1255 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
736fe67c
RR
1256 model_column, width, align, flags );
1257 PrependColumn( ret );
1258 return ret;
1259}
1260
1261wxDataViewColumn *
1262wxDataViewCtrlBase::PrependToggleColumn( const wxString &label, unsigned int model_column,
1263 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1264{
1265
1266 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1267 new wxDataViewToggleRenderer( wxT("bool"), mode ),
736fe67c
RR
1268 model_column, width, align, flags );
1269 PrependColumn( ret );
1270 return ret;
1271}
1272
1273wxDataViewColumn *
1274wxDataViewCtrlBase::PrependProgressColumn( const wxString &label, unsigned int model_column,
1275 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1276{
1277 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1278 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
736fe67c
RR
1279 model_column, width, align, flags );
1280 PrependColumn( ret );
1281 return ret;
1282}
1283
1284wxDataViewColumn *
1285wxDataViewCtrlBase::PrependDateColumn( const wxString &label, unsigned int model_column,
1286 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1287{
1288 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1289 new wxDataViewDateRenderer( wxT("datetime"), mode ),
736fe67c
RR
1290 model_column, width, align, flags );
1291 PrependColumn( ret );
1292 return ret;
1293}
1294
1295wxDataViewColumn *
1296wxDataViewCtrlBase::PrependBitmapColumn( const wxString &label, unsigned int model_column,
1297 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1298{
1299 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1300 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
736fe67c
RR
1301 model_column, width, align, flags );
1302 PrependColumn( ret );
1303 return ret;
1304}
1305
1306wxDataViewColumn *
1307wxDataViewCtrlBase::PrependTextColumn( const wxBitmap &label, unsigned int model_column,
1308 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1309{
1310 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1311 new wxDataViewTextRenderer( wxT("string"), mode ),
736fe67c
RR
1312 model_column, width, align, flags );
1313 PrependColumn( ret );
1314 return ret;
1315}
1316
1317wxDataViewColumn *
1318wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap &label, unsigned int model_column,
1319 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1320{
1321 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1322 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
736fe67c
RR
1323 model_column, width, align, flags );
1324 PrependColumn( ret );
1325 return ret;
1326}
1327
1328wxDataViewColumn *
1329wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap &label, unsigned int model_column,
1330 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1331{
1332 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1333 new wxDataViewToggleRenderer( wxT("bool"), mode ),
736fe67c
RR
1334 model_column, width, align, flags );
1335 PrependColumn( ret );
1336 return ret;
1337}
1338
1339wxDataViewColumn *
1340wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap &label, unsigned int model_column,
1341 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1342{
1343 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1344 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
736fe67c
RR
1345 model_column, width, align, flags );
1346 PrependColumn( ret );
1347 return ret;
1348}
1349
1350wxDataViewColumn *
1351wxDataViewCtrlBase::PrependDateColumn( const wxBitmap &label, unsigned int model_column,
1352 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1353{
1354 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1355 new wxDataViewDateRenderer( wxT("datetime"), mode ),
736fe67c
RR
1356 model_column, width, align, flags );
1357 PrependColumn( ret );
1358 return ret;
1359}
1360
1361wxDataViewColumn *
1362wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap &label, unsigned int model_column,
1363 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1364{
1365 wxDataViewColumn *ret = new wxDataViewColumn( label,
f2b7492a 1366 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ),
736fe67c
RR
1367 model_column, width, align, flags );
1368 PrependColumn( ret );
1369 return ret;
1370}
1371
c7074d44
RR
1372bool
1373wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col )
fa28826d 1374{
6842a71a 1375 col->SetOwner( (wxDataViewCtrl*) this );
fa28826d
RR
1376 return true;
1377}
1378
736fe67c
RR
1379bool
1380wxDataViewCtrlBase::PrependColumn( wxDataViewColumn *col )
1381{
1382 col->SetOwner( (wxDataViewCtrl*) this );
1383 return true;
1384}
1385
23318a53 1386bool
19723525
RR
1387wxDataViewCtrlBase::InsertColumn( unsigned int WXUNUSED(pos), wxDataViewColumn *col )
1388{
1389 col->SetOwner( (wxDataViewCtrl*) this );
1390 return true;
1391}
1392
eb7f97f8
RR
1393// ---------------------------------------------------------
1394// wxDataViewEvent
1395// ---------------------------------------------------------
1396
1397IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent)
1398
9b11752c
VZ
1399wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, wxDataViewEvent );
1400
1401wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, wxDataViewEvent );
1402wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, wxDataViewEvent );
1403wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, wxDataViewEvent );
1404wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, wxDataViewEvent );
1405wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, wxDataViewEvent );
1406wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, wxDataViewEvent );
3e978cf7 1407wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_START_EDITING, wxDataViewEvent );
9b11752c
VZ
1408wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, wxDataViewEvent );
1409wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED, wxDataViewEvent );
1410
1411wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU, wxDataViewEvent );
1412
1413wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, wxDataViewEvent );
1414wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, wxDataViewEvent );
1415wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, wxDataViewEvent );
1416wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED, wxDataViewEvent );
1417
47a8b1e1
VZ
1418wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_CACHE_HINT, wxDataViewEvent );
1419
9b11752c
VZ
1420wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_BEGIN_DRAG, wxDataViewEvent );
1421wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP_POSSIBLE, wxDataViewEvent );
1422wxDEFINE_EVENT( wxEVT_COMMAND_DATAVIEW_ITEM_DROP, wxDataViewEvent );
52e750fc 1423
47a8b1e1
VZ
1424
1425
52e750fc
RR
1426// -------------------------------------
1427// wxDataViewSpinRenderer
1428// -------------------------------------
1429
1430wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min, int max, wxDataViewCellMode mode, int alignment ) :
99c75ebc 1431 wxDataViewCustomRenderer(wxT("long"), mode, alignment )
b5ec7dd6 1432{
52e750fc
RR
1433 m_min = min;
1434 m_max = max;
1435}
b5ec7dd6 1436
64c70359 1437wxWindow* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
b5ec7dd6 1438{
52e750fc 1439 long l = value;
659fb68d
RR
1440 wxSize size = labelRect.GetSize();
1441#ifdef __WXMAC__
1442 size = wxSize( wxMax(70,labelRect.width ), -1 );
1443#endif
1444 wxString str;
2ddfe921 1445 str.Printf( wxT("%d"), (int) l );
659fb68d 1446 wxSpinCtrl *sc = new wxSpinCtrl( parent, wxID_ANY, str,
724852da 1447 labelRect.GetTopLeft(), size, wxSP_ARROW_KEYS|wxTE_PROCESS_ENTER, m_min, m_max, l );
659fb68d
RR
1448#ifdef __WXMAC__
1449 size = sc->GetSize();
1450 wxPoint pt = sc->GetPosition();
1451 sc->SetSize( pt.x - 4, pt.y - 4, size.x, size.y );
1452#endif
777f9cef 1453
659fb68d 1454 return sc;
52e750fc 1455}
b5ec7dd6 1456
64c70359 1457bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxWindow* editor, wxVariant &value )
b5ec7dd6 1458{
52e750fc
RR
1459 wxSpinCtrl *sc = (wxSpinCtrl*) editor;
1460 long l = sc->GetValue();
1461 value = l;
1462 return true;
1463}
b5ec7dd6 1464
52e750fc
RR
1465bool wxDataViewSpinRenderer::Render( wxRect rect, wxDC *dc, int state )
1466{
1467 wxString str;
99c75ebc 1468 str.Printf(wxT("%d"), (int) m_data );
52e750fc
RR
1469 RenderText( str, 0, rect, dc, state );
1470 return true;
1471}
b5ec7dd6 1472
52e750fc
RR
1473wxSize wxDataViewSpinRenderer::GetSize() const
1474{
a1c9e7d1
VS
1475 wxSize sz = GetTextExtent(wxString::Format("%d", (int)m_data));
1476
1477 // Allow some space for the spin buttons, which is approximately the size
1478 // of a scrollbar (and getting pixel-exact value would be complicated).
1479 // Also add some whitespace between the text and the button:
1480 sz.x += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
1481 sz.x += GetTextExtent("M").x;
1482
1483 return sz;
52e750fc 1484}
b5ec7dd6 1485
52e750fc
RR
1486bool wxDataViewSpinRenderer::SetValue( const wxVariant &value )
1487{
1488 m_data = value.GetLong();
1489 return true;
1490}
b5ec7dd6 1491
52e750fc
RR
1492bool wxDataViewSpinRenderer::GetValue( wxVariant &value ) const
1493{
1494 value = m_data;
1495 return true;
1496}
1497
7448d67c
RR
1498// -------------------------------------
1499// wxDataViewChoiceRenderer
1500// -------------------------------------
1501
e86edab0 1502#if defined(wxHAS_GENERIC_DATAVIEWCTRL) || defined(__WXOSX_CARBON__)
7448d67c
RR
1503
1504wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString& choices, wxDataViewCellMode mode, int alignment ) :
1505 wxDataViewCustomRenderer(wxT("string"), mode, alignment )
1506{
1507 m_choices = choices;
1508}
1509
64c70359 1510wxWindow* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
7448d67c 1511{
34b239ec
VS
1512 wxChoice* c = new wxChoice
1513 (
1514 parent,
1515 wxID_ANY,
1516 labelRect.GetTopLeft(),
1517 wxSize(labelRect.GetWidth(), -1),
1518 m_choices
1519 );
a3669fa9 1520 c->Move(labelRect.GetRight() - c->GetRect().width, wxDefaultCoord);
7448d67c 1521 c->SetStringSelection( value.GetString() );
7448d67c
RR
1522 return c;
1523}
1524
64c70359 1525bool wxDataViewChoiceRenderer::GetValueFromEditorCtrl( wxWindow* editor, wxVariant &value )
7448d67c
RR
1526{
1527 wxChoice *c = (wxChoice*) editor;
1528 wxString s = c->GetStringSelection();
1529 value = s;
1530 return true;
1531}
1532
1533bool wxDataViewChoiceRenderer::Render( wxRect rect, wxDC *dc, int state )
1534{
1535 RenderText( m_data, 0, rect, dc, state );
1536 return true;
1537}
1538
1539wxSize wxDataViewChoiceRenderer::GetSize() const
1540{
a1c9e7d1
VS
1541 wxSize sz;
1542
1543 for ( wxArrayString::const_iterator i = m_choices.begin(); i != m_choices.end(); ++i )
1544 sz.IncTo(GetTextExtent(*i));
1545
1546 // Allow some space for the right-side button, which is approximately the
1547 // size of a scrollbar (and getting pixel-exact value would be complicated).
1548 // Also add some whitespace between the text and the button:
1549 sz.x += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
1550 sz.x += GetTextExtent("M").x;
1551
1552 return sz;
7448d67c
RR
1553}
1554
1555bool wxDataViewChoiceRenderer::SetValue( const wxVariant &value )
1556{
1557 m_data = value.GetString();
1558 return true;
1559}
1560
1561bool wxDataViewChoiceRenderer::GetValue( wxVariant &value ) const
1562{
1563 value = m_data;
1564 return true;
1565}
1566
65887bd0
RR
1567// ----------------------------------------------------------------------------
1568// wxDataViewChoiceByIndexRenderer
1569// ----------------------------------------------------------------------------
1570
1571wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString &choices,
1572 wxDataViewCellMode mode, int alignment ) :
1573 wxDataViewChoiceRenderer( choices, mode, alignment )
1574{
1575}
ce00f59b 1576
64c70359 1577wxWindow* wxDataViewChoiceByIndexRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
65887bd0
RR
1578{
1579 wxVariant string_value = GetChoice( value.GetLong() );
ce00f59b 1580
65887bd0
RR
1581 return wxDataViewChoiceRenderer::CreateEditorCtrl( parent, labelRect, string_value );
1582}
1583
64c70359 1584bool wxDataViewChoiceByIndexRenderer::GetValueFromEditorCtrl( wxWindow* editor, wxVariant &value )
65887bd0
RR
1585{
1586 wxVariant string_value;
1587 if (!wxDataViewChoiceRenderer::GetValueFromEditorCtrl( editor, string_value ))
1588 return false;
1589
1590 value = (long) GetChoices().Index( string_value.GetString() );
1591 return true;
1592}
1593
1594bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant &value )
1595{
1596 wxVariant string_value = GetChoice( value.GetLong() );
1597 return wxDataViewChoiceRenderer::SetValue( string_value );
1598}
ce00f59b 1599
65887bd0
RR
1600bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant &value ) const
1601{
1602 wxVariant string_value;
1603 if (!wxDataViewChoiceRenderer::GetValue( string_value ))
1604 return false;
ce00f59b 1605
65887bd0
RR
1606 value = (long) GetChoices().Index( string_value.GetString() );
1607 return true;
1608}
1609
7448d67c
RR
1610#endif
1611
8eff6c56
RR
1612//-----------------------------------------------------------------------------
1613// wxDataViewListStore
1614//-----------------------------------------------------------------------------
1615
1616wxDataViewListStore::wxDataViewListStore()
1617{
1618}
1619
1620wxDataViewListStore::~wxDataViewListStore()
1621{
1622 wxVector<wxDataViewListStoreLine*>::iterator it;
1623 for (it = m_data.begin(); it != m_data.end(); ++it)
1624 {
1625 wxDataViewListStoreLine* line = *it;
1626 delete line;
1627 }
1628}
1629
1630void wxDataViewListStore::PrependColumn( const wxString &varianttype )
1631{
1632 m_cols.Insert( varianttype, 0 );
1633}
1634
1635void wxDataViewListStore::InsertColumn( unsigned int pos, const wxString &varianttype )
1636{
1637 m_cols.Insert( varianttype, pos );
1638}
1639
1640void wxDataViewListStore::AppendColumn( const wxString &varianttype )
1641{
1642 m_cols.Add( varianttype );
1643}
1644
1645unsigned int wxDataViewListStore::GetColumnCount() const
1646{
1647 return m_cols.GetCount();
1648}
1649
1650wxString wxDataViewListStore::GetColumnType( unsigned int pos ) const
1651{
1652 return m_cols[pos];
1653}
8c2654ce 1654
8eff6c56
RR
1655void wxDataViewListStore::AppendItem( const wxVector<wxVariant> &values, wxClientData *data )
1656{
1657 wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data );
1658 line->m_values = values;
1659 m_data.push_back( line );
8c2654ce 1660
8eff6c56
RR
1661 RowAppended();
1662}
1663
1664void wxDataViewListStore::PrependItem( const wxVector<wxVariant> &values, wxClientData *data )
1665{
1666 wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data );
1667 line->m_values = values;
1668 m_data.insert( m_data.begin(), line );
8c2654ce 1669
8eff6c56
RR
1670 RowPrepended();
1671}
1672
3569e0d0 1673void wxDataViewListStore::InsertItem( unsigned int row, const wxVector<wxVariant> &values,
8af28fab 1674 wxClientData *data )
8eff6c56
RR
1675{
1676 wxDataViewListStoreLine *line = new wxDataViewListStoreLine( data );
1677 line->m_values = values;
1678 m_data.insert( m_data.begin()+row, line );
8c2654ce 1679
8eff6c56
RR
1680 RowInserted( row );
1681}
1682
8af28fab 1683void wxDataViewListStore::DeleteItem( unsigned int row )
8eff6c56
RR
1684{
1685 wxVector<wxDataViewListStoreLine*>::iterator it = m_data.begin() + row;
2d6bba41 1686 delete *it;
8eff6c56 1687 m_data.erase( it );
8c2654ce 1688
8eff6c56
RR
1689 RowDeleted( row );
1690}
1691
1692void wxDataViewListStore::DeleteAllItems()
1693{
1694 wxVector<wxDataViewListStoreLine*>::iterator it;
1695 for (it = m_data.begin(); it != m_data.end(); ++it)
1696 {
1697 wxDataViewListStoreLine* line = *it;
1698 delete line;
1699 }
8c2654ce 1700
8af28fab
FM
1701 m_data.clear();
1702
8eff6c56
RR
1703 Reset( 0 );
1704}
1705
1706void wxDataViewListStore::GetValueByRow( wxVariant &value, unsigned int row, unsigned int col ) const
1707{
1708 wxDataViewListStoreLine *line = m_data[row];
1709 value = line->m_values[col];
1710}
1711
1712bool wxDataViewListStore::SetValueByRow( const wxVariant &value, unsigned int row, unsigned int col )
1713{
1714 wxDataViewListStoreLine *line = m_data[row];
1715 line->m_values[col] = value;
8c2654ce 1716
8eff6c56
RR
1717 return true;
1718}
1719
dc813e6c
RR
1720//-----------------------------------------------------------------------------
1721// wxDataViewListCtrl
1722//-----------------------------------------------------------------------------
1723
1724IMPLEMENT_DYNAMIC_CLASS(wxDataViewListCtrl,wxDataViewCtrl)
1725
1726BEGIN_EVENT_TABLE(wxDataViewListCtrl,wxDataViewCtrl)
1727 EVT_SIZE( wxDataViewListCtrl::OnSize )
1728END_EVENT_TABLE()
1729
1730wxDataViewListCtrl::wxDataViewListCtrl()
1731{
1732}
1733
1734wxDataViewListCtrl::wxDataViewListCtrl( wxWindow *parent, wxWindowID id,
1735 const wxPoint& pos, const wxSize& size, long style,
1736 const wxValidator& validator )
1737{
1738 Create( parent, id, pos, size, style, validator );
dc813e6c
RR
1739}
1740
1741wxDataViewListCtrl::~wxDataViewListCtrl()
1742{
1743}
1744
1745
1746bool wxDataViewListCtrl::Create( wxWindow *parent, wxWindowID id,
1747 const wxPoint& pos, const wxSize& size, long style,
1748 const wxValidator& validator )
1749{
9ba38914
VS
1750 if ( !wxDataViewCtrl::Create( parent, id, pos, size, style, validator ) )
1751 return false;
1752
1753 wxDataViewListStore *store = new wxDataViewListStore;
1754 AssociateModel( store );
1755 store->DecRef();
1756
1757 return true;
dc813e6c
RR
1758}
1759
95b20f41 1760bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn *column, const wxString &varianttype )
dc813e6c
RR
1761{
1762 GetStore()->AppendColumn( varianttype );
95b20f41 1763 return wxDataViewCtrl::AppendColumn( column );
dc813e6c
RR
1764}
1765
95b20f41 1766bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn *column, const wxString &varianttype )
dc813e6c
RR
1767{
1768 GetStore()->PrependColumn( varianttype );
95b20f41 1769 return wxDataViewCtrl::PrependColumn( column );
dc813e6c
RR
1770}
1771
95b20f41 1772bool wxDataViewListCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *column, const wxString &varianttype )
dc813e6c
RR
1773{
1774 GetStore()->InsertColumn( pos, varianttype );
95b20f41
RR
1775 return wxDataViewCtrl::InsertColumn( pos, column );
1776}
1777
1778bool wxDataViewListCtrl::PrependColumn( wxDataViewColumn *col )
1779{
1780 return PrependColumn( col, "string" );
1781}
1782
1783bool wxDataViewListCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *col )
1784{
1785 return InsertColumn( pos, col, "string" );
1786}
1787
1788bool wxDataViewListCtrl::AppendColumn( wxDataViewColumn *col )
1789{
1790 return AppendColumn( col, "string" );
dc813e6c 1791}
8c2654ce 1792
3569e0d0 1793wxDataViewColumn *wxDataViewListCtrl::AppendTextColumn( const wxString &label,
dc813e6c
RR
1794 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1795{
1796 GetStore()->AppendColumn( wxT("string") );
8c2654ce 1797
95b20f41
RR
1798 wxDataViewColumn *ret = new wxDataViewColumn( label,
1799 new wxDataViewTextRenderer( wxT("string"), mode ),
1800 GetStore()->GetColumnCount()-1, width, align, flags );
8c2654ce 1801
95b20f41 1802 wxDataViewCtrl::AppendColumn( ret );
8c2654ce 1803
95b20f41 1804 return ret;
dc813e6c
RR
1805}
1806
3569e0d0 1807wxDataViewColumn *wxDataViewListCtrl::AppendToggleColumn( const wxString &label,
dc813e6c
RR
1808 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1809{
1810 GetStore()->AppendColumn( wxT("bool") );
8c2654ce 1811
95b20f41
RR
1812 wxDataViewColumn *ret = new wxDataViewColumn( label,
1813 new wxDataViewToggleRenderer( wxT("bool"), mode ),
1814 GetStore()->GetColumnCount()-1, width, align, flags );
8c2654ce 1815
95b20f41 1816 wxDataViewCtrl::AppendColumn( ret );
8c2654ce 1817
95b20f41 1818 return ret;
dc813e6c
RR
1819}
1820
3569e0d0 1821wxDataViewColumn *wxDataViewListCtrl::AppendProgressColumn( const wxString &label,
dc813e6c
RR
1822 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1823{
1824 GetStore()->AppendColumn( wxT("long") );
8c2654ce 1825
95b20f41
RR
1826 wxDataViewColumn *ret = new wxDataViewColumn( label,
1827 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ),
1828 GetStore()->GetColumnCount()-1, width, align, flags );
8c2654ce 1829
95b20f41 1830 wxDataViewCtrl::AppendColumn( ret );
8c2654ce 1831
95b20f41 1832 return ret;
dc813e6c
RR
1833}
1834
3569e0d0 1835wxDataViewColumn *wxDataViewListCtrl::AppendIconTextColumn( const wxString &label,
dc813e6c
RR
1836 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
1837{
1838 GetStore()->AppendColumn( wxT("wxDataViewIconText") );
8c2654ce 1839
95b20f41
RR
1840 wxDataViewColumn *ret = new wxDataViewColumn( label,
1841 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ),
1842 GetStore()->GetColumnCount()-1, width, align, flags );
8c2654ce 1843
95b20f41 1844 wxDataViewCtrl::AppendColumn( ret );
8c2654ce 1845
95b20f41 1846 return ret;
dc813e6c
RR
1847}
1848
1849void wxDataViewListCtrl::OnSize( wxSizeEvent &event )
1850{
1851 event.Skip( true );
1852}
1853
e94d0c1e
RR
1854//-----------------------------------------------------------------------------
1855// wxDataViewTreeStore
1856//-----------------------------------------------------------------------------
1857
b5ec7dd6
VZ
1858wxDataViewTreeStoreNode::wxDataViewTreeStoreNode(
1859 wxDataViewTreeStoreNode *parent,
e94d0c1e
RR
1860 const wxString &text, const wxIcon &icon, wxClientData *data )
1861{
1862 m_parent = parent;
1863 m_text = text;
1864 m_icon = icon;
1865 m_data = data;
1866}
1867
1868wxDataViewTreeStoreNode::~wxDataViewTreeStoreNode()
1869{
1870 if (m_data)
1871 delete m_data;
1872}
b5ec7dd6 1873
e94d0c1e 1874#include "wx/listimpl.cpp"
a76c2f37 1875WX_DEFINE_LIST(wxDataViewTreeStoreNodeList)
e94d0c1e 1876
b5ec7dd6
VZ
1877wxDataViewTreeStoreContainerNode::wxDataViewTreeStoreContainerNode(
1878 wxDataViewTreeStoreNode *parent, const wxString &text,
e94d0c1e
RR
1879 const wxIcon &icon, const wxIcon &expanded, wxClientData *data ) :
1880 wxDataViewTreeStoreNode( parent, text, icon, data )
1881{
1882 m_iconExpanded = expanded;
a75124d0 1883 m_isExpanded = false;
e94d0c1e
RR
1884 m_children.DeleteContents(true);
1885}
1886
1887wxDataViewTreeStoreContainerNode::~wxDataViewTreeStoreContainerNode()
1888{
1889}
1890
1891//-----------------------------------------------------------------------------
1892
1893wxDataViewTreeStore::wxDataViewTreeStore()
1894{
1895 m_root = new wxDataViewTreeStoreContainerNode( NULL, wxEmptyString );
1896}
1897
1898wxDataViewTreeStore::~wxDataViewTreeStore()
1899{
1900 delete m_root;
1901}
1902
b5ec7dd6 1903wxDataViewItem wxDataViewTreeStore::AppendItem( const wxDataViewItem& parent,
e94d0c1e
RR
1904 const wxString &text, const wxIcon &icon, wxClientData *data )
1905{
1906 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1907 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6
VZ
1908
1909 wxDataViewTreeStoreNode *node =
e94d0c1e
RR
1910 new wxDataViewTreeStoreNode( parent_node, text, icon, data );
1911 parent_node->GetChildren().Append( node );
b5ec7dd6 1912
e94d0c1e
RR
1913 return node->GetItem();
1914}
1915
1916wxDataViewItem wxDataViewTreeStore::PrependItem( const wxDataViewItem& parent,
1917 const wxString &text, const wxIcon &icon, wxClientData *data )
1918{
1919 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1920 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6
VZ
1921
1922 wxDataViewTreeStoreNode *node =
e94d0c1e
RR
1923 new wxDataViewTreeStoreNode( parent_node, text, icon, data );
1924 parent_node->GetChildren().Insert( node );
b5ec7dd6 1925
e94d0c1e
RR
1926 return node->GetItem();
1927}
1928
b5ec7dd6 1929wxDataViewItem
e700e296
RR
1930wxDataViewTreeStore::InsertItem(const wxDataViewItem& parent,
1931 const wxDataViewItem& previous,
1932 const wxString& text,
1933 const wxIcon& icon,
1934 wxClientData *data)
e94d0c1e 1935{
e700e296
RR
1936 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1937 if (!parent_node) return wxDataViewItem(0);
1938
1939 wxDataViewTreeStoreNode *previous_node = FindNode( previous );
1940 int pos = parent_node->GetChildren().IndexOf( previous_node );
1941 if (pos == wxNOT_FOUND) return wxDataViewItem(0);
1942
1943 wxDataViewTreeStoreNode *node =
1944 new wxDataViewTreeStoreNode( parent_node, text, icon, data );
1945 parent_node->GetChildren().Insert( (size_t) pos, node );
1946
1947 return node->GetItem();
e94d0c1e
RR
1948}
1949
b5ec7dd6
VZ
1950wxDataViewItem wxDataViewTreeStore::PrependContainer( const wxDataViewItem& parent,
1951 const wxString &text, const wxIcon &icon, const wxIcon &expanded,
e94d0c1e
RR
1952 wxClientData *data )
1953{
1954 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1955 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6
VZ
1956
1957 wxDataViewTreeStoreContainerNode *node =
e94d0c1e
RR
1958 new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
1959 parent_node->GetChildren().Insert( node );
b5ec7dd6 1960
e94d0c1e
RR
1961 return node->GetItem();
1962}
1963
b5ec7dd6
VZ
1964wxDataViewItem
1965wxDataViewTreeStore::AppendContainer(const wxDataViewItem& parent,
1966 const wxString &text,
1967 const wxIcon& icon,
1968 const wxIcon& expanded,
1969 wxClientData * data)
e94d0c1e
RR
1970{
1971 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1972 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6
VZ
1973
1974 wxDataViewTreeStoreContainerNode *node =
e94d0c1e
RR
1975 new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
1976 parent_node->GetChildren().Append( node );
b5ec7dd6 1977
e94d0c1e
RR
1978 return node->GetItem();
1979}
1980
b5ec7dd6 1981wxDataViewItem
e700e296
RR
1982wxDataViewTreeStore::InsertContainer(const wxDataViewItem& parent,
1983 const wxDataViewItem& previous,
1984 const wxString& text,
1985 const wxIcon& icon,
1986 const wxIcon& expanded,
1987 wxClientData * data)
e94d0c1e 1988{
e700e296
RR
1989 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
1990 if (!parent_node) return wxDataViewItem(0);
8c2654ce 1991
e700e296
RR
1992 wxDataViewTreeStoreNode *previous_node = FindNode( previous );
1993 int pos = parent_node->GetChildren().IndexOf( previous_node );
1994 if (pos == wxNOT_FOUND) return wxDataViewItem(0);
8c2654ce 1995
e700e296
RR
1996 wxDataViewTreeStoreContainerNode *node =
1997 new wxDataViewTreeStoreContainerNode( parent_node, text, icon, expanded, data );
1998 parent_node->GetChildren().Insert( (size_t) pos, node );
1999
2000 return node->GetItem();
e94d0c1e
RR
2001}
2002
8ddda15b
RR
2003bool wxDataViewTreeStore::IsContainer( const wxDataViewItem& item ) const
2004{
2005 wxDataViewTreeStoreNode *node = FindNode( item );
2006 if (!node) return false;
2007
2008 return node->IsContainer();
2009}
2010
e94d0c1e
RR
2011wxDataViewItem wxDataViewTreeStore::GetNthChild( const wxDataViewItem& parent, unsigned int pos ) const
2012{
2013 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent );
2014 if (!parent_node) return wxDataViewItem(0);
b5ec7dd6 2015
e94d0c1e
RR
2016 wxDataViewTreeStoreNodeList::compatibility_iterator node = parent_node->GetChildren().Item( pos );
2017 if (node)
d5c4a81f 2018 return wxDataViewItem(node->GetData());
b5ec7dd6 2019
e94d0c1e
RR
2020 return wxDataViewItem(0);
2021}
2022
2023int wxDataViewTreeStore::GetChildCount( const wxDataViewItem& parent ) const
2024{
2025 wxDataViewTreeStoreNode *node = FindNode( parent );
2026 if (!node) return -1;
b5ec7dd6 2027
e94d0c1e
RR
2028 if (!node->IsContainer())
2029 return 0;
b5ec7dd6 2030
e94d0c1e 2031 wxDataViewTreeStoreContainerNode *container_node = (wxDataViewTreeStoreContainerNode*) node;
b5ec7dd6 2032 return (int) container_node->GetChildren().GetCount();
e94d0c1e
RR
2033}
2034
2035void wxDataViewTreeStore::SetItemText( const wxDataViewItem& item, const wxString &text )
2036{
2037 wxDataViewTreeStoreNode *node = FindNode( item );
2038 if (!node) return;
b5ec7dd6 2039
e94d0c1e 2040 node->SetText( text );
e94d0c1e
RR
2041}
2042
2043wxString wxDataViewTreeStore::GetItemText( const wxDataViewItem& item ) const
2044{
2045 wxDataViewTreeStoreNode *node = FindNode( item );
2046 if (!node) return wxEmptyString;
b5ec7dd6 2047
e94d0c1e
RR
2048 return node->GetText();
2049}
2050
2051void wxDataViewTreeStore::SetItemIcon( const wxDataViewItem& item, const wxIcon &icon )
2052{
2053 wxDataViewTreeStoreNode *node = FindNode( item );
2054 if (!node) return;
b5ec7dd6 2055
e94d0c1e 2056 node->SetIcon( icon );
e94d0c1e
RR
2057}
2058
2059const wxIcon &wxDataViewTreeStore::GetItemIcon( const wxDataViewItem& item ) const
2060{
2061 wxDataViewTreeStoreNode *node = FindNode( item );
2062 if (!node) return wxNullIcon;
b5ec7dd6 2063
e94d0c1e
RR
2064 return node->GetIcon();
2065}
2066
2067void wxDataViewTreeStore::SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon )
2068{
2069 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
2070 if (!node) return;
b5ec7dd6 2071
e94d0c1e 2072 node->SetExpandedIcon( icon );
e94d0c1e
RR
2073}
2074
2075const wxIcon &wxDataViewTreeStore::GetItemExpandedIcon( const wxDataViewItem& item ) const
2076{
2077 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
2078 if (!node) return wxNullIcon;
b5ec7dd6 2079
e94d0c1e
RR
2080 return node->GetExpandedIcon();
2081}
2082
2083void wxDataViewTreeStore::SetItemData( const wxDataViewItem& item, wxClientData *data )
2084{
2085 wxDataViewTreeStoreNode *node = FindNode( item );
2086 if (!node) return;
b5ec7dd6 2087
e94d0c1e 2088 node->SetData( data );
e94d0c1e
RR
2089}
2090
2091wxClientData *wxDataViewTreeStore::GetItemData( const wxDataViewItem& item ) const
2092{
2093 wxDataViewTreeStoreNode *node = FindNode( item );
2094 if (!node) return NULL;
b5ec7dd6 2095
e94d0c1e
RR
2096 return node->GetData();
2097}
2098
2099void wxDataViewTreeStore::DeleteItem( const wxDataViewItem& item )
2100{
2101 if (!item.IsOk()) return;
2102
2103 wxDataViewItem parent_item = GetParent( item );
2104
2105 wxDataViewTreeStoreContainerNode *parent_node = FindContainerNode( parent_item );
2106 if (!parent_node) return;
b5ec7dd6 2107
e94d0c1e
RR
2108 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
2109 if (!node) return;
b5ec7dd6 2110
e94d0c1e 2111 parent_node->GetChildren().DeleteObject( node );
e94d0c1e
RR
2112}
2113
2114void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem& item )
2115{
2116 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
2117 if (!node) return;
b5ec7dd6 2118
e94d0c1e 2119 node->GetChildren().clear();
e94d0c1e
RR
2120}
2121
2122void wxDataViewTreeStore::DeleteAllItems()
2123{
d5c4a81f 2124 DeleteChildren(wxDataViewItem(m_root));
e94d0c1e
RR
2125}
2126
b5ec7dd6
VZ
2127void
2128wxDataViewTreeStore::GetValue(wxVariant &variant,
2129 const wxDataViewItem &item,
2130 unsigned int WXUNUSED(col)) const
e94d0c1e
RR
2131{
2132 // if (col != 0) return;
b5ec7dd6 2133
e94d0c1e
RR
2134 wxDataViewTreeStoreNode *node = FindNode( item );
2135 if (!node) return;
b5ec7dd6 2136
a75124d0
RR
2137 wxIcon icon( node->GetIcon());
2138 if (node->IsContainer())
2139 {
2140 wxDataViewTreeStoreContainerNode *container = (wxDataViewTreeStoreContainerNode*) node;
2141 if (container->IsExpanded() && container->GetExpandedIcon().IsOk())
2142 icon = container->GetExpandedIcon();
2143 }
777f9cef 2144
a75124d0 2145 wxDataViewIconText data( node->GetText(), icon );
b5ec7dd6 2146
e94d0c1e
RR
2147 variant << data;
2148}
2149
b5ec7dd6
VZ
2150bool
2151wxDataViewTreeStore::SetValue(const wxVariant& variant,
2152 const wxDataViewItem& item,
2153 unsigned int WXUNUSED(col))
e94d0c1e
RR
2154{
2155 // if (col != 0) return false;
b5ec7dd6 2156
e94d0c1e
RR
2157 wxDataViewTreeStoreNode *node = FindNode( item );
2158 if (!node) return false;
b5ec7dd6 2159
e94d0c1e 2160 wxDataViewIconText data;
b5ec7dd6 2161
e94d0c1e 2162 data << variant;
b5ec7dd6 2163
e94d0c1e
RR
2164 node->SetText( data.GetText() );
2165 node->SetIcon( data.GetIcon() );
b5ec7dd6 2166
e94d0c1e
RR
2167 return true;
2168}
2169
2170wxDataViewItem wxDataViewTreeStore::GetParent( const wxDataViewItem &item ) const
2171{
2172 wxDataViewTreeStoreNode *node = FindNode( item );
2173 if (!node) return wxDataViewItem(0);
b5ec7dd6 2174
e94d0c1e
RR
2175 wxDataViewTreeStoreNode *parent = node->GetParent();
2176 if (!parent) return wxDataViewItem(0);
b5ec7dd6 2177
e94d0c1e
RR
2178 if (parent == m_root)
2179 return wxDataViewItem(0);
b5ec7dd6 2180
e94d0c1e
RR
2181 return parent->GetItem();
2182}
2183
e94d0c1e
RR
2184unsigned int wxDataViewTreeStore::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const
2185{
2186 wxDataViewTreeStoreContainerNode *node = FindContainerNode( item );
2187 if (!node) return 0;
2188
2189 wxDataViewTreeStoreNodeList::iterator iter;
2190 for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++)
2191 {
2192 wxDataViewTreeStoreNode* child = *iter;
2193 children.Add( child->GetItem() );
2194 }
b5ec7dd6 2195
e94d0c1e
RR
2196 return node->GetChildren().GetCount();
2197}
2198
b5ec7dd6 2199int wxDataViewTreeStore::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
862de7b3 2200 unsigned int WXUNUSED(column), bool WXUNUSED(ascending) ) const
e94d0c1e
RR
2201{
2202 wxDataViewTreeStoreNode *node1 = FindNode( item1 );
2203 wxDataViewTreeStoreNode *node2 = FindNode( item2 );
b5ec7dd6 2204
e94d0c1e
RR
2205 if (!node1 || !node2)
2206 return 0;
b5ec7dd6
VZ
2207
2208 wxDataViewTreeStoreContainerNode* parent1 =
e94d0c1e 2209 (wxDataViewTreeStoreContainerNode*) node1->GetParent();
b5ec7dd6 2210 wxDataViewTreeStoreContainerNode* parent2 =
e94d0c1e 2211 (wxDataViewTreeStoreContainerNode*) node2->GetParent();
b5ec7dd6 2212
e94d0c1e
RR
2213 if (parent1 != parent2)
2214 {
2215 wxLogError( wxT("Comparing items with different parent.") );
2216 return 0;
2217 }
b5ec7dd6 2218
9c205231 2219 if (node1->IsContainer() && !node2->IsContainer())
e94d0c1e 2220 return -1;
b5ec7dd6 2221
9c205231
RR
2222 if (node2->IsContainer() && !node1->IsContainer())
2223 return 1;
2224
2225 return parent1->GetChildren().IndexOf( node1 ) - parent2->GetChildren().IndexOf( node2 );
e94d0c1e
RR
2226}
2227
2228wxDataViewTreeStoreNode *wxDataViewTreeStore::FindNode( const wxDataViewItem &item ) const
2229{
2230 if (!item.IsOk())
2231 return m_root;
b5ec7dd6 2232
e94d0c1e
RR
2233 return (wxDataViewTreeStoreNode*) item.GetID();
2234}
2235
2236wxDataViewTreeStoreContainerNode *wxDataViewTreeStore::FindContainerNode( const wxDataViewItem &item ) const
2237{
2238 if (!item.IsOk())
2239 return (wxDataViewTreeStoreContainerNode*) m_root;
2240
2241 wxDataViewTreeStoreNode* node = (wxDataViewTreeStoreNode*) item.GetID();
b5ec7dd6 2242
e94d0c1e
RR
2243 if (!node->IsContainer())
2244 return NULL;
b5ec7dd6 2245
e94d0c1e
RR
2246 return (wxDataViewTreeStoreContainerNode*) node;
2247}
2248
a75124d0
RR
2249//-----------------------------------------------------------------------------
2250// wxDataViewTreeCtrl
2251//-----------------------------------------------------------------------------
2252
2253IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl,wxDataViewCtrl)
2254
2255BEGIN_EVENT_TABLE(wxDataViewTreeCtrl,wxDataViewCtrl)
2256 EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded)
2257 EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed)
9c150d5f 2258 EVT_SIZE( wxDataViewTreeCtrl::OnSize )
a75124d0
RR
2259END_EVENT_TABLE()
2260
43c64cc6 2261bool wxDataViewTreeCtrl::Create( wxWindow *parent, wxWindowID id,
777f9cef 2262 const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator )
a75124d0 2263{
43c64cc6
VZ
2264 if ( !wxDataViewCtrl::Create( parent, id, pos, size, style, validator ) )
2265 return false;
777f9cef 2266
43c64cc6 2267 // create the standard model and a column in the tree
a75124d0
RR
2268 wxDataViewTreeStore *store = new wxDataViewTreeStore;
2269 AssociateModel( store );
2270 store->DecRef();
777f9cef 2271
0e17930f
VZ
2272 AppendIconTextColumn
2273 (
2274 wxString(), // no label (header is not shown anyhow)
2275 0, // the only model column
2276 wxDATAVIEW_CELL_EDITABLE,
2277 -1, // default width
2278 wxALIGN_NOT, // and alignment
d13b34d3 2279 0 // not resizable
0e17930f 2280 );
a75124d0 2281
43c64cc6 2282 return true;
a75124d0
RR
2283}
2284
a75124d0
RR
2285wxDataViewItem wxDataViewTreeCtrl::AppendItem( const wxDataViewItem& parent,
2286 const wxString &text, int iconIndex, wxClientData *data )
2287{
abfdefed
VZ
2288 wxDataViewItem res = GetStore()->
2289 AppendItem( parent, text, GetImage(iconIndex), data );
8c2654ce 2290
e700e296 2291 GetStore()->ItemAdded( parent, res );
8c2654ce 2292
e700e296 2293 return res;
a75124d0
RR
2294}
2295
2296wxDataViewItem wxDataViewTreeCtrl::PrependItem( const wxDataViewItem& parent,
2297 const wxString &text, int iconIndex, wxClientData *data )
2298{
abfdefed
VZ
2299 wxDataViewItem res = GetStore()->
2300 PrependItem( parent, text, GetImage(iconIndex), data );
8c2654ce 2301
e700e296 2302 GetStore()->ItemAdded( parent, res );
8c2654ce 2303
e700e296 2304 return res;
a75124d0
RR
2305}
2306
2307wxDataViewItem wxDataViewTreeCtrl::InsertItem( const wxDataViewItem& parent, const wxDataViewItem& previous,
2308 const wxString &text, int iconIndex, wxClientData *data )
2309{
abfdefed
VZ
2310 wxDataViewItem res = GetStore()->
2311 InsertItem( parent, previous, text, GetImage(iconIndex), data );
8c2654ce 2312
e700e296 2313 GetStore()->ItemAdded( parent, res );
8c2654ce 2314
e700e296 2315 return res;
a75124d0
RR
2316}
2317
2318wxDataViewItem wxDataViewTreeCtrl::PrependContainer( const wxDataViewItem& parent,
2319 const wxString &text, int iconIndex, int expandedIndex, wxClientData *data )
2320{
abfdefed
VZ
2321 wxDataViewItem res = GetStore()->
2322 PrependContainer( parent, text,
2323 GetImage(iconIndex), GetImage(expandedIndex), data );
8c2654ce 2324
e700e296 2325 GetStore()->ItemAdded( parent, res );
8c2654ce 2326
e700e296 2327 return res;
a75124d0
RR
2328}
2329
2330wxDataViewItem wxDataViewTreeCtrl::AppendContainer( const wxDataViewItem& parent,
2331 const wxString &text, int iconIndex, int expandedIndex, wxClientData *data )
2332{
abfdefed
VZ
2333 wxDataViewItem res = GetStore()->
2334 AppendContainer( parent, text,
2335 GetImage(iconIndex), GetImage(expandedIndex), data );
8c2654ce 2336
e700e296 2337 GetStore()->ItemAdded( parent, res );
8c2654ce 2338
e700e296 2339 return res;
a75124d0
RR
2340}
2341
2342wxDataViewItem wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem& parent, const wxDataViewItem& previous,
2343 const wxString &text, int iconIndex, int expandedIndex, wxClientData *data )
2344{
abfdefed
VZ
2345 wxDataViewItem res = GetStore()->
2346 InsertContainer( parent, previous, text,
2347 GetImage(iconIndex), GetImage(expandedIndex), data );
8c2654ce 2348
e700e296 2349 GetStore()->ItemAdded( parent, res );
8c2654ce 2350
e700e296
RR
2351 return res;
2352}
2353
2354void wxDataViewTreeCtrl::SetItemText( const wxDataViewItem& item, const wxString &text )
3569e0d0 2355{
e700e296 2356 GetStore()->SetItemText(item,text);
8c2654ce 2357
e700e296
RR
2358 // notify control
2359 GetStore()->ValueChanged( item, 0 );
2360}
2361
2362void wxDataViewTreeCtrl::SetItemIcon( const wxDataViewItem& item, const wxIcon &icon )
3569e0d0 2363{
e700e296 2364 GetStore()->SetItemIcon(item,icon);
8c2654ce 2365
e700e296
RR
2366 // notify control
2367 GetStore()->ValueChanged( item, 0 );
2368}
2369
2370void wxDataViewTreeCtrl::SetItemExpandedIcon( const wxDataViewItem& item, const wxIcon &icon )
3569e0d0 2371{
e700e296 2372 GetStore()->SetItemExpandedIcon(item,icon);
8c2654ce 2373
e700e296
RR
2374 // notify control
2375 GetStore()->ValueChanged( item, 0 );
2376}
2377
2378void wxDataViewTreeCtrl::DeleteItem( const wxDataViewItem& item )
3569e0d0 2379{
e700e296
RR
2380 wxDataViewItem parent_item = GetStore()->GetParent( item );
2381
2382 GetStore()->DeleteItem(item);
8c2654ce 2383
e700e296
RR
2384 // notify control
2385 GetStore()->ItemDeleted( parent_item, item );
2386}
2387
2388void wxDataViewTreeCtrl::DeleteChildren( const wxDataViewItem& item )
3569e0d0 2389{
2f21b2be
RR
2390 wxDataViewTreeStoreContainerNode *node = GetStore()->FindContainerNode( item );
2391 if (!node) return;
2392
2393 wxDataViewItemArray array;
2394 wxDataViewTreeStoreNodeList::iterator iter;
2395 for (iter = node->GetChildren().begin(); iter != node->GetChildren().end(); iter++)
2396 {
2397 wxDataViewTreeStoreNode* child = *iter;
2398 array.Add( child->GetItem() );
2399 }
2400
2401 GetStore()->DeleteChildren( item );
2402
2403 // notify control
2404 GetStore()->ItemsDeleted( item, array );
e700e296
RR
2405}
2406
2407void wxDataViewTreeCtrl::DeleteAllItems()
3569e0d0 2408{
e700e296 2409 GetStore()->DeleteAllItems();
8c2654ce 2410
e700e296 2411 GetStore()->Cleared();
a75124d0
RR
2412}
2413
a75124d0
RR
2414void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent &event )
2415{
abfdefed 2416 if (HasImageList()) return;
777f9cef 2417
a75124d0
RR
2418 wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() );
2419 if (!container) return;
777f9cef 2420
a75124d0 2421 container->SetExpanded( true );
8c2654ce 2422
a75124d0
RR
2423 GetStore()->ItemChanged( event.GetItem() );
2424}
2425
2426void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent &event )
2427{
abfdefed 2428 if (HasImageList()) return;
777f9cef 2429
a75124d0
RR
2430 wxDataViewTreeStoreContainerNode* container = GetStore()->FindContainerNode( event.GetItem() );
2431 if (!container) return;
777f9cef 2432
a75124d0 2433 container->SetExpanded( false );
8c2654ce 2434
a75124d0
RR
2435 GetStore()->ItemChanged( event.GetItem() );
2436}
2437
a6aaf49f 2438void wxDataViewTreeCtrl::OnSize( wxSizeEvent &event )
1a07a730 2439{
ad386793 2440#if defined(wxUSE_GENERICDATAVIEWCTRL)
4bfd0ed5
VZ
2441 // automatically resize our only column to take the entire control width
2442 if ( GetColumnCount() )
2443 {
2444 wxSize size = GetClientSize();
2445 GetColumn(0)->SetWidth(size.x);
2446 }
1a07a730 2447#endif
a6aaf49f 2448 event.Skip( true );
1a07a730 2449}
a75124d0 2450
b5ec7dd6 2451#endif // wxUSE_DATAVIEWCTRL
e0000f94 2452