summaryrefslogtreecommitdiffstats
path: root/gtk/src/renderer_button.c
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2008-06-17 15:40:49 +0000
committerjstebbins <[email protected]>2008-06-17 15:40:49 +0000
commit8bbd36bcbe75a53b29f7cc62e5ae9d107f92eddc (patch)
treeaafba8f8091293cc3faac87f0c61460cc6017c39 /gtk/src/renderer_button.c
parent01cf7f40ab14ce0961c5ea0c6e16580284c03945 (diff)
LinGui: Initial import
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1517 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'gtk/src/renderer_button.c')
-rw-r--r--gtk/src/renderer_button.c213
1 files changed, 213 insertions, 0 deletions
diff --git a/gtk/src/renderer_button.c b/gtk/src/renderer_button.c
new file mode 100644
index 000000000..52cb9864d
--- /dev/null
+++ b/gtk/src/renderer_button.c
@@ -0,0 +1,213 @@
+#include <gtk/gtkmarshal.h>
+#include "renderer_button.h"
+
+/* Some boring function declarations: GObject type system stuff */
+static void custom_cell_renderer_button_init (CustomCellRendererButton *cellprogress);
+static void custom_cell_renderer_button_class_init (CustomCellRendererButtonClass *klass);
+static void custom_cell_renderer_button_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void custom_cell_renderer_button_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void custom_cell_renderer_button_finalize (GObject *gobject);
+
+// My customized part that adds "clicked" signal
+static gint
+custom_cell_renderer_button_activate (GtkCellRenderer *cell,
+ GdkEvent *event,
+ GtkWidget *widget,
+ const gchar *path,
+ GdkRectangle *background_area,
+ GdkRectangle *cell_area,
+ GtkCellRendererState flags);
+
+enum {
+ CLICKED,
+ LAST_SIGNAL
+};
+
+static guint button_cell_signals[LAST_SIGNAL] = { 0 };
+
+static gpointer parent_class;
+
+/***************************************************************************
+ *
+ * custom_cell_renderer_button_get_type: here we register our type with
+ * the GObject type system if we
+ * haven't done so yet. Everything
+ * else is done in the callbacks.
+ *
+ ***************************************************************************/
+GType
+custom_cell_renderer_button_get_type (void)
+{
+ static GType cell_button_type = 0;
+
+ if (cell_button_type == 0)
+ {
+ static const GTypeInfo cell_button_info =
+ {
+ sizeof (CustomCellRendererButtonClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc) custom_cell_renderer_button_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (CustomCellRendererButton),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) custom_cell_renderer_button_init,
+ };
+
+ /* Derive from GtkCellRendererPixbuf */
+ cell_button_type = g_type_register_static (GTK_TYPE_CELL_RENDERER_PIXBUF,
+ "CustomCellRendererButton",
+ &cell_button_info,
+ 0);
+ }
+
+ return cell_button_type;
+}
+
+/***************************************************************************
+ *
+ * custom_cell_renderer_button_init: set some default properties of the
+ * parent (GtkCellRendererPixbuf).
+ *
+ ***************************************************************************/
+static void
+custom_cell_renderer_button_init (CustomCellRendererButton *cellbutton)
+{
+ GTK_CELL_RENDERER(cellbutton)->mode = GTK_CELL_RENDERER_MODE_ACTIVATABLE;
+ GTK_CELL_RENDERER(cellbutton)->xpad = 2;
+ GTK_CELL_RENDERER(cellbutton)->ypad = 2;
+}
+
+/***************************************************************************
+ *
+ * custom_cell_renderer_button_class_init:
+ *
+ * set up our own get_property and set_property functions, and
+ * override the parent's functions that we need to implement.
+ * If you want cells that can be activated on their own (ie. not
+ * just the whole row selected) or cells that are editable, you
+ * will need to override 'activate' and 'start_editing' as well.
+ *
+ ***************************************************************************/
+static void
+custom_cell_renderer_button_class_init (CustomCellRendererButtonClass *klass)
+{
+ GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS(klass);
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ parent_class = g_type_class_peek_parent (klass);
+ object_class->finalize = custom_cell_renderer_button_finalize;
+
+ /* Hook up functions to set and get our
+ * custom cell renderer properties */
+ object_class->get_property = custom_cell_renderer_button_get_property;
+ object_class->set_property = custom_cell_renderer_button_set_property;
+
+ // Override activate
+ cell_class->activate = custom_cell_renderer_button_activate;
+
+ button_cell_signals[CLICKED] =
+ g_signal_new (g_intern_static_string ("clicked"),
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (CustomCellRendererButtonClass, clicked),
+ NULL, NULL,
+ gtk_marshal_VOID__STRING,
+ G_TYPE_NONE, 1,
+ G_TYPE_STRING);
+}
+
+/***************************************************************************
+ *
+ * custom_cell_renderer_button_finalize: free any resources here
+ *
+ ***************************************************************************/
+static void
+custom_cell_renderer_button_finalize (GObject *object)
+{
+ /*
+ If you need to do anyting with the renderer button ...
+ CustomCellRendererProgress *cellrendererbutton = CUSTOM_CELL_RENDERER_BUTTON(object);
+ */
+
+ /* Free any dynamically allocated resources here */
+
+ (* G_OBJECT_CLASS (parent_class)->finalize) (object);
+}
+
+/***************************************************************************
+ *
+ * custom_cell_renderer_button_get_property: as it says
+ *
+ ***************************************************************************/
+static void
+custom_cell_renderer_button_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *psec)
+{
+ //CustomCellRendererButton *cellbutton = CUSTOM_CELL_RENDERER_BUTTON(object);
+
+ switch (param_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, psec);
+ break;
+ }
+}
+
+/***************************************************************************
+ *
+ * custom_cell_renderer_button_set_property: as it says
+ *
+ ***************************************************************************/
+static void
+custom_cell_renderer_button_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ //CustomCellRendererButton *cellbutton = CUSTOM_CELL_RENDERER_BUTTON(object);
+
+ switch (param_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
+ break;
+ }
+}
+
+/***************************************************************************
+ *
+ * custom_cell_renderer_button_new: return a new cell renderer instance
+ *
+ ***************************************************************************/
+GtkCellRenderer *
+custom_cell_renderer_button_new (void)
+{
+ return g_object_new(CUSTOM_TYPE_CELL_RENDERER_BUTTON, NULL);
+}
+
+static gint
+custom_cell_renderer_button_activate (GtkCellRenderer *cell,
+ GdkEvent *event,
+ GtkWidget *widget,
+ const gchar *path,
+ GdkRectangle *background_area,
+ GdkRectangle *cell_area,
+ GtkCellRendererState flags)
+{
+ CustomCellRendererButton *cellbutton;
+
+ g_debug("custom_cell_renderer_button_activate ()\n");
+ cellbutton = CUSTOM_CELL_RENDERER_BUTTON (cell);
+ g_signal_emit (cell, button_cell_signals[CLICKED], 0, path);
+ return TRUE;
+}