Bug 793125 - Crash due to popup menus left attached too long
[evolution.git] / src / calendar / gui / ea-jump-button.c
blobbc5f86b712ff892eed88a551f77560ee135b2ecc
1 /*
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU Lesser General Public License as published by
5 * the Free Software Foundation.
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10 * for more details.
12 * You should have received a copy of the GNU Lesser General Public License
13 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 * Authors:
17 * Yang Wu <yang.wu@sun.com>
19 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
23 #include "evolution-config.h"
25 #include "ea-jump-button.h"
26 #include "ea-calendar-helpers.h"
27 #include "ea-week-view.h"
28 #include "e-week-view.h"
29 #include <libgnomecanvas/libgnomecanvas.h>
30 #include <glib/gi18n.h>
32 static void ea_jump_button_class_init (EaJumpButtonClass *klass);
34 static const gchar * ea_jump_button_get_name (AtkObject *accessible);
35 static const gchar * ea_jump_button_get_description (AtkObject *accessible);
37 /* action interface */
38 static void atk_action_interface_init (AtkActionIface *iface);
39 static gboolean jump_button_do_action (AtkAction *action,
40 gint i);
41 static gint jump_button_get_n_actions (AtkAction *action);
42 static const gchar * jump_button_get_keybinding (AtkAction *action,
43 gint i);
45 static gpointer parent_class = NULL;
47 GType
48 ea_jump_button_get_type (void)
50 static GType type = 0;
51 AtkObjectFactory *factory;
52 GTypeQuery query;
53 GType derived_atk_type;
55 if (!type) {
56 static GTypeInfo tinfo = {
57 sizeof (EaJumpButtonClass),
58 (GBaseInitFunc) NULL,
59 (GBaseFinalizeFunc) NULL,
60 (GClassInitFunc) ea_jump_button_class_init,
61 (GClassFinalizeFunc) NULL,
62 /* class_data */ NULL,
63 sizeof (EaJumpButton),
64 /* n_preallocs */ 0,
65 (GInstanceInitFunc) NULL,
66 /* value_table */ NULL
69 static const GInterfaceInfo atk_action_info = {
70 (GInterfaceInitFunc) atk_action_interface_init,
71 (GInterfaceFinalizeFunc) NULL,
72 NULL
76 * Figure out the size of the class and instance
77 * we are run-time deriving from (atk object for
78 * GNOME_TYPE_CANVAS_ITEM, in this case)
81 factory = atk_registry_get_factory (
82 atk_get_default_registry (), GNOME_TYPE_CANVAS_ITEM);
83 derived_atk_type =
84 atk_object_factory_get_accessible_type (factory);
85 g_type_query (derived_atk_type, &query);
87 tinfo.class_size = query.class_size;
88 tinfo.instance_size = query.instance_size;
90 /* we inherit the component and other
91 * interfaces from GNOME_TYPE_CANVAS_ITEM */
92 type = g_type_register_static (
93 derived_atk_type, "EaJumpButton", &tinfo, 0);
95 g_type_add_interface_static (
96 type, ATK_TYPE_ACTION, &atk_action_info);
99 return type;
102 static void
103 ea_jump_button_class_init (EaJumpButtonClass *klass)
105 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
107 parent_class = g_type_class_peek_parent (klass);
109 class->get_name = ea_jump_button_get_name;
110 class->get_description = ea_jump_button_get_description;
113 AtkObject *
114 ea_jump_button_new (GObject *obj)
116 AtkObject *atk_obj = NULL;
117 GObject *target_obj;
119 g_return_val_if_fail (GNOME_IS_CANVAS_ITEM (obj), NULL);
121 target_obj = obj;
122 atk_obj = g_object_get_data (target_obj, "accessible-object");
124 if (!atk_obj) {
125 static AtkRole event_role = ATK_ROLE_INVALID;
126 atk_obj = ATK_OBJECT (
127 g_object_new (EA_TYPE_JUMP_BUTTON, NULL));
128 atk_object_initialize (atk_obj, target_obj);
129 if (event_role == ATK_ROLE_INVALID)
130 event_role = atk_role_register ("Jump Button");
131 atk_obj->role = event_role;
134 /* The registered factory for GNOME_TYPE_CANVAS_ITEM cannot create
135 * an EaJumpbutton, we should save the EaJumpbutton object in it. */
136 g_object_set_data (obj, "accessible-object", atk_obj);
138 return atk_obj;
141 static const gchar *
142 ea_jump_button_get_name (AtkObject *accessible)
144 g_return_val_if_fail (EA_IS_JUMP_BUTTON (accessible), NULL);
146 if (accessible->name)
147 return accessible->name;
148 return _("Jump button");
151 static const gchar *
152 ea_jump_button_get_description (AtkObject *accessible)
154 if (accessible->description)
155 return accessible->description;
157 return _("Click here, you can find more events.");
160 static void
161 atk_action_interface_init (AtkActionIface *iface)
163 g_return_if_fail (iface != NULL);
165 iface->do_action = jump_button_do_action;
166 iface->get_n_actions = jump_button_get_n_actions;
167 iface->get_keybinding = jump_button_get_keybinding;
170 static gboolean
171 jump_button_do_action (AtkAction *action,
172 gint i)
174 gboolean return_value = TRUE;
175 AtkGObjectAccessible *atk_gobj;
176 GObject *g_obj;
177 GnomeCanvasItem *item;
178 ECalendarView *cal_view;
179 EWeekView *week_view;
181 atk_gobj = ATK_GOBJECT_ACCESSIBLE (action);
182 g_obj = atk_gobject_accessible_get_object (atk_gobj);
183 if (!g_obj)
184 return FALSE;
186 item = GNOME_CANVAS_ITEM (g_obj);
187 cal_view = ea_calendar_helpers_get_cal_view_from (GNOME_CANVAS_ITEM (item));
188 week_view = E_WEEK_VIEW (cal_view);
190 switch (i)
192 case 0:
193 e_week_view_jump_to_button_item (week_view, GNOME_CANVAS_ITEM (item));
194 break;
195 default:
196 return_value = FALSE;
197 break;
199 return return_value;
202 static gint
203 jump_button_get_n_actions (AtkAction *action)
205 return 1;
208 static const gchar *
209 jump_button_get_keybinding (AtkAction *action,
210 gint i)
212 const gchar *return_value = NULL;
214 switch (i)
216 case 0:
218 return_value = "space or enter";
219 break;
221 default:
222 break;
224 return return_value;