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 _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 _theme_hook(Evas_Object *obj)
48 Widget_Data *wd = elm_widget_data_get(obj);
50 _elm_theme_object_set(obj, wd->frm, "photo", "base", elm_widget_style_get(obj));
51 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->img);
52 edje_object_scale_set(wd->frm, elm_widget_scale_get(obj) * _elm_config->scale);
57 _sizing_eval(Evas_Object *obj)
59 Widget_Data *wd = elm_widget_data_get(obj);
60 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
64 evas_object_size_hint_min_set(wd->img,
65 wd->size * elm_widget_scale_get(obj) * _elm_config->scale,
66 wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
67 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->img);
68 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
69 edje_object_size_min_restricted_calc(wd->frm, &minw, &minh, minw, minh);
70 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
73 evas_object_size_hint_min_set(obj, minw, minh);
74 evas_object_size_hint_max_set(obj, maxw, maxh);
79 _icon_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
82 Widget_Data *wd = elm_widget_data_get(data);
86 Evas_Object *icon = _els_smart_icon_object_get(wd->img);
87 evas_object_geometry_get(icon, NULL, NULL, &w, &h);
88 Edje_Message_Int_Set *msg = alloca(sizeof(Edje_Message_Int_Set) + (sizeof(int)));
93 edje_object_message_send(wd->frm, EDJE_MESSAGE_INT_SET, 0, msg);
99 _drag_done_cb(void *unused __UNUSED__, Evas_Object *obj)
101 elm_object_scroll_freeze_pop(obj);
102 evas_object_smart_callback_call(obj, "drag,end", NULL);
106 _longpress(void *objv)
108 Widget_Data *wd = elm_widget_data_get(objv);
113 printf("Long press: start drag!\n");
114 wd->longtimer = NULL; /* clear: must return NULL now */
115 evas_object_event_callback_del(objv, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move);
117 tmp = _els_smart_icon_object_get(wd->img);
119 evas_object_image_file_get(tmp,&file,NULL);
122 /* FIXME: Deal with relative paths */
123 buf = malloc(strlen(file) + strlen("file://") + 1);
124 sprintf(buf, "%s%s","file://",file);
125 elm_drag_start(objv, ELM_SEL_FORMAT_IMAGE, buf, _drag_done_cb, NULL);
128 elm_object_scroll_freeze_push(objv);
130 evas_object_smart_callback_call(objv, "drag,start", NULL);
132 return 0; /* Don't call again */
136 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event)
138 Widget_Data *wd = elm_widget_data_get(data);
139 Evas_Event_Mouse_Move *move = event;
144 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_MOVE, _mouse_move);
148 /* if the event is held, stop waiting */
149 if (move->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
151 /* Moved too far: No longpress for you! */
152 ecore_timer_del(wd->longtimer);
153 wd->longtimer = NULL;
154 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_MOVE,
160 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
162 Widget_Data *wd = elm_widget_data_get(data);
164 if (wd->longtimer) ecore_timer_del(wd->longtimer);
166 /* FIXME: Hard coded timeout */
167 wd->longtimer = ecore_timer_add(0.7,_longpress, data);
168 evas_object_event_callback_add(obj,EVAS_CALLBACK_MOUSE_MOVE,
173 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
175 Widget_Data *wd = elm_widget_data_get(data);
177 if (wd && wd->longtimer)
179 ecore_timer_del(wd->longtimer);
180 wd->longtimer = NULL;
183 evas_object_smart_callback_call(data, "clicked", NULL);
188 * Add a new photo to the parent
190 * @param parent The parent object
191 * @return The new object or NULL if it cannot be created
196 elm_photo_add(Evas_Object *parent)
203 wd = ELM_NEW(Widget_Data);
204 e = evas_object_evas_get(parent);
205 obj = elm_widget_add(e);
206 ELM_SET_WIDTYPE(widtype, "photo");
207 elm_widget_type_set(obj, "photo");
208 elm_widget_sub_object_add(parent, obj);
209 elm_widget_data_set(obj, wd);
210 elm_widget_del_hook_set(obj, _del_hook);
211 elm_widget_theme_hook_set(obj, _theme_hook);
212 elm_widget_can_focus_set(obj, 0);
214 wd->frm = edje_object_add(e);
215 _elm_theme_object_set(obj, wd->frm, "photo", "base", "default");
216 elm_widget_resize_object_set(obj, wd->frm);
218 wd->img = _els_smart_icon_add(e);
219 _els_smart_icon_scale_up_set(wd->img, 1);
220 _els_smart_icon_scale_down_set(wd->img, 1);
221 _els_smart_icon_smooth_scale_set(wd->img, 1);
222 _els_smart_icon_fill_inside_set(wd->img, 0);
223 _els_smart_icon_scale_size_set(wd->img, 0);
224 wd->fill = EINA_FALSE;
225 _els_smart_icon_scale_set(wd->img, elm_widget_scale_get(obj) * _elm_config->scale);
226 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
228 evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_DOWN,
230 evas_object_repeat_events_set(wd->img, 1);
231 edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->img);
232 evas_object_show(wd->img);
233 elm_widget_sub_object_add(obj, wd->img);
235 wd->longtimer = NULL;
237 icon = _els_smart_icon_object_get(wd->img);
238 evas_object_event_callback_add(icon, EVAS_CALLBACK_MOVE,
239 _icon_move_resize, obj);
240 evas_object_event_callback_add(icon, EVAS_CALLBACK_RESIZE,
241 _icon_move_resize, obj);
247 * Set the file that will be used as photo
249 * @param obj The photo object
250 * @param file The path to file that will be used as photo
252 * @return (1 = success, 0 = error)
257 elm_photo_file_set(Evas_Object *obj, const char *file)
259 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
260 Widget_Data *wd = elm_widget_data_get(obj);
262 if (!wd) return EINA_FALSE;
263 if (!_els_smart_icon_file_key_set(wd->img, file, NULL))
271 * Set the size that will be used on the photo
273 * @param obj The photo object
274 * @param size The size that the photo will be
279 elm_photo_size_set(Evas_Object *obj, int size)
281 ELM_CHECK_WIDTYPE(obj, widtype);
282 Widget_Data *wd = elm_widget_data_get(obj);
285 wd->size = (size > 0) ? size : 0;
287 _els_smart_icon_scale_size_set(wd->img, wd->size);
293 * Set if the photo should be completely visible or not.
295 * @param obj The photo object
296 * @param fill if true the photo will be completely visible
301 elm_photo_fill_inside_set(Evas_Object *obj, Eina_Bool fill)
303 ELM_CHECK_WIDTYPE(obj, widtype);
304 Widget_Data *wd = elm_widget_data_get(obj);
306 _els_smart_icon_fill_inside_set(wd->img, fill);
312 * Set editability of the photo.
314 * An editable photo can be dragged to or from, and can be cut or pasted too.
315 * Note that pasting an image or dropping an item on the image will delete the
318 * @param obj The photo object.
319 * @param set To set of clear editablity.
322 elm_photo_editable_set(Evas_Object *obj, Eina_Bool set)
324 ELM_CHECK_WIDTYPE(obj, widtype);
325 Widget_Data *wd = elm_widget_data_get(obj);
328 _els_smart_icon_edit_set(wd->img, set, obj);
331 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/