7cf1af7a877f199217c323e2aac7e29896387a3c
[platform/core/uifw/at-spi2-atk.git] / atk-adaptor / document-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 "common/spi-dbus.h"
29
30 #include "accessible-marshaller.h"
31
32 static DBusMessage *
33 impl_GetLocale (DBusConnection *bus,
34                 DBusMessage *message,
35                 void *user_data)
36 {
37   AtkDocument *document = (AtkDocument *) user_data;
38   const gchar *lc;
39   DBusMessage *reply;
40
41   g_return_val_if_fail (ATK_IS_DOCUMENT (user_data),
42                         droute_not_yet_handled_error (message));
43   lc = atk_document_get_locale (document);
44   if (!lc)
45     lc = "";
46   reply = dbus_message_new_method_return (message);
47   if (reply)
48     {
49       dbus_message_append_args (reply, DBUS_TYPE_STRING, &lc,
50                                 DBUS_TYPE_INVALID);
51     }
52   return reply;
53 }
54
55 static DBusMessage *
56 impl_GetAttributeValue (DBusConnection * bus, DBusMessage * message,
57                         void *user_data)
58 {
59   AtkDocument *document = (AtkDocument *) user_data;
60   DBusError error;
61   gchar *attributename;
62   const gchar *atr;
63   DBusMessage *reply;
64
65   g_return_val_if_fail (ATK_IS_DOCUMENT (user_data),
66                         droute_not_yet_handled_error (message));
67   dbus_error_init (&error);
68   if (!dbus_message_get_args
69       (message, &error, DBUS_TYPE_STRING, &attributename, DBUS_TYPE_INVALID))
70     {
71       return droute_invalid_arguments_error (message);
72     }
73   atr = atk_document_get_attribute_value (document, attributename);
74   if (!atr)
75     atr = "";
76   reply = dbus_message_new_method_return (message);
77   if (reply)
78     {
79       dbus_message_append_args (reply, DBUS_TYPE_STRING, &atr,
80                                 DBUS_TYPE_INVALID);
81     }
82   return reply;
83 }
84
85 static DBusMessage *
86 impl_GetAttributes (DBusConnection * bus, DBusMessage * message,
87                     void *user_data)
88 {
89   AtkDocument *document = (AtkDocument *) user_data;
90   DBusMessage *reply;
91   AtkAttributeSet *attributes;
92   DBusMessageIter iter;
93
94   g_return_val_if_fail (ATK_IS_DOCUMENT (user_data),
95                         droute_not_yet_handled_error (message));
96
97   attributes = atk_document_get_attributes (document);
98
99   reply = dbus_message_new_method_return (message);
100   if (reply)
101     {
102       dbus_message_iter_init_append (reply, &iter);
103       spi_atk_append_attribute_set (&iter, attributes);
104     }
105
106   if (attributes)
107     atk_attribute_set_free (attributes);
108   return reply;
109 }
110
111 static DRouteMethod methods[] = {
112   {impl_GetLocale, "GetLocale"},
113   {impl_GetAttributeValue, "GetAttributeValue"},
114   {impl_GetAttributes, "GetAttributes"},
115   {NULL, NULL}
116 };
117
118 void
119 spi_initialize_document (DRoutePath *path)
120 {
121   droute_path_add_interface (path,
122                              SPI_DBUS_INTERFACE_DOCUMENT,
123                              methods,
124                              NULL);
125 };