aspect_ratio_retained -> aspect_fixed
[framework/uifw/elementary.git] / src / lib / els_icon.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3 #include "els_icon.h"
4
5 #ifdef _WIN32
6 # define FMT_SIZE_T "%Iu"
7 #else
8 # define FMT_SIZE_T "%zu"
9 #endif
10
11 typedef struct _Smart_Data Smart_Data;
12
13 struct _Smart_Data
14 {
15    Evas_Coord   x, y, w, h;
16    Evas_Object *obj;
17    Evas_Object *prev;
18    int          size;
19    double       scale;
20    Eina_Bool fill_inside : 1;
21    Eina_Bool scale_up : 1;
22    Eina_Bool scale_down : 1;
23    Eina_Bool preloading : 1;
24    Eina_Bool show : 1;
25    Eina_Bool edit : 1;
26    Eina_Bool edje : 1;
27    Eina_Bool aspect_fixed: 1;
28    Elm_Image_Orient orient;
29 };
30
31 /* local subsystem functions */
32 static void _smart_reconfigure(Smart_Data *sd);
33 static void _smart_init(void);
34 static void _smart_add(Evas_Object *obj);
35 static void _smart_del(Evas_Object *obj);
36 static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
37 static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
38 static void _smart_show(Evas_Object *obj);
39 static void _smart_hide(Evas_Object *obj);
40 static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
41 static void _smart_clip_set(Evas_Object *obj, Evas_Object * clip);
42 static void _smart_clip_unset(Evas_Object *obj);
43
44 static void _els_smart_icon_flip_horizontal(Smart_Data *sd);
45 static void _els_smart_icon_flip_vertical(Smart_Data *sd);
46 static void _els_smart_icon_rotate_180(Smart_Data *sd);
47 static Eina_Bool _els_smart_icon_dropcb(void *,Evas_Object *, Elm_Selection_Data *);
48
49 /* local subsystem globals */
50 static Evas_Smart *_e_smart = NULL;
51
52 /* externally accessible functions */
53 Evas_Object *
54 _els_smart_icon_add(Evas *evas)
55 {
56    _smart_init();
57    return evas_object_smart_add(evas, _e_smart);
58 }
59
60 static void
61 _preloaded(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event __UNUSED__)
62 {
63    Smart_Data *sd = data;
64
65    sd->preloading = EINA_FALSE;
66    if (obj == sd->obj)
67      {
68         if (sd->show)
69           evas_object_show(sd->obj);
70      }
71    if (sd->prev) evas_object_del(sd->prev);
72    sd->prev = NULL;
73 }
74
75 static void
76 _els_smart_icon_file_helper(Evas_Object *obj)
77 {
78    Smart_Data *sd;
79    Evas_Object *pclip;
80
81    sd = evas_object_smart_data_get(obj);
82    /* smart code here */
83    if (sd->prev) evas_object_del(sd->prev);
84    pclip = evas_object_clip_get(sd->obj);
85    if (sd->obj) sd->prev = sd->obj;
86    sd->obj = evas_object_image_add(evas_object_evas_get(obj));
87    evas_object_image_load_orientation_set(sd->obj, EINA_TRUE);
88    evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED,
89                                   _preloaded, sd);
90    evas_object_smart_member_add(sd->obj, obj);
91    if (sd->prev) evas_object_smart_member_add(sd->prev, obj);
92    evas_object_image_scale_hint_set(sd->obj, EVAS_IMAGE_SCALE_HINT_STATIC);
93    evas_object_clip_set(sd->obj, pclip);
94
95    sd->edje = EINA_FALSE;
96
97    if (!sd->size)
98      evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
99 }
100
101 Eina_Bool
102 _els_smart_icon_memfile_set(Evas_Object *obj, const void *img, size_t size, const char *format, const char *key)
103 {
104    Smart_Data *sd;
105
106    sd = evas_object_smart_data_get(obj);
107    if (!sd) return EINA_FALSE;
108    _els_smart_icon_file_helper(obj);
109
110    evas_object_image_memfile_set(sd->obj, (void*)img, size, (char*)format, (char*)key);
111    sd->preloading = EINA_TRUE;
112    sd->show = EINA_TRUE;
113    evas_object_hide(sd->obj);
114    evas_object_image_preload(sd->obj, EINA_FALSE);
115    if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
116      {
117         ERR("Things are going bad for some random " FMT_SIZE_T " byte chunk of memory (%p)", size, sd->obj);
118         return EINA_FALSE;
119      }
120    _smart_reconfigure(sd);
121    return EINA_TRUE;
122 }
123
124 Eina_Bool
125 _els_smart_icon_file_key_set(Evas_Object *obj, const char *file, const char *key)
126 {
127    Smart_Data *sd;
128    Evas_Coord w, h;
129
130    sd = evas_object_smart_data_get(obj);
131    if (!sd) return EINA_FALSE;
132    _els_smart_icon_file_helper(obj);
133
134    evas_object_image_file_set(sd->obj, file, key);
135    sd->preloading = EINA_TRUE;
136    sd->show = EINA_TRUE;
137    evas_object_hide(sd->obj);
138    _els_smart_icon_size_get(obj, &w, &h);
139    evas_object_image_load_size_set(sd->obj, w, h);
140    evas_object_image_preload(sd->obj, EINA_FALSE);
141    if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
142      {
143         ERR("Things are going bad for '%s' (%p)", file, sd->obj);
144         return EINA_FALSE;
145      }
146    _smart_reconfigure(sd);
147    return EINA_TRUE;
148 }
149
150 void
151 _els_smart_icon_preload_set(Evas_Object *obj, Eina_Bool disable)
152 {
153    Smart_Data *sd;
154
155    sd = evas_object_smart_data_get(obj);
156    if ((!sd) || sd->edje) return;
157    evas_object_image_preload(sd->obj, disable);
158    sd->preloading = !disable;
159 }
160
161 Eina_Bool
162 _els_smart_icon_file_edje_set(Evas_Object *obj, const char *file, const char *part)
163 {
164    Smart_Data *sd;
165    Evas_Object *pclip;
166
167    sd = evas_object_smart_data_get(obj);
168    if (!sd) return EINA_FALSE;
169    /* smart code here */
170    if (sd->prev) evas_object_del(sd->prev);
171    sd->prev = NULL;
172
173    if (!sd->edje)
174      {
175         pclip = evas_object_clip_get(sd->obj);
176         if (sd->obj) evas_object_del(sd->obj);
177         sd->obj = edje_object_add(evas_object_evas_get(obj));
178         evas_object_smart_member_add(sd->obj, obj);
179         if (sd->show) evas_object_show(sd->obj);
180         evas_object_clip_set(sd->obj, pclip);
181      }
182    sd->edje = EINA_TRUE;
183    if (!edje_object_file_set(sd->obj, file, part))
184      return EINA_FALSE;
185    _smart_reconfigure(sd);
186    return EINA_TRUE;
187 }
188
189 void
190 _els_smart_icon_file_get(const Evas_Object *obj, const char **file, const char **key)
191 {
192    Smart_Data *sd = evas_object_smart_data_get(obj);
193    if (!sd) return;
194    if (sd->edje)
195      edje_object_file_get(sd->obj, file, key);
196    else
197      evas_object_image_file_get(sd->obj, file, key);
198 }
199
200 void
201 _els_smart_icon_smooth_scale_set(Evas_Object *obj, Eina_Bool smooth)
202 {
203    Smart_Data *sd = evas_object_smart_data_get(obj);
204    if (!sd) return;
205    if (sd->edje)
206      return;
207    evas_object_image_smooth_scale_set(sd->obj, smooth);
208 }
209
210 Eina_Bool
211 _els_smart_icon_smooth_scale_get(const Evas_Object *obj)
212 {
213    Smart_Data *sd = evas_object_smart_data_get(obj);
214    if (!sd) return EINA_FALSE;
215    if (sd->edje)
216      return EINA_FALSE;
217    return evas_object_image_smooth_scale_get(sd->obj);
218 }
219
220 Evas_Object *
221 _els_smart_icon_object_get(const Evas_Object *obj)
222 {
223    Smart_Data *sd = evas_object_smart_data_get(obj);
224    if (!sd) return NULL;
225    return sd->obj;
226 }
227
228 void
229 _els_smart_icon_size_get(const Evas_Object *obj, int *w, int *h)
230 {
231    Smart_Data *sd;
232    int tw, th;
233    int cw, ch;
234    const char *type;
235
236    sd = evas_object_smart_data_get(obj);
237    if (!sd) return;
238    type = evas_object_type_get(sd->obj);
239    if (!type) return;
240    if (!strcmp(type, "edje"))
241      edje_object_size_min_get(sd->obj, &tw, &th);
242    else
243      evas_object_image_size_get(sd->obj, &tw, &th);
244    evas_object_geometry_get(sd->obj, NULL, NULL, &cw, &ch);
245    tw = tw > cw ? tw : cw;
246    th = th > ch ? th : ch;
247    tw = ((double)tw) * sd->scale;
248    th = ((double)th) * sd->scale;
249    if (w) *w = tw;
250    if (h) *h = th;
251 }
252
253 void
254 _els_smart_icon_fill_inside_set(Evas_Object *obj, Eina_Bool fill_inside)
255 {
256    Smart_Data *sd;
257
258    sd = evas_object_smart_data_get(obj);
259    if (!sd) return;
260    if (((sd->fill_inside) && (fill_inside)) ||
261        ((!sd->fill_inside) && (!fill_inside))) return;
262    sd->fill_inside = fill_inside;
263    _smart_reconfigure(sd);
264 }
265
266 Eina_Bool
267 _els_smart_icon_fill_inside_get(const Evas_Object *obj)
268 {
269    Smart_Data *sd = evas_object_smart_data_get(obj);
270    if (!sd) return EINA_FALSE;
271    return sd->fill_inside;
272 }
273
274 void
275 _els_smart_icon_scale_up_set(Evas_Object *obj, Eina_Bool scale_up)
276 {
277    Smart_Data *sd;
278
279    sd = evas_object_smart_data_get(obj);
280    if (!sd) return;
281    if (((sd->scale_up) && (scale_up)) ||
282        ((!sd->scale_up) && (!scale_up))) return;
283    sd->scale_up = scale_up;
284    _smart_reconfigure(sd);
285 }
286
287 Eina_Bool
288 _els_smart_icon_scale_up_get(const Evas_Object *obj)
289 {
290    Smart_Data *sd; sd = evas_object_smart_data_get(obj);
291    if (!sd) return EINA_FALSE;
292    return sd->scale_up;
293 }
294
295 void
296 _els_smart_icon_scale_down_set(Evas_Object *obj, Eina_Bool scale_down)
297 {
298    Smart_Data *sd;
299
300    sd = evas_object_smart_data_get(obj);
301    if (!sd) return;
302    if (((sd->scale_down) && (scale_down)) ||
303        ((!sd->scale_down) && (!scale_down))) return;
304    sd->scale_down = scale_down;
305    _smart_reconfigure(sd);
306 }
307
308 Eina_Bool
309 _els_smart_icon_scale_down_get(const Evas_Object *obj)
310 {
311    Smart_Data *sd; sd = evas_object_smart_data_get(obj);
312    if (!sd) return EINA_FALSE;
313    return sd->scale_up;
314 }
315
316 void
317 _els_smart_icon_scale_size_set(Evas_Object *obj, int size)
318 {
319    Smart_Data *sd;
320
321    sd = evas_object_smart_data_get(obj);
322    if (!sd) return;
323    sd->size = size;
324    if (!sd->obj) return;
325    if (sd->edje)
326      return;
327    evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
328 }
329
330 int
331 _els_smart_icon_scale_size_get(const Evas_Object *obj)
332 {
333    Smart_Data *sd; sd = evas_object_smart_data_get(obj);
334    if (!sd) return 0;
335    return sd->size;
336 }
337
338 void
339 _els_smart_icon_scale_set(Evas_Object *obj, double scale)
340 {
341    Smart_Data *sd = evas_object_smart_data_get(obj);
342    if (!sd) return;
343    sd->scale = scale;
344    _smart_reconfigure(sd);
345 }
346
347 double
348 _els_smart_icon_scale_get(const Evas_Object *obj)
349 {
350    Smart_Data *sd; sd = evas_object_smart_data_get(obj);
351    if (!sd) return 0.0;
352    return sd->scale;
353 }
354
355 void
356 _els_smart_icon_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
357 {
358    Smart_Data   *sd;
359    unsigned int *data, *data2 = NULL, *to, *from;
360    int           x, y, w, hw, iw, ih;
361
362    sd = evas_object_smart_data_get(obj);
363    if (!sd) return;
364    if (sd->edje)
365      return;
366
367    switch (orient)
368      {
369       case ELM_IMAGE_FLIP_HORIZONTAL:
370          _els_smart_icon_flip_horizontal(sd);
371          return;
372       case ELM_IMAGE_FLIP_VERTICAL:
373          _els_smart_icon_flip_vertical(sd);
374          return;
375       case ELM_IMAGE_ROTATE_180:
376          _els_smart_icon_rotate_180(sd);
377          return;
378       default:
379          break;
380      }
381
382    evas_object_image_size_get(sd->obj, &iw, &ih);
383    /* we need separate destination memory if we want to rotate 90 or 270 degree */
384    evas_object_image_data_copy_set(sd->obj, data2);
385    if (!data2) return;
386
387    w = ih;
388    ih = iw;
389    iw = w;
390    hw = w * ih;
391
392    evas_object_image_size_set(sd->obj, iw, ih);
393    data = evas_object_image_data_get(sd->obj, EINA_TRUE);
394
395    switch (orient)
396      {
397       case ELM_IMAGE_FLIP_TRANSPOSE:
398          to = data;
399          hw = -hw + 1;
400          break;
401       case ELM_IMAGE_FLIP_TRANSVERSE:
402          to = data + hw - 1;
403          w = -w;
404          hw = hw - 1;
405          break;
406       case ELM_IMAGE_ROTATE_90:
407          to = data + w - 1;
408          hw = -hw - 1;
409          break;
410       case ELM_IMAGE_ROTATE_270:
411          to = data + hw - w;
412          w = -w;
413          hw = hw + 1;
414          break;
415       default:
416          ERR("unknown orient %d", orient);
417          evas_object_image_data_set(sd->obj, data); // give it back
418          if (data2) free(data2);
419          return;
420      }
421    from = data2;
422    for (x = iw; --x >= 0;)
423      {
424         for (y = ih; --y >= 0;)
425           {
426              *to = *from;
427              from++;
428              to += w;
429           }
430         to += hw;
431      }
432    sd->orient = orient;
433    if (data2) free(data2);
434    evas_object_image_data_set(sd->obj, data);
435    evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
436    _smart_reconfigure(sd);
437 }
438
439 Elm_Image_Orient
440 _els_smart_icon_orient_get(const Evas_Object *obj)
441 {
442    Smart_Data *sd; sd = evas_object_smart_data_get(obj);
443    if (!sd) return 0;
444    return sd->orient;
445 }
446
447 /**
448  * Turns on editing through drag and drop and copy and paste.
449  */
450 void
451 _els_smart_icon_edit_set(Evas_Object *obj, Eina_Bool edit, Evas_Object *parent)
452 {
453    Smart_Data   *sd = evas_object_smart_data_get(obj);
454    if (!sd) return;
455
456    if (sd->edje)
457      {
458         printf("No editing edje objects yet (ever)\n");
459         return;
460      }
461
462    /* Unfortunately eina bool is not a bool, but a char */
463    if (edit == sd->edit) return;
464
465    sd->edit = edit;
466
467    if (sd->edit)
468      elm_drop_target_add(obj, ELM_SEL_FORMAT_IMAGE, _els_smart_icon_dropcb,
469                          parent);
470    else
471      elm_drop_target_del(obj);
472 }
473
474 Eina_Bool
475 _els_smart_icon_edit_get(const Evas_Object *obj)
476 {
477    Smart_Data *sd; sd = evas_object_smart_data_get(obj);
478    if (!sd) return EINA_FALSE;
479    return sd->edit;
480 }
481
482 Evas_Object *
483 _els_smart_icon_edje_get(Evas_Object *obj)
484 {
485    Smart_Data *sd = evas_object_smart_data_get(obj);
486    if (!sd) return NULL;
487    if (!sd->edje) return NULL;
488    return sd->obj;
489 }
490
491 void
492 _els_smart_icon_aspect_fixed_set(Evas_Object *obj, Eina_Bool fixed)
493 {
494    Smart_Data *sd;
495
496    sd = evas_object_smart_data_get(obj);
497    if (!sd) return;
498
499    fixed = !!fixed;
500    if (sd->aspect_fixed == fixed) return;
501    sd->aspect_fixed = fixed;
502    _smart_reconfigure(sd);
503 }
504
505 Eina_Bool
506 _els_smart_icon_aspect_fixed_get(const Evas_Object *obj)
507 {
508    Smart_Data *sd;
509
510    sd = evas_object_smart_data_get(obj);
511    if (!sd) return EINA_FALSE;
512    return sd->aspect_fixed;
513 }
514
515 /* local subsystem globals */
516 static void
517 _smart_reconfigure(Smart_Data *sd)
518 {
519    Evas_Coord x, y, w, h;
520    const char *type;
521
522    if (!sd->obj) return;
523
524    w = sd->w;
525    h = sd->h;
526
527    type = evas_object_type_get(sd->obj);
528    if (!type) return;
529    if (!strcmp(type, "edje"))
530      {
531         x = sd->x;
532         y = sd->y;
533         evas_object_move(sd->obj, x, y);
534         evas_object_resize(sd->obj, w, h);
535      }
536    else
537      {
538         int iw = 0, ih = 0;
539         double alignh = 0.5, alignv = 0.5;
540         Evas_Object *parent;
541
542         evas_object_image_size_get(sd->obj, &iw, &ih);
543
544         iw = ((double)iw) * sd->scale;
545         ih = ((double)ih) * sd->scale;
546
547         if (iw < 1) iw = 1;
548         if (ih < 1) ih = 1;
549
550         if (sd->aspect_fixed)
551           {
552              h = ((double)ih * w) / (double)iw;
553              if (sd->fill_inside)
554                {
555                   if (h > sd->h)
556                     {
557                        h = sd->h;
558                        w = ((double)iw * h) / (double)ih;
559                     }
560                }
561              else
562                {
563                   if (h < sd->h)
564                     {
565                        h = sd->h;
566                        w = ((double)iw * h) / (double)ih;
567                     }
568                }
569           }
570         if (!sd->scale_up)
571           {
572              if (w > iw) w = iw;
573              if (h > ih) h = ih;
574           }
575         if (!sd->scale_down)
576           {
577              if (w < iw) w = iw;
578              if (h < ih) h = ih;
579           }
580         parent = elm_widget_parent_widget_get(sd->obj);
581         if (parent)
582           evas_object_size_hint_align_get(parent, &alignh, &alignv);
583         x = sd->x + ((sd->w - w) * alignh);
584         y = sd->y + ((sd->h - h) * alignv);
585         evas_object_move(sd->obj, x, y);
586         evas_object_image_fill_set(sd->obj, 0, 0, w, h);
587         evas_object_resize(sd->obj, w, h);
588      }
589 }
590
591 static void
592 _smart_init(void)
593 {
594    if (_e_smart) return;
595      {
596         static const Evas_Smart_Class sc =
597           {
598              "e_icon",
599              EVAS_SMART_CLASS_VERSION,
600              _smart_add,
601              _smart_del,
602              _smart_move,
603              _smart_resize,
604              _smart_show,
605              _smart_hide,
606              _smart_color_set,
607              _smart_clip_set,
608              _smart_clip_unset,
609              NULL,
610              NULL,
611              NULL,
612              NULL,
613              NULL,
614              NULL,
615              NULL
616           };
617         _e_smart = evas_smart_class_new(&sc);
618      }
619 }
620
621 static void
622 _smart_add(Evas_Object *obj)
623 {
624    Smart_Data *sd;
625
626    sd = calloc(1, sizeof(Smart_Data));
627    if (!sd) return;
628    sd->obj = evas_object_image_add(evas_object_evas_get(obj));
629    sd->prev = NULL;
630    evas_object_image_scale_hint_set(sd->obj, EVAS_IMAGE_SCALE_HINT_STATIC);
631    sd->x = 0;
632    sd->y = 0;
633    sd->w = 0;
634    sd->h = 0;
635    sd->fill_inside = EINA_TRUE;
636    sd->scale_up = EINA_TRUE;
637    sd->scale_down = EINA_TRUE;
638    sd->aspect_fixed = EINA_TRUE;
639    sd->size = 64;
640    sd->scale = 1.0;
641    evas_object_smart_member_add(sd->obj, obj);
642    evas_object_smart_data_set(obj, sd);
643    evas_object_event_callback_add(sd->obj, EVAS_CALLBACK_IMAGE_PRELOADED,
644                                   _preloaded, sd);
645 }
646
647 static void
648 _smart_del(Evas_Object *obj)
649 {
650    Smart_Data *sd;
651
652    sd = evas_object_smart_data_get(obj);
653    if (!sd) return;
654    evas_object_del(sd->obj);
655    if (sd->prev) evas_object_del(sd->prev);
656    free(sd);
657 }
658
659 static void
660 _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
661 {
662    Smart_Data *sd;
663
664    sd = evas_object_smart_data_get(obj);
665    if (!sd) return;
666    if ((sd->x == x) && (sd->y == y)) return;
667    sd->x = x;
668    sd->y = y;
669    _smart_reconfigure(sd);
670 }
671
672 static void
673 _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
674 {
675    Smart_Data *sd;
676
677    sd = evas_object_smart_data_get(obj);
678    if (!sd) return;
679    if ((sd->w == w) && (sd->h == h)) return;
680    sd->w = w;
681    sd->h = h;
682    _smart_reconfigure(sd);
683 }
684
685 static void
686 _smart_show(Evas_Object *obj)
687 {
688    Smart_Data *sd;
689
690    sd = evas_object_smart_data_get(obj);
691    if (!sd) return;
692    sd->show = EINA_TRUE;
693    if (!sd->preloading)
694      {
695         evas_object_show(sd->obj);
696         if (sd->prev) evas_object_del(sd->prev);
697         sd->prev = NULL;
698      }
699 }
700
701 static void
702 _smart_hide(Evas_Object *obj)
703 {
704    Smart_Data *sd;
705
706    sd = evas_object_smart_data_get(obj);
707    if (!sd) return;
708    sd->show = EINA_FALSE;
709    evas_object_hide(sd->obj);
710    if (sd->prev) evas_object_del(sd->prev);
711    sd->prev = NULL;
712 }
713
714 static void
715 _smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
716 {
717    Smart_Data *sd;
718
719    sd = evas_object_smart_data_get(obj);
720    if (!sd) return;
721    evas_object_color_set(sd->obj, r, g, b, a);
722    if (sd->prev) evas_object_color_set(sd->prev, r, g, b, a);
723 }
724
725 static void
726 _smart_clip_set(Evas_Object *obj, Evas_Object * clip)
727 {
728    Smart_Data *sd;
729
730    sd = evas_object_smart_data_get(obj);
731    if (!sd) return;
732    evas_object_clip_set(sd->obj, clip);
733    if (sd->prev) evas_object_clip_set(sd->prev, clip);
734 }
735
736 static void
737 _smart_clip_unset(Evas_Object *obj)
738 {
739    Smart_Data *sd;
740
741    sd = evas_object_smart_data_get(obj);
742    if (!sd) return;
743    evas_object_clip_unset(sd->obj);
744    if (sd->prev) evas_object_clip_unset(sd->prev);
745 }
746
747 static void
748 _els_smart_icon_flip_horizontal(Smart_Data *sd)
749 {
750    unsigned int   *data;
751    unsigned int   *p1, *p2, tmp;
752    int             x, y, iw, ih;
753
754    evas_object_image_size_get(sd->obj, &iw, &ih);
755    data = evas_object_image_data_get(sd->obj, EINA_TRUE);
756
757    for (y = 0; y < ih; y++)
758      {
759         p1 = data + (y * iw);
760         p2 = data + ((y + 1) * iw) - 1;
761         for (x = 0; x < (iw >> 1); x++)
762           {
763              tmp = *p1;
764              *p1 = *p2;
765              *p2 = tmp;
766              p1++;
767              p2--;
768           }
769      }
770
771    evas_object_image_data_set(sd->obj, data);
772    evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
773    _smart_reconfigure(sd);
774 }
775
776 static void
777 _els_smart_icon_flip_vertical(Smart_Data *sd)
778 {
779    unsigned int   *data;
780    unsigned int   *p1, *p2, tmp;
781    int             x, y, iw, ih;
782
783    evas_object_image_size_get(sd->obj, &iw, &ih);
784    data = evas_object_image_data_get(sd->obj, EINA_TRUE);
785
786    for (y = 0; y < (ih >> 1); y++)
787      {
788         p1 = data + (y * iw);
789         p2 = data + ((ih - 1 - y) * iw);
790         for (x = 0; x < iw; x++)
791           {
792              tmp = *p1;
793              *p1 = *p2;
794              *p2 = tmp;
795              p1++;
796              p2++;
797           }
798      }
799
800    evas_object_image_data_set(sd->obj, data);
801    evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
802    _smart_reconfigure(sd);
803 }
804
805 static void
806 _els_smart_icon_rotate_180(Smart_Data *sd)
807 {
808    unsigned int   *data;
809    unsigned int   *p1, *p2, tmp;
810    int             x, hw, iw, ih;
811
812    evas_object_image_size_get(sd->obj, &iw, &ih);
813    data = evas_object_image_data_get(sd->obj, 1);
814
815    hw = iw * ih;
816    x = (hw / 2);
817    p1 = data;
818    p2 = data + hw - 1;
819    for (; --x > 0;)
820      {
821         tmp = *p1;
822         *p1 = *p2;
823         *p2 = tmp;
824         p1++;
825         p2--;
826      }
827    evas_object_image_data_set(sd->obj, data);
828    evas_object_image_data_update_add(sd->obj, 0, 0, iw, ih);
829    _smart_reconfigure(sd);
830 }
831
832 static Eina_Bool
833 _els_smart_icon_dropcb(void *elmobj,Evas_Object *obj, Elm_Selection_Data *drop)
834 {
835    _els_smart_icon_file_key_set(obj, drop->data, NULL);
836    evas_object_smart_callback_call(elmobj, "drop", drop->data);
837
838    return EINA_TRUE;
839 }
840 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 :*/