]> git.saurik.com Git - wxWidgets.git/blame - src/common/datavcmn.cpp
fix warnings due to using deprecated-but-used-internally methods from the header...
[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
d5025dc0
RR
29bool operator == (const wxDataViewItem &left, const wxDataViewItem &right)
30{
31 return (left.GetID() == right.GetID() );
32}
33
34
f554a14b 35// ---------------------------------------------------------
d5025dc0 36// wxDataViewModel
f554a14b 37// ---------------------------------------------------------
239eaa41 38
e0062c04 39wxDataViewModel::wxDataViewModel()
239eaa41 40{
8f850e28 41 m_notifiers.DeleteContents( true );
ef427989 42 m_sortingColumn = 0;
9a45b5d5 43 m_ascending = true;
239eaa41
RR
44}
45
e0062c04 46bool wxDataViewModel::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
239eaa41 47{
8f850e28
RR
48 bool ret = true;
49
85e5bb6a 50 wxList::compatibility_iterator node = m_notifiers.GetFirst();
8f850e28
RR
51 while (node)
52 {
e0062c04
RR
53 wxDataViewModelNotifier* notifier = (wxDataViewModelNotifier*) node->GetData();
54 if (!notifier->ItemAdded( parent, item ))
8f850e28
RR
55 ret = false;
56 node = node->GetNext();
57 }
f554a14b 58
8f850e28 59 return ret;
239eaa41
RR
60}
61
e0062c04 62bool wxDataViewModel::ItemDeleted( const wxDataViewItem &item )
239eaa41 63{
8f850e28
RR
64 bool ret = true;
65
85e5bb6a 66 wxList::compatibility_iterator node = m_notifiers.GetFirst();
8f850e28
RR
67 while (node)
68 {
e0062c04
RR
69 wxDataViewModelNotifier* notifier = (wxDataViewModelNotifier*) node->GetData();
70 if (!notifier->ItemDeleted( item ))
8f850e28
RR
71 ret = false;
72 node = node->GetNext();
73 }
f554a14b 74
8f850e28 75 return ret;
239eaa41
RR
76}
77
e0062c04 78bool wxDataViewModel::ItemChanged( const wxDataViewItem &item )
239eaa41 79{
8f850e28
RR
80 bool ret = true;
81
85e5bb6a 82 wxList::compatibility_iterator node = m_notifiers.GetFirst();
8f850e28
RR
83 while (node)
84 {
e0062c04
RR
85 wxDataViewModelNotifier* notifier = (wxDataViewModelNotifier*) node->GetData();
86 if (!notifier->ItemChanged( item ))
8f850e28
RR
87 ret = false;
88 node = node->GetNext();
89 }
f554a14b 90
8f850e28 91 return ret;
239eaa41
RR
92}
93
e0062c04 94bool wxDataViewModel::ValueChanged( const wxDataViewItem &item, unsigned int col )
239eaa41 95{
8f850e28 96 bool ret = true;
b5d777c7 97
85e5bb6a 98 wxList::compatibility_iterator node = m_notifiers.GetFirst();
b5d777c7
RR
99 while (node)
100 {
e0062c04
RR
101 wxDataViewModelNotifier* notifier = (wxDataViewModelNotifier*) node->GetData();
102 if (!notifier->ValueChanged( item, col ))
8f850e28 103 ret = false;
b5d777c7
RR
104 node = node->GetNext();
105 }
f554a14b 106
b5d777c7 107 return ret;
239eaa41
RR
108}
109
e0062c04 110bool wxDataViewModel::Cleared()
4eccd3a1
RR
111{
112 bool ret = true;
113
85e5bb6a 114 wxList::compatibility_iterator node = m_notifiers.GetFirst();
4eccd3a1
RR
115 while (node)
116 {
e0062c04 117 wxDataViewModelNotifier* notifier = (wxDataViewModelNotifier*) node->GetData();
8f850e28
RR
118 if (!notifier->Cleared())
119 ret = false;
120 node = node->GetNext();
121 }
f554a14b 122
8f850e28 123 return ret;
239eaa41
RR
124}
125
ef427989
RR
126void wxDataViewModel::Resort()
127{
128 wxList::compatibility_iterator node = m_notifiers.GetFirst();
129 while (node)
130 {
131 wxDataViewModelNotifier* notifier = (wxDataViewModelNotifier*) node->GetData();
132 notifier->Resort();
133 node = node->GetNext();
134 }
135}
136
e0062c04 137void wxDataViewModel::AddNotifier( wxDataViewModelNotifier *notifier )
239eaa41 138{
8f850e28
RR
139 m_notifiers.Append( notifier );
140 notifier->SetOwner( this );
239eaa41
RR
141}
142
e0062c04 143void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier *notifier )
239eaa41 144{
8f850e28 145 m_notifiers.DeleteObject( notifier );
239eaa41
RR
146}
147
ef427989
RR
148int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 )
149{
cf283a47 150 // sort branches before leaves
ed903e42
RR
151 bool item1_is_container = IsContainer(item1);
152 bool item2_is_container = IsContainer(item2);
cf283a47 153
ed903e42 154 if (item1_is_container && !item2_is_container)
cf283a47 155 return 1;
ed903e42 156 if (item2_is_container && !item1_is_container)
cf283a47
RR
157 return -1;
158
ef427989
RR
159 wxVariant value1,value2;
160 GetValue( value1, item1, m_sortingColumn );
161 GetValue( value2, item2, m_sortingColumn );
cf283a47 162
4508fcd2
RR
163 if (!m_ascending)
164 {
165 wxVariant temp = value1;
166 value1 = value2;
167 value2 = temp;
168 }
169
ef427989
RR
170 if (value1.GetType() == wxT("string"))
171 {
172 wxString str1 = value1.GetString();
173 wxString str2 = value2.GetString();
0be79c8a 174 int res = str1.Cmp( str2 );
cf283a47
RR
175 if (res) return res;
176 } else
ef427989
RR
177 if (value1.GetType() == wxT("long"))
178 {
179 long l1 = value1.GetLong();
180 long l2 = value2.GetLong();
cf283a47
RR
181 long res = l1-l2;
182 if (res) return res;
183 } else
ef427989
RR
184 if (value1.GetType() == wxT("double"))
185 {
186 double d1 = value1.GetDouble();
187 double d2 = value2.GetDouble();
ef427989 188 if (d1 < d2) return 1;
cf283a47
RR
189 if (d1 > d2) return -1;
190 } else
ef427989
RR
191 if (value1.GetType() == wxT("datetime"))
192 {
193 wxDateTime dt1 = value1.GetDateTime();
194 wxDateTime dt2 = value2.GetDateTime();
ef427989 195 if (dt1.IsEarlierThan(dt2)) return 1;
cf283a47 196 if (dt2.IsEarlierThan(dt1)) return -11;
ef427989
RR
197 }
198
cf283a47
RR
199 // items must be different
200 unsigned long litem1 = (unsigned long) item1.GetID();
201 unsigned long litem2 = (unsigned long) item2.GetID();
202
203 if (!m_ascending)
204 return litem2-litem1;
205 return litem1-litem2;
ef427989
RR
206}
207
c534e696
RR
208// ---------------------------------------------------------
209// wxDataViewIndexListModel
210// ---------------------------------------------------------
211
212wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size )
213{
214 // build initial index
215 unsigned int i;
216 for (i = 1; i < initial_size+1; i++)
217 m_hash.Add( (void*) i );
218 m_lastIndex = initial_size + 1;
219}
220
221wxDataViewIndexListModel::~wxDataViewIndexListModel()
222{
223}
224
225void wxDataViewIndexListModel::RowPrepended()
226{
227 unsigned int id = m_lastIndex++;
228 m_hash.Insert( (void*) id, 0 );
229 wxDataViewItem item( (void*) id );
230 ItemAdded( wxDataViewItem(0), item );
231}
232
233void wxDataViewIndexListModel::RowInserted( unsigned int before )
234{
235 unsigned int id = m_lastIndex++;
236 m_hash.Insert( (void*) id, before );
237 wxDataViewItem item( (void*) id );
238 ItemAdded( wxDataViewItem(0), item );
239}
240
241void wxDataViewIndexListModel::RowAppended()
242{
243 unsigned int id = m_lastIndex++;
244 m_hash.Add( (void*) id );
245 wxDataViewItem item( (void*) id );
246 ItemAdded( wxDataViewItem(0), item );
247}
248
249void wxDataViewIndexListModel::RowDeleted( unsigned int row )
250{
251 wxDataViewItem item( m_hash[row] );
252 m_hash.RemoveAt( row );
253 wxDataViewModel::ItemDeleted( item );
254}
255
256void wxDataViewIndexListModel::RowChanged( unsigned int row )
257{
258 wxDataViewModel::ItemChanged( GetItem(row) );
259}
260
261void wxDataViewIndexListModel::RowValueChanged( unsigned int row, unsigned int col )
262{
263 wxDataViewModel::ValueChanged( GetItem(row), col );
264}
265
266unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) const
267{
268 // assert for not found
269 return (unsigned int) m_hash.Index( item.GetID() );
270}
271
272wxDataViewItem wxDataViewIndexListModel::GetItem( unsigned int row ) const
273{
274 return wxDataViewItem( m_hash[row] );
275}
276
277int wxDataViewIndexListModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 )
278{
279 return GetRow(item1) - GetRow(item2);
280}
281
282void wxDataViewIndexListModel::GetValue( wxVariant &variant,
283 const wxDataViewItem &item, unsigned int col ) const
284{
285 return GetValue( variant, GetRow(item), col );
286}
287
288bool wxDataViewIndexListModel::SetValue( const wxVariant &variant,
289 const wxDataViewItem &item, unsigned int col )
290{
291 return SetValue( variant, GetRow(item), col );
292}
293
294wxDataViewItem wxDataViewIndexListModel::GetParent( const wxDataViewItem &item ) const
295{
296 return wxDataViewItem(0);
297}
298
299bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem &item ) const
300{
301 // only the invisible root item has children
302 if (!item.IsOk())
303 return true;
304
305 return false;
306}
307
308wxDataViewItem wxDataViewIndexListModel::GetFirstChild( const wxDataViewItem &parent ) const
309{
310 if (!parent.IsOk())
311 {
312 if (m_hash.GetCount() == 0)
313 return wxDataViewItem(0);
314
315 return wxDataViewItem( m_hash[0]);
316 }
317
318 return wxDataViewItem(0);
319}
320
321wxDataViewItem wxDataViewIndexListModel::GetNextSibling( const wxDataViewItem &item ) const
322{
323 if (!item.IsOk())
324 return wxDataViewItem(0);
325
326 int pos = m_hash.Index( item.GetID() );
327 if ((pos == wxNOT_FOUND) || (pos == m_hash.GetCount()-1))
328 return wxDataViewItem(0);
329
330 return wxDataViewItem( m_hash[pos+1] );
331}
332
f554a14b 333// ---------------------------------------------------------
baa9ebc4 334// wxDataViewRendererBase
f554a14b 335// ---------------------------------------------------------
6842a71a 336
baa9ebc4 337IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase, wxObject)
6842a71a 338
9861f022
RR
339wxDataViewRendererBase::wxDataViewRendererBase( const wxString &varianttype,
340 wxDataViewCellMode WXUNUSED(mode),
341 int WXUNUSED(align) )
6842a71a
RR
342{
343 m_variantType = varianttype;
1e510b1e 344 m_editorCtrl = NULL;
9861f022
RR
345}
346
347const wxDataViewCtrl* wxDataViewRendererBase::GetView() const
348{
349 return wx_const_cast(wxDataViewRendererBase*, this)->GetOwner()->GetOwner();
6842a71a 350}
f554a14b 351
e0062c04 352bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect )
1e510b1e 353{
e0062c04 354 m_item = item; // remember for later
1e510b1e
RR
355
356 unsigned int col = GetOwner()->GetModelColumn();
357 wxVariant value;
e0062c04 358 GetOwner()->GetOwner()->GetModel()->GetValue( value, item, col );
1e510b1e
RR
359
360 m_editorCtrl = CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect, value );
361
30715fa1
RR
362 wxDataViewEditorCtrlEvtHandler *handler =
363 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl, (wxDataViewRenderer*) this );
364
365 m_editorCtrl->PushEventHandler( handler );
1e510b1e 366
30715fa1
RR
367#if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
368 handler->SetFocusOnIdle();
369#else
1e510b1e 370 m_editorCtrl->SetFocus();
30715fa1
RR
371#endif
372
1e510b1e
RR
373 return true;
374}
375
376void wxDataViewRendererBase::CancelEditing()
377{
2fa73716 378 wxPendingDelete.Append( m_editorCtrl );
1e510b1e
RR
379
380 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
2fa73716
RR
381
382 // m_editorCtrl->PopEventHandler( true );
1e510b1e
RR
383}
384
385bool wxDataViewRendererBase::FinishEditing()
386{
1e510b1e
RR
387 wxVariant value;
388 GetValueFromEditorCtrl( m_editorCtrl, value );
389
2fa73716 390 wxPendingDelete.Append( m_editorCtrl );
1e510b1e
RR
391
392 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
393
394 if (!Validate(value))
395 return false;
396
397 unsigned int col = GetOwner()->GetModelColumn();
e0062c04
RR
398 GetOwner()->GetOwner()->GetModel()->SetValue( value, m_item, col );
399 GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item, col );
1e510b1e 400
2fa73716
RR
401 // m_editorCtrl->PopEventHandler( true );
402
1e510b1e
RR
403 return true;
404}
405
406//-----------------------------------------------------------------------------
407// wxDataViewEditorCtrlEvtHandler
408//-----------------------------------------------------------------------------
409
410BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler, wxEvtHandler)
411 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar)
412 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus)
30715fa1 413 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle)
1e510b1e
RR
414END_EVENT_TABLE()
415
416wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
417 wxControl *editorCtrl,
418 wxDataViewRenderer *owner )
419{
420 m_owner = owner;
421 m_editorCtrl = editorCtrl;
422
423 m_finished = false;
424}
425
30715fa1
RR
426void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent &event )
427{
428 if (m_focusOnIdle)
429 {
430 m_focusOnIdle = false;
431 if (wxWindow::FindFocus() != m_editorCtrl)
432 m_editorCtrl->SetFocus();
433 }
434
435 event.Skip();
436}
437
1e510b1e
RR
438void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event )
439{
440 switch ( event.m_keyCode )
441 {
442 case WXK_RETURN:
443 m_finished = true;
444 m_owner->FinishEditing();
445 break;
446
447 case WXK_ESCAPE:
448 m_finished = true;
449 m_owner->CancelEditing();
450 break;
451
452 default:
453 event.Skip();
454 }
455}
456
457void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event )
458{
459 if (!m_finished)
460 {
461 m_finished = true;
462 m_owner->FinishEditing();
463 }
464
1e510b1e
RR
465 event.Skip();
466}
467
f554a14b 468// ---------------------------------------------------------
fa28826d 469// wxDataViewColumnBase
f554a14b 470// ---------------------------------------------------------
fa28826d
RR
471
472IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase, wxObject)
473
9861f022 474wxDataViewColumnBase::wxDataViewColumnBase(const wxString& WXUNUSED(title),
baa9ebc4 475 wxDataViewRenderer *renderer,
0a71f9e9 476 unsigned int model_column,
008b5a66 477 int WXUNUSED(width),
87f0efe2 478 wxAlignment WXUNUSED(align),
9861f022 479 int WXUNUSED(flags))
fa28826d 480{
baa9ebc4 481 m_renderer = renderer;
6842a71a 482 m_model_column = model_column;
6842a71a 483 m_owner = NULL;
baa9ebc4 484 m_renderer->SetOwner( (wxDataViewColumn*) this );
9861f022
RR
485
486 // NOTE: the wxDataViewColumn's ctor must store the width, align, flags
487 // parameters inside the native control!
6842a71a
RR
488}
489
07a84e7b
RR
490wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap& bitmap,
491 wxDataViewRenderer *renderer,
492 unsigned int model_column,
493 int WXUNUSED(width),
87f0efe2 494 wxAlignment WXUNUSED(align),
9861f022 495 int WXUNUSED(flags) )
07a84e7b
RR
496{
497 m_renderer = renderer;
498 m_model_column = model_column;
07a84e7b
RR
499 m_bitmap = bitmap;
500 m_owner = NULL;
501 m_renderer->SetOwner( (wxDataViewColumn*) this );
502}
503
6842a71a
RR
504wxDataViewColumnBase::~wxDataViewColumnBase()
505{
baa9ebc4
RR
506 if (m_renderer)
507 delete m_renderer;
fa28826d
RR
508}
509
9861f022 510int wxDataViewColumnBase::GetFlags() const
fa28826d 511{
9861f022 512 int ret = 0;
fa28826d 513
9861f022
RR
514 if (IsSortable())
515 ret |= wxDATAVIEW_COL_SORTABLE;
516 if (IsResizeable())
517 ret |= wxDATAVIEW_COL_RESIZABLE;
518 if (IsHidden())
519 ret |= wxDATAVIEW_COL_HIDDEN;
fa28826d 520
9861f022 521 return ret;
07a84e7b
RR
522}
523
9861f022 524void wxDataViewColumnBase::SetFlags(int flags)
07a84e7b 525{
9861f022
RR
526 SetSortable((flags & wxDATAVIEW_COL_SORTABLE) != 0);
527 SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0);
528 SetHidden((flags & wxDATAVIEW_COL_HIDDEN) != 0);
07a84e7b
RR
529}
530
f554a14b 531// ---------------------------------------------------------
239eaa41 532// wxDataViewCtrlBase
f554a14b 533// ---------------------------------------------------------
239eaa41
RR
534
535IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl)
536
537wxDataViewCtrlBase::wxDataViewCtrlBase()
538{
539 m_model = NULL;
fa28826d 540 m_cols.DeleteContents( true );
3b6280be
RR
541 m_expander_column = 0;
542 m_indent = 8;
239eaa41
RR
543}
544
545wxDataViewCtrlBase::~wxDataViewCtrlBase()
546{
87f0efe2
RR
547 // IMPORTANT: before calling DecRef() on our model (since it may
548 // result in a free() call), erase all columns (since
549 // they hold a pointer to our model)
550 m_cols.Clear();
551
552 if (m_model)
553 {
554 m_model->DecRef();
555 m_model = NULL;
556 }
239eaa41
RR
557}
558
e0062c04 559bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel *model )
239eaa41 560{
1821abd1
RR
561 if (m_model)
562 {
87f0efe2 563 m_model->DecRef(); // discard old model, if any
1821abd1 564 }
87f0efe2
RR
565
566 // add our own reference to the new model:
239eaa41 567 m_model = model;
1821abd1
RR
568 if (m_model)
569 {
87f0efe2 570 m_model->IncRef();
1821abd1 571 }
f554a14b 572
239eaa41
RR
573 return true;
574}
575
e0062c04 576wxDataViewModel* wxDataViewCtrlBase::GetModel()
239eaa41
RR
577{
578 return m_model;
579}
580
1286b7ba 581bool wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_column,
87f0efe2 582 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
fa28826d 583{
1286b7ba 584 return AppendColumn( new wxDataViewColumn( label,
9861f022
RR
585 new wxDataViewTextRenderer( wxT("string"), mode, (int)align ),
586 model_column, width, align, flags ) );
fa28826d
RR
587}
588
1286b7ba 589bool wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int model_column,
87f0efe2 590 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
605c2c4a 591{
1286b7ba 592 return AppendColumn( new wxDataViewColumn( label,
9861f022
RR
593 new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ),
594 model_column, width, align, flags ) );
605c2c4a
RR
595}
596
1286b7ba 597bool wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, unsigned int model_column,
87f0efe2 598 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
ad63bf41 599{
1286b7ba 600 return AppendColumn( new wxDataViewColumn( label,
9861f022
RR
601 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ),
602 model_column, width, align, flags ) );
ad63bf41
RR
603}
604
1286b7ba 605bool wxDataViewCtrlBase::AppendDateColumn( const wxString &label, unsigned int model_column,
87f0efe2 606 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
4d496ecb 607{
1286b7ba 608 return AppendColumn( new wxDataViewColumn( label,
9861f022
RR
609 new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ),
610 model_column, width, align, flags ) );
4d496ecb
RR
611}
612
1286b7ba 613bool wxDataViewCtrlBase::AppendBitmapColumn( const wxString &label, unsigned int model_column,
87f0efe2 614 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 615{
1286b7ba 616 return AppendColumn( new wxDataViewColumn( label,
9861f022
RR
617 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ),
618 model_column, width, align, flags ) );
07a84e7b
RR
619}
620
1286b7ba 621bool wxDataViewCtrlBase::AppendTextColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 622 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 623{
1286b7ba 624 return AppendColumn( new wxDataViewColumn( label,
9861f022
RR
625 new wxDataViewTextRenderer( wxT("string"), mode, (int)align ),
626 model_column, width, align, flags ) );
07a84e7b
RR
627}
628
1286b7ba 629bool wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 630 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 631{
1286b7ba 632 return AppendColumn( new wxDataViewColumn( label,
9861f022
RR
633 new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ),
634 model_column, width, align, flags ) );
07a84e7b
RR
635}
636
1286b7ba 637bool wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 638 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 639{
1286b7ba 640 return AppendColumn( new wxDataViewColumn( label,
9861f022
RR
641 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ),
642 model_column, width, align, flags ) );
07a84e7b
RR
643}
644
1286b7ba 645bool wxDataViewCtrlBase::AppendDateColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 646 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 647{
1286b7ba 648 return AppendColumn( new wxDataViewColumn( label,
9861f022
RR
649 new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ),
650 model_column, width, align, flags ) );
07a84e7b
RR
651}
652
1286b7ba 653bool wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 654 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 655{
1286b7ba 656 return AppendColumn( new wxDataViewColumn( label,
9861f022
RR
657 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ),
658 model_column, width, align, flags ) );
07a84e7b
RR
659}
660
fa28826d
RR
661bool wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col )
662{
663 m_cols.Append( (wxObject*) col );
6842a71a 664 col->SetOwner( (wxDataViewCtrl*) this );
fa28826d
RR
665 return true;
666}
667
9861f022 668unsigned int wxDataViewCtrlBase::GetColumnCount() const
fa28826d
RR
669{
670 return m_cols.GetCount();
671}
672
0a71f9e9 673bool wxDataViewCtrlBase::DeleteColumn( unsigned int WXUNUSED(pos) )
fa28826d
RR
674{
675 return false;
676}
677
678bool wxDataViewCtrlBase::ClearColumns()
679{
680 return false;
681}
682
0a71f9e9 683wxDataViewColumn* wxDataViewCtrlBase::GetColumn( unsigned int pos )
fa28826d
RR
684{
685 return (wxDataViewColumn*) m_cols[ pos ];
686}
687
eb7f97f8
RR
688// ---------------------------------------------------------
689// wxDataViewEvent
690// ---------------------------------------------------------
691
692IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent)
693
e0062c04
RR
694DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_SELECTED)
695DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED)
31fb32e1
RR
696DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK)
697DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK)
c0a66d92 698DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED)
eb7f97f8 699
e0062c04
RR
700DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_ADDED)
701DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_DELETED)
702DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ITEM_CHANGED)
1821abd1 703DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED)
1821abd1 704DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED)
eb7f97f8 705
8045736e 706#endif