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
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);
36 static const char SIG_CLICKED[] = "clicked";
38 static const Evas_Smart_Cb_Description _signals[] = {
45 _del_hook(Evas_Object *obj)
47 Widget_Data *wd = elm_widget_data_get(obj);
54 _del_pre_hook(Evas_Object *obj)
56 Widget_Data *wd = elm_widget_data_get(obj);
59 evas_object_del(wd->img);
63 _theme_hook(Evas_Object *obj)
65 Widget_Data *wd = elm_widget_data_get(obj);
72 _sizing_eval(Evas_Object *obj)
74 Widget_Data *wd = elm_widget_data_get(obj);
75 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
79 _els_smart_icon_size_get(wd->img, &w, &h);
80 _els_smart_icon_scale_up_set(wd->img, wd->scale_up);
81 _els_smart_icon_scale_down_set(wd->img, wd->scale_down);
82 _els_smart_icon_smooth_scale_set(wd->img, wd->smooth);
83 _els_smart_icon_fill_inside_set(wd->img, !(wd->fill_outside));
84 if (wd->no_scale) _els_smart_icon_scale_set(wd->img, 1.0);
87 _els_smart_icon_scale_set(wd->img, elm_widget_scale_get(obj) * _elm_config->scale);
88 _els_smart_icon_size_get(wd->img, &w, &h);
100 evas_object_size_hint_min_set(obj, minw, minh);
101 evas_object_size_hint_max_set(obj, maxw, maxh);
105 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
107 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
111 * Add a new image to the parent
113 * @param parent The parent object
114 * @return The new object or NULL if it cannot be created
119 elm_image_add(Evas_Object *parent)
125 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
127 ELM_SET_WIDTYPE(widtype, "image");
128 elm_widget_type_set(obj, "image");
129 elm_widget_sub_object_add(parent, obj);
130 elm_widget_data_set(obj, wd);
131 elm_widget_del_hook_set(obj, _del_hook);
132 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
133 elm_widget_theme_hook_set(obj, _theme_hook);
134 elm_widget_can_focus_set(obj, EINA_FALSE);
136 wd->img = _els_smart_icon_add(e);
137 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
139 evas_object_repeat_events_set(wd->img, EINA_TRUE);
140 elm_widget_resize_object_set(obj, wd->img);
142 evas_object_smart_callbacks_descriptions_set(obj, _signals);
144 wd->smooth = EINA_TRUE;
145 wd->scale_up = EINA_TRUE;
146 wd->scale_down = EINA_TRUE;
148 _els_smart_icon_scale_size_set(wd->img, 0);
155 * Set the file that will be used as image
157 * @param obj The image object
158 * @param file The path to file that will be used as image
159 * @param group The group that the image belongs in edje file
161 * @return (1 = success, 0 = error)
166 elm_image_file_set(Evas_Object *obj, const char *file, const char *group)
168 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
169 Widget_Data *wd = elm_widget_data_get(obj);
173 if (!wd) return EINA_FALSE;
174 EINA_SAFETY_ON_NULL_RETURN_VAL(file, EINA_FALSE);
175 if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
176 ret = _els_smart_icon_file_edje_set(wd->img, file, group);
178 ret = _els_smart_icon_file_key_set(wd->img, file, group);
184 * Get the file that will be used as image
186 * @param obj The image object
187 * @param file The path to file
188 * @param group The group that the image belongs in edje file
193 elm_image_file_get(const Evas_Object *obj, const char **file, const char **group)
195 ELM_CHECK_WIDTYPE(obj, widtype);
196 Widget_Data *wd = elm_widget_data_get(obj);
198 _els_smart_icon_file_get(wd->img, file, group);
202 * Set the smooth effect for a image
204 * @param obj The image object
205 * @param smooth A bool to set (or no) smooth effect
206 * (1 = smooth, 0 = not smooth)
211 elm_image_smooth_set(Evas_Object *obj, Eina_Bool smooth)
213 ELM_CHECK_WIDTYPE(obj, widtype);
214 Widget_Data *wd = elm_widget_data_get(obj);
222 * Get the smooth effect for a image
224 * @param obj The image object
225 * @return If setted smooth effect
230 elm_image_smooth_get(const Evas_Object *obj)
232 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
233 Widget_Data *wd = elm_widget_data_get(obj);
235 if (!wd) return EINA_FALSE;
240 * Gets the current size of the image.
242 * Either width or height (or both) may be NULL.
244 * On error, neither w or h will be written too.
246 * @param obj The image object.
247 * @param w Pointer to store width, or NULL.
248 * @param h Pointer to store height, or NULL.
253 elm_image_object_size_get(const Evas_Object *obj, int *w, int *h)
255 ELM_CHECK_WIDTYPE(obj, widtype);
256 Widget_Data *wd = elm_widget_data_get(obj);
259 _els_smart_icon_size_get(wd->img, w, h);
263 * Set if the object are scalable
265 * @param obj The image object.
266 * @param no_scale A bool to set scale (or no).
267 * (1 = no_scale, 0 = scale)
272 elm_image_no_scale_set(Evas_Object *obj, Eina_Bool no_scale)
274 ELM_CHECK_WIDTYPE(obj, widtype);
275 Widget_Data *wd = elm_widget_data_get(obj);
278 wd->no_scale = no_scale;
284 * Get if the object isn't scalable
286 * @param obj The image object
287 * @return If isn't scalable
292 elm_image_no_scale_get(const Evas_Object *obj)
294 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
295 Widget_Data *wd = elm_widget_data_get(obj);
296 if (!wd) return EINA_FALSE;
301 * Set if the object is (up/down) scalable
303 * @param obj The image object
304 * @param scale_up A bool to set if the object is scalable up
305 * @param scale_down A bool to set if the object is scalable down
310 elm_image_scale_set(Evas_Object *obj, Eina_Bool scale_up, Eina_Bool scale_down)
312 ELM_CHECK_WIDTYPE(obj, widtype);
313 Widget_Data *wd = elm_widget_data_get(obj);
316 wd->scale_up = scale_up;
317 wd->scale_down = scale_down;
322 * Get if the object is (up/down) scalable
324 * @param obj The image object
325 * @param scale_up A bool to set if the object is scalable up
326 * @param scale_down A bool to set if the object is scalable down
331 elm_image_scale_get(const Evas_Object *obj, Eina_Bool *scale_up, Eina_Bool *scale_down)
333 ELM_CHECK_WIDTYPE(obj, widtype);
334 Widget_Data *wd = elm_widget_data_get(obj);
336 if (scale_up) *scale_up = wd->scale_up;
337 if (scale_down) *scale_down = wd->scale_down;
341 * Set if the object is filled outside
343 * @param obj The image object
344 * @param fill_outside A bool to set if the object is filled outside
345 * (1 = filled, 0 = no filled)
350 elm_image_fill_outside_set(Evas_Object *obj, Eina_Bool fill_outside)
352 ELM_CHECK_WIDTYPE(obj, widtype);
353 Widget_Data *wd = elm_widget_data_get(obj);
356 wd->fill_outside = fill_outside;
361 * Get if the object is filled outside
363 * @param obj The image object
364 * @return If the object is filled outside
369 elm_image_fill_outside_get(const Evas_Object *obj)
371 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
372 Widget_Data *wd = elm_widget_data_get(obj);
374 if (!wd) return EINA_FALSE;
375 return wd->fill_outside;
379 * Set the prescale size for the image
381 * @param obj The image object
382 * @param size The prescale size
387 elm_image_prescale_set(Evas_Object *obj, int size)
389 ELM_CHECK_WIDTYPE(obj, widtype);
390 Widget_Data *wd = elm_widget_data_get(obj);
393 _els_smart_icon_scale_size_set(wd->img, size);
397 * Get the prescale size for the image
399 * @param obj The image object
400 * @return The prescale size
405 elm_image_prescale_get(const Evas_Object *obj)
407 ELM_CHECK_WIDTYPE(obj, widtype) 0;
408 Widget_Data *wd = elm_widget_data_get(obj);
411 return _els_smart_icon_scale_size_get(wd->img);
415 * Set the image orient
417 * @param obj The image object
418 * @param orient The image orient
419 * (ELM_IMAGE_ORIENT_NONE, ELM_IMAGE_ROTATE_90_CW,
420 * ELM_IMAGE_ROTATE_180_CW, ELM_IMAGE_ROTATE_90_CCW,
421 * ELM_IMAGE_FLIP_HORIZONTAL,ELM_IMAGE_FLIP_VERTICAL,
422 * ELM_IMAGE_FLIP_TRANSPOSE, ELM_IMAGE_FLIP_TRANSVERSE)
427 elm_image_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
429 ELM_CHECK_WIDTYPE(obj, widtype);
430 Widget_Data *wd = elm_widget_data_get(obj);
433 _els_smart_icon_orient_set(wd->img, orient);
437 * Get the image orient
439 * @param obj The image object
440 * @return The image orient
441 * (ELM_IMAGE_ORIENT_NONE, ELM_IMAGE_ROTATE_90_CW,
442 * ELM_IMAGE_ROTATE_180_CW, ELM_IMAGE_ROTATE_90_CCW,
443 * ELM_IMAGE_FLIP_HORIZONTAL,ELM_IMAGE_FLIP_VERTICAL,
444 * ELM_IMAGE_FLIP_TRANSPOSE, ELM_IMAGE_FLIP_TRANSVERSE)
448 EAPI Elm_Image_Orient
449 elm_image_orient_get(const Evas_Object *obj)
451 ELM_CHECK_WIDTYPE(obj, widtype) ELM_IMAGE_ORIENT_NONE;
452 Widget_Data *wd = elm_widget_data_get(obj);
453 if (!wd) return ELM_IMAGE_ORIENT_NONE;
454 return _els_smart_icon_orient_get(wd->img);
458 * Make the image 'editable'.
460 * This means the image is a valid drag target for drag and drop, and can be
463 * @param obj Image object.
464 * @param set Turn on or off editability.
469 elm_image_editable_set(Evas_Object *obj, Eina_Bool set)
471 ELM_CHECK_WIDTYPE(obj, widtype);
472 Widget_Data *wd = elm_widget_data_get(obj);
475 _els_smart_icon_edit_set(wd->img, set, obj);
479 * Make the image 'editable'.
481 * This means the image is a valid drag target for drag and drop, and can be
484 * @param obj Image object.
485 * @return Editability.
488 elm_image_editable_get(const Evas_Object *obj)
490 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
491 Widget_Data *wd = elm_widget_data_get(obj);
492 if (!wd) return EINA_FALSE;
493 return _els_smart_icon_edit_get(wd->img);
497 * Get the image object
499 * When you create a image with elm_image_add(). You can get this object (be
500 * careful to not manipulate it as it is under control of elementary), and use
501 * it to do things like get pixel data, save the image to a file, etc.
503 * @param obj The image object to get the inlined image from
504 * @return The inlined image object, or NULL if none exists
509 elm_image_object_get(const Evas_Object *obj)
511 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
512 Widget_Data *wd = elm_widget_data_get(obj);
513 if (!wd) return NULL;
514 return _els_smart_icon_object_get(wd->img);
518 * Enable/disable retaining up the aspect ratio of the image.
520 * @param obj The image object.
521 * @param retained Retaining or Non retaining.
526 elm_image_aspect_ratio_retained_set(Evas_Object *obj, Eina_Bool retained)
528 ELM_CHECK_WIDTYPE(obj, widtype);
529 Widget_Data *wd = elm_widget_data_get(obj);
531 return _els_smart_icon_aspect_ratio_retained_set(wd->img, retained);
535 * Get if the object retains the aspect ratio.
537 * @param obj The image object.
538 * @return If the object retains the aspect ratio.
543 elm_image_aspect_ratio_retained_get(const Evas_Object *obj)
545 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
546 Widget_Data *wd = elm_widget_data_get(obj);
547 if (!wd) return EINA_FALSE;
548 return _els_smart_icon_aspect_ratio_retained_get(wd->img);
551 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 :*/