1 #include <Elementary.h>
5 * @defgroup Image Image
7 * A standard image 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 image
15 * "drop" - Something has been dropped on the image
18 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);
46 _del_pre_hook(Evas_Object *obj)
48 Widget_Data *wd = elm_widget_data_get(obj);
51 evas_object_del(wd->img);
55 _theme_hook(Evas_Object *obj)
57 Widget_Data *wd = elm_widget_data_get(obj);
64 _sizing_eval(Evas_Object *obj)
66 Widget_Data *wd = elm_widget_data_get(obj);
67 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
71 _els_smart_icon_size_get(wd->img, &w, &h);
72 _els_smart_icon_scale_up_set(wd->img, wd->scale_up);
73 _els_smart_icon_scale_down_set(wd->img, wd->scale_down);
74 _els_smart_icon_smooth_scale_set(wd->img, wd->smooth);
75 _els_smart_icon_fill_inside_set(wd->img, !(wd->fill_outside));
76 if (wd->no_scale) _els_smart_icon_scale_set(wd->img, 1.0);
79 _els_smart_icon_scale_set(wd->img, elm_widget_scale_get(obj) * _elm_config->scale);
80 _els_smart_icon_size_get(wd->img, &w, &h);
92 evas_object_size_hint_min_set(obj, minw, minh);
93 evas_object_size_hint_max_set(obj, maxw, maxh);
97 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
99 evas_object_smart_callback_call(data, "clicked", NULL);
103 * Add a new image to the parent
105 * @param parent The parent object
106 * @return The new object or NULL if it cannot be created
111 elm_image_add(Evas_Object *parent)
117 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
119 ELM_SET_WIDTYPE(widtype, "image");
120 elm_widget_type_set(obj, "image");
121 elm_widget_sub_object_add(parent, obj);
122 elm_widget_data_set(obj, wd);
123 elm_widget_del_hook_set(obj, _del_hook);
124 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
125 elm_widget_theme_hook_set(obj, _theme_hook);
126 elm_widget_can_focus_set(obj, EINA_FALSE);
128 wd->img = _els_smart_icon_add(e);
129 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
131 evas_object_repeat_events_set(wd->img, EINA_TRUE);
132 elm_widget_resize_object_set(obj, wd->img);
134 wd->smooth = EINA_TRUE;
135 wd->scale_up = EINA_TRUE;
136 wd->scale_down = EINA_TRUE;
138 _els_smart_icon_scale_size_set(wd->img, 0);
145 * Set the file that will be used as image
147 * @param obj The image object
148 * @param file The path to file that will be used as image
149 * @param group The group that the image belongs in edje file
151 * @return (1 = success, 0 = error)
156 elm_image_file_set(Evas_Object *obj, const char *file, const char *group)
158 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
159 Widget_Data *wd = elm_widget_data_get(obj);
163 if (!wd) return EINA_FALSE;
164 EINA_SAFETY_ON_NULL_RETURN_VAL(file, EINA_FALSE);
165 if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
166 ret = _els_smart_icon_file_edje_set(wd->img, file, group);
168 ret = _els_smart_icon_file_key_set(wd->img, file, group);
174 * Get the file that will be used as image
176 * @param obj The image object
177 * @param file The path to file
178 * @param group The group that the image belongs in edje file
183 elm_image_file_get(const Evas_Object *obj, const char **file, const char **group)
185 ELM_CHECK_WIDTYPE(obj, widtype);
186 Widget_Data *wd = elm_widget_data_get(obj);
188 _els_smart_icon_file_get(wd->img, file, group);
192 * Set the smooth effect for a image
194 * @param obj The image object
195 * @param smooth A bool to set (or no) smooth effect
196 * (1 = smooth, 0 = not smooth)
201 elm_image_smooth_set(Evas_Object *obj, Eina_Bool smooth)
203 ELM_CHECK_WIDTYPE(obj, widtype);
204 Widget_Data *wd = elm_widget_data_get(obj);
212 * Get the smooth effect for a image
214 * @param obj The image object
215 * @return If setted smooth effect
220 elm_image_smooth_get(const Evas_Object *obj)
222 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
223 Widget_Data *wd = elm_widget_data_get(obj);
225 if (!wd) return EINA_FALSE;
230 * Gets the current size of the image.
232 * Either width or height (or both) may be NULL.
234 * On error, neither w or h will be written too.
236 * @param obj The image object.
237 * @param w Pointer to store width, or NULL.
238 * @param h Pointer to store height, or NULL.
241 elm_image_object_size_get(const Evas_Object *obj, int *w, int *h)
243 ELM_CHECK_WIDTYPE(obj, widtype);
244 Widget_Data *wd = elm_widget_data_get(obj);
247 _els_smart_icon_size_get(wd->img, w, h);
251 * Set if the object are scalable
253 * @param obj The image object.
254 * @param no_scale A bool to set scale (or no).
255 * (1 = no_scale, 0 = scale)
260 elm_image_no_scale_set(Evas_Object *obj, Eina_Bool no_scale)
262 ELM_CHECK_WIDTYPE(obj, widtype);
263 Widget_Data *wd = elm_widget_data_get(obj);
266 wd->no_scale = no_scale;
272 * Get if the object isn't scalable
274 * @param obj The image object
275 * @return If isn't scalable
280 elm_image_no_scale_get(const Evas_Object *obj)
282 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
283 Widget_Data *wd = elm_widget_data_get(obj);
284 if (!wd) return EINA_FALSE;
289 * Set if the object is (up/down) scalable
291 * @param obj The image object
292 * @param scale_up A bool to set if the object is scalable up
293 * @param scale_down A bool to set if the object is scalable down
298 elm_image_scale_set(Evas_Object *obj, Eina_Bool scale_up, Eina_Bool scale_down)
300 ELM_CHECK_WIDTYPE(obj, widtype);
301 Widget_Data *wd = elm_widget_data_get(obj);
304 wd->scale_up = scale_up;
305 wd->scale_down = scale_down;
310 * Get if the object is (up/down) scalable
312 * @param obj The image object
313 * @param scale_up A bool to set if the object is scalable up
314 * @param scale_down A bool to set if the object is scalable down
319 elm_image_scale_get(const Evas_Object *obj, Eina_Bool *scale_up, Eina_Bool *scale_down)
321 ELM_CHECK_WIDTYPE(obj, widtype);
322 Widget_Data *wd = elm_widget_data_get(obj);
324 if (scale_up) *scale_up = wd->scale_up;
325 if (scale_down) *scale_down = wd->scale_down;
329 * Set if the object is filled outside
331 * @param obj The image object
332 * @param fill_outside A bool to set if the object is filled outside
333 * (1 = filled, 0 = no filled)
338 elm_image_fill_outside_set(Evas_Object *obj, Eina_Bool fill_outside)
340 ELM_CHECK_WIDTYPE(obj, widtype);
341 Widget_Data *wd = elm_widget_data_get(obj);
344 wd->fill_outside = fill_outside;
349 * Get if the object is filled outside
351 * @param obj The image object
352 * @return If the object is filled outside
357 elm_image_fill_outside_get(const Evas_Object *obj)
359 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
360 Widget_Data *wd = elm_widget_data_get(obj);
362 if (!wd) return EINA_FALSE;
363 return wd->fill_outside;
367 * Set the prescale size for the image
369 * @param obj The image object
370 * @param size The prescale size
375 elm_image_prescale_set(Evas_Object *obj, int size)
377 ELM_CHECK_WIDTYPE(obj, widtype);
378 Widget_Data *wd = elm_widget_data_get(obj);
381 _els_smart_icon_scale_size_set(wd->img, size);
385 * Get the prescale size for the image
387 * @param obj The image object
388 * @return The prescale size
393 elm_image_prescale_get(const Evas_Object *obj)
395 ELM_CHECK_WIDTYPE(obj, widtype) 0;
396 Widget_Data *wd = elm_widget_data_get(obj);
399 return _els_smart_icon_scale_size_get(wd->img);
403 * Set the image orient
405 * @param obj The image object
406 * @param orient The image orient
407 * (ELM_IMAGE_ORIENT_NONE, ELM_IMAGE_ROTATE_90_CW,
408 * ELM_IMAGE_ROTATE_180_CW, ELM_IMAGE_ROTATE_90_CCW,
409 * ELM_IMAGE_FLIP_HORIZONTAL,ELM_IMAGE_FLIP_VERTICAL,
410 * ELM_IMAGE_FLIP_TRANSPOSE, ELM_IMAGE_FLIP_TRANSVERSE)
415 elm_image_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
417 ELM_CHECK_WIDTYPE(obj, widtype);
418 Widget_Data *wd = elm_widget_data_get(obj);
421 _els_smart_icon_orient_set(wd->img, orient);
425 * Get the image orient
427 * @param obj The image object
428 * @return The image orient
429 * (ELM_IMAGE_ORIENT_NONE, ELM_IMAGE_ROTATE_90_CW,
430 * ELM_IMAGE_ROTATE_180_CW, ELM_IMAGE_ROTATE_90_CCW,
431 * ELM_IMAGE_FLIP_HORIZONTAL,ELM_IMAGE_FLIP_VERTICAL,
432 * ELM_IMAGE_FLIP_TRANSPOSE, ELM_IMAGE_FLIP_TRANSVERSE)
436 EAPI Elm_Image_Orient
437 elm_image_orient_get(const Evas_Object *obj)
439 ELM_CHECK_WIDTYPE(obj, widtype) ELM_IMAGE_ORIENT_NONE;
440 Widget_Data *wd = elm_widget_data_get(obj);
441 if (!wd) return ELM_IMAGE_ORIENT_NONE;
442 return _els_smart_icon_orient_get(wd->img);
446 * Make the image 'editable'.
448 * This means the image is a valid drag target for drag and drop, and can be
451 * @param obj Image object.
452 * @param set Turn on or off editability.
455 elm_image_editable_set(Evas_Object *obj, Eina_Bool set)
457 ELM_CHECK_WIDTYPE(obj, widtype);
458 Widget_Data *wd = elm_widget_data_get(obj);
461 _els_smart_icon_edit_set(wd->img, set, obj);
465 * Make the image 'editable'.
467 * This means the image is a valid drag target for drag and drop, and can be
470 * @param obj Image object.
471 * @return Editability.
474 elm_image_editable_get(const Evas_Object *obj)
476 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
477 Widget_Data *wd = elm_widget_data_get(obj);
478 if (!wd) return EINA_FALSE;
479 return _els_smart_icon_edit_get(wd->img);
483 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/