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 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 <libempathy/empathy-debug.h>
27 #include "empathy-cell-renderer-activatable.h"
29 #define DEBUG_DOMAIN "CellRendererActivatable"
31 static void empathy_cell_renderer_activatable_init (EmpathyCellRendererActivatable *cell);
32 static void empathy_cell_renderer_activatable_class_init (EmpathyCellRendererActivatableClass *klass);
33 static gboolean cell_renderer_activatable_activate (GtkCellRenderer *cell,
37 GdkRectangle *background_area,
38 GdkRectangle *cell_area,
39 GtkCellRendererState flags);
46 static guint signals[LAST_SIGNAL];
48 G_DEFINE_TYPE (EmpathyCellRendererActivatable, empathy_cell_renderer_activatable, GTK_TYPE_CELL_RENDERER_PIXBUF)
51 empathy_cell_renderer_activatable_init (EmpathyCellRendererActivatable *cell)
56 "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE,
62 empathy_cell_renderer_activatable_class_init (EmpathyCellRendererActivatableClass *klass)
64 GtkCellRendererClass *cell_class;
66 cell_class = GTK_CELL_RENDERER_CLASS (klass);
67 cell_class->activate = cell_renderer_activatable_activate;
69 signals[PATH_ACTIVATED] =
70 g_signal_new ("path-activated",
71 G_TYPE_FROM_CLASS (klass),
75 g_cclosure_marshal_VOID__STRING,
81 empathy_cell_renderer_activatable_new (void)
83 return g_object_new (EMPATHY_TYPE_CELL_RENDERER_ACTIVATABLE, NULL);
87 cell_renderer_activatable_activate (GtkCellRenderer *cell,
90 const gchar *path_string,
91 GdkRectangle *background_area,
92 GdkRectangle *cell_area,
93 GtkCellRendererState flags)
95 EmpathyCellRendererActivatable *activatable;
96 gint ex, ey, bx, by, bw, bh;
98 activatable = EMPATHY_CELL_RENDERER_ACTIVATABLE (cell);
100 if (!GTK_IS_TREE_VIEW (widget) ||
101 event->type != GDK_BUTTON_PRESS) {
105 ex = (gint) ((GdkEventButton *) event)->x;
106 ey = (gint) ((GdkEventButton *) event)->y;
107 bx = background_area->x;
108 by = background_area->y;
109 bw = background_area->width;
110 bh = background_area->height;
112 if (ex < bx || ex > (bx+bw) || ey < by || ey > (by+bh)){
113 /* Click wasn't on the icon */
117 g_signal_emit (activatable, signals[PATH_ACTIVATED], 0, path_string);