From 8dbd325155839805fa62277df60a8b7e5086d51c Mon Sep 17 00:00:00 2001 From: Thiep Ha Date: Tue, 3 May 2016 09:49:14 +0000 Subject: [PATCH] elm cnp/Wl: set selection for all data types Currently, not all selection data types are set. This patch sets selection for all suitable types that we supported. Change-Id: I18b32aa28685b4c9e0e60fc378f7d597aab7217b --- src/lib/elm_cnp.c | 128 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 100 insertions(+), 28 deletions(-) diff --git a/src/lib/elm_cnp.c b/src/lib/elm_cnp.c index 6730db5..fef334f 100644 --- a/src/lib/elm_cnp.c +++ b/src/lib/elm_cnp.c @@ -2499,6 +2499,21 @@ static unsigned int _wl_elm_widget_window_get(const Evas_Object *obj); static Evas * _wl_evas_get_from_win(unsigned int win); static Eina_Bool +_wl_is_uri_type_data(const char *data, int len) +{ + char *p; + if (len < 6) return EINA_FALSE; + + p = (char *)data; + if (!p) return EINA_FALSE; + if (strncmp(p, "file:/", 6)) + { + if (*p != '/') return EINA_FALSE; + } + return EINA_TRUE; +} + +static Eina_Bool _wl_targets_converter(char *target, Wl_Cnp_Selection *sel EINA_UNUSED, void *data EINA_UNUSED, int size EINA_UNUSED, void **data_ret, int *size_ret) { cnp_debug("in\n"); @@ -2919,6 +2934,10 @@ _wl_elm_cnp_selection_set(Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Form //Wl_Cnp_Selection *sel = &wl_cnp_selection; Wl_Cnp_Selection *sel = wl_cnp_selections + selection; // + // TIZEN_ONLY(20160811): To distinguish clipboard selection in cbhm + const char **t = NULL; + // + if ((!selbuf) && (format != ELM_SEL_FORMAT_IMAGE)) return elm_object_cnp_selection_clear(obj, selection); @@ -2956,6 +2975,10 @@ _wl_elm_cnp_selection_set(Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Form if (selbuf) { + int i = 0, count = 0; + Eina_Bool is_uri = EINA_FALSE; + const char **types; + if (format & ELM_SEL_FORMAT_IMAGE) { /* FIXME */ @@ -2971,51 +2994,100 @@ _wl_elm_cnp_selection_set(Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Form } else { - const char *types[10] = {0, }; - int i = -1; + free(sel->selbuf); + sel->buflen = buflen; + sel->selbuf = strdup((char*)selbuf); + } - // TIZEN_ONLY(20160706): To distinguish clipboard selection in cbhm - if (selection == ELM_SEL_TYPE_CLIPBOARD) + is_uri = _wl_is_uri_type_data(selbuf, buflen); + types = malloc(sizeof(char *)); + if (!types) return EINA_FALSE; + +// TIZEN_ONLY(20160811): To distinguish clipboard selection in cbhm + if (selection == ELM_SEL_TYPE_CLIPBOARD) + { + types[count] = "CLIPBOARD_BEGIN"; + count++; + t = realloc(types, sizeof(char *) * count); + if (!t) { - types[++i] = "CLIPBOARD_BEGIN"; + free(types); + return EINA_FALSE; } - // + types = t; + } - if ((format & ELM_SEL_FORMAT_MARKUP) || - (format & ELM_SEL_FORMAT_TEXT)) + for (i = 0, count = count + 1; i < CNP_N_ATOMS; i++) + { + if (format & _atoms[i].formats) { - types[++i] = "application/x-elementary-markup"; - types[++i] = "text/plain"; - types[++i] = "text/plain;charset=utf-8"; + if ((is_uri) || ((!is_uri) && + strcmp(_atoms[i].name, "text/uri-list"))) + { + + types[count - 1] = _atoms[i].name; + count++; + t = realloc(types, sizeof(char *) * count); + if (!t) + { + free(types); + return EINA_FALSE; + } + types = t; + } } + } - if (format & ELM_SEL_FORMAT_HTML) +/* + for (i = 0, count = 1; i < CNP_N_ATOMS; i++) + { + if (format & _atoms[i].formats) { - types[++i] = "text/html"; - types[++i] = "text/html;charset=utf-8"; - } + if ((is_uri) || ((!is_uri) && + strcmp(_atoms[i].name, "text/uri-list"))) + { + const char **t = NULL; - // TIZEN_ONLY(20160706): To distinguish clipboard selection in cbhm - if (selection == ELM_SEL_TYPE_CLIPBOARD) + types[count - 1] = _atoms[i].name; + count++; + t = realloc(types, sizeof(char *) * count); + if (!t) + { + free(types); + return EINA_FALSE; + } + types = t; + } + } + } +*/ + if (selection == ELM_SEL_TYPE_CLIPBOARD) + { + types[count] = "CLIPBOARD_END"; + count++; + t = realloc(types, sizeof(char *) * count); + if (!t) { - types[++i] = "CLIPBOARD_END"; + free(types); + return EINA_FALSE; } - // + types = t; + } +// + types[count - 1] = 0; - if (i < 0) return EINA_FALSE; + if (i < 0) return EINA_FALSE; - ecore_wl_dnd_selection_set(ecore_wl_input_get(), types); + ecore_wl_dnd_selection_set(ecore_wl_input_get(), types); - free(sel->selbuf); - sel->buflen = buflen; - sel->selbuf = strdup((char*)selbuf); - - return EINA_TRUE; - } + free(types); + return EINA_TRUE; } else - sel->selbuf = NULL; + { + sel->selbuf = NULL; + } return EINA_FALSE; } -- 2.7.4