OSDN Git Service

MacGui: Remove Target Size as a rate control option as it doesn't really work correct...
[handbrake-jp/handbrake-jp-git.git] / gtk / src / renderer_button.c
1 #include <gtk/gtkmarshal.h>
2 #include "renderer_button.h"
3
4 /* Some boring function declarations: GObject type system stuff */
5 static void     custom_cell_renderer_button_init       (CustomCellRendererButton      *cellprogress);
6 static void     custom_cell_renderer_button_class_init (CustomCellRendererButtonClass *klass);
7 static void     custom_cell_renderer_button_get_property  (GObject                    *object,
8                                                              guint                       param_id,
9                                                              GValue                     *value,
10                                                              GParamSpec                 *pspec);
11 static void     custom_cell_renderer_button_set_property  (GObject                    *object,
12                                                              guint                       param_id,
13                                                              const GValue               *value,
14                                                              GParamSpec                 *pspec);
15 static void     custom_cell_renderer_button_finalize (GObject *gobject);
16
17 // My customized part that adds "clicked" signal
18 static gint
19 custom_cell_renderer_button_activate (GtkCellRenderer      *cell,
20                                    GdkEvent             *event,
21                                    GtkWidget            *widget,
22                                    const gchar          *path,
23                                    GdkRectangle         *background_area,
24                                    GdkRectangle         *cell_area,
25                                    GtkCellRendererState  flags);
26
27 enum {
28   CLICKED,
29   LAST_SIGNAL
30 };
31
32 static guint button_cell_signals[LAST_SIGNAL] = { 0 };
33
34 static   gpointer parent_class;
35
36 /***************************************************************************
37  *
38  *  custom_cell_renderer_button_get_type: here we register our type with
39  *                                        the GObject type system if we
40  *                                        haven't done so yet. Everything
41  *                                        else is done in the callbacks.
42  *
43  ***************************************************************************/
44 GType
45 custom_cell_renderer_button_get_type (void)
46 {
47         static GType cell_button_type = 0;
48
49         if (cell_button_type == 0)
50         {
51                 static const GTypeInfo cell_button_info =
52                 {
53                         sizeof (CustomCellRendererButtonClass),
54                         NULL,                                                     /* base_init */
55                         NULL,                                                     /* base_finalize */
56                         (GClassInitFunc) custom_cell_renderer_button_class_init,
57                         NULL,                                                     /* class_finalize */
58                         NULL,                                                     /* class_data */
59                         sizeof (CustomCellRendererButton),
60                         0,                                                        /* n_preallocs */
61                         (GInstanceInitFunc) custom_cell_renderer_button_init,
62                 };
63
64                 /* Derive from GtkCellRendererPixbuf */
65                 cell_button_type = g_type_register_static (GTK_TYPE_CELL_RENDERER_PIXBUF,
66                                                                                                          "CustomCellRendererButton",
67                                                                                                           &cell_button_info,
68                                                                                                           0);
69         }
70
71         return cell_button_type;
72 }
73
74 /***************************************************************************
75  *
76  *  custom_cell_renderer_button_init: set some default properties of the
77  *                                    parent (GtkCellRendererPixbuf).
78  *
79  ***************************************************************************/
80 static void
81 custom_cell_renderer_button_init (CustomCellRendererButton *cellbutton)
82 {
83         GTK_CELL_RENDERER(cellbutton)->mode = GTK_CELL_RENDERER_MODE_ACTIVATABLE;
84         GTK_CELL_RENDERER(cellbutton)->xpad = 2;
85         GTK_CELL_RENDERER(cellbutton)->ypad = 2;
86 }
87
88 /***************************************************************************
89  *
90  *  custom_cell_renderer_button_class_init:
91  *
92  *  set up our own get_property and set_property functions, and
93  *  override the parent's functions that we need to implement.
94  *  If you want cells that can be activated on their own (ie. not
95  *  just the whole row selected) or cells that are editable, you
96  *  will need to override 'activate' and 'start_editing' as well.
97  *
98  ***************************************************************************/
99 static void
100 custom_cell_renderer_button_class_init (CustomCellRendererButtonClass *klass)
101 {
102         GtkCellRendererClass *cell_class   = GTK_CELL_RENDERER_CLASS(klass);
103         GObjectClass         *object_class = G_OBJECT_CLASS(klass);
104
105         parent_class           = g_type_class_peek_parent (klass);
106         object_class->finalize = custom_cell_renderer_button_finalize;
107
108         /* Hook up functions to set and get our
109          *   custom cell renderer properties */
110         object_class->get_property = custom_cell_renderer_button_get_property;
111         object_class->set_property = custom_cell_renderer_button_set_property;
112
113         // Override activate
114         cell_class->activate = custom_cell_renderer_button_activate;
115
116         button_cell_signals[CLICKED] =
117                 g_signal_new (g_intern_static_string ("clicked"),
118                           G_OBJECT_CLASS_TYPE (object_class),
119                           G_SIGNAL_RUN_LAST,
120                           G_STRUCT_OFFSET (CustomCellRendererButtonClass, clicked),
121                           NULL, NULL,
122                           gtk_marshal_VOID__STRING,
123                           G_TYPE_NONE, 1,
124                           G_TYPE_STRING);
125 }
126
127 /***************************************************************************
128  *
129  *  custom_cell_renderer_button_finalize: free any resources here
130  *
131  ***************************************************************************/
132 static void
133 custom_cell_renderer_button_finalize (GObject *object)
134 {
135         /*
136         If you need to do anyting with the renderer button ...
137         CustomCellRendererProgress *cellrendererbutton = CUSTOM_CELL_RENDERER_BUTTON(object);
138         */
139
140         /* Free any dynamically allocated resources here */
141
142         (* G_OBJECT_CLASS (parent_class)->finalize) (object);
143 }
144
145 /***************************************************************************
146  *
147  *  custom_cell_renderer_button_get_property: as it says
148  *
149  ***************************************************************************/
150 static void
151 custom_cell_renderer_button_get_property (GObject    *object,
152                                           guint       param_id,
153                                           GValue     *value,
154                                           GParamSpec *psec)
155 {
156         //CustomCellRendererButton  *cellbutton = CUSTOM_CELL_RENDERER_BUTTON(object);
157
158         switch (param_id)
159         {
160                 default:
161                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, psec);
162                         break;
163         }
164 }
165
166 /***************************************************************************
167  *
168  *  custom_cell_renderer_button_set_property: as it says
169  *
170  ***************************************************************************/
171 static void
172 custom_cell_renderer_button_set_property (GObject      *object,
173                                           guint         param_id,
174                                           const GValue *value,
175                                           GParamSpec   *pspec)
176 {
177         //CustomCellRendererButton *cellbutton = CUSTOM_CELL_RENDERER_BUTTON(object);
178
179         switch (param_id)
180         {
181                 default:
182                         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
183                         break;
184         }
185 }
186
187 /***************************************************************************
188  *
189  *  custom_cell_renderer_button_new: return a new cell renderer instance
190  *
191  ***************************************************************************/
192 GtkCellRenderer *
193 custom_cell_renderer_button_new (void)
194 {
195         return g_object_new(CUSTOM_TYPE_CELL_RENDERER_BUTTON, NULL);
196 }
197
198 static gint
199 custom_cell_renderer_button_activate (GtkCellRenderer      *cell,
200                                    GdkEvent             *event,
201                                    GtkWidget            *widget,
202                                    const gchar          *path,
203                                    GdkRectangle         *background_area,
204                                    GdkRectangle         *cell_area,
205                                    GtkCellRendererState  flags)
206 {
207         CustomCellRendererButton *cellbutton;
208   
209         g_debug("custom_cell_renderer_button_activate ()\n");
210         cellbutton = CUSTOM_CELL_RENDERER_BUTTON (cell);
211         g_signal_emit (cell, button_cell_signals[CLICKED], 0, path);
212         return TRUE;
213 }