From 518cef04707760634dd3937c3a928bbc2db24836 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 25 May 2012 17:02:35 +0000 Subject: [PATCH] Add wxDataViewListCtrl::{Set,Get}ItemData() methods. These methods are convenient when migrating the code that previously used wxListCtrl to wxDataViewCtrl. Closes #11088. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71562 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/dataview.h | 8 ++++++++ interface/wx/dataview.h | 43 +++++++++++++++++++++++++++++++++++++++++ src/common/datavcmn.cpp | 16 +++++++++++++++ 4 files changed, 68 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index 84b20935c6..d0ddc372b8 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -556,6 +556,7 @@ All (GUI): - Added custom text and dimension scaling to wxRichTextCtrl. - Added pixel font size capability to wxTextAttr and wxRichTextCtrl. - Fully implement wxStyledTextCtrl::PositionToXY() (troelsk). +- Added wxDataViewListCtrl::{Set,Get}ItemData(). GTK: diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 234ec4170f..9e1ad7bac1 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -972,6 +972,9 @@ public: void DeleteItem( unsigned int pos ); void DeleteAllItems(); + void SetItemData( const wxDataViewItem& item, wxUIntPtr data ); + wxUIntPtr GetItemData( const wxDataViewItem& item ) const; + // override base virtuals virtual unsigned int GetColumnCount() const; @@ -1077,6 +1080,11 @@ public: bool GetToggleValue( unsigned int row, unsigned int col ) const { wxVariant value; GetStore()->GetValueByRow( value, row, col ); return value.GetBool(); } + void SetItemData( const wxDataViewItem& item, wxUIntPtr data ) + { GetStore()->SetItemData( item, data ); } + wxUIntPtr GetItemData( const wxDataViewItem& item ) const + { return GetStore()->GetItemData( item ); } + void OnSize( wxSizeEvent &event ); private: diff --git a/interface/wx/dataview.h b/interface/wx/dataview.h index 5b00916342..a491490c40 100644 --- a/interface/wx/dataview.h +++ b/interface/wx/dataview.h @@ -2337,6 +2337,15 @@ public: */ void DeleteAllItems(); + /** + Returns the client data associated with the item. + + @see SetItemData() + + @since 2.9.4 + */ + wxUIntPtr GetItemData(const wxDataViewItem& item) const; + /** Sets the value in the store and update the control. */ @@ -2379,6 +2388,19 @@ public: */ bool GetToggleValue( unsigned int row, unsigned int col ) const; + /** + Associates a client data pointer with the given item. + + Notice that the control does @e not take ownership of the pointer for + compatibility with wxListCtrl. I.e. it will @e not delete the pointer + (if it is a pointer and not a number) itself, it is up to you to do it. + + @see GetItemData() + + @since 2.9.4 + */ + void SetItemData(const wxDataViewItem& item, wxUIntPtr data); + //@} }; @@ -2688,6 +2710,15 @@ public: */ void DeleteAllItems(); + /** + Returns the client data associated with the item. + + @see SetItemData() + + @since 2.9.4 + */ + wxUIntPtr GetItemData(const wxDataViewItem& item) const; + /** Overridden from wxDataViewModel */ @@ -2698,6 +2729,18 @@ public: */ virtual wxString GetColumnType( unsigned int col ) const; + /** + Sets the client data associated with the item. + + Notice that this class does @e not take ownership of the passed in + pointer and will not delete it. + + @see GetItemData() + + @since 2.9.4 + */ + void SetItemData(const wxDataViewItem& item, wxUIntPtr data); + /** Overridden from wxDataViewIndexListModel */ diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index ef43faa33b..ab385d09d3 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -1761,6 +1761,22 @@ void wxDataViewListStore::DeleteAllItems() Reset( 0 ); } +void wxDataViewListStore::SetItemData( const wxDataViewItem& item, wxUIntPtr data ) +{ + wxDataViewListStoreLine* line = m_data[wxPtrToUInt( item.GetID() ) - 1]; + if (!line) return; + + line->SetData( data ); +} + +wxUIntPtr wxDataViewListStore::GetItemData( const wxDataViewItem& item ) const +{ + wxDataViewListStoreLine* line = m_data[wxPtrToUInt( item.GetID() ) - 1]; + if (!line) return NULL; + + return line->GetData(); +} + void wxDataViewListStore::GetValueByRow( wxVariant &value, unsigned int row, unsigned int col ) const { wxDataViewListStoreLine *line = m_data[row]; -- 2.45.2