diff options
author | Thiep Ha <thiepha@gmail.com> | 2017-12-07 15:04:04 +0900 |
---|---|---|
committer | Thiep Ha <thiepha@gmail.com> | 2017-12-08 11:17:23 +0900 |
commit | 821493add198e2033205d031b5d77b4b2b3ce38b (patch) | |
tree | 1d565f929f1658024b08101893bf27e43c13c69b | |
parent | d6874f71061f371556728b358e85aa5df6466123 (diff) | |
download | efl-821493add198e2033205d031b5d77b4b2b3ce38b.tar.gz |
cocoa: add implementation for cocoa, have not test yet
-rw-r--r-- | src/lib/elementary/efl_selection_manager.c | 215 | ||||
-rw-r--r-- | src/lib/elementary/efl_selection_manager_private.h | 11 |
2 files changed, 224 insertions, 2 deletions
diff --git a/src/lib/elementary/efl_selection_manager.c b/src/lib/elementary/efl_selection_manager.c index 66f0290a55..1c17d2acb5 100644 --- a/src/lib/elementary/efl_selection_manager.c +++ b/src/lib/elementary/efl_selection_manager.c @@ -107,6 +107,15 @@ _sel_manager_seat_selection_init(Efl_Selection_Manager_Data *pd, unsigned int se seat_sel->sel = sel; } #endif +#ifdef HAVE_ELEMENTARY_CO + if (!seat_sel->sel) + { + Sel_Manager_Selection *sel = calloc(1, sizeof(Sel_Manager_Selection)); + sel->seat_sel = seat_sel; + seat_sel->sel = sel; + } +#endif + return seat_sel; } @@ -3540,6 +3549,188 @@ _wl_sel_manager_drop_target_add(Efl_Selection_Manager_Data *pd, Efl_Object *targ } #endif +#ifdef HAVE_ELEMENTARY_COCOA +static Ecore_Cocoa_Window * +_cocoa_window_get(const Evas_Object *obj) +{ + Evas_Object *top, *par; + Ecore_Cocoa_Window *win = NULL; + + if (elm_widget_is(obj)) + { + top = elm_widget_top_get(obj); + if (!top) + { + par = elm_widget_parent_widget_get(obj); + if (par) top = elm_widget_top_get(par); + } + if ((top) && (efl_isa(top, EFL_UI_WIN_CLASS))) + win = elm_win_cocoa_window_get(top); + } + if (!win) + { + // FIXME + CRI("WIN has not been retrieved!!!"); + } + + return win; +} + +static Ecore_Cocoa_Cnp_Type +_sel_format_to_ecore_cocoa_cnp_type(Efl_Selection_Format fmt) +{ + Ecore_Cocoa_Cnp_Type type = 0; + + if ((fmt & EFL_SELECTION_FORMAT_TEXT) || + (fmt & EFL_SELECTION_FORMAT_VCARD)) + type |= ECORE_COCOA_CNP_TYPE_STRING; + if (fmt & EFL_SELECTION_FORMAT_MARKUP) + type |= ECORE_COCOA_CNP_TYPE_MARKUP; + if (fmt & EFL_SELECTION_FORMAT_HTML) + type |= ECORE_COCOA_CNP_TYPE_HTML; + if (fmt & EFL_SELECTION_FORMAT_IMAGE) + type |= ECORE_COCOA_CNP_TYPE_IMAGE; + + return type; +} + +static void +_cocoa_sel_obj_del_req_cb(void *data, + Evas *e EINA_UNUSED, + Evas_Object *obj, + void *ev_info EINA_UNUSED) +{ + Sel_Manager_Selection *sel = data; + if (sel->request_obj == obj) sel->request_obj = NULL; +} + +static void +_cocoa_sel_obj_del_cb(void *data, + Evas *e EINA_UNUSED, + Evas_Object *obj, + void *ev_info EINA_UNUSED) +{ + Sel_Manager_Selection *sel = data; + if (sel->owner == obj) + { + sel->owner = NULL; + } + //if (dragwidget == obj) dragwidget = NULL; +} + +static void +_job_pb_cb(void *data) +{ + Sel_Manager_Selection *sel = data; + Efl_Selection_Data ddata; + Ecore_Cocoa_Cnp_Type type, get_type; + void *pbdata; + int pbdata_len; + + if (sel->data_func) + { + ddata.x = 0; + ddata.y = 0; + + /* Pass to cocoa clipboard */ + type = _sel_format_to_ecore_cocoa_cnp_type(sel->request_format); + pbdata = ecore_cocoa_clipboard_get(&pbdata_len, type, &get_type); + + ddata.format = EFL_SELECTION_FORMAT_NONE; + if (get_type & ECORE_COCOA_CNP_TYPE_STRING) + ddata.format |= EFL_SELECTION_FORMAT_TEXT; + if (get_type & ECORE_COCOA_CNP_TYPE_MARKUP) + ddata.format |= EFL_SELECTION_FORMAT_MARKUP; + if (get_type & ECORE_COCOA_CNP_TYPE_IMAGE) + ddata.format |= EFL_SELECTION_FORMAT_IMAGE; + if (get_type & ECORE_COCOA_CNP_TYPE_HTML) + ddata.format |= EFL_SELECTION_FORMAT_HTML; + + ddata.data = pbdata; + ddata.len = pbdata_len; + ddata.action = EFL_SELECTION_ACTION_UNKNOWN; + sel->data_func(sel->data_func_data, sel->request_obj, &ddata); + free(pbdata); + } +} + +static void +_cocoa_efl_sel_manager_selection_set(Efl_Selection_Manager_Data *pd, + Evas_Object *owner, + Efl_Selection_Type type, + Efl_Selection_Format format, + const void *buf, + size_t len, + Sel_Manager_Seat_Selection *seat_sel) +{ + Sel_Manager_Selection *sel; + Ecore_Cocoa_Cnp_Type ecore_type; + Ecore_Win32_Window *win; + + sel = seat_sel->sel; + win = _cocoa_window_get(owner); + if ((!buf) && (format != EFL_SELECTION_FORMAT_IMAGE)) + return efl_selection_manager_selection_clear(pd->sel_man, owner, type, seat_sel->seat); + if (len <= 0) return EINA_FALSE; + + efl_event_callback_call(sel->owner, EFL_SELECTION_EVENT_SELECTION_LOSS, NULL); + if (sel->owner) + evas_object_event_callback_del_full(sel->owner, EVAS_CALLBACK_DEL, + _cocoa_sel_obj_del_cb, sel); + + sel->owner = owner; + sel->win = win; + sel->format = format; + + evas_object_event_callback_add(sel->owner, EVAS_CALLBACK_DEL, + _cocoa_sel_obj_del_cb, sel); + ELM_SAFE_FREE(sel->buf, free); + sel->len = 0; + if (buf) + { + sel->buf = malloc(len + 1); + if (EINA_UNLIKELY(!sel->buf)) + { + CRI("Failed to allocate memory!"); + efl_selection_manager_selection_clear(pd->sel_man, owner, type, seat_sel->seat); + return; + } + memcpy(sel->buf, buf, len); + sel->buf[len] = 0; + sel->len = len; + ecore_type = _sel_format_to_ecore_cocoa_cnp_type(format); + ecore_cocoa_clipboard_set(buf, len, ecore_type); + } + + return; +} + +static void +_cocoa_efl_sel_manager_selection_get(const Evas_Object *owner, + Efl_Selection_Manager_Data *pd, + Efl_Selection_Type type EINA_UNUSED, + Efl_Selection_Format format, + Sel_Manager_Seat_Selection *seat_sel) +{ + Ecore_Cocoa_Window *win; + Sel_Manager_Selection *sel; + + sel = seat_sel->sel; + sel->request_format = format; + win = _cocoa_window_get(owner); + if (sel->request_obj) + evas_object_event_callback_del_full(sel->request_obj, EVAS_CALLBACK_DEL, + _cocoa_sel_obj_del_req_cb, sel); + + sel->win = win; + ecore_job_add(_job_pb_cb, sel); + + evas_object_event_callback_add(sel->request_obj, EVAS_CALLBACK_DEL, + _cocoa_sel_obj_del_req_cb, sel); +} + +#endif + static int _drop_item_container_cmp(const void *d1, const void *d2) { @@ -3916,6 +4107,7 @@ _efl_selection_manager_selection_set(Eo *obj, Efl_Selection_Manager_Data *pd, return _wl_efl_sel_manager_selection_set(pd, owner, type, format, buf, len, seat_sel); #endif #ifdef HAVE_ELEMENTARY_COCOA + return _cocoa_efl_sel_manager_selection_set(pd, owner, type, format, buf, len, seat_sel); #endif #ifdef HAVE_ELEMENTARY_WIN32 #endif @@ -3941,6 +4133,9 @@ _efl_selection_manager_selection_get(Eo *obj, Efl_Selection_Manager_Data *pd, #ifdef HAVE_ELEMENTARY_WL2 sel = seat_sel->sel; #endif +#ifdef HAVE_ELEMENTARY_COCOA + sel = seat_sel->sel; +#endif sel->request_obj = owner; sel->data_func_data = data_func_data; sel->data_func = data_func; @@ -3952,6 +4147,9 @@ _efl_selection_manager_selection_get(Eo *obj, Efl_Selection_Manager_Data *pd, #ifdef HAVE_ELEMENTARY_WL2 _wl_efl_sel_manager_selection_get(owner, pd, type, format, seat_sel); #endif +#ifdef HAVE_ELEMENTARY_COCOA + _cocoa_efl_sel_manager_selection_get(owner, pd, type, format, seat_sel); +#endif } EOLIAN static void @@ -3971,6 +4169,9 @@ _efl_selection_manager_selection_clear(Eo *obj, Efl_Selection_Manager_Data *pd, #ifdef HAVE_ELEMENTARY_WL2 sel = seat_sel->sel; #endif +#ifdef HAVE_ELEMENTARY_COCOA + sel = seat_sel->sel; +#endif if ((!sel->active) && (sel->owner != owner)) { return; @@ -3999,6 +4200,20 @@ _efl_selection_manager_selection_clear(Eo *obj, Efl_Selection_Manager_Data *pd, sel->selection_serial = ecore_wl2_dnd_selection_clear(_wl_seat_get(_wl_window_get(owner), owner, seat)); ERR("sel serial: %d", sel->selection_serial); #endif +#ifdef HAVE_ELEMENTARY_COCOA + if (sel->owner) + evas_object_event_callback_del_full(sel->owner, EVAS_CALLBACK_DEL, + _cocoa_sel_obj_del_cb, sel); + if (sel->request_obj) + evas_object_event_callback_del_full(sel->request_obj, EVAS_CALLBACK_DEL, + _cocoa_sel_obj_del_req_cb, sel); + sel->owner = NULL; + sel->request_obj = NULL; + ELM_SAFE_FREE(sel->buf, free); + sel->len = 0; + + ecore_cocoa_clipboard_clear(); +#endif } EOLIAN static Eina_Bool diff --git a/src/lib/elementary/efl_selection_manager_private.h b/src/lib/elementary/efl_selection_manager_private.h index 33534cfe7a..e45e2e770b 100644 --- a/src/lib/elementary/efl_selection_manager_private.h +++ b/src/lib/elementary/efl_selection_manager_private.h @@ -43,11 +43,11 @@ typedef struct _Anim_Icon Anim_Icon; typedef struct _Sel_Manager_Drag_Container Sel_Manager_Drag_Container; typedef struct _Drop_Format Drop_Format; typedef struct _Item_Container_Drop_Info Item_Container_Drop_Info; +typedef struct _Sel_Manager_Selection Sel_Manager_Selection; #ifdef HAVE_ELEMENTARY_X typedef struct _Tmp_Info Tmp_Info; typedef struct _Saved_Type Saved_Type; -typedef struct _Sel_Manager_Selection Sel_Manager_Selection; typedef Eina_Bool (*X11_Converter_Fn_Cb) (char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize); typedef int (*X11_Response_Handler_Cb) (Sel_Manager_Selection *sel, Ecore_X_Event_Selection_Notify *); @@ -107,10 +107,14 @@ struct _Sel_Manager_Selection Ecore_Event_Handler *offer_handler; Ecore_Wl2_Window *win; #endif +#ifdef HAVE_ELEMENTARY_COCOA + Ecore_Cocoa_Window *win; + int pb_count; +#endif Efl_Selection_Format format; Efl_Selection_Action action; - Eina_Bool active; + Eina_Bool active : 1; Eo *owner; @@ -131,6 +135,9 @@ struct _Sel_Manager_Seat_Selection #ifdef HAVE_ELEMENTARY_WL2 Sel_Manager_Selection *sel; #endif +#ifdef HAVE_ELEMENTARY_COCOA + Sel_Manager_Selection *sel; +#endif //drag Eo *drag_obj; |