summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiep Ha <thiepha@gmail.com>2015-06-09 09:07:05 +0900
committerThiep Ha <thiepha@gmail.com>2015-06-09 09:07:05 +0900
commit55261e144d6815f01175e834effec9a432f0e9cc (patch)
tree49a61e0dbabd9dc20382ea6cc0a3a7566bc7d300
parent6261b683566dd22f323905d019ae8b815cd7d7f8 (diff)
Cnp/X11: move entry-only code in elm_cnp to entry
There is code in elm_cnp.c which is used to paste data to entry widget only. This can cause error if widget is not entry. This patch removes that code in elm_cnp.c and adds datacb to entry to insert content to entry. @fix
-rw-r--r--src/lib/elm_cnp.c40
-rw-r--r--src/lib/elm_entry.c55
2 files changed, 48 insertions, 47 deletions
diff --git a/src/lib/elm_cnp.c b/src/lib/elm_cnp.c
index 7be51dab0..b059e21ab 100644
--- a/src/lib/elm_cnp.c
+++ b/src/lib/elm_cnp.c
@@ -1087,23 +1087,8 @@ _x11_notify_handler_text(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify
1087 ddata.action = sel->action; 1087 ddata.action = sel->action;
1088 sel->datacb(sel->udata, sel->widget, &ddata); 1088 sel->datacb(sel->udata, sel->widget, &ddata);
1089 } 1089 }
1090 else 1090 else cnp_debug("Paste request\n");
1091 {
1092 char *stripstr, *mkupstr;
1093 1091
1094 stripstr = malloc(data->length + 1);
1095 if (!stripstr) goto end;
1096 strncpy(stripstr, (char *)data->data, data->length);
1097 stripstr[data->length] = '\0';
1098 cnp_debug("Notify handler text %d %d %p\n", data->format,
1099 data->length, data->data);
1100 mkupstr = _elm_util_text_to_mkup((const char *)stripstr);
1101 cnp_debug("String is %s (from %s)\n", stripstr, data->data);
1102 /* TODO BUG: should never NEVER assume it's an elm_entry! */
1103 _elm_entry_entry_paste(sel->requestwidget, mkupstr);
1104 free(stripstr);
1105 free(mkupstr);
1106 }
1107end: 1092end:
1108 if (sel == (_x11_selections + ELM_SEL_TYPE_XDND)) 1093 if (sel == (_x11_selections + ELM_SEL_TYPE_XDND))
1109 ecore_x_dnd_send_finished(); 1094 ecore_x_dnd_send_finished();
@@ -1233,8 +1218,18 @@ _x11_notify_handler_uri(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *
1233 } 1218 }
1234 else 1219 else
1235 { 1220 {
1221 if (sel->datacb)
1222 {
1223 Elm_Selection_Data ddata;
1224 ddata.x = ddata.y = 0;
1225 ddata.format = ELM_SEL_FORMAT_IMAGE;
1226 ddata.data = stripstr;
1227 ddata.len = strlen(stripstr);
1228 sel->datacb(sel->udata, sel->requestwidget, &ddata);
1229 }
1230 else cnp_debug("Paste request\n");
1231
1236 savedtypes.imgfile = NULL; 1232 savedtypes.imgfile = NULL;
1237 _pasteimage_append(p, sel->requestwidget);
1238 free(stripstr); 1233 free(stripstr);
1239 } 1234 }
1240 return 0; 1235 return 0;
@@ -1300,7 +1295,6 @@ static int
1300_x11_notify_handler_image(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify) 1295_x11_notify_handler_image(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
1301{ 1296{
1302 Ecore_X_Selection_Data *data; 1297 Ecore_X_Selection_Data *data;
1303 Tmp_Info *tmp;
1304 1298
1305 cnp_debug("got a image file!\n"); 1299 cnp_debug("got a image file!\n");
1306 data = notify->data; 1300 data = notify->data;
@@ -1316,16 +1310,8 @@ _x11_notify_handler_image(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify
1316 ddata.len = data->length; 1310 ddata.len = data->length;
1317 ddata.action = sel->action; 1311 ddata.action = sel->action;
1318 sel->datacb(sel->udata, sel->widget, &ddata); 1312 sel->datacb(sel->udata, sel->widget, &ddata);
1319 return 0;
1320 } 1313 }
1321 /* generate tmp name */ 1314 else cnp_debug("Paste request\n");
1322 tmp = _tempfile_new(data->length);
1323 if (!tmp) return 0;
1324 memcpy(tmp->map, data->data, data->length);
1325 munmap(tmp->map, data->length);
1326 /* FIXME: Add to paste image data to clean up */
1327 _pasteimage_append(tmp->filename, sel->requestwidget);
1328 _tmpinfo_free(tmp);
1329 return 0; 1315 return 0;
1330} 1316}
1331 1317
diff --git a/src/lib/elm_entry.c b/src/lib/elm_entry.c
index e810afd1c..44f430c4d 100644
--- a/src/lib/elm_entry.c
+++ b/src/lib/elm_entry.c
@@ -630,32 +630,26 @@ _elm_entry_theme_group_get(Evas_Object *obj)
630} 630}
631 631
632static Eina_Bool 632static Eina_Bool
633_drag_drop_cb(void *data EINA_UNUSED, 633_selection_data_cb(void *data EINA_UNUSED,
634 Evas_Object *obj, 634 Evas_Object *obj,
635 Elm_Selection_Data *drop) 635 Elm_Selection_Data *sel_data)
636{ 636{
637 Eina_Bool rv;
638 char *buf; 637 char *buf;
639 638
639 if (!sel_data->data) return EINA_FALSE;
640 ELM_ENTRY_DATA_GET(obj, sd); 640 ELM_ENTRY_DATA_GET(obj, sd);
641 641
642 edje_object_part_text_cursor_copy 642 buf = malloc(sel_data->len + 1);
643 (sd->entry_edje, "elm.text", EDJE_CURSOR_MAIN, /*->*/ EDJE_CURSOR_USER);
644 rv = edje_object_part_text_cursor_coord_set
645 (sd->entry_edje, "elm.text", EDJE_CURSOR_MAIN, drop->x, drop->y);
646
647 if (!rv) WRN("Warning: Failed to position cursor: paste anyway");
648
649 buf = malloc(drop->len + 1);
650 if (!buf) 643 if (!buf)
651 { 644 {
652 ERR("Failed to allocate memory for dropped text %p", obj); 645 ERR("Failed to allocate memory for pasted/dropped text %p", obj);
653 return EINA_FALSE; 646 return EINA_FALSE;
654 } 647 }
655 memcpy(buf, drop->data, drop->len); 648 memcpy(buf, sel_data->data, sel_data->len);
656 buf[drop->len] = '\0'; 649 buf[sel_data->len] = '\0';
657 650
658 if (drop->format & ELM_SEL_FORMAT_IMAGE) 651 if ((sel_data->format & ELM_SEL_FORMAT_IMAGE) &&
652 (sd->cnp_mode != ELM_CNP_MODE_NO_IMAGE))
659 { 653 {
660 char *entry_tag; 654 char *entry_tag;
661 int len; 655 int len;
@@ -671,12 +665,33 @@ _drag_drop_cb(void *data EINA_UNUSED,
671 { 665 {
672 elm_entry_entry_insert(obj, buf); 666 elm_entry_entry_insert(obj, buf);
673 } 667 }
674
675 free(buf); 668 free(buf);
669
670 return EINA_TRUE;
671}
672
673static Eina_Bool
674_drag_drop_cb(void *data EINA_UNUSED,
675 Evas_Object *obj,
676 Elm_Selection_Data *drop)
677{
678 Eina_Bool rv;
679
680 ELM_ENTRY_DATA_GET(obj, sd);
681
682 edje_object_part_text_cursor_copy
683 (sd->entry_edje, "elm.text", EDJE_CURSOR_MAIN, /*->*/ EDJE_CURSOR_USER);
684 rv = edje_object_part_text_cursor_coord_set
685 (sd->entry_edje, "elm.text", EDJE_CURSOR_MAIN, drop->x, drop->y);
686
687 if (!rv) WRN("Warning: Failed to position cursor: paste anyway");
688
689 rv = _selection_data_cb(NULL, obj, drop);
690
676 edje_object_part_text_cursor_copy 691 edje_object_part_text_cursor_copy
677 (sd->entry_edje, "elm.text", EDJE_CURSOR_USER, /*->*/ EDJE_CURSOR_MAIN); 692 (sd->entry_edje, "elm.text", EDJE_CURSOR_USER, /*->*/ EDJE_CURSOR_MAIN);
678 693
679 return EINA_TRUE; 694 return rv;
680} 695}
681 696
682static Elm_Sel_Format 697static Elm_Sel_Format
@@ -1371,7 +1386,7 @@ _paste_cb(void *data,
1371 formats |= ELM_SEL_FORMAT_IMAGE; 1386 formats |= ELM_SEL_FORMAT_IMAGE;
1372 1387
1373 elm_cnp_selection_get 1388 elm_cnp_selection_get
1374 (data, ELM_SEL_TYPE_CLIPBOARD, formats, NULL, NULL); 1389 (data, ELM_SEL_TYPE_CLIPBOARD, formats, _selection_data_cb, NULL);
1375} 1390}
1376 1391
1377static void 1392static void
@@ -2122,7 +2137,7 @@ _entry_paste_request_signal_cb(void *data,
2122 else if (sd->cnp_mode != ELM_CNP_MODE_NO_IMAGE) 2137 else if (sd->cnp_mode != ELM_CNP_MODE_NO_IMAGE)
2123 formats |= ELM_SEL_FORMAT_IMAGE; 2138 formats |= ELM_SEL_FORMAT_IMAGE;
2124 2139
2125 elm_cnp_selection_get(data, type, formats, NULL, NULL); 2140 elm_cnp_selection_get(data, type, formats, _selection_data_cb, NULL);
2126 } 2141 }
2127} 2142}
2128 2143