Added new API for ATK 1.11/1.12. Minor docs cleanup.
[platform/upstream/atk.git] / atk / atkimage.c
1 /* ATK -  Accessibility Toolkit
2  * Copyright 2001 Sun Microsystems Inc.
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include "atkimage.h"
21
22 GType
23 atk_image_get_type (void)
24 {
25   static GType type = 0;
26
27   if (!type) {
28     static const GTypeInfo tinfo =
29     {
30       sizeof (AtkImageIface),
31       (GBaseInitFunc) NULL,
32       (GBaseFinalizeFunc) NULL
33     };
34
35     type = g_type_register_static (G_TYPE_INTERFACE, "AtkImage", &tinfo, 0);
36   }
37
38   return type;
39 }
40
41 /**
42  * atk_image_get_image_description:
43  * @image: a #GObject instance that implements AtkImageIface
44  *
45  * Get a textual description of this image.
46  *
47  * Returns: a string representing the image description
48  **/
49 G_CONST_RETURN gchar*
50 atk_image_get_image_description (AtkImage *image)
51 {
52   AtkImageIface *iface;
53
54   g_return_val_if_fail (ATK_IS_IMAGE (image), NULL);
55
56   iface = ATK_IMAGE_GET_IFACE (image);
57
58   if (iface->get_image_description)
59     {
60       return (iface->get_image_description) (image);
61     }
62   else
63     {
64       return NULL;
65     }
66 }
67
68 /**
69  * atk_image_get_image_size:
70  * @image: a #GObject instance that implements AtkImageIface
71  * @width: filled with the image width
72  * @height: filled with the image height
73  *
74  * Get the width and height in pixels for the specified image.
75  * The values of @width and @height are returned as -1 if the
76  * values cannot be obtained.
77  **/
78 void
79 atk_image_get_image_size (AtkImage *image, 
80                           int      *width,
81                           int      *height)
82 {
83   AtkImageIface *iface;
84   gint local_width, local_height;
85   gint *real_width, *real_height;
86
87   g_return_if_fail (ATK_IS_IMAGE (image));
88
89   if (width)
90     real_width = width;
91   else
92     real_width = &local_width;
93   if (height)
94     real_height = height;
95   else
96     real_height = &local_height;
97   
98   iface = ATK_IMAGE_GET_IFACE (image);
99
100   if (iface->get_image_size)
101   {
102     iface->get_image_size (image, real_width, real_height);
103   }
104   else
105   {
106     *width = -1;
107     *height = -1;
108   }
109 }
110
111 /**
112  * atk_image_set_image_description:
113  * @image: a #GObject instance that implements AtkImageIface
114  * @description: a string description to set for @image
115  *
116  * Sets the textual description for this image.
117  *
118  * Returns: boolean TRUE, or FALSE if operation could
119  * not be completed.
120  **/
121 gboolean
122 atk_image_set_image_description (AtkImage        *image,
123                                  const gchar     *description)
124 {
125   AtkImageIface *iface;
126
127   g_return_val_if_fail (ATK_IS_IMAGE (image), FALSE);
128
129   iface = ATK_IMAGE_GET_IFACE (image);
130
131   if (iface->set_image_description)
132     {
133       return (iface->set_image_description) (image, description);
134     }
135   else
136     {
137       return FALSE;
138     }
139 }
140
141 /**
142  * atk_image_get_image_position:
143  * @image: a #GObject instance that implements AtkImageIface
144  * @x: address of #gint to put x coordinate position; otherwise, -1 if value cannot be obtained.
145  * @y: address of #gint to put y coordinate position; otherwise, -1 if value cannot be obtained.
146  * @coord_type: specifies whether the coordinates are relative to the screen
147  * or to the components top level window
148  * 
149  * Gets the position of the image in the form of a point specifying the
150  * images top-left corner.
151  **/
152 void     
153 atk_image_get_image_position (AtkImage *image,
154                         gint *x,
155                         gint *y,
156                         AtkCoordType coord_type)
157 {
158   AtkImageIface *iface;
159   gint local_x, local_y;
160   gint *real_x, *real_y;
161
162   g_return_if_fail (ATK_IS_IMAGE (image));
163
164   if (x)
165     real_x = x;
166   else
167     real_x = &local_x;
168   if (y)
169     real_y = y;
170   else
171     real_y = &local_y;
172   
173   iface = ATK_IMAGE_GET_IFACE (image);
174
175   g_return_if_fail (ATK_IS_IMAGE (image));
176
177   iface = ATK_IMAGE_GET_IFACE (image);
178
179   if (iface->get_image_position)
180   {
181     (iface->get_image_position) (image, real_x, real_y, coord_type);
182   }
183   else
184   {
185     *x = -1;
186     *y = -1;
187   }
188 }
189
190 /** 
191  * Returns a string corresponding to the POSIX LC_MESSAGES locale used by the image description, or NULL if the image does not specify a locale. 
192  * @Since ATK 1.12
193  */
194 G_CONST_RETURN gchar* 
195 atk_image_get_image_locale (AtkImage   *image)
196 {
197         
198   AtkImageIface *iface;
199
200   g_return_val_if_fail (ATK_IS_IMAGE (image), NULL);
201
202   iface = ATK_IMAGE_GET_IFACE (image);
203
204   if (iface->get_image_locale)
205     {
206       return (iface->get_image_locale) (image);
207     }
208   else
209     {
210       return NULL;
211     }
212 }