2 #include "theme_view.h"
5 enum { PROP_PERCENTAGE
= 1, PROP_THEME
, PROP_SNAPSHOT
, };
7 static gpointer parent_class
= NULL
;
9 static void custom_list_init(CustomList
*cellprogress
);
10 static void custom_list_class_init(CustomListClass
*klass
);
11 static void custom_list_get_property(GObject
*object
, guint param_id
, GValue
*value
, GParamSpec
*pspec
);
12 static void custom_list_set_property(GObject
*object
, guint param_id
, const GValue
*value
, GParamSpec
*pspec
);
13 static void custom_list_finalize(GObject
*gobject
);
16 // These functions are the heart of our custom cell renderer
17 static void custom_list_get_size(GtkCellRenderer
*cell
, GtkWidget
*widget
, GdkRectangle
*cell_area
, gint
*x_offset
, gint
*y_offset
, gint
*width
, gint
*height
);
18 static void custom_list_render(GtkCellRenderer
*cell
, GdkWindow
*window
, GtkWidget
*widget
, GdkRectangle
*background_area
, GdkRectangle
*cell_area
, GdkRectangle
*expose_area
, guint flags
);
22 // register our type with the GObject type system if we haven't done so yet.
23 // Everything else is done in the callbacks.
24 GType
custom_list_get_type()
26 static GType type
= 0;
32 static const GTypeInfo cell_info
=
34 sizeof (CustomListClass
),
37 (GClassInitFunc
)custom_list_class_init
,
42 (GInstanceInitFunc
)custom_list_init
,
45 // Derive from GtkCellRenderer
46 type
= g_type_register_static(GTK_TYPE_CELL_RENDERER
, "CustomList", &cell_info
, 0);
53 // klass initialisation
54 // - override the parent's functions that we need to implement.
55 // - declare our property
56 // - If you want cells that are editable, you need to override 'activate' and 'start_editing'.
57 static void custom_list_class_init(CustomListClass
*klass
)
59 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS(klass
);
60 GObjectClass
*object_class
= G_OBJECT_CLASS(klass
);
62 printf("custom_list_class_init : deb\n");
63 parent_class
= g_type_class_peek_parent (klass
);
65 cell_class
->render
= custom_list_render
;
66 cell_class
->get_size
= custom_list_get_size
;
67 object_class
->get_property
= custom_list_get_property
;
68 object_class
->set_property
= custom_list_set_property
;
69 object_class
->finalize
= custom_list_finalize
;
71 // Install our very own properties
72 g_object_class_install_property(object_class
, PROP_PERCENTAGE
, g_param_spec_double("percentage", "Percentage", "The fractional progress to display", 0.0, 1.0, 0.0, G_PARAM_READWRITE
));
73 g_object_class_install_property(object_class
, PROP_THEME
, g_param_spec_string("theme", "Theme", "Theme file name", NULL
, G_PARAM_READWRITE
));
74 g_object_class_install_property(object_class
, PROP_SNAPSHOT
, g_param_spec_string("snapshot", "Snapshot", "Snapshot file name", NULL
, G_PARAM_READWRITE
));
78 // CustomList renderer initialisation
79 static void custom_list_init(CustomList
*custom_list
)
81 printf("custom_list_init : deb\n");
82 // set some default properties of the parent (GtkCellRenderer).
83 GTK_CELL_RENDERER(custom_list
)->mode
= GTK_CELL_RENDERER_MODE_INERT
;
84 GTK_CELL_RENDERER(custom_list
)->xpad
= 2;
85 GTK_CELL_RENDERER(custom_list
)->ypad
= 2;
89 static void custom_list_finalize(GObject
*object
)
92 CustomList *cellrendererprogress = CUSTOM_LIST(object);
95 printf("custom_list_finalize\n");
96 // Free any dynamically allocated resources here
98 (* G_OBJECT_CLASS (parent_class
)->finalize
) (object
);
102 static void custom_list_set_property(GObject
*object
, guint param_id
, const GValue
*value
, GParamSpec
*pspec
)
104 CustomList
*custom_list
= CUSTOM_LIST(object
);
107 case PROP_PERCENTAGE
:
108 printf("custom_list_set_property : PROP_PERCENTAGE\n");
109 custom_list
->progress
= g_value_get_double(value
);
113 printf("custom_list_set_property : PROP_THEME\n");
114 //if (custom_list->nameTheme) g_free(custom_list->nameTheme);
115 custom_list
->nameTheme
= g_strdup(g_value_get_string(value
));
119 printf("custom_list_set_property : PROP_SNAPSHOT\n");
120 custom_list
->nameSnapshot
= g_strdup(g_value_get_string(value
));
124 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
, param_id
, pspec
);
130 static void custom_list_get_property(GObject
*object
, guint param_id
, GValue
*value
, GParamSpec
*psec
)
132 CustomList
*custom_list
= CUSTOM_LIST(object
);
135 case PROP_PERCENTAGE
:
136 printf("custom_list_get_property : PROP_PERCENTAGE\n");
137 g_value_set_double(value
, custom_list
->progress
);
141 printf("custom_list_get_property : PROP_THEME\n");
142 g_value_set_string(value
, g_strdup(custom_list
->nameTheme
));
146 printf("custom_list_get_property : PROP_SNAPSHOT\n");
147 g_value_set_string(value
, g_strdup(custom_list
->nameSnapshot
));
149 //g_value_set_object (value, (GObject *)priv->image);
152 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, param_id
, psec
);
158 GtkCellRenderer
*custom_list_new()
160 return g_object_new(CUSTOM_LIST_TYPE
, NULL
);
164 /***************************************************************************
166 * custom_cell_renderer_progress_get_size: crucial - calculate the size
167 * of our cell, taking into account
168 * padding and alignment properties
171 ***************************************************************************/
173 #define FIXED_WIDTH 100
174 #define FIXED_HEIGHT 20
176 static void custom_list_get_size(GtkCellRenderer
*cell
, GtkWidget
*widget
, GdkRectangle
*cell_area
, gint
*x_offset
, gint
*y_offset
, gint
*width
, gint
*height
)
181 calc_width
= (gint
) cell
->xpad
* 2 + FIXED_WIDTH
;
182 calc_height
= (gint
) cell
->ypad
* 2 + FIXED_HEIGHT
;
188 *height
= calc_height
;
192 *x_offset
= cell
->xalign
* (cell_area
->width
- calc_width
);
193 *x_offset
= MAX (*x_offset
, 0);
197 *y_offset
= cell
->yalign
* (cell_area
->height
- calc_height
);
198 *y_offset
= MAX (*y_offset
, 0);
204 /***************************************************************************
206 * custom_cell_renderer_progress_render: crucial - do the rendering.
208 ***************************************************************************/
210 static void custom_list_render(GtkCellRenderer
*cell
, GdkWindow
*window
, GtkWidget
*widget
, GdkRectangle
*background_area
, GdkRectangle
*cell_area
, GdkRectangle
*expose_area
, guint flags
)
212 CustomList
*custom_list
= CUSTOM_LIST(cell
);
215 gint x_offset
, y_offset
;
217 //printf("custom_list_render\n");
218 custom_list_get_size (cell
, widget
, cell_area
, &x_offset
, &y_offset
, &width
, &height
);
220 if (GTK_WIDGET_HAS_FOCUS (widget
))
221 state
= GTK_STATE_ACTIVE
;
223 state
= GTK_STATE_NORMAL
;
225 width
-= cell
->xpad
*2;
226 height
-= cell
->ypad
*2;
228 gtk_paint_box (widget
->style
, window
, GTK_STATE_NORMAL
, GTK_SHADOW_IN
, NULL
, widget
, "trough", cell_area
->x
+ x_offset
+ cell
->xpad
, cell_area
->y
+ y_offset
+ cell
->ypad
, width
- 1, height
- 1);
230 gtk_paint_box (widget
->style
, window
, state
, GTK_SHADOW_OUT
, NULL
, widget
, "bar", cell_area
->x
+ x_offset
+ cell
->xpad
, cell_area
->y
+ y_offset
+ cell
->ypad
, width
* custom_list
->progress
, height
- 1);