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 * "drop" - Something was dropped on the widget
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);
38 _del_hook(Evas_Object *obj)
40 Widget_Data *wd = elm_widget_data_get(obj);
46 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
48 Widget_Data *wd = elm_widget_data_get(obj);
50 edje_object_mirrored_set(wd->frm, rtl);
54 _theme_hook(Evas_Object *obj)
56 Widget_Data *wd = elm_widget_data_get(obj);
58 _elm_widget_mirrored_reload(obj);
59 _mirrored_set(wd->frm, elm_widget_mirrored_get(obj));
60 _elm_theme_object_set(obj, wd->frm, "photo", "base",
61 elm_widget_style_get(obj));
62 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->img);
63 edje_object_scale_set(wd->frm, elm_widget_scale_get(obj) *
69 _sizing_eval(Evas_Object *obj)
71 Widget_Data *wd = elm_widget_data_get(obj);
72 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
79 scale = (wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
80 evas_object_size_hint_min_set(wd->img, scale, scale);
81 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->img);
82 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
83 edje_object_size_min_restricted_calc(wd->frm, &minw, &minh, minw, minh);
84 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
87 evas_object_size_hint_min_set(obj, minw, minh);
88 evas_object_size_hint_max_set(obj, maxw, maxh);
93 _icon_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
96 Widget_Data *wd = elm_widget_data_get(data);
101 Edje_Message_Int_Set *msg;
102 Evas_Object *icon = _els_smart_icon_object_get(wd->img);
104 evas_object_geometry_get(icon, NULL, NULL, &w, &h);
105 msg = alloca(sizeof(Edje_Message_Int_Set) + (sizeof(int)));
107 msg->val[0] = (int)w;
108 msg->val[1] = (int)h;
110 edje_object_message_send(wd->frm, EDJE_MESSAGE_INT_SET, 0, msg);
116 _drag_done_cb(void *unused __UNUSED__, Evas_Object *obj)
118 elm_object_scroll_freeze_pop(obj);
119 evas_object_smart_callback_call(obj, "drag,end", NULL);
123 _longpress(void *objv)
125 Widget_Data *wd = elm_widget_data_get(objv);
130 DBG("Long press: start drag!");
131 wd->longtimer = NULL; /* clear: must return NULL now */
132 evas_object_event_callback_del(objv, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move);
134 tmp = _els_smart_icon_object_get(wd->img);
136 evas_object_image_file_get(tmp,&file,NULL);
139 /* FIXME: Deal with relative paths */
140 buf = malloc(strlen(file) + strlen("file://") + 1);
141 sprintf(buf, "%s%s","file://",file);
142 elm_drag_start(objv, ELM_SEL_FORMAT_IMAGE, buf, _drag_done_cb, NULL);
145 elm_object_scroll_freeze_push(objv);
147 evas_object_smart_callback_call(objv, "drag,start", NULL);
149 return 0; /* Don't call again */
153 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event)
155 Widget_Data *wd = elm_widget_data_get(data);
156 Evas_Event_Mouse_Move *move = event;
161 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move);
165 /* if the event is held, stop waiting */
166 if (move->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
168 /* Moved too far: No longpress for you! */
169 ecore_timer_del(wd->longtimer);
170 wd->longtimer = NULL;
171 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_MOVE,
177 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
179 Widget_Data *wd = elm_widget_data_get(data);
181 if (wd->longtimer) ecore_timer_del(wd->longtimer);
183 /* FIXME: Hard coded timeout */
184 wd->longtimer = ecore_timer_add(0.7, _longpress, data);
185 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_MOVE,
190 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
192 Widget_Data *wd = elm_widget_data_get(data);
194 if ((wd) && (wd->longtimer))
196 ecore_timer_del(wd->longtimer);
197 wd->longtimer = NULL;
200 evas_object_smart_callback_call(data, "clicked", NULL);
205 * Add a new photo to the parent
207 * @param parent The parent object
208 * @return The new object or NULL if it cannot be created
213 elm_photo_add(Evas_Object *parent)
220 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
222 ELM_SET_WIDTYPE(widtype, "photo");
223 elm_widget_type_set(obj, "photo");
224 elm_widget_sub_object_add(parent, obj);
225 elm_widget_data_set(obj, wd);
226 elm_widget_del_hook_set(obj, _del_hook);
227 elm_widget_theme_hook_set(obj, _theme_hook);
228 elm_widget_can_focus_set(obj, EINA_FALSE);
230 wd->frm = edje_object_add(e);
231 _elm_theme_object_set(obj, wd->frm, "photo", "base", "default");
232 elm_widget_resize_object_set(obj, wd->frm);
234 wd->img = _els_smart_icon_add(e);
235 _els_smart_icon_scale_up_set(wd->img, 1);
236 _els_smart_icon_scale_down_set(wd->img, 1);
237 _els_smart_icon_smooth_scale_set(wd->img, 1);
238 _els_smart_icon_fill_inside_set(wd->img, 0);
239 _els_smart_icon_scale_size_set(wd->img, 0);
240 wd->fill = EINA_FALSE;
241 _els_smart_icon_scale_set(wd->img,
242 elm_widget_scale_get(obj) * _elm_config->scale);
243 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
245 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_DOWN,
247 evas_object_repeat_events_set(wd->img, 1);
248 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->img);
249 evas_object_show(wd->img);
250 elm_widget_sub_object_add(obj, wd->img);
252 wd->longtimer = NULL;
254 icon = _els_smart_icon_object_get(wd->img);
255 evas_object_event_callback_add(icon, EVAS_CALLBACK_MOVE,
256 _icon_move_resize, obj);
257 evas_object_event_callback_add(icon, EVAS_CALLBACK_RESIZE,
258 _icon_move_resize, obj);
260 _mirrored_set(obj, elm_widget_mirrored_get(obj));
266 * Set the file that will be used as photo
268 * @param obj The photo object
269 * @param file The path to file that will be used as photo
271 * @return (1 = success, 0 = error)
276 elm_photo_file_set(Evas_Object *obj, const char *file)
278 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
279 Widget_Data *wd = elm_widget_data_get(obj);
281 if (!wd) return EINA_FALSE;
282 if (!_els_smart_icon_file_key_set(wd->img, file, NULL))
290 * Set the size that will be used on the photo
292 * @param obj The photo object
293 * @param size The size that the photo will be
298 elm_photo_size_set(Evas_Object *obj, int size)
300 ELM_CHECK_WIDTYPE(obj, widtype);
301 Widget_Data *wd = elm_widget_data_get(obj);
304 wd->size = (size > 0) ? size : 0;
306 _els_smart_icon_scale_size_set(wd->img, wd->size);
312 * Set if the photo should be completely visible or not.
314 * @param obj The photo object
315 * @param fill if true the photo will be completely visible
320 elm_photo_fill_inside_set(Evas_Object *obj, Eina_Bool fill)
322 ELM_CHECK_WIDTYPE(obj, widtype);
323 Widget_Data *wd = elm_widget_data_get(obj);
326 _els_smart_icon_fill_inside_set(wd->img, fill);
332 * Set editability of the photo.
334 * An editable photo can be dragged to or from, and can be cut or pasted too.
335 * Note that pasting an image or dropping an item on the image will delete the
338 * @param obj The photo object.
339 * @param set To set of clear editablity.
342 elm_photo_editable_set(Evas_Object *obj, Eina_Bool set)
344 ELM_CHECK_WIDTYPE(obj, widtype);
345 Widget_Data *wd = elm_widget_data_get(obj);
348 _els_smart_icon_edit_set(wd->img, set, obj);
351 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/