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