Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / eail / eail_photocam.c
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd.
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 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.
18  */
19
20 /**
21  * @file eail_photocam.c
22  * @brief EailPhotocam implementation
23  */
24
25 #include <Elementary.h>
26 #include <atk/atk.h>
27
28 #include "eail_photocam.h"
29
30 /**
31  * @brief 'zoom in' action name
32  */
33 #define EAIL_PHOTOCAM_ACTION_ZOOM_IN "zoom_in"
34
35 /**
36  * @brief 'zoom out' action name
37  */
38 #define EAIL_PHOTOCAM_ACTION_ZOOM_OUT "zoom_out"
39
40 /**
41  * @brief 'click' action name
42  */
43 #define EAIL_PHOTOCAM_ACTION_CLICK "click"
44
45 /**
46  * @brief Zoom increment
47  */
48 #define EAIL_PHOTOCAM_ZOOM_STEP 0.0625
49
50 static void atk_image_iface_init(AtkImageIface *iface);
51
52 /**
53  * @brief EailPhotocam type definition
54  */
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));
59
60 /**
61  * @brief 'zoom in' action callback
62  *
63  * @param action AtkAction instance
64  * @param data data passed to callback
65  * @return TRUE on success, FALSE otherwise
66  */
67 static gboolean
68 _eail_photocam_action_zoom_in(AtkAction *action, void *data)
69 {
70    Evas_Object *widget;
71    double zoom_level, set_zoom;
72
73    g_return_val_if_fail(EAIL_IS_PHOTOCAM(action), FALSE);
74
75    widget = eail_widget_get_widget(EAIL_WIDGET(action));
76    if (!widget) return FALSE;
77
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;
81
82    elm_photocam_zoom_set(widget, set_zoom);
83    return TRUE;
84 }
85
86 /**
87  * @brief 'zoom out' action callback
88  *
89  * @param action AtkAction instance
90  * @param data data passed to callback
91  * @return TRUE on success, FALSE otherwise
92  */
93 static gboolean
94 _eail_photocam_action_zoom_out(AtkAction *action, void *data)
95 {
96    Evas_Object *widget;
97    double zoom_level;
98
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;
102
103    zoom_level = elm_photocam_zoom_get(widget) + EAIL_PHOTOCAM_ZOOM_STEP;
104    elm_photocam_zoom_set(widget, zoom_level);
105
106    return TRUE;
107 }
108
109 /**
110  * @brief 'click' action callback
111  *
112  * @param action AtkAction instance
113  * @param data data passed to callback
114  * @return TRUE on success, FALSE otherwise
115  */
116 static gboolean
117 _eail_photocam_action_click(AtkAction *action, void *data)
118 {
119    Evas_Object *widget;
120
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;
124
125    evas_object_smart_callback_call(widget, "clicked", NULL);
126    return TRUE;
127 }
128
129 /**
130  * @brief EailPhotocam initializer
131  *
132  * @param obj AtkObject instance
133  * @param data initialization data
134  */
135 static void
136 eail_photocam_initialize(AtkObject *obj, gpointer data)
137 {
138    ATK_OBJECT_CLASS(eail_photocam_parent_class)->initialize(obj, data);
139
140    obj->role = ATK_ROLE_IMAGE;
141
142    eail_action_widget_action_append(EAIL_ACTION_WIDGET(obj),
143                                     EAIL_PHOTOCAM_ACTION_ZOOM_IN,
144                                     NULL,
145                                     _eail_photocam_action_zoom_in);
146    eail_action_widget_action_append(EAIL_ACTION_WIDGET(obj),
147                                     EAIL_PHOTOCAM_ACTION_ZOOM_OUT,
148                                     NULL,
149                                     _eail_photocam_action_zoom_out);
150    eail_action_widget_action_append(EAIL_ACTION_WIDGET(obj),
151                                     EAIL_PHOTOCAM_ACTION_CLICK,
152                                     NULL,
153                                     _eail_photocam_action_click);
154 }
155
156 /**
157  * @brief Gets the state set of obj
158  *
159  * The caller must unreference it when it is no longer needed.
160  *
161  * @param obj AtkObject instance
162  * @return AtkStateSet representing the state set of obj
163  */
164 static AtkStateSet*
165 eail_photocam_ref_state_set(AtkObject *obj)
166 {
167    AtkStateSet *state_set;
168
169    state_set = ATK_OBJECT_CLASS(eail_photocam_parent_class)->ref_state_set(obj);
170    return state_set;
171 }
172
173 /**
174  * @brief EailPhotocam finalizer
175  *
176  * Frees allocated resources.
177  *
178  * @param object GObject instance
179  */
180 static void
181 eail_photocam_finalize(GObject *object)
182 {
183    EailPhotocam *photocam = EAIL_PHOTOCAM(object);
184    if (photocam->description)
185      free(photocam->description);
186
187    G_OBJECT_CLASS(eail_photocam_parent_class)->finalize(object);
188 }
189
190 /**
191  * @brief EailPhotocam class initializer
192  *
193  * @param klass EailPhotocamClass instance
194  */
195 static void
196 eail_photocam_class_init(EailPhotocamClass *klass)
197 {
198    AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
199    GObjectClass *g_object_class = G_OBJECT_CLASS(klass);
200
201    atk_class->initialize = eail_photocam_initialize;
202    atk_class->ref_state_set = eail_photocam_ref_state_set;
203
204    g_object_class->finalize = eail_photocam_finalize;
205 }
206
207 /**
208  * @brief EailPhotocam instance intializer
209  *
210  * @param photocam EailPhotocam instance
211  */
212 static void eail_photocam_init(EailPhotocam *photocam)
213 {
214    photocam->description = NULL;
215 }
216
217 /**
218  * @brief Gets the image's size
219  *
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
223  */
224 static void
225 eail_photocam_image_size_get(AtkImage *image, gint *width, gint *height)
226 {
227    g_return_if_fail(ATK_IS_IMAGE(image));
228    Evas_Object *widget = eail_widget_get_widget(EAIL_WIDGET(image));
229    if (!widget)
230      {
231         *width = -1;
232         *height = -1;
233         return;
234      }
235    elm_photocam_image_size_get(widget, width, height);
236 }
237
238 /**
239  * @brief Gets the image's description
240  *
241  * @param image AtkImage instance
242  * @return string representing the image's description
243  */
244 static const char*
245 eail_photocam_image_description_get(AtkImage* image)
246 {
247    EailPhotocam *photocam;
248
249    g_return_val_if_fail(EAIL_IS_PHOTOCAM(image), NULL);
250    photocam = EAIL_PHOTOCAM(image);
251
252    return photocam->description;
253 }
254
255 /**
256  * @brief Sets the image's description
257  *
258  * @param image AtkImage instance
259  * @param description new image description
260  * @return TRUE if description was set successfully, FALSE otherwise
261  */
262 static gboolean
263 eail_photocam_image_description_set(AtkImage *image, const char *description)
264 {
265    EailPhotocam *photocam;
266
267    g_return_val_if_fail(EAIL_IS_PHOTOCAM(image), FALSE);
268    photocam = EAIL_PHOTOCAM(image);
269
270    if (photocam->description) free(photocam->description);
271    photocam->description = g_strdup(description);
272
273    return TRUE;
274 }
275
276 /**
277  * @brief Gets the image's position
278  *
279  * Position is in the form of a point specifying background top-left corner.
280  *
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
286  */
287 static void
288 eail_photocam_image_position_get(AtkImage *image,
289                                  gint *x,
290                                  gint *y,
291                                  AtkCoordType coord_type)
292 {
293    atk_component_get_position(ATK_COMPONENT(image), x, y, coord_type);
294 }
295
296 /**
297  * @brief Gets photocam's locale (LC_MESSAGES variable)
298  *
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
303  *
304  */
305 const gchar *
306 eail_photocam_get_image_locale(AtkImage *image)
307 {
308     return setlocale(LC_MESSAGES, NULL);
309 }
310
311 /**
312  * @brief AktImage interface initializer
313  *
314  * @param iface AtkImageIface instance
315  */
316 static void
317 atk_image_iface_init(AtkImageIface *iface)
318 {
319    if (!iface) return;
320
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;
326 }