e31266f4786a973f8ab2b459e969ffadd92d0545
[platform/upstream/at-spi2-atk.git] / atk-adaptor / adaptors / hypertext-adaptor.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2008 Novell, Inc.
6  * Copyright 2001, 2002 Sun Microsystems Inc.,
7  * Copyright 2001, 2002 Ximian, Inc.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22  * Boston, MA 02111-1307, USA.
23  */
24
25 #include <atk/atk.h>
26 #include <droute/droute.h>
27 #include "bridge.h"
28
29 #include "spi-dbus.h"
30 #include "object.h"
31
32 #include "introspection.h"
33
34 static DBusMessage *
35 impl_GetNLinks (DBusConnection * bus, DBusMessage * message, void *user_data)
36 {
37   AtkHypertext *hypertext = (AtkHypertext *) user_data;
38   gint rv;
39   DBusMessage *reply;
40
41   g_return_val_if_fail (ATK_IS_HYPERTEXT (user_data),
42                         droute_not_yet_handled_error (message));
43   rv = atk_hypertext_get_n_links (hypertext);
44   reply = dbus_message_new_method_return (message);
45   if (reply)
46     {
47       dbus_message_append_args (reply, DBUS_TYPE_INT32, &rv,
48                                 DBUS_TYPE_INVALID);
49     }
50   return reply;
51 }
52
53 static DBusMessage *
54 impl_GetLink (DBusConnection * bus, DBusMessage * message, void *user_data)
55 {
56   AtkHypertext *hypertext = (AtkHypertext *) user_data;
57   dbus_int32_t linkIndex;
58   AtkHyperlink *link;
59
60   g_return_val_if_fail (ATK_IS_HYPERTEXT (user_data),
61                         droute_not_yet_handled_error (message));
62   if (!dbus_message_get_args
63       (message, NULL, DBUS_TYPE_INT32, &linkIndex, DBUS_TYPE_INVALID))
64     {
65       return droute_invalid_arguments_error (message);
66     }
67   link = atk_hypertext_get_link (hypertext, linkIndex);
68   /*The above line doesn't ref the link, and the next call is going to unref*/
69   if (link)
70     g_object_ref (link);
71   return spi_hyperlink_return_reference (message, link);
72 }
73
74 static DBusMessage *
75 impl_GetLinkIndex (DBusConnection * bus, DBusMessage * message,
76                    void *user_data)
77 {
78   AtkHypertext *hypertext = (AtkHypertext *) user_data;
79   dbus_int32_t characterIndex;
80   dbus_int32_t rv;
81   DBusMessage *reply;
82
83   g_return_val_if_fail (ATK_IS_HYPERTEXT (user_data),
84                         droute_not_yet_handled_error (message));
85   if (!dbus_message_get_args
86       (message, NULL, DBUS_TYPE_INT32, &characterIndex, DBUS_TYPE_INVALID))
87     {
88       return droute_invalid_arguments_error (message);
89     }
90   rv = atk_hypertext_get_link_index (hypertext, characterIndex);
91   reply = dbus_message_new_method_return (message);
92   if (reply)
93     {
94       dbus_message_append_args (reply, DBUS_TYPE_INT32, &rv,
95                                 DBUS_TYPE_INVALID);
96     }
97   return reply;
98 }
99
100 static DRouteMethod methods[] = {
101   {impl_GetNLinks, "GetNLinks"},
102   {impl_GetLink, "GetLink"},
103   {impl_GetLinkIndex, "GetLinkIndex"},
104   {NULL, NULL}
105 };
106
107 void
108 spi_initialize_hypertext (DRoutePath * path)
109 {
110   spi_atk_add_interface (path,
111                          ATSPI_DBUS_INTERFACE_HYPERTEXT, spi_org_a11y_atspi_Hypertext, methods, NULL);
112 };