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 <stdio.h>
25
#include <string.h>
26

            
27
#include "my-atk-image.h"
28
#include "my-atk-object.h"
29

            
30
typedef struct _MyAtkImageInfo MyAtkImageInfo;
31

            
32
static void atk_image_interface_init (AtkImageIface *iface);
33

            
34
6
G_DEFINE_TYPE_WITH_CODE (MyAtkImage,
35
                         my_atk_image,
36
                         MY_TYPE_ATK_OBJECT,
37
                         G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE,
38
                                                atk_image_interface_init));
39

            
40
guint
41
6
my_atk_set_image (AtkImage *image,
42
                  const gchar *desc,
43
                  const gint x,
44
                  const gint y,
45
                  const gint width,
46
                  const gint height,
47
                  const gchar *locale)
48
{
49
6
  g_return_val_if_fail (MY_IS_ATK_IMAGE (image), FALSE);
50

            
51
6
  MyAtkImage *self = MY_ATK_IMAGE (image);
52

            
53
6
  self->description = g_strdup (desc);
54
6
  self->x = x;
55
6
  self->y = y;
56
6
  self->width = width;
57
6
  self->height = height;
58
6
  self->locale = g_strdup (locale);
59

            
60
6
  return 0;
61
}
62

            
63
static void
64
6
my_atk_image_init (MyAtkImage *obj)
65
{
66
6
  MyAtkImage *self = MY_ATK_IMAGE (obj);
67
6
  self->description = NULL;
68
6
  self->x = -1;
69
6
  self->y = -1;
70
6
  self->width = -1;
71
6
  self->height = -1;
72
6
  self->locale = NULL;
73
6
}
74

            
75
void
76
2
my_atk_image_get_image_position (AtkImage *obj, gint *x, gint *y, AtkCoordType coord_type)
77
{
78
2
  g_return_if_fail (MY_IS_ATK_IMAGE (obj));
79

            
80
2
  MyAtkImage *self = MY_ATK_IMAGE (obj);
81
2
  *x = self->x;
82
2
  *y = self->y;
83
}
84

            
85
const gchar *
86
1
my_atk_image_get_image_description (AtkImage *obj)
87
{
88
1
  g_return_val_if_fail (MY_IS_ATK_IMAGE (obj), NULL);
89

            
90
1
  MyAtkImage *self = MY_ATK_IMAGE (obj);
91

            
92
2
  return g_strdup (self->description);
93
}
94

            
95
void
96
2
my_atk_image_get_image_size (AtkImage *obj, gint *width, gint *height)
97
{
98
2
  g_return_if_fail (MY_IS_ATK_IMAGE (obj));
99

            
100
2
  MyAtkImage *self = MY_ATK_IMAGE (obj);
101
2
  *width = self->width;
102
2
  *height = self->height;
103
}
104

            
105
gboolean
106
my_atk_image_set_image_description (AtkImage *obj, const gchar *desc)
107
{
108
  g_return_val_if_fail (MY_IS_ATK_IMAGE (obj), FALSE);
109

            
110
  MyAtkImage *self = MY_ATK_IMAGE (obj);
111

            
112
  g_free (self->description);
113
  self->description = g_strdup (desc);
114

            
115
  return TRUE;
116
}
117

            
118
const gchar *
119
1
my_atk_image_get_image_locale (AtkImage *obj)
120
{
121
1
  g_return_val_if_fail (MY_IS_ATK_IMAGE (obj), NULL);
122

            
123
1
  MyAtkImage *self = MY_ATK_IMAGE (obj);
124

            
125
1
  return self->locale;
126
}
127

            
128
static void
129
6
atk_image_interface_init (AtkImageIface *iface)
130
{
131
6
  if (!iface)
132
    return;
133
6
  iface->get_image_position = my_atk_image_get_image_position;
134
6
  iface->set_image_description = my_atk_image_set_image_description;
135
6
  iface->get_image_description = my_atk_image_get_image_description;
136
6
  iface->get_image_size = my_atk_image_get_image_size;
137
6
  iface->get_image_locale = my_atk_image_get_image_locale;
138
}
139

            
140
static void
141
my_atk_image_initialize (AtkObject *obj, gpointer data)
142
{
143
}
144

            
145
static void
146
my_atk_image_finalize (GObject *object)
147
{
148
}
149

            
150
static void
151
6
my_atk_image_class_init (MyAtkImageClass *my_class)
152
{
153
6
  AtkObjectClass *atk_class = ATK_OBJECT_CLASS (my_class);
154
6
  GObjectClass *gobject_class = G_OBJECT_CLASS (my_class);
155

            
156
6
  gobject_class->finalize = my_atk_image_finalize;
157

            
158
6
  atk_class->initialize = my_atk_image_initialize;
159
6
}