1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007 Raphael Slinckx <raphael@slinckx.net>
4 * Copyright (C) 2007-2008 Collabora Ltd.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Authors: Raphael Slinckx <raphael@slinckx.net>
23 #include <gtk/gtktreeview.h>
25 #include "empathy-cell-renderer-activatable.h"
27 static void empathy_cell_renderer_activatable_init (EmpathyCellRendererActivatable *cell);
28 static void empathy_cell_renderer_activatable_class_init (EmpathyCellRendererActivatableClass *klass);
29 static gboolean cell_renderer_activatable_activate (GtkCellRenderer *cell,
33 GdkRectangle *background_area,
34 GdkRectangle *cell_area,
35 GtkCellRendererState flags);
42 static guint signals[LAST_SIGNAL];
44 G_DEFINE_TYPE (EmpathyCellRendererActivatable, empathy_cell_renderer_activatable, GTK_TYPE_CELL_RENDERER_PIXBUF)
47 empathy_cell_renderer_activatable_init (EmpathyCellRendererActivatable *cell)
52 "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE,
58 empathy_cell_renderer_activatable_class_init (EmpathyCellRendererActivatableClass *klass)
60 GtkCellRendererClass *cell_class;
62 cell_class = GTK_CELL_RENDERER_CLASS (klass);
63 cell_class->activate = cell_renderer_activatable_activate;
65 signals[PATH_ACTIVATED] =
66 g_signal_new ("path-activated",
67 G_TYPE_FROM_CLASS (klass),
71 g_cclosure_marshal_VOID__STRING,
77 empathy_cell_renderer_activatable_new (void)
79 return g_object_new (EMPATHY_TYPE_CELL_RENDERER_ACTIVATABLE, NULL);
83 cell_renderer_activatable_activate (GtkCellRenderer *cell,
86 const gchar *path_string,
87 GdkRectangle *background_area,
88 GdkRectangle *cell_area,
89 GtkCellRendererState flags)
91 EmpathyCellRendererActivatable *activatable;
92 gint ex, ey, bx, by, bw, bh;
94 activatable = EMPATHY_CELL_RENDERER_ACTIVATABLE (cell);
96 if (!GTK_IS_TREE_VIEW (widget) || event == NULL ||
97 event->type != GDK_BUTTON_PRESS) {
101 ex = (gint) ((GdkEventButton *) event)->x;
102 ey = (gint) ((GdkEventButton *) event)->y;
103 bx = background_area->x;
104 by = background_area->y;
105 bw = background_area->width;
106 bh = background_area->height;
108 if (ex < bx || ex > (bx+bw) || ey < by || ey > (by+bh)){
109 /* Click wasn't on the icon */
113 g_signal_emit (activatable, signals[PATH_ACTIVATED], 0, path_string);