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 * "drag,start" - Someone started dragging the image out of the object
15 * "drag,end" - Dragged item was dropped (somewhere)
18 typedef struct _Widget_Data Widget_Data;
26 Ecore_Timer *longtimer;
29 static const char *widtype = NULL;
30 static void _del_hook(Evas_Object *obj);
31 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
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);
35 static void _mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
37 static const char SIG_CLICKED[] = "clicked";
38 static const char SIG_DRAG_START[] = "drag,start";
39 static const char SIG_DRAG_END[] = "drag,end";
41 static const Evas_Smart_Cb_Description _signals[] = {
50 _del_hook(Evas_Object *obj)
52 Widget_Data *wd = elm_widget_data_get(obj);
58 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
60 Widget_Data *wd = elm_widget_data_get(obj);
62 edje_object_mirrored_set(wd->frm, rtl);
66 _theme_hook(Evas_Object *obj)
68 Widget_Data *wd = elm_widget_data_get(obj);
70 _elm_widget_mirrored_reload(obj);
71 _mirrored_set(wd->frm, elm_widget_mirrored_get(obj));
72 _elm_theme_object_set(obj, wd->frm, "photo", "base",
73 elm_widget_style_get(obj));
74 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->img);
75 edje_object_scale_set(wd->frm, elm_widget_scale_get(obj) *
81 _sizing_eval(Evas_Object *obj)
83 Widget_Data *wd = elm_widget_data_get(obj);
84 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
91 scale = (wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
92 evas_object_size_hint_min_set(wd->img, scale, scale);
93 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->img);
94 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
95 edje_object_size_min_restricted_calc(wd->frm, &minw, &minh, minw, minh);
96 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
99 evas_object_size_hint_min_set(obj, minw, minh);
100 evas_object_size_hint_max_set(obj, maxw, maxh);
105 _icon_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
108 Widget_Data *wd = elm_widget_data_get(data);
113 Edje_Message_Int_Set *msg;
114 Evas_Object *icon = _els_smart_icon_object_get(wd->img);
116 evas_object_geometry_get(icon, NULL, NULL, &w, &h);
117 msg = alloca(sizeof(Edje_Message_Int_Set) + (sizeof(int)));
119 msg->val[0] = (int)w;
120 msg->val[1] = (int)h;
122 edje_object_message_send(wd->frm, EDJE_MESSAGE_INT_SET, 0, msg);
128 _drag_done_cb(void *unused __UNUSED__, Evas_Object *obj)
130 elm_object_scroll_freeze_pop(obj);
131 evas_object_smart_callback_call(obj, SIG_DRAG_END, NULL);
135 _longpress(void *objv)
137 Widget_Data *wd = elm_widget_data_get(objv);
142 DBG("Long press: start drag!");
143 wd->longtimer = NULL; /* clear: must return NULL now */
144 evas_object_event_callback_del(objv, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move);
146 tmp = _els_smart_icon_object_get(wd->img);
148 evas_object_image_file_get(tmp,&file,NULL);
151 /* FIXME: Deal with relative paths */
152 buf = malloc(strlen(file) + strlen("file://") + 1);
153 sprintf(buf, "%s%s","file://",file);
154 elm_drag_start(objv, ELM_SEL_FORMAT_IMAGE, buf, _drag_done_cb, NULL);
157 elm_object_scroll_freeze_push(objv);
159 evas_object_smart_callback_call(objv, SIG_DRAG_START, NULL);
161 return 0; /* Don't call again */
165 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event)
167 Widget_Data *wd = elm_widget_data_get(data);
168 Evas_Event_Mouse_Move *move = event;
173 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move);
177 /* if the event is held, stop waiting */
178 if (move->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
180 /* Moved too far: No longpress for you! */
181 ecore_timer_del(wd->longtimer);
182 wd->longtimer = NULL;
183 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_MOVE,
189 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
191 Widget_Data *wd = elm_widget_data_get(data);
193 if (wd->longtimer) ecore_timer_del(wd->longtimer);
195 /* FIXME: Hard coded timeout */
196 wd->longtimer = ecore_timer_add(0.7, _longpress, data);
197 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_MOVE,
202 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
204 Widget_Data *wd = elm_widget_data_get(data);
206 if ((wd) && (wd->longtimer))
208 ecore_timer_del(wd->longtimer);
209 wd->longtimer = NULL;
212 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
217 * Add a new photo to the parent
219 * @param parent The parent object
220 * @return The new object or NULL if it cannot be created
225 elm_photo_add(Evas_Object *parent)
232 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
234 ELM_SET_WIDTYPE(widtype, "photo");
235 elm_widget_type_set(obj, "photo");
236 elm_widget_sub_object_add(parent, obj);
237 elm_widget_data_set(obj, wd);
238 elm_widget_del_hook_set(obj, _del_hook);
239 elm_widget_theme_hook_set(obj, _theme_hook);
240 elm_widget_can_focus_set(obj, EINA_FALSE);
242 wd->frm = edje_object_add(e);
243 _elm_theme_object_set(obj, wd->frm, "photo", "base", "default");
244 elm_widget_resize_object_set(obj, wd->frm);
246 wd->img = _els_smart_icon_add(e);
247 _els_smart_icon_scale_up_set(wd->img, 1);
248 _els_smart_icon_scale_down_set(wd->img, 1);
249 _els_smart_icon_smooth_scale_set(wd->img, 1);
250 _els_smart_icon_fill_inside_set(wd->img, 0);
251 _els_smart_icon_scale_size_set(wd->img, 0);
252 wd->fill = EINA_FALSE;
253 _els_smart_icon_scale_set(wd->img,
254 elm_widget_scale_get(obj) * _elm_config->scale);
255 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
257 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_DOWN,
259 evas_object_repeat_events_set(wd->img, 1);
260 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->img);
261 evas_object_show(wd->img);
262 elm_widget_sub_object_add(obj, wd->img);
264 wd->longtimer = NULL;
266 icon = _els_smart_icon_object_get(wd->img);
267 evas_object_event_callback_add(icon, EVAS_CALLBACK_MOVE,
268 _icon_move_resize, obj);
269 evas_object_event_callback_add(icon, EVAS_CALLBACK_RESIZE,
270 _icon_move_resize, obj);
272 evas_object_smart_callbacks_descriptions_set(obj, _signals);
274 _mirrored_set(obj, elm_widget_mirrored_get(obj));
280 * Set the file that will be used as photo
282 * @param obj The photo object
283 * @param file The path to file that will be used as photo
285 * @return (1 = success, 0 = error)
290 elm_photo_file_set(Evas_Object *obj, const char *file)
292 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
293 Widget_Data *wd = elm_widget_data_get(obj);
295 if (!wd) return EINA_FALSE;
296 if (!_els_smart_icon_file_key_set(wd->img, file, NULL))
304 * Set the size that will be used on the photo
306 * @param obj The photo object
307 * @param size The size that the photo will be
312 elm_photo_size_set(Evas_Object *obj, int size)
314 ELM_CHECK_WIDTYPE(obj, widtype);
315 Widget_Data *wd = elm_widget_data_get(obj);
318 wd->size = (size > 0) ? size : 0;
320 _els_smart_icon_scale_size_set(wd->img, wd->size);
326 * Set if the photo should be completely visible or not.
328 * @param obj The photo object
329 * @param fill if true the photo will be completely visible
334 elm_photo_fill_inside_set(Evas_Object *obj, Eina_Bool fill)
336 ELM_CHECK_WIDTYPE(obj, widtype);
337 Widget_Data *wd = elm_widget_data_get(obj);
340 _els_smart_icon_fill_inside_set(wd->img, fill);
346 * Set editability of the photo.
348 * An editable photo can be dragged to or from, and can be cut or pasted too.
349 * Note that pasting an image or dropping an item on the image will delete the
352 * @param obj The photo object.
353 * @param set To set of clear editablity.
356 elm_photo_editable_set(Evas_Object *obj, Eina_Bool set)
358 ELM_CHECK_WIDTYPE(obj, widtype);
359 Widget_Data *wd = elm_widget_data_get(obj);
362 _els_smart_icon_edit_set(wd->img, set, obj);
365 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 :*/