Add the possibility to disable invisible wxDataViewCtrl items.

Add new wxDataViewModel::IsEnabled() and wxDataViewListStore::IsEnabledByRow()
methods and implement support for actually disabling the items in wxOSX/Cocoa
native implementation of wxDataViewCtrl and limited support for it in the
generic version.

We need to implement this in wxGTK using GtkCellRenderer "sensitive" propriety
later.

Closes #12686.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66403 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-12-19 15:02:56 +00:00
parent 46405e36bf
commit 98f8e6666b
11 changed files with 132 additions and 2 deletions

View File

@@ -653,6 +653,10 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned l
wxDefaultSize, style );
m_ctrl[2] = lc;
MyListStoreDerivedModel* page2_model = new MyListStoreDerivedModel();
lc->AssociateModel(page2_model);
page2_model->DecRef();
lc->AppendToggleColumn( "Toggle" );
lc->AppendTextColumn( "Text" );
lc->AppendProgressColumn( "Progress" );

View File

@@ -244,6 +244,17 @@ bool MyMusicTreeModel::SetValue( const wxVariant &variant,
return false;
}
bool MyMusicTreeModel::IsEnabled( const wxDataViewItem &item,
unsigned int col ) const
{
wxASSERT(item.IsOk());
MyMusicTreeModelNode *node = (MyMusicTreeModelNode*) item.GetID();
// disable Beethoven's ratings, his pieces can only be good
return !(col == 3 && node->m_artist.EndsWith("Beethoven"));
}
wxDataViewItem MyMusicTreeModel::GetParent( const wxDataViewItem &item ) const
{
// the invisible root node has no parent
@@ -525,3 +536,14 @@ bool MyListModel::SetValueByRow( const wxVariant &variant,
return false;
}
// ----------------------------------------------------------------------------
// MyListStoreDerivedModel
// ----------------------------------------------------------------------------
bool MyListStoreDerivedModel::IsEnabledByRow(unsigned int row, unsigned int col) const
{
// disabled the last two checkboxes
return !(col == 0 && 8 <= row && row <= 9);
}

View File

@@ -163,6 +163,9 @@ public:
virtual bool SetValue( const wxVariant &variant,
const wxDataViewItem &item, unsigned int col );
virtual bool IsEnabled( const wxDataViewItem &item,
unsigned int col ) const;
virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const;
virtual bool IsContainer( const wxDataViewItem &item ) const;
virtual unsigned int GetChildren( const wxDataViewItem &parent,
@@ -235,3 +238,12 @@ private:
wxIcon m_icon[2];
};
// ----------------------------------------------------------------------------
// MyListStoreDerivedModel
// ----------------------------------------------------------------------------
class MyListStoreDerivedModel : public wxDataViewListStore
{
public:
virtual bool IsEnabledByRow(unsigned int row, unsigned int col) const;
};