c714a45e51f874f9dc3813a2df49c1a6bd62dfdf
[platform/upstream/at-spi2-atk.git] / tests / dummyatk / my-atk-image.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
24 #include <stdio.h>
25 #include <string.h>
26 #include <atk/atk.h>
27
28 #include "my-atk-object.h"
29 #include "my-atk-image.h"
30
31 typedef struct _MyAtkImageInfo MyAtkImageInfo;
32
33 static void atk_image_interface_init (AtkImageIface *iface);
34
35 G_DEFINE_TYPE_WITH_CODE (MyAtkImage,
36                          my_atk_image,
37                          MY_TYPE_ATK_OBJECT,
38                          G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE,
39                              atk_image_interface_init));
40
41 guint
42 my_atk_set_image (AtkImage *image,
43                   const gchar *desc,
44                   const gint x,
45                   const gint y,
46                   const gint width,
47                   const gint height,
48                   const gchar *locale)
49 {
50   g_return_val_if_fail (MY_IS_ATK_IMAGE (image), FALSE);
51
52   MyAtkImage *self = MY_ATK_IMAGE (image);
53
54   self->description = g_strdup (desc);
55   self->x = x;
56   self->y = y;
57   self->width = width;
58   self->height = height;
59   self->locale = g_strdup (locale);
60
61   return 0;
62 }
63
64 static void
65 my_atk_image_init (MyAtkImage *obj)
66 {
67   MyAtkImage *self = MY_ATK_IMAGE (obj);
68   self->description = NULL;
69   self->x = -1;
70   self->y = -1;
71   self->width = -1;
72   self->height = -1;
73   self->locale = NULL;
74 }
75
76 void my_atk_image_get_image_position (AtkImage *obj, gint *x, gint *y, AtkCoordType coord_type)
77 {
78   g_return_if_fail (MY_IS_ATK_IMAGE (obj));
79
80   MyAtkImage *self = MY_ATK_IMAGE (obj);
81   *x = self->x;
82   *y = self->y;
83 }
84
85 const gchar*
86 my_atk_image_get_image_description (AtkImage *obj)
87 {
88   g_return_val_if_fail (MY_IS_ATK_IMAGE (obj), NULL);
89
90   MyAtkImage *self = MY_ATK_IMAGE (obj);
91
92   return g_strdup (self->description);
93 }
94
95 void my_atk_image_get_image_size (AtkImage *obj, gint *width, gint *height)
96 {
97   g_return_if_fail (MY_IS_ATK_IMAGE (obj));
98
99   MyAtkImage *self = MY_ATK_IMAGE (obj);
100   *width = self->width;
101   *height = self->height;
102 }
103
104 gboolean
105 my_atk_image_set_image_description (AtkImage *obj, const gchar * desc)
106 {
107   g_return_val_if_fail (MY_IS_ATK_IMAGE (obj), FALSE);
108
109   MyAtkImage *self = MY_ATK_IMAGE (obj);
110
111   g_free (self->description);
112   self->description = g_strdup (desc);
113
114   return TRUE;
115 }
116
117 const gchar*
118 my_atk_image_get_image_locale (AtkImage *obj)
119 {
120   g_return_val_if_fail (MY_IS_ATK_IMAGE (obj), NULL);
121
122   MyAtkImage *self = MY_ATK_IMAGE (obj);
123
124   return self->locale;
125 }
126
127 static void
128 atk_image_interface_init (AtkImageIface *iface)
129 {
130   if (!iface) return;
131   iface->get_image_position = my_atk_image_get_image_position;
132   iface->set_image_description = my_atk_image_set_image_description;
133   iface->get_image_description = my_atk_image_get_image_description;
134   iface->get_image_size = my_atk_image_get_image_size;
135   iface->get_image_locale = my_atk_image_get_image_locale;
136 }
137
138 static void
139 my_atk_image_initialize (AtkObject *obj, gpointer data)
140 {
141 }
142
143 static void
144 my_atk_image_finalize (GObject *object)
145 {
146 }
147
148 static void
149 my_atk_image_class_init (MyAtkImageClass *my_class)
150 {
151   AtkObjectClass *atk_class = ATK_OBJECT_CLASS (my_class);
152   GObjectClass *gobject_class = G_OBJECT_CLASS (my_class);
153
154   gobject_class->finalize = my_atk_image_finalize;
155
156   atk_class->initialize = my_atk_image_initialize;
157 }