[gnome-video-arcade] Fix Favorite column activations.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-video-arcade] Fix Favorite column activations.
- Date: Sat, 26 Mar 2011 22:46:18 +0000 (UTC)
commit 66b266d7ad8015446586a9e370c352ac53107323
Author: Matthew Barnes <mbarnes redhat com>
Date: Sat Mar 26 18:38:33 2011 -0400
Fix Favorite column activations.
In GTK3, insensitive cells no longer respond to activations, so I had to
work around it by overriding the render() method and temporarily setting
the cell's sensitivity before chaining up, then restoring the old value.
docs/reference/gnome-video-arcade-sections.txt | 3 +
docs/reference/tmpl/gva-cell-renderer-pixbuf.sgml | 23 ++++
src/gva-cell-renderer-pixbuf.c | 140 ++++++++++++++++++++-
src/gva-cell-renderer-pixbuf.h | 9 ++-
src/gva-columns.c | 2 +-
5 files changed, 170 insertions(+), 7 deletions(-)
---
diff --git a/docs/reference/gnome-video-arcade-sections.txt b/docs/reference/gnome-video-arcade-sections.txt
index 0dc9b10..bee5c02 100644
--- a/docs/reference/gnome-video-arcade-sections.txt
+++ b/docs/reference/gnome-video-arcade-sections.txt
@@ -19,6 +19,8 @@ gva_mame_version_lookup
<TITLE>GvaCellRendererPixbuf</TITLE>
GvaCellRendererPixbuf
gva_cell_renderer_pixbuf_new
+gva_cell_renderer_pixbuf_get_active
+gva_cell_renderer_pixbuf_set_active
<SUBSECTION Standard>
GVA_CELL_RENDERER_PIXBUF
GVA_IS_CELL_RENDERER_PIXBUF
@@ -28,6 +30,7 @@ GVA_IS_CELL_RENDERER_PIXBUF_CLASS
GVA_CELL_RENDERER_PIXBUF_GET_CLASS
GvaCellRendererPixbufClass
<SUBSECTION Private>
+GvaCellRendererPixbufPrivate
gva_cell_renderer_pixbuf_get_type
</SECTION>
diff --git a/docs/reference/tmpl/gva-cell-renderer-pixbuf.sgml b/docs/reference/tmpl/gva-cell-renderer-pixbuf.sgml
index a761f9f..0e6aa70 100644
--- a/docs/reference/tmpl/gva-cell-renderer-pixbuf.sgml
+++ b/docs/reference/tmpl/gva-cell-renderer-pixbuf.sgml
@@ -34,6 +34,11 @@
@gvacellrendererpixbuf: the object which received the signal.
@arg1:
+<!-- ##### ARG GvaCellRendererPixbuf:active ##### -->
+<para>
+
+</para>
+
<!-- ##### FUNCTION gva_cell_renderer_pixbuf_new ##### -->
<para>
@@ -43,3 +48,21 @@
@Returns:
+<!-- ##### FUNCTION gva_cell_renderer_pixbuf_get_active ##### -->
+<para>
+
+</para>
+
+ cell:
+ Returns:
+
+
+<!-- ##### FUNCTION gva_cell_renderer_pixbuf_set_active ##### -->
+<para>
+
+</para>
+
+ cell:
+ active:
+
+
diff --git a/src/gva-cell-renderer-pixbuf.c b/src/gva-cell-renderer-pixbuf.c
index e6fd65d..a6221f3 100644
--- a/src/gva-cell-renderer-pixbuf.c
+++ b/src/gva-cell-renderer-pixbuf.c
@@ -18,7 +18,23 @@
#include "gva-cell-renderer-pixbuf.h"
-enum {
+#define GVA_CELL_RENDERER_PIXBUF_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), GVA_TYPE_CELL_RENDERER_PIXBUF, GvaCellRendererPixbufPrivate))
+
+struct _GvaCellRendererPixbufPrivate
+{
+ gboolean active;
+};
+
+enum
+{
+ PROP_0,
+ PROP_ACTIVE
+};
+
+enum
+{
CLICKED,
LAST_SIGNAL
};
@@ -26,6 +42,42 @@ enum {
static gpointer parent_class = NULL;
static guint signals[LAST_SIGNAL] = { 0 };
+static void
+cell_renderer_pixbuf_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id)
+ {
+ case PROP_ACTIVE:
+ gva_cell_renderer_pixbuf_set_active (
+ GVA_CELL_RENDERER_PIXBUF (object),
+ g_value_get_boolean (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+cell_renderer_pixbuf_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id)
+ {
+ case PROP_ACTIVE:
+ g_value_set_boolean (
+ value, gva_cell_renderer_pixbuf_get_active (
+ GVA_CELL_RENDERER_PIXBUF (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
static gboolean
cell_renderer_pixbuf_activate (GtkCellRenderer *cell,
GdkEvent *event,
@@ -46,14 +98,59 @@ cell_renderer_pixbuf_activate (GtkCellRenderer *cell,
}
static void
+cell_renderer_pixbuf_render (GtkCellRenderer *cell,
+ cairo_t *cr,
+ GtkWidget *widget,
+ const GdkRectangle *background_area,
+ const GdkRectangle *cell_area,
+ GtkCellRendererState flags)
+{
+ GvaCellRendererPixbufPrivate *priv;
+ gboolean sensitive;
+
+ priv = GVA_CELL_RENDERER_PIXBUF_GET_PRIVATE (cell);
+
+ sensitive = gtk_cell_renderer_get_sensitive (cell);
+ gtk_cell_renderer_set_sensitive (cell, priv->active);
+
+ /* Chain up to parent's render() method. */
+ GTK_CELL_RENDERER_CLASS (parent_class)->render (
+ cell, cr, widget, background_area, cell_area, flags);
+
+ gtk_cell_renderer_set_sensitive (cell, sensitive);
+}
+
+static void
cell_renderer_pixbuf_class_init (GvaCellRendererPixbufClass *class)
{
+ GObjectClass *object_class;
GtkCellRendererClass *cell_renderer_class;
parent_class = g_type_class_peek_parent (class);
+ g_type_class_add_private (class, sizeof (GvaCellRendererPixbufPrivate));
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = cell_renderer_pixbuf_set_property;
+ object_class->get_property = cell_renderer_pixbuf_get_property;
cell_renderer_class = GTK_CELL_RENDERER_CLASS (class);
cell_renderer_class->activate = cell_renderer_pixbuf_activate;
+ cell_renderer_class->render = cell_renderer_pixbuf_render;
+
+ /**
+ * GvaCellRendererPixbuf:active
+ *
+ * Whether to draw the pixbuf as active.
+ **/
+ g_object_class_install_property (
+ object_class,
+ PROP_ACTIVE,
+ g_param_spec_boolean (
+ "active",
+ NULL,
+ NULL,
+ FALSE,
+ G_PARAM_READWRITE));
/**
* GvaCellRendererPixbuf::clicked:
@@ -75,12 +172,11 @@ cell_renderer_pixbuf_class_init (GvaCellRendererPixbufClass *class)
}
static void
-cell_renderer_pixbuf_init (GvaCellRendererPixbuf *cell_renderer_pixbuf)
+cell_renderer_pixbuf_init (GvaCellRendererPixbuf *cell)
{
- GtkCellRendererMode mode;
+ cell->priv = GVA_CELL_RENDERER_PIXBUF_GET_PRIVATE (cell);
- mode = GTK_CELL_RENDERER_MODE_ACTIVATABLE;
- g_object_set (cell_renderer_pixbuf, "mode", mode, NULL);
+ g_object_set (cell, "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL);
}
GType
@@ -124,3 +220,37 @@ gva_cell_renderer_pixbuf_new (void)
{
return g_object_new (GVA_TYPE_CELL_RENDERER_PIXBUF, NULL);
}
+
+/**
+ * gva_cell_renderer_pixbuf_get_active:
+ * @cell: a #GvaCellRendererPixbuf
+ *
+ * Returns whether @cell should be drawn as active.
+ *
+ * Returns: whether to draw the pixbuf as active
+ **/
+gboolean
+gva_cell_renderer_pixbuf_get_active (GvaCellRendererPixbuf *cell)
+{
+ g_return_val_if_fail (GVA_IS_CELL_RENDERER_PIXBUF (cell), FALSE);
+
+ return cell->priv->active;
+}
+
+/**
+ * gva_cell_renderer_pixbuf_set_active:
+ * @cell: a #GvaCellRendererPixbuf
+ * @active: whether to draw the pixbuf as active
+ *
+ * Sets whether @cell should be drawn as active.
+ **/
+void
+gva_cell_renderer_pixbuf_set_active (GvaCellRendererPixbuf *cell,
+ gboolean active)
+{
+ g_return_if_fail (GVA_IS_CELL_RENDERER_PIXBUF (cell));
+
+ cell->priv->active = active;
+
+ g_object_notify (G_OBJECT (cell), "active");
+}
diff --git a/src/gva-cell-renderer-pixbuf.h b/src/gva-cell-renderer-pixbuf.h
index 6b043b7..73ce9c3 100644
--- a/src/gva-cell-renderer-pixbuf.h
+++ b/src/gva-cell-renderer-pixbuf.h
@@ -53,6 +53,7 @@ G_BEGIN_DECLS
typedef struct _GvaCellRendererPixbuf GvaCellRendererPixbuf;
typedef struct _GvaCellRendererPixbufClass GvaCellRendererPixbufClass;
+typedef struct _GvaCellRendererPixbufPrivate GvaCellRendererPixbufPrivate;
/**
* GvaCellRendererPixbuf:
@@ -63,18 +64,24 @@ typedef struct _GvaCellRendererPixbufClass GvaCellRendererPixbufClass;
struct _GvaCellRendererPixbuf
{
GtkCellRendererPixbuf parent;
+ GvaCellRendererPixbufPrivate *priv;
};
struct _GvaCellRendererPixbufClass
{
GtkCellRendererPixbufClass parent_class;
- void (*clicked) (GvaCellRendererPixbuf *cell_renderer_pixbuf,
+ void (*clicked) (GvaCellRendererPixbuf *cell,
GtkTreePath *tree_path);
};
GType gva_cell_renderer_pixbuf_get_type (void);
GtkCellRenderer * gva_cell_renderer_pixbuf_new (void);
+gboolean gva_cell_renderer_pixbuf_get_active
+ (GvaCellRendererPixbuf *cell);
+void gva_cell_renderer_pixbuf_set_active
+ (GvaCellRendererPixbuf *cell,
+ gboolean active);
G_END_DECLS
diff --git a/src/gva-columns.c b/src/gva-columns.c
index 944bd95..741b25f 100644
--- a/src/gva-columns.c
+++ b/src/gva-columns.c
@@ -486,7 +486,7 @@ columns_factory_favorite (GvaGameStoreColumn column_id)
gtk_tree_view_column_pack_start (column, renderer, TRUE);
gtk_tree_view_column_add_attribute (
- column, renderer, "sensitive", column_id);
+ column, renderer, "active", column_id);
g_signal_connect (
renderer, "clicked",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]