1 #include <Elementary.h>
8 * A standard icon that may be provided by the theme (delete, edit,
9 * arrows etc.) or a custom file (PNG, JPG, EDJE etc.) used for an
10 * icon. The Icon may scale or not and of course... support alpha
13 * Signals that you can add callbacks for are:
15 * clicked - This is called when a user has clicked the icon
18 typedef struct _Widget_Data Widget_Data;
24 Eina_Bool scale_up : 1;
25 Eina_Bool scale_down : 1;
27 Eina_Bool fill_outside : 1;
28 Eina_Bool no_scale : 1;
31 static const char *widtype = NULL;
32 static void _del_hook(Evas_Object *obj);
33 static void _theme_hook(Evas_Object *obj);
34 static void _sizing_eval(Evas_Object *obj);
35 static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
38 _del_hook(Evas_Object *obj)
40 Widget_Data *wd = elm_widget_data_get(obj);
43 if (wd->stdicon) eina_stringshare_del(wd->stdicon);
48 _theme_hook(Evas_Object *obj)
50 Widget_Data *wd = elm_widget_data_get(obj);
53 _elm_theme_object_icon_set(obj, wd->img, wd->stdicon, elm_widget_style_get(obj));
58 _sizing_eval(Evas_Object *obj)
60 Widget_Data *wd = elm_widget_data_get(obj);
62 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
65 _els_smart_icon_size_get(wd->img, &w, &h);
66 _els_smart_icon_scale_up_set(wd->img, wd->scale_up);
67 _els_smart_icon_scale_down_set(wd->img, wd->scale_down);
68 _els_smart_icon_smooth_scale_set(wd->img, wd->smooth);
69 _els_smart_icon_fill_inside_set(wd->img, !(wd->fill_outside));
70 if (wd->no_scale) _els_smart_icon_scale_set(wd->img, 1.0);
73 _els_smart_icon_scale_set(wd->img, elm_widget_scale_get(obj) *
75 _els_smart_icon_size_get(wd->img, &w, &h);
87 evas_object_size_hint_min_set(obj, minw, minh);
88 evas_object_size_hint_max_set(obj, maxw, maxh);
92 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
94 Evas_Event_Mouse_Up *ev = event_info;
95 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
96 evas_object_smart_callback_call(data, "clicked", event_info);
100 * Add a new icon to the parent
102 * @param parent The parent object
103 * @return The new object or NULL if it cannot be created
108 elm_icon_add(Evas_Object *parent)
114 wd = ELM_NEW(Widget_Data);
115 e = evas_object_evas_get(parent);
116 obj = elm_widget_add(e);
117 ELM_SET_WIDTYPE(widtype, "icon");
118 elm_widget_type_set(obj, "icon");
119 elm_widget_can_focus_set(obj, EINA_FALSE);
120 elm_widget_sub_object_add(parent, obj);
121 elm_widget_data_set(obj, wd);
122 elm_widget_del_hook_set(obj, _del_hook);
123 elm_widget_theme_hook_set(obj, _theme_hook);
125 wd->img = _els_smart_icon_add(e);
126 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
128 evas_object_repeat_events_set(wd->img, 1);
129 elm_widget_resize_object_set(obj, wd->img);
131 wd->smooth = EINA_TRUE;
132 wd->scale_up = EINA_TRUE;
133 wd->scale_down = EINA_TRUE;
140 * Set the file that will be used as icon
142 * @param obj The icon object
143 * @param file The path to file that will be used as icon
144 * @param group The group that the icon belongs in edje file
146 * @return (1 = sucess, 0 = error)
151 elm_icon_file_set(Evas_Object *obj, const char *file, const char *group)
153 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
154 Widget_Data *wd = elm_widget_data_get(obj);
158 if ((!wd) || (!file)) return EINA_FALSE;
159 if (wd->stdicon) eina_stringshare_del(wd->stdicon);
161 if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
162 ret = _els_smart_icon_file_edje_set(wd->img, file, group);
164 ret = _els_smart_icon_file_key_set(wd->img, file, group);
170 * Set the theme, as standard, for a icon
172 * @param obj The icon object
173 * @param name The theme name
175 * @return (1 = sucess, 0 = error)
180 elm_icon_standard_set(Evas_Object *obj, const char *name)
182 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
183 Widget_Data *wd = elm_widget_data_get(obj);
186 if ((!wd) || (!name)) return EINA_FALSE;
187 eina_stringshare_replace(&wd->stdicon, name);
188 ret = _elm_theme_object_icon_set(obj, wd->img, name, "default");
194 * Set the smooth effect for a icon
196 * @param obj The icon object
197 * @param smooth A bool to set (or no) smooth effect
198 * (1 = smooth, 0 = not smooth)
203 elm_icon_smooth_set(Evas_Object *obj, Eina_Bool smooth)
205 ELM_CHECK_WIDTYPE(obj, widtype);
206 Widget_Data *wd = elm_widget_data_get(obj);
214 * Set if the object are scalable
216 * @param obj The icon object
217 * @param no_scale A bool to set scale (or no)
218 * (1 = no_scale, 0 = scale)
223 elm_icon_no_scale_set(Evas_Object *obj, Eina_Bool no_scale)
225 ELM_CHECK_WIDTYPE(obj, widtype);
226 Widget_Data *wd = elm_widget_data_get(obj);
229 wd->no_scale = no_scale;
234 * Set if the object is (up/down) scalable
236 * @param obj The icon object
237 * @param scale_up A bool to set if the object is scalable up
238 * @param scale_down A bool to set if the object is scalable down
243 elm_icon_scale_set(Evas_Object *obj, Eina_Bool scale_up, Eina_Bool scale_down)
245 ELM_CHECK_WIDTYPE(obj, widtype);
246 Widget_Data *wd = elm_widget_data_get(obj);
249 wd->scale_up = scale_up;
250 wd->scale_down = scale_down;
255 * Set if the object is filled outside
257 * @param obj The icon object
258 * @param fill_outside A bool to set if the object is filled outside
259 * (1 = filled, 0 = no filled)
264 elm_icon_fill_outside_set(Evas_Object *obj, Eina_Bool fill_outside)
266 ELM_CHECK_WIDTYPE(obj, widtype);
267 Widget_Data *wd = elm_widget_data_get(obj);
270 wd->fill_outside = fill_outside;
276 * Set the prescale size for the icon
278 * @param obj The icon object
279 * @param size The prescale size
284 elm_icon_prescale_set(Evas_Object *obj, int size)
286 ELM_CHECK_WIDTYPE(obj, widtype);
287 Widget_Data *wd = elm_widget_data_get(obj);
290 _els_smart_icon_scale_size_set(wd->img, size);