Visual Studio builds: Support Visual Studio 2017
[atk.git] / atk / atkimage.c
blob3a00886496af3747542bdf0278c4ff911c8b99e4
1 /* ATK - Accessibility Toolkit
2 * Copyright 2001 Sun Microsystems Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include "config.h"
22 #include "atkimage.h"
24 /**
25 * SECTION:atkimage
26 * @Short_description: The ATK Interface implemented by components
27 * which expose image or pixmap content on-screen.
28 * @Title:AtkImage
30 * #AtkImage should be implemented by #AtkObject subtypes on behalf of
31 * components which display image/pixmap information onscreen, and
32 * which provide information (other than just widget borders, etc.)
33 * via that image content. For instance, icons, buttons with icons,
34 * toolbar elements, and image viewing panes typically should
35 * implement #AtkImage.
37 * #AtkImage primarily provides two types of information: coordinate
38 * information (useful for screen review mode of screenreaders, and
39 * for use by onscreen magnifiers), and descriptive information. The
40 * descriptive information is provided for alternative, text-only
41 * presentation of the most significant information present in the
42 * image.
45 GType
46 atk_image_get_type (void)
48 static GType type = 0;
50 if (!type) {
51 static const GTypeInfo tinfo =
53 sizeof (AtkImageIface),
54 (GBaseInitFunc) NULL,
55 (GBaseFinalizeFunc) NULL
58 type = g_type_register_static (G_TYPE_INTERFACE, "AtkImage", &tinfo, 0);
61 return type;
64 /**
65 * atk_image_get_image_description:
66 * @image: a #GObject instance that implements AtkImageIface
68 * Get a textual description of this image.
70 * Returns: a string representing the image description
71 **/
72 const gchar*
73 atk_image_get_image_description (AtkImage *image)
75 AtkImageIface *iface;
77 g_return_val_if_fail (ATK_IS_IMAGE (image), NULL);
79 iface = ATK_IMAGE_GET_IFACE (image);
81 if (iface->get_image_description)
83 return (iface->get_image_description) (image);
85 else
87 return NULL;
91 /**
92 * atk_image_get_image_size:
93 * @image: a #GObject instance that implements AtkImageIface
94 * @width: (out) (optional): filled with the image width, or -1 if the value cannot be obtained.
95 * @height: (out) (optional): filled with the image height, or -1 if the value cannot be obtained.
97 * Get the width and height in pixels for the specified image.
98 * The values of @width and @height are returned as -1 if the
99 * values cannot be obtained (for instance, if the object is not onscreen).
101 void
102 atk_image_get_image_size (AtkImage *image,
103 int *width,
104 int *height)
106 AtkImageIface *iface;
107 gint local_width, local_height;
108 gint *real_width, *real_height;
110 g_return_if_fail (ATK_IS_IMAGE (image));
112 if (width)
113 real_width = width;
114 else
115 real_width = &local_width;
116 if (height)
117 real_height = height;
118 else
119 real_height = &local_height;
121 iface = ATK_IMAGE_GET_IFACE (image);
123 if (iface->get_image_size)
125 iface->get_image_size (image, real_width, real_height);
127 else
129 *real_width = -1;
130 *real_height = -1;
135 * atk_image_set_image_description:
136 * @image: a #GObject instance that implements AtkImageIface
137 * @description: a string description to set for @image
139 * Sets the textual description for this image.
141 * Returns: boolean TRUE, or FALSE if operation could
142 * not be completed.
144 gboolean
145 atk_image_set_image_description (AtkImage *image,
146 const gchar *description)
148 AtkImageIface *iface;
150 g_return_val_if_fail (ATK_IS_IMAGE (image), FALSE);
152 iface = ATK_IMAGE_GET_IFACE (image);
154 if (iface->set_image_description)
156 return (iface->set_image_description) (image, description);
158 else
160 return FALSE;
165 * atk_image_get_image_position:
166 * @image: a #GObject instance that implements AtkImageIface
167 * @x: (out) (optional): address of #gint to put x coordinate position; otherwise, -1 if value cannot be obtained.
168 * @y: (out) (optional): address of #gint to put y coordinate position; otherwise, -1 if value cannot be obtained.
169 * @coord_type: specifies whether the coordinates are relative to the screen
170 * or to the components top level window
172 * Gets the position of the image in the form of a point specifying the
173 * images top-left corner.
175 void
176 atk_image_get_image_position (AtkImage *image,
177 gint *x,
178 gint *y,
179 AtkCoordType coord_type)
181 AtkImageIface *iface;
182 gint local_x, local_y;
183 gint *real_x, *real_y;
185 g_return_if_fail (ATK_IS_IMAGE (image));
187 if (x)
188 real_x = x;
189 else
190 real_x = &local_x;
191 if (y)
192 real_y = y;
193 else
194 real_y = &local_y;
196 iface = ATK_IMAGE_GET_IFACE (image);
198 if (iface->get_image_position)
200 (iface->get_image_position) (image, real_x, real_y, coord_type);
202 else
204 *real_x = -1;
205 *real_y = -1;
210 * atk_image_get_image_locale:
211 * @image: An #AtkImage
213 * Since: 1.12
215 * Returns: (nullable): a string corresponding to the POSIX
216 * LC_MESSAGES locale used by the image description, or %NULL if the
217 * image does not specify a locale.
220 const gchar*
221 atk_image_get_image_locale (AtkImage *image)
224 AtkImageIface *iface;
226 g_return_val_if_fail (ATK_IS_IMAGE (image), NULL);
228 iface = ATK_IMAGE_GET_IFACE (image);
230 if (iface->get_image_locale)
232 return (iface->get_image_locale) (image);
234 else
236 return NULL;