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:
@@ -434,6 +434,7 @@ All (GUI):
|
||||
- Added wxUIActionSimulator (Steven Lamerton, GSoC 2010 project).
|
||||
- wxAUI: support auto-orientable toolbars (wsu).
|
||||
- Added wxDataViewCtrl::Set/GetCurrentItem().
|
||||
- Added possibility to disable individual wxDataViewCtrl items (Neno Ganchev).
|
||||
- wxHTML: render in RTL order inside RTL window (Richard Bullington-McGuire).
|
||||
- wxRibbon: added EVT_RIBBONGALLERY_CLICKED event (John Roberts).
|
||||
- Add support for CP-866 encoding to wxEncodingConverter (madnut).
|
||||
|
@@ -234,6 +234,13 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
// Override this if you want to disable specific items
|
||||
virtual bool IsEnabled(const wxDataViewItem &WXUNUSED(item),
|
||||
unsigned int WXUNUSED(col)) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// define hierachy
|
||||
virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const = 0;
|
||||
virtual bool IsContainer( const wxDataViewItem &item ) const = 0;
|
||||
@@ -304,6 +311,12 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool IsEnabledByRow(unsigned int WXUNUSED(row),
|
||||
unsigned int WXUNUSED(col)) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// helper methods provided by list models only
|
||||
virtual unsigned GetRow( const wxDataViewItem &item ) const = 0;
|
||||
@@ -344,6 +357,11 @@ public:
|
||||
return GetAttrByRow( GetRow(item), col, attr );
|
||||
}
|
||||
|
||||
virtual bool IsEnabled(const wxDataViewItem &item, unsigned int col) const
|
||||
{
|
||||
return IsEnabledByRow( GetRow(item), col );
|
||||
}
|
||||
|
||||
|
||||
virtual bool IsListModel() const { return true; }
|
||||
};
|
||||
|
@@ -116,6 +116,8 @@ public:
|
||||
|
||||
virtual void SetAttr(const wxDataViewItemAttr& WXUNUSED(attr)) { }
|
||||
|
||||
virtual void SetEnabled(bool WXUNUSED(enabled)) { }
|
||||
|
||||
wxString GetVariantType() const { return m_variantType; }
|
||||
|
||||
// helper that calls SetValue and SetAttr:
|
||||
@@ -261,6 +263,11 @@ public:
|
||||
virtual void SetAttr(const wxDataViewItemAttr& attr) { m_attr = attr; }
|
||||
const wxDataViewItemAttr& GetAttr() const { return m_attr; }
|
||||
|
||||
// Store the enabled state of the item so that it can be accessed from
|
||||
// Render() via GetEnabled() if needed.
|
||||
virtual void SetEnabled(bool enabled) { m_enabled = enabled; }
|
||||
bool GetEnabled() const { return m_enabled; }
|
||||
|
||||
|
||||
// Implementation only from now on
|
||||
|
||||
@@ -277,6 +284,7 @@ protected:
|
||||
|
||||
private:
|
||||
wxDataViewItemAttr m_attr;
|
||||
bool m_enabled;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxDataViewCustomRendererBase);
|
||||
};
|
||||
|
@@ -87,6 +87,9 @@ public:
|
||||
// called to ensure that the given attribute will be used for rendering the
|
||||
// next cell (which had been already associated with this renderer before)
|
||||
virtual void OSXApplyAttr(const wxDataViewItemAttr& attr);
|
||||
|
||||
// called to set the state of the next cell to be rendered
|
||||
virtual void OSXApplyEnabled(bool enabled);
|
||||
#endif // Cocoa
|
||||
|
||||
private:
|
||||
|
@@ -167,6 +167,32 @@ public:
|
||||
virtual bool GetAttr(const wxDataViewItem& item, unsigned int col,
|
||||
wxDataViewItemAttr& attr) const;
|
||||
|
||||
/**
|
||||
Override this to indicate that the item should be disabled.
|
||||
|
||||
Disabled items are displayed differently (e.g. grayed out) and cannot
|
||||
be interacted with.
|
||||
|
||||
The base class version always returns @true, thus making all items
|
||||
enabled by default.
|
||||
|
||||
@param item
|
||||
The item whose enabled status is requested.
|
||||
@param col
|
||||
The column of the item whose enabled status is requested.
|
||||
@return
|
||||
@true if this item should be enabled, @false otherwise.
|
||||
|
||||
@note Currently disabling items is fully implemented only for the
|
||||
native control implementation in wxOSX/Cocoa. This feature is
|
||||
partially supported in the generic version but not in wxGTK or
|
||||
wxOSX/Carbon native implementations.
|
||||
|
||||
@since 2.9.2
|
||||
*/
|
||||
virtual bool IsEnabled(const wxDataViewItem &item,
|
||||
unsigned int col) const;
|
||||
|
||||
/**
|
||||
Override this so the control can query the child items of an item.
|
||||
Returns the number of items.
|
||||
@@ -371,6 +397,28 @@ public:
|
||||
virtual bool GetAttrByRow(unsigned int row, unsigned int col,
|
||||
wxDataViewItemAttr& attr) const;
|
||||
|
||||
/**
|
||||
Override this if you want to disable specific items.
|
||||
|
||||
The base class version always returns @true, thus making all items
|
||||
enabled by default.
|
||||
|
||||
@param row
|
||||
The row of the item whose enabled status is requested.
|
||||
@param col
|
||||
The column of the item whose enabled status is requested.
|
||||
@return
|
||||
@true if the item at this row and column should be enabled,
|
||||
@false otherwise.
|
||||
|
||||
@note See wxDataViewModel::IsEnabled() for the current status of
|
||||
support for disabling the items under different platforms.
|
||||
|
||||
@since 2.9.2
|
||||
*/
|
||||
virtual bool IsEnabledByRow(unsigned int row,
|
||||
unsigned int col) const;
|
||||
|
||||
/**
|
||||
Returns the number of items (i.e. rows) in the list.
|
||||
*/
|
||||
|
@@ -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" );
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
};
|
||||
|
@@ -790,6 +790,8 @@ void wxDataViewRendererBase::PrepareForItem(const wxDataViewModel *model,
|
||||
wxDataViewItemAttr attr;
|
||||
model->GetAttr(item, column, attr);
|
||||
SetAttr(attr);
|
||||
|
||||
SetEnabled(model->IsEnabled(item, column));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -845,7 +845,8 @@ bool wxDataViewToggleRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state
|
||||
int flags = 0;
|
||||
if (m_toggle)
|
||||
flags |= wxCONTROL_CHECKED;
|
||||
if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE)
|
||||
if (GetMode() != wxDATAVIEW_CELL_ACTIVATABLE ||
|
||||
GetEnabled() == false)
|
||||
flags |= wxCONTROL_DISABLED;
|
||||
|
||||
// check boxes we draw must always have the same, standard size (if it's
|
||||
@@ -868,7 +869,10 @@ void wxDataViewToggleRenderer::WXOnActivate(wxDataViewModel *model,
|
||||
const wxDataViewItem & item,
|
||||
unsigned int col)
|
||||
{
|
||||
if (model->IsEnabled(item, col))
|
||||
{
|
||||
model->ChangeValue(!valueOld.GetBool(), item, col);
|
||||
}
|
||||
}
|
||||
|
||||
wxSize wxDataViewToggleRenderer::GetSize() const
|
||||
|
@@ -1695,6 +1695,9 @@ outlineView:(NSOutlineView*)outlineView
|
||||
model->GetAttr(dvItem, colIdx, attr);
|
||||
renderer->OSXApplyAttr(attr);
|
||||
|
||||
// set the state (enabled/disabled) of the item
|
||||
renderer->OSXApplyEnabled(model->IsEnabled(dvItem, colIdx));
|
||||
|
||||
// and finally do draw it
|
||||
renderer->MacRender();
|
||||
}
|
||||
@@ -2487,6 +2490,11 @@ void wxDataViewRenderer::OSXApplyAttr(const wxDataViewItemAttr& attr)
|
||||
[(id)cell setTextColor:colText];
|
||||
}
|
||||
|
||||
void wxDataViewRenderer::OSXApplyEnabled(bool enabled)
|
||||
{
|
||||
[GetNativeData()->GetItemCell() setEnabled:enabled];
|
||||
}
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS(wxDataViewRenderer,wxDataViewRendererBase)
|
||||
|
||||
// ---------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user