1 #include <Elementary.h>
5 * @defgroup Photo Photo
7 * For displaying the photo of a person (contact). Simple yet
8 * with a very specific purpose.
10 * Signals that you can add callbacks for are:
12 * "clicked" - This is called when a user has clicked the photo
13 * "drag,start" - Someone started dragging the image out of the object
14 * "drag,end" - Dragged item was dropped (somewhere)
17 typedef struct _Widget_Data Widget_Data;
25 Ecore_Timer *longtimer;
28 static const char *widtype = NULL;
29 static void _del_hook(Evas_Object *obj);
30 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
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);
34 static void _mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
36 static const char SIG_CLICKED[] = "clicked";
37 static const char SIG_DRAG_START[] = "drag,start";
38 static const char SIG_DRAG_END[] = "drag,end";
40 static const Evas_Smart_Cb_Description _signals[] = {
49 _del_hook(Evas_Object *obj)
51 Widget_Data *wd = elm_widget_data_get(obj);
57 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
59 Widget_Data *wd = elm_widget_data_get(obj);
61 edje_object_mirrored_set(wd->frm, rtl);
65 _theme_hook(Evas_Object *obj)
67 Widget_Data *wd = elm_widget_data_get(obj);
69 _elm_widget_mirrored_reload(obj);
70 _mirrored_set(wd->frm, elm_widget_mirrored_get(obj));
71 _elm_theme_object_set(obj, wd->frm, "photo", "base",
72 elm_widget_style_get(obj));
73 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->img);
74 edje_object_scale_set(wd->frm, elm_widget_scale_get(obj) *
80 _sizing_eval(Evas_Object *obj)
82 Widget_Data *wd = elm_widget_data_get(obj);
83 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
90 scale = (wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
91 evas_object_size_hint_min_set(wd->img, scale, scale);
92 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->img);
93 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
94 edje_object_size_min_restricted_calc(wd->frm, &minw, &minh, minw, minh);
95 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
98 evas_object_size_hint_min_set(obj, minw, minh);
99 evas_object_size_hint_max_set(obj, maxw, maxh);
104 _icon_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
107 Widget_Data *wd = elm_widget_data_get(data);
112 Edje_Message_Int_Set *msg;
113 Evas_Object *icon = _els_smart_icon_object_get(wd->img);
115 evas_object_geometry_get(icon, NULL, NULL, &w, &h);
116 msg = alloca(sizeof(Edje_Message_Int_Set) + (sizeof(int)));
118 msg->val[0] = (int)w;
119 msg->val[1] = (int)h;
121 edje_object_message_send(wd->frm, EDJE_MESSAGE_INT_SET, 0, msg);
127 _drag_done_cb(void *unused __UNUSED__, Evas_Object *obj)
129 elm_object_scroll_freeze_pop(obj);
130 evas_object_smart_callback_call(obj, SIG_DRAG_END, NULL);
134 _longpress(void *objv)
136 Widget_Data *wd = elm_widget_data_get(objv);
141 DBG("Long press: start drag!");
142 wd->longtimer = NULL; /* clear: must return NULL now */
143 evas_object_event_callback_del(objv, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move);
145 tmp = _els_smart_icon_object_get(wd->img);
147 evas_object_image_file_get(tmp,&file,NULL);
150 /* FIXME: Deal with relative paths */
151 buf = malloc(strlen(file) + strlen("file://") + 1);
152 sprintf(buf, "%s%s","file://",file);
153 elm_drag_start(objv, ELM_SEL_FORMAT_IMAGE, buf, _drag_done_cb, NULL);
156 elm_object_scroll_freeze_push(objv);
158 evas_object_smart_callback_call(objv, SIG_DRAG_START, NULL);
160 return 0; /* Don't call again */
164 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event)
166 Widget_Data *wd = elm_widget_data_get(data);
167 Evas_Event_Mouse_Move *move = event;
172 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move);
176 /* if the event is held, stop waiting */
177 if (move->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
179 /* Moved too far: No longpress for you! */
180 ecore_timer_del(wd->longtimer);
181 wd->longtimer = NULL;
182 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_MOVE,
188 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
190 Widget_Data *wd = elm_widget_data_get(data);
192 if (wd->longtimer) ecore_timer_del(wd->longtimer);
194 /* FIXME: Hard coded timeout */
195 wd->longtimer = ecore_timer_add(0.7, _longpress, data);
196 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_MOVE,
201 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
203 Widget_Data *wd = elm_widget_data_get(data);
205 if ((wd) && (wd->longtimer))
207 ecore_timer_del(wd->longtimer);
208 wd->longtimer = NULL;
211 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
216 * Add a new photo to the parent
218 * @param parent The parent object
219 * @return The new object or NULL if it cannot be created
224 elm_photo_add(Evas_Object *parent)
231 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
233 ELM_SET_WIDTYPE(widtype, "photo");
234 elm_widget_type_set(obj, "photo");
235 elm_widget_sub_object_add(parent, obj);
236 elm_widget_data_set(obj, wd);
237 elm_widget_del_hook_set(obj, _del_hook);
238 elm_widget_theme_hook_set(obj, _theme_hook);
239 elm_widget_can_focus_set(obj, EINA_FALSE);
241 wd->frm = edje_object_add(e);
242 _elm_theme_object_set(obj, wd->frm, "photo", "base", "default");
243 elm_widget_resize_object_set(obj, wd->frm);
245 wd->img = _els_smart_icon_add(e);
246 _els_smart_icon_scale_up_set(wd->img, 1);
247 _els_smart_icon_scale_down_set(wd->img, 1);
248 _els_smart_icon_smooth_scale_set(wd->img, 1);
249 _els_smart_icon_fill_inside_set(wd->img, 0);
250 _els_smart_icon_scale_size_set(wd->img, 0);
251 wd->fill = EINA_FALSE;
252 _els_smart_icon_scale_set(wd->img,
253 elm_widget_scale_get(obj) * _elm_config->scale);
254 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
256 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_DOWN,
258 evas_object_repeat_events_set(wd->img, 1);
259 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->img);
260 evas_object_show(wd->img);
261 elm_widget_sub_object_add(obj, wd->img);
263 wd->longtimer = NULL;
265 icon = _els_smart_icon_object_get(wd->img);
266 evas_object_event_callback_add(icon, EVAS_CALLBACK_MOVE,
267 _icon_move_resize, obj);
268 evas_object_event_callback_add(icon, EVAS_CALLBACK_RESIZE,
269 _icon_move_resize, obj);
271 evas_object_smart_callbacks_descriptions_set(obj, _signals);
273 _mirrored_set(obj, elm_widget_mirrored_get(obj));
279 * Set the file that will be used as photo
281 * @param obj The photo object
282 * @param file The path to file that will be used as photo
284 * @return (1 = success, 0 = error)
289 elm_photo_file_set(Evas_Object *obj, const char *file)
291 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
292 Widget_Data *wd = elm_widget_data_get(obj);
294 if (!wd) return EINA_FALSE;
295 if (!_els_smart_icon_file_key_set(wd->img, file, NULL))
303 * Set the size that will be used on the photo
305 * @param obj The photo object
306 * @param size The size that the photo will be
311 elm_photo_size_set(Evas_Object *obj, int size)
313 ELM_CHECK_WIDTYPE(obj, widtype);
314 Widget_Data *wd = elm_widget_data_get(obj);
317 wd->size = (size > 0) ? size : 0;
319 _els_smart_icon_scale_size_set(wd->img, wd->size);
325 * Set if the photo should be completely visible or not.
327 * @param obj The photo object
328 * @param fill if true the photo will be completely visible
333 elm_photo_fill_inside_set(Evas_Object *obj, Eina_Bool fill)
335 ELM_CHECK_WIDTYPE(obj, widtype);
336 Widget_Data *wd = elm_widget_data_get(obj);
339 _els_smart_icon_fill_inside_set(wd->img, fill);
345 * Set editability of the photo.
347 * An editable photo can be dragged to or from, and can be cut or pasted too.
348 * Note that pasting an image or dropping an item on the image will delete the
351 * @param obj The photo object.
352 * @param set To set of clear editablity.
355 elm_photo_editable_set(Evas_Object *obj, Eina_Bool set)
357 ELM_CHECK_WIDTYPE(obj, widtype);
358 Widget_Data *wd = elm_widget_data_get(obj);
361 _els_smart_icon_edit_set(wd->img, set, obj);
364 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/