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)
192 sd = evas_object_smart_data_get(obj);
194 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
195 edje_object_size_min_get(sd->obj, &tw, &th);
197 evas_object_image_size_get(sd->obj, &tw, &th);
198 evas_object_geometry_get(sd->obj, NULL, NULL, &cw, &ch);
199 tw = tw > cw ? tw : cw;
200 th = th > ch ? th : ch;
201 tw = ((double)tw) * sd->scale;
202 th = ((double)th) * sd->scale;
208 _els_smart_icon_fill_inside_set(Evas_Object *obj, Eina_Bool fill_inside)
212 sd = evas_object_smart_data_get(obj);
214 if (((sd->fill_inside) && (fill_inside)) ||
215 ((!sd->fill_inside) && (!fill_inside))) return;
216 sd->fill_inside = fill_inside;
217 _smart_reconfigure(sd);
221 _els_smart_icon_fill_inside_get(const Evas_Object *obj)
223 Smart_Data *sd = evas_object_smart_data_get(obj);
224 if (!sd) return EINA_FALSE;
225 return sd->fill_inside;
229 _els_smart_icon_scale_up_set(Evas_Object *obj, Eina_Bool scale_up)
233 sd = evas_object_smart_data_get(obj);
235 if (((sd->scale_up) && (scale_up)) ||
236 ((!sd->scale_up) && (!scale_up))) return;
237 sd->scale_up = scale_up;
238 _smart_reconfigure(sd);
242 _els_smart_icon_scale_up_get(const Evas_Object *obj)
244 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
245 if (!sd) return EINA_FALSE;
250 _els_smart_icon_scale_down_set(Evas_Object *obj, Eina_Bool scale_down)
254 sd = evas_object_smart_data_get(obj);
256 if (((sd->scale_down) && (scale_down)) ||
257 ((!sd->scale_down) && (!scale_down))) return;
258 sd->scale_down = scale_down;
259 _smart_reconfigure(sd);
263 _els_smart_icon_scale_down_get(const Evas_Object *obj)
265 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
266 if (!sd) return EINA_FALSE;
271 _els_smart_icon_scale_size_set(Evas_Object *obj, int size)
275 sd = evas_object_smart_data_get(obj);
278 if (!sd->obj) return;
281 evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
285 _els_smart_icon_scale_size_get(const Evas_Object *obj)
287 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
293 _els_smart_icon_scale_set(Evas_Object *obj, double scale)
295 Smart_Data *sd = evas_object_smart_data_get(obj);
298 _smart_reconfigure(sd);
302 _els_smart_icon_scale_get(const Evas_Object *obj)
304 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
310 _els_smart_icon_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
314 unsigned int *data, *data2, *to, *from;
315 int x, y, w, hw, iw, ih;
316 const char *file, *key;
318 sd = evas_object_smart_data_get(obj);
325 case ELM_IMAGE_FLIP_HORIZONTAL:
326 _els_smart_icon_flip_horizontal(sd);
328 case ELM_IMAGE_FLIP_VERTICAL:
329 _els_smart_icon_flip_vertical(sd);
331 case ELM_IMAGE_ROTATE_180_CW:
332 _els_smart_icon_rotate_180(sd);
338 evas_object_image_size_get(sd->obj, &iw, &ih);
339 evas_object_image_file_get(sd->obj, &file, &key);
340 tmp = evas_object_image_add(evas_object_evas_get(sd->obj));
341 evas_object_image_file_set(tmp, file, key);
342 data2 = evas_object_image_data_get(tmp, EINA_FALSE);
349 evas_object_image_size_set(sd->obj, iw, ih);
350 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
353 case ELM_IMAGE_FLIP_TRANSPOSE:
357 case ELM_IMAGE_FLIP_TRANSVERSE:
362 case ELM_IMAGE_ROTATE_90_CW:
366 case ELM_IMAGE_ROTATE_90_CCW:
372 ERR("unknown orient %d", orient);
373 evas_object_del(tmp);
374 evas_object_image_data_set(sd->obj, data); // give it back
378 for (x = iw; --x >= 0;)
380 for (y = ih; --y >= 0;)
389 evas_object_del(tmp);
390 evas_object_image_data_set(sd->obj, data);
391 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
392 _smart_reconfigure(sd);
396 _els_smart_icon_orient_get(const Evas_Object *obj)
398 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
404 * Turns on editing through drag and drop and copy and paste.
407 _els_smart_icon_edit_set(Evas_Object *obj, Eina_Bool edit, Evas_Object *parent)
409 Smart_Data *sd = evas_object_smart_data_get(obj);
414 printf("No editing edje objects yet (ever)\n");
418 /* Unfortunately eina bool is not a bool, but a char */
419 if (edit == sd->edit) return;
424 elm_drop_target_add(obj, ELM_SEL_FORMAT_IMAGE, _els_smart_icon_dropcb,
427 elm_drop_target_del(obj);
431 _els_smart_icon_edit_get(const Evas_Object *obj)
433 Smart_Data *sd; sd = evas_object_smart_data_get(obj);
434 if (!sd) return EINA_FALSE;
439 _els_smart_icon_edje_get(Evas_Object *obj)
441 Smart_Data *sd = evas_object_smart_data_get(obj);
442 if (!sd) return NULL;
443 if (!sd->edje) return NULL;
448 _els_smart_icon_aspect_ratio_retained_set(Evas_Object *obj, Eina_Bool retained)
452 sd = evas_object_smart_data_get(obj);
455 retained = !!retained;
456 if (sd->aspect_ratio_retained == retained) return;
457 sd->aspect_ratio_retained = retained;
458 _smart_reconfigure(sd);
462 _els_smart_icon_aspect_ratio_retained_get(const Evas_Object *obj)
466 sd = evas_object_smart_data_get(obj);
467 if (!sd) return EINA_FALSE;
468 return sd->aspect_ratio_retained;
471 /* local subsystem globals */
473 _smart_reconfigure(Smart_Data *sd)
475 Evas_Coord x, y, w, h;
477 if (!sd->obj) return;
482 if (!strcmp(evas_object_type_get(sd->obj), "edje"))
486 evas_object_move(sd->obj, x, y);
487 evas_object_resize(sd->obj, w, h);
493 evas_object_image_size_get(sd->obj, &iw, &ih);
495 iw = ((double)iw) * sd->scale;
496 ih = ((double)ih) * sd->scale;
501 if (sd->aspect_ratio_retained)
503 h = ((double)ih * w) / (double)iw;
509 w = ((double)iw * h) / (double)ih;
517 w = ((double)iw * h) / (double)ih;
531 x = sd->x + ((sd->w - w) / 2);
532 y = sd->y + ((sd->h - h) / 2);
533 evas_object_move(sd->obj, x, y);
534 evas_object_image_fill_set(sd->obj, 0, 0, w, h);
535 evas_object_resize(sd->obj, w, h);
542 if (_e_smart) return;
544 static const Evas_Smart_Class sc =
547 EVAS_SMART_CLASS_VERSION,
565 _e_smart = evas_smart_class_new(&sc);
570 _smart_add(Evas_Object *obj)
574 sd = calloc(1, sizeof(Smart_Data));
576 sd->obj = evas_object_image_add(evas_object_evas_get(obj));
578 evas_object_image_scale_hint_set(sd->obj, EVAS_IMAGE_SCALE_HINT_STATIC);
583 sd->fill_inside = EINA_TRUE;
584 sd->scale_up = EINA_TRUE;
585 sd->scale_down = EINA_TRUE;
586 sd->aspect_ratio_retained = EINA_TRUE;
589 evas_object_smart_member_add(sd->obj, obj);
590 evas_object_smart_data_set(obj, sd);
591 evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED,
596 _smart_del(Evas_Object *obj)
600 sd = evas_object_smart_data_get(obj);
602 evas_object_del(sd->obj);
603 if (sd->prev) evas_object_del(sd->prev);
608 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
612 sd = evas_object_smart_data_get(obj);
614 if ((sd->x == x) && (sd->y == y)) return;
617 _smart_reconfigure(sd);
621 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
625 sd = evas_object_smart_data_get(obj);
627 if ((sd->w == w) && (sd->h == h)) return;
630 _smart_reconfigure(sd);
634 _smart_show(Evas_Object *obj)
638 sd = evas_object_smart_data_get(obj);
640 sd->show = EINA_TRUE;
643 evas_object_show(sd->obj);
644 if (sd->prev) evas_object_del(sd->prev);
650 _smart_hide(Evas_Object *obj)
654 sd = evas_object_smart_data_get(obj);
656 sd->show = EINA_FALSE;
657 evas_object_hide(sd->obj);
658 if (sd->prev) evas_object_del(sd->prev);
663 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
667 sd = evas_object_smart_data_get(obj);
669 evas_object_color_set(sd->obj, r, g, b, a);
670 if (sd->prev) evas_object_color_set(sd->prev, r, g, b, a);
674 _smart_clip_set(Evas_Object *obj, Evas_Object * clip)
678 sd = evas_object_smart_data_get(obj);
680 evas_object_clip_set(sd->obj, clip);
681 if (sd->prev) evas_object_clip_set(sd->prev, clip);
685 _smart_clip_unset(Evas_Object *obj)
689 sd = evas_object_smart_data_get(obj);
691 evas_object_clip_unset(sd->obj);
692 if (sd->prev) evas_object_clip_unset(sd->prev);
696 _els_smart_icon_flip_horizontal(Smart_Data *sd)
699 unsigned int *p1, *p2, tmp;
702 evas_object_image_size_get(sd->obj, &iw, &ih);
703 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
705 for (y = 0; y < ih; y++)
707 p1 = data + (y * iw);
708 p2 = data + ((y + 1) * iw) - 1;
709 for (x = 0; x < (iw >> 1); x++)
719 evas_object_image_data_set(sd->obj, data);
720 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
721 _smart_reconfigure(sd);
725 _els_smart_icon_flip_vertical(Smart_Data *sd)
728 unsigned int *p1, *p2, tmp;
731 evas_object_image_size_get(sd->obj, &iw, &ih);
732 data = evas_object_image_data_get(sd->obj, EINA_TRUE);
734 for (y = 0; y < (ih >> 1); y++)
736 p1 = data + (y * iw);
737 p2 = data + ((ih - 1 - y) * iw);
738 for (x = 0; x < iw; x++)
748 evas_object_image_data_set(sd->obj, data);
749 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
750 _smart_reconfigure(sd);
754 _els_smart_icon_rotate_180(Smart_Data *sd)
757 unsigned int *p1, *p2, tmp;
760 evas_object_image_size_get(sd->obj, &iw, &ih);
761 data = evas_object_image_data_get(sd->obj, 1);
775 evas_object_image_data_set(sd->obj, data);
776 evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
777 _smart_reconfigure(sd);
781 _els_smart_icon_dropcb(void *elmobj,Evas_Object *obj, Elm_Selection_Data *drop)
783 _els_smart_icon_file_key_set(obj, drop->data, NULL);
784 evas_object_smart_callback_call(elmobj, "drop", drop->data);
788 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 :*/