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