2010-12-20 03:09:19 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "elementary_config.h"
|
|
|
|
#endif
|
2010-06-17 01:06:07 -07:00
|
|
|
#include <Elementary.h>
|
2014-11-28 23:06:50 -08:00
|
|
|
#include <Efreet.h>
|
2010-06-17 01:06:07 -07:00
|
|
|
#include "elm_priv.h"
|
2011-11-20 06:56:12 -08:00
|
|
|
#ifdef HAVE_MMAN_H
|
|
|
|
# include <sys/mman.h>
|
|
|
|
#endif
|
2010-06-17 01:06:07 -07:00
|
|
|
|
2016-05-03 02:07:48 -07:00
|
|
|
#define DEBUGON 1
|
2013-05-21 03:25:00 -07:00
|
|
|
#ifdef DEBUGON
|
2015-02-25 00:36:13 -08:00
|
|
|
# define cnp_debug(fmt, args...) fprintf(stderr, __FILE__":%s/%d : " fmt , __FUNCTION__, __LINE__, ##args)
|
2013-05-21 03:25:00 -07:00
|
|
|
#else
|
|
|
|
# define cnp_debug(x...) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
2015-03-09 09:17:52 -07:00
|
|
|
#define ARRAYINIT(foo) [foo] =
|
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
// common stuff
|
2010-12-20 03:09:19 -08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CNP_ATOM_TARGETS = 0,
|
2011-09-27 23:48:44 -07:00
|
|
|
CNP_ATOM_ATOM,
|
|
|
|
CNP_ATOM_LISTING_ATOMS = CNP_ATOM_ATOM,
|
2010-12-20 03:09:19 -08:00
|
|
|
CNP_ATOM_text_urilist,
|
|
|
|
CNP_ATOM_text_x_vcard,
|
|
|
|
CNP_ATOM_image_png,
|
|
|
|
CNP_ATOM_image_jpeg,
|
|
|
|
CNP_ATOM_image_bmp,
|
|
|
|
CNP_ATOM_image_gif,
|
|
|
|
CNP_ATOM_image_tiff,
|
|
|
|
CNP_ATOM_image_svg,
|
|
|
|
CNP_ATOM_image_xpm,
|
|
|
|
CNP_ATOM_image_tga,
|
|
|
|
CNP_ATOM_image_ppm,
|
|
|
|
CNP_ATOM_XELM,
|
2012-07-16 02:16:30 -07:00
|
|
|
// CNP_ATOM_text_html_utf8,
|
|
|
|
// CNP_ATOM_text_html,
|
2010-12-20 03:09:19 -08:00
|
|
|
CNP_ATOM_UTF8STRING,
|
|
|
|
CNP_ATOM_STRING,
|
2012-10-04 16:19:05 -07:00
|
|
|
CNP_ATOM_COMPOUND_TEXT,
|
2010-12-20 03:09:19 -08:00
|
|
|
CNP_ATOM_TEXT,
|
|
|
|
CNP_ATOM_text_plain_utf8,
|
|
|
|
CNP_ATOM_text_plain,
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
CNP_N_ATOMS,
|
|
|
|
};
|
2010-06-17 01:06:07 -07:00
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
typedef struct _Tmp_Info Tmp_Info;
|
|
|
|
typedef struct _Saved_Type Saved_Type;
|
2012-09-06 00:43:10 -07:00
|
|
|
typedef struct _Cnp_Escape Cnp_Escape;
|
2012-08-22 01:33:43 -07:00
|
|
|
typedef struct _Dropable Dropable;
|
2013-11-04 05:08:53 -08:00
|
|
|
typedef struct _Dropable_Cbs Dropable_Cbs;
|
2013-03-16 23:36:30 -07:00
|
|
|
static Eina_Bool doaccept = EINA_FALSE;
|
2010-06-17 01:06:07 -07:00
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
struct _Tmp_Info
|
|
|
|
{
|
2010-09-21 21:42:41 -07:00
|
|
|
char *filename;
|
|
|
|
void *map;
|
2010-12-20 03:09:19 -08:00
|
|
|
int fd;
|
|
|
|
int len;
|
2010-09-21 21:42:41 -07:00
|
|
|
};
|
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
struct _Saved_Type
|
|
|
|
{
|
|
|
|
const char **types;
|
2011-06-20 00:13:50 -07:00
|
|
|
char *imgfile;
|
2010-12-20 03:09:19 -08:00
|
|
|
int ntypes;
|
|
|
|
int x, y;
|
|
|
|
Eina_Bool textreq: 1;
|
|
|
|
};
|
2010-09-21 21:42:41 -07:00
|
|
|
|
2012-09-06 00:43:10 -07:00
|
|
|
struct _Cnp_Escape
|
2012-08-22 01:33:43 -07:00
|
|
|
{
|
|
|
|
const char *escape;
|
|
|
|
const char *value;
|
|
|
|
};
|
|
|
|
|
2013-11-04 05:08:53 -08:00
|
|
|
struct _Dropable_Cbs
|
2010-12-20 03:09:19 -08:00
|
|
|
{
|
2013-11-04 05:08:53 -08:00
|
|
|
EINA_INLIST;
|
2011-12-27 03:24:13 -08:00
|
|
|
Elm_Sel_Format types;
|
2013-02-21 05:21:08 -08:00
|
|
|
Elm_Drag_State entercb;
|
|
|
|
Elm_Drag_State leavecb;
|
|
|
|
Elm_Drag_Pos poscb;
|
2012-05-09 01:43:45 -07:00
|
|
|
Elm_Drop_Cb dropcb;
|
2013-02-21 05:21:08 -08:00
|
|
|
void *enterdata;
|
|
|
|
void *leavedata;
|
|
|
|
void *posdata;
|
2013-10-27 02:27:17 -07:00
|
|
|
void *dropdata;
|
2013-11-04 05:08:53 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _Dropable
|
|
|
|
{
|
|
|
|
Evas_Object *obj;
|
|
|
|
/* FIXME: Cache window */
|
|
|
|
Eina_Inlist *cbs_list; /* List of Dropable_Cbs * */
|
2013-02-21 05:21:08 -08:00
|
|
|
struct {
|
2014-03-18 23:59:13 -07:00
|
|
|
Evas_Coord x, y;
|
|
|
|
Eina_Bool in : 1;
|
|
|
|
const char *type;
|
|
|
|
Elm_Sel_Format format;
|
2013-02-21 05:21:08 -08:00
|
|
|
} last;
|
2010-12-20 03:09:19 -08:00
|
|
|
};
|
|
|
|
|
2013-03-16 23:36:30 -07:00
|
|
|
struct _Item_Container_Drop_Info
|
|
|
|
{ /* Info kept for containers to support drop */
|
|
|
|
Evas_Object *obj;
|
|
|
|
Elm_Xy_Item_Get_Cb itemgetcb;
|
|
|
|
Elm_Drop_Item_Container_Cb dropcb;
|
|
|
|
Elm_Drag_Item_Container_Pos poscb;
|
|
|
|
};
|
|
|
|
typedef struct _Item_Container_Drop_Info Item_Container_Drop_Info;
|
|
|
|
|
|
|
|
struct _Anim_Icon
|
|
|
|
{
|
|
|
|
int start_x;
|
|
|
|
int start_y;
|
|
|
|
int start_w;
|
|
|
|
int start_h;
|
|
|
|
Evas_Object *o;
|
|
|
|
};
|
|
|
|
typedef struct _Anim_Icon Anim_Icon;
|
|
|
|
|
|
|
|
struct _Item_Container_Drag_Info
|
|
|
|
{ /* Info kept for containers to support drag */
|
|
|
|
Evas_Object *obj;
|
|
|
|
Ecore_Timer *tm; /* When this expires, start drag */
|
|
|
|
double anim_tm; /* Time period to set tm */
|
|
|
|
double tm_to_drag; /* Time period to set tm */
|
|
|
|
Elm_Xy_Item_Get_Cb itemgetcb;
|
|
|
|
Elm_Item_Container_Data_Get_Cb data_get;
|
|
|
|
|
|
|
|
Evas_Coord x_down; /* Mouse down x cord when drag starts */
|
|
|
|
Evas_Coord y_down; /* Mouse down y cord when drag starts */
|
|
|
|
|
|
|
|
/* Some extra information needed to impl default anim */
|
|
|
|
Evas *e;
|
|
|
|
Eina_List *icons; /* List of icons to animate (Anim_Icon) */
|
|
|
|
int final_icon_w; /* We need the w and h of the final icon for the animation */
|
|
|
|
int final_icon_h;
|
|
|
|
Ecore_Animator *ea;
|
|
|
|
|
|
|
|
Elm_Drag_User_Info user_info;
|
|
|
|
};
|
|
|
|
typedef struct _Item_Container_Drag_Info Item_Container_Drag_Info;
|
|
|
|
|
2015-03-10 02:34:06 -07:00
|
|
|
typedef struct _Cnp_Atom Cnp_Atom;
|
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
static int _elm_cnp_init_count = 0;
|
|
|
|
/* Stringshared, so I can just compare pointers later */
|
|
|
|
static const char *text_uri;
|
2013-05-13 04:18:24 -07:00
|
|
|
|
2015-02-25 00:36:34 -08:00
|
|
|
/* Hash table type->Elm_Sel_Format */
|
|
|
|
static Eina_Hash *_types_hash = NULL;
|
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
/* Data for DND in progress */
|
|
|
|
static Saved_Type savedtypes = { NULL, NULL, 0, 0, 0, EINA_FALSE };
|
|
|
|
|
2013-05-21 03:25:00 -07:00
|
|
|
/* Drag & Drop functions */
|
|
|
|
/* FIXME: Way too many globals */
|
|
|
|
static Eina_List *drops = NULL;
|
|
|
|
static Evas_Object *dragwin = NULL;
|
|
|
|
static int dragwin_x_start, dragwin_y_start;
|
|
|
|
static int dragwin_x_end, dragwin_y_end;
|
|
|
|
static int _dragx = 0, _dragy = 0;
|
|
|
|
static Ecore_Event_Handler *handler_pos = NULL;
|
|
|
|
static Ecore_Event_Handler *handler_drop = NULL;
|
|
|
|
static Ecore_Event_Handler *handler_enter = NULL;
|
|
|
|
static Ecore_Event_Handler *handler_status = NULL;
|
|
|
|
static Ecore_Event_Handler *handler_leave = NULL;
|
|
|
|
static Ecore_Event_Handler *handler_up = NULL;
|
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
/* TODO BUG: should NEVER have these as globals! They should be per context (window). */
|
2013-02-22 00:49:08 -08:00
|
|
|
static Elm_Drag_Pos dragposcb = NULL;
|
|
|
|
static Elm_Drag_Accept dragacceptcb = NULL;
|
|
|
|
static Elm_Drag_State dragdonecb = NULL;
|
|
|
|
static void *dragposdata = NULL;
|
|
|
|
static void *dragacceptdata = NULL;
|
2012-08-22 01:33:43 -07:00
|
|
|
static void *dragdonedata = NULL;
|
2013-02-22 00:49:08 -08:00
|
|
|
static Evas_Object *dragwidget = NULL;
|
|
|
|
static Elm_Xdnd_Action dragaction = ELM_XDND_ACTION_UNKNOWN;
|
2012-08-22 01:33:43 -07:00
|
|
|
|
2013-03-16 23:36:30 -07:00
|
|
|
static Eina_List *cont_drop_tg = NULL; /* List of Item_Container_Drop_Info */
|
|
|
|
static Eina_List *cont_drag_tg = NULL; /* List of Item_Container_Drag_Info */
|
|
|
|
|
|
|
|
static void _cont_obj_mouse_up( void *data, Evas *e, Evas_Object *obj, void *event_info);
|
|
|
|
static void _cont_obj_mouse_move( void *data, Evas *e, Evas_Object *obj, void *event_info);
|
2013-11-05 07:26:51 -08:00
|
|
|
static void _all_drop_targets_cbs_del(void *data, Evas *e, Evas_Object *obj, void *info);
|
2015-02-25 00:36:34 -08:00
|
|
|
static Eina_Bool _elm_cnp_shutdown(void);
|
2014-10-20 09:10:02 -07:00
|
|
|
static Eina_Bool _local_elm_drop_target_del(Evas_Object *obj, Elm_Sel_Format format,
|
|
|
|
Elm_Drag_State entercb, void *enterdata,
|
|
|
|
Elm_Drag_State leavecb, void *leavedata,
|
|
|
|
Elm_Drag_Pos poscb, void *posdata,
|
|
|
|
Elm_Drop_Cb dropcb, void *dropdata);
|
2013-03-16 23:36:30 -07:00
|
|
|
|
2013-05-21 03:25:00 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
2015-03-10 02:34:06 -07:00
|
|
|
static Ecore_X_Window _x11_elm_widget_xwin_get(const Evas_Object *obj);
|
2012-08-22 01:33:43 -07:00
|
|
|
static Tmp_Info *_tempfile_new (int size);
|
|
|
|
static int _tmpinfo_free (Tmp_Info *tmp);
|
2012-08-28 23:52:48 -07:00
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
typedef struct _X11_Cnp_Selection X11_Cnp_Selection;
|
|
|
|
|
|
|
|
typedef Eina_Bool (*X11_Converter_Fn_Cb) (char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
|
|
|
|
typedef int (*X11_Response_Handler_Cb) (X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *);
|
2015-06-13 23:53:45 -07:00
|
|
|
typedef Eina_Bool (*X11_Data_Preparer_Cb) (Ecore_X_Event_Selection_Notify *, Elm_Selection_Data *, Tmp_Info **);
|
2010-12-20 03:09:19 -08:00
|
|
|
|
2014-01-06 06:30:02 -08:00
|
|
|
static void _x11_sel_obj_del (void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED);
|
|
|
|
static void _x11_sel_obj_del2 (void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED);
|
|
|
|
static Eina_Bool _x11_selection_clear (void *udata EINA_UNUSED, int type, void *event);
|
|
|
|
static Eina_Bool _x11_selection_notify (void *udata EINA_UNUSED, int type, void *event);
|
2012-08-22 01:33:43 -07:00
|
|
|
static Eina_Bool _x11_targets_converter (char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
|
|
|
|
static Eina_Bool _x11_text_converter (char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
|
|
|
|
static Eina_Bool _x11_general_converter (char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
|
|
|
|
static Eina_Bool _x11_image_converter (char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
|
|
|
|
static Eina_Bool _x11_vcard_send (char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
|
2014-01-06 06:30:02 -08:00
|
|
|
static Eina_Bool _x11_is_uri_type_data (X11_Cnp_Selection *sel EINA_UNUSED, Ecore_X_Event_Selection_Notify *notify);
|
2015-06-13 10:33:14 -07:00
|
|
|
static Eina_Bool _x11_notify_handler_targets (X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
|
2015-06-13 23:53:45 -07:00
|
|
|
static Eina_Bool _x11_data_preparer_text (Ecore_X_Event_Selection_Notify *notify, Elm_Selection_Data *ddata, Tmp_Info **tmp_info);
|
2015-11-30 05:29:06 -08:00
|
|
|
static Eina_Bool _x11_data_preparer_markup (Ecore_X_Event_Selection_Notify *notify, Elm_Selection_Data *ddata, Tmp_Info **tmp_info);
|
2015-06-13 23:53:45 -07:00
|
|
|
static Eina_Bool _x11_data_preparer_image (Ecore_X_Event_Selection_Notify *notify, Elm_Selection_Data *ddata, Tmp_Info **tmp_info);
|
|
|
|
static Eina_Bool _x11_data_preparer_uri (Ecore_X_Event_Selection_Notify *notify, Elm_Selection_Data *ddata, Tmp_Info **tmp_info);
|
2012-08-22 01:33:43 -07:00
|
|
|
//static int _x11_notify_handler_html (X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
|
2015-06-13 23:53:45 -07:00
|
|
|
static Eina_Bool _x11_data_preparer_vcard (Ecore_X_Event_Selection_Notify *notify, Elm_Selection_Data *ddata, Tmp_Info **tmp_info);
|
2014-01-06 06:30:02 -08:00
|
|
|
static Eina_Bool _x11_dnd_enter (void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev);
|
|
|
|
static Eina_Bool _x11_dnd_drop (void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev);
|
|
|
|
static Eina_Bool _x11_dnd_position (void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev);
|
|
|
|
static Eina_Bool _x11_dnd_status (void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev);
|
|
|
|
static Eina_Bool _x11_dnd_leave (void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev);
|
|
|
|
static Eina_Bool _x11_drag_mouse_up (void *data, int etype EINA_UNUSED, void *event);
|
|
|
|
static void _x11_drag_move (void *data EINA_UNUSED, Ecore_X_Xdnd_Position *pos);
|
2012-08-22 02:37:00 -07:00
|
|
|
|
|
|
|
static Eina_Bool _x11_elm_cnp_init (void);
|
2014-01-23 05:22:33 -08:00
|
|
|
static Eina_Bool _x11_elm_cnp_selection_set (Ecore_X_Window xwin, Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format, const void *selbuf, size_t buflen);
|
2014-01-06 06:30:02 -08:00
|
|
|
static void _x11_elm_cnp_selection_loss_callback_set(Evas_Object *obj EINA_UNUSED, Elm_Sel_Type selection, Elm_Selection_Loss_Cb func, const void *data);
|
2012-08-22 02:37:00 -07:00
|
|
|
static Eina_Bool _x11_elm_object_cnp_selection_clear (Evas_Object *obj, Elm_Sel_Type selection);
|
2015-06-08 10:44:29 -07:00
|
|
|
static Eina_Bool _x11_elm_cnp_selection_get (Ecore_X_Window xwin, const Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format, Elm_Drop_Cb datacb, void *udata);
|
2013-09-30 03:21:31 -07:00
|
|
|
static Eina_Bool _x11_elm_drop_target_add (Evas_Object *obj, Elm_Sel_Format format,
|
2013-02-21 05:21:08 -08:00
|
|
|
Elm_Drag_State entercb, void *enterdata,
|
|
|
|
Elm_Drag_State leavecb, void *leavedata,
|
|
|
|
Elm_Drag_Pos poscb, void *posdata,
|
2013-10-27 02:27:17 -07:00
|
|
|
Elm_Drop_Cb dropcb, void *dropdata);
|
2013-11-04 05:08:53 -08:00
|
|
|
static Eina_Bool _x11_elm_drop_target_del (Evas_Object *obj, Elm_Sel_Format format,
|
|
|
|
Elm_Drag_State entercb, void *enterdata,
|
|
|
|
Elm_Drag_State leavecb, void *leavedata,
|
|
|
|
Elm_Drag_Pos poscb, void *posdata,
|
|
|
|
Elm_Drop_Cb dropcb, void *dropdata);
|
2014-01-06 06:30:02 -08:00
|
|
|
static Eina_Bool _x11_elm_selection_selection_has_owner (Evas_Object *obj EINA_UNUSED);
|
2012-08-22 01:33:43 -07:00
|
|
|
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
|
|
|
|
2016-05-03 02:07:48 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
typedef struct _Wl_Cnp_Selection Wl_Cnp_Selection;
|
|
|
|
|
|
|
|
typedef Eina_Bool (*Wl_Converter_Fn_Cb) (char *target, Wl_Cnp_Selection *sel, void *data, int size, void **data_ret, int *size_ret);
|
|
|
|
static Eina_Bool _wl_targets_converter(char *target, Wl_Cnp_Selection *sel, void *data, int size, void **data_ret, int *size_ret);
|
|
|
|
static Eina_Bool _wl_general_converter(char *target, Wl_Cnp_Selection *sel, void *data, int size, void **data_ret, int *size_ret);
|
|
|
|
static Eina_Bool _wl_text_converter(char *target, Wl_Cnp_Selection *sel, void *data, int size, void **data_ret, int *size_ret);
|
2016-05-03 02:30:39 -07:00
|
|
|
|
|
|
|
typedef Eina_Bool (*Wl_Data_Preparer_Cb) (Wl_Cnp_Selection *sel, Elm_Selection_Data *ddata, Ecore_Wl2_Event_Selection_Data_Ready *ev, Tmp_Info **tmp_info);
|
|
|
|
static Eina_Bool _wl_data_preparer_markup(Wl_Cnp_Selection *sel, Elm_Selection_Data *ddata, Ecore_Wl2_Event_Selection_Data_Ready *ev, Tmp_Info **tmp_info);
|
|
|
|
static Eina_Bool _wl_data_preparer_uri(Wl_Cnp_Selection *sel, Elm_Selection_Data *ddata, Ecore_Wl2_Event_Selection_Data_Ready *ev, Tmp_Info **tmp_info);
|
|
|
|
static Eina_Bool _wl_data_preparer_vcard(Wl_Cnp_Selection *sel, Elm_Selection_Data *ddata, Ecore_Wl2_Event_Selection_Data_Ready *ev, Tmp_Info **tmp_info);
|
|
|
|
static Eina_Bool _wl_data_preparer_image(Wl_Cnp_Selection *sel, Elm_Selection_Data *ddata, Ecore_Wl2_Event_Selection_Data_Ready *ev, Tmp_Info **tmp_info);
|
|
|
|
static Eina_Bool _wl_data_preparer_text(Wl_Cnp_Selection *sel, Elm_Selection_Data *ddata, Ecore_Wl2_Event_Selection_Data_Ready *ev, Tmp_Info **tmp_info);
|
2016-05-03 02:07:48 -07:00
|
|
|
#endif
|
|
|
|
|
2015-03-10 02:34:06 -07:00
|
|
|
struct _Cnp_Atom
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
Elm_Sel_Format formats;
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
/* Called by ecore to do conversion */
|
|
|
|
X11_Converter_Fn_Cb x_converter;
|
2015-06-13 23:53:45 -07:00
|
|
|
X11_Data_Preparer_Cb x_data_preparer;
|
2015-03-10 02:34:06 -07:00
|
|
|
/* Atom */
|
|
|
|
Ecore_X_Atom x_atom;
|
|
|
|
#endif
|
2016-05-03 02:07:48 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
Wl_Converter_Fn_Cb wl_converter;
|
2016-05-03 02:30:39 -07:00
|
|
|
Wl_Data_Preparer_Cb wl_data_preparer;
|
2016-05-03 02:07:48 -07:00
|
|
|
#endif
|
|
|
|
|
2015-03-10 02:34:06 -07:00
|
|
|
void *_term;
|
|
|
|
};
|
|
|
|
|
|
|
|
static Eina_List *
|
|
|
|
_dropable_list_geom_find(Evas *evas, Evas_Coord px, Evas_Coord py)
|
|
|
|
{
|
|
|
|
Eina_List *itr, *top_objects_list = NULL, *dropable_list = NULL;
|
|
|
|
Evas_Object *top_obj;
|
|
|
|
Dropable *dropable = NULL;
|
|
|
|
|
|
|
|
if (!drops) return NULL;
|
|
|
|
|
|
|
|
/* We retrieve the (non-smart) objects pointed by (px, py) */
|
|
|
|
top_objects_list = evas_tree_objects_at_xy_get(evas, NULL, px, py);
|
|
|
|
/* We walk on this list from the last because if the list contains more than one
|
|
|
|
* element, all but the last will repeat events. The last one can repeat events
|
|
|
|
* or not. Anyway, this last one is the first that has to be taken into account
|
|
|
|
* for the determination of the drop target.
|
|
|
|
*/
|
|
|
|
EINA_LIST_REVERSE_FOREACH(top_objects_list, itr, top_obj)
|
|
|
|
{
|
|
|
|
Evas_Object *object = top_obj;
|
|
|
|
/* We search for the dropable data into the object. If not found, we search into its parent.
|
|
|
|
* For example, if a button is a drop target, the first object will be an (internal) image.
|
|
|
|
* The drop target is attached to the button, i.e to image's parent. That's why we need to
|
|
|
|
* walk on the parents until NULL.
|
|
|
|
* If we find this dropable data, we found our drop target.
|
|
|
|
*/
|
|
|
|
while (object)
|
|
|
|
{
|
2016-03-02 04:10:48 -08:00
|
|
|
dropable = eo_key_data_get(object, "__elm_dropable");
|
2015-03-10 02:34:06 -07:00
|
|
|
if (dropable)
|
|
|
|
{
|
|
|
|
Eina_Bool exist = EINA_FALSE;
|
|
|
|
Eina_List *l;
|
|
|
|
Dropable *d = NULL;
|
|
|
|
EINA_LIST_FOREACH(dropable_list, l, d)
|
|
|
|
{
|
|
|
|
if (d == dropable)
|
|
|
|
{
|
|
|
|
exist = EINA_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!exist)
|
|
|
|
dropable_list = eina_list_append(dropable_list, dropable);
|
|
|
|
object = evas_object_smart_parent_get(object);
|
|
|
|
if (dropable)
|
|
|
|
cnp_debug("Drop target %p of type %s found\n",
|
|
|
|
dropable->obj, eo_class_name_get(eo_class_get(dropable->obj)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
object = evas_object_smart_parent_get(object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
eina_list_free(top_objects_list);
|
|
|
|
return dropable_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_dropable_coords_adjust(Dropable *dropable, Evas_Coord *x, Evas_Coord *y)
|
|
|
|
{
|
|
|
|
Ecore_Evas *ee;
|
|
|
|
Evas *evas = evas_object_evas_get(dropable->obj);
|
|
|
|
int ex = 0, ey = 0, ew = 0, eh = 0;
|
|
|
|
Evas_Object *win;
|
|
|
|
|
|
|
|
ee = ecore_evas_ecore_evas_get(evas);
|
|
|
|
ecore_evas_geometry_get(ee, &ex, &ey, &ew, &eh);
|
|
|
|
*x = *x - ex;
|
|
|
|
*y = *y - ey;
|
|
|
|
|
|
|
|
/* For Wayland, frame coords have to be subtracted. */
|
|
|
|
Evas_Coord fx, fy;
|
|
|
|
evas_output_framespace_get(evas, &fx, &fy, NULL, NULL);
|
|
|
|
if (fx || fy) cnp_debug("evas frame fx %d fy %d\n", fx, fy);
|
|
|
|
*x = *x - fx;
|
|
|
|
*y = *y - fy;
|
|
|
|
|
|
|
|
if (elm_widget_is(dropable->obj))
|
|
|
|
{
|
|
|
|
win = elm_widget_top_get(dropable->obj);
|
|
|
|
if (win && eo_isa(win, ELM_WIN_CLASS))
|
|
|
|
{
|
|
|
|
Evas_Coord x2, y2;
|
|
|
|
int rot = elm_win_rotation_get(win);
|
|
|
|
switch (rot)
|
|
|
|
{
|
|
|
|
case 90:
|
|
|
|
x2 = ew - *y;
|
|
|
|
y2 = *x;
|
|
|
|
break;
|
|
|
|
case 180:
|
|
|
|
x2 = ew - *x;
|
|
|
|
y2 = eh - *y;
|
|
|
|
break;
|
|
|
|
case 270:
|
|
|
|
x2 = *y;
|
|
|
|
y2 = eh - *x;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
x2 = *x;
|
|
|
|
y2 = *y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cnp_debug("rotation %d, w %d, h %d - x:%d->%d, y:%d->%d\n",
|
|
|
|
rot, ew, eh, *x, x2, *y, y2);
|
|
|
|
*x = x2;
|
|
|
|
*y = y2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Elm_Sel_Format
|
|
|
|
_dnd_types_to_format(const char **types, int ntypes)
|
|
|
|
{
|
|
|
|
Elm_Sel_Format ret_type = 0;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < ntypes; i++)
|
|
|
|
{
|
|
|
|
Cnp_Atom *atom = eina_hash_find(_types_hash, types[i]);
|
|
|
|
if (atom) ret_type |= atom->formats;
|
|
|
|
}
|
|
|
|
return ret_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_drag_cancel_animate(void *data EINA_UNUSED, double pos)
|
|
|
|
{ /* Animation to "move back" drag-window */
|
|
|
|
if (pos >= 0.99)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
Ecore_X_Window xdragwin = _x11_elm_widget_xwin_get(data);
|
|
|
|
ecore_x_window_ignore_set(xdragwin, 0);
|
|
|
|
#endif
|
|
|
|
evas_object_del(data);
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
x = dragwin_x_end - (pos * (dragwin_x_end - dragwin_x_start));
|
|
|
|
y = dragwin_y_end - (pos * (dragwin_y_end - dragwin_y_start));
|
|
|
|
evas_object_move(data, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_all_drop_targets_cbs_del(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Dropable *dropable = NULL;
|
2016-03-02 04:10:48 -08:00
|
|
|
dropable = eo_key_data_get(obj, "__elm_dropable");
|
2015-03-10 02:34:06 -07:00
|
|
|
if (dropable)
|
|
|
|
{
|
|
|
|
Dropable_Cbs *cbs;
|
|
|
|
while (dropable->cbs_list)
|
|
|
|
{
|
|
|
|
cbs = EINA_INLIST_CONTAINER_GET(dropable->cbs_list, Dropable_Cbs);
|
|
|
|
elm_drop_target_del(obj, cbs->types,
|
|
|
|
cbs->entercb, cbs->enterdata, cbs->leavecb, cbs->leavedata,
|
|
|
|
cbs->poscb, cbs->posdata, cbs->dropcb, cbs->dropdata);
|
|
|
|
// If elm_drop_target_del() happened to delete dropabale, then
|
|
|
|
// re-fetch it each loop to make sure it didn't
|
2016-03-02 04:10:48 -08:00
|
|
|
dropable = eo_key_data_get(obj, "__elm_dropable");
|
2015-03-10 02:34:06 -07:00
|
|
|
if (!dropable) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-09 09:17:52 -07:00
|
|
|
static Cnp_Atom _atoms[CNP_N_ATOMS] = {
|
|
|
|
ARRAYINIT(CNP_ATOM_TARGETS) {
|
|
|
|
.name = "TARGETS",
|
|
|
|
.formats = ELM_SEL_FORMAT_TARGETS,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_targets_converter,
|
2016-05-03 02:07:48 -07:00
|
|
|
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_converter = _wl_targets_converter,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_ATOM) {
|
|
|
|
.name = "ATOM", // for opera browser
|
|
|
|
.formats = ELM_SEL_FORMAT_TARGETS,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_targets_converter,
|
2016-05-03 02:07:48 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_converter = _wl_targets_converter,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_XELM) {
|
|
|
|
.name = "application/x-elementary-markup",
|
|
|
|
.formats = ELM_SEL_FORMAT_MARKUP,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_general_converter,
|
2015-11-30 05:29:06 -08:00
|
|
|
.x_data_preparer = _x11_data_preparer_markup,
|
2016-05-03 02:07:48 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_converter = _wl_general_converter,
|
2016-05-03 02:30:39 -07:00
|
|
|
.wl_data_preparer = _wl_data_preparer_markup,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_text_urilist) {
|
|
|
|
.name = "text/uri-list",
|
|
|
|
.formats = ELM_SEL_FORMAT_IMAGE,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_general_converter,
|
2015-06-13 23:53:45 -07:00
|
|
|
.x_data_preparer = _x11_data_preparer_uri,
|
2016-05-03 02:07:48 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_converter = _wl_general_converter,
|
2016-05-03 02:30:39 -07:00
|
|
|
.wl_data_preparer = _wl_data_preparer_uri,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_text_x_vcard) {
|
|
|
|
.name = "text/x-vcard",
|
|
|
|
.formats = ELM_SEL_FORMAT_VCARD,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_vcard_send,
|
2015-06-13 23:53:45 -07:00
|
|
|
.x_data_preparer = _x11_data_preparer_vcard,
|
2016-05-03 02:30:39 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_data_preparer = _wl_data_preparer_vcard,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_image_png) {
|
|
|
|
.name = "image/png",
|
|
|
|
.formats = ELM_SEL_FORMAT_IMAGE,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_image_converter,
|
2015-06-13 23:53:45 -07:00
|
|
|
.x_data_preparer = _x11_data_preparer_image,
|
2016-05-03 02:30:39 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_data_preparer = _wl_data_preparer_image,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_image_jpeg) {
|
|
|
|
.name = "image/jpeg",
|
|
|
|
.formats = ELM_SEL_FORMAT_IMAGE,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_image_converter,
|
2015-06-13 23:53:45 -07:00
|
|
|
.x_data_preparer = _x11_data_preparer_image,
|
2016-05-03 02:30:39 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_data_preparer = _wl_data_preparer_image,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_image_bmp) {
|
|
|
|
.name = "image/x-ms-bmp",
|
|
|
|
.formats = ELM_SEL_FORMAT_IMAGE,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_image_converter,
|
2015-06-13 23:53:45 -07:00
|
|
|
.x_data_preparer = _x11_data_preparer_image,
|
2016-05-03 02:30:39 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_data_preparer = _wl_data_preparer_image,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_image_gif) {
|
|
|
|
.name = "image/gif",
|
|
|
|
.formats = ELM_SEL_FORMAT_IMAGE,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_image_converter,
|
2015-06-13 23:53:45 -07:00
|
|
|
.x_data_preparer = _x11_data_preparer_image,
|
2016-05-03 02:30:39 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_data_preparer = _wl_data_preparer_image,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_image_tiff) {
|
|
|
|
.name = "image/tiff",
|
|
|
|
.formats = ELM_SEL_FORMAT_IMAGE,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_image_converter,
|
2015-06-13 23:53:45 -07:00
|
|
|
.x_data_preparer = _x11_data_preparer_image,
|
2016-05-03 02:30:39 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_data_preparer = _wl_data_preparer_image,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_image_svg) {
|
|
|
|
.name = "image/svg+xml",
|
|
|
|
.formats = ELM_SEL_FORMAT_IMAGE,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_image_converter,
|
2015-06-13 23:53:45 -07:00
|
|
|
.x_data_preparer = _x11_data_preparer_image,
|
2016-05-03 02:30:39 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_data_preparer = _wl_data_preparer_image,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_image_xpm) {
|
|
|
|
.name = "image/x-xpixmap",
|
|
|
|
.formats = ELM_SEL_FORMAT_IMAGE,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_image_converter,
|
2015-06-13 23:53:45 -07:00
|
|
|
.x_data_preparer = _x11_data_preparer_image,
|
2016-05-03 02:30:39 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_data_preparer = _wl_data_preparer_image,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_image_tga) {
|
|
|
|
.name = "image/x-tga",
|
|
|
|
.formats = ELM_SEL_FORMAT_IMAGE,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_image_converter,
|
2015-06-13 23:53:45 -07:00
|
|
|
.x_data_preparer = _x11_data_preparer_image,
|
2016-05-03 02:30:39 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_data_preparer = _wl_data_preparer_image,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_image_ppm) {
|
|
|
|
.name = "image/x-portable-pixmap",
|
|
|
|
.formats = ELM_SEL_FORMAT_IMAGE,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_image_converter,
|
2015-06-13 23:53:45 -07:00
|
|
|
.x_data_preparer = _x11_data_preparer_image,
|
2016-05-03 02:30:39 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_data_preparer = _wl_data_preparer_image,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2013-09-30 03:21:31 -07:00
|
|
|
/*
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_text_html_utf8) {
|
|
|
|
.name = "text/html;charset=utf-8",
|
|
|
|
.formats = ELM_SEL_FORMAT_HTML,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_general_converter,
|
|
|
|
.x_notify = _x11_notify_handler_html,
|
2016-05-03 02:07:48 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_converter = _wl_general_converter,
|
2016-05-03 02:30:39 -07:00
|
|
|
.wl_data_preparer = _wl_data_preparer_handler_html,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2016-05-03 02:30:39 -07:00
|
|
|
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_text_html) {
|
|
|
|
.name = "text/html",
|
|
|
|
.formats = ELM_SEL_FORMAT_HTML,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_general_converter,
|
|
|
|
.x_notify = _x11_notify_handler_html,
|
2016-05-03 02:07:48 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_converter = _wl_general_converter,
|
2016-05-03 02:30:39 -07:00
|
|
|
.wl_data_preparer = _wl_data_preparer_handler_html,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2012-07-16 02:16:30 -07:00
|
|
|
*/
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_UTF8STRING) {
|
|
|
|
.name = "UTF8_STRING",
|
|
|
|
.formats = ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_text_converter,
|
2015-06-13 23:53:45 -07:00
|
|
|
.x_data_preparer = _x11_data_preparer_text,
|
2016-05-03 02:07:48 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_converter = _wl_text_converter,
|
2016-05-03 02:30:39 -07:00
|
|
|
.wl_data_preparer = _wl_data_preparer_text,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_STRING) {
|
|
|
|
.name = "STRING",
|
|
|
|
.formats = ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_text_converter,
|
2015-06-13 23:53:45 -07:00
|
|
|
.x_data_preparer = _x11_data_preparer_text,
|
2016-05-03 02:07:48 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_converter = _wl_text_converter,
|
2016-05-03 02:30:39 -07:00
|
|
|
.wl_data_preparer = _wl_data_preparer_text,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_COMPOUND_TEXT) {
|
|
|
|
.name = "COMPOUND_TEXT",
|
|
|
|
.formats = ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_text_converter,
|
2015-06-13 23:53:45 -07:00
|
|
|
.x_data_preparer = _x11_data_preparer_text,
|
2016-05-03 02:07:48 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_converter = _wl_text_converter,
|
2016-05-03 02:30:39 -07:00
|
|
|
.wl_data_preparer = _wl_data_preparer_text,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-10-04 16:19:05 -07:00
|
|
|
},
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_TEXT) {
|
|
|
|
.name = "TEXT",
|
|
|
|
.formats = ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_text_converter,
|
2015-06-13 23:53:45 -07:00
|
|
|
.x_data_preparer = _x11_data_preparer_text,
|
2016-05-03 02:07:48 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_converter = _wl_text_converter,
|
2016-05-03 02:30:39 -07:00
|
|
|
.wl_data_preparer = _wl_data_preparer_text,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_text_plain_utf8) {
|
|
|
|
.name = "text/plain;charset=utf-8",
|
|
|
|
.formats = ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_text_converter,
|
2015-06-13 23:53:45 -07:00
|
|
|
.x_data_preparer = _x11_data_preparer_text,
|
2016-05-03 02:07:48 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_converter = _wl_text_converter,
|
2016-05-03 02:30:39 -07:00
|
|
|
.wl_data_preparer = _wl_data_preparer_text,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2015-03-09 09:17:52 -07:00
|
|
|
ARRAYINIT(CNP_ATOM_text_plain) {
|
|
|
|
.name = "text/plain",
|
|
|
|
.formats = ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
.x_converter = _x11_text_converter,
|
2015-06-13 23:53:45 -07:00
|
|
|
.x_data_preparer = _x11_data_preparer_text,
|
2016-05-03 02:07:48 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
.wl_converter = _wl_text_converter,
|
2016-05-03 02:30:39 -07:00
|
|
|
.wl_data_preparer = _wl_data_preparer_text,
|
2015-03-09 09:17:52 -07:00
|
|
|
#endif
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
2010-06-17 01:06:07 -07:00
|
|
|
};
|
|
|
|
|
2015-03-10 02:34:06 -07:00
|
|
|
// x11 specific stuff
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2015-03-09 09:17:52 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
2015-03-10 02:34:06 -07:00
|
|
|
#define ARRAYINIT(foo) [foo] =
|
|
|
|
struct _X11_Cnp_Selection
|
|
|
|
{
|
|
|
|
const char *debug;
|
|
|
|
Evas_Object *widget;
|
|
|
|
char *selbuf;
|
|
|
|
Evas_Object *requestwidget;
|
|
|
|
void *udata;
|
|
|
|
Elm_Sel_Format requestformat;
|
|
|
|
Elm_Drop_Cb datacb;
|
|
|
|
Eina_Bool (*set) (Ecore_X_Window, const void *data, int size);
|
|
|
|
Eina_Bool (*clear) (void);
|
|
|
|
void (*request) (Ecore_X_Window, const char *target);
|
|
|
|
Elm_Selection_Loss_Cb loss_cb;
|
|
|
|
void *loss_data;
|
|
|
|
|
|
|
|
Elm_Sel_Format format;
|
|
|
|
Ecore_X_Selection ecore_sel;
|
|
|
|
Ecore_X_Window xwin;
|
|
|
|
Elm_Xdnd_Action action;
|
|
|
|
|
|
|
|
Eina_Bool active : 1;
|
|
|
|
};
|
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
static X11_Cnp_Selection _x11_selections[ELM_SEL_TYPE_CLIPBOARD + 1] = {
|
2012-06-25 04:16:25 -07:00
|
|
|
ARRAYINIT(ELM_SEL_TYPE_PRIMARY) {
|
|
|
|
.debug = "Primary",
|
|
|
|
.ecore_sel = ECORE_X_SELECTION_PRIMARY,
|
|
|
|
.set = ecore_x_selection_primary_set,
|
|
|
|
.clear = ecore_x_selection_primary_clear,
|
|
|
|
.request = ecore_x_selection_primary_request,
|
|
|
|
},
|
|
|
|
ARRAYINIT(ELM_SEL_TYPE_SECONDARY) {
|
|
|
|
.debug = "Secondary",
|
|
|
|
.ecore_sel = ECORE_X_SELECTION_SECONDARY,
|
|
|
|
.set = ecore_x_selection_secondary_set,
|
|
|
|
.clear = ecore_x_selection_secondary_clear,
|
|
|
|
.request = ecore_x_selection_secondary_request,
|
|
|
|
},
|
|
|
|
ARRAYINIT(ELM_SEL_TYPE_XDND) {
|
|
|
|
.debug = "XDnD",
|
|
|
|
.ecore_sel = ECORE_X_SELECTION_XDND,
|
|
|
|
.request = ecore_x_selection_xdnd_request,
|
|
|
|
},
|
|
|
|
ARRAYINIT(ELM_SEL_TYPE_CLIPBOARD) {
|
|
|
|
.debug = "Clipboard",
|
|
|
|
.ecore_sel = ECORE_X_SELECTION_CLIPBOARD,
|
|
|
|
.set = ecore_x_selection_clipboard_set,
|
|
|
|
.clear = ecore_x_selection_clipboard_clear,
|
|
|
|
.request = ecore_x_selection_clipboard_request,
|
|
|
|
},
|
2010-06-17 01:06:07 -07:00
|
|
|
};
|
|
|
|
|
2012-06-25 04:16:25 -07:00
|
|
|
static void
|
2014-01-06 06:30:02 -08:00
|
|
|
_x11_sel_obj_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
|
2012-06-25 04:16:25 -07:00
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
X11_Cnp_Selection *sel = data;
|
2015-06-24 22:54:36 -07:00
|
|
|
if (sel->widget == obj)
|
|
|
|
{
|
|
|
|
sel->loss_cb = NULL;
|
|
|
|
sel->loss_data = NULL;
|
|
|
|
sel->widget = NULL;
|
|
|
|
}
|
2013-02-22 00:49:08 -08:00
|
|
|
if (dragwidget == obj) dragwidget = NULL;
|
2012-06-25 04:16:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-01-06 06:30:02 -08:00
|
|
|
_x11_sel_obj_del2(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
|
2012-06-25 04:16:25 -07:00
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
X11_Cnp_Selection *sel = data;
|
2012-06-25 04:16:25 -07:00
|
|
|
if (sel->requestwidget == obj) sel->requestwidget = NULL;
|
|
|
|
}
|
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_x11_selection_clear(void *udata EINA_UNUSED, int type EINA_UNUSED, void *event)
|
2010-06-25 05:14:34 -07:00
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
Ecore_X_Event_Selection_Clear *ev = event;
|
|
|
|
X11_Cnp_Selection *sel;
|
|
|
|
unsigned int i;
|
2010-06-17 01:06:07 -07:00
|
|
|
|
2012-08-28 00:49:27 -07:00
|
|
|
_x11_elm_cnp_init();
|
2012-08-22 01:33:43 -07:00
|
|
|
for (i = ELM_SEL_TYPE_PRIMARY; i <= ELM_SEL_TYPE_CLIPBOARD; i++)
|
|
|
|
{
|
|
|
|
if (_x11_selections[i].ecore_sel == ev->selection) break;
|
|
|
|
}
|
|
|
|
cnp_debug("selection %d clear\n", i);
|
|
|
|
/* Not me... Don't care */
|
|
|
|
if (i > ELM_SEL_TYPE_CLIPBOARD) return ECORE_CALLBACK_PASS_ON;
|
2010-06-17 01:06:07 -07:00
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
sel = _x11_selections + i;
|
|
|
|
if (sel->loss_cb) sel->loss_cb(sel->loss_data, i);
|
2012-06-25 04:16:25 -07:00
|
|
|
if (sel->widget)
|
|
|
|
evas_object_event_callback_del_full(sel->widget, EVAS_CALLBACK_DEL,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_sel_obj_del, sel);
|
2012-06-25 04:16:25 -07:00
|
|
|
if (sel->requestwidget)
|
|
|
|
evas_object_event_callback_del_full(sel->requestwidget, EVAS_CALLBACK_DEL,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_sel_obj_del2, sel);
|
2010-06-17 01:06:07 -07:00
|
|
|
sel->widget = NULL;
|
2012-06-25 04:16:25 -07:00
|
|
|
sel->requestwidget = NULL;
|
2015-06-23 07:58:48 -07:00
|
|
|
sel->loss_cb = NULL;
|
|
|
|
sel->loss_data = NULL;
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2012-06-25 04:16:25 -07:00
|
|
|
sel->active = EINA_FALSE;
|
2013-05-29 04:47:08 -07:00
|
|
|
ELM_SAFE_FREE(sel->selbuf, free);
|
2012-08-22 01:33:43 -07:00
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
2010-06-17 01:06:07 -07:00
|
|
|
}
|
|
|
|
|
2010-06-30 06:20:58 -07:00
|
|
|
/*
|
|
|
|
* Response to a selection notify:
|
2012-05-22 19:15:56 -07:00
|
|
|
* - So we have asked for the selection list.
|
|
|
|
* - If it's the targets list, parse it, and fire of what we want,
|
|
|
|
* else it's the data we want.
|
2010-06-23 01:02:35 -07:00
|
|
|
*/
|
2010-06-25 02:58:14 -07:00
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_x11_selection_notify(void *udata EINA_UNUSED, int type EINA_UNUSED, void *event)
|
2010-12-20 03:09:19 -08:00
|
|
|
{
|
2010-06-23 01:02:35 -07:00
|
|
|
Ecore_X_Event_Selection_Notify *ev = event;
|
2012-08-22 01:33:43 -07:00
|
|
|
X11_Cnp_Selection *sel;
|
2010-06-23 01:02:35 -07:00
|
|
|
int i;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-06-30 06:20:58 -07:00
|
|
|
cnp_debug("selection notify callback: %d\n",ev->selection);
|
2010-12-20 03:09:19 -08:00
|
|
|
switch (ev->selection)
|
|
|
|
{
|
2010-06-23 01:02:35 -07:00
|
|
|
case ECORE_X_SELECTION_PRIMARY:
|
2012-08-22 01:33:43 -07:00
|
|
|
sel = _x11_selections + ELM_SEL_TYPE_PRIMARY;
|
|
|
|
break;
|
2010-06-23 01:02:35 -07:00
|
|
|
case ECORE_X_SELECTION_SECONDARY:
|
2012-08-22 01:33:43 -07:00
|
|
|
sel = _x11_selections + ELM_SEL_TYPE_SECONDARY;
|
|
|
|
break;
|
2010-09-06 23:56:16 -07:00
|
|
|
case ECORE_X_SELECTION_XDND:
|
2012-08-22 01:33:43 -07:00
|
|
|
sel = _x11_selections + ELM_SEL_TYPE_XDND;
|
|
|
|
break;
|
2012-02-22 18:52:07 -08:00
|
|
|
case ECORE_X_SELECTION_CLIPBOARD:
|
2012-08-22 01:33:43 -07:00
|
|
|
sel = _x11_selections + ELM_SEL_TYPE_CLIPBOARD;
|
|
|
|
break;
|
2010-06-23 01:02:35 -07:00
|
|
|
default:
|
2012-08-22 01:33:43 -07:00
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
2010-12-20 03:09:19 -08:00
|
|
|
}
|
|
|
|
cnp_debug("Target is %s\n", ev->target);
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2015-06-19 04:18:18 -07:00
|
|
|
if (ev->selection != ECORE_X_SELECTION_XDND &&
|
|
|
|
(!strcmp(ev->target, "TARGETS") || !strcmp(ev->target, "ATOMS")))
|
2015-06-13 10:33:14 -07:00
|
|
|
{
|
|
|
|
_x11_notify_handler_targets(sel, ev);
|
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
|
|
|
}
|
2010-12-20 03:09:19 -08:00
|
|
|
for (i = 0; i < CNP_N_ATOMS; i++)
|
2010-06-23 01:02:35 -07:00
|
|
|
{
|
2015-03-09 09:17:52 -07:00
|
|
|
if (!strcmp(ev->target, _atoms[i].name))
|
2011-04-01 04:35:07 -07:00
|
|
|
{
|
2015-06-13 23:53:45 -07:00
|
|
|
if (_atoms[i].x_data_preparer)
|
2010-12-20 03:09:19 -08:00
|
|
|
{
|
2015-06-13 10:33:14 -07:00
|
|
|
Elm_Selection_Data ddata;
|
|
|
|
Tmp_Info *tmp_info = NULL;
|
|
|
|
Eina_Bool success;
|
|
|
|
ddata.data = NULL;
|
2015-03-09 09:17:52 -07:00
|
|
|
cnp_debug("Found something: %s\n", _atoms[i].name);
|
2015-06-13 23:53:45 -07:00
|
|
|
success = _atoms[i].x_data_preparer(ev, &ddata, &tmp_info);
|
2015-06-13 10:33:14 -07:00
|
|
|
if (_atoms[i].formats == ELM_SEL_FORMAT_IMAGE && savedtypes.imgfile) break;
|
|
|
|
if (ev->selection == ECORE_X_SELECTION_XDND)
|
|
|
|
{
|
|
|
|
if (success)
|
|
|
|
{
|
|
|
|
Dropable *dropable;
|
|
|
|
Eina_List *l;
|
|
|
|
cnp_debug("drag & drop\n");
|
|
|
|
EINA_LIST_FOREACH(drops, l, dropable)
|
|
|
|
{
|
|
|
|
if (dropable->obj == sel->requestwidget) break;
|
|
|
|
dropable = NULL;
|
|
|
|
}
|
|
|
|
if (dropable)
|
|
|
|
{
|
|
|
|
Dropable_Cbs *cbs;
|
|
|
|
Eina_Inlist *itr;
|
|
|
|
ddata.x = savedtypes.x;
|
|
|
|
ddata.y = savedtypes.y;
|
|
|
|
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
|
|
|
|
if ((cbs->types & dropable->last.format) && cbs->dropcb)
|
|
|
|
cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* We have to finish DnD, no matter what */
|
|
|
|
ecore_x_dnd_send_finished();
|
|
|
|
}
|
|
|
|
else if (sel->datacb && success)
|
|
|
|
{
|
|
|
|
ddata.x = ddata.y = 0;
|
|
|
|
sel->datacb(sel->udata, sel->requestwidget, &ddata);
|
|
|
|
}
|
|
|
|
free(ddata.data);
|
|
|
|
if (tmp_info) _tmpinfo_free(tmp_info);
|
2010-12-20 03:09:19 -08:00
|
|
|
}
|
2012-08-22 01:33:43 -07:00
|
|
|
else cnp_debug("Ignored: No handler!\n");
|
2014-06-29 19:50:56 -07:00
|
|
|
break;
|
2011-04-01 04:35:07 -07:00
|
|
|
}
|
2010-06-23 01:02:35 -07:00
|
|
|
}
|
2010-06-25 02:58:14 -07:00
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
2010-06-23 01:02:35 -07:00
|
|
|
}
|
|
|
|
|
2011-12-20 00:37:26 -08:00
|
|
|
static Elm_Sel_Format
|
|
|
|
_get_selection_type(void *data, int size)
|
|
|
|
{
|
|
|
|
if (size == sizeof(Elm_Sel_Type))
|
|
|
|
{
|
2012-05-22 19:15:56 -07:00
|
|
|
unsigned int seltype = *((unsigned int *)data);
|
|
|
|
if (seltype > ELM_SEL_TYPE_CLIPBOARD)
|
|
|
|
return ELM_SEL_FORMAT_NONE;
|
2012-08-22 01:33:43 -07:00
|
|
|
X11_Cnp_Selection *sel = _x11_selections + seltype;
|
2011-12-20 19:49:53 -08:00
|
|
|
if (sel->active &&
|
2011-12-27 03:24:13 -08:00
|
|
|
(sel->format >= ELM_SEL_FORMAT_TARGETS) &&
|
2012-02-22 18:52:07 -08:00
|
|
|
(sel->format <= ELM_SEL_FORMAT_HTML))
|
2011-12-20 00:37:26 -08:00
|
|
|
return sel->format;
|
|
|
|
}
|
|
|
|
return ELM_SEL_FORMAT_NONE;
|
|
|
|
}
|
2010-06-30 06:20:58 -07:00
|
|
|
|
2010-09-27 11:45:38 -07:00
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_x11_targets_converter(char *target EINA_UNUSED, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize)
|
2010-12-20 03:09:19 -08:00
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
int i, count;
|
2010-06-17 01:06:07 -07:00
|
|
|
Ecore_X_Atom *aret;
|
2012-08-22 01:33:43 -07:00
|
|
|
X11_Cnp_Selection *sel;
|
2011-12-20 19:49:53 -08:00
|
|
|
Elm_Sel_Format seltype;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-09-27 11:45:38 -07:00
|
|
|
if (!data_ret) return EINA_FALSE;
|
2011-12-20 00:37:26 -08:00
|
|
|
if (_get_selection_type(data, size) == ELM_SEL_FORMAT_NONE)
|
2011-09-10 12:43:46 -07:00
|
|
|
{
|
2011-12-20 19:49:53 -08:00
|
|
|
/* TODO : fallback into precise type */
|
|
|
|
seltype = ELM_SEL_FORMAT_TEXT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
sel = _x11_selections + *((int *)data);
|
2011-12-20 19:49:53 -08:00
|
|
|
seltype = sel->format;
|
2011-09-10 12:43:46 -07:00
|
|
|
}
|
2010-06-17 01:06:07 -07:00
|
|
|
|
2015-06-19 04:18:18 -07:00
|
|
|
for (i = CNP_ATOM_LISTING_ATOMS + 1, count = 0; i < CNP_N_ATOMS ; i++)
|
2010-12-20 03:09:19 -08:00
|
|
|
{
|
2015-03-09 09:17:52 -07:00
|
|
|
if (seltype & _atoms[i].formats) count++;
|
2010-12-20 03:09:19 -08:00
|
|
|
}
|
2010-06-17 01:06:07 -07:00
|
|
|
aret = malloc(sizeof(Ecore_X_Atom) * count);
|
2012-05-21 21:42:45 -07:00
|
|
|
if (!aret) return EINA_FALSE;
|
2015-06-19 04:18:18 -07:00
|
|
|
for (i = CNP_ATOM_LISTING_ATOMS + 1, count = 0; i < CNP_N_ATOMS ; i++)
|
2010-12-20 03:09:19 -08:00
|
|
|
{
|
2015-03-09 09:17:52 -07:00
|
|
|
if (seltype & _atoms[i].formats)
|
|
|
|
aret[count ++] = _atoms[i].x_atom;
|
2010-12-20 03:09:19 -08:00
|
|
|
}
|
2010-06-17 01:06:07 -07:00
|
|
|
|
2010-07-13 19:20:30 -07:00
|
|
|
*data_ret = aret;
|
2010-06-17 01:06:07 -07:00
|
|
|
if (typesize) *typesize = 32 /* urk */;
|
2010-12-20 03:09:19 -08:00
|
|
|
if (ttype) *ttype = ECORE_X_ATOM_ATOM;
|
2010-06-17 01:06:07 -07:00
|
|
|
if (size_ret) *size_ret = count;
|
2010-09-27 11:45:38 -07:00
|
|
|
return EINA_TRUE;
|
2010-06-17 01:06:07 -07:00
|
|
|
}
|
|
|
|
|
2010-09-27 11:45:38 -07:00
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_x11_image_converter(char *target EINA_UNUSED, void *data EINA_UNUSED, int size EINA_UNUSED, void **data_ret EINA_UNUSED, int *size_ret EINA_UNUSED, Ecore_X_Atom *ttype EINA_UNUSED, int *typesize EINA_UNUSED)
|
2010-08-18 12:18:42 -07:00
|
|
|
{
|
2010-12-20 03:09:19 -08:00
|
|
|
cnp_debug("Image converter called\n");
|
2010-09-27 11:45:38 -07:00
|
|
|
return EINA_TRUE;
|
2010-06-30 06:20:58 -07:00
|
|
|
}
|
|
|
|
|
2010-09-27 11:45:38 -07:00
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_x11_vcard_send(char *target EINA_UNUSED, void *data EINA_UNUSED, int size EINA_UNUSED, void **data_ret, int *size_ret, Ecore_X_Atom *ttype EINA_UNUSED, int *typesize EINA_UNUSED)
|
2010-09-16 22:39:00 -07:00
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
X11_Cnp_Selection *sel;
|
2010-09-21 21:42:36 -07:00
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
cnp_debug("Vcard send called\n");
|
2012-08-22 01:33:43 -07:00
|
|
|
sel = _x11_selections + *((int *)data);
|
2010-09-21 21:42:36 -07:00
|
|
|
if (data_ret) *data_ret = strdup(sel->selbuf);
|
|
|
|
if (size_ret) *size_ret = strlen(sel->selbuf);
|
2010-09-27 11:45:38 -07:00
|
|
|
return EINA_TRUE;
|
2010-09-16 22:39:00 -07:00
|
|
|
}
|
2011-06-22 22:52:40 -07:00
|
|
|
|
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_x11_is_uri_type_data(X11_Cnp_Selection *sel EINA_UNUSED, Ecore_X_Event_Selection_Notify *notify)
|
2011-06-22 22:52:40 -07:00
|
|
|
{
|
|
|
|
Ecore_X_Selection_Data *data;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
data = notify->data;
|
|
|
|
cnp_debug("data->format is %d %p %p\n", data->format, notify, data);
|
|
|
|
if (data->content == ECORE_X_SELECTION_CONTENT_FILES) return EINA_TRUE;
|
2011-12-28 04:54:59 -08:00
|
|
|
p = (char *)data->data;
|
2011-06-22 22:52:40 -07:00
|
|
|
if (!p) return EINA_TRUE;
|
|
|
|
cnp_debug("Got %s\n", p);
|
2014-01-12 21:00:09 -08:00
|
|
|
if (strncmp(p, "file:/", 6))
|
2011-06-22 22:52:40 -07:00
|
|
|
{
|
|
|
|
if (*p != '/') return EINA_FALSE;
|
|
|
|
}
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-06-30 06:20:58 -07:00
|
|
|
/*
|
|
|
|
* Callback to handle a targets response on a selection request:
|
|
|
|
* So pick the format we'd like; and then request it.
|
|
|
|
*/
|
2015-06-13 10:33:14 -07:00
|
|
|
static Eina_Bool
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_targets(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
|
2010-08-18 12:18:42 -07:00
|
|
|
{
|
2010-06-30 06:20:58 -07:00
|
|
|
Ecore_X_Selection_Data_Targets *targets;
|
|
|
|
Ecore_X_Atom *atomlist;
|
2010-12-20 03:09:19 -08:00
|
|
|
int i, j;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-06-30 06:20:58 -07:00
|
|
|
targets = notify->data;
|
|
|
|
atomlist = (Ecore_X_Atom *)(targets->data.data);
|
2012-08-22 01:33:43 -07:00
|
|
|
for (j = (CNP_ATOM_LISTING_ATOMS + 1); j < CNP_N_ATOMS; j++)
|
2010-06-30 06:20:58 -07:00
|
|
|
{
|
2015-03-09 09:17:52 -07:00
|
|
|
cnp_debug("\t%s %d\n", _atoms[j].name, _atoms[j].x_atom);
|
|
|
|
if (!(_atoms[j].formats & sel->requestformat)) continue;
|
2011-04-01 04:35:07 -07:00
|
|
|
for (i = 0; i < targets->data.length; i++)
|
|
|
|
{
|
2015-06-13 23:53:45 -07:00
|
|
|
if ((_atoms[j].x_atom == atomlist[i]) && (_atoms[j].x_data_preparer))
|
2011-04-01 04:35:07 -07:00
|
|
|
{
|
2015-07-29 07:26:14 -07:00
|
|
|
if (j == CNP_ATOM_text_urilist)
|
2011-06-22 22:52:40 -07:00
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
if (!_x11_is_uri_type_data(sel, notify)) continue;
|
2011-06-22 22:52:40 -07:00
|
|
|
}
|
2015-03-09 09:17:52 -07:00
|
|
|
cnp_debug("Atom %s matches\n", _atoms[j].name);
|
2011-04-01 04:35:07 -07:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
2010-06-30 06:20:58 -07:00
|
|
|
}
|
|
|
|
cnp_debug("Couldn't find anything that matches\n");
|
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
2011-04-01 04:35:07 -07:00
|
|
|
done:
|
2012-06-19 16:33:57 -07:00
|
|
|
cnp_debug("Sending request for %s, xwin=%#llx\n",
|
2015-03-09 09:17:52 -07:00
|
|
|
_atoms[j].name, (unsigned long long)sel->xwin);
|
|
|
|
sel->request(sel->xwin, _atoms[j].name);
|
2010-06-30 06:20:58 -07:00
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
|
|
|
}
|
2010-06-17 01:06:07 -07:00
|
|
|
|
2015-06-13 10:33:14 -07:00
|
|
|
static Eina_Bool
|
2015-06-13 23:53:45 -07:00
|
|
|
_x11_data_preparer_text(Ecore_X_Event_Selection_Notify *notify,
|
2015-06-13 10:33:14 -07:00
|
|
|
Elm_Selection_Data *ddata, Tmp_Info **tmp_info EINA_UNUSED)
|
2010-08-18 12:18:42 -07:00
|
|
|
{
|
2015-06-13 10:33:14 -07:00
|
|
|
Ecore_X_Selection_Data *data = notify->data;
|
|
|
|
ddata->format = ELM_SEL_FORMAT_TEXT;
|
|
|
|
ddata->data = eina_memdup(data->data, data->length, EINA_TRUE);
|
|
|
|
ddata->len = data->length;
|
|
|
|
return EINA_TRUE;
|
2010-06-23 01:02:35 -07:00
|
|
|
}
|
|
|
|
|
2015-11-30 05:29:06 -08:00
|
|
|
static Eina_Bool
|
|
|
|
_x11_data_preparer_markup(Ecore_X_Event_Selection_Notify *notify,
|
|
|
|
Elm_Selection_Data *ddata, Tmp_Info **tmp_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Ecore_X_Selection_Data *data = notify->data;
|
|
|
|
ddata->format = ELM_SEL_FORMAT_MARKUP;
|
|
|
|
ddata->data = eina_memdup(data->data, data->length, EINA_TRUE);
|
|
|
|
ddata->len = data->length;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-06-30 06:20:58 -07:00
|
|
|
/**
|
|
|
|
* So someone is pasting an image into my entry or widget...
|
|
|
|
*/
|
2015-06-13 10:33:14 -07:00
|
|
|
static Eina_Bool
|
2015-06-13 23:53:45 -07:00
|
|
|
_x11_data_preparer_uri(Ecore_X_Event_Selection_Notify *notify,
|
2015-06-13 10:33:14 -07:00
|
|
|
Elm_Selection_Data *ddata, Tmp_Info **tmp_info EINA_UNUSED)
|
2010-06-30 06:20:58 -07:00
|
|
|
{
|
|
|
|
Ecore_X_Selection_Data *data;
|
2010-09-06 23:56:16 -07:00
|
|
|
Ecore_X_Selection_Data_Files *files;
|
2013-02-19 02:14:35 -08:00
|
|
|
char *p, *s, *stripstr = NULL;
|
2010-06-30 06:20:58 -07:00
|
|
|
|
|
|
|
data = notify->data;
|
2010-12-20 03:09:19 -08:00
|
|
|
cnp_debug("data->format is %d %p %p\n", data->format, notify, data);
|
2010-09-06 23:56:16 -07:00
|
|
|
if (data->content == ECORE_X_SELECTION_CONTENT_FILES)
|
|
|
|
{
|
2013-02-19 02:14:35 -08:00
|
|
|
int i, len = 0;
|
2014-11-28 23:06:50 -08:00
|
|
|
Efreet_Uri **uri;
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2010-09-06 23:56:16 -07:00
|
|
|
cnp_debug("got a files list\n");
|
|
|
|
files = notify->data;
|
2013-02-19 02:14:35 -08:00
|
|
|
/*
|
2010-09-06 23:56:16 -07:00
|
|
|
if (files->num_files > 1)
|
|
|
|
{
|
2013-02-19 02:14:35 -08:00
|
|
|
// Don't handle many items <- this makes mr bigglesworth sad :(
|
2010-09-06 23:56:16 -07:00
|
|
|
cnp_debug("more then one file: Bailing\n");
|
2015-06-13 10:33:14 -07:00
|
|
|
return EINA_FALSE;
|
2010-09-06 23:56:16 -07:00
|
|
|
}
|
2011-09-30 01:48:25 -07:00
|
|
|
stripstr = p = strdup(files->files[0]);
|
2013-02-19 02:14:35 -08:00
|
|
|
*/
|
2014-11-28 23:06:50 -08:00
|
|
|
|
|
|
|
uri = calloc(1, sizeof(*uri) * files->num_files);
|
2015-06-13 10:33:14 -07:00
|
|
|
if (!uri) return EINA_FALSE;
|
2014-11-28 23:06:50 -08:00
|
|
|
|
2013-02-19 02:14:35 -08:00
|
|
|
for (i = 0; i < files->num_files ; i++)
|
|
|
|
{
|
2014-11-28 23:06:50 -08:00
|
|
|
uri[i] = efreet_uri_decode(files->files[i]);
|
|
|
|
if (!uri[i])
|
|
|
|
{
|
|
|
|
/* Is there any reason why we care of URI without scheme? */
|
|
|
|
if (files->files[i][0] != '/') continue;
|
|
|
|
len += strlen(files->files[i]) + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (strcmp(uri[i]->protocol, "file"))
|
|
|
|
{
|
|
|
|
efreet_uri_free(uri[i]);
|
|
|
|
uri[i] = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
len += strlen(uri[i]->path) + 1;
|
|
|
|
}
|
2013-02-19 02:14:35 -08:00
|
|
|
}
|
|
|
|
p = NULL;
|
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
s = stripstr = malloc(len + 1);
|
|
|
|
for (i = 0; i < files->num_files ; i++)
|
|
|
|
{
|
2014-11-28 23:06:50 -08:00
|
|
|
if (uri[i])
|
|
|
|
p = (char *)uri[i]->path;
|
|
|
|
else
|
|
|
|
p = files->files[i];
|
|
|
|
|
2015-06-14 22:08:34 -07:00
|
|
|
if (s)
|
2013-02-19 02:14:35 -08:00
|
|
|
{
|
2015-06-14 22:08:34 -07:00
|
|
|
len = strlen(p);
|
|
|
|
strcpy(s, p);
|
|
|
|
if (i < (files->num_files - 1))
|
|
|
|
{
|
|
|
|
s[len] = '\n';
|
|
|
|
s[len + 1] = 0;
|
|
|
|
s += len + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s[len] = 0;
|
|
|
|
s += len;
|
|
|
|
}
|
2013-02-19 02:14:35 -08:00
|
|
|
}
|
2014-11-28 23:06:50 -08:00
|
|
|
|
|
|
|
if (uri[i])
|
|
|
|
efreet_uri_free(uri[i]);
|
2013-02-19 02:14:35 -08:00
|
|
|
}
|
|
|
|
}
|
2014-11-28 23:06:50 -08:00
|
|
|
free(uri);
|
2010-09-06 23:56:16 -07:00
|
|
|
}
|
2011-03-31 05:29:20 -07:00
|
|
|
else
|
|
|
|
{
|
2014-11-28 23:06:50 -08:00
|
|
|
Efreet_Uri *uri;
|
|
|
|
|
2015-06-14 01:12:36 -07:00
|
|
|
p = (char *)eina_memdup((unsigned char *)data->data, data->length, EINA_TRUE);
|
|
|
|
if (!p) return EINA_FALSE;
|
2014-11-28 23:06:50 -08:00
|
|
|
uri = efreet_uri_decode(p);
|
|
|
|
if (!uri)
|
|
|
|
{
|
|
|
|
/* Is there any reason why we care of URI without scheme? */
|
2015-06-14 01:12:36 -07:00
|
|
|
if (p[0] == '/') stripstr = p;
|
|
|
|
else free(p);
|
2014-11-28 23:06:50 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-14 01:12:36 -07:00
|
|
|
free(p);
|
|
|
|
stripstr = (char *)eina_memdup((unsigned char *)uri->path, strlen(uri->path), EINA_TRUE);
|
2015-06-14 22:05:02 -07:00
|
|
|
efreet_uri_free(uri);
|
2015-06-13 10:33:14 -07:00
|
|
|
if (!stripstr) return EINA_FALSE;
|
2013-02-19 02:14:35 -08:00
|
|
|
}
|
2011-03-31 05:29:20 -07:00
|
|
|
}
|
2014-11-28 23:06:50 -08:00
|
|
|
|
2013-02-19 02:14:35 -08:00
|
|
|
if (!stripstr)
|
2010-09-06 23:56:16 -07:00
|
|
|
{
|
|
|
|
cnp_debug("Couldn't find a file\n");
|
2015-06-13 10:33:14 -07:00
|
|
|
return EINA_FALSE;
|
2010-12-20 03:09:19 -08:00
|
|
|
}
|
2014-01-21 18:08:47 -08:00
|
|
|
free(savedtypes.imgfile);
|
2010-09-06 23:56:16 -07:00
|
|
|
if (savedtypes.textreq)
|
|
|
|
{
|
|
|
|
savedtypes.textreq = 0;
|
2013-02-19 02:14:35 -08:00
|
|
|
savedtypes.imgfile = stripstr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-13 10:33:14 -07:00
|
|
|
ddata->format = ELM_SEL_FORMAT_IMAGE;
|
|
|
|
ddata->data = stripstr;
|
|
|
|
ddata->len = strlen(stripstr);
|
2013-03-16 19:41:41 -07:00
|
|
|
savedtypes.imgfile = NULL;
|
2010-09-06 23:56:16 -07:00
|
|
|
}
|
2015-06-13 10:33:14 -07:00
|
|
|
return EINA_TRUE;
|
2010-06-30 06:20:58 -07:00
|
|
|
}
|
|
|
|
|
2010-09-16 22:39:00 -07:00
|
|
|
/**
|
2013-11-21 18:06:37 -08:00
|
|
|
* Just received an vcard, either through cut and paste, or dnd.
|
2010-09-16 22:39:00 -07:00
|
|
|
*/
|
2015-06-13 10:33:14 -07:00
|
|
|
static Eina_Bool
|
2015-06-13 23:53:45 -07:00
|
|
|
_x11_data_preparer_vcard(Ecore_X_Event_Selection_Notify *notify,
|
2015-06-13 10:33:14 -07:00
|
|
|
Elm_Selection_Data *ddata, Tmp_Info **tmp_info EINA_UNUSED)
|
2010-09-16 22:39:00 -07:00
|
|
|
{
|
|
|
|
cnp_debug("vcard receive\n");
|
2015-06-13 10:33:14 -07:00
|
|
|
Ecore_X_Selection_Data *data = notify->data;
|
|
|
|
ddata->format = ELM_SEL_FORMAT_VCARD;
|
|
|
|
ddata->data = eina_memdup(data->data, data->length, EINA_TRUE);
|
|
|
|
ddata->len = data->length;
|
|
|
|
return EINA_TRUE;
|
2010-09-16 22:39:00 -07:00
|
|
|
}
|
|
|
|
|
2015-06-13 10:33:14 -07:00
|
|
|
static Eina_Bool
|
2015-06-13 23:53:45 -07:00
|
|
|
_x11_data_preparer_image(Ecore_X_Event_Selection_Notify *notify,
|
2015-06-13 10:33:14 -07:00
|
|
|
Elm_Selection_Data *ddata, Tmp_Info **tmp_info)
|
2010-06-30 06:20:58 -07:00
|
|
|
{
|
2015-06-13 10:33:14 -07:00
|
|
|
Ecore_X_Selection_Data *data = notify->data;
|
2011-12-28 04:54:59 -08:00
|
|
|
cnp_debug("got a image file!\n");
|
2010-12-20 03:09:19 -08:00
|
|
|
cnp_debug("Size if %d\n", data->length);
|
2015-06-09 00:51:13 -07:00
|
|
|
|
2015-06-13 10:33:14 -07:00
|
|
|
ddata->format = ELM_SEL_FORMAT_IMAGE;
|
|
|
|
data = notify->data;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2015-06-13 10:33:14 -07:00
|
|
|
Tmp_Info *tmp = _tempfile_new(data->length);
|
|
|
|
if (!tmp) return EINA_FALSE;
|
|
|
|
memcpy(tmp->map, data->data, data->length);
|
|
|
|
munmap(tmp->map, data->length);
|
|
|
|
ddata->data = strdup(tmp->filename);
|
|
|
|
ddata->len = strlen(tmp->filename);
|
|
|
|
*tmp_info = tmp;
|
|
|
|
return EINA_TRUE;
|
2010-09-26 21:25:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Warning: Generic text/html can';t handle it sanely.
|
|
|
|
* Firefox sends ucs2 (i think).
|
|
|
|
* chrome sends utf8... blerg
|
|
|
|
*/
|
2012-07-16 02:16:30 -07:00
|
|
|
/*
|
2010-09-26 21:25:26 -07:00
|
|
|
static int
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_html(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
|
2010-12-20 03:09:19 -08:00
|
|
|
{
|
2010-09-26 21:25:26 -07:00
|
|
|
Ecore_X_Selection_Data *data;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-09-26 21:25:26 -07:00
|
|
|
cnp_debug("Got some HTML: Checking encoding is useful\n");
|
|
|
|
data = notify->data;
|
2012-05-22 17:53:07 -07:00
|
|
|
char *stripstr = malloc(data->length + 1);
|
2012-05-21 21:42:45 -07:00
|
|
|
if (!stripstr) return 0;
|
2012-05-21 18:35:12 -07:00
|
|
|
strncpy(stripstr, (char *)data->data, data->length);
|
|
|
|
stripstr[data->length] = '\0';
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-10-17 21:49:00 -07:00
|
|
|
if (sel->datacb)
|
|
|
|
{
|
|
|
|
Elm_Selection_Data ddata;
|
|
|
|
ddata.x = ddata.y = 0;
|
|
|
|
ddata.format = ELM_SEL_FORMAT_HTML;
|
2012-05-21 18:35:12 -07:00
|
|
|
ddata.data = stripstr;
|
2010-10-17 21:49:00 -07:00
|
|
|
ddata.len = data->length;
|
2013-02-22 00:49:08 -08:00
|
|
|
ddata.action = ELM_XDND_ACTION_UNKNOWN;
|
2010-10-17 21:49:00 -07:00
|
|
|
sel->datacb(sel->udata, sel->widget, &ddata);
|
2012-05-22 18:05:22 -07:00
|
|
|
free(stripstr);
|
2010-10-17 21:49:00 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
cnp_debug("String is %s (%d bytes)\n", stripstr, data->length);
|
2012-07-16 02:16:30 -07:00
|
|
|
// TODO BUG: should never NEVER assume it's an elm_entry!
|
2011-08-03 02:00:36 -07:00
|
|
|
_elm_entry_entry_paste(sel->requestwidget, stripstr);
|
2010-12-20 01:47:30 -08:00
|
|
|
free(stripstr);
|
2010-08-18 12:18:42 -07:00
|
|
|
return 0;
|
2010-06-30 06:20:58 -07:00
|
|
|
}
|
2012-07-16 02:16:30 -07:00
|
|
|
*/
|
2010-06-30 06:20:58 -07:00
|
|
|
|
2010-09-27 11:45:38 -07:00
|
|
|
static Eina_Bool
|
2012-10-04 16:19:05 -07:00
|
|
|
_x11_text_converter(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize)
|
2010-08-18 12:18:42 -07:00
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
X11_Cnp_Selection *sel;
|
2010-06-17 01:06:07 -07:00
|
|
|
|
2010-09-06 23:56:16 -07:00
|
|
|
cnp_debug("text converter\n");
|
2011-12-20 00:37:26 -08:00
|
|
|
if (_get_selection_type(data, size) == ELM_SEL_FORMAT_NONE)
|
2011-08-25 19:43:48 -07:00
|
|
|
{
|
2011-10-20 21:32:27 -07:00
|
|
|
if (data_ret)
|
|
|
|
{
|
2011-10-20 21:38:21 -07:00
|
|
|
*data_ret = malloc(size * sizeof(char) + 1);
|
2012-05-21 21:42:45 -07:00
|
|
|
if (!*data_ret) return EINA_FALSE;
|
2011-10-20 21:32:27 -07:00
|
|
|
memcpy(*data_ret, data, size);
|
|
|
|
((char**)(data_ret))[0][size] = 0;
|
|
|
|
}
|
2011-09-10 12:43:46 -07:00
|
|
|
if (size_ret) *size_ret = size;
|
2011-08-25 19:43:48 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
2012-08-22 01:33:43 -07:00
|
|
|
sel = _x11_selections + *((int *)data);
|
2010-09-27 11:45:38 -07:00
|
|
|
if (!sel->active) return EINA_TRUE;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2011-01-13 15:04:04 -08:00
|
|
|
if ((sel->format & ELM_SEL_FORMAT_MARKUP) ||
|
|
|
|
(sel->format & ELM_SEL_FORMAT_HTML))
|
2010-10-20 15:33:58 -07:00
|
|
|
{
|
2012-01-29 00:52:34 -08:00
|
|
|
*data_ret = _elm_util_mkup_to_text(sel->selbuf);
|
2013-12-04 00:10:51 -08:00
|
|
|
if (size_ret && *data_ret) *size_ret = strlen(*data_ret);
|
2010-10-20 15:33:58 -07:00
|
|
|
}
|
2011-01-13 15:04:04 -08:00
|
|
|
else if (sel->format & ELM_SEL_FORMAT_TEXT)
|
2010-10-20 15:33:58 -07:00
|
|
|
{
|
2012-10-04 16:19:05 -07:00
|
|
|
ecore_x_selection_converter_text(target, sel->selbuf,
|
|
|
|
strlen(sel->selbuf),
|
|
|
|
data_ret, size_ret,
|
|
|
|
ttype, typesize);
|
2010-10-20 15:33:58 -07:00
|
|
|
}
|
2011-01-13 15:04:04 -08:00
|
|
|
else if (sel->format & ELM_SEL_FORMAT_IMAGE)
|
2010-10-20 15:33:58 -07:00
|
|
|
{
|
2011-04-01 04:35:07 -07:00
|
|
|
cnp_debug("Image %s\n", evas_object_type_get(sel->widget));
|
|
|
|
cnp_debug("Elm type: %s\n", elm_object_widget_type_get(sel->widget));
|
2011-12-28 04:54:59 -08:00
|
|
|
evas_object_image_file_get(elm_photocam_internal_image_get(sel->widget),
|
|
|
|
(const char **)data_ret, NULL);
|
2011-04-01 04:35:07 -07:00
|
|
|
if (!*data_ret) *data_ret = strdup("No file");
|
|
|
|
else *data_ret = strdup(*data_ret);
|
2015-06-12 01:02:05 -07:00
|
|
|
|
|
|
|
if (!*data_ret)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate memory!");
|
|
|
|
*size_ret = 0;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
2011-04-01 04:35:07 -07:00
|
|
|
*size_ret = strlen(*data_ret);
|
2010-10-20 15:33:58 -07:00
|
|
|
}
|
2010-09-27 11:45:38 -07:00
|
|
|
return EINA_TRUE;
|
2010-06-17 01:06:07 -07:00
|
|
|
}
|
|
|
|
|
2010-09-27 11:45:38 -07:00
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_x11_general_converter(char *target EINA_UNUSED, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype EINA_UNUSED, int *typesize EINA_UNUSED)
|
2010-08-18 12:18:42 -07:00
|
|
|
{
|
2011-12-20 00:37:26 -08:00
|
|
|
if (_get_selection_type(data, size) == ELM_SEL_FORMAT_NONE)
|
2011-08-25 19:32:49 -07:00
|
|
|
{
|
2011-10-20 21:32:27 -07:00
|
|
|
if (data_ret)
|
|
|
|
{
|
2011-10-20 21:38:21 -07:00
|
|
|
*data_ret = malloc(size * sizeof(char) + 1);
|
2012-05-21 21:42:45 -07:00
|
|
|
if (!*data_ret) return EINA_FALSE;
|
2011-10-20 21:32:27 -07:00
|
|
|
memcpy(*data_ret, data, size);
|
|
|
|
((char**)(data_ret))[0][size] = 0;
|
|
|
|
}
|
2011-09-10 12:43:46 -07:00
|
|
|
if (size_ret) *size_ret = size;
|
2011-08-25 19:32:49 -07:00
|
|
|
}
|
2011-12-20 00:37:26 -08:00
|
|
|
else
|
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
X11_Cnp_Selection *sel = _x11_selections + *((int *)data);
|
2013-03-16 23:36:30 -07:00
|
|
|
if (sel->selbuf)
|
|
|
|
{
|
|
|
|
if (data_ret) *data_ret = strdup(sel->selbuf);
|
|
|
|
if (size_ret) *size_ret = strlen(sel->selbuf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (data_ret) *data_ret = NULL;
|
|
|
|
if (size_ret) *size_ret = 0;
|
|
|
|
}
|
2011-12-20 00:37:26 -08:00
|
|
|
}
|
2010-09-27 11:45:38 -07:00
|
|
|
return EINA_TRUE;
|
2010-06-17 01:06:07 -07:00
|
|
|
}
|
|
|
|
|
2013-02-21 05:21:08 -08:00
|
|
|
static Dropable *
|
|
|
|
_x11_dropable_find(Ecore_X_Window win)
|
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
Dropable *dropable;
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2013-02-21 05:21:08 -08:00
|
|
|
if (!drops) return NULL;
|
|
|
|
EINA_LIST_FOREACH(drops, l, dropable)
|
|
|
|
{
|
|
|
|
if (_x11_elm_widget_xwin_get(dropable->obj) == win) return dropable;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-02-25 00:36:09 -08:00
|
|
|
static Evas *
|
|
|
|
_x11_evas_get_from_xwin(Ecore_X_Window win)
|
|
|
|
{
|
|
|
|
/* Find the Evas connected to the window */
|
|
|
|
Dropable *dropable = _x11_dropable_find(win);
|
|
|
|
return dropable ? evas_object_evas_get(dropable->obj) : NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-06 23:56:16 -07:00
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_x11_dnd_enter(void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev)
|
2010-09-06 23:56:16 -07:00
|
|
|
{
|
|
|
|
Ecore_X_Event_Xdnd_Enter *enter = ev;
|
|
|
|
int i;
|
2013-02-21 05:21:08 -08:00
|
|
|
Dropable *dropable;
|
2010-09-06 23:56:16 -07:00
|
|
|
|
2013-06-26 05:02:09 -07:00
|
|
|
if (!enter) return EINA_TRUE;
|
2013-02-21 05:21:08 -08:00
|
|
|
dropable = _x11_dropable_find(enter->win);
|
|
|
|
if (dropable)
|
|
|
|
{
|
|
|
|
cnp_debug("Enter %x\n", enter->win);
|
|
|
|
}
|
2010-09-06 23:56:16 -07:00
|
|
|
/* Skip it */
|
2012-06-19 16:33:57 -07:00
|
|
|
cnp_debug("enter types=%p (%d)\n", enter->types, enter->num_types);
|
2013-06-26 05:02:09 -07:00
|
|
|
if ((!enter->num_types) || (!enter->types)) return EINA_TRUE;
|
2010-09-06 23:56:16 -07:00
|
|
|
|
|
|
|
cnp_debug("Types\n");
|
|
|
|
savedtypes.ntypes = enter->num_types;
|
2014-01-21 18:08:47 -08:00
|
|
|
free(savedtypes.types);
|
2010-09-06 23:56:16 -07:00
|
|
|
savedtypes.types = malloc(sizeof(char *) * enter->num_types);
|
2010-12-20 03:09:19 -08:00
|
|
|
if (!savedtypes.types) return EINA_FALSE;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
for (i = 0; i < enter->num_types; i++)
|
2010-09-06 23:56:16 -07:00
|
|
|
{
|
|
|
|
savedtypes.types[i] = eina_stringshare_add(enter->types[i]);
|
2010-12-20 03:09:19 -08:00
|
|
|
cnp_debug("Type is %s %p %p\n", enter->types[i],
|
2012-08-22 01:33:43 -07:00
|
|
|
savedtypes.types[i], text_uri);
|
2010-09-06 23:56:16 -07:00
|
|
|
if (savedtypes.types[i] == text_uri)
|
|
|
|
{
|
|
|
|
/* Request it, so we know what it is */
|
|
|
|
cnp_debug("Sending uri request\n");
|
|
|
|
savedtypes.textreq = 1;
|
2014-01-21 18:08:47 -08:00
|
|
|
ELM_SAFE_FREE(savedtypes.imgfile, free);
|
2010-09-06 23:56:16 -07:00
|
|
|
ecore_x_selection_xdnd_request(enter->win, text_uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: Find an object and make it current */
|
2010-10-18 11:15:59 -07:00
|
|
|
return EINA_TRUE;
|
2010-09-06 23:56:16 -07:00
|
|
|
}
|
|
|
|
|
2013-02-21 05:21:08 -08:00
|
|
|
static void
|
2014-03-18 23:59:13 -07:00
|
|
|
_x11_dnd_dropable_handle(Dropable *dropable, Evas_Coord x, Evas_Coord y, Elm_Xdnd_Action action)
|
2013-02-21 05:21:08 -08:00
|
|
|
{
|
2014-03-18 23:59:13 -07:00
|
|
|
Dropable *d, *last_dropable = NULL;
|
|
|
|
Eina_List *l;
|
2013-11-04 05:08:53 -08:00
|
|
|
Dropable_Cbs *cbs;
|
2013-11-18 03:34:07 -08:00
|
|
|
Eina_Inlist *itr;
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2014-03-18 23:59:13 -07:00
|
|
|
EINA_LIST_FOREACH(drops, l, d)
|
2013-02-21 05:21:08 -08:00
|
|
|
{
|
2014-03-18 23:59:13 -07:00
|
|
|
if (d->last.in)
|
|
|
|
{
|
|
|
|
last_dropable = d;
|
|
|
|
break;
|
|
|
|
}
|
2013-02-21 05:21:08 -08:00
|
|
|
}
|
2014-03-18 23:59:13 -07:00
|
|
|
if (last_dropable)
|
2013-02-21 05:21:08 -08:00
|
|
|
{
|
2014-03-18 23:59:13 -07:00
|
|
|
if (last_dropable == dropable) // same
|
|
|
|
{
|
2015-09-18 01:30:23 -07:00
|
|
|
Evas_Coord ox, oy;
|
|
|
|
|
2014-03-18 23:59:13 -07:00
|
|
|
cnp_debug("same obj dropable %p\n", dropable->obj);
|
2015-09-18 01:30:23 -07:00
|
|
|
evas_object_geometry_get(dropable->obj, &ox, &oy, NULL, NULL);
|
2014-03-18 23:59:13 -07:00
|
|
|
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
|
2015-02-25 00:36:38 -08:00
|
|
|
if ((cbs->types & dropable->last.format) && cbs->poscb)
|
2015-09-18 01:30:23 -07:00
|
|
|
cbs->poscb(cbs->posdata, dropable->obj, x - ox, y - oy, action);
|
2014-03-18 23:59:13 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (dropable) // leave last obj and enter new one
|
|
|
|
{
|
|
|
|
cnp_debug("leave %p\n", last_dropable->obj);
|
|
|
|
cnp_debug("enter %p\n", dropable->obj);
|
|
|
|
last_dropable->last.in = EINA_FALSE;
|
|
|
|
last_dropable->last.type = NULL;
|
|
|
|
dropable->last.in = EINA_TRUE;
|
|
|
|
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
|
2015-02-25 00:36:38 -08:00
|
|
|
if ((cbs->types & dropable->last.format) && cbs->entercb)
|
2014-03-18 23:59:13 -07:00
|
|
|
cbs->entercb(cbs->enterdata, dropable->obj);
|
|
|
|
EINA_INLIST_FOREACH_SAFE(last_dropable->cbs_list, itr, cbs)
|
2015-02-25 00:36:38 -08:00
|
|
|
if ((cbs->types & last_dropable->last.format) && cbs->leavecb)
|
2014-03-18 23:59:13 -07:00
|
|
|
cbs->leavecb(cbs->leavedata, last_dropable->obj);
|
|
|
|
}
|
|
|
|
else // leave last obj
|
|
|
|
{
|
|
|
|
cnp_debug("leave %p\n", last_dropable->obj);
|
|
|
|
last_dropable->last.in = EINA_FALSE;
|
|
|
|
last_dropable->last.type = NULL;
|
|
|
|
EINA_INLIST_FOREACH_SAFE(last_dropable->cbs_list, itr, cbs)
|
2015-02-25 00:36:38 -08:00
|
|
|
if ((cbs->types & last_dropable->last.format) && cbs->leavecb)
|
2014-03-18 23:59:13 -07:00
|
|
|
cbs->leavecb(cbs->leavedata, last_dropable->obj);
|
|
|
|
}
|
|
|
|
}
|
2013-02-21 05:21:08 -08:00
|
|
|
}
|
2014-03-18 23:59:13 -07:00
|
|
|
else
|
2013-02-21 05:21:08 -08:00
|
|
|
{
|
2014-03-18 23:59:13 -07:00
|
|
|
if (dropable) // enter new obj
|
2013-02-21 05:21:08 -08:00
|
|
|
{
|
2015-09-18 01:30:23 -07:00
|
|
|
Evas_Coord ox, oy;
|
|
|
|
|
2014-03-18 23:59:13 -07:00
|
|
|
cnp_debug("enter %p\n", dropable->obj);
|
2015-09-18 01:30:23 -07:00
|
|
|
evas_object_geometry_get(dropable->obj, &ox, &oy, NULL, NULL);
|
2014-03-18 23:59:13 -07:00
|
|
|
dropable->last.in = EINA_TRUE;
|
2013-11-18 03:34:07 -08:00
|
|
|
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
|
2014-03-18 23:59:13 -07:00
|
|
|
{
|
2015-02-25 00:36:38 -08:00
|
|
|
if (cbs->types & dropable->last.format)
|
|
|
|
{
|
|
|
|
if (cbs->entercb)
|
|
|
|
cbs->entercb(cbs->enterdata, dropable->obj);
|
|
|
|
if (cbs->poscb)
|
2015-09-18 01:30:23 -07:00
|
|
|
cbs->poscb(cbs->posdata, dropable->obj,
|
|
|
|
x - ox, y - oy, action);
|
2015-02-25 00:36:38 -08:00
|
|
|
}
|
2014-03-18 23:59:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cnp_debug("both dropable & last_dropable are null\n");
|
2013-02-21 05:21:08 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-22 00:49:08 -08:00
|
|
|
static Elm_Xdnd_Action
|
|
|
|
_x11_dnd_action_map(Ecore_X_Atom action)
|
|
|
|
{
|
|
|
|
Elm_Xdnd_Action act = ELM_XDND_ACTION_UNKNOWN;
|
|
|
|
|
|
|
|
if (action == ECORE_X_ATOM_XDND_ACTION_COPY)
|
|
|
|
act = ELM_XDND_ACTION_COPY;
|
|
|
|
else if (action == ECORE_X_ATOM_XDND_ACTION_MOVE)
|
|
|
|
act = ELM_XDND_ACTION_MOVE;
|
|
|
|
else if (action == ECORE_X_ATOM_XDND_ACTION_PRIVATE)
|
|
|
|
act = ELM_XDND_ACTION_PRIVATE;
|
|
|
|
else if (action == ECORE_X_ATOM_XDND_ACTION_ASK)
|
|
|
|
act = ELM_XDND_ACTION_ASK;
|
|
|
|
else if (action == ECORE_X_ATOM_XDND_ACTION_LIST)
|
|
|
|
act = ELM_XDND_ACTION_LIST;
|
|
|
|
else if (action == ECORE_X_ATOM_XDND_ACTION_LINK)
|
|
|
|
act = ELM_XDND_ACTION_LINK;
|
|
|
|
else if (action == ECORE_X_ATOM_XDND_ACTION_DESCRIPTION)
|
|
|
|
act = ELM_XDND_ACTION_DESCRIPTION;
|
|
|
|
return act;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Ecore_X_Atom
|
|
|
|
_x11_dnd_action_rev_map(Elm_Xdnd_Action action)
|
|
|
|
{
|
|
|
|
Ecore_X_Atom act = ECORE_X_ATOM_XDND_ACTION_MOVE;
|
|
|
|
|
|
|
|
if (action == ELM_XDND_ACTION_COPY)
|
|
|
|
act = ECORE_X_ATOM_XDND_ACTION_COPY;
|
|
|
|
else if (action == ELM_XDND_ACTION_MOVE)
|
|
|
|
act = ECORE_X_ATOM_XDND_ACTION_MOVE;
|
|
|
|
else if (action == ELM_XDND_ACTION_PRIVATE)
|
|
|
|
act = ECORE_X_ATOM_XDND_ACTION_PRIVATE;
|
|
|
|
else if (action == ELM_XDND_ACTION_ASK)
|
|
|
|
act = ECORE_X_ATOM_XDND_ACTION_ASK;
|
|
|
|
else if (action == ELM_XDND_ACTION_LIST)
|
|
|
|
act = ECORE_X_ATOM_XDND_ACTION_LIST;
|
|
|
|
else if (action == ELM_XDND_ACTION_LINK)
|
|
|
|
act = ECORE_X_ATOM_XDND_ACTION_LINK;
|
|
|
|
else if (action == ELM_XDND_ACTION_DESCRIPTION)
|
|
|
|
act = ECORE_X_ATOM_XDND_ACTION_DESCRIPTION;
|
|
|
|
return act;
|
|
|
|
}
|
|
|
|
|
2013-02-21 05:21:08 -08:00
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_x11_dnd_position(void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev)
|
2013-02-21 05:21:08 -08:00
|
|
|
{
|
|
|
|
Ecore_X_Event_Xdnd_Position *pos = ev;
|
2013-08-11 01:04:21 -07:00
|
|
|
Ecore_X_Rectangle rect = { 0, 0, 0, 0 };
|
2014-03-18 23:59:13 -07:00
|
|
|
Dropable *dropable;
|
2013-02-22 00:49:08 -08:00
|
|
|
Elm_Xdnd_Action act;
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2013-02-21 05:21:08 -08:00
|
|
|
/* Need to send a status back */
|
|
|
|
/* FIXME: Should check I can drop here */
|
|
|
|
/* FIXME: Should highlight widget */
|
2014-03-18 23:59:13 -07:00
|
|
|
dropable = _x11_dropable_find(pos->win);
|
2013-02-21 05:21:08 -08:00
|
|
|
if (dropable)
|
|
|
|
{
|
2014-03-18 23:59:13 -07:00
|
|
|
Evas_Coord x, y, ox = 0, oy = 0;
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2014-03-18 23:59:13 -07:00
|
|
|
act = _x11_dnd_action_map(pos->action);
|
2013-02-21 05:21:08 -08:00
|
|
|
x = pos->position.x;
|
|
|
|
y = pos->position.y;
|
2015-02-25 00:36:09 -08:00
|
|
|
_dropable_coords_adjust(dropable, &x, &y);
|
|
|
|
Evas *evas = _x11_evas_get_from_xwin(pos->win);
|
|
|
|
Eina_List *dropable_list = evas ? _dropable_list_geom_find(evas, x, y) : NULL;
|
2014-03-18 23:59:13 -07:00
|
|
|
/* check if there is dropable (obj) can accept this drop */
|
|
|
|
if (dropable_list)
|
2013-02-21 05:21:08 -08:00
|
|
|
{
|
2015-03-10 00:25:02 -07:00
|
|
|
Elm_Sel_Format saved_format = _dnd_types_to_format(savedtypes.types, savedtypes.ntypes);
|
2014-03-18 23:59:13 -07:00
|
|
|
Eina_List *l;
|
|
|
|
Eina_Bool found = EINA_FALSE;
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH(dropable_list, l, dropable)
|
|
|
|
{
|
|
|
|
Dropable_Cbs *cbs;
|
|
|
|
Eina_Inlist *itr;
|
|
|
|
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
|
|
|
|
{
|
2015-02-25 00:36:34 -08:00
|
|
|
Elm_Sel_Format common_fmt = saved_format & cbs->types;
|
|
|
|
if (common_fmt)
|
2014-03-18 23:59:13 -07:00
|
|
|
{
|
2015-02-25 00:36:34 -08:00
|
|
|
/* We found a target that can accept this type of data */
|
|
|
|
int i, min_index = CNP_N_ATOMS;
|
|
|
|
/* We have to find the first atom that corresponds to one
|
|
|
|
* of the supported data types. */
|
2014-03-18 23:59:13 -07:00
|
|
|
for (i = 0; i < savedtypes.ntypes; i++)
|
|
|
|
{
|
2015-03-09 09:17:52 -07:00
|
|
|
Cnp_Atom *atom = eina_hash_find(_types_hash, savedtypes.types[i]);
|
2015-02-25 00:36:34 -08:00
|
|
|
if (atom && (atom->formats & common_fmt))
|
2014-03-18 23:59:13 -07:00
|
|
|
{
|
2015-03-09 09:17:52 -07:00
|
|
|
int atom_idx = (atom - _atoms);
|
2015-02-25 00:36:34 -08:00
|
|
|
if (min_index > atom_idx) min_index = atom_idx;
|
2014-03-18 23:59:13 -07:00
|
|
|
}
|
|
|
|
}
|
2015-02-25 00:36:34 -08:00
|
|
|
if (min_index != CNP_N_ATOMS)
|
|
|
|
{
|
2015-03-09 09:17:52 -07:00
|
|
|
cnp_debug("Found atom %s\n", _atoms[min_index].name);
|
2015-02-25 00:36:34 -08:00
|
|
|
found = EINA_TRUE;
|
2015-03-09 09:17:52 -07:00
|
|
|
dropable->last.type = _atoms[min_index].name;
|
2015-02-25 00:36:34 -08:00
|
|
|
dropable->last.format = common_fmt;
|
|
|
|
break;
|
|
|
|
}
|
2014-03-18 23:59:13 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found) break;
|
|
|
|
}
|
|
|
|
if (found)
|
|
|
|
{
|
|
|
|
Dropable *d = NULL;
|
|
|
|
Eina_Rectangle inter_rect = {0, 0, 0, 0};
|
|
|
|
int idx = 0;
|
|
|
|
EINA_LIST_FOREACH(dropable_list, l, d)
|
|
|
|
{
|
|
|
|
if (idx == 0)
|
|
|
|
{
|
|
|
|
evas_object_geometry_get(d->obj, &inter_rect.x, &inter_rect.y,
|
|
|
|
&inter_rect.w, &inter_rect.h);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Eina_Rectangle cur_rect;
|
|
|
|
evas_object_geometry_get(d->obj, &cur_rect.x, &cur_rect.y,
|
|
|
|
&cur_rect.w, &cur_rect.h);
|
|
|
|
if (!eina_rectangle_intersection(&inter_rect, &cur_rect)) continue;
|
|
|
|
}
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
rect.x = inter_rect.x;
|
|
|
|
rect.y = inter_rect.y;
|
|
|
|
rect.width = inter_rect.w;
|
|
|
|
rect.height = inter_rect.h;
|
|
|
|
ecore_x_dnd_send_status(EINA_TRUE, EINA_FALSE, rect, pos->action);
|
|
|
|
cnp_debug("dnd position %i %i %p\n", x - ox, y - oy, dropable);
|
|
|
|
_x11_dnd_dropable_handle(dropable, x - ox, y - oy, act);
|
|
|
|
// CCCCCCC: call dnd exit on last obj if obj != last
|
|
|
|
// CCCCCCC: call drop position on obj
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//if not: send false status
|
|
|
|
ecore_x_dnd_send_status(EINA_FALSE, EINA_FALSE, rect, pos->action);
|
|
|
|
cnp_debug("dnd position (%d, %d) not in obj\n", x, y);
|
|
|
|
_x11_dnd_dropable_handle(NULL, 0, 0, act);
|
|
|
|
// CCCCCCC: call dnd exit on last obj
|
|
|
|
}
|
2015-06-14 01:14:02 -07:00
|
|
|
eina_list_free(dropable_list);
|
2013-02-21 05:21:08 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ecore_x_dnd_send_status(EINA_FALSE, EINA_FALSE, rect, pos->action);
|
2014-03-18 23:59:13 -07:00
|
|
|
cnp_debug("dnd position (%d, %d) has no drop\n", x, y);
|
|
|
|
_x11_dnd_dropable_handle(NULL, 0, 0, act);
|
2013-02-21 05:21:08 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ecore_x_dnd_send_status(EINA_FALSE, EINA_FALSE, rect, pos->action);
|
|
|
|
}
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_x11_dnd_leave(void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev)
|
2013-02-21 05:21:08 -08:00
|
|
|
{
|
2014-03-19 12:08:52 -07:00
|
|
|
#ifdef DEBUGON
|
2014-03-18 23:59:13 -07:00
|
|
|
cnp_debug("Leave %x\n", ((Ecore_X_Event_Xdnd_Leave *)ev)->win);
|
2014-03-19 12:08:52 -07:00
|
|
|
#else
|
|
|
|
(void)ev;
|
|
|
|
#endif
|
2014-03-18 23:59:13 -07:00
|
|
|
_x11_dnd_dropable_handle(NULL, 0, 0, ELM_XDND_ACTION_UNKNOWN);
|
|
|
|
// CCCCCCC: call dnd exit on last obj if there was one
|
2013-02-21 05:21:08 -08:00
|
|
|
// leave->win leave->source
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-06 23:56:16 -07:00
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_x11_dnd_drop(void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev)
|
2010-09-06 23:56:16 -07:00
|
|
|
{
|
2013-02-21 05:21:08 -08:00
|
|
|
Ecore_X_Event_Xdnd_Drop *drop;
|
2014-03-18 23:59:13 -07:00
|
|
|
Dropable *dropable = NULL;
|
2010-10-17 21:48:44 -07:00
|
|
|
Elm_Selection_Data ddata;
|
2013-02-21 05:21:08 -08:00
|
|
|
Evas_Coord x = 0, y = 0;
|
2013-02-22 00:49:08 -08:00
|
|
|
Elm_Xdnd_Action act = ELM_XDND_ACTION_UNKNOWN;
|
2014-03-18 23:59:13 -07:00
|
|
|
Eina_List *l;
|
|
|
|
Dropable_Cbs *cbs;
|
|
|
|
Eina_Inlist *itr;
|
2010-09-06 23:56:16 -07:00
|
|
|
|
|
|
|
drop = ev;
|
|
|
|
|
2012-06-19 16:33:57 -07:00
|
|
|
cnp_debug("drops %p (%d)\n", drops, eina_list_count(drops));
|
2013-02-21 05:21:08 -08:00
|
|
|
if (!(dropable = _x11_dropable_find(drop->win))) return EINA_TRUE;
|
2010-09-06 23:56:16 -07:00
|
|
|
|
|
|
|
/* Calculate real (widget relative) position */
|
2010-12-20 03:09:19 -08:00
|
|
|
// - window position
|
|
|
|
// - widget position
|
2013-02-21 05:21:08 -08:00
|
|
|
savedtypes.x = drop->position.x;
|
|
|
|
savedtypes.y = drop->position.y;
|
2015-02-25 00:36:09 -08:00
|
|
|
_dropable_coords_adjust(dropable, &savedtypes.x, &savedtypes.y);
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
cnp_debug("Drop position is %d,%d\n", savedtypes.x, savedtypes.y);
|
2010-09-06 23:56:16 -07:00
|
|
|
|
2014-03-18 23:59:13 -07:00
|
|
|
EINA_LIST_FOREACH(drops, l, dropable)
|
2010-09-06 23:56:16 -07:00
|
|
|
{
|
2014-03-18 23:59:13 -07:00
|
|
|
if (dropable->last.in)
|
2010-09-06 23:56:16 -07:00
|
|
|
{
|
2014-03-18 23:59:13 -07:00
|
|
|
evas_object_geometry_get(dropable->obj, &x, &y, NULL, NULL);
|
|
|
|
savedtypes.x -= x;
|
|
|
|
savedtypes.y -= y;
|
|
|
|
goto found;
|
2010-09-06 23:56:16 -07:00
|
|
|
}
|
|
|
|
}
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-09-06 23:56:16 -07:00
|
|
|
cnp_debug("Didn't find a target\n");
|
2010-12-20 03:09:19 -08:00
|
|
|
return EINA_TRUE;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-09-06 23:56:16 -07:00
|
|
|
found:
|
2013-02-21 05:21:08 -08:00
|
|
|
cnp_debug("0x%x\n", drop->win);
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2013-02-22 00:49:08 -08:00
|
|
|
act = _x11_dnd_action_map(drop->action);
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2014-12-14 05:36:04 -08:00
|
|
|
dropable->last.in = EINA_FALSE;
|
2015-02-25 00:36:34 -08:00
|
|
|
cnp_debug("Last type: %s - Last format: %X\n", dropable->last.type, dropable->last.format);
|
2014-03-18 23:59:13 -07:00
|
|
|
if ((!strcmp(dropable->last.type, text_uri)))
|
2010-09-06 23:56:16 -07:00
|
|
|
{
|
2011-01-07 20:55:31 -08:00
|
|
|
cnp_debug("We found a URI... (%scached) %s\n",
|
2011-06-20 00:13:50 -07:00
|
|
|
savedtypes.imgfile ? "" : "not ",
|
|
|
|
savedtypes.imgfile);
|
|
|
|
if (savedtypes.imgfile)
|
2010-09-06 23:56:16 -07:00
|
|
|
{
|
|
|
|
ddata.x = savedtypes.x;
|
|
|
|
ddata.y = savedtypes.y;
|
2013-02-22 00:49:08 -08:00
|
|
|
ddata.action = act;
|
2010-09-07 21:55:16 -07:00
|
|
|
|
2013-11-18 03:34:07 -08:00
|
|
|
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
|
2011-01-07 20:55:31 -08:00
|
|
|
{
|
2013-11-04 05:08:53 -08:00
|
|
|
/* If it's markup that also supports images */
|
2015-06-23 05:57:02 -07:00
|
|
|
if (cbs->types & ELM_SEL_FORMAT_IMAGE)
|
2013-11-04 05:08:53 -08:00
|
|
|
{
|
|
|
|
cnp_debug("Doing image insert (%s)\n", savedtypes.imgfile);
|
|
|
|
ddata.format = ELM_SEL_FORMAT_IMAGE;
|
|
|
|
ddata.data = (char *)savedtypes.imgfile;
|
2015-06-23 05:57:02 -07:00
|
|
|
ddata.len = strlen(ddata.data);
|
2015-02-25 00:36:38 -08:00
|
|
|
if ((cbs->types & dropable->last.format) && cbs->dropcb)
|
2013-11-18 03:34:07 -08:00
|
|
|
cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
|
2013-11-04 05:08:53 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cnp_debug("Item doesn't support images... passing\n");
|
|
|
|
}
|
2011-01-07 20:55:31 -08:00
|
|
|
}
|
2013-11-04 05:08:53 -08:00
|
|
|
ecore_x_dnd_send_finished();
|
|
|
|
ELM_SAFE_FREE(savedtypes.imgfile, free);
|
|
|
|
return EINA_TRUE;
|
2010-09-06 23:56:16 -07:00
|
|
|
}
|
|
|
|
else if (savedtypes.textreq)
|
|
|
|
{
|
2010-09-08 17:35:43 -07:00
|
|
|
/* Already asked: Pretend we asked now, and paste immediately when
|
2010-09-06 23:56:16 -07:00
|
|
|
* it comes in */
|
|
|
|
savedtypes.textreq = 0;
|
|
|
|
ecore_x_dnd_send_finished();
|
2010-12-20 03:09:19 -08:00
|
|
|
return EINA_TRUE;
|
2010-09-06 23:56:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-08 00:45:28 -07:00
|
|
|
cnp_debug("doing a request then: %s\n", dropable->last.type);
|
|
|
|
_x11_selections[ELM_SEL_TYPE_XDND].xwin = drop->win;
|
|
|
|
_x11_selections[ELM_SEL_TYPE_XDND].requestwidget = dropable->obj;
|
|
|
|
_x11_selections[ELM_SEL_TYPE_XDND].requestformat = dropable->last.format;
|
|
|
|
_x11_selections[ELM_SEL_TYPE_XDND].active = EINA_TRUE;
|
|
|
|
_x11_selections[ELM_SEL_TYPE_XDND].action = act;
|
|
|
|
ecore_x_selection_xdnd_request(drop->win, dropable->last.type);
|
2010-12-20 03:09:19 -08:00
|
|
|
return EINA_TRUE;
|
2010-09-06 23:56:16 -07:00
|
|
|
}
|
2012-08-22 01:33:43 -07:00
|
|
|
|
2010-09-13 02:16:01 -07:00
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_x11_dnd_status(void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev)
|
2010-09-13 02:16:01 -07:00
|
|
|
{
|
2013-02-21 05:21:08 -08:00
|
|
|
Ecore_X_Event_Xdnd_Status *status = ev;
|
2013-03-16 23:36:30 -07:00
|
|
|
doaccept = EINA_FALSE;
|
|
|
|
|
2010-09-13 02:16:01 -07:00
|
|
|
/* Only thing we care about: will accept */
|
2013-02-22 00:49:08 -08:00
|
|
|
if ((status) && (status->will_accept))
|
|
|
|
{
|
|
|
|
cnp_debug("Will accept\n");
|
|
|
|
doaccept = EINA_TRUE;
|
|
|
|
}
|
2013-03-16 23:36:30 -07:00
|
|
|
/* Won't accept */
|
2013-02-22 00:49:08 -08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
cnp_debug("Won't accept accept\n");
|
|
|
|
}
|
|
|
|
if (dragacceptcb)
|
|
|
|
dragacceptcb(dragacceptdata, _x11_selections[ELM_SEL_TYPE_XDND].widget,
|
|
|
|
doaccept);
|
2012-08-22 01:33:43 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2015-07-07 01:24:12 -07:00
|
|
|
static Eina_Bool
|
2016-02-29 03:32:52 -08:00
|
|
|
_x11_win_rotation_changed_cb(void *data, const Eo_Event *event)
|
2014-06-10 22:19:27 -07:00
|
|
|
{
|
|
|
|
Evas_Object *win = data;
|
2016-02-29 03:32:52 -08:00
|
|
|
int rot = elm_win_rotation_get(event->obj);
|
2014-06-10 22:19:27 -07:00
|
|
|
elm_win_rotation_set(win, rot);
|
2015-07-07 01:24:12 -07:00
|
|
|
return EINA_TRUE;
|
2014-06-10 22:19:27 -07:00
|
|
|
}
|
|
|
|
|
2013-02-19 04:10:02 -08:00
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_x11_drag_mouse_up(void *data, int etype EINA_UNUSED, void *event)
|
2012-08-22 01:33:43 -07:00
|
|
|
{
|
2013-02-23 19:11:24 -08:00
|
|
|
Ecore_X_Window xwin = (Ecore_X_Window)(long)data;
|
2013-02-19 04:10:02 -08:00
|
|
|
Ecore_Event_Mouse_Button *ev = event;
|
2012-08-22 01:33:43 -07:00
|
|
|
|
2013-02-19 04:10:02 -08:00
|
|
|
if ((ev->buttons == 1) &&
|
|
|
|
(ev->event_window == xwin))
|
2012-08-22 01:33:43 -07:00
|
|
|
{
|
2013-02-20 01:41:06 -08:00
|
|
|
Eina_Bool have_drops = EINA_FALSE;
|
|
|
|
Eina_List *l;
|
|
|
|
Dropable *dropable;
|
2013-03-16 23:36:30 -07:00
|
|
|
|
2013-02-19 04:10:02 -08:00
|
|
|
ecore_x_pointer_ungrab();
|
2013-05-29 04:47:08 -07:00
|
|
|
ELM_SAFE_FREE(handler_up, ecore_event_handler_del);
|
|
|
|
ELM_SAFE_FREE(handler_status, ecore_event_handler_del);
|
2013-02-21 05:21:08 -08:00
|
|
|
ecore_x_dnd_self_drop();
|
2013-03-16 23:36:30 -07:00
|
|
|
|
2013-02-19 04:10:02 -08:00
|
|
|
cnp_debug("mouse up, xwin=%#llx\n", (unsigned long long)xwin);
|
2013-03-16 23:36:30 -07:00
|
|
|
|
2013-02-20 01:41:06 -08:00
|
|
|
EINA_LIST_FOREACH(drops, l, dropable)
|
|
|
|
{
|
|
|
|
if (xwin == _x11_elm_widget_xwin_get(dropable->obj))
|
|
|
|
{
|
|
|
|
have_drops = EINA_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!have_drops) ecore_x_dnd_aware_set(xwin, EINA_FALSE);
|
2013-02-22 00:49:08 -08:00
|
|
|
if (dragdonecb) dragdonecb(dragdonedata, dragwidget);
|
2013-03-16 23:36:30 -07:00
|
|
|
if (dragwin)
|
|
|
|
{
|
2014-06-10 22:19:27 -07:00
|
|
|
if (dragwidget)
|
|
|
|
{
|
|
|
|
if (elm_widget_is(dragwidget))
|
|
|
|
{
|
|
|
|
Evas_Object *win = elm_widget_top_get(dragwidget);
|
|
|
|
if (win && eo_isa(win, ELM_WIN_CLASS))
|
2016-03-02 04:10:48 -08:00
|
|
|
eo_event_callback_del(win, ELM_WIN_EVENT_ROTATION_CHANGED, _x11_win_rotation_changed_cb, dragwin);
|
2014-06-10 22:19:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-16 23:36:30 -07:00
|
|
|
if (!doaccept)
|
|
|
|
{ /* Commit animation when drag cancelled */
|
|
|
|
/* Record final position of dragwin, then do animation */
|
|
|
|
ecore_animator_timeline_add(0.3,
|
|
|
|
_drag_cancel_animate, dragwin);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* No animation drop was committed */
|
2014-04-09 19:20:50 -07:00
|
|
|
Ecore_X_Window xdragwin = _x11_elm_widget_xwin_get(dragwin);
|
|
|
|
ecore_x_window_ignore_set(xdragwin, 0);
|
2013-03-16 23:36:30 -07:00
|
|
|
evas_object_del(dragwin);
|
|
|
|
}
|
|
|
|
|
|
|
|
dragwin = NULL; /* if not freed here, free in end of anim */
|
|
|
|
}
|
|
|
|
|
2013-02-22 00:49:08 -08:00
|
|
|
dragdonecb = NULL;
|
|
|
|
dragacceptcb = NULL;
|
|
|
|
dragposcb = NULL;
|
|
|
|
dragwidget = NULL;
|
2013-03-16 23:36:30 -07:00
|
|
|
doaccept = EINA_FALSE;
|
|
|
|
/* moved to _drag_cancel_animate
|
2013-02-19 04:10:02 -08:00
|
|
|
if (dragwin)
|
|
|
|
{
|
|
|
|
evas_object_del(dragwin);
|
|
|
|
dragwin = NULL;
|
|
|
|
}
|
2013-03-16 23:36:30 -07:00
|
|
|
*/
|
2012-08-22 01:33:43 -07:00
|
|
|
}
|
2013-02-19 04:10:02 -08:00
|
|
|
return EINA_TRUE;
|
2012-08-22 01:33:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-01-06 06:30:02 -08:00
|
|
|
_x11_drag_move(void *data EINA_UNUSED, Ecore_X_Xdnd_Position *pos)
|
2012-08-22 01:33:43 -07:00
|
|
|
{
|
2013-03-16 23:36:30 -07:00
|
|
|
evas_object_move(dragwin,
|
2013-02-22 00:49:08 -08:00
|
|
|
pos->position.x - _dragx, pos->position.y - _dragy);
|
2013-03-16 23:36:30 -07:00
|
|
|
dragwin_x_end = pos->position.x - _dragx;
|
|
|
|
dragwin_y_end = pos->position.y - _dragy;
|
|
|
|
cnp_debug("dragevas: %p -> %p\n",
|
|
|
|
dragwidget,
|
2013-02-22 00:49:08 -08:00
|
|
|
evas_object_evas_get(dragwidget));
|
|
|
|
if (dragposcb)
|
|
|
|
dragposcb(dragposdata, dragwidget, pos->position.x, pos->position.y,
|
|
|
|
dragaction);
|
2012-08-22 01:33:43 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 02:37:00 -07:00
|
|
|
static Ecore_X_Window
|
|
|
|
_x11_elm_widget_xwin_get(const Evas_Object *obj)
|
|
|
|
{
|
2014-01-14 16:59:01 -08:00
|
|
|
Evas_Object *top, *par;
|
2012-08-22 02:37:00 -07:00
|
|
|
Ecore_X_Window xwin = 0;
|
2013-03-16 23:36:30 -07:00
|
|
|
|
2014-03-28 02:22:49 -07:00
|
|
|
if (elm_widget_is(obj))
|
2014-01-14 16:59:01 -08:00
|
|
|
{
|
2014-03-28 02:22:49 -07:00
|
|
|
top = elm_widget_top_get(obj);
|
|
|
|
if (!top)
|
|
|
|
{
|
|
|
|
par = elm_widget_parent_widget_get(obj);
|
|
|
|
if (par) top = elm_widget_top_get(par);
|
|
|
|
}
|
2014-06-03 03:35:28 -07:00
|
|
|
if (top && (eo_isa(top, ELM_WIN_CLASS)))
|
2014-04-01 03:54:09 -07:00
|
|
|
xwin = elm_win_xwindow_get(top);
|
2014-01-14 16:59:01 -08:00
|
|
|
}
|
2012-08-22 02:37:00 -07:00
|
|
|
if (!xwin)
|
|
|
|
{
|
|
|
|
Ecore_Evas *ee;
|
|
|
|
Evas *evas = evas_object_evas_get(obj);
|
|
|
|
if (!evas) return 0;
|
|
|
|
ee = ecore_evas_ecore_evas_get(evas);
|
|
|
|
if (!ee) return 0;
|
2015-01-08 01:54:04 -08:00
|
|
|
|
|
|
|
while(!xwin)
|
|
|
|
{
|
|
|
|
const char *engine_name = ecore_evas_engine_name_get(ee);
|
|
|
|
if (!strcmp(engine_name, ELM_BUFFER))
|
|
|
|
{
|
|
|
|
ee = ecore_evas_buffer_ecore_evas_parent_get(ee);
|
|
|
|
if (!ee) return 0;
|
|
|
|
xwin = _elm_ee_xwin_get(ee);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* In case the engine is not a buffer, we want to check once. */
|
|
|
|
xwin = _elm_ee_xwin_get(ee);
|
|
|
|
if (!xwin) return 0;
|
|
|
|
}
|
|
|
|
}
|
2012-08-22 02:37:00 -07:00
|
|
|
}
|
|
|
|
return xwin;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_x11_elm_cnp_init(void)
|
|
|
|
{
|
|
|
|
int i;
|
2012-08-28 00:49:27 -07:00
|
|
|
static int _init_count = 0;
|
2013-03-16 23:36:30 -07:00
|
|
|
|
2012-08-28 00:49:27 -07:00
|
|
|
if (_init_count > 0) return EINA_TRUE;
|
|
|
|
_init_count++;
|
2012-08-22 02:37:00 -07:00
|
|
|
for (i = 0; i < CNP_N_ATOMS; i++)
|
|
|
|
{
|
2015-03-09 09:17:52 -07:00
|
|
|
_atoms[i].x_atom = ecore_x_atom_get(_atoms[i].name);
|
2012-08-22 02:37:00 -07:00
|
|
|
ecore_x_selection_converter_atom_add
|
2015-03-09 09:17:52 -07:00
|
|
|
(_atoms[i].x_atom, _atoms[i].x_converter);
|
2012-08-22 02:37:00 -07:00
|
|
|
}
|
2013-02-21 05:21:08 -08:00
|
|
|
//XXX delete handlers?
|
2012-08-22 02:37:00 -07:00
|
|
|
ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR, _x11_selection_clear, NULL);
|
|
|
|
ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY, _x11_selection_notify, NULL);
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
static Eina_Bool
|
2014-01-23 05:22:33 -08:00
|
|
|
_x11_elm_cnp_selection_set(Ecore_X_Window xwin, Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format, const void *selbuf, size_t buflen)
|
2012-08-22 01:33:43 -07:00
|
|
|
{
|
|
|
|
X11_Cnp_Selection *sel;
|
2012-08-29 00:29:21 -07:00
|
|
|
|
2012-08-28 00:49:27 -07:00
|
|
|
_x11_elm_cnp_init();
|
2012-08-22 01:33:43 -07:00
|
|
|
if ((!selbuf) && (format != ELM_SEL_FORMAT_IMAGE))
|
|
|
|
return elm_object_cnp_selection_clear(obj, selection);
|
|
|
|
|
|
|
|
sel = _x11_selections + selection;
|
2015-06-23 07:58:48 -07:00
|
|
|
if (sel->widget != obj && sel->loss_cb) sel->loss_cb(sel->loss_data, selection);
|
2012-08-22 01:33:43 -07:00
|
|
|
if (sel->widget)
|
|
|
|
evas_object_event_callback_del_full(sel->widget, EVAS_CALLBACK_DEL,
|
|
|
|
_x11_sel_obj_del, sel);
|
|
|
|
sel->active = EINA_TRUE;
|
|
|
|
sel->widget = obj;
|
|
|
|
sel->xwin = xwin;
|
2013-11-18 03:34:07 -08:00
|
|
|
if (sel->set) sel->set(xwin, &selection, sizeof(Elm_Sel_Type));
|
2012-08-22 01:33:43 -07:00
|
|
|
sel->format = format;
|
|
|
|
sel->loss_cb = NULL;
|
|
|
|
sel->loss_data = NULL;
|
|
|
|
|
|
|
|
evas_object_event_callback_add
|
|
|
|
(sel->widget, EVAS_CALLBACK_DEL, _x11_sel_obj_del, sel);
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2014-02-04 05:02:54 -08:00
|
|
|
ELM_SAFE_FREE(sel->selbuf, free);
|
2012-08-22 01:33:43 -07:00
|
|
|
if (selbuf)
|
|
|
|
{
|
|
|
|
if (format == ELM_SEL_FORMAT_IMAGE)
|
|
|
|
{
|
|
|
|
// selbuf is actual image data, not text/string
|
2013-05-07 20:50:09 -07:00
|
|
|
sel->selbuf = malloc(buflen + 1);
|
2012-08-22 01:33:43 -07:00
|
|
|
if (!sel->selbuf)
|
|
|
|
{
|
|
|
|
elm_object_cnp_selection_clear(obj, selection);
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
memcpy(sel->selbuf, selbuf, buflen);
|
2013-05-07 20:50:09 -07:00
|
|
|
sel->selbuf[buflen] = 0;
|
2012-08-22 01:33:43 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
sel->selbuf = strdup((char*)selbuf);
|
2010-09-13 02:16:01 -07:00
|
|
|
}
|
2012-08-22 01:33:43 -07:00
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-01-06 06:30:02 -08:00
|
|
|
_x11_elm_cnp_selection_loss_callback_set(Evas_Object *obj EINA_UNUSED, Elm_Sel_Type selection, Elm_Selection_Loss_Cb func, const void *data)
|
2012-08-22 01:33:43 -07:00
|
|
|
{
|
|
|
|
X11_Cnp_Selection *sel;
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2012-08-28 00:49:27 -07:00
|
|
|
_x11_elm_cnp_init();
|
2012-08-22 01:33:43 -07:00
|
|
|
sel = _x11_selections + selection;
|
|
|
|
sel->loss_cb = func;
|
|
|
|
sel->loss_data = (void *)data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_x11_elm_object_cnp_selection_clear(Evas_Object *obj, Elm_Sel_Type selection)
|
|
|
|
{
|
|
|
|
X11_Cnp_Selection *sel;
|
|
|
|
|
2012-08-28 00:49:27 -07:00
|
|
|
_x11_elm_cnp_init();
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
sel = _x11_selections + selection;
|
|
|
|
|
|
|
|
/* No longer this selection: Consider it gone! */
|
|
|
|
if ((!sel->active) || (sel->widget != obj)) return EINA_TRUE;
|
|
|
|
|
|
|
|
if (sel->widget)
|
|
|
|
evas_object_event_callback_del_full(sel->widget, EVAS_CALLBACK_DEL,
|
|
|
|
_x11_sel_obj_del, sel);
|
|
|
|
if (sel->requestwidget)
|
|
|
|
evas_object_event_callback_del_full(sel->requestwidget, EVAS_CALLBACK_DEL,
|
|
|
|
_x11_sel_obj_del2, sel);
|
|
|
|
sel->widget = NULL;
|
|
|
|
sel->requestwidget = NULL;
|
|
|
|
sel->loss_cb = NULL;
|
|
|
|
sel->loss_data = NULL;
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
sel->active = EINA_FALSE;
|
2013-05-29 04:47:08 -07:00
|
|
|
ELM_SAFE_FREE(sel->selbuf, free);
|
2012-08-22 01:33:43 -07:00
|
|
|
sel->clear();
|
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
return EINA_TRUE;
|
2010-09-13 02:16:01 -07:00
|
|
|
}
|
2010-09-06 23:56:16 -07:00
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
static Eina_Bool
|
2015-06-08 10:44:29 -07:00
|
|
|
_x11_elm_cnp_selection_get(Ecore_X_Window xwin, const Evas_Object *obj, Elm_Sel_Type selection,
|
2013-02-21 05:21:08 -08:00
|
|
|
Elm_Sel_Format format, Elm_Drop_Cb datacb,
|
|
|
|
void *udata)
|
2012-08-22 01:33:43 -07:00
|
|
|
{
|
|
|
|
X11_Cnp_Selection *sel;
|
|
|
|
|
2012-08-28 00:49:27 -07:00
|
|
|
_x11_elm_cnp_init();
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
sel = _x11_selections + selection;
|
|
|
|
|
|
|
|
if (sel->requestwidget)
|
|
|
|
evas_object_event_callback_del_full(sel->requestwidget, EVAS_CALLBACK_DEL,
|
|
|
|
_x11_sel_obj_del2, sel);
|
|
|
|
sel->requestformat = format;
|
2015-06-08 10:44:29 -07:00
|
|
|
sel->requestwidget = (Evas_Object *)obj;
|
2012-08-22 01:33:43 -07:00
|
|
|
sel->xwin = xwin;
|
|
|
|
sel->request(xwin, ECORE_X_SELECTION_TARGET_TARGETS);
|
|
|
|
sel->datacb = datacb;
|
|
|
|
sel->udata = udata;
|
|
|
|
|
|
|
|
evas_object_event_callback_add
|
|
|
|
(sel->requestwidget, EVAS_CALLBACK_DEL, _x11_sel_obj_del2, sel);
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2013-02-19 02:14:35 -08:00
|
|
|
_x11_elm_drop_target_add(Evas_Object *obj, Elm_Sel_Format format,
|
2013-02-21 05:21:08 -08:00
|
|
|
Elm_Drag_State entercb, void *enterdata,
|
|
|
|
Elm_Drag_State leavecb, void *leavedata,
|
|
|
|
Elm_Drag_Pos poscb, void *posdata,
|
2013-10-27 02:27:17 -07:00
|
|
|
Elm_Drop_Cb dropcb, void *dropdata)
|
2010-09-06 23:56:16 -07:00
|
|
|
{
|
2013-11-04 05:08:53 -08:00
|
|
|
Dropable *dropable = NULL;
|
|
|
|
Dropable_Cbs *cbs = NULL;
|
2012-08-22 01:33:43 -07:00
|
|
|
Ecore_X_Window xwin = _x11_elm_widget_xwin_get(obj);
|
2013-11-04 05:08:53 -08:00
|
|
|
Eina_List *l;
|
2013-10-27 02:27:17 -07:00
|
|
|
Eina_Bool first = !drops;
|
2013-02-22 01:24:49 -08:00
|
|
|
Eina_Bool have_drops = EINA_FALSE;
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2012-08-28 00:49:27 -07:00
|
|
|
_x11_elm_cnp_init();
|
2013-02-19 02:14:35 -08:00
|
|
|
|
2010-09-08 20:09:42 -07:00
|
|
|
/* Is this the first? */
|
2013-02-22 01:24:49 -08:00
|
|
|
EINA_LIST_FOREACH(drops, l, dropable)
|
|
|
|
{
|
|
|
|
if (xwin == _x11_elm_widget_xwin_get(dropable->obj))
|
|
|
|
{
|
|
|
|
have_drops = EINA_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-11-04 05:08:53 -08:00
|
|
|
dropable = NULL; // In case of error, we don't want to free it
|
2011-01-13 15:04:14 -08:00
|
|
|
|
2013-11-04 05:08:53 -08:00
|
|
|
cbs = calloc(1, sizeof(*cbs));
|
|
|
|
if (!cbs) return EINA_FALSE;
|
2013-10-12 20:56:04 -07:00
|
|
|
|
2013-11-04 05:08:53 -08:00
|
|
|
cbs->entercb = entercb;
|
|
|
|
cbs->enterdata = enterdata;
|
|
|
|
cbs->leavecb = leavecb;
|
|
|
|
cbs->leavedata = leavedata;
|
|
|
|
cbs->poscb = poscb;
|
|
|
|
cbs->posdata = posdata;
|
|
|
|
cbs->dropcb = dropcb;
|
|
|
|
cbs->dropdata = dropdata;
|
|
|
|
cbs->types = format;
|
2011-01-13 15:04:14 -08:00
|
|
|
|
2016-03-02 04:10:48 -08:00
|
|
|
dropable = eo_key_data_get(obj, "__elm_dropable");
|
2013-11-04 05:08:53 -08:00
|
|
|
if (!dropable)
|
2010-09-08 20:09:42 -07:00
|
|
|
{
|
2013-11-04 05:08:53 -08:00
|
|
|
/* Create new drop */
|
|
|
|
dropable = calloc(1, sizeof(Dropable));
|
|
|
|
if (!dropable) goto error;
|
2014-03-18 23:59:13 -07:00
|
|
|
dropable->last.in = EINA_FALSE;
|
2013-11-04 05:08:53 -08:00
|
|
|
drops = eina_list_append(drops, dropable);
|
|
|
|
if (!drops) goto error;
|
|
|
|
dropable->obj = obj;
|
2016-03-02 04:10:48 -08:00
|
|
|
eo_key_data_set(obj, "__elm_dropable", dropable);
|
2010-09-08 20:09:42 -07:00
|
|
|
}
|
2013-11-04 05:08:53 -08:00
|
|
|
dropable->cbs_list = eina_inlist_append(dropable->cbs_list, EINA_INLIST_GET(cbs));
|
|
|
|
|
2010-09-08 20:09:42 -07:00
|
|
|
evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
|
2013-11-04 05:08:53 -08:00
|
|
|
_all_drop_targets_cbs_del, obj);
|
2013-02-22 01:24:49 -08:00
|
|
|
if (!have_drops) ecore_x_dnd_aware_set(xwin, EINA_TRUE);
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
/* TODO BUG: should handle dnd-aware per window, not just the first
|
|
|
|
* window that requested it! */
|
2010-09-08 20:09:42 -07:00
|
|
|
/* If not the first: We're done */
|
2010-12-20 03:09:19 -08:00
|
|
|
if (!first) return EINA_TRUE;
|
2011-01-13 15:04:14 -08:00
|
|
|
|
2012-06-19 16:33:57 -07:00
|
|
|
cnp_debug("Adding drop target calls xwin=%#llx\n", (unsigned long long)xwin);
|
2010-09-08 20:09:42 -07:00
|
|
|
handler_enter = ecore_event_handler_add(ECORE_X_EVENT_XDND_ENTER,
|
2012-08-22 02:37:00 -07:00
|
|
|
_x11_dnd_enter, NULL);
|
2013-02-21 05:21:08 -08:00
|
|
|
handler_leave = ecore_event_handler_add(ECORE_X_EVENT_XDND_LEAVE,
|
|
|
|
_x11_dnd_leave, NULL);
|
2010-09-13 02:16:01 -07:00
|
|
|
handler_pos = ecore_event_handler_add(ECORE_X_EVENT_XDND_POSITION,
|
2012-08-22 02:37:00 -07:00
|
|
|
_x11_dnd_position, NULL);
|
2010-09-13 02:16:01 -07:00
|
|
|
handler_drop = ecore_event_handler_add(ECORE_X_EVENT_XDND_DROP,
|
2012-08-22 02:37:00 -07:00
|
|
|
_x11_dnd_drop, NULL);
|
2010-12-20 03:09:19 -08:00
|
|
|
return EINA_TRUE;
|
2013-11-04 05:08:53 -08:00
|
|
|
error:
|
|
|
|
free(cbs);
|
|
|
|
free(dropable);
|
|
|
|
return EINA_FALSE;
|
2010-09-06 23:56:16 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
static Eina_Bool
|
2013-11-04 05:08:53 -08:00
|
|
|
_x11_elm_drop_target_del(Evas_Object *obj, Elm_Sel_Format format,
|
|
|
|
Elm_Drag_State entercb, void *enterdata,
|
|
|
|
Elm_Drag_State leavecb, void *leavedata,
|
|
|
|
Elm_Drag_Pos poscb, void *posdata,
|
|
|
|
Elm_Drop_Cb dropcb, void *dropdata)
|
2010-09-08 20:09:42 -07:00
|
|
|
{
|
2014-04-03 06:54:14 -07:00
|
|
|
Dropable *dropable = NULL;
|
2013-10-12 20:56:04 -07:00
|
|
|
Eina_List *l;
|
2010-09-08 20:09:42 -07:00
|
|
|
Ecore_X_Window xwin;
|
2013-02-20 01:41:06 -08:00
|
|
|
Eina_Bool have_drops = EINA_FALSE;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2012-08-28 00:49:27 -07:00
|
|
|
_x11_elm_cnp_init();
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2014-10-20 09:10:02 -07:00
|
|
|
if (!_local_elm_drop_target_del(obj, format, entercb, enterdata,
|
|
|
|
leavecb, leavedata, poscb, posdata, dropcb, dropdata))
|
2010-09-08 20:09:42 -07:00
|
|
|
{
|
2014-10-20 09:10:02 -07:00
|
|
|
return EINA_FALSE;
|
2010-09-08 20:09:42 -07:00
|
|
|
}
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2013-11-21 18:06:37 -08:00
|
|
|
/* TODO BUG: we should handle dnd-aware per window, not just the last that released it */
|
2012-06-19 16:33:57 -07:00
|
|
|
|
2010-09-08 20:09:42 -07:00
|
|
|
/* If still drops there: All fine.. continue */
|
2010-12-20 03:09:19 -08:00
|
|
|
if (drops) return EINA_TRUE;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-09-09 01:59:38 -07:00
|
|
|
cnp_debug("Disabling DND\n");
|
2012-08-22 01:33:43 -07:00
|
|
|
xwin = _x11_elm_widget_xwin_get(obj);
|
2013-02-20 01:41:06 -08:00
|
|
|
EINA_LIST_FOREACH(drops, l, dropable)
|
|
|
|
{
|
|
|
|
if (xwin == _x11_elm_widget_xwin_get(dropable->obj))
|
|
|
|
{
|
|
|
|
have_drops = EINA_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!have_drops) ecore_x_dnd_aware_set(xwin, EINA_FALSE);
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2013-02-21 05:21:08 -08:00
|
|
|
if (!drops)
|
|
|
|
{
|
2013-05-29 04:47:08 -07:00
|
|
|
ELM_SAFE_FREE(handler_pos, ecore_event_handler_del);
|
|
|
|
ELM_SAFE_FREE(handler_drop, ecore_event_handler_del);
|
|
|
|
ELM_SAFE_FREE(handler_enter, ecore_event_handler_del);
|
|
|
|
ELM_SAFE_FREE(handler_leave, ecore_event_handler_del);
|
2013-02-21 05:21:08 -08:00
|
|
|
}
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2013-05-29 04:47:08 -07:00
|
|
|
ELM_SAFE_FREE(savedtypes.imgfile, free);
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
return EINA_TRUE;
|
2010-09-06 23:56:16 -07:00
|
|
|
}
|
|
|
|
|
2013-02-22 00:49:08 -08:00
|
|
|
static void
|
2014-01-06 06:30:02 -08:00
|
|
|
_x11_drag_target_del(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *info EINA_UNUSED)
|
2013-02-22 00:49:08 -08:00
|
|
|
{
|
|
|
|
X11_Cnp_Selection *sel = _x11_selections + ELM_SEL_TYPE_XDND;
|
|
|
|
|
|
|
|
if (dragwidget == obj)
|
|
|
|
{
|
|
|
|
sel->widget = NULL;
|
|
|
|
dragwidget = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
static Eina_Bool
|
2013-03-16 23:36:30 -07:00
|
|
|
_x11_elm_drag_start(Evas_Object *obj, Elm_Sel_Format format, const char *data,
|
2013-02-22 00:49:08 -08:00
|
|
|
Elm_Xdnd_Action action,
|
2013-02-21 05:21:08 -08:00
|
|
|
Elm_Drag_Icon_Create_Cb createicon, void *createdata,
|
2013-02-22 00:49:08 -08:00
|
|
|
Elm_Drag_Pos dragpos, void *dragdata,
|
|
|
|
Elm_Drag_Accept acceptcb, void *acceptdata,
|
2013-02-21 05:21:08 -08:00
|
|
|
Elm_Drag_State dragdone, void *donecbdata)
|
2010-12-20 03:09:19 -08:00
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
Ecore_X_Window xwin = _x11_elm_widget_xwin_get(obj);
|
2014-04-09 19:20:50 -07:00
|
|
|
Ecore_X_Window xdragwin;
|
2012-08-22 01:33:43 -07:00
|
|
|
X11_Cnp_Selection *sel;
|
2011-12-27 03:24:13 -08:00
|
|
|
Elm_Sel_Type xdnd = ELM_SEL_TYPE_XDND;
|
2010-09-13 02:16:05 -07:00
|
|
|
Ecore_Evas *ee;
|
2013-02-19 04:10:02 -08:00
|
|
|
int x, y, x2 = 0, y2 = 0, x3, y3;
|
|
|
|
Evas_Object *icon = NULL;
|
2013-07-05 02:49:31 -07:00
|
|
|
int w = 0, h = 0;
|
2014-04-21 01:27:46 -07:00
|
|
|
int ex, ey, ew, eh;
|
2013-02-22 00:49:08 -08:00
|
|
|
Ecore_X_Atom actx;
|
[DnD] Fix bug of hard-coded type when drag
Summary:
When we start dragging, the type is always set to "text/uri-list" no matter the format type set by application.
This patch fixs this hard-coded type issue. It will set types corresponding to the format type set by application.
For example, if application set format as ELM_SEL_FORMAT_TEXT, it will set types UTF8_STRING, STRING, COMPOUND_TEXT, TEXT,
text/plain, text/plain;charset=utf-8.
Reviewers: JackDanielZ, raster
Reviewed By: raster
CC: woohyun, seoz
Differential Revision: https://phab.enlightenment.org/D546
2014-02-17 22:47:07 -08:00
|
|
|
int i;
|
2014-04-21 01:27:46 -07:00
|
|
|
int xr, yr, rot;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2012-08-28 00:49:27 -07:00
|
|
|
_x11_elm_cnp_init();
|
2013-03-16 23:36:30 -07:00
|
|
|
|
2013-02-22 00:49:08 -08:00
|
|
|
cnp_debug("starting drag... %p\n", obj);
|
2010-09-09 01:59:42 -07:00
|
|
|
|
2012-01-02 20:44:48 -08:00
|
|
|
if (dragwin)
|
|
|
|
{
|
|
|
|
cnp_debug("another obj is dragging...\n");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
[DnD] Fix bug of hard-coded type when drag
Summary:
When we start dragging, the type is always set to "text/uri-list" no matter the format type set by application.
This patch fixs this hard-coded type issue. It will set types corresponding to the format type set by application.
For example, if application set format as ELM_SEL_FORMAT_TEXT, it will set types UTF8_STRING, STRING, COMPOUND_TEXT, TEXT,
text/plain, text/plain;charset=utf-8.
Reviewers: JackDanielZ, raster
Reviewed By: raster
CC: woohyun, seoz
Differential Revision: https://phab.enlightenment.org/D546
2014-02-17 22:47:07 -08:00
|
|
|
ecore_x_dnd_types_set(xwin, NULL, 0);
|
2015-06-19 04:18:18 -07:00
|
|
|
for (i = CNP_ATOM_LISTING_ATOMS + 1; i < CNP_N_ATOMS; i++)
|
[DnD] Fix bug of hard-coded type when drag
Summary:
When we start dragging, the type is always set to "text/uri-list" no matter the format type set by application.
This patch fixs this hard-coded type issue. It will set types corresponding to the format type set by application.
For example, if application set format as ELM_SEL_FORMAT_TEXT, it will set types UTF8_STRING, STRING, COMPOUND_TEXT, TEXT,
text/plain, text/plain;charset=utf-8.
Reviewers: JackDanielZ, raster
Reviewed By: raster
CC: woohyun, seoz
Differential Revision: https://phab.enlightenment.org/D546
2014-02-17 22:47:07 -08:00
|
|
|
{
|
2015-06-19 04:18:18 -07:00
|
|
|
if (format == ELM_SEL_FORMAT_TARGETS || (_atoms[i].formats & format))
|
[DnD] Fix bug of hard-coded type when drag
Summary:
When we start dragging, the type is always set to "text/uri-list" no matter the format type set by application.
This patch fixs this hard-coded type issue. It will set types corresponding to the format type set by application.
For example, if application set format as ELM_SEL_FORMAT_TEXT, it will set types UTF8_STRING, STRING, COMPOUND_TEXT, TEXT,
text/plain, text/plain;charset=utf-8.
Reviewers: JackDanielZ, raster
Reviewed By: raster
CC: woohyun, seoz
Differential Revision: https://phab.enlightenment.org/D546
2014-02-17 22:47:07 -08:00
|
|
|
{
|
2015-03-09 09:17:52 -07:00
|
|
|
ecore_x_dnd_type_set(xwin, _atoms[i].name, EINA_TRUE);
|
|
|
|
cnp_debug("set dnd type: %s\n", _atoms[i].name);
|
[DnD] Fix bug of hard-coded type when drag
Summary:
When we start dragging, the type is always set to "text/uri-list" no matter the format type set by application.
This patch fixs this hard-coded type issue. It will set types corresponding to the format type set by application.
For example, if application set format as ELM_SEL_FORMAT_TEXT, it will set types UTF8_STRING, STRING, COMPOUND_TEXT, TEXT,
text/plain, text/plain;charset=utf-8.
Reviewers: JackDanielZ, raster
Reviewed By: raster
CC: woohyun, seoz
Differential Revision: https://phab.enlightenment.org/D546
2014-02-17 22:47:07 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
sel = _x11_selections + ELM_SEL_TYPE_XDND;
|
2012-01-02 20:44:48 -08:00
|
|
|
sel->active = EINA_TRUE;
|
2010-09-09 01:59:42 -07:00
|
|
|
sel->widget = obj;
|
|
|
|
sel->format = format;
|
2010-09-09 02:37:19 -07:00
|
|
|
sel->selbuf = data ? strdup(data) : NULL;
|
2013-02-22 00:49:08 -08:00
|
|
|
sel->action = action;
|
|
|
|
dragwidget = obj;
|
|
|
|
dragaction = action;
|
2012-06-19 16:33:57 -07:00
|
|
|
|
2013-02-22 00:49:08 -08:00
|
|
|
evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
|
|
|
|
_x11_drag_target_del, obj);
|
2012-06-19 16:33:57 -07:00
|
|
|
/* TODO BUG: should NEVER have these as globals! They should be per context (window). */
|
2013-02-22 00:49:08 -08:00
|
|
|
dragposcb = dragpos;
|
|
|
|
dragposdata = dragdata;
|
|
|
|
dragacceptcb = acceptcb;
|
|
|
|
dragacceptdata = acceptdata;
|
2010-09-10 01:24:21 -07:00
|
|
|
dragdonecb = dragdone;
|
|
|
|
dragdonedata = donecbdata;
|
2012-08-22 02:37:00 -07:00
|
|
|
/* TODO BUG: should increase dnd-awareness, in case it's drop target as well. See _x11_drag_mouse_up() */
|
2012-01-02 03:04:40 -08:00
|
|
|
ecore_x_dnd_aware_set(xwin, EINA_TRUE);
|
2012-08-22 02:37:00 -07:00
|
|
|
ecore_x_dnd_callback_pos_update_set(_x11_drag_move, NULL);
|
2013-02-21 05:21:08 -08:00
|
|
|
ecore_x_dnd_self_begin(xwin, (unsigned char *)&xdnd, sizeof(Elm_Sel_Type));
|
2013-02-22 00:49:08 -08:00
|
|
|
actx = _x11_dnd_action_rev_map(dragaction);
|
|
|
|
ecore_x_dnd_source_action_set(actx);
|
2013-02-19 04:10:02 -08:00
|
|
|
ecore_x_pointer_grab(xwin);
|
2013-02-21 05:21:08 -08:00
|
|
|
handler_up = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP,
|
|
|
|
_x11_drag_mouse_up,
|
2013-02-19 04:10:02 -08:00
|
|
|
(void *)(long)xwin);
|
2010-09-13 02:16:01 -07:00
|
|
|
handler_status = ecore_event_handler_add(ECORE_X_EVENT_XDND_STATUS,
|
2012-08-22 02:37:00 -07:00
|
|
|
_x11_dnd_status, NULL);
|
2015-07-06 12:46:48 -07:00
|
|
|
dragwin = elm_win_add(NULL, "Elm-Drag", ELM_WIN_DND);
|
2013-02-19 04:10:02 -08:00
|
|
|
elm_win_alpha_set(dragwin, EINA_TRUE);
|
2012-01-02 20:44:48 -08:00
|
|
|
elm_win_override_set(dragwin, EINA_TRUE);
|
2014-04-09 19:20:50 -07:00
|
|
|
xdragwin = _x11_elm_widget_xwin_get(dragwin);
|
|
|
|
ecore_x_window_ignore_set(xdragwin, 1);
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2013-06-28 01:14:46 -07:00
|
|
|
/* dragwin has to be rotated as the main window is */
|
2014-03-28 02:22:49 -07:00
|
|
|
if (elm_widget_is(obj))
|
|
|
|
{
|
|
|
|
Evas_Object *win = elm_widget_top_get(obj);
|
2014-06-03 03:35:28 -07:00
|
|
|
if (win && eo_isa(win, ELM_WIN_CLASS))
|
2014-06-10 22:19:27 -07:00
|
|
|
{
|
|
|
|
elm_win_rotation_set(dragwin, elm_win_rotation_get(win));
|
2016-03-02 04:10:48 -08:00
|
|
|
eo_event_callback_add(win, ELM_WIN_EVENT_ROTATION_CHANGED, _x11_win_rotation_changed_cb, dragwin);
|
2014-06-10 22:19:27 -07:00
|
|
|
}
|
2014-03-28 02:22:49 -07:00
|
|
|
}
|
2013-06-28 01:14:46 -07:00
|
|
|
|
2013-02-19 04:10:02 -08:00
|
|
|
if (createicon)
|
|
|
|
{
|
|
|
|
Evas_Coord xoff = 0, yoff = 0;
|
2013-03-16 23:36:30 -07:00
|
|
|
|
2013-02-19 04:10:02 -08:00
|
|
|
icon = createicon(createdata, dragwin, &xoff, &yoff);
|
|
|
|
if (icon)
|
|
|
|
{
|
2013-03-16 23:36:30 -07:00
|
|
|
x2 = xoff;
|
|
|
|
y2 = yoff;
|
2013-02-19 04:10:02 -08:00
|
|
|
evas_object_geometry_get(icon, NULL, NULL, &w, &h);
|
|
|
|
}
|
|
|
|
}
|
2013-03-16 23:36:30 -07:00
|
|
|
else
|
2013-02-19 04:10:02 -08:00
|
|
|
{
|
|
|
|
icon = elm_icon_add(dragwin);
|
|
|
|
evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
2013-03-16 23:36:30 -07:00
|
|
|
// need to resize
|
2013-02-19 04:10:02 -08:00
|
|
|
}
|
2012-01-02 20:44:48 -08:00
|
|
|
elm_win_resize_object_add(dragwin, icon);
|
2010-09-13 02:16:01 -07:00
|
|
|
|
|
|
|
/* Position subwindow appropriately */
|
2010-09-13 02:16:05 -07:00
|
|
|
ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
|
2014-04-21 01:27:46 -07:00
|
|
|
ecore_evas_geometry_get(ee, &ex, &ey, &ew, &eh);
|
2010-12-20 03:09:19 -08:00
|
|
|
evas_object_resize(dragwin, w, h);
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-09-13 02:16:09 -07:00
|
|
|
evas_object_show(icon);
|
|
|
|
evas_object_show(dragwin);
|
2010-09-13 02:16:05 -07:00
|
|
|
evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x3, &y3);
|
2010-09-10 01:24:21 -07:00
|
|
|
|
2014-04-21 01:27:46 -07:00
|
|
|
rot = ecore_evas_rotation_get(ee);
|
|
|
|
switch (rot)
|
|
|
|
{
|
|
|
|
case 90:
|
|
|
|
xr = y3;
|
|
|
|
yr = ew - x3;
|
2015-10-21 14:39:05 -07:00
|
|
|
_dragx = y3 - y2;
|
|
|
|
_dragy = x3 - x2;
|
2014-04-21 01:27:46 -07:00
|
|
|
break;
|
|
|
|
case 180:
|
|
|
|
xr = ew - x3;
|
|
|
|
yr = eh - y3;
|
2015-10-21 14:39:05 -07:00
|
|
|
_dragx = x3 - x2;
|
|
|
|
_dragy = y3 - y2;
|
2014-04-21 01:27:46 -07:00
|
|
|
break;
|
|
|
|
case 270:
|
|
|
|
xr = eh - y3;
|
|
|
|
yr = x3;
|
2015-10-21 14:39:05 -07:00
|
|
|
_dragx = y3 - y2;
|
|
|
|
_dragy = x3 - x2;
|
2014-04-21 01:27:46 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
xr = x3;
|
|
|
|
yr = y3;
|
2015-10-21 14:39:05 -07:00
|
|
|
_dragx = x3 - x2;
|
|
|
|
_dragy = y3 - y2;
|
2014-04-21 01:27:46 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
x = ex + xr - _dragx;
|
|
|
|
y = ey + yr - _dragy;
|
|
|
|
evas_object_move(dragwin, x, y);
|
|
|
|
dragwin_x_start = dragwin_x_end = x;
|
|
|
|
dragwin_y_start = dragwin_y_end = y;
|
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
return EINA_TRUE;
|
2010-09-09 01:59:42 -07:00
|
|
|
}
|
2012-08-22 02:37:00 -07:00
|
|
|
|
2013-02-22 00:49:08 -08:00
|
|
|
static Eina_Bool
|
|
|
|
_x11_elm_drag_action_set(Evas_Object *obj, Elm_Xdnd_Action action)
|
|
|
|
{
|
|
|
|
Ecore_X_Atom actx;
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2013-02-22 00:49:08 -08:00
|
|
|
_x11_elm_cnp_init();
|
|
|
|
if (!dragwin) return EINA_FALSE;
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2013-02-22 00:49:08 -08:00
|
|
|
if (dragwidget != obj) return EINA_FALSE;
|
|
|
|
if (dragaction == action) return EINA_TRUE;
|
|
|
|
dragaction = action;
|
|
|
|
actx = _x11_dnd_action_rev_map(dragaction);
|
|
|
|
ecore_x_dnd_source_action_set(actx);
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-08-22 02:37:00 -07:00
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_x11_elm_selection_selection_has_owner(Evas_Object *obj EINA_UNUSED)
|
2012-08-22 02:37:00 -07:00
|
|
|
{
|
2012-08-28 00:49:27 -07:00
|
|
|
_x11_elm_cnp_init();
|
2012-08-22 02:37:00 -07:00
|
|
|
return !!ecore_x_selection_owner_get(ECORE_X_ATOM_SELECTION_CLIPBOARD);
|
|
|
|
}
|
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
#endif
|
2010-09-06 23:56:16 -07:00
|
|
|
|
2015-10-01 07:25:38 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
2012-08-28 23:52:48 -07:00
|
|
|
struct _Wl_Cnp_Selection
|
|
|
|
{
|
|
|
|
char *selbuf;
|
|
|
|
int buflen;
|
|
|
|
|
|
|
|
Evas_Object *widget;
|
|
|
|
Evas_Object *requestwidget;
|
2013-11-07 03:57:14 -08:00
|
|
|
|
|
|
|
void *udata;
|
|
|
|
Elm_Sel_Type seltype;
|
|
|
|
Elm_Sel_Format requestformat;
|
|
|
|
Elm_Drop_Cb datacb;
|
|
|
|
|
|
|
|
Elm_Selection_Loss_Cb loss_cb;
|
|
|
|
void *loss_data;
|
|
|
|
|
|
|
|
Elm_Sel_Format format;
|
2015-10-01 07:25:38 -07:00
|
|
|
Ecore_Wl2_Window *win;
|
2013-11-07 03:57:14 -08:00
|
|
|
Elm_Xdnd_Action action;
|
|
|
|
|
|
|
|
Eina_Bool active : 1;
|
2016-05-03 07:58:10 -07:00
|
|
|
Eina_Bool requestfinished : 1;
|
|
|
|
const char *requesttype;
|
2012-08-28 23:52:48 -07:00
|
|
|
};
|
|
|
|
|
2012-08-29 00:29:21 -07:00
|
|
|
static Eina_Bool _wl_elm_cnp_init(void);
|
|
|
|
|
2013-12-02 02:43:46 -08:00
|
|
|
static Wl_Cnp_Selection wl_cnp_selection =
|
2013-11-07 03:57:14 -08:00
|
|
|
{
|
2013-12-02 02:43:46 -08:00
|
|
|
0, 0, NULL, NULL,
|
|
|
|
NULL, 0, 0, NULL, NULL, NULL,
|
2016-05-03 07:58:10 -07:00
|
|
|
0, NULL, 0, EINA_FALSE, EINA_FALSE, ""
|
2013-11-07 03:57:14 -08:00
|
|
|
};
|
|
|
|
|
2014-01-06 06:30:02 -08:00
|
|
|
static void _wl_sel_obj_del2(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED);
|
|
|
|
static Eina_Bool _wl_elm_cnp_selection_set(Evas_Object *obj EINA_UNUSED, Elm_Sel_Type selection, Elm_Sel_Format format EINA_UNUSED, const void *selbuf, size_t buflen);
|
2015-06-26 07:44:40 -07:00
|
|
|
static Eina_Bool _wl_elm_cnp_selection_get(const Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format EINA_UNUSED, Elm_Drop_Cb datacb EINA_UNUSED, void *udata EINA_UNUSED);
|
2013-05-28 03:49:28 -07:00
|
|
|
static Eina_Bool _wl_elm_cnp_selection_clear(Evas_Object *obj, Elm_Sel_Type selection);
|
|
|
|
|
2014-01-06 06:30:02 -08:00
|
|
|
static Eina_Bool _wl_selection_send(void *udata, int type EINA_UNUSED, void *event);
|
|
|
|
static Eina_Bool _wl_selection_receive(void *udata, int type EINA_UNUSED, void *event);
|
2012-08-28 23:52:48 -07:00
|
|
|
|
2013-05-28 03:49:28 -07:00
|
|
|
static Eina_Bool _wl_elm_dnd_init(void);
|
2013-10-27 02:27:17 -07:00
|
|
|
static Eina_Bool _wl_elm_drop_target_add(Evas_Object *obj, Elm_Sel_Format format, Elm_Drag_State entercb, void *enterdata, Elm_Drag_State leavecb, void *leavedata, Elm_Drag_Pos poscb, void *posdata, Elm_Drop_Cb dropcb, void *dropdata);
|
2013-11-05 07:26:51 -08:00
|
|
|
static Eina_Bool _wl_elm_drop_target_del(Evas_Object *obj, Elm_Sel_Format format, Elm_Drag_State entercb, void *enterdata, Elm_Drag_State leavecb, void *leavedata, Elm_Drag_Pos poscb, void *posdata, Elm_Drop_Cb dropcb, void *dropdata);
|
2013-05-21 03:19:53 -07:00
|
|
|
|
2013-05-21 03:30:39 -07:00
|
|
|
static Eina_Bool _wl_elm_drag_action_set(Evas_Object *obj, Elm_Xdnd_Action action);
|
|
|
|
static Eina_Bool _wl_elm_drag_start(Evas_Object *obj, Elm_Sel_Format format, const char *data, Elm_Xdnd_Action action, Elm_Drag_Icon_Create_Cb createicon, void *createdata, Elm_Drag_Pos dragpos, void *dragdata, Elm_Drag_Accept acceptcb, void *acceptdata, Elm_Drag_State dragdone, void *donecbdata);
|
|
|
|
|
2013-05-28 03:49:28 -07:00
|
|
|
static void _wl_drag_source_del(void *data EINA_UNUSED, Evas *evas EINA_UNUSED, Evas_Object *obj, void *event EINA_UNUSED);
|
|
|
|
|
|
|
|
static Eina_Bool _wl_dnd_enter(void *data EINA_UNUSED, int type EINA_UNUSED, void *event);
|
|
|
|
static Eina_Bool _wl_dnd_leave(void *data EINA_UNUSED, int type EINA_UNUSED, void *event);
|
|
|
|
static Eina_Bool _wl_dnd_position(void *data EINA_UNUSED, int type EINA_UNUSED, void *event);
|
|
|
|
static Eina_Bool _wl_dnd_drop(void *data EINA_UNUSED, int type EINA_UNUSED, void *event);
|
|
|
|
/* static Eina_Bool _wl_dnd_offer(void *data EINA_UNUSED, int type EINA_UNUSED, void *event); */
|
|
|
|
|
|
|
|
static Eina_Bool _wl_dnd_end(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED);
|
2016-05-03 02:30:39 -07:00
|
|
|
static void _wl_dropable_data_handle(Wl_Cnp_Selection *sel, Ecore_Wl2_Event_Selection_Data_Ready *ev);
|
2013-05-28 03:49:28 -07:00
|
|
|
|
|
|
|
static Dropable *_wl_dropable_find(unsigned int win);
|
2015-02-25 00:36:26 -08:00
|
|
|
static void _wl_dropable_handle(Dropable *drop, Evas_Coord x, Evas_Coord y);
|
|
|
|
static void _wl_dropable_all_clean(unsigned int win);
|
2013-05-28 03:49:28 -07:00
|
|
|
static Eina_Bool _wl_drops_accept(const char *type);
|
2015-10-01 07:25:38 -07:00
|
|
|
static Ecore_Wl2_Window *_wl_elm_widget_window_get(const Evas_Object *obj);
|
2015-02-25 00:36:18 -08:00
|
|
|
static Evas * _wl_evas_get_from_win(unsigned int win);
|
2013-05-28 03:49:28 -07:00
|
|
|
|
2016-05-03 02:49:14 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_wl_is_uri_type_data(const char *data, int len)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
if (len < 6) return EINA_FALSE;
|
|
|
|
|
|
|
|
p = (char *)data;
|
|
|
|
if (!p) return EINA_FALSE;
|
|
|
|
if (strncmp(p, "file:/", 6))
|
|
|
|
{
|
|
|
|
if (*p != '/') return EINA_FALSE;
|
|
|
|
}
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2016-05-03 02:07:48 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_wl_targets_converter(char *target, Wl_Cnp_Selection *sel EINA_UNUSED, void *data EINA_UNUSED, int size EINA_UNUSED, void **data_ret, int *size_ret)
|
|
|
|
{
|
|
|
|
cnp_debug("in\n");
|
|
|
|
if (!data_ret) return EINA_FALSE;
|
|
|
|
|
|
|
|
const char *sep = "\n";
|
|
|
|
char *aret;
|
|
|
|
int len = 0;
|
|
|
|
int i = 0;
|
|
|
|
Elm_Sel_Format formats = ELM_SEL_FORMAT_NONE;
|
2016-05-03 03:41:00 -07:00
|
|
|
Eina_Bool is_uri = EINA_FALSE;
|
2016-05-03 02:07:48 -07:00
|
|
|
|
2016-05-03 03:41:00 -07:00
|
|
|
if (sel->format)
|
|
|
|
{
|
|
|
|
formats = sel->format;
|
|
|
|
is_uri = _wl_is_uri_type_data(sel->selbuf, sel->buflen);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Cnp_Atom *atom = eina_hash_find(_types_hash, target);
|
|
|
|
if (atom)
|
|
|
|
formats = atom->formats;
|
|
|
|
}
|
2016-05-03 02:07:48 -07:00
|
|
|
for (i = 0; i < CNP_N_ATOMS; i++)
|
|
|
|
{
|
|
|
|
if (formats & _atoms[i].formats)
|
|
|
|
{
|
2016-05-03 03:41:00 -07:00
|
|
|
if ((is_uri) || ((!is_uri) &&
|
|
|
|
strcmp(_atoms[i].name, "text/uri-list")))
|
|
|
|
len += strlen(_atoms[i].name) + strlen(sep);
|
2016-05-03 02:07:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
aret = calloc(1, len * sizeof(char));
|
|
|
|
if (!aret) return EINA_FALSE;
|
|
|
|
for (i = 0; i < CNP_N_ATOMS; i++)
|
|
|
|
{
|
|
|
|
if (formats & _atoms[i].formats)
|
|
|
|
{
|
2016-05-03 03:41:00 -07:00
|
|
|
if ((is_uri) || ((!is_uri) &&
|
|
|
|
strcmp(_atoms[i].name, "text/uri-list")))
|
|
|
|
{
|
|
|
|
aret = strcat(aret, _atoms[i].name);
|
|
|
|
aret = strcat(aret, sep);
|
|
|
|
}
|
2016-05-03 02:07:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*data_ret = aret;
|
|
|
|
if (size_ret) *size_ret = len;
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_wl_general_converter(char *target, Wl_Cnp_Selection *sel EINA_UNUSED, void *data, int size, void **data_ret, int *size_ret)
|
|
|
|
{
|
|
|
|
cnp_debug("in\n");
|
|
|
|
Elm_Sel_Format formats = ELM_SEL_FORMAT_NONE;
|
|
|
|
Cnp_Atom *atom = NULL;
|
|
|
|
|
|
|
|
atom = eina_hash_find(_types_hash, target);
|
|
|
|
if (atom)
|
|
|
|
formats = atom->formats;
|
|
|
|
if (formats == ELM_SEL_FORMAT_NONE)
|
|
|
|
{
|
|
|
|
if (data_ret)
|
|
|
|
{
|
|
|
|
*data_ret = malloc(size * sizeof(char) + 1);
|
|
|
|
if (!*data_ret) return EINA_FALSE;
|
|
|
|
memcpy(*data_ret, data, size);
|
|
|
|
((char**)(data_ret))[0][size] = 0;
|
|
|
|
}
|
|
|
|
if (size_ret) *size_ret = size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
if (data_ret) *data_ret = strdup(data);
|
|
|
|
if (size_ret) *size_ret = strlen(data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (data_ret) *data_ret = NULL;
|
|
|
|
if (size_ret) *size_ret = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_wl_text_converter(char *target, Wl_Cnp_Selection *sel, void *data, int size, void **data_ret, int *size_ret)
|
|
|
|
{
|
|
|
|
cnp_debug("in\n");
|
|
|
|
Elm_Sel_Format formats = ELM_SEL_FORMAT_NONE;
|
|
|
|
Cnp_Atom *atom = NULL;
|
|
|
|
|
|
|
|
atom = eina_hash_find(_types_hash, target);
|
|
|
|
if (atom)
|
|
|
|
formats = atom->formats;
|
|
|
|
if (formats == ELM_SEL_FORMAT_NONE)
|
|
|
|
{
|
|
|
|
if (data_ret)
|
|
|
|
{
|
|
|
|
*data_ret = malloc(size * sizeof(char) + 1);
|
|
|
|
if (!*data_ret) return EINA_FALSE;
|
|
|
|
memcpy(*data_ret, data, size);
|
|
|
|
((char**)(data_ret))[0][size] = 0;
|
|
|
|
if (size_ret) *size_ret = size;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((formats & ELM_SEL_FORMAT_MARKUP) ||
|
|
|
|
(formats & ELM_SEL_FORMAT_HTML))
|
|
|
|
{
|
|
|
|
*data_ret = _elm_util_mkup_to_text(data);
|
|
|
|
if (size_ret && *data_ret) *size_ret = strlen(*data_ret);
|
|
|
|
}
|
|
|
|
else if (formats & ELM_SEL_FORMAT_TEXT)
|
|
|
|
{
|
|
|
|
*data_ret = strdup(data);
|
|
|
|
if (size_ret && *data_ret) *size_ret = strlen(*data_ret);
|
|
|
|
}
|
|
|
|
else if (formats & ELM_SEL_FORMAT_IMAGE)
|
|
|
|
{
|
|
|
|
cnp_debug("Image %s\n", evas_object_type_get(sel->widget));
|
|
|
|
evas_object_image_file_get(elm_photocam_internal_image_get(sel->widget),
|
|
|
|
(const char **)data_ret, NULL);
|
|
|
|
if (!*data_ret) *data_ret = strdup("No file");
|
|
|
|
else *data_ret = strdup(*data_ret);
|
|
|
|
|
|
|
|
if (!*data_ret)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate memory!");
|
|
|
|
*size_ret = 0;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size_ret) *size_ret = strlen(*data_ret);
|
|
|
|
}
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2016-05-03 02:30:39 -07:00
|
|
|
static void
|
|
|
|
_wl_selection_parser(void *_data,
|
|
|
|
int size,
|
|
|
|
char ***ret_data,
|
|
|
|
int *ret_count)
|
|
|
|
{
|
|
|
|
char **files = NULL;
|
|
|
|
int num_files = 0;
|
|
|
|
char *data = NULL;
|
|
|
|
|
|
|
|
data = malloc(size);
|
|
|
|
if (data && (size > 0))
|
|
|
|
{
|
|
|
|
int i, is;
|
|
|
|
char *tmp;
|
|
|
|
char **t2;
|
|
|
|
|
|
|
|
memcpy(data, _data, size);
|
|
|
|
if (data[size - 1])
|
|
|
|
{
|
|
|
|
char *t;
|
|
|
|
|
|
|
|
/* Isn't nul terminated */
|
|
|
|
size++;
|
|
|
|
t = realloc(data, size);
|
|
|
|
if (!t) goto done;
|
|
|
|
data = t;
|
|
|
|
data[size - 1] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = malloc(size);
|
|
|
|
if (!tmp) goto done;
|
|
|
|
i = 0;
|
|
|
|
is = 0;
|
|
|
|
while ((is < size) && (data[is]))
|
|
|
|
{
|
|
|
|
if ((i == 0) && (data[is] == '#'))
|
|
|
|
for (; ((data[is]) && (data[is] != '\n')); is++) ;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((data[is] != '\r') &&
|
|
|
|
(data[is] != '\n'))
|
|
|
|
tmp[i++] = data[is++];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while ((data[is] == '\r') || (data[is] == '\n'))
|
|
|
|
is++;
|
|
|
|
tmp[i] = 0;
|
|
|
|
num_files++;
|
|
|
|
t2 = realloc(files, num_files * sizeof(char *));
|
|
|
|
if (t2)
|
|
|
|
{
|
|
|
|
files = t2;
|
|
|
|
files[num_files - 1] = strdup(tmp);
|
|
|
|
}
|
|
|
|
tmp[0] = 0;
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
tmp[i] = 0;
|
|
|
|
num_files++;
|
|
|
|
t2 = realloc(files, num_files * sizeof(char *));
|
|
|
|
if (t2)
|
|
|
|
{
|
|
|
|
files = t2;
|
|
|
|
files[num_files - 1] = strdup(tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(tmp);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
if (ret_data) *ret_data = files;
|
|
|
|
if (ret_count) *ret_count = num_files;
|
|
|
|
}
|
|
|
|
|
2016-05-03 07:58:10 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_wl_selection_get_timer_cb(void *data)
|
|
|
|
{
|
|
|
|
Wl_Cnp_Selection *sel = data;
|
|
|
|
Ecore_Wl2_Window *win;
|
|
|
|
|
|
|
|
win = _wl_elm_widget_window_get(sel->requestwidget);
|
|
|
|
ecore_wl2_dnd_selection_get(ecore_wl2_window_input_get(win),
|
|
|
|
sel->requesttype);
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_wl_notify_handler_targets(Wl_Cnp_Selection *sel, Ecore_Wl2_Event_Selection_Data_Ready *ev)
|
|
|
|
{
|
|
|
|
cnp_debug("In\n");
|
|
|
|
if (!ev) return EINA_FALSE;
|
|
|
|
char *data = ev->data;
|
|
|
|
int len = ev->len;
|
|
|
|
int count = 0, i = 0;
|
|
|
|
char **data_arr = NULL;
|
|
|
|
Cnp_Atom *atom = NULL;
|
|
|
|
|
|
|
|
_wl_selection_parser(data, len, &data_arr, &count);
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
atom = eina_hash_find(_types_hash, data_arr[i]);
|
|
|
|
if (atom && (atom->formats != ELM_SEL_FORMAT_TARGETS))
|
|
|
|
{
|
|
|
|
cnp_debug("Match found: %s\n", atom->name);
|
|
|
|
sel->requestfinished = EINA_FALSE;
|
|
|
|
/* Since we cannot call ecore_wl2_dnd_selection_get in here
|
|
|
|
(it makes selection_send cannot be called), we use ecore_timer
|
|
|
|
to call it */
|
|
|
|
sel->requesttype = atom->name;
|
|
|
|
ecore_timer_add(0.001, _wl_selection_get_timer_cb, sel);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(data_arr);
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2016-05-03 02:30:39 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_wl_data_preparer_markup(Wl_Cnp_Selection *sel, Elm_Selection_Data *ddata, Ecore_Wl2_Event_Selection_Data_Ready *ev, Tmp_Info **tmp_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
cnp_debug("In\n");
|
|
|
|
|
|
|
|
ddata->format = ELM_SEL_FORMAT_MARKUP;
|
|
|
|
ddata->data = eina_memdup((unsigned char *)ev->data, ev->len, EINA_TRUE);
|
|
|
|
ddata->len = ev->len;
|
|
|
|
ddata->action = sel->action;
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_wl_data_preparer_uri(Wl_Cnp_Selection *sel, Elm_Selection_Data *ddata, Ecore_Wl2_Event_Selection_Data_Ready *ev, Tmp_Info **tmp_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
cnp_debug("In\n");
|
|
|
|
|
|
|
|
char *p, *s, *stripstr = NULL;
|
|
|
|
char *data = ev->data;
|
|
|
|
Dropable *drop;
|
|
|
|
const char *type = NULL;
|
|
|
|
|
|
|
|
drop = eo_key_data_get(sel->requestwidget, "__elm_dropable");
|
|
|
|
if (drop)
|
|
|
|
type = drop->last.type;
|
|
|
|
if (!strcmp(type, "text/uri-list"))
|
|
|
|
{
|
|
|
|
int num_files = 0;
|
|
|
|
char **files = NULL;
|
|
|
|
int i, len = 0;
|
|
|
|
Efreet_Uri **uri;
|
|
|
|
|
|
|
|
_wl_selection_parser(ev->data, ev->len, &files, &num_files);
|
|
|
|
cnp_debug("got a files list\n");
|
|
|
|
uri = calloc(1, sizeof(*uri) * num_files);
|
|
|
|
if (!uri) return EINA_FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < num_files ; i++)
|
|
|
|
{
|
|
|
|
uri[i] = efreet_uri_decode(files[i]);
|
|
|
|
if (!uri[i])
|
|
|
|
{
|
|
|
|
/* Is there any reason why we care of URI without scheme? */
|
|
|
|
if (files[i][0] != '/') continue;
|
|
|
|
len += strlen(files[i]) + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (strcmp(uri[i]->protocol, "file"))
|
|
|
|
{
|
|
|
|
efreet_uri_free(uri[i]);
|
|
|
|
uri[i] = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
len += strlen(uri[i]->path) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p = NULL;
|
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
s = stripstr = malloc(len + 1);
|
|
|
|
for (i = 0; i < num_files ; i++)
|
|
|
|
{
|
|
|
|
if (uri[i])
|
|
|
|
p = (char *)uri[i]->path;
|
|
|
|
else
|
|
|
|
p = files[i];
|
|
|
|
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
len = strlen(p);
|
|
|
|
strcpy(s, p);
|
|
|
|
if (i < (num_files - 1))
|
|
|
|
{
|
|
|
|
s[len] = '\n';
|
|
|
|
s[len + 1] = 0;
|
|
|
|
s += len + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s[len] = 0;
|
|
|
|
s += len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uri[i])
|
|
|
|
efreet_uri_free(uri[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(uri);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Efreet_Uri *uri;
|
|
|
|
|
|
|
|
p = (char *)eina_memdup((unsigned char *)data,
|
|
|
|
ev->len, EINA_TRUE);
|
|
|
|
if (!p) return EINA_FALSE;
|
|
|
|
uri = efreet_uri_decode(p);
|
|
|
|
if (!uri)
|
|
|
|
{
|
|
|
|
/* Is there any reason why we care of URI without scheme? */
|
|
|
|
if (p[0] == '/') stripstr = p;
|
|
|
|
else free(p);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free(p);
|
|
|
|
stripstr = (char *)eina_memdup((unsigned char *)uri->path,
|
|
|
|
strlen(uri->path), EINA_TRUE);
|
|
|
|
efreet_uri_free(uri);
|
|
|
|
if (!stripstr) return EINA_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stripstr)
|
|
|
|
{
|
|
|
|
cnp_debug("Couldn't find a file\n");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
free(savedtypes.imgfile);
|
|
|
|
|
|
|
|
ddata->data = stripstr;
|
|
|
|
ddata->len = strlen(stripstr);
|
|
|
|
ddata->action = sel->action;
|
|
|
|
ddata->format = sel->requestformat;
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_wl_data_preparer_vcard(Wl_Cnp_Selection *sel, Elm_Selection_Data *ddata, Ecore_Wl2_Event_Selection_Data_Ready *ev, Tmp_Info **tmp_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
cnp_debug("In\n");
|
|
|
|
|
|
|
|
ddata->format = ELM_SEL_FORMAT_VCARD;
|
|
|
|
ddata->data = eina_memdup((unsigned char *)ev->data, ev->len, EINA_TRUE);
|
|
|
|
ddata->len = ev->len;
|
|
|
|
ddata->action = sel->action;
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_wl_data_preparer_image(Wl_Cnp_Selection *sel, Elm_Selection_Data *ddata, Ecore_Wl2_Event_Selection_Data_Ready *ev, Tmp_Info **tmp_info)
|
|
|
|
{
|
|
|
|
cnp_debug("In\n");
|
|
|
|
Tmp_Info *tmp;
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
tmp = _tempfile_new(ev->len);
|
|
|
|
if (!tmp)
|
|
|
|
return EINA_FALSE;
|
|
|
|
memcpy(tmp->map, ev->data, ev->len);
|
|
|
|
munmap(tmp->map, ev->len);
|
|
|
|
|
|
|
|
len = strlen(tmp->filename);
|
|
|
|
ddata->format = ELM_SEL_FORMAT_IMAGE;
|
|
|
|
ddata->data = eina_memdup((unsigned char*)tmp->filename, len, EINA_TRUE);
|
|
|
|
ddata->len = len;
|
|
|
|
ddata->action = sel->action;
|
|
|
|
*tmp_info = tmp;
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_wl_data_preparer_text(Wl_Cnp_Selection *sel, Elm_Selection_Data *ddata, Ecore_Wl2_Event_Selection_Data_Ready *ev, Tmp_Info **tmp_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
cnp_debug("In\n");
|
|
|
|
|
|
|
|
ddata->format = ELM_SEL_FORMAT_TEXT;
|
|
|
|
ddata->data = eina_memdup((unsigned char *)ev->data, ev->len, EINA_TRUE);
|
|
|
|
ddata->len = ev->len;
|
|
|
|
ddata->action = sel->action;
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2013-11-07 03:57:14 -08:00
|
|
|
static void
|
2014-01-06 06:30:02 -08:00
|
|
|
_wl_sel_obj_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
|
2013-11-07 03:57:14 -08:00
|
|
|
{
|
|
|
|
Wl_Cnp_Selection *sel = data;
|
|
|
|
if (sel->widget == obj) sel->widget = NULL;
|
|
|
|
if (dragwidget == obj) dragwidget = NULL;
|
|
|
|
}
|
|
|
|
|
2012-08-28 23:52:48 -07:00
|
|
|
static void
|
2014-01-06 06:30:02 -08:00
|
|
|
_wl_sel_obj_del2(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
|
2012-08-28 23:52:48 -07:00
|
|
|
{
|
|
|
|
Wl_Cnp_Selection *sel = data;
|
|
|
|
if (sel->requestwidget == obj) sel->requestwidget = NULL;
|
|
|
|
}
|
|
|
|
|
2013-09-30 03:21:31 -07:00
|
|
|
static Eina_Bool
|
2013-11-07 03:57:14 -08:00
|
|
|
_wl_elm_cnp_selection_set(Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format, const void *selbuf, size_t buflen)
|
2012-08-28 23:52:48 -07:00
|
|
|
{
|
2015-10-01 07:25:38 -07:00
|
|
|
Ecore_Wl2_Window *win;
|
2013-11-07 03:57:14 -08:00
|
|
|
Wl_Cnp_Selection *sel = &wl_cnp_selection;
|
|
|
|
|
|
|
|
if ((!selbuf) && (format != ELM_SEL_FORMAT_IMAGE))
|
|
|
|
return elm_object_cnp_selection_clear(obj, selection);
|
2012-08-28 23:52:48 -07:00
|
|
|
|
2014-07-08 06:45:47 -07:00
|
|
|
if (buflen <= 0)
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
2012-08-29 00:29:21 -07:00
|
|
|
_wl_elm_cnp_init();
|
|
|
|
|
2015-10-01 07:25:38 -07:00
|
|
|
win = _wl_elm_widget_window_get(obj);
|
2013-11-07 03:57:14 -08:00
|
|
|
|
2015-12-17 10:13:17 -08:00
|
|
|
if ((sel->widget != obj) && sel->loss_cb)
|
|
|
|
sel->loss_cb(sel->loss_data, selection);
|
2013-11-07 03:57:14 -08:00
|
|
|
|
|
|
|
if (sel->widget)
|
2013-12-02 02:43:46 -08:00
|
|
|
evas_object_event_callback_del_full(sel->widget,
|
2013-11-07 03:57:14 -08:00
|
|
|
EVAS_CALLBACK_DEL,
|
|
|
|
_wl_sel_obj_del, &wl_cnp_selection);
|
|
|
|
sel->active = EINA_TRUE;
|
|
|
|
sel->seltype = selection;
|
|
|
|
sel->widget = obj;
|
|
|
|
sel->win = win;
|
|
|
|
/* sel->set(win, &selection, sizeof(Elm_Sel_Type)); */
|
|
|
|
sel->format = format;
|
|
|
|
sel->loss_cb = NULL;
|
|
|
|
sel->loss_data = NULL;
|
|
|
|
|
|
|
|
evas_object_event_callback_add
|
2013-12-02 02:43:46 -08:00
|
|
|
(sel->widget, EVAS_CALLBACK_DEL, _wl_sel_obj_del,
|
2013-11-07 03:57:14 -08:00
|
|
|
&wl_cnp_selection);
|
|
|
|
|
|
|
|
if (selbuf)
|
2012-08-28 23:52:48 -07:00
|
|
|
{
|
2016-05-03 02:49:14 -07:00
|
|
|
int i = 0, count = 0;
|
|
|
|
Eina_Bool is_uri = EINA_FALSE;
|
|
|
|
const char **types;
|
|
|
|
|
2013-11-07 03:57:14 -08:00
|
|
|
if (format & ELM_SEL_FORMAT_IMAGE)
|
|
|
|
{
|
|
|
|
/* FIXME */
|
|
|
|
// selbuf is actual image data, not text/string
|
|
|
|
sel->selbuf = malloc(buflen + 1);
|
|
|
|
if (!sel->selbuf)
|
|
|
|
{
|
|
|
|
elm_object_cnp_selection_clear(obj, selection);
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
memcpy(sel->selbuf, selbuf, buflen);
|
|
|
|
sel->selbuf[buflen] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-03 02:49:14 -07:00
|
|
|
free(sel->selbuf);
|
|
|
|
sel->buflen = buflen;
|
|
|
|
sel->selbuf = strdup((char*)selbuf);
|
|
|
|
}
|
2012-08-28 23:52:48 -07:00
|
|
|
|
2016-05-03 02:49:14 -07:00
|
|
|
is_uri = _wl_is_uri_type_data(selbuf, buflen);
|
|
|
|
types = malloc(sizeof(char *));
|
|
|
|
if (!types) return EINA_FALSE;
|
|
|
|
for (i = 0, count = 1; i < CNP_N_ATOMS; i++)
|
|
|
|
{
|
|
|
|
if (format & _atoms[i].formats)
|
2013-11-07 03:57:14 -08:00
|
|
|
{
|
2016-05-03 02:49:14 -07:00
|
|
|
if ((is_uri) || ((!is_uri) &&
|
|
|
|
strcmp(_atoms[i].name, "text/uri-list")))
|
|
|
|
{
|
|
|
|
const char **t = NULL;
|
2013-11-07 03:57:14 -08:00
|
|
|
|
2016-05-03 02:49:14 -07:00
|
|
|
types[count - 1] = _atoms[i].name;
|
|
|
|
count++;
|
|
|
|
t = realloc(types, sizeof(char *) * count);
|
|
|
|
if (!t)
|
|
|
|
{
|
|
|
|
free(types);
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
types = t;
|
|
|
|
}
|
2013-11-07 03:57:14 -08:00
|
|
|
}
|
2016-05-03 02:49:14 -07:00
|
|
|
}
|
|
|
|
types[count - 1] = 0;
|
2013-11-07 03:57:14 -08:00
|
|
|
|
2016-05-03 02:49:14 -07:00
|
|
|
ecore_wl2_dnd_selection_set(ecore_wl2_window_input_get(win), types);
|
2013-11-07 03:57:14 -08:00
|
|
|
|
2016-05-03 02:49:14 -07:00
|
|
|
free(types);
|
|
|
|
return EINA_TRUE;
|
2012-08-28 23:52:48 -07:00
|
|
|
}
|
2013-11-07 03:57:14 -08:00
|
|
|
else
|
2016-05-03 02:49:14 -07:00
|
|
|
{
|
|
|
|
sel->selbuf = NULL;
|
|
|
|
}
|
2012-08-28 23:52:48 -07:00
|
|
|
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
2013-09-30 03:21:31 -07:00
|
|
|
static Eina_Bool
|
2015-06-26 07:44:40 -07:00
|
|
|
_wl_elm_cnp_selection_get(const Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format, Elm_Drop_Cb datacb, void *udata)
|
2012-08-28 23:52:48 -07:00
|
|
|
{
|
2015-10-01 07:25:38 -07:00
|
|
|
Ecore_Wl2_Window *win;
|
2013-11-07 03:57:14 -08:00
|
|
|
Wl_Cnp_Selection *sel = &wl_cnp_selection;
|
|
|
|
|
2012-08-29 00:29:21 -07:00
|
|
|
_wl_elm_cnp_init();
|
|
|
|
|
2015-10-01 07:25:38 -07:00
|
|
|
win = _wl_elm_widget_window_get(obj);
|
2013-11-07 03:57:14 -08:00
|
|
|
|
|
|
|
if (sel->requestwidget)
|
2013-12-02 02:43:46 -08:00
|
|
|
evas_object_event_callback_del_full(sel->requestwidget,
|
2013-11-07 03:57:14 -08:00
|
|
|
EVAS_CALLBACK_DEL,
|
|
|
|
_wl_sel_obj_del2, &wl_cnp_selection);
|
|
|
|
sel->requestformat = format;
|
2015-06-26 07:44:40 -07:00
|
|
|
sel->requestwidget = (Evas_Object *) obj;
|
2013-11-07 03:57:14 -08:00
|
|
|
sel->win = win;
|
|
|
|
sel->datacb = datacb;
|
|
|
|
sel->udata = udata;
|
2016-05-03 07:58:10 -07:00
|
|
|
sel->requesttype = "TARGETS";
|
2012-08-28 23:52:48 -07:00
|
|
|
|
2013-12-02 02:43:46 -08:00
|
|
|
evas_object_event_callback_add(sel->requestwidget,
|
|
|
|
EVAS_CALLBACK_DEL, _wl_sel_obj_del2,
|
2013-11-07 03:57:14 -08:00
|
|
|
&wl_cnp_selection);
|
|
|
|
|
2013-12-02 02:43:46 -08:00
|
|
|
if ((selection == ELM_SEL_TYPE_CLIPBOARD) ||
|
|
|
|
(selection == ELM_SEL_TYPE_PRIMARY) ||
|
2013-11-07 06:26:57 -08:00
|
|
|
(selection == ELM_SEL_TYPE_SECONDARY))
|
2012-08-28 23:52:48 -07:00
|
|
|
{
|
2016-05-03 07:58:10 -07:00
|
|
|
ecore_wl2_dnd_selection_get(ecore_wl2_window_input_get(win), "TARGETS");
|
2013-05-28 03:49:28 -07:00
|
|
|
}
|
2013-11-07 03:57:14 -08:00
|
|
|
|
2013-05-28 03:49:28 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2013-11-07 03:57:14 -08:00
|
|
|
static void
|
2014-01-06 06:30:02 -08:00
|
|
|
_wl_elm_cnp_selection_loss_callback_set(Evas_Object *obj EINA_UNUSED, Elm_Sel_Type selection EINA_UNUSED, Elm_Selection_Loss_Cb func, const void *data)
|
2013-11-07 03:57:14 -08:00
|
|
|
{
|
|
|
|
Wl_Cnp_Selection *sel = &wl_cnp_selection;
|
|
|
|
|
|
|
|
_wl_elm_cnp_init();
|
|
|
|
|
|
|
|
sel->loss_cb = func;
|
|
|
|
sel->loss_data = (void *)data;
|
|
|
|
}
|
|
|
|
|
2013-09-30 03:21:31 -07:00
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_wl_elm_cnp_selection_clear(Evas_Object *obj, Elm_Sel_Type selection EINA_UNUSED)
|
2013-05-28 03:49:28 -07:00
|
|
|
{
|
2013-11-07 03:57:14 -08:00
|
|
|
Wl_Cnp_Selection *sel = &wl_cnp_selection;
|
|
|
|
|
2013-05-28 03:49:28 -07:00
|
|
|
_wl_elm_cnp_init();
|
|
|
|
|
2013-11-07 03:57:14 -08:00
|
|
|
if ((!sel->active) || (sel->widget != obj))
|
|
|
|
return EINA_TRUE;
|
|
|
|
|
|
|
|
if (sel->widget)
|
2013-12-02 02:43:46 -08:00
|
|
|
evas_object_event_callback_del_full(sel->widget,
|
2013-11-07 03:57:14 -08:00
|
|
|
EVAS_CALLBACK_DEL,
|
|
|
|
_wl_sel_obj_del, &wl_cnp_selection);
|
|
|
|
if (sel->requestwidget)
|
2013-12-02 02:43:46 -08:00
|
|
|
evas_object_event_callback_del_full(sel->requestwidget,
|
2013-11-07 03:57:14 -08:00
|
|
|
EVAS_CALLBACK_DEL,
|
|
|
|
_wl_sel_obj_del2, &wl_cnp_selection);
|
|
|
|
|
|
|
|
sel->widget = NULL;
|
|
|
|
sel->requestwidget = NULL;
|
|
|
|
sel->loss_cb = NULL;
|
|
|
|
sel->loss_data = NULL;
|
|
|
|
|
|
|
|
sel->active = EINA_FALSE;
|
|
|
|
ELM_SAFE_FREE(sel->selbuf, free);
|
|
|
|
sel->buflen = 0;
|
|
|
|
/* sel->clear(); */
|
2015-10-01 07:25:38 -07:00
|
|
|
ecore_wl2_dnd_selection_clear(ecore_wl2_window_input_get(_wl_elm_widget_window_get(obj)));
|
2013-11-07 03:57:14 -08:00
|
|
|
|
2012-08-28 23:52:48 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2016-05-03 02:44:16 -07:00
|
|
|
_wl_selection_send(void *data, int type EINA_UNUSED, void *event)
|
2012-08-28 23:52:48 -07:00
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
int ret, len_remained;
|
|
|
|
int len_written = 0;
|
2016-05-03 02:44:16 -07:00
|
|
|
Wl_Cnp_Selection *sel;
|
|
|
|
Ecore_Wl2_Event_Data_Source_Send *ev;
|
|
|
|
void *data_ret = NULL;
|
|
|
|
int len_ret = 0;
|
|
|
|
int i = 0;
|
2012-08-28 23:52:48 -07:00
|
|
|
|
2012-08-29 00:29:21 -07:00
|
|
|
_wl_elm_cnp_init();
|
2016-05-03 02:44:16 -07:00
|
|
|
cnp_debug("In\n");
|
|
|
|
ev = event;
|
|
|
|
sel = data;
|
2012-08-29 00:29:21 -07:00
|
|
|
|
2016-05-03 02:44:16 -07:00
|
|
|
for (i = 0; i < CNP_N_ATOMS; i++)
|
|
|
|
{
|
|
|
|
if (!strcmp(_atoms[i].name, ev->type))
|
|
|
|
{
|
|
|
|
cnp_debug("Found a type: %s\n", _atoms[i].name);
|
|
|
|
Dropable *drop;
|
|
|
|
drop = eo_key_data_get(sel->requestwidget, "__elm_dropable");
|
|
|
|
if (drop)
|
|
|
|
drop->last.type = _atoms[i].name;
|
|
|
|
if (_atoms[i].wl_converter)
|
|
|
|
{
|
|
|
|
_atoms[i].wl_converter(ev->type, sel, sel->selbuf,
|
|
|
|
sel->buflen, &data_ret, &len_ret);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data_ret = strdup(sel->selbuf);
|
|
|
|
len_ret = sel->buflen;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
len_remained = len_ret;
|
|
|
|
buf = data_ret;
|
|
|
|
cnp_debug("write: %s", buf);
|
2012-08-28 23:52:48 -07:00
|
|
|
|
2016-05-03 02:44:16 -07:00
|
|
|
while (len_written < len_ret)
|
2012-08-28 23:52:48 -07:00
|
|
|
{
|
|
|
|
ret = write(ev->fd, buf, len_remained);
|
|
|
|
if (ret == -1) break;
|
|
|
|
buf += ret;
|
|
|
|
len_written += ret;
|
|
|
|
len_remained -= ret;
|
|
|
|
}
|
2016-05-03 02:44:16 -07:00
|
|
|
free(data_ret);
|
2012-08-28 23:52:48 -07:00
|
|
|
|
|
|
|
close(ev->fd);
|
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
|
|
|
}
|
|
|
|
|
2016-05-03 07:58:10 -07:00
|
|
|
static void
|
|
|
|
_wl_selection_data_handle(Wl_Cnp_Selection *sel, Ecore_Wl2_Event_Selection_Data_Ready *ev)
|
2012-08-28 23:52:48 -07:00
|
|
|
{
|
2016-05-03 07:58:10 -07:00
|
|
|
cnp_debug("In\n");
|
|
|
|
sel->requestfinished = EINA_TRUE;
|
|
|
|
if (sel->datacb)
|
2012-08-28 23:52:48 -07:00
|
|
|
{
|
2016-05-03 07:58:10 -07:00
|
|
|
if (!strcmp(sel->requesttype, "TARGETS") ||
|
|
|
|
!strcmp(sel->requesttype, "ATOMS"))
|
2012-08-28 23:52:48 -07:00
|
|
|
{
|
2016-05-03 07:58:10 -07:00
|
|
|
_wl_notify_handler_targets(sel, ev);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Cnp_Atom *atom = eina_hash_find(_types_hash, sel->requesttype);
|
|
|
|
if (atom && atom->wl_data_preparer)
|
2013-11-07 03:57:14 -08:00
|
|
|
{
|
|
|
|
Elm_Selection_Data sdata;
|
2016-05-03 07:58:10 -07:00
|
|
|
Tmp_Info *tmp_info = NULL;
|
|
|
|
Eina_Bool success;
|
|
|
|
sdata.data = NULL;
|
2013-11-07 03:57:14 -08:00
|
|
|
|
2016-05-03 07:58:10 -07:00
|
|
|
cnp_debug("Call notify for: %s\n", atom->name);
|
|
|
|
success = atom->wl_data_preparer(sel, &sdata, ev, &tmp_info);
|
|
|
|
if (success)
|
2013-11-07 03:57:14 -08:00
|
|
|
{
|
2016-05-03 07:58:10 -07:00
|
|
|
sdata.x = sdata.y = 0;
|
|
|
|
sel->datacb(sel->udata,
|
|
|
|
sel->requestwidget,
|
|
|
|
&sdata);
|
2013-11-07 03:57:14 -08:00
|
|
|
}
|
2016-05-03 07:58:10 -07:00
|
|
|
if (tmp_info) _tmpinfo_free(tmp_info);
|
|
|
|
free(sdata.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cnp_debug("request to paste: datacb does not exist\n");
|
|
|
|
}
|
|
|
|
}
|
2013-11-07 03:57:14 -08:00
|
|
|
|
|
|
|
|
2016-05-03 07:58:10 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_wl_selection_receive(void *data, int type EINA_UNUSED, void *event)
|
|
|
|
{
|
|
|
|
Wl_Cnp_Selection *sel;
|
|
|
|
Ecore_Wl2_Event_Selection_Data_Ready *ev;
|
|
|
|
cnp_debug("In\n");
|
2013-11-07 03:57:14 -08:00
|
|
|
|
2016-05-03 07:58:10 -07:00
|
|
|
_wl_elm_cnp_init();
|
|
|
|
ev = event;
|
|
|
|
sel = data;
|
2013-11-07 03:57:14 -08:00
|
|
|
|
2016-05-03 07:58:10 -07:00
|
|
|
if (sel->requestwidget)
|
|
|
|
{
|
|
|
|
if (!ev->done)
|
|
|
|
{
|
|
|
|
if (ev->sel_type == ECORE_WL2_SELECTION_DND)
|
2013-11-07 03:57:14 -08:00
|
|
|
{
|
2016-05-03 07:58:10 -07:00
|
|
|
_wl_dropable_data_handle(sel, ev);
|
2013-11-07 03:57:14 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-03 07:58:10 -07:00
|
|
|
_wl_selection_data_handle(sel, ev);
|
2013-11-07 03:57:14 -08:00
|
|
|
}
|
2012-08-28 23:52:48 -07:00
|
|
|
}
|
2016-05-03 07:58:10 -07:00
|
|
|
else if (sel->requestfinished)
|
2012-08-28 23:52:48 -07:00
|
|
|
{
|
2013-12-02 02:43:46 -08:00
|
|
|
evas_object_event_callback_del_full(sel->requestwidget,
|
2013-11-07 03:57:14 -08:00
|
|
|
EVAS_CALLBACK_DEL,
|
2012-08-28 23:52:48 -07:00
|
|
|
_wl_sel_obj_del2, sel);
|
|
|
|
sel->requestwidget = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
|
|
|
}
|
|
|
|
|
2013-09-30 03:21:31 -07:00
|
|
|
static Eina_Bool
|
2012-08-29 00:29:21 -07:00
|
|
|
_wl_elm_cnp_init(void)
|
2012-08-28 23:52:48 -07:00
|
|
|
{
|
2012-08-29 00:29:21 -07:00
|
|
|
static int _init_count = 0;
|
|
|
|
|
|
|
|
if (_init_count > 0) return EINA_TRUE;
|
|
|
|
_init_count++;
|
|
|
|
|
2015-10-01 07:25:38 -07:00
|
|
|
ecore_event_handler_add(ECORE_WL2_EVENT_DATA_SOURCE_SEND,
|
2012-08-28 23:52:48 -07:00
|
|
|
_wl_selection_send, &wl_cnp_selection);
|
2015-10-01 07:25:38 -07:00
|
|
|
ecore_event_handler_add(ECORE_WL2_EVENT_SELECTION_DATA_READY,
|
2012-08-28 23:52:48 -07:00
|
|
|
_wl_selection_receive, &wl_cnp_selection);
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
2013-05-21 03:19:53 -07:00
|
|
|
|
2013-09-30 03:21:31 -07:00
|
|
|
static Eina_Bool
|
2013-05-28 03:49:28 -07:00
|
|
|
_wl_elm_dnd_init(void)
|
|
|
|
{
|
|
|
|
static int _init_count = 0;
|
|
|
|
|
|
|
|
if (_init_count > 0) return EINA_TRUE;
|
|
|
|
_init_count++;
|
|
|
|
|
|
|
|
text_uri = eina_stringshare_add("text/uri-list");
|
|
|
|
|
2016-05-03 02:44:16 -07:00
|
|
|
_wl_elm_cnp_init();
|
2013-05-28 03:49:28 -07:00
|
|
|
|
2015-10-01 07:25:38 -07:00
|
|
|
ecore_event_handler_add(ECORE_WL2_EVENT_DND_END,
|
2013-05-28 03:49:28 -07:00
|
|
|
_wl_dnd_end, &wl_cnp_selection);
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2013-09-30 03:21:31 -07:00
|
|
|
static Eina_Bool
|
2013-10-27 02:27:17 -07:00
|
|
|
_wl_elm_drop_target_add(Evas_Object *obj, Elm_Sel_Format format, Elm_Drag_State entercb, void *enterdata, Elm_Drag_State leavecb, void *leavedata, Elm_Drag_Pos poscb, void *posdata, Elm_Drop_Cb dropcb, void *dropdata)
|
2013-05-21 03:19:53 -07:00
|
|
|
{
|
2013-11-05 07:26:51 -08:00
|
|
|
Dropable *dropable = NULL;
|
|
|
|
Dropable_Cbs *cbs = NULL;
|
2013-05-28 03:49:28 -07:00
|
|
|
|
2013-11-05 07:26:51 -08:00
|
|
|
Eina_Bool first = !drops;
|
2013-05-21 03:19:53 -07:00
|
|
|
|
2013-11-05 07:26:51 -08:00
|
|
|
cbs = calloc(1, sizeof(*cbs));
|
|
|
|
if (!cbs) return EINA_FALSE;
|
2013-05-21 03:19:53 -07:00
|
|
|
|
2013-11-05 07:26:51 -08:00
|
|
|
cbs->entercb = entercb;
|
|
|
|
cbs->enterdata = enterdata;
|
|
|
|
cbs->leavecb = leavecb;
|
|
|
|
cbs->leavedata = leavedata;
|
|
|
|
cbs->poscb = poscb;
|
|
|
|
cbs->posdata = posdata;
|
|
|
|
cbs->dropcb = dropcb;
|
|
|
|
cbs->dropdata = dropdata;
|
|
|
|
cbs->types = format;
|
2013-05-21 03:19:53 -07:00
|
|
|
|
2016-03-02 04:10:48 -08:00
|
|
|
dropable = eo_key_data_get(obj, "__elm_dropable");
|
2013-11-05 07:26:51 -08:00
|
|
|
if (!dropable)
|
2013-05-21 03:19:53 -07:00
|
|
|
{
|
2013-11-05 07:26:51 -08:00
|
|
|
/* Create new drop */
|
|
|
|
dropable = calloc(1, sizeof(Dropable));
|
|
|
|
if (!dropable) goto error;
|
|
|
|
drops = eina_list_append(drops, dropable);
|
|
|
|
if (!drops) goto error;
|
|
|
|
dropable->obj = obj;
|
2016-03-02 04:10:48 -08:00
|
|
|
eo_key_data_set(obj, "__elm_dropable", dropable);
|
2013-05-21 03:19:53 -07:00
|
|
|
}
|
2013-11-05 07:26:51 -08:00
|
|
|
dropable->cbs_list = eina_inlist_append(dropable->cbs_list, EINA_INLIST_GET(cbs));
|
2013-05-21 03:19:53 -07:00
|
|
|
|
|
|
|
evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
|
2013-11-05 07:26:51 -08:00
|
|
|
_all_drop_targets_cbs_del, obj);
|
2013-05-21 03:19:53 -07:00
|
|
|
|
2013-05-28 03:49:28 -07:00
|
|
|
if (first)
|
|
|
|
{
|
2013-09-30 03:21:31 -07:00
|
|
|
handler_enter =
|
2015-10-01 07:25:38 -07:00
|
|
|
ecore_event_handler_add(ECORE_WL2_EVENT_DND_ENTER,
|
2013-05-28 03:49:28 -07:00
|
|
|
_wl_dnd_enter, NULL);
|
2013-09-30 03:21:31 -07:00
|
|
|
handler_leave =
|
2015-10-01 07:25:38 -07:00
|
|
|
ecore_event_handler_add(ECORE_WL2_EVENT_DND_LEAVE,
|
2013-05-28 03:49:28 -07:00
|
|
|
_wl_dnd_leave, NULL);
|
2013-09-30 03:21:31 -07:00
|
|
|
handler_pos =
|
2015-10-01 07:25:38 -07:00
|
|
|
ecore_event_handler_add(ECORE_WL2_EVENT_DND_MOTION,
|
2013-05-28 03:49:28 -07:00
|
|
|
_wl_dnd_position, NULL);
|
2013-09-30 03:21:31 -07:00
|
|
|
handler_drop =
|
2015-10-01 07:25:38 -07:00
|
|
|
ecore_event_handler_add(ECORE_WL2_EVENT_DND_DROP,
|
2013-05-28 03:49:28 -07:00
|
|
|
_wl_dnd_drop, NULL);
|
2015-08-13 11:48:35 -07:00
|
|
|
_wl_elm_dnd_init();
|
2013-05-28 03:49:28 -07:00
|
|
|
}
|
|
|
|
|
2013-05-21 03:19:53 -07:00
|
|
|
return EINA_TRUE;
|
2013-11-05 07:26:51 -08:00
|
|
|
error:
|
|
|
|
free(cbs);
|
|
|
|
free(dropable);
|
|
|
|
return EINA_FALSE;
|
2013-05-21 03:19:53 -07:00
|
|
|
}
|
|
|
|
|
2013-09-30 03:21:31 -07:00
|
|
|
static Eina_Bool
|
2013-11-05 07:26:51 -08:00
|
|
|
_wl_elm_drop_target_del(Evas_Object *obj, Elm_Sel_Format format,
|
|
|
|
Elm_Drag_State entercb, void *enterdata,
|
|
|
|
Elm_Drag_State leavecb, void *leavedata,
|
|
|
|
Elm_Drag_Pos poscb, void *posdata,
|
|
|
|
Elm_Drop_Cb dropcb, void *dropdata)
|
2013-05-21 03:19:53 -07:00
|
|
|
{
|
|
|
|
|
2014-10-20 09:10:02 -07:00
|
|
|
if (!_local_elm_drop_target_del(obj, format, entercb, enterdata,
|
|
|
|
leavecb, leavedata, poscb, posdata, dropcb, dropdata))
|
2013-05-21 03:19:53 -07:00
|
|
|
{
|
2014-10-20 09:10:02 -07:00
|
|
|
return EINA_FALSE;
|
2013-05-21 03:19:53 -07:00
|
|
|
}
|
|
|
|
|
2013-05-28 03:49:28 -07:00
|
|
|
if (!drops)
|
|
|
|
{
|
2013-05-29 04:47:08 -07:00
|
|
|
ELM_SAFE_FREE(handler_pos, ecore_event_handler_del);
|
|
|
|
ELM_SAFE_FREE(handler_drop, ecore_event_handler_del);
|
|
|
|
ELM_SAFE_FREE(handler_enter, ecore_event_handler_del);
|
|
|
|
ELM_SAFE_FREE(handler_leave, ecore_event_handler_del);
|
2013-05-28 03:49:28 -07:00
|
|
|
}
|
|
|
|
|
2013-05-21 03:19:53 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2013-09-30 03:21:31 -07:00
|
|
|
static Eina_Bool
|
2013-05-21 03:30:39 -07:00
|
|
|
_wl_elm_drag_action_set(Evas_Object *obj, Elm_Xdnd_Action action)
|
|
|
|
{
|
|
|
|
if (!dragwin) return EINA_FALSE;
|
|
|
|
if (dragwidget != obj) return EINA_FALSE;
|
|
|
|
if (dragaction == action) return EINA_TRUE;
|
|
|
|
dragaction = action;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2015-03-11 11:08:42 -07:00
|
|
|
_wl_elm_drag_start(Evas_Object *obj, Elm_Sel_Format format, const char *data,
|
2013-05-21 03:30:39 -07:00
|
|
|
Elm_Xdnd_Action action,
|
|
|
|
Elm_Drag_Icon_Create_Cb createicon, void *createdata,
|
|
|
|
Elm_Drag_Pos dragpos, void *dragdata,
|
|
|
|
Elm_Drag_Accept acceptcb, void *acceptdata,
|
|
|
|
Elm_Drag_State dragdone, void *donecbdata)
|
|
|
|
{
|
2013-05-28 03:49:28 -07:00
|
|
|
Ecore_Evas *ee;
|
|
|
|
Evas_Object *icon = NULL;
|
2013-10-07 08:03:05 -07:00
|
|
|
int x, y, x2 = 0, y2 = 0, x3, y3, w = 0, h = 0;
|
2015-03-11 11:08:42 -07:00
|
|
|
const char *types[CNP_N_ATOMS + 1];
|
|
|
|
int i, nb_types = 0;
|
2015-10-01 07:25:38 -07:00
|
|
|
Ecore_Wl2_Window *parent = NULL, *win;
|
2013-05-28 03:49:28 -07:00
|
|
|
|
|
|
|
_wl_elm_dnd_init();
|
|
|
|
|
|
|
|
/* if we already have a drag, get out */
|
|
|
|
if (dragwin) return EINA_FALSE;
|
|
|
|
|
2015-06-19 04:18:18 -07:00
|
|
|
for (i = CNP_ATOM_LISTING_ATOMS + 1; i < CNP_N_ATOMS; i++)
|
2015-03-11 11:08:42 -07:00
|
|
|
{
|
2015-06-19 04:18:18 -07:00
|
|
|
if (format == ELM_SEL_FORMAT_TARGETS || (_atoms[i].formats & format))
|
2015-03-11 11:08:42 -07:00
|
|
|
{
|
|
|
|
types[nb_types++] = _atoms[i].name;
|
|
|
|
cnp_debug("set dnd type: %s\n", _atoms[i].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
types[nb_types] = NULL;
|
2015-10-01 07:25:38 -07:00
|
|
|
|
|
|
|
win = _wl_elm_widget_window_get(obj);
|
|
|
|
ecore_wl2_dnd_drag_types_set(ecore_wl2_window_input_get(win), types);
|
2013-05-28 03:49:28 -07:00
|
|
|
|
|
|
|
/* set the drag data used when a drop occurs */
|
2014-01-21 18:08:47 -08:00
|
|
|
free(wl_cnp_selection.selbuf);
|
2013-05-28 03:49:28 -07:00
|
|
|
wl_cnp_selection.selbuf = strdup((char*)data);
|
|
|
|
wl_cnp_selection.buflen = strlen(wl_cnp_selection.selbuf);
|
|
|
|
|
|
|
|
/* setup callback to notify if this object gets deleted */
|
2013-09-30 03:21:31 -07:00
|
|
|
evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
|
2013-05-28 03:49:28 -07:00
|
|
|
_wl_drag_source_del, obj);
|
|
|
|
|
|
|
|
dragwidget = obj;
|
|
|
|
dragaction = action;
|
|
|
|
dragposcb = dragpos;
|
|
|
|
dragposdata = dragdata;
|
|
|
|
dragacceptcb = acceptcb;
|
|
|
|
dragacceptdata = acceptdata;
|
|
|
|
dragdonecb = dragdone;
|
|
|
|
dragdonedata = donecbdata;
|
|
|
|
|
|
|
|
dragwin = elm_win_add(NULL, "Elm-Drag", ELM_WIN_DND);
|
|
|
|
elm_win_alpha_set(dragwin, EINA_TRUE);
|
|
|
|
elm_win_borderless_set(dragwin, EINA_TRUE);
|
|
|
|
elm_win_override_set(dragwin, EINA_TRUE);
|
|
|
|
|
2015-10-01 07:25:38 -07:00
|
|
|
win = elm_win_wl_window_get(dragwin);
|
|
|
|
|
|
|
|
ecore_wl2_window_type_set(win, ECORE_WL2_WINDOW_TYPE_DND);
|
2013-05-28 03:49:28 -07:00
|
|
|
|
|
|
|
if (createicon)
|
|
|
|
{
|
|
|
|
Evas_Coord xoff = 0, yoff = 0;
|
|
|
|
|
|
|
|
icon = createicon(createdata, dragwin, &xoff, &yoff);
|
|
|
|
if (icon)
|
|
|
|
{
|
|
|
|
x2 = xoff;
|
|
|
|
y2 = yoff;
|
|
|
|
evas_object_geometry_get(icon, NULL, NULL, &w, &h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
icon = elm_icon_add(dragwin);
|
2013-09-30 03:21:31 -07:00
|
|
|
evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND,
|
2013-05-28 03:49:28 -07:00
|
|
|
EVAS_HINT_EXPAND);
|
|
|
|
}
|
|
|
|
|
|
|
|
elm_win_resize_object_add(dragwin, icon);
|
|
|
|
evas_object_show(icon);
|
|
|
|
|
|
|
|
/* Position subwindow appropriately */
|
|
|
|
ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
|
|
|
|
ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
|
|
|
|
x += x2;
|
|
|
|
y += y2;
|
|
|
|
dragwin_x_start = dragwin_x_end = x;
|
|
|
|
dragwin_y_start = dragwin_y_end = y;
|
|
|
|
|
|
|
|
evas_object_move(dragwin, x, y);
|
|
|
|
evas_object_resize(dragwin, w, h);
|
|
|
|
evas_object_show(dragwin);
|
|
|
|
|
|
|
|
evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x3, &y3);
|
|
|
|
_dragx = x3 - x2;
|
|
|
|
_dragy = y3 - y2;
|
|
|
|
|
2015-01-05 09:05:50 -08:00
|
|
|
if (elm_widget_is(obj))
|
|
|
|
{
|
|
|
|
Evas_Object *top;
|
|
|
|
|
|
|
|
top = elm_widget_top_get(obj);
|
|
|
|
if (!top) top = elm_widget_top_get(elm_widget_parent_widget_get(obj));
|
|
|
|
if (top && (eo_isa(top, ELM_WIN_CLASS)))
|
|
|
|
parent = elm_win_wl_window_get(top);
|
|
|
|
}
|
|
|
|
if (!parent)
|
|
|
|
{
|
|
|
|
Evas *evas;
|
|
|
|
|
|
|
|
if (!(evas = evas_object_evas_get(obj)))
|
2015-01-05 09:17:03 -08:00
|
|
|
return EINA_FALSE;
|
2015-01-05 09:05:50 -08:00
|
|
|
if (!(ee = ecore_evas_ecore_evas_get(evas)))
|
2015-01-05 09:17:03 -08:00
|
|
|
return EINA_FALSE;
|
2015-01-05 09:05:50 -08:00
|
|
|
|
2016-01-07 11:56:30 -08:00
|
|
|
parent = ecore_evas_wayland2_window_get(ee);
|
2015-01-05 09:05:50 -08:00
|
|
|
}
|
|
|
|
|
2015-10-01 07:25:38 -07:00
|
|
|
ecore_wl2_dnd_drag_start(ecore_wl2_window_input_get(win), parent, win);
|
2013-05-28 03:49:28 -07:00
|
|
|
|
2013-05-21 03:30:39 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
2013-05-28 03:49:28 -07:00
|
|
|
|
2013-09-30 03:21:31 -07:00
|
|
|
static void
|
2013-05-28 03:49:28 -07:00
|
|
|
_wl_drag_source_del(void *data EINA_UNUSED, Evas *evas EINA_UNUSED, Evas_Object *obj, void *event EINA_UNUSED)
|
|
|
|
{
|
|
|
|
if (dragwidget == obj)
|
|
|
|
dragwidget = NULL;
|
|
|
|
}
|
|
|
|
|
2013-09-30 03:21:31 -07:00
|
|
|
static Eina_Bool
|
2013-05-28 03:49:28 -07:00
|
|
|
_wl_dnd_enter(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
|
|
|
|
{
|
2015-10-01 07:25:38 -07:00
|
|
|
Ecore_Wl2_Event_Dnd_Enter *ev;
|
2013-05-28 03:49:28 -07:00
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
ev = event;
|
|
|
|
|
|
|
|
if ((!ev->num_types) || (!ev->types)) return ECORE_CALLBACK_PASS_ON;
|
|
|
|
|
|
|
|
savedtypes.ntypes = ev->num_types;
|
2014-01-21 18:08:47 -08:00
|
|
|
free(savedtypes.types);
|
2013-05-28 03:49:28 -07:00
|
|
|
savedtypes.types = malloc(sizeof(char *) * ev->num_types);
|
|
|
|
if (!savedtypes.types) return EINA_FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < ev->num_types; i++)
|
|
|
|
{
|
|
|
|
savedtypes.types[i] = eina_stringshare_add(ev->types[i]);
|
|
|
|
if (savedtypes.types[i] == text_uri)
|
|
|
|
{
|
|
|
|
savedtypes.textreq = 1;
|
2014-01-21 18:08:47 -08:00
|
|
|
ELM_SAFE_FREE(savedtypes.imgfile, free);
|
2013-05-28 03:49:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
doaccept = EINA_FALSE;
|
|
|
|
for (i = 0; i < ev->num_types; i++)
|
|
|
|
{
|
2016-04-21 10:56:41 -07:00
|
|
|
doaccept |= _wl_drops_accept(ev->types[i]);
|
2013-05-28 03:49:28 -07:00
|
|
|
if (doaccept)
|
|
|
|
wl_data_offer_accept(ev->offer, ev->serial, ev->types[i]);
|
|
|
|
}
|
2016-04-21 10:56:41 -07:00
|
|
|
if (!doaccept)
|
|
|
|
wl_data_offer_accept(ev->offer, ev->serial, NULL);
|
2013-05-28 03:49:28 -07:00
|
|
|
|
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
|
|
|
}
|
|
|
|
|
2013-09-30 03:21:31 -07:00
|
|
|
static Eina_Bool
|
2013-05-28 03:49:28 -07:00
|
|
|
_wl_dnd_leave(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
|
|
|
|
{
|
2015-10-01 07:25:38 -07:00
|
|
|
Ecore_Wl2_Event_Dnd_Leave *ev;
|
2013-05-28 03:49:28 -07:00
|
|
|
Dropable *drop;
|
2015-03-10 11:30:00 -07:00
|
|
|
cnp_debug("In\n");
|
2013-05-28 03:49:28 -07:00
|
|
|
|
|
|
|
ev = event;
|
|
|
|
if ((drop = _wl_dropable_find(ev->win)))
|
|
|
|
{
|
2015-02-25 00:36:26 -08:00
|
|
|
_wl_dropable_handle(NULL, 0, 0);
|
|
|
|
_wl_dropable_all_clean(ev->win);
|
2013-05-28 03:49:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
|
|
|
}
|
|
|
|
|
2013-09-30 03:21:31 -07:00
|
|
|
static Eina_Bool
|
2013-05-28 03:49:28 -07:00
|
|
|
_wl_dnd_position(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
|
|
|
|
{
|
2015-10-01 07:25:38 -07:00
|
|
|
Ecore_Wl2_Event_Dnd_Motion *ev;
|
2015-02-25 00:36:26 -08:00
|
|
|
Dropable *drop;
|
2013-05-28 03:49:28 -07:00
|
|
|
Eina_Bool will_accept = EINA_FALSE;
|
|
|
|
|
|
|
|
ev = event;
|
|
|
|
|
2015-10-01 07:25:38 -07:00
|
|
|
cnp_debug("mouse pos %i %i\n", ev->x, ev->y);
|
2015-02-25 00:36:18 -08:00
|
|
|
|
2015-10-01 07:25:38 -07:00
|
|
|
dragwin_x_end = ev->x - _dragx;
|
|
|
|
dragwin_y_end = ev->y - _dragy;
|
2013-05-28 03:49:28 -07:00
|
|
|
|
2015-02-25 00:36:26 -08:00
|
|
|
drop = _wl_dropable_find(ev->win);
|
2013-05-28 03:49:28 -07:00
|
|
|
|
|
|
|
if (drop)
|
|
|
|
{
|
|
|
|
Evas_Coord x = 0, y = 0;
|
|
|
|
|
2015-10-01 07:25:38 -07:00
|
|
|
x = ev->x;
|
|
|
|
y = ev->y;
|
2015-02-25 00:36:18 -08:00
|
|
|
_dropable_coords_adjust(drop, &x, &y);
|
|
|
|
Evas *evas = _wl_evas_get_from_win(ev->win);
|
2013-05-28 03:49:28 -07:00
|
|
|
|
2015-02-25 00:36:18 -08:00
|
|
|
Eina_List *dropable_list = evas ? _dropable_list_geom_find(evas, x, y) : NULL;
|
2013-05-28 03:49:28 -07:00
|
|
|
|
2015-02-25 00:36:18 -08:00
|
|
|
/* check if there is dropable (obj) can accept this drop */
|
|
|
|
if (dropable_list)
|
|
|
|
{
|
2015-03-10 10:05:42 -07:00
|
|
|
Elm_Sel_Format saved_format = _dnd_types_to_format(savedtypes.types, savedtypes.ntypes);
|
2015-02-25 00:36:18 -08:00
|
|
|
Eina_List *l;
|
|
|
|
Eina_Bool found = EINA_FALSE;
|
|
|
|
Dropable *dropable = NULL;
|
2013-05-28 03:49:28 -07:00
|
|
|
|
2015-02-25 00:36:18 -08:00
|
|
|
EINA_LIST_FOREACH(dropable_list, l, dropable)
|
2013-05-28 03:49:28 -07:00
|
|
|
{
|
2013-11-05 07:26:51 -08:00
|
|
|
Dropable_Cbs *cbs;
|
2015-03-10 10:05:42 -07:00
|
|
|
Eina_Inlist *itr;
|
2015-02-25 00:36:18 -08:00
|
|
|
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
|
2013-05-28 03:49:28 -07:00
|
|
|
{
|
2015-03-10 10:05:42 -07:00
|
|
|
Elm_Sel_Format common_fmt = saved_format & cbs->types;
|
|
|
|
if (common_fmt)
|
2013-05-28 03:49:28 -07:00
|
|
|
{
|
2015-03-10 10:05:42 -07:00
|
|
|
/* We found a target that can accept this type of data */
|
|
|
|
int i, min_index = CNP_N_ATOMS;
|
|
|
|
/* We have to find the first atom that corresponds to one
|
|
|
|
* of the supported data types. */
|
2015-02-25 00:36:18 -08:00
|
|
|
for (i = 0; i < savedtypes.ntypes; i++)
|
|
|
|
{
|
2015-03-10 10:05:42 -07:00
|
|
|
Cnp_Atom *atom = eina_hash_find(_types_hash, savedtypes.types[i]);
|
|
|
|
if (atom && (atom->formats & common_fmt))
|
2015-02-25 00:36:18 -08:00
|
|
|
{
|
2015-03-10 10:05:42 -07:00
|
|
|
int atom_idx = (atom - _atoms);
|
|
|
|
if (min_index > atom_idx) min_index = atom_idx;
|
2015-02-25 00:36:18 -08:00
|
|
|
}
|
|
|
|
}
|
2015-03-10 10:05:42 -07:00
|
|
|
if (min_index != CNP_N_ATOMS)
|
|
|
|
{
|
|
|
|
cnp_debug("Found atom %s\n", _atoms[min_index].name);
|
|
|
|
found = EINA_TRUE;
|
|
|
|
dropable->last.type = _atoms[min_index].name;
|
|
|
|
dropable->last.format = common_fmt;
|
|
|
|
break;
|
|
|
|
}
|
2013-05-28 03:49:28 -07:00
|
|
|
}
|
|
|
|
}
|
2015-02-25 00:36:18 -08:00
|
|
|
if (found) break;
|
|
|
|
}
|
|
|
|
if (found)
|
|
|
|
{
|
|
|
|
Evas_Coord ox = 0, oy = 0;
|
|
|
|
|
|
|
|
evas_object_geometry_get(dropable->obj, &ox, &oy, NULL, NULL);
|
|
|
|
|
2015-03-10 11:30:00 -07:00
|
|
|
cnp_debug("Candidate %p (%s)\n",
|
|
|
|
dropable->obj, eo_class_name_get(eo_class_get(dropable->obj)));
|
2015-02-25 00:36:26 -08:00
|
|
|
_wl_dropable_handle(dropable, x - ox, y - oy);
|
2015-03-10 10:05:42 -07:00
|
|
|
wl_cnp_selection.requestwidget = dropable->obj;
|
|
|
|
will_accept = EINA_TRUE;
|
2015-02-25 00:36:18 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//if not: send false status
|
|
|
|
cnp_debug("dnd position (%d, %d) not in obj\n", x, y);
|
2015-02-25 00:36:26 -08:00
|
|
|
_wl_dropable_handle(NULL, 0, 0);
|
2015-02-25 00:36:18 -08:00
|
|
|
// CCCCCCC: call dnd exit on last obj
|
2013-05-28 03:49:28 -07:00
|
|
|
}
|
2015-06-14 01:14:02 -07:00
|
|
|
eina_list_free(dropable_list);
|
2013-05-28 03:49:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
doaccept = will_accept;
|
|
|
|
|
|
|
|
if (dragacceptcb)
|
|
|
|
dragacceptcb(dragacceptdata, wl_cnp_selection.requestwidget, will_accept);
|
|
|
|
|
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
|
|
|
}
|
|
|
|
|
2013-09-30 03:21:31 -07:00
|
|
|
static Eina_Bool
|
2013-05-28 03:49:28 -07:00
|
|
|
_wl_dnd_drop(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
|
|
|
|
{
|
2015-10-01 07:25:38 -07:00
|
|
|
Ecore_Wl2_Event_Dnd_Drop *ev;
|
|
|
|
Ecore_Wl2_Window *win;
|
2013-05-28 03:49:28 -07:00
|
|
|
Dropable *drop;
|
2015-03-10 11:30:00 -07:00
|
|
|
Eina_List *l;
|
2013-05-28 03:49:28 -07:00
|
|
|
|
2015-03-10 10:05:42 -07:00
|
|
|
cnp_debug("In\n");
|
2013-05-28 03:49:28 -07:00
|
|
|
ev = event;
|
2015-10-01 07:25:38 -07:00
|
|
|
savedtypes.x = ev->x;
|
|
|
|
savedtypes.y = ev->y;
|
2015-02-25 00:36:18 -08:00
|
|
|
|
2015-03-10 11:30:00 -07:00
|
|
|
EINA_LIST_FOREACH(drops, l, drop)
|
2015-02-25 00:36:18 -08:00
|
|
|
{
|
2015-03-10 11:30:00 -07:00
|
|
|
if (drop->last.in)
|
2015-02-25 00:36:18 -08:00
|
|
|
{
|
2015-03-10 11:30:00 -07:00
|
|
|
cnp_debug("Request data of type %s\n", drop->last.type);
|
|
|
|
wl_cnp_selection.requestwidget = drop->obj;
|
2016-05-03 02:30:39 -07:00
|
|
|
wl_cnp_selection.requestformat = drop->last.format;
|
2015-03-10 11:30:00 -07:00
|
|
|
evas_object_event_callback_add(wl_cnp_selection.requestwidget,
|
|
|
|
EVAS_CALLBACK_DEL,
|
|
|
|
_wl_sel_obj_del2,
|
|
|
|
&wl_cnp_selection);
|
2015-10-01 07:25:38 -07:00
|
|
|
|
|
|
|
win = _wl_elm_widget_window_get(drop->obj);
|
|
|
|
ecore_wl2_dnd_drag_get(ecore_wl2_window_input_get(win),
|
|
|
|
drop->last.type);
|
2015-03-10 11:30:00 -07:00
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
2013-05-28 03:49:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 07:25:38 -07:00
|
|
|
win = ecore_wl2_display_window_find(_elm_wl_display, ev->win);
|
|
|
|
ecore_wl2_dnd_drag_end(ecore_wl2_window_input_get(win));
|
2013-05-28 03:49:28 -07:00
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
|
|
|
}
|
|
|
|
|
2013-09-30 03:21:31 -07:00
|
|
|
static Eina_Bool
|
2015-10-09 08:40:10 -07:00
|
|
|
_wl_dnd_end(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
|
2013-05-28 03:49:28 -07:00
|
|
|
{
|
2015-10-01 07:25:38 -07:00
|
|
|
Ecore_Wl2_Event_Dnd_End *ev;
|
|
|
|
Ecore_Wl2_Window *win;
|
|
|
|
|
2015-03-10 10:05:42 -07:00
|
|
|
cnp_debug("In\n");
|
2013-05-28 03:49:28 -07:00
|
|
|
|
2015-10-01 07:25:38 -07:00
|
|
|
ev = event;
|
2013-05-28 03:49:28 -07:00
|
|
|
|
|
|
|
if (dragdonecb) dragdonecb(dragdonedata, dragwidget);
|
|
|
|
|
|
|
|
if (dragwin)
|
|
|
|
{
|
|
|
|
if (!doaccept)
|
|
|
|
{
|
|
|
|
/* Commit animation when drag cancelled */
|
|
|
|
/* Record final position of dragwin, then do animation */
|
|
|
|
ecore_animator_timeline_add(0.3, _drag_cancel_animate, dragwin);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No animation drop was committed */
|
|
|
|
evas_object_del(dragwin);
|
|
|
|
}
|
|
|
|
|
|
|
|
dragwin = NULL; /* if not freed here, free in end of anim */
|
|
|
|
}
|
|
|
|
|
|
|
|
dragdonecb = NULL;
|
|
|
|
dragacceptcb = NULL;
|
|
|
|
dragposcb = NULL;
|
|
|
|
dragwidget = NULL;
|
|
|
|
doaccept = EINA_FALSE;
|
|
|
|
|
2015-10-01 07:25:38 -07:00
|
|
|
win = ecore_wl2_display_window_find(_elm_wl_display, ev->win);
|
|
|
|
ecore_wl2_input_ungrab(ecore_wl2_window_input_get(win));
|
2013-05-28 03:49:28 -07:00
|
|
|
|
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
|
|
|
}
|
|
|
|
|
2013-09-30 03:21:31 -07:00
|
|
|
static void
|
2016-05-03 02:30:39 -07:00
|
|
|
_wl_dropable_data_handle(Wl_Cnp_Selection *sel, Ecore_Wl2_Event_Selection_Data_Ready *ev)
|
2013-05-28 03:49:28 -07:00
|
|
|
{
|
|
|
|
Dropable *drop;
|
2015-10-01 07:25:38 -07:00
|
|
|
Ecore_Wl2_Window *win;
|
2013-05-28 03:49:28 -07:00
|
|
|
|
2015-10-01 07:25:38 -07:00
|
|
|
cnp_debug("In\n");
|
2016-03-02 04:10:48 -08:00
|
|
|
drop = eo_key_data_get(sel->requestwidget, "__elm_dropable");
|
2015-03-11 11:08:42 -07:00
|
|
|
if (drop)
|
2013-05-28 03:49:28 -07:00
|
|
|
{
|
2016-05-03 02:30:39 -07:00
|
|
|
Cnp_Atom *atom = eina_hash_find(_types_hash, drop->last.type);
|
|
|
|
if (atom && atom->wl_data_preparer)
|
2013-11-05 07:26:51 -08:00
|
|
|
{
|
2016-05-03 02:30:39 -07:00
|
|
|
Elm_Selection_Data ddata;
|
|
|
|
Tmp_Info *tmp_info = NULL;
|
|
|
|
Eina_Bool success;
|
|
|
|
ddata.data = NULL;
|
|
|
|
|
|
|
|
cnp_debug("Call notify for: %s\n", atom->name);
|
|
|
|
success = atom->wl_data_preparer(sel, &ddata, ev, &tmp_info);
|
|
|
|
if (success)
|
2015-02-25 00:36:18 -08:00
|
|
|
{
|
2016-05-03 02:30:39 -07:00
|
|
|
Dropable *dropable;
|
|
|
|
Eina_List *l;
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH(drops, l, dropable)
|
2015-08-13 12:27:14 -07:00
|
|
|
{
|
2016-05-03 02:30:39 -07:00
|
|
|
if (dropable->obj == sel->requestwidget) break;
|
|
|
|
dropable = NULL;
|
2015-08-13 12:27:14 -07:00
|
|
|
}
|
2016-05-03 02:30:39 -07:00
|
|
|
if (dropable)
|
2015-03-11 11:08:42 -07:00
|
|
|
{
|
2016-05-03 02:30:39 -07:00
|
|
|
cnp_debug("call dropcb\n");
|
|
|
|
Dropable_Cbs *cbs;
|
|
|
|
Eina_Inlist *itr;
|
|
|
|
ddata.x = savedtypes.x;
|
|
|
|
ddata.y = savedtypes.y;
|
|
|
|
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
|
|
|
|
if ((cbs->types & dropable->last.format) &&
|
|
|
|
cbs->dropcb)
|
|
|
|
cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
|
2015-03-11 11:08:42 -07:00
|
|
|
}
|
2015-02-25 00:36:18 -08:00
|
|
|
}
|
2016-05-03 02:30:39 -07:00
|
|
|
win = _wl_elm_widget_window_get(sel->requestwidget);
|
|
|
|
ecore_wl2_dnd_drag_end(ecore_wl2_window_input_get(win));
|
|
|
|
if (tmp_info) _tmpinfo_free(tmp_info);
|
|
|
|
free(ddata.data);
|
|
|
|
return;
|
2013-11-05 07:26:51 -08:00
|
|
|
}
|
2013-05-28 03:49:28 -07:00
|
|
|
}
|
2015-10-01 07:25:38 -07:00
|
|
|
|
2016-05-03 02:30:39 -07:00
|
|
|
win = _wl_elm_widget_window_get(sel->requestwidget);
|
2015-10-01 07:25:38 -07:00
|
|
|
ecore_wl2_dnd_drag_end(ecore_wl2_window_input_get(win));
|
2015-08-13 12:45:19 -07:00
|
|
|
savedtypes.textreq = 0;
|
2013-05-28 03:49:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static Dropable *
|
|
|
|
_wl_dropable_find(unsigned int win)
|
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
Dropable *dropable;
|
2015-10-01 07:25:38 -07:00
|
|
|
Ecore_Wl2_Window *window;
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2013-05-28 03:49:28 -07:00
|
|
|
if (!drops) return NULL;
|
2015-10-01 07:25:38 -07:00
|
|
|
|
|
|
|
window = ecore_wl2_display_window_find(_elm_wl_display, win);
|
|
|
|
if (!window) return NULL;
|
|
|
|
|
2013-05-28 03:49:28 -07:00
|
|
|
EINA_LIST_FOREACH(drops, l, dropable)
|
2015-10-01 07:25:38 -07:00
|
|
|
if (_wl_elm_widget_window_get(dropable->obj) == window)
|
2013-05-28 03:49:28 -07:00
|
|
|
return dropable;
|
2015-10-01 07:25:38 -07:00
|
|
|
|
2013-05-28 03:49:28 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-02-25 00:36:18 -08:00
|
|
|
static Evas *
|
|
|
|
_wl_evas_get_from_win(unsigned int win)
|
|
|
|
{
|
|
|
|
Dropable *dropable = _wl_dropable_find(win);
|
|
|
|
return dropable ? evas_object_evas_get(dropable->obj) : NULL;
|
|
|
|
}
|
|
|
|
|
2015-02-25 00:36:26 -08:00
|
|
|
static void
|
|
|
|
_wl_dropable_handle(Dropable *drop, Evas_Coord x, Evas_Coord y)
|
2013-05-28 03:49:28 -07:00
|
|
|
{
|
2015-02-25 00:36:26 -08:00
|
|
|
Dropable *d, *last_dropable = NULL;
|
|
|
|
Dropable_Cbs *cbs;
|
|
|
|
Eina_Inlist *itr;
|
2013-05-28 03:49:28 -07:00
|
|
|
Eina_List *l;
|
|
|
|
|
2015-02-25 00:36:26 -08:00
|
|
|
EINA_LIST_FOREACH(drops, l, d)
|
2013-05-28 03:49:28 -07:00
|
|
|
{
|
2015-02-25 00:36:26 -08:00
|
|
|
if (d->last.in)
|
2013-05-28 03:49:28 -07:00
|
|
|
{
|
2015-02-25 00:36:26 -08:00
|
|
|
last_dropable = d;
|
|
|
|
break;
|
2013-05-28 03:49:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-25 00:36:26 -08:00
|
|
|
/* If we are on the same object, just update the position */
|
|
|
|
if ((drop) && (last_dropable == drop))
|
2013-05-28 03:49:28 -07:00
|
|
|
{
|
2013-11-18 03:34:07 -08:00
|
|
|
EINA_INLIST_FOREACH_SAFE(drop->cbs_list, itr, cbs)
|
2013-11-05 07:26:51 -08:00
|
|
|
if (cbs->poscb)
|
|
|
|
cbs->poscb(cbs->posdata, drop->obj, x, y, dragaction);
|
2015-02-25 00:36:26 -08:00
|
|
|
return;
|
2013-05-28 03:49:28 -07:00
|
|
|
}
|
2015-02-25 00:36:26 -08:00
|
|
|
/* We leave the last dropable */
|
|
|
|
if (last_dropable)
|
2013-05-28 03:49:28 -07:00
|
|
|
{
|
2015-02-25 00:36:26 -08:00
|
|
|
EINA_INLIST_FOREACH_SAFE(last_dropable->cbs_list, itr, cbs)
|
2013-11-05 07:26:51 -08:00
|
|
|
if (cbs->leavecb)
|
2015-02-25 00:36:26 -08:00
|
|
|
cbs->leavecb(cbs->leavedata, last_dropable->obj);
|
|
|
|
last_dropable->last.in = EINA_FALSE;
|
2013-05-28 03:49:28 -07:00
|
|
|
}
|
2015-02-25 00:36:26 -08:00
|
|
|
/* We enter the new dropable */
|
|
|
|
if (drop)
|
2013-05-28 03:49:28 -07:00
|
|
|
{
|
2013-11-18 03:34:07 -08:00
|
|
|
EINA_INLIST_FOREACH_SAFE(drop->cbs_list, itr, cbs)
|
2013-11-05 07:26:51 -08:00
|
|
|
if (cbs->entercb)
|
|
|
|
cbs->entercb(cbs->enterdata, drop->obj);
|
2015-02-25 00:36:26 -08:00
|
|
|
EINA_INLIST_FOREACH_SAFE(drop->cbs_list, itr, cbs)
|
|
|
|
if (cbs->poscb)
|
|
|
|
cbs->poscb(cbs->posdata, drop->obj, x, y, dragaction);
|
|
|
|
drop->last.in = EINA_TRUE;
|
2013-05-28 03:49:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-30 03:21:31 -07:00
|
|
|
static void
|
2015-02-25 00:36:26 -08:00
|
|
|
_wl_dropable_all_clean(unsigned int win)
|
2013-05-28 03:49:28 -07:00
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
Dropable *dropable;
|
2015-10-01 07:25:38 -07:00
|
|
|
Ecore_Wl2_Window *window;
|
|
|
|
|
|
|
|
window = ecore_wl2_display_window_find(_elm_wl_display, win);
|
|
|
|
if (!window) return;
|
2013-05-28 03:49:28 -07:00
|
|
|
|
|
|
|
EINA_LIST_FOREACH(drops, l, dropable)
|
|
|
|
{
|
2015-10-01 07:25:38 -07:00
|
|
|
if (_wl_elm_widget_window_get(dropable->obj) == window)
|
2013-05-28 03:49:28 -07:00
|
|
|
{
|
2015-02-25 00:36:26 -08:00
|
|
|
dropable->last.x = 0;
|
|
|
|
dropable->last.y = 0;
|
|
|
|
dropable->last.in = EINA_FALSE;
|
2013-05-28 03:49:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-30 03:21:31 -07:00
|
|
|
static Eina_Bool
|
2013-05-28 03:49:28 -07:00
|
|
|
_wl_drops_accept(const char *type)
|
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
Dropable *drop;
|
|
|
|
Eina_Bool will_accept = EINA_FALSE;
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH(drops, l, drop)
|
|
|
|
{
|
2013-11-05 07:26:51 -08:00
|
|
|
Dropable_Cbs *cbs;
|
|
|
|
EINA_INLIST_FOREACH(drop->cbs_list, cbs)
|
2013-05-28 03:49:28 -07:00
|
|
|
{
|
2013-11-05 07:26:51 -08:00
|
|
|
switch (cbs->types)
|
2013-05-28 03:49:28 -07:00
|
|
|
{
|
2013-11-05 07:26:51 -08:00
|
|
|
case ELM_SEL_FORMAT_TARGETS:
|
|
|
|
case ELM_SEL_FORMAT_IMAGE:
|
2015-06-23 05:58:45 -07:00
|
|
|
if (!strncmp(type, "image/", 6))
|
2013-11-05 07:26:51 -08:00
|
|
|
{
|
|
|
|
wl_cnp_selection.requestwidget = drop->obj;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ELM_SEL_FORMAT_NONE:
|
|
|
|
break;
|
|
|
|
case ELM_SEL_FORMAT_MARKUP:
|
2016-04-21 10:57:37 -07:00
|
|
|
case ELM_SEL_FORMAT_TEXT:
|
|
|
|
if (eina_streq(type, "application/x-elementary-markup") ||
|
|
|
|
eina_streq(type, "text/plain") ||
|
|
|
|
eina_streq(type, "text/plain;charset=utf-8") ||
|
|
|
|
eina_streq(type, "UTF8_STRING") ||
|
|
|
|
eina_streq(type, "STRING") ||
|
|
|
|
eina_streq(type, "TEXT"))
|
|
|
|
return EINA_TRUE;
|
|
|
|
break;
|
2013-11-05 07:26:51 -08:00
|
|
|
case ELM_SEL_FORMAT_VCARD:
|
|
|
|
break;
|
|
|
|
case ELM_SEL_FORMAT_HTML:
|
2016-04-21 10:57:37 -07:00
|
|
|
if (eina_streq(type, "text/html") ||
|
|
|
|
eina_streq(type, "text/html;charset=utf-8"))
|
|
|
|
return EINA_TRUE;
|
|
|
|
break;
|
2013-05-28 03:49:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return will_accept;
|
|
|
|
}
|
|
|
|
|
2015-10-01 07:25:38 -07:00
|
|
|
static Ecore_Wl2_Window *
|
2015-06-26 07:44:40 -07:00
|
|
|
_wl_elm_widget_window_get(const Evas_Object *obj)
|
2013-05-28 03:49:28 -07:00
|
|
|
{
|
|
|
|
Evas_Object *top;
|
2015-10-01 07:25:38 -07:00
|
|
|
Ecore_Wl2_Window *win = NULL;
|
2013-05-28 03:49:28 -07:00
|
|
|
|
2014-03-28 02:22:49 -07:00
|
|
|
if (elm_widget_is(obj))
|
|
|
|
{
|
|
|
|
top = elm_widget_top_get(obj);
|
|
|
|
if (!top) top = elm_widget_top_get(elm_widget_parent_widget_get(obj));
|
2014-06-03 03:35:28 -07:00
|
|
|
if (top && (eo_isa(top, ELM_WIN_CLASS)))
|
2014-04-01 03:54:09 -07:00
|
|
|
win = elm_win_wl_window_get(top);
|
2014-03-28 02:22:49 -07:00
|
|
|
}
|
2013-05-28 03:49:28 -07:00
|
|
|
if (!win)
|
|
|
|
{
|
|
|
|
Ecore_Evas *ee;
|
|
|
|
Evas *evas;
|
2015-03-05 08:31:30 -08:00
|
|
|
const char *engine_name;
|
2013-05-28 03:49:28 -07:00
|
|
|
|
|
|
|
if (!(evas = evas_object_evas_get(obj)))
|
2015-10-01 07:25:38 -07:00
|
|
|
return NULL;
|
2013-05-28 03:49:28 -07:00
|
|
|
if (!(ee = ecore_evas_ecore_evas_get(evas)))
|
2015-10-01 07:25:38 -07:00
|
|
|
return NULL;
|
2013-05-28 03:49:28 -07:00
|
|
|
|
2015-03-05 08:31:30 -08:00
|
|
|
engine_name = ecore_evas_engine_name_get(ee);
|
|
|
|
if (!strcmp(engine_name, ELM_BUFFER))
|
2015-01-08 01:54:04 -08:00
|
|
|
{
|
2015-03-05 08:31:30 -08:00
|
|
|
ee = ecore_evas_buffer_ecore_evas_parent_get(ee);
|
2015-10-01 07:25:38 -07:00
|
|
|
if (!ee) return NULL;
|
2016-01-07 11:56:30 -08:00
|
|
|
win = ecore_evas_wayland2_window_get(ee);
|
2015-03-05 08:31:30 -08:00
|
|
|
}
|
|
|
|
else if (!strncmp(engine_name, "wayland", sizeof("wayland") - 1))
|
|
|
|
{
|
|
|
|
/* In case the engine is not a buffer, we want to check once. */
|
2016-01-07 11:56:30 -08:00
|
|
|
win = ecore_evas_wayland2_window_get(ee);
|
2015-10-01 07:25:38 -07:00
|
|
|
if (!win) return NULL;
|
2015-01-08 01:54:04 -08:00
|
|
|
}
|
2013-05-28 03:49:28 -07:00
|
|
|
}
|
|
|
|
|
2015-10-01 07:25:38 -07:00
|
|
|
return win;
|
2013-05-28 03:49:28 -07:00
|
|
|
}
|
|
|
|
|
2015-10-09 08:18:20 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_ELEMENTARY_COCOA
|
|
|
|
|
|
|
|
typedef struct _Cocoa_Cnp_Selection Cocoa_Cnp_Selection;
|
|
|
|
|
|
|
|
struct _Cocoa_Cnp_Selection
|
|
|
|
{
|
|
|
|
Ecore_Cocoa_Window *win;
|
|
|
|
Evas_Object *widget;
|
|
|
|
char *selbuf;
|
|
|
|
int buflen;
|
|
|
|
Evas_Object *requestwidget;
|
|
|
|
void *udata;
|
|
|
|
Elm_Sel_Format requestformat;
|
|
|
|
Elm_Drop_Cb datacb;
|
|
|
|
|
|
|
|
Elm_Selection_Loss_Cb loss_cb;
|
|
|
|
void *loss_data;
|
|
|
|
int pb_count;
|
|
|
|
|
|
|
|
Elm_Sel_Format format;
|
|
|
|
|
|
|
|
Eina_Bool active : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
static Cocoa_Cnp_Selection _cocoa_cnp_sel;
|
|
|
|
|
|
|
|
static Ecore_Cocoa_Window *
|
|
|
|
_cocoa_elm_widget_cocoa_window_get(const Evas_Object *obj)
|
|
|
|
{
|
|
|
|
Evas_Object *top, *par;
|
|
|
|
Ecore_Cocoa_Window *win = NULL;
|
|
|
|
|
|
|
|
if (elm_widget_is(obj))
|
|
|
|
{
|
|
|
|
top = elm_widget_top_get(obj);
|
|
|
|
if (!top)
|
|
|
|
{
|
|
|
|
par = elm_widget_parent_widget_get(obj);
|
|
|
|
if (par) top = elm_widget_top_get(par);
|
|
|
|
}
|
|
|
|
if ((top) && (eo_isa(top, ELM_WIN_CLASS)))
|
|
|
|
win = elm_win_cocoa_window_get(top);
|
|
|
|
}
|
|
|
|
if (!win)
|
|
|
|
{
|
|
|
|
// FIXME
|
|
|
|
CRI("WIN has not been retrieved!!!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return win;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Ecore_Cocoa_Cnp_Type
|
|
|
|
_elm_sel_format_to_ecore_cocoa_cnp_type(Elm_Sel_Format fmt)
|
|
|
|
{
|
|
|
|
Ecore_Cocoa_Cnp_Type type = 0;
|
|
|
|
|
|
|
|
if ((fmt & ELM_SEL_FORMAT_TEXT) ||
|
|
|
|
(fmt & ELM_SEL_FORMAT_VCARD))
|
|
|
|
type |= ECORE_COCOA_CNP_TYPE_STRING;
|
|
|
|
if (fmt & ELM_SEL_FORMAT_MARKUP)
|
|
|
|
type |= ECORE_COCOA_CNP_TYPE_MARKUP;
|
|
|
|
if (fmt & ELM_SEL_FORMAT_HTML)
|
|
|
|
type |= ECORE_COCOA_CNP_TYPE_HTML;
|
|
|
|
if (fmt & ELM_SEL_FORMAT_IMAGE)
|
|
|
|
type |= ECORE_COCOA_CNP_TYPE_IMAGE;
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cocoa_sel_obj_del_req_cb(void *data,
|
|
|
|
Evas *e EINA_UNUSED,
|
|
|
|
Evas_Object *obj,
|
|
|
|
void *ev_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Cocoa_Cnp_Selection *sel = data;
|
|
|
|
if (sel->requestwidget == obj) sel->requestwidget = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cocoa_sel_obj_del_cb(void *data,
|
|
|
|
Evas *e EINA_UNUSED,
|
|
|
|
Evas_Object *obj,
|
|
|
|
void *ev_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Cocoa_Cnp_Selection *sel = data;
|
|
|
|
if (sel->widget == obj)
|
|
|
|
{
|
|
|
|
sel->widget = NULL;
|
|
|
|
sel->loss_cb = NULL;
|
|
|
|
sel->loss_data = NULL;
|
|
|
|
}
|
|
|
|
if (dragwidget == obj) dragwidget = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_job_pb_cb(void *data)
|
|
|
|
{
|
|
|
|
Cocoa_Cnp_Selection *sel = data;
|
|
|
|
Elm_Selection_Data ddata;
|
|
|
|
Ecore_Cocoa_Cnp_Type type, get_type;
|
|
|
|
void *pbdata;
|
|
|
|
int pbdata_len;
|
|
|
|
|
|
|
|
if (sel->datacb)
|
|
|
|
{
|
|
|
|
ddata.x = 0;
|
|
|
|
ddata.y = 0;
|
|
|
|
|
|
|
|
/* Pass to cocoa clipboard */
|
|
|
|
type = _elm_sel_format_to_ecore_cocoa_cnp_type(sel->requestformat);
|
|
|
|
pbdata = ecore_cocoa_selection_clipboard_get(&pbdata_len, type, &get_type);
|
|
|
|
|
|
|
|
ddata.format = ELM_SEL_FORMAT_NONE;
|
|
|
|
if (get_type & ECORE_COCOA_CNP_TYPE_STRING)
|
|
|
|
ddata.format |= ELM_SEL_FORMAT_TEXT;
|
|
|
|
if (get_type & ECORE_COCOA_CNP_TYPE_MARKUP)
|
|
|
|
ddata.format |= ELM_SEL_FORMAT_MARKUP;
|
|
|
|
if (get_type & ECORE_COCOA_CNP_TYPE_IMAGE)
|
|
|
|
ddata.format |= ELM_SEL_FORMAT_IMAGE;
|
|
|
|
if (get_type & ECORE_COCOA_CNP_TYPE_HTML)
|
|
|
|
ddata.format |= ELM_SEL_FORMAT_HTML;
|
|
|
|
|
|
|
|
ddata.data = pbdata;
|
|
|
|
ddata.len = pbdata_len;
|
|
|
|
ddata.action = ELM_XDND_ACTION_UNKNOWN;
|
|
|
|
sel->datacb(sel->udata, sel->requestwidget, &ddata);
|
|
|
|
free(pbdata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_cocoa_elm_cnp_selection_set(Ecore_Cocoa_Window *win,
|
|
|
|
Evas_Object *obj,
|
|
|
|
Elm_Sel_Type selection,
|
|
|
|
Elm_Sel_Format format,
|
|
|
|
const void *selbuf,
|
|
|
|
size_t buflen)
|
|
|
|
{
|
|
|
|
Cocoa_Cnp_Selection *sel = &_cocoa_cnp_sel;
|
|
|
|
Ecore_Cocoa_Cnp_Type type;
|
|
|
|
Eina_Bool ok = EINA_TRUE;
|
|
|
|
|
|
|
|
if ((!selbuf) && (format != ELM_SEL_FORMAT_IMAGE))
|
|
|
|
return elm_object_cnp_selection_clear(obj, selection);
|
|
|
|
if (buflen <= 0) return EINA_FALSE;
|
|
|
|
|
|
|
|
if (sel->loss_cb) sel->loss_cb(sel->loss_data, selection);
|
|
|
|
if (sel->widget)
|
|
|
|
evas_object_event_callback_del_full(sel->widget, EVAS_CALLBACK_DEL,
|
|
|
|
_cocoa_sel_obj_del_cb, sel);
|
|
|
|
|
|
|
|
sel->widget = obj;
|
|
|
|
sel->win = win;
|
|
|
|
sel->format = format;
|
|
|
|
sel->loss_cb = NULL;
|
|
|
|
sel->loss_data = NULL;
|
|
|
|
|
|
|
|
evas_object_event_callback_add(sel->widget, EVAS_CALLBACK_DEL,
|
|
|
|
_cocoa_sel_obj_del_cb, sel);
|
|
|
|
ELM_SAFE_FREE(sel->selbuf, free);
|
|
|
|
sel->buflen = 0;
|
|
|
|
if (selbuf)
|
|
|
|
{
|
|
|
|
sel->selbuf = malloc(buflen + 1);
|
|
|
|
if (EINA_UNLIKELY(!sel->selbuf))
|
|
|
|
{
|
|
|
|
CRI("Failed to allocate memory!");
|
|
|
|
elm_object_cnp_selection_clear(obj, selection);
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
memcpy(sel->selbuf, selbuf, buflen);
|
|
|
|
sel->selbuf[buflen] = 0;
|
|
|
|
sel->buflen = buflen;
|
|
|
|
type = _elm_sel_format_to_ecore_cocoa_cnp_type(format);
|
|
|
|
ecore_cocoa_selection_clipboard_set(selbuf, buflen, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cocoa_elm_cnp_selection_loss_callback_set(Evas_Object *obj EINA_UNUSED,
|
|
|
|
Elm_Sel_Type selection EINA_UNUSED,
|
|
|
|
Elm_Selection_Loss_Cb func EINA_UNUSED,
|
|
|
|
const void *data EINA_UNUSED)
|
|
|
|
{
|
|
|
|
// Currently, we have no way to track changes in Cocoa pasteboard.
|
|
|
|
// Therefore, don't track this...
|
|
|
|
//sel->loss_cb = func;
|
|
|
|
//sel->loss_data = (void *)data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_cocoa_elm_cnp_selection_clear(Evas_Object *obj EINA_UNUSED,
|
|
|
|
Elm_Sel_Type selection EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Cocoa_Cnp_Selection *sel = &_cocoa_cnp_sel;
|
|
|
|
|
|
|
|
if (sel->widget)
|
|
|
|
evas_object_event_callback_del_full(sel->widget, EVAS_CALLBACK_DEL,
|
|
|
|
_cocoa_sel_obj_del_cb, sel);
|
|
|
|
if (sel->requestwidget)
|
|
|
|
evas_object_event_callback_del_full(sel->requestwidget, EVAS_CALLBACK_DEL,
|
|
|
|
_cocoa_sel_obj_del_req_cb, sel);
|
|
|
|
|
|
|
|
sel->widget = NULL;
|
|
|
|
sel->requestwidget = NULL;
|
|
|
|
sel->loss_cb = NULL;
|
|
|
|
sel->loss_data = NULL;
|
|
|
|
ELM_SAFE_FREE(sel->selbuf, free);
|
|
|
|
sel->buflen = 0;
|
|
|
|
ecore_cocoa_selection_clipboard_clear();
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_cocoa_elm_cnp_selection_get(const Evas_Object *obj,
|
|
|
|
Ecore_Cocoa_Window *win,
|
|
|
|
Elm_Sel_Type selection EINA_UNUSED,
|
|
|
|
Elm_Sel_Format format,
|
|
|
|
Elm_Drop_Cb datacb,
|
|
|
|
void *udata)
|
|
|
|
{
|
|
|
|
Cocoa_Cnp_Selection *sel = &_cocoa_cnp_sel;
|
|
|
|
|
|
|
|
if (sel->requestwidget)
|
|
|
|
evas_object_event_callback_del_full(sel->requestwidget, EVAS_CALLBACK_DEL,
|
|
|
|
_cocoa_sel_obj_del_req_cb, sel);
|
|
|
|
|
|
|
|
sel->requestformat = format;
|
|
|
|
sel->requestwidget = (Evas_Object *)obj;
|
|
|
|
sel->win = win;
|
|
|
|
sel->datacb = datacb;
|
|
|
|
sel->udata = udata;
|
|
|
|
|
|
|
|
ecore_job_add(_job_pb_cb, sel);
|
|
|
|
|
|
|
|
evas_object_event_callback_add(sel->requestwidget, EVAS_CALLBACK_DEL,
|
|
|
|
_cocoa_sel_obj_del_req_cb, sel);
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-28 23:52:48 -07:00
|
|
|
#endif
|
|
|
|
|
2012-08-22 02:37:00 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// for local (Within 1 app/process) cnp (used by fb as fallback
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
#if 1
|
|
|
|
typedef struct _Local_Selinfo Local_Selinfo;
|
|
|
|
|
|
|
|
struct _Local_Selinfo
|
|
|
|
{
|
|
|
|
Elm_Sel_Format format;
|
|
|
|
struct {
|
2013-05-07 20:50:09 -07:00
|
|
|
char *buf;
|
2012-08-22 02:37:00 -07:00
|
|
|
size_t size;
|
|
|
|
} sel;
|
|
|
|
struct {
|
|
|
|
Evas_Object *obj;
|
|
|
|
Elm_Drop_Cb func;
|
|
|
|
void *data;
|
|
|
|
Ecore_Job *job;
|
|
|
|
} get;
|
|
|
|
};
|
|
|
|
|
|
|
|
// for ELM_SEL_TYPE_PRIMARY, ELM_SEL_TYPE_SECONDARY, ELM_SEL_TYPE_XDND,
|
|
|
|
// ELM_SEL_TYPE_CLIPBOARD
|
|
|
|
static Local_Selinfo _local_selinfo[4];
|
|
|
|
|
|
|
|
static void _local_get_job(void *data);
|
|
|
|
|
|
|
|
static Eina_Bool _local_elm_cnp_init(void);
|
2014-01-06 06:30:02 -08:00
|
|
|
static Eina_Bool _local_elm_cnp_selection_set(Evas_Object *obj EINA_UNUSED, Elm_Sel_Type selection, Elm_Sel_Format format, const void *selbuf, size_t buflen);
|
|
|
|
static void _local_elm_cnp_selection_loss_callback_set(Evas_Object *obj EINA_UNUSED, Elm_Sel_Type selection EINA_UNUSED, Elm_Selection_Loss_Cb func EINA_UNUSED, const void *data EINA_UNUSED);
|
|
|
|
static Eina_Bool _local_elm_object_cnp_selection_clear(Evas_Object *obj EINA_UNUSED, Elm_Sel_Type selection);
|
2015-06-08 10:44:29 -07:00
|
|
|
static Eina_Bool _local_elm_cnp_selection_get(const Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format EINA_UNUSED, Elm_Drop_Cb datacb, void *udata);
|
2014-01-06 06:30:02 -08:00
|
|
|
static Eina_Bool _local_elm_drop_target_add(Evas_Object *obj EINA_UNUSED, Elm_Sel_Format format EINA_UNUSED,
|
|
|
|
Elm_Drag_State entercb EINA_UNUSED, void *enterdata EINA_UNUSED,
|
|
|
|
Elm_Drag_State leavecb EINA_UNUSED, void *leavedata EINA_UNUSED,
|
|
|
|
Elm_Drag_Pos poscb EINA_UNUSED, void *posdata EINA_UNUSED,
|
|
|
|
Elm_Drop_Cb dropcb EINA_UNUSED, void *dropdata EINA_UNUSED);
|
|
|
|
static Eina_Bool _local_elm_drag_start(Evas_Object *obj EINA_UNUSED,
|
|
|
|
Elm_Sel_Format format EINA_UNUSED,
|
|
|
|
const char *data EINA_UNUSED,
|
|
|
|
Elm_Xdnd_Action action EINA_UNUSED,
|
|
|
|
Elm_Drag_Icon_Create_Cb createicon EINA_UNUSED,
|
|
|
|
void *createdata EINA_UNUSED,
|
|
|
|
Elm_Drag_Pos dragpos EINA_UNUSED,
|
|
|
|
void *dragdata EINA_UNUSED,
|
|
|
|
Elm_Drag_Accept acceptcb EINA_UNUSED,
|
|
|
|
void *acceptdata EINA_UNUSED,
|
|
|
|
Elm_Drag_State dragdone EINA_UNUSED,
|
|
|
|
void *donecbdata EINA_UNUSED);
|
|
|
|
static Eina_Bool _local_elm_selection_selection_has_owner(Evas_Object *obj EINA_UNUSED);
|
2012-08-22 02:37:00 -07:00
|
|
|
|
|
|
|
static void
|
|
|
|
_local_get_job(void *data)
|
|
|
|
{
|
|
|
|
Local_Selinfo *info = data;
|
|
|
|
Elm_Selection_Data ev;
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2012-08-22 02:37:00 -07:00
|
|
|
info->get.job = NULL;
|
|
|
|
ev.x = 0;
|
|
|
|
ev.y = 0;
|
|
|
|
ev.format = info->format;
|
|
|
|
ev.data = info->sel.buf;
|
|
|
|
ev.len = info->sel.size;
|
2013-02-22 00:49:08 -08:00
|
|
|
ev.action = ELM_XDND_ACTION_UNKNOWN;
|
2012-08-22 02:37:00 -07:00
|
|
|
if (info->get.func)
|
|
|
|
info->get.func(info->get.data, info->get.obj, &ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_local_elm_cnp_init(void)
|
|
|
|
{
|
2012-08-28 00:49:27 -07:00
|
|
|
static int _init_count = 0;
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2012-08-28 00:49:27 -07:00
|
|
|
if (_init_count > 0) return EINA_TRUE;
|
|
|
|
_init_count++;
|
2012-08-22 02:37:00 -07:00
|
|
|
memset(&(_local_selinfo), 0, sizeof(_local_selinfo));
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_local_elm_cnp_selection_set(Evas_Object *obj EINA_UNUSED,
|
2012-08-22 02:37:00 -07:00
|
|
|
Elm_Sel_Type selection, Elm_Sel_Format format,
|
|
|
|
const void *selbuf, size_t buflen)
|
|
|
|
{
|
2012-08-28 00:49:27 -07:00
|
|
|
_local_elm_cnp_init();
|
2014-01-21 18:08:47 -08:00
|
|
|
free(_local_selinfo[selection].sel.buf);
|
2012-08-22 02:37:00 -07:00
|
|
|
_local_selinfo[selection].format = format;
|
2013-05-07 20:50:09 -07:00
|
|
|
_local_selinfo[selection].sel.buf = malloc(buflen + 1);
|
2012-08-22 02:37:00 -07:00
|
|
|
if (_local_selinfo[selection].sel.buf)
|
|
|
|
{
|
|
|
|
memcpy(_local_selinfo[selection].sel.buf, selbuf, buflen);
|
2013-05-07 20:50:09 -07:00
|
|
|
_local_selinfo[selection].sel.buf[buflen] = 0;
|
2012-08-22 02:37:00 -07:00
|
|
|
_local_selinfo[selection].sel.size = buflen;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_local_selinfo[selection].sel.size = 0;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-01-06 06:30:02 -08:00
|
|
|
_local_elm_cnp_selection_loss_callback_set(Evas_Object *obj EINA_UNUSED,
|
|
|
|
Elm_Sel_Type selection EINA_UNUSED,
|
|
|
|
Elm_Selection_Loss_Cb func EINA_UNUSED,
|
|
|
|
const void *data EINA_UNUSED)
|
2012-08-22 02:37:00 -07:00
|
|
|
{
|
2012-08-28 00:49:27 -07:00
|
|
|
_local_elm_cnp_init();
|
2015-10-28 10:06:29 -07:00
|
|
|
// this doesn't need to do anything as we never lose selection to anyone
|
2012-08-22 02:37:00 -07:00
|
|
|
// as thisis local
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_local_elm_object_cnp_selection_clear(Evas_Object *obj EINA_UNUSED,
|
2012-08-22 02:37:00 -07:00
|
|
|
Elm_Sel_Type selection)
|
|
|
|
{
|
2012-08-28 00:49:27 -07:00
|
|
|
_local_elm_cnp_init();
|
2014-01-21 18:08:47 -08:00
|
|
|
ELM_SAFE_FREE(_local_selinfo[selection].sel.buf, free);
|
2012-08-22 02:37:00 -07:00
|
|
|
_local_selinfo[selection].sel.size = 0;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2015-06-08 10:44:29 -07:00
|
|
|
_local_elm_cnp_selection_get(const Evas_Object *obj,
|
2012-08-22 02:37:00 -07:00
|
|
|
Elm_Sel_Type selection,
|
2014-01-06 06:30:02 -08:00
|
|
|
Elm_Sel_Format format EINA_UNUSED,
|
2012-08-22 02:37:00 -07:00
|
|
|
Elm_Drop_Cb datacb, void *udata)
|
|
|
|
{
|
2012-08-28 00:49:27 -07:00
|
|
|
_local_elm_cnp_init();
|
2012-08-22 02:37:00 -07:00
|
|
|
if (_local_selinfo[selection].get.job)
|
|
|
|
ecore_job_del(_local_selinfo[selection].get.job);
|
2015-06-08 10:44:29 -07:00
|
|
|
_local_selinfo[selection].get.obj = (Evas_Object *)obj;
|
2012-08-22 02:37:00 -07:00
|
|
|
_local_selinfo[selection].get.func = datacb;
|
|
|
|
_local_selinfo[selection].get.data = udata;
|
2013-09-30 03:21:31 -07:00
|
|
|
_local_selinfo[selection].get.job =
|
2012-08-22 02:37:00 -07:00
|
|
|
ecore_job_add(_local_get_job, &(_local_selinfo[selection]));
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_local_elm_drop_target_add(Evas_Object *obj EINA_UNUSED,
|
|
|
|
Elm_Sel_Format format EINA_UNUSED,
|
|
|
|
Elm_Drag_State entercb EINA_UNUSED,
|
|
|
|
void *enterdata EINA_UNUSED,
|
|
|
|
Elm_Drag_State leavecb EINA_UNUSED,
|
|
|
|
void *leavedata EINA_UNUSED,
|
|
|
|
Elm_Drag_Pos poscb EINA_UNUSED,
|
|
|
|
void *posdata EINA_UNUSED,
|
|
|
|
Elm_Drop_Cb dropcb EINA_UNUSED,
|
|
|
|
void *dropdata EINA_UNUSED)
|
2012-08-22 02:37:00 -07:00
|
|
|
{
|
|
|
|
// XXX: implement me
|
2012-08-28 00:49:27 -07:00
|
|
|
_local_elm_cnp_init();
|
2012-08-22 02:37:00 -07:00
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2014-10-20 09:10:02 -07:00
|
|
|
_local_elm_drop_target_del(Evas_Object *obj, Elm_Sel_Format format,
|
|
|
|
Elm_Drag_State entercb, void *enterdata,
|
|
|
|
Elm_Drag_State leavecb, void *leavedata,
|
|
|
|
Elm_Drag_Pos poscb, void *posdata,
|
|
|
|
Elm_Drop_Cb dropcb, void *dropdata)
|
2012-08-22 02:37:00 -07:00
|
|
|
{
|
2014-10-20 09:10:02 -07:00
|
|
|
Dropable *dropable = NULL;
|
|
|
|
|
2012-08-28 00:49:27 -07:00
|
|
|
_local_elm_cnp_init();
|
2014-10-20 09:10:02 -07:00
|
|
|
|
2016-03-02 04:10:48 -08:00
|
|
|
dropable = eo_key_data_get(obj, "__elm_dropable");
|
2014-10-20 09:10:02 -07:00
|
|
|
if (dropable)
|
|
|
|
{
|
|
|
|
Eina_Inlist *itr;
|
|
|
|
Dropable_Cbs *cbs_info;
|
|
|
|
/* Look for the callback in the list */
|
|
|
|
EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs_info)
|
|
|
|
if (cbs_info->entercb == entercb && cbs_info->enterdata == enterdata &&
|
|
|
|
cbs_info->leavecb == leavecb && cbs_info->leavedata == leavedata &&
|
|
|
|
cbs_info->poscb == poscb && cbs_info->posdata == posdata &&
|
|
|
|
cbs_info->dropcb == dropcb && cbs_info->dropdata == dropdata &&
|
|
|
|
cbs_info->types == format)
|
|
|
|
{
|
|
|
|
dropable->cbs_list = eina_inlist_remove(dropable->cbs_list,
|
|
|
|
EINA_INLIST_GET(cbs_info));
|
|
|
|
free(cbs_info);
|
|
|
|
}
|
|
|
|
/* In case no more callbacks are listed for the object */
|
|
|
|
if (!dropable->cbs_list)
|
|
|
|
{
|
|
|
|
drops = eina_list_remove(drops, dropable);
|
2016-04-21 02:01:00 -07:00
|
|
|
eo_key_del(obj, "__elm_dropable");
|
2014-10-20 09:10:02 -07:00
|
|
|
free(dropable);
|
|
|
|
dropable = NULL;
|
|
|
|
evas_object_event_callback_del(obj, EVAS_CALLBACK_DEL,
|
|
|
|
_all_drop_targets_cbs_del);
|
|
|
|
}
|
2015-02-25 00:36:34 -08:00
|
|
|
if (!drops)
|
|
|
|
{
|
|
|
|
_elm_cnp_shutdown();
|
|
|
|
}
|
2014-10-20 09:10:02 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-08-22 02:37:00 -07:00
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_local_elm_drag_start(Evas_Object *obj EINA_UNUSED,
|
|
|
|
Elm_Sel_Format format EINA_UNUSED,
|
|
|
|
const char *data EINA_UNUSED,
|
|
|
|
Elm_Xdnd_Action action EINA_UNUSED,
|
|
|
|
Elm_Drag_Icon_Create_Cb createicon EINA_UNUSED,
|
|
|
|
void *createdata EINA_UNUSED,
|
|
|
|
Elm_Drag_Pos dragpos EINA_UNUSED,
|
|
|
|
void *dragdata EINA_UNUSED,
|
|
|
|
Elm_Drag_Accept acceptcb EINA_UNUSED,
|
|
|
|
void *acceptdata EINA_UNUSED,
|
|
|
|
Elm_Drag_State dragdone EINA_UNUSED,
|
|
|
|
void *donecbdata EINA_UNUSED)
|
2012-08-22 02:37:00 -07:00
|
|
|
{
|
|
|
|
// XXX: implement me
|
2012-08-28 00:49:27 -07:00
|
|
|
_local_elm_cnp_init();
|
2012-08-22 02:37:00 -07:00
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
2013-02-22 00:49:08 -08:00
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_local_elm_drag_action_set(Evas_Object *obj EINA_UNUSED,
|
|
|
|
Elm_Xdnd_Action action EINA_UNUSED)
|
2013-02-22 00:49:08 -08:00
|
|
|
{
|
|
|
|
// XXX: implement me
|
|
|
|
_local_elm_cnp_init();
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-08-22 02:37:00 -07:00
|
|
|
static Eina_Bool
|
2014-01-06 06:30:02 -08:00
|
|
|
_local_elm_selection_selection_has_owner(Evas_Object *obj EINA_UNUSED)
|
2012-08-22 02:37:00 -07:00
|
|
|
{
|
2012-08-28 00:49:27 -07:00
|
|
|
_local_elm_cnp_init();
|
2012-08-22 02:37:00 -07:00
|
|
|
if (_local_selinfo[ELM_SEL_TYPE_CLIPBOARD].sel.buf) return EINA_TRUE;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-15 14:13:42 -07:00
|
|
|
// win32 specific stuff
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifdef HAVE_ELEMENTARY_WIN32
|
|
|
|
|
|
|
|
typedef struct _Win32_Cnp_Selection Win32_Cnp_Selection;
|
|
|
|
|
|
|
|
struct _Win32_Cnp_Selection
|
|
|
|
{
|
|
|
|
const char *debug;
|
|
|
|
Evas_Object *widget;
|
|
|
|
char *selbuf;
|
|
|
|
Evas_Object *requestwidget;
|
|
|
|
void *udata;
|
|
|
|
Elm_Sel_Format requestformat;
|
|
|
|
Elm_Drop_Cb datacb;
|
|
|
|
Eina_Bool (*set)(const Ecore_Win32_Window *window, const void *data, int size);
|
|
|
|
Eina_Bool (*clear)(const Ecore_Win32_Window *window);
|
|
|
|
Eina_Bool (*get)(const Ecore_Win32_Window *window , void **data, int *size);
|
|
|
|
Elm_Selection_Loss_Cb loss_cb;
|
|
|
|
void *loss_data;
|
|
|
|
|
|
|
|
Elm_Sel_Format format;
|
|
|
|
Ecore_Win32_Selection ecore_sel;
|
|
|
|
Ecore_Win32_Window *win;
|
|
|
|
Elm_Xdnd_Action action;
|
|
|
|
|
|
|
|
Eina_Bool active : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ARRAYINIT(foo) [foo] =
|
|
|
|
|
|
|
|
static Win32_Cnp_Selection _win32_selections[ELM_SEL_TYPE_CLIPBOARD + 1] =
|
|
|
|
{
|
|
|
|
ARRAYINIT(ELM_SEL_TYPE_PRIMARY)
|
|
|
|
{
|
|
|
|
.debug = "Primary",
|
|
|
|
.ecore_sel = ECORE_WIN32_SELECTION_PRIMARY,
|
|
|
|
.set = ecore_win32_clipboard_set,
|
|
|
|
.clear = ecore_win32_clipboard_clear,
|
|
|
|
.get = ecore_win32_clipboard_get,
|
|
|
|
},
|
|
|
|
ARRAYINIT(ELM_SEL_TYPE_SECONDARY)
|
|
|
|
{
|
|
|
|
.debug = "Secondary",
|
|
|
|
.ecore_sel = ECORE_WIN32_SELECTION_OTHER,
|
|
|
|
},
|
|
|
|
ARRAYINIT(ELM_SEL_TYPE_XDND)
|
|
|
|
{
|
|
|
|
.debug = "XDnD",
|
|
|
|
.ecore_sel = ECORE_WIN32_SELECTION_OTHER,
|
|
|
|
},
|
|
|
|
ARRAYINIT(ELM_SEL_TYPE_CLIPBOARD)
|
|
|
|
{
|
|
|
|
.debug = "Clipboard",
|
|
|
|
.ecore_sel = ECORE_WIN32_SELECTION_CLIPBOARD,
|
|
|
|
.set = ecore_win32_clipboard_set,
|
|
|
|
.clear = ecore_win32_clipboard_clear,
|
|
|
|
.get = ecore_win32_clipboard_get,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
_win32_sel_obj_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Win32_Cnp_Selection *sel = data;
|
|
|
|
if (sel->widget == obj) sel->widget = NULL;
|
|
|
|
if (dragwidget == obj) dragwidget = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_win32_sel_obj_del2(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Win32_Cnp_Selection *sel = data;
|
|
|
|
if (sel->requestwidget == obj) sel->requestwidget = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_win32_elm_cnp_init(void)
|
|
|
|
{
|
|
|
|
static int _init_count = 0;
|
|
|
|
|
|
|
|
if (_init_count > 0) return EINA_TRUE;
|
|
|
|
_init_count++;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Ecore_Win32_Window *
|
|
|
|
_win32_elm_widget_window_get(const Evas_Object *obj)
|
|
|
|
{
|
|
|
|
Evas_Object *top;
|
|
|
|
Ecore_Win32_Window *win = NULL;
|
|
|
|
|
|
|
|
if (elm_widget_is(obj))
|
|
|
|
{
|
|
|
|
top = elm_widget_top_get(obj);
|
|
|
|
if (!top)
|
|
|
|
{
|
|
|
|
Evas_Object *par;
|
|
|
|
par = elm_widget_parent_widget_get(obj);
|
|
|
|
if (par) top = elm_widget_top_get(par);
|
|
|
|
}
|
|
|
|
if (top && (eo_isa(top, ELM_WIN_CLASS)))
|
|
|
|
win = elm_win_win32_window_get(top);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!win)
|
|
|
|
{
|
|
|
|
Ecore_Evas *ee;
|
|
|
|
Evas *evas;
|
|
|
|
const char *engine_name;
|
|
|
|
|
|
|
|
evas = evas_object_evas_get(obj);
|
|
|
|
if (!evas) return NULL;
|
|
|
|
|
|
|
|
ee = ecore_evas_ecore_evas_get(evas);
|
|
|
|
if (!ee) return NULL;
|
|
|
|
|
|
|
|
engine_name = ecore_evas_engine_name_get(ee);
|
|
|
|
if (!strcmp(engine_name, ELM_BUFFER))
|
|
|
|
{
|
|
|
|
ee = ecore_evas_buffer_ecore_evas_parent_get(ee);
|
|
|
|
if (!ee) return NULL;
|
|
|
|
win = ecore_evas_win32_window_get(ee);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((strcmp(engine_name, ELM_SOFTWARE_WIN32) == 0) ||
|
|
|
|
(strcmp(engine_name, ELM_SOFTWARE_DDRAW) == 0))
|
|
|
|
return ecore_evas_win32_window_get(ee);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return win;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_win32_elm_cnp_selection_set(Ecore_Win32_Window *win, Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format, const void *selbuf, size_t buflen)
|
|
|
|
{
|
|
|
|
Win32_Cnp_Selection *sel;
|
|
|
|
|
|
|
|
if (selection != ELM_SEL_TYPE_CLIPBOARD)
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
_win32_elm_cnp_init();
|
|
|
|
if ((!selbuf) && (format != ELM_SEL_FORMAT_IMAGE))
|
|
|
|
return elm_object_cnp_selection_clear(obj, selection);
|
|
|
|
|
|
|
|
sel = _win32_selections + selection;
|
|
|
|
if (sel->widget != obj && sel->loss_cb) sel->loss_cb(sel->loss_data, selection);
|
|
|
|
if (sel->widget)
|
|
|
|
evas_object_event_callback_del_full(sel->widget, EVAS_CALLBACK_DEL,
|
|
|
|
_win32_sel_obj_del, sel);
|
|
|
|
sel->active = EINA_TRUE;
|
|
|
|
sel->widget = obj;
|
|
|
|
sel->win = win;
|
|
|
|
if (sel->set) sel->set(win, selbuf, buflen);
|
|
|
|
sel->format = format;
|
|
|
|
sel->loss_cb = NULL;
|
|
|
|
sel->loss_data = NULL;
|
|
|
|
|
|
|
|
evas_object_event_callback_add
|
|
|
|
(sel->widget, EVAS_CALLBACK_DEL, _win32_sel_obj_del, sel);
|
|
|
|
|
|
|
|
ELM_SAFE_FREE(sel->selbuf, free);
|
|
|
|
if (selbuf)
|
|
|
|
{
|
|
|
|
if (format == ELM_SEL_FORMAT_IMAGE)
|
|
|
|
{
|
|
|
|
// selbuf is actual image data, not text/string
|
|
|
|
sel->selbuf = malloc(buflen + 1);
|
|
|
|
if (!sel->selbuf)
|
|
|
|
{
|
|
|
|
elm_object_cnp_selection_clear(obj, selection);
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
memcpy(sel->selbuf, selbuf, buflen);
|
|
|
|
sel->selbuf[buflen] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sel->selbuf = strdup((char*)selbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_win32_elm_cnp_selection_loss_callback_set(Evas_Object *obj EINA_UNUSED, Elm_Sel_Type selection, Elm_Selection_Loss_Cb func, const void *data)
|
|
|
|
{
|
|
|
|
Win32_Cnp_Selection *sel;
|
|
|
|
|
|
|
|
if (selection != ELM_SEL_TYPE_CLIPBOARD)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_win32_elm_cnp_init();
|
|
|
|
sel = _win32_selections + selection;
|
|
|
|
sel->loss_cb = func;
|
|
|
|
sel->loss_data = (void *)data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_win32_elm_object_cnp_selection_clear(Ecore_Win32_Window *win, Evas_Object *obj, Elm_Sel_Type selection)
|
|
|
|
{
|
|
|
|
Win32_Cnp_Selection *sel;
|
|
|
|
|
|
|
|
if (selection != ELM_SEL_TYPE_CLIPBOARD)
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
_win32_elm_cnp_init();
|
|
|
|
|
|
|
|
sel = _win32_selections + selection;
|
|
|
|
|
|
|
|
/* No longer this selection: Consider it gone! */
|
|
|
|
if ((!sel->active) || (sel->widget != obj))
|
|
|
|
return EINA_TRUE;
|
|
|
|
|
|
|
|
if (sel->widget)
|
|
|
|
evas_object_event_callback_del_full(sel->widget, EVAS_CALLBACK_DEL,
|
|
|
|
_win32_sel_obj_del, sel);
|
|
|
|
if (sel->requestwidget)
|
|
|
|
evas_object_event_callback_del_full(sel->requestwidget, EVAS_CALLBACK_DEL,
|
|
|
|
_win32_sel_obj_del2, sel);
|
|
|
|
sel->widget = NULL;
|
|
|
|
sel->requestwidget = NULL;
|
|
|
|
sel->loss_cb = NULL;
|
|
|
|
sel->loss_data = NULL;
|
|
|
|
|
|
|
|
sel->active = EINA_FALSE;
|
|
|
|
ELM_SAFE_FREE(sel->selbuf, free);
|
|
|
|
/* sel->clear(win); */
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_win32_elm_cnp_selection_get(Ecore_Win32_Window *win,
|
|
|
|
const Evas_Object *obj,
|
|
|
|
Elm_Sel_Type selection,
|
|
|
|
Elm_Sel_Format format,
|
|
|
|
Elm_Drop_Cb datacb,
|
|
|
|
void *udata)
|
|
|
|
{
|
|
|
|
Win32_Cnp_Selection *sel;
|
|
|
|
void *data;
|
|
|
|
int size;
|
|
|
|
|
|
|
|
if (selection != ELM_SEL_TYPE_CLIPBOARD)
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
|
|
|
_win32_elm_cnp_init();
|
|
|
|
|
|
|
|
sel = _win32_selections + selection;
|
|
|
|
|
|
|
|
if (sel->requestwidget)
|
|
|
|
evas_object_event_callback_del_full(sel->requestwidget, EVAS_CALLBACK_DEL,
|
|
|
|
_win32_sel_obj_del2, sel);
|
|
|
|
sel->requestformat = format;
|
|
|
|
sel->requestwidget = (Evas_Object *)obj;
|
|
|
|
sel->win = win;
|
|
|
|
sel->get(win, &data, &size);
|
|
|
|
sel->datacb = datacb;
|
|
|
|
sel->udata = udata;
|
|
|
|
|
|
|
|
if (!data || (size <= 0))
|
|
|
|
goto cb_add;
|
|
|
|
|
|
|
|
if ((sel->format & ELM_SEL_FORMAT_MARKUP) ||
|
|
|
|
(sel->format & ELM_SEL_FORMAT_HTML))
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
str = (char *)malloc(size + 1);
|
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
memcpy(str, data, size);
|
|
|
|
str[size] = '\0';
|
|
|
|
data = _elm_util_mkup_to_text(str);
|
|
|
|
free(str);
|
|
|
|
if (data)
|
|
|
|
size = strlen(data);
|
|
|
|
else
|
|
|
|
size = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free(data);
|
|
|
|
data = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sel->datacb && data && (size > 0))
|
|
|
|
{
|
|
|
|
Elm_Selection_Data sdata;
|
|
|
|
|
|
|
|
sdata.x = sdata.y = 0;
|
|
|
|
sdata.format = ELM_SEL_FORMAT_TEXT;
|
|
|
|
sdata.data = data;
|
|
|
|
sdata.len = size;
|
|
|
|
sdata.action = sel->action;
|
|
|
|
sel->datacb(sel->udata, sel->requestwidget, &sdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
free(data);
|
|
|
|
|
|
|
|
cb_add:
|
|
|
|
evas_object_event_callback_add
|
|
|
|
(sel->requestwidget, EVAS_CALLBACK_DEL, _win32_sel_obj_del2, sel);
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_ELEMENTARY_WIN32 */
|
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
// common internal funcs
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
static Eina_Bool
|
2012-08-29 00:29:21 -07:00
|
|
|
_elm_cnp_init(void)
|
2012-08-22 01:33:43 -07:00
|
|
|
{
|
2015-03-10 00:25:02 -07:00
|
|
|
int i;
|
2012-08-28 00:49:27 -07:00
|
|
|
if (_elm_cnp_init_count > 0) return EINA_TRUE;
|
|
|
|
_elm_cnp_init_count++;
|
2012-08-22 01:33:43 -07:00
|
|
|
text_uri = eina_stringshare_add("text/uri-list");
|
2015-03-10 00:25:02 -07:00
|
|
|
_types_hash = eina_hash_string_small_new(NULL);
|
|
|
|
for (i = 0; i < CNP_N_ATOMS; i++)
|
|
|
|
{
|
|
|
|
eina_hash_add(_types_hash, _atoms[i].name, &_atoms[i]);
|
|
|
|
}
|
2012-08-22 01:33:43 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2015-02-25 00:36:34 -08:00
|
|
|
static Eina_Bool
|
|
|
|
_elm_cnp_shutdown(void)
|
|
|
|
{
|
|
|
|
if (!_elm_cnp_init_count) return EINA_TRUE;
|
|
|
|
if (--_elm_cnp_init_count > 0) return EINA_TRUE;
|
|
|
|
eina_stringshare_del(text_uri);
|
|
|
|
text_uri = NULL;
|
2015-07-30 22:42:53 -07:00
|
|
|
ELM_SAFE_FREE(_types_hash, eina_hash_free);
|
2015-02-25 00:36:34 -08:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
/* TODO: this should not be an actual tempfile, but rather encode the object
|
|
|
|
* as http://dataurl.net/ if it's an image or similar. Evas should support
|
|
|
|
* decoding it as memfile. */
|
2010-12-20 03:09:19 -08:00
|
|
|
static Tmp_Info *
|
2012-08-22 01:33:43 -07:00
|
|
|
_tempfile_new(int size)
|
2010-12-20 03:09:19 -08:00
|
|
|
{
|
2011-11-20 06:56:12 -08:00
|
|
|
#ifdef HAVE_MMAN_H
|
2010-12-20 03:09:19 -08:00
|
|
|
Tmp_Info *info;
|
2014-01-08 03:32:27 -08:00
|
|
|
const char *tmppath = NULL;
|
2012-12-06 20:03:01 -08:00
|
|
|
mode_t cur_umask;
|
2010-09-21 21:42:41 -07:00
|
|
|
int len;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2013-01-15 19:34:18 -08:00
|
|
|
info = calloc(1, sizeof(Tmp_Info));
|
2010-09-21 21:42:41 -07:00
|
|
|
if (!info) return NULL;
|
2014-01-08 05:08:44 -08:00
|
|
|
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
|
|
|
|
if (getuid() == geteuid())
|
|
|
|
#endif
|
|
|
|
tmppath = getenv("TMP");
|
2010-09-21 21:42:41 -07:00
|
|
|
if (!tmppath) tmppath = P_tmpdir;
|
2010-12-20 03:09:19 -08:00
|
|
|
len = snprintf(NULL, 0, "%s/%sXXXXXX", tmppath, "elmcnpitem-");
|
2012-12-10 00:01:16 -08:00
|
|
|
if (len < 0) goto on_error;
|
2010-12-20 03:09:19 -08:00
|
|
|
len++;
|
2010-09-21 21:42:41 -07:00
|
|
|
info->filename = malloc(len);
|
2012-12-10 00:01:16 -08:00
|
|
|
if (!info->filename) goto on_error;
|
2010-12-20 03:09:19 -08:00
|
|
|
snprintf(info->filename,len,"%s/%sXXXXXX", tmppath, "elmcnpitem-");
|
2012-12-06 20:03:01 -08:00
|
|
|
cur_umask = umask(S_IRWXO | S_IRWXG);
|
2010-09-21 21:42:41 -07:00
|
|
|
info->fd = mkstemp(info->filename);
|
2012-12-06 20:03:01 -08:00
|
|
|
umask(cur_umask);
|
2012-12-10 00:01:16 -08:00
|
|
|
if (info->fd < 0) goto on_error;
|
2010-12-20 03:09:19 -08:00
|
|
|
# ifdef __linux__
|
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
/* And before someone says anything see POSIX 1003.1-2008 page 400 */
|
|
|
|
long pid;
|
2013-09-30 03:21:31 -07:00
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
pid = (long)getpid();
|
|
|
|
/* Use pid instead of /proc/self: That way if can be passed around */
|
|
|
|
len = snprintf(NULL,0,"/proc/%li/fd/%i", pid, info->fd);
|
|
|
|
len++;
|
|
|
|
tmp = malloc(len);
|
|
|
|
if (tmp)
|
|
|
|
{
|
|
|
|
snprintf(tmp,len, "/proc/%li/fd/%i", pid, info->fd);
|
|
|
|
unlink(info->filename);
|
|
|
|
free(info->filename);
|
|
|
|
info->filename = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
cnp_debug("filename is %s\n", info->filename);
|
2012-12-10 00:01:16 -08:00
|
|
|
if (size < 1) goto on_error;
|
2010-09-21 21:42:41 -07:00
|
|
|
/* Map it in */
|
|
|
|
if (ftruncate(info->fd, size))
|
|
|
|
{
|
|
|
|
perror("ftruncate");
|
2012-12-10 00:01:16 -08:00
|
|
|
goto on_error;
|
2010-09-21 21:42:41 -07:00
|
|
|
}
|
2011-07-04 04:04:26 -07:00
|
|
|
eina_mmap_safety_enabled_set(EINA_TRUE);
|
2010-12-20 03:09:19 -08:00
|
|
|
info->map = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, info->fd, 0);
|
2010-09-21 21:42:41 -07:00
|
|
|
if (info->map == MAP_FAILED)
|
|
|
|
{
|
|
|
|
perror("mmap");
|
2012-12-10 00:01:16 -08:00
|
|
|
goto on_error;
|
2010-09-21 21:42:41 -07:00
|
|
|
}
|
|
|
|
return info;
|
2012-12-10 00:01:16 -08:00
|
|
|
|
|
|
|
on_error:
|
|
|
|
if (info->fd >= 0) close(info->fd);
|
|
|
|
info->fd = -1;
|
|
|
|
/* Set map to NULL and return */
|
|
|
|
info->map = NULL;
|
|
|
|
info->len = 0;
|
2013-06-10 06:53:11 -07:00
|
|
|
free(info->filename);
|
2012-12-10 00:01:16 -08:00
|
|
|
free(info);
|
|
|
|
return NULL;
|
2011-11-20 06:56:12 -08:00
|
|
|
#else
|
|
|
|
(void) size;
|
|
|
|
return NULL;
|
|
|
|
#endif
|
2010-09-21 21:42:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-08-22 01:33:43 -07:00
|
|
|
_tmpinfo_free(Tmp_Info *info)
|
2010-09-21 21:42:41 -07:00
|
|
|
{
|
|
|
|
if (!info) return 0;
|
|
|
|
free(info->filename);
|
|
|
|
free(info);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-09-09 01:59:38 -07:00
|
|
|
|
2012-08-22 02:37:00 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2012-08-22 01:33:43 -07:00
|
|
|
// common exposed funcs
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2012-08-22 02:37:00 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2012-08-22 01:33:43 -07:00
|
|
|
EAPI Eina_Bool
|
|
|
|
elm_cnp_selection_set(Evas_Object *obj, Elm_Sel_Type selection,
|
|
|
|
Elm_Sel_Format format, const void *selbuf, size_t buflen)
|
|
|
|
{
|
|
|
|
if (selection > ELM_SEL_TYPE_CLIPBOARD) return EINA_FALSE;
|
2012-08-29 00:29:21 -07:00
|
|
|
if (!_elm_cnp_init_count) _elm_cnp_init();
|
2012-08-22 01:33:43 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
2014-01-23 05:22:33 -08:00
|
|
|
Ecore_X_Window xwin = _x11_elm_widget_xwin_get(obj);
|
|
|
|
if (xwin)
|
|
|
|
return _x11_elm_cnp_selection_set(xwin, obj, selection, format, selbuf, buflen);
|
2012-08-28 23:52:48 -07:00
|
|
|
#endif
|
2015-10-01 07:25:38 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
2014-09-08 03:51:56 -07:00
|
|
|
if (_wl_elm_widget_window_get(obj))
|
2012-08-28 23:52:48 -07:00
|
|
|
return _wl_elm_cnp_selection_set(obj, selection, format, selbuf, buflen);
|
2015-10-09 08:18:20 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_COCOA
|
|
|
|
Ecore_Cocoa_Window *win = _cocoa_elm_widget_cocoa_window_get(obj);
|
|
|
|
if (win)
|
|
|
|
return _cocoa_elm_cnp_selection_set(win, obj, selection, format, selbuf, buflen);
|
2015-10-15 14:13:42 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WIN32
|
|
|
|
Ecore_Win32_Window *win;
|
|
|
|
|
|
|
|
win = _win32_elm_widget_window_get(obj);
|
|
|
|
if (win)
|
|
|
|
return _win32_elm_cnp_selection_set(win, obj, selection, format, selbuf, buflen);
|
2012-08-22 01:33:43 -07:00
|
|
|
#endif
|
2012-08-22 02:37:00 -07:00
|
|
|
return _local_elm_cnp_selection_set(obj, selection, format, selbuf, buflen);
|
2010-09-09 01:59:38 -07:00
|
|
|
}
|
2010-12-20 03:09:19 -08:00
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
EAPI void
|
|
|
|
elm_cnp_selection_loss_callback_set(Evas_Object *obj, Elm_Sel_Type selection,
|
|
|
|
Elm_Selection_Loss_Cb func,
|
|
|
|
const void *data)
|
2010-12-20 03:09:19 -08:00
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
if (selection > ELM_SEL_TYPE_CLIPBOARD) return;
|
2012-08-29 00:29:21 -07:00
|
|
|
if (!_elm_cnp_init_count) _elm_cnp_init();
|
2012-08-22 01:33:43 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
if (_x11_elm_widget_xwin_get(obj))
|
|
|
|
_x11_elm_cnp_selection_loss_callback_set(obj, selection, func, data);
|
2013-11-07 03:57:14 -08:00
|
|
|
#endif
|
2015-10-01 07:25:38 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
2014-09-08 03:51:56 -07:00
|
|
|
if (_wl_elm_widget_window_get(obj))
|
2013-11-07 03:57:14 -08:00
|
|
|
_wl_elm_cnp_selection_loss_callback_set(obj, selection, func, data);
|
2015-10-09 08:18:20 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_COCOA
|
|
|
|
if (_cocoa_elm_widget_cocoa_window_get(obj))
|
|
|
|
_cocoa_elm_cnp_selection_loss_callback_set(obj, selection, func, data);
|
2015-10-15 14:13:42 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WIN32
|
|
|
|
if (_win32_elm_widget_window_get(obj))
|
|
|
|
_win32_elm_cnp_selection_loss_callback_set(obj, selection, func, data);
|
2013-09-30 03:21:31 -07:00
|
|
|
#endif
|
2012-08-22 02:37:00 -07:00
|
|
|
_local_elm_cnp_selection_loss_callback_set(obj, selection, func, data);
|
2012-08-22 01:33:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
|
|
|
elm_object_cnp_selection_clear(Evas_Object *obj, Elm_Sel_Type selection)
|
|
|
|
{
|
|
|
|
if (selection > ELM_SEL_TYPE_CLIPBOARD) return EINA_FALSE;
|
2012-08-29 00:29:21 -07:00
|
|
|
if (!_elm_cnp_init_count) _elm_cnp_init();
|
2012-08-22 01:33:43 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
if (_x11_elm_widget_xwin_get(obj))
|
|
|
|
return _x11_elm_object_cnp_selection_clear(obj, selection);
|
2013-05-28 03:49:28 -07:00
|
|
|
#endif
|
2015-10-01 07:25:38 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
2014-09-08 03:51:56 -07:00
|
|
|
if (_wl_elm_widget_window_get(obj))
|
2013-05-28 03:49:28 -07:00
|
|
|
return _wl_elm_cnp_selection_clear(obj, selection);
|
2015-10-09 08:18:20 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_COCOA
|
|
|
|
if (_cocoa_elm_widget_cocoa_window_get(obj))
|
|
|
|
return _cocoa_elm_cnp_selection_clear(obj, selection);
|
2015-10-15 14:13:42 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WIN32
|
|
|
|
Ecore_Win32_Window *win;
|
|
|
|
|
|
|
|
win = _win32_elm_widget_window_get(obj);
|
|
|
|
if (win)
|
|
|
|
return _win32_elm_object_cnp_selection_clear(win, obj, selection);
|
2012-08-22 01:33:43 -07:00
|
|
|
#endif
|
2012-08-22 02:37:00 -07:00
|
|
|
return _local_elm_object_cnp_selection_clear(obj, selection);
|
2010-09-09 01:59:38 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
EAPI Eina_Bool
|
2015-06-08 10:44:29 -07:00
|
|
|
elm_cnp_selection_get(const Evas_Object *obj, Elm_Sel_Type selection,
|
2012-08-22 01:33:43 -07:00
|
|
|
Elm_Sel_Format format, Elm_Drop_Cb datacb, void *udata)
|
2010-09-09 01:59:38 -07:00
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
if (selection > ELM_SEL_TYPE_CLIPBOARD) return EINA_FALSE;
|
2012-08-29 00:29:21 -07:00
|
|
|
if (!_elm_cnp_init_count) _elm_cnp_init();
|
2012-08-22 01:33:43 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
2014-01-23 05:22:33 -08:00
|
|
|
Ecore_X_Window xwin = _x11_elm_widget_xwin_get(obj);
|
|
|
|
if (xwin)
|
|
|
|
return _x11_elm_cnp_selection_get(xwin, obj, selection, format, datacb, udata);
|
2012-08-28 23:52:48 -07:00
|
|
|
#endif
|
2015-10-01 07:25:38 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
2014-09-08 03:51:56 -07:00
|
|
|
if (_wl_elm_widget_window_get(obj))
|
2012-08-28 23:52:48 -07:00
|
|
|
return _wl_elm_cnp_selection_get(obj, selection, format, datacb, udata);
|
2015-10-09 08:18:20 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_COCOA
|
|
|
|
Ecore_Cocoa_Window *win = _cocoa_elm_widget_cocoa_window_get(obj);
|
|
|
|
if (win)
|
|
|
|
return _cocoa_elm_cnp_selection_get(obj, win, selection, format, datacb, udata);
|
2015-10-15 14:13:42 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WIN32
|
|
|
|
Ecore_Win32_Window *win;
|
|
|
|
|
|
|
|
win = _win32_elm_widget_window_get(obj);
|
|
|
|
if (win)
|
|
|
|
return _win32_elm_cnp_selection_get(win, obj, selection, format, datacb, udata);
|
2012-08-22 01:33:43 -07:00
|
|
|
#endif
|
2012-08-22 02:37:00 -07:00
|
|
|
return _local_elm_cnp_selection_get(obj, selection, format, datacb, udata);
|
2012-08-22 01:33:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a widget as drop target.
|
|
|
|
*/
|
|
|
|
EAPI Eina_Bool
|
2013-02-19 02:14:35 -08:00
|
|
|
elm_drop_target_add(Evas_Object *obj, Elm_Sel_Format format,
|
2013-02-21 05:21:08 -08:00
|
|
|
Elm_Drag_State entercb, void *enterdata,
|
|
|
|
Elm_Drag_State leavecb, void *leavedata,
|
|
|
|
Elm_Drag_Pos poscb, void *posdata,
|
2013-10-27 02:27:17 -07:00
|
|
|
Elm_Drop_Cb dropcb, void *dropdata)
|
2012-08-22 01:33:43 -07:00
|
|
|
{
|
2012-08-29 00:29:21 -07:00
|
|
|
if (!_elm_cnp_init_count) _elm_cnp_init();
|
2012-08-22 01:33:43 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
if (_x11_elm_widget_xwin_get(obj))
|
2013-02-21 05:21:08 -08:00
|
|
|
return _x11_elm_drop_target_add(obj, format, entercb, enterdata,
|
|
|
|
leavecb, leavedata, poscb, posdata,
|
2013-10-27 02:27:17 -07:00
|
|
|
dropcb, dropdata);
|
2013-05-21 03:19:53 -07:00
|
|
|
#endif
|
2015-10-01 07:25:38 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
2014-09-08 03:51:56 -07:00
|
|
|
if (_wl_elm_widget_window_get(obj))
|
|
|
|
return _wl_elm_drop_target_add(obj, format, entercb, enterdata,
|
|
|
|
leavecb, leavedata, poscb, posdata,
|
|
|
|
dropcb, dropdata);
|
2012-08-22 01:33:43 -07:00
|
|
|
#endif
|
2013-02-21 05:21:08 -08:00
|
|
|
return _local_elm_drop_target_add(obj, format, entercb, enterdata,
|
|
|
|
leavecb, leavedata, poscb, posdata,
|
2013-10-27 02:27:17 -07:00
|
|
|
dropcb, dropdata);
|
2012-08-22 01:33:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
2013-11-04 05:08:53 -08:00
|
|
|
elm_drop_target_del(Evas_Object *obj, Elm_Sel_Format format,
|
|
|
|
Elm_Drag_State entercb, void *enterdata,
|
|
|
|
Elm_Drag_State leavecb, void *leavedata,
|
|
|
|
Elm_Drag_Pos poscb, void *posdata,
|
|
|
|
Elm_Drop_Cb dropcb, void *dropdata)
|
2012-08-22 01:33:43 -07:00
|
|
|
{
|
2012-08-29 00:29:21 -07:00
|
|
|
if (!_elm_cnp_init_count) _elm_cnp_init();
|
2012-08-22 01:33:43 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
if (_x11_elm_widget_xwin_get(obj))
|
2013-11-04 05:08:53 -08:00
|
|
|
return _x11_elm_drop_target_del(obj, format, entercb, enterdata,
|
|
|
|
leavecb, leavedata, poscb, posdata, dropcb, dropdata);
|
2013-05-21 03:19:53 -07:00
|
|
|
#endif
|
2015-10-01 07:25:38 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
2014-09-08 03:51:56 -07:00
|
|
|
if (_wl_elm_widget_window_get(obj))
|
|
|
|
return _wl_elm_drop_target_del(obj, format, entercb, enterdata,
|
|
|
|
leavecb, leavedata, poscb, posdata, dropcb, dropdata);
|
2012-08-22 01:33:43 -07:00
|
|
|
#endif
|
2014-10-20 09:10:02 -07:00
|
|
|
/* FIXME: Not the best place for an error message, but meh.
|
|
|
|
* This code path is actually valid if running in framebuffer, but it still shouldn't
|
|
|
|
* be getting here because the drop target shouldn't be added. This is an error
|
|
|
|
* and it's because of some stupid handling in both the X11 and the wayland backends
|
|
|
|
* as seen in the commit that introduced this comment.
|
|
|
|
* Window check is probably not the best idea, you should be doing engine check instead. */
|
|
|
|
ERR("Please contact developers, you should probably not get here.");
|
|
|
|
return _local_elm_drop_target_del(obj, format, entercb, enterdata,
|
|
|
|
leavecb, leavedata, poscb, posdata, dropcb, dropdata);
|
2012-08-22 01:33:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
2013-02-19 04:10:02 -08:00
|
|
|
elm_drag_start(Evas_Object *obj, Elm_Sel_Format format, const char *data,
|
2013-02-22 00:49:08 -08:00
|
|
|
Elm_Xdnd_Action action,
|
2013-02-21 05:21:08 -08:00
|
|
|
Elm_Drag_Icon_Create_Cb createicon, void *createdata,
|
2013-02-22 00:49:08 -08:00
|
|
|
Elm_Drag_Pos dragpos, void *dragdata,
|
|
|
|
Elm_Drag_Accept acceptcb, void *acceptdata,
|
2013-02-21 05:21:08 -08:00
|
|
|
Elm_Drag_State dragdone, void *donecbdata)
|
2012-08-22 01:33:43 -07:00
|
|
|
{
|
2012-08-29 00:29:21 -07:00
|
|
|
if (!_elm_cnp_init_count) _elm_cnp_init();
|
2012-08-22 01:33:43 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
if (_x11_elm_widget_xwin_get(obj))
|
2013-09-30 03:21:31 -07:00
|
|
|
return _x11_elm_drag_start(obj, format, data, action,
|
|
|
|
createicon, createdata,
|
2013-02-22 00:49:08 -08:00
|
|
|
dragpos, dragdata,
|
|
|
|
acceptcb, acceptdata,
|
2013-02-19 04:10:02 -08:00
|
|
|
dragdone, donecbdata);
|
2013-05-21 03:30:39 -07:00
|
|
|
#endif
|
2015-10-01 07:25:38 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
2014-09-08 03:51:56 -07:00
|
|
|
if (_wl_elm_widget_window_get(obj))
|
|
|
|
return _wl_elm_drag_start(obj, format, data, action,
|
|
|
|
createicon, createdata,
|
|
|
|
dragpos, dragdata,
|
|
|
|
acceptcb, acceptdata,
|
|
|
|
dragdone, donecbdata);
|
2012-08-22 01:33:43 -07:00
|
|
|
#endif
|
2013-02-22 00:49:08 -08:00
|
|
|
return _local_elm_drag_start(obj, format, data, action,
|
|
|
|
createicon, createdata,
|
|
|
|
dragpos, dragdata,
|
|
|
|
acceptcb, acceptdata,
|
2013-02-19 04:10:02 -08:00
|
|
|
dragdone, donecbdata);
|
2010-09-09 01:59:38 -07:00
|
|
|
}
|
2012-08-22 01:33:43 -07:00
|
|
|
|
2013-02-22 00:49:08 -08:00
|
|
|
EAPI Eina_Bool
|
|
|
|
elm_drag_action_set(Evas_Object *obj, Elm_Xdnd_Action action)
|
|
|
|
{
|
|
|
|
if (!_elm_cnp_init_count) _elm_cnp_init();
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
if (_x11_elm_widget_xwin_get(obj))
|
|
|
|
return _x11_elm_drag_action_set(obj, action);
|
2013-05-21 03:30:39 -07:00
|
|
|
#endif
|
2015-10-01 07:25:38 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
2014-09-08 03:51:56 -07:00
|
|
|
if (_wl_elm_widget_window_get(obj))
|
|
|
|
return _wl_elm_drag_action_set(obj, action);
|
2013-02-22 00:49:08 -08:00
|
|
|
#endif
|
|
|
|
return _local_elm_drag_action_set(obj, action);
|
|
|
|
}
|
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
EAPI Eina_Bool
|
|
|
|
elm_selection_selection_has_owner(Evas_Object *obj)
|
|
|
|
{
|
2012-08-29 00:29:21 -07:00
|
|
|
if (!_elm_cnp_init_count) _elm_cnp_init();
|
2012-08-22 01:33:43 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
if (_x11_elm_widget_xwin_get(obj))
|
2012-08-22 02:37:00 -07:00
|
|
|
return _x11_elm_selection_selection_has_owner(obj);
|
2012-08-28 23:52:48 -07:00
|
|
|
#endif
|
2015-10-01 07:25:38 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
Ecore_Wl2_Window *win;
|
|
|
|
|
|
|
|
win = _wl_elm_widget_window_get(obj);
|
|
|
|
if (win)
|
|
|
|
return ecore_wl2_dnd_selection_owner_has(ecore_wl2_window_input_get(win));
|
2010-06-25 04:56:02 -07:00
|
|
|
#endif
|
2012-08-22 02:37:00 -07:00
|
|
|
return _local_elm_selection_selection_has_owner(obj);
|
2012-08-22 01:33:43 -07:00
|
|
|
}
|
2010-09-09 01:59:38 -07:00
|
|
|
|
2013-03-16 23:36:30 -07:00
|
|
|
/* START - Support elm containers for Drag and Drop */
|
|
|
|
/* START - Support elm containers for Drop */
|
|
|
|
static int
|
|
|
|
_drop_item_container_cmp(const void *d1,
|
|
|
|
const void *d2)
|
|
|
|
{
|
|
|
|
const Item_Container_Drop_Info *st = d1;
|
|
|
|
return (((uintptr_t) (st->obj)) - ((uintptr_t) d2));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_elm_item_container_pos_cb(void *data, Evas_Object *obj, Evas_Coord x, Evas_Coord y, Elm_Xdnd_Action action)
|
|
|
|
{ /* obj is the container pointer */
|
|
|
|
Elm_Object_Item *it = NULL;
|
|
|
|
int xposret = 0;
|
|
|
|
int yposret = 0;
|
2013-05-13 23:05:56 -07:00
|
|
|
|
2013-03-16 23:36:30 -07:00
|
|
|
Item_Container_Drop_Info *st =
|
|
|
|
eina_list_search_unsorted(cont_drop_tg, _drop_item_container_cmp, obj);
|
|
|
|
|
|
|
|
if (st && st->poscb)
|
|
|
|
{ /* Call container drop func with specific item pointer */
|
|
|
|
int xo = 0;
|
|
|
|
int yo = 0;
|
2015-04-03 07:04:58 -07:00
|
|
|
|
|
|
|
evas_object_geometry_get(obj, &xo, &yo, NULL, NULL);
|
2013-03-16 23:36:30 -07:00
|
|
|
if (st->itemgetcb)
|
|
|
|
it = st->itemgetcb(obj, x+xo, y+yo, &xposret, &yposret);
|
|
|
|
|
|
|
|
st->poscb(data, obj, it, x, y, xposret, yposret, action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_elm_item_container_drop_cb(void *data, Evas_Object *obj , Elm_Selection_Data *ev)
|
|
|
|
{ /* obj is the container pointer */
|
|
|
|
Elm_Object_Item *it = NULL;
|
|
|
|
int xposret = 0;
|
|
|
|
int yposret = 0;
|
2013-05-13 23:05:56 -07:00
|
|
|
|
2013-03-16 23:36:30 -07:00
|
|
|
Item_Container_Drop_Info *st =
|
|
|
|
eina_list_search_unsorted(cont_drop_tg, _drop_item_container_cmp, obj);
|
|
|
|
|
|
|
|
if (st && st->dropcb)
|
|
|
|
{ /* Call container drop func with specific item pointer */
|
|
|
|
int xo = 0;
|
|
|
|
int yo = 0;
|
2015-04-03 07:04:58 -07:00
|
|
|
|
|
|
|
evas_object_geometry_get(obj, &xo, &yo, NULL, NULL);
|
2013-03-16 23:36:30 -07:00
|
|
|
if (st->itemgetcb)
|
|
|
|
it = st->itemgetcb(obj, ev->x+xo, ev->y+yo, &xposret, &yposret);
|
|
|
|
|
|
|
|
return st->dropcb(data, obj, it, ev, xposret, yposret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
elm_drop_item_container_del_internal(Evas_Object *obj, Eina_Bool full)
|
|
|
|
{
|
|
|
|
Item_Container_Drop_Info *st =
|
|
|
|
eina_list_search_unsorted(cont_drop_tg, _drop_item_container_cmp, obj);
|
|
|
|
|
|
|
|
if (st)
|
|
|
|
{
|
2013-11-04 05:08:53 -08:00
|
|
|
// temp until st is stored inside data of obj.
|
|
|
|
_all_drop_targets_cbs_del(NULL, NULL, obj, NULL);
|
2013-03-16 23:36:30 -07:00
|
|
|
st->itemgetcb= NULL;
|
|
|
|
st->poscb = NULL;
|
|
|
|
st->dropcb = NULL;
|
|
|
|
|
|
|
|
if (full)
|
|
|
|
{
|
|
|
|
cont_drop_tg = eina_list_remove(cont_drop_tg, st);
|
|
|
|
free(st);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
2013-05-21 03:25:00 -07:00
|
|
|
|
2013-03-16 23:36:30 -07:00
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
|
|
|
elm_drop_item_container_del(Evas_Object *obj)
|
|
|
|
{
|
|
|
|
return elm_drop_item_container_del_internal(obj, EINA_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
|
|
|
elm_drop_item_container_add(Evas_Object *obj,
|
|
|
|
Elm_Sel_Format format,
|
|
|
|
Elm_Xy_Item_Get_Cb itemgetcb,
|
|
|
|
Elm_Drag_State entercb, void *enterdata,
|
|
|
|
Elm_Drag_State leavecb, void *leavedata,
|
|
|
|
Elm_Drag_Item_Container_Pos poscb, void *posdata,
|
2013-10-27 02:27:17 -07:00
|
|
|
Elm_Drop_Item_Container_Cb dropcb, void *dropdata)
|
2013-03-16 23:36:30 -07:00
|
|
|
{
|
|
|
|
Item_Container_Drop_Info *st;
|
|
|
|
|
|
|
|
if (elm_drop_item_container_del_internal(obj, EINA_FALSE))
|
|
|
|
{ /* Updating info of existing obj */
|
|
|
|
st = eina_list_search_unsorted(cont_drop_tg, _drop_item_container_cmp, obj);
|
2013-11-18 03:34:07 -08:00
|
|
|
if (!st) return EINA_FALSE;
|
2013-03-16 23:36:30 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
st = calloc(1, sizeof(*st));
|
2013-11-18 03:34:07 -08:00
|
|
|
if (!st) return EINA_FALSE;
|
|
|
|
|
2013-03-16 23:36:30 -07:00
|
|
|
st->obj = obj;
|
|
|
|
cont_drop_tg = eina_list_append(cont_drop_tg, st);
|
|
|
|
}
|
|
|
|
|
|
|
|
st->itemgetcb = itemgetcb;
|
|
|
|
st->poscb = poscb;
|
|
|
|
st->dropcb = dropcb;
|
|
|
|
elm_drop_target_add(obj, format,
|
|
|
|
entercb, enterdata,
|
|
|
|
leavecb, leavedata,
|
|
|
|
_elm_item_container_pos_cb, posdata,
|
2013-10-27 02:27:17 -07:00
|
|
|
_elm_item_container_drop_cb, dropdata);
|
2013-03-16 23:36:30 -07:00
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
/* END - Support elm containers for Drop */
|
|
|
|
|
|
|
|
/* START - Support elm containers for Drag */
|
|
|
|
static int
|
|
|
|
_drag_item_container_cmp(const void *d1,
|
|
|
|
const void *d2)
|
|
|
|
{
|
|
|
|
const Item_Container_Drag_Info *st = d1;
|
|
|
|
return (((uintptr_t) (st->obj)) - ((uintptr_t) d2));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-01-06 06:30:02 -08:00
|
|
|
_cont_drag_done_cb(void *data, Evas_Object *obj EINA_UNUSED)
|
2013-03-16 23:36:30 -07:00
|
|
|
{
|
|
|
|
Item_Container_Drag_Info *st = data;
|
|
|
|
elm_widget_scroll_freeze_pop(st->obj);
|
2013-09-30 03:21:31 -07:00
|
|
|
if (st->user_info.dragdone)
|
2013-05-13 23:05:56 -07:00
|
|
|
st->user_info.dragdone(st->user_info.donecbdata, dragwidget, doaccept);
|
2013-03-16 23:36:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_cont_obj_drag_start(void *data)
|
|
|
|
{ /* Start a drag-action when timer expires */
|
2013-10-12 20:56:04 -07:00
|
|
|
cnp_debug("In\n");
|
2013-03-16 23:36:30 -07:00
|
|
|
Item_Container_Drag_Info *st = data;
|
|
|
|
st->tm = NULL;
|
|
|
|
Elm_Drag_User_Info *info = &st->user_info;
|
2013-11-28 06:05:28 -08:00
|
|
|
if (info->dragstart) info->dragstart(info->startcbdata, st->obj);
|
2013-03-16 23:36:30 -07:00
|
|
|
elm_widget_scroll_freeze_push(st->obj);
|
|
|
|
evas_object_event_callback_del_full
|
|
|
|
(st->obj, EVAS_CALLBACK_MOUSE_MOVE, _cont_obj_mouse_move, st);
|
|
|
|
elm_drag_start( /* Commit the start only if data_get successful */
|
|
|
|
st->obj, info->format,
|
|
|
|
info->data, info->action,
|
|
|
|
info->createicon, info->createdata,
|
|
|
|
info->dragpos, info->dragdata,
|
|
|
|
info->acceptcb, info->acceptdata,
|
|
|
|
_cont_drag_done_cb, st);
|
2013-12-04 00:10:51 -08:00
|
|
|
ELM_SAFE_FREE(info->data, free);
|
2013-03-16 23:36:30 -07:00
|
|
|
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_anim_st_free(Item_Container_Drag_Info *st)
|
|
|
|
{ /* Stops and free mem of ongoing animation */
|
|
|
|
if (st)
|
|
|
|
{
|
2013-05-29 04:47:08 -07:00
|
|
|
ELM_SAFE_FREE(st->ea, ecore_animator_del);
|
2013-03-16 23:36:30 -07:00
|
|
|
Anim_Icon *sti;
|
|
|
|
|
|
|
|
EINA_LIST_FREE(st->icons, sti)
|
|
|
|
{
|
|
|
|
evas_object_del(sti->o);
|
|
|
|
free(sti);
|
|
|
|
}
|
|
|
|
|
|
|
|
st->icons = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline Eina_List *
|
|
|
|
_anim_icons_make(Eina_List *icons)
|
|
|
|
{ /* Make local copies of all icons, add them to list */
|
|
|
|
Eina_List *list = NULL, *itr;
|
|
|
|
Evas_Object *o;
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH(icons, itr, o)
|
|
|
|
{ /* Now add icons to animation window */
|
|
|
|
Anim_Icon *st = calloc(1, sizeof(*st));
|
2015-06-12 01:01:55 -07:00
|
|
|
|
|
|
|
if (!st)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate memory for icon!");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-03-16 23:36:30 -07:00
|
|
|
evas_object_geometry_get(o, &st->start_x, &st->start_y, &st->start_w, &st->start_h);
|
|
|
|
evas_object_show(o);
|
|
|
|
st->o = o;
|
|
|
|
list = eina_list_append(list, st);
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_drag_anim_play(void *data, double pos)
|
|
|
|
{ /* Impl of the animation of icons, called on frame time */
|
2013-10-12 20:56:04 -07:00
|
|
|
cnp_debug("In\n");
|
2013-03-16 23:36:30 -07:00
|
|
|
Item_Container_Drag_Info *st = data;
|
|
|
|
Eina_List *l;
|
|
|
|
Anim_Icon *sti;
|
|
|
|
|
|
|
|
if (st->ea)
|
|
|
|
{
|
|
|
|
if (pos > 0.99)
|
|
|
|
{
|
|
|
|
st->ea = NULL; /* Avoid deleting on mouse up */
|
|
|
|
EINA_LIST_FOREACH(st->icons, l, sti)
|
|
|
|
evas_object_hide(sti->o);
|
|
|
|
|
|
|
|
_cont_obj_drag_start(st); /* Start dragging */
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Evas_Coord xm, ym;
|
|
|
|
evas_pointer_canvas_xy_get(st->e, &xm, &ym);
|
|
|
|
EINA_LIST_FOREACH(st->icons, l, sti)
|
|
|
|
{
|
|
|
|
int x, y, h, w;
|
|
|
|
w = sti->start_w + ((st->final_icon_w - sti->start_w) * pos);
|
|
|
|
h = sti->start_h + ((st->final_icon_h - sti->start_h) * pos);
|
|
|
|
x = sti->start_x - (pos * ((sti->start_x + (w/2) - xm)));
|
|
|
|
y = sti->start_y - (pos * ((sti->start_y + (h/2) - ym)));
|
|
|
|
evas_object_move(sti->o, x, y);
|
|
|
|
evas_object_resize(sti->o, w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline Eina_Bool
|
|
|
|
_drag_anim_start(void *data)
|
|
|
|
{ /* Start default animation */
|
2013-10-12 20:56:04 -07:00
|
|
|
cnp_debug("In\n");
|
2013-03-16 23:36:30 -07:00
|
|
|
Item_Container_Drag_Info *st = data;
|
|
|
|
|
|
|
|
st->tm = NULL;
|
|
|
|
/* Now we need to build an (Anim_Icon *) list */
|
|
|
|
st->icons = _anim_icons_make(st->user_info.icons);
|
|
|
|
if (st->user_info.createicon)
|
|
|
|
{
|
2015-07-06 12:46:48 -07:00
|
|
|
Evas_Object *temp_win = elm_win_add(NULL, "Temp", ELM_WIN_DND);
|
2013-03-16 23:36:30 -07:00
|
|
|
Evas_Object *final_icon = st->user_info.createicon(st->user_info.createdata, temp_win, NULL, NULL);
|
|
|
|
evas_object_geometry_get(final_icon, NULL, NULL, &st->final_icon_w, &st->final_icon_h);
|
|
|
|
evas_object_del(final_icon);
|
|
|
|
evas_object_del(temp_win);
|
|
|
|
}
|
|
|
|
st->ea = ecore_animator_timeline_add(st->anim_tm, _drag_anim_play, st);
|
|
|
|
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_cont_obj_anim_start(void *data)
|
|
|
|
{ /* Start a drag-action when timer expires */
|
2013-10-12 20:56:04 -07:00
|
|
|
cnp_debug("In\n");
|
2013-03-16 23:36:30 -07:00
|
|
|
Item_Container_Drag_Info *st = data;
|
|
|
|
int xposret, yposret; /* Unused */
|
|
|
|
Elm_Object_Item *it = (st->itemgetcb) ?
|
|
|
|
(st->itemgetcb(st->obj, st->x_down, st->y_down, &xposret, &yposret))
|
|
|
|
: NULL;
|
|
|
|
|
|
|
|
st->tm = NULL;
|
|
|
|
st->user_info.format = ELM_SEL_FORMAT_TARGETS; /* Default */
|
|
|
|
st->icons = NULL;
|
|
|
|
st->user_info.data = NULL;
|
|
|
|
st->user_info.action = ELM_XDND_ACTION_COPY; /* Default */
|
|
|
|
|
|
|
|
if (!it) /* Failed to get mouse-down item, abort drag */
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
|
|
|
|
if (st->data_get)
|
|
|
|
{ /* collect info then start animation or start dragging */
|
2014-05-10 07:15:54 -07:00
|
|
|
if (st->data_get( /* Collect drag info */
|
2013-03-16 23:36:30 -07:00
|
|
|
st->obj, /* The container object */
|
|
|
|
it, /* Drag started on this item */
|
|
|
|
&st->user_info))
|
|
|
|
{
|
|
|
|
if (st->user_info.icons)
|
|
|
|
_drag_anim_start(st);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (st->anim_tm)
|
|
|
|
{
|
|
|
|
// even if we don't manage the icons animation, we have
|
|
|
|
// to wait until it is finished before beginning drag.
|
|
|
|
st->tm = ecore_timer_add(st->anim_tm, _cont_obj_drag_start, st);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_cont_obj_drag_start(st); /* Start dragging, no anim */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-01-06 06:30:02 -08:00
|
|
|
_cont_obj_mouse_down(void *data, Evas *e, Evas_Object *obj EINA_UNUSED, void *event_info)
|
2013-03-16 23:36:30 -07:00
|
|
|
{ /* Launch a timer to start dragging */
|
|
|
|
Evas_Event_Mouse_Down *ev = event_info;
|
2013-10-12 20:56:04 -07:00
|
|
|
cnp_debug("In - event %X\n", ev->event_flags);
|
2013-03-16 23:36:30 -07:00
|
|
|
if (ev->button != 1)
|
|
|
|
return; /* We only process left-click at the moment */
|
|
|
|
|
|
|
|
Item_Container_Drag_Info *st = data;
|
|
|
|
evas_object_event_callback_add(st->obj, EVAS_CALLBACK_MOUSE_MOVE,
|
|
|
|
_cont_obj_mouse_move, st);
|
|
|
|
|
|
|
|
evas_object_event_callback_add(st->obj, EVAS_CALLBACK_MOUSE_UP,
|
|
|
|
_cont_obj_mouse_up, st);
|
2013-05-21 10:24:02 -07:00
|
|
|
|
2014-01-21 06:16:41 -08:00
|
|
|
ecore_timer_del(st->tm);
|
2013-03-16 23:36:30 -07:00
|
|
|
|
|
|
|
st->e = e;
|
|
|
|
st->x_down = ev->canvas.x;
|
|
|
|
st->y_down = ev->canvas.y;
|
|
|
|
st->tm = ecore_timer_add(st->tm_to_drag, _cont_obj_anim_start, st);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool elm_drag_item_container_del_internal(Evas_Object *obj, Eina_Bool full);
|
|
|
|
|
|
|
|
static void
|
2014-01-06 06:30:02 -08:00
|
|
|
_cont_obj_mouse_move(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
|
2013-03-16 23:36:30 -07:00
|
|
|
{ /* Cancel any drag waiting to start on timeout */
|
2013-10-12 20:56:04 -07:00
|
|
|
cnp_debug("In\n");
|
2013-03-16 23:36:30 -07:00
|
|
|
if (((Evas_Event_Mouse_Move *)event_info)->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
|
|
|
|
{
|
2013-10-12 20:56:04 -07:00
|
|
|
cnp_debug("event on hold - have to cancel DnD\n");
|
2013-03-16 23:36:30 -07:00
|
|
|
Item_Container_Drag_Info *st = data;
|
2013-05-13 23:05:56 -07:00
|
|
|
|
2013-03-16 23:36:30 -07:00
|
|
|
evas_object_event_callback_del_full
|
|
|
|
(st->obj, EVAS_CALLBACK_MOUSE_MOVE, _cont_obj_mouse_move, st);
|
|
|
|
evas_object_event_callback_del_full
|
|
|
|
(st->obj, EVAS_CALLBACK_MOUSE_UP, _cont_obj_mouse_up, st);
|
|
|
|
elm_drag_item_container_del_internal(obj, EINA_FALSE);
|
|
|
|
|
2013-05-29 04:47:08 -07:00
|
|
|
ELM_SAFE_FREE(st->tm, ecore_timer_del);
|
2013-03-16 23:36:30 -07:00
|
|
|
|
|
|
|
_anim_st_free(st);
|
|
|
|
}
|
2013-10-12 20:56:04 -07:00
|
|
|
cnp_debug("Out\n");
|
2013-03-16 23:36:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-01-06 06:30:02 -08:00
|
|
|
_cont_obj_mouse_up(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
|
2013-03-16 23:36:30 -07:00
|
|
|
{ /* Cancel any drag waiting to start on timeout */
|
|
|
|
Item_Container_Drag_Info *st = data;
|
|
|
|
|
2013-10-12 20:56:04 -07:00
|
|
|
cnp_debug("In\n");
|
2013-03-16 23:36:30 -07:00
|
|
|
if (((Evas_Event_Mouse_Up *)event_info)->button != 1)
|
|
|
|
return; /* We only process left-click at the moment */
|
|
|
|
|
|
|
|
evas_object_event_callback_del_full
|
|
|
|
(st->obj, EVAS_CALLBACK_MOUSE_MOVE, _cont_obj_mouse_move, st);
|
|
|
|
evas_object_event_callback_del_full
|
|
|
|
(st->obj, EVAS_CALLBACK_MOUSE_UP, _cont_obj_mouse_up, st);
|
|
|
|
|
2013-05-29 04:47:08 -07:00
|
|
|
ELM_SAFE_FREE(st->tm, ecore_timer_del);
|
2013-03-16 23:36:30 -07:00
|
|
|
|
|
|
|
_anim_st_free(st);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
elm_drag_item_container_del_internal(Evas_Object *obj, Eina_Bool full)
|
|
|
|
{
|
|
|
|
Item_Container_Drag_Info *st =
|
|
|
|
eina_list_search_unsorted(cont_drag_tg, _drag_item_container_cmp, obj);
|
|
|
|
|
|
|
|
if (st)
|
|
|
|
{
|
2013-05-29 04:47:08 -07:00
|
|
|
ELM_SAFE_FREE(st->tm, ecore_timer_del); /* Cancel drag-start timer */
|
2013-03-16 23:36:30 -07:00
|
|
|
|
|
|
|
if (st->ea) /* Cancel ongoing default animation */
|
|
|
|
_anim_st_free(st);
|
|
|
|
|
|
|
|
if (full)
|
|
|
|
{
|
2013-05-14 07:47:41 -07:00
|
|
|
st->itemgetcb = NULL;
|
2013-03-16 23:36:30 -07:00
|
|
|
st->data_get = NULL;
|
|
|
|
evas_object_event_callback_del_full
|
|
|
|
(obj, EVAS_CALLBACK_MOUSE_DOWN, _cont_obj_mouse_down, st);
|
|
|
|
|
|
|
|
cont_drag_tg = eina_list_remove(cont_drag_tg, st);
|
2013-12-04 00:10:51 -08:00
|
|
|
ELM_SAFE_FREE(st->user_info.data, free);
|
2013-07-05 01:35:29 -07:00
|
|
|
free(st);
|
2013-03-16 23:36:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
|
|
|
elm_drag_item_container_del(Evas_Object *obj)
|
|
|
|
{
|
|
|
|
return elm_drag_item_container_del_internal(obj, EINA_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
2013-05-13 23:05:56 -07:00
|
|
|
elm_drag_item_container_add(Evas_Object *obj, double anim_tm, double tm_to_drag, Elm_Xy_Item_Get_Cb itemgetcb, Elm_Item_Container_Data_Get_Cb data_get)
|
2013-03-16 23:36:30 -07:00
|
|
|
{
|
|
|
|
Item_Container_Drag_Info *st;
|
|
|
|
|
|
|
|
if (elm_drag_item_container_del_internal(obj, EINA_FALSE))
|
|
|
|
{ /* Updating info of existing obj */
|
|
|
|
st = eina_list_search_unsorted(cont_drag_tg, _drag_item_container_cmp, obj);
|
2013-11-18 03:34:07 -08:00
|
|
|
if (!st) return EINA_FALSE;
|
2013-03-16 23:36:30 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
st = calloc(1, sizeof(*st));
|
2013-11-18 03:34:07 -08:00
|
|
|
if (!st) return EINA_FALSE;
|
|
|
|
|
2013-03-16 23:36:30 -07:00
|
|
|
st->obj = obj;
|
|
|
|
cont_drag_tg = eina_list_append(cont_drag_tg, st);
|
|
|
|
|
|
|
|
/* Register for mouse callback for container to start/abort drag */
|
|
|
|
evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN,
|
|
|
|
_cont_obj_mouse_down, st);
|
|
|
|
}
|
|
|
|
|
|
|
|
st->tm = NULL;
|
|
|
|
st->anim_tm = anim_tm;
|
|
|
|
st->tm_to_drag = tm_to_drag;
|
|
|
|
st->itemgetcb = itemgetcb;
|
|
|
|
st->data_get = data_get;
|
2013-05-21 03:25:00 -07:00
|
|
|
|
2013-03-16 23:36:30 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
/* END - Support elm containers for Drag */
|
|
|
|
/* END - Support elm containers for Drag and Drop */
|
2013-11-28 06:06:46 -08:00
|
|
|
|
|
|
|
EAPI Eina_Bool
|
|
|
|
elm_drag_cancel(Evas_Object *obj)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
Ecore_X_Window xwin = _x11_elm_widget_xwin_get(obj);
|
|
|
|
if (xwin)
|
|
|
|
{
|
|
|
|
ecore_x_pointer_ungrab();
|
|
|
|
ELM_SAFE_FREE(handler_up, ecore_event_handler_del);
|
|
|
|
ELM_SAFE_FREE(handler_status, ecore_event_handler_del);
|
|
|
|
ecore_x_dnd_abort(xwin);
|
2015-02-25 00:35:43 -08:00
|
|
|
if (dragwidget)
|
2014-06-10 22:19:27 -07:00
|
|
|
{
|
2015-02-25 00:35:43 -08:00
|
|
|
if (elm_widget_is(dragwidget))
|
|
|
|
{
|
|
|
|
Evas_Object *win = elm_widget_top_get(dragwidget);
|
|
|
|
if (win && eo_isa(win, ELM_WIN_CLASS))
|
2016-03-02 04:10:48 -08:00
|
|
|
eo_event_callback_del(win, ELM_WIN_EVENT_ROTATION_CHANGED, _x11_win_rotation_changed_cb, dragwin);
|
2015-02-25 00:35:43 -08:00
|
|
|
}
|
2014-06-10 22:19:27 -07:00
|
|
|
}
|
2015-02-25 00:35:43 -08:00
|
|
|
goto end;
|
2014-06-10 22:19:27 -07:00
|
|
|
}
|
2013-11-28 06:06:46 -08:00
|
|
|
#endif
|
2015-10-01 07:25:38 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_WL2
|
|
|
|
Ecore_Wl2_Window *win;
|
|
|
|
|
|
|
|
win = _wl_elm_widget_window_get(obj);
|
|
|
|
if (win)
|
|
|
|
ecore_wl2_dnd_drag_end(ecore_wl2_window_input_get(win));
|
2013-11-28 06:06:46 -08:00
|
|
|
#endif
|
|
|
|
|
2015-02-25 00:35:43 -08:00
|
|
|
end:
|
2013-11-28 06:06:46 -08:00
|
|
|
ELM_SAFE_FREE(dragwin, evas_object_del);
|
|
|
|
dragdonecb = NULL;
|
|
|
|
dragacceptcb = NULL;
|
|
|
|
dragposcb = NULL;
|
|
|
|
dragwidget = NULL;
|
|
|
|
doaccept = EINA_FALSE;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
2015-10-09 08:18:20 -07:00
|
|
|
|