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.
250 elm_image_object_size_get(const Evas_Object *obj, int *w, int *h)
252 ELM_CHECK_WIDTYPE(obj, widtype);
253 Widget_Data *wd = elm_widget_data_get(obj);
256 _els_smart_icon_size_get(wd->img, w, h);
260 * Set if the object are scalable
262 * @param obj The image object.
263 * @param no_scale A bool to set scale (or no).
264 * (1 = no_scale, 0 = scale)
269 elm_image_no_scale_set(Evas_Object *obj, Eina_Bool no_scale)
271 ELM_CHECK_WIDTYPE(obj, widtype);
272 Widget_Data *wd = elm_widget_data_get(obj);
275 wd->no_scale = no_scale;
281 * Get if the object isn't scalable
283 * @param obj The image object
284 * @return If isn't scalable
289 elm_image_no_scale_get(const Evas_Object *obj)
291 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
292 Widget_Data *wd = elm_widget_data_get(obj);
293 if (!wd) return EINA_FALSE;
298 * Set if the object is (up/down) scalable
300 * @param obj The image object
301 * @param scale_up A bool to set if the object is scalable up
302 * @param scale_down A bool to set if the object is scalable down
307 elm_image_scale_set(Evas_Object *obj, Eina_Bool scale_up, Eina_Bool scale_down)
309 ELM_CHECK_WIDTYPE(obj, widtype);
310 Widget_Data *wd = elm_widget_data_get(obj);
313 wd->scale_up = scale_up;
314 wd->scale_down = scale_down;
319 * Get if the object is (up/down) scalable
321 * @param obj The image object
322 * @param scale_up A bool to set if the object is scalable up
323 * @param scale_down A bool to set if the object is scalable down
328 elm_image_scale_get(const Evas_Object *obj, Eina_Bool *scale_up, Eina_Bool *scale_down)
330 ELM_CHECK_WIDTYPE(obj, widtype);
331 Widget_Data *wd = elm_widget_data_get(obj);
333 if (scale_up) *scale_up = wd->scale_up;
334 if (scale_down) *scale_down = wd->scale_down;
338 * Set if the object is filled outside
340 * @param obj The image object
341 * @param fill_outside A bool to set if the object is filled outside
342 * (1 = filled, 0 = no filled)
347 elm_image_fill_outside_set(Evas_Object *obj, Eina_Bool fill_outside)
349 ELM_CHECK_WIDTYPE(obj, widtype);
350 Widget_Data *wd = elm_widget_data_get(obj);
353 wd->fill_outside = fill_outside;
358 * Get if the object is filled outside
360 * @param obj The image object
361 * @return If the object is filled outside
366 elm_image_fill_outside_get(const Evas_Object *obj)
368 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
369 Widget_Data *wd = elm_widget_data_get(obj);
371 if (!wd) return EINA_FALSE;
372 return wd->fill_outside;
376 * Set the prescale size for the image
378 * @param obj The image object
379 * @param size The prescale size
384 elm_image_prescale_set(Evas_Object *obj, int size)
386 ELM_CHECK_WIDTYPE(obj, widtype);
387 Widget_Data *wd = elm_widget_data_get(obj);
390 _els_smart_icon_scale_size_set(wd->img, size);
394 * Get the prescale size for the image
396 * @param obj The image object
397 * @return The prescale size
402 elm_image_prescale_get(const Evas_Object *obj)
404 ELM_CHECK_WIDTYPE(obj, widtype) 0;
405 Widget_Data *wd = elm_widget_data_get(obj);
408 return _els_smart_icon_scale_size_get(wd->img);
412 * Set the image orient
414 * @param obj The image object
415 * @param orient The image orient
416 * (ELM_IMAGE_ORIENT_NONE, ELM_IMAGE_ROTATE_90_CW,
417 * ELM_IMAGE_ROTATE_180_CW, ELM_IMAGE_ROTATE_90_CCW,
418 * ELM_IMAGE_FLIP_HORIZONTAL,ELM_IMAGE_FLIP_VERTICAL,
419 * ELM_IMAGE_FLIP_TRANSPOSE, ELM_IMAGE_FLIP_TRANSVERSE)
424 elm_image_orient_set(Evas_Object *obj, Elm_Image_Orient orient)
426 ELM_CHECK_WIDTYPE(obj, widtype);
427 Widget_Data *wd = elm_widget_data_get(obj);
430 _els_smart_icon_orient_set(wd->img, orient);
434 * Get the image orient
436 * @param obj The image object
437 * @return The image orient
438 * (ELM_IMAGE_ORIENT_NONE, ELM_IMAGE_ROTATE_90_CW,
439 * ELM_IMAGE_ROTATE_180_CW, ELM_IMAGE_ROTATE_90_CCW,
440 * ELM_IMAGE_FLIP_HORIZONTAL,ELM_IMAGE_FLIP_VERTICAL,
441 * ELM_IMAGE_FLIP_TRANSPOSE, ELM_IMAGE_FLIP_TRANSVERSE)
445 EAPI Elm_Image_Orient
446 elm_image_orient_get(const Evas_Object *obj)
448 ELM_CHECK_WIDTYPE(obj, widtype) ELM_IMAGE_ORIENT_NONE;
449 Widget_Data *wd = elm_widget_data_get(obj);
450 if (!wd) return ELM_IMAGE_ORIENT_NONE;
451 return _els_smart_icon_orient_get(wd->img);
455 * Make the image 'editable'.
457 * This means the image is a valid drag target for drag and drop, and can be
460 * @param obj Image object.
461 * @param set Turn on or off editability.
464 elm_image_editable_set(Evas_Object *obj, Eina_Bool set)
466 ELM_CHECK_WIDTYPE(obj, widtype);
467 Widget_Data *wd = elm_widget_data_get(obj);
470 _els_smart_icon_edit_set(wd->img, set, obj);
474 * Make the image 'editable'.
476 * This means the image is a valid drag target for drag and drop, and can be
479 * @param obj Image object.
480 * @return Editability.
483 elm_image_editable_get(const Evas_Object *obj)
485 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
486 Widget_Data *wd = elm_widget_data_get(obj);
487 if (!wd) return EINA_FALSE;
488 return _els_smart_icon_edit_get(wd->img);
492 * Get the image object
494 * When you create a image with elm_image_add(). You can get this object (be
495 * careful to not manipulate it as it is under control of elementary), and use
496 * it to do things like get pixel data, save the image to a file, etc.
498 * @param obj The image object to get the inlined image from
499 * @return The inlined image object, or NULL if none exists
504 elm_image_object_get(const Evas_Object *obj)
506 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
507 Widget_Data *wd = elm_widget_data_get(obj);
508 if (!wd) return NULL;
509 return _els_smart_icon_object_get(wd->img);
513 * Enable/disable retaining up the aspect ratio of the image.
515 * @param obj The image object.
516 * @param retained Retaining or Non retaining.
521 elm_image_aspect_ratio_retained_set(Evas_Object *obj, Eina_Bool retained)
523 ELM_CHECK_WIDTYPE(obj, widtype);
524 Widget_Data *wd = elm_widget_data_get(obj);
526 return _els_smart_icon_aspect_ratio_retained_set(wd->img, retained);
530 * Get if the object retains the aspect ratio.
532 * @param obj The image object.
533 * @return If the object retains the aspect ratio.
538 elm_image_aspect_ratio_retained_get(const Evas_Object *obj)
540 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
541 Widget_Data *wd = elm_widget_data_get(obj);
542 if (!wd) return EINA_FALSE;
543 return _els_smart_icon_aspect_ratio_retained_get(wd->img);
546 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 :*/