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>
24 #include "empathy-cell-renderer-activatable.h"
26 #include "empathy-utils.h"
34 PROP_SHOW_ON_SELECT
= 1
38 gboolean show_on_select
;
39 } EmpathyCellRendererActivatablePriv
;
41 static guint signals
[LAST_SIGNAL
];
43 G_DEFINE_TYPE (EmpathyCellRendererActivatable
,
44 empathy_cell_renderer_activatable
, GTK_TYPE_CELL_RENDERER_PIXBUF
)
46 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCellRendererActivatable)
49 empathy_cell_renderer_activatable_init (EmpathyCellRendererActivatable
*cell
)
51 cell
->priv
= G_TYPE_INSTANCE_GET_PRIVATE (cell
,
52 EMPATHY_TYPE_CELL_RENDERER_ACTIVATABLE
,
53 EmpathyCellRendererActivatablePriv
);
58 "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE
,
64 cell_renderer_activatable_get_property (GObject
*object
,
69 EmpathyCellRendererActivatablePriv
*priv
= GET_PRIV (object
);
73 case PROP_SHOW_ON_SELECT
:
74 g_value_set_boolean (value
, priv
->show_on_select
);
77 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
83 cell_renderer_activatable_set_property (GObject
*object
,
88 EmpathyCellRendererActivatablePriv
*priv
= GET_PRIV (object
);
92 case PROP_SHOW_ON_SELECT
:
93 priv
->show_on_select
= g_value_get_boolean (value
);
96 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
102 empathy_cell_renderer_activatable_new (void)
104 return g_object_new (EMPATHY_TYPE_CELL_RENDERER_ACTIVATABLE
, NULL
);
108 cell_renderer_activatable_activate (GtkCellRenderer
*cell
,
111 const gchar
*path_string
,
112 const GdkRectangle
*background_area
,
113 const GdkRectangle
*cell_area
,
114 GtkCellRendererState flags
)
116 EmpathyCellRendererActivatable
*activatable
;
117 gint ex
, ey
, bx
, by
, bw
, bh
;
119 activatable
= EMPATHY_CELL_RENDERER_ACTIVATABLE (cell
);
121 if (!GTK_IS_TREE_VIEW (widget
) || event
== NULL
||
122 event
->type
!= GDK_BUTTON_PRESS
) {
126 ex
= (gint
) ((GdkEventButton
*) event
)->x
;
127 ey
= (gint
) ((GdkEventButton
*) event
)->y
;
128 bx
= background_area
->x
;
129 by
= background_area
->y
;
130 bw
= background_area
->width
;
131 bh
= background_area
->height
;
133 if (ex
< bx
|| ex
> (bx
+bw
) || ey
< by
|| ey
> (by
+bh
)){
134 /* Click wasn't on the icon */
138 g_signal_emit (activatable
, signals
[PATH_ACTIVATED
], 0, path_string
);
144 cell_renderer_activatable_render (
145 GtkCellRenderer
*cell
,
148 const GdkRectangle
*background_area
,
149 const GdkRectangle
*cell_area
,
150 GtkCellRendererState flags
)
152 EmpathyCellRendererActivatablePriv
*priv
= GET_PRIV (cell
);
154 if (priv
->show_on_select
&& !(flags
& (GTK_CELL_RENDERER_SELECTED
)))
157 GTK_CELL_RENDERER_CLASS
158 (empathy_cell_renderer_activatable_parent_class
)->render (
159 cell
, cr
, widget
, background_area
, cell_area
, flags
);
163 empathy_cell_renderer_activatable_class_init (
164 EmpathyCellRendererActivatableClass
*klass
)
166 GtkCellRendererClass
*cell_class
;
167 GObjectClass
*oclass
;
169 oclass
= G_OBJECT_CLASS (klass
);
170 oclass
->get_property
= cell_renderer_activatable_get_property
;
171 oclass
->set_property
= cell_renderer_activatable_set_property
;
173 cell_class
= GTK_CELL_RENDERER_CLASS (klass
);
174 cell_class
->activate
= cell_renderer_activatable_activate
;
175 cell_class
->render
= cell_renderer_activatable_render
;
177 signals
[PATH_ACTIVATED
] =
178 g_signal_new ("path-activated",
179 G_TYPE_FROM_CLASS (klass
),
183 g_cclosure_marshal_generic
,
187 g_object_class_install_property (oclass
, PROP_SHOW_ON_SELECT
,
188 g_param_spec_boolean ("show-on-select",
190 "Whether the cell renderer should be shown only when it's selected",
192 G_PARAM_STATIC_STRINGS
| G_PARAM_READWRITE
));
194 g_type_class_add_private (klass
,
195 sizeof (EmpathyCellRendererActivatablePriv
));