1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4
5 #define EFL_ACCESS_IMAGE_PROTECTED
6 #define EFL_ACCESS_OBJECT_PROTECTED
7 #define EFL_ACCESS_COMPONENT_PROTECTED
8 #define EFL_ACCESS_WIDGET_ACTION_PROTECTED
9 #define EFL_LAYOUT_CALC_PROTECTED
10 #define EFL_INPUT_CLICKABLE_PROTECTED
11
12 #include <Elementary.h>
13
14 #include "elm_priv.h"
15 #include "efl_ui_widget_image.h"
16
17 #define FMT_SIZE_T "%zu"
18
19 #define MY_CLASS EFL_UI_IMAGE_CLASS
20 #define MY_CLASS_NAME "Efl.Ui.Image"
21
22 #define NON_EXISTING (void *)-1
23 static const char *icon_theme = NULL;
24
25 static const char SIG_DND[] = "drop";
26 static const char SIG_CLICKED[] = "clicked";
27 static const char SIG_DOWNLOAD_START[] = "download,start";
28 static const char SIG_DOWNLOAD_PROGRESS[] = "download,progress";
29 static const char SIG_DOWNLOAD_DONE[] = "download,done";
30 static const char SIG_DOWNLOAD_ERROR[] = "download,error";
31 static const char SIG_LOAD_OPEN[] = "load,open";
32 static const char SIG_LOAD_READY[] = "load,ready";
33 static const char SIG_LOAD_ERROR[] = "load,error";
34 static const char SIG_LOAD_CANCEL[] = "load,cancel";
35 static const Evas_Smart_Cb_Description _smart_callbacks[] = {
36 {SIG_DND, ""},
37 {SIG_CLICKED, ""},
38 {SIG_DOWNLOAD_START, ""},
39 {SIG_DOWNLOAD_PROGRESS, ""},
40 {SIG_DOWNLOAD_DONE, ""},
41 {SIG_DOWNLOAD_ERROR, ""},
42 {SIG_LOAD_OPEN, "Triggered when the file has been opened (image size is known)"},
43 {SIG_LOAD_READY, "Triggered when the image file is ready for display"},
44 {SIG_LOAD_ERROR, "Triggered whenener an I/O or decoding error occurred"},
45 {SIG_LOAD_CANCEL, "Triggered whenener async I/O was cancelled"},
46 {NULL, NULL}
47 };
48
49 static Eina_Bool _key_action_activate(Evas_Object *obj, const char *params);
50 static Eina_Error _efl_ui_image_smart_internal_file_set(Eo *obj, Efl_Ui_Image_Data *sd);
51 static void _efl_ui_image_remote_copier_cancel(Eo *obj, Efl_Ui_Image_Data *sd);
52 static void _efl_ui_image_model_properties_changed_cb(void *data, const Efl_Event *event);
53 static void _on_size_hints_changed(void *data, const Efl_Event *e);
54 static Eina_Bool _efl_ui_image_download(Eo *obj, Efl_Ui_Image_Data *sd, const char *url);
55 static void _update_viewmodel(Eo *obj, Efl_Ui_Image_Data *pd);
56
57 static const Elm_Action key_actions[] = {
58 {"activate", _key_action_activate},
59 {NULL, NULL}
60 };
61
62 typedef struct _Async_Open_Data Async_Open_Data;
63
64 struct _Async_Open_Data
65 {
66 Eo *obj;
67 Eina_Stringshare *file, *key;
68 Eina_File *f_set, *f_open;
69 void *map;
70 };
71
72 static void
_prev_img_del(Efl_Ui_Image_Data * sd)73 _prev_img_del(Efl_Ui_Image_Data *sd)
74 {
75 elm_widget_sub_object_del(sd->self, sd->prev_img);
76 evas_object_smart_member_del(sd->prev_img);
77 evas_object_del(sd->prev_img);
78 sd->prev_img = NULL;
79 }
80
81 static void
_recover_status(Eo * obj,Efl_Ui_Image_Data * sd)82 _recover_status(Eo *obj, Efl_Ui_Image_Data *sd)
83 {
84 int r, g, b, a;
85 Evas_Object *pclip = efl_canvas_object_clipper_get(obj);
86 if (pclip) efl_canvas_object_clipper_set(sd->img, pclip);
87
88 efl_gfx_color_get(obj, &r, &g, &b, &a);
89 efl_gfx_color_set(sd->img, r, g, b, a);
90 efl_gfx_entity_visible_set(sd->img, sd->show);
91 }
92
93 static void
_on_image_preloaded(void * data,Evas * e EINA_UNUSED,Evas_Object * obj,void * event EINA_UNUSED)94 _on_image_preloaded(void *data,
95 Evas *e EINA_UNUSED,
96 Evas_Object *obj,
97 void *event EINA_UNUSED)
98 {
99 Efl_Ui_Image_Data *sd = data;
100 Evas_Load_Error err;
101
102 sd->preload_status = EFL_UI_IMAGE_PRELOADED;
103 if (sd->show) evas_object_show(obj);
104 _prev_img_del(sd);
105 err = evas_object_image_load_error_get(obj);
106 if (!err)
107 {
108 evas_object_smart_callback_call(sd->self, SIG_LOAD_READY, NULL);
109 if (sd->autoplay) efl_player_playing_set(sd->self, EINA_TRUE);
110 }
111 else evas_object_smart_callback_call(sd->self, SIG_LOAD_ERROR, NULL);
112 }
113
114 static void
_on_mouse_up(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info)115 _on_mouse_up(void *data,
116 Evas *e EINA_UNUSED,
117 Evas_Object *obj EINA_UNUSED,
118 void *event_info)
119 {
120 ELM_WIDGET_DATA_GET_OR_RETURN(data, wd);
121
122 Evas_Event_Mouse_Up *ev = event_info;
123
124 if (ev->button != 1) return;
125 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
126 if (!wd->still_in) return;
127
128 evas_object_smart_callback_call(data, "clicked", NULL);
129 }
130
131 static Eina_Bool
_efl_ui_image_animate_cb(void * data)132 _efl_ui_image_animate_cb(void *data)
133 {
134 EFL_UI_IMAGE_DATA_GET(data, sd);
135
136 if (!sd->anim) return ECORE_CALLBACK_CANCEL;
137
138 sd->cur_frame++;
139 if ((sd->frame_count > 0) && (sd->cur_frame > sd->frame_count))
140 {
141 if (sd->playback_loop)
142 sd->cur_frame = sd->cur_frame % sd->frame_count;
143 else
144 {
145 sd->anim_timer = NULL;
146 sd->cur_frame = 0;
147 return EINA_FALSE;
148 }
149 }
150
151 evas_object_image_animated_frame_set(sd->img, sd->cur_frame);
152
153 sd->frame_duration = evas_object_image_animated_frame_duration_get
154 (sd->img, sd->cur_frame, 0);
155
156 if (sd->frame_duration > 0)
157 ecore_timer_interval_set(sd->anim_timer, sd->frame_duration / sd->playback_speed);
158
159 return ECORE_CALLBACK_RENEW;
160 }
161
162 static Evas_Object *
_img_new(Evas_Object * obj)163 _img_new(Evas_Object *obj)
164 {
165 Evas_Object *img;
166
167 EFL_UI_IMAGE_DATA_GET(obj, sd);
168
169 img = evas_object_image_add(evas_object_evas_get(obj));
170 evas_object_image_scale_hint_set(img, EVAS_IMAGE_SCALE_HINT_STATIC);
171 evas_object_event_callback_add
172 (img, EVAS_CALLBACK_IMAGE_PRELOADED, _on_image_preloaded, sd);
173 evas_object_smart_member_add(img, obj);
174 elm_widget_sub_object_add(obj, img);
175
176 return img;
177 }
178
179 static void
_image_sizing_eval(Eo * obj,Efl_Ui_Image_Data * sd,Evas_Object * img)180 _image_sizing_eval(Eo *obj, Efl_Ui_Image_Data *sd, Evas_Object *img)
181 {
182 Evas_Coord x = 0, y = 0, w = 1, h = 1;
183 int ox, oy, ow, oh;
184 Eina_Bool img_no_resize = EINA_FALSE;
185
186 evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
187 if (efl_isa(img, EFL_CANVAS_LAYOUT_CLASS))
188 {
189 x = ox;
190 y = oy;
191 w = ow;
192 h = oh;
193 goto done;
194 }
195 else
196 {
197 double alignh = 0.5, alignv = 0.5;
198 int iw = 0, ih = 0, offset_x = 0, offset_y = 0;
199
200 //1. Get the original image size (iw x ih)
201 evas_object_image_size_get(img, &iw, &ih);
202
203 //Exception Case
204 if ((iw == 0) || (ih == 0) || (ow == 0) || (oh == 0))
205 {
206 img_no_resize = EINA_TRUE;
207 }
208
209 iw = ((double)iw) * sd->scale;
210 ih = ((double)ih) * sd->scale;
211
212 if (iw < 1) iw = 1;
213 if (ih < 1) ih = 1;
214
215 //2. Calculate internal image size (w x h)
216 // according to (iw x ih), (ow x oh), and scale_type
217 switch (sd->scale_type)
218 {
219 case EFL_GFX_IMAGE_SCALE_METHOD_NONE:
220 w = iw;
221 h = ih;
222 break;
223 case EFL_GFX_IMAGE_SCALE_METHOD_FILL:
224 w = ow;
225 h = oh;
226 break;
227 case EFL_GFX_IMAGE_SCALE_METHOD_FIT:
228 w = ow;
229 h = ((double)ih * w) / (double)iw;
230 if (h > oh)
231 {
232 h = oh;
233 w = ((double)iw * h) / (double)ih;
234 }
235 break;
236 case EFL_GFX_IMAGE_SCALE_METHOD_FIT_WIDTH:
237 w = ow;
238 h = ((double)ih * w) / (double)iw;
239 break;
240 case EFL_GFX_IMAGE_SCALE_METHOD_FIT_HEIGHT:
241 h = oh;
242 w = ((double)iw * h) / (double)ih;
243 break;
244 case EFL_GFX_IMAGE_SCALE_METHOD_EXPAND:
245 w = ow;
246 h = ((double)ih * w) / (double)iw;
247 if (h < oh)
248 {
249 h = oh;
250 w = ((double)iw * h) / (double)ih;
251 }
252 break;
253 case EFL_GFX_IMAGE_SCALE_METHOD_TILE:
254 evas_object_geometry_get(obj, &x, &y, &w, &h);
255 evas_object_image_fill_set(img, x, y, iw, ih);
256 goto done;
257 }
258 if (((!sd->scale_up) && (w > iw))
259 || ((!sd->scale_down) && (w < iw)))
260 {
261 w = iw;
262 }
263 if (((!sd->scale_up) && (h > ih))
264 || ((!sd->scale_down) && (h < ih)))
265 {
266 h = ih;
267 }
268 //3. Calculate offset according to align value
269 if (!elm_widget_is_legacy(sd->self))
270 {
271 offset_x = ((ow - w) * sd->align_x);
272 offset_y = ((oh - h) * sd->align_y);
273 }
274 else
275 {
276 evas_object_size_hint_align_get(sd->self, &alignh, &alignv);
277 if (EINA_DBL_EQ(alignh, EVAS_HINT_FILL)) alignh = 0.5;
278 if (EINA_DBL_EQ(alignv, EVAS_HINT_FILL)) alignv = 0.5;
279
280 offset_x = ((ow - w) * alignh);
281 offset_y = ((oh - h) * alignv);
282 }
283
284 x = ox + offset_x;
285 y = oy + offset_y;
286
287 //4. Fill, move, resize
288 if (offset_x >= 0) offset_x = 0;
289 if (offset_y >= 0) offset_y = 0;
290
291 evas_object_image_fill_set(img, offset_x, offset_y, w, h);
292
293 if (ow - w < 0)
294 {
295 x = ox;
296 w = ow;
297 }
298 if (oh - h < 0)
299 {
300 y = oy;
301 h = oh;
302 }
303 }
304 done:
305 if (img_no_resize)
306 evas_object_geometry_set(img, 0, 0, 0, 0);
307 else
308 evas_object_geometry_set(img, x, y, w, h);
309
310 evas_object_geometry_set(sd->hit_rect, x, y, w, h);
311 }
312
313 static inline void
_async_open_data_free(Async_Open_Data * data)314 _async_open_data_free(Async_Open_Data *data)
315 {
316 if (!data) return;
317 eina_stringshare_del(data->file);
318 eina_stringshare_del(data->key);
319 if (data->map) eina_file_map_free(data->f_open, data->map);
320 if (data->f_open) eina_file_close(data->f_open);
321 if (data->f_set) eina_file_close(data->f_set);
322 free(data);
323 }
324
325 static void
_efl_ui_image_async_open_do(void * data,Ecore_Thread * thread)326 _efl_ui_image_async_open_do(void *data, Ecore_Thread *thread)
327 {
328 Async_Open_Data *todo = data;
329 Eina_File *f;
330 void *map = NULL;
331 size_t size;
332
333 if (ecore_thread_check(thread)) return;
334
335 if (todo->f_set) f = eina_file_dup(todo->f_set);
336 else if (todo->file)
337 {
338 // blocking
339 f = eina_file_open(todo->file, EINA_FALSE);
340 if (!f) return;
341 }
342 else
343 {
344 CRI("Async open has no input file!");
345 return;
346 }
347 if (ecore_thread_check(thread))
348 {
349 if (!todo->f_set) eina_file_close(f);
350 return;
351 }
352
353 // Read just enough data for map to actually do something.
354 size = eina_file_size_get(f);
355 // Read and ensure all pages are in memory for sure first just
356 // 1 byte per page will do. also keep a limit on how much we will
357 // blindly load in here to let's say 32KB (Should be enough to get
358 // image headers without getting to much data from the hard drive).
359 size = size > 32 * 1024 ? 32 * 1024 : size;
360 map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
361 eina_file_map_populate(f, EINA_FILE_POPULATE, map, 0, size);
362
363 if (ecore_thread_check(thread))
364 {
365 if (map) eina_file_map_free(f, map);
366 if (!todo->f_set) eina_file_close(f);
367 return;
368 }
369 todo->f_open = f;
370 todo->map = map;
371 }
372
373 static void
_async_clear(Efl_Ui_Image_Data * sd)374 _async_clear(Efl_Ui_Image_Data *sd)
375 {
376 sd->async.th = NULL;
377 sd->async.todo = NULL;
378 eina_stringshare_del(sd->async.file);
379 eina_stringshare_del(sd->async.key);
380 sd->async.file = NULL;
381 sd->async.key = NULL;
382 }
383
384 static void
_async_cancel(Efl_Ui_Image_Data * sd)385 _async_cancel(Efl_Ui_Image_Data *sd)
386 {
387 if (sd->async.th)
388 {
389 ecore_thread_cancel(sd->async.th);
390 ((Async_Open_Data *)(sd->async.todo))->obj = NULL;
391 _async_clear(sd);
392 }
393 }
394
395 static void
_efl_ui_image_async_open_cancel(void * data,Ecore_Thread * thread)396 _efl_ui_image_async_open_cancel(void *data, Ecore_Thread *thread)
397 {
398 Async_Open_Data *todo = data;
399
400 DBG("Async open thread was canceled");
401 if (todo->obj)
402 {
403 EFL_UI_IMAGE_DATA_GET(todo->obj, sd);
404 if (sd)
405 {
406 evas_object_smart_callback_call(todo->obj, SIG_LOAD_CANCEL, NULL);
407 if (thread == sd->async.th) _async_clear(sd);
408 }
409 }
410 _async_open_data_free(todo);
411 }
412
413 static void
_efl_ui_image_async_open_done(void * data,Ecore_Thread * thread)414 _efl_ui_image_async_open_done(void *data, Ecore_Thread *thread)
415 {
416 Async_Open_Data *todo = data;
417 const char *key;
418 Eina_Bool ok;
419 Eina_File *f;
420 void *map;
421
422 if (todo->obj)
423 {
424 EFL_UI_IMAGE_DATA_GET(todo->obj, sd);
425 if (sd)
426 {
427 if (thread == sd->async.th)
428 {
429 DBG("Async open succeeded");
430 _async_clear(sd);
431 key = todo->key;
432 map = todo->map;
433 f = todo->f_open;
434 ok = f && map;
435
436 if (ok)
437 {
438 efl_file_key_set(sd->self, key);
439 ok = !efl_file_mmap_set(sd->self, f);
440 if (ok)
441 {
442 if (sd->edje)
443 {
444 _prev_img_del(sd);
445 ok = edje_object_mmap_set(sd->img, f, key);
446 }
447 else
448 ok = !_efl_ui_image_smart_internal_file_set(sd->self, sd);
449 }
450 }
451 if (ok)
452 {
453 evas_object_smart_callback_call(sd->self, SIG_LOAD_OPEN, NULL);
454 if (sd->autoplay) efl_player_playing_set(sd->self, EINA_TRUE);
455 }
456 else evas_object_smart_callback_call(sd->self, SIG_LOAD_ERROR, NULL);
457 }
458 }
459 }
460 // close f, map and free strings
461 _async_open_data_free(todo);
462 }
463
464 static Eina_Error
_efl_ui_image_async_file_set(Eo * obj,Efl_Ui_Image_Data * sd)465 _efl_ui_image_async_file_set(Eo *obj, Efl_Ui_Image_Data *sd)
466 {
467 Async_Open_Data *todo;
468 const char *file = efl_file_get(obj);
469 const char *key = efl_file_key_get(obj);
470 const Eina_File *f = efl_file_mmap_get(obj);
471
472 if (sd->async.th &&
473 ((file == sd->async.file) ||
474 (file && sd->async.file && !strcmp(file, sd->async.file))) &&
475 ((key == sd->async.key) ||
476 (key && sd->async.key && !strcmp(key, sd->async.key))))
477 return 0;
478
479 todo = calloc(1, sizeof(Async_Open_Data));
480 if (!todo) return EINA_FALSE;
481
482 _async_cancel(sd);
483
484 todo->obj = obj;
485 todo->file = eina_stringshare_add(file);
486 todo->key = eina_stringshare_add(key);
487 todo->f_set = f ? eina_file_dup(f) : NULL;
488
489 eina_stringshare_replace(&sd->async.file, file);
490 eina_stringshare_replace(&sd->async.key, key);
491
492 sd->async.todo = todo;
493 sd->async.th = ecore_thread_run(_efl_ui_image_async_open_do,
494 _efl_ui_image_async_open_done,
495 _efl_ui_image_async_open_cancel, todo);
496 if (sd->async.th) return 0;
497
498 _async_open_data_free(todo);
499 _async_clear(sd);
500 DBG("Could not spawn an async thread!");
501 return EFL_GFX_IMAGE_LOAD_ERROR_GENERIC;
502 }
503
504 static Eina_Error
_efl_ui_image_edje_file_set(Evas_Object * obj)505 _efl_ui_image_edje_file_set(Evas_Object *obj)
506 {
507 Eina_Error err;
508 const Eina_File *f;
509 const char *key;
510
511 EFL_UI_IMAGE_DATA_GET(obj, sd);
512
513 err = efl_file_load(efl_super(obj, MY_CLASS));
514 if (err) return err;
515
516 f = efl_file_mmap_get(obj);
517 key = efl_file_key_get(obj);
518 _prev_img_del(sd);
519
520 if (!sd->edje)
521 {
522 evas_object_del(sd->img);
523
524 /* Edje object instead */
525 sd->img = edje_object_add(evas_object_evas_get(obj));
526 _recover_status(obj, sd);
527 sd->edje = EINA_TRUE;
528 evas_object_smart_member_add(sd->img, obj);
529 }
530
531 _async_cancel(sd);
532
533 if (!sd->async_enable)
534 {
535 efl_file_key_set(sd->img, key);
536 err = efl_file_mmap_set(sd->img, f);
537 if (!err) err = efl_file_load(sd->img);
538 if (err)
539 {
540 ERR("failed to set edje file '%s', group '%s': %s", eina_file_filename_get(f), key,
541 edje_load_error_str(edje_object_load_error_get(sd->img)));
542 return err;
543 }
544 }
545 else
546 return _efl_ui_image_async_file_set(obj, sd);
547 if (sd->autoplay) efl_player_playing_set(sd->self, EINA_TRUE);
548
549 /* FIXME: do i want to update icon on file change ? */
550 efl_canvas_group_change(obj);
551
552 return 0;
553 }
554
555 EOLIAN static void
_efl_ui_image_efl_gfx_image_smooth_scale_set(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd,Eina_Bool smooth)556 _efl_ui_image_efl_gfx_image_smooth_scale_set(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd, Eina_Bool smooth)
557 {
558 sd->smooth = smooth;
559 if (sd->img && (!sd->edje)) evas_object_image_smooth_scale_set(sd->img, smooth);
560 }
561
562 EOLIAN static Eina_Bool
_efl_ui_image_efl_gfx_image_smooth_scale_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)563 _efl_ui_image_efl_gfx_image_smooth_scale_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
564 {
565 return sd->smooth;
566 }
567
568 static Eina_Bool
_efl_ui_image_drag_n_drop_cb(void * elm_obj,Evas_Object * obj,Elm_Selection_Data * drop)569 _efl_ui_image_drag_n_drop_cb(void *elm_obj,
570 Evas_Object *obj,
571 Elm_Selection_Data *drop)
572 {
573 Eina_Bool ret = EINA_FALSE;
574 ret = efl_file_simple_load(obj, drop->data, NULL);
575 if (ret)
576 {
577 DBG("dnd: %s, %s, %s", elm_widget_type_get(elm_obj),
578 SIG_DND, (char *)drop->data);
579
580 efl_event_callback_legacy_call(elm_obj, EFL_UI_IMAGE_EVENT_DROP, drop->data);
581 return EINA_TRUE;
582 }
583
584 return EINA_FALSE;
585 }
586
587 EOLIAN static void
_efl_ui_image_efl_canvas_group_group_add(Eo * obj,Efl_Ui_Image_Data * priv)588 _efl_ui_image_efl_canvas_group_group_add(Eo *obj, Efl_Ui_Image_Data *priv)
589 {
590 efl_canvas_group_add(efl_super(obj, MY_CLASS));
591
592 priv->hit_rect = evas_object_rectangle_add(evas_object_evas_get(obj));
593 evas_object_smart_member_add(priv->hit_rect, obj);
594 elm_widget_sub_object_add(obj, priv->hit_rect);
595
596 evas_object_color_set(priv->hit_rect, 0, 0, 0, 0);
597 evas_object_show(priv->hit_rect);
598 evas_object_repeat_events_set(priv->hit_rect, EINA_TRUE);
599
600 if (elm_widget_is_legacy(obj))
601 {
602 evas_object_event_callback_add
603 (priv->hit_rect, EVAS_CALLBACK_MOUSE_UP, _on_mouse_up, obj);
604 priv->playback_loop = EINA_TRUE;
605 }
606 else
607 {
608 efl_ui_action_connector_bind_clickable_to_object(priv->hit_rect, obj);
609 }
610
611 priv->smooth = EINA_TRUE;
612 priv->fill_inside = EINA_TRUE;
613 priv->aspect_fixed = EINA_TRUE;
614 priv->load_size = EINA_SIZE2D(0, 0);
615 priv->scale = 1.0;
616 priv->scale_up = EINA_TRUE;
617 priv->scale_down = EINA_TRUE;
618 priv->align_x = 0.5;
619 priv->align_y = 0.5;
620
621 elm_widget_can_focus_set(obj, EINA_FALSE);
622 }
623
624 EOLIAN static void
_efl_ui_image_efl_canvas_group_group_del(Eo * obj,Efl_Ui_Image_Data * sd)625 _efl_ui_image_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Image_Data *sd)
626 {
627 Efl_Model *model;
628
629 if (elm_widget_is_legacy(obj))
630 efl_event_callback_del(obj, EFL_GFX_ENTITY_EVENT_HINTS_CHANGED,
631 _on_size_hints_changed, sd);
632 ecore_timer_del(sd->anim_timer);
633 evas_object_del(sd->img);
634 _prev_img_del(sd);
635 _async_cancel(sd);
636 if (sd->remote.copier) _efl_ui_image_remote_copier_cancel(obj, sd);
637 if (sd->remote.binbuf) ELM_SAFE_FREE(sd->remote.binbuf, eina_binbuf_free);
638 ELM_SAFE_FREE(sd->remote.key, eina_stringshare_del);
639
640 model = efl_ui_view_model_get(obj);
641 if (model)
642 {
643 efl_event_callback_del(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
644 _efl_ui_image_model_properties_changed_cb, obj);
645 }
646
647 efl_canvas_group_del(efl_super(obj, MY_CLASS));
648 }
649
650 /* this function exists solely to call efl_canvas_group_change */
651 EOLIAN static void
_efl_ui_image_efl_gfx_entity_position_set(Eo * obj,Efl_Ui_Image_Data * sd EINA_UNUSED,Eina_Position2D pos)652 _efl_ui_image_efl_gfx_entity_position_set(Eo *obj, Efl_Ui_Image_Data *sd EINA_UNUSED, Eina_Position2D pos)
653 {
654 if (_evas_object_intercept_call(obj, EVAS_OBJECT_INTERCEPT_CB_MOVE, 0, pos.x, pos.y))
655 return;
656
657 efl_gfx_entity_position_set(efl_super(obj, MY_CLASS), pos);
658 efl_canvas_group_change(obj);
659 }
660
661 /* this function exists solely to call efl_canvas_group_change */
662 EOLIAN static void
_efl_ui_image_efl_gfx_entity_size_set(Eo * obj,Efl_Ui_Image_Data * sd EINA_UNUSED,Eina_Size2D sz)663 _efl_ui_image_efl_gfx_entity_size_set(Eo *obj, Efl_Ui_Image_Data *sd EINA_UNUSED, Eina_Size2D sz)
664 {
665 if (_evas_object_intercept_call(obj, EVAS_OBJECT_INTERCEPT_CB_RESIZE, 0, sz.w, sz.h))
666 return;
667
668 efl_gfx_entity_size_set(efl_super(obj, MY_CLASS), sz);
669 efl_canvas_group_change(obj);
670 }
671
672 static void
_efl_ui_image_show(Eo * obj,Efl_Ui_Image_Data * sd)673 _efl_ui_image_show(Eo *obj, Efl_Ui_Image_Data *sd)
674 {
675 sd->show = EINA_TRUE;
676
677 efl_gfx_entity_visible_set(efl_super(obj, MY_CLASS), EINA_TRUE);
678
679 if (sd->preload_status == EFL_UI_IMAGE_PRELOADING) return;
680 if (sd->img) efl_gfx_entity_visible_set(sd->img, EINA_TRUE);
681 _prev_img_del(sd);
682 }
683
684 static void
_efl_ui_image_hide(Eo * obj,Efl_Ui_Image_Data * sd)685 _efl_ui_image_hide(Eo *obj, Efl_Ui_Image_Data *sd)
686 {
687 sd->show = EINA_FALSE;
688 efl_gfx_entity_visible_set(efl_super(obj, MY_CLASS), EINA_FALSE);
689 if (sd->img) efl_gfx_entity_visible_set(sd->img, EINA_FALSE);
690 _prev_img_del(sd);
691 }
692
693 EOLIAN static void
_efl_ui_image_efl_gfx_entity_visible_set(Eo * obj,Efl_Ui_Image_Data * sd,Eina_Bool vis)694 _efl_ui_image_efl_gfx_entity_visible_set(Eo *obj, Efl_Ui_Image_Data *sd, Eina_Bool vis)
695 {
696 if (_evas_object_intercept_call(obj, EVAS_OBJECT_INTERCEPT_CB_VISIBLE, 0, vis))
697 return;
698
699 if (vis) _efl_ui_image_show(obj, sd);
700 else _efl_ui_image_hide(obj, sd);
701 }
702
703 EOLIAN static void
_efl_ui_image_efl_canvas_group_group_member_add(Eo * obj,Efl_Ui_Image_Data * sd,Evas_Object * member)704 _efl_ui_image_efl_canvas_group_group_member_add(Eo *obj, Efl_Ui_Image_Data *sd, Evas_Object *member)
705 {
706 efl_canvas_group_member_add(efl_super(obj, MY_CLASS), member);
707
708 if (sd->hit_rect)
709 evas_object_raise(sd->hit_rect);
710 }
711
712 EOLIAN static void
_efl_ui_image_efl_gfx_color_color_set(Eo * obj,Efl_Ui_Image_Data * sd,int r,int g,int b,int a)713 _efl_ui_image_efl_gfx_color_color_set(Eo *obj, Efl_Ui_Image_Data *sd, int r, int g, int b, int a)
714 {
715 if (_evas_object_intercept_call(obj, EVAS_OBJECT_INTERCEPT_CB_COLOR_SET, 0, r, g, b, a))
716 return;
717
718 efl_gfx_color_set(efl_super(obj, MY_CLASS), r, g, b, a);
719
720 evas_object_color_set(sd->hit_rect, 0, 0, 0, 0);
721 if (sd->img) evas_object_color_set(sd->img, r, g, b, a);
722 if (sd->prev_img) evas_object_color_set(sd->prev_img, r, g, b, a);
723 }
724
725 EOLIAN static void
_efl_ui_image_efl_canvas_object_clipper_set(Eo * obj,Efl_Ui_Image_Data * sd,Evas_Object * clip)726 _efl_ui_image_efl_canvas_object_clipper_set(Eo *obj, Efl_Ui_Image_Data *sd, Evas_Object *clip)
727 {
728 if (_evas_object_intercept_call(obj, EVAS_OBJECT_INTERCEPT_CB_CLIP_SET, 0, clip))
729 return;
730
731 efl_canvas_object_clipper_set(efl_super(obj, MY_CLASS), clip);
732
733 if (sd->img) evas_object_clip_set(sd->img, clip);
734 if (sd->prev_img) evas_object_clip_set(sd->prev_img, clip);
735 }
736
737 EOLIAN static Eina_Error
_efl_ui_image_efl_ui_widget_theme_apply(Eo * obj,Efl_Ui_Image_Data * sd EINA_UNUSED)738 _efl_ui_image_efl_ui_widget_theme_apply(Eo *obj, Efl_Ui_Image_Data *sd EINA_UNUSED)
739 {
740 Eina_Error int_ret = EFL_UI_THEME_APPLY_ERROR_GENERIC;
741
742 if (sd->stdicon)
743 _elm_theme_object_icon_set(obj, sd->stdicon, elm_widget_style_get(obj));
744
745 int_ret = efl_ui_widget_theme_apply(efl_super(obj, MY_CLASS));
746 if (int_ret == EFL_UI_THEME_APPLY_ERROR_GENERIC) return int_ret;
747
748 efl_canvas_group_change(obj);
749
750 return int_ret;
751 }
752
753 static Eina_Bool
_key_action_activate(Evas_Object * obj,const char * params EINA_UNUSED)754 _key_action_activate(Evas_Object *obj, const char *params EINA_UNUSED)
755 {
756 if (elm_widget_is_legacy(obj))
757 evas_object_smart_callback_call(obj, "clicked", NULL);
758 else
759 efl_event_callback_call(obj, EFL_INPUT_EVENT_CLICKED, NULL);
760 return EINA_TRUE;
761 }
762
763 static void
_efl_ui_image_efl_canvas_group_group_calculate(Eo * obj,Efl_Ui_Image_Data * sd)764 _efl_ui_image_efl_canvas_group_group_calculate(Eo *obj, Efl_Ui_Image_Data *sd)
765 {
766 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
767 Eina_Size2D sz;
768 double ts;
769
770 sd->in_calc = EINA_TRUE;
771 // TODO: remove this function after using the widget's scale value instead of image's scale value,
772 if (sd->no_scale)
773 sd->scale = 1.0;
774 else
775 sd->scale = efl_gfx_entity_scale_get(obj) * elm_config_scale_get();
776
777 ts = sd->scale;
778 sd->scale = 1.0;
779 sz = efl_gfx_view_size_get(obj);
780
781 sd->scale = ts;
782 evas_object_size_hint_combined_min_get(obj, &minw, &minh);
783
784 if (sd->no_scale)
785 {
786 maxw = minw = sz.w;
787 maxh = minh = sz.h;
788 if ((sd->scale > 1.0) && (sd->scale_up))
789 {
790 maxw = minw = sz.w * sd->scale;
791 maxh = minh = sz.h * sd->scale;
792 }
793 else if ((sd->scale < 1.0) && (sd->scale_down))
794 {
795 maxw = minw = sz.w * sd->scale;
796 maxh = minh = sz.h * sd->scale;
797 }
798 }
799 else
800 {
801 if (!sd->scale_down)
802 {
803 minw = sz.w * sd->scale;
804 minh = sz.h * sd->scale;
805 }
806 if (!sd->scale_up)
807 {
808 maxw = sz.w * sd->scale;
809 maxh = sz.h * sd->scale;
810 }
811 }
812
813 efl_gfx_hint_size_restricted_min_set(obj, EINA_SIZE2D(minw, minh));
814 efl_gfx_hint_size_restricted_max_set(obj, EINA_SIZE2D(maxw, maxh));
815
816 if (sd->img)
817 {
818 //Retained way. Nothing does, if either way hasn't been changed.
819 if (!sd->edje)
820 efl_gfx_image_orientation_set(sd->img, sd->orient);
821
822 _image_sizing_eval(obj, sd, sd->img);
823 if (sd->prev_img) _image_sizing_eval(obj, sd, sd->prev_img);
824 }
825 sd->in_calc = EINA_FALSE;
826 }
827
828 static void
_efl_ui_image_load_size_set_internal(Evas_Object * obj,Efl_Ui_Image_Data * sd)829 _efl_ui_image_load_size_set_internal(Evas_Object *obj, Efl_Ui_Image_Data *sd)
830 {
831 Eina_Size2D sz = sd->load_size;
832
833 if ((sz.w <= 0) || (sz.h <= 0))
834 sz = efl_gfx_view_size_get(obj);
835 evas_object_image_load_size_set(sd->img, sz.w, sz.h);
836 }
837
838 static void
_efl_ui_image_file_set_do(Evas_Object * obj)839 _efl_ui_image_file_set_do(Evas_Object *obj)
840 {
841 EFL_UI_IMAGE_DATA_GET(obj, sd);
842
843 ELM_SAFE_FREE(sd->prev_img, evas_object_del);
844
845 sd->prev_img = sd->img;
846 sd->img = _img_new(obj);
847 _recover_status(obj, sd);
848
849 sd->edje = EINA_FALSE;
850 evas_object_image_smooth_scale_set(sd->img, sd->smooth);
851 evas_object_image_load_orientation_set(sd->img, EINA_TRUE);
852 _efl_ui_image_load_size_set_internal(obj, sd);
853 }
854
855 static void
_on_size_hints_changed(void * data,const Efl_Event * ev)856 _on_size_hints_changed(void *data, const Efl_Event *ev)
857 {
858 Efl_Ui_Image_Data *pd = data;
859 if (!pd->in_calc)
860 efl_canvas_group_change(ev->object);
861 }
862
863 static void
_efl_ui_image_model_changed(void * data,const Efl_Event * event)864 _efl_ui_image_model_changed(void *data, const Efl_Event *event)
865 {
866 Efl_Model_Changed_Event *ev = event->info;
867
868 if (ev->previous)
869 efl_event_callback_del(ev->previous, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
870 _efl_ui_image_model_properties_changed_cb, event->object);
871 if (ev->current)
872 efl_event_callback_add(ev->current, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
873 _efl_ui_image_model_properties_changed_cb, event->object);
874
875 _update_viewmodel(event->object, data);
876 }
877
878 EOLIAN static Eo *
_efl_ui_image_efl_object_constructor(Eo * obj,Efl_Ui_Image_Data * pd)879 _efl_ui_image_efl_object_constructor(Eo *obj, Efl_Ui_Image_Data *pd)
880 {
881 obj = efl_constructor(efl_super(obj, MY_CLASS));
882 evas_object_smart_callbacks_descriptions_set(obj, _smart_callbacks);
883 efl_access_object_role_set(obj, EFL_ACCESS_ROLE_IMAGE);
884
885 pd->scale_type = EFL_GFX_IMAGE_SCALE_METHOD_FIT;
886 pd->self = obj;
887 /* legacy elm_image starts paused */
888 pd->paused = elm_widget_is_legacy(obj);
889 pd->playback_speed = 1;
890
891 return obj;
892 }
893
894 EOLIAN static void
_efl_ui_image_efl_object_invalidate(Eo * obj,Efl_Ui_Image_Data * pd EINA_UNUSED)895 _efl_ui_image_efl_object_invalidate(Eo *obj, Efl_Ui_Image_Data *pd EINA_UNUSED)
896 {
897 Efl_Model *model;
898
899 if (pd->property_watch)
900 efl_event_callback_del(obj, EFL_UI_VIEW_EVENT_MODEL_CHANGED,
901 _efl_ui_image_model_changed, pd);
902
903 model = efl_ui_view_model_get(obj);
904 if (model)
905 efl_event_callback_del(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
906 _efl_ui_image_model_properties_changed_cb, obj);
907 efl_invalidate(efl_super(obj, EFL_UI_IMAGE_CLASS));
908 }
909
910 static const Eina_Slice remote_uri[] = {
911 EINA_SLICE_STR_LITERAL("http://"),
912 EINA_SLICE_STR_LITERAL("https://"),
913 EINA_SLICE_STR_LITERAL("ftp://"),
914 { }
915 };
916
917 static inline Eina_Bool
_efl_ui_image_is_remote(const char * file)918 _efl_ui_image_is_remote(const char *file)
919 {
920 Eina_Slice s = EINA_SLICE_STR(file);
921 const Eina_Slice *itr;
922
923 for (itr = remote_uri; itr->mem; itr++)
924 if (eina_slice_startswith(s, *itr))
925 return EINA_TRUE;
926
927 return EINA_FALSE;
928 }
929
930 EOLIAN Eina_Error
_efl_ui_image_efl_file_load(Eo * obj,Efl_Ui_Image_Data * sd)931 _efl_ui_image_efl_file_load(Eo *obj, Efl_Ui_Image_Data *sd)
932 {
933 Eina_Error ret;
934 const char *file = efl_file_get(obj);
935
936 if (efl_file_loaded_get(obj)) return 0;
937 _async_cancel(sd);
938
939 /* stop preloading as it may hit to-be-freed memory */
940 if (sd->img && sd->preload_status == EFL_UI_IMAGE_PRELOADING)
941 evas_object_image_preload(sd->img, EINA_TRUE);
942
943 if (sd->remote.copier) _efl_ui_image_remote_copier_cancel(obj, sd);
944 if (sd->remote.binbuf) ELM_SAFE_FREE(sd->remote.binbuf, eina_binbuf_free);
945
946 if (sd->anim)
947 {
948 ELM_SAFE_FREE(sd->anim_timer, ecore_timer_del);
949 sd->paused = elm_widget_is_legacy(obj);
950 sd->anim = EINA_FALSE;
951 sd->frame_count = -1;
952 sd->cur_frame = -1;
953 sd->frame_duration = -1;
954 }
955
956 if (file && _efl_ui_image_is_remote(file))
957 {
958 evas_object_hide(sd->img);
959 if (_efl_ui_image_download(obj, sd, file))
960 {
961 evas_object_smart_callback_call(obj, SIG_DOWNLOAD_START, NULL);
962 return 0;
963 }
964 }
965
966 if (!sd->async_enable)
967 ret = _efl_ui_image_smart_internal_file_set(obj, sd);
968 else
969 ret = _efl_ui_image_async_file_set(obj, sd);
970
971 return ret;
972 }
973
974 EOLIAN void
_efl_ui_image_efl_file_unload(Eo * obj,Efl_Ui_Image_Data * sd)975 _efl_ui_image_efl_file_unload(Eo *obj, Efl_Ui_Image_Data *sd)
976 {
977 _async_cancel(sd);
978
979 /* stop preloading as it may hit to-be-freed memory */
980 if (sd->img && sd->preload_status == EFL_UI_IMAGE_PRELOADING)
981 evas_object_image_preload(sd->img, EINA_TRUE);
982
983 if (sd->remote.copier) _efl_ui_image_remote_copier_cancel(obj, sd);
984 if (sd->remote.binbuf) ELM_SAFE_FREE(sd->remote.binbuf, eina_binbuf_free);
985
986 if (sd->anim)
987 {
988 ELM_SAFE_FREE(sd->anim_timer, ecore_timer_del);
989 sd->paused = elm_widget_is_legacy(obj);
990 sd->anim = EINA_FALSE;
991 sd->frame_count = -1;
992 sd->cur_frame = -1;
993 sd->frame_duration = -1;
994 }
995
996 if (sd->prev_img)
997 _prev_img_del(sd);
998 _efl_ui_image_file_set_do(obj);
999 efl_file_unload(sd->img);
1000 efl_file_unload(efl_super(obj, MY_CLASS));
1001
1002 efl_canvas_group_change(obj);
1003 }
1004
1005 static Eina_Error
_efl_ui_image_smart_internal_file_set(Eo * obj,Efl_Ui_Image_Data * sd)1006 _efl_ui_image_smart_internal_file_set(Eo *obj, Efl_Ui_Image_Data *sd)
1007 {
1008 Eina_Error err;
1009 const Eina_File *f;
1010 const char *key;
1011 const char *file = efl_file_get(obj);
1012
1013 if (eina_str_has_extension(file, ".edj"))
1014 return _efl_ui_image_edje_file_set(obj);
1015
1016 err = efl_file_load(efl_super(obj, MY_CLASS));
1017 if (err) return err;
1018
1019 f = efl_file_mmap_get(obj);
1020 key = efl_file_key_get(obj);
1021
1022 _efl_ui_image_file_set_do(obj);
1023
1024 evas_object_image_mmap_set(sd->img, f, key);
1025
1026 err = evas_object_image_load_error_get(sd->img);
1027 if (err)
1028 {
1029 if (file || f)
1030 {
1031 if (key)
1032 ERR("Failed to load image '%s' '%s': %s. (%p)",
1033 eina_file_filename_get(f), key,
1034 evas_load_error_str(err), obj);
1035 else
1036 ERR("Failed to load image '%s': %s. (%p)",
1037 eina_file_filename_get(f),
1038 evas_load_error_str(err), obj);
1039 }
1040 else
1041 {
1042 ERR("NULL image file passed! (%p)", obj);
1043 }
1044 _prev_img_del(sd);
1045 return err;
1046 }
1047
1048 if (sd->preload_status == EFL_UI_IMAGE_PRELOAD_DISABLED)
1049 {
1050 _prev_img_del(sd);
1051 if (sd->autoplay) efl_player_playing_set(sd->self, EINA_TRUE);
1052 }
1053 else
1054 {
1055 evas_object_hide(sd->img);
1056 sd->preload_status = EFL_UI_IMAGE_PRELOADING;
1057 evas_object_image_preload(sd->img, EINA_FALSE);
1058 }
1059
1060 efl_canvas_group_change(obj);
1061
1062 return 0;
1063 }
1064
1065 static void
_efl_ui_image_remote_copier_del(void * data EINA_UNUSED,const Efl_Event * event)1066 _efl_ui_image_remote_copier_del(void *data EINA_UNUSED, const Efl_Event *event)
1067 {
1068 Eo *dialer = efl_io_copier_source_get(event->object);
1069 efl_del(dialer);
1070 }
1071
1072 static void
_efl_ui_image_remote_copier_cancel(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)1073 _efl_ui_image_remote_copier_cancel(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1074 {
1075 Eo *copier = sd->remote.copier;
1076
1077 if (!copier) return;
1078 /* copier is flagged as close_on_invalidate, thus:
1079 * efl_del()
1080 * -> efl_io_closer_close()
1081 * -> "done" event
1082 * -> _efl_ui_image_remote_copier_done()
1083 *
1084 * flag sd->remote.copier = NULL so _efl_ui_image_remote_copier_done()
1085 * knows about it.
1086 */
1087 sd->remote.copier = NULL;
1088 efl_del(copier);
1089 }
1090
1091 static void
_efl_ui_image_remote_copier_done(void * data,const Efl_Event * event EINA_UNUSED)1092 _efl_ui_image_remote_copier_done(void *data, const Efl_Event *event EINA_UNUSED)
1093 {
1094 Eo *obj = data;
1095 Efl_Ui_Image_Data *sd = efl_data_scope_get(obj, MY_CLASS);
1096 Eina_File *f;
1097 Eo *dialer;
1098 const char *url;
1099 Eina_Error ret;
1100
1101 /* we're called from _efl_ui_image_remote_copier_cancel() */
1102 if (!sd->remote.copier) return;
1103
1104 /* stop preloading as it may hit to-be-freed memory */
1105 if (sd->img && sd->preload_status == EFL_UI_IMAGE_PRELOADING)
1106 evas_object_image_preload(sd->img, EINA_TRUE);
1107
1108 if (sd->remote.binbuf) eina_binbuf_free(sd->remote.binbuf);
1109 sd->remote.binbuf = efl_io_copier_binbuf_steal(sd->remote.copier);
1110
1111 dialer = efl_io_copier_source_get(sd->remote.copier);
1112 url = efl_net_dialer_address_dial_get(dialer);
1113 f = eina_file_virtualize(url,
1114 eina_binbuf_string_get(sd->remote.binbuf),
1115 eina_binbuf_length_get(sd->remote.binbuf),
1116 EINA_FALSE);
1117 efl_file_mmap_set(obj, f);
1118 ret = _efl_ui_image_smart_internal_file_set(obj, sd);
1119 eina_file_close(f);
1120
1121 if (ret)
1122 {
1123 Efl_Ui_Image_Error err = { 0, EINA_TRUE };
1124
1125 ELM_SAFE_FREE(sd->remote.binbuf, eina_binbuf_free);
1126 evas_object_smart_callback_call(obj, SIG_DOWNLOAD_ERROR, &err);
1127 }
1128 else
1129 {
1130 if (sd->preload_status != EFL_UI_IMAGE_PRELOAD_DISABLED)
1131 {
1132 sd->preload_status = EFL_UI_IMAGE_PRELOADING;
1133 evas_object_image_preload(sd->img, EINA_FALSE);
1134 }
1135 evas_object_smart_callback_call(obj, SIG_DOWNLOAD_DONE, NULL);
1136 }
1137
1138 ELM_SAFE_FREE(sd->remote.key, eina_stringshare_del);
1139 ELM_SAFE_FREE(sd->remote.copier, efl_del);
1140 }
1141
1142 static void
_efl_ui_image_remote_copier_error(void * data,const Efl_Event * event)1143 _efl_ui_image_remote_copier_error(void *data, const Efl_Event *event)
1144 {
1145 Eo *obj = data;
1146 Efl_Ui_Image_Data *sd = efl_data_scope_get(obj, MY_CLASS);
1147 Eina_Error *perr = event->info;
1148 Efl_Ui_Image_Error err = { *perr, EINA_FALSE };
1149
1150 evas_object_smart_callback_call(obj, SIG_DOWNLOAD_ERROR, &err);
1151
1152 _efl_ui_image_remote_copier_cancel(obj, sd);
1153 ELM_SAFE_FREE(sd->remote.key, eina_stringshare_del);
1154 }
1155
1156 static void
_efl_ui_image_remote_copier_progress(void * data,const Efl_Event * event)1157 _efl_ui_image_remote_copier_progress(void *data, const Efl_Event *event)
1158 {
1159 Eo *obj = data;
1160 Efl_Ui_Image_Progress progress;
1161 uint64_t now, total;
1162
1163 efl_io_copier_progress_get(event->object, &now, NULL, &total);
1164
1165 progress.now = now;
1166 progress.total = total;
1167 evas_object_smart_callback_call(obj, SIG_DOWNLOAD_PROGRESS, &progress);
1168 }
1169
1170 EFL_CALLBACKS_ARRAY_DEFINE(_efl_ui_image_remote_copier_cbs,
1171 { EFL_EVENT_DEL, _efl_ui_image_remote_copier_del },
1172 { EFL_IO_COPIER_EVENT_DONE, _efl_ui_image_remote_copier_done },
1173 { EFL_IO_COPIER_EVENT_ERROR, _efl_ui_image_remote_copier_error },
1174 { EFL_IO_COPIER_EVENT_PROGRESS, _efl_ui_image_remote_copier_progress });
1175
1176 static Eina_Bool
_efl_ui_image_download(Eo * obj,Efl_Ui_Image_Data * sd,const char * url)1177 _efl_ui_image_download(Eo *obj, Efl_Ui_Image_Data *sd, const char *url)
1178 {
1179 Eo *dialer;
1180 Efl_Ui_Image_Error img_err = { ENOSYS, EINA_FALSE };
1181 Eina_Error err;
1182 const char *key = efl_file_key_get(obj);
1183
1184 dialer = efl_add(EFL_NET_DIALER_HTTP_CLASS, obj,
1185 efl_net_dialer_http_allow_redirects_set(efl_added, EINA_TRUE));
1186 EINA_SAFETY_ON_NULL_GOTO(dialer, error_dialer);
1187
1188 sd->remote.copier = efl_add(EFL_IO_COPIER_CLASS, obj,
1189 efl_io_copier_source_set(efl_added, dialer),
1190 efl_io_closer_close_on_invalidate_set(efl_added, EINA_TRUE),
1191 efl_event_callback_array_add(efl_added, _efl_ui_image_remote_copier_cbs(), obj));
1192 EINA_SAFETY_ON_NULL_GOTO(sd->remote.copier, error_copier);
1193 eina_stringshare_replace(&sd->remote.key, key);
1194
1195 err = efl_net_dialer_dial(dialer, url);
1196 if (err)
1197 {
1198 img_err.status = err;
1199 ERR("Could not download %s: %s", url, eina_error_msg_get(err));
1200 evas_object_smart_callback_call(obj, SIG_DOWNLOAD_ERROR, &img_err);
1201 goto error_dial;
1202 }
1203 return EINA_TRUE;
1204
1205 error_dial:
1206 evas_object_smart_callback_call(obj, SIG_DOWNLOAD_ERROR, &img_err);
1207 _efl_ui_image_remote_copier_cancel(obj, sd);
1208 return EINA_FALSE;
1209
1210 error_copier:
1211 efl_del(dialer);
1212 error_dialer:
1213 evas_object_smart_callback_call(obj, SIG_DOWNLOAD_ERROR, &img_err);
1214 return EINA_FALSE;
1215 }
1216
1217 EOLIAN static const char*
_efl_ui_image_efl_layout_group_group_data_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd,const char * key)1218 _efl_ui_image_efl_layout_group_group_data_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd, const char *key)
1219 {
1220 if (sd->edje)
1221 return edje_object_data_get(sd->img, key);
1222 return NULL;
1223 }
1224
1225 EOLIAN static Eina_Bool
_efl_ui_image_efl_layout_group_part_exist_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd,const char * part)1226 _efl_ui_image_efl_layout_group_part_exist_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd, const char *part)
1227 {
1228 if (sd->edje)
1229 return edje_object_part_exists(sd->img, part);
1230 return EINA_FALSE;
1231 }
1232
1233
1234 EOLIAN static void
_efl_ui_image_efl_layout_signal_signal_emit(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd,const char * emission,const char * source)1235 _efl_ui_image_efl_layout_signal_signal_emit(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd, const char *emission, const char *source)
1236 {
1237 if (sd->edje)
1238 edje_object_signal_emit(sd->img, emission, source);
1239 }
1240
1241 EOLIAN static void
_efl_ui_image_efl_layout_signal_message_send(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd,int id,const Eina_Value msg)1242 _efl_ui_image_efl_layout_signal_message_send(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd, int id, const Eina_Value msg)
1243 {
1244 if (pd->edje)
1245 efl_layout_signal_message_send(pd->img, id, msg);
1246 }
1247
1248 EOLIAN static Eina_Bool
_efl_ui_image_efl_layout_signal_signal_callback_add(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd,const char * emission,const char * source,void * func_data,EflLayoutSignalCb func,Eina_Free_Cb func_free_cb)1249 _efl_ui_image_efl_layout_signal_signal_callback_add(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd, const char *emission, const char *source, void *func_data, EflLayoutSignalCb func, Eina_Free_Cb func_free_cb)
1250 {
1251 if (pd->edje)
1252 return efl_layout_signal_callback_add(pd->img, emission, source, func_data, func, func_free_cb);
1253 return EINA_FALSE;
1254 }
1255
1256 EOLIAN static Eina_Bool
_efl_ui_image_efl_layout_signal_signal_callback_del(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd,const char * emission,const char * source,void * func_data,EflLayoutSignalCb func,Eina_Free_Cb func_free_cb)1257 _efl_ui_image_efl_layout_signal_signal_callback_del(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd, const char *emission, const char *source, void *func_data, EflLayoutSignalCb func, Eina_Free_Cb func_free_cb)
1258 {
1259 if (pd->edje)
1260 return efl_layout_signal_callback_del(pd->img, emission, source, func_data, func, func_free_cb);
1261 return EINA_FALSE;
1262 }
1263
1264 EOLIAN static void
_efl_ui_image_efl_layout_signal_signal_process(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd,Eina_Bool recurse)1265 _efl_ui_image_efl_layout_signal_signal_process(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd, Eina_Bool recurse)
1266 {
1267 if (pd->edje)
1268 efl_layout_signal_process(pd->img, recurse);
1269 }
1270
1271
1272 EOLIAN static Eina_Size2D
_efl_ui_image_efl_layout_group_group_size_min_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)1273 _efl_ui_image_efl_layout_group_group_size_min_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1274 {
1275 if (sd->edje)
1276 return efl_layout_group_size_min_get(sd->img);
1277 else
1278 return EINA_SIZE2D(0, 0);
1279 }
1280
1281 EOLIAN static Eina_Size2D
_efl_ui_image_efl_layout_group_group_size_max_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)1282 _efl_ui_image_efl_layout_group_group_size_max_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1283 {
1284 if (sd->edje)
1285 return efl_layout_group_size_max_get(sd->img);
1286 else
1287 return EINA_SIZE2D(0, 0);
1288 }
1289
1290 EOLIAN static void
_efl_ui_image_efl_layout_calc_calc_force(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)1291 _efl_ui_image_efl_layout_calc_calc_force(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1292 {
1293 if (sd->edje)
1294 edje_object_calc_force(sd->img);
1295 }
1296
1297 EOLIAN static Eina_Size2D
_efl_ui_image_efl_layout_calc_calc_size_min(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd,Eina_Size2D restricted)1298 _efl_ui_image_efl_layout_calc_calc_size_min(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd, Eina_Size2D restricted)
1299 {
1300 if (sd->edje)
1301 return efl_layout_calc_size_min(sd->img, restricted);
1302 else
1303 {
1304 // Ignore restricted here? Combine with min? Hmm...
1305 return efl_gfx_hint_size_combined_min_get(sd->img);
1306 }
1307 }
1308
1309 EOLIAN Eina_Rect
_efl_ui_image_efl_layout_calc_calc_parts_extends(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)1310 _efl_ui_image_efl_layout_calc_calc_parts_extends(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1311 {
1312 if (sd->edje)
1313 return efl_layout_calc_parts_extends(sd->img);
1314 return efl_gfx_entity_geometry_get(sd->img);
1315 }
1316
1317 EOLIAN static int
_efl_ui_image_efl_layout_calc_calc_freeze(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)1318 _efl_ui_image_efl_layout_calc_calc_freeze(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1319 {
1320 if (sd->edje) return edje_object_freeze(sd->img);
1321 return 0;
1322 }
1323
1324 EOLIAN static int
_efl_ui_image_efl_layout_calc_calc_thaw(Eo * obj,Efl_Ui_Image_Data * sd)1325 _efl_ui_image_efl_layout_calc_calc_thaw(Eo *obj, Efl_Ui_Image_Data *sd)
1326 {
1327 if (sd->edje)
1328 {
1329 int ret = edje_object_thaw(sd->img);
1330 efl_canvas_group_calculate(obj);
1331 return ret;
1332 }
1333 return 0;
1334 }
1335
1336 EOLIAN void
_efl_ui_image_efl_layout_calc_calc_auto_update_hints_set(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd,Eina_Bool update)1337 _efl_ui_image_efl_layout_calc_calc_auto_update_hints_set(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd, Eina_Bool update)
1338 {
1339 if (sd->edje)
1340 efl_layout_calc_auto_update_hints_set(sd->img, update);
1341 }
1342
1343 EOLIAN Eina_Bool
_efl_ui_image_efl_layout_calc_calc_auto_update_hints_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)1344 _efl_ui_image_efl_layout_calc_calc_auto_update_hints_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1345 {
1346 if (sd->edje) return efl_layout_calc_auto_update_hints_get(sd->img);
1347 return EINA_TRUE;
1348 }
1349
1350 #if 0
1351 // Kept for reference: wait for async open to complete - probably unused.
1352 static Eina_Bool
1353 _efl_ui_image_efl_file_async_wait(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd)
1354 {
1355 Eina_Bool ok = EINA_TRUE;
1356 if (!pd->async.th) return ok;
1357 if (!ecore_thread_wait(pd->async.th, 1.0))
1358 {
1359 ERR("Failed to wait on async file open!");
1360 ok = EINA_FALSE;
1361 }
1362 return ok;
1363 }
1364 #endif
1365
1366 /* Legacy style async API. While legacy only, this is new from 1.19.
1367 * Tizen has used elm_image_async_open_set() internally for a while, despite
1368 * EFL upstream not exposing a proper async API. */
1369
1370 EAPI void
elm_image_async_open_set(Eo * obj,Eina_Bool async)1371 elm_image_async_open_set(Eo *obj, Eina_Bool async)
1372 {
1373 Efl_Ui_Image_Data *pd;
1374
1375 EINA_SAFETY_ON_FALSE_RETURN(efl_isa(obj, MY_CLASS));
1376 pd = efl_data_scope_get(obj, MY_CLASS);
1377 if (pd->async_enable == async) return;
1378 pd->async_enable = async;
1379 if (!async) _async_cancel(pd);
1380 }
1381
1382 EOLIAN static Eina_Size2D
_efl_ui_image_efl_gfx_view_view_size_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)1383 _efl_ui_image_efl_gfx_view_view_size_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1384 {
1385 int tw, th;
1386
1387 if (!sd->img)
1388 {
1389 tw = 0; th = 0;
1390 }
1391 else if (efl_isa(sd->img, EFL_CANVAS_LAYOUT_CLASS))
1392 edje_object_size_min_get(sd->img, &tw, &th);
1393 else
1394 evas_object_image_size_get(sd->img, &tw, &th);
1395
1396 return EINA_SIZE2D(tw, th);
1397 }
1398
1399 EOLIAN static Eina_Size2D
_efl_ui_image_efl_gfx_image_image_size_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)1400 _efl_ui_image_efl_gfx_image_image_size_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1401 {
1402 if (!sd->img || sd->edje)
1403 return EINA_SIZE2D(0, 0);
1404
1405 return efl_gfx_image_size_get(sd->img);
1406 }
1407
1408 EOLIAN static double
_efl_ui_image_efl_gfx_image_ratio_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd)1409 _efl_ui_image_efl_gfx_image_ratio_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd)
1410 {
1411 if (pd->edje) return 1.0; //documented value for the case that ratio cannot be calculated
1412 return efl_gfx_image_ratio_get(pd->img);
1413 }
1414
1415 EOLIAN static Eina_Rect
_efl_ui_image_efl_gfx_image_content_region_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd)1416 _efl_ui_image_efl_gfx_image_content_region_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd)
1417 {
1418 if (pd->edje)
1419 {
1420 Eina_Size2D size = efl_gfx_entity_size_get(pd->img);
1421 return EINA_RECT(0, 0, size.w, size.h);
1422 }
1423
1424 return efl_gfx_image_content_region_get(pd->img);
1425 }
1426
1427 EOLIAN static void
_efl_ui_image_efl_gfx_image_border_insets_set(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd,int l,int r,int t,int b)1428 _efl_ui_image_efl_gfx_image_border_insets_set(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd, int l, int r, int t, int b)
1429 {
1430 if (pd->edje) return;
1431 efl_gfx_image_border_insets_set(pd->img, l, r, t, b);
1432 }
1433
1434 EOLIAN static void
_efl_ui_image_efl_gfx_image_border_insets_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd,int * l,int * r,int * t,int * b)1435 _efl_ui_image_efl_gfx_image_border_insets_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd, int *l, int *r, int *t, int *b)
1436 {
1437 if (pd->edje)
1438 {
1439 if (l) *l = 0;
1440 if (r) *r = 0;
1441 if (t) *t = 0;
1442 if (b) *b = 0;
1443 }
1444 else
1445 {
1446 efl_gfx_image_border_insets_get(pd->img, l, r, t, b);
1447 }
1448 }
1449
1450 EOLIAN static void
_efl_ui_image_efl_gfx_image_border_insets_scale_set(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd,double scale)1451 _efl_ui_image_efl_gfx_image_border_insets_scale_set(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd, double scale)
1452 {
1453 if (pd->edje) return;
1454 efl_gfx_image_border_insets_scale_set(pd->img, scale);
1455 }
1456
1457 EOLIAN static double
_efl_ui_image_efl_gfx_image_border_insets_scale_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd)1458 _efl_ui_image_efl_gfx_image_border_insets_scale_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd)
1459 {
1460 if (pd->edje) return 0.0;
1461 return efl_gfx_image_border_insets_scale_get(pd->img);
1462 }
1463
1464
1465 EOLIAN static void
_efl_ui_image_efl_gfx_image_center_fill_mode_set(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd,Efl_Gfx_Center_Fill_Mode fill)1466 _efl_ui_image_efl_gfx_image_center_fill_mode_set(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd, Efl_Gfx_Center_Fill_Mode fill)
1467 {
1468 if (pd->edje) return;
1469 efl_gfx_image_center_fill_mode_set(pd->img, fill);
1470 }
1471
1472
1473 EOLIAN static Efl_Gfx_Center_Fill_Mode
_efl_ui_image_efl_gfx_image_center_fill_mode_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd)1474 _efl_ui_image_efl_gfx_image_center_fill_mode_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd)
1475 {
1476 if (pd->edje) return EFL_GFX_CENTER_FILL_MODE_DEFAULT;
1477 return efl_gfx_image_center_fill_mode_get(pd->img);
1478 }
1479
1480 EOLIAN static Eina_Error
_efl_ui_image_efl_gfx_image_stretch_region_set(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd,Eina_Iterator * horizontal,Eina_Iterator * vertical)1481 _efl_ui_image_efl_gfx_image_stretch_region_set(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd, Eina_Iterator *horizontal, Eina_Iterator *vertical)
1482 {
1483 if (pd->edje)
1484 {
1485 eina_iterator_free(horizontal);
1486 eina_iterator_free(vertical);
1487 return EINA_ERROR_NO_ERROR;
1488 }
1489 else
1490 {
1491 return efl_gfx_image_stretch_region_set(pd->img, horizontal, vertical);
1492 }
1493 }
1494
1495 EOLIAN static void
_efl_ui_image_efl_gfx_image_stretch_region_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd,Eina_Iterator ** horizontal,Eina_Iterator ** vertical)1496 _efl_ui_image_efl_gfx_image_stretch_region_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd, Eina_Iterator **horizontal, Eina_Iterator **vertical)
1497 {
1498 if (pd->edje)
1499 {
1500 if (horizontal) *horizontal = NULL;
1501 if (vertical) *vertical = NULL;
1502 }
1503 else
1504 {
1505 efl_gfx_image_stretch_region_get(pd->img, horizontal, vertical);
1506 }
1507 }
1508
1509 EOLIAN static void
_efl_ui_image_efl_gfx_image_scale_hint_set(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd,Efl_Gfx_Image_Scale_Hint hint)1510 _efl_ui_image_efl_gfx_image_scale_hint_set(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd, Efl_Gfx_Image_Scale_Hint hint)
1511 {
1512 if (pd->edje) return;
1513 return efl_gfx_image_scale_hint_set(pd->img, hint);
1514 }
1515
1516 EOLIAN static Efl_Gfx_Image_Scale_Hint
_efl_ui_image_efl_gfx_image_scale_hint_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd)1517 _efl_ui_image_efl_gfx_image_scale_hint_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd)
1518 {
1519 if (pd->edje) return EFL_GFX_IMAGE_SCALE_HINT_NONE;
1520 return efl_gfx_image_scale_hint_get(pd->img);
1521 }
1522
1523 EOLIAN static void
_efl_ui_image_efl_gfx_image_content_hint_set(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd,Efl_Gfx_Image_Content_Hint hint)1524 _efl_ui_image_efl_gfx_image_content_hint_set(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd, Efl_Gfx_Image_Content_Hint hint)
1525 {
1526 if (pd->edje) return;
1527 return efl_gfx_image_content_hint_set(pd->img, hint);
1528 }
1529
1530 EOLIAN static Efl_Gfx_Image_Content_Hint
_efl_ui_image_efl_gfx_image_content_hint_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd)1531 _efl_ui_image_efl_gfx_image_content_hint_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd)
1532 {
1533 if (pd->edje) return EFL_GFX_IMAGE_CONTENT_HINT_NONE;
1534 return efl_gfx_image_content_hint_get(pd->img);
1535 }
1536
1537 EOLIAN static Eina_Error
_efl_ui_image_efl_gfx_image_image_load_error_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd)1538 _efl_ui_image_efl_gfx_image_image_load_error_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd)
1539 {
1540 if (pd->edje) return EINA_ERROR_NO_ERROR;
1541
1542 return efl_gfx_image_load_error_get(pd->img);
1543 }
1544
1545 EAPI void
elm_image_prescale_set(Evas_Object * obj,int size)1546 elm_image_prescale_set(Evas_Object *obj,
1547 int size)
1548 {
1549 EFL_UI_IMAGE_CHECK(obj);
1550 efl_gfx_image_load_controller_load_size_set(obj, EINA_SIZE2D(size, size));
1551 }
1552
1553 EOLIAN static void
_efl_ui_image_efl_gfx_image_load_controller_load_size_set(Eo * obj,Efl_Ui_Image_Data * sd,Eina_Size2D sz)1554 _efl_ui_image_efl_gfx_image_load_controller_load_size_set(Eo *obj, Efl_Ui_Image_Data *sd, Eina_Size2D sz)
1555 {
1556 sd->load_size = sz;
1557
1558 if (!sd->img) return;
1559 _efl_ui_image_load_size_set_internal(obj, sd);
1560 }
1561
1562 EOLIAN static void
_efl_ui_image_efl_gfx_image_load_controller_load_async_start(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd)1563 _efl_ui_image_efl_gfx_image_load_controller_load_async_start(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd)
1564 {
1565 if (pd->edje) return;
1566 efl_gfx_image_load_controller_load_async_start(pd->img);
1567 }
1568
1569 EOLIAN static void
_efl_ui_image_efl_gfx_image_load_controller_load_async_cancel(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd)1570 _efl_ui_image_efl_gfx_image_load_controller_load_async_cancel(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd)
1571 {
1572 if (pd->edje) return;
1573 efl_gfx_image_load_controller_load_async_cancel(pd->img);
1574 }
1575
1576 EOLIAN static void
_efl_ui_image_efl_gfx_image_load_controller_load_dpi_set(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd,double dpi)1577 _efl_ui_image_efl_gfx_image_load_controller_load_dpi_set(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd, double dpi)
1578 {
1579 if (pd->edje) return;
1580 efl_gfx_image_load_controller_load_dpi_set(pd->img, dpi);
1581 }
1582
1583
1584 EOLIAN static double
_efl_ui_image_efl_gfx_image_load_controller_load_dpi_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd)1585 _efl_ui_image_efl_gfx_image_load_controller_load_dpi_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd)
1586 {
1587 if (pd->edje) return 0.0;
1588 return efl_gfx_image_load_controller_load_dpi_get(pd->img);
1589 }
1590
1591 EOLIAN static void
_efl_ui_image_efl_gfx_image_load_controller_load_orientation_set(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd,Eina_Bool enable)1592 _efl_ui_image_efl_gfx_image_load_controller_load_orientation_set(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd, Eina_Bool enable)
1593 {
1594 if (pd->edje) return;
1595 efl_gfx_image_load_controller_load_orientation_set(pd->img, enable);
1596 }
1597
1598
1599 EOLIAN static Eina_Bool
_efl_ui_image_efl_gfx_image_load_controller_load_orientation_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd)1600 _efl_ui_image_efl_gfx_image_load_controller_load_orientation_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd)
1601 {
1602 if (pd->edje) return EINA_FALSE;
1603 return efl_gfx_image_load_controller_load_orientation_get(pd->img);
1604 }
1605
1606
1607 EOLIAN static void
_efl_ui_image_efl_gfx_image_load_controller_load_scale_down_set(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd,int div)1608 _efl_ui_image_efl_gfx_image_load_controller_load_scale_down_set(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd, int div)
1609 {
1610 if (pd->edje) return;
1611 efl_gfx_image_load_controller_load_scale_down_set(pd->img, div);
1612 }
1613
1614 EOLIAN static int
_efl_ui_image_efl_gfx_image_load_controller_load_scale_down_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd)1615 _efl_ui_image_efl_gfx_image_load_controller_load_scale_down_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd)
1616 {
1617 if (pd->edje) return EINA_FALSE;
1618 return efl_gfx_image_load_controller_load_scale_down_get(pd->img);
1619 }
1620
1621 EOLIAN static void
_efl_ui_image_efl_gfx_image_load_controller_load_skip_header_set(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd,Eina_Bool skip)1622 _efl_ui_image_efl_gfx_image_load_controller_load_skip_header_set(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd, Eina_Bool skip)
1623 {
1624 if (pd->edje) return;
1625 return efl_gfx_image_load_controller_load_skip_header_set(pd->img, skip);
1626 }
1627
1628 EOLIAN static Eina_Bool
_efl_ui_image_efl_gfx_image_load_controller_load_skip_header_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd)1629 _efl_ui_image_efl_gfx_image_load_controller_load_skip_header_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd)
1630 {
1631 if (pd->edje) return EINA_FALSE;
1632 return efl_gfx_image_load_controller_load_skip_header_get(pd->img);
1633 }
1634
1635
1636 EOLIAN static void
_efl_ui_image_efl_gfx_image_load_controller_load_region_set(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd,Eina_Rect region)1637 _efl_ui_image_efl_gfx_image_load_controller_load_region_set(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd, Eina_Rect region)
1638 {
1639 if (pd->edje) return;
1640 return efl_gfx_image_load_controller_load_region_set(pd->img, region);
1641 }
1642
1643
1644 EOLIAN static Eina_Rect
_efl_ui_image_efl_gfx_image_load_controller_load_region_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd)1645 _efl_ui_image_efl_gfx_image_load_controller_load_region_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd)
1646 {
1647
1648 if (pd->edje) return EINA_RECT(0, 0, 0, 0);
1649 return efl_gfx_image_load_controller_load_region_get(pd->img);
1650 }
1651
1652
1653 EOLIAN static Eina_Bool
_efl_ui_image_efl_gfx_image_load_controller_load_region_support_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd)1654 _efl_ui_image_efl_gfx_image_load_controller_load_region_support_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd)
1655 {
1656 if (pd->edje) return EINA_FALSE;
1657 return EINA_TRUE;
1658 }
1659
1660 EAPI int
elm_image_prescale_get(const Evas_Object * obj)1661 elm_image_prescale_get(const Evas_Object *obj)
1662 {
1663 Eina_Size2D sz;
1664 EFL_UI_IMAGE_CHECK(obj) 0;
1665
1666 sz = efl_gfx_image_load_controller_load_size_get(obj);
1667
1668 return MAX(sz.w, sz.h);
1669 }
1670
1671 EOLIAN static Eina_Size2D
_efl_ui_image_efl_gfx_image_load_controller_load_size_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)1672 _efl_ui_image_efl_gfx_image_load_controller_load_size_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1673 {
1674 return sd->load_size;
1675 }
1676
1677 EOLIAN static void
_efl_ui_image_efl_gfx_image_orientable_image_orientation_set(Eo * obj,Efl_Ui_Image_Data * sd,Efl_Gfx_Image_Orientation orient)1678 _efl_ui_image_efl_gfx_image_orientable_image_orientation_set(Eo *obj, Efl_Ui_Image_Data *sd, Efl_Gfx_Image_Orientation orient)
1679 {
1680 if (sd->edje) return;
1681 if (sd->orient == orient) return;
1682
1683 sd->orient = orient;
1684 efl_canvas_group_change(obj);
1685 }
1686
1687 EOLIAN static Efl_Gfx_Image_Orientation
_efl_ui_image_efl_gfx_image_orientable_image_orientation_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)1688 _efl_ui_image_efl_gfx_image_orientable_image_orientation_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1689 {
1690 return sd->orient;
1691 }
1692
1693 /**
1694 * Turns on editing through drag and drop and copy and paste.
1695 */
1696 EOLIAN static void
_efl_ui_image_efl_ui_draggable_drag_target_set(Eo * obj,Efl_Ui_Image_Data * sd,Eina_Bool edit)1697 _efl_ui_image_efl_ui_draggable_drag_target_set(Eo *obj, Efl_Ui_Image_Data *sd, Eina_Bool edit)
1698 {
1699 if (sd->edje)
1700 {
1701 WRN("No editing edje objects yet (ever)\n");
1702 return;
1703 }
1704
1705 edit = !!edit;
1706
1707 if (edit == sd->edit) return;
1708
1709 sd->edit = edit;
1710
1711 if (sd->edit)
1712 elm_drop_target_add
1713 (obj, ELM_SEL_FORMAT_IMAGE,
1714 NULL, NULL,
1715 NULL, NULL,
1716 NULL, NULL,
1717 _efl_ui_image_drag_n_drop_cb, obj);
1718 else
1719 elm_drop_target_del
1720 (obj, ELM_SEL_FORMAT_IMAGE,
1721 NULL, NULL,
1722 NULL, NULL,
1723 NULL, NULL,
1724 _efl_ui_image_drag_n_drop_cb, obj);
1725 }
1726
1727 EOLIAN static Eina_Bool
_efl_ui_image_efl_ui_draggable_drag_target_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)1728 _efl_ui_image_efl_ui_draggable_drag_target_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1729 {
1730 return sd->edit;
1731 }
1732
1733 EAPI Eina_Bool
elm_image_animated_available_get(const Evas_Object * obj)1734 elm_image_animated_available_get(const Evas_Object *obj)
1735 {
1736 return efl_playable_get(obj);
1737 }
1738
1739 EOLIAN static Eina_Bool
_efl_ui_image_efl_playable_playable_get(const Eo * obj,Efl_Ui_Image_Data * sd)1740 _efl_ui_image_efl_playable_playable_get(const Eo *obj, Efl_Ui_Image_Data *sd)
1741 {
1742 if (sd->edje) return EINA_TRUE;
1743
1744 return evas_object_image_animated_get(elm_image_object_get(obj));
1745 }
1746
1747 static Eina_Bool
_efl_ui_image_animated_set_internal(Eo * obj,Efl_Ui_Image_Data * sd,Eina_Bool anim)1748 _efl_ui_image_animated_set_internal(Eo *obj, Efl_Ui_Image_Data *sd, Eina_Bool anim)
1749 {
1750 anim = !!anim;
1751 if (sd->anim == anim) return EINA_TRUE;
1752
1753 if (sd->edje)
1754 {
1755 edje_object_animation_set(sd->img, anim);
1756 sd->anim = anim;
1757 efl_player_playback_loop_set(sd->img, sd->playback_loop);
1758 return EINA_TRUE;
1759 }
1760 sd->img = elm_image_object_get(obj);
1761
1762 if (elm_widget_is_legacy(obj)) sd->anim = anim; //legacy
1763
1764 if (!evas_object_image_animated_get(sd->img)) return EINA_FALSE;
1765 sd->anim = anim;
1766
1767 if (anim)
1768 {
1769 sd->frame_count = evas_object_image_animated_frame_count_get(sd->img);
1770 sd->cur_frame = 1;
1771 sd->frame_duration =
1772 evas_object_image_animated_frame_duration_get
1773 (sd->img, sd->cur_frame, 0);
1774 evas_object_image_animated_frame_set(sd->img, sd->cur_frame);
1775 if (!sd->paused)//legacy
1776 sd->anim_timer = ecore_timer_add
1777 (sd->frame_duration / sd->playback_speed, _efl_ui_image_animate_cb, obj);
1778 }
1779 else
1780 {
1781 sd->frame_count = -1;
1782 sd->cur_frame = -1;
1783 sd->frame_duration = -1;
1784 ELM_SAFE_FREE(sd->anim_timer, ecore_timer_del);
1785 }
1786 return EINA_TRUE;
1787 }
1788
1789 static Eina_Bool
_efl_ui_image_animated_get_internal(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)1790 _efl_ui_image_animated_get_internal(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1791 {
1792 if (sd->edje)
1793 return edje_object_animation_get(sd->img);
1794 return sd->anim;
1795 }
1796
1797 EAPI void
elm_image_animated_set(Evas_Object * obj,Eina_Bool anim)1798 elm_image_animated_set(Evas_Object *obj, Eina_Bool anim)
1799 {
1800 Efl_Ui_Image_Data *sd = efl_data_scope_get(obj, MY_CLASS);
1801 if (!sd) return;
1802 _efl_ui_image_animated_set_internal(obj, sd, anim);
1803 }
1804
1805 EAPI Eina_Bool
elm_image_animated_get(const Evas_Object * obj)1806 elm_image_animated_get(const Evas_Object *obj)
1807 {
1808 Efl_Ui_Image_Data *sd = efl_data_scope_get(obj, MY_CLASS);
1809 if (!sd) return EINA_FALSE;
1810 return _efl_ui_image_animated_get_internal(obj, sd);
1811 }
1812
1813 EOLIAN static Eina_Bool
_efl_ui_image_efl_player_playing_set(Eo * obj,Efl_Ui_Image_Data * sd,Eina_Bool playing)1814 _efl_ui_image_efl_player_playing_set(Eo *obj, Efl_Ui_Image_Data *sd, Eina_Bool playing)
1815 {
1816 return _efl_ui_image_animated_set_internal(obj, sd, playing);
1817 }
1818
1819 EOLIAN static Eina_Bool
_efl_ui_image_efl_player_playing_get(const Eo * obj,Efl_Ui_Image_Data * sd)1820 _efl_ui_image_efl_player_playing_get(const Eo *obj, Efl_Ui_Image_Data *sd)
1821 {
1822 return _efl_ui_image_animated_get_internal(obj, sd);
1823 }
1824
1825 EOLIAN static void
_efl_ui_image_efl_player_playback_loop_set(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd,Eina_Bool playback_loop)1826 _efl_ui_image_efl_player_playback_loop_set(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd, Eina_Bool playback_loop)
1827 {
1828 playback_loop = !!playback_loop;
1829 sd->playback_loop = playback_loop;
1830 }
1831
1832 EOLIAN static Eina_Bool
_efl_ui_image_efl_player_playback_loop_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)1833 _efl_ui_image_efl_player_playback_loop_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1834 {
1835 return sd->playback_loop;
1836 }
1837
1838 EOLIAN static void
_efl_ui_image_efl_player_autoplay_set(Eo * obj,Efl_Ui_Image_Data * sd,Eina_Bool autoplay)1839 _efl_ui_image_efl_player_autoplay_set(Eo *obj, Efl_Ui_Image_Data *sd, Eina_Bool autoplay)
1840 {
1841 autoplay = !!autoplay;
1842 if (sd->autoplay == autoplay) return;
1843 sd->autoplay = autoplay;
1844 if (sd->img && (!sd->edje))
1845 {
1846 /* filter cases where we aren't going to immediately start playing */
1847 if (!autoplay) return;
1848 if ((sd->preload_status != EFL_UI_IMAGE_PRELOADED) &&
1849 (sd->preload_status != EFL_UI_IMAGE_PRELOAD_DISABLED))
1850 return;
1851 }
1852 efl_player_playing_set(obj, EINA_TRUE);
1853 }
1854
1855 EOLIAN static Eina_Bool
_efl_ui_image_efl_player_autoplay_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)1856 _efl_ui_image_efl_player_autoplay_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1857 {
1858 return sd->autoplay;
1859 }
1860
1861 EOLIAN static void
_efl_ui_image_efl_player_playback_speed_set(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd,double factor)1862 _efl_ui_image_efl_player_playback_speed_set(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd, double factor)
1863 {
1864 EINA_SAFETY_ON_TRUE_RETURN(factor < 0.0);
1865 EINA_SAFETY_ON_TRUE_RETURN(EINA_DBL_EQ(factor, 0.0));
1866 if (EINA_DBL_EQ(sd->playback_speed, factor)) return;
1867 sd->playback_speed = factor;
1868 if (sd->edje)
1869 efl_player_playback_speed_set(sd->img, factor);
1870 else if (sd->anim_timer)
1871 {
1872 ecore_timer_interval_set(sd->anim_timer, sd->frame_duration / sd->playback_speed);
1873 ecore_timer_reset(sd->anim_timer);
1874 }
1875 }
1876
1877 EOLIAN static double
_efl_ui_image_efl_player_playback_speed_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)1878 _efl_ui_image_efl_player_playback_speed_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1879 {
1880 return sd->playback_speed;
1881 }
1882
1883 EOLIAN static void
_efl_ui_image_efl_player_playback_position_set(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd,double sec)1884 _efl_ui_image_efl_player_playback_position_set(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd, double sec)
1885 {
1886 EINA_SAFETY_ON_TRUE_RETURN(sec < 0.0);
1887 if (sd->edje)
1888 efl_player_playback_position_set(sd->img, sec);
1889 else if ((sd->frame_count > 0) && (sd->frame_duration > 0.0))
1890 {
1891 /* validate total animation time */
1892 EINA_SAFETY_ON_TRUE_RETURN(sd->frame_count * sd->frame_duration < sec);
1893 sd->cur_frame = lround(sec / sd->frame_duration);
1894 }
1895 }
1896
1897 EOLIAN static double
_efl_ui_image_efl_player_playback_position_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)1898 _efl_ui_image_efl_player_playback_position_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1899 {
1900 if (sd->edje)
1901 efl_player_playback_position_get(sd->img);
1902 else if ((sd->frame_count > 0) && (sd->frame_duration > 0.0))
1903 return sd->cur_frame * sd->frame_duration;
1904 return 0.0;
1905 }
1906
1907 EOLIAN static double
_efl_ui_image_efl_player_playback_progress_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)1908 _efl_ui_image_efl_player_playback_progress_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1909 {
1910 if (sd->edje)
1911 efl_player_playback_progress_get(sd->img);
1912 else if (sd->frame_count > 1)
1913 return ((double)sd->cur_frame - 1.0) / ((double)sd->frame_count - 1.0);
1914 return 0.0;
1915 }
1916
1917 EOLIAN static void
_efl_ui_image_efl_player_playback_progress_set(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd,double progress)1918 _efl_ui_image_efl_player_playback_progress_set(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd, double progress)
1919 {
1920 EINA_SAFETY_ON_TRUE_RETURN(progress > 1 || progress < 0);
1921 if (sd->edje)
1922 efl_player_playback_progress_set(sd->img, progress);
1923 else if (sd->frame_count > 0)
1924 sd->cur_frame = (lround(progress * (sd->frame_count - 1)) + 1);
1925 else
1926 sd->cur_frame = 1;
1927 }
1928
1929 static Eina_Bool
_efl_ui_image_animated_paused_set_internal(Eo * obj,Efl_Ui_Image_Data * sd,Eina_Bool paused)1930 _efl_ui_image_animated_paused_set_internal(Eo *obj, Efl_Ui_Image_Data *sd, Eina_Bool paused)
1931 {
1932 paused = !!paused;
1933 if (!sd->anim) return EINA_FALSE;
1934 if (sd->paused == paused) return EINA_TRUE;
1935 sd->paused = paused;
1936 if (sd->edje)
1937 {
1938 edje_object_play_set(sd->img, !paused);
1939 return EINA_TRUE;
1940 }
1941 if (!paused)
1942 {
1943 sd->anim_timer = ecore_timer_add
1944 (sd->frame_duration / sd->playback_speed, _efl_ui_image_animate_cb, obj);
1945 }
1946 else
1947 {
1948 ELM_SAFE_FREE(sd->anim_timer, ecore_timer_del);
1949 }
1950 return EINA_TRUE;
1951 }
1952
1953 static Eina_Bool
_efl_ui_image_animated_paused_get_internal(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)1954 _efl_ui_image_animated_paused_get_internal(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
1955 {
1956 if (sd->edje)
1957 return !edje_object_play_get(sd->img);
1958 return sd->paused;
1959 }
1960
1961 EAPI void
elm_image_animated_play_set(Elm_Image * obj,Eina_Bool play)1962 elm_image_animated_play_set(Elm_Image *obj, Eina_Bool play)
1963 {
1964 Efl_Ui_Image_Data *sd = efl_data_scope_get(obj, MY_CLASS);
1965 if (!sd) return;
1966 _efl_ui_image_animated_paused_set_internal(obj, sd, !play);
1967 }
1968
1969 EAPI Eina_Bool
elm_image_animated_play_get(const Elm_Image * obj)1970 elm_image_animated_play_get(const Elm_Image *obj)
1971 {
1972 Efl_Ui_Image_Data *sd = efl_data_scope_get(obj, MY_CLASS);
1973 if (!sd) return EINA_FALSE;
1974 return !_efl_ui_image_animated_paused_get_internal(obj, sd);
1975 }
1976
1977 EOLIAN static Eina_Bool
_efl_ui_image_efl_player_paused_set(Eo * obj,Efl_Ui_Image_Data * sd,Eina_Bool paused)1978 _efl_ui_image_efl_player_paused_set(Eo *obj, Efl_Ui_Image_Data *sd, Eina_Bool paused)
1979 {
1980 return _efl_ui_image_animated_paused_set_internal(obj, sd, paused);
1981 }
1982
1983 EOLIAN static Eina_Bool
_efl_ui_image_efl_player_paused_get(const Eo * obj,Efl_Ui_Image_Data * sd)1984 _efl_ui_image_efl_player_paused_get(const Eo *obj, Efl_Ui_Image_Data *sd)
1985 {
1986 return _efl_ui_image_animated_paused_get_internal(obj, sd);
1987 }
1988
1989 EOLIAN static void
_efl_ui_image_efl_gfx_image_scale_method_set(Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd EINA_UNUSED,Efl_Gfx_Image_Scale_Method scale_type)1990 _efl_ui_image_efl_gfx_image_scale_method_set(Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd EINA_UNUSED, Efl_Gfx_Image_Scale_Method scale_type)
1991 {
1992 if (scale_type == sd->scale_type) return;
1993
1994 sd->scale_type = scale_type;
1995
1996 efl_canvas_group_change(obj);
1997 }
1998
1999 EOLIAN static Efl_Gfx_Image_Scale_Method
_efl_ui_image_efl_gfx_image_scale_method_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)2000 _efl_ui_image_efl_gfx_image_scale_method_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
2001 {
2002 return sd->scale_type;
2003 }
2004
2005 EOLIAN static void
_efl_ui_image_efl_gfx_image_can_upscale_set(Eo * obj,Efl_Ui_Image_Data * sd,Eina_Bool can_upscale)2006 _efl_ui_image_efl_gfx_image_can_upscale_set(Eo *obj, Efl_Ui_Image_Data *sd, Eina_Bool can_upscale)
2007 {
2008 if (can_upscale == sd->scale_up) return;
2009
2010 sd->scale_up = !!can_upscale;
2011
2012 efl_canvas_group_change(obj);
2013 }
2014
2015 EOLIAN static Eina_Bool
_efl_ui_image_efl_gfx_image_can_upscale_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)2016 _efl_ui_image_efl_gfx_image_can_upscale_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
2017 {
2018 return sd->scale_up;
2019 }
2020
2021 EOLIAN static void
_efl_ui_image_efl_gfx_image_can_downscale_set(Eo * obj,Efl_Ui_Image_Data * sd,Eina_Bool can_downscale)2022 _efl_ui_image_efl_gfx_image_can_downscale_set(Eo *obj, Efl_Ui_Image_Data *sd, Eina_Bool can_downscale)
2023 {
2024 if (can_downscale == sd->scale_down) return;
2025
2026 sd->scale_down = !!can_downscale;
2027
2028 efl_canvas_group_change(obj);
2029 }
2030
2031 EOLIAN static Eina_Bool
_efl_ui_image_efl_gfx_image_can_downscale_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)2032 _efl_ui_image_efl_gfx_image_can_downscale_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
2033 {
2034 return sd->scale_down;
2035 }
2036
2037 EOLIAN static void
_efl_ui_image_efl_gfx_arrangement_content_align_set(Eo * obj,Efl_Ui_Image_Data * sd,double align_x,double align_y)2038 _efl_ui_image_efl_gfx_arrangement_content_align_set(Eo *obj, Efl_Ui_Image_Data *sd, double align_x, double align_y)
2039 {
2040 if (align_x > 1.0)
2041 align_x = 1.0;
2042 else if (align_x < 0.0)
2043 align_x = 0.0;
2044
2045 if (align_y > 1.0)
2046 align_y = 1.0;
2047 else if (align_y < 0.0)
2048 align_y = 0.0;
2049
2050 if ((EINA_DBL_EQ(align_x, sd->align_x)) && (EINA_DBL_EQ(align_y, sd->align_y))) return;
2051
2052 sd->align_x = align_x;
2053 sd->align_y = align_y;
2054
2055 efl_canvas_group_change(obj);
2056 }
2057
2058 EOLIAN static void
_efl_ui_image_efl_gfx_arrangement_content_align_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd,double * align_x,double * align_y)2059 _efl_ui_image_efl_gfx_arrangement_content_align_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd, double *align_x, double *align_y)
2060 {
2061 if (align_x) *align_x = sd->align_x;
2062 if (align_y) *align_y = sd->align_y;
2063 }
2064
2065 // A11Y
2066
2067 EOLIAN static Eina_Rect
_efl_ui_image_efl_access_component_extents_get(const Eo * obj,Efl_Ui_Image_Data * sd EINA_UNUSED,Eina_Bool screen_coords)2068 _efl_ui_image_efl_access_component_extents_get(const Eo *obj, Efl_Ui_Image_Data *sd EINA_UNUSED, Eina_Bool screen_coords)
2069 {
2070 int ee_x, ee_y;
2071 Eina_Rect r;
2072 Evas_Object *image = elm_image_object_get(obj);
2073
2074 r.x = r.y = r.w = r.h = -1;
2075 if (!image) return r;
2076
2077 evas_object_geometry_get(image, &r.x, &r.y, NULL, NULL);
2078 if (screen_coords)
2079 {
2080 Ecore_Evas *ee = ecore_evas_ecore_evas_get(evas_object_evas_get(image));
2081 if (!ee) return r;
2082 ecore_evas_geometry_get(ee, &ee_x, &ee_y, NULL, NULL);
2083 r.x += ee_x;
2084 r.y += ee_y;
2085 }
2086 elm_image_object_size_get(obj, &r.w, &r.h);
2087 return r;
2088 }
2089
2090 EOLIAN const Efl_Access_Action_Data *
_efl_ui_image_efl_access_widget_action_elm_actions_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * pd EINA_UNUSED)2091 _efl_ui_image_efl_access_widget_action_elm_actions_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *pd EINA_UNUSED)
2092 {
2093 static Efl_Access_Action_Data atspi_actions[] = {
2094 { "activate", "activate", NULL, _key_action_activate },
2095 { NULL, NULL, NULL, NULL },
2096 };
2097 return &atspi_actions[0];
2098 }
2099
2100 static Eina_Bool
_icon_standard_set(Evas_Object * obj,const char * name)2101 _icon_standard_set(Evas_Object *obj, const char *name)
2102 {
2103 EFL_UI_IMAGE_DATA_GET(obj, sd);
2104
2105 if (_elm_theme_object_icon_set(obj, name, "default"))
2106 {
2107 /* TODO: elm_unneed_efreet() */
2108 sd->freedesktop.use = EINA_FALSE;
2109 return EINA_TRUE;
2110 }
2111 return EINA_FALSE;
2112 }
2113
2114 static Eina_Bool
_icon_freedesktop_set(Evas_Object * obj,const char * name,int size)2115 _icon_freedesktop_set(Evas_Object *obj, const char *name, int size)
2116 {
2117 const char *path;
2118
2119 EFL_UI_IMAGE_DATA_GET(obj, sd);
2120
2121 elm_need_efreet();
2122
2123 if (icon_theme == NON_EXISTING) return EINA_FALSE;
2124
2125 if (!icon_theme)
2126 {
2127 Efreet_Icon_Theme *theme;
2128 /* TODO: Listen for EFREET_EVENT_ICON_CACHE_UPDATE */
2129 theme = efreet_icon_theme_find(elm_config_icon_theme_get());
2130 if (!theme)
2131 {
2132 const char **itr;
2133 static const char *themes[] = {
2134 "gnome", "Human", "oxygen", "hicolor", NULL
2135 };
2136 for (itr = themes; *itr; itr++)
2137 {
2138 theme = efreet_icon_theme_find(*itr);
2139 if (theme) break;
2140 }
2141 }
2142
2143 if (!theme)
2144 {
2145 icon_theme = NON_EXISTING;
2146 return EINA_FALSE;
2147 }
2148 else
2149 icon_theme = eina_stringshare_add(theme->name.internal);
2150 }
2151 path = efreet_icon_path_find(icon_theme, name, size);
2152 sd->freedesktop.use = !!path;
2153 if (sd->freedesktop.use)
2154 {
2155 sd->freedesktop.requested_size = size;
2156 efl_file_simple_load(obj, path, NULL);
2157 return EINA_TRUE;
2158 }
2159 return EINA_FALSE;
2160 }
2161
2162 static inline int
_icon_size_min_get(Evas_Object * image)2163 _icon_size_min_get(Evas_Object *image)
2164 {
2165 int w, h;
2166
2167 evas_object_geometry_get(image, NULL, NULL, &w, &h);
2168
2169 return MAX(16, MIN(w, h));
2170 }
2171
2172 /* FIXME: move this code to ecore */
2173 #ifdef _WIN32
2174 static Eina_Bool
_path_is_absolute(const char * path)2175 _path_is_absolute(const char *path)
2176 {
2177 //TODO: Check if this works with all absolute paths in windows
2178 return (isalpha(*path)) && (*(path + 1) == ':') &&
2179 ((*(path + 2) == '\\') || (*(path + 2) == '/'));
2180 }
2181
2182 #else
2183 static Eina_Bool
_path_is_absolute(const char * path)2184 _path_is_absolute(const char *path)
2185 {
2186 return *path == '/';
2187 }
2188
2189 #endif
2190
2191 static Eina_Bool
_internal_efl_ui_image_icon_set(Evas_Object * obj,const char * name,Eina_Bool * fdo)2192 _internal_efl_ui_image_icon_set(Evas_Object *obj, const char *name, Eina_Bool *fdo)
2193 {
2194 char *tmp;
2195 Eina_Bool ret = EINA_FALSE;
2196
2197 EFL_UI_IMAGE_DATA_GET(obj, sd);
2198
2199 /* try locating the icon using the specified theme */
2200 if (!strcmp(ELM_CONFIG_ICON_THEME_ELEMENTARY, elm_config_icon_theme_get()))
2201 {
2202 ret = _icon_standard_set(obj, name);
2203 if (ret && fdo) *fdo = EINA_FALSE;
2204 if (!ret)
2205 {
2206 ret = _icon_freedesktop_set(obj, name, _icon_size_min_get(obj));
2207 if (ret && fdo) *fdo = EINA_TRUE;
2208 }
2209 }
2210 else
2211 {
2212 ret = _icon_freedesktop_set(obj, name, _icon_size_min_get(obj));
2213 if (ret && fdo) *fdo = EINA_TRUE;
2214 }
2215
2216 if (ret)
2217 {
2218 eina_stringshare_replace(&sd->stdicon, name);
2219 efl_canvas_group_change(obj);
2220 return EINA_TRUE;
2221 }
2222 else
2223 eina_stringshare_replace(&sd->stdicon, NULL);
2224
2225 if (_path_is_absolute(name))
2226 {
2227 if (fdo)
2228 *fdo = EINA_FALSE;
2229 return efl_file_simple_load(obj, name, NULL);
2230 }
2231
2232 /* if that fails, see if icon name is in the format size/name. if so,
2233 try locating a fallback without the size specification */
2234 if (!(tmp = strchr(name, '/'))) return EINA_FALSE;
2235 ++tmp;
2236 if (*tmp) return _internal_efl_ui_image_icon_set(obj, tmp, fdo);
2237 /* give up */
2238 return EINA_FALSE;
2239 }
2240
2241 static void
_efl_ui_image_icon_resize_cb(void * data,Evas * e EINA_UNUSED,Evas_Object * obj,void * event_info EINA_UNUSED)2242 _efl_ui_image_icon_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
2243 {
2244 EFL_UI_IMAGE_DATA_GET(data, sd);
2245 const char *refup = eina_stringshare_ref(sd->stdicon);
2246 Eina_Bool fdo = EINA_FALSE;
2247
2248 if (!_internal_efl_ui_image_icon_set(obj, sd->stdicon, &fdo) || (!fdo))
2249 evas_object_event_callback_del_full
2250 (obj, EVAS_CALLBACK_RESIZE, _efl_ui_image_icon_resize_cb, data);
2251 eina_stringshare_del(refup);
2252 }
2253
2254 EOLIAN static Eina_Bool
_efl_ui_image_icon_set(Eo * obj,Efl_Ui_Image_Data * _pd EINA_UNUSED,const char * name)2255 _efl_ui_image_icon_set(Eo *obj, Efl_Ui_Image_Data *_pd EINA_UNUSED, const char *name)
2256 {
2257 Eina_Bool fdo = EINA_FALSE;
2258
2259 if (!name) return EINA_FALSE;
2260
2261 evas_object_event_callback_del_full
2262 (obj, EVAS_CALLBACK_RESIZE, _efl_ui_image_icon_resize_cb, obj);
2263
2264 Eina_Bool int_ret = _internal_efl_ui_image_icon_set(obj, name, &fdo);
2265
2266 if (fdo)
2267 evas_object_event_callback_add
2268 (obj, EVAS_CALLBACK_RESIZE, _efl_ui_image_icon_resize_cb, obj);
2269
2270 return int_ret;
2271 }
2272
2273 EOLIAN static const char*
_efl_ui_image_icon_get(const Eo * obj EINA_UNUSED,Efl_Ui_Image_Data * sd)2274 _efl_ui_image_icon_get(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Data *sd)
2275 {
2276 return sd->stdicon;
2277 }
2278
2279 void
_update_viewmodel(Eo * obj,Efl_Ui_Image_Data * pd)2280 _update_viewmodel(Eo *obj, Efl_Ui_Image_Data *pd)
2281 {
2282 Eina_Value *vfile = NULL;
2283 Eina_Value *vkey = NULL;
2284 Eina_File *f = NULL;
2285 char *file = NULL;
2286 char *key = NULL;
2287 Efl_Model *model;
2288
2289 if (!pd->property.file) return ;
2290
2291 if (!pd->property_watch)
2292 {
2293 efl_event_callback_add(obj, EFL_UI_VIEW_EVENT_MODEL_CHANGED,
2294 _efl_ui_image_model_changed, pd);
2295 pd->property_watch = EINA_TRUE;
2296 }
2297
2298 model = efl_ui_view_model_get(obj);
2299 if (!model) return ;
2300
2301 vfile = efl_model_property_get(model, pd->property.file);
2302 if (!vfile) return;
2303 vkey = efl_model_property_get(model, pd->property.key);
2304
2305 if (eina_value_type_get(vfile) == EINA_VALUE_TYPE_ERROR)
2306 goto err;
2307
2308 if (pd->property.icon)
2309 {
2310 file = eina_value_to_string(vfile);
2311
2312 efl_ui_image_icon_set(obj, file);
2313 }
2314 else
2315 {
2316 if (vkey && eina_value_type_get(vkey) != EINA_VALUE_TYPE_ERROR)
2317 key = eina_value_to_string(vkey);
2318 if (eina_value_type_get(vfile) == EINA_VALUE_TYPE_FILE)
2319 {
2320 eina_value_get(vfile, &f);
2321
2322 efl_file_simple_mmap_load(obj, f, key);
2323 }
2324 else
2325 {
2326 file = eina_value_to_string(vfile);
2327
2328 efl_file_simple_load(obj, file, key);
2329 }
2330 }
2331
2332 free(file);
2333 free(key);
2334 err:
2335 eina_value_free(vfile);
2336 eina_value_free(vkey);
2337 }
2338
2339 static void
_efl_ui_image_model_properties_changed_cb(void * data,const Efl_Event * event)2340 _efl_ui_image_model_properties_changed_cb(void *data, const Efl_Event *event)
2341 {
2342 Efl_Model_Property_Event *evt = event->info;
2343 Eina_Array_Iterator it;
2344 Eo *obj = data;
2345 const char *prop;
2346 unsigned int i;
2347 Eina_Bool refresh = EINA_FALSE;
2348 EFL_UI_IMAGE_DATA_GET(obj, pd);
2349
2350 if (!evt->changed_properties)
2351 return;
2352
2353 EINA_ARRAY_ITER_NEXT(evt->changed_properties, i, prop, it)
2354 {
2355 if (pd->property.file &&
2356 (pd->property.file == prop || !strcmp(pd->property.file, prop)))
2357 {
2358 refresh = EINA_TRUE;
2359 break ;
2360 }
2361 if (pd->property.key &&
2362 (pd->property.key == prop || !strcmp(pd->property.key, prop)))
2363 {
2364 refresh = EINA_TRUE;
2365 break ;
2366 }
2367 }
2368
2369 if (refresh) _update_viewmodel(obj, pd);
2370 }
2371
2372 EOLIAN static Eina_Error
_efl_ui_image_efl_ui_property_bind_property_bind(Eo * obj,Efl_Ui_Image_Data * pd,const char * key,const char * property)2373 _efl_ui_image_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Image_Data *pd, const char *key, const char *property)
2374 {
2375 Eina_Stringshare *sk;
2376
2377 if (efl_ui_property_bind(efl_super(obj, EFL_UI_IMAGE_CLASS), key, property) == 0)
2378 return 0;
2379
2380 if (strcmp(key, "filename") == 0)
2381 {
2382 pd->property.icon = EINA_FALSE;
2383 eina_stringshare_replace(&pd->property.file, property);
2384 }
2385 else if (strcmp(key, "icon") == 0)
2386 {
2387 pd->property.icon = EINA_TRUE;
2388 eina_stringshare_replace(&pd->property.file, property);
2389 eina_stringshare_replace(&pd->property.key, NULL);
2390 }
2391 else if (strcmp(key, "key") == 0)
2392 {
2393 eina_stringshare_replace(&pd->property.key, property);
2394 }
2395 else
2396 {
2397 return EFL_PROPERTY_ERROR_INVALID_KEY;
2398 }
2399
2400 _update_viewmodel(obj, pd);
2401
2402 sk = eina_stringshare_add(key);
2403 efl_event_callback_call(obj, EFL_UI_PROPERTY_BIND_EVENT_PROPERTY_BOUND, (void*) sk);
2404 eina_stringshare_del(sk);
2405
2406 return 0;
2407 }
2408
2409 EAPI void
elm_image_smooth_set(Evas_Object * obj,Eina_Bool smooth)2410 elm_image_smooth_set(Evas_Object *obj, Eina_Bool smooth)
2411 {
2412 EINA_SAFETY_ON_FALSE_RETURN(efl_isa(obj, MY_CLASS));
2413 efl_gfx_image_smooth_scale_set(obj, smooth);
2414 efl_canvas_group_change(obj);
2415 }
2416
2417 EAPI Eina_Bool
elm_image_smooth_get(const Evas_Object * obj)2418 elm_image_smooth_get(const Evas_Object *obj)
2419 {
2420 EINA_SAFETY_ON_FALSE_RETURN_VAL(efl_isa(obj, MY_CLASS), EINA_FALSE);
2421 return efl_gfx_image_smooth_scale_get(obj);
2422 }
2423
2424 // A11Y - END
2425
2426 /* Legacy deprecated functions */
2427 EAPI void
elm_image_editable_set(Evas_Object * obj,Eina_Bool edit)2428 elm_image_editable_set(Evas_Object *obj, Eina_Bool edit)
2429 {
2430 efl_ui_draggable_drag_target_set(obj, edit);
2431 }
2432
2433 EAPI Eina_Bool
elm_image_editable_get(const Evas_Object * obj)2434 elm_image_editable_get(const Evas_Object *obj)
2435 {
2436 return efl_ui_draggable_drag_target_get(obj);
2437 }
2438
2439 EAPI Eina_Bool
elm_image_file_set(Evas_Object * obj,const char * file,const char * group)2440 elm_image_file_set(Evas_Object *obj, const char *file, const char *group)
2441 {
2442 Eina_Bool ret = EINA_FALSE;
2443
2444 EFL_UI_IMAGE_CHECK(obj) EINA_FALSE;
2445
2446 /* check if previous path is same with new one.
2447 and return true if they are same */
2448 const char *cur_file_path = efl_file_get(obj);
2449 if ((cur_file_path && file) && !strcmp(cur_file_path, file))
2450 {
2451 const char *cur_group = efl_file_key_get(obj);
2452 if (!(cur_group && group && strcmp(cur_group, group)))
2453 {
2454 if (efl_file_loaded_get(obj)) return EINA_TRUE;
2455 if (_efl_ui_image_is_remote(file)) return EINA_TRUE;
2456 }
2457 }
2458
2459 ret = efl_file_simple_load(obj, file, group);
2460 efl_canvas_group_change(obj);
2461 return ret;
2462 }
2463
2464 EAPI void
elm_image_file_get(const Eo * obj,const char ** file,const char ** group)2465 elm_image_file_get(const Eo *obj, const char **file, const char **group)
2466 {
2467 EFL_UI_IMAGE_DATA_GET(obj, sd);
2468 efl_file_simple_get(sd->img, file, group);
2469 }
2470
2471 EAPI Eina_Bool
elm_image_mmap_set(Evas_Object * obj,const Eina_File * file,const char * group)2472 elm_image_mmap_set(Evas_Object *obj, const Eina_File *file, const char *group)
2473 {
2474 EFL_UI_IMAGE_CHECK(obj) EINA_FALSE;
2475 return efl_file_simple_mmap_load(obj, file, group);
2476 }
2477
2478 EAPI Eina_Bool
elm_image_memfile_set(Evas_Object * obj,const void * img,size_t size,const char * format,const char * key)2479 elm_image_memfile_set(Evas_Object *obj, const void *img, size_t size, const char *format, const char *key)
2480 {
2481 EINA_SAFETY_ON_NULL_RETURN_VAL(img, EINA_FALSE);
2482
2483 Evas_Load_Error err;
2484
2485 EFL_UI_IMAGE_CHECK(obj) EINA_FALSE;
2486 EFL_UI_IMAGE_DATA_GET(obj, sd);
2487
2488 if (efl_file_loaded_get(obj))
2489 efl_file_unload(obj);
2490 else
2491 _efl_ui_image_file_set_do(obj);
2492
2493 evas_object_image_memfile_set
2494 (sd->img, (void *)img, size, (char *)format, (char *)key);
2495
2496 if (sd->preload_status == EFL_UI_IMAGE_PRELOAD_DISABLED)
2497 {
2498 _prev_img_del(sd);
2499 if (sd->autoplay) efl_player_playing_set(sd->self, EINA_TRUE);
2500 }
2501 else
2502 {
2503 sd->preload_status = EFL_UI_IMAGE_PRELOADING;
2504 evas_object_image_preload(sd->img, EINA_FALSE);
2505 }
2506
2507 err = evas_object_image_load_error_get(sd->img);
2508 if (err != EVAS_LOAD_ERROR_NONE)
2509 {
2510 if (img)
2511 ERR("Failed to load image from memory block (" FMT_SIZE_T
2512 " bytes): %s (%p)", size, evas_load_error_str(err), sd->img);
2513 else
2514 ERR("NULL image data passed (%p)", sd->img);
2515
2516 _prev_img_del(sd);
2517 return EINA_FALSE;
2518 }
2519
2520 efl_canvas_group_change(obj);
2521
2522 return EINA_TRUE;
2523 }
2524
2525 EAPI void
elm_image_fill_outside_set(Evas_Object * obj,Eina_Bool fill_outside)2526 elm_image_fill_outside_set(Evas_Object *obj, Eina_Bool fill_outside)
2527 {
2528 EFL_UI_IMAGE_CHECK(obj);
2529 EFL_UI_IMAGE_DATA_GET(obj, sd);
2530 fill_outside = !!fill_outside;
2531
2532 if (sd->fill_inside == !fill_outside) return;
2533
2534 sd->fill_inside = !fill_outside;
2535
2536 if (sd->aspect_fixed)
2537 {
2538 if (sd->fill_inside) sd->scale_type = EFL_GFX_IMAGE_SCALE_METHOD_FIT;
2539 else sd->scale_type = EFL_GFX_IMAGE_SCALE_METHOD_EXPAND;
2540 }
2541 else
2542 sd->scale_type = EFL_GFX_IMAGE_SCALE_METHOD_FILL;
2543
2544 efl_canvas_group_change(obj);
2545 }
2546
2547 EAPI Eina_Bool
elm_image_fill_outside_get(const Evas_Object * obj)2548 elm_image_fill_outside_get(const Evas_Object *obj)
2549 {
2550 EFL_UI_IMAGE_CHECK(obj) EINA_FALSE;
2551 EFL_UI_IMAGE_DATA_GET(obj, sd);
2552
2553 return !sd->fill_inside;
2554 }
2555
2556 // TODO: merge preload and async code
2557 EAPI void
elm_image_preload_disabled_set(Evas_Object * obj,Eina_Bool disable)2558 elm_image_preload_disabled_set(Evas_Object *obj, Eina_Bool disable)
2559 {
2560 EFL_UI_IMAGE_CHECK(obj);
2561 EFL_UI_IMAGE_DATA_GET(obj, sd);
2562
2563 if (sd->edje) return;
2564 if (!sd->img)
2565 {
2566 if (disable) sd->preload_status = EFL_UI_IMAGE_PRELOAD_DISABLED;
2567 else sd->preload_status = EFL_UI_IMAGE_PRELOAD_ENABLED;
2568 return;
2569 }
2570
2571 if (disable)
2572 {
2573 if (sd->preload_status == EFL_UI_IMAGE_PRELOADING)
2574 {
2575 evas_object_image_preload(sd->img, disable);
2576 if (sd->show) evas_object_show(sd->img);
2577 _prev_img_del(sd);
2578 }
2579 sd->preload_status = EFL_UI_IMAGE_PRELOAD_DISABLED;
2580 }
2581 else if (sd->preload_status == EFL_UI_IMAGE_PRELOAD_DISABLED)
2582 {
2583 sd->preload_status = EFL_UI_IMAGE_PRELOADING;
2584 evas_object_image_preload(sd->img, disable);
2585 }
2586 }
2587
2588 EAPI void
elm_image_orient_set(Evas_Object * obj,Elm_Image_Orient elm_orient)2589 elm_image_orient_set(Evas_Object *obj, Elm_Image_Orient elm_orient)
2590 {
2591 // This array takes an Elm_Image_Orient and turns it into an Efl_Gfx_Image_Orientation
2592 static const Efl_Gfx_Image_Orientation efl_orient[8] = {
2593 EFL_GFX_IMAGE_ORIENTATION_NONE,
2594 EFL_GFX_IMAGE_ORIENTATION_RIGHT,
2595 EFL_GFX_IMAGE_ORIENTATION_DOWN,
2596 EFL_GFX_IMAGE_ORIENTATION_LEFT,
2597 EFL_GFX_IMAGE_ORIENTATION_FLIP_HORIZONTAL,
2598 EFL_GFX_IMAGE_ORIENTATION_FLIP_VERTICAL,
2599 EFL_GFX_IMAGE_ORIENTATION_LEFT | EFL_GFX_IMAGE_ORIENTATION_FLIP_VERTICAL,
2600 EFL_GFX_IMAGE_ORIENTATION_RIGHT | EFL_GFX_IMAGE_ORIENTATION_FLIP_VERTICAL
2601 };
2602
2603 EFL_UI_IMAGE_CHECK(obj);
2604 EFL_UI_IMAGE_DATA_GET(obj, sd);
2605 EINA_SAFETY_ON_FALSE_RETURN(elm_orient >= 0 && elm_orient < 8);
2606 sd->image_orient = elm_orient;
2607 efl_gfx_image_orientation_set(obj, efl_orient[elm_orient]);
2608
2609 // to keep behavior compatibility, update inlined image orientation
2610 if (sd->img) efl_gfx_image_orientation_set(sd->img, efl_orient[elm_orient]);
2611 }
2612
2613 EAPI Elm_Image_Orient
elm_image_orient_get(const Evas_Object * obj)2614 elm_image_orient_get(const Evas_Object *obj)
2615 {
2616 EFL_UI_IMAGE_CHECK(obj) ELM_IMAGE_ORIENT_NONE;
2617 EFL_UI_IMAGE_DATA_GET(obj, sd);
2618
2619 return sd->image_orient;
2620 }
2621
2622 EAPI Evas_Object*
elm_image_object_get(const Evas_Object * obj)2623 elm_image_object_get(const Evas_Object *obj)
2624 {
2625 EFL_UI_IMAGE_CHECK(obj) NULL;
2626 EFL_UI_IMAGE_DATA_GET(obj, sd);
2627 if (!sd->img)
2628 sd->img = _img_new((Evas_Object *)obj);
2629
2630 return sd->img;
2631 }
2632
2633 EAPI void
elm_image_object_size_get(const Evas_Object * obj,int * w,int * h)2634 elm_image_object_size_get(const Evas_Object *obj, int *w, int *h)
2635 {
2636 Eina_Size2D sz;
2637 sz = efl_gfx_view_size_get(obj);
2638 if (w) *w = sz.w;
2639 if (h) *h = sz.h;
2640 }
2641
2642 EAPI void
elm_image_no_scale_set(Evas_Object * obj,Eina_Bool no_scale)2643 elm_image_no_scale_set(Evas_Object *obj, Eina_Bool no_scale)
2644 {
2645 EFL_UI_IMAGE_CHECK(obj);
2646 EFL_UI_IMAGE_DATA_GET(obj, sd);
2647 sd->no_scale = no_scale;
2648
2649 efl_canvas_group_change(obj);
2650 }
2651
2652 EAPI Eina_Bool
elm_image_no_scale_get(const Evas_Object * obj)2653 elm_image_no_scale_get(const Evas_Object *obj)
2654 {
2655 EFL_UI_IMAGE_CHECK(obj) EINA_FALSE;
2656 EFL_UI_IMAGE_DATA_GET(obj, sd);
2657 return sd->no_scale;
2658 }
2659
2660 EAPI void
elm_image_resizable_set(Evas_Object * obj,Eina_Bool up,Eina_Bool down)2661 elm_image_resizable_set(Evas_Object *obj, Eina_Bool up, Eina_Bool down)
2662 {
2663 EFL_UI_IMAGE_CHECK(obj);
2664 EFL_UI_IMAGE_DATA_GET(obj, sd);
2665 sd->scale_up = !!up;
2666 sd->scale_down = !!down;
2667
2668 efl_canvas_group_change(obj);
2669 }
2670
2671 EAPI void
elm_image_resizable_get(const Evas_Object * obj,Eina_Bool * size_up,Eina_Bool * size_down)2672 elm_image_resizable_get(const Evas_Object *obj, Eina_Bool *size_up, Eina_Bool *size_down)
2673 {
2674 EFL_UI_IMAGE_CHECK(obj);
2675 EFL_UI_IMAGE_DATA_GET(obj, sd);
2676 if (size_up) *size_up = sd->scale_up;
2677 if (size_down) *size_down = sd->scale_down;
2678 }
2679
2680 EAPI void
elm_image_aspect_fixed_set(Evas_Object * obj,Eina_Bool fixed)2681 elm_image_aspect_fixed_set(Evas_Object *obj, Eina_Bool fixed)
2682 {
2683 EFL_UI_IMAGE_CHECK(obj);
2684 EFL_UI_IMAGE_DATA_GET(obj, sd);
2685 fixed = !!fixed;
2686 if (sd->aspect_fixed == fixed) return;
2687
2688 sd->aspect_fixed = fixed;
2689
2690 if (sd->aspect_fixed)
2691 {
2692 if (sd->fill_inside) sd->scale_type = EFL_GFX_IMAGE_SCALE_METHOD_FIT;
2693 else sd->scale_type = EFL_GFX_IMAGE_SCALE_METHOD_EXPAND;
2694 }
2695 else
2696 sd->scale_type = EFL_GFX_IMAGE_SCALE_METHOD_FILL;
2697
2698 efl_canvas_group_change(obj);
2699 }
2700
2701 EAPI Eina_Bool
elm_image_aspect_fixed_get(const Evas_Object * obj)2702 elm_image_aspect_fixed_get(const Evas_Object *obj)
2703 {
2704 EFL_UI_IMAGE_CHECK(obj) EINA_FALSE;
2705 EFL_UI_IMAGE_DATA_GET(obj, sd);
2706 return sd->aspect_fixed;
2707 }
2708
2709 /* Standard widget overrides */
2710
ELM_WIDGET_KEY_DOWN_DEFAULT_IMPLEMENT(efl_ui_image,Efl_Ui_Image_Data)2711 ELM_WIDGET_KEY_DOWN_DEFAULT_IMPLEMENT(efl_ui_image, Efl_Ui_Image_Data)
2712
2713 /* Internal EO APIs and hidden overrides */
2714
2715 #define EFL_UI_IMAGE_EXTRA_OPS \
2716 EFL_CANVAS_GROUP_ADD_DEL_OPS(efl_ui_image), \
2717 EFL_CANVAS_GROUP_CALC_OPS(efl_ui_image)
2718
2719 #include "efl_ui_image.eo.c"
2720
2721 #include "efl_ui_image_legacy_eo.h"
2722
2723 #define MY_CLASS_NAME_LEGACY "elm_image"
2724
2725 static void
2726 _efl_ui_image_legacy_class_constructor(Efl_Class *klass)
2727 {
2728 evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass);
2729 }
2730
2731 EOLIAN static Eo *
_efl_ui_image_legacy_efl_object_constructor(Eo * obj,void * pd EINA_UNUSED)2732 _efl_ui_image_legacy_efl_object_constructor(Eo *obj, void *pd EINA_UNUSED)
2733 {
2734 obj = efl_constructor(efl_super(obj, EFL_UI_IMAGE_LEGACY_CLASS));
2735 efl_canvas_object_type_set(obj, MY_CLASS_NAME_LEGACY);
2736 return obj;
2737 }
2738
2739 EAPI Evas_Object *
elm_image_add(Evas_Object * parent)2740 elm_image_add(Evas_Object *parent)
2741 {
2742 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
2743 Evas_Object *obj = elm_legacy_add(EFL_UI_IMAGE_LEGACY_CLASS, parent);
2744 EFL_UI_IMAGE_DATA_GET(obj, priv);
2745
2746 efl_event_callback_add(obj, EFL_GFX_ENTITY_EVENT_HINTS_CHANGED, _on_size_hints_changed, priv);
2747
2748 return obj;
2749 }
2750
2751 #include "efl_ui_image_legacy_eo.c"
2752