Hello,
I wanted to study the GtkCellRendererCombo so I added it directly to the
treeview (as column).
The combobox is initially hidden, only the "text" value is shown.
The combo becomes visible after user clicks or double-clicks the column in
the row.

Unfortunately the click event does not work (or pass through) when the
GtkCellRendererCombo is baked inside a custom-renderer class. Therefore it
simply shows the "text" value, the combo-list itself is not accessible or
visible.

This might explain why GTK3 has NO renderer for very common type of
widgets, like GtkButton.
There is no GtkCellRendererButton class because it cannot handle the events.

I may need to use the low-level painting functions directly, like
gtk_paint_arrow(...)
gtk_paint_shadow(...)
gtk_paint_box(...)
And somehow calculate the co-ordinates for click-events.

Ref: http://developer.gnome.org/gtk3/3.4/GtkStyle.html

All comments are welcome.
// Osmo Antero

/*
Adding GtkCellRendererCombo directly (as column) to the treeview, just to
study its behaviour.

GtkTreeStore *store = gtk_tree_store_new(NUM_COLS,
                               G_TYPE_INT,
                               G_TYPE_POINTER,
                               G_TYPE_STRING); // <-- combo "text" field
...

// Combo cell renderer (directly as column)
renderer = gtk_cell_renderer_combo_new();

GtkTreeIter iter;
GtkListStore *combo_store = gtk_list_store_new (1, G_TYPE_STRING);
gtk_list_store_append(combo_store, &iter);
gtk_list_store_set(combo_store, &iter, 0, "First Item", -1);
gtk_list_store_append(combo_store, &iter);
gtk_list_store_set(combo_store, &iter, 0, "Second Item", -1);

g_object_set (renderer, "editable", FALSE,
                        "has-entry", TRUE,
                        "model", combo_store,
                        "text-column", 0,
                        NULL);

col = gtk_tree_view_column_new();
gtk_tree_view_column_pack_start (col, renderer, TRUE);
gtk_tree_view_column_add_attribute(col, renderer, "text", COL_2);
gtk_tree_view_column_set_title (col, "Combo");
gtk_tree_view_append_column(GTK_TREE_VIEW(tv),col);
*/


On Tue, Jun 5, 2012 at 8:38 PM, Osmo Antero <osm...@gmail.com> wrote:

> Hello,
> I want to create my own cell-renderer for a treeview widget.
> This custom cell will contain a text string and a combobox with some
> values.
> So my custom cell (row) contains both GtkCellRendererText and
> GtkCellRendererCombo widgets.
>
> The cell renderer works well that it displays the text string, but the
> combobox is *invisible*.
>
> In cell-renderer.c, I carefully get the size of the combobox:
>     gtk_cell_renderer_get_preferred_size(p->combo_renderer, widget, NULL,
> &size);
>     combo_area.width = size.width;
>     combo_area.height = size.height;
>
> And then render it to cell with:
>     combo_area.x = title_area.x + title_area.width + GUI_PAD;
>     combo_area.y = fill_area.y + (fill_area.height - combo_area.height )/2;
>     gtk_cell_renderer_render(p->combo_renderer, window, widget,
> background_area, &combo_area, flags);
>
> See the render_row(...) function in "cell-renderer.c" file.
> But the p->combo_renderer (of type GtkCellRendererCombo) will not show up.
>
> The treeview row should display:
>  "Node 1-0 text  [Combobox with values]"
>  "Node 1-1 text [Combobox with values]"
>  "Node 1-2 text [Combobox with values]"
> ...
> What could be wrong with my code?
>
> Here is a complete example of this:
> http://www.futuredesktop.org/tmp/Test6.tar.gz
>
> Use the "m.sh" script to compile it:
> $ ./m.sh
>
> Then run:
> $ ./main
>
> You should see this:
> http://bildr.no/view/1197967
>


> Ref: http://developer.gnome.org/gtk3/stable/GtkCellRendererCombo.html
> GtkCellRendererCombo
>
> Thanks for all comments.
>
> Kindly
> Osmo Antero
>
>
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to