Merge "[edje_externals/elm_datefield.c] Datefield widget external file is updated...
[framework/uifw/elementary.git] / src / lib / elm_image.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3 #include "els_icon.h"
4
5 typedef struct _Widget_Data Widget_Data;
6
7 struct _Widget_Data
8 {
9    Evas_Object *img;
10    Eina_Bool scale_up : 1;
11    Eina_Bool scale_down : 1;
12    Eina_Bool smooth : 1;
13    Eina_Bool fill_outside : 1;
14    Eina_Bool no_scale : 1;
15 };
16
17 static const char *widtype = NULL;
18 static void _del_hook(Evas_Object *obj);
19 static void _theme_hook(Evas_Object *obj);
20 static void _sizing_eval(Evas_Object *obj);
21 static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
22
23 static const char SIG_CLICKED[] = "clicked";
24
25 static const Evas_Smart_Cb_Description _signals[] = {
26    {SIG_CLICKED, ""},
27    {NULL, NULL}
28 };
29
30
31 static void
32 _del_hook(Evas_Object *obj)
33 {
34    Widget_Data *wd = elm_widget_data_get(obj);
35
36    if (!wd) return;
37    free(wd);
38 }
39
40 static void
41 _del_pre_hook(Evas_Object *obj)
42 {
43    Widget_Data *wd = elm_widget_data_get(obj);
44
45    if (!wd) return;
46    evas_object_del(wd->img);
47 }
48
49 static void
50 _theme_hook(Evas_Object *obj)
51 {
52    Widget_Data *wd = elm_widget_data_get(obj);
53
54    if (!wd) return;
55    _sizing_eval(obj);
56 }
57
58 static void
59 _sizing_eval(Evas_Object *obj)
60 {
61    Widget_Data *wd = elm_widget_data_get(obj);
62    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
63    int w, h;
64
65    if (!wd) return;
66    _els_smart_icon_size_get(wd->img, &w, &h);
67    _els_smart_icon_scale_up_set(wd->img, wd->scale_up);
68    _els_smart_icon_scale_down_set(wd->img, wd->scale_down);
69    _els_smart_icon_smooth_scale_set(wd->img, wd->smooth);
70    _els_smart_icon_fill_inside_set(wd->img, !(wd->fill_outside));
71    if (wd->no_scale) _els_smart_icon_scale_set(wd->img, 1.0);
72    else
73      {
74         _els_smart_icon_scale_set(wd->img, elm_widget_scale_get(obj) * _elm_config->scale);
75         _els_smart_icon_size_get(wd->img, &w, &h);
76      }
77    if (!wd->scale_down)
78      {
79         minw = w;
80         minh = h;
81      }
82    if (!wd->scale_up)
83      {
84         maxw = w;
85         maxh = h;
86      }
87    evas_object_size_hint_min_set(obj, minw, minh);
88    evas_object_size_hint_max_set(obj, maxw, maxh);
89 }
90
91 static void
92 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
93 {
94    evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
95 }
96
97 EAPI Evas_Object *
98 elm_image_add(Evas_Object *parent)
99 {
100    Evas_Object *obj;
101    Evas *e;
102    Widget_Data *wd;
103
104    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
105
106    ELM_SET_WIDTYPE(widtype, "image");
107    elm_widget_type_set(obj, "image");
108    elm_widget_sub_object_add(parent, obj);
109    elm_widget_data_set(obj, wd);
110    elm_widget_del_hook_set(obj, _del_hook);
111    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
112    elm_widget_theme_hook_set(obj, _theme_hook);
113    elm_widget_can_focus_set(obj, EINA_FALSE);
114
115    wd->img = _els_smart_icon_add(e);
116    evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
117                                   _mouse_up, obj);
118    evas_object_repeat_events_set(wd->img, EINA_TRUE);
119    elm_widget_resize_object_set(obj, wd->img);
120
121    evas_object_smart_callbacks_descriptions_set(obj, _signals);
122
123    wd->smooth = EINA_TRUE;
124    wd->scale_up = EINA_TRUE;
125    wd->scale_down = EINA_TRUE;
126
127    _els_smart_icon_scale_size_set(wd->img, 0);
128
129    _sizing_eval(obj);
130    return obj;
131 }
132
133 EAPI Eina_Bool
134 elm_image_file_set(Evas_Object *obj, const char *file, const char *group)
135 {
136    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
137    Widget_Data *wd = elm_widget_data_get(obj);
138    Eina_Bool ret;
139    const char *p;
140
141    if (!wd) return EINA_FALSE;
142    EINA_SAFETY_ON_NULL_RETURN_VAL(file, EINA_FALSE);
143    if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
144      ret = _els_smart_icon_file_edje_set(wd->img, file, group);
145    else
146      ret = _els_smart_icon_file_key_set(wd->img, file, group);
147    _sizing_eval(obj);
148    return ret;
149 }
150
151 EAPI void
152 elm_image_file_get(const Evas_Object *obj, const char **file, const char **group)
153 {
154    ELM_CHECK_WIDTYPE(obj, widtype);
155    Widget_Data *wd = elm_widget_data_get(obj);
156    if (!wd) return;
157    _els_smart_icon_file_get(wd->img, file, group);
158 }
159
160 EAPI void
161 elm_image_smooth_set(Evas_Object *obj, Eina_Bool smooth)
162 {
163    ELM_CHECK_WIDTYPE(obj, widtype);
164    Widget_Data *wd = elm_widget_data_get(obj);
165
166    if (!wd) return;
167    wd->smooth = smooth;
168    _sizing_eval(obj);
169 }
170
171 EAPI Eina_Bool
172 elm_image_smooth_get(const Evas_Object *obj)
173 {
174    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
175    Widget_Data *wd = elm_widget_data_get(obj);
176
177    if (!wd) return EINA_FALSE;
178    return wd->smooth;
179 }
180
181 EAPI void
182 elm_image_object_size_get(const Evas_Object *obj, int *w, int *h)
183 {
184    ELM_CHECK_WIDTYPE(obj, widtype);
185    Widget_Data *wd = elm_widget_data_get(obj);
186
187    if (!wd) return;
188    _els_smart_icon_size_get(wd->img, w, h);
189 }
190
191 EAPI void
192 elm_image_no_scale_set(Evas_Object *obj, Eina_Bool no_scale)
193 {
194    ELM_CHECK_WIDTYPE(obj, widtype);
195    Widget_Data *wd = elm_widget_data_get(obj);
196
197    if (!wd) return;
198    wd->no_scale = no_scale;
199    _sizing_eval(obj);
200
201 }
202
203 EAPI Eina_Bool
204 elm_image_no_scale_get(const Evas_Object *obj)
205 {
206    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
207    Widget_Data *wd = elm_widget_data_get(obj);
208    if (!wd) return EINA_FALSE;
209    return wd->no_scale;
210 }
211
212 EAPI void
213 elm_image_scale_set(Evas_Object *obj, Eina_Bool scale_up, Eina_Bool scale_down)
214 {
215    ELM_CHECK_WIDTYPE(obj, widtype);
216    Widget_Data *wd = elm_widget_data_get(obj);
217
218    if (!wd) return;
219    wd->scale_up = scale_up;
220    wd->scale_down = scale_down;
221    _sizing_eval(obj);
222 }
223
224 EAPI void
225 elm_image_scale_get(const Evas_Object *obj, Eina_Bool *scale_up, Eina_Bool *scale_down)
226 {
227    ELM_CHECK_WIDTYPE(obj, widtype);
228    Widget_Data *wd = elm_widget_data_get(obj);
229    if (!wd) return;
230    if (scale_up) *scale_up = wd->scale_up;
231    if (scale_down) *scale_down = wd->scale_down;
232 }
233
234 EAPI void
235 elm_image_fill_outside_set(Evas_Object *obj, Eina_Bool fill_outside)
236 {
237    ELM_CHECK_WIDTYPE(obj, widtype);
238    Widget_Data *wd = elm_widget_data_get(obj);
239
240    if (!wd) return;
241    wd->fill_outside = fill_outside;
242    _sizing_eval(obj);
243 }
244
245 EAPI Eina_Bool
246 elm_image_fill_outside_get(const Evas_Object *obj)
247 {
248    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
249    Widget_Data *wd = elm_widget_data_get(obj);
250
251    if (!wd) return EINA_FALSE;
252    return wd->fill_outside;
253 }
254
255 EAPI void
256 elm_image_prescale_set(Evas_Object *obj, int size)
257 {
258    ELM_CHECK_WIDTYPE(obj, widtype);
259    Widget_Data *wd = elm_widget_data_get(obj);
260
261    if (!wd) return;
262    _els_smart_icon_scale_size_set(wd->img, size);
263 }
264
265 EAPI int
266 elm_image_prescale_get(const Evas_Object *obj)
267 {
268    ELM_CHECK_WIDTYPE(obj, widtype) 0;
269    Widget_Data *wd = elm_widget_data_get(obj);
270
271    if (!wd) return 0;
272    return _els_smart_icon_scale_size_get(wd->img);
273 }
274
275 EAPI void
276 elm_image_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
277 {
278    ELM_CHECK_WIDTYPE(obj, widtype);
279    Widget_Data *wd = elm_widget_data_get(obj);
280
281    if (!wd) return;
282    _els_smart_icon_orient_set(wd->img, orient);
283 }
284
285 EAPI Elm_Image_Orient
286 elm_image_orient_get(const Evas_Object *obj)
287 {
288    ELM_CHECK_WIDTYPE(obj, widtype) ELM_IMAGE_ORIENT_NONE;
289    Widget_Data *wd = elm_widget_data_get(obj);
290    if (!wd) return ELM_IMAGE_ORIENT_NONE;
291    return _els_smart_icon_orient_get(wd->img);
292 }
293
294 EAPI void
295 elm_image_editable_set(Evas_Object *obj, Eina_Bool set)
296 {
297    ELM_CHECK_WIDTYPE(obj, widtype);
298    Widget_Data *wd = elm_widget_data_get(obj);
299
300    if (!wd) return;
301    _els_smart_icon_edit_set(wd->img, set, obj);
302 }
303
304 EAPI Eina_Bool
305 elm_image_editable_get(const Evas_Object *obj)
306 {
307    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
308    Widget_Data *wd = elm_widget_data_get(obj);
309    if (!wd) return EINA_FALSE;
310    return _els_smart_icon_edit_get(wd->img);
311 }
312
313 EAPI Evas_Object *
314 elm_image_object_get(const Evas_Object *obj)
315 {
316    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
317    Widget_Data *wd = elm_widget_data_get(obj);
318    if (!wd) return NULL;
319    return _els_smart_icon_object_get(wd->img);
320 }
321
322 EAPI void
323 elm_image_aspect_ratio_retained_set(Evas_Object *obj, Eina_Bool retained)
324 {
325    ELM_CHECK_WIDTYPE(obj, widtype);
326    Widget_Data *wd = elm_widget_data_get(obj);
327    if (!wd) return;
328    return _els_smart_icon_aspect_ratio_retained_set(wd->img, retained);
329 }
330
331 EAPI Eina_Bool
332 elm_image_aspect_ratio_retained_get(const Evas_Object *obj)
333 {
334    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
335    Widget_Data *wd = elm_widget_data_get(obj);
336    if (!wd) return EINA_FALSE;
337    return _els_smart_icon_aspect_ratio_retained_get(wd->img);
338 }
339
340 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 :*/