evolution-3.6.4/calendar/gui/ea-jump-button.c

No issues found

  1 /*
  2  *
  3  * This program is free software; you can redistribute it and/or
  4  * modify it under the terms of the GNU Lesser General Public
  5  * License as published by the Free Software Foundation; either
  6  * version 2 of the License, or (at your option) version 3.
  7  *
  8  * This program is distributed in the hope that it will be useful,
  9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 11  * Lesser General Public License for more details.
 12  *
 13  * You should have received a copy of the GNU Lesser General Public
 14  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 15  *
 16  *
 17  * Authors:
 18  *		Yang Wu <yang.wu@sun.com>
 19  *
 20  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 21  *
 22  */
 23 
 24 #ifdef HAVE_CONFIG_H
 25 #include <config.h>
 26 #endif
 27 
 28 #include "ea-jump-button.h"
 29 #include "ea-calendar-helpers.h"
 30 #include "ea-week-view.h"
 31 #include "e-week-view.h"
 32 #include <libgnomecanvas/libgnomecanvas.h>
 33 #include <glib/gi18n.h>
 34 
 35 static void ea_jump_button_class_init (EaJumpButtonClass *klass);
 36 
 37 static const gchar * ea_jump_button_get_name (AtkObject *accessible);
 38 static const gchar * ea_jump_button_get_description (AtkObject *accessible);
 39 
 40 /* action interface */
 41 static void                  atk_action_interface_init  (AtkActionIface *iface);
 42 static gboolean              jump_button_do_action      (AtkAction      *action,
 43                                                          gint           i);
 44 static gint                  jump_button_get_n_actions  (AtkAction      *action);
 45 static const gchar * jump_button_get_keybinding (AtkAction      *action,
 46                                                          gint           i);
 47 
 48 static gpointer parent_class = NULL;
 49 
 50 GType
 51 ea_jump_button_get_type (void)
 52 {
 53 	static GType type = 0;
 54 	AtkObjectFactory *factory;
 55 	GTypeQuery query;
 56 	GType derived_atk_type;
 57 
 58 	if (!type) {
 59 		static GTypeInfo tinfo = {
 60 			sizeof (EaJumpButtonClass),
 61 			(GBaseInitFunc) NULL,
 62 			(GBaseFinalizeFunc) NULL,
 63 			(GClassInitFunc) ea_jump_button_class_init,
 64 			(GClassFinalizeFunc) NULL,
 65 			/* class_data */ NULL,
 66 			sizeof (EaJumpButton),
 67 			/* n_preallocs */ 0,
 68 			(GInstanceInitFunc) NULL,
 69 			/* value_table */ NULL
 70 		};
 71 
 72 		static const GInterfaceInfo atk_action_info = {
 73 			(GInterfaceInitFunc) atk_action_interface_init,
 74 			(GInterfaceFinalizeFunc) NULL,
 75 			NULL
 76 		};
 77 
 78 		/*
 79 		 * Figure out the size of the class and instance
 80 		 * we are run-time deriving from (atk object for
 81 		 * GNOME_TYPE_CANVAS_ITEM, in this case)
 82 		 */
 83 
 84 		factory = atk_registry_get_factory (
 85 			atk_get_default_registry (), GNOME_TYPE_CANVAS_ITEM);
 86 		derived_atk_type =
 87 			atk_object_factory_get_accessible_type (factory);
 88 		g_type_query (derived_atk_type, &query);
 89 
 90 		tinfo.class_size = query.class_size;
 91 		tinfo.instance_size = query.instance_size;
 92 
 93 		/* we inherit the component and other
 94 		 * interfaces from GNOME_TYPE_CANVAS_ITEM */
 95 		type = g_type_register_static (
 96 			derived_atk_type, "EaJumpButton", &tinfo, 0);
 97 
 98 		g_type_add_interface_static (
 99 			type, ATK_TYPE_ACTION, &atk_action_info);
100 	}
101 
102 	return type;
103 }
104 
105 static void
106 ea_jump_button_class_init (EaJumpButtonClass *klass)
107 {
108 	AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
109 
110 	parent_class = g_type_class_peek_parent (klass);
111 
112 	class->get_name = ea_jump_button_get_name;
113 	class->get_description = ea_jump_button_get_description;
114 }
115 
116 AtkObject *
117 ea_jump_button_new (GObject *obj)
118 {
119 	AtkObject *atk_obj = NULL;
120 	GObject *target_obj;
121 
122 	g_return_val_if_fail (GNOME_IS_CANVAS_ITEM (obj), NULL);
123 
124 	target_obj = obj;
125 	atk_obj = g_object_get_data (target_obj, "accessible-object");
126 
127 	if (!atk_obj) {
128 		static AtkRole event_role = ATK_ROLE_INVALID;
129 		atk_obj = ATK_OBJECT (
130 			g_object_new (EA_TYPE_JUMP_BUTTON, NULL));
131 		atk_object_initialize (atk_obj, target_obj);
132 		if (event_role == ATK_ROLE_INVALID)
133 			event_role = atk_role_register ("Jump Button");
134 		atk_obj->role = event_role;
135 	}
136 
137 	/* The registered factory for GNOME_TYPE_CANVAS_ITEM cannot create
138 	 * an EaJumpbutton, we should save the EaJumpbutton object in it. */
139 	g_object_set_data (obj, "accessible-object", atk_obj);
140 
141 	return atk_obj;
142 }
143 
144 static const gchar *
145 ea_jump_button_get_name (AtkObject *accessible)
146 {
147 	g_return_val_if_fail (EA_IS_JUMP_BUTTON (accessible), NULL);
148 
149 	if (accessible->name)
150 		return accessible->name;
151 	return _("Jump button");
152 }
153 
154 static const gchar *
155 ea_jump_button_get_description (AtkObject *accessible)
156 {
157 	if (accessible->description)
158 		return accessible->description;
159 
160 	return _("Click here, you can find more events.");
161 }
162 
163 static void
164 atk_action_interface_init (AtkActionIface *iface)
165 {
166   g_return_if_fail (iface != NULL);
167 
168   iface->do_action = jump_button_do_action;
169   iface->get_n_actions = jump_button_get_n_actions;
170   iface->get_keybinding = jump_button_get_keybinding;
171 }
172 
173 static gboolean
174 jump_button_do_action (AtkAction *action,
175                        gint i)
176 {
177   gboolean return_value = TRUE;
178   AtkGObjectAccessible *atk_gobj;
179   GObject *g_obj;
180   GnomeCanvasItem *item;
181   ECalendarView *cal_view;
182   EWeekView *week_view;
183 
184   atk_gobj = ATK_GOBJECT_ACCESSIBLE (action);
185   g_obj = atk_gobject_accessible_get_object (atk_gobj);
186   if (!g_obj)
187 	  return FALSE;
188 
189   item = GNOME_CANVAS_ITEM (g_obj);
190   cal_view = ea_calendar_helpers_get_cal_view_from (GNOME_CANVAS_ITEM (item));
191   week_view = E_WEEK_VIEW (cal_view);
192 
193   switch (i)
194     {
195     case 0:
196 	    e_week_view_jump_to_button_item (week_view, GNOME_CANVAS_ITEM (item));
197 	    break;
198     default:
199 	    return_value = FALSE;
200       break;
201     }
202   return return_value;
203 }
204 
205 static gint
206 jump_button_get_n_actions (AtkAction *action)
207 {
208   return 1;
209 }
210 
211 static const gchar *
212 jump_button_get_keybinding (AtkAction *action,
213                             gint i)
214 {
215   const gchar *return_value = NULL;
216 
217   switch (i)
218     {
219     case 0:
220       {
221 	      return_value = "space or enter";
222 	      break;
223       }
224     default:
225       break;
226     }
227   return return_value;
228 }