]> Dogcows Code - chaz/tint2/blob - src/tint2conf/theme_view.c
some changed in tint2conf theme switcher. not yet ready.
[chaz/tint2] / src / tint2conf / theme_view.c
1
2 #include "theme_view.h"
3
4
5 enum { PROP_PERCENTAGE = 1, PROP_THEME, PROP_SNAPSHOT, };
6
7 static gpointer parent_class = NULL;
8
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);
14
15
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);
19
20
21
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()
25 {
26 static GType type = 0;
27
28 if (type)
29 return type;
30
31 if (1) {
32 static const GTypeInfo cell_info =
33 {
34 sizeof (CustomListClass),
35 NULL,
36 NULL,
37 (GClassInitFunc)custom_list_class_init,
38 NULL,
39 NULL,
40 sizeof (CustomList),
41 0,
42 (GInstanceInitFunc)custom_list_init,
43 };
44
45 // Derive from GtkCellRenderer
46 type = g_type_register_static(GTK_TYPE_CELL_RENDERER, "CustomList", &cell_info, 0);
47 }
48
49 return type;
50 }
51
52
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)
58 {
59 GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS(klass);
60 GObjectClass *object_class = G_OBJECT_CLASS(klass);
61
62 printf("custom_list_class_init : deb\n");
63 parent_class = g_type_class_peek_parent (klass);
64
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;
70
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));
75 }
76
77
78 // CustomList renderer initialisation
79 static void custom_list_init(CustomList *custom_list)
80 {
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;
86 }
87
88
89 static void custom_list_finalize(GObject *object)
90 {
91 /*
92 CustomList *cellrendererprogress = CUSTOM_LIST(object);
93 */
94
95 printf("custom_list_finalize\n");
96 // Free any dynamically allocated resources here
97
98 (* G_OBJECT_CLASS (parent_class)->finalize) (object);
99 }
100
101
102 static void custom_list_set_property(GObject *object, guint param_id, const GValue *value, GParamSpec *pspec)
103 {
104 CustomList *custom_list = CUSTOM_LIST(object);
105
106 switch (param_id) {
107 case PROP_PERCENTAGE:
108 printf("custom_list_set_property : PROP_PERCENTAGE\n");
109 custom_list->progress = g_value_get_double(value);
110 break;
111
112 case PROP_THEME:
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));
116 break;
117
118 case PROP_SNAPSHOT:
119 printf("custom_list_set_property : PROP_SNAPSHOT\n");
120 custom_list->nameSnapshot = g_strdup(g_value_get_string(value));
121 break;
122
123 default:
124 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
125 break;
126 }
127 }
128
129
130 static void custom_list_get_property(GObject *object, guint param_id, GValue *value, GParamSpec *psec)
131 {
132 CustomList *custom_list = CUSTOM_LIST(object);
133
134 switch (param_id) {
135 case PROP_PERCENTAGE:
136 printf("custom_list_get_property : PROP_PERCENTAGE\n");
137 g_value_set_double(value, custom_list->progress);
138 break;
139
140 case PROP_THEME:
141 printf("custom_list_get_property : PROP_THEME\n");
142 g_value_set_string(value, g_strdup(custom_list->nameTheme));
143 break;
144
145 case PROP_SNAPSHOT:
146 printf("custom_list_get_property : PROP_SNAPSHOT\n");
147 g_value_set_string(value, g_strdup(custom_list->nameSnapshot));
148 break;
149 //g_value_set_object (value, (GObject *)priv->image);
150
151 default:
152 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, psec);
153 break;
154 }
155 }
156
157
158 GtkCellRenderer *custom_list_new()
159 {
160 return g_object_new(CUSTOM_LIST_TYPE, NULL);
161 }
162
163
164 /***************************************************************************
165 *
166 * custom_cell_renderer_progress_get_size: crucial - calculate the size
167 * of our cell, taking into account
168 * padding and alignment properties
169 * of parent.
170 *
171 ***************************************************************************/
172
173 #define FIXED_WIDTH 100
174 #define FIXED_HEIGHT 20
175
176 static void custom_list_get_size(GtkCellRenderer *cell, GtkWidget *widget, GdkRectangle *cell_area, gint *x_offset, gint *y_offset, gint *width, gint *height)
177 {
178 gint calc_width;
179 gint calc_height;
180
181 calc_width = (gint) cell->xpad * 2 + FIXED_WIDTH;
182 calc_height = (gint) cell->ypad * 2 + FIXED_HEIGHT;
183
184 if (width)
185 *width = calc_width;
186
187 if (height)
188 *height = calc_height;
189
190 if (cell_area) {
191 if (x_offset) {
192 *x_offset = cell->xalign * (cell_area->width - calc_width);
193 *x_offset = MAX (*x_offset, 0);
194 }
195
196 if (y_offset) {
197 *y_offset = cell->yalign * (cell_area->height - calc_height);
198 *y_offset = MAX (*y_offset, 0);
199 }
200 }
201 }
202
203
204 /***************************************************************************
205 *
206 * custom_cell_renderer_progress_render: crucial - do the rendering.
207 *
208 ***************************************************************************/
209
210 static void custom_list_render(GtkCellRenderer *cell, GdkWindow *window, GtkWidget *widget, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, guint flags)
211 {
212 CustomList *custom_list = CUSTOM_LIST(cell);
213 GtkStateType state;
214 gint width, height;
215 gint x_offset, y_offset;
216
217 //printf("custom_list_render\n");
218 custom_list_get_size (cell, widget, cell_area, &x_offset, &y_offset, &width, &height);
219
220 if (GTK_WIDGET_HAS_FOCUS (widget))
221 state = GTK_STATE_ACTIVE;
222 else
223 state = GTK_STATE_NORMAL;
224
225 width -= cell->xpad*2;
226 height -= cell->ypad*2;
227
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);
229
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);
231 }
232
233
234
This page took 0.044231 seconds and 5 git commands to generate.