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
17 typedef struct _Widget_Data Widget_Data;
22 Eina_Bool scale_up : 1;
23 Eina_Bool scale_down : 1;
25 Eina_Bool fill_outside : 1;
26 Eina_Bool no_scale : 1;
29 static const char *widtype = NULL;
30 static void _del_hook(Evas_Object *obj);
31 static void _theme_hook(Evas_Object *obj);
32 static void _sizing_eval(Evas_Object *obj);
33 static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
35 static const char SIG_CLICKED[] = "clicked";
37 static const Evas_Smart_Cb_Description _signals[] = {
44 _del_hook(Evas_Object *obj)
46 Widget_Data *wd = elm_widget_data_get(obj);
53 _del_pre_hook(Evas_Object *obj)
55 Widget_Data *wd = elm_widget_data_get(obj);
58 evas_object_del(wd->img);
62 _theme_hook(Evas_Object *obj)
64 Widget_Data *wd = elm_widget_data_get(obj);
71 _sizing_eval(Evas_Object *obj)
73 Widget_Data *wd = elm_widget_data_get(obj);
74 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
78 _els_smart_icon_size_get(wd->img, &w, &h);
79 _els_smart_icon_scale_up_set(wd->img, wd->scale_up);
80 _els_smart_icon_scale_down_set(wd->img, wd->scale_down);
81 _els_smart_icon_smooth_scale_set(wd->img, wd->smooth);
82 _els_smart_icon_fill_inside_set(wd->img, !(wd->fill_outside));
83 if (wd->no_scale) _els_smart_icon_scale_set(wd->img, 1.0);
86 _els_smart_icon_scale_set(wd->img, elm_widget_scale_get(obj) * _elm_config->scale);
87 _els_smart_icon_size_get(wd->img, &w, &h);
99 evas_object_size_hint_min_set(obj, minw, minh);
100 evas_object_size_hint_max_set(obj, maxw, maxh);
104 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
106 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
110 * Add a new image to the parent
112 * @param parent The parent object
113 * @return The new object or NULL if it cannot be created
118 elm_image_add(Evas_Object *parent)
124 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
126 ELM_SET_WIDTYPE(widtype, "image");
127 elm_widget_type_set(obj, "image");
128 elm_widget_sub_object_add(parent, obj);
129 elm_widget_data_set(obj, wd);
130 elm_widget_del_hook_set(obj, _del_hook);
131 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
132 elm_widget_theme_hook_set(obj, _theme_hook);
133 elm_widget_can_focus_set(obj, EINA_FALSE);
135 wd->img = _els_smart_icon_add(e);
136 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
138 evas_object_repeat_events_set(wd->img, EINA_TRUE);
139 elm_widget_resize_object_set(obj, wd->img);
141 evas_object_smart_callbacks_descriptions_set(obj, _signals);
143 wd->smooth = EINA_TRUE;
144 wd->scale_up = EINA_TRUE;
145 wd->scale_down = EINA_TRUE;
147 _els_smart_icon_scale_size_set(wd->img, 0);
154 * Set the file that will be used as image
156 * @param obj The image object
157 * @param file The path to file that will be used as image
158 * @param group The group that the image belongs in edje file
160 * @return (1 = success, 0 = error)
165 elm_image_file_set(Evas_Object *obj, const char *file, const char *group)
167 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
168 Widget_Data *wd = elm_widget_data_get(obj);
172 if (!wd) return EINA_FALSE;
173 EINA_SAFETY_ON_NULL_RETURN_VAL(file, EINA_FALSE);
174 if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
175 ret = _els_smart_icon_file_edje_set(wd->img, file, group);
177 ret = _els_smart_icon_file_key_set(wd->img, file, group);
183 * Get the file that will be used as image
185 * @param obj The image object
186 * @param file The path to file
187 * @param group The group that the image belongs in edje file
192 elm_image_file_get(const Evas_Object *obj, const char **file, const char **group)
194 ELM_CHECK_WIDTYPE(obj, widtype);
195 Widget_Data *wd = elm_widget_data_get(obj);
197 _els_smart_icon_file_get(wd->img, file, group);
201 * Set the smooth effect for a image
203 * @param obj The image object
204 * @param smooth A bool to set (or no) smooth effect
205 * (1 = smooth, 0 = not smooth)
210 elm_image_smooth_set(Evas_Object *obj, Eina_Bool smooth)
212 ELM_CHECK_WIDTYPE(obj, widtype);
213 Widget_Data *wd = elm_widget_data_get(obj);
221 * Get the smooth effect for a image
223 * @param obj The image object
224 * @return If setted smooth effect
229 elm_image_smooth_get(const Evas_Object *obj)
231 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
232 Widget_Data *wd = elm_widget_data_get(obj);
234 if (!wd) return EINA_FALSE;
239 * Gets the current size of the image.
241 * Either width or height (or both) may be NULL.
243 * On error, neither w or h will be written too.
245 * @param obj The image object.
246 * @param w Pointer to store width, or NULL.
247 * @param h Pointer to store height, or NULL.
252 elm_image_object_size_get(const Evas_Object *obj, int *w, int *h)
254 ELM_CHECK_WIDTYPE(obj, widtype);
255 Widget_Data *wd = elm_widget_data_get(obj);
258 _els_smart_icon_size_get(wd->img, w, h);
262 * Set if the object are scalable
264 * @param obj The image object.
265 * @param no_scale A bool to set scale (or no).
266 * (1 = no_scale, 0 = scale)
271 elm_image_no_scale_set(Evas_Object *obj, Eina_Bool no_scale)
273 ELM_CHECK_WIDTYPE(obj, widtype);
274 Widget_Data *wd = elm_widget_data_get(obj);
277 wd->no_scale = no_scale;
283 * Get if the object isn't scalable
285 * @param obj The image object
286 * @return If isn't scalable
291 elm_image_no_scale_get(const Evas_Object *obj)
293 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
294 Widget_Data *wd = elm_widget_data_get(obj);
295 if (!wd) return EINA_FALSE;
300 * Set if the object is (up/down) scalable
302 * @param obj The image object
303 * @param scale_up A bool to set if the object is scalable up
304 * @param scale_down A bool to set if the object is scalable down
309 elm_image_scale_set(Evas_Object *obj, Eina_Bool scale_up, Eina_Bool scale_down)
311 ELM_CHECK_WIDTYPE(obj, widtype);
312 Widget_Data *wd = elm_widget_data_get(obj);
315 wd->scale_up = scale_up;
316 wd->scale_down = scale_down;
321 * Get if the object is (up/down) scalable
323 * @param obj The image object
324 * @param scale_up A bool to set if the object is scalable up
325 * @param scale_down A bool to set if the object is scalable down
330 elm_image_scale_get(const Evas_Object *obj, Eina_Bool *scale_up, Eina_Bool *scale_down)
332 ELM_CHECK_WIDTYPE(obj, widtype);
333 Widget_Data *wd = elm_widget_data_get(obj);
335 if (scale_up) *scale_up = wd->scale_up;
336 if (scale_down) *scale_down = wd->scale_down;
340 * Set if the object is filled outside
342 * @param obj The image object
343 * @param fill_outside A bool to set if the object is filled outside
344 * (1 = filled, 0 = no filled)
349 elm_image_fill_outside_set(Evas_Object *obj, Eina_Bool fill_outside)
351 ELM_CHECK_WIDTYPE(obj, widtype);
352 Widget_Data *wd = elm_widget_data_get(obj);
355 wd->fill_outside = fill_outside;
360 * Get if the object is filled outside
362 * @param obj The image object
363 * @return If the object is filled outside
368 elm_image_fill_outside_get(const Evas_Object *obj)
370 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
371 Widget_Data *wd = elm_widget_data_get(obj);
373 if (!wd) return EINA_FALSE;
374 return wd->fill_outside;
378 * Set the prescale size for the image
380 * @param obj The image object
381 * @param size The prescale size
386 elm_image_prescale_set(Evas_Object *obj, int size)
388 ELM_CHECK_WIDTYPE(obj, widtype);
389 Widget_Data *wd = elm_widget_data_get(obj);
392 _els_smart_icon_scale_size_set(wd->img, size);
396 * Get the prescale size for the image
398 * @param obj The image object
399 * @return The prescale size
404 elm_image_prescale_get(const Evas_Object *obj)
406 ELM_CHECK_WIDTYPE(obj, widtype) 0;
407 Widget_Data *wd = elm_widget_data_get(obj);
410 return _els_smart_icon_scale_size_get(wd->img);
414 * Set the image orient
416 * @param obj The image object
417 * @param orient The image orient
418 * (ELM_IMAGE_ORIENT_NONE, ELM_IMAGE_ROTATE_90_CW,
419 * ELM_IMAGE_ROTATE_180_CW, ELM_IMAGE_ROTATE_90_CCW,
420 * ELM_IMAGE_FLIP_HORIZONTAL,ELM_IMAGE_FLIP_VERTICAL,
421 * ELM_IMAGE_FLIP_TRANSPOSE, ELM_IMAGE_FLIP_TRANSVERSE)
426 elm_image_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
428 ELM_CHECK_WIDTYPE(obj, widtype);
429 Widget_Data *wd = elm_widget_data_get(obj);
432 _els_smart_icon_orient_set(wd->img, orient);
436 * Get the image orient
438 * @param obj The image object
439 * @return The image orient
440 * (ELM_IMAGE_ORIENT_NONE, ELM_IMAGE_ROTATE_90_CW,
441 * ELM_IMAGE_ROTATE_180_CW, ELM_IMAGE_ROTATE_90_CCW,
442 * ELM_IMAGE_FLIP_HORIZONTAL,ELM_IMAGE_FLIP_VERTICAL,
443 * ELM_IMAGE_FLIP_TRANSPOSE, ELM_IMAGE_FLIP_TRANSVERSE)
447 EAPI Elm_Image_Orient
448 elm_image_orient_get(const Evas_Object *obj)
450 ELM_CHECK_WIDTYPE(obj, widtype) ELM_IMAGE_ORIENT_NONE;
451 Widget_Data *wd = elm_widget_data_get(obj);
452 if (!wd) return ELM_IMAGE_ORIENT_NONE;
453 return _els_smart_icon_orient_get(wd->img);
457 * Make the image 'editable'.
459 * This means the image is a valid drag target for drag and drop, and can be
462 * @param obj Image object.
463 * @param set Turn on or off editability.
468 elm_image_editable_set(Evas_Object *obj, Eina_Bool set)
470 ELM_CHECK_WIDTYPE(obj, widtype);
471 Widget_Data *wd = elm_widget_data_get(obj);
474 _els_smart_icon_edit_set(wd->img, set, obj);
478 * Make the image 'editable'.
480 * This means the image is a valid drag target for drag and drop, and can be
483 * @param obj Image object.
484 * @return Editability.
487 elm_image_editable_get(const Evas_Object *obj)
489 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
490 Widget_Data *wd = elm_widget_data_get(obj);
491 if (!wd) return EINA_FALSE;
492 return _els_smart_icon_edit_get(wd->img);
496 * Get the image object
498 * When you create a image with elm_image_add(). You can get this object (be
499 * careful to not manipulate it as it is under control of elementary), and use
500 * it to do things like get pixel data, save the image to a file, etc.
502 * @param obj The image object to get the inlined image from
503 * @return The inlined image object, or NULL if none exists
508 elm_image_object_get(const Evas_Object *obj)
510 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
511 Widget_Data *wd = elm_widget_data_get(obj);
512 if (!wd) return NULL;
513 return _els_smart_icon_object_get(wd->img);
517 * Enable/disable retaining up the aspect ratio of the image.
519 * @param obj The image object.
520 * @param retained Retaining or Non retaining.
525 elm_image_aspect_ratio_retained_set(Evas_Object *obj, Eina_Bool retained)
527 ELM_CHECK_WIDTYPE(obj, widtype);
528 Widget_Data *wd = elm_widget_data_get(obj);
530 return _els_smart_icon_aspect_ratio_retained_set(wd->img, retained);
534 * Get if the object retains the aspect ratio.
536 * @param obj The image object.
537 * @return If the object retains the aspect ratio.
542 elm_image_aspect_ratio_retained_get(const Evas_Object *obj)
544 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
545 Widget_Data *wd = elm_widget_data_get(obj);
546 if (!wd) return EINA_FALSE;
547 return _els_smart_icon_aspect_ratio_retained_get(wd->img);
550 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 :*/