]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxDataViewListCtrl::{Set,Get}ItemData() methods.
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 25 May 2012 17:02:35 +0000 (17:02 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 25 May 2012 17:02:35 +0000 (17:02 +0000)
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
include/wx/dataview.h
interface/wx/dataview.h
src/common/datavcmn.cpp

index 84b20935c6e1aeb2e7c23e67e17e4ea6539c53b3..d0ddc372b8703f304cd4f4ca0e5061f9a429886e 100644 (file)
@@ -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:
 
index 234ec4170f480a6fdce46bb7f0ee0839f1ccdf8c..9e1ad7bac1f6200306f034bf7e27e04b87a1337c 100644 (file)
@@ -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:
index 5b009163420d089be58bec99d7045167734e220c..a491490c40a5e6f4acd66abc3bb0b2bbdabcaede 100644 (file)
@@ -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
     */
index ef43faa33b6e0e6d5d74fe9f49e53c309857cd28..ab385d09d3ea9693d17517de74246610c62cb831 100644 (file)
@@ -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];