1 #include <Elementary.h>
5 * @defgroup Photo Photo
8 * For displaying the photo of a person (contact). Simple yet
9 * with a very specific purpose.
11 * Signals that you can add callbacks for are:
13 * "clicked" - This is called when a user has clicked the photo
14 * "drop" - Something was dropped on the widget
15 * "drag,start" - Someone started dragging the image out of the object
16 * "drag,end" - Dragged item was dropped (somewhere)
19 typedef struct _Widget_Data Widget_Data;
27 Ecore_Timer *longtimer;
30 static const char *widtype = NULL;
31 static void _del_hook(Evas_Object *obj);
32 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
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);
36 static void _mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
39 _del_hook(Evas_Object *obj)
41 Widget_Data *wd = elm_widget_data_get(obj);
47 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
49 Widget_Data *wd = elm_widget_data_get(obj);
51 edje_object_mirrored_set(wd->frm, rtl);
55 _theme_hook(Evas_Object *obj)
57 Widget_Data *wd = elm_widget_data_get(obj);
59 _elm_widget_mirrored_reload(obj);
60 _mirrored_set(wd->frm, elm_widget_mirrored_get(obj));
61 _elm_theme_object_set(obj, wd->frm, "photo", "base",
62 elm_widget_style_get(obj));
63 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->img);
64 edje_object_scale_set(wd->frm, elm_widget_scale_get(obj) *
70 _sizing_eval(Evas_Object *obj)
72 Widget_Data *wd = elm_widget_data_get(obj);
73 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
80 scale = (wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
81 evas_object_size_hint_min_set(wd->img, scale, scale);
82 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->img);
83 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
84 edje_object_size_min_restricted_calc(wd->frm, &minw, &minh, minw, minh);
85 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
88 evas_object_size_hint_min_set(obj, minw, minh);
89 evas_object_size_hint_max_set(obj, maxw, maxh);
94 _icon_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
97 Widget_Data *wd = elm_widget_data_get(data);
102 Edje_Message_Int_Set *msg;
103 Evas_Object *icon = _els_smart_icon_object_get(wd->img);
105 evas_object_geometry_get(icon, NULL, NULL, &w, &h);
106 msg = alloca(sizeof(Edje_Message_Int_Set) + (sizeof(int)));
108 msg->val[0] = (int)w;
109 msg->val[1] = (int)h;
111 edje_object_message_send(wd->frm, EDJE_MESSAGE_INT_SET, 0, msg);
117 _drag_done_cb(void *unused __UNUSED__, Evas_Object *obj)
119 elm_object_scroll_freeze_pop(obj);
120 evas_object_smart_callback_call(obj, "drag,end", NULL);
124 _longpress(void *objv)
126 Widget_Data *wd = elm_widget_data_get(objv);
131 DBG("Long press: start drag!");
132 wd->longtimer = NULL; /* clear: must return NULL now */
133 evas_object_event_callback_del(objv, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move);
135 tmp = _els_smart_icon_object_get(wd->img);
137 evas_object_image_file_get(tmp,&file,NULL);
140 /* FIXME: Deal with relative paths */
141 buf = malloc(strlen(file) + strlen("file://") + 1);
142 sprintf(buf, "%s%s","file://",file);
143 elm_drag_start(objv, ELM_SEL_FORMAT_IMAGE, buf, _drag_done_cb, NULL);
146 elm_object_scroll_freeze_push(objv);
148 evas_object_smart_callback_call(objv, "drag,start", NULL);
150 return 0; /* Don't call again */
154 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event)
156 Widget_Data *wd = elm_widget_data_get(data);
157 Evas_Event_Mouse_Move *move = event;
162 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move);
166 /* if the event is held, stop waiting */
167 if (move->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
169 /* Moved too far: No longpress for you! */
170 ecore_timer_del(wd->longtimer);
171 wd->longtimer = NULL;
172 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_MOVE,
178 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
180 Widget_Data *wd = elm_widget_data_get(data);
182 if (wd->longtimer) ecore_timer_del(wd->longtimer);
184 /* FIXME: Hard coded timeout */
185 wd->longtimer = ecore_timer_add(0.7, _longpress, data);
186 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_MOVE,
191 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
193 Widget_Data *wd = elm_widget_data_get(data);
195 if ((wd) && (wd->longtimer))
197 ecore_timer_del(wd->longtimer);
198 wd->longtimer = NULL;
201 evas_object_smart_callback_call(data, "clicked", NULL);
206 * Add a new photo to the parent
208 * @param parent The parent object
209 * @return The new object or NULL if it cannot be created
214 elm_photo_add(Evas_Object *parent)
221 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
223 ELM_SET_WIDTYPE(widtype, "photo");
224 elm_widget_type_set(obj, "photo");
225 elm_widget_sub_object_add(parent, obj);
226 elm_widget_data_set(obj, wd);
227 elm_widget_del_hook_set(obj, _del_hook);
228 elm_widget_theme_hook_set(obj, _theme_hook);
229 elm_widget_can_focus_set(obj, EINA_FALSE);
231 wd->frm = edje_object_add(e);
232 _elm_theme_object_set(obj, wd->frm, "photo", "base", "default");
233 elm_widget_resize_object_set(obj, wd->frm);
235 wd->img = _els_smart_icon_add(e);
236 _els_smart_icon_scale_up_set(wd->img, 1);
237 _els_smart_icon_scale_down_set(wd->img, 1);
238 _els_smart_icon_smooth_scale_set(wd->img, 1);
239 _els_smart_icon_fill_inside_set(wd->img, 0);
240 _els_smart_icon_scale_size_set(wd->img, 0);
241 wd->fill = EINA_FALSE;
242 _els_smart_icon_scale_set(wd->img,
243 elm_widget_scale_get(obj) * _elm_config->scale);
244 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
246 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_DOWN,
248 evas_object_repeat_events_set(wd->img, 1);
249 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->img);
250 evas_object_show(wd->img);
251 elm_widget_sub_object_add(obj, wd->img);
253 wd->longtimer = NULL;
255 icon = _els_smart_icon_object_get(wd->img);
256 evas_object_event_callback_add(icon, EVAS_CALLBACK_MOVE,
257 _icon_move_resize, obj);
258 evas_object_event_callback_add(icon, EVAS_CALLBACK_RESIZE,
259 _icon_move_resize, obj);
261 _mirrored_set(obj, elm_widget_mirrored_get(obj));
267 * Set the file that will be used as photo
269 * @param obj The photo object
270 * @param file The path to file that will be used as photo
272 * @return (1 = success, 0 = error)
277 elm_photo_file_set(Evas_Object *obj, const char *file)
279 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
280 Widget_Data *wd = elm_widget_data_get(obj);
282 if (!wd) return EINA_FALSE;
283 if (!_els_smart_icon_file_key_set(wd->img, file, NULL))
291 * Set the size that will be used on the photo
293 * @param obj The photo object
294 * @param size The size that the photo will be
299 elm_photo_size_set(Evas_Object *obj, int size)
301 ELM_CHECK_WIDTYPE(obj, widtype);
302 Widget_Data *wd = elm_widget_data_get(obj);
305 wd->size = (size > 0) ? size : 0;
307 _els_smart_icon_scale_size_set(wd->img, wd->size);
313 * Set if the photo should be completely visible or not.
315 * @param obj The photo object
316 * @param fill if true the photo will be completely visible
321 elm_photo_fill_inside_set(Evas_Object *obj, Eina_Bool fill)
323 ELM_CHECK_WIDTYPE(obj, widtype);
324 Widget_Data *wd = elm_widget_data_get(obj);
327 _els_smart_icon_fill_inside_set(wd->img, fill);
333 * Set editability of the photo.
335 * An editable photo can be dragged to or from, and can be cut or pasted too.
336 * Note that pasting an image or dropping an item on the image will delete the
339 * @param obj The photo object.
340 * @param set To set of clear editablity.
343 elm_photo_editable_set(Evas_Object *obj, Eina_Bool set)
345 ELM_CHECK_WIDTYPE(obj, widtype);
346 Widget_Data *wd = elm_widget_data_get(obj);
349 _els_smart_icon_edit_set(wd->img, set, obj);
352 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/