Dear. All elementary library developers.
 
I deprecated old apis(elm_entry_cnp_textonly_set/get) in this patch.
Please review this patch once again.
 
Best regards.
-----Original Message-----
From: "Carsten Haitzler"<ras...@rasterman.com>
To: "Enlightenment developer 
list"<enlightenment-devel@lists.sourceforge.net>
Cc: "김대성"<ad960...@naver.com>
Sent: 12-02-24(금) 18:49:29
Subject: Re: [E-devel] suggest new api for elm_entry's copy & paste behavior
On Fri, 17 Feb 2012 17:45:57 +0900 김대성<ad960...@naver.com> said:
could you provide this new api and ALSO deprecate the old apis so we dont have
an instant api break? (we can deprecate and move over the next few days/weeeks)?
>
> 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.
--
------------- Codito, ergo sum - "I code, therefore I am" --------------
The Rasterman (Carsten Haitzler) ras...@rasterman.com
Index: src/lib/elm_entry.c
===================================================================
--- src/lib/elm_entry.c (revision 68468)
+++ 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 = NULL;
+   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
@@ -1656,8 +1711,13 @@
         if ((top) && (elm_win_xwindow_get(top)))
           {
              wd->selection_asked = EINA_TRUE;
-             elm_cnp_selection_get(type, ELM_SEL_FORMAT_MARKUP, data,
-                               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(type, formats, data,
+                                   NULL, NULL);
           }
 #endif
      }
@@ -2314,7 +2374,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 +2495,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)
      {
@@ -3313,26 +3373,44 @@
 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
Index: src/lib/elm_entry.h
===================================================================
--- src/lib/elm_entry.h (revision 68468)
+++ src/lib/elm_entry.h (working copy)
@@ -1026,30 +1026,6 @@
 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.
@@ -1383,5 +1359,47 @@
 EAPI void                   elm_entry_filter_accept_set(void *data, 
Evas_Object *entry, char **text);
 
 /**
+ * @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);
+
+
+/**
  * @}
  */
Index: src/lib/elm_deprecated.h
===================================================================
--- src/lib/elm_deprecated.h    (revision 68468)
+++ src/lib/elm_deprecated.h    (working copy)
@@ -4249,6 +4249,35 @@
 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);
+
+
+
+/**
  * @}
  */
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to