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 Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2.1 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
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library; if not, write to the
19
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
 * Boston, MA 02110-1301, USA.
21
 */
22

            
23
#include <atk/atk.h>
24
#include <glib-object.h>
25

            
26
#include "my-atk-document.h"
27
#include "my-atk-object.h"
28

            
29
static void atk_document_interface_init (AtkDocumentIface *iface);
30

            
31
5
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
5
my_atk_set_document (AtkDocument *obj, gint page, gint page_num)
39
{
40
5
  g_return_if_fail (MY_IS_ATK_DOCUMENT (obj));
41
5
  MyAtkDocument *self = MY_ATK_DOCUMENT (obj);
42

            
43
5
  self->pages = page;
44
5
  self->current_page = page_num;
45

            
46
  AtkAttribute *attr1, *attr2;
47
5
  attr1 = g_malloc (sizeof (AtkAttribute));
48
5
  attr1->name = g_strdup ("atspi1");
49
5
  attr1->value = g_strdup ("test1");
50

            
51
5
  attr2 = g_malloc (sizeof (AtkAttribute));
52
5
  attr2->name = g_strdup ("atspi2");
53
5
  attr2->value = g_strdup ("test2");
54

            
55
5
  self->attributes = g_slist_append (NULL, attr1);
56
5
  self->attributes = g_slist_append (self->attributes, attr2);
57
}
58

            
59
static void
60
5
my_atk_document_init (MyAtkDocument *obj)
61
{
62
5
  obj->disposed = FALSE;
63
5
  obj->locale = NULL;
64
5
  obj->document_type = NULL;
65
5
  obj->pages = 0;
66
5
  obj->current_page = 0;
67
5
}
68

            
69
AtkAttributeSet *
70
3
my_atk_document_get_document_attributes (AtkDocument *document)
71
{
72
3
  MyAtkDocument *self = MY_ATK_DOCUMENT (document);
73

            
74
3
  return self->attributes;
75
}
76

            
77
const gchar *
78
2
my_atk_document_get_document_attribute_value (AtkDocument *document, const gchar *value)
79
{
80
2
  AtkAttributeSet *attr = my_atk_document_get_document_attributes (document);
81
2
  GSList *cur_attr = (GSList *) attr;
82
  AtkAttribute *at;
83

            
84
3
  while (cur_attr)
85
    {
86
3
      at = (AtkAttribute *) cur_attr->data;
87
3
      if (!g_strcmp0 (at->name, value))
88
        {
89
2
          return at->value;
90
        }
91
1
      cur_attr = cur_attr->next;
92
    }
93
  return NULL;
94
}
95

            
96
gboolean
97
my_atk_document_set_document_attribute (AtkDocument *document, const gchar *attribute_name, const gchar *attribute_value)
98
{
99
  return FALSE;
100
}
101

            
102
gint
103
my_atk_document_get_current_page_number (AtkDocument *document)
104
{
105
  return 0;
106
}
107

            
108
gint
109
my_atk_document_get_page_count (AtkDocument *document)
110
{
111
  return 0;
112
}
113

            
114
const gchar *
115
1
my_atk_document_get_document_locale (AtkDocument *document)
116
{
117

            
118
1
  return g_strdup ("document_locale");
119
}
120

            
121
static GArray *
122
2
my_atk_document_get_text_selections (AtkDocument *document)
123
{
124
2
  g_return_val_if_fail (MY_IS_ATK_DOCUMENT (document), NULL);
125
2
  MyAtkDocument *self = MY_ATK_DOCUMENT (document);
126

            
127
2
  return self->text_selections;
128
}
129

            
130
static gboolean
131
1
my_atk_document_set_text_selections (AtkDocument *document, GArray *selections)
132
{
133
1
  g_return_val_if_fail (MY_IS_ATK_DOCUMENT (document), FALSE);
134
1
  MyAtkDocument *self = MY_ATK_DOCUMENT (document);
135

            
136
1
  if (self->text_selections)
137
    g_array_free (self->text_selections, TRUE);
138
1
  self->text_selections = g_array_copy (selections);
139
1
  return TRUE;
140
}
141

            
142
static void
143
5
atk_document_interface_init (AtkDocumentIface *iface)
144
{
145
5
  if (!iface)
146
    return;
147

            
148
5
  iface->get_document_locale = my_atk_document_get_document_locale;
149
5
  iface->get_document_attributes = my_atk_document_get_document_attributes;
150
5
  iface->get_document_attribute_value = my_atk_document_get_document_attribute_value;
151
5
  iface->set_document_attribute = my_atk_document_set_document_attribute;
152
5
  iface->get_current_page_number = my_atk_document_get_current_page_number;
153
5
  iface->get_page_count = my_atk_document_get_page_count;
154
5
  iface->get_text_selections = my_atk_document_get_text_selections;
155
5
  iface->set_text_selections = my_atk_document_set_text_selections;
156
}
157

            
158
static void
159
my_atk_document_initialize (AtkObject *obj, gpointer data)
160
{
161
}
162

            
163
static void
164
my_atk_document_finalize (GObject *object)
165
{
166
}
167

            
168
static void
169
5
my_atk_document_class_init (MyAtkDocumentClass *my_class)
170
{
171
5
  AtkObjectClass *atk_class = ATK_OBJECT_CLASS (my_class);
172
5
  GObjectClass *gobject_class = G_OBJECT_CLASS (my_class);
173

            
174
5
  gobject_class->finalize = my_atk_document_finalize;
175

            
176
5
  atk_class->initialize = my_atk_document_initialize;
177
5
}