2 # include "elementary_config.h"
4 #include <Elementary.h>
9 #ifdef HAVE_ELEMENTARY_X
11 #define ARRAYINIT(foo) [foo] =
16 # define cnp_debug(x...) fprintf(stderr, __FILE__": " x)
18 # define cnp_debug(x...)
21 #define PROVIDER_SET "__elm_cnp_provider_set"
23 typedef struct _Paste_Image Paste_Image;
24 typedef struct _Cnp_Selection Cnp_Selection;
25 typedef struct _Escape Escape;
26 typedef struct _Tmp_Info Tmp_Info;
27 typedef struct _Cnp_Atom Cnp_Atom;
28 typedef struct _Saved_Type Saved_Type;
29 typedef struct _Dropable Dropable;
31 typedef Eina_Bool (*Converter_Fn_Cb) (char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
32 typedef int (*Response_Handler_Cb) (Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *);
33 typedef int (*Notify_Handler_Cb) (Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *);
39 CNP_ATOM_LISTING_ATOMS = CNP_ATOM_ATOM,
41 CNP_ATOM_text_urilist,
42 CNP_ATOM_text_x_vcard,
53 CNP_ATOM_text_html_utf8,
58 CNP_ATOM_text_plain_utf8,
77 Evas_Object *requestwidget;
79 Elm_Sel_Format requestformat;
81 Eina_Bool (*set) (Ecore_X_Window, const void *data, int size);
82 Eina_Bool (*clear) (void);
83 void (*request) (Ecore_X_Window, const char *target);
85 Elm_Sel_Format format;
86 Ecore_X_Selection ecore_sel;
108 Elm_Sel_Format formats;
109 /* Called by ecore to do conversion */
110 Converter_Fn_Cb converter;
111 Response_Handler_Cb response;
112 Notify_Handler_Cb notify;
123 Eina_Bool textreq: 1;
129 /* FIXME: Cache window */
130 Elm_Sel_Format types;
135 static Tmp_Info *elm_cnp_tempfile_create(int size);
136 static int tmpinfo_free(Tmp_Info *tmp);
138 static Eina_Bool _elm_cnp_init(void);
139 static Eina_Bool selection_clear(void *udata __UNUSED__, int type, void *event);
140 static Eina_Bool selection_notify(void *udata __UNUSED__, int type, void *event);
141 static char *remove_tags(const char *p, int *len);
142 static char *mark_up(const char *start, int inlen, int *lenp);
144 static Evas_Object *image_provider(void *images, Evas_Object *entry, const char *item);
145 static void entry_deleted(void *images, Evas *e, Evas_Object *entry, void *unused);
147 static Eina_Bool targets_converter(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
148 static Eina_Bool text_converter(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
149 static Eina_Bool general_converter(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
150 static Eina_Bool image_converter(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
151 static Eina_Bool vcard_send(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
153 static int response_handler_targets(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *);
155 static int notify_handler_targets(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
156 static int notify_handler_text(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
157 static int notify_handler_image(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
158 static int notify_handler_uri(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
159 static int notify_handler_edje(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
160 static int notify_handler_html(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify);
161 static int vcard_receive(Cnp_Selection *sed, Ecore_X_Event_Selection_Notify *notify);
163 static Paste_Image *pasteimage_alloc(const char *file, int pathlen);
164 static Eina_Bool pasteimage_append(Paste_Image *pi, Evas_Object *entry);
165 static void pasteimage_free(Paste_Image *pi);
166 static void entry_insert_filter(Evas_Object* entry, char* str);
168 #define _PARAGRAPH_SEPARATOR "\xE2\x80\xA9"
170 /* Optimisation: Turn this into a 256 byte table:
171 * then can lookup in one index, not N checks */
172 static const Escape escapes[] = {
173 { "<ps>", _PARAGRAPH_SEPARATOR },
182 #define N_ESCAPES ((int)(sizeof(escapes) / sizeof(escapes[0])))
184 static Cnp_Atom atoms[CNP_N_ATOMS] = {
185 [CNP_ATOM_TARGETS] = {
187 (Elm_Sel_Format) -1, // everything
189 response_handler_targets,
190 notify_handler_targets,
195 (Elm_Sel_Format) -1, // everything
197 response_handler_targets,
198 notify_handler_targets,
202 "application/x-elementary-markup",
203 ELM_SEL_FORMAT_MARKUP,
209 [CNP_ATOM_text_uri] = {
211 ELM_SEL_FORMAT_IMAGE, /* Either images or entries */
217 [CNP_ATOM_text_urilist] = {
219 ELM_SEL_FORMAT_IMAGE,
225 [CNP_ATOM_text_x_vcard] = {
227 ELM_SEL_FORMAT_VCARD,
231 [CNP_ATOM_image_png] = {
233 ELM_SEL_FORMAT_IMAGE,
236 notify_handler_image,
239 [CNP_ATOM_image_jpeg] = {
241 ELM_SEL_FORMAT_IMAGE,
244 notify_handler_image,/* Raw image data is the same */
247 [CNP_ATOM_image_bmp] = {
249 ELM_SEL_FORMAT_IMAGE,
252 notify_handler_image,/* Raw image data is the same */
255 [CNP_ATOM_image_gif] = {
257 ELM_SEL_FORMAT_IMAGE,
260 notify_handler_image,/* Raw image data is the same */
263 [CNP_ATOM_image_tiff] = {
265 ELM_SEL_FORMAT_IMAGE,
268 notify_handler_image,/* Raw image data is the same */
271 [CNP_ATOM_image_svg] = {
273 ELM_SEL_FORMAT_IMAGE,
276 notify_handler_image,/* Raw image data is the same */
279 [CNP_ATOM_image_xpm] = {
281 ELM_SEL_FORMAT_IMAGE,
284 notify_handler_image,/* Raw image data is the same */
287 [CNP_ATOM_image_tga] = {
289 ELM_SEL_FORMAT_IMAGE,
292 notify_handler_image,/* Raw image data is the same */
295 [CNP_ATOM_image_ppm] = {
296 "image/x-portable-pixmap",
297 ELM_SEL_FORMAT_IMAGE,
300 notify_handler_image,/* Raw image data is the same */
303 [CNP_ATOM_text_html_utf8] = {
304 "text/html;charset=utf-8",
311 [CNP_ATOM_text_html] = {
316 notify_handler_html, /* No encoding: Webkit only */
319 [CNP_ATOM_UTF8STRING] = {
321 ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
327 [CNP_ATOM_STRING] = {
329 ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
337 ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
343 [CNP_ATOM_text_plain_utf8] = {
344 "text/plain;charset=utf-8",
345 ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
351 [CNP_ATOM_text_plain] = {
353 ELM_SEL_FORMAT_TEXT | ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_HTML,
361 static Cnp_Selection selections[ELM_SEL_MAX] = {
362 ARRAYINIT(ELM_SEL_PRIMARY) {
364 .ecore_sel = ECORE_X_SELECTION_PRIMARY,
365 .set = ecore_x_selection_primary_set,
366 .clear = ecore_x_selection_primary_clear,
367 .request = ecore_x_selection_primary_request,
369 ARRAYINIT(ELM_SEL_SECONDARY) {
370 .debug = "Secondary",
371 .ecore_sel = ECORE_X_SELECTION_SECONDARY,
372 .set = ecore_x_selection_secondary_set,
373 .clear = ecore_x_selection_secondary_clear,
374 .request = ecore_x_selection_secondary_request,
376 ARRAYINIT(ELM_SEL_CLIPBOARD) {
377 .debug = "Clipboard",
378 .ecore_sel = ECORE_X_SELECTION_CLIPBOARD,
379 .set = ecore_x_selection_clipboard_set,
380 .clear = ecore_x_selection_clipboard_clear,
381 .request = ecore_x_selection_clipboard_request,
383 ARRAYINIT(ELM_SEL_XDND) {
385 .ecore_sel = ECORE_X_SELECTION_XDND,
386 .request = ecore_x_selection_xdnd_request,
390 /* Data for DND in progress */
391 static Saved_Type savedtypes = { NULL, NULL, 0, 0, 0, EINA_FALSE };
393 static void (*dragdonecb) (void *data, Evas_Object *obj) = NULL;
394 static void *dragdonedata = NULL;
396 static int _elm_cnp_init_count = 0;
398 static Eina_List *pastedimages = NULL;
401 * Drag & Drop functions
404 /* FIXME: Way too many globals */
405 static Eina_List *drops = NULL;
406 static Evas_Object *dragwin = NULL;
407 static int _dragx = 0, _dragy = 0;
408 static Ecore_Event_Handler *handler_pos = NULL;
409 static Ecore_Event_Handler *handler_drop = NULL;
410 static Ecore_Event_Handler *handler_enter = NULL;
411 static Ecore_Event_Handler *handler_status = NULL;
415 /* Stringshared, so I can just compare pointers later */
416 static const char *text_uri;
419 elm_selection_selection_has_owner(void)
421 #ifdef HAVE_ELEMENTARY_X
422 return !!ecore_x_selection_owner_get(ECORE_X_ATOM_SELECTION_CLIPBOARD);
429 elm_selection_set(Elm_Sel_Type selection, Evas_Object *widget, Elm_Sel_Format format, const char *selbuf)
431 #ifdef HAVE_ELEMENTARY_X
432 Evas_Object *top = elm_widget_top_get(widget);
436 if (top) xwin = elm_win_xwindow_get(top);
437 else xwin = elm_win_xwindow_get(widget);
438 if (!xwin) return EINA_FALSE;
439 if ((unsigned int)selection >= (unsigned int)ELM_SEL_MAX) return EINA_FALSE;
440 if (!_elm_cnp_init_count) _elm_cnp_init();
441 if ((!selbuf) && (format != ELM_SEL_FORMAT_IMAGE))
442 return elm_selection_clear(selection, widget);
444 sel = selections + selection;
447 sel->widget = widget;
449 sel->set(xwin, &selection, sizeof(Elm_Sel_Type));
450 sel->format = format;
451 sel->selbuf = selbuf ? strdup(selbuf) : NULL;
460 elm_selection_clear(Elm_Sel_Type selection, Evas_Object *widget)
462 #ifdef HAVE_ELEMENTARY_X
465 if ((unsigned int)selection >= (unsigned int)ELM_SEL_MAX) return EINA_FALSE;
466 if (!_elm_cnp_init_count) _elm_cnp_init();
468 sel = selections + selection;
470 /* No longer this selection: Consider it gone! */
471 if ((!sel->active) || (sel->widget != widget)) return EINA_TRUE;
484 elm_selection_get(Elm_Sel_Type selection, Elm_Sel_Format format,
485 Evas_Object *widget, Elm_Drop_Cb datacb, void *udata)
487 #ifdef HAVE_ELEMENTARY_X
491 if ((unsigned int)selection >= (unsigned int)ELM_SEL_MAX) return EINA_FALSE;
492 if (!_elm_cnp_init_count) _elm_cnp_init();
494 sel = selections + selection;
495 top = elm_widget_top_get(widget);
496 if (!top) return EINA_FALSE;
498 sel->requestformat = format;
499 sel->requestwidget = widget;
500 sel->request(elm_win_xwindow_get(top), ECORE_X_SELECTION_TARGET_TARGETS);
501 sel->datacb = datacb;
510 #ifdef HAVE_ELEMENTARY_X
517 if (_elm_cnp_init_count++) return EINA_TRUE;
518 for (i = 0; i < CNP_N_ATOMS; i++)
520 atoms[i].atom = ecore_x_atom_get(atoms[i].name);
521 ecore_x_selection_converter_atom_add(atoms[i].atom,
525 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR, selection_clear, NULL);
526 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY, selection_notify, NULL);
528 text_uri = eina_stringshare_add("text/uri-list");
533 selection_clear(void *udata __UNUSED__, int type __UNUSED__, void *event)
535 Ecore_X_Event_Selection_Clear *ev = event;
539 for (i = 0; i < ELM_SEL_MAX; i++)
541 if (selections[i].ecore_sel == ev->selection) break;
543 cnp_debug("selection %d clear\n", i);
544 /* Not me... Don't care */
545 if (i == ELM_SEL_MAX) return ECORE_CALLBACK_PASS_ON;
547 sel = selections + i;
552 return ECORE_CALLBACK_PASS_ON;
557 * Response to a selection notify:
558 * - So we have asked for the selection list.
559 * - If it's the targets list, parse it, and fire of what we want,
560 * else it's the data we want.
563 selection_notify(void *udata __UNUSED__, int type __UNUSED__, void *event)
565 Ecore_X_Event_Selection_Notify *ev = event;
569 cnp_debug("selection notify callback: %d\n",ev->selection);
570 switch (ev->selection)
572 case ECORE_X_SELECTION_CLIPBOARD:
573 sel = selections + ELM_SEL_CLIPBOARD;
575 case ECORE_X_SELECTION_PRIMARY:
576 sel = selections + ELM_SEL_PRIMARY;
578 case ECORE_X_SELECTION_SECONDARY:
579 sel = selections + ELM_SEL_SECONDARY;
581 case ECORE_X_SELECTION_XDND:
582 sel = selections + ELM_SEL_XDND;
585 return ECORE_CALLBACK_PASS_ON;
587 cnp_debug("Target is %s\n", ev->target);
589 for (i = 0; i < CNP_N_ATOMS; i++)
591 if (!strcmp(ev->target, atoms[i].name))
595 cnp_debug("Found something: %s\n", atoms[i].name);
596 atoms[i].notify(sel, ev);
600 cnp_debug("Ignored: No handler!\n");
605 return ECORE_CALLBACK_PASS_ON;
611 targets_converter(char *target __UNUSED__, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize)
617 if (!data_ret) return EINA_FALSE;
619 if (size != sizeof(int))
623 *data_ret = malloc(size * sizeof(char) + 1);
624 memcpy(*data_ret, data, size);
625 ((char**)(data_ret))[0][size] = 0;
627 if (size_ret) *size_ret = size;
631 if (!data || (*((unsigned int *)data) >= ELM_SEL_MAX))
633 sel = selections + *((int *)data);
635 for (i = 0, count = 0; i < CNP_N_ATOMS ; i++)
637 if (sel->format & atoms[i].formats) count++;
640 aret = malloc(sizeof(Ecore_X_Atom) * count);
641 for (i = 0, count = 0; i < CNP_N_ATOMS; i++)
643 if (sel->format & atoms[i].formats) aret[count ++] = atoms[i].atom;
647 if (typesize) *typesize = 32 /* urk */;
648 if (ttype) *ttype = ECORE_X_ATOM_ATOM;
649 if (size_ret) *size_ret = count;
655 image_converter(char *target __UNUSED__, void *data __UNUSED__, int size __UNUSED__, void **data_ret __UNUSED__, int *size_ret __UNUSED__, Ecore_X_Atom *ttype __UNUSED__, int *typesize __UNUSED__)
657 cnp_debug("Image converter called\n");
662 vcard_send(char *target __UNUSED__, void *data __UNUSED__, int size __UNUSED__, void **data_ret, int *size_ret, Ecore_X_Atom *ttype __UNUSED__, int *typesize __UNUSED__)
666 cnp_debug("Vcard send called\n");
668 if (!data || (*((unsigned int *)data) >= ELM_SEL_MAX))
670 sel = selections + *((int *)data);
672 if (data_ret) *data_ret = strdup(sel->selbuf);
673 if (size_ret) *size_ret = strlen(sel->selbuf);
680 is_uri_type_data(Cnp_Selection *sel __UNUSED__, Ecore_X_Event_Selection_Notify *notify)
682 Ecore_X_Selection_Data *data;
686 cnp_debug("data->format is %d %p %p\n", data->format, notify, data);
687 if (data->content == ECORE_X_SELECTION_CONTENT_FILES) return EINA_TRUE;
688 else p = (char *)data->data;
690 if (!p) return EINA_TRUE;
691 cnp_debug("Got %s\n", p);
692 if (strncmp(p, "file://", 7))
694 if (*p != '/') return EINA_FALSE;
701 * Callback to handle a targets response on a selection request:
702 * So pick the format we'd like; and then request it.
705 notify_handler_targets(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
707 Ecore_X_Selection_Data_Targets *targets;
708 Ecore_X_Atom *atomlist;
712 targets = notify->data;
713 atomlist = (Ecore_X_Atom *)(targets->data.data);
715 for (j = (CNP_ATOM_LISTING_ATOMS+1); j < CNP_N_ATOMS; j++)
717 cnp_debug("\t%s %d\n", atoms[j].name, atoms[j].atom);
718 if (!(atoms[j].formats & sel->requestformat)) continue;
719 for (i = 0; i < targets->data.length; i++)
721 if ((atoms[j].atom == atomlist[i]) && (atoms[j].notify))
724 if ((j == CNP_ATOM_text_uri) ||
725 (j == CNP_ATOM_text_urilist))
727 if(!is_uri_type_data(sel, notify)) continue;
730 cnp_debug("Atom %s matches\n",atoms[j].name);
736 cnp_debug("Couldn't find anything that matches\n");
737 return ECORE_CALLBACK_PASS_ON;
740 top = elm_widget_top_get(sel->requestwidget);
741 if (!top) top = sel->requestwidget;
742 cnp_debug("Sending request for %s\n", atoms[j].name);
743 sel->request(elm_win_xwindow_get(top), atoms[j].name);
745 return ECORE_CALLBACK_PASS_ON;
749 response_handler_targets(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
751 Ecore_X_Selection_Data_Targets *targets;
752 Ecore_X_Atom *atomlist;
756 targets = notify->data;
757 atomlist = (Ecore_X_Atom *)(targets->data.data);
759 /* Start from 1: Skip targets */
760 for (j = 1 ; j < CNP_N_ATOMS ; j ++)
762 if (!(atoms[j].formats & sel->requestformat)) continue;
763 for (i = 0 ; i < targets->data.length ; i ++)
765 if ((atoms[j].atom == atomlist[i]) && (atoms[j].response))
767 /* Found a match: Use it */
773 if (j == CNP_N_ATOMS)
775 cnp_debug("No matching type found\n");
779 top = elm_widget_top_get(sel->requestwidget);
782 sel->request(elm_win_xwindow_get(top), atoms[j].name);
787 entry_insert_filter(Evas_Object* entry, char* str)
792 char *insertStr = str;
793 // if entry has text only set then remove item tags
794 if (elm_entry_cnp_mode_get(entry) != ELM_CNP_MODE_MARKUP)
798 char *startTag = NULL;
801 startTag = strstr(insertStr, "<item");
803 startTag = strstr(insertStr, "</item");
805 endTag = strstr(startTag, ">");
808 if (!endTag || startTag > endTag)
810 cnp_debug("Broken tag: %s\n", str);
814 size_t sindex = startTag - insertStr;
815 size_t eindex = endTag - insertStr + 1;
817 Eina_Strbuf *buf = eina_strbuf_new();
820 eina_strbuf_append(buf, insertStr);
821 eina_strbuf_remove(buf, sindex, eindex);
822 insertStr = eina_strbuf_string_steal(buf);
823 eina_strbuf_free(buf);
827 cnp_debug("remove item tag: %s\n", insertStr);
829 // if entry has single line set then remove <br> & <ps> tags
830 if (elm_entry_single_line_get(entry))
832 Eina_Strbuf *buf = eina_strbuf_new();
835 eina_strbuf_append(buf, insertStr);
836 eina_strbuf_replace_all(buf, "<br>", "");
837 eina_strbuf_replace_all(buf, "<ps>", "");
838 insertStr = eina_strbuf_string_steal(buf);
839 eina_strbuf_free(buf);
842 cnp_debug("remove break tag: %s\n", insertStr);
844 elm_entry_entry_insert(entry, insertStr);
846 //_elm_entry_entry_paste//
848 if (insertStr != str)
853 notify_handler_text(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
855 Ecore_X_Selection_Data *data;
862 Elm_Selection_Data ddata;
864 str = malloc(sizeof(char) * (data->length + 1));
865 strncpy(str, (char *)data->data, data->length);
866 str[data->length] = '\0';
868 ddata.x = ddata.y = 0;
869 ddata.format = ELM_SEL_FORMAT_TEXT;
871 ddata.len = data->length;
872 sel->datacb(sel->udata, sel->widget, &ddata);
877 cnp_debug("Notify handler text %d %d %p\n", data->format,data->length, data->data);
878 str = mark_up((char *)data->data, data->length, NULL);
879 cnp_debug("String is %s (from %s)\n", str, data->data);
880 entry_insert_filter(sel->requestwidget, str);
881 //elm_entry_entry_insert(sel->requestwidget, str);
888 * So someone is pasting an image into my entry or widget...
891 notify_handler_uri(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
893 Ecore_X_Selection_Data *data;
894 Ecore_X_Selection_Data_Files *files;
899 cnp_debug("data->format is %d %p %p\n", data->format, notify, data);
900 if (data->content == ECORE_X_SELECTION_CONTENT_FILES)
902 cnp_debug("got a files list\n");
903 files = notify->data;
904 if (files->num_files > 1)
906 /* Don't handle many items */
907 cnp_debug("more then one file: Bailing\n");
910 stripstr = p = strdup(files->files[0]);
914 stripstr = p = malloc(data->length * sizeof(char) + 1);
915 memcpy(stripstr, data->data, data->length);
916 stripstr[data->length] = 0;
921 cnp_debug("Couldn't find a file\n");
924 cnp_debug("Got %s\n",p);
927 Elm_Selection_Data ddata;
929 ddata.x = ddata.y = 0;
930 ddata.format = ELM_SEL_FORMAT_IMAGE;
932 ddata.len = data->length;
933 sel->datacb(sel->udata, sel->widget, &ddata);
937 if (strncmp(p, "file://", 7))
939 /* Try and continue if it looks sane */
948 p += strlen("file://");
951 if (savedtypes.pi) pasteimage_free(savedtypes.pi);
952 pi = pasteimage_alloc(p, strlen(p));
953 if (savedtypes.textreq)
955 savedtypes.textreq = 0;
960 pasteimage_append(pi, sel->requestwidget);
961 savedtypes.pi = NULL;
968 * Just receieved an vcard, either through cut and paste, or dnd.
971 vcard_receive(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
975 Ecore_X_Selection_Data *data;
978 cnp_debug("vcard receive\n");
980 if (sel == (selections + ELM_SEL_XDND))
982 Elm_Selection_Data ddata;
984 cnp_debug("drag & drop\n");
985 /* FIXME: this needs to be generic: Used for all receives */
986 EINA_LIST_FOREACH(drops, l, dropable)
988 if (dropable->obj == sel->requestwidget) break;
992 cnp_debug("Unable to find drop object");
993 ecore_x_dnd_send_finished();
996 dropable = eina_list_data_get(l);
997 ddata.x = savedtypes.x;
998 ddata.y = savedtypes.y;
999 ddata.format = ELM_SEL_FORMAT_VCARD;
1000 ddata.data = data->data;
1001 ddata.len = data->length;
1002 dropable->dropcb(dropable->cbdata, dropable->obj, &ddata);
1003 ecore_x_dnd_send_finished();
1005 else if (sel->datacb)
1007 Elm_Selection_Data ddata;
1008 ddata.x = ddata.y = 0;
1009 ddata.format = ELM_SEL_FORMAT_IMAGE;
1010 ddata.data = data->data;
1011 ddata.len = data->length;
1012 sel->datacb(sel->udata, sel->widget, &ddata);
1016 cnp_debug("Paste request\n");
1024 notify_handler_image(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
1026 Ecore_X_Selection_Data *data;
1030 cnp_debug("got a png (or a jpeg)!\n");
1031 data = notify->data;
1033 cnp_debug("Size if %d\n", data->length);
1037 Elm_Selection_Data ddata;
1039 ddata.x = ddata.y = 0;
1040 ddata.format = ELM_SEL_FORMAT_IMAGE;
1041 ddata.data = data->data;
1042 ddata.len = data->length;
1043 sel->datacb(sel->udata, sel->widget, &ddata);
1047 /* generate tmp name */
1048 tmp = elm_cnp_tempfile_create(data->length);
1049 memcpy(tmp->map, data->data, data->length);
1050 munmap(tmp->map,data->length);
1052 /* FIXME: Add to paste image data to clean up */
1053 pi = pasteimage_alloc(tmp->filename, strlen(tmp->filename));
1054 pasteimage_append(pi, sel->requestwidget);
1061 notify_handler_edje(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
1063 Ecore_X_Selection_Data *data;
1065 data = notify->data;
1067 char *stripstr = NULL;
1068 stripstr = malloc(sizeof(char) * (data->length + 1));
1069 strncpy(stripstr, (char *)data->data, data->length);
1070 stripstr[data->length] = '\0';
1074 Elm_Selection_Data ddata;
1075 ddata.x = ddata.y = 0;
1076 ddata.format = ELM_SEL_FORMAT_MARKUP;
1077 ddata.data = stripstr;
1078 ddata.len = data->length;
1079 sel->datacb(sel->udata, sel->widget, &ddata);
1082 entry_insert_filter(sel->requestwidget, stripstr);
1083 //elm_entry_entry_insert(sel->requestwidget, stripstr);
1085 cnp_debug("String is %s (%d bytes)\n", stripstr, data->length);
1091 * Warning: Generic text/html can';t handle it sanely.
1092 * Firefox sends ucs2 (i think).
1093 * chrome sends utf8... blerg
1096 notify_handler_html(Cnp_Selection *sel, Ecore_X_Event_Selection_Notify *notify)
1098 Ecore_X_Selection_Data *data;
1100 cnp_debug("Got some HTML: Checking encoding is useful\n");
1101 data = notify->data;
1103 char *stripstr = NULL;
1104 stripstr = malloc(sizeof(char) * (data->length + 1));
1105 strncpy(stripstr, (char *)data->data, data->length);
1106 stripstr[data->length] = '\0';
1110 Elm_Selection_Data ddata;
1111 ddata.x = ddata.y = 0;
1112 ddata.format = ELM_SEL_FORMAT_HTML;
1113 ddata.data = stripstr;
1114 ddata.len = data->length;
1115 sel->datacb(sel->udata, sel->widget, &ddata);
1118 entry_insert_filter(sel->requestwidget, stripstr);
1119 //elm_entry_entry_insert(sel->requestwidget, stripstr);
1121 cnp_debug("String is %s (%d bytes)\n", stripstr, data->length);
1128 text_converter(char *target __UNUSED__, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype __UNUSED__, int *typesize __UNUSED__)
1132 cnp_debug("text converter\n");
1133 if (size != sizeof(int))
1137 *data_ret = malloc(size * sizeof(char) + 1);
1138 memcpy(*data_ret, data, size);
1139 ((char**)(data_ret))[0][size] = 0;
1141 if (size_ret) *size_ret = size;
1144 if (!data || (*((unsigned int *)data) >= ELM_SEL_MAX))
1146 sel = selections + *((int *)data);
1147 if (!sel->active) return EINA_TRUE;
1149 if (sel->format & ELM_SEL_FORMAT_MARKUP)
1150 *data_ret = remove_tags(sel->selbuf, size_ret);
1151 else if (sel->format & ELM_SEL_FORMAT_HTML)
1154 Eina_Strbuf *buf = eina_strbuf_new();
1157 eina_strbuf_append(buf, sel->selbuf);
1158 eina_strbuf_replace_all(buf, " ", " ");
1159 text = eina_strbuf_string_steal(buf);
1160 eina_strbuf_free(buf);
1161 *data_ret = remove_tags(text, size_ret);
1165 *data_ret = remove_tags(sel->selbuf, size_ret);
1167 else if (sel->format & ELM_SEL_FORMAT_TEXT)
1169 *data_ret = strdup(sel->selbuf);
1170 *size_ret = strlen(sel->selbuf);
1172 else if (sel->format & ELM_SEL_FORMAT_IMAGE)
1174 cnp_debug("Image %s\n", evas_object_type_get(sel->widget));
1175 cnp_debug("Elm type: %s\n", elm_object_widget_type_get(sel->widget));
1176 evas_object_image_file_get(elm_photocam_internal_image_get(sel->widget), (const char **)data_ret, NULL);
1177 if (!*data_ret) *data_ret = strdup("No file");
1178 else *data_ret = strdup(*data_ret);
1179 *size_ret = strlen(*data_ret);
1185 general_converter(char *target __UNUSED__, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype __UNUSED__, int *typesize __UNUSED__)
1187 if (size == sizeof(int))
1190 if (!data || (*((unsigned int *)data) >= ELM_SEL_MAX))
1193 sel = selections + *((int *)data);
1194 if (data_ret) *data_ret = strdup(sel->selbuf);
1195 if (size_ret) *size_ret = strlen(sel->selbuf);
1201 *data_ret = malloc(size * sizeof(char) + 1);
1202 memcpy(*data_ret, data, size);
1203 ((char**)(data_ret))[0][size] = 0;
1205 if (size_ret) *size_ret = size;
1211 * Image paste provide
1214 /* FIXME: Should add provider for each pasted item: Use data to store it
1216 static Evas_Object *
1217 image_provider(void *images __UNUSED__, Evas_Object *entry, const char *item)
1222 cnp_debug("image provider for %s called\n", item);
1223 EINA_LIST_FOREACH(pastedimages, l, pi)
1225 cnp_debug("is it %s?\n",pi->tag);
1226 if (!strcmp(pi->tag, item))
1230 o = evas_object_image_filled_add(evas_object_evas_get(entry));
1231 /* FIXME: Handle eets */
1232 cnp_debug("file is %s (object is %p)\n", pi->file, o);
1233 evas_object_image_file_set(o, pi->file, NULL);
1234 evas_object_show(o);
1242 static Paste_Image *
1243 pasteimage_alloc(const char *file, int pathlen)
1247 char *buf, *filebuf;
1248 int prefixlen = strlen("file://");
1250 pi = calloc(1, sizeof(Paste_Image));
1251 if (!pi) return NULL;
1253 len = snprintf(NULL, 0, "pasteimage-%p", pi);
1261 snprintf(buf, len, "pasteimage-%p", pi);
1266 if (strstr(file,"file://")) file += prefixlen;
1267 filebuf = alloca(pathlen + 1);
1268 strncpy(filebuf, file, pathlen);
1269 filebuf[pathlen] = 0;
1270 pi->file = strdup(filebuf);
1277 pasteimage_free(Paste_Image *pi)
1280 if (pi->file) free((void*)pi->file);
1281 if (pi->tag) free((void*)pi->tag);
1286 pasteimage_provider_set(Evas_Object *entry)
1291 if (!entry) return EINA_FALSE;
1292 type = elm_widget_type_get(entry);
1293 cnp_debug("type is %s\n", type);
1294 if ((!type) || (strcmp(type, "entry"))) return EINA_FALSE;
1296 v = evas_object_data_get(entry, PROVIDER_SET);
1299 evas_object_data_set(entry, PROVIDER_SET, pasteimage_provider_set);
1300 elm_entry_item_provider_append(entry, image_provider, NULL);
1301 evas_object_event_callback_add(entry, EVAS_CALLBACK_FREE,
1302 entry_deleted, NULL);
1309 pasteimage_append(Paste_Image *pi, Evas_Object *entry)
1313 static const char *tagstring = "<item absize=240x180 href=file://%s></item>";
1315 if (!pi) return EINA_FALSE;
1316 if (!entry) return EINA_FALSE;
1317 if (elm_entry_cnp_mode_get(entry) != ELM_CNP_MODE_MARKUP) return EINA_FALSE;
1319 pasteimage_provider_set(entry);
1321 len = strlen(tagstring)+strlen(pi->file);
1323 pastedimages = eina_list_append(pastedimages, pi);
1324 entrytag = alloca(len + 1);
1325 snprintf(entrytag, len + 1, tagstring, pi->file);
1326 elm_entry_entry_insert(entry, entrytag);
1332 entry_deleted(void *images __UNUSED__, Evas *e __UNUSED__, Evas_Object *entry, void *unused __UNUSED__)
1337 EINA_LIST_FOREACH_SAFE(pastedimages, l, next, pi)
1339 if (pi->entry == entry)
1340 pastedimages = eina_list_remove_list(pastedimages, l);
1346 remove_tags(const char *p, int *len)
1350 if (!p) return NULL;
1352 q = malloc(strlen(p) + 1);
1353 if (!q) return NULL;
1358 Eina_Bool esc = EINA_TRUE;
1363 x = strchr(p + 3, '>');
1367 if (len) *len = strlen(ret);
1370 if (memcmp(p + 1, "br", 2) && memcmp(p + 1, "ps", 2))
1372 strncpy(q, p, x - p + 1);
1377 if (p[i] == '/') i--;
1388 strncpy(q, p, x - p + 1);
1396 strcpy(q, _PARAGRAPH_SEPARATOR);
1397 q += sizeof(_PARAGRAPH_SEPARATOR) - 1;
1402 for (i = 3 ; i < N_ESCAPES ; i++)
1404 if (strncmp(p, escapes[i].escape, strlen(escapes[i].escape)))
1406 p += strlen(escapes[i].escape);
1407 strcpy(q, escapes[i].value);
1408 q += strlen(escapes[i].value);
1411 if (i == N_ESCAPES) *q ++= '&';
1418 if (len) *len = q - ret;
1424 mark_up(const char *start, int inlen, int *lenp)
1429 const char *endp = NULL;
1431 if (!start) return NULL;
1432 if (inlen >= 0) endp = start + inlen;
1433 /* First pass: Count characters */
1434 for (l = 0, p = start; ((!endp) || (p < endp)) && (*p); p++)
1436 for (i = 0 ; i < N_ESCAPES ; i ++)
1438 if (*p == escapes[i].value[0])
1440 if (!strncmp(p, escapes[i].value, strlen(escapes[i].value)))
1441 l += strlen(escapes[i].escape);
1445 if (i == N_ESCAPES) l++;
1448 q = ret = malloc(l + 1);
1450 /* Second pass: Change characters */
1451 for (p = start; ((!endp) || (p < endp)) && (*p); )
1453 for (i = 0; i < N_ESCAPES; i++)
1455 if (*p == escapes[i].value[0])
1457 if (!strncmp(p, escapes[i].value, strlen(escapes[i].value)))
1459 strcpy(q, escapes[i].escape);
1460 q += strlen(escapes[i].escape);
1461 p += strlen(escapes[i].value);
1466 if (i == N_ESCAPES) *q++ = *p++;
1470 if (lenp) *lenp = l;
1476 _dnd_enter(void *data __UNUSED__, int etype __UNUSED__, void *ev)
1478 Ecore_X_Event_Xdnd_Enter *enter = ev;
1482 if ((!enter) || (!enter->num_types) || (!enter->types)) return EINA_TRUE;
1484 cnp_debug("Types\n");
1485 savedtypes.ntypes = enter->num_types;
1486 if (savedtypes.types) free(savedtypes.types);
1487 savedtypes.types = malloc(sizeof(char *) * enter->num_types);
1488 if (!savedtypes.types) return EINA_FALSE;
1490 for (i = 0; i < enter->num_types; i++)
1492 savedtypes.types[i] = eina_stringshare_add(enter->types[i]);
1493 cnp_debug("Type is %s %p %p\n", enter->types[i],
1494 savedtypes.types[i],text_uri);
1495 if (savedtypes.types[i] == text_uri)
1497 /* Request it, so we know what it is */
1498 cnp_debug("Sending uri request\n");
1499 savedtypes.textreq = 1;
1500 if (savedtypes.pi) pasteimage_free(savedtypes.pi);
1501 savedtypes.pi = NULL; /* FIXME: Free? */
1502 ecore_x_selection_xdnd_request(enter->win, text_uri);
1506 /* FIXME: Find an object and make it current */
1511 _dnd_drop(void *data __UNUSED__, int etype __UNUSED__, void *ev)
1513 struct _Ecore_X_Event_Xdnd_Drop *drop;
1517 Ecore_X_Window xwin;
1518 Elm_Selection_Data ddata;
1524 // check we still have something to drop
1525 if (!drops) return EINA_TRUE;
1527 /* Find any widget in our window; then work out geometry rel to our window */
1528 for (l = drops; l; l = l->next)
1531 xwin = (Ecore_X_Window)ecore_evas_window_get
1532 (ecore_evas_ecore_evas_get(evas_object_evas_get
1534 if (xwin == drop->win) break;
1536 /* didn't find a window */
1537 if (!l) return EINA_TRUE;
1539 /* Calculate real (widget relative) position */
1540 // - window position
1541 // - widget position
1542 ee = ecore_evas_ecore_evas_get(evas_object_evas_get(dropable->obj));
1543 ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
1544 savedtypes.x = drop->position.x - x;
1545 savedtypes.y = drop->position.y - y;
1547 cnp_debug("Drop position is %d,%d\n", savedtypes.x, savedtypes.y);
1549 for (; l; l = l->next)
1552 evas_object_geometry_get(dropable->obj, &x, &y, &w, &h);
1553 if ((savedtypes.x >= x) && (savedtypes.y >= y) &&
1554 (savedtypes.x < x + w) && (savedtypes.y < y + h))
1558 if (!l) return EINA_TRUE; /* didn't find one */
1560 evas_object_geometry_get(dropable->obj, &x, &y, NULL, NULL);
1564 /* Find our type from the previous list */
1565 for (i = 0; i < CNP_N_ATOMS; i++)
1567 for (j = 0; j < savedtypes.ntypes; j++)
1569 if (!strcmp(savedtypes.types[j], atoms[i].name)) goto found;
1573 cnp_debug("Didn't find a target\n");
1577 cnp_debug("Found a target we'd like: %s\n", atoms[i].name);
1578 cnp_debug("0x%x\n",xwin);
1580 if (i == CNP_ATOM_text_urilist)
1582 cnp_debug("We found a URI... (%scached) %s\n",
1583 savedtypes.pi ? "" : "not ",
1584 savedtypes.pi->file);
1588 static const char *tagstring = "<item absize=240x180 href="
1589 "file://%s></item>";
1590 ddata.x = savedtypes.x;
1591 ddata.y = savedtypes.y;
1593 /* If it's markup that also supports images */
1594 if ((dropable->types & ELM_SEL_FORMAT_MARKUP) &&
1595 (dropable->types & ELM_SEL_FORMAT_IMAGE))
1598 ddata.format = ELM_SEL_FORMAT_MARKUP;
1599 pasteimage_provider_set(dropable->obj);
1601 pastedimages = eina_list_append(pastedimages, savedtypes.pi);
1602 len = strlen(tagstring) + strlen(savedtypes.pi->file);
1603 entrytag = alloca(len + 1);
1604 snprintf(entrytag, len + 1, tagstring, savedtypes.pi->file);
1605 ddata.data = entrytag;
1606 cnp_debug("Insert %s\n", (char *)ddata.data);
1607 dropable->dropcb(dropable->cbdata, dropable->obj, &ddata);
1608 ecore_x_dnd_send_finished();
1610 if (savedtypes.pi) pasteimage_free(savedtypes.pi);
1611 savedtypes.pi = NULL;
1614 else if (dropable->types & ELM_SEL_FORMAT_IMAGE)
1616 cnp_debug("Doing image insert (%s)\n", savedtypes.pi->file);
1617 ddata.format = ELM_SEL_FORMAT_IMAGE;
1618 ddata.data = (char *)savedtypes.pi->file;
1619 dropable->dropcb(dropable->cbdata, dropable->obj, &ddata);
1620 ecore_x_dnd_send_finished();
1622 if (savedtypes.pi) pasteimage_free(savedtypes.pi);
1623 savedtypes.pi = NULL;
1629 cnp_debug("Item doesn't support images... passing\n");
1630 pasteimage_free(savedtypes.pi);
1634 else if (savedtypes.textreq)
1636 /* Already asked: Pretend we asked now, and paste immediately when
1638 savedtypes.textreq = 0;
1639 ecore_x_dnd_send_finished();
1644 cnp_debug("doing a request then\n");
1645 selections[ELM_SEL_XDND].requestwidget = dropable->obj;
1646 selections[ELM_SEL_XDND].requestformat = ELM_SEL_FORMAT_MARKUP;
1647 selections[ELM_SEL_XDND].active = EINA_TRUE;
1649 ecore_x_selection_xdnd_request(xwin, atoms[i].name);
1654 _dnd_position(void *data __UNUSED__, int etype __UNUSED__, void *ev)
1656 struct _Ecore_X_Event_Xdnd_Position *pos;
1657 Ecore_X_Rectangle rect;
1661 /* Need to send a status back */
1662 /* FIXME: Should check I can drop here */
1663 /* FIXME: Should highlight widget */
1664 rect.x = pos->position.x - 5;
1665 rect.y = pos->position.y - 5;
1668 ecore_x_dnd_send_status(EINA_TRUE, EINA_FALSE, rect, pos->action);
1674 * When dragging this is callback response from the destination.
1675 * The important thing we care about: Can we drop; thus update cursor
1679 _dnd_status(void *data __UNUSED__, int etype __UNUSED__, void *ev)
1681 struct _Ecore_X_Event_Xdnd_Status *status = ev;
1683 if (!status) return EINA_TRUE;
1685 /* Only thing we care about: will accept */
1686 if (status->will_accept)
1688 cnp_debug("Will accept\n");
1691 { /* Won't accept */
1692 cnp_debug("Won't accept accept\n");
1698 * Add a widget as drop target.
1701 elm_drop_target_add(Evas_Object *obj, Elm_Sel_Type format, Elm_Drop_Cb dropcb, void *cbdata)
1704 Ecore_X_Window xwin;
1709 if (!obj) return EINA_FALSE;
1710 top = elm_widget_top_get(obj);
1711 if (!top || !elm_win_xwindow_get(top)) return EINA_FALSE;
1712 if (!_elm_cnp_init_count) _elm_cnp_init();
1714 /* Is this the first? */
1715 first = (!drops) ? 1 : 0;
1717 EINA_LIST_FOREACH(drops, item, drop)
1719 if (drop->obj == obj)
1721 /* Update: Not a new one */
1722 drop->dropcb = dropcb;
1723 drop->cbdata = cbdata;
1724 drop->types = format;
1729 /* Create new drop */
1730 drop = calloc(1, sizeof(Dropable));
1731 if (!drop) return EINA_FALSE;
1732 /* FIXME: Check for eina's deranged error method */
1733 drops = eina_list_append(drops, drop);
1735 if (!drops/* || or other error */)
1740 drop->dropcb = dropcb;
1741 drop->cbdata = cbdata;
1742 drop->types = format;
1745 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
1746 /* I love C and varargs */
1747 (Evas_Object_Event_Cb)elm_drop_target_del,
1749 /* FIXME: Handle resizes */
1751 /* If not the first: We're done */
1752 if (!first) return EINA_TRUE;
1754 xwin = (Ecore_X_Window)ecore_evas_window_get
1755 (ecore_evas_ecore_evas_get(evas_object_evas_get(obj)));
1757 ecore_x_dnd_aware_set(xwin, EINA_TRUE);
1759 cnp_debug("Adding drop target calls\n");
1760 handler_enter = ecore_event_handler_add(ECORE_X_EVENT_XDND_ENTER,
1762 handler_pos = ecore_event_handler_add(ECORE_X_EVENT_XDND_POSITION,
1763 _dnd_position, NULL);
1764 handler_drop = ecore_event_handler_add(ECORE_X_EVENT_XDND_DROP,
1771 elm_drop_target_del(Evas_Object *obj)
1773 Dropable *drop,*del;
1775 Ecore_X_Window xwin;
1778 EINA_LIST_FOREACH(drops, item, drop)
1780 if (drop->obj == obj)
1782 drops = eina_list_remove_list(drops, item);
1787 if (!del) return EINA_FALSE;
1789 evas_object_event_callback_del(obj, EVAS_CALLBACK_FREE,
1790 (Evas_Object_Event_Cb)elm_drop_target_del);
1792 /* If still drops there: All fine.. continue */
1793 if (drops) return EINA_TRUE;
1795 cnp_debug("Disabling DND\n");
1796 xwin = (Ecore_X_Window)ecore_evas_window_get
1797 (ecore_evas_ecore_evas_get(evas_object_evas_get(obj)));
1798 ecore_x_dnd_aware_set(xwin, EINA_FALSE);
1800 ecore_event_handler_del(handler_pos);
1801 ecore_event_handler_del(handler_drop);
1802 ecore_event_handler_del(handler_enter);
1806 pasteimage_free(savedtypes.pi);
1807 savedtypes.pi = NULL;
1815 _drag_mouse_up(void *un __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *data __UNUSED__)
1817 evas_object_event_callback_del(obj, EVAS_CALLBACK_MOUSE_UP, _drag_mouse_up);
1821 dragdonecb(dragdonecb,selections[ELM_SEL_XDND].widget);
1826 evas_object_del(dragwin);
1832 _drag_move(void *data __UNUSED__, Ecore_X_Xdnd_Position *pos)
1834 evas_object_move(dragwin,
1835 pos->position.x - _dragx,
1836 pos->position.y - _dragy);
1841 elm_drag_start(Evas_Object *obj, Elm_Sel_Format format, const char *data, void (*dragdone) (void *data, Evas_Object *), void *donecbdata)
1843 Ecore_X_Window xwin;
1845 Elm_Sel_Type xdnd = ELM_SEL_XDND;
1847 int x, y, x2, y2, x3, y3;
1851 if (!_elm_cnp_init_count) _elm_cnp_init();
1853 xwin = elm_win_xwindow_get(obj);
1855 cnp_debug("starting drag...\n");
1857 ecore_x_dnd_type_set(xwin, "text/uri-list", 1);
1858 sel = selections + ELM_SEL_XDND;
1861 sel->format = format;
1862 sel->selbuf = data ? strdup(data) : NULL;
1863 dragdonecb = dragdone;
1864 dragdonedata = donecbdata;
1866 ecore_x_dnd_callback_pos_update_set(_drag_move, NULL);
1867 ecore_x_dnd_begin(xwin, (unsigned char *)&xdnd, sizeof(Elm_Sel_Type));
1868 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP,
1869 _drag_mouse_up, NULL);
1871 handler_status = ecore_event_handler_add(ECORE_X_EVENT_XDND_STATUS,
1874 dragwin = elm_win_add(NULL, "Elm Drag Object", ELM_WIN_UTILITY);
1875 elm_win_override_set(dragwin, 1);
1877 /* FIXME: Images only */
1878 icon = elm_icon_add(dragwin);
1879 elm_icon_file_set(icon, data + 7, NULL); /* 7!? "file://" */
1880 elm_win_resize_object_add(dragwin,icon);
1881 evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1882 evas_object_size_hint_align_set(icon, EVAS_HINT_FILL, EVAS_HINT_FILL);
1884 /* Position subwindow appropriately */
1885 ee = ecore_evas_ecore_evas_get(evas_object_evas_get(obj));
1886 ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
1887 evas_object_geometry_get(obj, &x2, &y2, &w, &h);
1890 evas_object_move(dragwin, x, y);
1891 evas_object_resize(icon, w, h);
1892 evas_object_resize(dragwin, w, h);
1894 evas_object_show(icon);
1895 evas_object_show(dragwin);
1897 evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x3, &y3);
1905 elm_cnp_tempfile_create(int size)
1908 const char *tmppath;
1911 info = malloc(sizeof(Tmp_Info));
1912 if (!info) return NULL;
1914 tmppath = getenv("TMP");
1915 if (!tmppath) tmppath = P_tmpdir;
1916 len = snprintf(NULL, 0, "%s/%sXXXXXX", tmppath, "elmcnpitem-");
1923 info->filename = malloc(len);
1924 if (!info->filename)
1929 snprintf(info->filename,len,"%s/%sXXXXXX", tmppath, "elmcnpitem-");
1931 info->fd = mkstemp(info->filename);
1936 /* And before someone says anything see POSIX 1003.1-2008 page 400 */
1939 pid = (long)getpid();
1940 /* Use pid instead of /proc/self: That way if can be passed around */
1941 len = snprintf(NULL,0,"/proc/%li/fd/%i", pid, info->fd);
1946 snprintf(tmp,len, "/proc/%li/fd/%i", pid, info->fd);
1947 unlink(info->filename);
1948 free(info->filename);
1949 info->filename = tmp;
1954 cnp_debug("filename is %s\n", info->filename);
1957 /* Set map to NULL and return */
1964 if (ftruncate(info->fd, size))
1966 perror("ftruncate");
1972 eina_mmap_safety_enabled_set(EINA_TRUE);
1974 info->map = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, info->fd, 0);
1975 if (info->map == MAP_FAILED)
1987 tmpinfo_free(Tmp_Info *info)
1989 if (!info) return 0;
1990 free(info->filename);
1996 /* Stubs for windows */
1998 elm_drag_start(Evas_Object *o, Elm_Sel_Format f, const char *d, void (*donecb)(void *, Evas_Object *),void *cbdata)
2004 elm_drop_target_add(Evas_Object *obj, Elm_Sel_Type format, Elm_Drop_Cb dropcb, void *cbdata)
2010 elm_drop_target_del(Evas_Object *o)
2016 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/