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_file_edje_set(Evas_Object *obj, const char *file, const char *part)
125 sd = evas_object_smart_data_get(obj);
126 if (!sd) return EINA_FALSE;
127 /* smart code here */
128 if (sd->prev) evas_object_del(sd->prev);
133 pclip = evas_object_clip_get(sd->obj);
134 if (sd->obj) evas_object_del(sd->obj);
135 sd->obj = edje_object_add(evas_object_evas_get(obj));
136 evas_object_smart_member_add(sd->obj, obj);
137 if (sd->show) evas_object_show(sd->obj);
138 evas_object_clip_set(sd->obj, pclip);
140 sd->edje = EINA_TRUE;
141 if (!edje_object_file_set(sd->obj, file, part))
143 _smart_reconfigure(sd);
148 _els_smart_icon_file_get(const Evas_Object *obj, const char **file, const char **key)
150 Smart_Data *sd = evas_object_smart_data_get(obj);
153 edje_object_file_get(sd->obj, file, key);
155 evas_object_image_file_get(sd->obj, file, key);
159 _els_smart_icon_smooth_scale_set(Evas_Object *obj, Eina_Bool smooth)
161 Smart_Data *sd = evas_object_smart_data_get(obj);
165 evas_object_image_smooth_scale_set(sd->obj, smooth);
169 _els_smart_icon_smooth_scale_get(const Evas_Object *obj)
171 Smart_Data *sd = evas_object_smart_data_get(obj);
172 if (!sd) return EINA_FALSE;
175 return evas_object_image_smooth_scale_get(sd->obj);
179 _els_smart_icon_object_get(const Evas_Object *obj)
181 Smart_Data *sd = evas_object_smart_data_get(obj);
182 if (!sd) return NULL;
187 _els_smart_icon_size_get(const Evas_Object *obj, int *w, int *h)
194 sd = evas_object_smart_data_get(obj);
196 type = evas_object_type_get(sd->obj);
198 if (!strcmp(type, "edje"))
199 edje_object_size_min_get(sd->obj, &tw, &th);
201 evas_object_image_size_get(sd->obj, &tw, &th);
202 evas_object_geometry_get(sd->obj, NULL, NULL, &cw, &ch);
203 tw = tw > cw ? tw : cw;
204 th = th > ch ? th : ch;
205 tw = ((double)tw) * sd->scale;
206 th = ((double)th) * sd->scale;
212 _els_smart_icon_fill_inside_set(Evas_Object *obj, Eina_Bool fill_inside)
216 sd = evas_object_smart_data_get(obj);
218 if (((sd->fill_inside) && (fill_inside)) ||
219 ((!sd->fill_inside) && (!fill_inside))) return;
220 sd->fill_inside = fill_inside;
221 _smart_reconfigure(sd);
225 _els_smart_icon_fill_inside_get(const Evas_Object *obj)
227 Smart_Data *sd = evas_object_smart_data_get(obj);
228 if (!sd) return EINA_FALSE;
229 return sd->fill_inside;
233 _els_smart_icon_scale_up_set(Evas_Object *obj, Eina_Bool scale_up)
237 sd = evas_object_smart_data_get(obj);
239 if (((sd->scale_up) && (scale_up)) ||
240 ((!sd->scale_up) && (!scale_up))) return;
241 sd->scale_up = scale_up;
242 _smart_reconfigure(sd);
246 _els_smart_icon_scale_up_get(const Evas_Object *obj)
248 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
249 if (!sd) return EINA_FALSE;
254 _els_smart_icon_scale_down_set(Evas_Object *obj, Eina_Bool scale_down)
258 sd = evas_object_smart_data_get(obj);
260 if (((sd->scale_down) && (scale_down)) ||
261 ((!sd->scale_down) && (!scale_down))) return;
262 sd->scale_down = scale_down;
263 _smart_reconfigure(sd);
267 _els_smart_icon_scale_down_get(const Evas_Object *obj)
269 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
270 if (!sd) return EINA_FALSE;
275 _els_smart_icon_scale_size_set(Evas_Object *obj, int size)
279 sd = evas_object_smart_data_get(obj);
282 if (!sd->obj) return;
285 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
289 _els_smart_icon_scale_size_get(const Evas_Object *obj)
291 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
297 _els_smart_icon_scale_set(Evas_Object *obj, double scale)
299 Smart_Data *sd = evas_object_smart_data_get(obj);
302 _smart_reconfigure(sd);
306 _els_smart_icon_scale_get(const Evas_Object *obj)
308 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
314 _els_smart_icon_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
318 unsigned int *data, *data2, *to, *from;
319 int x, y, w, hw, iw, ih;
320 const char *file, *key;
322 sd = evas_object_smart_data_get(obj);
329 case ELM_IMAGE_FLIP_HORIZONTAL:
330 _els_smart_icon_flip_horizontal(sd);
332 case ELM_IMAGE_FLIP_VERTICAL:
333 _els_smart_icon_flip_vertical(sd);
335 case ELM_IMAGE_ROTATE_180_CW:
336 _els_smart_icon_rotate_180(sd);
342 evas_object_image_size_get(sd->obj, &iw, &ih);
343 evas_object_image_file_get(sd->obj, &file, &key);
344 tmp = evas_object_image_add(evas_object_evas_get(sd->obj));
345 evas_object_image_file_set(tmp, file, key);
346 data2 = evas_object_image_data_get(tmp, EINA_FALSE);
353 evas_object_image_size_set(sd->obj, iw, ih);
354 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
357 case ELM_IMAGE_FLIP_TRANSPOSE:
361 case ELM_IMAGE_FLIP_TRANSVERSE:
366 case ELM_IMAGE_ROTATE_90_CW:
370 case ELM_IMAGE_ROTATE_90_CCW:
376 ERR("unknown orient %d", orient);
377 evas_object_del(tmp);
378 evas_object_image_data_set(sd->obj, data); // give it back
382 for (x = iw; --x >= 0;)
384 for (y = ih; --y >= 0;)
393 evas_object_del(tmp);
394 evas_object_image_data_set(sd->obj, data);
395 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
396 _smart_reconfigure(sd);
400 _els_smart_icon_orient_get(const Evas_Object *obj)
402 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
408 * Turns on editing through drag and drop and copy and paste.
411 _els_smart_icon_edit_set(Evas_Object *obj, Eina_Bool edit, Evas_Object *parent)
413 Smart_Data *sd = evas_object_smart_data_get(obj);
418 printf("No editing edje objects yet (ever)\n");
422 /* Unfortunately eina bool is not a bool, but a char */
423 if (edit == sd->edit) return;
428 elm_drop_target_add(obj, ELM_SEL_FORMAT_IMAGE, _els_smart_icon_dropcb,
431 elm_drop_target_del(obj);
435 _els_smart_icon_edit_get(const Evas_Object *obj)
437 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
438 if (!sd) return EINA_FALSE;
443 _els_smart_icon_edje_get(Evas_Object *obj)
445 Smart_Data *sd = evas_object_smart_data_get(obj);
446 if (!sd) return NULL;
447 if (!sd->edje) return NULL;
452 _els_smart_icon_aspect_ratio_retained_set(Evas_Object *obj, Eina_Bool retained)
456 sd = evas_object_smart_data_get(obj);
459 retained = !!retained;
460 if (sd->aspect_ratio_retained == retained) return;
461 sd->aspect_ratio_retained = retained;
462 _smart_reconfigure(sd);
466 _els_smart_icon_aspect_ratio_retained_get(const Evas_Object *obj)
470 sd = evas_object_smart_data_get(obj);
471 if (!sd) return EINA_FALSE;
472 return sd->aspect_ratio_retained;
475 /* local subsystem globals */
477 _smart_reconfigure(Smart_Data *sd)
479 Evas_Coord x, y, w, h;
482 if (!sd->obj) return;
487 type = evas_object_type_get(sd->obj);
489 if (!strcmp(type, "edje"))
493 evas_object_move(sd->obj, x, y);
494 evas_object_resize(sd->obj, w, h);
500 evas_object_image_size_get(sd->obj, &iw, &ih);
502 iw = ((double)iw) * sd->scale;
503 ih = ((double)ih) * sd->scale;
508 if (sd->aspect_ratio_retained)
510 h = ((double)ih * w) / (double)iw;
516 w = ((double)iw * h) / (double)ih;
524 w = ((double)iw * h) / (double)ih;
538 x = sd->x + ((sd->w - w) / 2);
539 y = sd->y + ((sd->h - h) / 2);
540 evas_object_move(sd->obj, x, y);
541 evas_object_image_fill_set(sd->obj, 0, 0, w, h);
542 evas_object_resize(sd->obj, w, h);
549 if (_e_smart) return;
551 static const Evas_Smart_Class sc =
554 EVAS_SMART_CLASS_VERSION,
572 _e_smart = evas_smart_class_new(&sc);
577 _smart_add(Evas_Object *obj)
581 sd = calloc(1, sizeof(Smart_Data));
583 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
585 evas_object_image_scale_hint_set(sd->obj, EVAS_IMAGE_SCALE_HINT_STATIC);
590 sd->fill_inside = EINA_TRUE;
591 sd->scale_up = EINA_TRUE;
592 sd->scale_down = EINA_TRUE;
593 sd->aspect_ratio_retained = EINA_TRUE;
596 evas_object_smart_member_add(sd->obj, obj);
597 evas_object_smart_data_set(obj, sd);
598 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED,
603 _smart_del(Evas_Object *obj)
607 sd = evas_object_smart_data_get(obj);
609 evas_object_del(sd->obj);
610 if (sd->prev) evas_object_del(sd->prev);
615 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
619 sd = evas_object_smart_data_get(obj);
621 if ((sd->x == x) && (sd->y == y)) return;
624 _smart_reconfigure(sd);
628 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
632 sd = evas_object_smart_data_get(obj);
634 if ((sd->w == w) && (sd->h == h)) return;
637 _smart_reconfigure(sd);
641 _smart_show(Evas_Object *obj)
645 sd = evas_object_smart_data_get(obj);
647 sd->show = EINA_TRUE;
650 evas_object_show(sd->obj);
651 if (sd->prev) evas_object_del(sd->prev);
657 _smart_hide(Evas_Object *obj)
661 sd = evas_object_smart_data_get(obj);
663 sd->show = EINA_FALSE;
664 evas_object_hide(sd->obj);
665 if (sd->prev) evas_object_del(sd->prev);
670 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
674 sd = evas_object_smart_data_get(obj);
676 evas_object_color_set(sd->obj, r, g, b, a);
677 if (sd->prev) evas_object_color_set(sd->prev, r, g, b, a);
681 _smart_clip_set(Evas_Object *obj, Evas_Object * clip)
685 sd = evas_object_smart_data_get(obj);
687 evas_object_clip_set(sd->obj, clip);
688 if (sd->prev) evas_object_clip_set(sd->prev, clip);
692 _smart_clip_unset(Evas_Object *obj)
696 sd = evas_object_smart_data_get(obj);
698 evas_object_clip_unset(sd->obj);
699 if (sd->prev) evas_object_clip_unset(sd->prev);
703 _els_smart_icon_flip_horizontal(Smart_Data *sd)
706 unsigned int *p1, *p2, tmp;
709 evas_object_image_size_get(sd->obj, &iw, &ih);
710 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
712 for (y = 0; y < ih; y++)
714 p1 = data + (y * iw);
715 p2 = data + ((y + 1) * iw) - 1;
716 for (x = 0; x < (iw >> 1); x++)
726 evas_object_image_data_set(sd->obj, data);
727 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
728 _smart_reconfigure(sd);
732 _els_smart_icon_flip_vertical(Smart_Data *sd)
735 unsigned int *p1, *p2, tmp;
738 evas_object_image_size_get(sd->obj, &iw, &ih);
739 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
741 for (y = 0; y < (ih >> 1); y++)
743 p1 = data + (y * iw);
744 p2 = data + ((ih - 1 - y) * iw);
745 for (x = 0; x < iw; x++)
755 evas_object_image_data_set(sd->obj, data);
756 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
757 _smart_reconfigure(sd);
761 _els_smart_icon_rotate_180(Smart_Data *sd)
764 unsigned int *p1, *p2, tmp;
767 evas_object_image_size_get(sd->obj, &iw, &ih);
768 data = evas_object_image_data_get(sd->obj, 1);
782 evas_object_image_data_set(sd->obj, data);
783 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
784 _smart_reconfigure(sd);
788 _els_smart_icon_dropcb(void *elmobj,Evas_Object *obj, Elm_Selection_Data *drop)
790 _els_smart_icon_file_key_set(obj, drop->data, NULL);
791 evas_object_smart_callback_call(elmobj, "drop", drop->data);
795 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 :*/