Fix handling of disabled cells in wxGTK wxDataViewCtrl.

The original code (see r66404 and r66416) didn't work because it used
wxDataViewRenderer::SetMode() to make the renderer inactive but then used its
GetMode() to restore the previous state -- which was lost. The result of this
was that if the overridden IsEnabled() in the model ever returned false for
any row, all the cells in this column, in all the rows, became insensitive, as
could be seen by the inability to edit any rating in the first page of the
dataview sample (even though it was disabled for a single row only) and any
checkboxes on its third page (even though only the last two of them were
supposed to be disabled).

Fix this simply by making the renderer insensitive at GTK level only, but do
not change the mode at wx level.

See #12686.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78470 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2015-02-10 23:14:48 +00:00
parent 48c6d036f9
commit 6ad2d4f264
2 changed files with 18 additions and 37 deletions

View File

@ -76,8 +76,12 @@ public:
// specific attributes: can return NULL if this renderer doesn't render any
// text
virtual GtkCellRendererText *GtkGetTextRenderer() const { return NULL; }
wxDataViewCellMode GtkGetMode() { return m_mode; }
// Change the mode at GTK level without touching m_mode, this is useful for
// temporarily making the renderer insensitive but does mean that GetMode()
// may return a value different from the actual GTK renderer mode.
void GtkSetMode(wxDataViewCellMode mode);
protected:
virtual void GtkOnCellChanged(const wxVariant& value,
@ -90,6 +94,9 @@ protected:
GtkCellRenderer *m_renderer;
int m_alignment;
// We store the renderer mode at wx level as it can differ from the mode of
// the corresponding GTK+ renderer as explained above.
wxDataViewCellMode m_mode;
// true if we hadn't changed any visual attributes or restored them since

View File

@ -1854,6 +1854,13 @@ void wxDataViewRenderer::GtkInitHandlers()
}
void wxDataViewRenderer::SetMode( wxDataViewCellMode mode )
{
m_mode = mode;
GtkSetMode(mode);
}
void wxDataViewRenderer::GtkSetMode( wxDataViewCellMode mode )
{
GtkCellRendererMode gtkMode;
switch (mode)
@ -1875,9 +1882,6 @@ void wxDataViewRenderer::SetMode( wxDataViewCellMode mode )
return;
}
m_mode = mode;
// This value is most often ignored in GtkTreeView
GValue gvalue = G_VALUE_INIT;
g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() );
g_value_set_enum( &gvalue, gtkMode );
@ -1887,33 +1891,7 @@ void wxDataViewRenderer::SetMode( wxDataViewCellMode mode )
wxDataViewCellMode wxDataViewRenderer::GetMode() const
{
wxDataViewCellMode ret;
GValue gvalue;
g_object_get( G_OBJECT(m_renderer), "mode", &gvalue, NULL);
switch (g_value_get_enum(&gvalue))
{
default:
wxFAIL_MSG( "unknown GtkCellRendererMode value" );
// fall through (we have to return something)
case GTK_CELL_RENDERER_MODE_INERT:
ret = wxDATAVIEW_CELL_INERT;
break;
case GTK_CELL_RENDERER_MODE_ACTIVATABLE:
ret = wxDATAVIEW_CELL_ACTIVATABLE;
break;
case GTK_CELL_RENDERER_MODE_EDITABLE:
ret = wxDATAVIEW_CELL_EDITABLE;
break;
}
g_value_unset( &gvalue );
return ret;
return m_mode;
}
void wxDataViewRenderer::GtkApplyAlignment(GtkCellRenderer *renderer)
@ -2937,11 +2915,7 @@ static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *WXUNUSED(column),
g_value_unset( &gvalue );
// b) this actually disables the control/renderer
if (enabled)
cell->SetMode( cell->GtkGetMode() );
else
cell->SetMode( wxDATAVIEW_CELL_INERT );
cell->GtkSetMode(enabled ? cell->GetMode() : wxDATAVIEW_CELL_INERT);
// deal with attributes: if the renderer doesn't support them at all, we
// don't even need to query the model for them