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