/**************************************************************** Render worklist cell *****************************************************************/ static void cell_render_func(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *model, GtkTreeIter *it, gpointer data) { gint cid; struct universal target; gtk_tree_model_get(model, it, 0, &cid, -1); target = cid_production(cid); if (GTK_IS_CELL_RENDERER_PIXBUF(rend)) { GdkPixbuf *pix; struct sprite *sprite; if (VUT_UTYPE == target.kind) { sprite = sprite_scale(get_unittype_sprite(tileset, target.value.utype, DIR8_SOUTH, TRUE), max_unit_width, max_unit_height); } else { sprite = get_building_sprite(tileset, target.value.building); } pix = sprite_get_pixbuf(sprite); g_object_set(rend, "pixbuf", pix, NULL); g_object_unref(G_OBJECT(pix)); if (VUT_UTYPE == target.kind) { free_sprite(sprite); } } else { struct city **pcity = data; gint column; char *row[4]; char buf[4][64]; guint i; gboolean useless; for (i = 0; i < ARRAY_SIZE(row); i++) { row[i] = buf[i]; } column = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(rend), "column")); get_city_dialog_production_row(row, sizeof(buf[0]), target, *pcity); g_object_set(rend, "text", row[column], NULL); if (NULL != *pcity && VUT_IMPROVEMENT == target.kind) { useless = is_improvement_redundant(*pcity, target.value.building); /* Mark building redundant if we are really certain that there is * no use for it. */ g_object_set(rend, "strikethrough", useless, NULL); } else { g_object_set(rend, "strikethrough", FALSE, NULL); } } }
static gboolean get_pixbuf_foreach (GtkCellRenderer *renderer, const GdkRectangle *cell_area, const GdkRectangle *cell_background, GetPixbufBoxData *data) { if (GTK_IS_CELL_RENDERER_PIXBUF (renderer)) { data->box = *cell_area; data->pixbuf_found = TRUE; } return (data->pixbuf_found != FALSE); }
static gboolean clicked_icon (GtkTreeView *tv, gint x, gint y, GtkTreePath **path) { GtkTreeViewColumn *col; gint cell_x, cell_y; gint cell_pos, cell_width; GList *cells, *l; gint depth; gint level_indentation; gint expander_size; gint indent; if (gtk_tree_view_get_path_at_pos (tv, x, y, path, &col, &cell_x, &cell_y)) { cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (col)); #if 1 /* ugly workaround to fix the problem: * manually calculate the indent for the row */ depth = gtk_tree_path_get_depth (*path); level_indentation = gtk_tree_view_get_level_indentation (tv); gtk_widget_style_get (GTK_WIDGET (tv), "expander-size", &expander_size, NULL); expander_size += 4; indent = (depth - 1) * level_indentation + depth * expander_size; #else indent = 0; #endif for (l = cells; l; l = l->next) { gtk_tree_view_column_cell_get_position (col, l->data, &cell_pos, &cell_width); if (cell_pos + indent <= cell_x && cell_x <= cell_pos + indent + cell_width) { g_print ("clicked in %s\n", g_type_name_from_instance (l->data)); if (GTK_IS_CELL_RENDERER_PIXBUF (l->data)) { g_list_free (cells); return TRUE; } } } g_list_free (cells); } return FALSE; }