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_photocam.c
22 * @brief EailPhotocam implementation
25 #include <Elementary.h>
28 #include "eail_photocam.h"
31 * @brief 'zoom in' action name
33 #define EAIL_PHOTOCAM_ACTION_ZOOM_IN "zoom_in"
36 * @brief 'zoom out' action name
38 #define EAIL_PHOTOCAM_ACTION_ZOOM_OUT "zoom_out"
41 * @brief 'click' action name
43 #define EAIL_PHOTOCAM_ACTION_CLICK "click"
46 * @brief Zoom increment
48 #define EAIL_PHOTOCAM_ZOOM_STEP 0.0625
50 static void atk_image_iface_init(AtkImageIface *iface);
53 * @brief EailPhotocam type definition
55 G_DEFINE_TYPE_WITH_CODE(EailPhotocam, eail_photocam,
56 EAIL_TYPE_SCROLLABLE_WIDGET,
57 G_IMPLEMENT_INTERFACE(ATK_TYPE_IMAGE,
58 atk_image_iface_init));
61 * @brief 'zoom in' action callback
63 * @param action AtkAction instance
64 * @param data data passed to callback
65 * @return TRUE on success, FALSE otherwise
68 _eail_photocam_action_zoom_in(AtkAction *action, void *data)
71 double zoom_level, set_zoom;
73 g_return_val_if_fail(EAIL_IS_PHOTOCAM(action), FALSE);
75 widget = eail_widget_get_widget(EAIL_WIDGET(action));
76 if (!widget) return FALSE;
78 zoom_level = elm_photocam_zoom_get(widget);
79 set_zoom = zoom_level - EAIL_PHOTOCAM_ZOOM_STEP;
80 if (set_zoom < 0.0) return FALSE;
82 elm_photocam_zoom_set(widget, set_zoom);
87 * @brief 'zoom out' action callback
89 * @param action AtkAction instance
90 * @param data data passed to callback
91 * @return TRUE on success, FALSE otherwise
94 _eail_photocam_action_zoom_out(AtkAction *action, void *data)
99 g_return_val_if_fail(EAIL_IS_PHOTOCAM(action), FALSE);
100 widget = eail_widget_get_widget(EAIL_WIDGET(action));
101 if (!widget) return FALSE;
103 zoom_level = elm_photocam_zoom_get(widget) + EAIL_PHOTOCAM_ZOOM_STEP;
104 elm_photocam_zoom_set(widget, zoom_level);
110 * @brief 'click' action callback
112 * @param action AtkAction instance
113 * @param data data passed to callback
114 * @return TRUE on success, FALSE otherwise
117 _eail_photocam_action_click(AtkAction *action, void *data)
121 g_return_val_if_fail(EAIL_IS_PHOTOCAM(action), FALSE);
122 widget = eail_widget_get_widget(EAIL_WIDGET(action));
123 if (!widget) return FALSE;
125 evas_object_smart_callback_call(widget, "clicked", NULL);
130 * @brief EailPhotocam initializer
132 * @param obj AtkObject instance
133 * @param data initialization data
136 eail_photocam_initialize(AtkObject *obj, gpointer data)
138 ATK_OBJECT_CLASS(eail_photocam_parent_class)->initialize(obj, data);
140 obj->role = ATK_ROLE_IMAGE;
142 eail_action_widget_action_append(EAIL_ACTION_WIDGET(obj),
143 EAIL_PHOTOCAM_ACTION_ZOOM_IN,
145 _eail_photocam_action_zoom_in);
146 eail_action_widget_action_append(EAIL_ACTION_WIDGET(obj),
147 EAIL_PHOTOCAM_ACTION_ZOOM_OUT,
149 _eail_photocam_action_zoom_out);
150 eail_action_widget_action_append(EAIL_ACTION_WIDGET(obj),
151 EAIL_PHOTOCAM_ACTION_CLICK,
153 _eail_photocam_action_click);
157 * @brief Gets the state set of obj
159 * The caller must unreference it when it is no longer needed.
161 * @param obj AtkObject instance
162 * @return AtkStateSet representing the state set of obj
165 eail_photocam_ref_state_set(AtkObject *obj)
167 AtkStateSet *state_set;
169 state_set = ATK_OBJECT_CLASS(eail_photocam_parent_class)->ref_state_set(obj);
174 * @brief EailPhotocam finalizer
176 * Frees allocated resources.
178 * @param object GObject instance
181 eail_photocam_finalize(GObject *object)
183 EailPhotocam *photocam = EAIL_PHOTOCAM(object);
184 if (photocam->description)
185 free(photocam->description);
187 G_OBJECT_CLASS(eail_photocam_parent_class)->finalize(object);
191 * @brief EailPhotocam class initializer
193 * @param klass EailPhotocamClass instance
196 eail_photocam_class_init(EailPhotocamClass *klass)
198 AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
199 GObjectClass *g_object_class = G_OBJECT_CLASS(klass);
201 atk_class->initialize = eail_photocam_initialize;
202 atk_class->ref_state_set = eail_photocam_ref_state_set;
204 g_object_class->finalize = eail_photocam_finalize;
208 * @brief EailPhotocam instance intializer
210 * @param photocam EailPhotocam instance
212 static void eail_photocam_init(EailPhotocam *photocam)
214 photocam->description = NULL;
218 * @brief Gets the image's size
220 * @param image AtkImage instance
221 * @param [out] width image width or -1 if value cannot be obtained
222 * @param [out] height image height or -1 if value cannot be obtained
225 eail_photocam_image_size_get(AtkImage *image, gint *width, gint *height)
227 g_return_if_fail(ATK_IS_IMAGE(image));
228 Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(image));
235 elm_photocam_image_size_get(widget, width, height);
239 * @brief Gets the image's description
241 * @param image AtkImage instance
242 * @return string representing the image's description
245 eail_photocam_image_description_get(AtkImage* image)
247 EailPhotocam *photocam;
249 g_return_val_if_fail(EAIL_IS_PHOTOCAM(image), NULL);
250 photocam = EAIL_PHOTOCAM(image);
252 return photocam->description;
256 * @brief Sets the image's description
258 * @param image AtkImage instance
259 * @param description new image description
260 * @return TRUE if description was set successfully, FALSE otherwise
263 eail_photocam_image_description_set(AtkImage *image, const char *description)
265 EailPhotocam *photocam;
267 g_return_val_if_fail(EAIL_IS_PHOTOCAM(image), FALSE);
268 photocam = EAIL_PHOTOCAM(image);
270 if (photocam->description) free(photocam->description);
271 photocam->description = g_strdup(description);
277 * @brief Gets the image's position
279 * Position is in the form of a point specifying background top-left corner.
281 * @param image AtkImage instance
282 * @param [out] x x coordinate or -1 if value cannot be obtained
283 * @param [out] y y coordinate or -1 if value cannot be obtained
284 * @param coord_type specifies whether the coordinates are relative to the screen
285 * or to the components top level window
288 eail_photocam_image_position_get(AtkImage *image,
291 AtkCoordType coord_type)
293 atk_component_get_position(ATK_COMPONENT(image), x, y, coord_type);
297 * @brief Gets photocam's locale (LC_MESSAGES variable)
299 * @param image AtkImage instance
300 * @return string corresponding to the POSIX LC_MESSAGES
301 * locale used by the image description, or NULL if
302 * the image does not specify a locale
306 eail_photocam_get_image_locale(AtkImage *image)
308 return setlocale(LC_MESSAGES, NULL);
312 * @brief AktImage interface initializer
314 * @param iface AtkImageIface instance
317 atk_image_iface_init(AtkImageIface *iface)
321 iface->get_image_size = eail_photocam_image_size_get;
322 iface->get_image_description = eail_photocam_image_description_get;
323 iface->set_image_description = eail_photocam_image_description_set;
324 iface->get_image_position = eail_photocam_image_position_get;
325 iface->get_image_locale = eail_photocam_get_image_locale;