Merge branch 'master' into svn_merge
[framework/uifw/elementary.git] / src / lib / elm_icon.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 #ifdef ELM_EFREET
5 #define NON_EXISTING (void *)-1
6 static const char *icon_theme = NULL;
7 #endif
8
9 /**
10  * @defgroup Icon Icon
11  * @ingroup Elementary
12  *
13  * A standard icon that may be provided by the theme (delete, edit,
14  * arrows etc.) or a custom file (PNG, JPG, EDJE etc.) used for an
15  * icon. The Icon may scale or not and of course... support alpha
16  * channels.
17  *
18  * Signals that you can add callbacks for are:
19  *
20  * "clicked" - This is called when a user has clicked the icon
21  */
22
23 typedef struct _Widget_Data Widget_Data;
24
25 struct _Widget_Data
26 {
27    Evas_Object *img;
28    const char *stdicon;
29    Elm_Icon_Lookup_Order lookup_order;
30
31 #ifdef HAVE_ELEMENTARY_ETHUMB
32    struct {
33       int id;
34
35       struct {
36          const char *path;
37          const char *key;
38       } file, thumb;
39
40       Ethumb_Exists *exists;
41
42       Ecore_Event_Handler *eeh;
43
44       Ethumb_Thumb_Format format;
45
46       Eina_Bool retry : 1;
47    } thumb;
48 #endif
49
50 #ifdef ELM_EFREET
51    struct {
52         int requested_size;
53         Eina_Bool use : 1;
54    } freedesktop;
55 #endif
56    Eina_Bool scale_up : 1;
57    Eina_Bool scale_down : 1;
58    Eina_Bool smooth : 1;
59    Eina_Bool fill_outside : 1;
60    Eina_Bool no_scale : 1;
61 };
62
63 #ifdef HAVE_ELEMENTARY_ETHUMB
64 static Eina_List *_elm_icon_retry = NULL;
65 static int _icon_pending_request = 0;
66
67 static void _icon_thumb_exists(Ethumb_Client *client __UNUSED__, Ethumb_Exists *thread, Eina_Bool exists, void *data);
68 #endif
69
70 static const char *widtype = NULL;
71 static void _del_hook(Evas_Object *obj);
72 static void _theme_hook(Evas_Object *obj);
73 static void _sizing_eval(Evas_Object *obj);
74 static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
75
76 static Eina_Bool _icon_standard_set(Widget_Data *wd, Evas_Object *obj, const char *name);
77 static Eina_Bool _icon_freedesktop_set(Widget_Data *wd, Evas_Object *obj, const char *name, int size);
78
79 static const char SIG_CLICKED[] = "clicked";
80
81 static const Evas_Smart_Cb_Description _signals[] = {
82    {SIG_CLICKED, ""},
83    {NULL, NULL}
84 };
85
86
87 //FIXME: move this code to ecore
88 #ifdef _WIN32
89 static Eina_Bool
90 _path_is_absolute(const char *path)
91 {
92    //TODO: Check if this works with all absolute paths in windows
93    return ((isalpha (*path)) && (*(path + 1) == ':') && ((*(path + 2) == '\\') || (*(path + 2) == '/')));
94 }
95 #else
96 static Eina_Bool
97 _path_is_absolute(const char *path)
98 {
99    return  (*path == '/');
100 }
101 #endif
102
103 static inline int
104 _icon_size_min_get(Evas_Object *icon)
105 {
106    int size;
107    _els_smart_icon_size_get(icon, &size, NULL);
108    return (size < 32) ? 32 : size;
109 }
110
111 #ifdef HAVE_ELEMENTARY_ETHUMB
112 static void
113 _icon_thumb_stop(Widget_Data *wd, void *ethumbd)
114 {
115    if (wd->thumb.id >= 0)
116      {
117         ethumb_client_generate_cancel(ethumbd, wd->thumb.id, NULL, NULL, NULL);
118         wd->thumb.id = -1;
119         _icon_pending_request--;
120      }
121
122    if (wd->thumb.exists)
123      {
124         ethumb_client_thumb_exists_cancel(wd->thumb.exists, _icon_thumb_exists, wd);
125         wd->thumb.exists = NULL;
126         _icon_pending_request--;
127      }
128
129    if (wd->thumb.retry)
130      {
131         _elm_icon_retry = eina_list_remove(_elm_icon_retry, wd);
132         wd->thumb.retry = EINA_FALSE;
133      }
134 }
135
136 static Eina_Bool
137 _icon_thumb_display(Widget_Data *wd)
138 {
139    Eina_Bool ret = EINA_FALSE;
140
141    if (wd->thumb.format == ETHUMB_THUMB_EET)
142      {
143         static const char *extensions[] = {
144           ".avi", ".mp4", ".ogv", ".mov", ".mpg", ".wmv", NULL
145         };
146         const char **ext, *ptr;
147         int prefix_size;
148         Eina_Bool video = EINA_FALSE;
149
150         prefix_size = eina_stringshare_strlen(wd->thumb.file.path) - 4;
151         if (prefix_size >= 0)
152           {
153              ptr = wd->thumb.file.path + prefix_size;
154              for (ext = extensions; *ext; ++ext)
155                if (!strcasecmp(ptr, *ext))
156                  {
157                     video = EINA_TRUE;
158                     break;
159                  }
160           }
161
162         if (video)
163           ret = _els_smart_icon_file_edje_set(wd->img, wd->thumb.thumb.path, wd->thumb.thumb.key);
164      }
165
166    if (!ret)
167      ret = _els_smart_icon_file_key_set(wd->img, wd->thumb.thumb.path, wd->thumb.thumb.key);
168
169    return ret;
170 }
171
172 static Eina_Bool
173 _icon_thumb_retry(Widget_Data *wd)
174 {
175    return _icon_thumb_display(wd);
176 }
177
178 static void
179 _icon_thumb_cleanup(Ethumb_Client *ethumbd)
180 {
181    Eina_List *l, *ll;
182    Widget_Data *wd;
183
184    EINA_LIST_FOREACH_SAFE(_elm_icon_retry, l, ll, wd)
185      if (_icon_thumb_retry(wd))
186        {
187           _elm_icon_retry = eina_list_remove_list(_elm_icon_retry, l);
188           wd->thumb.retry = EINA_FALSE;
189        }
190
191    if (_icon_pending_request == 0)
192      EINA_LIST_FREE(_elm_icon_retry, wd)
193        _icon_thumb_stop(wd, ethumbd);
194 }
195
196 static void
197 _icon_thumb_finish(Widget_Data *wd, Ethumb_Client *ethumbd)
198 {
199    const char *file = NULL, *group = NULL;
200    Eina_Bool ret;
201
202    _els_smart_icon_file_get(wd->img, &file, &group);
203    file = eina_stringshare_ref(file);
204    group = eina_stringshare_ref(group);
205
206    ret = _icon_thumb_display(wd);
207
208    if (!ret && file)
209      {
210         const char *p;
211
212         if (!wd->thumb.retry)
213           {
214              _elm_icon_retry = eina_list_append(_elm_icon_retry, wd);
215              wd->thumb.retry = EINA_TRUE;
216           }
217
218         /* Back to previous image */
219         if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
220           _els_smart_icon_file_edje_set(wd->img, file, group);
221         else
222           _els_smart_icon_file_key_set(wd->img, file, group);
223      }
224
225    _icon_thumb_cleanup(ethumbd);
226
227    eina_stringshare_del(file);
228    eina_stringshare_del(group);
229 }
230
231 static void
232 _icon_thumb_cb(void *data,
233                Ethumb_Client *ethumbd,
234                int id,
235                const char *file __UNUSED__,
236                const char *key __UNUSED__,
237                const char *thumb_path,
238                const char *thumb_key,
239                Eina_Bool success)
240 {
241    Widget_Data *wd = data;
242
243    EINA_SAFETY_ON_FALSE_RETURN(wd->thumb.id == id);
244    wd->thumb.id = -1;
245
246    _icon_pending_request--;
247
248    if (success)
249      {
250         eina_stringshare_replace(&wd->thumb.thumb.path, thumb_path);
251         eina_stringshare_replace(&wd->thumb.thumb.key, thumb_key);
252         wd->thumb.format = ethumb_client_format_get(ethumbd);
253
254         _icon_thumb_finish(wd, ethumbd);
255      }
256    else
257      {
258         ERR("could not generate thumbnail for %s (key: %s)", file, key);
259         _icon_thumb_cleanup(ethumbd);
260      }
261 }
262
263 static void
264 _icon_thumb_exists(Ethumb_Client *client __UNUSED__, Ethumb_Exists *thread, Eina_Bool exists, void *data)
265 {
266    Widget_Data *wd = data;
267    Ethumb_Client *ethumbd;
268
269    if (ethumb_client_thumb_exists_check(thread))
270      return ;
271
272    wd->thumb.exists = NULL;
273
274    ethumbd = elm_thumb_ethumb_client_get();
275
276    if (exists)
277      {
278         const char *thumb_path, *thumb_key;
279
280         _icon_pending_request--;
281         ethumb_client_thumb_path_get(ethumbd, &thumb_path, &thumb_key);
282         eina_stringshare_replace(&wd->thumb.thumb.path, thumb_path);
283         eina_stringshare_replace(&wd->thumb.thumb.key, thumb_key);
284         wd->thumb.format = ethumb_client_format_get(ethumbd);
285
286         _icon_thumb_finish(wd, ethumbd);
287      }
288    else if ((wd->thumb.id = ethumb_client_generate(ethumbd, _icon_thumb_cb, wd, NULL)) == -1)
289      {
290         ERR("Generate was unable to start !");
291         /* Failed to generate thumbnail */
292         _icon_pending_request--;
293      }
294 }
295
296 static void
297 _icon_thumb_apply(Widget_Data *wd)
298 {
299    Ethumb_Client *ethumbd;
300
301    ethumbd = elm_thumb_ethumb_client_get();
302
303    _icon_thumb_stop(wd, ethumbd);
304
305    if (!wd->thumb.file.path) return ;
306
307    _icon_pending_request++;
308    if (!ethumb_client_file_set(ethumbd, wd->thumb.file.path, wd->thumb.file.key)) return ;
309    ethumb_client_size_set(ethumbd, _icon_size_min_get(wd->img), _icon_size_min_get(wd->img));
310    wd->thumb.exists = ethumb_client_thumb_exists(ethumbd, _icon_thumb_exists, wd);
311 }
312
313 static Eina_Bool
314 _icon_thumb_apply_cb(void *data, int type __UNUSED__, void *ev __UNUSED__)
315 {
316    Widget_Data *wd = data;
317
318    _icon_thumb_apply(wd);
319    return ECORE_CALLBACK_RENEW;
320 }
321 #endif
322
323 static void
324 _del_hook(Evas_Object *obj)
325 {
326    Widget_Data *wd = elm_widget_data_get(obj);
327
328 #ifdef HAVE_ELEMENTARY_ETHUMB
329    Ethumb_Client *ethumbd;
330 #endif
331
332    if (!wd) return;
333    if (wd->stdicon) eina_stringshare_del(wd->stdicon);
334
335 #ifdef HAVE_ELEMENTARY_ETHUMB
336    ethumbd = elm_thumb_ethumb_client_get();
337    _icon_thumb_stop(wd, ethumbd);
338
339    eina_stringshare_del(wd->thumb.file.path);
340    eina_stringshare_del(wd->thumb.file.key);
341    eina_stringshare_del(wd->thumb.thumb.path);
342    eina_stringshare_del(wd->thumb.thumb.key);
343
344    if (wd->thumb.eeh)
345      ecore_event_handler_del(wd->thumb.eeh);
346 #endif
347
348    free(wd);
349 }
350
351 static void
352 _theme_hook(Evas_Object *obj)
353 {
354    Widget_Data *wd = elm_widget_data_get(obj);
355    if (!wd) return;
356    if (wd->stdicon)
357      _elm_theme_object_icon_set(obj, wd->img, wd->stdicon, elm_widget_style_get(obj));
358    _sizing_eval(obj);
359 }
360
361 static void
362 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
363 {
364    Widget_Data *wd = elm_widget_data_get(obj);
365    if (!wd) return;
366    Evas_Object *icon_edje;
367    icon_edje = _els_smart_icon_edje_get(wd->img);
368    if (!icon_edje) return;
369    edje_object_signal_emit(icon_edje, emission, source);
370 }
371
372 static void
373 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
374 {
375    Widget_Data *wd = elm_widget_data_get(obj);
376    if (!wd) return;
377    Evas_Object *icon_edje;
378    icon_edje = _els_smart_icon_edje_get(wd->img);
379    if (!icon_edje) return;
380    edje_object_signal_callback_add(icon_edje, emission, source, func_cb, data);
381 }
382
383 static void
384 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
385 {
386    Widget_Data *wd = elm_widget_data_get(obj);
387    if (!wd) return;
388    Evas_Object *icon_edje;
389    icon_edje = _els_smart_icon_edje_get(wd->img);
390    if (!icon_edje) return;
391    edje_object_signal_callback_del_full(icon_edje, emission, source, func_cb,
392                                         data);
393 }
394
395 static void
396 _sizing_eval(Evas_Object *obj)
397 {
398    Widget_Data *wd = elm_widget_data_get(obj);
399    if (!wd) return;
400    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
401    int w, h;
402
403    _els_smart_icon_size_get(wd->img, &w, &h);
404 #ifdef ELM_EFREET
405    if ((wd->freedesktop.use) && (!((w - wd->freedesktop.requested_size) % 16)))
406      {
407         /* This icon has been set to a freedesktop icon, and the requested
408            appears to have a different size than the requested size, so try to
409            request another, higher resolution, icon.
410 FIXME: Find a better heuristic to determine if there should be
411 an icon with a different resolution. */
412         _icon_freedesktop_set(wd, obj, wd->stdicon, w);
413      }
414 #endif
415    _els_smart_icon_scale_up_set(wd->img, wd->scale_up);
416    _els_smart_icon_scale_down_set(wd->img, wd->scale_down);
417    _els_smart_icon_smooth_scale_set(wd->img, wd->smooth);
418    _els_smart_icon_fill_inside_set(wd->img, !(wd->fill_outside));
419    if (wd->no_scale) _els_smart_icon_scale_set(wd->img, 1.0);
420    else
421      {
422         _els_smart_icon_scale_set(wd->img, elm_widget_scale_get(obj) *
423                                   _elm_config->scale);
424         _els_smart_icon_size_get(wd->img, &w, &h);
425      }
426    if (!wd->scale_down)
427      {
428         minw = w;
429         minh = h;
430      }
431    if (!wd->scale_up)
432      {
433         maxw = w;
434         maxh = h;
435      }
436    evas_object_size_hint_min_set(obj, minw, minh);
437    evas_object_size_hint_max_set(obj, maxw, maxh);
438 }
439
440 static void
441 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
442 {
443    Evas_Event_Mouse_Up *ev = event_info;
444    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
445    evas_object_smart_callback_call(data, SIG_CLICKED, event_info);
446 }
447
448 /**
449  * Add a new icon to the parent
450  *
451  * @param parent The parent object
452  * @return The new object or NULL if it cannot be created
453  *
454  * @ingroup Icon
455  */
456 EAPI Evas_Object *
457 elm_icon_add(Evas_Object *parent)
458 {
459    Evas_Object *obj;
460    Evas *e;
461    Widget_Data *wd;
462
463    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
464
465    ELM_SET_WIDTYPE(widtype, "icon");
466    elm_widget_type_set(obj, "icon");
467    elm_widget_can_focus_set(obj, EINA_FALSE);
468    elm_widget_sub_object_add(parent, obj);
469    elm_widget_data_set(obj, wd);
470    elm_widget_del_hook_set(obj, _del_hook);
471    elm_widget_theme_hook_set(obj, _theme_hook);
472    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
473    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
474    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
475
476    wd->lookup_order = ELM_ICON_LOOKUP_THEME_FDO;
477    wd->img = _els_smart_icon_add(e);
478    evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
479                                   _mouse_up, obj);
480    evas_object_repeat_events_set(wd->img, EINA_TRUE);
481    elm_widget_resize_object_set(obj, wd->img);
482
483    evas_object_smart_callbacks_descriptions_set(obj, _signals);
484
485 #ifdef HAVE_ELEMENTARY_ETHUMB
486    wd->thumb.id = -1;
487 #endif
488
489    wd->smooth = EINA_TRUE;
490    wd->scale_up = EINA_TRUE;
491    wd->scale_down = EINA_TRUE;
492
493    _sizing_eval(obj);
494    return obj;
495 }
496
497 /**
498  * Set the file that will be used as icon
499  *
500  * @param obj The icon object
501  * @param file The path to file that will be used as icon
502  * @param group The group that the icon belongs in edje file
503  *
504  * @return (1 = success, 0 = error)
505  *
506  * @ingroup Icon
507  */
508 EAPI Eina_Bool
509 elm_icon_file_set(Evas_Object *obj, const char *file, const char *group)
510 {
511    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
512    Widget_Data *wd = elm_widget_data_get(obj);
513    Eina_Bool ret;
514    const char *p;
515
516    if (!wd) return EINA_FALSE;
517    EINA_SAFETY_ON_NULL_RETURN_VAL(file, EINA_FALSE);
518    if (wd->stdicon) eina_stringshare_del(wd->stdicon);
519    wd->stdicon = NULL;
520    if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
521      ret = _els_smart_icon_file_edje_set(wd->img, file, group);
522    else
523      ret = _els_smart_icon_file_key_set(wd->img, file, group);
524    _sizing_eval(obj);
525    return ret;
526 }
527
528 /**
529  * Get the file that will be used as icon
530  *
531  * @param obj The icon object
532  * @param file The path to file that will be used as icon
533  * @param group The group that the icon belongs in edje file
534  *
535  * @ingroup Icon
536  */
537 EAPI void
538 elm_icon_file_get(const Evas_Object *obj, const char **file, const char **group)
539 {
540    ELM_CHECK_WIDTYPE(obj, widtype);
541    Widget_Data *wd = elm_widget_data_get(obj);
542    if (!wd) return;
543    _els_smart_icon_file_get(wd->img, file, group);
544 }
545
546 EAPI void
547 elm_icon_thumb_set(const Evas_Object *obj, const char *file, const char *group)
548 {
549    ELM_CHECK_WIDTYPE(obj, widtype);
550    Widget_Data *wd = elm_widget_data_get(obj);
551    if (!wd) return;
552
553 #ifdef HAVE_ELEMENTARY_ETHUMB
554    eina_stringshare_replace(&wd->thumb.file.path, file);
555    eina_stringshare_replace(&wd->thumb.file.key, group);
556
557    if (elm_thumb_ethumb_client_connected())
558      {
559         _icon_thumb_apply(wd);
560         return ;
561      }
562
563    if (!wd->thumb.eeh)
564      {
565         wd->thumb.eeh = ecore_event_handler_add(ELM_ECORE_EVENT_ETHUMB_CONNECT, _icon_thumb_apply_cb, wd);
566      }
567 #else
568    (void) obj;
569    (void) file;
570    (void) group;
571 #endif
572 }
573
574 static Eina_Bool
575 _icon_standard_set(Widget_Data *wd, Evas_Object *obj, const char *name)
576 {
577    if (_elm_theme_object_icon_set(obj, wd->img, name, "default"))
578      {
579 #ifdef ELM_EFREET
580         /* TODO: elm_unneed_efreet() */
581         wd->freedesktop.use = EINA_FALSE;
582 #endif
583         return EINA_TRUE;
584      }
585    return EINA_FALSE;
586 }
587
588 static Eina_Bool
589 _icon_file_set(Widget_Data *wd, Evas_Object *obj, const char *path)
590 {
591    if (elm_icon_file_set(obj, path, NULL))
592      {
593 #ifdef ELM_EFREET
594         /* TODO: elm_unneed_efreet() */
595         wd->freedesktop.use = EINA_FALSE;
596 #endif
597         return EINA_TRUE;
598      }
599    return EINA_FALSE;
600 }
601
602 static Eina_Bool
603 _icon_freedesktop_set(Widget_Data *wd, Evas_Object *obj, const char *name, int size)
604 {
605 #ifdef ELM_EFREET
606    const char *path;
607
608    elm_need_efreet();
609    if (icon_theme == NON_EXISTING) return EINA_FALSE;
610    if (!icon_theme)
611      {
612         Efreet_Icon_Theme *theme;
613         /* TODO: Listen for EFREET_EVENT_ICON_CACHE_UPDATE */
614         theme = efreet_icon_theme_find(getenv("E_ICON_THEME"));
615         if (!theme)
616           {
617              const char **itr;
618              static const char *themes[] = {
619                   "gnome", "Human", "oxygen", "hicolor", NULL
620              };
621              for (itr = themes; *itr; itr++)
622                {
623                   theme = efreet_icon_theme_find(*itr);
624                   if (theme) break;
625                }
626           }
627
628         if (!theme)
629           {
630              icon_theme = NON_EXISTING;
631              return EINA_FALSE;
632           }
633         else
634           icon_theme = eina_stringshare_add(theme->name.internal);
635      }
636    path = efreet_icon_path_find(icon_theme, name, size);
637    wd->freedesktop.use = !!path;
638    if (wd->freedesktop.use)
639      {
640         wd->freedesktop.requested_size = size;
641         elm_icon_file_set(obj, path, NULL);
642         return EINA_TRUE;
643      }
644 #endif
645    return EINA_FALSE;
646 }
647
648 static Eina_Bool
649 _elm_icon_standard_set(Widget_Data *wd, Evas_Object *obj, const char *name, Eina_Bool *fdo)
650 {
651    char *tmp;
652    Eina_Bool ret;
653
654    /* try locating the icon using the specified lookup order */
655    switch (wd->lookup_order)
656      {
657       case ELM_ICON_LOOKUP_FDO:
658          ret = _icon_freedesktop_set(wd, obj, name, _icon_size_min_get(wd->img));
659          if (ret && fdo) *fdo = EINA_TRUE;
660          break;
661       case ELM_ICON_LOOKUP_THEME:
662          ret = _icon_standard_set(wd, obj, name);
663          break;
664       case ELM_ICON_LOOKUP_THEME_FDO:
665          ret = _icon_standard_set(wd, obj, name);
666          if (!ret)
667            {
668               ret = _icon_freedesktop_set(wd, obj, name, _icon_size_min_get(wd->img));
669               if (ret && fdo) *fdo = EINA_TRUE;
670            }
671          break;
672       case ELM_ICON_LOOKUP_FDO_THEME:
673       default:
674          ret = _icon_freedesktop_set(wd, obj, name, _icon_size_min_get(wd->img));
675          if (!ret)
676            ret = _icon_standard_set(wd, obj, name);
677          else if (fdo)
678            *fdo = EINA_TRUE;
679          break;
680      }
681
682    if (ret)
683      {
684         eina_stringshare_replace(&wd->stdicon, name);
685         _sizing_eval(obj);
686         return EINA_TRUE;
687      }
688
689    if (_path_is_absolute(name))
690      return _icon_file_set(wd, obj, name);
691
692    /* if that fails, see if icon name is in the format size/name. if so,
693       try locating a fallback without the size specification */
694    if (!(tmp = strchr(name, '/'))) return EINA_FALSE;
695    ++tmp;
696    if (*tmp) return elm_icon_standard_set(obj, tmp);
697    /* give up */
698    return EINA_FALSE;
699 }
700
701 static void
702 _elm_icon_standard_resize(void *data,
703                           Evas *e __UNUSED__,
704                           Evas_Object *obj,
705                           void *event_info __UNUSED__)
706 {
707    Widget_Data *wd = data;
708    const char *refup = eina_stringshare_ref(wd->stdicon);
709    Eina_Bool fdo = EINA_FALSE;
710
711    if (!_elm_icon_standard_set(wd, obj, wd->stdicon, &fdo) || (!fdo))
712      evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE,
713                                          _elm_icon_standard_resize, wd);
714 #ifdef HAVE_ELEMENTARY_ETHUMB
715    if (wd->thumb.file.path)
716      elm_icon_thumb_set(obj, wd->thumb.file.path, wd->thumb.file.key);
717 #endif
718
719    eina_stringshare_del(refup);
720 }
721
722 /**
723  * Set the theme, as standard, for an icon.
724  * If theme was not found and it is the absolute path of an image file, this
725  * image will be used.
726  *
727  * @param obj The icon object
728  * @param name The theme name
729  *
730  * @return (1 = success, 0 = error)
731  *
732  * @ingroup Icon
733  */
734 EAPI Eina_Bool
735 elm_icon_standard_set(Evas_Object *obj, const char *name)
736 {
737    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
738    Widget_Data *wd = elm_widget_data_get(obj);
739    Eina_Bool fdo = EINA_FALSE;
740    Eina_Bool ret;
741
742    if ((!wd) || (!name)) return EINA_FALSE;
743
744    evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE,
745                                        _elm_icon_standard_resize, wd);
746
747    ret = _elm_icon_standard_set(wd, obj, name, &fdo);
748
749    if (fdo)
750      evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
751                                     _elm_icon_standard_resize, wd);
752
753    return ret;
754 }
755
756 /**
757  * Get the theme, as standard, for an icon
758  *
759  * @param obj The icon object
760  * @return The theme name
761  *
762  * @ingroup Icon
763  */
764 EAPI const char *
765 elm_icon_standard_get(const Evas_Object *obj)
766 {
767    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
768    Widget_Data *wd = elm_widget_data_get(obj);
769    if (!wd) return NULL;
770    return wd->stdicon;
771 }
772
773 /**
774  * Sets icon lookup order, used by elm_icon_standard_set().
775  *
776  * @param obj The icon object
777  * @param order The icon lookup order
778  *
779  * @ingroup Icon
780  */
781 EAPI void
782 elm_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
783 {
784    ELM_CHECK_WIDTYPE(obj, widtype);
785    Widget_Data *wd = elm_widget_data_get(obj);
786    if (wd) wd->lookup_order = order;
787 }
788
789 /**
790  * Gets the icon lookup order.
791  *
792  * @param obj The icon object
793  * @return The icon lookup order
794  *
795  * @ingroup Icon
796  */
797 EAPI Elm_Icon_Lookup_Order
798 elm_icon_order_lookup_get(const Evas_Object *obj)
799 {
800    ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
801    Widget_Data *wd = elm_widget_data_get(obj);
802    if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
803    return wd->lookup_order;
804 }
805
806 /**
807  * Set the smooth effect for an icon
808  *
809  * @param obj The icon object
810  * @param smooth A bool to set (or no) smooth effect
811  * (1 = smooth, 0 = not smooth)
812  *
813  * @ingroup Icon
814  */
815 EAPI void
816 elm_icon_smooth_set(Evas_Object *obj, Eina_Bool smooth)
817 {
818    ELM_CHECK_WIDTYPE(obj, widtype);
819    Widget_Data *wd = elm_widget_data_get(obj);
820
821    if (!wd) return;
822    wd->smooth = smooth;
823    _sizing_eval(obj);
824 }
825
826 /**
827  * Get the smooth effect for an icon
828  *
829  * @param obj The icon object
830  * @return If setted smooth effect
831  *
832  * @ingroup Icon
833  */
834 EAPI Eina_Bool
835 elm_icon_smooth_get(const Evas_Object *obj)
836 {
837    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
838    Widget_Data *wd = elm_widget_data_get(obj);
839
840    if (!wd) return EINA_FALSE;
841    return wd->smooth;
842 }
843
844 /**
845  * Set if the object is scalable
846  *
847  * @param obj The icon object
848  * @param no_scale A bool to set scale (or no)
849  * (1 = no_scale, 0 = scale)
850  *
851  * @ingroup Icon
852  */
853 EAPI void
854 elm_icon_no_scale_set(Evas_Object *obj, Eina_Bool no_scale)
855 {
856    ELM_CHECK_WIDTYPE(obj, widtype);
857    Widget_Data *wd = elm_widget_data_get(obj);
858
859    if (!wd) return;
860    wd->no_scale = no_scale;
861    _sizing_eval(obj);
862 }
863
864 /**
865  * Get if the object isn't scalable
866  *
867  * @param obj The icon object
868  * @return If isn't scalable
869  *
870  * @ingroup Icon
871  */
872 EAPI Eina_Bool
873 elm_icon_no_scale_get(const Evas_Object *obj)
874 {
875    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
876    Widget_Data *wd = elm_widget_data_get(obj);
877    if (!wd) return EINA_FALSE;
878    return wd->no_scale;
879 }
880
881 /**
882  * Set if the object is (up/down) scalable
883  *
884  * @param obj The icon object
885  * @param scale_up A bool to set if the object is scalable up
886  * @param scale_down A bool to set if the object is scalable down
887  *
888  * @ingroup Icon
889  */
890 EAPI void
891 elm_icon_scale_set(Evas_Object *obj, Eina_Bool scale_up, Eina_Bool scale_down)
892 {
893    ELM_CHECK_WIDTYPE(obj, widtype);
894    Widget_Data *wd = elm_widget_data_get(obj);
895
896    if (!wd) return;
897    wd->scale_up = scale_up;
898    wd->scale_down = scale_down;
899    _sizing_eval(obj);
900 }
901
902 /**
903  * Get if the object is (up/down) scalable
904  *
905  * @param obj The icon object
906  * @param scale_up A bool to set if the object is scalable up
907  * @param scale_down A bool to set if the object is scalable down
908  *
909  * @ingroup Icon
910  */
911 EAPI void
912 elm_icon_scale_get(const Evas_Object *obj, Eina_Bool *scale_up, Eina_Bool *scale_down)
913 {
914    ELM_CHECK_WIDTYPE(obj, widtype);
915    Widget_Data *wd = elm_widget_data_get(obj);
916    if (!wd) return;
917    if (scale_up) *scale_up = wd->scale_up;
918    if (scale_down) *scale_down = wd->scale_down;
919 }
920
921 /**
922  * Set if the object is filled outside
923  *
924  * @param obj The icon object
925  * @param fill_outside A bool to set if the object is filled outside
926  * (1 = filled, 0 = no filled)
927  *
928  * @ingroup Icon
929  */
930 EAPI void
931 elm_icon_fill_outside_set(Evas_Object *obj, Eina_Bool fill_outside)
932 {
933    ELM_CHECK_WIDTYPE(obj, widtype);
934    Widget_Data *wd = elm_widget_data_get(obj);
935
936    if (!wd) return;
937    wd->fill_outside = fill_outside;
938    _sizing_eval(obj);
939 }
940
941 /**
942  * Get if the object is filled outside
943  *
944  * @param obj The icon object
945  * @return If the object is filled outside
946  *
947  * @ingroup Icon
948  */
949 EAPI Eina_Bool
950 elm_icon_fill_outside_get(const Evas_Object *obj)
951 {
952    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
953    Widget_Data *wd = elm_widget_data_get(obj);
954
955    if (!wd) return EINA_FALSE;
956    return wd->fill_outside;
957 }
958
959 /**
960  * Set the prescale size for the icon
961  *
962  * @param obj The icon object
963  * @param size The prescale size
964  *
965  * @ingroup Icon
966  */
967 EAPI void
968 elm_icon_prescale_set(Evas_Object *obj, int size)
969 {
970    ELM_CHECK_WIDTYPE(obj, widtype);
971    Widget_Data *wd = elm_widget_data_get(obj);
972
973    if (!wd) return;
974    _els_smart_icon_scale_size_set(wd->img, size);
975 }
976
977 /**
978  * Get the prescale size for the icon
979  *
980  * @param obj The icon object
981  * @return The prescale size
982  *
983  * @ingroup Icon
984  */
985 EAPI int
986 elm_icon_prescale_get(const Evas_Object *obj)
987 {
988    ELM_CHECK_WIDTYPE(obj, widtype) 0;
989    Widget_Data *wd = elm_widget_data_get(obj);
990
991    if (!wd) return 0;
992    return _els_smart_icon_scale_size_get(wd->img);
993 }