1 #include <Elementary.h>
7 * A standard icon that may be provided by the theme (delete, edit,
8 * arrows etc.) or a custom file (PNG, JPG, EDJE etc.) used for an
9 * icon. The Icon may scale or not and of course... support alpha
12 * Signals that you can add callbacks for are:
14 * clicked - This is called when a user has clicked the icon
17 typedef struct _Widget_Data Widget_Data;
23 Eina_Bool scale_up : 1;
24 Eina_Bool scale_down : 1;
26 Eina_Bool fill_outside : 1;
27 Eina_Bool no_scale : 1;
30 static const char *widtype = NULL;
31 static void _del_hook(Evas_Object *obj);
32 static void _theme_hook(Evas_Object *obj);
33 static void _sizing_eval(Evas_Object *obj);
34 static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
37 _del_hook(Evas_Object *obj)
39 Widget_Data *wd = elm_widget_data_get(obj);
42 if (wd->stdicon) eina_stringshare_del(wd->stdicon);
47 _theme_hook(Evas_Object *obj)
49 Widget_Data *wd = elm_widget_data_get(obj);
52 _elm_theme_object_icon_set(obj, wd->img, wd->stdicon, "default");
57 _sizing_eval(Evas_Object *obj)
59 Widget_Data *wd = elm_widget_data_get(obj);
61 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
64 _els_smart_icon_size_get(wd->img, &w, &h);
65 _els_smart_icon_scale_up_set(wd->img, wd->scale_up);
66 _els_smart_icon_scale_down_set(wd->img, wd->scale_down);
67 _els_smart_icon_smooth_scale_set(wd->img, wd->smooth);
68 _els_smart_icon_fill_inside_set(wd->img, !(wd->fill_outside));
69 if (wd->no_scale) _els_smart_icon_scale_set(wd->img, 1.0);
72 _els_smart_icon_scale_set(wd->img, elm_widget_scale_get(obj) *
74 _els_smart_icon_size_get(wd->img, &w, &h);
86 evas_object_size_hint_min_set(obj, minw, minh);
87 evas_object_size_hint_max_set(obj, maxw, maxh);
91 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
93 Evas_Event_Mouse_Up *ev = event_info;
94 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
95 evas_object_smart_callback_call(data, "clicked", event_info);
99 * Add a new icon to the parent
101 * @param parent The parent object
102 * @return The new object or NULL if it cannot be created
107 elm_icon_add(Evas_Object *parent)
113 wd = ELM_NEW(Widget_Data);
114 e = evas_object_evas_get(parent);
115 obj = elm_widget_add(e);
116 ELM_SET_WIDTYPE(widtype, "icon");
117 elm_widget_type_set(obj, "icon");
118 elm_widget_sub_object_add(parent, obj);
119 elm_widget_data_set(obj, wd);
120 elm_widget_del_hook_set(obj, _del_hook);
121 elm_widget_theme_hook_set(obj, _theme_hook);
122 elm_widget_can_focus_set(obj, 0);
124 wd->img = _els_smart_icon_add(e);
125 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
127 evas_object_repeat_events_set(wd->img, 1);
128 elm_widget_resize_object_set(obj, wd->img);
130 wd->smooth = EINA_TRUE;
131 wd->scale_up = EINA_TRUE;
132 wd->scale_down = EINA_TRUE;
139 * Set the file that will be used as icon
141 * @param obj The icon object
142 * @param file The path to file that will be used as icon
143 * @param group The group that the icon belongs in edje file
145 * @return (1 = sucess, 0 = error)
150 elm_icon_file_set(Evas_Object *obj, const char *file, const char *group)
152 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
153 Widget_Data *wd = elm_widget_data_get(obj);
157 if ((!wd) || (!file)) return EINA_FALSE;
158 if (wd->stdicon) eina_stringshare_del(wd->stdicon);
160 if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
161 ret = _els_smart_icon_file_edje_set(wd->img, file, group);
163 ret = _els_smart_icon_file_key_set(wd->img, file, group);
169 * Set the theme, as standard, for a icon
171 * @param obj The icon object
172 * @param name The theme name
174 * @return (1 = sucess, 0 = error)
179 elm_icon_standard_set(Evas_Object *obj, const char *name)
181 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
182 Widget_Data *wd = elm_widget_data_get(obj);
185 if ((!wd) || (!name)) return EINA_FALSE;
186 eina_stringshare_replace(&wd->stdicon, name);
187 ret = _elm_theme_object_icon_set(obj, wd->img, name, "default");
193 * Set the smooth effect for a icon
195 * @param obj The icon object
196 * @param smooth A bool to set (or no) smooth effect
197 * (1 = smooth, 0 = not smooth)
202 elm_icon_smooth_set(Evas_Object *obj, Eina_Bool smooth)
204 ELM_CHECK_WIDTYPE(obj, widtype);
205 Widget_Data *wd = elm_widget_data_get(obj);
213 * Set if the object are scalable
215 * @param obj The icon object
216 * @param no_scale A bool to set scale (or no)
217 * (1 = no_scale, 0 = scale)
222 elm_icon_no_scale_set(Evas_Object *obj, Eina_Bool no_scale)
224 ELM_CHECK_WIDTYPE(obj, widtype);
225 Widget_Data *wd = elm_widget_data_get(obj);
228 wd->no_scale = no_scale;
233 * Set if the object is (up/down) scalable
235 * @param obj The icon object
236 * @param scale_up A bool to set if the object is scalable up
237 * @param scale_down A bool to set if the object is scalable down
242 elm_icon_scale_set(Evas_Object *obj, Eina_Bool scale_up, Eina_Bool scale_down)
244 ELM_CHECK_WIDTYPE(obj, widtype);
245 Widget_Data *wd = elm_widget_data_get(obj);
248 wd->scale_up = scale_up;
249 wd->scale_down = scale_down;
254 * Set if the object is filled outside
256 * @param obj The icon object
257 * @param fill_outside A bool to set if the object is filled outside
258 * (1 = filled, 0 = no filled)
263 elm_icon_fill_outside_set(Evas_Object *obj, Eina_Bool fill_outside)
265 ELM_CHECK_WIDTYPE(obj, widtype);
266 Widget_Data *wd = elm_widget_data_get(obj);
269 wd->fill_outside = fill_outside;
275 * Set the prescale size for the icon
277 * @param obj The icon object
278 * @param size The prescale size
283 elm_icon_prescale_set(Evas_Object *obj, int size)
285 ELM_CHECK_WIDTYPE(obj, widtype);
286 Widget_Data *wd = elm_widget_data_get(obj);
289 _els_smart_icon_scale_size_set(wd->img, size);