diff --git a/legacy/elementary/src/lib/elm_deprecated.h b/legacy/elementary/src/lib/elm_deprecated.h index e7e25cf382..c20b871ab3 100644 --- a/legacy/elementary/src/lib/elm_deprecated.h +++ b/legacy/elementary/src/lib/elm_deprecated.h @@ -4392,6 +4392,33 @@ EINA_DEPRECATED EAPI double elm_route_lon_max_get(Evas_Object *obj); EINA_DEPRECATED EAPI double elm_route_lat_max_get(Evas_Object *obj); +/** + * Control pasting of text and images for the widget. + * + * Normally the entry allows both text and images to be pasted. By setting + * textonly to be true, this prevents images from being pasted. + * + * Note this only changes the behaviour of text. + * + * @param obj The entry object + * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is + * text+image+other. + * @deprecated Use elm_entry_cnp_mode_set() instead. + */ +EINA_DEPRECATED EAPI void elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly); + +/** + * Getting elm_entry text paste/drop mode. + * + * In textonly mode, only text may be pasted or dropped into the widget. + * + * @param obj The entry object + * @return If the widget only accepts text from pastes. + * @deprecated Use elm_entry_cnp_mode_get() instead. + */ +EINA_DEPRECATED EAPI Eina_Bool elm_entry_cnp_textonly_get(const Evas_Object *obj); + + /** * Get the duration after which tooltip will be shown. * diff --git a/legacy/elementary/src/lib/elm_entry.c b/legacy/elementary/src/lib/elm_entry.c index 26643277e5..f7aaeb3c28 100644 --- a/legacy/elementary/src/lib/elm_entry.c +++ b/legacy/elementary/src/lib/elm_entry.c @@ -67,7 +67,7 @@ struct _Widget_Data Eina_Bool drag_selection_asked : 1; Eina_Bool can_write : 1; Eina_Bool autosave : 1; - Eina_Bool textonly : 1; + Elm_CNP_Mode cnp_mode : 2; Eina_Bool usedown : 1; Eina_Bool scroll : 1; Eina_Bool h_bounce : 1; @@ -1146,11 +1146,67 @@ _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) elm_widget_scroll_hold_push(data); } +static char * +_remove_item_tags(const char *str) +{ + char *ret; + if (!str) + return NULL; + + Eina_Strbuf *buf = eina_strbuf_new(); + if (!buf) + return NULL; + + if (!eina_strbuf_append(buf, str)) + return NULL; + + while (EINA_TRUE) + { + const char *temp = eina_strbuf_string_get(buf); + + char *startTag = NULL; + char *endTag = NULL; + + startTag = strstr(temp, ""); + else + break; + if (!endTag || startTag > endTag) + break; + + size_t sindex = startTag - temp; + size_t eindex = endTag - temp + 1; + if (!eina_strbuf_remove(buf, sindex, eindex)) + break; + } + ret = eina_strbuf_string_steal(buf); + eina_strbuf_free(buf); + return ret; +} + void _elm_entry_entry_paste(Evas_Object *obj, const char *entry) { Widget_Data *wd = elm_widget_data_get(obj); - edje_object_part_text_user_insert(wd->ent, "elm.text", entry); + + char *str = NULL; + if (wd->cnp_mode == ELM_CNP_MODE_NO_IMAGE) + { + str = _remove_item_tags(entry); + if (!str) + str = strdup(entry); + } + else + str = strdup(entry); + if (!str) + str = entry; + + edje_object_part_text_user_insert(wd->ent, "elm.text", str); + if ( str != entry) + free(str); } static void @@ -1162,10 +1218,11 @@ _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) if (wd->sel_notify_handler) { #ifdef HAVE_ELEMENTARY_X - Elm_Sel_Format formats; + Elm_Sel_Format formats = ELM_SEL_FORMAT_MARKUP; wd->selection_asked = EINA_TRUE; - formats = ELM_SEL_FORMAT_MARKUP; - if (!wd->textonly) + if (wd->cnp_mode == ELM_CNP_MODE_PLAINTEXT) + formats = ELM_SEL_FORMAT_TEXT; + else if (wd->cnp_mode != ELM_CNP_MODE_NO_IMAGE) formats |= ELM_SEL_FORMAT_IMAGE; elm_cnp_selection_get(data, ELM_SEL_TYPE_CLIPBOARD, formats, NULL, NULL); #endif @@ -1658,8 +1715,13 @@ _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char if ((top) && (elm_win_xwindow_get(top))) { wd->selection_asked = EINA_TRUE; - elm_cnp_selection_get(data, type, ELM_SEL_FORMAT_MARKUP, - NULL, NULL); + Elm_Sel_Format formats = ELM_SEL_FORMAT_MARKUP; + if (wd->cnp_mode == ELM_CNP_MODE_PLAINTEXT) + formats = ELM_SEL_FORMAT_TEXT; + else if (wd->cnp_mode != ELM_CNP_MODE_NO_IMAGE) + formats |= ELM_SEL_FORMAT_IMAGE; + elm_cnp_selection_get(data, type, formats, + NULL, NULL); } #endif } @@ -2316,7 +2378,7 @@ elm_entry_add(Evas_Object *parent) wd->disabled = EINA_FALSE; wd->context_menu = EINA_TRUE; wd->autosave = EINA_TRUE; - wd->textonly = EINA_FALSE; + wd->cnp_mode = ELM_CNP_MODE_MARKUP; wd->scroll = EINA_FALSE; wd->input_panel_imdata = NULL; @@ -2437,7 +2499,7 @@ elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line) if (wd->single_line == single_line) return; wd->single_line = single_line; wd->linewrap = ELM_WRAP_NONE; - elm_entry_cnp_textonly_set(obj, EINA_TRUE); + elm_entry_cnp_mode_set(obj, ELM_CNP_MODE_NO_IMAGE); _theme_hook(obj); if (wd->scroller) { @@ -3315,26 +3377,44 @@ elm_entry_autosave_get(const Evas_Object *obj) EAPI void elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly) { - Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP; ELM_CHECK_WIDTYPE(obj, widtype); - Widget_Data *wd = elm_widget_data_get(obj); - if (!wd) return; - textonly = !!textonly; - if (wd->textonly == textonly) return; - wd->textonly = !!textonly; - if (!textonly) format |= ELM_SEL_FORMAT_IMAGE; -#ifdef HAVE_ELEMENTARY_X - elm_drop_target_add(obj, format, _drag_drop_cb, NULL); -#endif + Elm_CNP_Mode cnp_mode = ELM_CNP_MODE_MARKUP; + if (textonly) + cnp_mode = ELM_CNP_MODE_NO_IMAGE; + elm_entry_cnp_mode_set(obj, cnp_mode); } EAPI Eina_Bool elm_entry_cnp_textonly_get(const Evas_Object *obj) { ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE; + return elm_entry_cnp_mode_get(obj) != ELM_CNP_MODE_MARKUP; +} + +EAPI void +elm_entry_cnp_mode_set(Evas_Object *obj, Elm_CNP_Mode cnp_mode) +{ + Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP; + ELM_CHECK_WIDTYPE(obj, widtype); Widget_Data *wd = elm_widget_data_get(obj); - if (!wd) return EINA_FALSE; - return wd->textonly; + if (!wd) return; + if (wd->cnp_mode == cnp_mode) return; + wd->cnp_mode = cnp_mode; + if (wd->cnp_mode == ELM_CNP_MODE_PLAINTEXT) + format = ELM_SEL_FORMAT_TEXT; + else if (cnp_mode == ELM_CNP_MODE_MARKUP) format |= ELM_SEL_FORMAT_IMAGE; +#ifdef HAVE_ELEMENTARY_X + elm_drop_target_add(obj, format, _drag_drop_cb, NULL); +#endif +} + +EAPI Elm_CNP_Mode +elm_entry_cnp_mode_get(const Evas_Object *obj) +{ + ELM_CHECK_WIDTYPE(obj, widtype) ELM_CNP_MODE_MARKUP; + Widget_Data *wd = elm_widget_data_get(obj); + if (!wd) return ELM_CNP_MODE_MARKUP; + return wd->cnp_mode; } EAPI void diff --git a/legacy/elementary/src/lib/elm_entry.h b/legacy/elementary/src/lib/elm_entry.h index adf358324f..dc095b6558 100644 --- a/legacy/elementary/src/lib/elm_entry.h +++ b/legacy/elementary/src/lib/elm_entry.h @@ -1025,30 +1025,6 @@ EAPI void elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autos */ EAPI Eina_Bool elm_entry_autosave_get(const Evas_Object *obj); -/** - * Control pasting of text and images for the widget. - * - * Normally the entry allows both text and images to be pasted. By setting - * textonly to be true, this prevents images from being pasted. - * - * Note this only changes the behaviour of text. - * - * @param obj The entry object - * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is - * text+image+other. - */ -EAPI void elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly); - -/** - * Getting elm_entry text paste/drop mode. - * - * In textonly mode, only text may be pasted or dropped into the widget. - * - * @param obj The entry object - * @return If the widget only accepts text from pastes. - */ -EAPI Eina_Bool elm_entry_cnp_textonly_get(const Evas_Object *obj); - /** * Enable or disable scrolling in entry * @@ -1407,6 +1383,48 @@ EAPI void elm_entry_filter_accept_set(void *data, Evas_Object */ EAPI void *elm_entry_imf_context_get(Evas_Object *obj); +/** + * @enum _Elm_CNP_Mode + * @typedef Elm_CNP_Mode + * Enum of entry's copy & paste policy. + * + * @see elm_entry_cnp_mode_set() + * @see elm_entry_cnp_mode_get() + */ +typedef enum _Elm_CNP_Mode { + ELM_CNP_MODE_MARKUP = 0, /**< copy & paste text with markup tag */ + ELM_CNP_MODE_NO_IMAGE = 1, /**< copy & paste text without item(image) tag */ + ELM_CNP_MODE_PLAINTEXT = 2 /**< copy & paste text without markup tag */ +} Elm_CNP_Mode; + +/** + * Control pasting of text and images for the widget. + * + * Normally the entry allows both text and images to be pasted. + * By setting cnp_mode to be ELM_CNP_MODE_NO_IMAGE, this prevents images from being copy or past. + * By setting cnp_mode to be ELM_CNP_MODE_PLAINTEXT, this remove all tags in text . + * + * @note this only changes the behaviour of text. + * + * @param obj The entry object + * @param mode One of #Elm_CNP_Mode: #ELM_CNP_MODE_MARKUP, + * #ELM_CNP_MODE_NO_IMAGE, #ELM_CNP_MODE_PLAINTEXT. + */ +EAPI void elm_entry_cnp_mode_set(Evas_Object *obj, Elm_CNP_Mode cnp_mode); + +/** + * Getting elm_entry text paste/drop mode. + * + * Normally the entry allows both text and images to be pasted. + * This gets the copy & paste mode of the entry. + * + * @param obj The entry object + * @return mode One of #Elm_CNP_Mode: #ELM_CNP_MODE_MARKUP, + * #ELM_CNP_MODE_NO_IMAGE, #ELM_CNP_MODE_PLAINTEXT. + */ +EAPI Elm_CNP_Mode elm_entry_cnp_mode_get(const Evas_Object *obj); + + /** * @} */