1 #include <Elementary.h>
5 typedef struct _Smart_Data Smart_Data;
14 Eina_Bool fill_inside : 1;
15 Eina_Bool scale_up : 1;
16 Eina_Bool scale_down : 1;
17 Eina_Bool preloading : 1;
21 Eina_Bool aspect_ratio_retained: 1;
22 Elm_Image_Orient orient;
25 /* local subsystem functions */
26 static void _smart_reconfigure(Smart_Data *sd);
27 static void _smart_init(void);
28 static void _smart_add(Evas_Object *obj);
29 static void _smart_del(Evas_Object *obj);
30 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
31 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
32 static void _smart_show(Evas_Object *obj);
33 static void _smart_hide(Evas_Object *obj);
34 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
35 static void _smart_clip_set(Evas_Object *obj, Evas_Object * clip);
36 static void _smart_clip_unset(Evas_Object *obj);
38 static void _els_smart_icon_flip_horizontal(Smart_Data *sd);
39 static void _els_smart_icon_flip_vertical(Smart_Data *sd);
40 static void _els_smart_icon_rotate_180(Smart_Data *sd);
41 static Eina_Bool _els_smart_icon_dropcb(void *,Evas_Object *, Elm_Selection_Data *);
43 /* local subsystem globals */
44 static Evas_Smart *_e_smart = NULL;
46 /* externally accessible functions */
48 _els_smart_icon_add(Evas *evas)
51 return evas_object_smart_add(evas, _e_smart);
55 _preloaded(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
57 Smart_Data *sd = data;
59 sd->preloading = EINA_FALSE;
63 evas_object_show(sd->obj);
65 if (sd->prev) evas_object_del(sd->prev);
70 _els_smart_icon_file_key_set(Evas_Object *obj, const char *file, const char *key)
75 sd = evas_object_smart_data_get(obj);
76 if (!sd) return EINA_FALSE;
78 /* NOTE: Do not merge upstream for the if (sd->edje) { } statements
79 But wonder whether the edje resource icons have no problem. */
82 if (sd->prev) evas_object_del(sd->prev);
83 pclip = evas_object_clip_get(sd->obj);
84 if (sd->obj) sd->prev = sd->obj;
85 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
86 evas_object_event_callback_add(sd->obj,
87 EVAS_CALLBACK_IMAGE_PRELOADED,
89 evas_object_smart_member_add(sd->obj, obj);
90 if (sd->prev) evas_object_smart_member_add(sd->prev, obj);
91 evas_object_image_scale_hint_set(sd->obj,
92 EVAS_IMAGE_SCALE_HINT_STATIC);
93 evas_object_clip_set(sd->obj, pclip);
95 sd->edje = EINA_FALSE;
99 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
100 evas_object_image_file_set(sd->obj, file, key);
101 // NOTE: Do not merge upstream for sd->preloading.
102 sd->preloading = EINA_FALSE; // by default preload off by seok.j.jeong
103 sd->show = EINA_TRUE;
104 // NOTE: Do not merge upstream for sd->preloading.
106 evas_object_image_preload(sd->obj, EINA_FALSE);
107 // NOTE: Do not merge upstream for sd->preloading.
108 if (sd->preloading) // sd->preloading can be changed by above function. so add "if (sd->preloading)" as below
109 evas_object_hide(sd->obj);
110 if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
112 ERR("Things are going bad for '%s' (%p)", file, sd->obj);
115 _smart_reconfigure(sd);
120 _els_smart_icon_preload_set(Evas_Object *obj, Eina_Bool disable)
124 sd = evas_object_smart_data_get(obj);
125 if ((!sd) || sd->edje) return;
126 evas_object_image_preload(sd->obj, disable);
127 sd->preloading = !disable;
131 _els_smart_icon_file_edje_set(Evas_Object *obj, const char *file, const char *part)
136 sd = evas_object_smart_data_get(obj);
137 if (!sd) return EINA_FALSE;
138 /* smart code here */
139 if (sd->prev) evas_object_del(sd->prev);
144 pclip = evas_object_clip_get(sd->obj);
145 if (sd->obj) evas_object_del(sd->obj);
146 sd->obj = edje_object_add(evas_object_evas_get(obj));
147 evas_object_smart_member_add(sd->obj, obj);
148 if (sd->show) evas_object_show(sd->obj);
149 evas_object_clip_set(sd->obj, pclip);
151 sd->edje = EINA_TRUE;
152 if (!edje_object_file_set(sd->obj, file, part))
154 _smart_reconfigure(sd);
159 _els_smart_icon_file_get(const Evas_Object *obj, const char **file, const char **key)
161 Smart_Data *sd = evas_object_smart_data_get(obj);
164 edje_object_file_get(sd->obj, file, key);
166 evas_object_image_file_get(sd->obj, file, key);
170 _els_smart_icon_smooth_scale_set(Evas_Object *obj, Eina_Bool smooth)
172 Smart_Data *sd = evas_object_smart_data_get(obj);
176 evas_object_image_smooth_scale_set(sd->obj, smooth);
180 _els_smart_icon_smooth_scale_get(const Evas_Object *obj)
182 Smart_Data *sd = evas_object_smart_data_get(obj);
183 if (!sd) return EINA_FALSE;
186 return evas_object_image_smooth_scale_get(sd->obj);
190 _els_smart_icon_object_get(const Evas_Object *obj)
192 Smart_Data *sd = evas_object_smart_data_get(obj);
193 if (!sd) return NULL;
198 _els_smart_icon_size_get(const Evas_Object *obj, int *w, int *h)
205 sd = evas_object_smart_data_get(obj);
207 type = evas_object_type_get(sd->obj);
209 if (!strcmp(type, "edje"))
210 edje_object_size_min_get(sd->obj, &tw, &th);
212 evas_object_image_size_get(sd->obj, &tw, &th);
213 evas_object_geometry_get(sd->obj, NULL, NULL, &cw, &ch);
214 tw = tw > cw ? tw : cw;
215 th = th > ch ? th : ch;
216 tw = ((double)tw) * sd->scale;
217 th = ((double)th) * sd->scale;
223 _els_smart_icon_fill_inside_set(Evas_Object *obj, Eina_Bool fill_inside)
227 sd = evas_object_smart_data_get(obj);
229 if (((sd->fill_inside) && (fill_inside)) ||
230 ((!sd->fill_inside) && (!fill_inside))) return;
231 sd->fill_inside = fill_inside;
232 _smart_reconfigure(sd);
236 _els_smart_icon_fill_inside_get(const Evas_Object *obj)
238 Smart_Data *sd = evas_object_smart_data_get(obj);
239 if (!sd) return EINA_FALSE;
240 return sd->fill_inside;
244 _els_smart_icon_scale_up_set(Evas_Object *obj, Eina_Bool scale_up)
248 sd = evas_object_smart_data_get(obj);
250 if (((sd->scale_up) && (scale_up)) ||
251 ((!sd->scale_up) && (!scale_up))) return;
252 sd->scale_up = scale_up;
253 _smart_reconfigure(sd);
257 _els_smart_icon_scale_up_get(const Evas_Object *obj)
259 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
260 if (!sd) return EINA_FALSE;
265 _els_smart_icon_scale_down_set(Evas_Object *obj, Eina_Bool scale_down)
269 sd = evas_object_smart_data_get(obj);
271 if (((sd->scale_down) && (scale_down)) ||
272 ((!sd->scale_down) && (!scale_down))) return;
273 sd->scale_down = scale_down;
274 _smart_reconfigure(sd);
278 _els_smart_icon_scale_down_get(const Evas_Object *obj)
280 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
281 if (!sd) return EINA_FALSE;
286 _els_smart_icon_scale_size_set(Evas_Object *obj, int size)
290 sd = evas_object_smart_data_get(obj);
293 if (!sd->obj) return;
296 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
300 _els_smart_icon_scale_size_get(const Evas_Object *obj)
302 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
308 _els_smart_icon_scale_set(Evas_Object *obj, double scale)
310 Smart_Data *sd = evas_object_smart_data_get(obj);
313 _smart_reconfigure(sd);
317 _els_smart_icon_scale_get(const Evas_Object *obj)
319 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
325 _els_smart_icon_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
329 unsigned int *data, *data2, *to, *from;
330 int x, y, w, hw, iw, ih;
331 const char *file, *key;
333 sd = evas_object_smart_data_get(obj);
340 case ELM_IMAGE_FLIP_HORIZONTAL:
341 _els_smart_icon_flip_horizontal(sd);
343 case ELM_IMAGE_FLIP_VERTICAL:
344 _els_smart_icon_flip_vertical(sd);
346 case ELM_IMAGE_ROTATE_180_CW:
347 _els_smart_icon_rotate_180(sd);
353 evas_object_image_size_get(sd->obj, &iw, &ih);
354 evas_object_image_file_get(sd->obj, &file, &key);
355 tmp = evas_object_image_add(evas_object_evas_get(sd->obj));
356 evas_object_image_file_set(tmp, file, key);
357 data2 = evas_object_image_data_get(tmp, EINA_FALSE);
364 evas_object_image_size_set(sd->obj, iw, ih);
365 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
368 case ELM_IMAGE_FLIP_TRANSPOSE:
372 case ELM_IMAGE_FLIP_TRANSVERSE:
377 case ELM_IMAGE_ROTATE_90_CW:
381 case ELM_IMAGE_ROTATE_90_CCW:
387 ERR("unknown orient %d", orient);
388 evas_object_del(tmp);
389 evas_object_image_data_set(sd->obj, data); // give it back
393 for (x = iw; --x >= 0;)
395 for (y = ih; --y >= 0;)
404 evas_object_del(tmp);
405 evas_object_image_data_set(sd->obj, data);
406 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
407 _smart_reconfigure(sd);
411 _els_smart_icon_orient_get(const Evas_Object *obj)
413 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
419 * Turns on editing through drag and drop and copy and paste.
422 _els_smart_icon_edit_set(Evas_Object *obj, Eina_Bool edit, Evas_Object *parent)
424 Smart_Data *sd = evas_object_smart_data_get(obj);
429 printf("No editing edje objects yet (ever)\n");
433 /* Unfortunately eina bool is not a bool, but a char */
434 if (edit == sd->edit) return;
439 elm_drop_target_add(obj, ELM_SEL_FORMAT_IMAGE, _els_smart_icon_dropcb,
442 elm_drop_target_del(obj);
446 _els_smart_icon_edit_get(const Evas_Object *obj)
448 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
449 if (!sd) return EINA_FALSE;
454 _els_smart_icon_edje_get(Evas_Object *obj)
456 Smart_Data *sd = evas_object_smart_data_get(obj);
457 if (!sd) return NULL;
458 if (!sd->edje) return NULL;
463 _els_smart_icon_aspect_ratio_retained_set(Evas_Object *obj, Eina_Bool retained)
467 sd = evas_object_smart_data_get(obj);
470 retained = !!retained;
471 if (sd->aspect_ratio_retained == retained) return;
472 sd->aspect_ratio_retained = retained;
473 _smart_reconfigure(sd);
477 _els_smart_icon_aspect_ratio_retained_get(const Evas_Object *obj)
481 sd = evas_object_smart_data_get(obj);
482 if (!sd) return EINA_FALSE;
483 return sd->aspect_ratio_retained;
486 /* local subsystem globals */
488 _smart_reconfigure(Smart_Data *sd)
490 Evas_Coord x, y, w, h;
493 if (!sd->obj) return;
498 type = evas_object_type_get(sd->obj);
500 if (!strcmp(type, "edje"))
504 evas_object_move(sd->obj, x, y);
505 evas_object_resize(sd->obj, w, h);
511 evas_object_image_size_get(sd->obj, &iw, &ih);
513 iw = ((double)iw) * sd->scale;
514 ih = ((double)ih) * sd->scale;
519 if (sd->aspect_ratio_retained)
521 h = ((double)ih * w) / (double)iw;
527 w = ((double)iw * h) / (double)ih;
535 w = ((double)iw * h) / (double)ih;
549 x = sd->x + ((sd->w - w) / 2);
550 y = sd->y + ((sd->h - h) / 2);
551 evas_object_move(sd->obj, x, y);
552 evas_object_image_fill_set(sd->obj, 0, 0, w, h);
553 evas_object_resize(sd->obj, w, h);
560 if (_e_smart) return;
562 static const Evas_Smart_Class sc =
565 EVAS_SMART_CLASS_VERSION,
583 _e_smart = evas_smart_class_new(&sc);
588 _smart_add(Evas_Object *obj)
592 sd = calloc(1, sizeof(Smart_Data));
594 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
596 evas_object_image_scale_hint_set(sd->obj, EVAS_IMAGE_SCALE_HINT_STATIC);
601 sd->fill_inside = EINA_TRUE;
602 sd->scale_up = EINA_TRUE;
603 sd->scale_down = EINA_TRUE;
604 sd->aspect_ratio_retained = EINA_TRUE;
607 evas_object_smart_member_add(sd->obj, obj);
608 evas_object_smart_data_set(obj, sd);
609 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED,
614 _smart_del(Evas_Object *obj)
618 sd = evas_object_smart_data_get(obj);
620 evas_object_del(sd->obj);
621 if (sd->prev) evas_object_del(sd->prev);
626 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
630 sd = evas_object_smart_data_get(obj);
632 if ((sd->x == x) && (sd->y == y)) return;
635 _smart_reconfigure(sd);
639 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
643 sd = evas_object_smart_data_get(obj);
645 if ((sd->w == w) && (sd->h == h)) return;
648 _smart_reconfigure(sd);
652 _smart_show(Evas_Object *obj)
656 sd = evas_object_smart_data_get(obj);
658 sd->show = EINA_TRUE;
661 evas_object_show(sd->obj);
662 if (sd->prev) evas_object_del(sd->prev);
668 _smart_hide(Evas_Object *obj)
672 sd = evas_object_smart_data_get(obj);
674 sd->show = EINA_FALSE;
675 evas_object_hide(sd->obj);
676 if (sd->prev) evas_object_del(sd->prev);
681 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
685 sd = evas_object_smart_data_get(obj);
687 evas_object_color_set(sd->obj, r, g, b, a);
688 if (sd->prev) evas_object_color_set(sd->prev, r, g, b, a);
692 _smart_clip_set(Evas_Object *obj, Evas_Object * clip)
696 sd = evas_object_smart_data_get(obj);
698 evas_object_clip_set(sd->obj, clip);
699 if (sd->prev) evas_object_clip_set(sd->prev, clip);
703 _smart_clip_unset(Evas_Object *obj)
707 sd = evas_object_smart_data_get(obj);
709 evas_object_clip_unset(sd->obj);
710 if (sd->prev) evas_object_clip_unset(sd->prev);
714 _els_smart_icon_flip_horizontal(Smart_Data *sd)
717 unsigned int *p1, *p2, tmp;
720 evas_object_image_size_get(sd->obj, &iw, &ih);
721 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
723 for (y = 0; y < ih; y++)
725 p1 = data + (y * iw);
726 p2 = data + ((y + 1) * iw) - 1;
727 for (x = 0; x < (iw >> 1); x++)
737 evas_object_image_data_set(sd->obj, data);
738 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
739 _smart_reconfigure(sd);
743 _els_smart_icon_flip_vertical(Smart_Data *sd)
746 unsigned int *p1, *p2, tmp;
749 evas_object_image_size_get(sd->obj, &iw, &ih);
750 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
752 for (y = 0; y < (ih >> 1); y++)
754 p1 = data + (y * iw);
755 p2 = data + ((ih - 1 - y) * iw);
756 for (x = 0; x < iw; x++)
766 evas_object_image_data_set(sd->obj, data);
767 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
768 _smart_reconfigure(sd);
772 _els_smart_icon_rotate_180(Smart_Data *sd)
775 unsigned int *p1, *p2, tmp;
778 evas_object_image_size_get(sd->obj, &iw, &ih);
779 data = evas_object_image_data_get(sd->obj, 1);
793 evas_object_image_data_set(sd->obj, data);
794 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
795 _smart_reconfigure(sd);
799 _els_smart_icon_dropcb(void *elmobj,Evas_Object *obj, Elm_Selection_Data *drop)
801 _els_smart_icon_file_key_set(obj, drop->data, NULL);
802 evas_object_smart_callback_call(elmobj, "drop", drop->data);
806 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 :*/