Re: How to add a custom cell renderer to a Gtk::IconView
- From: Todor Todorov <ttodorov gmx net>
- To: José Alburquerque <jaalburquerque cox net>
- Cc: gtkmm-list gnome org
- Subject: Re: How to add a custom cell renderer to a Gtk::IconView
- Date: Fri, 20 Nov 2009 23:49:09 -0500
Thanks for the reply. The only thing I don't know how to do is how to
adapt the C/gtk+ renderer to the gtkmm/sigc signal-slot mechanism. My
custom renderer has a vfunc declared in the class as:
void ( *toggled )( GtkCellRendererThumb* renderer, gchar* path, gpointer
data );
I obviously need it in order to tell the model when a thumbnail in my
icon view has been permanently selected via its checkbox. I tried the
following:
...
Gtk::IconView *browser = 0;
builder->get_widget( "browser", browser );
{
GtkIconView *view = browser->gobj();
GtkCellRenderer *cell = gtk_cell_renderer_thumb_new();
gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( view ), cell, FALSE );
g_object_set( cell, "thumb-checkable", TRUE, "xpad", 2, "ypad",
2, NULL );
gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( view ), cell,
"thumb-name", 0, "thumb-date", 1,
"thumb-image", 2,
"thumb-checked", 3,
"thumb-duplicate", 4, NULL );
g_signal_connect( G_OBJECT( cell ), "toggled", G_CALLBACK(
&MainWindow::on_thumbnail_checked ), NULL );
}
browser->set_model( thumblist );
...
The callback is a member function declared as
Everything works up to the call of
On 11/20/2009 12:32 AM, Jos Alburquerque wrote:
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.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]