2 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
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 License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 * @file eail_background.c
22 * @brief EailBackground implementation
25 #include <Elementary.h>
27 #include "eail_background.h"
29 static void atk_image_interface_init(AtkImageIface *iface);
32 * @brief EailBackground type definition
34 G_DEFINE_TYPE_WITH_CODE(EailBackground,
37 G_IMPLEMENT_INTERFACE(ATK_TYPE_IMAGE,
38 atk_image_interface_init));
41 static void eail_background_initialize(AtkObject *obj, gpointer data);
42 static void eail_background_finalize(GObject *object);
43 static AtkAttributeSet *eail_background_get_attributes(AtkObject *obj);
46 static void eail_background_get_image_position (AtkImage *image,
49 AtkCoordType coord_type);
50 static const gchar *eail_background_get_image_description(AtkImage *image);
51 static gboolean eail_background_set_image_description(AtkImage *image,
52 const gchar *description);
53 static void eail_background_get_image_size(AtkImage *image,
56 const gchar *eail_background_get_image_locale(AtkImage *image);
60 * Implementation of the *AtkObject* interface
64 * @brief EailBackground class initializer
66 * @param klass EailBackgroundClass instance
69 eail_background_class_init(EailBackgroundClass *klass)
71 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
72 GObjectClass *object_class = G_OBJECT_CLASS(klass);
74 atk_class->initialize = eail_background_initialize;
75 atk_class->get_attributes = eail_background_get_attributes;
77 object_class->finalize = eail_background_finalize;
81 * @brief EailBackground initializer
83 * @param obj AtkObject (EailBackground) instance to be initialized
84 * @param data additional data
87 eail_background_initialize(AtkObject *obj, gpointer data)
89 ATK_OBJECT_CLASS(eail_background_parent_class)->initialize(obj, data);
91 obj->role = ATK_ROLE_IMAGE;
95 * @brief EailBackground finalizer
97 * Destroys the object and allocated resources.
99 * @param object EailBackground instance to be finalized
102 eail_background_finalize(GObject *object)
104 EailBackground *bg = EAIL_BACKGROUND(object);
106 if (bg->description) free(bg->description);
108 G_OBJECT_CLASS(eail_background_parent_class)->finalize(object);
112 * @brief EailBackground instance initializer
114 * @param background EailBackground instance
117 eail_background_init(EailBackground *background)
119 background->description = NULL;
123 * @brief Gets obj's attributes set
125 * The caller must unreference it when it is no longer needed.
127 * @param obj AtkObject instance
128 * @return AtkAttributeSet containing obj's attributes
130 static AtkAttributeSet *
131 eail_background_get_attributes(AtkObject *obj)
134 AtkAttributeSet *attributes;
138 const char *mode, *file;
140 attributes = ATK_OBJECT_CLASS(eail_background_parent_class)->get_attributes(obj);
142 widget = eail_widget_get_widget(EAIL_WIDGET(obj));
143 if (!widget) return attributes;
145 elm_bg_file_get(widget, &file, NULL);
148 elm_bg_color_get(widget, &r, &g, &b);
149 g_snprintf(color, sizeof(color), "#%02x%02x%02x", r, g, b);
150 attr = g_new(AtkAttribute, 1);
151 attr->name = g_strdup("color");
152 attr->value = g_strdup(color);
153 attributes = g_slist_append(attributes, attr);
157 attr = g_new(AtkAttribute, 1);
158 attr->name = g_strdup("file");
159 attr->value = g_strdup(file);
160 attributes = g_slist_append(attributes, attr);
163 switch (elm_bg_option_get(widget))
165 case ELM_BG_OPTION_CENTER:
168 case ELM_BG_OPTION_SCALE:
171 case ELM_BG_OPTION_STRETCH:
174 case ELM_BG_OPTION_TILE:
182 attr = g_new(AtkAttribute, 1);
183 attr->name = g_strdup("display mode");
184 attr->value = g_strdup(mode);
185 attributes = g_slist_append(attributes, attr);
192 * AtkImage interface implementation
196 * @brief AtkImage interface initializer
198 * @param iface AtkImageIface instance
201 atk_image_interface_init(AtkImageIface *iface)
203 g_return_if_fail(iface);
205 iface->get_image_description = eail_background_get_image_description;
206 iface->set_image_description = eail_background_set_image_description;
207 iface->get_image_size = eail_background_get_image_size;
208 iface->get_image_position = eail_background_get_image_position;
209 iface->get_image_locale = eail_background_get_image_locale;
213 * @brief Gets background's image position.
215 * Position is in the form of a point specifying background top-left corner.
217 * @param image AtkImage instance
218 * @param [out] x x coordinate or -1 if value cannot be obtained
219 * @param [out] y y coordinate or -1 if value cannot be obtained
220 * @param coord_type specifies whether the coordinates are relative to the screen or to the component's top level window
223 eail_background_get_image_position(AtkImage *image,
226 AtkCoordType coord_type)
228 atk_component_get_position(ATK_COMPONENT(image), x, y, coord_type);
232 * @brief Gets background image's description
234 * @param image AtkImage instance
235 * @return string representing image's description
238 eail_background_get_image_description(AtkImage *image)
243 g_return_val_if_fail(EAIL_IS_BACKGROUND(image), NULL);
245 bg = EAIL_BACKGROUND(image);
246 if (!bg) return NULL;
248 desc = bg->description;
254 * @brief Sets background image's description
256 * @param image AtkImage instance
257 * @param description new image description
258 * @return TRUE if description was set successfully, FALSE otherwise
261 eail_background_set_image_description(AtkImage *image,
262 const gchar *description)
266 g_return_val_if_fail(EAIL_IS_BACKGROUND(image), FALSE);
268 bg = EAIL_BACKGROUND(image);
269 if (!bg) return FALSE;
272 free(bg->description);
274 bg->description = g_strdup(description);
275 if (!bg->description) return FALSE;
281 * @brief Gets background's widget size
283 * @param image AtkImage instance
284 * @param [out] width background's width or -1 if value cannot be obtained
285 * @param [out] height background's height or -1 if value cannot be obtained
288 eail_background_get_image_size(AtkImage *image,
295 bg = EAIL_BACKGROUND(image);
297 *width = *height = -1;
299 widget = eail_widget_get_widget(EAIL_WIDGET(image));
303 evas_object_geometry_get(widget, NULL, NULL, width, height);
307 * @brief Gets background's locale (LC_MESSAGES variable)
309 * @param image AtkImage instance
310 * @return string corresponding to the POSIX LC_MESSAGES
311 * locale used by the image description, or NULL if
312 * the image does not specify a locale
316 eail_background_get_image_locale(AtkImage *image)
318 return setlocale(LC_MESSAGES, NULL);