summaryrefslogtreecommitdiff
path: root/atk/atkimage.c
blob: 9d8a58fd94ba2faa7e51c230a6c61570250117b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/* ATK -  Accessibility Toolkit
 * Copyright 2001 Sun Microsystems Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include "config.h"

#include "atkimage.h"

/**
 * SECTION:atkimage
 * @Short_description: The ATK Interface implemented by components
 *  which expose image or pixmap content on-screen.
 * @Title:AtkImage
 *
 * #AtkImage should be implemented by #AtkObject subtypes on behalf of
 * components which display image/pixmap information onscreen, and
 * which provide information (other than just widget borders, etc.)
 * via that image content.  For instance, icons, buttons with icons,
 * toolbar elements, and image viewing panes typically should
 * implement #AtkImage.
 *
 * #AtkImage primarily provides two types of information: coordinate
 * information (useful for screen review mode of screenreaders, and
 * for use by onscreen magnifiers), and descriptive information.  The
 * descriptive information is provided for alternative, text-only
 * presentation of the most significant information present in the
 * image.
 */

GType
atk_image_get_type (void)
{
  static GType type = 0;

  if (!type) {
    static const GTypeInfo tinfo =
    {
      sizeof (AtkImageIface),
      (GBaseInitFunc) NULL,
      (GBaseFinalizeFunc) NULL
    };

    type = g_type_register_static (G_TYPE_INTERFACE, "AtkImage", &tinfo, 0);
  }

  return type;
}

/**
 * atk_image_get_image_description:
 * @image: a #GObject instance that implements AtkImageIface
 *
 * Get a textual description of this image.
 *
 * Returns: a string representing the image description
 **/
const gchar*
atk_image_get_image_description (AtkImage *image)
{
  AtkImageIface *iface;

  g_return_val_if_fail (ATK_IS_IMAGE (image), NULL);

  iface = ATK_IMAGE_GET_IFACE (image);

  if (iface->get_image_description)
    {
      return (iface->get_image_description) (image);
    }
  else
    {
      return NULL;
    }
}

/**
 * atk_image_get_image_size:
 * @image: a #GObject instance that implements AtkImageIface
 * @width: filled with the image width, or -1 if the value cannot be obtained.
 * @height: filled with the image height, or -1 if the value cannot be obtained.
 *
 * Get the width and height in pixels for the specified image.
 * The values of @width and @height are returned as -1 if the
 * values cannot be obtained (for instance, if the object is not onscreen).
 **/
void
atk_image_get_image_size (AtkImage *image, 
                          int      *width,
                          int      *height)
{
  AtkImageIface *iface;
  gint local_width, local_height;
  gint *real_width, *real_height;

  g_return_if_fail (ATK_IS_IMAGE (image));

  if (width)
    real_width = width;
  else
    real_width = &local_width;
  if (height)
    real_height = height;
  else
    real_height = &local_height;
  
  iface = ATK_IMAGE_GET_IFACE (image);

  if (iface->get_image_size)
  {
    iface->get_image_size (image, real_width, real_height);
  }
  else
  {
    *real_width = -1;
    *real_height = -1;
  }
}

/**
 * atk_image_set_image_description:
 * @image: a #GObject instance that implements AtkImageIface
 * @description: a string description to set for @image
 *
 * Sets the textual description for this image.
 *
 * Returns: boolean TRUE, or FALSE if operation could
 * not be completed.
 **/
gboolean
atk_image_set_image_description (AtkImage        *image,
                                 const gchar     *description)
{
  AtkImageIface *iface;

  g_return_val_if_fail (ATK_IS_IMAGE (image), FALSE);

  iface = ATK_IMAGE_GET_IFACE (image);

  if (iface->set_image_description)
    {
      return (iface->set_image_description) (image, description);
    }
  else
    {
      return FALSE;
    }
}

/**
 * atk_image_get_image_position:
 * @image: a #GObject instance that implements AtkImageIface
 * @x: address of #gint to put x coordinate position; otherwise, -1 if value cannot be obtained.
 * @y: address of #gint to put y coordinate position; otherwise, -1 if value cannot be obtained.
 * @coord_type: specifies whether the coordinates are relative to the screen
 * or to the components top level window
 * 
 * Gets the position of the image in the form of a point specifying the
 * images top-left corner.
 **/
void     
atk_image_get_image_position (AtkImage *image,
                        gint *x,
		        gint *y,
    		        AtkCoordType coord_type)
{
  AtkImageIface *iface;
  gint local_x, local_y;
  gint *real_x, *real_y;

  g_return_if_fail (ATK_IS_IMAGE (image));

  if (x)
    real_x = x;
  else
    real_x = &local_x;
  if (y)
    real_y = y;
  else
    real_y = &local_y;

  iface = ATK_IMAGE_GET_IFACE (image);

  if (iface->get_image_position)
  {
    (iface->get_image_position) (image, real_x, real_y, coord_type);
  }
  else
  {
    *real_x = -1;
    *real_y = -1;
  }
}

/**
 * atk_image_get_image_locale: 
 * @image: An #AtkImage
 *
 * Since ATK 1.12
 *
 * Returns: (nullable): a string corresponding to the POSIX
 * LC_MESSAGES locale used by the image description, or %NULL if the
 * image does not specify a locale.
 *
 */
const gchar*
atk_image_get_image_locale (AtkImage   *image)
{
	
  AtkImageIface *iface;

  g_return_val_if_fail (ATK_IS_IMAGE (image), NULL);

  iface = ATK_IMAGE_GET_IFACE (image);

  if (iface->get_image_locale)
    {
      return (iface->get_image_locale) (image);
    }
  else
    {
      return NULL;
    }
}