Use wxDataViewRenderer::PrepareForItem() in all ports
wxOSX and wxGTK previously used their own methods for handling the enabled state and the attributes of the items being rendered, change them to reuse the same methods as the generic implementation, i.e. SetEnabled() and SetAttr() and remove the port-specific GtkSetAttr(), OSXApplyAttr() and so on. This has the advantage of ensuring that the logic is the same for all platforms (e.g. item enabled status wasn't handled in the same way in wxGTK as in the other ports previously) and hopefully makes the code simpler by cutting down on the number of virtual methods. Notice that GtkSupportsAttrs() optimization was removed as it didn't seem to be worth the bother (we basically saved a call to a virtual model method at a price of a virtual renderer method call) and preserving it would have complicated things needlessly.
This commit is contained in:
@@ -808,34 +808,42 @@ wxDataViewRendererBase::CheckedGetValue(const wxDataViewModel* model,
|
||||
}
|
||||
|
||||
bool
|
||||
wxDataViewRendererBase::PrepareValue(const wxDataViewModel* model,
|
||||
const wxDataViewItem& item,
|
||||
unsigned column)
|
||||
wxDataViewRendererBase::PrepareForItem(const wxDataViewModel *model,
|
||||
const wxDataViewItem& item,
|
||||
unsigned column)
|
||||
{
|
||||
// Now check if we have a value and remember it if we do.
|
||||
const wxVariant& value = CheckedGetValue(model, item, column);
|
||||
if ( !value.IsNull() )
|
||||
{
|
||||
SetValue(value);
|
||||
|
||||
if ( value.IsNull() )
|
||||
return false;
|
||||
// Also set up the attributes for this item if it's not empty.
|
||||
wxDataViewItemAttr attr;
|
||||
model->GetAttr(item, column, attr);
|
||||
SetAttr(attr);
|
||||
}
|
||||
|
||||
SetValue(value);
|
||||
// Finally determine the enabled/disabled state and apply it, even to the
|
||||
// empty cells.
|
||||
bool enabled = true;
|
||||
switch ( GetMode() )
|
||||
{
|
||||
case wxDATAVIEW_CELL_INERT:
|
||||
enabled = false;
|
||||
break;
|
||||
|
||||
case wxDATAVIEW_CELL_ACTIVATABLE:
|
||||
case wxDATAVIEW_CELL_EDITABLE:
|
||||
enabled = model->IsEnabled(item, column);
|
||||
break;
|
||||
}
|
||||
|
||||
SetEnabled(enabled);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxDataViewRendererBase::PrepareForItem(const wxDataViewModel *model,
|
||||
const wxDataViewItem& item,
|
||||
unsigned column)
|
||||
{
|
||||
if ( !PrepareValue(model, item, column) )
|
||||
return;
|
||||
|
||||
wxDataViewItemAttr attr;
|
||||
model->GetAttr(item, column, attr);
|
||||
SetAttr(attr);
|
||||
|
||||
SetEnabled(model->IsEnabled(item, column));
|
||||
}
|
||||
|
||||
|
||||
int wxDataViewRendererBase::GetEffectiveAlignment() const
|
||||
{
|
||||
@@ -991,6 +999,18 @@ wxDataViewCustomRendererBase::RenderText(const wxString& text,
|
||||
rectText, GetEffectiveAlignment());
|
||||
}
|
||||
|
||||
void wxDataViewCustomRendererBase::SetEnabled(bool enabled)
|
||||
{
|
||||
// The native base renderer needs to know about the enabled state as well
|
||||
// but in the generic case the base class method is pure, so we can't just
|
||||
// call it unconditionally.
|
||||
#ifndef wxHAS_GENERIC_DATAVIEWCTRL
|
||||
wxDataViewRenderer::SetEnabled(enabled);
|
||||
#endif // !wxHAS_GENERIC_DATAVIEWCTRL
|
||||
|
||||
m_enabled = enabled;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxDataViewEditorCtrlEvtHandler
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user