1 #include <Elementary.h>
4 typedef struct _Smart_Data Smart_Data;
13 Eina_Bool fill_inside : 1;
14 Eina_Bool scale_up : 1;
15 Eina_Bool scale_down : 1;
16 Eina_Bool preloading : 1;
20 Eina_Bool aspect_ratio_retained: 1;
21 Elm_Image_Orient orient;
24 /* local subsystem functions */
25 static void _smart_reconfigure(Smart_Data *sd);
26 static void _smart_init(void);
27 static void _smart_add(Evas_Object *obj);
28 static void _smart_del(Evas_Object *obj);
29 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
30 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
31 static void _smart_show(Evas_Object *obj);
32 static void _smart_hide(Evas_Object *obj);
33 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
34 static void _smart_clip_set(Evas_Object *obj, Evas_Object * clip);
35 static void _smart_clip_unset(Evas_Object *obj);
37 static void _els_smart_icon_flip_horizontal(Smart_Data *sd);
38 static void _els_smart_icon_flip_vertical(Smart_Data *sd);
39 static void _els_smart_icon_rotate_180(Smart_Data *sd);
40 static Eina_Bool _els_smart_icon_dropcb(void *,Evas_Object *, Elm_Selection_Data *);
42 /* local subsystem globals */
43 static Evas_Smart *_e_smart = NULL;
45 /* externally accessible functions */
47 _els_smart_icon_add(Evas *evas)
50 return evas_object_smart_add(evas, _e_smart);
54 _preloaded(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
56 Smart_Data *sd = data;
58 sd->preloading = EINA_FALSE;
62 evas_object_show(sd->obj);
64 if (sd->prev) evas_object_del(sd->prev);
69 _els_smart_icon_file_key_set(Evas_Object *obj, const char *file, const char *key)
74 sd = evas_object_smart_data_get(obj);
75 if (!sd) return EINA_FALSE;
77 /* NOTE: Do not merge upstream for the if (sd->edje) { } statements
78 But wonder whether the edje resource icons have no problem. */
81 if (sd->prev) evas_object_del(sd->prev);
82 pclip = evas_object_clip_get(sd->obj);
83 if (sd->obj) sd->prev = sd->obj;
84 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
85 evas_object_event_callback_add(sd->obj,
86 EVAS_CALLBACK_IMAGE_PRELOADED,
88 evas_object_smart_member_add(sd->obj, obj);
89 if (sd->prev) evas_object_smart_member_add(sd->prev, obj);
90 evas_object_image_scale_hint_set(sd->obj,
91 EVAS_IMAGE_SCALE_HINT_STATIC);
92 evas_object_clip_set(sd->obj, pclip);
94 sd->edje = EINA_FALSE;
98 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
99 evas_object_image_file_set(sd->obj, file, key);
100 // NOTE: Do not merge upstream for sd->preloading.
101 sd->preloading = EINA_FALSE; // by default preload off by seok.j.jeong
102 sd->show = EINA_TRUE;
103 // NOTE: Do not merge upstream for sd->preloading.
105 evas_object_image_preload(sd->obj, EINA_FALSE);
106 // NOTE: Do not merge upstream for sd->preloading.
107 if (sd->preloading) // sd->preloading can be changed by above function. so add "if (sd->preloading)" as below
108 evas_object_hide(sd->obj);
109 if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
111 ERR("Things are going bad for '%s' (%p)", file, sd->obj);
114 _smart_reconfigure(sd);
119 _els_smart_icon_file_edje_set(Evas_Object *obj, const char *file, const char *part)
124 sd = evas_object_smart_data_get(obj);
125 if (!sd) return EINA_FALSE;
126 /* smart code here */
127 if (sd->prev) evas_object_del(sd->prev);
132 pclip = evas_object_clip_get(sd->obj);
133 if (sd->obj) evas_object_del(sd->obj);
134 sd->obj = edje_object_add(evas_object_evas_get(obj));
135 evas_object_smart_member_add(sd->obj, obj);
136 if (sd->show) evas_object_show(sd->obj);
137 evas_object_clip_set(sd->obj, pclip);
139 sd->edje = EINA_TRUE;
140 if (!edje_object_file_set(sd->obj, file, part))
142 _smart_reconfigure(sd);
147 _els_smart_icon_file_get(const Evas_Object *obj, const char **file, const char **key)
149 Smart_Data *sd = evas_object_smart_data_get(obj);
152 edje_object_file_get(sd->obj, file, key);
154 evas_object_image_file_get(sd->obj, file, key);
158 _els_smart_icon_smooth_scale_set(Evas_Object *obj, Eina_Bool smooth)
160 Smart_Data *sd = evas_object_smart_data_get(obj);
164 evas_object_image_smooth_scale_set(sd->obj, smooth);
168 _els_smart_icon_smooth_scale_get(const Evas_Object *obj)
170 Smart_Data *sd = evas_object_smart_data_get(obj);
171 if (!sd) return EINA_FALSE;
174 return evas_object_image_smooth_scale_get(sd->obj);
178 _els_smart_icon_object_get(const Evas_Object *obj)
180 Smart_Data *sd = evas_object_smart_data_get(obj);
181 if (!sd) return NULL;
186 _els_smart_icon_size_get(const Evas_Object *obj, int *w, int *h)
193 sd = evas_object_smart_data_get(obj);
195 type = evas_object_type_get(sd->obj);
197 if (!strcmp(type, "edje"))
198 edje_object_size_min_get(sd->obj, &tw, &th);
200 evas_object_image_size_get(sd->obj, &tw, &th);
201 evas_object_geometry_get(sd->obj, NULL, NULL, &cw, &ch);
202 tw = tw > cw ? tw : cw;
203 th = th > ch ? th : ch;
204 tw = ((double)tw) * sd->scale;
205 th = ((double)th) * sd->scale;
211 _els_smart_icon_fill_inside_set(Evas_Object *obj, Eina_Bool fill_inside)
215 sd = evas_object_smart_data_get(obj);
217 if (((sd->fill_inside) && (fill_inside)) ||
218 ((!sd->fill_inside) && (!fill_inside))) return;
219 sd->fill_inside = fill_inside;
220 _smart_reconfigure(sd);
224 _els_smart_icon_fill_inside_get(const Evas_Object *obj)
226 Smart_Data *sd = evas_object_smart_data_get(obj);
227 if (!sd) return EINA_FALSE;
228 return sd->fill_inside;
232 _els_smart_icon_scale_up_set(Evas_Object *obj, Eina_Bool scale_up)
236 sd = evas_object_smart_data_get(obj);
238 if (((sd->scale_up) && (scale_up)) ||
239 ((!sd->scale_up) && (!scale_up))) return;
240 sd->scale_up = scale_up;
241 _smart_reconfigure(sd);
245 _els_smart_icon_scale_up_get(const Evas_Object *obj)
247 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
248 if (!sd) return EINA_FALSE;
253 _els_smart_icon_scale_down_set(Evas_Object *obj, Eina_Bool scale_down)
257 sd = evas_object_smart_data_get(obj);
259 if (((sd->scale_down) && (scale_down)) ||
260 ((!sd->scale_down) && (!scale_down))) return;
261 sd->scale_down = scale_down;
262 _smart_reconfigure(sd);
266 _els_smart_icon_scale_down_get(const Evas_Object *obj)
268 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
269 if (!sd) return EINA_FALSE;
274 _els_smart_icon_scale_size_set(Evas_Object *obj, int size)
278 sd = evas_object_smart_data_get(obj);
281 if (!sd->obj) return;
284 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
288 _els_smart_icon_scale_size_get(const Evas_Object *obj)
290 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
296 _els_smart_icon_scale_set(Evas_Object *obj, double scale)
298 Smart_Data *sd = evas_object_smart_data_get(obj);
301 _smart_reconfigure(sd);
305 _els_smart_icon_scale_get(const Evas_Object *obj)
307 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
313 _els_smart_icon_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
317 unsigned int *data, *data2, *to, *from;
318 int x, y, w, hw, iw, ih;
319 const char *file, *key;
321 sd = evas_object_smart_data_get(obj);
328 case ELM_IMAGE_FLIP_HORIZONTAL:
329 _els_smart_icon_flip_horizontal(sd);
331 case ELM_IMAGE_FLIP_VERTICAL:
332 _els_smart_icon_flip_vertical(sd);
334 case ELM_IMAGE_ROTATE_180_CW:
335 _els_smart_icon_rotate_180(sd);
341 evas_object_image_size_get(sd->obj, &iw, &ih);
342 evas_object_image_file_get(sd->obj, &file, &key);
343 tmp = evas_object_image_add(evas_object_evas_get(sd->obj));
344 evas_object_image_file_set(tmp, file, key);
345 data2 = evas_object_image_data_get(tmp, EINA_FALSE);
352 evas_object_image_size_set(sd->obj, iw, ih);
353 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
356 case ELM_IMAGE_FLIP_TRANSPOSE:
360 case ELM_IMAGE_FLIP_TRANSVERSE:
365 case ELM_IMAGE_ROTATE_90_CW:
369 case ELM_IMAGE_ROTATE_90_CCW:
375 ERR("unknown orient %d", orient);
376 evas_object_del(tmp);
377 evas_object_image_data_set(sd->obj, data); // give it back
381 for (x = iw; --x >= 0;)
383 for (y = ih; --y >= 0;)
392 evas_object_del(tmp);
393 evas_object_image_data_set(sd->obj, data);
394 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
395 _smart_reconfigure(sd);
399 _els_smart_icon_orient_get(const Evas_Object *obj)
401 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
407 * Turns on editing through drag and drop and copy and paste.
410 _els_smart_icon_edit_set(Evas_Object *obj, Eina_Bool edit, Evas_Object *parent)
412 Smart_Data *sd = evas_object_smart_data_get(obj);
417 printf("No editing edje objects yet (ever)\n");
421 /* Unfortunately eina bool is not a bool, but a char */
422 if (edit == sd->edit) return;
427 elm_drop_target_add(obj, ELM_SEL_FORMAT_IMAGE, _els_smart_icon_dropcb,
430 elm_drop_target_del(obj);
434 _els_smart_icon_edit_get(const Evas_Object *obj)
436 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
437 if (!sd) return EINA_FALSE;
442 _els_smart_icon_edje_get(Evas_Object *obj)
444 Smart_Data *sd = evas_object_smart_data_get(obj);
445 if (!sd) return NULL;
446 if (!sd->edje) return NULL;
451 _els_smart_icon_aspect_ratio_retained_set(Evas_Object *obj, Eina_Bool retained)
455 sd = evas_object_smart_data_get(obj);
458 retained = !!retained;
459 if (sd->aspect_ratio_retained == retained) return;
460 sd->aspect_ratio_retained = retained;
461 _smart_reconfigure(sd);
465 _els_smart_icon_aspect_ratio_retained_get(const Evas_Object *obj)
469 sd = evas_object_smart_data_get(obj);
470 if (!sd) return EINA_FALSE;
471 return sd->aspect_ratio_retained;
474 /* local subsystem globals */
476 _smart_reconfigure(Smart_Data *sd)
478 Evas_Coord x, y, w, h;
481 if (!sd->obj) return;
486 type = evas_object_type_get(sd->obj);
488 if (!strcmp(type, "edje"))
492 evas_object_move(sd->obj, x, y);
493 evas_object_resize(sd->obj, w, h);
499 evas_object_image_size_get(sd->obj, &iw, &ih);
501 iw = ((double)iw) * sd->scale;
502 ih = ((double)ih) * sd->scale;
507 if (sd->aspect_ratio_retained)
509 h = ((double)ih * w) / (double)iw;
515 w = ((double)iw * h) / (double)ih;
523 w = ((double)iw * h) / (double)ih;
537 x = sd->x + ((sd->w - w) / 2);
538 y = sd->y + ((sd->h - h) / 2);
539 evas_object_move(sd->obj, x, y);
540 evas_object_image_fill_set(sd->obj, 0, 0, w, h);
541 evas_object_resize(sd->obj, w, h);
548 if (_e_smart) return;
550 static const Evas_Smart_Class sc =
553 EVAS_SMART_CLASS_VERSION,
571 _e_smart = evas_smart_class_new(&sc);
576 _smart_add(Evas_Object *obj)
580 sd = calloc(1, sizeof(Smart_Data));
582 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
584 evas_object_image_scale_hint_set(sd->obj, EVAS_IMAGE_SCALE_HINT_STATIC);
589 sd->fill_inside = EINA_TRUE;
590 sd->scale_up = EINA_TRUE;
591 sd->scale_down = EINA_TRUE;
592 sd->aspect_ratio_retained = EINA_TRUE;
595 evas_object_smart_member_add(sd->obj, obj);
596 evas_object_smart_data_set(obj, sd);
597 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED,
602 _smart_del(Evas_Object *obj)
606 sd = evas_object_smart_data_get(obj);
608 evas_object_del(sd->obj);
609 if (sd->prev) evas_object_del(sd->prev);
614 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
618 sd = evas_object_smart_data_get(obj);
620 if ((sd->x == x) && (sd->y == y)) return;
623 _smart_reconfigure(sd);
627 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
631 sd = evas_object_smart_data_get(obj);
633 if ((sd->w == w) && (sd->h == h)) return;
636 _smart_reconfigure(sd);
640 _smart_show(Evas_Object *obj)
644 sd = evas_object_smart_data_get(obj);
646 sd->show = EINA_TRUE;
649 evas_object_show(sd->obj);
650 if (sd->prev) evas_object_del(sd->prev);
656 _smart_hide(Evas_Object *obj)
660 sd = evas_object_smart_data_get(obj);
662 sd->show = EINA_FALSE;
663 evas_object_hide(sd->obj);
664 if (sd->prev) evas_object_del(sd->prev);
669 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
673 sd = evas_object_smart_data_get(obj);
675 evas_object_color_set(sd->obj, r, g, b, a);
676 if (sd->prev) evas_object_color_set(sd->prev, r, g, b, a);
680 _smart_clip_set(Evas_Object *obj, Evas_Object * clip)
684 sd = evas_object_smart_data_get(obj);
686 evas_object_clip_set(sd->obj, clip);
687 if (sd->prev) evas_object_clip_set(sd->prev, clip);
691 _smart_clip_unset(Evas_Object *obj)
695 sd = evas_object_smart_data_get(obj);
697 evas_object_clip_unset(sd->obj);
698 if (sd->prev) evas_object_clip_unset(sd->prev);
702 _els_smart_icon_flip_horizontal(Smart_Data *sd)
705 unsigned int *p1, *p2, tmp;
708 evas_object_image_size_get(sd->obj, &iw, &ih);
709 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
711 for (y = 0; y < ih; y++)
713 p1 = data + (y * iw);
714 p2 = data + ((y + 1) * iw) - 1;
715 for (x = 0; x < (iw >> 1); x++)
725 evas_object_image_data_set(sd->obj, data);
726 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
727 _smart_reconfigure(sd);
731 _els_smart_icon_flip_vertical(Smart_Data *sd)
734 unsigned int *p1, *p2, tmp;
737 evas_object_image_size_get(sd->obj, &iw, &ih);
738 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
740 for (y = 0; y < (ih >> 1); y++)
742 p1 = data + (y * iw);
743 p2 = data + ((ih - 1 - y) * iw);
744 for (x = 0; x < iw; x++)
754 evas_object_image_data_set(sd->obj, data);
755 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
756 _smart_reconfigure(sd);
760 _els_smart_icon_rotate_180(Smart_Data *sd)
763 unsigned int *p1, *p2, tmp;
766 evas_object_image_size_get(sd->obj, &iw, &ih);
767 data = evas_object_image_data_get(sd->obj, 1);
781 evas_object_image_data_set(sd->obj, data);
782 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
783 _smart_reconfigure(sd);
787 _els_smart_icon_dropcb(void *elmobj,Evas_Object *obj, Elm_Selection_Data *drop)
789 _els_smart_icon_file_key_set(obj, drop->data, NULL);
790 evas_object_smart_callback_call(elmobj, "drop", drop->data);
794 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 :*/