[cnp] merge with opensource
authorminseok3.kim <minseok3.kim@samsung.com>
Thu, 8 Mar 2012 12:03:22 +0000 (21:03 +0900)
committerminseok3.kim <minseok3.kim@samsung.com>
Thu, 8 Mar 2012 12:03:22 +0000 (21:03 +0900)
src/bin/test_cnp.c
src/lib/elm_cnp.c
src/lib/elm_cnp.h

index 9be8a58..0a22001 100644 (file)
@@ -3,24 +3,17 @@
 # include "elementary_config.h"
 #endif
 #ifndef ELM_LIB_QUICKLAUNCH
-<<<<<<< HEAD
-=======
 
 static Evas_Object *glb;
 
->>>>>>> remotes/origin/upstream
 static void
 _bt_copy_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
 {
    Evas_Object *en = (Evas_Object*)(data);
    const char *txt = elm_object_text_get(en);
 
-<<<<<<< HEAD
-   elm_cnp_selection_set(ELM_SEL_TYPE_CLIPBOARD, elm_object_parent_widget_get(en),
-=======
    elm_object_text_set(glb, txt);
    elm_cnp_selection_set(elm_object_parent_widget_get(en), ELM_SEL_TYPE_CLIPBOARD,
->>>>>>> remotes/origin/upstream
                          ELM_SEL_FORMAT_TEXT, txt, strlen(txt));
 }
 
@@ -29,10 +22,6 @@ _bt_paste_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UN
 {
    Evas_Object *en = (Evas_Object*)(data);
 
-<<<<<<< HEAD
-   elm_cnp_selection_get(ELM_SEL_TYPE_CLIPBOARD, ELM_SEL_FORMAT_TEXT,
-                         en, NULL, NULL);
-=======
    elm_cnp_selection_get(en, ELM_SEL_TYPE_CLIPBOARD, ELM_SEL_FORMAT_TEXT,
                          NULL, NULL);
 }
@@ -44,17 +33,12 @@ _bt_clear_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UN
 
    elm_object_text_set(glb, "");
    elm_object_cnp_selection_clear(elm_object_parent_widget_get(en), ELM_SEL_TYPE_CLIPBOARD);
->>>>>>> remotes/origin/upstream
 }
 
 void
 test_cnp(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
 {
-<<<<<<< HEAD
-   Evas_Object *win, *bg, *gd, *bt, *en;
-=======
    Evas_Object *win, *bg, *gd, *bt, *en, *lb;
->>>>>>> remotes/origin/upstream
 
    win = elm_win_add(NULL, "CopyPaste", ELM_WIN_BASIC);
    elm_win_title_set(win, "CopyPaste");
@@ -76,23 +60,13 @@ test_cnp(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __
    elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
-<<<<<<< HEAD
-   elm_object_text_set(en,
-                               "Elementary provides "
-                                );
-   elm_grid_pack(gd, en, 10, 10, 60, 40);
-=======
    elm_object_text_set(en, "Elementary provides ");
    elm_grid_pack(gd, en, 10, 10, 60, 30);
->>>>>>> remotes/origin/upstream
    evas_object_show(en);
 
    bt = elm_button_add(win);
    elm_object_text_set(bt, "Copy from left entry");
    evas_object_smart_callback_add(bt, "clicked", _bt_copy_clicked, en);
-<<<<<<< HEAD
-   elm_grid_pack(gd, bt, 70, 10, 22, 40);
-=======
    elm_grid_pack(gd, bt, 70, 10, 22, 30);
    evas_object_show(bt);
 
@@ -100,7 +74,6 @@ test_cnp(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __
    elm_object_text_set(bt, "Clear clipboard");
    evas_object_smart_callback_add(bt, "clicked", _bt_clear_clicked, en);
    elm_grid_pack(gd, bt, 70, 70, 22, 20);
->>>>>>> remotes/origin/upstream
    evas_object_show(bt);
 
    en = elm_entry_add(win);
@@ -108,26 +81,13 @@ test_cnp(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __
    elm_entry_line_wrap_set(en, ELM_WRAP_CHAR);
    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
-<<<<<<< HEAD
-   elm_object_text_set(en,
-                               "rich copying and pasting functionality,"
-                                );
-   elm_grid_pack(gd, en, 10, 50, 60, 40);
-=======
    elm_object_text_set(en, "rich copying and pasting functionality,");
    elm_grid_pack(gd, en, 10, 40, 60, 30);
->>>>>>> remotes/origin/upstream
    evas_object_show(en);
 
    bt = elm_button_add(win);
    elm_object_text_set(bt, "Paste to left entry");
    evas_object_smart_callback_add(bt, "clicked", _bt_paste_clicked, en);
-<<<<<<< HEAD
-   elm_grid_pack(gd, bt, 70, 50, 22, 40);
-   evas_object_show(bt);
-
-   evas_object_resize(win, 480, 140);
-=======
    elm_grid_pack(gd, bt, 70, 40, 22, 30);
    evas_object_show(bt);
 
@@ -146,7 +106,6 @@ test_cnp(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __
    evas_object_show(glb);
 
    evas_object_resize(win, 480, 200);
->>>>>>> remotes/origin/upstream
    evas_object_show(win);
 }
 #endif
index 50f3921..d44e8ba 100644 (file)
@@ -142,10 +142,12 @@ static int notify_handler_targets(Cnp_Selection *sel, Ecore_X_Event_Selection_No
 static int notify_handler_text(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
 static int notify_handler_image(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
 static int notify_handler_uri(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
+static int notify_handler_edje(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
 static int notify_handler_html(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
 static int vcard_receive(Cnp_Selection *sed, Ecore_X_Event_Selection_Notify *notify);
 
 static Eina_Bool pasteimage_append(char *file, Evas_Object *entry);
+static void entry_insert_filter(Evas_Object* entry, char* str);
 
 static Cnp_Atom atoms[CNP_N_ATOMS] = {
      [CNP_ATOM_TARGETS] = {
@@ -169,12 +171,12 @@ static Cnp_Atom atoms[CNP_N_ATOMS] = {
           ELM_SEL_FORMAT_MARKUP,
           general_converter,
           NULL,
-          NULL,
+          notify_handler_edje,
           0
      },
      [CNP_ATOM_text_uri] = {
           "text/uri",
-          ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE, /* Either images or entries */
+          ELM_SEL_FORMAT_IMAGE, /* Either images or entries */
           general_converter,
           NULL,
           notify_handler_uri,
@@ -616,6 +618,9 @@ targets_converter(char *target __UNUSED__, void *data, int size, void **data_ret
 
    if (!data_ret) return EINA_FALSE;
 
+   if (!data || (*((unsigned int *)data) > ELM_SEL_TYPE_CLIPBOARD))
+     return EINA_FALSE;
+
    if (_get_selection_type(data, size) == ELM_SEL_FORMAT_NONE)
      {
         /* TODO : fallback into precise type */
@@ -660,6 +665,8 @@ vcard_send(char *target __UNUSED__, void *data __UNUSED__, int size __UNUSED__,
 
    cnp_debug("Vcard send called\n");
 
+   if (!data || (*((unsigned int *)data) > ELM_SEL_TYPE_CLIPBOARD))
+     return EINA_FALSE;
    sel = selections + *((int *)data);
 
    if (data_ret) *data_ret = strdup(sel->selbuf);
@@ -668,6 +675,7 @@ vcard_send(char *target __UNUSED__, void *data __UNUSED__, int size __UNUSED__,
    return EINA_TRUE;
 }
 
+#if 0
 static Eina_Bool
 is_uri_type_data(Cnp_Selection *sel __UNUSED__, Ecore_X_Event_Selection_Notify *notify)
 {
@@ -688,7 +696,7 @@ is_uri_type_data(Cnp_Selection *sel __UNUSED__, Ecore_X_Event_Selection_Notify *
 
    return EINA_TRUE;
 }
-
+#endif
 /*
  * Callback to handle a targets response on a selection request:
  * So pick the format we'd like; and then request it.
@@ -712,11 +720,13 @@ notify_handler_targets(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notif
           {
              if ((atoms[j].atom == atomlist[i]) && (atoms[j].notify))
                {
+#if 0
                   if ((j == CNP_ATOM_text_uri) ||
                       (j == CNP_ATOM_text_urilist))
                     {
                       if(!is_uri_type_data(sel, notify)) continue;
                     }
+#endif
                   cnp_debug("Atom %s matches\n",atoms[j].name);
                   goto done;
                }
@@ -769,6 +779,34 @@ found:
    return 0;
 }
 
+static void
+entry_insert_filter(Evas_Object* entry, char* str)
+{
+   if (!entry || !str)
+     return;
+
+   char *insertStr = str;
+
+   // if entry has single line set then remove <br> & <ps> tags
+   if (elm_entry_single_line_get(entry))
+     {
+        Eina_Strbuf *buf = eina_strbuf_new();
+        if (buf)
+          {
+             eina_strbuf_append(buf, insertStr);
+             eina_strbuf_replace_all(buf, "<br>", "");
+             eina_strbuf_replace_all(buf, "<ps>", "");
+             insertStr = eina_strbuf_string_steal(buf);
+             eina_strbuf_free(buf);
+          }
+     }
+   cnp_debug("remove break tag: %s\n", insertStr);
+
+   _elm_entry_entry_paste(entry, insertStr);
+
+   if (insertStr != str)
+     free(insertStr);
+}
 
 static int
 notify_handler_text(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
@@ -781,19 +819,24 @@ notify_handler_text(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
    if (sel->datacb)
      {
         Elm_Selection_Data ddata;
+        str = malloc(sizeof(char) * (data->length + 1));
+        strncpy(str, (char *)data->data, data->length);
+        str[data->length] = '\0';
 
         ddata.x = ddata.y = 0;
         ddata.format = ELM_SEL_FORMAT_TEXT;
-        ddata.data = data->data;
+        ddata.data = str;
         ddata.len = data->length;
         sel->datacb(sel->udata, sel->widget, &ddata);
+        free(str);
         return 0;
      }
 
    cnp_debug("Notify handler text %d %d %p\n", data->format,data->length, data->data);
    str = _elm_util_text_to_mkup((const char *) data->data);
    cnp_debug("String is %s (from %s)\n", str, data->data);
-   _elm_entry_entry_paste(sel->requestwidget, str);
+   entry_insert_filter(sel->requestwidget, str);
+   //_elm_entry_entry_paste(sel->requestwidget, str);
    free(str);
    return 0;
 }
@@ -836,6 +879,18 @@ notify_handler_uri(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
         return 0;
      }
    cnp_debug("Got %s\n",p);
+   if (sel->datacb)
+     {
+        Elm_Selection_Data ddata;
+
+        ddata.x = ddata.y = 0;
+        ddata.format = ELM_SEL_FORMAT_IMAGE;
+        ddata.data = p;
+        ddata.len = data->length;
+        sel->datacb(sel->udata, sel->widget, &ddata);
+        free(p);
+        return 0;
+     }
    if (strncmp(p, "file://", 7))
      {
         /* Try and continue if it looks sane */
@@ -956,6 +1011,35 @@ notify_handler_image(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
    return 0;
 }
 
+static int
+notify_handler_edje(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
+{
+   Ecore_X_Selection_Data *data;
+
+   data = notify->data;
+
+   char *stripstr = NULL;
+   stripstr = malloc(sizeof(char) * (data->length + 1));
+   strncpy(stripstr, (char *)data->data, data->length);
+   stripstr[data->length] = '\0';
+
+   if (sel->datacb)
+     {
+        Elm_Selection_Data ddata;
+        ddata.x = ddata.y = 0;
+        ddata.format = ELM_SEL_FORMAT_MARKUP;
+        ddata.data = stripstr;
+        ddata.len = data->length;
+        sel->datacb(sel->udata, sel->widget, &ddata);
+     }
+   else
+     entry_insert_filter(sel->requestwidget, stripstr);
+     //_elm_entry_entry_paste(sel->requestwidget, stripstr);
+
+   cnp_debug("String is %s (%d bytes)\n", stripstr, data->length);
+   free(stripstr);
+   return 0;
+}
 
 /**
  *    Warning: Generic text/html can';t handle it sanely.
@@ -970,22 +1054,25 @@ notify_handler_html(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
    cnp_debug("Got some HTML: Checking encoding is useful\n");
    data = notify->data;
 
+   char *stripstr = NULL;
+   stripstr = malloc(sizeof(char) * (data->length + 1));
+   strncpy(stripstr, (char *)data->data, data->length);
+   stripstr[data->length] = '\0';
+
    if (sel->datacb)
      {
         Elm_Selection_Data ddata;
         ddata.x = ddata.y = 0;
         ddata.format = ELM_SEL_FORMAT_HTML;
-        ddata.data = data->data;
+        ddata.data = stripstr;
         ddata.len = data->length;
         sel->datacb(sel->udata, sel->widget, &ddata);
-        return 0;
      }
+   else
+     entry_insert_filter(sel->requestwidget, stripstr);
+   //_elm_entry_entry_paste(sel->requestwidget, stripstr);
 
-   char *stripstr = malloc(sizeof(char) * (data->length + 1));
-   strncpy(stripstr, (char *)data->data, data->length);
-   stripstr[data->length] = '\0';
    cnp_debug("String is %s (%d bytes)\n", stripstr, data->length);
-   _elm_entry_entry_paste(sel->requestwidget, stripstr);
    free(stripstr);
    return 0;
 }
@@ -997,6 +1084,8 @@ text_converter(char *target __UNUSED__, void *data, int size, void **data_ret, i
    Cnp_Selection *sel;
 
    cnp_debug("text converter\n");
+   if (!data || (*((unsigned int *)data) > ELM_SEL_TYPE_CLIPBOARD))
+     return EINA_FALSE;
    if (_get_selection_type(data, size) == ELM_SEL_FORMAT_NONE)
      {
         if (data_ret)
@@ -1011,11 +1100,23 @@ text_converter(char *target __UNUSED__, void *data, int size, void **data_ret, i
    sel = selections + *((int *)data);
    if (!sel->active) return EINA_TRUE;
 
-   if ((sel->format & ELM_SEL_FORMAT_MARKUP) ||
-       (sel->format & ELM_SEL_FORMAT_HTML))
+   if (sel->format & ELM_SEL_FORMAT_MARKUP)
+     *data_ret = _elm_util_mkup_to_text(sel->selbuf);
+   else if (sel->format & ELM_SEL_FORMAT_HTML)
      {
-        *data_ret = _elm_util_mkup_to_text(sel->selbuf);
-        if (size_ret) *size_ret = strlen(*data_ret);
+        char *text = NULL;
+        Eina_Strbuf *buf = eina_strbuf_new();
+        if (buf)
+          {
+             eina_strbuf_append(buf, sel->selbuf);
+             eina_strbuf_replace_all(buf, "&nbsp;", " ");
+             text = eina_strbuf_string_steal(buf);
+             eina_strbuf_free(buf);
+             *data_ret = _elm_util_mkup_to_text(text);
+             free(text);
+          }
+        else
+          *data_ret = _elm_util_mkup_to_text(sel->selbuf);
      }
    else if (sel->format & ELM_SEL_FORMAT_TEXT)
      {
@@ -1050,7 +1151,11 @@ general_converter(char *target __UNUSED__, void *data, int size, void **data_ret
      }
    else
      {
-        Cnp_Selection *sel = selections + *((int *)data);
+        Cnp_Selection *sel;
+        if (!data || (*((unsigned int *)data) > ELM_SEL_TYPE_CLIPBOARD))
+          return EINA_FALSE;
+
+        sel = selections + *((int *)data);
         if (data_ret) *data_ret = strdup(sel->selbuf);
         if (size_ret) *size_ret = strlen(sel->selbuf);
      }
index 24bbbc4..b61ef59 100644 (file)
@@ -1,46 +1,4 @@
 /**
-<<<<<<< HEAD
- * @addtogroup CopyPaste
- * @{
- */
-
-typedef struct _Elm_Selection_Data Elm_Selection_Data;
-typedef Eina_Bool                (*Elm_Drop_Cb)(void *d, Evas_Object *o, Elm_Selection_Data *data);
-
-typedef enum
-{
-   ELM_SEL_TYPE_PRIMARY,
-   ELM_SEL_TYPE_SECONDARY,
-   ELM_SEL_TYPE_CLIPBOARD,
-   ELM_SEL_TYPE_XDND,
-
-   ELM_SEL_TYPE_MAX,
-} Elm_Sel_Type;
-
-typedef enum
-{
-   /** Targets: for matching every atom requesting */
-   ELM_SEL_FORMAT_TARGETS = -1,
-   /** they come from outside of elm */
-   ELM_SEL_FORMAT_NONE = 0x0,
-   /** Plain unformated text: Used for things that don't want rich markup */
-   ELM_SEL_FORMAT_TEXT = 0x01,
-   /** Edje textblock markup, including inline images */
-   ELM_SEL_FORMAT_MARKUP = 0x02,
-   /** Images */
-   ELM_SEL_FORMAT_IMAGE = 0x04,
-   /** Vcards */
-   ELM_SEL_FORMAT_VCARD = 0x08,
-   /** Raw HTMLish things for widgets that want that stuff (hello webkit!) */
-   ELM_SEL_FORMAT_HTML = 0x10,
-
-   ELM_SEL_FORMAT_MAX
-} Elm_Sel_Format;
-
-struct _Elm_Selection_Data
-{
-   int            x, y;
-=======
  * @defgroup CopyPaste CopyPaste
  *
  * Implements the following functionality
@@ -122,25 +80,10 @@ typedef enum
 struct _Elm_Selection_Data
 {
    Evas_Coord     x, y;
->>>>>>> remotes/origin/upstream
    Elm_Sel_Format format;
    void          *data;
    size_t         len;
 };
-<<<<<<< HEAD
-
-/**
- * @brief Set a data of a widget to copy and paste.
- *
- * Append the given callback to the list. This functions will be called
- * called.
- *
- * @param selection selection type for copying and pasting
- * @param widget The source widget pointer
- * @param format Type of selection format
- * @param buf The pointer of data source
- * @return If EINA_TRUE, setting data is success.
-=======
 typedef struct _Elm_Selection_Data Elm_Selection_Data;
 
 /**
@@ -166,47 +109,10 @@ typedef Eina_Bool (*Elm_Drop_Cb)(void *data, Evas_Object *obj, Elm_Selection_Dat
  * @param buf The data selected
  * @param buflen The size of @p buf
  * @return If EINA_TRUE, setting data was successful.
->>>>>>> remotes/origin/upstream
- *
- * @ingroup CopyPaste
- *
- */
-<<<<<<< HEAD
-
-EAPI Eina_Bool elm_cnp_selection_set(Elm_Sel_Type selection, Evas_Object *widget, Elm_Sel_Format format, const void *buf, size_t buflen);
-
-/**
- * @brief Retrive the data from the widget which is set for copying and pasting.
- *
- * Getting the data from the widget which is set for copying and pasting.
- * Mainly the widget is elm_entry. If then @p datacb and @p udata are
- * can be NULL. If not, @p datacb and @p udata are used for retriving data.
- *
- * @see also elm_cnp_selection_set()
- *
- * @param selection selection type for copying and pasting
- * @param widget The source widget pointer
- * @param datacb The user data callback if the target widget isn't elm_entry
- * @param udata The user data pointer for @p datacb
- * @return If EINA_TRUE, getting data is success.
  *
  * @ingroup CopyPaste
  *
  */
-
-EAPI Eina_Bool elm_cnp_selection_get(Elm_Sel_Type selection, Elm_Sel_Format format, Evas_Object *widget, Elm_Drop_Cb datacb, void *udata);
-
-/**
- * @brief Clear the data in the widget which is set for copying and pasting.
- *
- * Clear the data in the widget. Normally this function isn't need to call.
- *
- * @see also elm_cnp_selection_set()
- *
- * @param selection selection type for copying and pasting
- * @param widget The source widget pointer
- * @return If EINA_TRUE, clearing data is success.
-=======
 EAPI Eina_Bool elm_cnp_selection_set(Evas_Object *obj, Elm_Sel_Type selection,
                                      Elm_Sel_Format format,
                                      const void *buf, size_t buflen);
@@ -244,18 +150,12 @@ EAPI Eina_Bool elm_cnp_selection_get(Evas_Object *obj, Elm_Sel_Type selection,
  * @param obj The source widget
  * @param selection Selection type for copying and pasting
  * @return If EINA_TRUE, clearing data was successful.
->>>>>>> remotes/origin/upstream
  *
  * @ingroup CopyPaste
  *
  */
-<<<<<<< HEAD
-
-EAPI Eina_Bool elm_cnp_selection_clear(Elm_Sel_Type selection, Evas_Object *widget);
-=======
 EAPI Eina_Bool elm_object_cnp_selection_clear(Evas_Object *obj,
                                               Elm_Sel_Type selection);
->>>>>>> remotes/origin/upstream
 
 /**
  * @}