cnp: support multiple mime types 70/84070/3
authorMinchul Lee <slotus.lee@samsung.com>
Tue, 16 Aug 2016 11:11:09 +0000 (20:11 +0900)
committerMinchul Lee <slotus.lee@samsung.com>
Wed, 17 Aug 2016 06:18:49 +0000 (23:18 -0700)
Change-Id: I7c9c5e519f1e1e3714fb62a5eae9c7549aff71fe
Signed-off-by: Minchul Lee <slotus.lee@samsung.com>
src/lib/elm_cnp.c

index def5608..24373af 100644 (file)
@@ -2947,9 +2947,10 @@ _wl_elm_cnp_selection_set(Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Form
         if (!types) return EINA_FALSE;
 
 // TIZEN_ONLY(20160811): To distinguish clipboard selection in cbhm
+        count++;
         if (selection == ELM_SEL_TYPE_CLIPBOARD)
           {
-             types[count] = "CLIPBOARD_BEGIN";
+             types[count - 1] = "CLIPBOARD_BEGIN";
              count++;
              t = realloc(types, sizeof(char *) * count);
              if (!t)
@@ -3006,7 +3007,7 @@ _wl_elm_cnp_selection_set(Evas_Object *obj, Elm_Sel_Type selection, Elm_Sel_Form
 */
         if (selection == ELM_SEL_TYPE_CLIPBOARD)
           {
-             types[count] = "CLIPBOARD_END";
+             types[count - 1] = "CLIPBOARD_END";
              count++;
              t = realloc(types, sizeof(char *) * count);
              if (!t)
@@ -3200,6 +3201,140 @@ _wl_selection_send(void *udata, int type EINA_UNUSED, void *event)
    return ECORE_CALLBACK_PASS_ON;
 }
 
+// TIZEN ONLY(20160730): support multiple mime types
+static Eina_Bool
+_wl_selection_receive(void *udata, int type EINA_UNUSED, void *event)
+{
+   char *mime_type;
+   Wl_Cnp_Selection *sel = udata;
+   Ecore_Wl_Event_Selection_Data_Ready *ev = event;
+
+   // TIZEN ONLY(20160627): support multiple selection types' buffer
+   sel = NULL;
+   Wl_Cnp_Selection *sels = udata;
+   int i = 0;
+   for (i = 0; i < ELM_SEL_TYPE_CLIPBOARD + 1; i++)
+     {
+        if (sels[i].requestwidget && (i != ELM_SEL_TYPE_XDND))
+          {
+             sel = sels + i;
+             cnp_debug("requested type: %s\n", sel->debug);
+             break;
+          }
+     }
+   if (!sel) return ECORE_CALLBACK_PASS_ON;
+   //
+
+   _wl_elm_cnp_init();
+
+   if ((!ev->num_types) || (!ev->types)) return ECORE_CALLBACK_PASS_ON;
+
+   for (i = 0; i < ev->num_types; i++)
+     DBG("mime type(%s)", ev->types[i]);
+
+   mime_type = ev->types[0];
+   if (!mime_type)
+     {
+        ERR("mime type NOT exist");
+        return ECORE_CALLBACK_PASS_ON;
+     }
+
+   if (!sel->requestwidget)
+     {
+        ERR("requested widget NOT exist");
+        return ECORE_CALLBACK_PASS_ON;
+     }
+
+   if (!ev->done)
+     {
+        for (i = 0; i < CNP_N_ATOMS; ++i)
+          {
+             if (!strcmp(mime_type, _atoms[i].name))
+               {
+                  if (_atoms[i].wl_data_preparer)
+                    {
+                       Eina_Bool success;
+                       Elm_Selection_Data sdata;
+                       Tmp_Info *tmp_info = NULL;
+                       sdata.data = NULL;
+                       cnp_debug("Found something: %s(%d), data(%s)\n", _atoms[i].name, i, ev->data);
+                       success = _atoms[i].wl_data_preparer(wl_cnp_selections, &sdata, ev, &tmp_info);
+                       if (_atoms[i].formats == ELM_SEL_FORMAT_IMAGE && savedtypes.imgfile)
+                         {
+                            cnp_debug("imgfile of savedtypes exist");
+                            break;
+                         }
+
+                       if (sel->seltype == ELM_SEL_TYPE_XDND)
+                         {
+                            Eina_List *l;
+                            Dropable *dropable;
+
+                            EINA_LIST_FOREACH(drops, l, dropable)
+                              {
+                                 if (dropable->obj == sel->requestwidget) break;
+                                 dropable = NULL;
+                              }
+
+                            if (dropable)
+                              {
+                                 Dropable_Cbs *cbs;
+
+                                 sdata.x = savedtypes.x;
+                                 sdata.y = savedtypes.y;
+                                 sdata.format = ELM_SEL_FORMAT_TEXT;
+                                 sdata.data = ev->data;
+                                 sdata.len = ev->len;
+                                 sdata.action = sel->action;
+
+                                 EINA_INLIST_FOREACH(dropable->cbs_list, cbs)
+                                    if (cbs->dropcb)
+                                      cbs->dropcb(cbs->dropdata, dropable->obj, &sdata);
+
+                                 goto end;
+                              }
+                         }
+
+                       if (sel->datacb && success)
+                         {
+                            sdata.x = sdata.y = 0;
+                            sdata.len = ev->len;
+                            sdata.data = strndup(ev->data, ev->len);
+                            cnp_debug("selected format(%d), data(%s)", sdata.format, sdata.data);
+                            sdata.action = sel->action;
+                            sel->datacb(sel->udata,
+                                        sel->requestwidget,
+                                        &sdata);
+                         }
+
+                       if (sdata.data) free(sdata.data);
+                       if (tmp_info) _tmpinfo_free(tmp_info);
+                       goto end;
+                    }
+                  else cnp_debug("Ignored: No handler!\n");
+                  break;
+               }
+          }
+     }
+   else
+     {
+        evas_object_event_callback_del_full(sel->requestwidget,
+                                            EVAS_CALLBACK_DEL,
+                                            _wl_sel_obj_del2, sel);
+        sel->requestwidget = NULL;
+     }
+
+end:
+   if (sel->seltype == ELM_SEL_TYPE_XDND)
+     {
+        /* FIXME: Send Finished ?? */
+     }
+
+   return ECORE_CALLBACK_PASS_ON;
+}
+//
+
+/*
 static Eina_Bool
 _wl_selection_receive(void *udata, int type EINA_UNUSED, void *event)
 {
@@ -3281,7 +3416,7 @@ _wl_selection_receive(void *udata, int type EINA_UNUSED, void *event)
                   strncpy(stripstr, (char *)ev->data, ev->len);
                   stripstr[ev->len] = '\0';
                   mkupstr = _elm_util_text_to_mkup((const char *)stripstr);
-                  /* TODO BUG: should never NEVER assume it's an elm_entry! */
+                  // TODO BUG: should never NEVER assume it's an elm_entry!
                   _elm_entry_entry_paste(sel->requestwidget, mkupstr);
                   free(stripstr);
                   free(mkupstr);
@@ -3299,11 +3434,12 @@ _wl_selection_receive(void *udata, int type EINA_UNUSED, void *event)
 end:
    if (sel->seltype == ELM_SEL_TYPE_XDND)
      {
-        /* FIXME: Send Finished ?? */
+        // FIXME: Send Finished ??
      }
 
    return ECORE_CALLBACK_PASS_ON;
 }
+*/
 
 static Eina_Bool
 _wl_elm_cnp_init(void)