Re: How to add a custom cell renderer to a Gtk::IconView



On Tue, 2009-11-17 at 22:58 -0500, Todor Todorov wrote: 
> I need to clarify. What I tried was:
> 
> Glib::RefPtr<Gtk::CellLayout> cl = Glib::wrap( GTK_CELL_LAYOUT( my_icon_view.gobj() ) );
> 
> 
> And the error was: "Glib::wrap_auto_interface(): The C++ instance
> (N3Gtk8IconViewE) does not dynamic_cast to the interface."
> 
> 
> On 11/17/2009 10:47 PM, Todor Todorov wrote:
> > Hello list,
> >
> > I encountered the following problem: Under Gtk+ it is possible to have a
> > GktIconView and cast it to a GtkCellLayout via the GTK_CELL_LAYOUT(obj)
> > macro. Then I could add a custom cell renderer and set attributes to it.
> >
> > Now I have implemented my cell renderer in C++/Gtkmm and would like to
> > add it to my Gtk::IconView. And since the class does not provide a
> > pack_start() functionality like TreeView, I would have to go and find my
> > own way to do it...
> >
> > The first problem is that the IconView class does not inherit (in the
> > traditional C++ way) from Gtk::CellLayout. Second, the
> > reinterpret_cast<> did not work either. There is no function in the
> > Gtk::IconView API that lets me convert to a CellLayout, or in the
> > Gtk::CellLayout API to create it from an IconView... Third, I tried to
> > do something like
> >
> > Gtk::CellLayout *cl = Glib::wrap( GTK_CELL_LAYOUT( my_icon_view.gobj() ) );
> > cl->pack_start( renderer, false );
> > cl->add_attribute( renderer->property_blah(), columns.blah );
> > ....
> >
> > While it compiles, the application crashed with a reinterpret_cast
> > failure reported. The only thing that worked so far was to take my Gtk+
> > implementation of the renderer, add it to my project and create a
> > GtkIconView, cast it to GTK_CELL_LAYOUT, add the renderer with
> > properties, and at the end wrap it into a Gtk::IconView and work from
> > there as it were pure Gtkmm.
> >
> > I wonder though, is this the best way? I would like to not handle Gtk+
> > objects directly in my code. Can anyone make a suggestion as to how to
> > add a custom cell renderer to a Gtk::IconView in a "best practice"
> > approach? Your help and time are greatly appreciated.

The problem is that Gtk::IconView does not implement the Gtk::CellLayout
interface because the change was done in Gtk+ at a time when gtkmm could
not break ABI (I think searching on the list will provide more info).
For now you're probably doing it the right way until the change can be
made to gtkmm.

-- 
José





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]