summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiep Ha <thiepha@gmail.com>2015-06-09 17:04:48 +0900
committerThiep Ha <thiepha@gmail.com>2015-06-09 18:15:11 +0900
commit9b0c1f0062fff2d4f28834390d0a23d45558fac7 (patch)
tree9c6c6267a8434c0389b972759176f7355cbb33df
parent0ad02006ea209712a3ba761058c3a9a8ac9f6ccc (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.c61
-rw-r--r--src/lib/elm_entry.c50
2 files changed, 61 insertions, 50 deletions
diff --git a/src/lib/elm_cnp.c b/src/lib/elm_cnp.c
index fa6409ea8..5adf1cd13 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,23 +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 { 988
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 cnp_debug("String is %s (from %s)\n", stripstr, data->data);
1000 /* TODO BUG: should never NEVER assume it's an elm_entry! */
1001 _elm_entry_entry_paste(sel->requestwidget, mkupstr);
1002 free(stripstr);
1003 free(mkupstr);
1004 }
1005end: 989end:
1006 if (sel == (_x11_selections + ELM_SEL_TYPE_XDND)) 990 if (sel == (_x11_selections + ELM_SEL_TYPE_XDND))
1007 ecore_x_dnd_send_finished(); 991 ecore_x_dnd_send_finished();
@@ -1159,10 +1143,17 @@ _x11_notify_handler_uri(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *
1159 cbs->dropcb(cbs->dropdata, dropable->obj, &ddata); 1143 cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
1160 } 1144 }
1161 } 1145 }
1162 else 1146 else if (sel->datacb)
1163 { 1147 {
1164 _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);
1165 } 1154 }
1155 else cnp_debug("Paste request\n");
1156
1166 savedtypes.imgfile = NULL; 1157 savedtypes.imgfile = NULL;
1167 free(stripstr); 1158 free(stripstr);
1168 } 1159 }
@@ -1229,7 +1220,6 @@ static int
1229_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)
1230{ 1221{
1231 Ecore_X_Selection_Data *data; 1222 Ecore_X_Selection_Data *data;
1232 Tmp_Info *tmp;
1233 1223
1234 cnp_debug("got a image file!\n"); 1224 cnp_debug("got a image file!\n");
1235 data = notify->data; 1225 data = notify->data;
@@ -1237,6 +1227,7 @@ _x11_notify_handler_image(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify
1237 cnp_debug("Size if %d\n", data->length); 1227 cnp_debug("Size if %d\n", data->length);
1238 if (sel == (_x11_selections + ELM_SEL_TYPE_XDND)) 1228 if (sel == (_x11_selections + ELM_SEL_TYPE_XDND))
1239 { 1229 {
1230 Tmp_Info *tmp;
1240 Eina_List *l; 1231 Eina_List *l;
1241 Dropable *dropable; 1232 Dropable *dropable;
1242 1233
@@ -1271,7 +1262,6 @@ _x11_notify_handler_image(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify
1271 } 1262 }
1272 _tmpinfo_free(tmp); 1263 _tmpinfo_free(tmp);
1273 ecore_x_dnd_send_finished(); 1264 ecore_x_dnd_send_finished();
1274 return 0;
1275 } 1265 }
1276 else if (sel->datacb) 1266 else if (sel->datacb)
1277 { 1267 {
@@ -1283,16 +1273,8 @@ _x11_notify_handler_image(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify
1283 ddata.len = data->length; 1273 ddata.len = data->length;
1284 ddata.action = sel->action; 1274 ddata.action = sel->action;
1285 sel->datacb(sel->udata, sel->widget, &ddata); 1275 sel->datacb(sel->udata, sel->widget, &ddata);
1286 return 0;
1287 } 1276 }
1288 /* generate tmp name */ 1277 else cnp_debug("Paste request\n");
1289 tmp = _tempfile_new(data->length);
1290 if (!tmp) return 0;
1291 memcpy(tmp->map, data->data, data->length);
1292 munmap(tmp->map, data->length);
1293 /* FIXME: Add to paste image data to clean up */
1294 _pasteimage_append(tmp->filename, sel->requestwidget);
1295 _tmpinfo_free(tmp);
1296 return 0; 1278 return 0;
1297} 1279}
1298 1280
@@ -3989,23 +3971,6 @@ _tmpinfo_free(Tmp_Info *info)
3989 return 0; 3971 return 0;
3990} 3972}
3991 3973
3992static Eina_Bool
3993_pasteimage_append(char *file, Evas_Object *entry)
3994{
3995 char *entrytag;
3996 int len;
3997 /* TODO BUG: shouldn't define absize=240x180. Prefer data:// instead of href:// -- may need support for evas. See http://dataurl.net/ */
3998 static const char *tagstring = "<item absize=240x180 href=file://%s></item>";
3999
4000 if ((!file) || (!entry)) return EINA_FALSE;
4001 len = strlen(tagstring)+strlen(file);
4002 entrytag = alloca(len + 1);
4003 snprintf(entrytag, len + 1, tagstring, file);
4004 /* TODO BUG: should never NEVER assume it's an elm_entry! */
4005 _elm_entry_entry_paste(entry, entrytag);
4006 return EINA_TRUE;
4007}
4008
4009//////////////////////////////////////////////////////////////////////////// 3974////////////////////////////////////////////////////////////////////////////
4010//////////////////////////////////////////////////////////////////////////// 3975////////////////////////////////////////////////////////////////////////////
4011//////////////////////////////////////////////////////////////////////////// 3976////////////////////////////////////////////////////////////////////////////
diff --git a/src/lib/elm_entry.c b/src/lib/elm_entry.c
index c88cfe2d3..9ccb07596 100644
--- a/src/lib/elm_entry.c
+++ b/src/lib/elm_entry.c
@@ -632,6 +632,52 @@ _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 }
675 free(buf);
676
677 return EINA_TRUE;
678}
679
680static Eina_Bool
635_drag_drop_cb(void *data EINA_UNUSED, 681_drag_drop_cb(void *data EINA_UNUSED,
636 Evas_Object *obj, 682 Evas_Object *obj,
637 Elm_Selection_Data *drop) 683 Elm_Selection_Data *drop)
@@ -1356,7 +1402,7 @@ _paste_cb(void *data,
1356 formats |= ELM_SEL_FORMAT_IMAGE; 1402 formats |= ELM_SEL_FORMAT_IMAGE;
1357 1403
1358 elm_cnp_selection_get 1404 elm_cnp_selection_get
1359 (data, ELM_SEL_TYPE_CLIPBOARD, formats, NULL, NULL); 1405 (data, ELM_SEL_TYPE_CLIPBOARD, formats, _selection_data_cb, NULL);
1360} 1406}
1361 1407
1362static void 1408static void
@@ -2110,7 +2156,7 @@ _entry_paste_request_signal_cb(void *data,
2110 else if (sd->cnp_mode != ELM_CNP_MODE_NO_IMAGE) 2156 else if (sd->cnp_mode != ELM_CNP_MODE_NO_IMAGE)
2111 formats |= ELM_SEL_FORMAT_IMAGE; 2157 formats |= ELM_SEL_FORMAT_IMAGE;
2112 2158
2113 elm_cnp_selection_get(data, type, formats, NULL, NULL); 2159 elm_cnp_selection_get(data, type, formats, _selection_data_cb, NULL);
2114 } 2160 }
2115} 2161}
2116 2162