Dear. All elementary developer.
 
Attached to the mail is the patch for new API.
This patch changes elm_entry_cnp_test_only_set/get APIs to 
elm_entry_cnp_mode_set/get APIs.
 
Patch is useful for 3 cases when copy&paste through entry in application.
case 1 : get original markup text
case 2 : get markup text without image
case 3 : get plain text
 
CNP_MODE can be set these values.
EML_CNP_MODE_MARKUP : any tags are not removed.
EML_CNP_MODE_NO_IMAGE : just removes all item tags.
EML_CNP_MODE_PLAINTEXT : removes all item tags, fonts and color tags.
 
Please review this patch.
 
Best regards.
Index: src/lib/elm_entry.c
===================================================================
--- src/lib/elm_entry.c (revision 68035)
+++ src/lib/elm_entry.c (working copy)
@@ -67,7 +67,7 @@
    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;
@@ -1129,14 +1129,67 @@
      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);
+   
+   char *str;
+   if (wd->cnp_mode == ELM_CNP_MODE_NO_IMAGE)
+     {
+        str = _remove_item_tags(entry);
+        if (!str)
+          str = strdup(entry);
+     }
+   else
+     str = strdup(entry);
+
    Elm_Entry_Change_Info info;
    info.merge = EINA_FALSE;
    info.insert = EINA_TRUE;
    info.change.insert.pos = elm_entry_cursor_pos_get(obj);
-   info.change.insert.content = eina_stringshare_add(entry);
+   info.change.insert.content = eina_stringshare_add(str);
      {
         char *tmp;
         tmp = evas_textblock_text_markup_to_utf8(elm_entry_textblock_get(obj),
@@ -1145,10 +1198,11 @@
         free(tmp);
      }
 
-   elm_entry_entry_insert(obj, entry);
+   elm_entry_entry_insert(obj, str);
    evas_object_smart_callback_call(obj, SIG_CHANGED_USER, &info);
 
    eina_stringshare_del(info.change.insert.content);
+   free(str);
 }
 
 static void
@@ -1160,10 +1214,11 @@
    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(ELM_SEL_TYPE_CLIPBOARD, formats, data, NULL, 
NULL);
 #endif
@@ -1175,13 +1230,33 @@
 {
    Widget_Data *wd = elm_widget_data_get(obj);
    const char *sel;
+   char *sel_str = NULL;
+   Elm_Sel_Format formats = ELM_SEL_FORMAT_MARKUP;
 
    if (!wd) return;
    sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
    if ((!sel) || (!sel[0])) return; /* avoid deleting our own selection */
-   elm_cnp_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel, 
strlen(sel));
+
+   if (wd->cnp_mode == ELM_CNP_MODE_PLAINTEXT)
+     {
+        sel_str = elm_entry_markup_to_utf8(sel);
+        if (!sel_str)
+          return;
+        formats = ELM_SEL_FORMAT_TEXT;
+     }
+   else if (wd->cnp_mode == ELM_CNP_MODE_NO_IMAGE)
+     {
+        sel_str = _remove_item_tags(sel);
+        if (!sel_str)
+          sel_str = strdup(sel);
+     }
+   else
+     sel_str = strdup(sel);
+
+   elm_cnp_selection_set(seltype, obj, formats, sel_str, strlen(sel_str));
    if (seltype == ELM_SEL_TYPE_CLIPBOARD)
-     eina_stringshare_replace(&wd->cut_sel, sel);
+     eina_stringshare_replace(&wd->cut_sel, sel_str);
+   free(sel_str);
 }
 
 static void
@@ -1656,7 +1731,12 @@
         if ((top) && (elm_win_xwindow_get(top)))
           {
              wd->selection_asked = EINA_TRUE;
-             elm_cnp_selection_get(type, ELM_SEL_FORMAT_MARKUP, data,
+             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(type, formats, data,
                                NULL, NULL);
           }
 #endif
@@ -2314,7 +2394,7 @@
    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;
 
@@ -2435,7 +2515,7 @@
    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)
      {
@@ -3311,28 +3391,29 @@
 }
 
 EAPI void
-elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
+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;
    Widget_Data *wd = elm_widget_data_get(obj);
    if (!wd) return EINA_FALSE;
-   return wd->textonly;
+   return wd->cnp_mode;
 }
 
 EAPI void
Index: src/lib/elm_entry.h
===================================================================
--- src/lib/elm_entry.h (revision 68035)
+++ src/lib/elm_entry.h (working copy)
@@ -59,6 +59,20 @@
 } Elm_Input_Panel_Return_Key_Type;
 
 /**
+ * @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;
+
+/**
  * @defgroup Entry Entry
  *
  * @image html img/widget/entry/preview-00.png
@@ -983,26 +997,29 @@
 /**
  * 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.
+ * Normally the entry allows both text and images to be pasted.
+ * By setting textonly to be ELM_CNP_MODE_NO_IMAGE, this prevents images from 
being copy or past.
+ * By setting textonly to be ELM_CNP_MODE_PLAINTEXT, this remove all tags in 
text .
  *
- * Note this only changes the behaviour of text.
+ * @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.
+ * @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_textonly_set(Evas_Object *obj, Eina_Bool 
textonly);
+EAPI void         elm_entry_cnp_mode_set(Evas_Object *obj, Elm_CNP_Mode 
cnp_mode);
 
 /**
  * Getting elm_entry text paste/drop mode.
  *
- * In textonly mode, only text may be pasted or dropped into the widget.
+ * 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 If the widget only accepts text from pastes.
+ * @return mode One of #Elm_CNP_Mode: #ELM_CNP_MODE_MARKUP,
+ * #ELM_CNP_MODE_NO_IMAGE, #ELM_CNP_MODE_PLAINTEXT.
  */
-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);
 
 /**
  * Enable or disable scrolling in entry
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to