summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiep Ha <thiepha@gmail.com>2015-06-09 17:04:48 +0900
committerDaniel Zaoui <daniel.zaoui@yahoo.com>2015-06-12 11:53:34 +0300
commit5e468afa0d5b26cb6628460d3392b4d7aefa12c6 (patch)
tree833ab2903b3da9be553a9788368528a6e6a70cad
parent562a334fc0e52538df37155d33b354d1c582dd12 (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.c67
-rw-r--r--src/lib/elm_entry.c54
2 files changed, 64 insertions, 57 deletions
diff --git a/src/lib/elm_cnp.c b/src/lib/elm_cnp.c
index 8ccbe09bc..c38dbf57a 100644
--- a/src/lib/elm_cnp.c
+++ b/src/lib/elm_cnp.c
@@ -200,7 +200,6 @@ static Eina_Bool _local_elm_drop_target_del(Evas_Object *obj, Elm_Sel_Format fo
200static Ecore_X_Window _x11_elm_widget_xwin_get(const Evas_Object *obj); 200static Ecore_X_Window _x11_elm_widget_xwin_get(const Evas_Object *obj);
201static Tmp_Info *_tempfile_new (int size); 201static Tmp_Info *_tempfile_new (int size);
202static int _tmpinfo_free (Tmp_Info *tmp); 202static int _tmpinfo_free (Tmp_Info *tmp);
203static Eina_Bool _pasteimage_append (char *file, Evas_Object *entry);
204 203
205typedef struct _X11_Cnp_Selection X11_Cnp_Selection; 204typedef struct _X11_Cnp_Selection X11_Cnp_Selection;
206 205
@@ -985,31 +984,8 @@ _x11_notify_handler_text(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify
985 ddata.action = sel->action; 984 ddata.action = sel->action;
986 sel->datacb(sel->udata, sel->widget, &ddata); 985 sel->datacb(sel->udata, sel->widget, &ddata);
987 } 986 }
988 else 987 else cnp_debug("Paste request\n");
989 {
990 char *stripstr, *mkupstr;
991
992 stripstr = malloc(data->length + 1);
993 if (!stripstr) goto end;
994 strncpy(stripstr, (char *)data->data, data->length);
995 stripstr[data->length] = '\0';
996 cnp_debug("Notify handler text %d %d %p\n", data->format,
997 data->length, data->data);
998 mkupstr = _elm_util_text_to_mkup((const char *)stripstr);
999
1000 if (!mkupstr)
1001 {
1002 ERR("Failed to convert text to markup text!");
1003 free(stripstr);
1004 goto end;
1005 }
1006 988
1007 cnp_debug("String is %s (from %s)\n", stripstr, data->data);
1008 /* TODO BUG: should never NEVER assume it's an elm_entry! */
1009 _elm_entry_entry_paste(sel->requestwidget, mkupstr);
1010 free(stripstr);
1011 free(mkupstr);
1012 }
1013end: 989end:
1014 if (sel == (_x11_selections + ELM_SEL_TYPE_XDND)) 990 if (sel == (_x11_selections + ELM_SEL_TYPE_XDND))
1015 ecore_x_dnd_send_finished(); 991 ecore_x_dnd_send_finished();
@@ -1167,10 +1143,17 @@ _x11_notify_handler_uri(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *
1167 cbs->dropcb(cbs->dropdata, dropable->obj, &ddata); 1143 cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
1168 } 1144 }
1169 } 1145 }
1170 else 1146 else if (sel->datacb)
1171 { 1147 {
1172 _pasteimage_append(p, sel->requestwidget); 1148 Elm_Selection_Data ddata;
1149 ddata.x = ddata.y = 0;
1150 ddata.format = ELM_SEL_FORMAT_IMAGE;
1151 ddata.data = stripstr;
1152 ddata.len = strlen(stripstr);
1153 sel->datacb(sel->udata, sel->requestwidget, &ddata);
1173 } 1154 }
1155 else cnp_debug("Paste request\n");
1156
1174 savedtypes.imgfile = NULL; 1157 savedtypes.imgfile = NULL;
1175 free(stripstr); 1158 free(stripstr);
1176 } 1159 }
@@ -1237,7 +1220,6 @@ static int
1237_x11_notify_handler_image(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify) 1220_x11_notify_handler_image(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
1238{ 1221{
1239 Ecore_X_Selection_Data *data; 1222 Ecore_X_Selection_Data *data;
1240 Tmp_Info *tmp;
1241 1223
1242 cnp_debug("got a image file!\n"); 1224 cnp_debug("got a image file!\n");
1243 data = notify->data; 1225 data = notify->data;
@@ -1245,6 +1227,7 @@ _x11_notify_handler_image(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify
1245 cnp_debug("Size if %d\n", data->length); 1227 cnp_debug("Size if %d\n", data->length);
1246 if (sel == (_x11_selections + ELM_SEL_TYPE_XDND)) 1228 if (sel == (_x11_selections + ELM_SEL_TYPE_XDND))
1247 { 1229 {
1230 Tmp_Info *tmp;
1248 Eina_List *l; 1231 Eina_List *l;
1249 Dropable *dropable; 1232 Dropable *dropable;
1250 1233
@@ -1279,7 +1262,6 @@ _x11_notify_handler_image(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify
1279 } 1262 }
1280 _tmpinfo_free(tmp); 1263 _tmpinfo_free(tmp);
1281 ecore_x_dnd_send_finished(); 1264 ecore_x_dnd_send_finished();
1282 return 0;
1283 } 1265 }
1284 else if (sel->datacb) 1266 else if (sel->datacb)
1285 { 1267 {
@@ -1291,16 +1273,8 @@ _x11_notify_handler_image(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify
1291 ddata.len = data->length; 1273 ddata.len = data->length;
1292 ddata.action = sel->action; 1274 ddata.action = sel->action;
1293 sel->datacb(sel->udata, sel->widget, &ddata); 1275 sel->datacb(sel->udata, sel->widget, &ddata);
1294 return 0;
1295 } 1276 }
1296 /* generate tmp name */ 1277 else cnp_debug("Paste request\n");
1297 tmp = _tempfile_new(data->length);
1298 if (!tmp) return 0;
1299 memcpy(tmp->map, data->data, data->length);
1300 munmap(tmp->map, data->length);
1301 /* FIXME: Add to paste image data to clean up */
1302 _pasteimage_append(tmp->filename, sel->requestwidget);
1303 _tmpinfo_free(tmp);
1304 return 0; 1278 return 0;
1305} 1279}
1306 1280
@@ -4005,23 +3979,6 @@ _tmpinfo_free(Tmp_Info *info)
4005 return 0; 3979 return 0;
4006} 3980}
4007 3981
4008static Eina_Bool
4009_pasteimage_append(char *file, Evas_Object *entry)
4010{
4011 char *entrytag;
4012 int len;
4013 /* TODO BUG: shouldn't define absize=240x180. Prefer data:// instead of href:// -- may need support for evas. See http://dataurl.net/ */
4014 static const char *tagstring = "<item absize=240x180 href=file://%s></item>";
4015
4016 if ((!file) || (!entry)) return EINA_FALSE;
4017 len = strlen(tagstring)+strlen(file);
4018 entrytag = alloca(len + 1);
4019 snprintf(entrytag, len + 1, tagstring, file);
4020 /* TODO BUG: should never NEVER assume it's an elm_entry! */
4021 _elm_entry_entry_paste(entry, entrytag);
4022 return EINA_TRUE;
4023}
4024
4025//////////////////////////////////////////////////////////////////////////// 3982////////////////////////////////////////////////////////////////////////////
4026//////////////////////////////////////////////////////////////////////////// 3983////////////////////////////////////////////////////////////////////////////
4027//////////////////////////////////////////////////////////////////////////// 3984////////////////////////////////////////////////////////////////////////////
diff --git a/src/lib/elm_entry.c b/src/lib/elm_entry.c
index c88cfe2d3..040160442 100644
--- a/src/lib/elm_entry.c
+++ b/src/lib/elm_entry.c
@@ -632,6 +632,56 @@ _elm_entry_theme_group_get(Evas_Object *obj)
632} 632}
633 633
634static Eina_Bool 634static Eina_Bool
635_selection_data_cb(void *data EINA_UNUSED,
636 Evas_Object *obj,
637 Elm_Selection_Data *sel_data)
638{
639 char *buf;
640
641 if (!sel_data->data) return EINA_FALSE;
642 ELM_ENTRY_DATA_GET(obj, sd);
643
644 buf = malloc(sel_data->len + 1);
645 if (!buf)
646 {
647 ERR("Failed to allocate memory, obj: %p", obj);
648 return EINA_FALSE;
649 }
650 memcpy(buf, sel_data->data, sel_data->len);
651 buf[sel_data->len] = '\0';
652
653 if ((sel_data->format & ELM_SEL_FORMAT_IMAGE) &&
654 (sd->cnp_mode != ELM_CNP_MODE_NO_IMAGE))
655 {
656 char *entry_tag;
657 int len;
658 static const char *tag_string =
659 "<item absize=240x180 href=file://%s></item>";
660
661 len = strlen(tag_string) + strlen(buf);
662 entry_tag = alloca(len + 1);
663 snprintf(entry_tag, len + 1, tag_string, buf);
664 elm_entry_entry_insert(obj, entry_tag);
665 }
666 else
667 {
668 char *txt = _elm_util_text_to_mkup(buf);
669 if (txt)
670 {
671 elm_entry_entry_insert(obj, txt);
672 free(txt);
673 }
674 else
675 {
676 ERR("Failed to convert text to markup text!");
677 }
678 }
679 free(buf);
680
681 return EINA_TRUE;
682}
683
684static Eina_Bool
635_drag_drop_cb(void *data EINA_UNUSED, 685_drag_drop_cb(void *data EINA_UNUSED,
636 Evas_Object *obj, 686 Evas_Object *obj,
637 Elm_Selection_Data *drop) 687 Elm_Selection_Data *drop)
@@ -1356,7 +1406,7 @@ _paste_cb(void *data,
1356 formats |= ELM_SEL_FORMAT_IMAGE; 1406 formats |= ELM_SEL_FORMAT_IMAGE;
1357 1407
1358 elm_cnp_selection_get 1408 elm_cnp_selection_get
1359 (data, ELM_SEL_TYPE_CLIPBOARD, formats, NULL, NULL); 1409 (data, ELM_SEL_TYPE_CLIPBOARD, formats, _selection_data_cb, NULL);
1360} 1410}
1361 1411
1362static void 1412static void
@@ -2110,7 +2160,7 @@ _entry_paste_request_signal_cb(void *data,
2110 else if (sd->cnp_mode != ELM_CNP_MODE_NO_IMAGE) 2160 else if (sd->cnp_mode != ELM_CNP_MODE_NO_IMAGE)
2111 formats |= ELM_SEL_FORMAT_IMAGE; 2161 formats |= ELM_SEL_FORMAT_IMAGE;
2112 2162
2113 elm_cnp_selection_get(data, type, formats, NULL, NULL); 2163 elm_cnp_selection_get(data, type, formats, _selection_data_cb, NULL);
2114 } 2164 }
2115} 2165}
2116 2166