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