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