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 Eina_Bool pasteimage_append(char *file, Evas_Object *entry);
+static void entry_insert_filter(Evas_Object* entry, char* str);
static Cnp_Atom atoms[CNP_N_ATOMS] = {
[CNP_ATOM_TARGETS] = {
ELM_SEL_FORMAT_MARKUP,
general_converter,
NULL,
- NULL,
+ notify_handler_edje,
0
},
[CNP_ATOM_text_uri] = {
"text/uri",
- ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE, /* Either images or entries */
+ ELM_SEL_FORMAT_IMAGE, /* Either images or entries */
general_converter,
NULL,
notify_handler_uri,
},
};
-static Cnp_Selection selections[ELM_SEL_TYPE_MAX] = {
+static Cnp_Selection selections[ELM_SEL_TYPE_CLIPBOARD + 1] = {
ARRAYINIT(ELM_SEL_TYPE_PRIMARY) {
.debug = "Primary",
.ecore_sel = ECORE_X_SELECTION_PRIMARY,
.clear = ecore_x_selection_secondary_clear,
.request = ecore_x_selection_secondary_request,
},
+ ARRAYINIT(ELM_SEL_TYPE_XDND) {
+ .debug = "XDnD",
+ .ecore_sel = ECORE_X_SELECTION_XDND,
+ .request = ecore_x_selection_xdnd_request,
+ },
ARRAYINIT(ELM_SEL_TYPE_CLIPBOARD) {
.debug = "Clipboard",
.ecore_sel = ECORE_X_SELECTION_CLIPBOARD,
.clear = ecore_x_selection_clipboard_clear,
.request = ecore_x_selection_clipboard_request,
},
- ARRAYINIT(ELM_SEL_TYPE_XDND) {
- .debug = "XDnD",
- .ecore_sel = ECORE_X_SELECTION_XDND,
- .request = ecore_x_selection_xdnd_request,
- },
};
/* Data for DND in progress */
}
EAPI Eina_Bool
-elm_cnp_selection_set(Elm_Sel_Type selection, Evas_Object *obj,
+elm_cnp_selection_set(Evas_Object *obj, Elm_Sel_Type selection,
Elm_Sel_Format format, const void *selbuf, size_t buflen)
{
#ifdef HAVE_ELEMENTARY_X
if (top) xwin = elm_win_xwindow_get(top);
else xwin = elm_win_xwindow_get(obj);
- if ((!xwin) || (selection >= ELM_SEL_TYPE_MAX))
+ if ((!xwin) || (selection > ELM_SEL_TYPE_CLIPBOARD))
return EINA_FALSE;
if (!_elm_cnp_init_count) _elm_cnp_init();
if ((!selbuf) && (format != ELM_SEL_FORMAT_IMAGE))
- return elm_cnp_selection_clear(selection, obj);
+ return elm_object_cnp_selection_clear(obj, selection);
sel = selections + selection;
}
EAPI Eina_Bool
-elm_cnp_selection_clear(Elm_Sel_Type selection, Evas_Object *obj)
+elm_object_cnp_selection_clear(Evas_Object *obj, Elm_Sel_Type selection)
{
#ifdef HAVE_ELEMENTARY_X
Cnp_Selection *sel;
- if ((unsigned int)selection >= (unsigned int)ELM_SEL_TYPE_MAX)
+ if ((unsigned int)selection > (unsigned int)ELM_SEL_TYPE_CLIPBOARD)
return EINA_FALSE;
if (!_elm_cnp_init_count) _elm_cnp_init();
}
EAPI Eina_Bool
-elm_cnp_selection_get(Elm_Sel_Type selection, Elm_Sel_Format format,
- Evas_Object *obj, Elm_Drop_Cb datacb, void *udata)
+elm_cnp_selection_get(Evas_Object *obj, Elm_Sel_Type selection,
+ Elm_Sel_Format format, Elm_Drop_Cb datacb, void *udata)
{
#ifdef HAVE_ELEMENTARY_X
Evas_Object *top;
Cnp_Selection *sel;
- if (selection >= ELM_SEL_TYPE_MAX)
+ if (selection > ELM_SEL_TYPE_CLIPBOARD)
return EINA_FALSE;
if (!_elm_cnp_init_count) _elm_cnp_init();
Cnp_Selection *sel;
int i;
- for (i = 0; i < ELM_SEL_TYPE_MAX; i++)
+ for (i = 0; i <= ELM_SEL_TYPE_CLIPBOARD; i++)
{
if (selections[i].ecore_sel == ev->selection) break;
}
cnp_debug("selection %d clear\n", i);
/* Not me... Don't care */
- if (i == ELM_SEL_TYPE_MAX) return ECORE_CALLBACK_PASS_ON;
+ if (i > ELM_SEL_TYPE_CLIPBOARD) return ECORE_CALLBACK_PASS_ON;
sel = selections + i;
sel->active = EINA_FALSE;
cnp_debug("selection notify callback: %d\n",ev->selection);
switch (ev->selection)
{
- case ECORE_X_SELECTION_CLIPBOARD:
- sel = selections + ELM_SEL_TYPE_CLIPBOARD;
- break;
case ECORE_X_SELECTION_PRIMARY:
sel = selections + ELM_SEL_TYPE_PRIMARY;
break;
case ECORE_X_SELECTION_XDND:
sel = selections + ELM_SEL_TYPE_XDND;
break;
+ case ECORE_X_SELECTION_CLIPBOARD:
+ sel = selections + ELM_SEL_TYPE_CLIPBOARD;
+ break;
default:
return ECORE_CALLBACK_PASS_ON;
}
Cnp_Selection *sel = selections + *((int *)data);
if (sel->active &&
(sel->format >= ELM_SEL_FORMAT_TARGETS) &&
- (sel->format < ELM_SEL_FORMAT_MAX))
+ (sel->format <= ELM_SEL_FORMAT_HTML))
return sel->format;
}
return ELM_SEL_FORMAT_NONE;
if (!data_ret) return EINA_FALSE;
+ if (!data || (*((unsigned int *)data) > ELM_SEL_TYPE_CLIPBOARD))
+ return EINA_FALSE;
+
if (_get_selection_type(data, size) == ELM_SEL_FORMAT_NONE)
{
/* TODO : fallback into precise type */
cnp_debug("Vcard send called\n");
+ if (!data || (*((unsigned int *)data) > ELM_SEL_TYPE_CLIPBOARD))
+ return EINA_FALSE;
sel = selections + *((int *)data);
if (data_ret) *data_ret = strdup(sel->selbuf);
return EINA_TRUE;
}
+#if 0
static Eina_Bool
is_uri_type_data(Cnp_Selection *sel __UNUSED__, Ecore_X_Event_Selection_Notify *notify)
{
return EINA_TRUE;
}
-
+#endif
/*
* Callback to handle a targets response on a selection request:
* So pick the format we'd like; and then request it.
{
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;
+ if (!is_uri_type_data(sel, notify)) continue;
}
+#endif
cnp_debug("Atom %s matches\n",atoms[j].name);
goto done;
}
return 0;
}
+static void
+entry_insert_filter(Evas_Object* entry, char* str)
+{
+ if (!entry || !str)
+ return;
+
+ char *insertStr = str;
+
+ // if entry has single line set then remove <br/> & <ps/> 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, "<br/>", "");
+ eina_strbuf_replace_all(buf, "<ps/>", "");
+ insertStr = eina_strbuf_string_steal(buf);
+ eina_strbuf_free(buf);
+ }
+ }
+ cnp_debug("remove break tag: %s\n", insertStr);
+
+ _elm_entry_entry_paste(entry, insertStr);
+
+ if (insertStr != str)
+ free(insertStr);
+}
static int
notify_handler_text(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
{
Ecore_X_Selection_Data *data;
char *str;
+ char *mkupstr;
data = notify->data;
+ str = malloc(sizeof(char) * (data->length + 1));
+ if (str)
+ {
+ strncpy(str, (char *)data->data, data->length);
+ str[data->length] = '\0';
+ }
+ else
+ str = data->data;
if (sel->datacb)
{
ddata.x = ddata.y = 0;
ddata.format = ELM_SEL_FORMAT_TEXT;
- ddata.data = data->data;
+ ddata.data = str;
ddata.len = data->length;
sel->datacb(sel->udata, sel->widget, &ddata);
- return 0;
}
+ else
+ {
+ cnp_debug("Notify handler text %d %d %p\n", data->format, data->length, data->data);
+ mkupstr = _elm_util_text_to_mkup((const char *) str);
+ if (mkupstr)
+ {
+ entry_insert_filter(sel->requestwidget, mkupstr);
+ free(mkupstr);
+ }
+ else
+ entry_insert_filter(sel->requestwidget, str);
- cnp_debug("Notify handler text %d %d %p\n", data->format,data->length, data->data);
- str = _elm_util_text_to_mkup((const char *) data->data);
- cnp_debug("String is %s (from %s)\n", str, data->data);
- _elm_entry_entry_paste(sel->requestwidget, str);
- free(str);
+ cnp_debug("String is %s (from %s)\n", str, data->data);
+ //_elm_entry_entry_paste(sel->requestwidget, str);
+ }
+
+ if (str != data->data)
+ free(str);
return 0;
}
return 0;
}
cnp_debug("Got %s\n",p);
+ if (sel->datacb)
+ {
+ Elm_Selection_Data ddata;
+
+ ddata.x = ddata.y = 0;
+ ddata.format = ELM_SEL_FORMAT_IMAGE;
+ 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 */
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_paste(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.
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_paste(sel->requestwidget, stripstr);
- char *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_paste(sel->requestwidget, stripstr);
free(stripstr);
return 0;
}
Cnp_Selection *sel;
cnp_debug("text converter\n");
+ if (!data || (*((unsigned int *)data) > ELM_SEL_TYPE_CLIPBOARD))
+ return EINA_FALSE;
if (_get_selection_type(data, size) == ELM_SEL_FORMAT_NONE)
{
if (data_ret)
sel = selections + *((int *)data);
if (!sel->active) return EINA_TRUE;
- if ((sel->format & ELM_SEL_FORMAT_MARKUP) ||
- (sel->format & ELM_SEL_FORMAT_HTML))
+ if (sel->format & ELM_SEL_FORMAT_MARKUP)
+ *data_ret = _elm_util_mkup_to_text(sel->selbuf);
+ else if (sel->format & ELM_SEL_FORMAT_HTML)
{
- *data_ret = _elm_util_mkup_to_text(sel->selbuf);
- if (size_ret) *size_ret = strlen(*data_ret);
+ char *text = NULL;
+ Eina_Strbuf *buf = eina_strbuf_new();
+ if (buf)
+ {
+ eina_strbuf_append(buf, sel->selbuf);
+ eina_strbuf_replace_all(buf, " ", " ");
+ text = eina_strbuf_string_steal(buf);
+ eina_strbuf_free(buf);
+ *data_ret = _elm_util_mkup_to_text(text);
+ free(text);
+ }
+ else
+ *data_ret = _elm_util_mkup_to_text(sel->selbuf);
}
else if (sel->format & ELM_SEL_FORMAT_TEXT)
{
}
else
{
- Cnp_Selection *sel = selections + *((int *)data);
+ Cnp_Selection *sel;
+ if (!data || (*((unsigned int *)data) > ELM_SEL_TYPE_CLIPBOARD))
+ return EINA_FALSE;
+
+ sel = selections + *((int *)data);
if (data_ret) *data_ret = strdup(sel->selbuf);
if (size_ret) *size_ret = strlen(sel->selbuf);
}
ecore_x_dnd_callback_pos_update_set(_drag_move, NULL);
ecore_x_dnd_begin(xwin, (unsigned char *)&xdnd, sizeof(Elm_Sel_Type));
evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP,
- _drag_mouse_up, (uintptr_t *)xwin);
+ _drag_mouse_up, (void *)(long)xwin);
handler_status = ecore_event_handler_add(ECORE_X_EVENT_XDND_STATUS,
_dnd_status, NULL);