svn update: 51469 (latest:51480)
[framework/uifw/elementary.git] / src / lib / elm_cnp_helper.c
1 #include <stdbool.h>
2
3 #include <stdio.h> // debug
4
5 #include <Elementary.h>
6
7 #include "elm_priv.h"
8
9 #ifdef HAVE_ELEMENTARY_X
10
11 # include <X11/X.h>
12 # include <X11/Xatom.h>
13
14
15 # define ARRAYINIT(foo)  [foo]=
16
17 #define DEBUGON 0
18
19 #if DEBUGON
20 #define cnp_debug(x...) printf(__FILE__": " x)
21 #else
22 #define cnp_debug(x...)
23 #endif
24
25
26 enum {
27      CNP_ATOM_TARGETS = 0,
28      CNP_ATOM_text_uri,
29      CNP_ATOM_image_png,
30      CNP_ATOM_XELM,
31      CNP_ATOM_text_html_utf8,
32      CNP_ATOM_text_html,
33      CNP_ATOM_UTF8STRING,
34      CNP_ATOM_STRING,
35      CNP_ATOM_TEXT,
36      CNP_ATOM_text_plain_utf8,
37      CNP_ATOM_text_plain,
38
39      CNP_N_ATOMS,
40 };
41 struct pasteimage {
42      Evas_Object *entry;
43      const char *tag;
44      const char *file;
45      Evas_Object *img;
46 };
47
48
49 struct _elm_cnp_selection {
50    const char *debug;
51    Evas_Object *widget;
52
53    enum _elm_sel_format format;
54    char *selbuf;
55
56    unsigned int active : 1;
57
58    Ecore_X_Selection ecore_sel;
59
60    Evas_Object *requestwidget;
61    enum _elm_sel_format requestformat;
62
63    int (*set)(Ecore_X_Window, const void *data, int size);
64    int (*clear)(void);
65    void (*request)(Ecore_X_Window, const char *target);
66 };
67
68 /* Optimisation: Turn this into a 256 byte table:
69  *      then can lookup in one index, not N checks */
70 static const struct escapes {
71    const char *escape;
72    const char value;
73 } escapes[] = {
74    { "<br>",    '\n' },
75    { "<\t>",    '\t' },
76    { "gt;",     '>' },
77    { "lt;",     '<' },
78    { "amp;",'&' },
79    { "quot;",'\'' },
80    { "dquot;", '"' },
81 };
82 #define N_ESCAPES ((int)(sizeof(escapes)/sizeof(escapes[0])))
83
84
85 static Eina_Bool _elm_cnp_init(void);
86 static Eina_Bool selection_clear(void *udata __UNUSED__, int type, void *event);
87 //static Eina_Bool selection_request(void *udata __UNUSED__, int type, void *event);
88 static Eina_Bool selection_notify(void *udata __UNUSED__, int type, void *event);
89 static char *remove_tags(const char *p, int *len);
90 static char *mark_up(const char *start, int *lenp);
91
92 static Evas_Object *image_provider(void *images, Evas_Object *entry, const char *item);
93
94
95 typedef int (*converter_fn)(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
96
97 static int targets_converter(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
98 static int text_converter(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
99 static int html_converter(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
100 static int edje_converter(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
101 static int uri_converter(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
102 static int png_converter(char *target, void *data, int size, void **data_ret, int *size_ret, Ecore_X_Atom *ttype, int *typesize);
103
104 /* FIXME: Which way should this be: Notify or response */
105 typedef int (*response_handler)(struct _elm_cnp_selection *sel,
106       Ecore_X_Event_Selection_Notify *);
107 static int response_handler_targets(struct _elm_cnp_selection *sel,
108       Ecore_X_Event_Selection_Notify *);
109
110 typedef int (*notify_handler)(struct _elm_cnp_selection *sel,
111       Ecore_X_Event_Selection_Notify *);
112 static int notify_handler_targets(struct _elm_cnp_selection *sel,
113       Ecore_X_Event_Selection_Notify *notify);
114 static int notify_handler_text(struct _elm_cnp_selection *sel,
115       Ecore_X_Event_Selection_Notify *notify);
116 static int notify_handler_png(struct _elm_cnp_selection *sel,
117       Ecore_X_Event_Selection_Notify *notify);
118 static int notify_handler_uri(struct _elm_cnp_selection *sel,
119       Ecore_X_Event_Selection_Notify *notify);
120
121
122 static struct {
123    const char *name;
124    enum _elm_sel_format formats;
125    /* Called by ecore to do conversion */
126    converter_fn converter;
127    response_handler response;
128    notify_handler notify;
129    /* Atom */
130    Ecore_X_Atom atom;
131 } atoms[CNP_N_ATOMS] = {
132    [CNP_ATOM_TARGETS] = {
133         "TARGETS",
134         (enum _elm_sel_format)-1,
135         targets_converter,
136         response_handler_targets,
137         notify_handler_targets,
138         0
139    },
140    [CNP_ATOM_XELM] =  {
141         "application/x-elementary-markup",
142         ELM_SEL_MARKUP,
143         edje_converter,
144         NULL,
145         NULL,
146         0
147    },
148    [CNP_ATOM_text_uri] = {
149         "text/uri",
150         ELM_SEL_MARKUP | ELM_SEL_IMAGE, /* Either images or entries */
151         uri_converter,
152         NULL,
153         notify_handler_uri,
154         0
155    },
156    [CNP_ATOM_image_png] = {
157         "image/png",
158         ELM_SEL_IMAGE | ELM_SEL_IMAGE,
159         png_converter,
160         NULL,
161         notify_handler_png,
162         0
163    },
164    [CNP_ATOM_text_html_utf8] = {
165         "text/html;charset=utf-8",
166         ELM_SEL_MARKUP,
167         html_converter,
168         NULL,
169         NULL,
170         0
171    },
172    [CNP_ATOM_text_html] = {
173         "text/html",
174         ELM_SEL_MARKUP,
175         html_converter,
176         NULL,
177         NULL,
178         0
179    },
180    [CNP_ATOM_UTF8STRING] = {
181         "UTF8_STRING",
182         ELM_SEL_MARKUP,
183         text_converter,
184         NULL,
185         notify_handler_text,
186         0
187    },
188    [CNP_ATOM_STRING] = {
189         "STRING",
190         ELM_SEL_MARKUP | ELM_SEL_IMAGE,
191         text_converter,
192         NULL,
193         notify_handler_text,
194         0
195    },
196    [CNP_ATOM_TEXT] = {
197         "TEXT",
198         ELM_SEL_MARKUP | ELM_SEL_IMAGE,
199         text_converter,
200         NULL,
201         NULL,
202         0
203    },
204    [CNP_ATOM_text_plain_utf8] = {
205         "text/plain;charset=ut-8",
206         ELM_SEL_MARKUP,
207         text_converter,
208         NULL,
209         NULL,
210         0
211    },
212    [CNP_ATOM_text_plain] = {
213         "text/plain",
214         ELM_SEL_MARKUP,
215         text_converter,
216         NULL,
217         NULL,
218         0
219    },
220 };
221
222 static struct _elm_cnp_selection selections[ELM_SEL_MAX] = {
223    ARRAYINIT(ELM_SEL_PRIMARY) {
224        .debug = "Primary",
225        .ecore_sel = ECORE_X_SELECTION_PRIMARY,
226        .set = ecore_x_selection_primary_set,
227        .clear = ecore_x_selection_primary_clear,
228        .request = ecore_x_selection_primary_request,
229    },
230    ARRAYINIT(ELM_SEL_SECONDARY) {
231        .debug = "Secondary",
232        .ecore_sel = ECORE_X_SELECTION_SECONDARY,
233        .set = ecore_x_selection_secondary_set,
234        .clear = ecore_x_selection_secondary_clear,
235        .request = ecore_x_selection_secondary_request,
236    },
237    ARRAYINIT(ELM_SEL_CLIPBOARD) {
238        .debug = "Clipboard",
239        .ecore_sel = ECORE_X_SELECTION_CLIPBOARD,
240        .set = ecore_x_selection_clipboard_set,
241        .clear = ecore_x_selection_clipboard_clear,
242        .request = ecore_x_selection_clipboard_request,
243    }
244 };
245
246 static int _elm_cnp_init_count = 0;
247   /* Gah... who left this out of XAtoms.h */
248 static Ecore_X_Atom clipboard_atom;
249
250 Eina_List *pastedimages;
251 #endif
252
253
254 Eina_Bool
255 elm_selection_set(enum _elm_sel_type selection, Evas_Object *widget,
256                         enum _elm_sel_format format, const char *selbuf)
257 {
258 #ifdef HAVE_ELEMENTARY_X
259    struct _elm_cnp_selection *sel;
260
261    if ((unsigned int)selection >= (unsigned int)ELM_SEL_MAX) return EINA_FALSE;
262    if (!_elm_cnp_init_count) _elm_cnp_init();
263    if (!selbuf && format != ELM_SEL_IMAGE)
264      return elm_selection_clear(selection, widget);
265
266    sel = selections + selection;
267
268    sel->active = 1;
269    sel->widget = widget;
270
271    sel->set(elm_win_xwindow_get(widget),&selection,sizeof(enum _elm_sel_type));
272    sel->format = format;
273    sel->selbuf = selbuf ? strdup(selbuf) : NULL;
274
275    return EINA_TRUE;
276 #else
277    return EINA_FALSE;
278 #endif
279 }
280
281 Eina_Bool
282 elm_selection_clear(enum _elm_sel_type selection, Evas_Object *widget)
283 {
284 #ifdef HAVE_ELEMENTARY_X
285    struct _elm_cnp_selection *sel;
286
287    if ((unsigned int)selection >= (unsigned int)ELM_SEL_MAX) return EINA_FALSE;
288    if (!_elm_cnp_init_count) _elm_cnp_init();
289
290    sel = selections + selection;
291
292    /* No longer this selection: Consider it gone! */
293    if (!sel->active || sel->widget != widget) return EINA_TRUE;
294
295    sel->active = 0;
296    sel->widget = NULL;
297    sel->clear();
298
299    return EINA_TRUE;
300 #else
301    return EINA_FALSE;
302 #endif
303 }
304
305 Eina_Bool
306 elm_selection_get(enum _elm_sel_type selection, enum _elm_sel_format format,
307                         Evas_Object *widget)
308 {
309 #ifdef HAVE_ELEMENTARY_X
310    Evas_Object *top;
311    struct _elm_cnp_selection *sel;
312
313    if ((unsigned int)selection >= (unsigned int)ELM_SEL_MAX) return EINA_FALSE;
314    if (!_elm_cnp_init_count) _elm_cnp_init();
315
316    sel = selections + selection;
317    top = elm_widget_top_get(widget);
318    if (!top) return EINA_FALSE;
319
320    sel->requestformat = format;
321    sel->requestwidget = widget;
322    sel->request(elm_win_xwindow_get(top), ECORE_X_SELECTION_TARGET_UTF8_STRING);
323
324    return EINA_TRUE;
325 #else
326    return EINA_FALSE;
327 #endif
328 }
329
330 #ifdef HAVE_ELEMENTARY_X
331
332 static Eina_Bool
333 _elm_cnp_init(void){
334    int i;
335    if (_elm_cnp_init_count ++) return EINA_TRUE;
336
337    /* FIXME: Handle XCB */
338    for (i = 0 ; i < CNP_N_ATOMS ; i ++)
339      {
340         atoms[i].atom = ecore_x_atom_get(atoms[i].name);
341         ecore_x_selection_converter_atom_add(atoms[i].atom,
342               atoms[i].converter);
343      }
344    clipboard_atom = ecore_x_atom_get("CLIPBOARD");
345
346    ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR, selection_clear,NULL);
347    ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,selection_notify,NULL);
348     return EINA_TRUE;
349 }
350
351 static Eina_Bool
352 selection_clear(void *udata __UNUSED__, int type __UNUSED__, void *event){
353    Ecore_X_Event_Selection_Clear *ev = event;
354    struct _elm_cnp_selection *sel;
355    int i;
356
357    for (i = 0 ; i < ELM_SEL_MAX ; i ++)
358      {
359         if (selections[i].ecore_sel == ev->selection) break;
360      }
361    /* Not me... Don't care */
362    if (i == ELM_SEL_MAX) return ECORE_CALLBACK_PASS_ON;
363
364    sel = selections + i;
365    sel->active = 0;
366    sel->widget = NULL;
367    sel->selbuf = NULL;
368
369    return ECORE_CALLBACK_PASS_ON;
370 }
371
372 #if 0
373 /**
374  * Response to a selection request
375  */
376 static Eina_Bool
377 selection_request(void *udata __UNUSED__, int type, void *event){
378    Ecore_X_Event_Selection_Request *ev = event;
379    struct _elm_cnp_selection *sel;
380    int i;
381 printf("selection request callback: %d\n",ev->selection);
382 printf("selection request callback: %d\n",ev->target);
383
384    if (ev->selection == clipboard_atom){
385          sel = selections + ELM_SEL_CLIPBOARD;
386    } else if (ev->selection == XA_PRIMARY){
387          sel = selections + ELM_SEL_PRIMARY;
388    } else if (ev->selection ==  XA_SECONDARY){
389          sel = selections + ELM_SEL_SECONDARY;
390    } else {
391          return ECORE_CALLBACK_PASS_ON;
392    }
393    return ECORE_CALLBACK_PASS_ON;
394
395    for (i = 0 ; i < CNP_N_ATOMS ; i ++)
396      {
397         if (ev->target == atoms[i].atom)
398           {
399              if (atoms[i].response){
400                   atoms[i].response(sel, ev);
401              } else {
402                   printf("Ignored: No handler!\n");
403              }
404           }
405      }
406
407    return ECORE_CALLBACK_PASS_ON;
408 }
409 #endif
410
411
412 /*
413  * Response to a selection notify:
414  *      - So we have asked for the selection list.
415  *      - If it's the targets list, parse it, and fire of what we want,
416  *      else it's the data we want.
417  */
418 static Eina_Bool
419 selection_notify(void *udata __UNUSED__, int type __UNUSED__, void *event){
420    Ecore_X_Event_Selection_Notify *ev = event;
421    struct _elm_cnp_selection *sel;
422    int i;
423
424    cnp_debug("selection notify callback: %d\n",ev->selection);
425    switch (ev->selection){
426       case ECORE_X_SELECTION_CLIPBOARD:
427          sel = selections + ELM_SEL_CLIPBOARD;
428          break;
429
430       case ECORE_X_SELECTION_PRIMARY:
431          sel = selections + ELM_SEL_PRIMARY;
432          break;
433       case ECORE_X_SELECTION_SECONDARY:
434          sel = selections + ELM_SEL_SECONDARY;
435          break;
436       default:
437          return ECORE_CALLBACK_PASS_ON;
438    }
439    cnp_debug("Target is %s\n",ev->target);
440
441    for (i = 0 ; i < CNP_N_ATOMS ; i ++)
442      {
443         if (strcmp(ev->target, atoms[i].name) == 0)
444           {
445              if (atoms[i].notify){
446                   cnp_debug("Found something: %s\n", atoms[i].name);
447                   atoms[i].notify(sel, ev);
448              } else {
449                   printf("Ignored: No handler!\n");
450              }
451           }
452      }
453
454    return ECORE_CALLBACK_PASS_ON;
455 }
456
457
458
459 static int
460 targets_converter(char *target __UNUSED__, void *data, int size __UNUSED__,
461                   void **data_ret, int *size_ret,
462                   Ecore_X_Atom *ttype, int *typesize){
463    int i,count;
464    Ecore_X_Atom *aret;
465    struct _elm_cnp_selection *sel;
466
467    if (!data_ret) return -1;
468
469    sel = selections + *(int*)data;
470
471    for (i = 0, count = 0 ; i < CNP_N_ATOMS ; i ++)
472         if (sel->format & atoms[i].formats)
473            count ++;
474
475    aret = malloc(sizeof(Ecore_X_Atom) * count);
476    for (i = 0, count = 0 ; i < CNP_N_ATOMS ; i ++)
477         if (sel->format & atoms[i].formats)
478           aret[count ++] = atoms[i].atom;
479
480    *data_ret = aret;
481    if (typesize) *typesize = 32 /* urk */;
482    if (ttype) *ttype = XA_ATOM;
483    if (size_ret) *size_ret = count;
484
485    return 1;
486 }
487
488 static int
489 png_converter(char *target __UNUSED__, void *data __UNUSED__, int size __UNUSED__,
490               void **data_ret __UNUSED__, int *size_ret __UNUSED__,
491               Ecore_X_Atom *ttype __UNUSED__, int *typesize __UNUSED__)
492 {
493      return 1;
494 }
495
496 /*
497  * Callback to handle a targets response on a selection request:
498  * So pick the format we'd like; and then request it.
499  */
500 static int
501 notify_handler_targets(struct _elm_cnp_selection *sel,
502                        Ecore_X_Event_Selection_Notify *notify)
503 {
504    Ecore_X_Selection_Data_Targets *targets;
505    Ecore_X_Atom *atomlist;
506    int i,j;
507
508    targets = notify->data;
509    atomlist = (Ecore_X_Atom *)(targets->data.data);
510
511    for (j = 1; j < CNP_N_ATOMS ; j ++)
512      {
513         cnp_debug("\t%s %d\n",atoms[j].name, atoms[j].atom);
514         if (!(atoms[j].formats & sel->requestformat)) continue;
515         for (i = 0 ; i < targets->data.length ; i ++)
516           {
517              if (atoms[j].atom == atomlist[i])
518                {
519                   cnp_debug("Atom %s matches\n",atoms[j].name);
520                   goto done;
521                }
522           }
523      }
524
525    cnp_debug("Couldn't find anything that matches\n");
526    return ECORE_CALLBACK_PASS_ON;
527
528    done:
529    cnp_debug("Sending request for %s\n",atoms[j].name);
530    sel->request(elm_win_xwindow_get(sel->requestwidget), atoms[j].name);
531
532    return ECORE_CALLBACK_PASS_ON;
533 }
534
535 static int
536 response_handler_targets(struct _elm_cnp_selection *sel,
537                          Ecore_X_Event_Selection_Notify *notify)
538 {
539    Ecore_X_Selection_Data_Targets *targets;
540    Ecore_X_Atom *atomlist;
541    Evas_Object *top;
542    int i,j;
543    int prio, selected;
544
545    targets = notify->data;
546    atomlist = (Ecore_X_Atom *)(targets->data.data);
547
548    prio = -1;
549    selected = -1;
550    /* Start from 1: Skip targets */
551    for (j = 1 ; j < CNP_N_ATOMS ; j ++)
552      {
553         if (!(atoms[j].formats & sel->requestformat)) continue;
554         for (i = 0 ; i < targets->data.length ; i ++)
555           {
556              if (atoms[j].atom == atomlist[i] && atoms[j].response){
557                   /* Found a match: Use it */
558                   goto found;
559              }
560         }
561      }
562         found:
563    if (j == CNP_N_ATOMS)
564      {
565         cnp_debug("No matching type found\n");
566         return 0;
567      }
568
569    top = elm_widget_top_get(sel->requestwidget);
570    if (!top) return 0;
571
572    sel->request(elm_win_xwindow_get(top), atoms[j].name);
573    return 0;
574 }
575
576
577 static int
578 notify_handler_text(struct _elm_cnp_selection *sel,
579                     Ecore_X_Event_Selection_Notify *notify)
580 {
581    Ecore_X_Selection_Data *data;
582    char *str;
583
584    data = notify->data;
585    str = mark_up((char*)data->data, NULL);
586    elm_entry_entry_insert(sel->requestwidget, str);
587    free(str);
588
589    return 0;
590 }
591
592
593 /**
594  * So someone is pasting an image into my entry or widget...
595  */
596 static int
597 notify_handler_uri(struct _elm_cnp_selection *sel,
598          Ecore_X_Event_Selection_Notify *notify)
599 {
600    Ecore_X_Selection_Data *data;
601    struct pasteimage *pi;
602    char entrytag[100];
603    char *p;
604
605    data = notify->data;
606    p = (char *)data->data;
607    cnp_debug("Got %s\n",p);
608    if (strncmp(p,"file://",7) != 0){
609         cnp_debug("Doesn't start with ;file;  %s\n",p);
610         return 0;
611    }
612
613    p += strlen("file://");
614
615    pi = calloc(1,sizeof(struct pasteimage));
616    snprintf(entrytag, sizeof(entrytag), "pasteimage-%p",pi);
617    pi->tag = strdup(entrytag);
618    pi->file = strndup(p,data->length - strlen("file://"));
619
620    elm_entry_item_provider_append(sel->requestwidget, image_provider, pi);
621    pastedimages = eina_list_append(pastedimages, pi);
622
623    snprintf(entrytag, sizeof(entrytag), "<item absize=240x180 href=%s>",pi->tag);
624    elm_entry_entry_insert(sel->requestwidget, entrytag);
625
626    return 0;
627 }
628
629 static int
630 notify_handler_png(struct _elm_cnp_selection *sel __UNUSED__,
631                    Ecore_X_Event_Selection_Notify *notify __UNUSED__)
632 {
633    cnp_debug("got a png!\n");
634    return 0;
635 }
636
637
638 static int
639 text_converter(char *target __UNUSED__, void *data, int size __UNUSED__,
640                void **data_ret, int *size_ret,
641                Ecore_X_Atom *ttype __UNUSED__, int *typesize __UNUSED__)
642 {
643    struct _elm_cnp_selection *sel;
644
645    sel = selections + *(int *)data;
646    if (!sel->active)
647      {
648         return 1;
649      }
650
651    if (sel->format == ELM_SEL_MARKUP){
652         *data_ret = remove_tags(sel->selbuf, size_ret);
653    } else if (sel->format == ELM_SEL_IMAGE){
654         cnp_debug("Image %s\n",evas_object_type_get(sel->widget));
655         cnp_debug("Elm type: %s\n",elm_object_widget_type_get(sel->widget));
656         evas_object_image_file_get(elm_photocam_internal_image_get(sel->widget), (const char **)data_ret, NULL);
657         if (!*data_ret) *data_ret = strdup("No file");
658         else *data_ret = strdup(*data_ret);
659         *size_ret = strlen(*data_ret);
660    }
661    return 1;
662 }
663
664 static int
665 edje_converter(char *target __UNUSED__, void *data, int size __UNUSED__, 
666                void **data_ret, int *size_ret, Ecore_X_Atom *ttype __UNUSED__, 
667                int *typesize __UNUSED__)
668 {
669    struct _elm_cnp_selection *sel;
670
671    sel = selections + *(int *)data;
672    if (data_ret) *data_ret = strdup(sel->selbuf);
673    if (size_ret) *size_ret = strlen(sel->selbuf);
674
675    return 1;
676 }
677
678
679 static int
680 html_converter(char *target __UNUSED__, void *data, int size __UNUSED__, 
681                void **data_ret, int *size_ret, Ecore_X_Atom *ttype __UNUSED__, 
682                int *typesize __UNUSED__)
683 {
684    struct _elm_cnp_selection *sel;
685
686    sel = selections + *(int *)data;
687    if (data_ret) *data_ret = strdup(sel->selbuf);
688    if (size_ret) *size_ret = strlen(sel->selbuf);
689
690    return 1;
691 }
692
693 static int
694 uri_converter(char *target __UNUSED__, void *data, int size __UNUSED__, 
695               void **data_ret, int *size_ret, Ecore_X_Atom *ttype __UNUSED__, 
696               int *typesize __UNUSED__)
697 {
698     struct _elm_cnp_selection *sel;
699     sel = selections + *(int *)data;
700     cnp_debug("Uri converter\n");
701     if (data_ret) *data_ret = strdup(sel->selbuf);
702     if (size_ret) *size_ret = strlen(sel->selbuf);
703     return 1;
704 }
705
706
707 /*
708  * Image paste provide
709  */
710
711 /* FIXME: Should add provider for each pated item: Use data to store it
712  * much easier */
713 static Evas_Object *
714 image_provider(void *images __UNUSED__, Evas_Object *entry, const char *item)
715 {
716    struct pasteimage *pi;
717    Eina_List *l;
718
719    cnp_debug("image provider for %s called\n",item);
720    EINA_LIST_FOREACH(pastedimages, l, pi)
721      {
722         cnp_debug("is it %s?\n",pi->tag);
723         if (strcmp(pi->tag,item) == 0){
724              /* Found it */
725              Evas_Object *o;
726              o = evas_object_image_filled_add(evas_object_evas_get(entry));
727              /* FIXME: Handle eets */
728              cnp_debug("file is %s (object is %p)\n",pi->file,o);
729              evas_object_image_file_set(o, pi->file, NULL);
730              evas_object_show(o);
731              return o;
732         }
733      }
734    return NULL;
735 }
736
737 static void
738 entry_deleted(void *images __UNUSED__, Evas *e __UNUSED__, Evas_Object *entry, void *unused __UNUSED__)
739 {
740    struct pasteimage *pi;
741    Eina_List *l,*next;
742
743    EINA_LIST_FOREACH_SAFE(pastedimages, l, next, pi)
744      {
745         if (pi->entry == entry){
746              pastedimages = eina_list_remove_list(pastedimages, l);
747         }
748      }
749 }
750
751
752 static char *
753 remove_tags(const char *p, int *len){
754    char *q,*ret;
755    int i;
756    if (!p) return NULL;
757
758    q = malloc(strlen(p) + 1);
759    if (!q) return NULL;
760    ret = q;
761
762    while (*p)
763      {
764         if (*p != '<' && *p != '&'){
765              *q ++ = *p ++;
766         } else if (*p == '<') {
767              if (p[1] == 'b' && p[2] == 'r' &&
768                         (p[3] == ' ' || p[3] == '/' || p[3] == '>'))
769                 *q++ = '\n';
770              while (*p && *p != '>') p ++;
771              p ++;
772         } else if (*p == '&') {
773              p ++;
774              for (i = 0 ; i < N_ESCAPES ; i ++){
775                   if (!strncmp(p,escapes[i].escape, strlen(escapes[i].escape))){
776                        p += strlen(escapes[i].escape);
777                        *q = escapes[i].value;
778                        q ++;
779                        break;
780                   }
781              }
782              if (i == N_ESCAPES)
783                *q ++ = '&';
784         }
785      }
786    *q = 0;
787    if (len) *len = q - ret;
788    return ret;
789 }
790
791 /* Mark up */
792 static char *
793 mark_up(const char *start, int *lenp){
794   int l,i;
795   const char *p;
796   char *q,*ret;
797
798   if (!start) return NULL;
799   /* First pass: Count characters */
800   for (l = 0, p = start ; *p ; p ++)
801     {
802     for (i = 0 ; i < N_ESCAPES ; i ++)
803       {
804          if (*p == escapes[i].value)
805            {
806               l += strlen(escapes[i].escape);
807               break;
808            }
809       }
810     if (i == N_ESCAPES)
811          l ++;
812   }
813
814   q = ret = malloc(l + 1);
815
816   /* Second pass: Change characters */
817   for (p = start ; *p ; )
818     {
819     for (i = 0 ; i < N_ESCAPES ; i ++)
820       {
821          if (*p == escapes[i].value)
822            {
823               strcpy(q, escapes[i].escape);
824               q += strlen(escapes[i].escape);
825               p ++;
826               break;
827            }
828       }
829     if (i == N_ESCAPES)
830          *q ++ = *p ++;
831   }
832   *q = 0;
833
834   if (lenp) *lenp = l;
835   return ret;
836 }
837
838
839 #endif