2008-12-05 13:10:50 -08:00
|
|
|
#include <Elementary.h>
|
|
|
|
#include "elm_priv.h"
|
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* @defgroup Photo Photo
|
|
|
|
*
|
|
|
|
* For displaying the photo of a person (contact). Simple yet
|
|
|
|
* with a very specific purpose.
|
2009-10-14 01:41:36 -07:00
|
|
|
*
|
|
|
|
* Signals that you can add callbacks for are:
|
|
|
|
*
|
2010-09-07 23:20:05 -07:00
|
|
|
* - clicked: This is called when a user has clicked the photo
|
|
|
|
* - drop: Something was dropped on the widget
|
2010-09-09 01:59:42 -07:00
|
|
|
* - drag,start: Someone started dragging the image out of the object
|
|
|
|
* - drag,end: Dragged item was dropped (somewhere)
|
2009-09-17 15:39:18 -07:00
|
|
|
*/
|
|
|
|
|
2008-12-05 13:10:50 -08:00
|
|
|
typedef struct _Widget_Data Widget_Data;
|
|
|
|
|
|
|
|
struct _Widget_Data
|
|
|
|
{
|
|
|
|
Evas_Object *frm;
|
|
|
|
Evas_Object *img;
|
|
|
|
int size;
|
2010-07-14 07:48:21 -07:00
|
|
|
Eina_Bool fill;
|
2010-09-09 01:59:42 -07:00
|
|
|
Ecore_Timer *longtimer;
|
2008-12-05 13:10:50 -08:00
|
|
|
};
|
|
|
|
|
2010-03-08 22:15:39 -08:00
|
|
|
static const char *widtype = NULL;
|
2008-12-05 13:10:50 -08:00
|
|
|
static void _del_hook(Evas_Object *obj);
|
|
|
|
static void _theme_hook(Evas_Object *obj);
|
|
|
|
static void _sizing_eval(Evas_Object *obj);
|
2009-02-25 07:54:26 -08:00
|
|
|
static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
|
2008-12-05 13:10:50 -08:00
|
|
|
|
|
|
|
static void
|
|
|
|
_del_hook(Evas_Object *obj)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-03-09 03:42:53 -08:00
|
|
|
if (!wd) return;
|
2008-12-05 13:10:50 -08:00
|
|
|
free(wd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_theme_hook(Evas_Object *obj)
|
|
|
|
{
|
2009-02-02 21:09:03 -08:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-03-09 03:42:53 -08:00
|
|
|
if (!wd) return;
|
2010-07-14 07:48:21 -07:00
|
|
|
_elm_theme_object_set(obj, wd->frm, "photo", "base", elm_widget_style_get(obj));
|
|
|
|
edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->img);
|
2009-02-02 21:09:03 -08:00
|
|
|
edje_object_scale_set(wd->frm, elm_widget_scale_get(obj) * _elm_config->scale);
|
2008-12-05 13:10:50 -08:00
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_sizing_eval(Evas_Object *obj)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
|
2010-03-09 03:42:53 -08:00
|
|
|
if (!wd) return;
|
2010-07-14 07:48:21 -07:00
|
|
|
|
|
|
|
if(wd->size > 0) {
|
|
|
|
evas_object_size_hint_min_set(wd->img,
|
|
|
|
wd->size * elm_widget_scale_get(obj) * _elm_config->scale,
|
|
|
|
wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
|
|
|
|
edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->img);
|
|
|
|
elm_coords_finger_size_adjust(1, &minw, 1, &minh);
|
|
|
|
edje_object_size_min_restricted_calc(wd->frm, &minw, &minh, minw, minh);
|
|
|
|
elm_coords_finger_size_adjust(1, &minw, 1, &minh);
|
|
|
|
maxw = minw;
|
|
|
|
maxh = minh;
|
|
|
|
evas_object_size_hint_min_set(obj, minw, minh);
|
|
|
|
evas_object_size_hint_max_set(obj, maxw, maxh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_icon_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
|
|
|
|
{
|
|
|
|
Evas_Coord w, h;
|
|
|
|
Widget_Data *wd = elm_widget_data_get(data);
|
|
|
|
if (!wd) return;
|
|
|
|
|
|
|
|
if(wd->fill) {
|
|
|
|
Evas_Object *icon = _els_smart_icon_object_get(wd->img);
|
|
|
|
evas_object_geometry_get(icon, NULL, NULL, &w, &h);
|
|
|
|
Edje_Message_Int_Set *msg = alloca(sizeof(Edje_Message_Int_Set) + (sizeof(int)));
|
|
|
|
msg->count=2;
|
|
|
|
msg->val[0] = (int)w;
|
|
|
|
msg->val[1] = (int)h;
|
|
|
|
|
|
|
|
edje_object_message_send(wd->frm, EDJE_MESSAGE_INT_SET, 0, msg);
|
|
|
|
}
|
2008-12-05 13:10:50 -08:00
|
|
|
}
|
|
|
|
|
2010-09-09 01:59:42 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_longpress(void *objv)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(objv);
|
|
|
|
|
|
|
|
printf("Long press: start drag!\n");
|
|
|
|
wd->longtimer = NULL;
|
|
|
|
|
|
|
|
elm_drag_start(objv, ELM_SEL_FORMAT_IMAGE,"/home/nash/Desktop/IMG_4084.jpg");
|
2010-09-09 02:12:08 -07:00
|
|
|
evas_object_smart_callback_call(objv, "drag,start", NULL);
|
2010-09-09 01:59:42 -07:00
|
|
|
|
|
|
|
return 0; /* Don't call again */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info)
|
|
|
|
{
|
|
|
|
Widget_Data *wd = elm_widget_data_get(data);
|
|
|
|
|
|
|
|
if (wd->longtimer) ecore_timer_del(wd->longtimer);
|
|
|
|
/* FIXME: Hard coded */
|
|
|
|
wd->longtimer = ecore_timer_add(0.7,_longpress, data);
|
|
|
|
}
|
2010-07-14 07:48:21 -07:00
|
|
|
|
2008-12-05 13:10:50 -08:00
|
|
|
static void
|
2010-09-09 01:59:42 -07:00
|
|
|
_mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
|
2008-12-05 13:10:50 -08:00
|
|
|
{
|
2010-09-09 01:59:42 -07:00
|
|
|
Widget_Data *wd = elm_widget_data_get(data);
|
|
|
|
|
|
|
|
if (wd && wd->longtimer)
|
|
|
|
{
|
|
|
|
ecore_timer_del(wd->longtimer);
|
|
|
|
wd->longtimer = NULL;
|
|
|
|
}
|
|
|
|
|
2008-12-05 13:10:50 -08:00
|
|
|
evas_object_smart_callback_call(data, "clicked", NULL);
|
|
|
|
}
|
|
|
|
|
2010-09-09 01:59:42 -07:00
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* Add a new photo to the parent
|
|
|
|
*
|
|
|
|
* @param parent The parent object
|
|
|
|
* @return The new object or NULL if it cannot be created
|
|
|
|
*
|
|
|
|
* @ingroup Photo
|
|
|
|
*/
|
2008-12-05 13:10:50 -08:00
|
|
|
EAPI Evas_Object *
|
|
|
|
elm_photo_add(Evas_Object *parent)
|
|
|
|
{
|
|
|
|
Evas_Object *obj;
|
|
|
|
Evas *e;
|
|
|
|
Widget_Data *wd;
|
2010-07-14 07:48:21 -07:00
|
|
|
Evas_Object *icon;
|
2009-07-06 23:46:51 -07:00
|
|
|
|
2008-12-05 13:10:50 -08:00
|
|
|
wd = ELM_NEW(Widget_Data);
|
|
|
|
e = evas_object_evas_get(parent);
|
|
|
|
obj = elm_widget_add(e);
|
2010-03-08 22:15:39 -08:00
|
|
|
ELM_SET_WIDTYPE(widtype, "photo");
|
2009-05-13 05:21:52 -07:00
|
|
|
elm_widget_type_set(obj, "photo");
|
|
|
|
elm_widget_sub_object_add(parent, obj);
|
2008-12-05 13:10:50 -08:00
|
|
|
elm_widget_data_set(obj, wd);
|
|
|
|
elm_widget_del_hook_set(obj, _del_hook);
|
|
|
|
elm_widget_theme_hook_set(obj, _theme_hook);
|
|
|
|
elm_widget_can_focus_set(obj, 0);
|
|
|
|
|
|
|
|
wd->frm = edje_object_add(e);
|
2010-05-11 18:03:46 -07:00
|
|
|
_elm_theme_object_set(obj, wd->frm, "photo", "base", "default");
|
2008-12-05 13:10:50 -08:00
|
|
|
elm_widget_resize_object_set(obj, wd->frm);
|
2009-07-06 23:46:51 -07:00
|
|
|
|
2008-12-05 13:10:50 -08:00
|
|
|
wd->img = _els_smart_icon_add(e);
|
|
|
|
_els_smart_icon_scale_up_set(wd->img, 1);
|
|
|
|
_els_smart_icon_scale_down_set(wd->img, 1);
|
|
|
|
_els_smart_icon_smooth_scale_set(wd->img, 1);
|
|
|
|
_els_smart_icon_fill_inside_set(wd->img, 0);
|
2010-07-14 07:48:21 -07:00
|
|
|
_els_smart_icon_scale_size_set(wd->img, 0);
|
|
|
|
wd->fill = EINA_FALSE;
|
2009-02-02 21:09:03 -08:00
|
|
|
_els_smart_icon_scale_set(wd->img, elm_widget_scale_get(obj) * _elm_config->scale);
|
2008-12-05 13:10:50 -08:00
|
|
|
evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_UP,
|
|
|
|
_mouse_up, obj);
|
2010-09-09 01:59:42 -07:00
|
|
|
evas_object_event_callback_add(wd->img, EVAS_CALLBACK_MOUSE_DOWN,
|
|
|
|
_mouse_down, obj);
|
2008-12-05 13:10:50 -08:00
|
|
|
evas_object_repeat_events_set(wd->img, 1);
|
|
|
|
edje_object_part_swallow(wd->frm, "elm.swallow.content", wd->img);
|
|
|
|
evas_object_show(wd->img);
|
2009-02-17 23:10:42 -08:00
|
|
|
elm_widget_sub_object_add(obj, wd->img);
|
2009-07-06 23:46:51 -07:00
|
|
|
|
2010-09-09 01:59:42 -07:00
|
|
|
wd->longtimer = NULL;
|
2009-07-06 23:46:51 -07:00
|
|
|
|
2010-07-14 07:48:21 -07:00
|
|
|
icon = _els_smart_icon_object_get(wd->img);
|
|
|
|
evas_object_event_callback_add(icon, EVAS_CALLBACK_MOVE,
|
|
|
|
_icon_move_resize, obj);
|
|
|
|
evas_object_event_callback_add(icon, EVAS_CALLBACK_RESIZE,
|
|
|
|
_icon_move_resize, obj);
|
2008-12-05 13:10:50 -08:00
|
|
|
_sizing_eval(obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* Set the file that will be used as photo
|
|
|
|
*
|
|
|
|
* @param obj The photo object
|
|
|
|
* @param file The path to file that will be used as photo
|
|
|
|
*
|
2010-09-08 17:35:43 -07:00
|
|
|
* @return (1 = success, 0 = error)
|
2009-09-17 15:39:18 -07:00
|
|
|
*
|
|
|
|
* @ingroup Photo
|
|
|
|
*/
|
2009-04-03 14:52:01 -07:00
|
|
|
EAPI Eina_Bool
|
2008-12-05 13:10:50 -08:00
|
|
|
elm_photo_file_set(Evas_Object *obj, const char *file)
|
|
|
|
{
|
2010-08-18 12:18:42 -07:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
|
|
|
|
if (!wd) return EINA_FALSE;
|
|
|
|
if (!_els_smart_icon_file_key_set(wd->img, file, NULL))
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
_sizing_eval(obj);
|
|
|
|
return EINA_TRUE;
|
2008-12-05 13:10:50 -08:00
|
|
|
}
|
|
|
|
|
2009-09-17 15:39:18 -07:00
|
|
|
/**
|
|
|
|
* Set the size that will be used on the photo
|
|
|
|
*
|
|
|
|
* @param obj The photo object
|
|
|
|
* @param size The size that the photo will be
|
|
|
|
*
|
|
|
|
* @ingroup Photo
|
|
|
|
*/
|
2008-12-05 13:10:50 -08:00
|
|
|
EAPI void
|
|
|
|
elm_photo_size_set(Evas_Object *obj, int size)
|
|
|
|
{
|
2010-03-08 22:15:39 -08:00
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
2008-12-05 13:10:50 -08:00
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
2010-03-09 03:42:53 -08:00
|
|
|
if (!wd) return;
|
2010-07-14 07:48:21 -07:00
|
|
|
|
2010-09-07 21:54:46 -07:00
|
|
|
wd->size = (size > 0) ? size : 0;
|
|
|
|
|
|
|
|
_els_smart_icon_scale_size_set(wd->img, wd->size);
|
2010-07-14 07:48:21 -07:00
|
|
|
|
2008-12-05 13:10:50 -08:00
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
2010-07-14 07:48:21 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set if the photo should be completely visible or not.
|
|
|
|
*
|
|
|
|
* @param obj The photo object
|
|
|
|
* @param fill if true the photo will be completely visible
|
|
|
|
*
|
|
|
|
* @ingroup Photo
|
|
|
|
*/
|
|
|
|
EAPI void
|
|
|
|
elm_photo_fill_inside_set(Evas_Object *obj, Eina_Bool fill)
|
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
if (!wd) return;
|
|
|
|
_els_smart_icon_fill_inside_set(wd->img, fill);
|
|
|
|
wd->fill = fill;
|
|
|
|
_sizing_eval(obj);
|
|
|
|
}
|
|
|
|
|
2010-09-07 23:20:01 -07:00
|
|
|
/**
|
|
|
|
* Set editability of the photo.
|
|
|
|
*
|
|
|
|
* An editable photo can be dragged to or from, and can be cut or pasted too.
|
|
|
|
* Note that pasting an image or dropping an item on the image will delete the
|
|
|
|
* existing content.
|
|
|
|
*
|
|
|
|
* @param obj The photo object.
|
|
|
|
* @param set To set of clear editablity.
|
|
|
|
*/
|
2010-09-07 21:55:20 -07:00
|
|
|
EAPI void
|
|
|
|
elm_photo_editable_set(Evas_Object *obj, Eina_Bool set)
|
|
|
|
{
|
|
|
|
ELM_CHECK_WIDTYPE(obj, widtype);
|
|
|
|
Widget_Data *wd = elm_widget_data_get(obj);
|
|
|
|
|
|
|
|
if (!wd) return;;
|
2010-09-07 23:20:05 -07:00
|
|
|
_els_smart_icon_edit_set(wd->img, set, obj);
|
2010-09-07 21:55:20 -07:00
|
|
|
}
|
|
|
|
|
2010-09-09 01:59:42 -07:00
|
|
|
/* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/
|