Support sending data with events
[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 #include "bridge.h"
28
29 #include "spi-dbus.h"
30 #include "object.h"
31 #include "introspection.h"
32
33 static dbus_bool_t
34 impl_get_CurrentPageNumber (DBusMessageIter * iter, void *user_data)
35 {
36   AtkDocument *document = (AtkDocument *) user_data;
37   g_return_val_if_fail (ATK_IS_DOCUMENT (user_data), FALSE);
38   return droute_return_v_int32 (iter, atk_document_get_current_page_number (document));
39 }
40
41 static dbus_bool_t
42 impl_get_PageCount (DBusMessageIter * iter, void *user_data)
43 {
44   AtkDocument *document = (AtkDocument *) user_data;
45   g_return_val_if_fail (ATK_IS_DOCUMENT (user_data), FALSE);
46   return droute_return_v_int32 (iter, atk_document_get_page_count (document));
47 }
48
49 static DBusMessage *
50 impl_GetLocale (DBusConnection * bus, DBusMessage * message, void *user_data)
51 {
52   AtkDocument *document = (AtkDocument *) user_data;
53   const gchar *lc;
54   DBusMessage *reply;
55
56   g_return_val_if_fail (ATK_IS_DOCUMENT (user_data),
57                         droute_not_yet_handled_error (message));
58   lc = atk_document_get_locale (document);
59   if (!lc)
60     lc = "";
61   reply = dbus_message_new_method_return (message);
62   if (reply)
63     {
64       dbus_message_append_args (reply, DBUS_TYPE_STRING, &lc,
65                                 DBUS_TYPE_INVALID);
66     }
67   return reply;
68 }
69
70 static DBusMessage *
71 impl_GetAttributeValue (DBusConnection * bus, DBusMessage * message,
72                         void *user_data)
73 {
74   AtkDocument *document = (AtkDocument *) user_data;
75   gchar *attributename;
76   const gchar *atr;
77   DBusMessage *reply;
78
79   g_return_val_if_fail (ATK_IS_DOCUMENT (user_data),
80                         droute_not_yet_handled_error (message));
81   if (!dbus_message_get_args
82       (message, NULL, DBUS_TYPE_STRING, &attributename, DBUS_TYPE_INVALID))
83     {
84       return droute_invalid_arguments_error (message);
85     }
86   atr = atk_document_get_attribute_value (document, attributename);
87   if (!atr)
88     atr = "";
89   reply = dbus_message_new_method_return (message);
90   if (reply)
91     {
92       dbus_message_append_args (reply, DBUS_TYPE_STRING, &atr,
93                                 DBUS_TYPE_INVALID);
94     }
95   return reply;
96 }
97
98 static DBusMessage *
99 impl_GetAttributes (DBusConnection * bus, DBusMessage * message,
100                     void *user_data)
101 {
102   AtkDocument *document = (AtkDocument *) user_data;
103   DBusMessage *reply;
104   AtkAttributeSet *attributes;
105   DBusMessageIter iter;
106
107   g_return_val_if_fail (ATK_IS_DOCUMENT (user_data),
108                         droute_not_yet_handled_error (message));
109
110   attributes = atk_document_get_attributes (document);
111
112   reply = dbus_message_new_method_return (message);
113   if (reply)
114     {
115       dbus_message_iter_init_append (reply, &iter);
116       spi_object_append_attribute_set (&iter, attributes);
117     }
118
119   if (attributes)
120     atk_attribute_set_free (attributes);
121   return reply;
122 }
123
124 static DRouteMethod methods[] = {
125   {impl_GetLocale, "GetLocale"},
126   {impl_GetAttributeValue, "GetAttributeValue"},
127   {impl_GetAttributes, "GetAttributes"},
128   {NULL, NULL}
129 };
130
131 static DRouteProperty properties[] = {
132   {impl_get_CurrentPageNumber, NULL, "CurrentPageNumber"},
133   {impl_get_PageCount, NULL, "PageCount"},
134   {NULL, NULL, NULL}
135 };
136
137 void
138 spi_initialize_document (DRoutePath * path)
139 {
140   droute_path_add_interface (path,
141                              ATSPI_DBUS_INTERFACE_DOCUMENT, spi_org_a11y_atspi_Document, methods, properties);
142 };