]> git.saurik.com Git - wxWidgets.git/blame - src/common/datavcmn.cpp
regenerated after wx/cpp.h addition
[wxWidgets.git] / src / common / datavcmn.cpp
CommitLineData
239eaa41
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/common/datavcmn.cpp
3// Purpose: wxDataViewCtrl base classes and common parts
4// Author: Robert Roebling
5// Created: 2006/02/20
6// RCS-ID: $Id$
7// Copyright: (c) 2006, Robert Roebling
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
8045736e
RR
18#if wxUSE_DATAVIEWCTRL
19
e7445ff8
PC
20#include "wx/dataview.h"
21
f554a14b 22#ifndef WX_PRECOMP
f554a14b
WS
23 #include "wx/log.h"
24#endif
25
4a2e5ee8 26const wxChar wxDataViewCtrlNameStr[] = wxT("dataviewCtrl");
239eaa41 27
f554a14b 28// ---------------------------------------------------------
239eaa41 29// wxDataViewModel
f554a14b 30// ---------------------------------------------------------
239eaa41
RR
31
32IMPLEMENT_ABSTRACT_CLASS(wxDataViewModel, wxObject)
33
f554a14b 34// ---------------------------------------------------------
239eaa41 35// wxDataViewListModel
f554a14b 36// ---------------------------------------------------------
239eaa41
RR
37
38IMPLEMENT_ABSTRACT_CLASS(wxDataViewListModel, wxDataViewModel)
39
40wxDataViewListModel::wxDataViewListModel()
41{
b5d777c7 42 m_viewingColumns.DeleteContents( true );
8f850e28 43 m_notifiers.DeleteContents( true );
239eaa41
RR
44}
45
46wxDataViewListModel::~wxDataViewListModel()
47{
239eaa41
RR
48}
49
50bool wxDataViewListModel::RowAppended()
51{
8f850e28
RR
52 bool ret = true;
53
85e5bb6a 54 wxList::compatibility_iterator node = m_notifiers.GetFirst();
8f850e28
RR
55 while (node)
56 {
57 wxDataViewListModelNotifier* notifier = (wxDataViewListModelNotifier*) node->GetData();
58 if (!notifier->RowAppended())
59 ret = false;
60 node = node->GetNext();
61 }
f554a14b 62
8f850e28 63 return ret;
239eaa41
RR
64}
65
66bool wxDataViewListModel::RowPrepended()
67{
8f850e28
RR
68 bool ret = true;
69
85e5bb6a 70 wxList::compatibility_iterator node = m_notifiers.GetFirst();
8f850e28
RR
71 while (node)
72 {
73 wxDataViewListModelNotifier* notifier = (wxDataViewListModelNotifier*) node->GetData();
74 if (!notifier->RowPrepended())
75 ret = false;
76 node = node->GetNext();
77 }
f554a14b 78
8f850e28 79 return ret;
239eaa41
RR
80}
81
82bool wxDataViewListModel::RowInserted( size_t before )
83{
8f850e28
RR
84 bool ret = true;
85
85e5bb6a 86 wxList::compatibility_iterator node = m_notifiers.GetFirst();
8f850e28
RR
87 while (node)
88 {
89 wxDataViewListModelNotifier* notifier = (wxDataViewListModelNotifier*) node->GetData();
90 if (!notifier->RowInserted(before))
91 ret = false;
92 node = node->GetNext();
93 }
f554a14b 94
8f850e28 95 return ret;
239eaa41
RR
96}
97
98bool wxDataViewListModel::RowDeleted( size_t row )
99{
8f850e28
RR
100 bool ret = true;
101
85e5bb6a 102 wxList::compatibility_iterator node = m_notifiers.GetFirst();
8f850e28
RR
103 while (node)
104 {
105 wxDataViewListModelNotifier* notifier = (wxDataViewListModelNotifier*) node->GetData();
106 if (!notifier->RowDeleted( row ))
107 ret = false;
108 node = node->GetNext();
109 }
f554a14b 110
8f850e28 111 return ret;
239eaa41
RR
112}
113
114bool wxDataViewListModel::RowChanged( size_t row )
115{
8f850e28
RR
116 bool ret = true;
117
85e5bb6a 118 wxList::compatibility_iterator node = m_notifiers.GetFirst();
8f850e28
RR
119 while (node)
120 {
121 wxDataViewListModelNotifier* notifier = (wxDataViewListModelNotifier*) node->GetData();
122 if (!notifier->RowChanged( row ))
123 ret = false;
124 node = node->GetNext();
125 }
f554a14b 126
8f850e28 127 return ret;
239eaa41
RR
128}
129
a7f61f76 130bool wxDataViewListModel::ValueChanged( size_t col, size_t row )
239eaa41 131{
8f850e28 132 bool ret = true;
b5d777c7 133
85e5bb6a 134 wxList::compatibility_iterator node = m_notifiers.GetFirst();
b5d777c7
RR
135 while (node)
136 {
8f850e28
RR
137 wxDataViewListModelNotifier* notifier = (wxDataViewListModelNotifier*) node->GetData();
138 if (!notifier->ValueChanged( col, row ))
139 ret = false;
b5d777c7
RR
140 node = node->GetNext();
141 }
f554a14b 142
b5d777c7 143 return ret;
239eaa41
RR
144}
145
4eccd3a1
RR
146bool wxDataViewListModel::RowsReordered( size_t *new_order )
147{
148 bool ret = true;
149
85e5bb6a 150 wxList::compatibility_iterator node = m_notifiers.GetFirst();
4eccd3a1
RR
151 while (node)
152 {
153 wxDataViewListModelNotifier* notifier = (wxDataViewListModelNotifier*) node->GetData();
154 if (!notifier->RowsReordered( new_order ))
155 ret = false;
156 node = node->GetNext();
157 }
f554a14b 158
4eccd3a1
RR
159 return ret;
160}
161
239eaa41
RR
162bool wxDataViewListModel::Cleared()
163{
8f850e28
RR
164 bool ret = true;
165
85e5bb6a 166 wxList::compatibility_iterator node = m_notifiers.GetFirst();
8f850e28
RR
167 while (node)
168 {
169 wxDataViewListModelNotifier* notifier = (wxDataViewListModelNotifier*) node->GetData();
170 if (!notifier->Cleared())
171 ret = false;
172 node = node->GetNext();
173 }
f554a14b 174
8f850e28 175 return ret;
239eaa41
RR
176}
177
b5d777c7
RR
178void wxDataViewListModel::AddViewingColumn( wxDataViewColumn *view_column, size_t model_column )
179{
180 m_viewingColumns.Append( new wxDataViewViewingColumn( view_column, model_column ) );
181}
182
183void wxDataViewListModel::RemoveViewingColumn( wxDataViewColumn *column )
184{
85e5bb6a 185 wxList::compatibility_iterator node = m_viewingColumns.GetFirst();
b5d777c7
RR
186 while (node)
187 {
188 wxDataViewViewingColumn* tmp = (wxDataViewViewingColumn*) node->GetData();
f554a14b 189
b5d777c7
RR
190 if (tmp->m_viewColumn == column)
191 {
192 m_viewingColumns.DeleteObject( tmp );
193 return;
194 }
f554a14b 195
b5d777c7
RR
196 node = node->GetNext();
197 }
198}
199
8f850e28 200void wxDataViewListModel::AddNotifier( wxDataViewListModelNotifier *notifier )
239eaa41 201{
8f850e28
RR
202 m_notifiers.Append( notifier );
203 notifier->SetOwner( this );
239eaa41
RR
204}
205
8f850e28 206void wxDataViewListModel::RemoveNotifier( wxDataViewListModelNotifier *notifier )
239eaa41 207{
8f850e28 208 m_notifiers.DeleteObject( notifier );
239eaa41
RR
209}
210
f554a14b 211// ---------------------------------------------------------
4eccd3a1 212// wxDataViewSortedListModelNotifier
f554a14b 213// ---------------------------------------------------------
4eccd3a1
RR
214
215class wxDataViewSortedListModelNotifier: public wxDataViewListModelNotifier
216{
217public:
218 wxDataViewSortedListModelNotifier( wxDataViewSortedListModel *model )
4627af27
RR
219 { m_model = model; }
220
221 virtual bool RowAppended()
222 { return m_model->ChildRowAppended(); }
9969fdfe 223
4627af27
RR
224 virtual bool RowPrepended()
225 { return m_model->ChildRowPrepended(); }
9969fdfe 226
4627af27
RR
227 virtual bool RowInserted( size_t before )
228 { return m_model->ChildRowInserted( before ); }
9969fdfe 229
4627af27
RR
230 virtual bool RowDeleted( size_t row )
231 { return m_model->ChildRowDeleted( row ); }
9969fdfe 232
4627af27
RR
233 virtual bool RowChanged( size_t row )
234 { return m_model->ChildRowChanged( row ); }
9969fdfe 235
4eccd3a1 236 virtual bool ValueChanged( size_t col, size_t row )
4627af27 237 { return m_model->ChildValueChanged( col, row); }
9969fdfe 238
4627af27 239 virtual bool RowsReordered( size_t *new_order )
9969fdfe
WS
240 { return m_model->ChildRowsReordered( new_order ); }
241
4627af27
RR
242 virtual bool Cleared()
243 { return m_model->ChildCleared(); }
f554a14b 244
4eccd3a1
RR
245 wxDataViewSortedListModel *m_model;
246};
247
f554a14b 248// ---------------------------------------------------------
4eccd3a1 249// wxDataViewSortedListModel compare function
f554a14b 250// ---------------------------------------------------------
8981608c
RR
251
252int wxCALLBACK wxDataViewListModelSortedDefaultCompare
253 (size_t row1, size_t row2, size_t col, wxDataViewListModel* model )
254{
3f3af7e7
RR
255 wxVariant value1,value2;
256 model->GetValue( value1, col, row1 );
257 model->GetValue( value2, col, row2 );
8981608c
RR
258 if (value1.GetType() == wxT("string"))
259 {
260 wxString str1 = value1.GetString();
261 wxString str2 = value2.GetString();
262 return str1.Cmp( str2 );
263 }
264 if (value1.GetType() == wxT("long"))
265 {
266 long l1 = value1.GetLong();
267 long l2 = value2.GetLong();
268 return l1-l2;
269 }
270 if (value1.GetType() == wxT("double"))
271 {
272 double d1 = value1.GetDouble();
273 double d2 = value2.GetDouble();
274 if (d1 == d2) return 0;
275 if (d1 < d2) return 1;
276 return -1;
277 }
278 if (value1.GetType() == wxT("datetime"))
279 {
280 wxDateTime dt1 = value1.GetDateTime();
281 wxDateTime dt2 = value2.GetDateTime();
282 if (dt1.IsEqualTo(dt2)) return 0;
283 if (dt1.IsEarlierThan(dt2)) return 1;
284 return -1;
285 }
286
287 return 0;
288}
289
290static wxDataViewListModelCompare s_CmpFunc;
291static wxDataViewListModel *s_CmpModel;
292static size_t s_CmpCol;
293
294int LINKAGEMODE wxDataViewIntermediateCmp( size_t row1, size_t row2 )
295{
296 return s_CmpFunc( row1, row2, s_CmpCol, s_CmpModel );
297}
298
f554a14b 299// ---------------------------------------------------------
4eccd3a1
RR
300// wxDataViewSortedListModel
301// ---------------------------------------------------------
8981608c
RR
302
303IMPLEMENT_ABSTRACT_CLASS(wxDataViewSortedListModel, wxDataViewListModel)
304
305wxDataViewSortedListModel::wxDataViewSortedListModel( wxDataViewListModel *child ) :
306 m_array( wxDataViewIntermediateCmp )
307{
308 m_child = child;
309 s_CmpCol = 0;
310 s_CmpModel = child;
311 s_CmpFunc = wxDataViewListModelSortedDefaultCompare;
f554a14b 312
4eccd3a1
RR
313 m_notifierOnChild = new wxDataViewSortedListModelNotifier( this );
314 m_child->AddNotifier( m_notifierOnChild );
f554a14b
WS
315
316 Resort();
8981608c
RR
317}
318
319wxDataViewSortedListModel::~wxDataViewSortedListModel()
320{
4eccd3a1 321 m_child->RemoveNotifier( m_notifierOnChild );
8981608c
RR
322}
323
8f850e28
RR
324void wxDataViewSortedListModel::Resort()
325{
326 m_array.Clear();
327 size_t n = m_child->GetNumberOfRows();
328 size_t i;
329 for (i = 0; i < n; i++)
330 m_array.Add( i );
331}
332
3f3af7e7
RR
333#if 0
334static void Dump( wxDataViewListModel *model, size_t col )
335{
336 size_t n = model->GetNumberOfRows();
337 size_t i;
338 for (i = 0; i < n; i++)
339 {
340 wxVariant variant;
341 model->GetValue( variant, col, i );
342 wxString tmp;
343 tmp = variant.GetString();
344 wxPrintf( wxT("%d: %s\n"), (int) i, tmp.c_str() );
345 }
346}
347#endif
348
4627af27
RR
349bool wxDataViewSortedListModel::ChildRowAppended()
350{
351 // no need to fix up array
9969fdfe 352
4627af27 353 size_t len = m_array.GetCount();
9969fdfe 354
4627af27 355 size_t pos = m_array.Add( len );
9969fdfe 356
4627af27
RR
357 if (pos == 0)
358 return wxDataViewListModel::RowPrepended();
9969fdfe 359
4627af27
RR
360 if (pos == len)
361 return wxDataViewListModel::RowAppended();
9969fdfe 362
4627af27
RR
363 return wxDataViewListModel::RowInserted( pos );
364}
365
366bool wxDataViewSortedListModel::ChildRowPrepended()
367{
368 // fix up array
369 size_t i;
370 size_t len = m_array.GetCount();
371 for (i = 0; i < len; i++)
372 {
373 size_t value = m_array[i];
374 m_array[i] = value+1;
375 }
9969fdfe 376
4627af27 377 size_t pos = m_array.Add( 0 );
9969fdfe 378
4627af27
RR
379 if (pos == 0)
380 return wxDataViewListModel::RowPrepended();
9969fdfe 381
4627af27
RR
382 if (pos == len)
383 return wxDataViewListModel::RowAppended();
9969fdfe 384
4627af27
RR
385 return wxDataViewListModel::RowInserted( pos );
386}
387
388bool wxDataViewSortedListModel::ChildRowInserted( size_t before )
389{
390 // fix up array
391 size_t i;
392 size_t len = m_array.GetCount();
393 for (i = 0; i < len; i++)
394 {
395 size_t value = m_array[i];
396 if (value >= before)
397 m_array[i] = value+1;
398 }
9969fdfe 399
4627af27 400 size_t pos = m_array.Add( before );
9969fdfe 401
4627af27
RR
402 if (pos == 0)
403 return wxDataViewListModel::RowPrepended();
9969fdfe 404
4627af27
RR
405 if (pos == len)
406 return wxDataViewListModel::RowAppended();
9969fdfe 407
4627af27
RR
408 return wxDataViewListModel::RowInserted( pos );
409}
410
411bool wxDataViewSortedListModel::ChildRowDeleted( size_t row )
412{
413 size_t i;
414 size_t len = m_array.GetCount();
415 int pos = -1;
416 for (i = 0; i < len; i++)
417 {
418 size_t value = m_array[i];
419 if (value == row)
420 {
421 // delete later
422 pos = (int) i;
423 }
424 else
425 {
426 // Fix up array
427 if (value > row)
428 m_array[i] = value-1;
429 }
430 }
9969fdfe 431
4627af27
RR
432 if (pos == -1)
433 return false; // we should probably assert
434
9969fdfe 435 // remove
4627af27
RR
436 m_array.RemoveAt( (size_t) pos );
437
438 return wxDataViewListModel::RowDeleted( (size_t) pos);
439}
440
441bool wxDataViewSortedListModel::ChildRowChanged( size_t row )
442{
443 size_t i;
444 size_t len = m_array.GetCount();
445
446 // Remove and readd sorted. Find out at which
447 // position it was and where it ended.
448 size_t start_pos = 0,end_pos = 0;
449 for (i = 0; i < len; i++)
450 if (m_array[i] == row)
451 {
452 start_pos = i;
453 break;
454 }
455 m_array.RemoveAt( start_pos );
456 m_array.Add( row );
457
458 for (i = 0; i < len; i++)
459 if (m_array[i] == row)
460 {
461 end_pos = i;
462 break;
463 }
464
465 if (end_pos == start_pos)
466 return wxDataViewListModel::RowChanged( start_pos );
467
468 // Create an array where order[old] -> new_pos, so that
469 // if nothing changed order[0] -> 0 etc.
470 size_t *order = new size_t[ len ];
471 // Fill up initial values.
472 for (i = 0; i < len; i++)
473 order[i] = i;
474
475 if (start_pos < end_pos)
476 {
477 for (i = start_pos; i < end_pos; i++)
478 order[i] = order[i+1];
479 order[end_pos] = start_pos;
480 }
481 else
482 {
483 for (i = end_pos; i > start_pos; i--)
484 order[i] = order[i-1];
485 order[start_pos] = end_pos;
486 }
487
488 wxDataViewListModel::RowsReordered( order );
489
490 delete [] order;
491
492 return true;
493}
494
4eccd3a1
RR
495bool wxDataViewSortedListModel::ChildValueChanged( size_t col, size_t row )
496{
497 size_t i;
498 size_t len = m_array.GetCount();
f554a14b 499
4eccd3a1
RR
500 // Remove and readd sorted. Find out at which
501 // position it was and where it ended.
502 size_t start_pos = 0,end_pos = 0;
503 for (i = 0; i < len; i++)
504 if (m_array[i] == row)
505 {
506 start_pos = i;
507 break;
508 }
3f3af7e7 509 m_array.RemoveAt( start_pos );
4eccd3a1 510 m_array.Add( row );
f554a14b 511
4eccd3a1
RR
512 for (i = 0; i < len; i++)
513 if (m_array[i] == row)
514 {
515 end_pos = i;
516 break;
517 }
f554a14b 518
4eccd3a1
RR
519 if (end_pos == start_pos)
520 return wxDataViewListModel::ValueChanged( col, start_pos );
f554a14b 521
4eccd3a1
RR
522 // Create an array where order[old] -> new_pos, so that
523 // if nothing changed order[0] -> 0 etc.
524 size_t *order = new size_t[ len ];
525 // Fill up initial values.
526 for (i = 0; i < len; i++)
527 order[i] = i;
528
529 if (start_pos < end_pos)
530 {
531 for (i = start_pos; i < end_pos; i++)
532 order[i] = order[i+1];
533 order[end_pos] = start_pos;
534 }
535 else
536 {
537 for (i = end_pos; i > start_pos; i--)
538 order[i] = order[i-1];
539 order[start_pos] = end_pos;
f554a14b
WS
540 }
541
3f3af7e7 542 wxDataViewListModel::RowsReordered( order );
f554a14b 543
4eccd3a1 544 delete [] order;
f554a14b 545
4eccd3a1
RR
546 return true;
547}
548
9969fdfe 549bool wxDataViewSortedListModel::ChildRowsReordered( size_t *WXUNUSED(new_order) )
4627af27
RR
550{
551 // Nothing needs to be done. If the sort criteria
552 // of this list don't change, the order of the
553 // items of the child list isn't relevant.
554 return true;
555}
556
557bool wxDataViewSortedListModel::ChildCleared()
558{
559 return wxDataViewListModel::Cleared();
560}
561
8981608c
RR
562size_t wxDataViewSortedListModel::GetNumberOfRows()
563{
3f3af7e7 564 return m_array.GetCount();
8981608c
RR
565}
566
567size_t wxDataViewSortedListModel::GetNumberOfCols()
568{
569 return m_child->GetNumberOfCols();
570}
571
572wxString wxDataViewSortedListModel::GetColType( size_t col )
573{
574 return m_child->GetColType( col );
575}
576
3f3af7e7 577void wxDataViewSortedListModel::GetValue( wxVariant &variant, size_t col, size_t row )
8981608c
RR
578{
579 size_t child_row = m_array[row];
3f3af7e7 580 m_child->GetValue( variant, col, child_row );
8981608c
RR
581}
582
583bool wxDataViewSortedListModel::SetValue( wxVariant &variant, size_t col, size_t row )
584{
585 size_t child_row = m_array[row];
586 bool ret = m_child->SetValue( variant, col, child_row );
f554a14b 587
4627af27
RR
588 // Do nothing here as the change in the
589 // child model will be reported back.
f554a14b 590
8981608c
RR
591 return ret;
592}
593
594bool wxDataViewSortedListModel::RowAppended()
595{
596 // you can only append
597 bool ret = m_child->RowAppended();
f554a14b 598
4627af27
RR
599 // Do nothing here as the change in the
600 // child model will be reported back.
f554a14b 601
8981608c
RR
602 return ret;
603}
604
605bool wxDataViewSortedListModel::RowPrepended()
606{
607 // you can only append
608 bool ret = m_child->RowAppended();
f554a14b 609
4627af27
RR
610 // Do nothing here as the change in the
611 // child model will be reported back.
f554a14b 612
8981608c
RR
613 return ret;
614}
615
f554a14b 616bool wxDataViewSortedListModel::RowInserted( size_t WXUNUSED(before) )
8981608c
RR
617{
618 // you can only append
619 bool ret = m_child->RowAppended();
f554a14b 620
4627af27
RR
621 // Do nothing here as the change in the
622 // child model will be reported back.
f554a14b 623
8981608c
RR
624 return ret;
625}
626
627bool wxDataViewSortedListModel::RowDeleted( size_t row )
628{
629 size_t child_row = m_array[row];
f554a14b 630
8981608c 631 bool ret = m_child->RowDeleted( child_row );
f554a14b 632
4eccd3a1
RR
633 // Do nothing here as the change in the
634 // child model will be reported back.
f554a14b 635
8981608c
RR
636 return ret;
637}
638
639bool wxDataViewSortedListModel::RowChanged( size_t row )
640{
641 size_t child_row = m_array[row];
642 bool ret = m_child->RowChanged( child_row );
f554a14b 643
4eccd3a1
RR
644 // Do nothing here as the change in the
645 // child model will be reported back.
f554a14b 646
8981608c
RR
647 return ret;
648}
649
650bool wxDataViewSortedListModel::ValueChanged( size_t col, size_t row )
651{
652 size_t child_row = m_array[row];
653 bool ret = m_child->ValueChanged( col, child_row );
f554a14b 654
4eccd3a1
RR
655 // Do nothing here as the change in the
656 // child model will be reported back.
f554a14b 657
8981608c
RR
658 return ret;
659}
660
f554a14b 661bool wxDataViewSortedListModel::RowsReordered( size_t *WXUNUSED(new_order) )
4eccd3a1
RR
662{
663 // We sort them ourselves.
664
665 return false;
666}
667
8981608c
RR
668bool wxDataViewSortedListModel::Cleared()
669{
670 bool ret = m_child->Cleared();
f554a14b 671
4627af27
RR
672 // Do nothing here as the change in the
673 // child model will be reported back.
9969fdfe 674
8981608c
RR
675 return ret;
676}
677
f554a14b 678// ---------------------------------------------------------
6842a71a 679// wxDataViewCellBase
f554a14b 680// ---------------------------------------------------------
6842a71a
RR
681
682IMPLEMENT_ABSTRACT_CLASS(wxDataViewCellBase, wxObject)
683
684wxDataViewCellBase::wxDataViewCellBase( const wxString &varianttype, wxDataViewCellMode mode )
685{
686 m_variantType = varianttype;
687 m_mode = mode;
688}
f554a14b
WS
689
690// ---------------------------------------------------------
fa28826d 691// wxDataViewColumnBase
f554a14b 692// ---------------------------------------------------------
fa28826d
RR
693
694IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase, wxObject)
695
27fd2cb6
VZ
696wxDataViewColumnBase::wxDataViewColumnBase(const wxString& title,
697 wxDataViewCell *cell,
698 size_t model_column,
699 int WXUNUSED(fixed_width),
700 wxDataViewColumnSizing WXUNUSED(sizing),
701 int flags )
fa28826d 702{
6842a71a
RR
703 m_cell = cell;
704 m_model_column = model_column;
fa28826d
RR
705 m_flags = flags;
706 m_title = title;
6842a71a
RR
707 m_owner = NULL;
708 m_cell->SetOwner( (wxDataViewColumn*) this );
709}
710
711wxDataViewColumnBase::~wxDataViewColumnBase()
712{
713 if (m_cell)
714 delete m_cell;
f554a14b 715
b5d777c7
RR
716 if (GetOwner())
717 {
718 GetOwner()->GetModel()->RemoveViewingColumn( (wxDataViewColumn*) this );
719 }
fa28826d
RR
720}
721
722void wxDataViewColumnBase::SetTitle( const wxString &title )
723{
724 m_title = title;
725}
726
727wxString wxDataViewColumnBase::GetTitle()
728{
729 return m_title;
730}
731
f554a14b 732// ---------------------------------------------------------
239eaa41 733// wxDataViewCtrlBase
f554a14b 734// ---------------------------------------------------------
239eaa41
RR
735
736IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl)
737
738wxDataViewCtrlBase::wxDataViewCtrlBase()
739{
740 m_model = NULL;
fa28826d 741 m_cols.DeleteContents( true );
239eaa41
RR
742}
743
744wxDataViewCtrlBase::~wxDataViewCtrlBase()
745{
239eaa41
RR
746}
747
6e2e590f 748bool wxDataViewCtrlBase::AssociateModel( wxDataViewListModel *model )
239eaa41 749{
239eaa41 750 m_model = model;
f554a14b 751
239eaa41
RR
752 return true;
753}
754
6e2e590f 755wxDataViewListModel* wxDataViewCtrlBase::GetModel()
239eaa41
RR
756{
757 return m_model;
758}
759
605c2c4a 760bool wxDataViewCtrlBase::AppendTextColumn( const wxString &label, size_t model_column )
fa28826d 761{
6842a71a 762 return AppendColumn( new wxDataViewColumn( label, new wxDataViewTextCell(), model_column ) );
fa28826d
RR
763}
764
605c2c4a
RR
765bool wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, size_t model_column )
766{
533544f2 767 return AppendColumn( new wxDataViewColumn( label, new wxDataViewToggleCell(), model_column, 30 ) );
605c2c4a
RR
768}
769
ad63bf41
RR
770bool wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, size_t model_column )
771{
533544f2 772 return AppendColumn( new wxDataViewColumn( label, new wxDataViewProgressCell(), model_column, 70 ) );
ad63bf41
RR
773}
774
4d496ecb
RR
775bool wxDataViewCtrlBase::AppendDateColumn( const wxString &label, size_t model_column )
776{
777 return AppendColumn( new wxDataViewColumn( label, new wxDataViewDateCell(), model_column ) );
778}
779
fa28826d
RR
780bool wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col )
781{
782 m_cols.Append( (wxObject*) col );
6842a71a 783 col->SetOwner( (wxDataViewCtrl*) this );
b5d777c7 784 m_model->AddViewingColumn( col, col->GetModelColumn() );
fa28826d
RR
785 return true;
786}
787
788size_t wxDataViewCtrlBase::GetNumberOfColumns()
789{
790 return m_cols.GetCount();
791}
792
f554a14b 793bool wxDataViewCtrlBase::DeleteColumn( size_t WXUNUSED(pos) )
fa28826d
RR
794{
795 return false;
796}
797
798bool wxDataViewCtrlBase::ClearColumns()
799{
800 return false;
801}
802
803wxDataViewColumn* wxDataViewCtrlBase::GetColumn( size_t pos )
804{
805 return (wxDataViewColumn*) m_cols[ pos ];
806}
807
8045736e 808#endif