1 #include <Elementary.h>
5 * @defgroup Image Image
8 * A standard image 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 image
16 * "drop" - Something has been dropped on the image
19 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);
47 _del_pre_hook(Evas_Object *obj)
49 Widget_Data *wd = elm_widget_data_get(obj);
52 evas_object_del(wd->img);
56 _theme_hook(Evas_Object *obj)
58 Widget_Data *wd = elm_widget_data_get(obj);
65 _sizing_eval(Evas_Object *obj)
67 Widget_Data *wd = elm_widget_data_get(obj);
68 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
72 _els_smart_icon_size_get(wd->img, &w, &h);
73 _els_smart_icon_scale_up_set(wd->img, wd->scale_up);
74 _els_smart_icon_scale_down_set(wd->img, wd->scale_down);
75 _els_smart_icon_smooth_scale_set(wd->img, wd->smooth);
76 _els_smart_icon_fill_inside_set(wd->img, !(wd->fill_outside));
77 if (wd->no_scale) _els_smart_icon_scale_set(wd->img, 1.0);
80 _els_smart_icon_scale_set(wd->img, elm_widget_scale_get(obj) * _elm_config->scale);
81 _els_smart_icon_size_get(wd->img, &w, &h);
93 evas_object_size_hint_min_set(obj, minw, minh);
94 evas_object_size_hint_max_set(obj, maxw, maxh);
98 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
100 evas_object_smart_callback_call(data, "clicked", NULL);
104 * Add a new image to the parent
106 * @param parent The parent object
107 * @return The new object or NULL if it cannot be created
112 elm_image_add(Evas_Object *parent)
118 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
120 ELM_SET_WIDTYPE(widtype, "image");
121 elm_widget_type_set(obj, "image");
122 elm_widget_sub_object_add(parent, obj);
123 elm_widget_data_set(obj, wd);
124 elm_widget_del_hook_set(obj, _del_hook);
125 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
126 elm_widget_theme_hook_set(obj, _theme_hook);
127 elm_widget_can_focus_set(obj, EINA_FALSE);
129 wd->img = _els_smart_icon_add(e);
130 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
132 evas_object_repeat_events_set(wd->img, EINA_TRUE);
133 elm_widget_resize_object_set(obj, wd->img);
135 wd->smooth = EINA_TRUE;
136 wd->scale_up = EINA_TRUE;
137 wd->scale_down = EINA_TRUE;
139 _els_smart_icon_scale_size_set(wd->img, 0);
146 * Set the file that will be used as image
148 * @param obj The image object
149 * @param file The path to file that will be used as image
150 * @param group The group that the image belongs in edje file
152 * @return (1 = success, 0 = error)
157 elm_image_file_set(Evas_Object *obj, const char *file, const char *group)
159 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
160 Widget_Data *wd = elm_widget_data_get(obj);
164 if (!wd) return EINA_FALSE;
165 EINA_SAFETY_ON_NULL_RETURN_VAL(file, EINA_FALSE);
166 if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
167 ret = _els_smart_icon_file_edje_set(wd->img, file, group);
169 ret = _els_smart_icon_file_key_set(wd->img, file, group);
175 * Get the file that will be used as image
177 * @param obj The image object
178 * @param file The path to file
179 * @param group The group that the image belongs in edje file
184 elm_image_file_get(const Evas_Object *obj, const char **file, const char **group)
186 ELM_CHECK_WIDTYPE(obj, widtype);
187 Widget_Data *wd = elm_widget_data_get(obj);
189 _els_smart_icon_file_get(wd->img, file, group);
193 * Set the smooth effect for a image
195 * @param obj The image object
196 * @param smooth A bool to set (or no) smooth effect
197 * (1 = smooth, 0 = not smooth)
202 elm_image_smooth_set(Evas_Object *obj, Eina_Bool smooth)
204 ELM_CHECK_WIDTYPE(obj, widtype);
205 Widget_Data *wd = elm_widget_data_get(obj);
213 * Get the smooth effect for a image
215 * @param obj The image object
216 * @return If setted smooth effect
221 elm_image_smooth_get(const Evas_Object *obj)
223 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
224 Widget_Data *wd = elm_widget_data_get(obj);
226 if (!wd) return EINA_FALSE;
231 * Gets the current size of the image.
233 * Either width or height (or both) may be NULL.
235 * On error, neither w or h will be written too.
237 * @param obj The image object.
238 * @param w Pointer to store width, or NULL.
239 * @param h Pointer to store height, or NULL.
242 elm_image_object_size_get(const Evas_Object *obj, int *w, int *h)
244 ELM_CHECK_WIDTYPE(obj, widtype);
245 Widget_Data *wd = elm_widget_data_get(obj);
248 _els_smart_icon_size_get(wd->img, w, h);
252 * Set if the object are scalable
254 * @param obj The image object.
255 * @param no_scale A bool to set scale (or no).
256 * (1 = no_scale, 0 = scale)
261 elm_image_no_scale_set(Evas_Object *obj, Eina_Bool no_scale)
263 ELM_CHECK_WIDTYPE(obj, widtype);
264 Widget_Data *wd = elm_widget_data_get(obj);
267 wd->no_scale = no_scale;
273 * Get if the object isn't scalable
275 * @param obj The image object
276 * @return If isn't scalable
281 elm_image_no_scale_get(const Evas_Object *obj)
283 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
284 Widget_Data *wd = elm_widget_data_get(obj);
285 if (!wd) return EINA_FALSE;
290 * Set if the object is (up/down) scalable
292 * @param obj The image object
293 * @param scale_up A bool to set if the object is scalable up
294 * @param scale_down A bool to set if the object is scalable down
299 elm_image_scale_set(Evas_Object *obj, Eina_Bool scale_up, Eina_Bool scale_down)
301 ELM_CHECK_WIDTYPE(obj, widtype);
302 Widget_Data *wd = elm_widget_data_get(obj);
305 wd->scale_up = scale_up;
306 wd->scale_down = scale_down;
311 * Get if the object is (up/down) scalable
313 * @param obj The image object
314 * @param scale_up A bool to set if the object is scalable up
315 * @param scale_down A bool to set if the object is scalable down
320 elm_image_scale_get(const Evas_Object *obj, Eina_Bool *scale_up, Eina_Bool *scale_down)
322 ELM_CHECK_WIDTYPE(obj, widtype);
323 Widget_Data *wd = elm_widget_data_get(obj);
325 if (scale_up) *scale_up = wd->scale_up;
326 if (scale_down) *scale_down = wd->scale_down;
330 * Set if the object is filled outside
332 * @param obj The image object
333 * @param fill_outside A bool to set if the object is filled outside
334 * (1 = filled, 0 = no filled)
339 elm_image_fill_outside_set(Evas_Object *obj, Eina_Bool fill_outside)
341 ELM_CHECK_WIDTYPE(obj, widtype);
342 Widget_Data *wd = elm_widget_data_get(obj);
345 wd->fill_outside = fill_outside;
350 * Get if the object is filled outside
352 * @param obj The image object
353 * @return If the object is filled outside
358 elm_image_fill_outside_get(const Evas_Object *obj)
360 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
361 Widget_Data *wd = elm_widget_data_get(obj);
363 if (!wd) return EINA_FALSE;
364 return wd->fill_outside;
368 * Set the prescale size for the image
370 * @param obj The image object
371 * @param size The prescale size
376 elm_image_prescale_set(Evas_Object *obj, int size)
378 ELM_CHECK_WIDTYPE(obj, widtype);
379 Widget_Data *wd = elm_widget_data_get(obj);
382 _els_smart_icon_scale_size_set(wd->img, size);
386 * Get the prescale size for the image
388 * @param obj The image object
389 * @return The prescale size
394 elm_image_prescale_get(const Evas_Object *obj)
396 ELM_CHECK_WIDTYPE(obj, widtype) 0;
397 Widget_Data *wd = elm_widget_data_get(obj);
400 return _els_smart_icon_scale_size_get(wd->img);
404 * Set the image orient
406 * @param obj The image object
407 * @param orient The image orient
408 * (ELM_IMAGE_ORIENT_NONE, ELM_IMAGE_ROTATE_90_CW,
409 * ELM_IMAGE_ROTATE_180_CW, ELM_IMAGE_ROTATE_90_CCW,
410 * ELM_IMAGE_FLIP_HORIZONTAL,ELM_IMAGE_FLIP_VERTICAL,
411 * ELM_IMAGE_FLIP_TRANSPOSE, ELM_IMAGE_FLIP_TRANSVERSE)
416 elm_image_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
418 ELM_CHECK_WIDTYPE(obj, widtype);
419 Widget_Data *wd = elm_widget_data_get(obj);
422 _els_smart_icon_orient_set(wd->img, orient);
426 * Get the image orient
428 * @param obj The image object
429 * @return The image orient
430 * (ELM_IMAGE_ORIENT_NONE, ELM_IMAGE_ROTATE_90_CW,
431 * ELM_IMAGE_ROTATE_180_CW, ELM_IMAGE_ROTATE_90_CCW,
432 * ELM_IMAGE_FLIP_HORIZONTAL,ELM_IMAGE_FLIP_VERTICAL,
433 * ELM_IMAGE_FLIP_TRANSPOSE, ELM_IMAGE_FLIP_TRANSVERSE)
437 EAPI Elm_Image_Orient
438 elm_image_orient_get(const Evas_Object *obj)
440 ELM_CHECK_WIDTYPE(obj, widtype) ELM_IMAGE_ORIENT_NONE;
441 Widget_Data *wd = elm_widget_data_get(obj);
442 if (!wd) return ELM_IMAGE_ORIENT_NONE;
443 return _els_smart_icon_orient_get(wd->img);
447 * Make the image 'editable'.
449 * This means the image is a valid drag target for drag and drop, and can be
452 * @param obj Image object.
453 * @param set Turn on or off editability.
456 elm_image_editable_set(Evas_Object *obj, Eina_Bool set)
458 ELM_CHECK_WIDTYPE(obj, widtype);
459 Widget_Data *wd = elm_widget_data_get(obj);
462 _els_smart_icon_edit_set(wd->img, set, obj);
466 * Make the image 'editable'.
468 * This means the image is a valid drag target for drag and drop, and can be
471 * @param obj Image object.
472 * @return Editability.
475 elm_image_editable_get(const Evas_Object *obj)
477 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
478 Widget_Data *wd = elm_widget_data_get(obj);
479 if (!wd) return EINA_FALSE;
480 return _els_smart_icon_edit_get(wd->img);
485 * Enable/disable retaining up the aspect ratio of the image.
487 * @param obj The image object.
488 * @param retained Retaining or Non retaining.
493 elm_image_aspect_ratio_retained_set(Evas_Object *obj, Eina_Bool retained)
495 ELM_CHECK_WIDTYPE(obj, widtype);
496 Widget_Data *wd = elm_widget_data_get(obj);
498 return _els_smart_icon_aspect_ratio_retained_set(wd->img, retained);
502 * Get if the object retains the aspect ratio.
504 * @param obj The image object.
505 * @return If the object retains the aspect ratio.
510 elm_image_aspect_ratio_retained_get(const Evas_Object *obj)
512 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
513 Widget_Data *wd = elm_widget_data_get(obj);
514 if (!wd) return EINA_FALSE;
515 return _els_smart_icon_aspect_ratio_retained_get(wd->img);
518 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 :*/