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