4 * ROX-Filer, filer for the ROX desktop project
5 * Copyright (C) 2002, 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.
33 #include "cell_icon.h"
38 typedef struct _CellIcon CellIcon
;
39 typedef struct _CellIconClass CellIconClass
;
42 GtkCellRenderer parent
;
49 struct _CellIconClass
{
50 GtkCellRendererClass parent_class
;
54 /* Static prototypes */
55 static void cell_icon_set_property(GObject
*object
, guint param_id
,
56 const GValue
*value
, GParamSpec
*pspec
);
57 static void cell_icon_init (CellIcon
*cell
);
58 static void cell_icon_class_init (CellIconClass
*class);
59 static void cell_icon_get_size (GtkCellRenderer
*cell
,
61 GdkRectangle
*rectangle
,
66 static void cell_icon_render (GtkCellRenderer
*cell
,
69 GdkRectangle
*background_area
,
70 GdkRectangle
*cell_area
,
71 GdkRectangle
*expose_area
,
73 static GtkType
cell_icon_get_type(void);
81 /****************************************************************
82 * EXTERNAL INTERFACE *
83 ****************************************************************/
85 GtkCellRenderer
*cell_icon_new(void)
87 return GTK_CELL_RENDERER(g_object_new(cell_icon_get_type(), NULL
));
90 /****************************************************************
91 * INTERNAL FUNCTIONS *
92 ****************************************************************/
95 static GtkType
cell_icon_get_type(void)
97 static GtkType cell_icon_type
= 0;
101 static const GTypeInfo cell_icon_info
=
103 sizeof (CellIconClass
),
104 NULL
, /* base_init */
105 NULL
, /* base_finalize */
106 (GClassInitFunc
) cell_icon_class_init
,
107 NULL
, /* class_finalize */
108 NULL
, /* class_data */
111 (GInstanceInitFunc
) cell_icon_init
,
114 cell_icon_type
= g_type_register_static(GTK_TYPE_CELL_RENDERER
,
119 return cell_icon_type
;
122 static void cell_icon_init(CellIcon
*icon
)
126 static void cell_icon_class_init(CellIconClass
*class)
128 GObjectClass
*object_class
= G_OBJECT_CLASS(class);
129 GtkCellRendererClass
*cell_class
= GTK_CELL_RENDERER_CLASS(class);
131 object_class
->set_property
= cell_icon_set_property
;
133 cell_class
->get_size
= cell_icon_get_size
;
134 cell_class
->render
= cell_icon_render
;
136 g_object_class_install_property(object_class
,
138 g_param_spec_pointer("item",
140 _("The item to render."),
143 g_object_class_install_property(object_class
,
145 g_param_spec_boxed("background_gdk",
146 _("Background color"),
147 _("Background color as a GdkColor"),
152 static void cell_icon_set_property(GObject
*object
, guint param_id
,
153 const GValue
*value
, GParamSpec
*pspec
)
155 CellIcon
*icon
= (CellIcon
*) object
;
160 icon
->item
= (DirItem
*) g_value_get_pointer(value
);
162 case PROP_BACKGROUND_GDK
:
164 GdkColor
*bg
= g_value_get_boxed(value
);
165 icon
->selected
= bg
!= NULL
;
168 icon
->background
.red
= bg
->red
;
169 icon
->background
.green
= bg
->green
;
170 icon
->background
.blue
= bg
->blue
;
175 G_OBJECT_WARN_INVALID_PROPERTY_ID(object
,
181 static void cell_icon_get_size(GtkCellRenderer
*cell
,
183 GdkRectangle
*cell_area
,
194 *width
= SMALL_WIDTH
;
196 *height
= SMALL_HEIGHT
;
199 static void cell_icon_render(GtkCellRenderer
*cell
,
202 GdkRectangle
*background_area
,
203 GdkRectangle
*cell_area
,
204 GdkRectangle
*expose_area
,
207 CellIcon
*icon
= (CellIcon
*) cell
;
209 g_return_if_fail(icon
->item
!= NULL
);
211 /* Drag the background */
218 color
.red
= icon
->background
.red
;
219 color
.green
= icon
->background
.green
;
220 color
.blue
= icon
->background
.blue
;
222 gc
= gdk_gc_new(window
);
224 gdk_gc_set_rgb_fg_color(gc
, &color
);
226 gdk_draw_rectangle(window
, gc
, TRUE
,
229 background_area
->width
,
230 background_area
->height
);
232 g_object_unref(G_OBJECT(gc
));
237 if (!icon
->item
->image
)
240 draw_small_icon(window
, cell_area
, icon
->item
, icon
->item
->image
,
241 FALSE
); /* XXX: selected */