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



On Fri, 2009-11-20 at 23:59 -0500, Todor Todorov wrote: 
> Thanks for the reply. I only recently subscribed to the list and need 
> yet to find a searchable archive online, with somewhat usable 
> interface... Anyway, I really appreciate your time in helping me solve 
> this problem.

>From the main gtkmm page[1], select the Mailing Lists link.  The "List
Archives" section provides links to searchable archives.

[1] http://www.gtkmm.org/index.shtml

> 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 (gtk+ _class) struct 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.

It should be possible to wrap the renderer object in a Gtk::CellRenderer
casting it to a GtkCellRenderer and using Glib::wrap().  Using the
standard Gtk::Renderer signals would then be possible.  On the other
hand, you could also implement your renderer in C++.  There are two good
good examples of how to do that here:

http://git.gnome.org/cgit/gtkmm-documentation/tree/examples/others/cellrenderercustom

> 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
> 
> void on_thumbnail_checked( GtkCellRendererThumb* renderer, gchar* path, 
> gpointer data )
> {
>      std::cout << "test, path is " << path << std::endl;
> }
> 
> Everything works up to the call of the function. It is called once, the 
> first time one of the thumbnails is activated, and it prints out "test, 
> path is".
> Any subsequent click on a thumbnail does not trigger the callback, 
> although the activate function of the renderer itself is called every 
> time - verified thorugh g_print statements, which print out the tree 
> path as well....

Maybe the signal emission implementation in you renderer class is a
little off.  If the callback function is called once then it seems that
the mechanism does work, just not exactly as desired.  The logic may
need a little consideration.  For example, does the logic of the
renderer class dictate that the signal be emitted when the checkbox is
toggled? only selected?  Is the class designed so that the signal is
emitted when the icon is clicked? etc.  It's hard to know for certain
but these are just ideas to possibly help get your own ideas working.

-- 
José




























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