]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-cell-renderer-activatable.c
Don't forget to show the contact widget in some places
[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 "empathy-cell-renderer-activatable.h"
26
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,
30                                                               GdkEvent                            *event,
31                                                               GtkWidget                           *widget,
32                                                               const gchar                         *path,
33                                                               GdkRectangle                        *background_area,
34                                                               GdkRectangle                        *cell_area,
35                                                               GtkCellRendererState                 flags);
36
37 enum {
38         PATH_ACTIVATED,
39         LAST_SIGNAL
40 };
41
42 static guint signals[LAST_SIGNAL];
43
44 G_DEFINE_TYPE (EmpathyCellRendererActivatable, empathy_cell_renderer_activatable, GTK_TYPE_CELL_RENDERER_PIXBUF)
45
46 static void
47 empathy_cell_renderer_activatable_init (EmpathyCellRendererActivatable *cell)
48 {
49         g_object_set (cell,
50                       "xpad", 0,
51                       "ypad", 0,
52                       "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE,
53                       "follow-state", TRUE,
54                       NULL);
55 }
56
57 static void
58 empathy_cell_renderer_activatable_class_init (EmpathyCellRendererActivatableClass *klass)
59 {
60         GtkCellRendererClass *cell_class;
61
62         cell_class = GTK_CELL_RENDERER_CLASS (klass);
63         cell_class->activate = cell_renderer_activatable_activate;
64
65         signals[PATH_ACTIVATED] =
66                 g_signal_new ("path-activated",
67                               G_TYPE_FROM_CLASS (klass),
68                               G_SIGNAL_RUN_LAST,
69                               0,
70                               NULL, NULL,
71                               g_cclosure_marshal_VOID__STRING,
72                               G_TYPE_NONE,
73                               1, G_TYPE_STRING);
74 }
75
76 GtkCellRenderer *
77 empathy_cell_renderer_activatable_new (void)
78 {
79         return g_object_new (EMPATHY_TYPE_CELL_RENDERER_ACTIVATABLE, NULL);
80 }
81
82 static gboolean
83 cell_renderer_activatable_activate (GtkCellRenderer      *cell,
84                                     GdkEvent             *event,
85                                     GtkWidget            *widget,
86                                     const gchar          *path_string,
87                                     GdkRectangle         *background_area,
88                                     GdkRectangle         *cell_area,
89                                     GtkCellRendererState  flags)
90 {
91         EmpathyCellRendererActivatable *activatable;
92         gint                            ex, ey, bx, by, bw, bh;
93
94         activatable = EMPATHY_CELL_RENDERER_ACTIVATABLE (cell);
95
96         if (!GTK_IS_TREE_VIEW (widget) || event == NULL || 
97             event->type != GDK_BUTTON_PRESS) {
98                 return FALSE;
99         }
100
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;
107
108         if (ex < bx || ex > (bx+bw) || ey < by || ey > (by+bh)){
109                 /* Click wasn't on the icon */
110                 return FALSE;
111         }
112
113         g_signal_emit (activatable, signals[PATH_ACTIVATED], 0, path_string);
114
115         return TRUE;
116 }
117