62b0c81776a04b02c79cadfdab1a9fdc19c41798
[platform/upstream/at-spi2-atk.git] / tests / dummyatk / my-atk-document.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; https://wiki.gnome.org/Accessibility)
4  *
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include <glib-object.h>
24 #include <atk/atk.h>
25
26 #include "my-atk-object.h"
27 #include "my-atk-document.h"
28
29 static void atk_document_interface_init (AtkDocumentIface *iface);
30
31 G_DEFINE_TYPE_WITH_CODE (MyAtkDocument,
32                          my_atk_document,
33                          MY_TYPE_ATK_OBJECT,
34                          G_IMPLEMENT_INTERFACE (ATK_TYPE_DOCUMENT,
35                              atk_document_interface_init));
36
37 void
38 my_atk_set_document (AtkDocument *obj, gint page, gint page_num)
39 {
40   g_return_if_fail (MY_IS_ATK_DOCUMENT(obj));
41   MyAtkDocument *self = MY_ATK_DOCUMENT (obj);
42
43   self->pages = page;
44   self->current_page = page_num;
45
46   AtkAttribute *attr1, *attr2;
47   attr1 = g_malloc (sizeof (AtkAttribute));
48   attr1->name = g_strdup ("atspi1");
49   attr1->value = g_strdup ("test1");
50
51   attr2 = g_malloc (sizeof (AtkAttribute));
52   attr2->name = g_strdup ("atspi2");
53   attr2->value = g_strdup ("test2");
54
55   self->attributes = g_slist_append (NULL, attr1);
56   self->attributes = g_slist_append (self->attributes, attr2);
57 }
58
59 static void
60 my_atk_document_init (MyAtkDocument *obj)
61 {
62   obj->disposed = FALSE;
63   obj->locale = NULL;
64   obj->document_type = NULL;
65   obj->pages = 0;
66   obj->current_page = 0;
67 }
68
69 AtkAttributeSet *
70 my_atk_document_get_document_attributes (AtkDocument *document)
71 {
72   MyAtkDocument *self = MY_ATK_DOCUMENT (document);
73
74   return self->attributes;
75 }
76
77 const gchar *
78 my_atk_document_get_document_attribute_value (AtkDocument *document, const gchar *value)
79 {
80   AtkAttributeSet *attr = my_atk_document_get_document_attributes (document);
81   GSList *cur_attr = (GSList *) attr;
82   AtkAttribute *at;
83
84   while (cur_attr) {
85     at = (AtkAttribute *) cur_attr->data;
86     if (!g_strcmp0 (at->name, value)) {
87       return at->value;
88     }
89     cur_attr = cur_attr->next;
90   }
91   return NULL;
92 }
93
94 gboolean
95 my_atk_document_set_document_attribute (AtkDocument *document, const gchar *attribute_name, const gchar *attribute_value)
96 {
97   return FALSE;
98 }
99
100 gint
101 my_atk_document_get_current_page_number (AtkDocument *document)
102 {
103   return 0;
104 }
105
106 gint
107 my_atk_document_get_page_count (AtkDocument *document)
108 {
109   return 0;
110 }
111
112 const gchar *
113 my_atk_document_get_document_locale (AtkDocument *document)
114 {
115
116   return g_strdup("document_locale");
117 }
118
119 static void
120 atk_document_interface_init(AtkDocumentIface *iface)
121 {
122   if(!iface) return;
123
124   iface->get_document_locale = my_atk_document_get_document_locale;
125   iface->get_document_attributes = my_atk_document_get_document_attributes;
126   iface->get_document_attribute_value = my_atk_document_get_document_attribute_value;
127   iface->set_document_attribute = my_atk_document_set_document_attribute;
128   iface->get_current_page_number = my_atk_document_get_current_page_number;
129   iface->get_page_count = my_atk_document_get_page_count;
130 }
131
132 static void
133 my_atk_document_initialize(AtkObject *obj, gpointer data)
134 {
135 }
136
137 static void
138 my_atk_document_finalize(GObject *object)
139 {
140 }
141
142 static void
143 my_atk_document_class_init(MyAtkDocumentClass *my_class)
144 {
145   AtkObjectClass *atk_class = ATK_OBJECT_CLASS(my_class);
146   GObjectClass *gobject_class = G_OBJECT_CLASS(my_class);
147
148   gobject_class->finalize = my_atk_document_finalize;
149
150   atk_class->initialize = my_atk_document_initialize;
151 }
152