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 program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program 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 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
21 * Authors: Raphael Slinckx <raphael@slinckx.net>
24 #include <gtk/gtktreeview.h>
26 #include <libempathy/empathy-debug.h>
28 #include "empathy-cell-renderer-activatable.h"
30 #define DEBUG_DOMAIN "CellRendererActivatable"
32 static void empathy_cell_renderer_activatable_init (EmpathyCellRendererActivatable *cell);
33 static void empathy_cell_renderer_activatable_class_init (EmpathyCellRendererActivatableClass *klass);
34 static gboolean cell_renderer_activatable_activate (GtkCellRenderer *cell,
38 GdkRectangle *background_area,
39 GdkRectangle *cell_area,
40 GtkCellRendererState flags);
47 static guint signals[LAST_SIGNAL];
49 G_DEFINE_TYPE (EmpathyCellRendererActivatable, empathy_cell_renderer_activatable, GTK_TYPE_CELL_RENDERER_PIXBUF)
52 empathy_cell_renderer_activatable_init (EmpathyCellRendererActivatable *cell)
57 "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE,
63 empathy_cell_renderer_activatable_class_init (EmpathyCellRendererActivatableClass *klass)
65 GtkCellRendererClass *cell_class;
67 cell_class = GTK_CELL_RENDERER_CLASS (klass);
68 cell_class->activate = cell_renderer_activatable_activate;
70 signals[PATH_ACTIVATED] =
71 g_signal_new ("path-activated",
72 G_TYPE_FROM_CLASS (klass),
76 g_cclosure_marshal_VOID__STRING,
82 empathy_cell_renderer_activatable_new (void)
84 return g_object_new (EMPATHY_TYPE_CELL_RENDERER_ACTIVATABLE, NULL);
88 cell_renderer_activatable_activate (GtkCellRenderer *cell,
91 const gchar *path_string,
92 GdkRectangle *background_area,
93 GdkRectangle *cell_area,
94 GtkCellRendererState flags)
96 EmpathyCellRendererActivatable *activatable;
97 gint ex, ey, bx, by, bw, bh;
99 activatable = EMPATHY_CELL_RENDERER_ACTIVATABLE (cell);
101 if (!GTK_IS_TREE_VIEW (widget) ||
102 event->type != GDK_BUTTON_PRESS) {
106 ex = (gint) ((GdkEventButton *) event)->x;
107 ey = (gint) ((GdkEventButton *) event)->y;
108 bx = background_area->x;
109 by = background_area->y;
110 bw = background_area->width;
111 bh = background_area->height;
113 if (ex < bx || ex > (bx+bw) || ey < by || ey > (by+bh)){
114 /* Click wasn't on the icon */
118 g_signal_emit (activatable, signals[PATH_ACTIVATED], 0, path_string);