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)
downloadelementary-5e468afa0d5b26cb6628460d3392b4d7aefa12c6.tar.gz
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
static Ecore_X_Window _x11_elm_widget_xwin_get(const Evas_Object *obj);
static Tmp_Info *_tempfile_new (int size);
static int _tmpinfo_free (Tmp_Info *tmp);
-static Eina_Bool _pasteimage_append (char *file, Evas_Object *entry);
typedef struct _X11_Cnp_Selection X11_Cnp_Selection;
@@ -985,31 +984,8 @@ _x11_notify_handler_text(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify
ddata.action = sel->action;
sel->datacb(sel->udata, sel->widget, &ddata);
}
- else
- {
- char *stripstr, *mkupstr;
-
- stripstr = malloc(data->length + 1);
- if (!stripstr) goto end;
- strncpy(stripstr, (char *)data->data, data->length);
- stripstr[data->length] = '\0';
- cnp_debug("Notify handler text %d %d %p\n", data->format,
- data->length, data->data);
- mkupstr = _elm_util_text_to_mkup((const char *)stripstr);
-
- if (!mkupstr)
- {
- ERR("Failed to convert text to markup text!");
- free(stripstr);
- goto end;
- }
+ else cnp_debug("Paste request\n");
- cnp_debug("String is %s (from %s)\n", stripstr, data->data);
- /* TODO BUG: should never NEVER assume it's an elm_entry! */
- _elm_entry_entry_paste(sel->requestwidget, mkupstr);
- free(stripstr);
- free(mkupstr);
- }
end:
if (sel == (_x11_selections + ELM_SEL_TYPE_XDND))
ecore_x_dnd_send_finished();
@@ -1167,10 +1143,17 @@ _x11_notify_handler_uri(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *
cbs->dropcb(cbs->dropdata, dropable->obj, &ddata);
}
}
- else
+ else if (sel->datacb)
{
- _pasteimage_append(p, sel->requestwidget);
+ Elm_Selection_Data ddata;
+ ddata.x = ddata.y = 0;
+ ddata.format = ELM_SEL_FORMAT_IMAGE;
+ ddata.data = stripstr;
+ ddata.len = strlen(stripstr);
+ sel->datacb(sel->udata, sel->requestwidget, &ddata);
}
+ else cnp_debug("Paste request\n");
+
savedtypes.imgfile = NULL;
free(stripstr);
}
@@ -1237,7 +1220,6 @@ static int
_x11_notify_handler_image(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
{
Ecore_X_Selection_Data *data;
- Tmp_Info *tmp;
cnp_debug("got a image file!\n");
data = notify->data;
@@ -1245,6 +1227,7 @@ _x11_notify_handler_image(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify
cnp_debug("Size if %d\n", data->length);
if (sel == (_x11_selections + ELM_SEL_TYPE_XDND))
{
+ Tmp_Info *tmp;
Eina_List *l;
Dropable *dropable;
@@ -1279,7 +1262,6 @@ _x11_notify_handler_image(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify
}
_tmpinfo_free(tmp);
ecore_x_dnd_send_finished();
- return 0;
}
else if (sel->datacb)
{
@@ -1291,16 +1273,8 @@ _x11_notify_handler_image(X11_Cnp_Selection *sel, Ecore_X_Event_Selection_Notify
ddata.len = data->length;
ddata.action = sel->action;
sel->datacb(sel->udata, sel->widget, &ddata);
- return 0;
}
- /* generate tmp name */
- tmp = _tempfile_new(data->length);
- if (!tmp) return 0;
- memcpy(tmp->map, data->data, data->length);
- munmap(tmp->map, data->length);
- /* FIXME: Add to paste image data to clean up */
- _pasteimage_append(tmp->filename, sel->requestwidget);
- _tmpinfo_free(tmp);
+ else cnp_debug("Paste request\n");
return 0;
}
@@ -4005,23 +3979,6 @@ _tmpinfo_free(Tmp_Info *info)
return 0;
}
-static Eina_Bool
-_pasteimage_append(char *file, Evas_Object *entry)
-{
- char *entrytag;
- int len;
- /* TODO BUG: shouldn't define absize=240x180. Prefer data:// instead of href:// -- may need support for evas. See http://dataurl.net/ */
- static const char *tagstring = "<item absize=240x180 href=file://%s></item>";
-
- if ((!file) || (!entry)) return EINA_FALSE;
- len = strlen(tagstring)+strlen(file);
- entrytag = alloca(len + 1);
- snprintf(entrytag, len + 1, tagstring, file);
- /* TODO BUG: should never NEVER assume it's an elm_entry! */
- _elm_entry_entry_paste(entry, entrytag);
- return EINA_TRUE;
-}
-
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
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)
}
static Eina_Bool
+_selection_data_cb(void *data EINA_UNUSED,
+ Evas_Object *obj,
+ Elm_Selection_Data *sel_data)
+{
+ char *buf;
+
+ if (!sel_data->data) return EINA_FALSE;
+ ELM_ENTRY_DATA_GET(obj, sd);
+
+ buf = malloc(sel_data->len + 1);
+ if (!buf)
+ {
+ ERR("Failed to allocate memory, obj: %p", obj);
+ return EINA_FALSE;
+ }
+ memcpy(buf, sel_data->data, sel_data->len);
+ buf[sel_data->len] = '\0';
+
+ if ((sel_data->format & ELM_SEL_FORMAT_IMAGE) &&
+ (sd->cnp_mode != ELM_CNP_MODE_NO_IMAGE))
+ {
+ char *entry_tag;
+ int len;
+ static const char *tag_string =
+ "<item absize=240x180 href=file://%s></item>";
+
+ len = strlen(tag_string) + strlen(buf);
+ entry_tag = alloca(len + 1);
+ snprintf(entry_tag, len + 1, tag_string, buf);
+ elm_entry_entry_insert(obj, entry_tag);
+ }
+ else
+ {
+ char *txt = _elm_util_text_to_mkup(buf);
+ if (txt)
+ {
+ elm_entry_entry_insert(obj, txt);
+ free(txt);
+ }
+ else
+ {
+ ERR("Failed to convert text to markup text!");
+ }
+ }
+ free(buf);
+
+ return EINA_TRUE;
+}
+
+static Eina_Bool
_drag_drop_cb(void *data EINA_UNUSED,
Evas_Object *obj,
Elm_Selection_Data *drop)
@@ -1356,7 +1406,7 @@ _paste_cb(void *data,
formats |= ELM_SEL_FORMAT_IMAGE;
elm_cnp_selection_get
- (data, ELM_SEL_TYPE_CLIPBOARD, formats, NULL, NULL);
+ (data, ELM_SEL_TYPE_CLIPBOARD, formats, _selection_data_cb, NULL);
}
static void
@@ -2110,7 +2160,7 @@ _entry_paste_request_signal_cb(void *data,
else if (sd->cnp_mode != ELM_CNP_MODE_NO_IMAGE)
formats |= ELM_SEL_FORMAT_IMAGE;
- elm_cnp_selection_get(data, type, formats, NULL, NULL);
+ elm_cnp_selection_get(data, type, formats, _selection_data_cb, NULL);
}
}