diff --git a/include/wx/dataview.h b/include/wx/dataview.h index be3ce240a8..87bfcf12e2 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -81,10 +81,11 @@ extern WXDLLIMPEXP_DATA_ADV(const char) wxDataViewCtrlNameStr[]; class WXDLLIMPEXP_ADV wxDataViewItem { public: - wxDataViewItem( void* id = NULL ) - { m_id = id; } - wxDataViewItem( const wxDataViewItem &item ) - { m_id = item.m_id; } + wxDataViewItem() : m_id(NULL) {} + wxDataViewItem(const wxDataViewItem &item) : m_id(item.m_id) {} + + wxEXPLICIT wxDataViewItem(void* id) : m_id(id) {} + bool IsOk() const { return m_id != NULL; } void* GetID() const { return m_id; } operator const void* () const { return m_id; } diff --git a/interface/wx/dataview.h b/interface/wx/dataview.h index f4d4fcd8f1..9c24be7d76 100644 --- a/interface/wx/dataview.h +++ b/interface/wx/dataview.h @@ -614,8 +614,9 @@ public: /** Constructor. */ - wxDataViewItem(void* id = NULL); + wxDataViewItem(); wxDataViewItem(const wxDataViewItem& item); + explicit wxDataViewItem(void* id); //@} /** diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 611d3b1d5a..c5540283fc 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -387,7 +387,7 @@ wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size ) // build initial index unsigned int i; for (i = 1; i < initial_size+1; i++) - m_hash.Add( wxUIntToPtr(i) ); + m_hash.Add( wxDataViewItem(wxUIntToPtr(i)) ); m_nextFreeID = initial_size + 1; } @@ -403,7 +403,7 @@ void wxDataViewIndexListModel::Reset( unsigned int new_size ) // build initial index unsigned int i; for (i = 1; i < new_size+1; i++) - m_hash.Add( wxUIntToPtr(i) ); + m_hash.Add( wxDataViewItem(wxUIntToPtr(i)) ); m_nextFreeID = new_size + 1; @@ -417,8 +417,8 @@ void wxDataViewIndexListModel::RowPrepended() unsigned int id = m_nextFreeID; m_nextFreeID++; - m_hash.Insert( wxUIntToPtr(id), 0 ); wxDataViewItem item( wxUIntToPtr(id) ); + m_hash.Insert( item, 0 ); ItemAdded( wxDataViewItem(0), item ); } @@ -430,8 +430,8 @@ void wxDataViewIndexListModel::RowInserted( unsigned int before ) unsigned int id = m_nextFreeID; m_nextFreeID++; - m_hash.Insert( wxUIntToPtr(id), before ); wxDataViewItem item( wxUIntToPtr(id) ); + m_hash.Insert( item, before ); ItemAdded( wxDataViewItem(0), item ); } @@ -440,8 +440,8 @@ void wxDataViewIndexListModel::RowAppended() unsigned int id = m_nextFreeID; m_nextFreeID++; - m_hash.Add( wxUIntToPtr(id) ); wxDataViewItem item( wxUIntToPtr(id) ); + m_hash.Add( item ); ItemAdded( wxDataViewItem(0), item ); } @@ -490,7 +490,7 @@ unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) cons return wxPtrToUInt(item.GetID())-1; // assert for not found - return (unsigned int) m_hash.Index( item.GetID() ); + return (unsigned int) m_hash.Index( item ); } wxDataViewItem wxDataViewIndexListModel::GetItem( unsigned int row ) const @@ -2005,7 +2005,7 @@ wxDataViewItem wxDataViewTreeStore::GetNthChild( const wxDataViewItem& parent, u wxDataViewTreeStoreNodeList::compatibility_iterator node = parent_node->GetChildren().Item( pos ); if (node) - return node->GetData(); + return wxDataViewItem(node->GetData()); return wxDataViewItem(0); } @@ -2111,7 +2111,7 @@ void wxDataViewTreeStore::DeleteChildren( const wxDataViewItem& item ) void wxDataViewTreeStore::DeleteAllItems() { - DeleteChildren(m_root); + DeleteChildren(wxDataViewItem(m_root)); } void diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 167c1149b8..aaaa107c89 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -406,7 +406,7 @@ int LINKAGEMODE wxGenericTreeModelNodeCmp( wxDataViewTreeNode ** node1, int LINKAGEMODE wxGenericTreeModelItemCmp( void ** id1, void ** id2) { - return g_model->Compare( *id1, *id2, g_column, g_asending ); + return g_model->Compare( wxDataViewItem(*id1), wxDataViewItem(*id2), g_column, g_asending ); } @@ -2702,7 +2702,7 @@ public: if( node->GetNodes().GetCount() == 0) { int index = static_cast(row) - current - 1; - ret = node->GetChildren().Item( index ); + ret = wxDataViewItem(node->GetChildren().Item( index )); return DoJob::OK; } return DoJob::CONT; diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index e27c908000..ee2ea2b686 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -300,7 +300,7 @@ private: static int LINKAGEMODE wxGtkTreeModelChildCmp( void** id1, void** id2 ) { - int ret = gs_internal->GetDataViewModel()->Compare( *id1, *id2, + int ret = gs_internal->GetDataViewModel()->Compare( wxDataViewItem(*id1), wxDataViewItem(*id2), gs_internal->GetSortColumn(), (gs_internal->GetSortOrder() == GTK_SORT_ASCENDING) ); return ret; @@ -3334,7 +3334,7 @@ int wxGtkTreeModelChildWithPosCmp( const void* data1, const void* data2, const v static int LINKAGEMODE wxGtkTreeModelChildPtrCmp( void*** data1, void*** data2 ) { - return gs_internal->GetDataViewModel()->Compare( **data1, **data2, + return gs_internal->GetDataViewModel()->Compare( wxDataViewItem(**data1), wxDataViewItem(**data2), gs_internal->GetSortColumn(), (gs_internal->GetSortOrder() == GTK_SORT_ASCENDING) ); }