]> git.saurik.com Git - wxWidgets.git/blame - src/common/datavcmn.cpp
some (blind) compilation fixes after wxString/Unicode changes
[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// ---------------------------------------------------------
854cdb09 36// wxDataViewModelNotifier
f554a14b 37// ---------------------------------------------------------
239eaa41 38
8ab03001 39#include "wx/listimpl.cpp"
9d8fe14a
RR
40WX_DEFINE_LIST(wxDataViewModelNotifiers);
41
854cdb09
RR
42bool wxDataViewModelNotifier::ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items )
43{
44 size_t count = items.GetCount();
45 size_t i;
46 for (i = 0; i < count; i++)
47 if (!ItemAdded( parent, items[i] )) return false;
48
49 return true;
50}
51
52bool wxDataViewModelNotifier::ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items )
53{
54 size_t count = items.GetCount();
55 size_t i;
56 for (i = 0; i < count; i++)
57 if (!ItemDeleted( parent, items[i] )) return false;
58
59 return true;
60}
61
62bool wxDataViewModelNotifier::ItemsChanged( const wxDataViewItemArray &items )
63{
64 size_t count = items.GetCount();
65 size_t i;
66 for (i = 0; i < count; i++)
67 if (!ItemChanged( items[i] )) return false;
68
69 return true;
70}
71
72// ---------------------------------------------------------
73// wxDataViewModel
74// ---------------------------------------------------------
75
e0062c04 76wxDataViewModel::wxDataViewModel()
239eaa41 77{
8f850e28 78 m_notifiers.DeleteContents( true );
239eaa41
RR
79}
80
e0062c04 81bool wxDataViewModel::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
239eaa41 82{
8f850e28
RR
83 bool ret = true;
84
9d8fe14a
RR
85 wxDataViewModelNotifiers::iterator iter;
86 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
8f850e28 87 {
9d8fe14a 88 wxDataViewModelNotifier* notifier = *iter;
e0062c04 89 if (!notifier->ItemAdded( parent, item ))
8f850e28 90 ret = false;
8f850e28 91 }
f554a14b 92
8f850e28 93 return ret;
239eaa41
RR
94}
95
469d3e9b 96bool wxDataViewModel::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
239eaa41 97{
8f850e28
RR
98 bool ret = true;
99
9d8fe14a
RR
100 wxDataViewModelNotifiers::iterator iter;
101 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
8f850e28 102 {
9d8fe14a 103 wxDataViewModelNotifier* notifier = *iter;
469d3e9b 104 if (!notifier->ItemDeleted( parent, item ))
8f850e28 105 ret = false;
8f850e28 106 }
f554a14b 107
8f850e28 108 return ret;
239eaa41
RR
109}
110
e0062c04 111bool wxDataViewModel::ItemChanged( const wxDataViewItem &item )
239eaa41 112{
8f850e28
RR
113 bool ret = true;
114
9d8fe14a
RR
115 wxDataViewModelNotifiers::iterator iter;
116 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
8f850e28 117 {
9d8fe14a 118 wxDataViewModelNotifier* notifier = *iter;
e0062c04 119 if (!notifier->ItemChanged( item ))
8f850e28 120 ret = false;
8f850e28 121 }
f554a14b 122
8f850e28 123 return ret;
239eaa41
RR
124}
125
854cdb09
RR
126bool wxDataViewModel::ItemsAdded( const wxDataViewItem &parent, const wxDataViewItemArray &items )
127{
128 bool ret = true;
129
130 wxDataViewModelNotifiers::iterator iter;
131 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
132 {
133 wxDataViewModelNotifier* notifier = *iter;
134 if (!notifier->ItemsAdded( parent, items ))
135 ret = false;
136 }
137
138 return ret;
139}
140
141bool wxDataViewModel::ItemsDeleted( const wxDataViewItem &parent, const wxDataViewItemArray &items )
142{
143 bool ret = true;
144
145 wxDataViewModelNotifiers::iterator iter;
146 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
147 {
148 wxDataViewModelNotifier* notifier = *iter;
149 if (!notifier->ItemsDeleted( parent, items ))
150 ret = false;
151 }
152
153 return ret;
154}
155
156bool wxDataViewModel::ItemsChanged( const wxDataViewItemArray &items )
157{
158 bool ret = true;
159
160 wxDataViewModelNotifiers::iterator iter;
161 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
162 {
163 wxDataViewModelNotifier* notifier = *iter;
164 if (!notifier->ItemsChanged( items ))
165 ret = false;
166 }
167
168 return ret;
169}
170
e0062c04 171bool wxDataViewModel::ValueChanged( const wxDataViewItem &item, unsigned int col )
239eaa41 172{
8f850e28 173 bool ret = true;
b5d777c7 174
9d8fe14a
RR
175 wxDataViewModelNotifiers::iterator iter;
176 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
b5d777c7 177 {
9d8fe14a 178 wxDataViewModelNotifier* notifier = *iter;
e0062c04 179 if (!notifier->ValueChanged( item, col ))
8f850e28 180 ret = false;
b5d777c7 181 }
f554a14b 182
b5d777c7 183 return ret;
239eaa41
RR
184}
185
e0062c04 186bool wxDataViewModel::Cleared()
4eccd3a1
RR
187{
188 bool ret = true;
189
9d8fe14a
RR
190 wxDataViewModelNotifiers::iterator iter;
191 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
4eccd3a1 192 {
9d8fe14a 193 wxDataViewModelNotifier* notifier = *iter;
8f850e28
RR
194 if (!notifier->Cleared())
195 ret = false;
8f850e28 196 }
f554a14b 197
8f850e28 198 return ret;
239eaa41
RR
199}
200
ef427989
RR
201void wxDataViewModel::Resort()
202{
9d8fe14a
RR
203 wxDataViewModelNotifiers::iterator iter;
204 for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter)
ef427989 205 {
9d8fe14a 206 wxDataViewModelNotifier* notifier = *iter;
ef427989 207 notifier->Resort();
ef427989
RR
208 }
209}
210
e0062c04 211void wxDataViewModel::AddNotifier( wxDataViewModelNotifier *notifier )
239eaa41 212{
9d8fe14a 213 m_notifiers.push_back( notifier );
8f850e28 214 notifier->SetOwner( this );
239eaa41
RR
215}
216
e0062c04 217void wxDataViewModel::RemoveNotifier( wxDataViewModelNotifier *notifier )
239eaa41 218{
8f850e28 219 m_notifiers.DeleteObject( notifier );
239eaa41
RR
220}
221
7ee7191c
RR
222int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
223 unsigned int column, bool ascending )
ef427989 224{
cf283a47 225 // sort branches before leaves
ed903e42
RR
226 bool item1_is_container = IsContainer(item1);
227 bool item2_is_container = IsContainer(item2);
900af470 228
ed903e42 229 if (item1_is_container && !item2_is_container)
cf283a47 230 return 1;
ed903e42 231 if (item2_is_container && !item1_is_container)
cf283a47 232 return -1;
900af470 233
ef427989 234 wxVariant value1,value2;
7ee7191c
RR
235 GetValue( value1, item1, column );
236 GetValue( value2, item2, column );
237
238 if (!ascending)
239 {
240 wxVariant temp = value1;
241 value1 = value2;
242 value2 = temp;
243 }
cf283a47 244
ef427989
RR
245 if (value1.GetType() == wxT("string"))
246 {
247 wxString str1 = value1.GetString();
248 wxString str2 = value2.GetString();
0be79c8a 249 int res = str1.Cmp( str2 );
cf283a47
RR
250 if (res) return res;
251 } else
ef427989
RR
252 if (value1.GetType() == wxT("long"))
253 {
254 long l1 = value1.GetLong();
255 long l2 = value2.GetLong();
cf283a47
RR
256 long res = l1-l2;
257 if (res) return res;
258 } else
ef427989
RR
259 if (value1.GetType() == wxT("double"))
260 {
261 double d1 = value1.GetDouble();
262 double d2 = value2.GetDouble();
ef427989 263 if (d1 < d2) return 1;
cf283a47
RR
264 if (d1 > d2) return -1;
265 } else
ef427989
RR
266 if (value1.GetType() == wxT("datetime"))
267 {
268 wxDateTime dt1 = value1.GetDateTime();
269 wxDateTime dt2 = value2.GetDateTime();
ef427989 270 if (dt1.IsEarlierThan(dt2)) return 1;
cf283a47 271 if (dt2.IsEarlierThan(dt1)) return -11;
ef427989
RR
272 }
273
cf283a47 274 // items must be different
900af470
JS
275 unsigned long litem1 = (unsigned long) item1.GetID();
276 unsigned long litem2 = (unsigned long) item2.GetID();
b7fe2261 277
7ee7191c
RR
278 if (!ascending)
279 return litem2-litem2;
cf283a47 280
cf283a47 281 return litem1-litem2;
ef427989
RR
282}
283
c534e696
RR
284// ---------------------------------------------------------
285// wxDataViewIndexListModel
286// ---------------------------------------------------------
287
288wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size )
289{
290 // build initial index
291 unsigned int i;
292 for (i = 1; i < initial_size+1; i++)
293 m_hash.Add( (void*) i );
294 m_lastIndex = initial_size + 1;
295}
296
297wxDataViewIndexListModel::~wxDataViewIndexListModel()
298{
299}
300
301void wxDataViewIndexListModel::RowPrepended()
302{
303 unsigned int id = m_lastIndex++;
304 m_hash.Insert( (void*) id, 0 );
305 wxDataViewItem item( (void*) id );
306 ItemAdded( wxDataViewItem(0), item );
307}
308
309void wxDataViewIndexListModel::RowInserted( unsigned int before )
310{
311 unsigned int id = m_lastIndex++;
312 m_hash.Insert( (void*) id, before );
313 wxDataViewItem item( (void*) id );
314 ItemAdded( wxDataViewItem(0), item );
315}
316
317void wxDataViewIndexListModel::RowAppended()
318{
319 unsigned int id = m_lastIndex++;
320 m_hash.Add( (void*) id );
321 wxDataViewItem item( (void*) id );
322 ItemAdded( wxDataViewItem(0), item );
323}
324
325void wxDataViewIndexListModel::RowDeleted( unsigned int row )
326{
327 wxDataViewItem item( m_hash[row] );
469d3e9b 328 wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
d3f00f59 329 m_hash.RemoveAt( row );
c534e696
RR
330}
331
332void wxDataViewIndexListModel::RowChanged( unsigned int row )
333{
334 wxDataViewModel::ItemChanged( GetItem(row) );
335}
336
337void wxDataViewIndexListModel::RowValueChanged( unsigned int row, unsigned int col )
338{
339 wxDataViewModel::ValueChanged( GetItem(row), col );
340}
341
342unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) const
343{
344 // assert for not found
345 return (unsigned int) m_hash.Index( item.GetID() );
346}
347
348wxDataViewItem wxDataViewIndexListModel::GetItem( unsigned int row ) const
349{
fbda518c 350 wxASSERT( row < m_hash.GetCount() );
c534e696
RR
351 return wxDataViewItem( m_hash[row] );
352}
353
b7fe2261
VZ
354int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1,
355 const wxDataViewItem& item2,
356 unsigned int WXUNUSED(column),
357 bool ascending)
c534e696 358{
7ee7191c
RR
359 if (ascending)
360 return GetRow(item1) - GetRow(item2);
b7fe2261 361
7ee7191c 362 return GetRow(item2) - GetRow(item1);
c534e696
RR
363}
364
900af470 365void wxDataViewIndexListModel::GetValue( wxVariant &variant,
c534e696
RR
366 const wxDataViewItem &item, unsigned int col ) const
367{
900af470 368 GetValue( variant, GetRow(item), col );
c534e696
RR
369}
370
900af470 371bool wxDataViewIndexListModel::SetValue( const wxVariant &variant,
c534e696
RR
372 const wxDataViewItem &item, unsigned int col )
373{
374 return SetValue( variant, GetRow(item), col );
375}
376
900af470 377wxDataViewItem wxDataViewIndexListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const
c534e696
RR
378{
379 return wxDataViewItem(0);
380}
381
382bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem &item ) const
383{
384 // only the invisible root item has children
385 if (!item.IsOk())
386 return true;
900af470 387
c534e696
RR
388 return false;
389}
390
74fe973b 391unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const
c534e696 392{
74fe973b
RR
393 if (item.IsOk())
394 return 0;
c534e696 395
74fe973b 396 children = m_hash;
b7fe2261 397
74fe973b 398 return m_hash.GetCount();
c534e696
RR
399}
400
89352653
RR
401//-----------------------------------------------------------------------------
402// wxDataViewIconText
403//-----------------------------------------------------------------------------
404
405IMPLEMENT_DYNAMIC_CLASS(wxDataViewIconText,wxObject)
406
407IMPLEMENT_VARIANT_OBJECT(wxDataViewIconText)
408
409bool operator == (const wxDataViewIconText &one, const wxDataViewIconText &two)
410{
411 if (one.GetText() != two.GetText()) return false;
412 if (one.IsSameAs(two)) return false;
413 return true;
414}
415
f554a14b 416// ---------------------------------------------------------
baa9ebc4 417// wxDataViewRendererBase
f554a14b 418// ---------------------------------------------------------
6842a71a 419
baa9ebc4 420IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase, wxObject)
6842a71a 421
900af470 422wxDataViewRendererBase::wxDataViewRendererBase( const wxString &varianttype,
9861f022
RR
423 wxDataViewCellMode WXUNUSED(mode),
424 int WXUNUSED(align) )
6842a71a
RR
425{
426 m_variantType = varianttype;
1e510b1e 427 m_editorCtrl = NULL;
9861f022
RR
428}
429
430const wxDataViewCtrl* wxDataViewRendererBase::GetView() const
431{
432 return wx_const_cast(wxDataViewRendererBase*, this)->GetOwner()->GetOwner();
6842a71a 433}
f554a14b 434
e0062c04 435bool wxDataViewRendererBase::StartEditing( const wxDataViewItem &item, wxRect labelRect )
1e510b1e 436{
e0062c04 437 m_item = item; // remember for later
900af470 438
1e510b1e
RR
439 unsigned int col = GetOwner()->GetModelColumn();
440 wxVariant value;
e0062c04 441 GetOwner()->GetOwner()->GetModel()->GetValue( value, item, col );
900af470 442
1e510b1e 443 m_editorCtrl = CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect, value );
900af470
JS
444
445 wxDataViewEditorCtrlEvtHandler *handler =
30715fa1 446 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl, (wxDataViewRenderer*) this );
900af470 447
30715fa1 448 m_editorCtrl->PushEventHandler( handler );
900af470 449
30715fa1
RR
450#if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
451 handler->SetFocusOnIdle();
452#else
1e510b1e 453 m_editorCtrl->SetFocus();
30715fa1
RR
454#endif
455
afebb87b
RR
456 // Now we should send Editing Started event
457 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, GetOwner()->GetOwner()->GetId() );
458 event.SetDataViewColumn( GetOwner() );
459 event.SetModel( GetOwner()->GetOwner()->GetModel() );
460 event.SetItem( item );
afebb87b
RR
461 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event );
462
1e510b1e
RR
463 return true;
464}
465
466void wxDataViewRendererBase::CancelEditing()
467{
2fa73716 468 wxPendingDelete.Append( m_editorCtrl );
900af470 469
1e510b1e 470 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
900af470 471
2fa73716 472 // m_editorCtrl->PopEventHandler( true );
1e510b1e
RR
473}
474
475bool wxDataViewRendererBase::FinishEditing()
476{
1e510b1e
RR
477 wxVariant value;
478 GetValueFromEditorCtrl( m_editorCtrl, value );
479
2fa73716 480 wxPendingDelete.Append( m_editorCtrl );
900af470 481
1e510b1e 482 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
900af470 483
1e510b1e
RR
484 if (!Validate(value))
485 return false;
900af470 486
1e510b1e 487 unsigned int col = GetOwner()->GetModelColumn();
e0062c04
RR
488 GetOwner()->GetOwner()->GetModel()->SetValue( value, m_item, col );
489 GetOwner()->GetOwner()->GetModel()->ValueChanged( m_item, col );
900af470 490
2fa73716 491 // m_editorCtrl->PopEventHandler( true );
b7fe2261 492
afebb87b
RR
493 // Now we should send Editing Done event
494 wxDataViewEvent event( wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, GetOwner()->GetOwner()->GetId() );
495 event.SetDataViewColumn( GetOwner() );
496 event.SetModel( GetOwner()->GetOwner()->GetModel() );
8fdaf7de 497 event.SetItem( m_item );
afebb87b 498 GetOwner()->GetOwner()->GetEventHandler()->ProcessEvent( event );
900af470 499
1e510b1e
RR
500 return true;
501}
502
503//-----------------------------------------------------------------------------
504// wxDataViewEditorCtrlEvtHandler
505//-----------------------------------------------------------------------------
506
507BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler, wxEvtHandler)
508 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar)
509 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus)
30715fa1 510 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle)
1e510b1e
RR
511END_EVENT_TABLE()
512
513wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
514 wxControl *editorCtrl,
515 wxDataViewRenderer *owner )
516{
517 m_owner = owner;
518 m_editorCtrl = editorCtrl;
519
520 m_finished = false;
521}
522
30715fa1
RR
523void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent &event )
524{
525 if (m_focusOnIdle)
526 {
527 m_focusOnIdle = false;
528 if (wxWindow::FindFocus() != m_editorCtrl)
529 m_editorCtrl->SetFocus();
530 }
900af470 531
30715fa1
RR
532 event.Skip();
533}
534
1e510b1e
RR
535void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event )
536{
537 switch ( event.m_keyCode )
538 {
539 case WXK_RETURN:
540 m_finished = true;
541 m_owner->FinishEditing();
542 break;
543
544 case WXK_ESCAPE:
545 m_finished = true;
546 m_owner->CancelEditing();
547 break;
548
549 default:
550 event.Skip();
551 }
552}
553
554void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event )
555{
556 if (!m_finished)
557 {
558 m_finished = true;
559 m_owner->FinishEditing();
560 }
561
1e510b1e
RR
562 event.Skip();
563}
564
f554a14b 565// ---------------------------------------------------------
fa28826d 566// wxDataViewColumnBase
f554a14b 567// ---------------------------------------------------------
fa28826d
RR
568
569IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase, wxObject)
570
9861f022 571wxDataViewColumnBase::wxDataViewColumnBase(const wxString& WXUNUSED(title),
baa9ebc4 572 wxDataViewRenderer *renderer,
0a71f9e9 573 unsigned int model_column,
008b5a66 574 int WXUNUSED(width),
87f0efe2 575 wxAlignment WXUNUSED(align),
900af470 576 int WXUNUSED(flags))
fa28826d 577{
baa9ebc4 578 m_renderer = renderer;
6842a71a 579 m_model_column = model_column;
6842a71a 580 m_owner = NULL;
baa9ebc4 581 m_renderer->SetOwner( (wxDataViewColumn*) this );
9861f022
RR
582
583 // NOTE: the wxDataViewColumn's ctor must store the width, align, flags
584 // parameters inside the native control!
6842a71a
RR
585}
586
07a84e7b
RR
587wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap& bitmap,
588 wxDataViewRenderer *renderer,
589 unsigned int model_column,
590 int WXUNUSED(width),
87f0efe2 591 wxAlignment WXUNUSED(align),
900af470 592 int WXUNUSED(flags) )
07a84e7b
RR
593{
594 m_renderer = renderer;
595 m_model_column = model_column;
07a84e7b
RR
596 m_bitmap = bitmap;
597 m_owner = NULL;
598 m_renderer->SetOwner( (wxDataViewColumn*) this );
599}
600
6842a71a
RR
601wxDataViewColumnBase::~wxDataViewColumnBase()
602{
baa9ebc4
RR
603 if (m_renderer)
604 delete m_renderer;
fa28826d
RR
605}
606
9861f022 607int wxDataViewColumnBase::GetFlags() const
fa28826d 608{
9861f022 609 int ret = 0;
fa28826d 610
9861f022
RR
611 if (IsSortable())
612 ret |= wxDATAVIEW_COL_SORTABLE;
613 if (IsResizeable())
614 ret |= wxDATAVIEW_COL_RESIZABLE;
615 if (IsHidden())
616 ret |= wxDATAVIEW_COL_HIDDEN;
fa28826d 617
9861f022 618 return ret;
07a84e7b
RR
619}
620
9861f022 621void wxDataViewColumnBase::SetFlags(int flags)
07a84e7b 622{
9861f022
RR
623 SetSortable((flags & wxDATAVIEW_COL_SORTABLE) != 0);
624 SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0);
625 SetHidden((flags & wxDATAVIEW_COL_HIDDEN) != 0);
07a84e7b
RR
626}
627
f554a14b 628// ---------------------------------------------------------
239eaa41 629// wxDataViewCtrlBase
f554a14b 630// ---------------------------------------------------------
239eaa41
RR
631
632IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl)
633
634wxDataViewCtrlBase::wxDataViewCtrlBase()
635{
636 m_model = NULL;
3b6280be
RR
637 m_expander_column = 0;
638 m_indent = 8;
239eaa41
RR
639}
640
641wxDataViewCtrlBase::~wxDataViewCtrlBase()
642{
87f0efe2
RR
643 if (m_model)
644 {
645 m_model->DecRef();
646 m_model = NULL;
647 }
239eaa41
RR
648}
649
e0062c04 650bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel *model )
239eaa41 651{
1821abd1
RR
652 if (m_model)
653 {
87f0efe2 654 m_model->DecRef(); // discard old model, if any
1821abd1 655 }
87f0efe2
RR
656
657 // add our own reference to the new model:
239eaa41 658 m_model = model;
1821abd1
RR
659 if (m_model)
660 {
900af470 661 m_model->IncRef();
1821abd1 662 }
f554a14b 663
239eaa41
RR
664 return true;
665}
666
e0062c04 667wxDataViewModel* wxDataViewCtrlBase::GetModel()
239eaa41
RR
668{
669 return m_model;
670}
671
c7074d44
RR
672wxDataViewColumn *
673wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_column,
87f0efe2 674 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
fa28826d 675{
c7074d44 676 wxDataViewColumn *ret = new wxDataViewColumn( label,
900af470 677 new wxDataViewTextRenderer( wxT("string"), mode, (int)align ),
c7074d44
RR
678 model_column, width, align, flags );
679 AppendColumn( ret );
680 return ret;
fa28826d
RR
681}
682
b04fcede
RR
683wxDataViewColumn *
684wxDataViewCtrlBase::AppendIconTextColumn( const wxString &label, unsigned int model_column,
685 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
686{
687 wxDataViewColumn *ret = new wxDataViewColumn( label,
688 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ),
689 model_column, width, align, flags );
690 AppendColumn( ret );
691 return ret;
692}
693
c7074d44
RR
694wxDataViewColumn *
695wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int model_column,
87f0efe2 696 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
605c2c4a 697{
b7fe2261 698
c7074d44 699 wxDataViewColumn *ret = new wxDataViewColumn( label,
900af470 700 new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ),
c7074d44
RR
701 model_column, width, align, flags );
702 AppendColumn( ret );
703 return ret;
605c2c4a
RR
704}
705
c7074d44
RR
706wxDataViewColumn *
707wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, unsigned int model_column,
87f0efe2 708 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
ad63bf41 709{
c7074d44 710 wxDataViewColumn *ret = new wxDataViewColumn( label,
900af470 711 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ),
c7074d44
RR
712 model_column, width, align, flags );
713 AppendColumn( ret );
714 return ret;
ad63bf41
RR
715}
716
c7074d44
RR
717wxDataViewColumn *
718wxDataViewCtrlBase::AppendDateColumn( const wxString &label, unsigned int model_column,
87f0efe2 719 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
4d496ecb 720{
c7074d44 721 wxDataViewColumn *ret = new wxDataViewColumn( label,
900af470 722 new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ),
c7074d44
RR
723 model_column, width, align, flags );
724 AppendColumn( ret );
725 return ret;
4d496ecb
RR
726}
727
c7074d44
RR
728wxDataViewColumn *
729wxDataViewCtrlBase::AppendBitmapColumn( const wxString &label, unsigned int model_column,
87f0efe2 730 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 731{
c7074d44 732 wxDataViewColumn *ret = new wxDataViewColumn( label,
900af470 733 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ),
c7074d44
RR
734 model_column, width, align, flags );
735 AppendColumn( ret );
736 return ret;
07a84e7b
RR
737}
738
c7074d44
RR
739wxDataViewColumn *
740wxDataViewCtrlBase::AppendTextColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 741 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 742{
c7074d44 743 wxDataViewColumn *ret = new wxDataViewColumn( label,
900af470 744 new wxDataViewTextRenderer( wxT("string"), mode, (int)align ),
c7074d44
RR
745 model_column, width, align, flags );
746 AppendColumn( ret );
747 return ret;
b04fcede
RR
748}
749
750wxDataViewColumn *
751wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap &label, unsigned int model_column,
752 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
753{
754 wxDataViewColumn *ret = new wxDataViewColumn( label,
755 new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ),
756 model_column, width, align, flags );
757 AppendColumn( ret );
758 return ret;
07a84e7b
RR
759}
760
c7074d44
RR
761wxDataViewColumn *
762wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 763 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 764{
c7074d44 765 wxDataViewColumn *ret = new wxDataViewColumn( label,
900af470 766 new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ),
c7074d44
RR
767 model_column, width, align, flags );
768 AppendColumn( ret );
769 return ret;
07a84e7b
RR
770}
771
c7074d44
RR
772wxDataViewColumn *
773wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 774 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 775{
c7074d44 776 wxDataViewColumn *ret = new wxDataViewColumn( label,
900af470 777 new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ),
c7074d44
RR
778 model_column, width, align, flags );
779 AppendColumn( ret );
780 return ret;
07a84e7b
RR
781}
782
c7074d44
RR
783wxDataViewColumn *
784wxDataViewCtrlBase::AppendDateColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 785 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 786{
c7074d44 787 wxDataViewColumn *ret = new wxDataViewColumn( label,
900af470 788 new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ),
c7074d44
RR
789 model_column, width, align, flags );
790 AppendColumn( ret );
791 return ret;
07a84e7b
RR
792}
793
c7074d44
RR
794wxDataViewColumn *
795wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int model_column,
87f0efe2 796 wxDataViewCellMode mode, int width, wxAlignment align, int flags )
07a84e7b 797{
c7074d44 798 wxDataViewColumn *ret = new wxDataViewColumn( label,
900af470 799 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ),
c7074d44
RR
800 model_column, width, align, flags );
801 AppendColumn( ret );
802 return ret;
07a84e7b
RR
803}
804
c7074d44
RR
805bool
806wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col )
fa28826d 807{
6842a71a 808 col->SetOwner( (wxDataViewCtrl*) this );
fa28826d
RR
809 return true;
810}
811
eb7f97f8
RR
812// ---------------------------------------------------------
813// wxDataViewEvent
814// ---------------------------------------------------------
815
816IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent,wxNotifyEvent)
817
d86c1870
RR
818DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED)
819
e0062c04 820DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED)
6977c3bf 821DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING)
3ecb8a53 822DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED)
6977c3bf 823DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING)
3ecb8a53 824DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED)
e0000f94
RR
825DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED)
826DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE)
6608fdab 827DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED)
e0000f94 828
31fb32e1
RR
829DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK)
830DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK)
c0a66d92 831DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED)
eb7f97f8 832
8045736e 833#endif
e0000f94 834