1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/datavcmn.cpp
3 // Purpose: wxDataViewCtrl base classes and common parts
4 // Author: Robert Roebling
7 // Copyright: (c) 2006, Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_DATAVIEWCTRL
20 #include "wx/dataview.h"
26 const wxChar wxDataViewCtrlNameStr
[] = wxT("dataviewCtrl");
29 // ---------------------------------------------------------
30 // wxDataViewListModel
31 // ---------------------------------------------------------
33 wxDataViewListModel::wxDataViewListModel()
35 m_notifiers
.DeleteContents( true );
38 wxDataViewListModel::~wxDataViewListModel()
42 bool wxDataViewListModel::RowAppended()
46 wxList::compatibility_iterator node
= m_notifiers
.GetFirst();
49 wxDataViewListModelNotifier
* notifier
= (wxDataViewListModelNotifier
*) node
->GetData();
50 if (!notifier
->RowAppended())
52 node
= node
->GetNext();
58 bool wxDataViewListModel::RowPrepended()
62 wxList::compatibility_iterator node
= m_notifiers
.GetFirst();
65 wxDataViewListModelNotifier
* notifier
= (wxDataViewListModelNotifier
*) node
->GetData();
66 if (!notifier
->RowPrepended())
68 node
= node
->GetNext();
74 bool wxDataViewListModel::RowInserted( unsigned int before
)
78 wxList::compatibility_iterator node
= m_notifiers
.GetFirst();
81 wxDataViewListModelNotifier
* notifier
= (wxDataViewListModelNotifier
*) node
->GetData();
82 if (!notifier
->RowInserted(before
))
84 node
= node
->GetNext();
90 bool wxDataViewListModel::RowDeleted( unsigned int row
)
94 wxList::compatibility_iterator node
= m_notifiers
.GetFirst();
97 wxDataViewListModelNotifier
* notifier
= (wxDataViewListModelNotifier
*) node
->GetData();
98 if (!notifier
->RowDeleted( row
))
100 node
= node
->GetNext();
106 bool wxDataViewListModel::RowChanged( unsigned int row
)
110 wxList::compatibility_iterator node
= m_notifiers
.GetFirst();
113 wxDataViewListModelNotifier
* notifier
= (wxDataViewListModelNotifier
*) node
->GetData();
114 if (!notifier
->RowChanged( row
))
116 node
= node
->GetNext();
122 bool wxDataViewListModel::ValueChanged( unsigned int col
, unsigned int row
)
126 wxList::compatibility_iterator node
= m_notifiers
.GetFirst();
129 wxDataViewListModelNotifier
* notifier
= (wxDataViewListModelNotifier
*) node
->GetData();
130 if (!notifier
->ValueChanged( col
, row
))
132 node
= node
->GetNext();
138 bool wxDataViewListModel::RowsReordered( unsigned int *new_order
)
142 wxList::compatibility_iterator node
= m_notifiers
.GetFirst();
145 wxDataViewListModelNotifier
* notifier
= (wxDataViewListModelNotifier
*) node
->GetData();
146 if (!notifier
->RowsReordered( new_order
))
148 node
= node
->GetNext();
154 bool wxDataViewListModel::Cleared()
158 wxList::compatibility_iterator node
= m_notifiers
.GetFirst();
161 wxDataViewListModelNotifier
* notifier
= (wxDataViewListModelNotifier
*) node
->GetData();
162 if (!notifier
->Cleared())
164 node
= node
->GetNext();
170 void wxDataViewListModel::AddNotifier( wxDataViewListModelNotifier
*notifier
)
172 m_notifiers
.Append( notifier
);
173 notifier
->SetOwner( this );
176 void wxDataViewListModel::RemoveNotifier( wxDataViewListModelNotifier
*notifier
)
178 m_notifiers
.DeleteObject( notifier
);
181 // ---------------------------------------------------------
182 // wxDataViewSortedListModelNotifier
183 // ---------------------------------------------------------
185 class wxDataViewSortedListModelNotifier
: public wxDataViewListModelNotifier
188 wxDataViewSortedListModelNotifier( wxDataViewSortedListModel
*model
)
191 virtual bool RowAppended()
192 { return m_model
->ChildRowAppended(); }
194 virtual bool RowPrepended()
195 { return m_model
->ChildRowPrepended(); }
197 virtual bool RowInserted( unsigned int before
)
198 { return m_model
->ChildRowInserted( before
); }
200 virtual bool RowDeleted( unsigned int row
)
201 { return m_model
->ChildRowDeleted( row
); }
203 virtual bool RowChanged( unsigned int row
)
204 { return m_model
->ChildRowChanged( row
); }
206 virtual bool ValueChanged( unsigned int col
, unsigned int row
)
207 { return m_model
->ChildValueChanged( col
, row
); }
209 virtual bool RowsReordered( unsigned int *new_order
)
210 { return m_model
->ChildRowsReordered( new_order
); }
212 virtual bool Cleared()
213 { return m_model
->ChildCleared(); }
215 wxDataViewSortedListModel
*m_model
;
218 // ---------------------------------------------------------
219 // wxDataViewSortedListModel compare function
220 // ---------------------------------------------------------
222 int wxCALLBACK wxDataViewListModelSortedDefaultCompare
223 (unsigned int row1
, unsigned int row2
, unsigned int col
, wxDataViewListModel
* model
)
225 wxVariant value1
,value2
;
226 model
->GetValue( value1
, col
, row1
);
227 model
->GetValue( value2
, col
, row2
);
228 if (value1
.GetType() == wxT("string"))
230 wxString str1
= value1
.GetString();
231 wxString str2
= value2
.GetString();
232 return str1
.Cmp( str2
);
234 if (value1
.GetType() == wxT("long"))
236 long l1
= value1
.GetLong();
237 long l2
= value2
.GetLong();
240 if (value1
.GetType() == wxT("double"))
242 double d1
= value1
.GetDouble();
243 double d2
= value2
.GetDouble();
244 if (d1
== d2
) return 0;
245 if (d1
< d2
) return 1;
248 if (value1
.GetType() == wxT("datetime"))
250 wxDateTime dt1
= value1
.GetDateTime();
251 wxDateTime dt2
= value2
.GetDateTime();
252 if (dt1
.IsEqualTo(dt2
)) return 0;
253 if (dt1
.IsEarlierThan(dt2
)) return 1;
260 int wxCALLBACK wxDataViewListModelSortedDefaultCompareDescending
261 (unsigned int row1
, unsigned int row2
, unsigned int col
, wxDataViewListModel
* model
)
263 return wxDataViewListModelSortedDefaultCompare( row2
, row1
, col
, model
);
266 static wxDataViewListModelCompare s_CmpFunc
;
267 static wxDataViewListModel
*s_CmpModel
;
268 static unsigned int s_CmpCol
;
270 int LINKAGEMODE
wxDataViewIntermediateCmp( unsigned int row1
, unsigned int row2
)
272 return s_CmpFunc( row1
, row2
, s_CmpCol
, s_CmpModel
);
275 // ---------------------------------------------------------
276 // wxDataViewSortedListModel
277 // ---------------------------------------------------------
279 wxDataViewSortedListModel::wxDataViewSortedListModel( wxDataViewListModel
*child
) :
280 m_array( wxDataViewIntermediateCmp
)
286 m_notifierOnChild
= new wxDataViewSortedListModelNotifier( this );
287 m_child
->AddNotifier( m_notifierOnChild
);
294 wxDataViewSortedListModel::~wxDataViewSortedListModel()
299 void wxDataViewSortedListModel::DetachChild()
303 m_child
->RemoveNotifier( m_notifierOnChild
);
311 void wxDataViewSortedListModel::InitStatics()
314 s_CmpModel
= m_child
;
316 s_CmpFunc
= wxDataViewListModelSortedDefaultCompare
;
318 s_CmpFunc
= wxDataViewListModelSortedDefaultCompareDescending
;
321 void wxDataViewSortedListModel::Resort()
325 if (!m_child
) return;
327 unsigned int n
= m_child
->GetRowCount();
330 if (n
!= m_array
.GetCount())
332 // probably sorted for the first time -> no reordered
333 // -- just create index and leave
335 for (i
= 0; i
< n
; i
++)
340 unsigned int *old_array
= new unsigned int[ n
];
342 for (i
= 0; i
< n
; i
++)
343 old_array
[i
] = m_array
[ i
];
346 for (i
= 0; i
< n
; i
++)
349 unsigned int *order
= new unsigned int[ n
];
351 for (i
= 0; i
< n
; i
++)
353 unsigned int new_value
= m_array
[i
];
355 unsigned int old_pos
;
356 for (old_pos
= 0; old_pos
< n
; old_pos
++)
357 if (old_array
[old_pos
] == new_value
)
364 wxDataViewListModel::RowsReordered( order
);
370 static void Dump( wxDataViewListModel
*model
, unsigned int col
)
372 unsigned int n
= model
->GetRowCount();
374 for (i
= 0; i
< n
; i
++)
377 model
->GetValue( variant
, col
, i
);
379 tmp
= variant
.GetString();
380 wxPrintf( wxT("%d: %s\n"), (int) i
, tmp
.c_str() );
385 bool wxDataViewSortedListModel::ChildRowAppended()
387 // no need to fix up array
389 unsigned int len
= m_array
.GetCount();
391 unsigned int pos
= m_array
.Add( len
);
394 return wxDataViewListModel::RowPrepended();
397 return wxDataViewListModel::RowAppended();
399 return wxDataViewListModel::RowInserted( pos
);
402 bool wxDataViewSortedListModel::ChildRowPrepended()
406 unsigned int len
= m_array
.GetCount();
407 for (i
= 0; i
< len
; i
++)
409 unsigned int value
= m_array
[i
];
410 m_array
[i
] = value
+1;
413 unsigned int pos
= m_array
.Add( 0 );
416 return wxDataViewListModel::RowPrepended();
419 return wxDataViewListModel::RowAppended();
421 return wxDataViewListModel::RowInserted( pos
);
424 bool wxDataViewSortedListModel::ChildRowInserted( unsigned int before
)
428 unsigned int len
= m_array
.GetCount();
429 for (i
= 0; i
< len
; i
++)
431 unsigned int value
= m_array
[i
];
433 m_array
[i
] = value
+1;
436 unsigned int pos
= m_array
.Add( before
);
439 return wxDataViewListModel::RowPrepended();
442 return wxDataViewListModel::RowAppended();
444 return wxDataViewListModel::RowInserted( pos
);
447 bool wxDataViewSortedListModel::ChildRowDeleted( unsigned int row
)
450 unsigned int len
= m_array
.GetCount();
452 for (i
= 0; i
< len
; i
++)
454 unsigned int value
= m_array
[i
];
464 m_array
[i
] = value
-1;
469 return false; // we should probably assert
472 m_array
.RemoveAt( (unsigned int) pos
);
474 return wxDataViewListModel::RowDeleted( (unsigned int) pos
);
477 bool wxDataViewSortedListModel::ChildRowChanged( unsigned int row
)
480 unsigned int len
= m_array
.GetCount();
482 // Remove and readd sorted. Find out at which
483 // position it was and where it ended.
484 unsigned int start_pos
= 0,end_pos
= 0;
485 for (i
= 0; i
< len
; i
++)
486 if (m_array
[i
] == row
)
491 m_array
.RemoveAt( start_pos
);
494 for (i
= 0; i
< len
; i
++)
495 if (m_array
[i
] == row
)
501 if (end_pos
== start_pos
)
502 return wxDataViewListModel::RowChanged( start_pos
);
504 // Create an array where order[old] -> new_pos, so that
505 // if nothing changed order[0] -> 0 etc.
506 unsigned int *order
= new unsigned int[ len
];
507 // Fill up initial values.
508 for (i
= 0; i
< len
; i
++)
511 if (start_pos
< end_pos
)
513 for (i
= start_pos
; i
< end_pos
; i
++)
514 order
[i
] = order
[i
+1];
515 order
[end_pos
] = start_pos
;
519 for (i
= end_pos
; i
> start_pos
; i
--)
520 order
[i
] = order
[i
-1];
521 order
[start_pos
] = end_pos
;
524 wxDataViewListModel::RowsReordered( order
);
531 bool wxDataViewSortedListModel::ChildValueChanged( unsigned int col
, unsigned int row
)
534 unsigned int len
= m_array
.GetCount();
536 // Remove and readd sorted. Find out at which
537 // position it was and where it ended.
538 unsigned int start_pos
= 0,end_pos
= 0;
539 for (i
= 0; i
< len
; i
++)
540 if (m_array
[i
] == row
)
545 m_array
.RemoveAt( start_pos
);
548 for (i
= 0; i
< len
; i
++)
549 if (m_array
[i
] == row
)
555 if (end_pos
== start_pos
)
556 return wxDataViewListModel::ValueChanged( col
, start_pos
);
558 // Create an array where order[old] -> new_pos, so that
559 // if nothing changed order[0] -> 0 etc.
560 unsigned int *order
= new unsigned int[ len
];
561 // Fill up initial values.
562 for (i
= 0; i
< len
; i
++)
565 if (start_pos
< end_pos
)
567 for (i
= start_pos
; i
< end_pos
; i
++)
568 order
[i
] = order
[i
+1];
569 order
[end_pos
] = start_pos
;
573 for (i
= end_pos
; i
> start_pos
; i
--)
574 order
[i
] = order
[i
-1];
575 order
[start_pos
] = end_pos
;
578 wxDataViewListModel::RowsReordered( order
);
585 bool wxDataViewSortedListModel::ChildRowsReordered( unsigned int *WXUNUSED(new_order
) )
587 // Nothing needs to be done. If the sort criteria
588 // of this list don't change, the order of the
589 // items of the child list isn't relevant.
593 bool wxDataViewSortedListModel::ChildCleared()
595 return wxDataViewListModel::Cleared();
598 unsigned int wxDataViewSortedListModel::GetRowCount() const
600 if (!m_child
) return 0;
602 return m_child
->GetRowCount();
605 unsigned int wxDataViewSortedListModel::GetColumnCount() const
607 if (!m_child
) return 0;
609 return m_child
->GetColumnCount();
612 wxString
wxDataViewSortedListModel::GetColumnType( unsigned int col
) const
614 return m_child
->GetColumnType( col
);
617 void wxDataViewSortedListModel::GetValue( wxVariant
&variant
, unsigned int col
, unsigned int row
) const
619 unsigned int child_row
= m_array
[row
];
620 m_child
->GetValue( variant
, col
, child_row
);
623 bool wxDataViewSortedListModel::SetValue( const wxVariant
&variant
, unsigned int col
, unsigned int row
)
625 unsigned int child_row
= m_array
[row
];
626 bool ret
= m_child
->SetValue( variant
, col
, child_row
);
628 // Do nothing here as the change in the
629 // child model will be reported back.
634 bool wxDataViewSortedListModel::RowAppended()
636 // you can only append
637 bool ret
= m_child
->RowAppended();
639 // Do nothing here as the change in the
640 // child model will be reported back.
645 bool wxDataViewSortedListModel::RowPrepended()
647 // you can only append
648 bool ret
= m_child
->RowAppended();
650 // Do nothing here as the change in the
651 // child model will be reported back.
656 bool wxDataViewSortedListModel::RowInserted( unsigned int WXUNUSED(before
) )
658 // you can only append
659 bool ret
= m_child
->RowAppended();
661 // Do nothing here as the change in the
662 // child model will be reported back.
667 bool wxDataViewSortedListModel::RowDeleted( unsigned int row
)
669 unsigned int child_row
= m_array
[row
];
671 bool ret
= m_child
->RowDeleted( child_row
);
673 // Do nothing here as the change in the
674 // child model will be reported back.
679 bool wxDataViewSortedListModel::RowChanged( unsigned int row
)
681 unsigned int child_row
= m_array
[row
];
682 bool ret
= m_child
->RowChanged( child_row
);
684 // Do nothing here as the change in the
685 // child model will be reported back.
690 bool wxDataViewSortedListModel::ValueChanged( unsigned int col
, unsigned int row
)
692 unsigned int child_row
= m_array
[row
];
693 bool ret
= m_child
->ValueChanged( col
, child_row
);
695 // Do nothing here as the change in the
696 // child model will be reported back.
701 bool wxDataViewSortedListModel::RowsReordered( unsigned int *WXUNUSED(new_order
) )
703 // We sort them ourselves.
708 bool wxDataViewSortedListModel::Cleared()
710 bool ret
= m_child
->Cleared();
712 // Do nothing here as the change in the
713 // child model will be reported back.
718 // ---------------------------------------------------------
719 // wxDataViewRendererBase
720 // ---------------------------------------------------------
722 IMPLEMENT_ABSTRACT_CLASS(wxDataViewRendererBase
, wxObject
)
724 wxDataViewRendererBase::wxDataViewRendererBase( const wxString
&varianttype
,
725 wxDataViewCellMode
WXUNUSED(mode
),
726 int WXUNUSED(align
) )
728 m_variantType
= varianttype
;
730 m_row
= (unsigned int) -1;
733 const wxDataViewCtrl
* wxDataViewRendererBase::GetView() const
735 return wx_const_cast(wxDataViewRendererBase
*, this)->GetOwner()->GetOwner();
738 bool wxDataViewRendererBase::StartEditing( unsigned int row
, wxRect labelRect
)
740 m_row
= row
; // remember for later
742 unsigned int col
= GetOwner()->GetModelColumn();
744 GetOwner()->GetOwner()->GetModel()->GetValue( value
, col
, row
);
746 m_editorCtrl
= CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect
, value
);
748 wxDataViewEditorCtrlEvtHandler
*handler
=
749 new wxDataViewEditorCtrlEvtHandler( m_editorCtrl
, (wxDataViewRenderer
*) this );
751 m_editorCtrl
->PushEventHandler( handler
);
753 #if defined(__WXGTK20__) && !defined(wxUSE_GENERICDATAVIEWCTRL)
754 handler
->SetFocusOnIdle();
756 m_editorCtrl
->SetFocus();
762 void wxDataViewRendererBase::CancelEditing()
764 wxPendingDelete
.Append( m_editorCtrl
);
766 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
768 // m_editorCtrl->PopEventHandler( true );
771 bool wxDataViewRendererBase::FinishEditing()
774 GetValueFromEditorCtrl( m_editorCtrl
, value
);
776 wxPendingDelete
.Append( m_editorCtrl
);
778 GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
780 if (!Validate(value
))
783 unsigned int col
= GetOwner()->GetModelColumn();
784 GetOwner()->GetOwner()->GetModel()->SetValue( value
, col
, m_row
);
785 GetOwner()->GetOwner()->GetModel()->ValueChanged( col
, m_row
);
787 // m_editorCtrl->PopEventHandler( true );
792 //-----------------------------------------------------------------------------
793 // wxDataViewEditorCtrlEvtHandler
794 //-----------------------------------------------------------------------------
796 BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler
, wxEvtHandler
)
797 EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar
)
798 EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus
)
799 EVT_IDLE (wxDataViewEditorCtrlEvtHandler::OnIdle
)
802 wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
803 wxControl
*editorCtrl
,
804 wxDataViewRenderer
*owner
)
807 m_editorCtrl
= editorCtrl
;
812 void wxDataViewEditorCtrlEvtHandler::OnIdle( wxIdleEvent
&event
)
816 m_focusOnIdle
= false;
817 if (wxWindow::FindFocus() != m_editorCtrl
)
818 m_editorCtrl
->SetFocus();
824 void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent
&event
)
826 switch ( event
.m_keyCode
)
830 m_owner
->FinishEditing();
835 m_owner
->CancelEditing();
843 void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent
&event
)
848 m_owner
->FinishEditing();
854 // ---------------------------------------------------------
855 // wxDataViewColumnBase
856 // ---------------------------------------------------------
858 IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase
, wxObject
)
860 wxDataViewColumnBase::wxDataViewColumnBase(const wxString
& WXUNUSED(title
),
861 wxDataViewRenderer
*renderer
,
862 unsigned int model_column
,
864 wxAlignment
WXUNUSED(align
),
867 m_renderer
= renderer
;
868 m_model_column
= model_column
;
870 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
872 // NOTE: the wxDataViewColumn's ctor must store the width, align, flags
873 // parameters inside the native control!
876 wxDataViewColumnBase::wxDataViewColumnBase(const wxBitmap
& bitmap
,
877 wxDataViewRenderer
*renderer
,
878 unsigned int model_column
,
880 wxAlignment
WXUNUSED(align
),
881 int WXUNUSED(flags
) )
883 m_renderer
= renderer
;
884 m_model_column
= model_column
;
887 m_renderer
->SetOwner( (wxDataViewColumn
*) this );
890 wxDataViewColumnBase::~wxDataViewColumnBase()
896 int wxDataViewColumnBase::GetFlags() const
901 ret
|= wxDATAVIEW_COL_SORTABLE
;
903 ret
|= wxDATAVIEW_COL_RESIZABLE
;
905 ret
|= wxDATAVIEW_COL_HIDDEN
;
910 void wxDataViewColumnBase::SetFlags(int flags
)
912 SetSortable((flags
& wxDATAVIEW_COL_SORTABLE
) != 0);
913 SetResizeable((flags
& wxDATAVIEW_COL_RESIZABLE
) != 0);
914 SetHidden((flags
& wxDATAVIEW_COL_HIDDEN
) != 0);
917 // ---------------------------------------------------------
918 // wxDataViewEventListModelNotifier
919 // ---------------------------------------------------------
921 class WXDLLIMPEXP_ADV wxDataViewEventListModelNotifier
: public wxDataViewListModelNotifier
924 wxDataViewEventListModelNotifier( wxDataViewCtrl
*ctrl
) { m_ctrl
= ctrl
; }
926 bool SendEvent( wxEventType event_type
, unsigned int row
= 0, unsigned int col
= 0 )
928 wxDataViewEvent
event( event_type
, m_ctrl
->GetId() );
929 event
.SetEventObject( m_ctrl
);
930 event
.SetModel( m_ctrl
->GetModel() );
932 event
.SetColumn( col
);
933 m_ctrl
->GetEventHandler()->ProcessEvent( event
);
937 virtual bool RowAppended() { return SendEvent( wxEVT_COMMAND_DATAVIEW_MODEL_ROW_APPENDED
); }
938 virtual bool RowPrepended() { return SendEvent( wxEVT_COMMAND_DATAVIEW_MODEL_ROW_PREPENDED
); }
939 virtual bool RowInserted( unsigned int before
)
940 { return SendEvent( wxEVT_COMMAND_DATAVIEW_MODEL_ROW_INSERTED
, before
); }
941 virtual bool RowDeleted( unsigned int row
)
942 { return SendEvent( wxEVT_COMMAND_DATAVIEW_MODEL_ROW_DELETED
, row
); }
943 virtual bool RowChanged( unsigned int row
)
944 { return SendEvent( wxEVT_COMMAND_DATAVIEW_MODEL_ROW_CHANGED
, row
); }
945 virtual bool ValueChanged( unsigned int col
, unsigned int row
)
946 { return SendEvent( wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED
, row
, col
); }
947 virtual bool RowsReordered( unsigned int * WXUNUSED(new_order
) )
948 { return SendEvent( wxEVT_COMMAND_DATAVIEW_MODEL_ROWS_REORDERED
); }
949 virtual bool Cleared() { return SendEvent( wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED
); }
952 wxDataViewCtrl
*m_ctrl
;
956 // ---------------------------------------------------------
957 // wxDataViewCtrlBase
958 // ---------------------------------------------------------
960 IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase
, wxControl
)
962 wxDataViewCtrlBase::wxDataViewCtrlBase()
965 m_cols
.DeleteContents( true );
966 m_eventNotifier
= NULL
;
969 wxDataViewCtrlBase::~wxDataViewCtrlBase()
971 // IMPORTANT: before calling DecRef() on our model (since it may
972 // result in a free() call), erase all columns (since
973 // they hold a pointer to our model)
979 m_model
->RemoveNotifier( m_eventNotifier
);
980 m_eventNotifier
= NULL
;
987 bool wxDataViewCtrlBase::AssociateModel( wxDataViewListModel
*model
)
992 m_model
->RemoveNotifier( m_eventNotifier
);
993 m_eventNotifier
= NULL
;
995 m_model
->DecRef(); // discard old model, if any
998 // add our own reference to the new model:
1003 m_eventNotifier
= new wxDataViewEventListModelNotifier( (wxDataViewCtrl
*) this );
1004 m_model
->AddNotifier( m_eventNotifier
);
1010 wxDataViewListModel
* wxDataViewCtrlBase::GetModel()
1015 bool wxDataViewCtrlBase::AppendTextColumn( const wxString
&label
, unsigned int model_column
,
1016 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1018 return AppendColumn( new wxDataViewColumn( label
,
1019 new wxDataViewTextRenderer( wxT("string"), mode
, (int)align
),
1020 model_column
, width
, align
, flags
) );
1023 bool wxDataViewCtrlBase::AppendToggleColumn( const wxString
&label
, unsigned int model_column
,
1024 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1026 return AppendColumn( new wxDataViewColumn( label
,
1027 new wxDataViewToggleRenderer( wxT("bool"), mode
, (int)align
),
1028 model_column
, width
, align
, flags
) );
1031 bool wxDataViewCtrlBase::AppendProgressColumn( const wxString
&label
, unsigned int model_column
,
1032 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1034 return AppendColumn( new wxDataViewColumn( label
,
1035 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
, (int)align
),
1036 model_column
, width
, align
, flags
) );
1039 bool wxDataViewCtrlBase::AppendDateColumn( const wxString
&label
, unsigned int model_column
,
1040 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1042 return AppendColumn( new wxDataViewColumn( label
,
1043 new wxDataViewDateRenderer( wxT("datetime"), mode
, (int)align
),
1044 model_column
, width
, align
, flags
) );
1047 bool wxDataViewCtrlBase::AppendBitmapColumn( const wxString
&label
, unsigned int model_column
,
1048 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1050 return AppendColumn( new wxDataViewColumn( label
,
1051 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
, (int)align
),
1052 model_column
, width
, align
, flags
) );
1055 bool wxDataViewCtrlBase::AppendTextColumn( const wxBitmap
&label
, unsigned int model_column
,
1056 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1058 return AppendColumn( new wxDataViewColumn( label
,
1059 new wxDataViewTextRenderer( wxT("string"), mode
, (int)align
),
1060 model_column
, width
, align
, flags
) );
1063 bool wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap
&label
, unsigned int model_column
,
1064 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1066 return AppendColumn( new wxDataViewColumn( label
,
1067 new wxDataViewToggleRenderer( wxT("bool"), mode
, (int)align
),
1068 model_column
, width
, align
, flags
) );
1071 bool wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap
&label
, unsigned int model_column
,
1072 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1074 return AppendColumn( new wxDataViewColumn( label
,
1075 new wxDataViewProgressRenderer( wxEmptyString
, wxT("long"), mode
, (int)align
),
1076 model_column
, width
, align
, flags
) );
1079 bool wxDataViewCtrlBase::AppendDateColumn( const wxBitmap
&label
, unsigned int model_column
,
1080 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1082 return AppendColumn( new wxDataViewColumn( label
,
1083 new wxDataViewDateRenderer( wxT("datetime"), mode
, (int)align
),
1084 model_column
, width
, align
, flags
) );
1087 bool wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap
&label
, unsigned int model_column
,
1088 wxDataViewCellMode mode
, int width
, wxAlignment align
, int flags
)
1090 return AppendColumn( new wxDataViewColumn( label
,
1091 new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode
, (int)align
),
1092 model_column
, width
, align
, flags
) );
1095 bool wxDataViewCtrlBase::AppendColumn( wxDataViewColumn
*col
)
1097 m_cols
.Append( (wxObject
*) col
);
1098 col
->SetOwner( (wxDataViewCtrl
*) this );
1102 unsigned int wxDataViewCtrlBase::GetColumnCount() const
1104 return m_cols
.GetCount();
1107 bool wxDataViewCtrlBase::DeleteColumn( unsigned int WXUNUSED(pos
) )
1112 bool wxDataViewCtrlBase::ClearColumns()
1117 wxDataViewColumn
* wxDataViewCtrlBase::GetColumn( unsigned int pos
)
1119 return (wxDataViewColumn
*) m_cols
[ pos
];
1122 // ---------------------------------------------------------
1124 // ---------------------------------------------------------
1126 IMPLEMENT_DYNAMIC_CLASS(wxDataViewEvent
,wxNotifyEvent
)
1128 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ROW_SELECTED
)
1129 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ROW_ACTIVATED
)
1130 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK
)
1131 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK
)
1132 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED
)
1134 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_APPENDED
)
1135 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_PREPENDED
)
1136 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_INSERTED
)
1137 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_DELETED
)
1138 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ROW_CHANGED
)
1139 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_VALUE_CHANGED
)
1140 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_ROWS_REORDERED
)
1141 DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_MODEL_CLEARED
)