/**
+ * 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.
*
* @return Duration after which tooltip will be shown.
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;
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, "<item");
+ if (!startTag)
+ startTag = strstr(temp, "</item");
+ if (startTag)
+ endTag = strstr(startTag, ">");
+ 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
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
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
}
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;
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)
{
EAPI void
elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
{
+ ELM_CHECK_WIDTYPE(obj, widtype);
+ 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;
- textonly = !!textonly;
- if (wd->textonly == textonly) return;
- wd->textonly = !!textonly;
- if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
+ 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 Eina_Bool
-elm_entry_cnp_textonly_get(const Evas_Object *obj)
+EAPI Elm_CNP_Mode
+elm_entry_cnp_mode_get(const Evas_Object *obj)
{
- ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
+ ELM_CHECK_WIDTYPE(obj, widtype) ELM_CNP_MODE_MARKUP;
Widget_Data *wd = elm_widget_data_get(obj);
- if (!wd) return EINA_FALSE;
- return wd->textonly;
+ if (!wd) return ELM_CNP_MODE_MARKUP;
+ return wd->cnp_mode;
}
EAPI void
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
*
* Normally the entry is not scrollable unless you enable it with this call.
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);
+
+
+/**
* @}
*/