]> git.saurik.com Git - wxWidgets.git/blame - src/common/datavcmn.cpp
use wxObject copy ctor, not default ctor, in wxEvent copy ctor
[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
0a71f9e9 82bool wxDataViewListModel::RowInserted( unsigned int before )
239eaa41 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
0a71f9e9 98bool wxDataViewListModel::RowDeleted( unsigned int row )
239eaa41 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
0a71f9e9 114bool wxDataViewListModel::RowChanged( unsigned int row )
239eaa41 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
0a71f9e9 130bool wxDataViewListModel::ValueChanged( unsigned int col, unsigned int 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
0a71f9e9 146bool wxDataViewListModel::RowsReordered( unsigned int *new_order )
4eccd3a1
RR
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
0a71f9e9 178void wxDataViewListModel::AddViewingColumn( wxDataViewColumn *view_column, unsigned int model_column )
b5d777c7
RR
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
0a71f9e9 227 virtual bool RowInserted( unsigned int before )
4627af27 228 { return m_model->ChildRowInserted( before ); }
9969fdfe 229
0a71f9e9 230 virtual bool RowDeleted( unsigned int row )
4627af27 231 { return m_model->ChildRowDeleted( row ); }
9969fdfe 232
0a71f9e9 233 virtual bool RowChanged( unsigned int row )
4627af27 234 { return m_model->ChildRowChanged( row ); }
9969fdfe 235
0a71f9e9 236 virtual bool ValueChanged( unsigned int col, unsigned int row )
4627af27 237 { return m_model->ChildValueChanged( col, row); }
9969fdfe 238
0a71f9e9 239 virtual bool RowsReordered( unsigned int *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
0a71f9e9 253 (unsigned int row1, unsigned int row2, unsigned int col, wxDataViewListModel* model )
8981608c 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
31fb32e1
RR
290int wxCALLBACK wxDataViewListModelSortedDefaultCompareDescending
291 (unsigned int row1, unsigned int row2, unsigned int col, wxDataViewListModel* model )
292{
293 return wxDataViewListModelSortedDefaultCompare( row2, row1, col, model );
294}
295
8981608c
RR
296static wxDataViewListModelCompare s_CmpFunc;
297static wxDataViewListModel *s_CmpModel;
31fb32e1 298static unsigned int s_CmpCol;
8981608c 299
0a71f9e9 300int LINKAGEMODE wxDataViewIntermediateCmp( unsigned int row1, unsigned int row2 )
8981608c
RR
301{
302 return s_CmpFunc( row1, row2, s_CmpCol, s_CmpModel );
303}
304
f554a14b 305// ---------------------------------------------------------
4eccd3a1
RR
306// wxDataViewSortedListModel
307// ---------------------------------------------------------
8981608c
RR
308
309IMPLEMENT_ABSTRACT_CLASS(wxDataViewSortedListModel, wxDataViewListModel)
310
311wxDataViewSortedListModel::wxDataViewSortedListModel( wxDataViewListModel *child ) :
312 m_array( wxDataViewIntermediateCmp )
313{
314 m_child = child;
31fb32e1
RR
315
316 m_ascending = true;
f554a14b 317
4eccd3a1
RR
318 m_notifierOnChild = new wxDataViewSortedListModelNotifier( this );
319 m_child->AddNotifier( m_notifierOnChild );
f554a14b
WS
320
321 Resort();
8981608c
RR
322}
323
324wxDataViewSortedListModel::~wxDataViewSortedListModel()
325{
4eccd3a1 326 m_child->RemoveNotifier( m_notifierOnChild );
8981608c
RR
327}
328
31fb32e1
RR
329// FIXME
330void wxDataViewSortedListModel::InitStatics()
331{
332 s_CmpCol = 0;
333 s_CmpModel = m_child;
334 if (m_ascending)
335 s_CmpFunc = wxDataViewListModelSortedDefaultCompare;
336 else
337 s_CmpFunc = wxDataViewListModelSortedDefaultCompareDescending;
338}
339
8f850e28
RR
340void wxDataViewSortedListModel::Resort()
341{
31fb32e1
RR
342 InitStatics();
343
8f850e28 344 m_array.Clear();
0a71f9e9
RR
345 unsigned int n = m_child->GetNumberOfRows();
346 unsigned int i;
8f850e28
RR
347 for (i = 0; i < n; i++)
348 m_array.Add( i );
349}
350
3f3af7e7 351#if 0
0a71f9e9 352static void Dump( wxDataViewListModel *model, unsigned int col )
3f3af7e7 353{
0a71f9e9
RR
354 unsigned int n = model->GetNumberOfRows();
355 unsigned int i;
3f3af7e7
RR
356 for (i = 0; i < n; i++)
357 {
358 wxVariant variant;
359 model->GetValue( variant, col, i );
360 wxString tmp;
361 tmp = variant.GetString();
362 wxPrintf( wxT("%d: %s\n"), (int) i, tmp.c_str() );
363 }
364}
365#endif
366
4627af27
RR
367bool wxDataViewSortedListModel::ChildRowAppended()
368{
369 // no need to fix up array
9969fdfe 370
0a71f9e9 371 unsigned int len = m_array.GetCount();
9969fdfe 372
0a71f9e9 373 unsigned int pos = m_array.Add( len );
9969fdfe 374
4627af27
RR
375 if (pos == 0)
376 return wxDataViewListModel::RowPrepended();
9969fdfe 377
4627af27
RR
378 if (pos == len)
379 return wxDataViewListModel::RowAppended();
9969fdfe 380
4627af27
RR
381 return wxDataViewListModel::RowInserted( pos );
382}
383
384bool wxDataViewSortedListModel::ChildRowPrepended()
385{
386 // fix up array
0a71f9e9
RR
387 unsigned int i;
388 unsigned int len = m_array.GetCount();
4627af27
RR
389 for (i = 0; i < len; i++)
390 {
0a71f9e9 391 unsigned int value = m_array[i];
4627af27
RR
392 m_array[i] = value+1;
393 }
9969fdfe 394
0a71f9e9 395 unsigned int pos = m_array.Add( 0 );
9969fdfe 396
4627af27
RR
397 if (pos == 0)
398 return wxDataViewListModel::RowPrepended();
9969fdfe 399
4627af27
RR
400 if (pos == len)
401 return wxDataViewListModel::RowAppended();
9969fdfe 402
4627af27
RR
403 return wxDataViewListModel::RowInserted( pos );
404}
405
0a71f9e9 406bool wxDataViewSortedListModel::ChildRowInserted( unsigned int before )
4627af27
RR
407{
408 // fix up array
0a71f9e9
RR
409 unsigned int i;
410 unsigned int len = m_array.GetCount();
4627af27
RR
411 for (i = 0; i < len; i++)
412 {
0a71f9e9 413 unsigned int value = m_array[i];
4627af27
RR
414 if (value >= before)
415 m_array[i] = value+1;
416 }
9969fdfe 417
0a71f9e9 418 unsigned int pos = m_array.Add( before );
9969fdfe 419
4627af27
RR
420 if (pos == 0)
421 return wxDataViewListModel::RowPrepended();
9969fdfe 422
4627af27
RR
423 if (pos == len)
424 return wxDataViewListModel::RowAppended();
9969fdfe 425
4627af27
RR
426 return wxDataViewListModel::RowInserted( pos );
427}
428
0a71f9e9 429bool wxDataViewSortedListModel::ChildRowDeleted( unsigned int row )
4627af27 430{
0a71f9e9
RR
431 unsigned int i;
432 unsigned int len = m_array.GetCount();
4627af27
RR
433 int pos = -1;
434 for (i = 0; i < len; i++)
435 {
0a71f9e9 436 unsigned int value = m_array[i];
4627af27
RR
437 if (value == row)
438 {
439 // delete later
440 pos = (int) i;
441 }
442 else
443 {
444 // Fix up array
445 if (value > row)
446 m_array[i] = value-1;
447 }
448 }
9969fdfe 449
4627af27
RR
450 if (pos == -1)
451 return false; // we should probably assert
452
9969fdfe 453 // remove
0a71f9e9 454 m_array.RemoveAt( (unsigned int) pos );
4627af27 455
0a71f9e9 456 return wxDataViewListModel::RowDeleted( (unsigned int) pos);
4627af27
RR
457}
458
0a71f9e9 459bool wxDataViewSortedListModel::ChildRowChanged( unsigned int row )
4627af27 460{
0a71f9e9
RR
461 unsigned int i;
462 unsigned int len = m_array.GetCount();
4627af27
RR
463
464 // Remove and readd sorted. Find out at which
465 // position it was and where it ended.
0a71f9e9 466 unsigned int start_pos = 0,end_pos = 0;
4627af27
RR
467 for (i = 0; i < len; i++)
468 if (m_array[i] == row)
469 {
470 start_pos = i;
471 break;
472 }
473 m_array.RemoveAt( start_pos );
474 m_array.Add( row );
475
476 for (i = 0; i < len; i++)
477 if (m_array[i] == row)
478 {
479 end_pos = i;
480 break;
481 }
482
483 if (end_pos == start_pos)
484 return wxDataViewListModel::RowChanged( start_pos );
485
486 // Create an array where order[old] -> new_pos, so that
487 // if nothing changed order[0] -> 0 etc.
0a71f9e9 488 unsigned int *order = new unsigned int[ len ];
4627af27
RR
489 // Fill up initial values.
490 for (i = 0; i < len; i++)
491 order[i] = i;
492
493 if (start_pos < end_pos)
494 {
495 for (i = start_pos; i < end_pos; i++)
496 order[i] = order[i+1];
497 order[end_pos] = start_pos;
498 }
499 else
500 {
501 for (i = end_pos; i > start_pos; i--)
502 order[i] = order[i-1];
503 order[start_pos] = end_pos;
504 }
505
506 wxDataViewListModel::RowsReordered( order );
507
508 delete [] order;
509
510 return true;
511}
512
0a71f9e9 513bool wxDataViewSortedListModel::ChildValueChanged( unsigned int col, unsigned int row )
4eccd3a1 514{
0a71f9e9
RR
515 unsigned int i;
516 unsigned int len = m_array.GetCount();
f554a14b 517
4eccd3a1
RR
518 // Remove and readd sorted. Find out at which
519 // position it was and where it ended.
0a71f9e9 520 unsigned int start_pos = 0,end_pos = 0;
4eccd3a1
RR
521 for (i = 0; i < len; i++)
522 if (m_array[i] == row)
523 {
524 start_pos = i;
525 break;
526 }
3f3af7e7 527 m_array.RemoveAt( start_pos );
4eccd3a1 528 m_array.Add( row );
f554a14b 529
4eccd3a1
RR
530 for (i = 0; i < len; i++)
531 if (m_array[i] == row)
532 {
533 end_pos = i;
534 break;
535 }
f554a14b 536
4eccd3a1
RR
537 if (end_pos == start_pos)
538 return wxDataViewListModel::ValueChanged( col, start_pos );
f554a14b 539
4eccd3a1
RR
540 // Create an array where order[old] -> new_pos, so that
541 // if nothing changed order[0] -> 0 etc.
0a71f9e9 542 unsigned int *order = new unsigned int[ len ];
4eccd3a1
RR
543 // Fill up initial values.
544 for (i = 0; i < len; i++)
545 order[i] = i;
546
547 if (start_pos < end_pos)
548 {
549 for (i = start_pos; i < end_pos; i++)
550 order[i] = order[i+1];
551 order[end_pos] = start_pos;
552 }
553 else
554 {
555 for (i = end_pos; i > start_pos; i--)
556 order[i] = order[i-1];
557 order[start_pos] = end_pos;
f554a14b
WS
558 }
559
3f3af7e7 560 wxDataViewListModel::RowsReordered( order );
f554a14b 561
4eccd3a1 562 delete [] order;
f554a14b 563
4eccd3a1
RR
564 return true;
565}
566
0a71f9e9 567bool wxDataViewSortedListModel::ChildRowsReordered( unsigned int *WXUNUSED(new_order) )
4627af27
RR
568{
569 // Nothing needs to be done. If the sort criteria
570 // of this list don't change, the order of the
571 // items of the child list isn't relevant.
572 return true;
573}
574
575bool wxDataViewSortedListModel::ChildCleared()
576{
577 return wxDataViewListModel::Cleared();
578}
579
0a71f9e9 580unsigned int wxDataViewSortedListModel::GetNumberOfRows()
8981608c 581{
3f3af7e7 582 return m_array.GetCount();
8981608c
RR
583}
584
0a71f9e9 585unsigned int wxDataViewSortedListModel::GetNumberOfCols()
8981608c
RR
586{
587 return m_child->GetNumberOfCols();
588}
589
0a71f9e9 590wxString wxDataViewSortedListModel::GetColType( unsigned int col )
8981608c
RR
591{
592 return m_child->GetColType( col );
593}
594
0a71f9e9 595void wxDataViewSortedListModel::GetValue( wxVariant &variant, unsigned int col, unsigned int row )
8981608c 596{
0a71f9e9 597 unsigned int child_row = m_array[row];
3f3af7e7 598 m_child->GetValue( variant, col, child_row );
8981608c
RR
599}
600
0a71f9e9 601bool wxDataViewSortedListModel::SetValue( wxVariant &variant, unsigned int col, unsigned int row )
8981608c 602{
0a71f9e9 603 unsigned int child_row = m_array[row];
8981608c 604 bool ret = m_child->SetValue( variant, col, child_row );
f554a14b 605
4627af27
RR
606 // Do nothing here as the change in the
607 // child model will be reported back.
f554a14b 608
8981608c
RR
609 return ret;
610}
611
612bool wxDataViewSortedListModel::RowAppended()
613{
614 // you can only append
615 bool ret = m_child->RowAppended();
f554a14b 616
4627af27
RR
617 // Do nothing here as the change in the
618 // child model will be reported back.
f554a14b 619
8981608c
RR
620 return ret;
621}
622
623bool wxDataViewSortedListModel::RowPrepended()
624{
625 // you can only append
626 bool ret = m_child->RowAppended();
f554a14b 627
4627af27
RR
628 // Do nothing here as the change in the
629 // child model will be reported back.
f554a14b 630
8981608c
RR
631 return ret;
632}
633
0a71f9e9 634bool wxDataViewSortedListModel::RowInserted( unsigned int WXUNUSED(before) )
8981608c
RR
635{
636 // you can only append
637 bool ret = m_child->RowAppended();
f554a14b 638
4627af27
RR
639 // Do nothing here as the change in the
640 // child model will be reported back.
f554a14b 641
8981608c
RR
642 return ret;
643}
644
0a71f9e9 645bool wxDataViewSortedListModel::RowDeleted( unsigned int row )
8981608c 646{
0a71f9e9 647 unsigned int child_row = m_array[row];
f554a14b 648
8981608c 649 bool ret = m_child->RowDeleted( child_row );
f554a14b 650
4eccd3a1
RR
651 // Do nothing here as the change in the
652 // child model will be reported back.
f554a14b 653
8981608c
RR
654 return ret;
655}
656
0a71f9e9 657bool wxDataViewSortedListModel::RowChanged( unsigned int row )
8981608c 658{
0a71f9e9 659 unsigned int child_row = m_array[row];
8981608c 660 bool ret = m_child->RowChanged( child_row );
f554a14b 661
4eccd3a1
RR
662 // Do nothing here as the change in the
663 // child model will be reported back.
f554a14b 664
8981608c
RR
665 return ret;
666}
667
0a71f9e9 668bool wxDataViewSortedListModel::ValueChanged( unsigned int col, unsigned int row )
8981608c 669{
0a71f9e9 670 unsigned int child_row = m_array[row];
8981608c 671 bool ret = m_child->ValueChanged( col, child_row );
f554a14b 672
4eccd3a1
RR
673 // Do nothing here as the change in the
674 // child model will be reported back.
f554a14b 675
8981608c
RR
676 return ret;
677}
678
0a71f9e9 679bool wxDataViewSortedListModel::RowsReordered( unsigned int *WXUNUSED(new_order) )
4eccd3a1
RR
680{
681 // We sort them ourselves.
682
683 return false;
684}
685
8981608c
RR
686bool wxDataViewSortedListModel::Cleared()
687{
688 bool ret = m_child->Cleared();
f554a14b 689
4627af27
RR
690 // Do nothing here as the change in the
691 // child model will be reported back.
9969fdfe 692
8981608c
RR
693 return ret;
694}
695
f554a14b 696// ---------------------------------------------------------
baa9ebc4 697// wxDataViewRendererBase
f554a14b 698// ---------------------------------------------------------
6842a71a 699
baa9ebc4 700IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase, wxObject)
6842a71a 701
baa9ebc4 702wxDataViewRendererBase::wxDataViewRendererBase( const wxString &varianttype, wxDataViewCellMode mode )
6842a71a
RR
703{
704 m_variantType = varianttype;
705 m_mode = mode;
706}
f554a14b
WS
707
708// ---------------------------------------------------------
fa28826d 709// wxDataViewColumnBase
f554a14b 710// ---------------------------------------------------------
fa28826d
RR
711
712IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase, wxObject)
713
27fd2cb6 714wxDataViewColumnBase::wxDataViewColumnBase(const wxString& title,
baa9ebc4 715 wxDataViewRenderer *renderer,
0a71f9e9 716 unsigned int model_column,
008b5a66
RR
717 int WXUNUSED(width),
718 int flags )
fa28826d 719{
baa9ebc4 720 m_renderer = renderer;
6842a71a 721 m_model_column = model_column;
fa28826d
RR
722 m_flags = flags;
723 m_title = title;
6842a71a 724 m_owner = NULL;
baa9ebc4 725 m_renderer->SetOwner( (wxDataViewColumn*) this );
6842a71a
RR
726}
727
07a84e7b
RR
728wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap& bitmap,
729 wxDataViewRenderer *renderer,
730 unsigned int model_column,
731 int WXUNUSED(width),
732 int flags )
733{
734 m_renderer = renderer;
735 m_model_column = model_column;
736 m_flags = flags;
737 m_bitmap = bitmap;
738 m_owner = NULL;
739 m_renderer->SetOwner( (wxDataViewColumn*) this );
740}
741
6842a71a
RR
742wxDataViewColumnBase::~wxDataViewColumnBase()
743{
baa9ebc4
RR
744 if (m_renderer)
745 delete m_renderer;
f554a14b 746
b5d777c7
RR
747 if (GetOwner())
748 {
749 GetOwner()->GetModel()->RemoveViewingColumn( (wxDataViewColumn*) this );
750 }
fa28826d
RR
751}
752
753void wxDataViewColumnBase::SetTitle( const wxString &title )
754{
755 m_title = title;
756}
757
758wxString wxDataViewColumnBase::GetTitle()
759{
760 return m_title;
761}
762
07a84e7b
RR
763void wxDataViewColumnBase::SetBitmap( const wxBitmap &bitmap )
764{
765 m_bitmap = bitmap;
766}
767
768const wxBitmap &wxDataViewColumnBase::GetBitmap()
769{
770 return m_bitmap;
771}
772
f554a14b 773// ---------------------------------------------------------
239eaa41 774// wxDataViewCtrlBase
f554a14b 775// ---------------------------------------------------------
239eaa41
RR
776
777IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl)
778
779wxDataViewCtrlBase::wxDataViewCtrlBase()
780{
781 m_model = NULL;
fa28826d 782 m_cols.DeleteContents( true );
239eaa41
RR
783}
784
785wxDataViewCtrlBase::~wxDataViewCtrlBase()
786{
239eaa41
RR
787}
788
6e2e590f 789bool wxDataViewCtrlBase::AssociateModel( wxDataViewListModel *model )
239eaa41 790{
239eaa41 791 m_model = model;
f554a14b 792
239eaa41
RR
793 return true;
794}
795
6e2e590f 796wxDataViewListModel* wxDataViewCtrlBase::GetModel()
239eaa41
RR
797{
798 return m_model;
799}
800
1286b7ba
RR
801bool wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_column,
802 wxDataViewCellMode mode, int width )
fa28826d 803{
1286b7ba
RR
804 return AppendColumn( new wxDataViewColumn( label,
805 new wxDataViewTextRenderer( wxT("string"), mode ), model_column, width ) );
fa28826d
RR
806}
807
1286b7ba
RR
808bool wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int model_column,
809 wxDataViewCellMode mode, int width )
605c2c4a 810{
1286b7ba
RR
811 return AppendColumn( new wxDataViewColumn( label,
812 new wxDataViewToggleRenderer( wxT("bool"), mode ), model_column, width ) );
605c2c4a
RR
813}
814
1286b7ba
RR
815bool wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, unsigned int model_column,
816 wxDataViewCellMode mode, int width )
ad63bf41 817{
1286b7ba
RR
818 return AppendColumn( new wxDataViewColumn( label,
819 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ), model_column, width ) );
ad63bf41
RR
820}
821
1286b7ba
RR
822bool wxDataViewCtrlBase::AppendDateColumn( const wxString &label, unsigned int model_column,
823 wxDataViewCellMode mode, int width )
4d496ecb 824{
1286b7ba
RR
825 return AppendColumn( new wxDataViewColumn( label,
826 new wxDataViewDateRenderer( wxT("datetime"), mode), model_column, width ) );
4d496ecb
RR
827}
828
1286b7ba
RR
829bool wxDataViewCtrlBase::AppendBitmapColumn( const wxString &label, unsigned int model_column,
830 wxDataViewCellMode mode, int width )
07a84e7b 831{
1286b7ba
RR
832 return AppendColumn( new wxDataViewColumn( label,
833 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ), model_column, width ) );
07a84e7b
RR
834}
835
1286b7ba
RR
836bool wxDataViewCtrlBase::AppendTextColumn( const wxBitmap &label, unsigned int model_column,
837 wxDataViewCellMode mode, int width )
07a84e7b 838{
1286b7ba
RR
839 return AppendColumn( new wxDataViewColumn( label,
840 new wxDataViewTextRenderer( wxT("string"), mode ), model_column, width ) );
07a84e7b
RR
841}
842
1286b7ba
RR
843bool wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
844 wxDataViewCellMode mode, int width )
07a84e7b 845{
1286b7ba
RR
846 return AppendColumn( new wxDataViewColumn( label,
847 new wxDataViewToggleRenderer( wxT("bool"), mode ), model_column, width ) );
07a84e7b
RR
848}
849
1286b7ba
RR
850bool wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
851 wxDataViewCellMode mode, int width )
07a84e7b 852{
1286b7ba
RR
853 return AppendColumn( new wxDataViewColumn( label,
854 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ), model_column, width ) );
07a84e7b
RR
855}
856
1286b7ba
RR
857bool wxDataViewCtrlBase::AppendDateColumn( const wxBitmap &label, unsigned int model_column,
858 wxDataViewCellMode mode, int width )
07a84e7b 859{
1286b7ba
RR
860 return AppendColumn( new wxDataViewColumn( label,
861 new wxDataViewDateRenderer( wxT("datetime"), mode ), model_column, width ) );
07a84e7b
RR
862}
863
1286b7ba
RR
864bool wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
865 wxDataViewCellMode mode, int width )
07a84e7b 866{
1286b7ba
RR
867 return AppendColumn( new wxDataViewColumn( label,
868 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ), model_column, width ) );
07a84e7b
RR
869}
870
fa28826d
RR
871bool wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col )
872{
873 m_cols.Append( (wxObject*) col );
6842a71a 874 col->SetOwner( (wxDataViewCtrl*) this );
b5d777c7 875 m_model->AddViewingColumn( col, col->GetModelColumn() );
fa28826d
RR
876 return true;
877}
878
0a71f9e9 879unsigned int wxDataViewCtrlBase::GetNumberOfColumns()
fa28826d
RR
880{
881 return m_cols.GetCount();
882}
883
0a71f9e9 884bool wxDataViewCtrlBase::DeleteColumn( unsigned int WXUNUSED(pos) )
fa28826d
RR
885{
886 return false;
887}
888
889bool wxDataViewCtrlBase::ClearColumns()
890{
891 return false;
892}
893
0a71f9e9 894wxDataViewColumn* wxDataViewCtrlBase::GetColumn( unsigned int pos )
fa28826d
RR
895{
896 return (wxDataViewColumn*) m_cols[ pos ];
897}
898
eb7f97f8
RR
899// ---------------------------------------------------------
900// wxDataViewEvent
901// ---------------------------------------------------------
902
903IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent)
904
905DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ROW_SELECTED)
f828871d 906DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ROW_ACTIVATED)
31fb32e1
RR
907DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK)
908DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK)
eb7f97f8
RR
909
910
8045736e 911#endif