2 * Copyright (C) 2007 Raphael Slinckx <raphael@slinckx.net>
3 * Copyright (C) 2007-2009 Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Authors: Raphael Slinckx <raphael@slinckx.net>
20 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
27 #include <libempathy/empathy-utils.h>
29 #include "empathy-cell-renderer-activatable.h"
37 PROP_SHOW_ON_SELECT
= 1
41 gboolean show_on_select
;
42 } EmpathyCellRendererActivatablePriv
;
44 static guint signals
[LAST_SIGNAL
];
46 G_DEFINE_TYPE (EmpathyCellRendererActivatable
,
47 empathy_cell_renderer_activatable
, GTK_TYPE_CELL_RENDERER_PIXBUF
)
49 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCellRendererActivatable)
52 empathy_cell_renderer_activatable_init (EmpathyCellRendererActivatable
*cell
)
54 cell
->priv
= G_TYPE_INSTANCE_GET_PRIVATE (cell
,
55 EMPATHY_TYPE_CELL_RENDERER_ACTIVATABLE
,
56 EmpathyCellRendererActivatablePriv
);
61 "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE
,
67 cell_renderer_activatable_get_property (GObject
*object
,
72 EmpathyCellRendererActivatablePriv
*priv
= GET_PRIV (object
);
76 case PROP_SHOW_ON_SELECT
:
77 g_value_set_boolean (value
, priv
->show_on_select
);
80 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
86 cell_renderer_activatable_set_property (GObject
*object
,
91 EmpathyCellRendererActivatablePriv
*priv
= GET_PRIV (object
);
95 case PROP_SHOW_ON_SELECT
:
96 priv
->show_on_select
= g_value_get_boolean (value
);
99 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
105 empathy_cell_renderer_activatable_new (void)
107 return g_object_new (EMPATHY_TYPE_CELL_RENDERER_ACTIVATABLE
, NULL
);
111 cell_renderer_activatable_activate (GtkCellRenderer
*cell
,
114 const gchar
*path_string
,
115 GdkRectangle
*background_area
,
116 GdkRectangle
*cell_area
,
117 GtkCellRendererState flags
)
119 EmpathyCellRendererActivatable
*activatable
;
120 gint ex
, ey
, bx
, by
, bw
, bh
;
122 activatable
= EMPATHY_CELL_RENDERER_ACTIVATABLE (cell
);
124 if (!GTK_IS_TREE_VIEW (widget
) || event
== NULL
||
125 event
->type
!= GDK_BUTTON_PRESS
) {
129 ex
= (gint
) ((GdkEventButton
*) event
)->x
;
130 ey
= (gint
) ((GdkEventButton
*) event
)->y
;
131 bx
= background_area
->x
;
132 by
= background_area
->y
;
133 bw
= background_area
->width
;
134 bh
= background_area
->height
;
136 if (ex
< bx
|| ex
> (bx
+bw
) || ey
< by
|| ey
> (by
+bh
)){
137 /* Click wasn't on the icon */
141 g_signal_emit (activatable
, signals
[PATH_ACTIVATED
], 0, path_string
);
147 cell_renderer_activatable_render (
148 GtkCellRenderer
*cell
,
151 GdkRectangle
*background_area
,
152 GdkRectangle
*cell_area
,
153 GdkRectangle
*expose_area
,
154 GtkCellRendererState flags
)
156 EmpathyCellRendererActivatablePriv
*priv
= GET_PRIV (cell
);
158 if (priv
->show_on_select
&& !(flags
& (GTK_CELL_RENDERER_SELECTED
)))
161 GTK_CELL_RENDERER_CLASS
162 (empathy_cell_renderer_activatable_parent_class
)->render (
163 cell
, window
, widget
, background_area
, cell_area
, expose_area
, flags
);
167 empathy_cell_renderer_activatable_class_init (
168 EmpathyCellRendererActivatableClass
*klass
)
170 GtkCellRendererClass
*cell_class
;
171 GObjectClass
*oclass
;
173 oclass
= G_OBJECT_CLASS (klass
);
174 oclass
->get_property
= cell_renderer_activatable_get_property
;
175 oclass
->set_property
= cell_renderer_activatable_set_property
;
177 cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
178 cell_class
->activate
= cell_renderer_activatable_activate
;
179 cell_class
->render
= cell_renderer_activatable_render
;
181 signals
[PATH_ACTIVATED
] =
182 g_signal_new ("path-activated",
183 G_TYPE_FROM_CLASS (klass
),
187 g_cclosure_marshal_VOID__STRING
,
191 g_object_class_install_property (oclass
, PROP_SHOW_ON_SELECT
,
192 g_param_spec_boolean ("show-on-select",
194 "Whether the cell renderer should be shown only when it's selected",
196 G_PARAM_STATIC_STRINGS
| G_PARAM_READWRITE
));
198 g_type_class_add_private (klass
,
199 sizeof (EmpathyCellRendererActivatablePriv
));