Mercurial > geeqie.yaz
annotate src/cellrenderericon.c @ 882:912726c2f5e3
Fix a segfault occuring when opening some collection files.
Skip all lines not starting with a # when only geometry is required.
author | zas_ |
---|---|
date | Sun, 13 Jul 2008 12:36:18 +0000 |
parents | b54e3fc9cafb |
children | c24a297efbef |
rev | line source |
---|---|
9 | 1 /* cellrenderericon.c, based on: |
2 * | |
3 * gtkcellrendererpixbuf.c | |
4 * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com> | |
5 * | |
6 * This library is free software; you can redistribute it and/or | |
7 * modify it under the terms of the GNU Library General Public | |
8 * License as published by the Free Software Foundation; either | |
9 * version 2 of the License, or (at your option) any later version. | |
10 * | |
11 * This library is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * Library General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU Library General Public | |
17 * License along with this library; if not, write to the | |
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
19 * Boston, MA 02111-1307, USA. | |
20 */ | |
21 | |
22 #include <stdlib.h> | |
23 #include "cellrenderericon.h" | |
24 #include "intl.h" | |
25 | |
26 | |
27 #define FIXED_ICON_SIZE_MAX 512 | |
28 | |
852 | 29 #define TOGGLE_WIDTH 13 |
30 #define TOGGLE_SPACING 18 | |
31 | |
32 | |
9 | 33 static void gqv_cell_renderer_icon_get_property(GObject *object, |
442 | 34 guint param_id, |
35 GValue *value, | |
36 GParamSpec *pspec); | |
9 | 37 static void gqv_cell_renderer_icon_set_property(GObject *object, |
38 guint param_id, | |
39 const GValue *value, | |
40 GParamSpec *pspec); | |
41 static void gqv_cell_renderer_icon_init(GQvCellRendererIcon *celltext); | |
42 static void gqv_cell_renderer_icon_class_init(GQvCellRendererIconClass *class); | |
43 static void gqv_cell_renderer_icon_finalize(GObject *object); | |
44 static void gqv_cell_renderer_icon_get_size(GtkCellRenderer *cell, | |
45 GtkWidget *widget, | |
46 GdkRectangle *rectangle, | |
47 gint *x_offset, | |
48 gint *y_offset, | |
49 gint *width, | |
50 gint *height); | |
51 static void gqv_cell_renderer_icon_render(GtkCellRenderer *cell, | |
52 GdkWindow *window, | |
53 GtkWidget *widget, | |
54 GdkRectangle *background_area, | |
55 GdkRectangle *cell_area, | |
56 GdkRectangle *expose_area, | |
57 GtkCellRendererState flags); | |
58 | |
59 | |
60 enum { | |
61 PROP_ZERO, | |
62 PROP_PIXBUF, | |
63 PROP_TEXT, | |
64 PROP_BACKGROUND_GDK, | |
65 PROP_FOREGROUND_GDK, | |
66 PROP_FOCUSED, | |
67 PROP_FIXED_WIDTH, | |
68 PROP_FIXED_HEIGHT, | |
69 | |
70 PROP_BACKGROUND_SET, | |
71 PROP_FOREGROUND_SET, | |
852 | 72 PROP_SHOW_TEXT, |
73 PROP_SHOW_MARKS, | |
74 PROP_NUM_MARKS, | |
75 PROP_MARKS | |
9 | 76 }; |
77 | |
78 static gpointer parent_class; | |
79 | |
80 GType | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
446
diff
changeset
|
81 gqv_cell_renderer_icon_get_type(void) |
9 | 82 { |
83 static GType cell_icon_type = 0; | |
84 | |
85 if (!cell_icon_type) | |
86 { | |
87 static const GTypeInfo cell_icon_info = | |
88 { | |
691 | 89 sizeof(GQvCellRendererIconClass), /* class_size */ |
9 | 90 NULL, /* base_init */ |
91 NULL, /* base_finalize */ | |
691 | 92 (GClassInitFunc) gqv_cell_renderer_icon_class_init, /* class_init */ |
9 | 93 NULL, /* class_finalize */ |
94 NULL, /* class_data */ | |
691 | 95 sizeof(GQvCellRendererIcon), /* instance_size */ |
9 | 96 0, /* n_preallocs */ |
691 | 97 (GInstanceInitFunc) gqv_cell_renderer_icon_init, /* instance_init */ |
98 NULL, /* value_table */ | |
534 | 99 }; |
9 | 100 |
534 | 101 cell_icon_type = g_type_register_static(GTK_TYPE_CELL_RENDERER, |
102 "GQvCellRendererIcon", | |
103 &cell_icon_info, 0); | |
104 } | |
9 | 105 |
106 return cell_icon_type; | |
107 } | |
108 | |
109 static void | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
446
diff
changeset
|
110 gqv_cell_renderer_icon_init(GQvCellRendererIcon *cellicon) |
9 | 111 { |
112 GTK_CELL_RENDERER(cellicon)->xpad = 2; | |
113 GTK_CELL_RENDERER(cellicon)->ypad = 2; | |
114 } | |
115 | |
116 static void | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
446
diff
changeset
|
117 gqv_cell_renderer_icon_class_init(GQvCellRendererIconClass *class) |
9 | 118 { |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
512
diff
changeset
|
119 GObjectClass *object_class = G_OBJECT_CLASS(class); |
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
512
diff
changeset
|
120 GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS(class); |
9 | 121 |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
512
diff
changeset
|
122 parent_class = g_type_class_peek_parent(class); |
9 | 123 |
124 object_class->finalize = gqv_cell_renderer_icon_finalize; | |
125 | |
126 object_class->get_property = gqv_cell_renderer_icon_get_property; | |
127 object_class->set_property = gqv_cell_renderer_icon_set_property; | |
128 | |
129 cell_class->get_size = gqv_cell_renderer_icon_get_size; | |
130 cell_class->render = gqv_cell_renderer_icon_render; | |
131 | |
132 g_object_class_install_property(object_class, | |
133 PROP_PIXBUF, | |
134 g_param_spec_object("pixbuf", | |
135 _("Pixbuf Object"), | |
136 _("The pixbuf to render"), | |
137 GDK_TYPE_PIXBUF, | |
138 G_PARAM_READWRITE)); | |
139 | |
140 g_object_class_install_property(object_class, | |
141 PROP_TEXT, | |
142 g_param_spec_string("text", | |
143 _("Text"), | |
144 _("Text to render"), | |
145 NULL, | |
146 G_PARAM_READWRITE)); | |
147 | |
148 g_object_class_install_property(object_class, | |
149 PROP_BACKGROUND_GDK, | |
150 g_param_spec_boxed("background_gdk", | |
151 _("Background color"), | |
152 _("Background color as a GdkColor"), | |
153 GDK_TYPE_COLOR, | |
154 G_PARAM_READWRITE)); | |
155 | |
156 g_object_class_install_property(object_class, | |
157 PROP_FOREGROUND_GDK, | |
158 g_param_spec_boxed("foreground_gdk", | |
159 _("Foreground color"), | |
160 _("Foreground color as a GdkColor"), | |
161 GDK_TYPE_COLOR, | |
162 G_PARAM_READWRITE)); | |
163 | |
164 g_object_class_install_property(object_class, | |
165 PROP_FOCUSED, | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
446
diff
changeset
|
166 g_param_spec_boolean("has_focus", |
9 | 167 _("Focus"), |
168 _("Draw focus indicator"), | |
169 FALSE, | |
170 G_PARAM_READWRITE)); | |
171 | |
172 g_object_class_install_property(object_class, | |
173 PROP_FIXED_WIDTH, | |
174 g_param_spec_int("fixed_width", | |
175 _("Fixed width"), | |
176 _("Width of cell"), | |
177 -1, FIXED_ICON_SIZE_MAX, | |
178 -1, | |
179 G_PARAM_READWRITE)); | |
180 | |
181 g_object_class_install_property(object_class, | |
182 PROP_FIXED_HEIGHT, | |
183 g_param_spec_int("fixed_height", | |
184 _("Fixed height"), | |
185 _("Height of icon excluding text"), | |
186 -1, FIXED_ICON_SIZE_MAX, | |
187 -1, | |
188 G_PARAM_READWRITE)); | |
189 | |
190 g_object_class_install_property(object_class, | |
191 PROP_BACKGROUND_SET, | |
192 g_param_spec_boolean("background_set", | |
193 _("Background set"), | |
194 _("Whether this tag affects the background color"), | |
195 FALSE, | |
196 G_PARAM_READWRITE)); | |
197 | |
198 g_object_class_install_property(object_class, | |
199 PROP_FOREGROUND_SET, | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
446
diff
changeset
|
200 g_param_spec_boolean("foreground_set", |
9 | 201 _("Foreground set"), |
202 _("Whether this tag affects the foreground color"), | |
203 FALSE, | |
204 G_PARAM_READWRITE)); | |
205 | |
206 g_object_class_install_property(object_class, | |
207 PROP_SHOW_TEXT, | |
208 g_param_spec_boolean("show_text", | |
209 _("Show text"), | |
210 _("Whether the text is displayed"), | |
211 TRUE, | |
212 G_PARAM_READWRITE)); | |
852 | 213 |
214 g_object_class_install_property(object_class, | |
215 PROP_SHOW_MARKS, | |
216 g_param_spec_boolean("show_marks", | |
217 _("Show marks"), | |
218 _("Whether the marks are displayed"), | |
219 TRUE, | |
220 G_PARAM_READWRITE)); | |
221 | |
222 g_object_class_install_property(object_class, | |
223 PROP_NUM_MARKS, | |
224 g_param_spec_int("num_marks", | |
225 _("Number of marks"), | |
226 _("Number of marks"), | |
227 0, 32, | |
228 6, | |
229 G_PARAM_READWRITE)); | |
230 | |
231 g_object_class_install_property(object_class, | |
232 PROP_MARKS, | |
233 g_param_spec_uint("marks", | |
234 _("Marks"), | |
235 _("Marks bit array"), | |
236 0, 0xffffffff, | |
237 0, | |
238 G_PARAM_READWRITE)); | |
9 | 239 } |
240 | |
241 static void | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
446
diff
changeset
|
242 gqv_cell_renderer_icon_finalize(GObject *object) |
9 | 243 { |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
446
diff
changeset
|
244 GQvCellRendererIcon *cellicon = GQV_CELL_RENDERER_ICON(object); |
9 | 245 |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
512
diff
changeset
|
246 if (cellicon->pixbuf) g_object_unref(cellicon->pixbuf); |
9 | 247 |
248 g_free(cellicon->text); | |
249 | |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
512
diff
changeset
|
250 (*(G_OBJECT_CLASS(parent_class))->finalize)(object); |
9 | 251 } |
252 | |
253 static void | |
254 gqv_cell_renderer_icon_get_property(GObject *object, | |
255 guint param_id, | |
256 GValue *value, | |
257 GParamSpec *pspec) | |
258 { | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
446
diff
changeset
|
259 GQvCellRendererIcon *cellicon = GQV_CELL_RENDERER_ICON(object); |
442 | 260 |
9 | 261 switch (param_id) |
534 | 262 { |
263 case PROP_PIXBUF: | |
264 g_value_set_object(value, cellicon->pixbuf ? G_OBJECT(cellicon->pixbuf) : NULL); | |
9 | 265 break; |
266 case PROP_TEXT: | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
446
diff
changeset
|
267 g_value_set_string(value, cellicon->text); |
9 | 268 break; |
269 case PROP_BACKGROUND_GDK: | |
270 { | |
271 GdkColor color; | |
272 | |
273 color.red = cellicon->background.red; | |
274 color.green = cellicon->background.green; | |
275 color.blue = cellicon->background.blue; | |
276 | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
446
diff
changeset
|
277 g_value_set_boxed(value, &color); |
9 | 278 } |
279 break; | |
280 case PROP_FOREGROUND_GDK: | |
281 { | |
282 GdkColor color; | |
283 | |
284 color.red = cellicon->foreground.red; | |
285 color.green = cellicon->foreground.green; | |
286 color.blue = cellicon->foreground.blue; | |
287 | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
446
diff
changeset
|
288 g_value_set_boxed(value, &color); |
9 | 289 } |
290 break; | |
291 case PROP_FOCUSED: | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
446
diff
changeset
|
292 g_value_set_boolean(value, cellicon->focused); |
9 | 293 break; |
294 case PROP_FIXED_WIDTH: | |
295 g_value_set_int(value, cellicon->fixed_width); | |
296 break; | |
297 case PROP_FIXED_HEIGHT: | |
298 g_value_set_int(value, cellicon->fixed_height); | |
299 break; | |
300 case PROP_BACKGROUND_SET: | |
301 g_value_set_boolean(value, cellicon->background_set); | |
302 break; | |
303 case PROP_FOREGROUND_SET: | |
304 g_value_set_boolean(value, cellicon->foreground_set); | |
305 break; | |
306 case PROP_SHOW_TEXT: | |
307 g_value_set_boolean(value, cellicon->show_text); | |
308 break; | |
852 | 309 case PROP_SHOW_MARKS: |
310 g_value_set_boolean(value, cellicon->show_marks); | |
311 break; | |
312 case PROP_NUM_MARKS: | |
313 g_value_set_int(value, cellicon->num_marks); | |
314 break; | |
315 case PROP_MARKS: | |
316 g_value_set_uint(value, cellicon->marks); | |
317 break; | |
9 | 318 default: |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
446
diff
changeset
|
319 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); |
9 | 320 break; |
321 } | |
322 } | |
323 | |
324 static void | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
446
diff
changeset
|
325 set_bg_color(GQvCellRendererIcon *cellicon, |
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
446
diff
changeset
|
326 GdkColor *color) |
9 | 327 { |
328 if (color) | |
329 { | |
330 if (!cellicon->background_set) | |
331 { | |
332 cellicon->background_set = TRUE; | |
333 g_object_notify(G_OBJECT(cellicon), "background_set"); | |
334 } | |
335 | |
336 cellicon->background.red = color->red; | |
337 cellicon->background.green = color->green; | |
338 cellicon->background.blue = color->blue; | |
339 } | |
340 else | |
341 { | |
342 if (cellicon->background_set) | |
343 { | |
344 cellicon->background_set = FALSE; | |
345 g_object_notify(G_OBJECT(cellicon), "background_set"); | |
346 } | |
347 } | |
348 } | |
349 | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
446
diff
changeset
|
350 static void set_fg_color(GQvCellRendererIcon *cellicon, |
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
446
diff
changeset
|
351 GdkColor *color) |
9 | 352 { |
353 if (color) | |
354 { | |
355 if (!cellicon->foreground_set) | |
356 { | |
357 cellicon->foreground_set = TRUE; | |
358 g_object_notify(G_OBJECT(cellicon), "foreground_set"); | |
359 } | |
360 | |
361 cellicon->foreground.red = color->red; | |
362 cellicon->foreground.green = color->green; | |
363 cellicon->foreground.blue = color->blue; | |
364 } | |
365 else | |
366 { | |
367 if (cellicon->foreground_set) | |
368 { | |
369 cellicon->foreground_set = FALSE; | |
370 g_object_notify(G_OBJECT(cellicon), "foreground_set"); | |
371 } | |
372 } | |
373 } | |
374 | |
375 static void | |
376 gqv_cell_renderer_icon_set_property(GObject *object, | |
377 guint param_id, | |
378 const GValue *value, | |
379 GParamSpec *pspec) | |
380 { | |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
512
diff
changeset
|
381 GQvCellRendererIcon *cellicon = GQV_CELL_RENDERER_ICON(object); |
442 | 382 |
9 | 383 switch (param_id) |
534 | 384 { |
385 case PROP_PIXBUF: | |
9 | 386 { |
534 | 387 GdkPixbuf *pixbuf; |
9 | 388 |
534 | 389 pixbuf = (GdkPixbuf*) g_value_get_object(value); |
390 if (pixbuf) g_object_ref(pixbuf); | |
391 if (cellicon->pixbuf) g_object_unref(cellicon->pixbuf); | |
392 cellicon->pixbuf = pixbuf; | |
393 } | |
9 | 394 break; |
395 case PROP_TEXT: | |
396 { | |
397 gchar *text; | |
398 | |
399 text = cellicon->text; | |
400 cellicon->text = g_strdup(g_value_get_string(value)); | |
401 g_free(text); | |
402 | |
403 g_object_notify(object, "text"); | |
404 } | |
405 break; | |
406 case PROP_BACKGROUND_GDK: | |
407 set_bg_color(cellicon, g_value_get_boxed(value)); | |
408 break; | |
409 case PROP_FOREGROUND_GDK: | |
410 set_fg_color(cellicon, g_value_get_boxed(value)); | |
411 break; | |
412 case PROP_FOCUSED: | |
413 cellicon->focused = g_value_get_boolean(value); | |
414 break; | |
415 case PROP_FIXED_WIDTH: | |
416 cellicon->fixed_width = g_value_get_int(value); | |
417 break; | |
418 case PROP_FIXED_HEIGHT: | |
419 cellicon->fixed_height = g_value_get_int(value); | |
420 break; | |
421 case PROP_BACKGROUND_SET: | |
422 cellicon->background_set = g_value_get_boolean(value); | |
423 break; | |
424 case PROP_FOREGROUND_SET: | |
425 cellicon->foreground_set = g_value_get_boolean(value); | |
426 break; | |
427 case PROP_SHOW_TEXT: | |
428 cellicon->show_text = g_value_get_boolean(value); | |
429 break; | |
852 | 430 case PROP_SHOW_MARKS: |
431 cellicon->show_marks = g_value_get_boolean(value); | |
432 break; | |
433 case PROP_NUM_MARKS: | |
434 cellicon->num_marks = g_value_get_int(value); | |
435 break; | |
436 case PROP_MARKS: | |
437 cellicon->marks = g_value_get_uint(value); | |
438 break; | |
9 | 439 default: |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
446
diff
changeset
|
440 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); |
9 | 441 break; |
534 | 442 } |
9 | 443 } |
444 | |
445 static PangoLayout * | |
446 gqv_cell_renderer_icon_get_layout(GQvCellRendererIcon *cellicon, GtkWidget *widget, gboolean will_render) | |
447 { | |
448 PangoLayout *layout; | |
449 gint width; | |
450 | |
451 width = (cellicon->fixed_width > 0) ? cellicon->fixed_width * PANGO_SCALE : -1; | |
452 | |
453 layout = gtk_widget_create_pango_layout(widget, cellicon->text); | |
454 pango_layout_set_width(layout, width); | |
455 pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); | |
456 pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); | |
457 | |
458 if (will_render) | |
459 { | |
460 PangoAttrList *attr_list; | |
461 | |
462 attr_list = pango_attr_list_new(); | |
463 | |
464 if (cellicon->foreground_set) | |
465 { | |
466 PangoColor color; | |
467 PangoAttribute *attr; | |
468 | |
469 color = cellicon->foreground; | |
470 | |
471 attr = pango_attr_foreground_new(color.red, color.green, color.blue); | |
472 | |
473 attr->start_index = 0; | |
474 attr->end_index = G_MAXINT; | |
475 pango_attr_list_insert(attr_list, attr); | |
476 } | |
477 | |
478 pango_layout_set_attributes(layout, attr_list); | |
479 pango_attr_list_unref(attr_list); | |
480 } | |
481 | |
482 return layout; | |
483 } | |
484 | |
485 /** | |
486 * gqv_cell_renderer_icon_new: | |
442 | 487 * |
9 | 488 * Creates a new #GQvCellRendererIcon. Adjust rendering |
489 * parameters using object properties. Object properties can be set | |
490 * globally (with g_object_set()). Also, with #GtkTreeViewColumn, you | |
491 * can bind a property to a value in a #GtkTreeModel. For example, you | |
492 * can bind the "pixbuf" property on the cell renderer to a pixbuf value | |
493 * in the model, thus rendering a different image in each row of the | |
494 * #GtkTreeView. | |
442 | 495 * |
9 | 496 * Return value: the new cell renderer |
497 **/ | |
498 GtkCellRenderer * | |
499 gqv_cell_renderer_icon_new(void) | |
500 { | |
534 | 501 return g_object_new(GQV_TYPE_CELL_RENDERER_ICON, NULL); |
9 | 502 } |
503 | |
504 static void | |
505 gqv_cell_renderer_icon_get_size(GtkCellRenderer *cell, | |
506 GtkWidget *widget, | |
507 GdkRectangle *cell_area, | |
508 gint *x_offset, | |
509 gint *y_offset, | |
510 gint *width, | |
511 gint *height) | |
512 { | |
513 GQvCellRendererIcon *cellicon = (GQvCellRendererIcon *) cell; | |
514 gint calc_width; | |
515 gint calc_height; | |
516 | |
517 if (cellicon->fixed_width > 0) | |
518 { | |
519 calc_width = cellicon->fixed_width; | |
520 } | |
521 else | |
522 { | |
523 calc_width = (cellicon->pixbuf) ? gdk_pixbuf_get_width(cellicon->pixbuf) : 0; | |
524 } | |
525 | |
526 if (cellicon->fixed_height > 0) | |
527 { | |
528 calc_height = cellicon->fixed_height; | |
529 } | |
530 else | |
531 { | |
532 calc_height = (cellicon->pixbuf) ? gdk_pixbuf_get_height(cellicon->pixbuf) : 0; | |
533 } | |
534 | |
535 if (cellicon->show_text && cellicon->text) | |
536 { | |
537 PangoLayout *layout; | |
538 PangoRectangle rect; | |
539 | |
540 layout = gqv_cell_renderer_icon_get_layout(cellicon, widget, FALSE); | |
541 pango_layout_get_pixel_extents(layout, NULL, &rect); | |
542 g_object_unref(layout); | |
543 | |
544 calc_width = MAX(calc_width, rect.width); | |
545 calc_height += rect.height; | |
546 } | |
547 | |
852 | 548 if (cellicon->show_marks) |
549 { | |
550 calc_height += TOGGLE_SPACING; | |
551 calc_width = MAX(calc_width, TOGGLE_SPACING * cellicon->num_marks); | |
552 } | |
553 | |
9 | 554 calc_width += (gint)cell->xpad * 2; |
555 calc_height += (gint)cell->ypad * 2; | |
556 | |
557 if (x_offset) *x_offset = 0; | |
558 if (y_offset) *y_offset = 0; | |
559 | |
560 if (cell_area && calc_width > 0 && calc_height > 0) | |
561 { | |
562 if (x_offset) | |
563 { | |
564 *x_offset = (cell->xalign * (cell_area->width - calc_width - 2 * cell->xpad)); | |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
512
diff
changeset
|
565 *x_offset = MAX(*x_offset, 0) + cell->xpad; |
9 | 566 } |
567 if (y_offset) | |
568 { | |
569 *y_offset = (cell->yalign * (cell_area->height - calc_height - 2 * cell->ypad)); | |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
512
diff
changeset
|
570 *y_offset = MAX(*y_offset, 0) + cell->ypad; |
9 | 571 } |
572 } | |
573 | |
574 if (width) *width = calc_width; | |
575 if (height) *height = calc_height; | |
576 } | |
577 | |
578 static void | |
579 gqv_cell_renderer_icon_render(GtkCellRenderer *cell, | |
580 GdkWindow *window, | |
581 GtkWidget *widget, | |
582 GdkRectangle *background_area, | |
583 GdkRectangle *cell_area, | |
584 GdkRectangle *expose_area, | |
585 GtkCellRendererState flags) | |
586 | |
587 { | |
588 GQvCellRendererIcon *cellicon = (GQvCellRendererIcon *) cell; | |
589 GdkPixbuf *pixbuf; | |
590 const gchar *text; | |
591 GdkRectangle cell_rect; | |
592 GtkStateType state; | |
593 | |
594 pixbuf = cellicon->pixbuf; | |
595 text = cellicon->text; | |
596 | |
597 if (!pixbuf && !text) return; | |
598 | |
599 gqv_cell_renderer_icon_get_size(cell, widget, cell_area, | |
600 &cell_rect.x, &cell_rect.y, | |
601 &cell_rect.width, &cell_rect.height); | |
602 | |
603 cell_rect.x += cell->xpad; | |
604 cell_rect.y += cell->ypad; | |
605 cell_rect.width -= cell->xpad * 2; | |
606 cell_rect.height -= cell->ypad * 2; | |
607 | |
608 if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED) | |
609 { | |
610 if (GTK_WIDGET_HAS_FOCUS(widget)) | |
611 state = GTK_STATE_SELECTED; | |
612 else | |
613 state = GTK_STATE_ACTIVE; | |
614 } | |
615 else | |
616 { | |
617 if (GTK_WIDGET_STATE(widget) == GTK_STATE_INSENSITIVE) | |
618 state = GTK_STATE_INSENSITIVE; | |
619 else | |
620 state = GTK_STATE_NORMAL; | |
621 } | |
622 | |
623 if (pixbuf) | |
624 { | |
625 GdkRectangle pix_rect; | |
626 GdkRectangle draw_rect; | |
627 | |
628 pix_rect.width = gdk_pixbuf_get_width(pixbuf); | |
629 pix_rect.height = gdk_pixbuf_get_height(pixbuf); | |
630 | |
631 pix_rect.x = cell_area->x + (cell_area->width - pix_rect.width) / 2; | |
632 | |
633 if (cellicon->fixed_height > 0) | |
634 { | |
635 pix_rect.y = cell_area->y + cell->ypad + (cellicon->fixed_height - pix_rect.height) / 2; | |
636 } | |
637 else | |
638 { | |
639 pix_rect.y = cell_area->y + cell_rect.y; | |
640 } | |
641 | |
642 if (gdk_rectangle_intersect(cell_area, &pix_rect, &draw_rect) && | |
643 gdk_rectangle_intersect(expose_area, &draw_rect, &draw_rect)) | |
644 { | |
645 gdk_draw_pixbuf(window, | |
646 widget->style->black_gc, | |
647 pixbuf, | |
648 /* pixbuf 0, 0 is at pix_rect.x, pix_rect.y */ | |
649 draw_rect.x - pix_rect.x, | |
650 draw_rect.y - pix_rect.y, | |
651 draw_rect.x, | |
652 draw_rect.y, | |
653 draw_rect.width, | |
654 draw_rect.height, | |
655 GDK_RGB_DITHER_NORMAL, | |
656 0, 0); | |
657 } | |
658 } | |
659 | |
660 if (cellicon->show_text && text) | |
661 { | |
662 PangoLayout *layout; | |
663 PangoRectangle text_rect; | |
664 GdkRectangle pix_rect; | |
442 | 665 GdkRectangle draw_rect; |
9 | 666 |
667 layout = gqv_cell_renderer_icon_get_layout(cellicon, widget, TRUE); | |
668 pango_layout_get_pixel_extents(layout, NULL, &text_rect); | |
669 | |
670 pix_rect.width = text_rect.width; | |
671 pix_rect.height = text_rect.height; | |
672 pix_rect.x = cell_area->x + cell->xpad + (cell_rect.width - text_rect.width + 1) / 2; | |
673 pix_rect.y = cell_area->y + cell->ypad + (cell_rect.height - text_rect.height); | |
852 | 674 |
675 if (cellicon->show_marks) | |
676 { | |
677 pix_rect.y -= TOGGLE_SPACING; | |
678 } | |
9 | 679 |
680 if (gdk_rectangle_intersect(cell_area, &pix_rect, &draw_rect) && | |
681 gdk_rectangle_intersect(expose_area, &draw_rect, &draw_rect)) | |
682 { | |
683 gtk_paint_layout(widget->style, window, | |
684 state, TRUE, | |
685 cell_area, widget, | |
686 "cellrenderertext", | |
687 pix_rect.x - text_rect.x, pix_rect.y, | |
688 layout); | |
689 } | |
690 | |
691 g_object_unref(layout); | |
692 } | |
693 | |
852 | 694 if (cellicon->show_marks) |
695 { | |
696 GdkRectangle pix_rect; | |
697 GdkRectangle draw_rect; | |
698 gint i; | |
699 | |
700 pix_rect.width = TOGGLE_SPACING * cellicon->num_marks; | |
701 pix_rect.height = TOGGLE_SPACING; | |
702 pix_rect.x = cell_area->x + cell->xpad + (cell_rect.width - pix_rect.width + 1) / 2 + (TOGGLE_SPACING - TOGGLE_WIDTH) / 2; | |
703 pix_rect.y = cell_area->y + cell->ypad + (cell_rect.height - pix_rect.height) + (TOGGLE_SPACING - TOGGLE_WIDTH) / 2; | |
704 | |
853 | 705 if (gdk_rectangle_intersect(cell_area, &pix_rect, &draw_rect) && |
706 gdk_rectangle_intersect(expose_area, &draw_rect, &draw_rect)) | |
852 | 707 { |
853 | 708 for (i = 0; i < cellicon->num_marks; i++) |
709 { | |
710 gtk_paint_check (widget->style, window, | |
711 state, (cellicon->marks & (1 << i)) ? GTK_SHADOW_IN : GTK_SHADOW_OUT, | |
712 cell_area, widget, "cellcheck", | |
713 pix_rect.x + i * TOGGLE_SPACING + (TOGGLE_WIDTH - TOGGLE_SPACING) / 2, | |
714 pix_rect.y, | |
715 TOGGLE_WIDTH, TOGGLE_WIDTH); | |
716 } | |
852 | 717 } |
718 } | |
719 | |
534 | 720 if (cellicon->focused && GTK_WIDGET_HAS_FOCUS(widget)) |
9 | 721 { |
722 gtk_paint_focus(widget->style, window, | |
723 state, | |
724 cell_area, widget, | |
725 "cellrendererfocus", | |
726 cell_area->x, cell_area->y, | |
727 cell_area->width, cell_area->height); | |
728 } | |
729 } |