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