[libgd] icon-view: add support for cairo surfaces in the model
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgd] icon-view: add support for cairo surfaces in the model
- Date: Mon, 5 Aug 2013 12:54:59 +0000 (UTC)
commit 90e09d31572f5de136388493b86f481b4d884493
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon Aug 5 14:42:12 2013 +0200
icon-view: add support for cairo surfaces in the model
This is needed to support HiDpi icons.
libgd/gd-main-icon-view.c | 54 +++++++++++++++++++++++++++++++++++----------
1 files changed, 42 insertions(+), 12 deletions(-)
---
diff --git a/libgd/gd-main-icon-view.c b/libgd/gd-main-icon-view.c
index 2048d31..90443fe 100644
--- a/libgd/gd-main-icon-view.c
+++ b/libgd/gd-main-icon-view.c
@@ -26,6 +26,7 @@
#include <math.h>
#include <glib/gi18n.h>
+#include <cairo-gobject.h>
#define VIEW_ITEM_WIDTH 140
#define VIEW_ITEM_WRAP_WIDTH 128
@@ -34,6 +35,7 @@
struct _GdMainIconViewPrivate {
GtkCellRenderer *pixbuf_cell;
+ GtkCellRenderer *text_cell;
gboolean selection_mode;
};
@@ -56,6 +58,40 @@ get_source_row (GdkDragContext *context)
}
static void
+set_attributes_from_model (GdMainIconView *self)
+{
+ GtkTreeModel *model = gtk_icon_view_get_model (GTK_ICON_VIEW (self));
+ GtkCellLayout *layout = GTK_CELL_LAYOUT (self);
+ GType icon_gtype;
+
+ gtk_cell_layout_clear_attributes (layout, self->priv->pixbuf_cell);
+ gtk_cell_layout_clear_attributes (layout, self->priv->text_cell);
+
+ if (!model)
+ return;
+
+ gtk_cell_layout_add_attribute (layout, self->priv->pixbuf_cell,
+ "active", GD_MAIN_COLUMN_SELECTED);
+ gtk_cell_layout_add_attribute (layout, self->priv->pixbuf_cell,
+ "pulse", GD_MAIN_COLUMN_PULSE);
+
+ icon_gtype = gtk_tree_model_get_column_type (model, GD_MAIN_COLUMN_ICON);
+ if (icon_gtype == GDK_TYPE_PIXBUF)
+ gtk_cell_layout_add_attribute (layout, self->priv->pixbuf_cell,
+ "pixbuf", GD_MAIN_COLUMN_ICON);
+ else if (icon_gtype == CAIRO_GOBJECT_TYPE_SURFACE)
+ gtk_cell_layout_add_attribute (layout, self->priv->pixbuf_cell,
+ "surface", GD_MAIN_COLUMN_ICON);
+ else
+ g_assert_not_reached ();
+
+ gtk_cell_layout_add_attribute (layout, self->priv->text_cell,
+ "text", GD_MAIN_COLUMN_PRIMARY_TEXT);
+ gtk_cell_layout_add_attribute (layout, self->priv->text_cell,
+ "line-two", GD_MAIN_COLUMN_SECONDARY_TEXT);
+}
+
+static void
gd_main_icon_view_drag_data_get (GtkWidget *widget,
GdkDragContext *drag_context,
GtkSelectionData *data,
@@ -100,16 +136,9 @@ gd_main_icon_view_constructed (GObject *obj)
"xalign", 0.5,
"yalign", 0.5,
NULL);
-
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self), cell, FALSE);
- gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell,
- "active", GD_MAIN_COLUMN_SELECTED);
- gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell,
- "pixbuf", GD_MAIN_COLUMN_ICON);
- gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell,
- "pulse", GD_MAIN_COLUMN_PULSE);
- cell = gd_two_lines_renderer_new ();
+ self->priv->text_cell = cell = gd_two_lines_renderer_new ();
g_object_set (cell,
"xalign", 0.5,
"alignment", PANGO_ALIGN_CENTER,
@@ -118,10 +147,8 @@ gd_main_icon_view_constructed (GObject *obj)
"text-lines", 3,
NULL);
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self), cell, FALSE);
- gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell,
- "text", GD_MAIN_COLUMN_PRIMARY_TEXT);
- gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self), cell,
- "line-two", GD_MAIN_COLUMN_SECONDARY_TEXT);
+
+ set_attributes_from_model (self);
gtk_icon_view_enable_model_drag_source (GTK_ICON_VIEW (self),
GDK_BUTTON1_MASK,
@@ -334,6 +361,9 @@ static void
gd_main_icon_view_init (GdMainIconView *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GD_TYPE_MAIN_ICON_VIEW, GdMainIconViewPrivate);
+
+ g_signal_connect (self, "notify::model",
+ G_CALLBACK (set_attributes_from_model), NULL);
}
static GtkTreePath *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]