09a6d651ecddada7e0c64379ec87df85d7fed09f
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / 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
28 #include "spi-common/spi-dbus.h"
29
30 static DBusMessage *
31 impl_getNLinks (DBusConnection * bus, DBusMessage * message, void *user_data)
32 {
33   AtkHypertext *hypertext = (AtkHypertext *) user_data;
34   gint rv;
35   DBusMessage *reply;
36
37   g_return_val_if_fail (ATK_IS_HYPERTEXT (user_data),
38                         droute_not_yet_handled_error (message));
39   rv = atk_hypertext_get_n_links (hypertext);
40   reply = dbus_message_new_method_return (message);
41   if (reply)
42     {
43       dbus_message_append_args (reply, DBUS_TYPE_INT32, &rv,
44                                 DBUS_TYPE_INVALID);
45     }
46   return reply;
47 }
48
49 static DBusMessage *
50 impl_getLink (DBusConnection * bus, DBusMessage * message, void *user_data)
51 {
52   AtkHypertext *hypertext = (AtkHypertext *) user_data;
53   DBusError error;
54   dbus_int32_t linkIndex;
55   AtkHyperlink *link;
56
57   g_return_val_if_fail (ATK_IS_HYPERTEXT (user_data),
58                         droute_not_yet_handled_error (message));
59   dbus_error_init (&error);
60   if (!dbus_message_get_args
61       (message, &error, DBUS_TYPE_INT32, &linkIndex, DBUS_TYPE_INVALID))
62     {
63       return droute_invalid_arguments_error (message);
64     }
65   link = atk_hypertext_get_link (hypertext, linkIndex);
66   return NULL;  // TODO
67   //return spi_dbus_return_object (message, ATK_OBJECT (link), FALSE);
68 }
69
70 static DBusMessage *
71 impl_getLinkIndex (DBusConnection * bus, DBusMessage * message,
72                    void *user_data)
73 {
74   AtkHypertext *hypertext = (AtkHypertext *) user_data;
75   DBusError error;
76   dbus_int32_t characterIndex;
77   dbus_int32_t rv;
78   DBusMessage *reply;
79
80   g_return_val_if_fail (ATK_IS_HYPERTEXT (user_data),
81                         droute_not_yet_handled_error (message));
82   dbus_error_init (&error);
83   if (!dbus_message_get_args
84       (message, &error, DBUS_TYPE_INT32, &characterIndex, DBUS_TYPE_INVALID))
85     {
86       return droute_invalid_arguments_error (message);
87     }
88   rv = atk_hypertext_get_link_index (hypertext, characterIndex);
89   reply = dbus_message_new_method_return (message);
90   if (reply)
91     {
92       dbus_message_append_args (reply, DBUS_TYPE_INT32, &rv,
93                                 DBUS_TYPE_INVALID);
94     }
95   return reply;
96 }
97
98 static DRouteMethod methods[] = {
99   {impl_getNLinks, "getNLinks"},
100   {impl_getLink, "getLink"},
101   {impl_getLinkIndex, "getLinkIndex"},
102   {NULL, NULL}
103 };
104
105 void
106 spi_initialize_hypertext (DRoutePath *path)
107 {
108   droute_path_add_interface (path,
109                              SPI_DBUS_INTERFACE_HYPERTEXT,
110                              methods,
111                              NULL);
112 };