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>
|
|
|
|
#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
|
|
|
|
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_uri,
|
|
|
|
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;
|
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;
|
|
|
|
};
|
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
struct _Dropable
|
|
|
|
{
|
2012-05-09 01:43:45 -07:00
|
|
|
Evas_Object *obj;
|
2010-12-20 03:09:19 -08:00
|
|
|
/* FIXME: Cache window */
|
2011-12-27 03:24:13 -08:00
|
|
|
Elm_Sel_Format types;
|
2012-05-09 01:43:45 -07:00
|
|
|
Elm_Drop_Cb dropcb;
|
|
|
|
void *cbdata;
|
2010-12-20 03:09:19 -08:00
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
/* Data for DND in progress */
|
|
|
|
static Saved_Type savedtypes = { NULL, NULL, 0, 0, 0, EINA_FALSE };
|
|
|
|
|
|
|
|
/* TODO BUG: should NEVER have these as globals! They should be per context (window). */
|
|
|
|
static void (*dragdonecb) (void *data, Evas_Object *obj) = NULL;
|
|
|
|
static void *dragdonedata = NULL;
|
|
|
|
|
|
|
|
/* Drag & Drop functions */
|
|
|
|
/* FIXME: Way too many globals */
|
|
|
|
static Eina_List *drops = NULL;
|
|
|
|
static Evas_Object *dragwin = NULL;
|
|
|
|
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;
|
2013-02-19 04:10:02 -08:00
|
|
|
static Ecore_Event_Handler *handler_up = NULL;
|
2012-08-22 01:33:43 -07:00
|
|
|
|
|
|
|
static Tmp_Info *_tempfile_new (int size);
|
|
|
|
static int _tmpinfo_free (Tmp_Info *tmp);
|
|
|
|
static Eina_Bool _pasteimage_append (char *file, Evas_Object *entry);
|
|
|
|
|
2013-02-19 04:10:02 -08:00
|
|
|
//#define DEBUGON 1
|
2012-08-22 01:33:43 -07:00
|
|
|
#ifdef DEBUGON
|
|
|
|
# define cnp_debug(x...) fprintf(stderr, __FILE__": " x)
|
|
|
|
#else
|
|
|
|
# define cnp_debug(x...) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
2012-08-28 23:52:48 -07:00
|
|
|
// x11 specific stuff
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifdef HAVE_ELEMENTARY_X
|
|
|
|
#define ARRAYINIT(foo) [foo] =
|
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
typedef struct _X11_Cnp_Selection X11_Cnp_Selection;
|
|
|
|
typedef struct _X11_Cnp_Atom X11_Cnp_Atom;
|
|
|
|
|
|
|
|
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 *);
|
|
|
|
typedef int (*X11_Notify_Handler_Cb) (X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *);
|
|
|
|
|
|
|
|
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;
|
2010-06-17 01:06:07 -07:00
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
Elm_Sel_Format format;
|
|
|
|
Ecore_X_Selection ecore_sel;
|
|
|
|
Ecore_X_Window xwin;
|
2010-12-20 03:09:19 -08:00
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
Eina_Bool active : 1;
|
|
|
|
};
|
2010-12-20 03:09:19 -08:00
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
struct _X11_Cnp_Atom
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
Elm_Sel_Format formats;
|
|
|
|
/* Called by ecore to do conversion */
|
|
|
|
X11_Converter_Fn_Cb converter;
|
|
|
|
X11_Response_Handler_Cb response;
|
|
|
|
X11_Notify_Handler_Cb notify;
|
|
|
|
/* Atom */
|
|
|
|
Ecore_X_Atom atom;
|
|
|
|
};
|
2010-12-20 03:09:19 -08:00
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
static void _x11_sel_obj_del (void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
|
|
|
|
static void _x11_sel_obj_del2 (void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
|
|
|
|
static Eina_Bool _x11_selection_clear (void *udata __UNUSED__, int type, void *event);
|
|
|
|
static Eina_Bool _x11_selection_notify (void *udata __UNUSED__, int type, void *event);
|
|
|
|
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);
|
|
|
|
static Eina_Bool _x11_is_uri_type_data (X11_Cnp_Selection *sel __UNUSED__, Ecore_X_Event_Selection_Notify *notify);
|
|
|
|
static int _x11_response_handler_targets (X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *);
|
|
|
|
static int _x11_notify_handler_targets (X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
|
|
|
|
static int _x11_notify_handler_text (X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
|
|
|
|
static int _x11_notify_handler_image (X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
|
|
|
|
static int _x11_notify_handler_uri (X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
|
|
|
|
//static int _x11_notify_handler_html (X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
|
|
|
|
static int _x11_vcard_receive (X11_Cnp_Selection *sed, Ecore_X_Event_Selection_Notify *notify);
|
2012-08-22 02:37:00 -07:00
|
|
|
static Eina_Bool _x11_dnd_enter (void *data __UNUSED__, int etype __UNUSED__, void *ev);
|
|
|
|
static Eina_Bool _x11_dnd_drop (void *data __UNUSED__, int etype __UNUSED__, void *ev);
|
|
|
|
static Eina_Bool _x11_dnd_position (void *data __UNUSED__, int etype __UNUSED__, void *ev);
|
|
|
|
static Eina_Bool _x11_dnd_status (void *data __UNUSED__, int etype __UNUSED__, void *ev);
|
2013-02-19 04:10:02 -08:00
|
|
|
static Eina_Bool _x11_drag_mouse_up (void *data, int etype __UNUSED__, void *event);
|
2012-08-22 02:37:00 -07:00
|
|
|
static void _x11_drag_move (void *data __UNUSED__, Ecore_X_Xdnd_Position *pos);
|
|
|
|
|
|
|
|
static Ecore_X_Window _x11_elm_widget_xwin_get (const Evas_Object *obj);
|
|
|
|
|
|
|
|
static Eina_Bool _x11_elm_cnp_init (void);
|
|
|
|
static Eina_Bool _x11_elm_cnp_selection_set (Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format, const void *selbuf, size_t buflen);
|
|
|
|
static void _x11_elm_cnp_selection_loss_callback_set(Evas_Object *obj __UNUSED__, Elm_Sel_Type selection, Elm_Selection_Loss_Cb func, const void *data);
|
|
|
|
static Eina_Bool _x11_elm_object_cnp_selection_clear (Evas_Object *obj, Elm_Sel_Type selection);
|
|
|
|
static Eina_Bool _x11_elm_cnp_selection_get (Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format, Elm_Drop_Cb datacb, void *udata);
|
2013-02-19 02:14:35 -08:00
|
|
|
static Eina_Bool _x11_elm_drop_target_add (Evas_Object *obj, Elm_Sel_Format format, Elm_Drop_Cb dropcb, void *cbdata);
|
2012-08-22 02:37:00 -07:00
|
|
|
static Eina_Bool _x11_elm_drop_target_del (Evas_Object *obj);
|
|
|
|
static Eina_Bool _x11_elm_selection_selection_has_owner (Evas_Object *obj __UNUSED__);
|
2012-08-22 01:33:43 -07:00
|
|
|
|
|
|
|
static X11_Cnp_Atom _x11_atoms[CNP_N_ATOMS] = {
|
2012-06-25 04:16:25 -07:00
|
|
|
[CNP_ATOM_TARGETS] = {
|
|
|
|
"TARGETS",
|
|
|
|
ELM_SEL_FORMAT_TARGETS,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_targets_converter,
|
|
|
|
_x11_response_handler_targets,
|
|
|
|
_x11_notify_handler_targets,
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
|
|
|
[CNP_ATOM_ATOM] = {
|
|
|
|
"ATOM", // for opera browser
|
|
|
|
ELM_SEL_FORMAT_TARGETS,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_targets_converter,
|
|
|
|
_x11_response_handler_targets,
|
|
|
|
_x11_notify_handler_targets,
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
|
|
|
[CNP_ATOM_XELM] = {
|
|
|
|
"application/x-elementary-markup",
|
|
|
|
ELM_SEL_FORMAT_MARKUP,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_general_converter,
|
2012-06-25 04:16:25 -07:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0
|
|
|
|
},
|
|
|
|
[CNP_ATOM_text_uri] = {
|
|
|
|
"text/uri",
|
|
|
|
ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE, /* Either images or entries */
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_general_converter,
|
2012-06-25 04:16:25 -07:00
|
|
|
NULL,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_uri,
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
|
|
|
[CNP_ATOM_text_urilist] = {
|
|
|
|
"text/uri-list",
|
|
|
|
ELM_SEL_FORMAT_IMAGE,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_general_converter,
|
2012-06-25 04:16:25 -07:00
|
|
|
NULL,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_uri,
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
|
|
|
[CNP_ATOM_text_x_vcard] = {
|
|
|
|
"text/x-vcard",
|
|
|
|
ELM_SEL_FORMAT_VCARD,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_vcard_send, NULL,
|
|
|
|
_x11_vcard_receive, 0
|
2012-06-25 04:16:25 -07:00
|
|
|
},
|
|
|
|
[CNP_ATOM_image_png] = {
|
|
|
|
"image/png",
|
|
|
|
ELM_SEL_FORMAT_IMAGE,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_image_converter,
|
2012-06-25 04:16:25 -07:00
|
|
|
NULL,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_image,
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
|
|
|
[CNP_ATOM_image_jpeg] = {
|
|
|
|
"image/jpeg",
|
|
|
|
ELM_SEL_FORMAT_IMAGE,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_image_converter,
|
2012-06-25 04:16:25 -07:00
|
|
|
NULL,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_image,/* Raw image data is the same */
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
|
|
|
[CNP_ATOM_image_bmp] = {
|
|
|
|
"image/x-ms-bmp",
|
|
|
|
ELM_SEL_FORMAT_IMAGE,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_image_converter,
|
2012-06-25 04:16:25 -07:00
|
|
|
NULL,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_image,/* Raw image data is the same */
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
|
|
|
[CNP_ATOM_image_gif] = {
|
|
|
|
"image/gif",
|
|
|
|
ELM_SEL_FORMAT_IMAGE,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_image_converter,
|
2012-06-25 04:16:25 -07:00
|
|
|
NULL,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_image,/* Raw image data is the same */
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
|
|
|
[CNP_ATOM_image_tiff] = {
|
|
|
|
"image/tiff",
|
|
|
|
ELM_SEL_FORMAT_IMAGE,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_image_converter,
|
2012-06-25 04:16:25 -07:00
|
|
|
NULL,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_image,/* Raw image data is the same */
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
|
|
|
[CNP_ATOM_image_svg] = {
|
|
|
|
"image/svg+xml",
|
|
|
|
ELM_SEL_FORMAT_IMAGE,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_image_converter,
|
2012-06-25 04:16:25 -07:00
|
|
|
NULL,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_image,/* Raw image data is the same */
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
|
|
|
[CNP_ATOM_image_xpm] = {
|
|
|
|
"image/x-xpixmap",
|
|
|
|
ELM_SEL_FORMAT_IMAGE,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_image_converter,
|
2012-06-25 04:16:25 -07:00
|
|
|
NULL,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_image,/* Raw image data is the same */
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
|
|
|
[CNP_ATOM_image_tga] = {
|
|
|
|
"image/x-tga",
|
|
|
|
ELM_SEL_FORMAT_IMAGE,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_image_converter,
|
2012-06-25 04:16:25 -07:00
|
|
|
NULL,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_image,/* Raw image data is the same */
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
|
|
|
[CNP_ATOM_image_ppm] = {
|
|
|
|
"image/x-portable-pixmap",
|
|
|
|
ELM_SEL_FORMAT_IMAGE,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_image_converter,
|
2012-06-25 04:16:25 -07:00
|
|
|
NULL,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_image,/* Raw image data is the same */
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
2012-07-16 02:16:30 -07:00
|
|
|
/*
|
2012-06-25 04:16:25 -07:00
|
|
|
[CNP_ATOM_text_html_utf8] = {
|
|
|
|
"text/html;charset=utf-8",
|
|
|
|
ELM_SEL_FORMAT_HTML,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_general_converter,
|
2012-06-25 04:16:25 -07:00
|
|
|
NULL,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_html,
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
|
|
|
[CNP_ATOM_text_html] = {
|
|
|
|
"text/html",
|
|
|
|
ELM_SEL_FORMAT_HTML,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_general_converter,
|
2012-06-25 04:16:25 -07:00
|
|
|
NULL,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_html, // No encoding: Webkit only
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
2012-07-16 02:16:30 -07:00
|
|
|
*/
|
2012-06-25 04:16:25 -07:00
|
|
|
[CNP_ATOM_UTF8STRING] = {
|
|
|
|
"UTF8_STRING",
|
|
|
|
ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_text_converter,
|
2012-06-25 04:16:25 -07:00
|
|
|
NULL,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_text,
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
|
|
|
[CNP_ATOM_STRING] = {
|
|
|
|
"STRING",
|
|
|
|
ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_text_converter,
|
2012-06-25 04:16:25 -07:00
|
|
|
NULL,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_text,
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
2012-10-04 16:19:05 -07:00
|
|
|
[CNP_ATOM_COMPOUND_TEXT] = {
|
|
|
|
"COMPOUND_TEXT",
|
|
|
|
ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
|
|
|
|
_x11_text_converter,
|
|
|
|
NULL,
|
2013-02-19 02:48:37 -08:00
|
|
|
_x11_notify_handler_text,
|
2012-10-04 16:19:05 -07:00
|
|
|
0
|
|
|
|
},
|
2012-06-25 04:16:25 -07:00
|
|
|
[CNP_ATOM_TEXT] = {
|
|
|
|
"TEXT",
|
|
|
|
ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_text_converter,
|
2012-06-25 04:16:25 -07:00
|
|
|
NULL,
|
2013-02-19 02:48:37 -08:00
|
|
|
_x11_notify_handler_text,
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
|
|
|
[CNP_ATOM_text_plain_utf8] = {
|
|
|
|
"text/plain;charset=utf-8",
|
|
|
|
ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_text_converter,
|
2012-06-25 04:16:25 -07:00
|
|
|
NULL,
|
2013-02-19 02:14:35 -08:00
|
|
|
_x11_notify_handler_text,
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
|
|
|
[CNP_ATOM_text_plain] = {
|
|
|
|
"text/plain",
|
|
|
|
ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_text_converter,
|
2012-06-25 04:16:25 -07:00
|
|
|
NULL,
|
2013-02-19 02:14:35 -08:00
|
|
|
_x11_notify_handler_text,
|
2012-06-25 04:16:25 -07:00
|
|
|
0
|
|
|
|
},
|
2010-06-17 01:06:07 -07:00
|
|
|
};
|
|
|
|
|
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
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_sel_obj_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __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->widget == obj) sel->widget = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_sel_obj_del2(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __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
|
|
|
|
_x11_selection_clear(void *udata __UNUSED__, int type __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;
|
|
|
|
|
|
|
|
sel->active = EINA_FALSE;
|
2012-08-22 01:33:43 -07:00
|
|
|
sel->widget = NULL;
|
2011-12-27 03:24:13 -08:00
|
|
|
if (sel->selbuf)
|
2011-12-28 04:54:59 -08:00
|
|
|
{
|
|
|
|
free(sel->selbuf);
|
|
|
|
sel->selbuf = NULL;
|
|
|
|
}
|
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
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_selection_notify(void *udata __UNUSED__, int type __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);
|
2012-08-22 01:33:43 -07:00
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
for (i = 0; i < CNP_N_ATOMS; i++)
|
2010-06-23 01:02:35 -07:00
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
if (!strcmp(ev->target, _x11_atoms[i].name))
|
2011-04-01 04:35:07 -07:00
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
if (_x11_atoms[i].notify)
|
2010-12-20 03:09:19 -08:00
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
cnp_debug("Found something: %s\n", _x11_atoms[i].name);
|
|
|
|
_x11_atoms[i].notify(sel, ev);
|
2010-12-20 03:09:19 -08:00
|
|
|
}
|
2012-08-22 01:33:43 -07:00
|
|
|
else cnp_debug("Ignored: No handler!\n");
|
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
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_targets_converter(char *target __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
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
for (i = 0, count = 0; i < CNP_N_ATOMS ; i++)
|
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
if (seltype & _x11_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;
|
2010-12-20 03:09:19 -08:00
|
|
|
for (i = 0, count = 0; i < CNP_N_ATOMS; i++)
|
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
if (seltype & _x11_atoms[i].formats)
|
|
|
|
aret[count ++] = _x11_atoms[i].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
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_image_converter(char *target __UNUSED__, void *data __UNUSED__, int size __UNUSED__, void **data_ret __UNUSED__, int *size_ret __UNUSED__, Ecore_X_Atom *ttype __UNUSED__, int *typesize __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
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_vcard_send(char *target __UNUSED__, void *data __UNUSED__, int size __UNUSED__, void **data_ret, int *size_ret, Ecore_X_Atom *ttype __UNUSED__, int *typesize __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
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_is_uri_type_data(X11_Cnp_Selection *sel __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);
|
|
|
|
if (strncmp(p, "file://", 7))
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
static int
|
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
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
cnp_debug("\t%s %d\n", _x11_atoms[j].name, _x11_atoms[j].atom);
|
|
|
|
if (!(_x11_atoms[j].formats & sel->requestformat)) continue;
|
2011-04-01 04:35:07 -07:00
|
|
|
for (i = 0; i < targets->data.length; i++)
|
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
if ((_x11_atoms[j].atom == atomlist[i]) && (_x11_atoms[j].notify))
|
2011-04-01 04:35:07 -07:00
|
|
|
{
|
2011-06-22 22:52:40 -07:00
|
|
|
if ((j == CNP_ATOM_text_uri) ||
|
|
|
|
(j == CNP_ATOM_text_urilist))
|
|
|
|
{
|
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
|
|
|
}
|
2012-08-22 01:33:43 -07:00
|
|
|
cnp_debug("Atom %s matches\n", _x11_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",
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_atoms[j].name, (unsigned long long)sel->xwin);
|
|
|
|
sel->request(sel->xwin, _x11_atoms[j].name);
|
2010-06-30 06:20:58 -07:00
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
|
|
|
}
|
2010-06-17 01:06:07 -07:00
|
|
|
|
2010-06-23 01:02:35 -07:00
|
|
|
static int
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_response_handler_targets(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
|
2010-08-18 12:18:42 -07:00
|
|
|
{
|
2010-06-23 01:02:35 -07:00
|
|
|
Ecore_X_Selection_Data_Targets *targets;
|
|
|
|
Ecore_X_Atom *atomlist;
|
2012-08-22 01:33:43 -07:00
|
|
|
int i, j;
|
2010-06-23 01:02:35 -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-23 01:02:35 -07:00
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
if (!(_x11_atoms[j].formats & sel->requestformat)) continue;
|
|
|
|
for (i = 0; i < targets->data.length; i++)
|
2011-04-01 04:35:07 -07:00
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
if ((_x11_atoms[j].atom == atomlist[i]) &&
|
|
|
|
(_x11_atoms[j].response))
|
|
|
|
goto found;
|
2010-12-20 03:09:19 -08:00
|
|
|
}
|
2010-06-23 01:02:35 -07:00
|
|
|
}
|
2011-12-28 04:54:59 -08:00
|
|
|
cnp_debug("No matching type found\n");
|
|
|
|
return 0;
|
|
|
|
found:
|
2012-08-22 01:33:43 -07:00
|
|
|
sel->request(sel->xwin, _x11_atoms[j].name);
|
2010-06-23 01:02:35 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_text(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 *data;
|
2013-02-19 02:14:35 -08:00
|
|
|
Eina_List *l;
|
|
|
|
Dropable *dropable;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-06-30 06:20:58 -07:00
|
|
|
data = notify->data;
|
2013-02-19 02:14:35 -08:00
|
|
|
if (sel == (_x11_selections + ELM_SEL_TYPE_XDND))
|
|
|
|
{
|
|
|
|
Elm_Selection_Data ddata;
|
|
|
|
|
|
|
|
cnp_debug("drag & drop\n");
|
|
|
|
/* FIXME: this needs to be generic: Used for all receives */
|
|
|
|
EINA_LIST_FOREACH(drops, l, dropable)
|
|
|
|
{
|
|
|
|
if (dropable->obj == sel->requestwidget) break;
|
|
|
|
dropable = NULL;
|
|
|
|
}
|
|
|
|
if (dropable)
|
|
|
|
{
|
|
|
|
ddata.x = savedtypes.x;
|
|
|
|
ddata.y = savedtypes.y;
|
|
|
|
ddata.format = ELM_SEL_FORMAT_TEXT;
|
|
|
|
ddata.data = data->data;
|
|
|
|
ddata.len = data->length;
|
|
|
|
dropable->dropcb(dropable->cbdata, dropable->obj, &ddata);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
2011-06-20 00:13:50 -07:00
|
|
|
if (sel->datacb)
|
|
|
|
{
|
|
|
|
Elm_Selection_Data ddata;
|
|
|
|
|
|
|
|
ddata.x = ddata.y = 0;
|
|
|
|
ddata.format = ELM_SEL_FORMAT_TEXT;
|
|
|
|
ddata.data = data->data;
|
|
|
|
ddata.len = data->length;
|
|
|
|
sel->datacb(sel->udata, sel->widget, &ddata);
|
2012-10-04 16:17:28 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *stripstr, *mkupstr;
|
|
|
|
|
|
|
|
stripstr = malloc(data->length + 1);
|
2013-02-19 02:14:35 -08:00
|
|
|
if (!stripstr) goto end;
|
2012-10-04 16:17:28 -07:00
|
|
|
strncpy(stripstr, (char *)data->data, data->length);
|
|
|
|
stripstr[data->length] = '\0';
|
|
|
|
cnp_debug("Notify handler text %d %d %p\n", data->format,
|
|
|
|
data->length, data->data);
|
|
|
|
mkupstr = _elm_util_text_to_mkup((const char *)stripstr);
|
|
|
|
cnp_debug("String is %s (from %s)\n", stripstr, data->data);
|
|
|
|
/* TODO BUG: should never NEVER assume it's an elm_entry! */
|
|
|
|
_elm_entry_entry_paste(sel->requestwidget, mkupstr);
|
2012-05-22 19:15:56 -07:00
|
|
|
free(stripstr);
|
2012-10-04 16:17:28 -07:00
|
|
|
free(mkupstr);
|
2011-06-20 00:13:50 -07:00
|
|
|
}
|
2013-02-19 02:14:35 -08:00
|
|
|
end:
|
|
|
|
if (sel == (_x11_selections + ELM_SEL_TYPE_XDND))
|
|
|
|
ecore_x_dnd_send_finished();
|
2010-06-23 01:02:35 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-30 06:20:58 -07:00
|
|
|
/**
|
|
|
|
* So someone is pasting an image into my entry or widget...
|
|
|
|
*/
|
|
|
|
static int
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_uri(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
|
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;
|
|
|
|
|
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");
|
|
|
|
return 0;
|
|
|
|
}
|
2011-09-30 01:48:25 -07:00
|
|
|
stripstr = p = strdup(files->files[0]);
|
2013-02-19 02:14:35 -08:00
|
|
|
*/
|
|
|
|
for (i = 0; i < files->num_files ; i++)
|
|
|
|
{
|
|
|
|
p = files->files[i];
|
|
|
|
if ((strncmp(p, "file://", 7)) && (p[0] != '/')) continue;
|
|
|
|
len += strlen(files->files[i]) + 1;
|
|
|
|
}
|
|
|
|
p = NULL;
|
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
s = stripstr = malloc(len + 1);
|
|
|
|
for (i = 0; i < files->num_files ; i++)
|
|
|
|
{
|
|
|
|
p = files->files[i];
|
|
|
|
if (!strncmp(p, "file://", 7)) p += 7;
|
|
|
|
else if (p[0] != '/') continue;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-06 23:56:16 -07:00
|
|
|
}
|
2011-03-31 05:29:20 -07:00
|
|
|
else
|
|
|
|
{
|
2013-02-19 02:14:35 -08:00
|
|
|
p = (char *)data->data;
|
|
|
|
if ((!strncmp(p, "file://", 7)) || (p[0] == '/'))
|
|
|
|
{
|
|
|
|
int len = data->length;
|
|
|
|
if (!strncmp(p, "file://", 7))
|
|
|
|
{
|
|
|
|
p += 7;
|
|
|
|
len -= 7;
|
|
|
|
}
|
|
|
|
stripstr = malloc(len + 1);
|
|
|
|
if (!stripstr) return 0;
|
|
|
|
memcpy(stripstr, p, len);
|
|
|
|
stripstr[len] = 0;
|
|
|
|
}
|
2011-03-31 05:29:20 -07: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");
|
|
|
|
return 0;
|
2010-12-20 03:09:19 -08:00
|
|
|
}
|
2012-08-22 01:33:43 -07:00
|
|
|
if (savedtypes.imgfile) 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
|
|
|
|
{
|
|
|
|
_pasteimage_append(p, sel->requestwidget);
|
|
|
|
free(stripstr);
|
2010-09-06 23:56:16 -07:00
|
|
|
}
|
2010-06-30 06:20:58 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-16 22:39:00 -07:00
|
|
|
/**
|
|
|
|
* Just receieved an vcard, either through cut and paste, or dnd.
|
|
|
|
*/
|
|
|
|
static int
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_vcard_receive(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
|
2010-09-16 22:39:00 -07:00
|
|
|
{
|
2010-12-20 03:09:19 -08:00
|
|
|
Dropable *dropable;
|
2010-09-16 22:39:00 -07:00
|
|
|
Eina_List *l;
|
|
|
|
Ecore_X_Selection_Data *data;
|
|
|
|
|
|
|
|
data = notify->data;
|
|
|
|
cnp_debug("vcard receive\n");
|
2012-08-22 01:33:43 -07:00
|
|
|
if (sel == (_x11_selections + ELM_SEL_TYPE_XDND))
|
2010-10-17 21:49:00 -07:00
|
|
|
{
|
2010-10-17 21:48:44 -07:00
|
|
|
Elm_Selection_Data ddata;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-09-16 22:39:00 -07:00
|
|
|
cnp_debug("drag & drop\n");
|
|
|
|
/* FIXME: this needs to be generic: Used for all receives */
|
|
|
|
EINA_LIST_FOREACH(drops, l, dropable)
|
2010-12-20 03:09:19 -08:00
|
|
|
{
|
|
|
|
if (dropable->obj == sel->requestwidget) break;
|
|
|
|
}
|
2010-09-16 22:39:00 -07:00
|
|
|
if (!dropable)
|
|
|
|
{
|
|
|
|
cnp_debug("Unable to find drop object");
|
|
|
|
ecore_x_dnd_send_finished();
|
|
|
|
return 0;
|
2010-12-20 03:09:19 -08:00
|
|
|
}
|
2010-10-14 07:12:26 -07:00
|
|
|
dropable = eina_list_data_get(l);
|
2010-09-16 22:39:00 -07:00
|
|
|
ddata.x = savedtypes.x;
|
|
|
|
ddata.y = savedtypes.y;
|
|
|
|
ddata.format = ELM_SEL_FORMAT_VCARD;
|
|
|
|
ddata.data = data->data;
|
|
|
|
ddata.len = data->length;
|
|
|
|
dropable->dropcb(dropable->cbdata, dropable->obj, &ddata);
|
|
|
|
ecore_x_dnd_send_finished();
|
2010-10-17 21:49:00 -07:00
|
|
|
}
|
|
|
|
else if (sel->datacb)
|
|
|
|
{
|
|
|
|
Elm_Selection_Data ddata;
|
|
|
|
ddata.x = ddata.y = 0;
|
2012-07-11 03:08:46 -07:00
|
|
|
ddata.format = ELM_SEL_FORMAT_VCARD;
|
2010-10-17 21:49:00 -07:00
|
|
|
ddata.data = data->data;
|
|
|
|
ddata.len = data->length;
|
|
|
|
sel->datacb(sel->udata, sel->widget, &ddata);
|
|
|
|
}
|
2012-08-22 01:33:43 -07:00
|
|
|
else cnp_debug("Paste request\n");
|
2010-09-16 22:39:00 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-30 06:20:58 -07:00
|
|
|
static int
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_notify_handler_image(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
|
2010-06-30 06:20:58 -07:00
|
|
|
{
|
2010-09-06 23:56:16 -07:00
|
|
|
Ecore_X_Selection_Data *data;
|
2010-12-20 03:09:19 -08:00
|
|
|
Tmp_Info *tmp;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2011-12-28 04:54:59 -08:00
|
|
|
cnp_debug("got a image file!\n");
|
2010-09-06 23:56:16 -07:00
|
|
|
data = notify->data;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
cnp_debug("Size if %d\n", data->length);
|
2010-10-17 21:49:00 -07:00
|
|
|
if (sel->datacb)
|
|
|
|
{
|
2010-12-20 03:09:19 -08:00
|
|
|
Elm_Selection_Data ddata;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-10-17 21:49:00 -07:00
|
|
|
ddata.x = ddata.y = 0;
|
|
|
|
ddata.format = ELM_SEL_FORMAT_IMAGE;
|
|
|
|
ddata.data = data->data;
|
|
|
|
ddata.len = data->length;
|
|
|
|
sel->datacb(sel->udata, sel->widget, &ddata);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-09-06 23:56:16 -07:00
|
|
|
/* generate tmp name */
|
2012-08-22 01:33:43 -07:00
|
|
|
tmp = _tempfile_new(data->length);
|
2012-12-10 00:01:16 -08:00
|
|
|
if (!tmp) return 0;
|
2010-09-21 21:42:41 -07:00
|
|
|
memcpy(tmp->map, data->data, data->length);
|
2011-12-28 04:54:59 -08:00
|
|
|
munmap(tmp->map, data->length);
|
2010-09-06 23:56:16 -07:00
|
|
|
/* FIXME: Add to paste image data to clean up */
|
2012-08-22 01:33:43 -07:00
|
|
|
_pasteimage_append(tmp->filename, sel->requestwidget);
|
|
|
|
_tmpinfo_free(tmp);
|
2010-09-26 21:25:26 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
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);
|
|
|
|
if (size_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);
|
|
|
|
*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
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_general_converter(char *target __UNUSED__, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype __UNUSED__, int *typesize __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);
|
2011-12-20 00:37:26 -08: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-06-17 01:06:07 -07:00
|
|
|
}
|
|
|
|
|
2010-09-06 23:56:16 -07:00
|
|
|
static Eina_Bool
|
2012-08-22 02:37:00 -07:00
|
|
|
_x11_dnd_enter(void *data __UNUSED__, int etype __UNUSED__, void *ev)
|
2010-09-06 23:56:16 -07:00
|
|
|
{
|
|
|
|
Ecore_X_Event_Xdnd_Enter *enter = ev;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Skip it */
|
2012-06-19 16:33:57 -07:00
|
|
|
cnp_debug("enter %p\n", enter);
|
|
|
|
cnp_debug("enter types=%p (%d)\n", enter->types, enter->num_types);
|
2010-10-22 14:41:22 -07:00
|
|
|
if ((!enter) || (!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;
|
|
|
|
if (savedtypes.types) free(savedtypes.types);
|
|
|
|
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;
|
2012-08-22 01:33:43 -07:00
|
|
|
if (savedtypes.imgfile) free(savedtypes.imgfile);
|
2011-06-20 00:13:50 -07:00
|
|
|
savedtypes.imgfile = NULL;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2012-08-22 02:37:00 -07:00
|
|
|
_x11_dnd_drop(void *data __UNUSED__, int etype __UNUSED__, void *ev)
|
2010-09-06 23:56:16 -07:00
|
|
|
{
|
|
|
|
struct _Ecore_X_Event_Xdnd_Drop *drop;
|
2010-12-20 03:09:19 -08:00
|
|
|
Dropable *dropable;
|
2010-09-06 23:56:16 -07:00
|
|
|
Eina_List *l;
|
2010-09-07 21:55:12 -07:00
|
|
|
Ecore_Evas *ee;
|
2010-09-06 23:56:16 -07:00
|
|
|
Ecore_X_Window xwin;
|
2010-10-17 21:48:44 -07:00
|
|
|
Elm_Selection_Data ddata;
|
2010-12-20 03:09:19 -08:00
|
|
|
int x, y, w, h;
|
|
|
|
int i, j;
|
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));
|
|
|
|
|
2010-09-06 23:56:16 -07:00
|
|
|
// check we still have something to drop
|
2010-12-20 03:09:19 -08:00
|
|
|
if (!drops) return EINA_TRUE;
|
2010-09-06 23:56:16 -07:00
|
|
|
|
|
|
|
/* Find any widget in our window; then work out geometry rel to our window */
|
2010-12-20 03:09:19 -08:00
|
|
|
for (l = drops; l; l = l->next)
|
2010-09-06 23:56:16 -07:00
|
|
|
{
|
|
|
|
dropable = l->data;
|
2012-08-22 01:33:43 -07:00
|
|
|
xwin = _x11_elm_widget_xwin_get(dropable->obj);
|
2010-12-20 03:09:19 -08:00
|
|
|
if (xwin == drop->win) break;
|
2010-09-06 23:56:16 -07:00
|
|
|
}
|
|
|
|
/* didn't find a window */
|
2010-12-20 03:09:19 -08:00
|
|
|
if (!l) 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
|
2010-09-07 21:55:12 -07:00
|
|
|
ee = ecore_evas_ecore_evas_get(evas_object_evas_get(dropable->obj));
|
|
|
|
ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
|
2010-09-06 23:56:16 -07:00
|
|
|
savedtypes.x = drop->position.x - x;
|
|
|
|
savedtypes.y = drop->position.y - 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
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
for (; l; l = l->next)
|
2010-09-06 23:56:16 -07:00
|
|
|
{
|
|
|
|
dropable = l->data;
|
2013-02-19 02:14:35 -08:00
|
|
|
if (xwin == drop->win)
|
|
|
|
{
|
|
|
|
if (evas_object_visible_get(dropable->obj))
|
|
|
|
{
|
|
|
|
evas_object_geometry_get(dropable->obj, &x, &y, &w, &h);
|
|
|
|
if ((savedtypes.x >= x) && (savedtypes.y >= y) &&
|
|
|
|
(savedtypes.x < x + w) && (savedtypes.y < y + h))
|
|
|
|
break; /* found! */
|
|
|
|
}
|
|
|
|
}
|
2010-09-06 23:56:16 -07:00
|
|
|
}
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
if (!l) return EINA_TRUE; /* didn't find one */
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-09-06 23:56:16 -07:00
|
|
|
evas_object_geometry_get(dropable->obj, &x, &y, NULL, NULL);
|
|
|
|
savedtypes.x -= x;
|
|
|
|
savedtypes.y -= y;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-09-06 23:56:16 -07:00
|
|
|
/* Find our type from the previous list */
|
2010-12-20 03:09:19 -08:00
|
|
|
for (i = 0; i < CNP_N_ATOMS; i++)
|
2010-09-06 23:56:16 -07:00
|
|
|
{
|
2011-04-01 04:35:07 -07:00
|
|
|
for (j = 0; j < savedtypes.ntypes; j++)
|
2010-09-06 23:56:16 -07:00
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
if (!strcmp(savedtypes.types[j], _x11_atoms[i].name)) 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:
|
2012-08-22 01:33:43 -07:00
|
|
|
cnp_debug("Found a target we'd like: %s\n", _x11_atoms[i].name);
|
2010-12-20 03:09:19 -08:00
|
|
|
cnp_debug("0x%x\n",xwin);
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-09-06 23:56:16 -07:00
|
|
|
if (i == CNP_ATOM_text_urilist)
|
|
|
|
{
|
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
|
|
|
{
|
2011-01-07 20:55:31 -08:00
|
|
|
char *entrytag;
|
2013-02-19 02:14:35 -08:00
|
|
|
static const char *tagstring =
|
|
|
|
"<item absize=240x180 href=file://%s></item>";
|
2010-09-06 23:56:16 -07:00
|
|
|
ddata.x = savedtypes.x;
|
|
|
|
ddata.y = savedtypes.y;
|
2010-09-07 21:55:16 -07:00
|
|
|
|
2011-01-13 15:04:04 -08:00
|
|
|
/* If it's markup that also supports images */
|
|
|
|
if ((dropable->types & ELM_SEL_FORMAT_MARKUP) &&
|
2011-04-01 04:35:07 -07:00
|
|
|
(dropable->types & ELM_SEL_FORMAT_IMAGE))
|
2010-09-07 21:55:16 -07:00
|
|
|
{
|
2011-01-07 20:55:31 -08:00
|
|
|
int len;
|
2010-09-07 21:55:16 -07:00
|
|
|
ddata.format = ELM_SEL_FORMAT_MARKUP;
|
2011-01-07 20:55:31 -08:00
|
|
|
|
2011-06-20 00:13:50 -07:00
|
|
|
len = strlen(tagstring) + strlen(savedtypes.imgfile);
|
2011-01-07 20:55:31 -08:00
|
|
|
entrytag = alloca(len + 1);
|
2011-06-20 00:13:50 -07:00
|
|
|
snprintf(entrytag, len + 1, tagstring, savedtypes.imgfile);
|
2010-09-07 21:55:16 -07:00
|
|
|
ddata.data = entrytag;
|
2010-12-20 03:09:19 -08:00
|
|
|
cnp_debug("Insert %s\n", (char *)ddata.data);
|
2010-09-07 21:55:16 -07:00
|
|
|
dropable->dropcb(dropable->cbdata, dropable->obj, &ddata);
|
|
|
|
ecore_x_dnd_send_finished();
|
2012-08-22 01:33:43 -07:00
|
|
|
if (savedtypes.imgfile) free(savedtypes.imgfile);
|
2011-06-20 00:13:50 -07:00
|
|
|
savedtypes.imgfile = NULL;
|
2011-07-03 00:49:02 -07:00
|
|
|
|
2011-01-13 15:04:04 -08:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
else if (dropable->types & ELM_SEL_FORMAT_IMAGE)
|
|
|
|
{
|
2011-06-20 00:13:50 -07:00
|
|
|
cnp_debug("Doing image insert (%s)\n", savedtypes.imgfile);
|
2011-01-13 15:04:04 -08:00
|
|
|
ddata.format = ELM_SEL_FORMAT_IMAGE;
|
2011-06-20 00:13:50 -07:00
|
|
|
ddata.data = (char *)savedtypes.imgfile;
|
2011-01-13 15:04:04 -08:00
|
|
|
dropable->dropcb(dropable->cbdata, dropable->obj, &ddata);
|
|
|
|
ecore_x_dnd_send_finished();
|
2012-08-22 01:33:43 -07:00
|
|
|
if (savedtypes.imgfile) free(savedtypes.imgfile);
|
2011-06-20 00:13:50 -07:00
|
|
|
savedtypes.imgfile = NULL;
|
2011-01-13 15:04:04 -08:00
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
return EINA_TRUE;
|
2010-09-07 21:55:16 -07:00
|
|
|
}
|
2011-01-07 20:55:31 -08:00
|
|
|
else
|
|
|
|
{
|
2011-01-13 15:04:04 -08:00
|
|
|
cnp_debug("Item doesn't support images... passing\n");
|
|
|
|
return EINA_TRUE;
|
2011-01-07 20:55:31 -08:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-07 21:55:16 -07:00
|
|
|
cnp_debug("doing a request then\n");
|
2012-08-22 01:33:43 -07:00
|
|
|
_x11_selections[ELM_SEL_TYPE_XDND].xwin = xwin;
|
|
|
|
_x11_selections[ELM_SEL_TYPE_XDND].requestwidget = dropable->obj;
|
|
|
|
_x11_selections[ELM_SEL_TYPE_XDND].requestformat = ELM_SEL_FORMAT_MARKUP;
|
|
|
|
_x11_selections[ELM_SEL_TYPE_XDND].active = EINA_TRUE;
|
2010-09-06 23:56:16 -07:00
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
ecore_x_selection_xdnd_request(xwin, _x11_atoms[i].name);
|
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-06 23:56:16 -07:00
|
|
|
static Eina_Bool
|
2012-08-22 02:37:00 -07:00
|
|
|
_x11_dnd_position(void *data __UNUSED__, int etype __UNUSED__, void *ev)
|
2010-09-08 20:09:42 -07:00
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
struct _Ecore_X_Event_Xdnd_Position *pos = ev;
|
2010-09-08 20:09:42 -07:00
|
|
|
Ecore_X_Rectangle rect;
|
2011-01-07 20:55:15 -08:00
|
|
|
|
2010-09-08 20:09:42 -07:00
|
|
|
/* Need to send a status back */
|
|
|
|
/* FIXME: Should check I can drop here */
|
|
|
|
/* FIXME: Should highlight widget */
|
|
|
|
rect.x = pos->position.x - 5;
|
|
|
|
rect.y = pos->position.y - 5;
|
|
|
|
rect.width = 10;
|
|
|
|
rect.height = 10;
|
2010-12-20 03:09:19 -08:00
|
|
|
ecore_x_dnd_send_status(EINA_TRUE, EINA_FALSE, rect, pos->action);
|
|
|
|
return EINA_TRUE;
|
2010-09-06 23:56:16 -07:00
|
|
|
}
|
|
|
|
|
2010-09-13 02:16:01 -07:00
|
|
|
/**
|
|
|
|
* When dragging this is callback response from the destination.
|
|
|
|
* The important thing we care about: Can we drop; thus update cursor
|
|
|
|
* appropriately.
|
|
|
|
*/
|
|
|
|
static Eina_Bool
|
2012-08-22 02:37:00 -07:00
|
|
|
_x11_dnd_status(void *data __UNUSED__, int etype __UNUSED__, void *ev)
|
2010-09-13 02:16:01 -07:00
|
|
|
{
|
|
|
|
struct _Ecore_X_Event_Xdnd_Status *status = ev;
|
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
if (!status) return EINA_TRUE;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-09-13 02:16:01 -07:00
|
|
|
/* Only thing we care about: will accept */
|
2012-08-22 01:33:43 -07:00
|
|
|
if (status->will_accept) cnp_debug("Will accept\n");
|
|
|
|
/* Won't accept */
|
|
|
|
else cnp_debug("Won't accept accept\n");
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2013-02-19 04:10:02 -08:00
|
|
|
static Eina_Bool
|
|
|
|
_x11_drag_mouse_up(void *data, int etype __UNUSED__, void *event)
|
2012-08-22 01:33:43 -07:00
|
|
|
{
|
2013-02-19 04:10:02 -08:00
|
|
|
Ecore_X_Window xwin = (Ecore_X_Window)data;
|
|
|
|
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-19 04:10:02 -08:00
|
|
|
ecore_x_pointer_ungrab();
|
|
|
|
if (handler_up)
|
|
|
|
{
|
|
|
|
ecore_event_handler_del(handler_up);
|
|
|
|
handler_up = NULL;
|
|
|
|
}
|
|
|
|
ecore_x_dnd_drop();
|
|
|
|
|
|
|
|
cnp_debug("mouse up, xwin=%#llx\n", (unsigned long long)xwin);
|
|
|
|
|
|
|
|
// TODO BUG: should not revert to FALSE if xwin is a drop target!
|
|
|
|
ecore_x_dnd_aware_set(xwin, EINA_FALSE);
|
|
|
|
if (dragdonecb)
|
|
|
|
{
|
|
|
|
dragdonecb(dragdonedata, _x11_selections[ELM_SEL_TYPE_XDND].widget);
|
|
|
|
dragdonecb = NULL;
|
|
|
|
}
|
|
|
|
if (dragwin)
|
|
|
|
{
|
|
|
|
evas_object_del(dragwin);
|
|
|
|
dragwin = NULL;
|
|
|
|
}
|
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
|
2012-08-22 02:37:00 -07:00
|
|
|
_x11_drag_move(void *data __UNUSED__, Ecore_X_Xdnd_Position *pos)
|
2012-08-22 01:33:43 -07:00
|
|
|
{
|
|
|
|
evas_object_move(dragwin, pos->position.x - _dragx, pos->position.y - _dragy);
|
|
|
|
}
|
|
|
|
|
2012-08-22 02:37:00 -07:00
|
|
|
static Ecore_X_Window
|
|
|
|
_x11_elm_widget_xwin_get(const Evas_Object *obj)
|
|
|
|
{
|
|
|
|
Evas_Object *top;
|
|
|
|
Ecore_X_Window xwin = 0;
|
|
|
|
|
|
|
|
top = elm_widget_top_get(obj);
|
|
|
|
if (!top) top = elm_widget_top_get(elm_widget_parent_widget_get(obj));
|
|
|
|
if (top) xwin = elm_win_xwindow_get(top);
|
|
|
|
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;
|
|
|
|
xwin = _elm_ee_xwin_get(ee);
|
|
|
|
}
|
|
|
|
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;
|
2012-08-22 02:37:00 -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++)
|
|
|
|
{
|
|
|
|
_x11_atoms[i].atom = ecore_x_atom_get(_x11_atoms[i].name);
|
|
|
|
ecore_x_selection_converter_atom_add
|
|
|
|
(_x11_atoms[i].atom, _x11_atoms[i].converter);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
_x11_elm_cnp_selection_set(Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format, const void *selbuf, size_t buflen)
|
|
|
|
{
|
|
|
|
Ecore_X_Window xwin = _x11_elm_widget_xwin_get(obj);
|
|
|
|
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;
|
|
|
|
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,
|
|
|
|
_x11_sel_obj_del, sel);
|
|
|
|
sel->widget = NULL;
|
|
|
|
|
|
|
|
sel->active = EINA_TRUE;
|
|
|
|
sel->widget = obj;
|
|
|
|
sel->xwin = xwin;
|
|
|
|
sel->set(xwin, &selection, sizeof(Elm_Sel_Type));
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (selbuf)
|
|
|
|
{
|
|
|
|
if (format == ELM_SEL_FORMAT_IMAGE)
|
|
|
|
{
|
|
|
|
// selbuf is actual image data, not text/string
|
|
|
|
sel->selbuf = malloc(buflen);
|
|
|
|
if (!sel->selbuf)
|
|
|
|
{
|
|
|
|
elm_object_cnp_selection_clear(obj, selection);
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
memcpy(sel->selbuf, selbuf, buflen);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sel->selbuf = strdup((char*)selbuf);
|
2010-09-13 02:16:01 -07:00
|
|
|
}
|
|
|
|
else
|
2012-08-22 01:33:43 -07:00
|
|
|
sel->selbuf = NULL;
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_x11_elm_cnp_selection_loss_callback_set(Evas_Object *obj __UNUSED__, Elm_Sel_Type selection, Elm_Selection_Loss_Cb func, const void *data)
|
|
|
|
{
|
|
|
|
X11_Cnp_Selection *sel;
|
|
|
|
|
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();
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
sel->active = EINA_FALSE;
|
|
|
|
if (sel->selbuf)
|
|
|
|
{
|
|
|
|
free(sel->selbuf);
|
|
|
|
sel->selbuf = NULL;
|
2010-09-13 02:16:01 -07:00
|
|
|
}
|
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
|
|
|
|
_x11_elm_cnp_selection_get(Evas_Object *obj, Elm_Sel_Type selection,
|
|
|
|
Elm_Sel_Format format, Elm_Drop_Cb datacb, void *udata)
|
|
|
|
{
|
|
|
|
Ecore_X_Window xwin = _x11_elm_widget_xwin_get(obj);
|
|
|
|
X11_Cnp_Selection *sel;
|
|
|
|
|
2012-08-28 00:49:27 -07:00
|
|
|
_x11_elm_cnp_init();
|
|
|
|
|
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->requestwidget = NULL;
|
|
|
|
|
|
|
|
sel->requestformat = format;
|
|
|
|
sel->requestwidget = obj;
|
|
|
|
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);
|
|
|
|
|
|
|
|
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,
|
2012-08-22 01:33:43 -07:00
|
|
|
Elm_Drop_Cb dropcb, void *cbdata)
|
2010-09-06 23:56:16 -07:00
|
|
|
{
|
2010-12-20 03:09:19 -08:00
|
|
|
Dropable *drop;
|
2012-08-22 01:33:43 -07:00
|
|
|
Ecore_X_Window xwin = _x11_elm_widget_xwin_get(obj);
|
2011-01-13 15:04:14 -08:00
|
|
|
Eina_List *item;
|
2010-09-08 20:09:42 -07:00
|
|
|
int first;
|
2011-01-13 15:04:14 -08:00
|
|
|
|
2012-08-28 00:49:27 -07:00
|
|
|
_x11_elm_cnp_init();
|
2013-02-19 02:14:35 -08:00
|
|
|
|
2012-06-19 16:33:57 -07:00
|
|
|
/* TODO: check if obj is already a drop target. Do not add twice! */
|
|
|
|
|
2010-09-08 20:09:42 -07:00
|
|
|
/* Is this the first? */
|
2010-10-22 14:41:22 -07:00
|
|
|
first = (!drops) ? 1 : 0;
|
2011-01-13 15:04:14 -08:00
|
|
|
|
|
|
|
EINA_LIST_FOREACH(drops, item, drop)
|
|
|
|
{
|
|
|
|
if (drop->obj == obj)
|
|
|
|
{
|
|
|
|
/* Update: Not a new one */
|
|
|
|
drop->dropcb = dropcb;
|
|
|
|
drop->cbdata = cbdata;
|
|
|
|
drop->types = format;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create new drop */
|
2010-12-20 03:09:19 -08:00
|
|
|
drop = calloc(1, sizeof(Dropable));
|
|
|
|
if (!drop) return EINA_FALSE;
|
2010-09-08 20:09:42 -07:00
|
|
|
/* FIXME: Check for eina's deranged error method */
|
|
|
|
drops = eina_list_append(drops, drop);
|
2011-01-13 15:04:14 -08:00
|
|
|
|
2010-09-08 20:09:42 -07:00
|
|
|
if (!drops/* || or other error */)
|
|
|
|
{
|
|
|
|
free(drop);
|
2010-12-20 03:09:19 -08:00
|
|
|
return EINA_FALSE;
|
2010-09-08 20:09:42 -07:00
|
|
|
}
|
2011-01-13 15:04:14 -08:00
|
|
|
drop->dropcb = dropcb;
|
|
|
|
drop->cbdata = cbdata;
|
2010-09-08 20:09:42 -07:00
|
|
|
drop->types = format;
|
2011-01-13 15:04:14 -08:00
|
|
|
drop->obj = obj;
|
|
|
|
|
2010-09-08 20:09:42 -07:00
|
|
|
evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
|
|
|
|
/* I love C and varargs */
|
|
|
|
(Evas_Object_Event_Cb)elm_drop_target_del,
|
|
|
|
obj);
|
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
|
|
|
|
2010-12-20 03:09:19 -08:00
|
|
|
ecore_x_dnd_aware_set(xwin, EINA_TRUE);
|
2011-04-01 04:35:07 -07: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);
|
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;
|
2010-09-06 23:56:16 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_x11_elm_drop_target_del(Evas_Object *obj)
|
2010-09-08 20:09:42 -07:00
|
|
|
{
|
2010-12-20 03:09:19 -08:00
|
|
|
Dropable *drop,*del;
|
2010-09-08 20:09:42 -07:00
|
|
|
Eina_List *item;
|
|
|
|
Ecore_X_Window xwin;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2012-08-28 00:49:27 -07:00
|
|
|
_x11_elm_cnp_init();
|
|
|
|
|
2010-09-08 20:09:42 -07:00
|
|
|
del = NULL;
|
|
|
|
EINA_LIST_FOREACH(drops, item, drop)
|
|
|
|
{
|
|
|
|
if (drop->obj == obj)
|
|
|
|
{
|
|
|
|
drops = eina_list_remove_list(drops, item);
|
|
|
|
del = drop;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-12-20 03:09:19 -08:00
|
|
|
if (!del) return EINA_FALSE;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-09-08 20:09:42 -07:00
|
|
|
evas_object_event_callback_del(obj, EVAS_CALLBACK_FREE,
|
|
|
|
(Evas_Object_Event_Cb)elm_drop_target_del);
|
|
|
|
free(drop);
|
2012-06-19 16:33:57 -07:00
|
|
|
|
|
|
|
/* TODO BUG: we should handle dnd-aware per window, not just the last that reelased it */
|
|
|
|
|
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);
|
2010-12-20 03:09:19 -08:00
|
|
|
ecore_x_dnd_aware_set(xwin, EINA_FALSE);
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2010-09-08 20:09:42 -07:00
|
|
|
ecore_event_handler_del(handler_pos);
|
|
|
|
ecore_event_handler_del(handler_drop);
|
|
|
|
ecore_event_handler_del(handler_enter);
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
if (savedtypes.imgfile) free(savedtypes.imgfile);
|
2011-06-20 00:13:50 -07:00
|
|
|
savedtypes.imgfile = NULL;
|
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
|
|
|
}
|
|
|
|
|
2012-08-22 01:33:43 -07:00
|
|
|
static Eina_Bool
|
2013-02-19 04:10:02 -08:00
|
|
|
_x11_elm_drag_start(Evas_Object *obj, Elm_Sel_Format format, const char *data,
|
|
|
|
Evas_Object *(*createicon) (void *data, Evas_Object *win, Evas_Coord *xoff, Evas_Coord *yoff),
|
|
|
|
void *createdata,
|
|
|
|
void (*dragdone) (void *data, Evas_Object *obj),
|
|
|
|
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);
|
|
|
|
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;
|
2010-12-20 03:09:19 -08:00
|
|
|
int w, h;
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2012-08-28 00:49:27 -07:00
|
|
|
_x11_elm_cnp_init();
|
|
|
|
|
2010-09-09 01:59:42 -07:00
|
|
|
cnp_debug("starting drag...\n");
|
|
|
|
|
2012-01-02 20:44:48 -08:00
|
|
|
if (dragwin)
|
|
|
|
{
|
|
|
|
cnp_debug("another obj is dragging...\n");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ecore_x_dnd_type_set(xwin, "text/uri-list", EINA_TRUE);
|
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;
|
2012-06-19 16:33:57 -07:00
|
|
|
|
|
|
|
/* TODO BUG: should NEVER have these as globals! They should be per context (window). */
|
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);
|
2010-09-14 23:29:49 -07:00
|
|
|
ecore_x_dnd_begin(xwin, (unsigned char *)&xdnd, sizeof(Elm_Sel_Type));
|
2013-02-19 04:10:02 -08:00
|
|
|
ecore_x_pointer_grab(xwin);
|
|
|
|
handler_up = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP, _x11_drag_mouse_up,
|
|
|
|
(void *)(long)xwin);
|
|
|
|
// evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP,
|
|
|
|
// _x11_drag_mouse_up, (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);
|
2010-12-20 03:09:19 -08:00
|
|
|
dragwin = elm_win_add(NULL, "Elm Drag Object", ELM_WIN_UTILITY);
|
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);
|
2011-04-01 04:35:07 -07:00
|
|
|
|
2013-02-19 04:10:02 -08:00
|
|
|
if (createicon)
|
|
|
|
{
|
|
|
|
Evas_Coord xoff = 0, yoff = 0;
|
|
|
|
|
|
|
|
icon = createicon(createdata, dragwin, &xoff, &yoff);
|
|
|
|
if (icon)
|
|
|
|
{
|
|
|
|
evas_object_geometry_get(obj, &x2, &y2, NULL, NULL);
|
|
|
|
evas_object_geometry_get(icon, NULL, NULL, &w, &h);
|
|
|
|
x2 += xoff;
|
|
|
|
y2 += yoff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!icon)
|
|
|
|
{
|
|
|
|
evas_object_geometry_get(obj, &x2, &y2, &w, &h);
|
|
|
|
|
|
|
|
/* FIXME: Images only */
|
|
|
|
icon = elm_icon_add(dragwin);
|
|
|
|
if (!strncmp(data, "file://", 7))
|
|
|
|
elm_image_file_set(icon, data + 7, NULL); /* 7!? "file://" */
|
|
|
|
else
|
|
|
|
elm_image_file_set(icon, data, NULL);
|
|
|
|
evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
|
|
|
evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
|
|
|
}
|
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));
|
|
|
|
ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
|
|
|
|
x += x2;
|
|
|
|
y += y2;
|
|
|
|
evas_object_move(dragwin, x, y);
|
2010-12-20 03:09:19 -08:00
|
|
|
evas_object_resize(icon, w, h);
|
|
|
|
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);
|
|
|
|
_dragx = x3 - x2;
|
|
|
|
_dragy = y3 - y2;
|
2010-09-10 01:24:21 -07:00
|
|
|
|
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
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_x11_elm_selection_selection_has_owner(Evas_Object *obj __UNUSED__)
|
|
|
|
{
|
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
|
|
|
|
2012-08-28 23:52:48 -07:00
|
|
|
#ifdef HAVE_ELEMENTARY_WAYLAND
|
|
|
|
typedef struct _Wl_Cnp_Selection Wl_Cnp_Selection;
|
|
|
|
|
|
|
|
struct _Wl_Cnp_Selection
|
|
|
|
{
|
|
|
|
char *selbuf;
|
|
|
|
int buflen;
|
|
|
|
|
|
|
|
Evas_Object *widget;
|
|
|
|
Evas_Object *requestwidget;
|
|
|
|
};
|
|
|
|
|
2012-08-29 00:29:21 -07:00
|
|
|
static Eina_Bool _wl_elm_cnp_init(void);
|
|
|
|
|
2012-08-28 23:52:48 -07:00
|
|
|
static Wl_Cnp_Selection wl_cnp_selection = {0, 0, NULL, NULL};
|
2012-08-29 00:29:21 -07:00
|
|
|
static void _wl_sel_obj_del2(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__);
|
|
|
|
static Eina_Bool _wl_elm_cnp_selection_set(Evas_Object *obj __UNUSED__, Elm_Sel_Type selection, Elm_Sel_Format format __UNUSED__, const void *selbuf, size_t buflen);
|
|
|
|
static Eina_Bool _wl_elm_cnp_selection_get(Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format __UNUSED__, Elm_Drop_Cb datacb __UNUSED__, void *udata __UNUSED__);
|
|
|
|
static Eina_Bool _wl_selection_send(void *udata, int type __UNUSED__, void *event);
|
|
|
|
static Eina_Bool _wl_selection_receive(void *udata, int type __UNUSED__, void *event);
|
2012-08-28 23:52:48 -07:00
|
|
|
|
|
|
|
static void
|
|
|
|
_wl_sel_obj_del2(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
|
|
|
|
{
|
|
|
|
Wl_Cnp_Selection *sel = data;
|
|
|
|
if (sel->requestwidget == obj) sel->requestwidget = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_wl_elm_cnp_selection_set(Evas_Object *obj __UNUSED__, Elm_Sel_Type selection, Elm_Sel_Format format __UNUSED__, const void *selbuf, size_t buflen)
|
|
|
|
{
|
|
|
|
const char *types[10] = {0, };
|
|
|
|
|
2012-08-29 00:29:21 -07:00
|
|
|
_wl_elm_cnp_init();
|
|
|
|
|
2012-08-28 23:52:48 -07:00
|
|
|
/* TODO: other EML_SEL_TYPE and ELM_SEL_FORMAT */
|
|
|
|
if (ELM_SEL_TYPE_CLIPBOARD == selection)
|
|
|
|
{
|
|
|
|
types[0] = "text/plain;charset=utf-8";
|
|
|
|
ecore_wl_dnd_set_selection(ecore_wl_dnd_get(), types);
|
|
|
|
|
|
|
|
if (wl_cnp_selection.selbuf) free(wl_cnp_selection.selbuf);
|
|
|
|
wl_cnp_selection.selbuf = strdup((char*)selbuf);
|
|
|
|
wl_cnp_selection.buflen = buflen;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_wl_elm_cnp_selection_get(Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format __UNUSED__, Elm_Drop_Cb datacb __UNUSED__, void *udata __UNUSED__)
|
|
|
|
{
|
2012-08-29 00:29:21 -07:00
|
|
|
_wl_elm_cnp_init();
|
|
|
|
|
2012-08-28 23:52:48 -07:00
|
|
|
/* For now, just avoid overlapped request */
|
|
|
|
if (wl_cnp_selection.requestwidget) return EINA_FALSE;
|
|
|
|
|
|
|
|
/* TODO: other EML_SEL_TYPE and ELM_SEL_FORMAT */
|
|
|
|
if (ELM_SEL_TYPE_CLIPBOARD == selection)
|
|
|
|
{
|
|
|
|
wl_cnp_selection.requestwidget = obj;
|
|
|
|
evas_object_event_callback_add(wl_cnp_selection.requestwidget, EVAS_CALLBACK_DEL,
|
|
|
|
_wl_sel_obj_del2, &wl_cnp_selection);
|
|
|
|
ecore_wl_dnd_get_selection(ecore_wl_dnd_get(), "text/plain;charset=utf-8");
|
|
|
|
}
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_wl_selection_send(void *udata, int type __UNUSED__, void *event)
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
int ret, len_remained;
|
|
|
|
int len_written = 0;
|
|
|
|
Wl_Cnp_Selection *sel = udata;
|
|
|
|
Ecore_Wl_Event_Data_Source_Send *ev = event;
|
|
|
|
|
2012-08-29 00:29:21 -07:00
|
|
|
_wl_elm_cnp_init();
|
|
|
|
|
2012-08-28 23:52:48 -07:00
|
|
|
len_remained = sel->buflen;
|
|
|
|
buf = sel->selbuf;
|
|
|
|
|
|
|
|
while (len_written < sel->buflen)
|
|
|
|
{
|
|
|
|
ret = write(ev->fd, buf, len_remained);
|
|
|
|
if (ret == -1) break;
|
|
|
|
buf += ret;
|
|
|
|
len_written += ret;
|
|
|
|
len_remained -= ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(ev->fd);
|
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_wl_selection_receive(void *udata, int type __UNUSED__, void *event)
|
|
|
|
{
|
|
|
|
Wl_Cnp_Selection *sel = udata;
|
|
|
|
Ecore_Wl_Event_Selection_Data_Ready *ev = event;
|
|
|
|
|
2012-08-29 00:29:21 -07:00
|
|
|
_wl_elm_cnp_init();
|
|
|
|
|
2012-08-28 23:52:48 -07:00
|
|
|
if (sel->requestwidget)
|
|
|
|
{
|
|
|
|
if (!ev->done)
|
|
|
|
{
|
|
|
|
/* TODO BUG: should never NEVER assume it's an elm_entry! */
|
|
|
|
_elm_entry_entry_paste(sel->requestwidget, ev->data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
evas_object_event_callback_del_full(sel->requestwidget, EVAS_CALLBACK_DEL,
|
|
|
|
_wl_sel_obj_del2, sel);
|
|
|
|
sel->requestwidget = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
|
|
|
}
|
|
|
|
|
2012-08-29 00:29:21 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_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++;
|
|
|
|
|
2012-08-28 23:52:48 -07:00
|
|
|
ecore_event_handler_add(ECORE_WL_EVENT_DATA_SOURCE_SEND,
|
|
|
|
_wl_selection_send, &wl_cnp_selection);
|
|
|
|
ecore_event_handler_add(ECORE_WL_EVENT_SELECTION_DATA_READY,
|
|
|
|
_wl_selection_receive, &wl_cnp_selection);
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
#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 {
|
|
|
|
void *buf;
|
|
|
|
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);
|
|
|
|
static Eina_Bool _local_elm_cnp_selection_set(Evas_Object *obj __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 __UNUSED__, Elm_Sel_Type selection __UNUSED__, Elm_Selection_Loss_Cb func __UNUSED__, const void *data __UNUSED__);
|
|
|
|
static Eina_Bool _local_elm_object_cnp_selection_clear(Evas_Object *obj __UNUSED__, Elm_Sel_Type selection);
|
|
|
|
static Eina_Bool _local_elm_cnp_selection_get(Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Format format __UNUSED__, Elm_Drop_Cb datacb, void *udata);
|
2013-02-19 02:14:35 -08:00
|
|
|
static Eina_Bool _local_elm_drop_target_add(Evas_Object *obj __UNUSED__, Elm_Sel_Format format __UNUSED__, Elm_Drop_Cb dropcb __UNUSED__, void *cbdata __UNUSED__);
|
2012-08-22 02:37:00 -07:00
|
|
|
static Eina_Bool _local_elm_drop_target_del(Evas_Object *obj __UNUSED__);
|
2013-02-19 04:10:02 -08:00
|
|
|
static Eina_Bool _local_elm_drag_start(Evas_Object *obj __UNUSED__, Elm_Sel_Format format __UNUSED__, const char *data __UNUSED__, Evas_Object *(*createicon) (void *data, Evas_Object *win, Evas_Coord *xoff, Evas_Coord *yoff) __UNUSED__, void *createdata __UNUSED__, void (*dragdone) (void *data, Evas_Object *) __UNUSED__, void *donecbdata __UNUSED__);
|
2012-08-22 02:37:00 -07:00
|
|
|
static Eina_Bool _local_elm_selection_selection_has_owner(Evas_Object *obj __UNUSED__);
|
|
|
|
|
|
|
|
static void
|
|
|
|
_local_get_job(void *data)
|
|
|
|
{
|
|
|
|
Local_Selinfo *info = data;
|
|
|
|
Elm_Selection_Data ev;
|
|
|
|
|
|
|
|
info->get.job = NULL;
|
|
|
|
ev.x = 0;
|
|
|
|
ev.y = 0;
|
|
|
|
ev.format = info->format;
|
|
|
|
ev.data = info->sel.buf;
|
|
|
|
ev.len = info->sel.size;
|
|
|
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
|
_local_elm_cnp_selection_set(Evas_Object *obj __UNUSED__,
|
|
|
|
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();
|
2012-08-22 02:37:00 -07:00
|
|
|
if (_local_selinfo[selection].sel.buf)
|
|
|
|
free(_local_selinfo[selection].sel.buf);
|
|
|
|
_local_selinfo[selection].format = format;
|
|
|
|
_local_selinfo[selection].sel.buf = malloc(buflen);
|
|
|
|
if (_local_selinfo[selection].sel.buf)
|
|
|
|
{
|
|
|
|
memcpy(_local_selinfo[selection].sel.buf, selbuf, buflen);
|
|
|
|
_local_selinfo[selection].sel.size = buflen;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_local_selinfo[selection].sel.size = 0;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_local_elm_cnp_selection_loss_callback_set(Evas_Object *obj __UNUSED__,
|
|
|
|
Elm_Sel_Type selection __UNUSED__,
|
|
|
|
Elm_Selection_Loss_Cb func __UNUSED__,
|
|
|
|
const void *data __UNUSED__)
|
|
|
|
{
|
2012-08-28 00:49:27 -07:00
|
|
|
_local_elm_cnp_init();
|
2012-08-22 02:37:00 -07:00
|
|
|
// this doesnt need to do anything as we never lose selection to anyone
|
|
|
|
// as thisis local
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_local_elm_object_cnp_selection_clear(Evas_Object *obj __UNUSED__,
|
|
|
|
Elm_Sel_Type selection)
|
|
|
|
{
|
2012-08-28 00:49:27 -07:00
|
|
|
_local_elm_cnp_init();
|
2012-08-22 02:37:00 -07:00
|
|
|
if (_local_selinfo[selection].sel.buf)
|
|
|
|
free(_local_selinfo[selection].sel.buf);
|
|
|
|
_local_selinfo[selection].sel.buf = NULL;
|
|
|
|
_local_selinfo[selection].sel.size = 0;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_local_elm_cnp_selection_get(Evas_Object *obj,
|
|
|
|
Elm_Sel_Type selection,
|
|
|
|
Elm_Sel_Format format __UNUSED__,
|
|
|
|
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);
|
|
|
|
_local_selinfo[selection].get.obj = obj;
|
|
|
|
_local_selinfo[selection].get.func = datacb;
|
|
|
|
_local_selinfo[selection].get.data = udata;
|
|
|
|
_local_selinfo[selection].get.job =
|
|
|
|
ecore_job_add(_local_get_job, &(_local_selinfo[selection]));
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_local_elm_drop_target_add(Evas_Object *obj __UNUSED__,
|
2013-02-19 02:14:35 -08:00
|
|
|
Elm_Sel_Format format __UNUSED__,
|
2012-08-22 02:37:00 -07:00
|
|
|
Elm_Drop_Cb dropcb __UNUSED__,
|
|
|
|
void *cbdata __UNUSED__)
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
_local_elm_drop_target_del(Evas_Object *obj __UNUSED__)
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
_local_elm_drag_start(Evas_Object *obj __UNUSED__,
|
|
|
|
Elm_Sel_Format format __UNUSED__,
|
|
|
|
const char *data __UNUSED__,
|
2013-02-19 04:10:02 -08:00
|
|
|
Evas_Object *(*createicon) (void *data, Evas_Object *win, Evas_Coord *xoff, Evas_Coord *yoff) __UNUSED__,
|
|
|
|
void *createdata __UNUSED__,
|
|
|
|
void (*dragdone) (void *data, Evas_Object *obj) __UNUSED__,
|
2012-08-22 02:37:00 -07:00
|
|
|
void *donecbdata __UNUSED__)
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
_local_elm_selection_selection_has_owner(Evas_Object *obj __UNUSED__)
|
|
|
|
{
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
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");
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
2010-10-20 10:15:14 -07:00
|
|
|
const char *tmppath;
|
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;
|
|
|
|
tmppath = getenv("TMP");
|
|
|
|
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;
|
2012-08-22 01:33:43 -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;
|
|
|
|
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 01:33:43 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_pasteimage_append(char *file, Evas_Object *entry)
|
2010-09-09 01:59:38 -07:00
|
|
|
{
|
2012-08-22 01:33:43 -07:00
|
|
|
char *entrytag;
|
|
|
|
int len;
|
|
|
|
/* TODO BUG: shouldn't define absize=240x180. Prefer data:// instead of href:// -- may need support for evas. See http://dataurl.net/ */
|
|
|
|
static const char *tagstring = "<item absize=240x180 href=file://%s></item>";
|
|
|
|
|
|
|
|
if ((!file) || (!entry)) return EINA_FALSE;
|
|
|
|
len = strlen(tagstring)+strlen(file);
|
|
|
|
entrytag = alloca(len + 1);
|
|
|
|
snprintf(entrytag, len + 1, tagstring, file);
|
|
|
|
/* TODO BUG: should never NEVER assume it's an elm_entry! */
|
|
|
|
_elm_entry_entry_paste(entry, entrytag);
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
if (_x11_elm_widget_xwin_get(obj))
|
|
|
|
return _x11_elm_cnp_selection_set(obj, selection, format, selbuf, buflen);
|
2012-08-28 23:52:48 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WAYLAND
|
|
|
|
if (elm_win_wl_window_get(obj))
|
|
|
|
return _wl_elm_cnp_selection_set(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);
|
|
|
|
#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);
|
|
|
|
#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
|
|
|
|
elm_cnp_selection_get(Evas_Object *obj, Elm_Sel_Type selection,
|
|
|
|
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
|
|
|
|
if (_x11_elm_widget_xwin_get(obj))
|
|
|
|
return _x11_elm_cnp_selection_get(obj, selection, format, datacb, udata);
|
2012-08-28 23:52:48 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ELEMENTARY_WAYLAND
|
|
|
|
if (elm_win_wl_window_get(obj))
|
|
|
|
return _wl_elm_cnp_selection_get(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,
|
2012-08-22 01:33:43 -07:00
|
|
|
Elm_Drop_Cb dropcb, void *cbdata)
|
|
|
|
{
|
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_drop_target_add(obj, format, dropcb, cbdata);
|
|
|
|
#endif
|
2012-08-22 02:37:00 -07:00
|
|
|
return _local_elm_drop_target_add(obj, format, dropcb, cbdata);
|
2012-08-22 01:33:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Bool
|
|
|
|
elm_drop_target_del(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))
|
|
|
|
return _x11_elm_drop_target_del(obj);
|
|
|
|
#endif
|
2012-08-22 02:37:00 -07:00
|
|
|
return _local_elm_drop_target_del(obj);
|
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,
|
|
|
|
Evas_Object *(*createicon) (void *data, Evas_Object *win, Evas_Coord *xoff, Evas_Coord *yoff),
|
|
|
|
void *createdata,
|
|
|
|
void (*dragdone) (void *data, Evas_Object *obj),
|
|
|
|
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-02-19 04:10:02 -08:00
|
|
|
return _x11_elm_drag_start(obj, format, data, createicon, createdata,
|
|
|
|
dragdone, donecbdata);
|
2012-08-22 01:33:43 -07:00
|
|
|
#endif
|
2013-02-19 04:10:02 -08:00
|
|
|
return _local_elm_drag_start(obj, format, data, createicon, createdata,
|
|
|
|
dragdone, donecbdata);
|
2010-09-09 01:59:38 -07:00
|
|
|
}
|
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
|
|
|
|
#ifdef HAVE_ELEMENTARY_WAYLAND
|
2012-08-29 00:15:32 -07:00
|
|
|
if (elm_win_wl_window_get(obj))
|
|
|
|
return ecore_wl_dnd_selection_has_owner(ecore_wl_dnd_get());
|
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
|
|
|
|
2011-06-26 19:54:41 -07:00
|
|
|
/* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-3f0^-2{2(0W1st0 :*/
|