Gtk::CellRendererPixbuf: unable to set property 'surface'

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Gtk::CellRendererPixbuf: unable to set property 'surface'

Alexander Shaduri
Hi,

I'm trying to set a "surface" property on Gtk::CellRendererPixbuf
and getting a gtk error:

"unable to set property 'surface' of type 'CairoSurface' from value of type
'glibmm__CustomBoxed_N5Cairo6RefPtrINS_7SurfaceEEE'"


This is the code:

-------------------------------------------

class GscMainWindowIconView : public Gtk::IconView {

    Gtk::CellRendererPixbuf cell_renderer_pixbuf;
    // ...

    GscMainWindowIconView()
    {
       //...
       this->pack_start(cell_renderer_pixbuf, false);
       this->set_cell_data_func(cell_renderer_pixbuf,
       sigc::mem_fun(this, &GscMainWindowIconView::on_cell_data));
    }

    void on_cell_data(const Gtk::TreeModel::const_iterator& iter)
    {
       Gtk::TreeRow row = *iter;
       Glib::RefPtr<Gdk::Pixbuf> pixbuf = row[col_pixbuf];

       // I couldn't find the gtkmm version of gdk_cairo_surface_create_from_pixbuf(),
       // that's why I create the surface this way.
       Cairo::Format format = Cairo::FORMAT_ARGB32;
       if (pixbuf->get_n_channels() == 3) {
           format = Cairo::FORMAT_RGB24;
       }
    Cairo::RefPtr<Cairo::Surface> surface = get_window()->create_similar_image_surface(
               format, pixbuf->get_width(), pixbuf->get_height(), get_scale_factor());

       // THIS IS THE PROBLEM
       cell_renderer_pixbuf.property_surface().set_value(surface);
    }

}

-------------------------------------------

Note that if I change Cairo surface creation and property setting
to C-style, everything works (although I'm not sure whether the "surface"
variable leaks? The docs don't mention):

cairo_surface_t* surface = gdk_cairo_surface_create_from_pixbuf(
        pixbuf->gobj(), get_scale_factor(), get_window()->gobj());
g_object_set(G_OBJECT(cell_renderer_pixbuf.gobj()), "surface", surface, NULL);


This all comes from trying to port the code from this bug report:
https://bugzilla.gnome.org/show_bug.cgi?id=765167#c5


Thanks,
Alexander

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Gtk::CellRendererPixbuf: unable to set property 'surface'

Daniel Boles
On 3 October 2017 at 23:13, Alexander Shaduri <[hidden email]> wrote:
(although I'm not sure whether the "surface"
variable leaks? The docs don't mention):

cairo_surface_t* surface = gdk_cairo_surface_create_from_pixbuf(
        pixbuf->gobj(), get_scale_factor(), get_window()->gobj());
g_object_set(G_OBJECT(cell_renderer_pixbuf.gobj()), "surface", surface, NULL);

The create function returns an object with 1 reference, which you are responsible to destroy(). You pass it to GtkCellRendererPixbuf, whic passes the surface to gtk_image_definition_new_surface (cairo_surface_t *surface), which refs the surface. So you need to drop the reference you had after calling the latter, unless you want to keep the surface alive longer than the CellRenderer does.
 

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Gtk::CellRendererPixbuf: unable to set property 'surface'

Kjell Ahlstedt-2
In reply to this post by Alexander Shaduri
Den 2017-10-04 kl. 00:13, skrev Alexander Shaduri:
Hi,

I'm trying to set a "surface" property on Gtk::CellRendererPixbuf
and getting a gtk error:

"unable to set property 'surface' of type 'CairoSurface' from value of type
'glibmm__CustomBoxed_N5Cairo6RefPtrINS_7SurfaceEEE'"

The following comment comes from gtkmm/gdk/src/drawingcontext.hg:
  // A wrapped property_clip() would require a template specialization
  // Glib::Value<Cairo::RefPtr<T>>.
  //_WRAP_PROPERTY("clip", ::Cairo::RefPtr< ::Cairo::Region>)

Compare with
  _WRAP_PROPERTY("surface", ::Cairo::RefPtr< ::Cairo::Surface>)
from gtkmm/gtk/src/cellrendererpixbuf.hg.
Not much chance that CellRendererPixbuf::property_surface() will work. You can file a bug report in Bugzilla.

Kjell


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Gtk::CellRendererPixbuf: unable to set property 'surface'

Alexander Shaduri

Oh well, thanks for your reply.

Filed https://bugzilla.gnome.org/show_bug.cgi?id=788513

Thanks,
Alexander


On Wed, 2017-10-04 at 14:49 +0200, Kjell Ahlstedt wrote:

> Den 2017-10-04 kl. 00:13, skrev Alexander Shaduri:
> > Hi,
> >
> > I'm trying to set a "surface" property on Gtk::CellRendererPixbuf
> > and getting a gtk error:
> >
> > "unable to set property 'surface' of type 'CairoSurface' from value of type
> > 'glibmm__CustomBoxed_N5Cairo6RefPtrINS_7SurfaceEEE'"
> >
>  The following comment comes from gtkmm/gdk/src/drawingcontext.hg:
>   // A wrapped property_clip() would require a template specialization
>   // Glib::Value<Cairo::RefPtr<T>>.
>   //_WRAP_PROPERTY("clip", ::Cairo::RefPtr< ::Cairo::Region>)
>
> Compare with
>   _WRAP_PROPERTY("surface", ::Cairo::RefPtr< ::Cairo::Surface>)
> from gtkmm/gtk/src/cellrendererpixbuf.hg.
> Not much chance that CellRendererPixbuf::property_surface() will work. You can file a bug report in Bugzilla.
>
> Kjell
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list