2 * ROX-Filer, filer for the ROX desktop project
3 * Copyright (C) 2006, Thomas Leonard and others (see changelog for details).
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place, Suite 330, Boston, MA 02111-1307 USA
20 /* cell_icon.c - a GtkCellRenderer used for the icons in details mode
22 * Based on gtkcellrendererpixbuf.c.
32 #include "view_details.h"
33 #include "cell_icon.h"
42 typedef struct _CellIcon CellIcon
;
43 typedef struct _CellIconClass CellIconClass
;
46 GtkCellRenderer parent
;
48 ViewDetails
*view_details
;
53 struct _CellIconClass
{
54 GtkCellRendererClass parent_class
;
58 /* Static prototypes */
59 static void cell_icon_set_property(GObject
*object
, guint param_id
,
60 const GValue
*value
, GParamSpec
*pspec
);
61 static void cell_icon_init (CellIcon
*cell
);
62 static void cell_icon_class_init (CellIconClass
*class);
63 static void cell_icon_get_size (GtkCellRenderer
*cell
,
65 GdkRectangle
*rectangle
,
70 static void cell_icon_render (GtkCellRenderer
*cell
,
73 GdkRectangle
*background_area
,
74 GdkRectangle
*cell_area
,
75 GdkRectangle
*expose_area
,
77 static GtkType
cell_icon_get_type(void);
85 /****************************************************************
86 * EXTERNAL INTERFACE *
87 ****************************************************************/
89 GtkCellRenderer
*cell_icon_new(ViewDetails
*view_details
)
91 GtkCellRenderer
*cell
;
93 cell
= GTK_CELL_RENDERER(g_object_new(cell_icon_get_type(), NULL
));
94 ((CellIcon
*) cell
)->view_details
= view_details
;
99 /****************************************************************
100 * INTERNAL FUNCTIONS *
101 ****************************************************************/
104 static GtkType
cell_icon_get_type(void)
106 static GtkType cell_icon_type
= 0;
110 static const GTypeInfo cell_icon_info
=
112 sizeof (CellIconClass
),
113 NULL
, /* base_init */
114 NULL
, /* base_finalize */
115 (GClassInitFunc
) cell_icon_class_init
,
116 NULL
, /* class_finalize */
117 NULL
, /* class_data */
120 (GInstanceInitFunc
) cell_icon_init
,
123 cell_icon_type
= g_type_register_static(GTK_TYPE_CELL_RENDERER
,
128 return cell_icon_type
;
131 static void cell_icon_init(CellIcon
*icon
)
133 icon
->view_details
= NULL
;
136 static void cell_icon_class_init(CellIconClass
*class)
138 GObjectClass
*object_class
= G_OBJECT_CLASS(class);
139 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS(class);
141 object_class
->set_property
= cell_icon_set_property
;
143 cell_class
->get_size
= cell_icon_get_size
;
144 cell_class
->render
= cell_icon_render
;
146 g_object_class_install_property(object_class
,
148 g_param_spec_pointer("item",
150 "The item to render.",
153 g_object_class_install_property(object_class
,
155 g_param_spec_boxed("background_gdk",
157 "Background color as a GdkColor",
162 static void cell_icon_set_property(GObject
*object
, guint param_id
,
163 const GValue
*value
, GParamSpec
*pspec
)
165 CellIcon
*icon
= (CellIcon
*) object
;
170 icon
->item
= (ViewItem
*) g_value_get_pointer(value
);
172 case PROP_BACKGROUND_GDK
:
174 GdkColor
*bg
= g_value_get_boxed(value
);
177 icon
->background
.red
= bg
->red
;
178 icon
->background
.green
= bg
->green
;
179 icon
->background
.blue
= bg
->blue
;
184 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
,
190 /* Return the size to display this icon at. If huge, ensures that the image
191 * exists in that size, if present at all.
193 static DisplayStyle
get_style(GtkCellRenderer
*cell
)
195 CellIcon
*icon
= (CellIcon
*) cell
;
196 ViewItem
*view_item
= icon
->item
;
198 DirItem
*item
= view_item
->item
;
200 if (!view_item
->image
)
202 FilerWindow
*filer_window
= icon
->view_details
->filer_window
;
204 if (filer_window
->show_thumbs
&& item
->base_type
== TYPE_FILE
)
208 path
= make_path(filer_window
->real_path
,
211 view_item
->image
= g_fscache_lookup_full(pixmap_cache
,
212 path
, FSCACHE_LOOKUP_ONLY_NEW
, NULL
);
214 if (!view_item
->image
)
216 view_item
->image
= di_image(item
);
217 if (view_item
->image
)
218 g_object_ref(view_item
->image
);
222 size
= icon
->view_details
->filer_window
->display_style_wanted
;
224 if (size
== AUTO_SIZE_ICONS
)
226 if (!view_item
->image
|| view_item
->image
== di_image(item
))
231 if (size
== HUGE_ICONS
&& view_item
->image
&&
232 !view_item
->image
->huge_pixbuf
)
233 pixmap_make_huge(view_item
->image
);
238 static void cell_icon_get_size(GtkCellRenderer
*cell
,
240 GdkRectangle
*cell_area
,
250 size
= get_style(cell
);
251 image
= ((CellIcon
*) cell
)->item
->image
;
279 w
= image
->huge_width
;
280 h
= image
->huge_height
;
300 static void cell_icon_render(GtkCellRenderer
*cell
,
303 GdkRectangle
*background_area
,
304 GdkRectangle
*cell_area
,
305 GdkRectangle
*expose_area
,
308 CellIcon
*icon
= (CellIcon
*) cell
;
309 ViewItem
*view_item
= icon
->item
;
312 gboolean selected
= (flags
& GTK_CELL_RENDERER_SELECTED
) != 0;
315 g_return_if_fail(view_item
!= NULL
);
317 item
= view_item
->item
;
318 size
= get_style(cell
);
319 color
= &widget
->style
->base
[icon
->view_details
->filer_window
->selection_state
];
323 if (!view_item
->image
)
330 GdkRectangle area
= *cell_area
;
331 area
.width
= MIN(area
.width
, SMALL_WIDTH
);
332 area
.x
= cell_area
->x
+ cell_area
->width
- area
.width
;
333 draw_small_icon(window
, &area
, item
,
334 view_item
->image
, selected
, color
);
339 draw_large_icon(window
, cell_area
, item
,
340 view_item
->image
, selected
, color
);
343 if (!di_image(item
)->huge_pixbuf
)
344 pixmap_make_huge(di_image(item
));
345 draw_huge_icon(window
, cell_area
, item
,
346 view_item
->image
, selected
, color
);
349 g_warning("Unknown size %d\n", size
);