summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Guyomarc'h <jean.guyomarch@openwide.fr>2015-10-09 17:18:20 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-12-03 11:04:42 -0800
commitdc5eeb4ac5afcaff589d1eaa5f2135f92fb22d4f (patch)
treeda63fabc1e9ee12ee9991fb6ecc2bdf39ad56dcd
parente1c29985c4256cd77aee95fa6a0fa56e9ce0e78a (diff)
cnp: cocoa support for copy and paste (text only).
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
-rw-r--r--src/lib/elm_cnp.c272
1 files changed, 272 insertions, 0 deletions
diff --git a/src/lib/elm_cnp.c b/src/lib/elm_cnp.c
index 7be51d924..851c28be0 100644
--- a/src/lib/elm_cnp.c
+++ b/src/lib/elm_cnp.c
@@ -8,6 +8,10 @@
8# include <sys/mman.h> 8# include <sys/mman.h>
9#endif 9#endif
10 10
11#ifdef HAVE_ELEMENTARY_COCOA
12# include <Ecore_Cocoa.h>
13#endif
14
11//#define DEBUGON 1 15//#define DEBUGON 1
12#ifdef DEBUGON 16#ifdef DEBUGON
13# define cnp_debug(fmt, args...) fprintf(stderr, __FILE__":%s/%d : " fmt , __FUNCTION__, __LINE__, ##args) 17# define cnp_debug(fmt, args...) fprintf(stderr, __FILE__":%s/%d : " fmt , __FUNCTION__, __LINE__, ##args)
@@ -3481,6 +3485,255 @@ _wl_elm_widget_window_get(const Evas_Object *obj)
3481 3485
3482#endif 3486#endif
3483 3487
3488#ifdef HAVE_ELEMENTARY_COCOA
3489
3490typedef struct _Cocoa_Cnp_Selection Cocoa_Cnp_Selection;
3491
3492struct _Cocoa_Cnp_Selection
3493{
3494 Ecore_Cocoa_Window *win;
3495 Evas_Object *widget;
3496 char *selbuf;
3497 int buflen;
3498 Evas_Object *requestwidget;
3499 void *udata;
3500 Elm_Sel_Format requestformat;
3501 Elm_Drop_Cb datacb;
3502
3503 Elm_Selection_Loss_Cb loss_cb;
3504 void *loss_data;
3505 int pb_count;
3506
3507 Elm_Sel_Format format;
3508
3509 Eina_Bool active : 1;
3510};
3511
3512static Cocoa_Cnp_Selection _cocoa_cnp_sel;
3513
3514static Ecore_Cocoa_Window *
3515_cocoa_elm_widget_cocoa_window_get(const Evas_Object *obj)
3516{
3517 Evas_Object *top, *par;
3518 Ecore_Cocoa_Window *win = NULL;
3519
3520 if (elm_widget_is(obj))
3521 {
3522 top = elm_widget_top_get(obj);
3523 if (!top)
3524 {
3525 par = elm_widget_parent_widget_get(obj);
3526 if (par) top = elm_widget_top_get(par);
3527 }
3528 if ((top) && (eo_isa(top, ELM_WIN_CLASS)))
3529 win = elm_win_cocoa_window_get(top);
3530 }
3531 if (!win)
3532 {
3533 // FIXME
3534 CRI("WIN has not been retrieved!!!");
3535 }
3536
3537 return win;
3538}
3539
3540static Ecore_Cocoa_Cnp_Type
3541_elm_sel_format_to_ecore_cocoa_cnp_type(Elm_Sel_Format fmt)
3542{
3543 Ecore_Cocoa_Cnp_Type type = 0;
3544
3545 if ((fmt & ELM_SEL_FORMAT_TEXT) ||
3546 (fmt & ELM_SEL_FORMAT_VCARD))
3547 type |= ECORE_COCOA_CNP_TYPE_STRING;
3548 if (fmt & ELM_SEL_FORMAT_MARKUP)
3549 type |= ECORE_COCOA_CNP_TYPE_MARKUP;
3550 if (fmt & ELM_SEL_FORMAT_HTML)
3551 type |= ECORE_COCOA_CNP_TYPE_HTML;
3552 if (fmt & ELM_SEL_FORMAT_IMAGE)
3553 type |= ECORE_COCOA_CNP_TYPE_IMAGE;
3554
3555 return type;
3556}
3557
3558static void
3559_cocoa_sel_obj_del_req_cb(void *data,
3560 Evas *e EINA_UNUSED,
3561 Evas_Object *obj,
3562 void *ev_info EINA_UNUSED)
3563{
3564 Cocoa_Cnp_Selection *sel = data;
3565 if (sel->requestwidget == obj) sel->requestwidget = NULL;
3566}
3567
3568static void
3569_cocoa_sel_obj_del_cb(void *data,
3570 Evas *e EINA_UNUSED,
3571 Evas_Object *obj,
3572 void *ev_info EINA_UNUSED)
3573{
3574 Cocoa_Cnp_Selection *sel = data;
3575 if (sel->widget == obj)
3576 {
3577 sel->widget = NULL;
3578 sel->loss_cb = NULL;
3579 sel->loss_data = NULL;
3580 }
3581 if (dragwidget == obj) dragwidget = NULL;
3582}
3583
3584static void
3585_job_pb_cb(void *data)
3586{
3587 Cocoa_Cnp_Selection *sel = data;
3588 Elm_Selection_Data ddata;
3589 Ecore_Cocoa_Cnp_Type type, get_type;
3590 void *pbdata;
3591 int pbdata_len;
3592
3593 if (sel->datacb)
3594 {
3595 ddata.x = 0;
3596 ddata.y = 0;
3597
3598 /* Pass to cocoa clipboard */
3599 type = _elm_sel_format_to_ecore_cocoa_cnp_type(sel->requestformat);
3600 pbdata = ecore_cocoa_selection_clipboard_get(&pbdata_len, type, &get_type);
3601
3602 ddata.format = ELM_SEL_FORMAT_NONE;
3603 if (get_type & ECORE_COCOA_CNP_TYPE_STRING)
3604 ddata.format |= ELM_SEL_FORMAT_TEXT;
3605 if (get_type & ECORE_COCOA_CNP_TYPE_MARKUP)
3606 ddata.format |= ELM_SEL_FORMAT_MARKUP;
3607 if (get_type & ECORE_COCOA_CNP_TYPE_IMAGE)
3608 ddata.format |= ELM_SEL_FORMAT_IMAGE;
3609 if (get_type & ECORE_COCOA_CNP_TYPE_HTML)
3610 ddata.format |= ELM_SEL_FORMAT_HTML;
3611
3612 ddata.data = pbdata;
3613 ddata.len = pbdata_len;
3614 ddata.action = ELM_XDND_ACTION_UNKNOWN;
3615 sel->datacb(sel->udata, sel->requestwidget, &ddata);
3616 free(pbdata);
3617 }
3618}
3619
3620static Eina_Bool
3621_cocoa_elm_cnp_selection_set(Ecore_Cocoa_Window *win,
3622 Evas_Object *obj,
3623 Elm_Sel_Type selection,
3624 Elm_Sel_Format format,
3625 const void *selbuf,
3626 size_t buflen)
3627{
3628 Cocoa_Cnp_Selection *sel = &_cocoa_cnp_sel;
3629 Ecore_Cocoa_Cnp_Type type;
3630 Eina_Bool ok = EINA_TRUE;
3631
3632 if ((!selbuf) && (format != ELM_SEL_FORMAT_IMAGE))
3633 return elm_object_cnp_selection_clear(obj, selection);
3634 if (buflen <= 0) return EINA_FALSE;
3635
3636 if (sel->loss_cb) sel->loss_cb(sel->loss_data, selection);
3637 if (sel->widget)
3638 evas_object_event_callback_del_full(sel->widget, EVAS_CALLBACK_DEL,
3639 _cocoa_sel_obj_del_cb, sel);
3640
3641 sel->widget = obj;
3642 sel->win = win;
3643 sel->format = format;
3644 sel->loss_cb = NULL;
3645 sel->loss_data = NULL;
3646
3647 evas_object_event_callback_add(sel->widget, EVAS_CALLBACK_DEL,
3648 _cocoa_sel_obj_del_cb, sel);
3649 ELM_SAFE_FREE(sel->selbuf, free);
3650 sel->buflen = 0;
3651 if (selbuf)
3652 {
3653 sel->selbuf = malloc(buflen + 1);
3654 if (EINA_UNLIKELY(!sel->selbuf))
3655 {
3656 CRI("Failed to allocate memory!");
3657 elm_object_cnp_selection_clear(obj, selection);
3658 return EINA_FALSE;
3659 }
3660 memcpy(sel->selbuf, selbuf, buflen);
3661 sel->selbuf[buflen] = 0;
3662 sel->buflen = buflen;
3663 type = _elm_sel_format_to_ecore_cocoa_cnp_type(format);
3664 ecore_cocoa_selection_clipboard_set(selbuf, buflen, type);
3665 }
3666
3667 return ok;
3668}
3669
3670static void
3671_cocoa_elm_cnp_selection_loss_callback_set(Evas_Object *obj EINA_UNUSED,
3672 Elm_Sel_Type selection EINA_UNUSED,
3673 Elm_Selection_Loss_Cb func EINA_UNUSED,
3674 const void *data EINA_UNUSED)
3675{
3676 // Currently, we have no way to track changes in Cocoa pasteboard.
3677 // Therefore, don't track this...
3678 //sel->loss_cb = func;
3679 //sel->loss_data = (void *)data;
3680}
3681
3682static Eina_Bool
3683_cocoa_elm_cnp_selection_clear(Evas_Object *obj EINA_UNUSED,
3684 Elm_Sel_Type selection EINA_UNUSED)
3685{
3686 Cocoa_Cnp_Selection *sel = &_cocoa_cnp_sel;
3687
3688 if (sel->widget)
3689 evas_object_event_callback_del_full(sel->widget, EVAS_CALLBACK_DEL,
3690 _cocoa_sel_obj_del_cb, sel);
3691 if (sel->requestwidget)
3692 evas_object_event_callback_del_full(sel->requestwidget, EVAS_CALLBACK_DEL,
3693 _cocoa_sel_obj_del_req_cb, sel);
3694
3695 sel->widget = NULL;
3696 sel->requestwidget = NULL;
3697 sel->loss_cb = NULL;
3698 sel->loss_data = NULL;
3699 ELM_SAFE_FREE(sel->selbuf, free);
3700 sel->buflen = 0;
3701 ecore_cocoa_selection_clipboard_clear();
3702
3703 return EINA_TRUE;
3704}
3705
3706static Eina_Bool
3707_cocoa_elm_cnp_selection_get(const Evas_Object *obj,
3708 Ecore_Cocoa_Window *win,
3709 Elm_Sel_Type selection EINA_UNUSED,
3710 Elm_Sel_Format format,
3711 Elm_Drop_Cb datacb,
3712 void *udata)
3713{
3714 Cocoa_Cnp_Selection *sel = &_cocoa_cnp_sel;
3715
3716 if (sel->requestwidget)
3717 evas_object_event_callback_del_full(sel->requestwidget, EVAS_CALLBACK_DEL,
3718 _cocoa_sel_obj_del_req_cb, sel);
3719
3720 sel->requestformat = format;
3721 sel->requestwidget = (Evas_Object *)obj;
3722 sel->win = win;
3723 sel->datacb = datacb;
3724 sel->udata = udata;
3725
3726 ecore_job_add(_job_pb_cb, sel);
3727
3728 evas_object_event_callback_add(sel->requestwidget, EVAS_CALLBACK_DEL,
3729 _cocoa_sel_obj_del_req_cb, sel);
3730
3731 return EINA_TRUE;
3732}
3733
3734
3735#endif
3736
3484//////////////////////////////////////////////////////////////////////////// 3737////////////////////////////////////////////////////////////////////////////
3485// for local (Within 1 app/process) cnp (used by fb as fallback 3738// for local (Within 1 app/process) cnp (used by fb as fallback
3486//////////////////////////////////////////////////////////////////////////// 3739////////////////////////////////////////////////////////////////////////////
@@ -3860,6 +4113,11 @@ elm_cnp_selection_set(Evas_Object *obj, Elm_Sel_Type selection,
3860 if (_wl_elm_widget_window_get(obj)) 4113 if (_wl_elm_widget_window_get(obj))
3861 return _wl_elm_cnp_selection_set(obj, selection, format, selbuf, buflen); 4114 return _wl_elm_cnp_selection_set(obj, selection, format, selbuf, buflen);
3862#endif 4115#endif
4116#ifdef HAVE_ELEMENTARY_COCOA
4117 Ecore_Cocoa_Window *win = _cocoa_elm_widget_cocoa_window_get(obj);
4118 if (win)
4119 return _cocoa_elm_cnp_selection_set(win, obj, selection, format, selbuf, buflen);
4120#endif
3863 return _local_elm_cnp_selection_set(obj, selection, format, selbuf, buflen); 4121 return _local_elm_cnp_selection_set(obj, selection, format, selbuf, buflen);
3864} 4122}
3865 4123
@@ -3878,6 +4136,10 @@ elm_cnp_selection_loss_callback_set(Evas_Object *obj, Elm_Sel_Type selection,
3878 if (_wl_elm_widget_window_get(obj)) 4136 if (_wl_elm_widget_window_get(obj))
3879 _wl_elm_cnp_selection_loss_callback_set(obj, selection, func, data); 4137 _wl_elm_cnp_selection_loss_callback_set(obj, selection, func, data);
3880#endif 4138#endif
4139#ifdef HAVE_ELEMENTARY_COCOA
4140 if (_cocoa_elm_widget_cocoa_window_get(obj))
4141 _cocoa_elm_cnp_selection_loss_callback_set(obj, selection, func, data);
4142#endif
3881 _local_elm_cnp_selection_loss_callback_set(obj, selection, func, data); 4143 _local_elm_cnp_selection_loss_callback_set(obj, selection, func, data);
3882} 4144}
3883 4145
@@ -3894,6 +4156,10 @@ elm_object_cnp_selection_clear(Evas_Object *obj, Elm_Sel_Type selection)
3894 if (_wl_elm_widget_window_get(obj)) 4156 if (_wl_elm_widget_window_get(obj))
3895 return _wl_elm_cnp_selection_clear(obj, selection); 4157 return _wl_elm_cnp_selection_clear(obj, selection);
3896#endif 4158#endif
4159#ifdef HAVE_ELEMENTARY_COCOA
4160 if (_cocoa_elm_widget_cocoa_window_get(obj))
4161 return _cocoa_elm_cnp_selection_clear(obj, selection);
4162#endif
3897 return _local_elm_object_cnp_selection_clear(obj, selection); 4163 return _local_elm_object_cnp_selection_clear(obj, selection);
3898} 4164}
3899 4165
@@ -3912,6 +4178,11 @@ elm_cnp_selection_get(const Evas_Object *obj, Elm_Sel_Type selection,
3912 if (_wl_elm_widget_window_get(obj)) 4178 if (_wl_elm_widget_window_get(obj))
3913 return _wl_elm_cnp_selection_get(obj, selection, format, datacb, udata); 4179 return _wl_elm_cnp_selection_get(obj, selection, format, datacb, udata);
3914#endif 4180#endif
4181#ifdef HAVE_ELEMENTARY_COCOA
4182 Ecore_Cocoa_Window *win = _cocoa_elm_widget_cocoa_window_get(obj);
4183 if (win)
4184 return _cocoa_elm_cnp_selection_get(obj, win, selection, format, datacb, udata);
4185#endif
3915 return _local_elm_cnp_selection_get(obj, selection, format, datacb, udata); 4186 return _local_elm_cnp_selection_get(obj, selection, format, datacb, udata);
3916} 4187}
3917 4188
@@ -4535,3 +4806,4 @@ end:
4535 doaccept = EINA_FALSE; 4806 doaccept = EINA_FALSE;
4536 return EINA_TRUE; 4807 return EINA_TRUE;
4537} 4808}
4809