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 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
120 wd = ELM_NEW(Widget_Data);
121 e = evas_object_evas_get(parent);
123 obj = elm_widget_add(e);
124 ELM_SET_WIDTYPE(widtype, "image");
125 elm_widget_type_set(obj, "image");
126 elm_widget_sub_object_add(parent, obj);
127 elm_widget_data_set(obj, wd);
128 elm_widget_del_hook_set(obj, _del_hook);
129 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
130 elm_widget_theme_hook_set(obj, _theme_hook);
131 elm_widget_can_focus_set(obj, EINA_FALSE);
133 wd->img = _els_smart_icon_add(e);
134 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
136 evas_object_repeat_events_set(wd->img, EINA_TRUE);
137 elm_widget_resize_object_set(obj, wd->img);
139 wd->smooth = EINA_TRUE;
140 wd->scale_up = EINA_TRUE;
141 wd->scale_down = EINA_TRUE;
143 _els_smart_icon_scale_size_set(wd->img, 0);
150 * Set the file that will be used as image
152 * @param obj The image object
153 * @param file The path to file that will be used as image
154 * @param group The group that the image belongs in edje file
156 * @return (1 = success, 0 = error)
161 elm_image_file_set(Evas_Object *obj, const char *file, const char *group)
163 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
164 Widget_Data *wd = elm_widget_data_get(obj);
168 if (!wd) return EINA_FALSE;
169 EINA_SAFETY_ON_NULL_RETURN_VAL(file, EINA_FALSE);
170 if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
171 ret = _els_smart_icon_file_edje_set(wd->img, file, group);
173 ret = _els_smart_icon_file_key_set(wd->img, file, group);
179 * Get the file that will be used as image
181 * @param obj The image object
182 * @param file The path to file
183 * @param group The group that the image belongs in edje file
188 elm_image_file_get(const Evas_Object *obj, const char **file, const char **group)
190 ELM_CHECK_WIDTYPE(obj, widtype);
191 Widget_Data *wd = elm_widget_data_get(obj);
193 _els_smart_icon_file_get(wd->img, file, group);
197 * Set the smooth effect for a image
199 * @param obj The image object
200 * @param smooth A bool to set (or no) smooth effect
201 * (1 = smooth, 0 = not smooth)
206 elm_image_smooth_set(Evas_Object *obj, Eina_Bool smooth)
208 ELM_CHECK_WIDTYPE(obj, widtype);
209 Widget_Data *wd = elm_widget_data_get(obj);
217 * Get the smooth effect for a image
219 * @param obj The image object
220 * @return If setted smooth effect
225 elm_image_smooth_get(const Evas_Object *obj)
227 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
228 Widget_Data *wd = elm_widget_data_get(obj);
230 if (!wd) return EINA_FALSE;
235 * Gets the current size of the image.
237 * Either width or height (or both) may be NULL.
239 * On error, neither w or h will be written too.
241 * @param obj The image object.
242 * @param w Pointer to store width, or NULL.
243 * @param h Pointer to store height, or NULL.
246 elm_image_object_size_get(const Evas_Object *obj, int *w, int *h)
248 ELM_CHECK_WIDTYPE(obj, widtype);
249 Widget_Data *wd = elm_widget_data_get(obj);
252 _els_smart_icon_size_get(wd->img, w, h);
256 * Set if the object are scalable
258 * @param obj The image object.
259 * @param no_scale A bool to set scale (or no).
260 * (1 = no_scale, 0 = scale)
265 elm_image_no_scale_set(Evas_Object *obj, Eina_Bool no_scale)
267 ELM_CHECK_WIDTYPE(obj, widtype);
268 Widget_Data *wd = elm_widget_data_get(obj);
271 wd->no_scale = no_scale;
277 * Get if the object isn't scalable
279 * @param obj The image object
280 * @return If isn't scalable
285 elm_image_no_scale_get(const Evas_Object *obj)
287 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
288 Widget_Data *wd = elm_widget_data_get(obj);
289 if (!wd) return EINA_FALSE;
294 * Set if the object is (up/down) scalable
296 * @param obj The image object
297 * @param scale_up A bool to set if the object is scalable up
298 * @param scale_down A bool to set if the object is scalable down
303 elm_image_scale_set(Evas_Object *obj, Eina_Bool scale_up, Eina_Bool scale_down)
305 ELM_CHECK_WIDTYPE(obj, widtype);
306 Widget_Data *wd = elm_widget_data_get(obj);
309 wd->scale_up = scale_up;
310 wd->scale_down = scale_down;
315 * Get if the object is (up/down) scalable
317 * @param obj The image object
318 * @param scale_up A bool to set if the object is scalable up
319 * @param scale_down A bool to set if the object is scalable down
324 elm_image_scale_get(const Evas_Object *obj, Eina_Bool *scale_up, Eina_Bool *scale_down)
326 ELM_CHECK_WIDTYPE(obj, widtype);
327 Widget_Data *wd = elm_widget_data_get(obj);
329 if (scale_up) *scale_up = wd->scale_up;
330 if (scale_down) *scale_down = wd->scale_down;
334 * Set if the object is filled outside
336 * @param obj The image object
337 * @param fill_outside A bool to set if the object is filled outside
338 * (1 = filled, 0 = no filled)
343 elm_image_fill_outside_set(Evas_Object *obj, Eina_Bool fill_outside)
345 ELM_CHECK_WIDTYPE(obj, widtype);
346 Widget_Data *wd = elm_widget_data_get(obj);
349 wd->fill_outside = fill_outside;
354 * Get if the object is filled outside
356 * @param obj The image object
357 * @return If the object is filled outside
362 elm_image_fill_outside_get(const Evas_Object *obj)
364 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
365 Widget_Data *wd = elm_widget_data_get(obj);
367 if (!wd) return EINA_FALSE;
368 return wd->fill_outside;
372 * Set the prescale size for the image
374 * @param obj The image object
375 * @param size The prescale size
380 elm_image_prescale_set(Evas_Object *obj, int size)
382 ELM_CHECK_WIDTYPE(obj, widtype);
383 Widget_Data *wd = elm_widget_data_get(obj);
386 _els_smart_icon_scale_size_set(wd->img, size);
390 * Get the prescale size for the image
392 * @param obj The image object
393 * @return The prescale size
398 elm_image_prescale_get(const Evas_Object *obj)
400 ELM_CHECK_WIDTYPE(obj, widtype) 0;
401 Widget_Data *wd = elm_widget_data_get(obj);
404 return _els_smart_icon_scale_size_get(wd->img);
408 * Set the image orient
410 * @param obj The image object
411 * @param orient The image orient
412 * (ELM_IMAGE_ORIENT_NONE, ELM_IMAGE_ROTATE_90_CW,
413 * ELM_IMAGE_ROTATE_180_CW, ELM_IMAGE_ROTATE_90_CCW,
414 * ELM_IMAGE_FLIP_HORIZONTAL,ELM_IMAGE_FLIP_VERTICAL,
415 * ELM_IMAGE_FLIP_TRANSPOSE, ELM_IMAGE_FLIP_TRANSVERSE)
420 elm_image_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
422 ELM_CHECK_WIDTYPE(obj, widtype);
423 Widget_Data *wd = elm_widget_data_get(obj);
426 _els_smart_icon_orient_set(wd->img, orient);
430 * Get the image orient
432 * @param obj The image object
433 * @return The image orient
434 * (ELM_IMAGE_ORIENT_NONE, ELM_IMAGE_ROTATE_90_CW,
435 * ELM_IMAGE_ROTATE_180_CW, ELM_IMAGE_ROTATE_90_CCW,
436 * ELM_IMAGE_FLIP_HORIZONTAL,ELM_IMAGE_FLIP_VERTICAL,
437 * ELM_IMAGE_FLIP_TRANSPOSE, ELM_IMAGE_FLIP_TRANSVERSE)
441 EAPI Elm_Image_Orient
442 elm_image_orient_get(const Evas_Object *obj)
444 ELM_CHECK_WIDTYPE(obj, widtype) ELM_IMAGE_ORIENT_NONE;
445 Widget_Data *wd = elm_widget_data_get(obj);
446 if (!wd) return ELM_IMAGE_ORIENT_NONE;
447 return _els_smart_icon_orient_get(wd->img);
451 * Make the image 'editable'.
453 * This means the image is a valid drag target for drag and drop, and can be
456 * @param obj Image object.
457 * @param set Turn on or off editability.
460 elm_image_editable_set(Evas_Object *obj, Eina_Bool set)
462 ELM_CHECK_WIDTYPE(obj, widtype);
463 Widget_Data *wd = elm_widget_data_get(obj);
466 _els_smart_icon_edit_set(wd->img, set, obj);
470 * Make the image 'editable'.
472 * This means the image is a valid drag target for drag and drop, and can be
475 * @param obj Image object.
476 * @return Editability.
479 elm_image_editable_get(const Evas_Object *obj)
481 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
482 Widget_Data *wd = elm_widget_data_get(obj);
483 if (!wd) return EINA_FALSE;
484 return _els_smart_icon_edit_get(wd->img);
488 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/