summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@samsung.com>2015-06-18 10:15:58 +0300
committerDaniel Zaoui <daniel.zaoui@yahoo.com>2015-06-20 22:23:06 +0300
commit5a5785d26c7626bdd9175bd1b6196683697c0ede (patch)
tree29bfe20c6f3608821ce7faa86a2469162f5fe0cc
parent475bc14beddf4229b030acf0ae127e436ef63d2b (diff)
-rw-r--r--src/lib/elm_cnp.c299
1 files changed, 188 insertions, 111 deletions
diff --git a/src/lib/elm_cnp.c b/src/lib/elm_cnp.c
index 0aceecd70..b5e8b7e83 100644
--- a/src/lib/elm_cnp.c
+++ b/src/lib/elm_cnp.c
@@ -66,10 +66,8 @@ struct _Tmp_Info
66struct _Saved_Type 66struct _Saved_Type
67{ 67{
68 const char **types; 68 const char **types;
69 char *imgfile;
70 int ntypes; 69 int ntypes;
71 int x, y; 70 int x, y;
72 Eina_Bool textreq: 1;
73}; 71};
74 72
75struct _Cnp_Escape 73struct _Cnp_Escape
@@ -157,7 +155,20 @@ static const char *text_uri;
157static Eina_Hash *_types_hash = NULL; 155static Eina_Hash *_types_hash = NULL;
158 156
159/* Data for DND in progress */ 157/* Data for DND in progress */
160static Saved_Type savedtypes = { NULL, NULL, 0, 0, 0, EINA_FALSE }; 158static Saved_Type savedtypes = { NULL, 0, 0, 0 };
159
160/* Stores the data that has been requested before drop.
161 * It could be useful to preview images/data during DnD.
162 */
163typedef struct
164{
165 Elm_Selection_Data ddata;
166 Tmp_Info *tmp_info;
167 Eina_Bool requested:1;
168} Request_Data;
169static Request_Data **_requested_data = NULL;
170
171static Eina_Bool _drop_request = EINA_FALSE;
161 172
162/* Drag & Drop functions */ 173/* Drag & Drop functions */
163/* FIXME: Way too many globals */ 174/* FIXME: Way too many globals */
@@ -431,6 +442,19 @@ _all_drop_targets_cbs_del(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Obje
431 } 442 }
432} 443}
433 444
445static void
446_request_data_all_free(void)
447{
448 int i;
449 /* Free previous requested data */
450 for (i = 0; i < CNP_N_ATOMS; i++)
451 {
452 ELM_SAFE_FREE(_requested_data[i]->ddata.data, free);
453 ELM_SAFE_FREE(_requested_data[i]->tmp_info, _tmpinfo_free);
454 memset(_requested_data[i], 0, sizeof(Request_Data));
455 }
456}
457
434static Cnp_Atom _atoms[CNP_N_ATOMS] = { 458static Cnp_Atom _atoms[CNP_N_ATOMS] = {
435 ARRAYINIT(CNP_ATOM_TARGETS) { 459 ARRAYINIT(CNP_ATOM_TARGETS) {
436 .name = "TARGETS", 460 .name = "TARGETS",
@@ -617,6 +641,14 @@ static Cnp_Atom _atoms[CNP_N_ATOMS] = {
617 }, 641 },
618}; 642};
619 643
644static int
645_get_atom_id_by_mime_type(const char *type)
646{
647 Cnp_Atom *atom = eina_hash_find(_types_hash, type);
648 if (atom) return atom - _atoms;
649 else return -1;
650}
651
620// x11 specific stuff 652// x11 specific stuff
621//////////////////////////////////////////////////////////////////////////// 653////////////////////////////////////////////////////////////////////////////
622#ifdef HAVE_ELEMENTARY_X 654#ifdef HAVE_ELEMENTARY_X
@@ -732,7 +764,7 @@ _x11_selection_notify(void *udata EINA_UNUSED, int type EINA_UNUSED, void *event
732{ 764{
733 Ecore_X_Event_Selection_Notify *ev = event; 765 Ecore_X_Event_Selection_Notify *ev = event;
734 X11_Cnp_Selection *sel; 766 X11_Cnp_Selection *sel;
735 int i; 767 int atom_idx;
736 768
737 cnp_debug("selection notify callback: %d\n",ev->selection); 769 cnp_debug("selection notify callback: %d\n",ev->selection);
738 switch (ev->selection) 770 switch (ev->selection)
@@ -760,57 +792,63 @@ _x11_selection_notify(void *udata EINA_UNUSED, int type EINA_UNUSED, void *event
760 _x11_notify_handler_targets(sel, ev); 792 _x11_notify_handler_targets(sel, ev);
761 return ECORE_CALLBACK_PASS_ON; 793 return ECORE_CALLBACK_PASS_ON;
762 } 794 }
763 for (i = 0; i < CNP_N_ATOMS; i++) 795 atom_idx = _get_atom_id_by_mime_type(ev->target);
796 if (_atoms[atom_idx].x_data_preparer)
764 { 797 {
765 if (!strcmp(ev->target, _atoms[i].name)) 798 Elm_Selection_Data *ddata = &_requested_data[atom_idx]->ddata;
799 Eina_Bool success;
800 cnp_debug("Found something: %s\n", _atoms[atom_idx].name);
801 ELM_SAFE_FREE(_requested_data[atom_idx]->ddata.data, free);
802 ELM_SAFE_FREE(_requested_data[atom_idx]->tmp_info, _tmpinfo_free);
803 success = _atoms[atom_idx].x_data_preparer(ev, ddata, &(_requested_data[atom_idx]->tmp_info));
804 if (ev->selection == ECORE_X_SELECTION_XDND)
766 { 805 {
767 if (_atoms[i].x_data_preparer) 806 if (success)
768 { 807 {
769 Elm_Selection_Data ddata; 808 if (_drop_request)
770 Tmp_Info *tmp_info = NULL;
771 Eina_Bool success;
772 ddata.data = NULL;
773 cnp_debug("Found something: %s\n", _atoms[i].name);
774 success = _atoms[i].x_data_preparer(ev, &ddata, &tmp_info);
775 if (_atoms[i].formats == ELM_SEL_FORMAT_IMAGE && savedtypes.imgfile) break;
776 if (ev->selection == ECORE_X_SELECTION_XDND)
777 { 809 {
778 if (success) 810 Dropable *dropable;
811 Eina_List *l;
812 cnp_debug("drag & drop\n");
813 EINA_LIST_FOREACH(drops, l, dropable)
779 { 814 {
780 Dropable *dropable; 815 if (dropable->obj == sel->requestwidget) break;
781 Eina_List *l; 816 dropable = NULL;
782 cnp_debug("drag & drop\n"); 817 }
783 EINA_LIST_FOREACH(drops, l, dropable) 818 if (dropable)
784 { 819 {
785 if (dropable->obj == sel->requestwidget) break; 820 Dropable_Cbs *cbs;
786 dropable = NULL; 821 Eina_Inlist *itr;
787 } 822 ddata->x = savedtypes.x;
788 if (dropable) 823 ddata->y = savedtypes.y;
789 { 824 EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
790 Dropable_Cbs *cbs; 825 if ((cbs->types & dropable->last.format) && cbs->dropcb)
791 Eina_Inlist *itr; 826 cbs->dropcb(cbs->dropdata, dropable->obj, ddata);
792 ddata.x = savedtypes.x;
793 ddata.y = savedtypes.y;
794 EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
795 if ((cbs->types & dropable->last.format) && cbs->dropcb)
796 cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
797 }
798 } 827 }
799 /* We have to finish DnD, no matter what */ 828 _drop_request = EINA_FALSE;
800 ecore_x_dnd_send_finished(); 829 _request_data_all_free();
801 } 830 }
802 else if (sel->datacb && success) 831 else
803 { 832 {
804 ddata.x = ddata.y = 0; 833 cnp_debug("Caching data\n");
805 sel->datacb(sel->udata, sel->requestwidget, &ddata); 834 _requested_data[atom_idx]->requested = EINA_FALSE;
835 /* DnD is not finished yet. The data has just been requested during DnD and needs to be cached.
836 * The process will be finished on drop.
837 */
838 return ECORE_CALLBACK_PASS_ON;
806 } 839 }
807 free(ddata.data);
808 if (tmp_info) _tmpinfo_free(tmp_info);
809 } 840 }
810 else cnp_debug("Ignored: No handler!\n"); 841 /* We have to finish DnD, no matter what */
811 break; 842 ecore_x_dnd_send_finished();
843 }
844 else if (sel->datacb && success)
845 {
846 ddata->x = ddata->y = 0;
847 sel->datacb(sel->udata, sel->requestwidget, ddata);
848 _request_data_all_free();
812 } 849 }
813 } 850 }
851 else cnp_debug("Ignored: No handler!\n");
814 return ECORE_CALLBACK_PASS_ON; 852 return ECORE_CALLBACK_PASS_ON;
815} 853}
816 854
@@ -1052,19 +1090,9 @@ _x11_data_preparer_uri(Ecore_X_Event_Selection_Notify *notify,
1052 cnp_debug("Couldn't find a file\n"); 1090 cnp_debug("Couldn't find a file\n");
1053 return EINA_FALSE; 1091 return EINA_FALSE;
1054 } 1092 }
1055 free(savedtypes.imgfile); 1093 ddata->format = ELM_SEL_FORMAT_IMAGE;
1056 if (savedtypes.textreq) 1094 ddata->data = stripstr;
1057 { 1095 ddata->len = strlen(stripstr);
1058 savedtypes.textreq = 0;
1059 savedtypes.imgfile = stripstr;
1060 }
1061 else
1062 {
1063 ddata->format = ELM_SEL_FORMAT_IMAGE;
1064 ddata->data = stripstr;
1065 ddata->len = strlen(stripstr);
1066 savedtypes.imgfile = NULL;
1067 }
1068 return EINA_TRUE; 1096 return EINA_TRUE;
1069} 1097}
1070 1098
@@ -1256,17 +1284,11 @@ _x11_evas_get_from_xwin(Ecore_X_Window win)
1256static Eina_Bool 1284static Eina_Bool
1257_x11_dnd_enter(void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev) 1285_x11_dnd_enter(void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev)
1258{ 1286{
1259 Ecore_X_Event_Xdnd_Enter *enter = ev;
1260 int i; 1287 int i;
1261 Dropable *dropable; 1288 Ecore_X_Event_Xdnd_Enter *enter = ev;
1262 1289
1263 if (!enter) return EINA_TRUE; 1290 if (!enter) return EINA_TRUE;
1264 dropable = _x11_dropable_find(enter->win); 1291
1265 if (dropable)
1266 {
1267 cnp_debug("Enter %x\n", enter->win);
1268 }
1269 /* Skip it */
1270 cnp_debug("enter types=%p (%d)\n", enter->types, enter->num_types); 1292 cnp_debug("enter types=%p (%d)\n", enter->types, enter->num_types);
1271 if ((!enter->num_types) || (!enter->types)) return EINA_TRUE; 1293 if ((!enter->num_types) || (!enter->types)) return EINA_TRUE;
1272 1294
@@ -1276,6 +1298,9 @@ _x11_dnd_enter(void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev)
1276 savedtypes.types = malloc(sizeof(char *) * enter->num_types); 1298 savedtypes.types = malloc(sizeof(char *) * enter->num_types);
1277 if (!savedtypes.types) return EINA_FALSE; 1299 if (!savedtypes.types) return EINA_FALSE;
1278 1300
1301 _request_data_all_free();
1302 _x11_selections[ELM_SEL_TYPE_XDND].xwin = enter->win;
1303
1279 for (i = 0; i < enter->num_types; i++) 1304 for (i = 0; i < enter->num_types; i++)
1280 { 1305 {
1281 savedtypes.types[i] = eina_stringshare_add(enter->types[i]); 1306 savedtypes.types[i] = eina_stringshare_add(enter->types[i]);
@@ -1284,9 +1309,9 @@ _x11_dnd_enter(void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev)
1284 if (savedtypes.types[i] == text_uri) 1309 if (savedtypes.types[i] == text_uri)
1285 { 1310 {
1286 /* Request it, so we know what it is */ 1311 /* Request it, so we know what it is */
1287 cnp_debug("Sending uri request\n"); 1312 cnp_debug("Sending text/uri-list request\n");
1288 savedtypes.textreq = 1; 1313 _requested_data[CNP_ATOM_text_urilist]->requested = EINA_TRUE;
1289 ELM_SAFE_FREE(savedtypes.imgfile, free); 1314 ELM_SAFE_FREE(_requested_data[CNP_ATOM_text_urilist]->ddata.data, free);
1290 ecore_x_selection_xdnd_request(enter->win, text_uri); 1315 ecore_x_selection_xdnd_request(enter->win, text_uri);
1291 } 1316 }
1292 } 1317 }
@@ -1506,8 +1531,21 @@ _x11_dnd_position(void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev)
1506 ecore_x_dnd_send_status(EINA_TRUE, EINA_FALSE, rect, pos->action); 1531 ecore_x_dnd_send_status(EINA_TRUE, EINA_FALSE, rect, pos->action);
1507 cnp_debug("dnd position %i %i %p\n", x - ox, y - oy, dropable); 1532 cnp_debug("dnd position %i %i %p\n", x - ox, y - oy, dropable);
1508 _x11_dnd_dropable_handle(dropable, x - ox, y - oy, act); 1533 _x11_dnd_dropable_handle(dropable, x - ox, y - oy, act);
1509 // CCCCCCC: call dnd exit on last obj if obj != last 1534 // FIXME check if the object needs the request before the drop
1510 // CCCCCCC: call drop position on obj 1535 /* Request data before drop */
1536 {
1537 Cnp_Atom *atom = eina_hash_find(_types_hash, dropable->last.type);
1538 int atom_idx = (atom - _atoms);
1539 if (!_requested_data[atom_idx]->requested && !_requested_data[atom_idx]->ddata.data)
1540 {
1541 ecore_x_selection_xdnd_request(pos->win, dropable->last.type);
1542 _requested_data[atom_idx]->requested = EINA_TRUE;
1543 }
1544 else
1545 {
1546 // FIXME invoke the target cbs with the cached data
1547 }
1548 }
1511 } 1549 }
1512 else 1550 else
1513 { 1551 {
@@ -1515,7 +1553,6 @@ _x11_dnd_position(void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev)
1515 ecore_x_dnd_send_status(EINA_FALSE, EINA_FALSE, rect, pos->action); 1553 ecore_x_dnd_send_status(EINA_FALSE, EINA_FALSE, rect, pos->action);
1516 cnp_debug("dnd position (%d, %d) not in obj\n", x, y); 1554 cnp_debug("dnd position (%d, %d) not in obj\n", x, y);
1517 _x11_dnd_dropable_handle(NULL, 0, 0, act); 1555 _x11_dnd_dropable_handle(NULL, 0, 0, act);
1518 // CCCCCCC: call dnd exit on last obj
1519 } 1556 }
1520 eina_list_free(dropable_list); 1557 eina_list_free(dropable_list);
1521 } 1558 }
@@ -1536,28 +1573,34 @@ _x11_dnd_position(void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev)
1536static Eina_Bool 1573static Eina_Bool
1537_x11_dnd_leave(void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev) 1574_x11_dnd_leave(void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev)
1538{ 1575{
1576 Ecore_X_Event_Xdnd_Leave *leave = (Ecore_X_Event_Xdnd_Leave *)ev;
1539#ifdef DEBUGON 1577#ifdef DEBUGON
1540 cnp_debug("Leave %x\n", ((Ecore_X_Event_Xdnd_Leave *)ev)->win); 1578 cnp_debug("Leave %x\n", leave->win);
1541#else 1579#else
1542 (void)ev; 1580 (void)ev;
1543#endif 1581#endif
1544 _x11_dnd_dropable_handle(NULL, 0, 0, ELM_XDND_ACTION_UNKNOWN); 1582 _x11_dnd_dropable_handle(NULL, 0, 0, ELM_XDND_ACTION_UNKNOWN);
1583
1584 /* If the current xwin is different, we don't free the temp data.
1585 * It could happen if enter event into another xwin occurs before leave event of the first window */
1586 if (leave->win == _x11_selections[ELM_SEL_TYPE_XDND].xwin) _request_data_all_free();
1587
1545 // CCCCCCC: call dnd exit on last obj if there was one 1588 // CCCCCCC: call dnd exit on last obj if there was one
1546 // leave->win leave->source 1589 // leave->win leave->source
1547 return EINA_TRUE; 1590 return EINA_TRUE;
1548} 1591}
1549 1592
1550static Eina_Bool 1593static Eina_Bool
1551_x11_dnd_drop(void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev) 1594_x11_dnd_drop(void *_data EINA_UNUSED, int etype EINA_UNUSED, void *ev)
1552{ 1595{
1553 Ecore_X_Event_Xdnd_Drop *drop; 1596 Ecore_X_Event_Xdnd_Drop *drop;
1554 Dropable *dropable = NULL; 1597 Dropable *dropable = NULL;
1555 Elm_Selection_Data ddata;
1556 Evas_Coord x = 0, y = 0; 1598 Evas_Coord x = 0, y = 0;
1557 Elm_Xdnd_Action act = ELM_XDND_ACTION_UNKNOWN; 1599 Elm_Xdnd_Action act = ELM_XDND_ACTION_UNKNOWN;
1558 Eina_List *l; 1600 Eina_List *l;
1559 Dropable_Cbs *cbs; 1601 Dropable_Cbs *cbs;
1560 Eina_Inlist *itr; 1602 Eina_Inlist *itr;
1603 int atom_idx;
1561 1604
1562 drop = ev; 1605 drop = ev;
1563 1606
@@ -1588,25 +1631,29 @@ _x11_dnd_drop(void *data EINA_UNUSED, int etype EINA_UNUSED, void *ev)
1588 return EINA_TRUE; 1631 return EINA_TRUE;
1589 1632
1590found: 1633found:
1634 atom_idx = _get_atom_id_by_mime_type(dropable->last.type);
1591 cnp_debug("0x%x\n", drop->win); 1635 cnp_debug("0x%x\n", drop->win);
1592 1636
1593 act = _x11_dnd_action_map(drop->action); 1637 act = _x11_dnd_action_map(drop->action);
1594 1638
1595 dropable->last.in = EINA_FALSE; 1639 dropable->last.in = EINA_FALSE;
1596 cnp_debug("Last type: %s - Last format: %X\n", dropable->last.type, dropable->last.format); 1640 cnp_debug("Last type: %s - Last format: %X\n", dropable->last.type, dropable->last.format);
1597 if ((!strcmp(dropable->last.type, text_uri))) 1641 /* Check if the data has already been cached. */
1642 if (_requested_data[atom_idx]->ddata.data)
1598 { 1643 {
1599 cnp_debug("We found a URI... (%scached) %s\n", 1644 /* We just need to call drop callbacks as we already have the data */
1600 savedtypes.imgfile ? "" : "not ", 1645 Elm_Selection_Data *ddata = &_requested_data[atom_idx]->ddata;
1601 savedtypes.imgfile); 1646 cnp_debug("We found a cached data (%s)\n", dropable->last.type);
1602 if (savedtypes.imgfile) 1647 ddata->x = savedtypes.x;
1648 ddata->y = savedtypes.y;
1649 ddata->action = act;
1650 /* FIXME Special case that needs to be removed */
1651 if ((!strcmp(dropable->last.type, text_uri)))
1603 { 1652 {
1653 char *data = ddata->data;
1604 char *entrytag; 1654 char *entrytag;
1605 static const char *tagstring = 1655 static const char *tagstring =
1606 "<item absize=240x180 href=file://%s></item>"; 1656 "<item absize=240x180 href=file://%s></item>";
1607 ddata.x = savedtypes.x;
1608 ddata.y = savedtypes.y;
1609 ddata.action = act;
1610 1657
1611 EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs) 1658 EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
1612 { 1659 {
@@ -1615,50 +1662,67 @@ found:
1615 (cbs->types & ELM_SEL_FORMAT_IMAGE)) 1662 (cbs->types & ELM_SEL_FORMAT_IMAGE))
1616 { 1663 {
1617 int len; 1664 int len;
1618 ddata.format = ELM_SEL_FORMAT_MARKUP; 1665 ddata->format = ELM_SEL_FORMAT_MARKUP;
1619 1666
1620 len = strlen(tagstring) + strlen(savedtypes.imgfile); 1667 len = strlen(tagstring) + strlen(data);
1621 entrytag = alloca(len + 1); 1668 entrytag = alloca(len + 1);
1622 snprintf(entrytag, len + 1, tagstring, savedtypes.imgfile); 1669 snprintf(entrytag, len + 1, tagstring, data);
1623 ddata.data = entrytag; 1670 ddata->data = entrytag;
1624 cnp_debug("Insert %s\n", (char *)ddata.data); 1671 cnp_debug("Insert %s\n", data);
1625 if ((cbs->types & dropable->last.format) && cbs->dropcb) 1672 if ((cbs->types & dropable->last.format) && cbs->dropcb)
1626 cbs->dropcb(cbs->dropdata, dropable->obj, &ddata); 1673 cbs->dropcb(cbs->dropdata, dropable->obj, ddata);
1674 free(ddata->data);
1627 } 1675 }
1628 else if (cbs->types & ELM_SEL_FORMAT_IMAGE) 1676 else if (cbs->types & ELM_SEL_FORMAT_IMAGE)
1629 { 1677 {
1630 cnp_debug("Doing image insert (%s)\n", savedtypes.imgfile); 1678 cnp_debug("Doing image insert (%s)\n", data);
1631 ddata.format = ELM_SEL_FORMAT_IMAGE; 1679 ddata->format = ELM_SEL_FORMAT_IMAGE;
1632 ddata.data = (char *)savedtypes.imgfile; 1680 ddata->data = data;
1633 if ((cbs->types & dropable->last.format) && cbs->dropcb) 1681 if ((cbs->types & dropable->last.format) && cbs->dropcb)
1634 cbs->dropcb(cbs->dropdata, dropable->obj, &ddata); 1682 cbs->dropcb(cbs->dropdata, dropable->obj, ddata);
1635 } 1683 }
1636 else 1684 else
1637 { 1685 {
1638 cnp_debug("Item doesn't support images... passing\n"); 1686 cnp_debug("Item doesn't support images... passing\n");
1639 } 1687 }
1688 ddata->data = NULL;
1640 } 1689 }
1641 ecore_x_dnd_send_finished(); 1690 ddata->data = data;
1642 ELM_SAFE_FREE(savedtypes.imgfile, free);
1643 return EINA_TRUE;
1644 } 1691 }
1645 else if (savedtypes.textreq) 1692 else
1646 { 1693 {
1647 /* Already asked: Pretend we asked now, and paste immediately when 1694 EINA_INLIST_FOREACH_SAFE(dropable->cbs_list, itr, cbs)
1648 * it comes in */ 1695 if ((cbs->types & dropable->last.format) && cbs->dropcb)
1649 savedtypes.textreq = 0; 1696 cbs->dropcb(cbs->dropdata, dropable->obj, ddata);
1650 ecore_x_dnd_send_finished();
1651 return EINA_TRUE;
1652 } 1697 }
1698 _request_data_all_free();
1699 ecore_x_dnd_send_finished();
1700 }
1701 else if (_requested_data[atom_idx]->requested)
1702 {
1703 cnp_debug("Data already requested for %s\n", dropable->last.type);
1704 /* The data has been requested but has not been received yet.
1705 * Drop callbacks will be invoked when the data arrives
1706 * (selection notify event).
1707 * DnD finish will be done there.
1708 */
1709 _drop_request = EINA_TRUE;
1710 }
1711 else
1712 {
1713 /* We need to request the data. Drop callbacks will be invoked
1714 * when the data arrives (selection notify event).
1715 * DnD finish will be done there.
1716 */
1717 cnp_debug("doing a request then: %s\n", dropable->last.type);
1718 _x11_selections[ELM_SEL_TYPE_XDND].xwin = drop->win;
1719 _x11_selections[ELM_SEL_TYPE_XDND].requestwidget = dropable->obj;
1720 _x11_selections[ELM_SEL_TYPE_XDND].requestformat = dropable->last.format;
1721 _x11_selections[ELM_SEL_TYPE_XDND].active = EINA_TRUE;
1722 _x11_selections[ELM_SEL_TYPE_XDND].action = act;
1723 _drop_request = EINA_TRUE;
1724 ecore_x_selection_xdnd_request(drop->win, dropable->last.type);
1653 } 1725 }
1654
1655 cnp_debug("doing a request then: %s\n", dropable->last.type);
1656 _x11_selections[ELM_SEL_TYPE_XDND].xwin = drop->win;
1657 _x11_selections[ELM_SEL_TYPE_XDND].requestwidget = dropable->obj;
1658 _x11_selections[ELM_SEL_TYPE_XDND].requestformat = dropable->last.format;
1659 _x11_selections[ELM_SEL_TYPE_XDND].active = EINA_TRUE;
1660 _x11_selections[ELM_SEL_TYPE_XDND].action = act;
1661 ecore_x_selection_xdnd_request(drop->win, dropable->last.type);
1662 return EINA_TRUE; 1726 return EINA_TRUE;
1663} 1727}
1664 1728
@@ -2091,8 +2155,6 @@ _x11_elm_drop_target_del(Evas_Object *obj, Elm_Sel_Format format,
2091 ELM_SAFE_FREE(handler_leave, ecore_event_handler_del); 2155 ELM_SAFE_FREE(handler_leave, ecore_event_handler_del);
2092 } 2156 }
2093 2157
2094 ELM_SAFE_FREE(savedtypes.imgfile, free);
2095
2096 return EINA_TRUE; 2158 return EINA_TRUE;
2097} 2159}
2098 2160
@@ -2955,6 +3017,7 @@ _wl_dnd_enter(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
2955 savedtypes.types = malloc(sizeof(char *) * ev->num_types); 3017 savedtypes.types = malloc(sizeof(char *) * ev->num_types);
2956 if (!savedtypes.types) return EINA_FALSE; 3018 if (!savedtypes.types) return EINA_FALSE;
2957 3019
3020#if 0
2958 for (i = 0; i < ev->num_types; i++) 3021 for (i = 0; i < ev->num_types; i++)
2959 { 3022 {
2960 savedtypes.types[i] = eina_stringshare_add(ev->types[i]); 3023 savedtypes.types[i] = eina_stringshare_add(ev->types[i]);
@@ -2964,6 +3027,7 @@ _wl_dnd_enter(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
2964 ELM_SAFE_FREE(savedtypes.imgfile, free); 3027 ELM_SAFE_FREE(savedtypes.imgfile, free);
2965 } 3028 }
2966 } 3029 }
3030#endif
2967 3031
2968 doaccept = EINA_FALSE; 3032 doaccept = EINA_FALSE;
2969 for (i = 0; i < ev->num_types; i++) 3033 for (i = 0; i < ev->num_types; i++)
@@ -3233,11 +3297,13 @@ _wl_dropable_data_handle(Wl_Cnp_Selection *sel, char *data)
3233 memcpy(s, data, len); 3297 memcpy(s, data, len);
3234 s[len] = 0; 3298 s[len] = 0;
3235 3299
3300#if 0
3236 if (savedtypes.textreq) 3301 if (savedtypes.textreq)
3237 { 3302 {
3238 savedtypes.textreq = 0; 3303 savedtypes.textreq = 0;
3239 savedtypes.imgfile = s; 3304 savedtypes.imgfile = s;
3240 } 3305 }
3306#endif
3241 3307
3242 sdata.len = len; 3308 sdata.len = len;
3243 sdata.x = savedtypes.x; 3309 sdata.x = savedtypes.x;
@@ -3253,6 +3319,7 @@ _wl_dropable_data_handle(Wl_Cnp_Selection *sel, char *data)
3253 if (cbs->types && drop->last.format) 3319 if (cbs->types && drop->last.format)
3254 { 3320 {
3255 /* If it's markup that also supports images */ 3321 /* If it's markup that also supports images */
3322#if 0
3256 if (cbs->types & (ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE)) 3323 if (cbs->types & (ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE))
3257 { 3324 {
3258 sdata.format = ELM_SEL_FORMAT_MARKUP; 3325 sdata.format = ELM_SEL_FORMAT_MARKUP;
@@ -3264,6 +3331,7 @@ _wl_dropable_data_handle(Wl_Cnp_Selection *sel, char *data)
3264 sdata.data = (char *)savedtypes.imgfile; 3331 sdata.data = (char *)savedtypes.imgfile;
3265 } 3332 }
3266 else 3333 else
3334#endif
3267 { 3335 {
3268 sdata.format = drop->last.format; 3336 sdata.format = drop->last.format;
3269 sdata.data = s; 3337 sdata.data = s;
@@ -3273,7 +3341,6 @@ _wl_dropable_data_handle(Wl_Cnp_Selection *sel, char *data)
3273 } 3341 }
3274 } 3342 }
3275 ecore_wl_dnd_drag_end(ecore_wl_input_get()); 3343 ecore_wl_dnd_drag_end(ecore_wl_input_get());
3276 ELM_SAFE_FREE(savedtypes.imgfile, free);
3277} 3344}
3278 3345
3279static Dropable * 3346static Dropable *
@@ -3631,6 +3698,9 @@ _local_elm_drop_target_del(Evas_Object *obj, Elm_Sel_Format format,
3631 drops = eina_list_remove(drops, dropable); 3698 drops = eina_list_remove(drops, dropable);
3632 eo_do(obj, eo_key_data_del("__elm_dropable")); 3699 eo_do(obj, eo_key_data_del("__elm_dropable"));
3633 free(dropable); 3700 free(dropable);
3701 /* In case temp data remains allocated */
3702// ELM_SAFE_FREE(dropable->requested_data, free);
3703// ELM_SAFE_FREE(dropable->requested_);
3634 dropable = NULL; 3704 dropable = NULL;
3635 evas_object_event_callback_del(obj, EVAS_CALLBACK_DEL, 3705 evas_object_event_callback_del(obj, EVAS_CALLBACK_DEL,
3636 _all_drop_targets_cbs_del); 3706 _all_drop_targets_cbs_del);
@@ -3692,9 +3762,11 @@ _elm_cnp_init(void)
3692 _elm_cnp_init_count++; 3762 _elm_cnp_init_count++;
3693 text_uri = eina_stringshare_add("text/uri-list"); 3763 text_uri = eina_stringshare_add("text/uri-list");
3694 _types_hash = eina_hash_string_small_new(NULL); 3764 _types_hash = eina_hash_string_small_new(NULL);
3765 _requested_data = calloc(CNP_N_ATOMS, sizeof(Request_Data *));
3695 for (i = 0; i < CNP_N_ATOMS; i++) 3766 for (i = 0; i < CNP_N_ATOMS; i++)
3696 { 3767 {
3697 eina_hash_add(_types_hash, _atoms[i].name, &_atoms[i]); 3768 eina_hash_add(_types_hash, _atoms[i].name, &_atoms[i]);
3769 _requested_data[i] = calloc(1, sizeof(Request_Data));
3698 } 3770 }
3699 return EINA_TRUE; 3771 return EINA_TRUE;
3700} 3772}
@@ -3702,12 +3774,17 @@ _elm_cnp_init(void)
3702static Eina_Bool 3774static Eina_Bool
3703_elm_cnp_shutdown(void) 3775_elm_cnp_shutdown(void)
3704{ 3776{
3777 int i;
3705 if (!_elm_cnp_init_count) return EINA_TRUE; 3778 if (!_elm_cnp_init_count) return EINA_TRUE;
3706 if (--_elm_cnp_init_count > 0) return EINA_TRUE; 3779 if (--_elm_cnp_init_count > 0) return EINA_TRUE;
3707 eina_stringshare_del(text_uri); 3780 eina_stringshare_del(text_uri);
3708 text_uri = NULL; 3781 text_uri = NULL;
3709 eina_hash_free(_types_hash); 3782 eina_hash_free(_types_hash);
3710 _types_hash = NULL; 3783 _types_hash = NULL;
3784 _request_data_all_free();
3785 for (i = 0; i < CNP_N_ATOMS; i++) free(_requested_data[i]);
3786 free(_requested_data);
3787 _requested_data = NULL;
3711 return EINA_TRUE; 3788 return EINA_TRUE;
3712} 3789}
3713 3790