4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2005, the ROX-Filer team.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
22 /* cell_icon.c - a GtkCellRenderer used for the icons in details mode
24 * Based on gtkcellrendererpixbuf.c.
34 #include "view_details.h"
35 #include "cell_icon.h"
44 typedef struct _CellIcon CellIcon
;
45 typedef struct _CellIconClass CellIconClass
;
48 GtkCellRenderer parent
;
50 ViewDetails
*view_details
;
55 struct _CellIconClass
{
56 GtkCellRendererClass parent_class
;
60 /* Static prototypes */
61 static void cell_icon_set_property(GObject
*object
, guint param_id
,
62 const GValue
*value
, GParamSpec
*pspec
);
63 static void cell_icon_init (CellIcon
*cell
);
64 static void cell_icon_class_init (CellIconClass
*class);
65 static void cell_icon_get_size (GtkCellRenderer
*cell
,
67 GdkRectangle
*rectangle
,
72 static void cell_icon_render (GtkCellRenderer
*cell
,
75 GdkRectangle
*background_area
,
76 GdkRectangle
*cell_area
,
77 GdkRectangle
*expose_area
,
79 static GtkType
cell_icon_get_type(void);
87 /****************************************************************
88 * EXTERNAL INTERFACE *
89 ****************************************************************/
91 GtkCellRenderer
*cell_icon_new(ViewDetails
*view_details
)
93 GtkCellRenderer
*cell
;
95 cell
= GTK_CELL_RENDERER(g_object_new(cell_icon_get_type(), NULL
));
96 ((CellIcon
*) cell
)->view_details
= view_details
;
101 /****************************************************************
102 * INTERNAL FUNCTIONS *
103 ****************************************************************/
106 static GtkType
cell_icon_get_type(void)
108 static GtkType cell_icon_type
= 0;
112 static const GTypeInfo cell_icon_info
=
114 sizeof (CellIconClass
),
115 NULL
, /* base_init */
116 NULL
, /* base_finalize */
117 (GClassInitFunc
) cell_icon_class_init
,
118 NULL
, /* class_finalize */
119 NULL
, /* class_data */
122 (GInstanceInitFunc
) cell_icon_init
,
125 cell_icon_type
= g_type_register_static(GTK_TYPE_CELL_RENDERER
,
130 return cell_icon_type
;
133 static void cell_icon_init(CellIcon
*icon
)
135 icon
->view_details
= NULL
;
138 static void cell_icon_class_init(CellIconClass
*class)
140 GObjectClass
*object_class
= G_OBJECT_CLASS(class);
141 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS(class);
143 object_class
->set_property
= cell_icon_set_property
;
145 cell_class
->get_size
= cell_icon_get_size
;
146 cell_class
->render
= cell_icon_render
;
148 g_object_class_install_property(object_class
,
150 g_param_spec_pointer("item",
152 "The item to render.",
155 g_object_class_install_property(object_class
,
157 g_param_spec_boxed("background_gdk",
159 "Background color as a GdkColor",
164 static void cell_icon_set_property(GObject
*object
, guint param_id
,
165 const GValue
*value
, GParamSpec
*pspec
)
167 CellIcon
*icon
= (CellIcon
*) object
;
172 icon
->item
= (ViewItem
*) g_value_get_pointer(value
);
174 case PROP_BACKGROUND_GDK
:
176 GdkColor
*bg
= g_value_get_boxed(value
);
179 icon
->background
.red
= bg
->red
;
180 icon
->background
.green
= bg
->green
;
181 icon
->background
.blue
= bg
->blue
;
186 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
,
192 /* Return the size to display this icon at. If huge, ensures that the image
193 * exists in that size, if present at all.
195 static DisplayStyle
get_style(GtkCellRenderer
*cell
)
197 CellIcon
*icon
= (CellIcon
*) cell
;
198 ViewItem
*view_item
= icon
->item
;
200 DirItem
*item
= view_item
->item
;
202 if (!view_item
->image
)
204 FilerWindow
*filer_window
= icon
->view_details
->filer_window
;
206 if (filer_window
->show_thumbs
&& item
->base_type
== TYPE_FILE
)
210 path
= make_path(filer_window
->real_path
,
213 view_item
->image
= g_fscache_lookup_full(pixmap_cache
,
214 path
, FSCACHE_LOOKUP_ONLY_NEW
, NULL
);
216 if (!view_item
->image
)
218 view_item
->image
= di_image(item
);
219 if (view_item
->image
)
220 g_object_ref(view_item
->image
);
224 size
= icon
->view_details
->filer_window
->display_style_wanted
;
226 if (size
== AUTO_SIZE_ICONS
)
228 if (!view_item
->image
|| view_item
->image
== di_image(item
))
233 if (size
== HUGE_ICONS
&& view_item
->image
&&
234 !view_item
->image
->huge_pixbuf
)
235 pixmap_make_huge(view_item
->image
);
240 static void cell_icon_get_size(GtkCellRenderer
*cell
,
242 GdkRectangle
*cell_area
,
252 size
= get_style(cell
);
253 image
= ((CellIcon
*) cell
)->item
->image
;
281 w
= image
->huge_width
;
282 h
= image
->huge_height
;
302 static void cell_icon_render(GtkCellRenderer
*cell
,
305 GdkRectangle
*background_area
,
306 GdkRectangle
*cell_area
,
307 GdkRectangle
*expose_area
,
310 CellIcon
*icon
= (CellIcon
*) cell
;
311 ViewItem
*view_item
= icon
->item
;
314 gboolean selected
= (flags
& GTK_CELL_RENDERER_SELECTED
) != 0;
317 g_return_if_fail(view_item
!= NULL
);
319 item
= view_item
->item
;
320 size
= get_style(cell
);
321 color
= &widget
->style
->base
[icon
->view_details
->filer_window
->selection_state
];
325 if (!view_item
->image
)
332 GdkRectangle area
= *cell_area
;
333 area
.width
= MIN(area
.width
, SMALL_WIDTH
);
334 area
.x
= cell_area
->x
+ cell_area
->width
- area
.width
;
335 draw_small_icon(window
, &area
, item
,
336 view_item
->image
, selected
, color
);
341 draw_large_icon(window
, cell_area
, item
,
342 view_item
->image
, selected
, color
);
345 if (!di_image(item
)->huge_pixbuf
)
346 pixmap_make_huge(di_image(item
));
347 draw_huge_icon(window
, cell_area
, item
,
348 view_item
->image
, selected
, color
);
351 g_warning("Unknown size %d\n", size
);