X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Flib%2Felm_cnp_helper.c;h=59554caea15cf872291d9b5c0134d5b2d89e76da;hb=bfe867270ec39dda945e1dc3ab4969f91bf73236;hp=508197735d7f21ae6be884cae8afe676352a8a41;hpb=21982ac9d0ad08b6d6b9968a140908c6f242f790;p=framework%2Fuifw%2Felementary.git
diff --git a/src/lib/elm_cnp_helper.c b/src/lib/elm_cnp_helper.c
index 5081977..59554ca 100644
--- a/src/lib/elm_cnp_helper.c
+++ b/src/lib/elm_cnp_helper.c
@@ -12,7 +12,6 @@
//#define DEBUGON 1
-
#ifdef DEBUGON
# define cnp_debug(x...) fprintf(stderr, __FILE__": " x)
#else
@@ -143,7 +142,6 @@ static char *mark_up(const char *start, int inlen, int *lenp);
static Evas_Object *image_provider(void *images, Evas_Object *entry, const char *item);
static void entry_deleted(void *images, Evas *e, Evas_Object *entry, void *unused);
-
static Eina_Bool targets_converter(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
static Eina_Bool text_converter(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
static Eina_Bool html_converter(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
@@ -158,23 +156,26 @@ static int notify_handler_targets(Cnp_Selection *sel, Ecore_X_Event_Selection_No
static int notify_handler_text(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
static int notify_handler_image(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
static int notify_handler_uri(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
+static int notify_handler_edje(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
static int notify_handler_html(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
static int vcard_receive(Cnp_Selection *sed, Ecore_X_Event_Selection_Notify *notify);
static Paste_Image *pasteimage_alloc(const char *file, int pathlen);
static Eina_Bool pasteimage_append(Paste_Image *pi, Evas_Object *entry);
static void pasteimage_free(Paste_Image *pi);
+static void entry_insert_filter(Evas_Object* entry, char* str);
/* Optimisation: Turn this into a 256 byte table:
* then can lookup in one index, not N checks */
static const Escape escapes[] = {
- { "
", '\n' },
- { "<\t>", '\t' },
- { "gt;", '>' },
- { "lt;", '<' },
- { "amp;", '&' },
- { "quot;", '\'' },
- { "dquot;", '"' }
+ { "
", '\n' },
+ { "", '\n' },
+ { "<\t>", '\t' },
+ { "gt;", '>' },
+ { "lt;", '<' },
+ { "amp;", '&' },
+ { "quot;", '\'' },
+ { "dquot;", '"' }
};
#define N_ESCAPES ((int)(sizeof(escapes) / sizeof(escapes[0])))
@@ -189,10 +190,10 @@ static Cnp_Atom atoms[CNP_N_ATOMS] = {
},
[CNP_ATOM_XELM] = {
"application/x-elementary-markup",
- ELM_SEL_FORMAT_MARKUP,
+ ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
edje_converter,
NULL,
- NULL,
+ notify_handler_edje,
0
},
[CNP_ATOM_text_uri] = {
@@ -406,7 +407,6 @@ static Ecore_Event_Handler *handler_status = NULL;
/* Stringshared, so I can just compare pointers later */
static const char *text_uri;
-
/* For convert EFL to HTML */
#define TAGPOS_START 0x00000001
@@ -428,10 +428,24 @@ TagTable _EFLtoHTMLConvertTable[] = {
{"underline", "del", 0},
{"strikethrough", "ins", 0},
{"br", "br", 1},
+ {"ps", "br", 1},
{"b", "b", 1},
{"item", "img", 1}
};
+TagTable _HTMLtoEFLConvertTable[] = {
+ {"font", "", 0},
+ {"del", "underline", 0},
+ {"u", "underline", 0},
+ {"ins", "strikethrough", 0},
+ {"s", "strikethrough", 0},
+ {"br", "br", 1},
+ {"b", "b", 1},
+ {"strong", "b", 1},
+ {"img", "item", 1}
+};
+
+
typedef struct _TagNode TagNode, *PTagNode;
struct _TagNode {
char *tag; //EINA_STRINGSHARE if NULL just str
@@ -486,8 +500,12 @@ static void _link_match_tags(Eina_List *nodes);
static char *_get_tag_value(const char *tag_str, const char *tag_name);
static char *_convert_to_html(Eina_List* nodes);
static void _set_EFL_tag_data(Eina_List* nodes);
+static char *_convert_to_edje(Eina_List* nodes);
+static void _set_HTML_tag_data(Eina_List* nodes);
static PFontTagData _set_EFL_font_data(PFontTagData data, const char *tag_str);
static PItemTagData _set_EFL_item_data(PItemTagData data, const char *tag_str);
+static PFontTagData _set_HTML_font_data(PFontTagData data, const char *tag_str);
+static PItemTagData _set_HTML_img_data(PItemTagData data, const char *tag_str);
#ifdef DEBUGON
static void _dumpNode(Eina_List* nodes);
@@ -497,7 +515,11 @@ static PTagNode
_new_tag_node(char *tag, char *tag_str, char* str, char *pos_in_ori_str)
{
PTagNode newNode = calloc(1, sizeof(TagNode));
+ if (tag)
+ eina_str_tolower(&tag);
newNode->tag = tag;
+ if (tag_str)
+ eina_str_tolower(&tag_str);
newNode->tag_str = tag_str;
newNode->str = str;
newNode->pos_in_ori_str = pos_in_ori_str;
@@ -647,7 +669,7 @@ _link_match_tags(Eina_List *nodes)
trail->tagPosType = TAGPOS_ALONE;
continue;
}
- else if (!strcmp("item", trail->tag))
+ else if (!strcmp("item", trail->tag) || !strcmp("img", trail->tag))
{
trail->tagPosType = TAGPOS_ALONE;
continue;
@@ -750,7 +772,12 @@ _get_tag_value(const char *tag_str, const char *tag_name)
char *valueEnd = strchr(value, '\0');
int i;
- for (i = 0; i < spCnt; i++)
+ int start = 0;
+ if ((!strncmp(tag_str, "- href = modify;
cnp_debug("image href ---%s---\n", data->href);
+ free(value);
}
- free(value);
+ else
+ freeAndAssign(data->href, value);
}
value = _get_tag_value(tag_str, "absize");
@@ -843,6 +871,78 @@ _set_EFL_tag_data(Eina_List* nodes)
}
}
+static PFontTagData
+_set_HTML_font_data(PFontTagData data, const char *tag_str)
+{
+ char *value;
+
+ if (!data)
+ data = calloc(1, sizeof(FontTagData));
+ value = _get_tag_value(tag_str, "size");
+ freeAndAssign(data->size, value);
+ value = _get_tag_value(tag_str, "color");
+ freeAndAssign(data->color, value);
+ value = _get_tag_value(tag_str, "bgcolor");
+ freeAndAssign(data->bg_color, value);
+ value = _get_tag_value(tag_str, "face");
+ freeAndAssign(data->name, value);
+
+ return data;
+}
+
+static PItemTagData
+_set_HTML_img_data(PItemTagData data, const char *tag_str)
+{
+ char *value;
+
+ if (!data)
+ data = calloc(1, sizeof(ItemTagData));
+ value = _get_tag_value(tag_str, "src");
+ if (value)
+ {
+ char *path = strstr(value, "file://");
+ if (path)
+ {
+ char *modify = malloc(sizeof(char) * (strlen(value) + 1));
+ strncpy(modify, "file://", 8);
+ path += 7;
+ while (path[1] && path[0] && path[1] == '/' && path[0] == '/')
+ {
+ path++;
+ }
+ strcat(modify, path);
+ data->href = modify;
+ cnp_debug("image src ---%s---\n", data->href);
+ free(value);
+ }
+ else
+ freeAndAssign(data->href, value);
+ }
+
+ value = _get_tag_value(tag_str, "width");
+ freeAndAssign(data->width, value);
+ value = _get_tag_value(tag_str, "height");
+ freeAndAssign(data->height, value);
+ return data;
+}
+
+static void
+_set_HTML_tag_data(Eina_List* nodes)
+{
+ PTagNode trail;
+ Eina_List *l;
+
+ EINA_LIST_FOREACH(nodes, l, trail)
+ {
+ if (!trail->tag)
+ continue;
+ if (!strcmp("font", trail->tag))
+ trail->tagData = _set_HTML_font_data(trail->tagData, trail->tag_str);
+ else if (!strcmp("img", trail->tag))
+ trail->tagData = _set_HTML_img_data(trail->tagData, trail->tag_str);
+ }
+}
+
#ifdef DEBUGON
static void
_dumpNode(Eina_List* nodes)
@@ -865,7 +965,7 @@ _dumpNode(Eina_List* nodes)
cnp_debug(" tagData->name: %s, tagData->color: %s, tagData->size: %s, tagData->bg_color: %s",
data->name, data->color, data->size, data->bg_color);
}
- else if (!strcmp(trail->tag, "item"))
+ else if (!strcmp(trail->tag, "item") || !strcmp(trail->tag, "img"))
{
PItemTagData data = trail->tagData;
cnp_debug(" tagData->href: %s, tagData->width: %s, tagData->height: %s",
@@ -940,9 +1040,10 @@ _convert_to_html(Eina_List* nodes)
}
switch(trail->tagPosType)
{
+ /* closed tag does not need in HTML
case TAGPOS_ALONE:
- eina_strbuf_append(html, "/>");
- break;
+ eina_strbuf_append(html, " />");
+ break;*/
default:
eina_strbuf_append(html, ">");
break;
@@ -960,12 +1061,136 @@ _convert_to_html(Eina_List* nodes)
return ret;
}
+#define IMAGE_DEFAULT_WIDTH "240"
+#define IMAGE_DEFAULT_HEIGHT "180"
+
+
+static char *
+_convert_to_edje(Eina_List* nodes)
+{
+ PTagNode trail;
+ Eina_List *l;
+
+ Eina_Strbuf *html = eina_strbuf_new();
+
+ int tableCnt = sizeof(_HTMLtoEFLConvertTable) / sizeof(TagTable);
+
+ EINA_LIST_FOREACH(nodes, l, trail)
+ {
+ if (trail->tag)
+ {
+ char *tagName = trail->tagPosType == TAGPOS_END ?
+ trail->matchTag->tag : trail->tag;
+ int j;
+ for(j = 0; j < tableCnt; j++)
+ {
+ if (!strcmp(_HTMLtoEFLConvertTable[j].src, tagName))
+ {
+ if (_HTMLtoEFLConvertTable[j].dst[0] != '\0')
+ {
+ switch(trail->tagPosType)
+ {
+ case TAGPOS_END:
+ eina_strbuf_append(html, "");
+ break;
+ default:
+ eina_strbuf_append(html, "<");
+ break;
+ }
+
+ eina_strbuf_append(html, _HTMLtoEFLConvertTable[j].dst);
+ }
+ if (trail->tagPosType != TAGPOS_END)
+ {
+ if (!strcmp(_HTMLtoEFLConvertTable[j].src, "font"))
+ {
+ PFontTagData data = trail->tagData;
+ if (data->name)
+ {
+ }
+ if (data->color)
+ eina_strbuf_append_printf(html, "", data->color);
+ if (data->size)
+ eina_strbuf_append_printf(html, "", data->size);
+ if (data->bg_color)
+ {
+ }
+ break;
+ }
+ else if (!strcmp(_HTMLtoEFLConvertTable[j].src, "img"))
+ {
+ PItemTagData data = trail->tagData;
+ char *width = IMAGE_DEFAULT_WIDTH, *height = IMAGE_DEFAULT_HEIGHT;
+ if (data->width)
+ width = data->width;
+ if (data->height)
+ height = data->height;
+ eina_strbuf_append_printf(html, " absize=%sx%s", width, height);
+ if (data->href)
+ eina_strbuf_append_printf(html, " href=%s>
", data->href);
+ break;
+ }
+ }
+ else
+ {
+ if (_HTMLtoEFLConvertTable[j].dst[0] == '\0')
+ {
+ if (!strcmp(_HTMLtoEFLConvertTable[j].src, "font"))
+ {
+ if (trail->matchTag->tagData)
+ {
+ PFontTagData data = trail->matchTag->tagData;
+ if (data->name)
+ {
+ }
+ if (data->color)
+ eina_strbuf_append_printf(html, "");
+ if (data->size)
+ eina_strbuf_append_printf(html, "");
+ if (data->bg_color)
+ {
+ }
+ break;
+ }
+ }
+ }
+ }
+ switch(trail->tagPosType)
+ {
+ /* not support in efl
+ case TAGPOS_ALONE:
+ eina_strbuf_append(html, " />");
+ break;
+ */
+ default:
+ eina_strbuf_append(html, ">");
+ break;
+ }
+ break;
+ }
+ }/* for(j = 0; j < tableCnt; j++) end */
+ }
+ if (trail->str)
+ eina_strbuf_append(html, trail->str);
+ }
+
+ char *ret = eina_strbuf_string_steal(html);
+ eina_strbuf_free(html);
+ return ret;
+
+}
+
Eina_Bool
elm_selection_set(Elm_Sel_Type selection, Evas_Object *widget, Elm_Sel_Format format, const char *selbuf)
{
#ifdef HAVE_ELEMENTARY_X
+ Evas_Object *top = elm_widget_top_get(widget);
+ Ecore_X_Window xwin;
Cnp_Selection *sel;
+ if (top) xwin = elm_win_xwindow_get(top);
+ else xwin = elm_win_xwindow_get(widget);
+ if (!xwin) return EINA_FALSE;
if ((unsigned int)selection >= (unsigned int)ELM_SEL_MAX) return EINA_FALSE;
if (!_elm_cnp_init_count) _elm_cnp_init();
if ((!selbuf) && (format != ELM_SEL_FORMAT_IMAGE))
@@ -976,7 +1201,7 @@ elm_selection_set(Elm_Sel_Type selection, Evas_Object *widget, Elm_Sel_Format fo
sel->active = 1;
sel->widget = widget;
- sel->set(elm_win_xwindow_get(widget),&selection,sizeof(Elm_Sel_Type));
+ sel->set(xwin, &selection, sizeof(Elm_Sel_Type));
sel->format = format;
sel->selbuf = selbuf ? strdup(selbuf) : NULL;
@@ -1146,6 +1371,8 @@ targets_converter(char *target __UNUSED__, void *data, int size __UNUSED__, void
Cnp_Selection *sel;
if (!data_ret) return EINA_FALSE;
+ if (!data || (*((unsigned int *)data) >= ELM_SEL_MAX))
+ return EINA_FALSE;
sel = selections + *((int *)data);
@@ -1189,6 +1416,28 @@ vcard_send(char *target __UNUSED__, void *data __UNUSED__, int size __UNUSED__,
return EINA_TRUE;
}
+
+static Eina_Bool
+is_uri_type_data(Cnp_Selection *sel __UNUSED__, Ecore_X_Event_Selection_Notify *notify)
+{
+ Ecore_X_Selection_Data *data;
+ char *p;
+
+ data = notify->data;
+ cnp_debug("data->format is %d %p %p\n", data->format, notify, data);
+ if (data->content == ECORE_X_SELECTION_CONTENT_FILES) return EINA_TRUE;
+ else p = (char *)data->data;
+
+ if (!p) return EINA_TRUE;
+ cnp_debug("Got %s\n", p);
+ if (strncmp(p, "file://", 7))
+ {
+ if (*p != '/') return EINA_FALSE;
+ }
+
+ return EINA_TRUE;
+}
+
/*
* Callback to handle a targets response on a selection request:
* So pick the format we'd like; and then request it.
@@ -1198,6 +1447,7 @@ notify_handler_targets(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notif
{
Ecore_X_Selection_Data_Targets *targets;
Ecore_X_Atom *atomlist;
+ Evas_Object *top;
int i, j;
targets = notify->data;
@@ -1211,6 +1461,13 @@ notify_handler_targets(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notif
{
if ((atoms[j].atom == atomlist[i]) && (atoms[j].notify))
{
+#if 0
+ if ((j == CNP_ATOM_text_uri) ||
+ (j == CNP_ATOM_text_urilist))
+ {
+ if(!is_uri_type_data(sel, notify)) continue;
+ }
+#endif
cnp_debug("Atom %s matches\n",atoms[j].name);
goto done;
}
@@ -1221,8 +1478,10 @@ notify_handler_targets(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notif
return ECORE_CALLBACK_PASS_ON;
done:
- cnp_debug("Sending request for %s\n",atoms[j].name);
- sel->request(elm_win_xwindow_get(sel->requestwidget), atoms[j].name);
+ top = elm_widget_top_get(sel->requestwidget);
+ if (!top) top = sel->requestwidget;
+ cnp_debug("Sending request for %s\n", atoms[j].name);
+ sel->request(elm_win_xwindow_get(top), atoms[j].name);
return ECORE_CALLBACK_PASS_ON;
}
@@ -1265,6 +1524,69 @@ found:
return 0;
}
+static void
+entry_insert_filter(Evas_Object* entry, char* str)
+{
+ if (!entry || !str)
+ return;
+
+ char *insertStr = str;
+ // if entry has text only set then remove item tags
+ if (elm_entry_cnp_textonly_get(entry))
+ {
+ while (EINA_TRUE)
+ {
+ char *startTag = NULL;
+ char *endTag = NULL;
+
+ startTag = strstr(insertStr, "- ");
+ else
+ break;
+ if (!endTag || startTag > endTag)
+ {
+ cnp_debug("Broken tag: %s\n", str);
+ break;
+ }
+
+ size_t sindex = startTag - insertStr;
+ size_t eindex = endTag - insertStr + 1;
+
+ Eina_Strbuf *buf = eina_strbuf_new();
+ if (buf)
+ {
+ eina_strbuf_append(buf, insertStr);
+ eina_strbuf_remove(buf, sindex, eindex);
+ insertStr = eina_strbuf_string_steal(buf);
+ eina_strbuf_free(buf);
+ }
+ }
+ }
+ cnp_debug("remove item tag: %s\n", insertStr);
+
+ // if entry has single line set then remove
& tags
+ if (elm_entry_single_line_get(entry))
+ {
+ Eina_Strbuf *buf = eina_strbuf_new();
+ if (buf)
+ {
+ eina_strbuf_append(buf, insertStr);
+ eina_strbuf_replace_all(buf, "
", "");
+ eina_strbuf_replace_all(buf, "", "");
+ insertStr = eina_strbuf_string_steal(buf);
+ eina_strbuf_free(buf);
+ }
+ }
+ cnp_debug("remove break tag: %s\n", insertStr);
+
+ elm_entry_entry_insert(entry, insertStr);
+
+ if (insertStr != str)
+ free(insertStr);
+}
static int
notify_handler_text(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
@@ -1277,8 +1599,8 @@ notify_handler_text(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
if (sel->datacb)
{
Elm_Selection_Data ddata;
-
- str = mark_up((char *)data->data, data->length, NULL);
+
+ str = strdup(data->data);
ddata.x = ddata.y = 0;
ddata.format = ELM_SEL_FORMAT_TEXT;
ddata.data = str;
@@ -1287,11 +1609,12 @@ notify_handler_text(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
free(str);
return 0;
}
-
+
cnp_debug("Notify handler text %d %d %p\n", data->format,data->length, data->data);
str = mark_up((char *)data->data, data->length, NULL);
cnp_debug("String is %s (from %s)\n", str, data->data);
- elm_entry_entry_insert(sel->requestwidget, str);
+ entry_insert_filter(sel->requestwidget, str);
+ //elm_entry_entry_insert(sel->requestwidget, str);
free(str);
return 0;
}
@@ -1306,7 +1629,7 @@ notify_handler_uri(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
Ecore_X_Selection_Data *data;
Ecore_X_Selection_Data_Files *files;
Paste_Image *pi;
- char *p;
+ char *p, *stripstr;
data = notify->data;
cnp_debug("data->format is %d %p %p\n", data->format, notify, data);
@@ -1320,11 +1643,11 @@ notify_handler_uri(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
cnp_debug("more then one file: Bailing\n");
return 0;
}
- p = files->files[0];
+ stripstr = p = strdup(files->files[0]);
}
else
{
- p = (char *)data->data;
+ stripstr = p = strndup((char *)data->data, data->length);
}
if (!p)
@@ -1336,18 +1659,23 @@ notify_handler_uri(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
if (sel->datacb)
{
Elm_Selection_Data ddata;
-
+
ddata.x = ddata.y = 0;
ddata.format = ELM_SEL_FORMAT_MARKUP;
ddata.data = p;
ddata.len = data->length;
sel->datacb(sel->udata, sel->widget, &ddata);
+ free(p);
return 0;
}
if (strncmp(p, "file://", 7))
{
/* Try and continue if it looks sane */
- if (*p != '/') return 0;
+ if (*p != '/')
+ {
+ free(p);
+ return 0;
+ }
}
else
{
@@ -1366,6 +1694,7 @@ notify_handler_uri(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
pasteimage_append(pi, sel->requestwidget);
savedtypes.pi = NULL;
}
+ free(stripstr);
return 0;
}
@@ -1463,6 +1792,35 @@ notify_handler_image(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
return 0;
}
+static int
+notify_handler_edje(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
+{
+ Ecore_X_Selection_Data *data;
+
+ data = notify->data;
+
+ char *stripstr = NULL;
+ stripstr = malloc(sizeof(char) * (data->length + 1));
+ strncpy(stripstr, (char *)data->data, data->length);
+ stripstr[data->length] = '\0';
+
+ if (sel->datacb)
+ {
+ Elm_Selection_Data ddata;
+ ddata.x = ddata.y = 0;
+ ddata.format = ELM_SEL_FORMAT_MARKUP;
+ ddata.data = stripstr;
+ ddata.len = data->length;
+ sel->datacb(sel->udata, sel->widget, &ddata);
+ }
+ else
+ entry_insert_filter(sel->requestwidget, stripstr);
+ //elm_entry_entry_insert(sel->requestwidget, stripstr);
+
+ cnp_debug("String is %s (%d bytes)\n", stripstr, data->length);
+ free(stripstr);
+ return 0;
+}
/**
* Warning: Generic text/html can';t handle it sanely.
@@ -1477,23 +1835,25 @@ notify_handler_html(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
cnp_debug("Got some HTML: Checking encoding is useful\n");
data = notify->data;
+ char *stripstr = NULL;
+ stripstr = malloc(sizeof(char) * (data->length + 1));
+ strncpy(stripstr, (char *)data->data, data->length);
+ stripstr[data->length] = '\0';
+
if (sel->datacb)
{
Elm_Selection_Data ddata;
ddata.x = ddata.y = 0;
ddata.format = ELM_SEL_FORMAT_HTML;
- ddata.data = data->data;
+ ddata.data = stripstr;
ddata.len = data->length;
sel->datacb(sel->udata, sel->widget, &ddata);
- return 0;
}
+ else
+ entry_insert_filter(sel->requestwidget, stripstr);
+ //elm_entry_entry_insert(sel->requestwidget, stripstr);
- char *stripstr = NULL;
- stripstr = malloc(sizeof(char) * (data->length + 1));
- strncpy(stripstr, (char *)data->data, data->length);
- stripstr[data->length] = '\0';
cnp_debug("String is %s (%d bytes)\n", stripstr, data->length);
- elm_entry_entry_insert(sel->requestwidget, stripstr);
free(stripstr);
return 0;
}
@@ -1534,15 +1894,70 @@ static Eina_Bool
edje_converter(char *target __UNUSED__, void *data, int size __UNUSED__, void **data_ret, int *size_ret, Ecore_X_Atom *ttype __UNUSED__, int *typesize __UNUSED__)
{
Cnp_Selection *sel;
-
sel = selections + *((int *)data);
- if (data_ret) *data_ret = strdup(sel->selbuf);
- if (size_ret) *size_ret = strlen(sel->selbuf);
+/* if (data_ret) *data_ret = strdup(sel->selbuf);
+ if (size_ret) *size_ret = strlen(sel->selbuf);*/
+ char *edje = NULL;
+
+ if (data_ret && (sel->format == ELM_SEL_FORMAT_TEXT))
+ {
+ if (sel->selbuf && sel->selbuf[0] != '\0')
+ edje = mark_up(sel->selbuf, strlen(sel->selbuf), NULL);
+ }
+ else if (data_ret && ((sel->format & ELM_SEL_FORMAT_HTML)))
+ {
+ Eina_List *nodeList = NULL;
+ Eina_List *trail;
+ PTagNode nodeData;
+
+ nodeData = _get_start_node(sel->selbuf);
+
+ while (nodeData)
+ {
+ nodeList = eina_list_append(nodeList, nodeData);
+ nodeData = _get_next_node(nodeData);
+ }
+
+ _link_match_tags(nodeList);
+
+ _set_HTML_tag_data(nodeList);
+
+#ifdef DEBUGON
+ _dumpNode(nodeList);
+#endif
+ edje = _convert_to_edje(nodeList);
+
+ cnp_debug("convert edje: %s\n", edje);
+
+ EINA_LIST_FOREACH(nodeList, trail, nodeData)
+ _delete_node(nodeData);
+ eina_list_free(nodeList);
+
+ }
+ if (data_ret)
+ {
+ if (edje)
+ *data_ret = edje;
+ else
+ if (sel->selbuf)
+ *data_ret = strdup(sel->selbuf);
+ else
+ *data_ret = strdup("");
+ }
+ if (size_ret)
+ {
+ if (edje)
+ *size_ret = strlen(edje);
+ else
+ if (sel->selbuf)
+ *size_ret = strlen(sel->selbuf);
+ else
+ *size_ret = 0;
+ }
return EINA_TRUE;
}
-
static Eina_Bool
html_converter(char *target __UNUSED__, void *data, int size __UNUSED__, void **data_ret, int *size_ret, Ecore_X_Atom *ttype __UNUSED__, int *typesize __UNUSED__)
{
@@ -1551,13 +1966,25 @@ html_converter(char *target __UNUSED__, void *data, int size __UNUSED__, void **
sel = selections + *(int *)data;
char *html = NULL;
- if (data_ret && (sel->format & ELM_SEL_FORMAT_MARKUP))
+ char *convert_target = sel->selbuf;
+ Eina_Bool convert_edje = EINA_FALSE;
+
+ if (data_ret && (sel->format == ELM_SEL_FORMAT_TEXT))
+ {
+ if (sel->selbuf && sel->selbuf[0] != '\0')
+ {
+ convert_target = mark_up(sel->selbuf, strlen(sel->selbuf), NULL);
+ convert_edje = EINA_TRUE;
+ }
+ }
+
+ if (data_ret && ((sel->format & ELM_SEL_FORMAT_MARKUP) || convert_edje))
{
Eina_List *nodeList = NULL;
Eina_List *trail;
PTagNode nodeData;
- nodeData = _get_start_node(sel->selbuf);
+ nodeData = _get_start_node(convert_target);
while (nodeData)
{
@@ -1585,7 +2012,10 @@ html_converter(char *target __UNUSED__, void *data, int size __UNUSED__, void **
if (html)
*data_ret = html;
else
- *data_ret = strdup(sel->selbuf);
+ if (sel->selbuf)
+ *data_ret = strdup(sel->selbuf);
+ else
+ *data_ret = strdup("");
}
if (size_ret)
@@ -1593,8 +2023,13 @@ html_converter(char *target __UNUSED__, void *data, int size __UNUSED__, void **
if (html)
*size_ret = strlen(html);
else
- *size_ret = strlen(sel->selbuf);
+ if (sel->selbuf)
+ *size_ret = strlen(sel->selbuf);
+ else
+ *size_ret = 0;
}
+ if (convert_target != sel->selbuf)
+ free(convert_target);
return EINA_TRUE;
}
@@ -1717,6 +2152,7 @@ pasteimage_append(Paste_Image *pi, Evas_Object *entry)
if (!pi) return EINA_FALSE;
if (!entry) return EINA_FALSE;
+ if (elm_entry_cnp_textonly_get(entry)) return EINA_FALSE;
pasteimage_provider_set(entry);
@@ -1805,6 +2241,7 @@ mark_up(const char *start, int inlen, int *lenp)
{
if (*p == escapes[i].value)
{
+ if (!iscntrl(escapes[i].value)) l++;
l += strlen(escapes[i].escape);
break;
}
@@ -1815,12 +2252,13 @@ mark_up(const char *start, int inlen, int *lenp)
q = ret = malloc(l + 1);
/* Second pass: Change characters */
- for (p = start; *p; )
+ for (p = start; ((!endp) || (p < endp)) && (*p); )
{
for (i = 0; i < N_ESCAPES; i++)
{
if (*p == escapes[i].value)
{
+ if (!iscntrl(escapes[i].value)) *q++ = '&';
strcpy(q, escapes[i].escape);
q += strlen(escapes[i].escape);
p ++;
@@ -1861,6 +2299,7 @@ _dnd_enter(void *data __UNUSED__, int etype __UNUSED__, void *ev)
/* Request it, so we know what it is */
cnp_debug("Sending uri request\n");
savedtypes.textreq = 1;
+ if (savedtypes.pi) pasteimage_free(savedtypes.pi);
savedtypes.pi = NULL; /* FIXME: Free? */
ecore_x_selection_xdnd_request(enter->win, text_uri);
}
@@ -1969,6 +2408,9 @@ found:
cnp_debug("Insert %s\n", (char *)ddata.data);
dropable->dropcb(dropable->cbdata, dropable->obj, &ddata);
ecore_x_dnd_send_finished();
+
+ if (savedtypes.pi) pasteimage_free(savedtypes.pi);
+ savedtypes.pi = NULL;
return EINA_TRUE;
}
else if (dropable->types & ELM_SEL_FORMAT_IMAGE)
@@ -1979,7 +2421,7 @@ found:
dropable->dropcb(dropable->cbdata, dropable->obj, &ddata);
ecore_x_dnd_send_finished();
- pasteimage_free(savedtypes.pi);
+ if (savedtypes.pi) pasteimage_free(savedtypes.pi);
savedtypes.pi = NULL;
return EINA_TRUE;
@@ -2270,7 +2712,6 @@ elm_cnp_tempfile_create(int size)
tmppath = getenv("TMP");
if (!tmppath) tmppath = P_tmpdir;
- if (!tmppath) tmppath = "/tmp";
len = snprintf(NULL, 0, "%s/%sXXXXXX", tmppath, "elmcnpitem-");
if (len < 0)
{
@@ -2327,6 +2768,8 @@ elm_cnp_tempfile_create(int size)
return info;
}
+ eina_mmap_safety_enabled_set(EINA_TRUE);
+
info->map = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, info->fd, 0);
if (info->map == MAP_FAILED)
{