]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-cell-renderer-activatable.c
Updatre python binding
[empathy.git] / libempathy-gtk / empathy-cell-renderer-activatable.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007 Raphael Slinckx <raphael@slinckx.net>
4  * Copyright (C) 2007-2008 Collabora Ltd.
5  *
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.
10  *
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.
15  *
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
19  *
20  * Authors: Raphael Slinckx <raphael@slinckx.net>
21  */
22
23 #include <gtk/gtktreeview.h>
24
25 #include <libempathy/empathy-debug.h>
26
27 #include "empathy-cell-renderer-activatable.h"
28
29 #define DEBUG_DOMAIN "CellRendererActivatable"
30
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,
34                                                               GdkEvent                            *event,
35                                                               GtkWidget                           *widget,
36                                                               const gchar                         *path,
37                                                               GdkRectangle                        *background_area,
38                                                               GdkRectangle                        *cell_area,
39                                                               GtkCellRendererState                 flags);
40
41 enum {
42         PATH_ACTIVATED,
43         LAST_SIGNAL
44 };
45
46 static guint signals[LAST_SIGNAL];
47
48 G_DEFINE_TYPE (EmpathyCellRendererActivatable, empathy_cell_renderer_activatable, GTK_TYPE_CELL_RENDERER_PIXBUF)
49
50 static void
51 empathy_cell_renderer_activatable_init (EmpathyCellRendererActivatable *cell)
52 {
53         g_object_set (cell,
54                       "xpad", 0,
55                       "ypad", 0,
56                       "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE,
57                       "follow-state", TRUE,
58                       NULL);
59 }
60
61 static void
62 empathy_cell_renderer_activatable_class_init (EmpathyCellRendererActivatableClass *klass)
63 {
64         GtkCellRendererClass *cell_class;
65
66         cell_class = GTK_CELL_RENDERER_CLASS (klass);
67         cell_class->activate = cell_renderer_activatable_activate;
68
69         signals[PATH_ACTIVATED] =
70                 g_signal_new ("path-activated",
71                               G_TYPE_FROM_CLASS (klass),
72                               G_SIGNAL_RUN_LAST,
73                               0,
74                               NULL, NULL,
75                               g_cclosure_marshal_VOID__STRING,
76                               G_TYPE_NONE,
77                               1, G_TYPE_STRING);
78 }
79
80 GtkCellRenderer *
81 empathy_cell_renderer_activatable_new (void)
82 {
83         return g_object_new (EMPATHY_TYPE_CELL_RENDERER_ACTIVATABLE, NULL);
84 }
85
86 static gboolean
87 cell_renderer_activatable_activate (GtkCellRenderer      *cell,
88                                     GdkEvent             *event,
89                                     GtkWidget            *widget,
90                                     const gchar          *path_string,
91                                     GdkRectangle         *background_area,
92                                     GdkRectangle         *cell_area,
93                                     GtkCellRendererState  flags)
94 {
95         EmpathyCellRendererActivatable *activatable;
96         gint                            ex, ey, bx, by, bw, bh;
97
98         activatable = EMPATHY_CELL_RENDERER_ACTIVATABLE (cell);
99
100         if (!GTK_IS_TREE_VIEW (widget) ||
101             event->type != GDK_BUTTON_PRESS) {
102                 return FALSE;
103         }
104
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;
111
112         if (ex < bx || ex > (bx+bw) || ey < by || ey > (by+bh)){
113                 /* Click wasn't on the icon */
114                 return FALSE;
115         }
116
117         g_signal_emit (activatable, signals[PATH_ACTIVATED], 0, path_string);
118
119         return TRUE;
120 }
121