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