87bf266bfa63c1a06eca8391908e700f431a1650
[framework/uifw/edje.git] / src / lib / edje_entry.c
1 #include "edje_private.h"
2
3 #ifdef HAVE_ECORE_IMF
4 static Eina_Bool _edje_entry_imf_retrieve_surrounding_cb(void *data, Ecore_IMF_Context *ctx, char **text, int *cursor_pos);
5 static Eina_Bool _edje_entry_imf_event_commit_cb(void *data, int type, void *event);
6 static Eina_Bool _edje_entry_imf_event_preedit_changed_cb(void *data, int type, void *event);
7 static Eina_Bool _edje_entry_imf_event_delete_surrounding_cb(void *data, int type, void *event);
8 #endif
9
10 typedef struct _Entry Entry;
11 typedef struct _Sel Sel;
12 typedef struct _Anchor Anchor;
13
14 static void _edje_entry_imf_cursor_info_set(Entry *en);
15 static void _edje_entry_imf_context_reset(Entry *en);
16
17 struct _Entry
18 {
19    Edje_Real_Part *rp;
20    Evas_Object *cursor_bg;
21    Evas_Object *cursor_fg;
22    Evas_Textblock_Cursor *cursor;
23    Evas_Textblock_Cursor *sel_start, *sel_end;
24    Evas_Textblock_Cursor *cursor_user, *cursor_user_extra;
25    Evas_Textblock_Cursor *preedit_start, *preedit_end;
26    Ecore_Timer *pw_timer;
27    Eina_List *sel;
28    Eina_List *anchors;
29    Eina_List *anchorlist;
30    Eina_List *itemlist;
31    char *selection;
32    Eina_Bool selecting : 1;
33    Eina_Bool have_selection : 1;
34    Eina_Bool select_allow : 1;
35    Eina_Bool select_mod_start : 1;
36    Eina_Bool select_mod_end : 1;
37    Eina_Bool had_sel : 1;
38
39 #ifdef HAVE_ECORE_IMF
40    Eina_Bool have_preedit : 1;
41    Ecore_IMF_Context *imf_context;
42
43    Ecore_Event_Handler *imf_ee_handler_commit;
44    Ecore_Event_Handler *imf_ee_handler_delete;
45    Ecore_Event_Handler *imf_ee_handler_changed;
46 #endif
47 };
48
49 struct _Sel
50 {
51    Evas_Textblock_Rectangle rect;
52    Evas_Object *obj_fg, *obj_bg, *obj, *sobj;
53 };
54
55 struct _Anchor
56 {
57    Entry *en;
58    char *name;
59    Evas_Textblock_Cursor *start, *end;
60    Eina_List *sel;
61    Eina_Bool item : 1;
62 };
63
64 #ifdef HAVE_ECORE_IMF
65 static void
66 _preedit_clear(Entry *en)
67 {
68    if (en->preedit_start)
69      {
70         evas_textblock_cursor_free(en->preedit_start);
71         en->preedit_start = NULL;
72      }
73
74    if (en->preedit_end)
75      {
76         evas_textblock_cursor_free(en->preedit_end);
77         en->preedit_end = NULL;
78      }
79
80    en->have_preedit = EINA_FALSE;
81 }
82
83 static void
84 _preedit_del(Entry *en)
85 {
86    if (!en || !en->have_preedit) return;
87    if (!en->preedit_start || !en->preedit_end) return;
88    if (!evas_textblock_cursor_compare(en->preedit_start, en->preedit_end)) return;
89
90    /* delete the preedit characters */
91    evas_textblock_cursor_range_delete(en->preedit_start, en->preedit_end);
92 }
93
94 static void
95 _edje_entry_focus_in_cb(void *data, Evas_Object *o __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
96 {
97    Edje_Real_Part *rp;
98    Entry *en;
99
100    rp = data;
101    if (!rp || !rp->entry_data || !rp->edje || !rp->edje->obj) return;
102
103    en = rp->entry_data;
104    if (!en || !en->imf_context) return;
105
106    if (evas_object_focus_get(rp->edje->obj))
107      {
108         ecore_imf_context_reset(en->imf_context);
109         ecore_imf_context_focus_in(en->imf_context);
110         _edje_entry_imf_cursor_info_set(en);
111      }
112 }
113
114 static void
115 _edje_entry_focus_out_cb(void *data, Evas_Object *o __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
116 {
117    Edje_Real_Part *rp;
118    Entry *en;
119
120    rp = data;
121    if (!rp || !rp->entry_data) return;
122
123    en = rp->entry_data;
124    if (!en || !en->imf_context) return;
125
126    ecore_imf_context_reset(en->imf_context);
127    _edje_entry_imf_cursor_info_set(en);
128    ecore_imf_context_focus_out(en->imf_context);
129 }
130 #endif
131
132 static void
133 _edje_focus_in_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
134 {
135    Edje *ed = data;
136 #ifdef HAVE_ECORE_IMF
137    Edje_Real_Part *rp;
138    Entry *en;
139 #endif
140
141    _edje_emit(ed, "focus,in", "");
142 #ifdef HAVE_ECORE_IMF
143    rp = ed->focused_part;
144    if (!rp) return;
145
146    en = rp->entry_data;
147    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
148        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_EDITABLE))
149      return;
150
151    if (!en->imf_context) return;
152
153    ecore_imf_context_reset(en->imf_context);
154    ecore_imf_context_focus_in(en->imf_context);
155    _edje_entry_imf_cursor_info_set(en);
156 #endif
157 }
158
159 static void
160 _edje_focus_out_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
161 {
162    Edje *ed = data;
163 #ifdef HAVE_ECORE_IMF
164    Edje_Real_Part *rp = ed->focused_part;
165    Entry *en;
166 #endif
167
168    _edje_emit(ed, "focus,out", "");
169
170 #ifdef HAVE_ECORE_IMF
171    if (!rp) return;
172    en = rp->entry_data;
173    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
174        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_EDITABLE))
175      return;
176
177    if (!en->imf_context) return;
178
179    ecore_imf_context_reset(en->imf_context);
180    _edje_entry_imf_cursor_info_set(en);
181    ecore_imf_context_focus_out(en->imf_context);
182 #endif
183 }
184
185 static void
186 _text_filter_text_prepend(Entry *en, Evas_Textblock_Cursor *c, const char *text)
187 {
188    char *text2;
189    Edje_Text_Insert_Filter_Callback *cb;
190    Eina_List *l;
191
192    text2 = strdup(text);
193    EINA_LIST_FOREACH(en->rp->edje->text_insert_filter_callbacks, l, cb)
194      {
195         if (!strcmp(cb->part, en->rp->part->name))
196           {
197              cb->func(cb->data, en->rp->edje->obj, cb->part, EDJE_TEXT_FILTER_TEXT, &text2);
198              if (!text2) break;
199           }
200      }
201    if (text2)
202      {
203         evas_textblock_cursor_text_prepend(c, text2);
204         free(text2);
205      }
206 }
207
208 static void
209 _text_filter_format_prepend(Entry *en, Evas_Textblock_Cursor *c, const char *text)
210 {
211    char *text2;
212    Edje_Text_Insert_Filter_Callback *cb;
213    Eina_List *l;
214
215    text2 = strdup(text);
216    EINA_LIST_FOREACH(en->rp->edje->text_insert_filter_callbacks, l, cb)
217      {
218         if (!strcmp(cb->part, en->rp->part->name))
219           {
220              cb->func(cb->data, en->rp->edje->obj, cb->part, EDJE_TEXT_FILTER_FORMAT, &text2);
221              if (!text2) break;
222           }
223      }
224    if (text2)
225      {
226         evas_textblock_cursor_format_prepend(c, text2);
227         free(text2);
228      }
229 }
230
231 static void
232 _text_filter_markup_prepend(Entry *en, Evas_Textblock_Cursor *c, const char *text)
233 {
234    char *text2;
235    Edje_Text_Insert_Filter_Callback *cb;
236    Eina_List *l;
237
238    text2 = strdup(text);
239    EINA_LIST_FOREACH(en->rp->edje->text_insert_filter_callbacks, l, cb)
240      {
241         if (!strcmp(cb->part, en->rp->part->name))
242           {
243              cb->func(cb->data, en->rp->edje->obj, cb->part, EDJE_TEXT_FILTER_MARKUP, &text2);
244              if (!text2) break;
245           }
246      }
247    if (text2)
248      {
249         evas_object_textblock_text_markup_prepend(c, text2);
250         free(text2);
251      }
252 }
253
254 static void
255 _curs_update_from_curs(Evas_Textblock_Cursor *c, Evas_Object *o __UNUSED__, Entry *en, Evas_Coord *cx, Evas_Coord *cy)
256 {
257    Evas_Coord cw, ch;
258    Evas_Textblock_Cursor_Type cur_type;
259    if (c != en->cursor) return;
260    switch (en->rp->part->cursor_mode)
261      {
262       case EDJE_ENTRY_CURSOR_MODE_BEFORE:
263          cur_type = EVAS_TEXTBLOCK_CURSOR_BEFORE;
264          break;
265       case EDJE_ENTRY_CURSOR_MODE_UNDER:
266          /* no break for a resaon */
267       default:
268          cur_type = EVAS_TEXTBLOCK_CURSOR_UNDER;
269      }
270    evas_textblock_cursor_geometry_get(c, cx, cy, &cw, &ch, NULL, cur_type);
271    *cx += (cw / 2);
272    *cy += (ch / 2);
273 }
274
275 static int
276 _curs_line_last_get(Evas_Textblock_Cursor *c __UNUSED__, Evas_Object *o, Entry *en __UNUSED__)
277 {
278    Evas_Textblock_Cursor *cc;
279    int ln;
280
281    cc = evas_object_textblock_cursor_new(o);
282    evas_textblock_cursor_paragraph_last(cc);
283    ln = evas_textblock_cursor_line_geometry_get(cc, NULL, NULL, NULL, NULL);
284    evas_textblock_cursor_free(cc);
285    return ln;
286 }
287
288 static void
289 _curs_lin_start(Evas_Textblock_Cursor *c, Evas_Object *o __UNUSED__,
290                 Entry *en __UNUSED__)
291 {
292    evas_textblock_cursor_line_char_first(c);
293 }
294
295 static void
296 _curs_lin_end(Evas_Textblock_Cursor *c, Evas_Object *o __UNUSED__,
297               Entry *en __UNUSED__)
298 {
299    evas_textblock_cursor_line_char_last(c);
300 }
301
302 static void
303 _curs_start(Evas_Textblock_Cursor *c, Evas_Object *o __UNUSED__,
304             Entry *en __UNUSED__)
305 {
306    evas_textblock_cursor_paragraph_first(c);
307 }
308
309 static void
310 _curs_end(Evas_Textblock_Cursor *c, Evas_Object *o __UNUSED__, Entry *en __UNUSED__)
311 {
312    evas_textblock_cursor_paragraph_last(c);
313 }
314
315 static void
316 _curs_jump_line(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en, int ln)
317 {
318    Evas_Coord cx, cy;
319    Evas_Coord lx, ly, lw, lh;
320    int last = _curs_line_last_get(c, o, en);
321
322    if (ln < 0) ln = 0;
323    else
324      {
325         if (ln > last) ln = last;
326      }
327
328    _curs_update_from_curs(c, o, en, &cx, &cy);
329
330    if (!evas_object_textblock_line_number_geometry_get(o, ln, &lx, &ly, &lw, &lh))
331      return;
332    if (evas_textblock_cursor_char_coord_set(c, cx, ly + (lh / 2)))
333      return;
334    evas_textblock_cursor_line_set(c, ln);
335    if (cx < (lx + (lw / 2)))
336      {
337         if (ln == last) _curs_end(c, o, en);
338         _curs_lin_start(c, o, en);
339      }
340    else
341      {
342         if (ln == last)
343           _curs_end(c, o, en);
344         else
345           _curs_lin_end(c, o, en);
346      }
347 }
348
349 static void
350 _curs_jump_line_by(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en, int by)
351 {
352    int ln;
353
354    ln = evas_textblock_cursor_line_geometry_get(c, NULL, NULL, NULL, NULL) + by;
355    _curs_jump_line(c, o, en, ln);
356 }
357
358 static void
359 _curs_up(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en)
360 {
361    _curs_jump_line_by(c, o, en, -1);
362 }
363
364 static void
365 _curs_down(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en)
366 {
367    _curs_jump_line_by(c, o, en, 1);
368 }
369
370 static void
371 _sel_start(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en)
372 {
373    if (en->sel_start) return;
374    en->sel_start = evas_object_textblock_cursor_new(o);
375    evas_textblock_cursor_copy(c, en->sel_start);
376    en->sel_end = evas_object_textblock_cursor_new(o);
377    evas_textblock_cursor_copy(c, en->sel_end);
378
379    en->have_selection = EINA_FALSE;
380    if (en->selection)
381      {
382         free(en->selection);
383         en->selection = NULL;
384      }
385 }
386
387 static void
388 _sel_enable(Evas_Textblock_Cursor *c __UNUSED__, Evas_Object *o __UNUSED__, Entry *en)
389 {
390    if (en->have_selection) return;
391    en->have_selection = EINA_TRUE;
392    if (en->selection)
393      {
394         free(en->selection);
395         en->selection = NULL;
396      }
397    _edje_emit(en->rp->edje, "selection,start", en->rp->part->name);
398 }
399
400 static void
401 _sel_extend(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en)
402 {
403    if (!en->sel_end) return;
404    _sel_enable(c, o, en);
405    if (!evas_textblock_cursor_compare(c, en->sel_end)) return;
406    evas_textblock_cursor_copy(c, en->sel_end);
407    if (en->selection)
408      {
409         free(en->selection);
410         en->selection = NULL;
411      }
412    _edje_emit(en->rp->edje, "selection,changed", en->rp->part->name);
413    _edje_entry_imf_context_reset(en);
414 }
415
416 static void
417 _sel_preextend(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en)
418 {
419    if (!en->sel_end) return;
420    _sel_enable(c, o, en);
421    if (!evas_textblock_cursor_compare(c, en->sel_start)) return;
422    evas_textblock_cursor_copy(c, en->sel_start);
423    if (en->selection)
424      {
425         free(en->selection);
426         en->selection = NULL;
427      }
428    _edje_emit(en->rp->edje, "selection,changed", en->rp->part->name);
429    _edje_entry_imf_context_reset(en);
430 }
431
432 static void
433 _sel_clear(Evas_Textblock_Cursor *c __UNUSED__, Evas_Object *o __UNUSED__, Entry *en)
434 {
435    en->had_sel = EINA_FALSE;
436    if (en->sel_start)
437      {
438         evas_textblock_cursor_free(en->sel_start);
439         evas_textblock_cursor_free(en->sel_end);
440         en->sel_start = NULL;
441         en->sel_end = NULL;
442      }
443    if (en->selection)
444      {
445         free(en->selection);
446         en->selection = NULL;
447      }
448    while (en->sel)
449      {
450         Sel *sel;
451
452         sel = en->sel->data;
453         if (sel->obj_bg) evas_object_del(sel->obj_bg);
454         if (sel->obj_fg) evas_object_del(sel->obj_fg);
455         free(sel);
456         en->sel = eina_list_remove_list(en->sel, en->sel);
457      }
458    if (en->have_selection)
459      {
460         en->have_selection = EINA_FALSE;
461         _edje_emit(en->rp->edje, "selection,cleared", en->rp->part->name);
462      }
463 }
464
465 static void
466 _sel_update(Evas_Textblock_Cursor *c __UNUSED__, Evas_Object *o, Entry *en)
467 {
468    Eina_List *range = NULL, *l;
469    Sel *sel;
470    Evas_Coord x, y, w, h;
471    Evas_Object *smart, *clip;
472
473    smart = evas_object_smart_parent_get(o);
474    clip = evas_object_clip_get(o);
475    if (en->sel_start)
476      range = evas_textblock_cursor_range_geometry_get(en->sel_start, en->sel_end);
477    else
478      return;
479    if (eina_list_count(range) != eina_list_count(en->sel))
480      {
481         while (en->sel)
482           {
483              sel = en->sel->data;
484              if (sel->obj_bg) evas_object_del(sel->obj_bg);
485              if (sel->obj_fg) evas_object_del(sel->obj_fg);
486              free(sel);
487              en->sel = eina_list_remove_list(en->sel, en->sel);
488           }
489         if (en->have_selection)
490           {
491              for (l = range; l; l = eina_list_next(l))
492                {
493                   Evas_Object *ob;
494
495                   sel = calloc(1, sizeof(Sel));
496                   en->sel = eina_list_append(en->sel, sel);
497                   ob = edje_object_add(en->rp->edje->base.evas);
498                   edje_object_file_set(ob, en->rp->edje->path, en->rp->part->source);
499                   evas_object_smart_member_add(ob, smart);
500                   evas_object_stack_below(ob, o);
501                   evas_object_clip_set(ob, clip);
502                   evas_object_pass_events_set(ob, EINA_TRUE);
503                   evas_object_show(ob);
504                   sel->obj_bg = ob;
505                   _edje_subobj_register(en->rp->edje, sel->obj_bg);
506
507                   ob = edje_object_add(en->rp->edje->base.evas);
508                   edje_object_file_set(ob, en->rp->edje->path, en->rp->part->source2);
509                   evas_object_smart_member_add(ob, smart);
510                   evas_object_stack_above(ob, o);
511                   evas_object_clip_set(ob, clip);
512                   evas_object_pass_events_set(ob, EINA_TRUE);
513                   evas_object_show(ob);
514                   sel->obj_fg = ob;
515                   _edje_subobj_register(en->rp->edje, sel->obj_fg);
516                }
517           }
518      }
519    x = y = w = h = -1;
520    evas_object_geometry_get(o, &x, &y, &w, &h);
521    if (en->have_selection)
522      {
523         EINA_LIST_FOREACH(en->sel, l, sel)
524           {
525              Evas_Textblock_Rectangle *r;
526
527              r = range->data;
528              if (sel->obj_bg)
529                {
530                   evas_object_move(sel->obj_bg, x + r->x, y + r->y);
531                   evas_object_resize(sel->obj_bg, r->w, r->h);
532                }
533              if (sel->obj_fg)
534                {
535                   evas_object_move(sel->obj_fg, x + r->x, y + r->y);
536                   evas_object_resize(sel->obj_fg, r->w, r->h);
537                }
538              *(&(sel->rect)) = *r;
539              range = eina_list_remove_list(range, range);
540              free(r);
541           }
542      }
543    else
544      {
545         while (range)
546           {
547              free(range->data);
548              range = eina_list_remove_list(range, range);
549           }
550      }
551 }
552
553 static void
554 _edje_anchor_mouse_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
555 {
556    Anchor *an = data;
557    Evas_Event_Mouse_Down *ev = event_info;
558    Edje_Real_Part *rp = an->en->rp;
559    char *buf, *n;
560    size_t len;
561    int ignored;
562    Entry *en;
563
564    en = rp->entry_data;
565    if ((rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_EXPLICIT) &&
566        (en->select_allow))
567      return;
568    ignored = rp->part->ignore_flags & ev->event_flags;
569    if ((!ev->event_flags) || (!ignored))
570      {
571         n = an->name;
572         if (!n) n = "";
573         len = 200 + strlen(n);
574         buf = alloca(len);
575         if (ev->flags & EVAS_BUTTON_TRIPLE_CLICK)
576           snprintf(buf, len, "anchor,mouse,down,%i,%s,triple", ev->button, n);
577         else if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
578           snprintf(buf, len, "anchor,mouse,down,%i,%s,double", ev->button, n);
579         else
580           snprintf(buf, len, "anchor,mouse,down,%i,%s", ev->button, n);
581         _edje_emit(rp->edje, buf, rp->part->name);
582      }
583 }
584
585 static void
586 _edje_anchor_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
587 {
588    Anchor *an = data;
589    Evas_Event_Mouse_Up *ev = event_info;
590    Edje_Real_Part *rp = an->en->rp;
591    char *buf, *n;
592    size_t len;
593    int ignored;
594    Entry *en;
595
596    en = rp->entry_data;
597    ignored = rp->part->ignore_flags & ev->event_flags;
598    if ((rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_EXPLICIT) &&
599        (en->select_allow))
600      return;
601    n = an->name;
602    if (!n) n = "";
603    len = 200 + strlen(n);
604    buf = alloca(len);
605    if ((!ev->event_flags) || (!ignored))
606      {
607         snprintf(buf, len, "anchor,mouse,up,%i,%s", ev->button, n);
608         _edje_emit(rp->edje, buf, rp->part->name);
609      }
610    if ((rp->still_in) && (rp->clicked_button == ev->button) && (!ignored))
611      {
612         snprintf(buf, len, "anchor,mouse,clicked,%i,%s", ev->button, n);
613         _edje_emit(rp->edje, buf, rp->part->name);
614      }
615 }
616
617 static void
618 _edje_anchor_mouse_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
619 {
620    Anchor *an = data;
621    Evas_Event_Mouse_Move *ev = event_info;
622    Edje_Real_Part *rp = an->en->rp;
623    char *buf, *n;
624    size_t len;
625    int ignored;
626    Entry *en;
627
628    en = rp->entry_data;
629    if ((rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_EXPLICIT) &&
630        (en->select_allow))
631      return;
632    ignored = rp->part->ignore_flags & ev->event_flags;
633    if ((!ev->event_flags) || (!ignored))
634      {
635         n = an->name;
636         if (!n) n = "";
637         len = 200 + strlen(n);
638         buf = alloca(len);
639         snprintf(buf, len, "anchor,mouse,move,%s", n);
640         _edje_emit(rp->edje, buf, rp->part->name);
641      }
642 }
643
644 static void
645 _edje_anchor_mouse_in_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
646 {
647    Anchor *an = data;
648    Evas_Event_Mouse_In *ev = event_info;
649    Edje_Real_Part *rp = an->en->rp;
650    char *buf, *n;
651    size_t len;
652    int ignored;
653
654    ignored = rp->part->ignore_flags & ev->event_flags;
655    if ((!ev->event_flags) || (!ignored))
656      {
657         n = an->name;
658         if (!n) n = "";
659         len = 200 + strlen(n);
660         buf = alloca(len);
661         snprintf(buf, len, "anchor,mouse,in,%s", n);
662         _edje_emit(rp->edje, buf, rp->part->name);
663      }
664 }
665
666 static void
667 _edje_anchor_mouse_out_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
668 {
669    Anchor *an = data;
670    Evas_Event_Mouse_Out *ev = event_info;
671    Edje_Real_Part *rp = an->en->rp;
672    char *buf, *n;
673    size_t len;
674    int ignored;
675
676    ignored = rp->part->ignore_flags & ev->event_flags;
677    if ((!ev->event_flags) || (!ignored))
678      {
679         n = an->name;
680         if (!n) n = "";
681         len = 200 + strlen(n);
682         buf = alloca(len);
683         snprintf(buf, len, "anchor,mouse,out,%s", n);
684         _edje_emit(rp->edje, buf, rp->part->name);
685      }
686 }
687
688 static void
689 _anchors_update(Evas_Textblock_Cursor *c __UNUSED__, Evas_Object *o, Entry *en)
690 {
691    Eina_List *l, *ll, *range = NULL;
692    Evas_Coord x, y, w, h;
693    Evas_Object *smart, *clip;
694    Sel *sel;
695    Anchor *an;
696
697    smart = evas_object_smart_parent_get(o);
698    clip = evas_object_clip_get(o);
699    x = y = w = h = -1;
700    evas_object_geometry_get(o, &x, &y, &w, &h);
701    EINA_LIST_FOREACH(en->anchors, l, an)
702      {
703         // for item anchors
704         if (an->item)
705           {
706              Evas_Object *ob;
707
708              if (!an->sel)
709                {
710                   while (an->sel)
711                     {
712                        sel = an->sel->data;
713                        if (sel->obj_bg) evas_object_del(sel->obj_bg);
714                        if (sel->obj_fg) evas_object_del(sel->obj_fg);
715                        if (sel->obj) evas_object_del(sel->obj);
716                        free(sel);
717                        an->sel = eina_list_remove_list(an->sel, an->sel);
718                     }
719
720                   sel = calloc(1, sizeof(Sel));
721                   an->sel = eina_list_append(an->sel, sel);
722
723                   if (en->rp->edje->item_provider.func)
724                     {
725                        ob = en->rp->edje->item_provider.func
726                          (en->rp->edje->item_provider.data, smart, 
727                              en->rp->part->name, an->name);
728                        evas_object_smart_member_add(ob, smart);
729                        evas_object_stack_above(ob, o);
730                        evas_object_clip_set(ob, clip);
731                        evas_object_pass_events_set(ob, EINA_TRUE);
732                        evas_object_show(ob);
733                        sel->obj = ob;
734                     }
735                }
736           }
737         // for link anchors
738         else
739           {
740              range = 
741                evas_textblock_cursor_range_geometry_get(an->start, an->end);
742              if (eina_list_count(range) != eina_list_count(an->sel))
743                {
744                   while (an->sel)
745                     {
746                        sel = an->sel->data;
747                        if (sel->obj_bg) evas_object_del(sel->obj_bg);
748                        if (sel->obj_fg) evas_object_del(sel->obj_fg);
749                        if (sel->obj) evas_object_del(sel->obj);
750                        free(sel);
751                        an->sel = eina_list_remove_list(an->sel, an->sel);
752                     }
753                   for (ll = range; ll; ll = eina_list_next(ll))
754                     {
755                        Evas_Object *ob;
756
757                        sel = calloc(1, sizeof(Sel));
758                        an->sel = eina_list_append(an->sel, sel);
759                        ob = edje_object_add(en->rp->edje->base.evas);
760                        edje_object_file_set(ob, en->rp->edje->path, en->rp->part->source5);
761                        evas_object_smart_member_add(ob, smart);
762                        evas_object_stack_below(ob, o);
763                        evas_object_clip_set(ob, clip);
764                        evas_object_pass_events_set(ob, EINA_TRUE);
765                        evas_object_show(ob);
766                        sel->obj_bg = ob;
767                        _edje_subobj_register(en->rp->edje, sel->obj_bg);
768
769                        ob = edje_object_add(en->rp->edje->base.evas);
770                        edje_object_file_set(ob, en->rp->edje->path, en->rp->part->source6);
771                        evas_object_smart_member_add(ob, smart);
772                        evas_object_stack_above(ob, o);
773                        evas_object_clip_set(ob, clip);
774                        evas_object_pass_events_set(ob, EINA_TRUE);
775                        evas_object_show(ob);
776                        sel->obj_fg = ob;
777                        _edje_subobj_register(en->rp->edje, sel->obj_fg);
778
779                        ob = evas_object_rectangle_add(en->rp->edje->base.evas);
780                        evas_object_color_set(ob, 0, 0, 0, 0);
781                        evas_object_smart_member_add(ob, smart);
782                        evas_object_stack_above(ob, o);
783                        evas_object_clip_set(ob, clip);
784                        evas_object_repeat_events_set(ob, EINA_TRUE);
785                        evas_object_event_callback_add(ob, EVAS_CALLBACK_MOUSE_DOWN, _edje_anchor_mouse_down_cb, an);
786                        evas_object_event_callback_add(ob, EVAS_CALLBACK_MOUSE_UP, _edje_anchor_mouse_up_cb, an);
787                        evas_object_event_callback_add(ob, EVAS_CALLBACK_MOUSE_MOVE, _edje_anchor_mouse_move_cb, an);
788                        evas_object_event_callback_add(ob, EVAS_CALLBACK_MOUSE_IN, _edje_anchor_mouse_in_cb, an);
789                        evas_object_event_callback_add(ob, EVAS_CALLBACK_MOUSE_OUT, _edje_anchor_mouse_out_cb, an);
790                        evas_object_show(ob);
791                        sel->obj = ob;
792                     }
793                }
794           }
795         EINA_LIST_FOREACH(an->sel, ll, sel)
796           {
797              if (an->item)
798                {
799                   Evas_Coord cx, cy, cw, ch;
800
801                   if (!evas_textblock_cursor_format_item_geometry_get
802                       (an->start, &cx, &cy, &cw, &ch))
803                     continue;
804                   evas_object_move(sel->obj, x + cx, y + cy);
805                   evas_object_resize(sel->obj, cw, ch);
806                }
807              else
808                {
809                   Evas_Textblock_Rectangle *r;
810
811                   r = range->data;
812                   *(&(sel->rect)) = *r;
813                   if (sel->obj_bg)
814                     {
815                        evas_object_move(sel->obj_bg, x + r->x, y + r->y);
816                        evas_object_resize(sel->obj_bg, r->w, r->h);
817                     }
818                   if (sel->obj_fg)
819                     {
820                        evas_object_move(sel->obj_fg, x + r->x, y + r->y);
821                        evas_object_resize(sel->obj_fg, r->w, r->h);
822                     }
823                   if (sel->obj)
824                     {
825                        evas_object_move(sel->obj, x + r->x, y + r->y);
826                        evas_object_resize(sel->obj, r->w, r->h);
827                     }
828                   range = eina_list_remove_list(range, range);
829                   free(r);
830                }
831           }
832      }
833 }
834
835 static void
836 _anchors_clear(Evas_Textblock_Cursor *c __UNUSED__, Evas_Object *o __UNUSED__, Entry *en)
837 {
838    while (en->anchorlist)
839      {
840         free(en->anchorlist->data);
841         en->anchorlist = eina_list_remove_list(en->anchorlist, en->anchorlist);
842      }
843    while (en->itemlist)
844      {
845         free(en->itemlist->data);
846         en->itemlist = eina_list_remove_list(en->itemlist, en->itemlist);
847      }
848    while (en->anchors)
849      {
850         Anchor *an = en->anchors->data;
851
852         evas_textblock_cursor_free(an->start);
853         evas_textblock_cursor_free(an->end);
854         while (an->sel)
855           {
856              Sel *sel = an->sel->data;
857              if (sel->obj_bg) evas_object_del(sel->obj_bg);
858              if (sel->obj_fg) evas_object_del(sel->obj_fg);
859              if (sel->obj) evas_object_del(sel->obj);
860              free(sel);
861              an->sel = eina_list_remove_list(an->sel, an->sel);
862           }
863         free(an->name);
864         free(an);
865         en->anchors = eina_list_remove_list(en->anchors, en->anchors);
866      }
867 }
868
869 static void
870 _anchors_get(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en)
871 {
872    const Eina_List *anchors_a, *anchors_item;
873    Anchor *an = NULL;
874    _anchors_clear(c, o, en);
875
876    anchors_a = evas_textblock_node_format_list_get(o, "a");
877    anchors_item = evas_textblock_node_format_list_get(o, "item");
878
879    if (anchors_a)
880      {
881         const Evas_Object_Textblock_Node_Format *node;
882         const Eina_List *itr;
883         EINA_LIST_FOREACH(anchors_a, itr, node)
884           {
885              const char *s = evas_textblock_node_format_text_get(node);
886              char *p;
887              an = calloc(1, sizeof(Anchor));
888              if (!an)
889                 break;
890
891              an->en = en;
892              p = strstr(s, "href=");
893              if (p)
894                {
895                   an->name = strdup(p + 5);
896                }
897              en->anchors = eina_list_append(en->anchors, an);
898              an->start = evas_object_textblock_cursor_new(o);
899              an->end = evas_object_textblock_cursor_new(o);
900              evas_textblock_cursor_at_format_set(an->start, node);
901              evas_textblock_cursor_copy(an->start, an->end);
902
903              /* Close the anchor, if the anchor was without text,
904               * free it as well */
905              node = evas_textblock_node_format_next_get(node);
906              for (; node; node = evas_textblock_node_format_next_get(node))
907                {
908                   s = evas_textblock_node_format_text_get(node);
909                   if ((!strcmp(s, "- a")) || (!strcmp(s, "-a")))
910                      break;
911                }
912
913              if (node)
914                {
915                   evas_textblock_cursor_at_format_set(an->end, node);
916                }
917              else if (!evas_textblock_cursor_compare(an->start, an->end))
918                {
919                   if (an->name) free(an->name);
920                   evas_textblock_cursor_free(an->start);
921                   evas_textblock_cursor_free(an->end);
922                   en->anchors = eina_list_remove(en->anchors, an);
923                   free(an);
924                }
925              an = NULL;
926           }
927      }
928
929    if (anchors_item)
930      {
931         const Evas_Object_Textblock_Node_Format *node;
932         const Eina_List *itr;
933         EINA_LIST_FOREACH(anchors_item, itr, node)
934           {
935              const char *s = evas_textblock_node_format_text_get(node);
936              char *p;
937              an = calloc(1, sizeof(Anchor));
938              if (!an)
939                 break;
940
941              an->en = en;
942              an->item = 1;
943              p = strstr(s, "href=");
944              if (p)
945                {
946                   an->name = strdup(p + 5);
947                }
948              en->anchors = eina_list_append(en->anchors, an);
949              an->start = evas_object_textblock_cursor_new(o);
950              an->end = evas_object_textblock_cursor_new(o);
951              evas_textblock_cursor_at_format_set(an->start, node);
952              evas_textblock_cursor_copy(an->start, an->end);
953              /* Although needed in textblock, don't bother with finding the end
954               * here cause it doesn't really matter. */
955           }
956      }
957 }
958
959 static void
960 _free_entry_change_info(void *_info)
961 {
962    Edje_Entry_Change_Info *info = (Edje_Entry_Change_Info *) _info;
963    if (info->insert)
964      {
965         eina_stringshare_del(info->change.insert.content);
966      }
967    else
968      {
969         eina_stringshare_del(info->change.del.content);
970      }
971    free(info);
972 }
973
974 static void
975 _range_del_emit(Edje *ed, Evas_Textblock_Cursor *c __UNUSED__, Evas_Object *o __UNUSED__, Entry *en)
976 {
977    size_t start, end;
978    char *tmp;
979    Edje_Entry_Change_Info *info = calloc(1, sizeof(*info));
980    info->insert = EINA_FALSE;
981    start = evas_textblock_cursor_pos_get(en->sel_start);
982    end = evas_textblock_cursor_pos_get(en->sel_end);
983    info->change.del.start = start;
984    info->change.del.end = end;
985
986    tmp = evas_textblock_cursor_range_text_get(en->sel_start, en->sel_end, EVAS_TEXTBLOCK_TEXT_MARKUP);
987    info->change.del.content = eina_stringshare_add(tmp);
988    if (tmp) free(tmp);
989    evas_textblock_cursor_range_delete(en->sel_start, en->sel_end);
990    _edje_emit(ed, "entry,changed", en->rp->part->name);
991    _edje_emit_full(ed, "entry,changed,user", en->rp->part->name, info,
992                    _free_entry_change_info);
993 }
994
995 static void
996 _range_del(Evas_Textblock_Cursor *c __UNUSED__, Evas_Object *o __UNUSED__, Entry *en)
997 {
998    evas_textblock_cursor_range_delete(en->sel_start, en->sel_end);
999 }
1000
1001 static void
1002 _delete_emit(Edje *ed, Evas_Textblock_Cursor *c, Entry *en, size_t pos,
1003              Eina_Bool backspace)
1004 {
1005    if (!evas_textblock_cursor_char_next(c))
1006      {
1007         return;
1008      }
1009    evas_textblock_cursor_char_prev(c);
1010
1011    Edje_Entry_Change_Info *info = calloc(1, sizeof(*info));
1012    char *tmp = evas_textblock_cursor_content_get(c);
1013
1014    info->insert = EINA_FALSE;
1015    if (backspace)
1016      {
1017         info->change.del.start = pos - 1;
1018         info->change.del.end = pos;
1019      }
1020    else
1021      {
1022         info->change.del.start = pos + 1;
1023         info->change.del.end = pos;
1024      }
1025
1026    info->change.del.content = eina_stringshare_add(tmp);
1027    if (tmp) free(tmp);
1028
1029    evas_textblock_cursor_char_delete(c);
1030    _edje_emit(ed, "entry,changed", en->rp->part->name);
1031    _edje_emit_full(ed, "entry,changed,user", en->rp->part->name,
1032                    info, _free_entry_change_info);
1033 }
1034
1035 static void
1036 _edje_entry_hide_visible_password(Edje_Real_Part *rp)
1037 {
1038    const Evas_Object_Textblock_Node_Format *node;
1039    node = evas_textblock_node_format_first_get(rp->object);
1040    for (; node; node = evas_textblock_node_format_next_get(node))
1041      {
1042         const char *text = evas_textblock_node_format_text_get(node);
1043         if (text)
1044           {
1045              if (!strcmp(text, "+ password=off"))
1046                {
1047                   evas_textblock_node_format_remove_pair(rp->object,
1048                                                         (Evas_Object_Textblock_Node_Format *) node);
1049                   break;
1050                }
1051           }
1052      }
1053    _edje_entry_real_part_configure(rp);
1054    _edje_emit(rp->edje, "entry,changed", rp->part->name);
1055 }
1056
1057 static Eina_Bool
1058 _password_timer_cb(void *data)
1059 {
1060    Entry *en = (Entry *)data;
1061    _edje_entry_hide_visible_password(en->rp);
1062    en->pw_timer = NULL;
1063    return ECORE_CALLBACK_CANCEL;
1064 }
1065
1066 static void
1067 _edje_key_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1068 {
1069    Edje *ed = data;
1070    Evas_Event_Key_Down *ev = event_info;
1071    Edje_Real_Part *rp = ed->focused_part;
1072    Entry *en;
1073    Eina_Bool control, alt, shift;
1074    Eina_Bool multiline;
1075    Eina_Bool cursor_changed;
1076    int old_cur_pos;
1077    if (!rp) return;
1078    en = rp->entry_data;
1079    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
1080        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_EDITABLE))
1081      return;
1082    if (!ev->key) return;
1083
1084 #ifdef HAVE_ECORE_IMF
1085    if (en->imf_context)
1086      {
1087         Ecore_IMF_Event_Key_Down ecore_ev;
1088         ecore_imf_evas_event_key_down_wrap(ev, &ecore_ev);
1089         if (ecore_imf_context_filter_event(en->imf_context,
1090                                            ECORE_IMF_EVENT_KEY_DOWN,
1091                                            (Ecore_IMF_Event *)&ecore_ev))
1092           return;
1093      }
1094 #endif
1095
1096    old_cur_pos = evas_textblock_cursor_pos_get(en->cursor);
1097
1098    control = evas_key_modifier_is_set(ev->modifiers, "Control");
1099    alt = evas_key_modifier_is_set(ev->modifiers, "Alt");
1100    shift = evas_key_modifier_is_set(ev->modifiers, "Shift");
1101    multiline = rp->part->multiline;
1102    cursor_changed = EINA_FALSE;
1103    if (!strcmp(ev->key, "Escape"))
1104      {
1105         // dead keys here. Escape for now (should emit these)
1106         _edje_emit(ed, "entry,key,escape", rp->part->name);
1107         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1108      }
1109    else if (!strcmp(ev->key, "Up") || !strcmp(ev->key, "KP_Up"))
1110      {
1111         if (multiline)
1112           {
1113              if (en->select_allow)
1114                {
1115                   if (shift) _sel_start(en->cursor, rp->object, en);
1116                   else _sel_clear(en->cursor, rp->object, en);
1117                }
1118              _curs_up(en->cursor, rp->object, en);
1119              if (en->select_allow)
1120                {
1121                   if (shift) _sel_extend(en->cursor, rp->object, en);
1122                }
1123              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1124           }
1125         _sel_clear(en->cursor, rp->object, en);
1126         _edje_emit(ed, "entry,key,up", rp->part->name);
1127         _edje_emit(rp->edje, "cursor,changed,manual", rp->part->name);
1128      }
1129    else if (!strcmp(ev->key, "Down") || !strcmp(ev->key, "KP_Down"))
1130      {
1131         if (multiline)
1132           {
1133              if (en->select_allow)
1134                {
1135                   if (shift) _sel_start(en->cursor, rp->object, en);
1136                   else _sel_clear(en->cursor, rp->object, en);
1137                }
1138              _curs_down(en->cursor, rp->object, en);
1139              if (en->select_allow)
1140                {
1141                   if (shift) _sel_extend(en->cursor, rp->object, en);
1142                }
1143              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1144           }
1145         _sel_clear(en->cursor, rp->object, en);
1146         _edje_emit(ed, "entry,key,down", rp->part->name);
1147         _edje_emit(rp->edje, "cursor,changed,manual", rp->part->name);
1148      }
1149    else if (!strcmp(ev->key, "Left") || !strcmp(ev->key, "KP_Left"))
1150      {
1151         if (en->select_allow)
1152           {
1153              if (shift) _sel_start(en->cursor, rp->object, en);
1154              else _sel_clear(en->cursor, rp->object, en);
1155           }
1156         evas_textblock_cursor_char_prev(en->cursor);
1157         /* If control is pressed, go to the start of the word */
1158         if (control) evas_textblock_cursor_word_start(en->cursor);
1159         if (en->select_allow)
1160           {
1161              if (shift) _sel_extend(en->cursor, rp->object, en);
1162           }
1163         _sel_clear(en->cursor, rp->object, en);
1164         _edje_emit(ed, "entry,key,left", rp->part->name);
1165         _edje_emit(rp->edje, "cursor,changed,manual", rp->part->name);
1166         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1167      }
1168    else if (!strcmp(ev->key, "Right") || !strcmp(ev->key, "KP_Right"))
1169      {
1170         if (en->select_allow)
1171           {
1172              if (shift) _sel_start(en->cursor, rp->object, en);
1173              else _sel_clear(en->cursor, rp->object, en);
1174           }
1175         /* If control is pressed, go to the start of the word */
1176         if (control) evas_textblock_cursor_word_end(en->cursor);
1177         evas_textblock_cursor_char_next(en->cursor);
1178         if (en->select_allow)
1179           {
1180              if (shift) _sel_extend(en->cursor, rp->object, en);
1181           }
1182         _sel_clear(en->cursor, rp->object, en);
1183         _edje_emit(ed, "entry,key,right", rp->part->name);
1184         _edje_emit(rp->edje, "cursor,changed,manual", rp->part->name);
1185         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1186      }
1187    else if (!strcmp(ev->key, "BackSpace"))
1188      {
1189         if (control && !en->have_selection)
1190           {
1191              // del to start of previous word
1192              _sel_start(en->cursor, rp->object, en);
1193
1194              evas_textblock_cursor_char_prev(en->cursor);
1195              evas_textblock_cursor_word_start(en->cursor);
1196
1197              _sel_extend(en->cursor, rp->object, en);
1198
1199              _range_del_emit(ed, en->cursor, rp->object, en);
1200           }
1201         else if ((alt) && (shift))
1202           {
1203              // undo last action
1204           }
1205         else
1206           {
1207              if (en->have_selection)
1208                {
1209                   _range_del_emit(ed, en->cursor, rp->object, en);
1210                }
1211              else
1212                {
1213                   if (evas_textblock_cursor_char_prev(en->cursor))
1214                     {
1215                        _delete_emit(ed, en->cursor, en, old_cur_pos, EINA_TRUE);
1216                     }
1217                }
1218           }
1219         _sel_clear(en->cursor, rp->object, en);
1220         _anchors_get(en->cursor, rp->object, en);
1221         _edje_emit(ed, "entry,key,backspace", rp->part->name);
1222         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1223      }
1224    else if (!strcmp(ev->key, "Delete") || !strcmp(ev->key, "KP_Delete"))
1225      {
1226         if (control)
1227           {
1228              // del to end of next word
1229              _sel_start(en->cursor, rp->object, en);
1230
1231              evas_textblock_cursor_word_end(en->cursor);
1232              evas_textblock_cursor_char_next(en->cursor);
1233
1234              _sel_extend(en->cursor, rp->object, en);
1235
1236              _range_del_emit(ed, en->cursor, rp->object, en);
1237           }
1238         else if (shift)
1239           {
1240              // cut
1241           }
1242         else
1243           {
1244              if (en->have_selection)
1245                {
1246                   _range_del_emit(ed, en->cursor, rp->object, en);
1247                }
1248              else
1249                {
1250                   _delete_emit(ed, en->cursor, en, old_cur_pos, EINA_FALSE);
1251                }
1252           }
1253         _sel_clear(en->cursor, rp->object, en);
1254         _anchors_get(en->cursor, rp->object, en);
1255         _edje_emit(ed, "entry,key,delete", rp->part->name);
1256         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1257      }
1258    else if (!strcmp(ev->key, "Home") || !strcmp(ev->key, "KP_Home"))
1259      {
1260         if (en->select_allow)
1261           {
1262              if (shift) _sel_start(en->cursor, rp->object, en);
1263              else _sel_clear(en->cursor, rp->object, en);
1264           }
1265         if ((control) && (multiline))
1266           _curs_start(en->cursor, rp->object, en);
1267         else
1268           _curs_lin_start(en->cursor, rp->object, en);
1269         if (en->select_allow)
1270           {
1271              if (shift) _sel_extend(en->cursor, rp->object, en);
1272           }
1273         _edje_emit(ed, "entry,key,home", rp->part->name);
1274         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1275      }
1276    else if (!strcmp(ev->key, "End") || !strcmp(ev->key, "KP_End"))
1277      {
1278         if (en->select_allow)
1279           {
1280              if (shift) _sel_start(en->cursor, rp->object, en);
1281              else _sel_clear(en->cursor, rp->object, en);
1282           }
1283         if ((control) && (multiline))
1284           _curs_end(en->cursor, rp->object, en);
1285         else
1286           _curs_lin_end(en->cursor, rp->object, en);
1287         if (en->select_allow)
1288           {
1289              if (shift) _sel_extend(en->cursor, rp->object, en);
1290           }
1291         _edje_emit(ed, "entry,key,end", rp->part->name);
1292         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1293      }
1294    else if (!strcmp(ev->key, "Shift_L") || !strcmp(ev->key, "Shift_R"))
1295      {
1296         return;
1297      }
1298    else if ((control) && (!strcmp(ev->key, "v")))
1299      {
1300         _edje_emit(ed, "entry,paste,request", rp->part->name);
1301         _edje_emit(ed, "entry,paste,request,3", rp->part->name);
1302         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1303      }
1304    else if ((control) && (!strcmp(ev->key, "a")))
1305      {
1306           _edje_emit(ed, "entry,selection,all,request", rp->part->name);
1307         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1308      }
1309    else if ((control) && (!strcmp(ev->key, "A")))
1310      {
1311           _edje_emit(ed, "entry,selection,none,request", rp->part->name);
1312         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1313      }
1314    else if ((control) && ((!strcmp(ev->key, "c") || (!strcmp(ev->key, "Insert")))))
1315      {
1316         _edje_emit(ed, "entry,copy,notify", rp->part->name);
1317         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1318      }
1319    else if ((control) && ((!strcmp(ev->key, "x") || (!strcmp(ev->key, "m")))))
1320      {
1321         _edje_emit(ed, "entry,cut,notify", rp->part->name);
1322         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1323      }
1324    else if ((control) && (!strcmp(ev->key, "z")))
1325      {
1326         if (shift)
1327           {
1328              // redo
1329              _edje_emit(ed, "entry,redo,request", rp->part->name);
1330           }
1331         else
1332           {
1333              // undo
1334              _edje_emit(ed, "entry,undo,request", rp->part->name);
1335           }
1336         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1337      }
1338    else if ((control) && (!strcmp(ev->key, "y")))
1339      {
1340         // redo
1341         _edje_emit(ed, "entry,redo,request", rp->part->name);
1342         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1343      }
1344    else if ((control) && (!strcmp(ev->key, "w")))
1345      {
1346         _sel_clear(en->cursor, rp->object, en);
1347         // select current word?
1348         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1349      }
1350    else if (!strcmp(ev->key, "Tab"))
1351      {
1352         if (multiline)
1353           {
1354              if (shift)
1355                {
1356                   // remove a tab
1357                }
1358              else
1359                {
1360                   Edje_Entry_Change_Info *info = calloc(1, sizeof(*info));
1361                   info->insert = EINA_TRUE;
1362                   info->change.insert.plain_length = 1;
1363
1364                   if (en->have_selection)
1365                     {
1366                        _range_del_emit(ed, en->cursor, rp->object, en);
1367                        info->merge = EINA_TRUE;
1368                     }
1369                   _sel_clear(en->cursor, rp->object, en);
1370                   info->change.insert.pos =
1371                      evas_textblock_cursor_pos_get(en->cursor);
1372                   info->change.insert.content = eina_stringshare_add("<tab/>");
1373                   //yy
1374 //                  evas_textblock_cursor_format_prepend(en->cursor, "tab");
1375                   _text_filter_format_prepend(en, en->cursor, "tab");
1376                   _anchors_get(en->cursor, rp->object, en);
1377                   _edje_emit(ed, "entry,changed", rp->part->name);
1378                   _edje_emit_full(ed, "entry,changed,user", rp->part->name,
1379                                   info, _free_entry_change_info);
1380                }
1381              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1382           }
1383         _edje_emit(ed, "entry,key,tab", rp->part->name);
1384      }
1385    else if ((!strcmp(ev->key, "ISO_Left_Tab")) && (multiline))
1386      {
1387         // remove a tab
1388         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1389      }
1390    else if (!strcmp(ev->key, "Prior") || !strcmp(ev->key, "KP_Prior"))
1391      {
1392         if (en->select_allow)
1393           {
1394              if (shift) _sel_start(en->cursor, rp->object, en);
1395              else _sel_clear(en->cursor, rp->object, en);
1396           }
1397         _curs_jump_line_by(en->cursor, rp->object, en, -10);
1398         if (en->select_allow)
1399           {
1400              if (shift) _sel_extend(en->cursor, rp->object, en);
1401           }
1402         _sel_clear(en->cursor, rp->object, en);
1403         _edje_emit(ed, "entry,key,pgup", rp->part->name);
1404         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1405      }
1406    else if (!strcmp(ev->key, "Next") || !strcmp(ev->key, "KP_Next"))
1407      {
1408         if (en->select_allow)
1409           {
1410              if (shift) _sel_start(en->cursor, rp->object, en);
1411              else _sel_clear(en->cursor, rp->object, en);
1412           }
1413         _curs_jump_line_by(en->cursor, rp->object, en, 10);
1414         if (en->select_allow)
1415           {
1416              if (shift) _sel_extend(en->cursor, rp->object, en);
1417           }
1418         _sel_clear(en->cursor, rp->object, en);
1419         _edje_emit(ed, "entry,key,pgdn", rp->part->name);
1420         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1421      }
1422    else if ((!strcmp(ev->key, "Return")) || (!strcmp(ev->key, "KP_Enter")))
1423      {
1424         if (multiline)
1425           {
1426              Edje_Entry_Change_Info *info = calloc(1, sizeof(*info));
1427              info->insert = EINA_TRUE;
1428              info->change.insert.plain_length = 1;
1429              if (en->have_selection)
1430                {
1431                   _range_del_emit(ed, en->cursor, rp->object, en);
1432                   info->merge = EINA_TRUE;
1433                }
1434              _sel_clear(en->cursor, rp->object, en);
1435
1436              info->change.insert.pos =
1437                 evas_textblock_cursor_pos_get(en->cursor);
1438              if (shift)
1439                {
1440                   //yy
1441 //                  evas_textblock_cursor_format_prepend(en->cursor, "br");
1442                   _text_filter_format_prepend(en, en->cursor, "br");
1443                   info->change.insert.content = eina_stringshare_add("<br/>");
1444                }
1445              else
1446                {
1447                   //yy
1448 //                  evas_textblock_cursor_format_prepend(en->cursor, "ps");
1449                   _text_filter_format_prepend(en, en->cursor, "ps");
1450                   info->change.insert.content = eina_stringshare_add("<ps/>");
1451                }
1452              _anchors_get(en->cursor, rp->object, en);
1453              _edje_emit(ed, "entry,changed", rp->part->name);
1454              _edje_emit_full(ed, "entry,changed,user", rp->part->name,
1455                              info, _free_entry_change_info);
1456              _edje_emit(ed, "cursor,changed", rp->part->name);
1457              cursor_changed = EINA_TRUE;
1458              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1459           }
1460         _edje_emit(ed, "entry,key,enter", rp->part->name);
1461      }
1462    else
1463      {
1464         if (ev->string)
1465           {
1466              Edje_Entry_Change_Info *info = calloc(1, sizeof(*info));
1467              info->insert = EINA_TRUE;
1468              info->change.insert.plain_length = 1;
1469              info->change.insert.content = eina_stringshare_add(ev->string);
1470
1471              if (en->have_selection)
1472                {
1473                   _range_del_emit(ed, en->cursor, rp->object, en);
1474                   info->merge = EINA_TRUE;
1475                }
1476              _sel_clear(en->cursor, rp->object, en);
1477
1478              info->change.insert.pos =
1479                 evas_textblock_cursor_pos_get(en->cursor);
1480              // if PASSWORD_SHOW_LAST mode, appending text with password=off tag
1481              if ((rp->part->entry_mode == EDJE_ENTRY_EDIT_MODE_PASSWORD) &&
1482                  _edje_password_show_last)
1483                {
1484                   _edje_entry_hide_visible_password(en->rp);
1485                   _text_filter_format_prepend(en, en->cursor, "+ password=off");
1486                   _text_filter_text_prepend(en, en->cursor, ev->string);
1487                   _text_filter_format_prepend(en, en->cursor, "- password");
1488                   if (en->pw_timer)
1489                     {
1490                        ecore_timer_del(en->pw_timer);
1491                        en->pw_timer = NULL;
1492                     }
1493                   en->pw_timer = ecore_timer_add(_edje_password_show_last_timeout,
1494                                                  _password_timer_cb, en);
1495                }
1496              else
1497                _text_filter_text_prepend(en, en->cursor, ev->string);
1498              _anchors_get(en->cursor, rp->object, en);
1499              _edje_emit(ed, "entry,changed", rp->part->name);
1500              _edje_emit_full(ed, "entry,changed,user", rp->part->name,
1501                              info, _free_entry_change_info);
1502              _edje_emit(ed, "cursor,changed", rp->part->name);
1503              cursor_changed = EINA_TRUE;
1504              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1505           }
1506      }
1507    if (!cursor_changed && (old_cur_pos != evas_textblock_cursor_pos_get(en->cursor)))
1508      _edje_emit(ed, "cursor,changed", rp->part->name);
1509
1510    _edje_entry_imf_context_reset(en);
1511    _edje_entry_imf_cursor_info_set(en);
1512    _edje_entry_real_part_configure(rp);
1513 }
1514
1515 static void
1516 _edje_key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1517 {
1518    Edje *ed = data;
1519    Edje_Real_Part *rp = ed->focused_part;
1520    Entry *en;
1521
1522    if (!rp) return;
1523    en = rp->entry_data;
1524    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
1525        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_EDITABLE))
1526      return;
1527
1528 #ifdef HAVE_ECORE_IMF
1529    if (en->imf_context)
1530      {
1531         Evas_Event_Key_Up *ev = event_info;
1532         Ecore_IMF_Event_Key_Up ecore_ev;
1533
1534         ecore_imf_evas_event_key_up_wrap(ev, &ecore_ev);
1535         if (ecore_imf_context_filter_event(en->imf_context,
1536                                            ECORE_IMF_EVENT_KEY_UP,
1537                                            (Ecore_IMF_Event *)&ecore_ev))
1538           return;
1539      }
1540 #else
1541    (void) event_info;
1542 #endif
1543 }
1544
1545 static void
1546 _edje_part_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1547 {
1548    Edje_Real_Part *rp = data;
1549    Entry *en;
1550    if (!rp) return;
1551    en = rp->entry_data;
1552    if (!en) return;
1553    _edje_entry_imf_cursor_info_set(en);
1554 }
1555
1556 static void
1557 _edje_part_mouse_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1558 {
1559    Evas_Coord cx, cy;
1560    Edje_Real_Part *rp = data;
1561    Evas_Event_Mouse_Down *ev = event_info;
1562    Entry *en;
1563    Evas_Coord x, y, w, h;
1564    //   Eina_Bool multiline;
1565    Evas_Textblock_Cursor *tc;
1566    Eina_Bool dosel = EINA_FALSE;
1567    if (!rp) return;
1568    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1569    en = rp->entry_data;
1570    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
1571        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE))
1572      return;
1573    if ((ev->button != 1) && (ev->button != 2)) return;
1574
1575 #ifdef HAVE_ECORE_IMF
1576    if (en->imf_context)
1577      {
1578         Ecore_IMF_Event_Mouse_Down ecore_ev;
1579         ecore_imf_evas_event_mouse_down_wrap(ev, &ecore_ev);
1580         if (ecore_imf_context_filter_event(en->imf_context,
1581                                            ECORE_IMF_EVENT_MOUSE_DOWN,
1582                                            (Ecore_IMF_Event *)&ecore_ev))
1583           return;
1584      }
1585 #endif
1586
1587    en->select_mod_start = EINA_FALSE;
1588    en->select_mod_end = EINA_FALSE;
1589    if (rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_DEFAULT)
1590      dosel = EINA_TRUE;
1591    else if (rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_EXPLICIT)
1592      {
1593         if (en->select_allow) dosel = EINA_TRUE;
1594      }
1595    if (ev->button == 2) dosel = EINA_FALSE;
1596    if (dosel)
1597      {
1598         // double click -> select word
1599         // triple click -> select line
1600      }
1601    tc = evas_object_textblock_cursor_new(rp->object);
1602    evas_textblock_cursor_copy(en->cursor, tc);
1603    //   multiline = rp->part->multiline;
1604    evas_object_geometry_get(rp->object, &x, &y, &w, &h);
1605    cx = ev->canvas.x - x;
1606    cy = ev->canvas.y - y;
1607    if (!evas_textblock_cursor_char_coord_set(en->cursor, cx, cy))
1608      {
1609         Evas_Coord lx, ly, lw, lh;
1610         int line;
1611
1612         line = evas_textblock_cursor_line_coord_set(en->cursor, cy);
1613         if (line == -1)
1614           {
1615              if (rp->part->multiline)
1616                _curs_end(en->cursor, rp->object, en);
1617              else
1618                {
1619                   evas_textblock_cursor_paragraph_first(en->cursor);
1620                   evas_textblock_cursor_line_geometry_get(en->cursor, &lx, &ly, &lw, &lh);
1621                   if (!evas_textblock_cursor_char_coord_set(en->cursor, cx, ly + (lh / 2)))
1622                     _curs_end(en->cursor, rp->object, en);
1623                }
1624           }
1625         else
1626           {
1627              int lnum;
1628
1629              lnum = evas_textblock_cursor_line_geometry_get(en->cursor, &lx, &ly, &lw, &lh);
1630              if (lnum < 0)
1631                {
1632                   _curs_lin_start(en->cursor, rp->object, en);
1633                }
1634              else
1635                {
1636                   if (cx <= lx)
1637                     _curs_lin_start(en->cursor, rp->object, en);
1638                   else
1639                     _curs_lin_end(en->cursor, rp->object, en);
1640                }
1641           }
1642      }
1643    if (dosel)
1644      {
1645         if ((en->have_selection) &&
1646             (rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_EXPLICIT))
1647           {
1648              Eina_List *first, *last;
1649              FLOAT_T sc;
1650
1651              first = en->sel;
1652              last = eina_list_last(en->sel);
1653              if (first && last)
1654                {
1655                   Evas_Textblock_Rectangle *r1, *r2;
1656                   Evas_Coord d, d1, d2;
1657
1658                   r1 = first->data;
1659                   r2 = last->data;
1660                   d = r1->x - cx;
1661                   d1 = d * d;
1662                   d = (r1->y + (r1->h / 2)) - cy;
1663                   d1 += d * d;
1664                   d = r2->x + r2->w - 1 - cx;
1665                   d2 = d * d;
1666                   d = (r2->y + (r2->h / 2)) - cy;
1667                   d2 += d * d;
1668                   sc = rp->edje->scale;
1669                   if (sc == ZERO) sc = _edje_scale;
1670                   d = (Evas_Coord)MUL(FROM_INT(20), sc); // FIXME: maxing number!
1671                   d = d * d;
1672                   if (d1 < d2)
1673                     {
1674                        if (d1 <= d)
1675                          {
1676                             en->select_mod_start = EINA_TRUE;
1677                             en->selecting = EINA_TRUE;
1678                          }
1679                     }
1680                   else
1681                     {
1682                        if (d2 <= d)
1683                          {
1684                             en->select_mod_end = EINA_TRUE;
1685                             en->selecting = EINA_TRUE;
1686                          }
1687                     }
1688                }
1689           }
1690         else
1691           {
1692              en->selecting = EINA_TRUE;
1693              _sel_clear(en->cursor, rp->object, en);
1694              if (en->select_allow)
1695                {
1696                   _sel_start(en->cursor, rp->object, en);
1697                }
1698           }
1699      }
1700    if (evas_textblock_cursor_compare(tc, en->cursor))
1701      {
1702         _edje_emit(rp->edje, "cursor,changed", rp->part->name);
1703         _edje_emit(rp->edje, "cursor,changed,manual", rp->part->name);
1704      }
1705    evas_textblock_cursor_free(tc);
1706    
1707    _edje_entry_imf_context_reset(en);
1708    _edje_entry_imf_cursor_info_set(en);
1709
1710    _edje_entry_real_part_configure(rp);
1711    if (ev->button == 2)
1712      {
1713         _edje_emit(rp->edje, "entry,paste,request", rp->part->name);
1714         _edje_emit(rp->edje, "entry,paste,request,1", rp->part->name);
1715      }
1716 }
1717
1718 static void
1719 _edje_part_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1720 {
1721    Evas_Coord cx, cy;
1722    Edje_Real_Part *rp = data;
1723    Evas_Event_Mouse_Up *ev = event_info;
1724    Entry *en;
1725    Evas_Coord x, y, w, h;
1726    Evas_Textblock_Cursor *tc;
1727    if (ev->button != 1) return;
1728    if (!rp) return;
1729    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1730    en = rp->entry_data;
1731    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
1732        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE))
1733      return;
1734
1735 #ifdef HAVE_ECORE_IMF
1736    if (en->imf_context)
1737      {
1738         Ecore_IMF_Event_Mouse_Up ecore_ev;
1739         ecore_imf_evas_event_mouse_up_wrap(ev, &ecore_ev);
1740         if (ecore_imf_context_filter_event(en->imf_context,
1741                                            ECORE_IMF_EVENT_MOUSE_UP,
1742                                            (Ecore_IMF_Event *)&ecore_ev))
1743           return;
1744      }
1745 #endif
1746
1747    tc = evas_object_textblock_cursor_new(rp->object);
1748    evas_textblock_cursor_copy(en->cursor, tc);
1749    evas_object_geometry_get(rp->object, &x, &y, &w, &h);
1750    cx = ev->canvas.x - x;
1751    cy = ev->canvas.y - y;
1752    if (!evas_textblock_cursor_char_coord_set(en->cursor, cx, cy))
1753      {
1754         Evas_Coord lx, ly, lw, lh;
1755         int line;
1756
1757         line = evas_textblock_cursor_line_coord_set(en->cursor, cy);
1758         if (line == -1)
1759           {
1760              if (rp->part->multiline)
1761                _curs_end(en->cursor, rp->object, en);
1762              else
1763                {
1764                   evas_textblock_cursor_paragraph_first(en->cursor);
1765                   evas_textblock_cursor_line_geometry_get(en->cursor, &lx, &ly, &lw, &lh);
1766                   if (!evas_textblock_cursor_char_coord_set(en->cursor, cx, ly + (lh / 2)))
1767                     _curs_end(en->cursor, rp->object, en);
1768                }
1769           }
1770         else
1771           {
1772              int lnum;
1773
1774              lnum = evas_textblock_cursor_line_geometry_get(en->cursor, &lx, &ly, &lw, &lh);
1775              if (lnum < 0)
1776                {
1777                   _curs_lin_start(en->cursor, rp->object, en);
1778                }
1779              else
1780                {
1781                   if (cx <= lx)
1782                     _curs_lin_start(en->cursor, rp->object, en);
1783                   else
1784                     _curs_lin_end(en->cursor, rp->object, en);
1785                }
1786           }
1787      }
1788    if (rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_EXPLICIT)
1789      {
1790         if (en->select_allow)
1791           {
1792              if (en->had_sel)
1793                {
1794                   if (en->select_mod_end)
1795                     _sel_extend(en->cursor, rp->object, en);
1796                   else if (en->select_mod_start)
1797                     _sel_preextend(en->cursor, rp->object, en);
1798                }
1799              else
1800                _sel_extend(en->cursor, rp->object, en);
1801              //evas_textblock_cursor_copy(en->cursor, en->sel_end);
1802           }
1803      }
1804    else
1805      evas_textblock_cursor_copy(en->cursor, en->sel_end);
1806    if (en->selecting)
1807      {
1808         if (en->have_selection)
1809           en->had_sel = EINA_TRUE;
1810         en->selecting = EINA_FALSE;
1811      }
1812    if (evas_textblock_cursor_compare(tc, en->cursor))
1813      {
1814         _edje_emit(rp->edje, "cursor,changed", rp->part->name);
1815         _edje_emit(rp->edje, "cursor,changed,manual", rp->part->name);
1816      }
1817    evas_textblock_cursor_free(tc);
1818
1819    _edje_entry_imf_context_reset(en);
1820    _edje_entry_imf_cursor_info_set(en);
1821    _edje_entry_real_part_configure(rp);
1822 }
1823
1824 static void
1825 _edje_part_mouse_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1826 {
1827    Evas_Coord cx, cy;
1828    Edje_Real_Part *rp = data;
1829    Evas_Event_Mouse_Move *ev = event_info;
1830    Entry *en;
1831    Evas_Coord x, y, w, h;
1832    Evas_Textblock_Cursor *tc;
1833    if (!rp) return;
1834    en = rp->entry_data;
1835    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
1836        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE))
1837      return;
1838
1839 #ifdef HAVE_ECORE_IMF
1840    if (en->imf_context)
1841      {
1842         Ecore_IMF_Event_Mouse_Move ecore_ev;
1843         ecore_imf_evas_event_mouse_move_wrap(ev, &ecore_ev);
1844         if (ecore_imf_context_filter_event(en->imf_context,
1845                                            ECORE_IMF_EVENT_MOUSE_MOVE,
1846                                            (Ecore_IMF_Event *)&ecore_ev))
1847           return;
1848      }
1849 #endif
1850
1851    if (en->selecting)
1852      {
1853         tc = evas_object_textblock_cursor_new(rp->object);
1854         evas_textblock_cursor_copy(en->cursor, tc);
1855         evas_object_geometry_get(rp->object, &x, &y, &w, &h);
1856         cx = ev->cur.canvas.x - x;
1857         cy = ev->cur.canvas.y - y;
1858         if (!evas_textblock_cursor_char_coord_set(en->cursor, cx, cy))
1859           {
1860              Evas_Coord lx, ly, lw, lh;
1861
1862              if (evas_textblock_cursor_line_coord_set(en->cursor, cy) < 0)
1863                {
1864                   if (rp->part->multiline)
1865                     _curs_end(en->cursor, rp->object, en);
1866                   else
1867                     {
1868                        evas_textblock_cursor_paragraph_first(en->cursor);
1869                        evas_textblock_cursor_line_geometry_get(en->cursor, &lx, &ly, &lw, &lh);
1870                        if (!evas_textblock_cursor_char_coord_set(en->cursor, cx, ly + (lh / 2)))
1871                          _curs_end(en->cursor, rp->object, en);
1872                     }
1873                }
1874              else
1875                {
1876                   evas_textblock_cursor_line_geometry_get(en->cursor, &lx, &ly, &lw, &lh);
1877                   if (cx <= lx)
1878                     _curs_lin_start(en->cursor, rp->object, en);
1879                   else
1880                     _curs_lin_end(en->cursor, rp->object, en);
1881                }
1882           }
1883         if (rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_EXPLICIT)
1884           {
1885              if (en->select_allow)
1886                {
1887                   if (en->had_sel)
1888                     {
1889                        if (en->select_mod_end)
1890                          _sel_extend(en->cursor, rp->object, en);
1891                        else if (en->select_mod_start)
1892                          _sel_preextend(en->cursor, rp->object, en);
1893                     }
1894                   else
1895                     _sel_extend(en->cursor, rp->object, en);
1896                }
1897           }
1898         else
1899           {
1900              _sel_extend(en->cursor, rp->object, en);
1901           }
1902         if (en->select_allow)
1903           {
1904              if (evas_textblock_cursor_compare(en->sel_start, en->sel_end) != 0)
1905                _sel_enable(en->cursor, rp->object, en);
1906              if (en->have_selection)
1907                _sel_update(en->cursor, rp->object, en);
1908           }
1909         if (evas_textblock_cursor_compare(tc, en->cursor))
1910           {
1911              _edje_emit(rp->edje, "cursor,changed", rp->part->name);
1912              _edje_emit(rp->edje, "cursor,changed,manual", rp->part->name);
1913           }
1914         evas_textblock_cursor_free(tc);
1915
1916         _edje_entry_imf_context_reset(en);
1917         _edje_entry_imf_cursor_info_set(en);
1918
1919         _edje_entry_real_part_configure(rp);
1920      }
1921 }
1922
1923 static void
1924 _evas_focus_in_cb(void *data, Evas *e, __UNUSED__ void *event_info)
1925 {
1926    Edje *ed = (Edje *)data;
1927
1928    if (evas_focus_get(e) == ed->obj)
1929      {
1930         _edje_focus_in_cb(data, NULL, NULL, NULL);
1931      }
1932 }
1933
1934 static void
1935 _evas_focus_out_cb(void *data, Evas *e, __UNUSED__ void *event_info)
1936 {
1937    Edje *ed = (Edje *)data;
1938
1939    if (evas_focus_get(e) == ed->obj)
1940      {
1941         _edje_focus_out_cb(data, NULL, NULL, NULL);
1942      }
1943 }
1944
1945 /***************************************************************/
1946 void
1947 _edje_entry_init(Edje *ed)
1948 {
1949    if (!ed->has_entries)
1950      return;
1951    if (ed->entries_inited)
1952      return;
1953    ed->entries_inited = EINA_TRUE;
1954
1955    evas_object_event_callback_add(ed->obj, EVAS_CALLBACK_FOCUS_IN, _edje_focus_in_cb, ed);
1956    evas_object_event_callback_add(ed->obj, EVAS_CALLBACK_FOCUS_OUT, _edje_focus_out_cb, ed);
1957    evas_object_event_callback_add(ed->obj, EVAS_CALLBACK_KEY_DOWN, _edje_key_down_cb, ed);
1958    evas_object_event_callback_add(ed->obj, EVAS_CALLBACK_KEY_UP, _edje_key_up_cb, ed);
1959    evas_event_callback_add(ed->base.evas, EVAS_CALLBACK_CANVAS_FOCUS_IN, _evas_focus_in_cb, ed);
1960    evas_event_callback_add(ed->base.evas, EVAS_CALLBACK_CANVAS_FOCUS_OUT, _evas_focus_out_cb, ed);
1961 }
1962
1963 void
1964 _edje_entry_shutdown(Edje *ed)
1965 {
1966    if (!ed->has_entries)
1967      return;
1968    if (!ed->entries_inited)
1969      return;
1970    ed->entries_inited = EINA_FALSE;
1971
1972    evas_object_event_callback_del(ed->obj, EVAS_CALLBACK_FOCUS_IN, _edje_focus_in_cb);
1973    evas_object_event_callback_del(ed->obj, EVAS_CALLBACK_FOCUS_OUT, _edje_focus_out_cb);
1974    evas_object_event_callback_del(ed->obj, EVAS_CALLBACK_KEY_DOWN, _edje_key_down_cb);
1975    evas_object_event_callback_del(ed->obj, EVAS_CALLBACK_KEY_UP, _edje_key_up_cb);
1976    if (evas_event_callback_del_full(ed->base.evas, EVAS_CALLBACK_CANVAS_FOCUS_IN, _evas_focus_in_cb, ed) != ed)
1977      ERR("could not unregister EVAS_CALLBACK_FOCUS_IN");
1978    if (evas_event_callback_del_full(ed->base.evas, EVAS_CALLBACK_CANVAS_FOCUS_OUT, _evas_focus_out_cb, ed) != ed)
1979      ERR("could not unregister EVAS_CALLBACK_FOCUS_OUT");
1980 }
1981
1982 void
1983 _edje_entry_real_part_init(Edje_Real_Part *rp)
1984 {
1985    Entry *en;
1986 #ifdef HAVE_ECORE_IMF
1987    const char *ctx_id;
1988    const Ecore_IMF_Context_Info *ctx_info;
1989 #endif
1990
1991    en = calloc(1, sizeof(Entry));
1992    if (!en) return;
1993    rp->entry_data = en;
1994    en->rp = rp;
1995
1996    evas_object_event_callback_add(rp->object, EVAS_CALLBACK_MOVE, _edje_part_move_cb, rp);
1997
1998    evas_object_event_callback_add(rp->object, EVAS_CALLBACK_MOUSE_DOWN, _edje_part_mouse_down_cb, rp);
1999    evas_object_event_callback_add(rp->object, EVAS_CALLBACK_MOUSE_UP, _edje_part_mouse_up_cb, rp);
2000    evas_object_event_callback_add(rp->object, EVAS_CALLBACK_MOUSE_MOVE, _edje_part_mouse_move_cb, rp);
2001
2002    if (rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_DEFAULT)
2003      en->select_allow = EINA_TRUE;
2004
2005    if (rp->part->entry_mode == EDJE_ENTRY_EDIT_MODE_PASSWORD)
2006      {
2007         Edje_Part_Description_Text *txt;
2008
2009         txt = (Edje_Part_Description_Text *)rp->chosen_description;
2010
2011         en->select_allow = EINA_FALSE;
2012         if (txt && edje_string_get(&txt->text.repch))
2013           evas_object_textblock_replace_char_set(rp->object, edje_string_get(&txt->text.repch));
2014         else
2015           evas_object_textblock_replace_char_set(rp->object, "*");
2016      }
2017
2018    en->cursor_bg = edje_object_add(rp->edje->base.evas);
2019    edje_object_file_set(en->cursor_bg, rp->edje->path, rp->part->source3);
2020    evas_object_smart_member_add(en->cursor_bg, rp->edje->obj);
2021    evas_object_stack_below(en->cursor_bg, rp->object);
2022    evas_object_clip_set(en->cursor_bg, evas_object_clip_get(rp->object));
2023    evas_object_pass_events_set(en->cursor_bg, EINA_TRUE);
2024    _edje_subobj_register(en->rp->edje, en->cursor_bg);
2025
2026    en->cursor_fg = edje_object_add(rp->edje->base.evas);
2027    edje_object_file_set(en->cursor_fg, rp->edje->path, rp->part->source4);
2028    evas_object_smart_member_add(en->cursor_fg, rp->edje->obj);
2029    evas_object_stack_above(en->cursor_fg, rp->object);
2030    evas_object_clip_set(en->cursor_fg, evas_object_clip_get(rp->object));
2031    evas_object_pass_events_set(en->cursor_fg, EINA_TRUE);
2032    _edje_subobj_register(en->rp->edje, en->cursor_fg);
2033
2034    if (rp->part->entry_mode >= EDJE_ENTRY_EDIT_MODE_EDITABLE)
2035      {
2036         evas_object_show(en->cursor_bg);
2037         evas_object_show(en->cursor_fg);
2038 #ifdef HAVE_ECORE_IMF
2039         ecore_imf_init();
2040
2041         edje_object_signal_callback_add(rp->edje->obj, "focus,part,in", rp->part->name, _edje_entry_focus_in_cb, rp);
2042         edje_object_signal_callback_add(rp->edje->obj, "focus,part,out", rp->part->name, _edje_entry_focus_out_cb, rp);
2043
2044         ctx_id = ecore_imf_context_default_id_get();
2045         if (ctx_id)
2046           {
2047              ctx_info = ecore_imf_context_info_by_id_get(ctx_id);
2048              if (!ctx_info->canvas_type ||
2049                  strcmp(ctx_info->canvas_type, "evas") == 0)
2050                {
2051                   en->imf_context = ecore_imf_context_add(ctx_id);
2052                }
2053              else
2054                {
2055                   ctx_id = ecore_imf_context_default_id_by_canvas_type_get("evas");
2056                   if (ctx_id)
2057                     {
2058                        en->imf_context = ecore_imf_context_add(ctx_id);
2059                     }
2060                }
2061           }
2062         else
2063           en->imf_context = NULL;
2064
2065         if (!en->imf_context) goto done;
2066
2067         ecore_imf_context_client_window_set
2068            (en->imf_context, 
2069                (void *)ecore_evas_window_get
2070                (ecore_evas_ecore_evas_get(rp->edje->base.evas)));
2071         ecore_imf_context_client_canvas_set(en->imf_context, rp->edje->base.evas);
2072
2073         ecore_imf_context_retrieve_surrounding_callback_set(en->imf_context,
2074                                                             _edje_entry_imf_retrieve_surrounding_cb, rp->edje);
2075         en->imf_ee_handler_commit = ecore_event_handler_add(ECORE_IMF_EVENT_COMMIT, _edje_entry_imf_event_commit_cb, rp->edje);
2076         en->imf_ee_handler_delete = ecore_event_handler_add(ECORE_IMF_EVENT_DELETE_SURROUNDING, _edje_entry_imf_event_delete_surrounding_cb, rp->edje);
2077         en->imf_ee_handler_changed = ecore_event_handler_add(ECORE_IMF_EVENT_PREEDIT_CHANGED, _edje_entry_imf_event_preedit_changed_cb, rp->edje);
2078         ecore_imf_context_input_mode_set(en->imf_context,
2079                                          rp->part->entry_mode == EDJE_ENTRY_EDIT_MODE_PASSWORD ?
2080                                          ECORE_IMF_INPUT_MODE_INVISIBLE : ECORE_IMF_INPUT_MODE_FULL);
2081 #endif
2082      }
2083 #ifdef HAVE_ECORE_IMF
2084 done:
2085 #endif
2086    en->cursor = (Evas_Textblock_Cursor *)evas_object_textblock_cursor_get(rp->object);
2087 }
2088
2089 void
2090 _edje_entry_real_part_shutdown(Edje_Real_Part *rp)
2091 {
2092    Entry *en = rp->entry_data;
2093    if (!en) return;
2094    rp->entry_data = NULL;
2095    _sel_clear(en->cursor, rp->object, en);
2096    _anchors_clear(en->cursor, rp->object, en);
2097 #ifdef HAVE_ECORE_IMF
2098    _preedit_clear(en);
2099 #endif
2100    evas_object_del(en->cursor_bg);
2101    evas_object_del(en->cursor_fg);
2102
2103    if (en->pw_timer)
2104      {
2105         ecore_timer_del(en->pw_timer);
2106         en->pw_timer = NULL;
2107      }
2108
2109 #ifdef HAVE_ECORE_IMF
2110    if (rp->part->entry_mode >= EDJE_ENTRY_EDIT_MODE_EDITABLE)
2111      {
2112         if (en->imf_context)
2113           {
2114              if (en->imf_ee_handler_commit)
2115                {
2116                   ecore_event_handler_del(en->imf_ee_handler_commit);
2117                   en->imf_ee_handler_commit = NULL;
2118                }
2119
2120              if (en->imf_ee_handler_delete)
2121                {
2122                   ecore_event_handler_del(en->imf_ee_handler_delete);
2123                   en->imf_ee_handler_delete = NULL;
2124                }
2125
2126              if (en->imf_ee_handler_changed)
2127                {
2128                   ecore_event_handler_del(en->imf_ee_handler_changed);
2129                   en->imf_ee_handler_changed = NULL;
2130                }
2131
2132              ecore_imf_context_del(en->imf_context);
2133              en->imf_context = NULL;
2134           }
2135
2136         edje_object_signal_callback_del(rp->edje->obj, "focus,part,in", rp->part->name, _edje_entry_focus_in_cb);
2137         edje_object_signal_callback_del(rp->edje->obj, "focus,part,out", rp->part->name, _edje_entry_focus_out_cb);
2138         ecore_imf_shutdown();
2139      }
2140 #endif
2141
2142    free(en);
2143 }
2144
2145 void
2146 _edje_entry_real_part_configure(Edje_Real_Part *rp)
2147 {
2148    Evas_Coord x, y, w, h, xx, yy, ww, hh;
2149    Entry *en = rp->entry_data;
2150    Evas_Textblock_Cursor_Type cur_type;
2151    if (!en) return;
2152    switch (rp->part->cursor_mode)
2153      {
2154       case EDJE_ENTRY_CURSOR_MODE_BEFORE:
2155          cur_type = EVAS_TEXTBLOCK_CURSOR_BEFORE;
2156          break;
2157       case EDJE_ENTRY_CURSOR_MODE_UNDER:
2158          /* no break for a resaon */
2159       default:
2160          cur_type = EVAS_TEXTBLOCK_CURSOR_UNDER;
2161      }
2162
2163    _sel_update(en->cursor, rp->object, en);
2164    _anchors_update(en->cursor, rp->object, en);
2165    x = y = w = h = -1;
2166    xx = yy = ww = hh = -1;
2167    evas_object_geometry_get(rp->object, &x, &y, &w, &h);
2168    evas_textblock_cursor_geometry_get(en->cursor, &xx, &yy, &ww, &hh, NULL, cur_type);
2169    if (ww < 1) ww = 1;
2170    if (hh < 1) hh = 1;
2171    if (en->cursor_bg)
2172      {
2173         evas_object_move(en->cursor_bg, x + xx, y + yy);
2174         evas_object_resize(en->cursor_bg, ww, hh);
2175      }
2176    if (en->cursor_fg)
2177      {
2178         evas_object_move(en->cursor_fg, x + xx, y + yy);
2179         evas_object_resize(en->cursor_fg, ww, hh);
2180      }
2181 }
2182
2183 const char *
2184 _edje_entry_selection_get(Edje_Real_Part *rp)
2185 {
2186    Entry *en = rp->entry_data;
2187    if (!en) return NULL;
2188    // get selection - convert to markup
2189    if ((!en->selection) && (en->have_selection))
2190      en->selection = evas_textblock_cursor_range_text_get
2191         (en->sel_start, en->sel_end, EVAS_TEXTBLOCK_TEXT_MARKUP);
2192    return en->selection;
2193 }
2194
2195 const char *
2196 _edje_entry_text_get(Edje_Real_Part *rp)
2197 {
2198    Entry *en = rp->entry_data;
2199    if (!en) return NULL;
2200    // get text - convert to markup
2201    return evas_object_textblock_text_markup_get(rp->object);
2202 }
2203
2204 void
2205 _edje_entry_text_markup_set(Edje_Real_Part *rp, const char *text)
2206 {
2207    Entry *en = rp->entry_data;
2208    if (!en) return;
2209
2210    // set text as markup
2211    _sel_clear(en->cursor, rp->object, en);
2212    evas_object_textblock_text_markup_set(rp->object, text);
2213    _edje_entry_set_cursor_start(rp);
2214
2215    _anchors_get(en->cursor, rp->object, en);
2216    _edje_emit(rp->edje, "entry,changed", rp->part->name);
2217    _edje_entry_imf_cursor_info_set(en);
2218 #if 0
2219    /* Don't emit cursor changed cause it didn't. It's just init to 0. */
2220    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
2221 #endif
2222 }
2223
2224 void
2225 _edje_entry_text_markup_append(Edje_Real_Part *rp, const char *text)
2226 {
2227    Entry *en = rp->entry_data;
2228    Evas_Textblock_Cursor *end_cur;
2229    if (!en) return;
2230    end_cur = evas_object_textblock_cursor_new(rp->object);
2231    evas_textblock_cursor_paragraph_last(end_cur);
2232
2233    _text_filter_markup_prepend(en, end_cur, text);
2234    evas_textblock_cursor_free(end_cur);
2235
2236    /* We are updating according to the real cursor on purpose */
2237    _anchors_get(en->cursor, rp->object, en);
2238    _edje_emit(rp->edje, "entry,changed", rp->part->name);
2239
2240    _edje_entry_real_part_configure(rp);
2241 }
2242
2243 void
2244 _edje_entry_text_markup_insert(Edje_Real_Part *rp, const char *text)
2245 {
2246    Entry *en = rp->entry_data;
2247    if (!en) return;
2248    // prepend markup @ cursor pos
2249    if (en->have_selection)
2250      _range_del(en->cursor, rp->object, en);
2251    _sel_clear(en->cursor, rp->object, en);
2252    //xx
2253 //   evas_object_textblock_text_markup_prepend(en->cursor, text);
2254    _text_filter_markup_prepend(en, en->cursor, text);
2255    _anchors_get(en->cursor, rp->object, en);
2256    _edje_emit(rp->edje, "entry,changed", rp->part->name);
2257    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
2258
2259    _edje_entry_imf_context_reset(en);
2260    _edje_entry_imf_cursor_info_set(en);
2261    
2262    _edje_entry_real_part_configure(rp);
2263 }
2264
2265 void
2266 _edje_entry_set_cursor_start(Edje_Real_Part *rp)
2267 {
2268    Entry *en = rp->entry_data;
2269    if (!en) return;
2270    _curs_start(en->cursor, rp->object, en);
2271
2272    _edje_entry_imf_cursor_info_set(en);
2273 }
2274
2275 void
2276 _edje_entry_set_cursor_end(Edje_Real_Part *rp)
2277 {
2278    Entry *en = rp->entry_data;
2279    if (!en) return;
2280    _curs_end(en->cursor, rp->object, en);
2281
2282    _edje_entry_imf_cursor_info_set(en);
2283 }
2284
2285 void
2286 _edje_entry_select_none(Edje_Real_Part *rp)
2287 {
2288    Entry *en = rp->entry_data;
2289    if (!en) return;
2290    _sel_clear(en->cursor, rp->object, en);
2291 }
2292
2293 void
2294 _edje_entry_select_all(Edje_Real_Part *rp)
2295 {
2296    Entry *en = rp->entry_data;
2297    if (!en) return;
2298    _sel_clear(en->cursor, rp->object, en);
2299    _curs_start(en->cursor, rp->object, en);
2300    _sel_enable(en->cursor, rp->object, en);
2301    _sel_start(en->cursor, rp->object, en);
2302    _curs_end(en->cursor, rp->object, en);
2303    _sel_extend(en->cursor, rp->object, en);
2304
2305    _edje_entry_imf_context_reset(en);
2306    _edje_entry_imf_cursor_info_set(en);
2307    _edje_entry_real_part_configure(rp);
2308 }
2309
2310 void
2311 _edje_entry_select_begin(Edje_Real_Part *rp)
2312 {
2313    Entry *en = rp->entry_data;
2314    if (!en) return;
2315    _sel_clear(en->cursor, rp->object, en);
2316    _sel_enable(en->cursor, rp->object, en);
2317    _sel_start(en->cursor, rp->object, en);
2318    _sel_extend(en->cursor, rp->object, en);
2319
2320    _edje_entry_imf_context_reset(en);
2321    _edje_entry_imf_cursor_info_set(en);
2322
2323    _edje_entry_real_part_configure(rp);
2324 }
2325
2326 void
2327 _edje_entry_select_extend(Edje_Real_Part *rp)
2328 {
2329    Entry *en = rp->entry_data;
2330    if (!en) return;
2331    _sel_extend(en->cursor, rp->object, en);
2332
2333    _edje_entry_imf_context_reset(en);
2334    _edje_entry_imf_cursor_info_set(en);
2335
2336    _edje_entry_real_part_configure(rp);
2337 }
2338
2339 const Eina_List *
2340 _edje_entry_anchor_geometry_get(Edje_Real_Part *rp, const char *anchor)
2341 {
2342    Entry *en = rp->entry_data;
2343    Eina_List *l;
2344    Anchor *an;
2345
2346    if (!en) return NULL;
2347    EINA_LIST_FOREACH(en->anchors, l, an)
2348      {
2349         if (an->item) continue;
2350         if (!strcmp(anchor, an->name))
2351           return an->sel;
2352      }
2353    return NULL;
2354 }
2355
2356 const Eina_List *
2357 _edje_entry_anchors_list(Edje_Real_Part *rp)
2358 {
2359    Entry *en = rp->entry_data;
2360    Eina_List *l, *anchors = NULL;
2361    Anchor *an;
2362
2363    if (!en) return NULL;
2364    if (!en->anchorlist)
2365      {
2366         EINA_LIST_FOREACH(en->anchors, l, an)
2367           {
2368              const char *n = an->name;
2369              if (an->item) continue;
2370              if (!n) n = "";
2371              anchors = eina_list_append(anchors, strdup(n));
2372           }
2373         en->anchorlist = anchors;
2374      }
2375    return en->anchorlist;
2376 }
2377
2378 Eina_Bool
2379 _edje_entry_item_geometry_get(Edje_Real_Part *rp, const char *item, Evas_Coord *cx, Evas_Coord *cy, Evas_Coord *cw, Evas_Coord *ch)
2380 {
2381    Entry *en = rp->entry_data;
2382    Eina_List *l;
2383    Anchor *an;
2384
2385    if (!en) return EINA_FALSE;
2386    EINA_LIST_FOREACH(en->anchors, l, an)
2387      {
2388         if (an->item) continue;
2389         if (!strcmp(item, an->name))
2390           {
2391              evas_textblock_cursor_format_item_geometry_get(an->start, cx, cy, cw, ch);
2392              return EINA_TRUE;
2393           }
2394      }
2395    return EINA_FALSE;
2396 }
2397
2398 const Eina_List *
2399 _edje_entry_items_list(Edje_Real_Part *rp)
2400 {
2401    Entry *en = rp->entry_data;
2402    Eina_List *l, *items = NULL;
2403    Anchor *an;
2404
2405    if (!en) return NULL;
2406    if (!en->itemlist)
2407      {
2408         EINA_LIST_FOREACH(en->anchors, l, an)
2409           {
2410              const char *n = an->name;
2411              if (an->item) continue;
2412              if (!n) n = "";
2413              items = eina_list_append(items, strdup(n));
2414           }
2415         en->itemlist = items;
2416      }
2417    return en->itemlist;
2418 }
2419
2420 void
2421 _edje_entry_cursor_geometry_get(Edje_Real_Part *rp, Evas_Coord *cx, Evas_Coord *cy, Evas_Coord *cw, Evas_Coord *ch)
2422 {
2423    Evas_Coord x, y, w, h, xx, yy, ww, hh;
2424    Entry *en = rp->entry_data;
2425    Evas_Textblock_Cursor_Type cur_type;
2426    if (!en) return;
2427    switch (rp->part->cursor_mode)
2428      {
2429       case EDJE_ENTRY_CURSOR_MODE_BEFORE:
2430          cur_type = EVAS_TEXTBLOCK_CURSOR_BEFORE;
2431          break;
2432       case EDJE_ENTRY_CURSOR_MODE_UNDER:
2433          /* no break for a resaon */
2434       default:
2435          cur_type = EVAS_TEXTBLOCK_CURSOR_UNDER;
2436      }
2437
2438    x = y = w = h = -1;
2439    xx = yy = ww = hh = -1;
2440    evas_object_geometry_get(rp->object, &x, &y, &w, &h);
2441    evas_textblock_cursor_geometry_get(en->cursor, &xx, &yy, &ww, &hh, NULL, cur_type);
2442    if (ww < 1) ww = 1;
2443    if (rp->part->cursor_mode == EDJE_ENTRY_CURSOR_MODE_BEFORE)
2444      edje_object_size_min_restricted_calc(en->cursor_fg, &ww, NULL, ww, 0);
2445    if (hh < 1) hh = 1;
2446    if (cx) *cx = x + xx;
2447    if (cy) *cy = y + yy;
2448    if (cw) *cw = ww;
2449    if (ch) *ch = hh;
2450 }
2451
2452 void
2453 _edje_entry_select_allow_set(Edje_Real_Part *rp, Eina_Bool allow)
2454 {
2455    Entry *en = rp->entry_data;
2456    if (rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_DEFAULT)
2457      return;
2458    en->select_allow = allow;
2459 }
2460
2461 Eina_Bool
2462 _edje_entry_select_allow_get(const Edje_Real_Part *rp)
2463 {
2464    const Entry *en = rp->entry_data;
2465    return en->select_allow;
2466 }
2467
2468 void
2469 _edje_entry_select_abort(Edje_Real_Part *rp)
2470 {
2471    Entry *en = rp->entry_data;
2472    if (en->selecting)
2473      {
2474         en->selecting = EINA_FALSE;
2475
2476         _edje_entry_imf_context_reset(en);
2477         _edje_entry_imf_cursor_info_set(en);
2478         _edje_entry_real_part_configure(rp);
2479      }
2480 }
2481
2482 void
2483 _edje_entry_autocapital_type_set(Edje_Real_Part *rp, Edje_Text_Autocapital_Type autocapital_type)
2484 {
2485    Entry *en = rp->entry_data;
2486    if (!en) return;
2487
2488    if (rp->part->entry_mode == EDJE_ENTRY_EDIT_MODE_PASSWORD)
2489      autocapital_type = EDJE_TEXT_AUTOCAPITAL_TYPE_NONE;
2490
2491 #ifdef HAVE_ECORE_IMF
2492    if (en->imf_context)
2493      ecore_imf_context_autocapital_type_set(en->imf_context, autocapital_type);
2494 #endif
2495 }
2496
2497 Edje_Text_Autocapital_Type
2498 _edje_entry_autocapital_type_get(Edje_Real_Part *rp)
2499 {
2500    Entry *en = rp->entry_data;
2501    if (!en) return EDJE_TEXT_AUTOCAPITAL_TYPE_NONE;
2502
2503 #ifdef HAVE_ECORE_IMF
2504    if (en->imf_context)
2505      return ecore_imf_context_autocapital_type_get(en->imf_context);
2506 #endif
2507
2508    return EDJE_TEXT_AUTOCAPITAL_TYPE_NONE;
2509 }
2510
2511 void
2512 _edje_entry_input_panel_enabled_set(Edje_Real_Part *rp, Eina_Bool enabled)
2513 {
2514    Entry *en = rp->entry_data;
2515
2516    if (!en) return;
2517 #ifdef HAVE_ECORE_IMF
2518    if (en->imf_context)
2519      ecore_imf_context_input_panel_enabled_set(en->imf_context, enabled);
2520 #else
2521    (void) enabled;
2522 #endif
2523 }
2524
2525 Eina_Bool
2526 _edje_entry_input_panel_enabled_get(Edje_Real_Part *rp)
2527 {
2528    Entry *en = rp->entry_data;
2529    if (!en) return EINA_FALSE;
2530 #ifdef HAVE_ECORE_IMF
2531    if (en->imf_context)
2532      return ecore_imf_context_input_panel_enabled_get(en->imf_context);
2533 #endif
2534
2535    return EINA_FALSE;
2536 }
2537
2538 static Evas_Textblock_Cursor *
2539 _cursor_get(Edje_Real_Part *rp, Edje_Cursor cur)
2540 {
2541    Entry *en = rp->entry_data;
2542    if (!en) return NULL;
2543
2544    switch (cur)
2545      {
2546       case EDJE_CURSOR_MAIN:
2547          return en->cursor;
2548       case EDJE_CURSOR_SELECTION_BEGIN:
2549          return en->sel_start;
2550       case EDJE_CURSOR_SELECTION_END:
2551          return en->sel_end;
2552       case EDJE_CURSOR_PREEDIT_START:
2553          if (!en->preedit_start)
2554            en->preedit_start = evas_object_textblock_cursor_new(rp->object);
2555          return en->preedit_start;
2556       case EDJE_CURSOR_PREEDIT_END:
2557          if (!en->preedit_end)
2558            en->preedit_end = evas_object_textblock_cursor_new(rp->object);
2559          return en->preedit_end;
2560       case EDJE_CURSOR_USER:
2561          if (!en->cursor_user)
2562            en->cursor_user = evas_object_textblock_cursor_new(rp->object);
2563          return en->cursor_user;
2564       case EDJE_CURSOR_USER_EXTRA:
2565          if (!en->cursor_user_extra)
2566            en->cursor_user_extra = evas_object_textblock_cursor_new(rp->object);
2567          return en->cursor_user_extra;
2568       default:
2569          break;
2570      }
2571    return NULL;
2572 }
2573
2574 Eina_Bool
2575 _edje_entry_cursor_next(Edje_Real_Part *rp, Edje_Cursor cur)
2576 {
2577    Entry *en = rp->entry_data;
2578    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
2579    if (!c) return EINA_FALSE;
2580    if (!evas_textblock_cursor_char_next(c))
2581      {
2582         return EINA_FALSE;
2583      }
2584    _sel_update(c, rp->object, rp->entry_data);
2585
2586    _edje_entry_imf_context_reset(en);
2587    _edje_entry_imf_cursor_info_set(en);
2588
2589    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
2590    _edje_entry_real_part_configure(rp);
2591    return EINA_TRUE;
2592 }
2593
2594 Eina_Bool
2595 _edje_entry_cursor_prev(Edje_Real_Part *rp, Edje_Cursor cur)
2596 {
2597    Entry *en = rp->entry_data;
2598    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
2599    if (!c) return EINA_FALSE;
2600    if (!evas_textblock_cursor_char_prev(c))
2601      {
2602         if (evas_textblock_cursor_paragraph_prev(c)) goto ok;
2603         else return EINA_FALSE;
2604      }
2605 ok:
2606    _sel_update(c, rp->object, rp->entry_data);
2607
2608    _edje_entry_imf_context_reset(en);
2609    _edje_entry_imf_cursor_info_set(en);
2610
2611    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
2612    _edje_entry_real_part_configure(rp);
2613    return EINA_TRUE;
2614 }
2615
2616 Eina_Bool
2617 _edje_entry_cursor_up(Edje_Real_Part *rp, Edje_Cursor cur)
2618 {
2619    Entry *en = rp->entry_data;
2620    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
2621    Evas_Coord lx, ly, lw, lh, cx, cy, cw, ch;
2622    int ln;
2623    if (!c) return EINA_FALSE;
2624    ln = evas_textblock_cursor_line_geometry_get(c, NULL, NULL, NULL, NULL);
2625    ln--;
2626    if (ln < 0) return EINA_FALSE;
2627    if (!evas_object_textblock_line_number_geometry_get(rp->object, ln,
2628                                                        &lx, &ly, &lw, &lh))
2629      return EINA_FALSE;
2630    evas_textblock_cursor_char_geometry_get(c, &cx, &cy, &cw, &ch);
2631    if (!evas_textblock_cursor_char_coord_set(c, cx, ly + (lh / 2)))
2632      {
2633         if (cx < (lx + (lw / 2)))
2634           evas_textblock_cursor_line_char_last(c);
2635         else
2636           evas_textblock_cursor_line_char_last(c);
2637      }
2638    _sel_update(c, rp->object, rp->entry_data);
2639
2640    _edje_entry_imf_context_reset(en);
2641    _edje_entry_imf_cursor_info_set(en);
2642
2643    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
2644    _edje_entry_real_part_configure(rp);
2645    return EINA_TRUE;
2646 }
2647
2648 Eina_Bool
2649 _edje_entry_cursor_down(Edje_Real_Part *rp, Edje_Cursor cur)
2650 {
2651    Entry *en = rp->entry_data;
2652    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
2653    Evas_Coord lx, ly, lw, lh, cx, cy, cw, ch;
2654    int ln;
2655    if (!c) return EINA_FALSE;
2656    ln = evas_textblock_cursor_line_geometry_get(c, NULL, NULL, NULL, NULL);
2657    ln++;
2658    if (!evas_object_textblock_line_number_geometry_get(rp->object, ln,
2659                                                        &lx, &ly, &lw, &lh))
2660      return EINA_FALSE;
2661    evas_textblock_cursor_char_geometry_get(c, &cx, &cy, &cw, &ch);
2662    if (!evas_textblock_cursor_char_coord_set(c, cx, ly + (lh / 2)))
2663      {
2664         if (cx < (lx + (lw / 2)))
2665           evas_textblock_cursor_line_char_last(c);
2666         else
2667           evas_textblock_cursor_line_char_last(c);
2668      }
2669    _sel_update(c, rp->object, rp->entry_data);
2670
2671    _edje_entry_imf_context_reset(en);
2672    _edje_entry_imf_cursor_info_set(en);
2673    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
2674    _edje_entry_real_part_configure(rp);
2675    return EINA_TRUE;
2676 }
2677
2678 void
2679 _edje_entry_cursor_begin(Edje_Real_Part *rp, Edje_Cursor cur)
2680 {
2681    Entry *en = rp->entry_data;
2682    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
2683    if (!c) return;
2684    evas_textblock_cursor_paragraph_first(c);
2685    _sel_update(c, rp->object, rp->entry_data);
2686
2687    _edje_entry_imf_context_reset(en);
2688    _edje_entry_imf_cursor_info_set(en);
2689    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
2690    _edje_entry_real_part_configure(rp);
2691 }
2692
2693 void
2694 _edje_entry_cursor_end(Edje_Real_Part *rp, Edje_Cursor cur)
2695 {
2696    Entry *en = rp->entry_data;
2697    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
2698    if (!c) return;
2699    _curs_end(c, rp->object, rp->entry_data);
2700    _sel_update(c, rp->object, rp->entry_data);
2701
2702    _edje_entry_imf_context_reset(en);
2703    _edje_entry_imf_cursor_info_set(en);
2704
2705    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
2706    _edje_entry_real_part_configure(rp);
2707 }
2708
2709 void
2710 _edje_entry_cursor_copy(Edje_Real_Part *rp, Edje_Cursor cur, Edje_Cursor dst)
2711 {
2712    Entry *en = rp->entry_data;
2713    Evas_Textblock_Cursor *c;
2714    Evas_Textblock_Cursor *d;
2715
2716    c = _cursor_get(rp, cur);
2717    if (!c) return;
2718    d = _cursor_get(rp, dst);
2719    if (!d) return;
2720    evas_textblock_cursor_copy(c, d);
2721    _sel_update(c, rp->object, rp->entry_data);
2722
2723    _edje_entry_imf_context_reset(en);
2724    _edje_entry_imf_cursor_info_set(en);
2725    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
2726    _edje_entry_real_part_configure(rp);
2727 }
2728
2729 void
2730 _edje_entry_cursor_line_begin(Edje_Real_Part *rp, Edje_Cursor cur)
2731 {
2732    Entry *en = rp->entry_data;
2733    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
2734    if (!c) return;
2735    evas_textblock_cursor_line_char_first(c);
2736    _sel_update(c, rp->object, rp->entry_data);
2737
2738    _edje_entry_imf_context_reset(en);
2739    _edje_entry_imf_cursor_info_set(en);
2740
2741    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
2742    _edje_entry_real_part_configure(rp);
2743 }
2744
2745 void
2746 _edje_entry_cursor_line_end(Edje_Real_Part *rp, Edje_Cursor cur)
2747 {
2748    Entry *en = rp->entry_data;
2749    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
2750    if (!c) return;
2751    evas_textblock_cursor_line_char_last(c);
2752    _sel_update(c, rp->object, rp->entry_data);
2753
2754    _edje_entry_imf_context_reset(en);
2755    _edje_entry_imf_cursor_info_set(en);
2756    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
2757    _edje_entry_real_part_configure(rp);
2758 }
2759
2760 Eina_Bool
2761 _edje_entry_cursor_coord_set(Edje_Real_Part *rp, Edje_Cursor cur,
2762                              Evas_Coord x, Evas_Coord y)
2763 {
2764    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
2765    if (!c) return EINA_FALSE;
2766    return evas_textblock_cursor_char_coord_set(c, x, y);
2767 }
2768
2769 Eina_Bool
2770 _edje_entry_cursor_is_format_get(Edje_Real_Part *rp, Edje_Cursor cur)
2771 {
2772    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
2773    if (!c) return EINA_FALSE;
2774    if (evas_textblock_cursor_is_format(c)) return EINA_TRUE;
2775    return EINA_FALSE;
2776 }
2777
2778 Eina_Bool
2779 _edje_entry_cursor_is_visible_format_get(Edje_Real_Part *rp, Edje_Cursor cur)
2780 {
2781    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
2782    if (!c) return EINA_FALSE;
2783    return evas_textblock_cursor_format_is_visible_get(c);
2784 }
2785
2786 char *
2787 _edje_entry_cursor_content_get(Edje_Real_Part *rp, Edje_Cursor cur)
2788 {
2789    static char *s = NULL;
2790    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
2791
2792    if (!c) return NULL;
2793    if (s)
2794      {
2795         free(s);
2796         s = NULL;
2797      }
2798
2799    s = evas_textblock_cursor_content_get(c);
2800    return s;
2801 }
2802
2803 void
2804 _edje_entry_cursor_pos_set(Edje_Real_Part *rp, Edje_Cursor cur, int pos)
2805 {
2806    Entry *en = rp->entry_data;
2807    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
2808    if (!c) return;
2809    /* Abort if cursor position didn't really change */
2810    if (evas_textblock_cursor_pos_get(c) == pos)
2811       return;
2812
2813    evas_textblock_cursor_pos_set(c, pos);
2814    _sel_update(c, rp->object, rp->entry_data);
2815
2816    _edje_entry_imf_context_reset(en);
2817    _edje_entry_imf_cursor_info_set(en);
2818    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
2819    _edje_entry_real_part_configure(rp);
2820 }
2821
2822 int
2823 _edje_entry_cursor_pos_get(Edje_Real_Part *rp, Edje_Cursor cur)
2824 {
2825    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
2826    if (!c) return 0;
2827    return evas_textblock_cursor_pos_get(c);
2828 }
2829
2830 void
2831 _edje_entry_input_panel_layout_set(Edje_Real_Part *rp, Edje_Input_Panel_Layout layout)
2832 {
2833    Entry *en = rp->entry_data;
2834    if (!en) return;
2835 #ifdef HAVE_ECORE_IMF
2836    if (en->imf_context)
2837      ecore_imf_context_input_panel_layout_set(en->imf_context, layout);
2838 #else
2839    (void) layout;
2840 #endif
2841 }
2842
2843 Edje_Input_Panel_Layout
2844 _edje_entry_input_panel_layout_get(Edje_Real_Part *rp)
2845 {
2846    Entry *en = rp->entry_data;
2847    if (!en) return EDJE_INPUT_PANEL_LAYOUT_INVALID;
2848 #ifdef HAVE_ECORE_IMF
2849    if (en->imf_context)
2850      return ecore_imf_context_input_panel_layout_get(en->imf_context);
2851 #endif
2852
2853    return EDJE_INPUT_PANEL_LAYOUT_INVALID;
2854 }
2855
2856 static void
2857 _edje_entry_imf_context_reset(Entry *en)
2858 {
2859 #ifdef HAVE_ECORE_IMF
2860    if (en->imf_context)
2861      ecore_imf_context_reset(en->imf_context);
2862 #else
2863    (void) en;
2864 #endif
2865 }
2866
2867 static void
2868 _edje_entry_imf_cursor_info_set(Entry *en)
2869 {
2870 #ifdef HAVE_ECORE_IMF
2871    Evas_Coord cx, cy, cw, ch;
2872    if (!en || !en->rp || !en->imf_context) return;
2873
2874    _edje_entry_cursor_geometry_get(en->rp, &cx, &cy, &cw, &ch);
2875
2876    ecore_imf_context_cursor_position_set(en->imf_context,
2877                                          evas_textblock_cursor_pos_get(en->cursor));
2878    ecore_imf_context_cursor_location_set(en->imf_context, cx, cy, cw, ch);
2879 #else
2880    (void) en;
2881 #endif
2882 }
2883
2884 #ifdef HAVE_ECORE_IMF
2885 static Eina_Bool
2886 _edje_entry_imf_retrieve_surrounding_cb(void *data, Ecore_IMF_Context *ctx __UNUSED__, char **text, int *cursor_pos)
2887 {
2888    Edje *ed = data;
2889    Edje_Real_Part *rp = ed->focused_part;
2890    Entry *en;
2891    const char *str;
2892
2893    if (!rp) return EINA_FALSE;
2894    en = rp->entry_data;
2895    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
2896        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE))
2897      return EINA_FALSE;
2898
2899    if (text)
2900      {
2901         str = _edje_entry_text_get(rp);
2902         *text = str ? strdup(str) : strdup("");
2903      }
2904
2905    if (cursor_pos)
2906      *cursor_pos = evas_textblock_cursor_pos_get(en->cursor);
2907
2908    return EINA_TRUE;
2909 }
2910
2911 static Eina_Bool
2912 _edje_entry_imf_event_commit_cb(void *data, int type __UNUSED__, void *event)
2913 {
2914    Edje *ed = data;
2915    Edje_Real_Part *rp = ed->focused_part;
2916    Entry *en;
2917    Ecore_IMF_Event_Commit *ev = event;
2918    Evas_Textblock_Cursor *tc;
2919    Eina_Bool cursor_move = EINA_FALSE;
2920    int start_pos;
2921
2922    if ((!rp) || (!ev) || (!ev->str)) return ECORE_CALLBACK_PASS_ON;
2923
2924    en = rp->entry_data;
2925    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
2926        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE))
2927      return ECORE_CALLBACK_PASS_ON;
2928
2929    if (!en->imf_context) return ECORE_CALLBACK_PASS_ON;
2930    if (en->imf_context != ev->ctx) return ECORE_CALLBACK_PASS_ON;
2931
2932    if (en->have_selection)
2933      {
2934         if (strcmp(ev->str, ""))
2935           {
2936              /* delete selected characters */
2937              _range_del_emit(ed, en->cursor, rp->object, en);
2938              _sel_clear(en->cursor, rp->object, en);
2939           }
2940      }
2941
2942    tc = evas_object_textblock_cursor_new(rp->object);
2943
2944    /* calculate the cursor position to insert commit string */
2945    if (en->preedit_start)
2946      evas_textblock_cursor_copy(en->preedit_start, tc);
2947    else
2948      evas_textblock_cursor_copy(en->cursor, tc);
2949
2950    start_pos = evas_textblock_cursor_pos_get(tc);
2951
2952
2953 #ifdef HAVE_ECORE_IMF
2954    /* delete preedit characters */
2955    _preedit_del(en);
2956    _preedit_clear(en);
2957 #endif
2958
2959    if (evas_textblock_cursor_compare(en->cursor, tc))
2960      cursor_move = EINA_TRUE;
2961    if ((rp->part->entry_mode == EDJE_ENTRY_EDIT_MODE_PASSWORD) &&
2962        _edje_password_show_last)
2963      _edje_entry_hide_visible_password(en->rp);
2964    if ((rp->part->entry_mode == EDJE_ENTRY_EDIT_MODE_PASSWORD) &&
2965        _edje_password_show_last && (!en->preedit_start))
2966      {
2967         _text_filter_format_prepend(en, tc, "+ password=off");
2968         _text_filter_text_prepend(en, tc, ev->str);
2969         _text_filter_format_prepend(en, tc, "- password");
2970         if (en->pw_timer)
2971           {
2972              ecore_timer_del(en->pw_timer);
2973              en->pw_timer = NULL;
2974           }
2975         en->pw_timer = ecore_timer_add(_edje_password_show_last_timeout,
2976                                        _password_timer_cb, en);
2977      }
2978    else
2979      _text_filter_text_prepend(en, tc, ev->str);
2980
2981    if (!cursor_move)
2982      {
2983         /* move cursor to the end of commit string */
2984         evas_textblock_cursor_copy(tc, en->cursor);
2985      }
2986
2987    evas_textblock_cursor_free(tc);
2988
2989    _edje_entry_imf_cursor_info_set(en);
2990    _anchors_get(en->cursor, rp->object, en);
2991    _edje_emit(rp->edje, "entry,changed", rp->part->name);
2992
2993      {
2994         Edje_Entry_Change_Info *info = calloc(1, sizeof(*info));
2995         info->insert = EINA_TRUE;
2996         info->change.insert.pos = start_pos;
2997         info->change.insert.content = eina_stringshare_add(ev->str);
2998         info->change.insert.plain_length =
2999            eina_unicode_utf8_get_len(info->change.insert.content);
3000         _edje_emit_full(ed, "entry,changed,user", rp->part->name,
3001                         info, _free_entry_change_info);
3002         _edje_emit(ed, "cursor,changed", rp->part->name);
3003      }
3004
3005    return ECORE_CALLBACK_DONE;
3006 }
3007
3008 static Eina_Bool
3009 _edje_entry_imf_event_preedit_changed_cb(void *data, int type __UNUSED__, void *event)
3010 {
3011    Edje *ed = data;
3012    Edje_Real_Part *rp = ed->focused_part;
3013    Entry *en;
3014    Ecore_IMF_Event_Preedit_Changed *ev = event;
3015    int cursor_pos;
3016    int preedit_start_pos, preedit_end_pos;
3017    char *preedit_string;
3018    int i;
3019    Eina_Bool preedit_end_state = EINA_FALSE;
3020    Eina_List *attrs = NULL, *l = NULL;
3021    Ecore_IMF_Preedit_Attr *attr;
3022    Eina_Strbuf *buf;
3023
3024    if ((!rp) || (!ev)) return ECORE_CALLBACK_PASS_ON;
3025
3026    en = rp->entry_data;
3027    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
3028        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE))
3029      return ECORE_CALLBACK_PASS_ON;
3030
3031    if (!en->imf_context) return ECORE_CALLBACK_PASS_ON;
3032
3033    if (en->imf_context != ev->ctx) return ECORE_CALLBACK_PASS_ON;
3034
3035    ecore_imf_context_preedit_string_with_attributes_get(en->imf_context,
3036                                                         &preedit_string,
3037                                                         &attrs, &cursor_pos);
3038    if (!preedit_string) return ECORE_CALLBACK_PASS_ON;
3039
3040    if (!strcmp(preedit_string, ""))
3041      preedit_end_state = EINA_TRUE;
3042
3043    if (en->have_selection && !preedit_end_state)
3044      {
3045         /* delete selected characters */
3046         _range_del_emit(ed, en->cursor, rp->object, en);
3047         _sel_clear(en->cursor, rp->object, en);
3048      }
3049
3050    /* delete preedit characters */
3051    _preedit_del(en);
3052
3053    preedit_start_pos = evas_textblock_cursor_pos_get(en->cursor);
3054
3055    /* insert preedit character(s) */
3056    if (strlen(preedit_string) > 0)
3057      {
3058         buf = eina_strbuf_new();
3059         if (attrs)
3060           {
3061              EINA_LIST_FOREACH(attrs, l, attr)
3062                {
3063                   if (attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB1)
3064                     {
3065                        eina_strbuf_append(buf, "<preedit>");
3066                        eina_strbuf_append_n(buf, preedit_string + attr->start_index,
3067                                             attr->end_index - attr->start_index);
3068                        eina_strbuf_append(buf, "</preedit>");
3069                     }
3070
3071                   else if (attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB2 ||
3072                            attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB3)
3073                     {
3074                        eina_strbuf_append(buf, "<preedit_sel>");
3075                        eina_strbuf_append_n(buf, preedit_string + attr->start_index,
3076                                             attr->end_index - attr->start_index);
3077                        eina_strbuf_append(buf, "</preedit_sel>");
3078                     }
3079                }
3080           }
3081         if ((rp->part->entry_mode == EDJE_ENTRY_EDIT_MODE_PASSWORD) &&
3082             _edje_password_show_last)
3083           {
3084              _edje_entry_hide_visible_password(en->rp);
3085              _text_filter_format_prepend(en, en->cursor, "+ password=off");
3086              _text_filter_markup_prepend(en, en->cursor, eina_strbuf_string_get(buf));
3087              _text_filter_format_prepend(en, en->cursor, "- password");
3088              if (en->pw_timer)
3089                {
3090                   ecore_timer_del(en->pw_timer);
3091                   en->pw_timer = NULL;
3092                }
3093              en->pw_timer = ecore_timer_add(_edje_password_show_last_timeout,
3094                                             _password_timer_cb, en);
3095           }
3096         else
3097           {
3098              _text_filter_markup_prepend(en, en->cursor, eina_strbuf_string_get(buf));
3099           }
3100         eina_strbuf_free(buf);
3101      }
3102
3103    if (!preedit_end_state)
3104      {
3105         /* set preedit start cursor */
3106         if (!en->preedit_start)
3107           en->preedit_start = evas_object_textblock_cursor_new(rp->object);
3108         evas_textblock_cursor_copy(en->cursor, en->preedit_start);
3109
3110         /* set preedit end cursor */
3111         if (!en->preedit_end)
3112           en->preedit_end = evas_object_textblock_cursor_new(rp->object);
3113         evas_textblock_cursor_copy(en->cursor, en->preedit_end);
3114
3115         preedit_end_pos = evas_textblock_cursor_pos_get(en->cursor);
3116
3117         for (i = 0; i < (preedit_end_pos - preedit_start_pos); i++)
3118           {
3119              evas_textblock_cursor_char_prev(en->preedit_start);
3120           }
3121
3122         en->have_preedit = EINA_TRUE;
3123
3124         /* set cursor position */
3125         evas_textblock_cursor_pos_set(en->cursor, preedit_start_pos + cursor_pos);
3126      }
3127
3128    _edje_entry_imf_cursor_info_set(en);
3129    _anchors_get(en->cursor, rp->object, en);
3130    _edje_emit(rp->edje, "preedit,changed", rp->part->name);
3131    _edje_emit(ed, "cursor,changed", rp->part->name);
3132
3133    /* delete attribute list */
3134    if (attrs)
3135      {
3136         EINA_LIST_FREE(attrs, attr) free(attr);
3137      }
3138
3139    free(preedit_string);
3140
3141    return ECORE_CALLBACK_DONE;
3142 }
3143
3144 static Eina_Bool
3145 _edje_entry_imf_event_delete_surrounding_cb(void *data, int type __UNUSED__, void *event)
3146 {
3147    Edje *ed = data;
3148    Edje_Real_Part *rp = ed->focused_part;
3149    Entry *en;
3150    Ecore_IMF_Event_Delete_Surrounding *ev = event;
3151    Evas_Textblock_Cursor *del_start, *del_end;
3152    int cursor_pos;
3153
3154    if ((!rp) || (!ev)) return ECORE_CALLBACK_PASS_ON;
3155    en = rp->entry_data;
3156    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
3157        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE))
3158      return ECORE_CALLBACK_PASS_ON;
3159
3160    if (!en->imf_context) return ECORE_CALLBACK_PASS_ON;
3161    if (en->imf_context != ev->ctx) return ECORE_CALLBACK_PASS_ON;
3162
3163    cursor_pos = evas_textblock_cursor_pos_get(en->cursor);
3164
3165    del_start = evas_object_textblock_cursor_new(en->rp->object);
3166    evas_textblock_cursor_pos_set(del_start, cursor_pos + ev->offset);
3167
3168    del_end = evas_object_textblock_cursor_new(en->rp->object);
3169    evas_textblock_cursor_pos_set(del_end, cursor_pos + ev->offset + ev->n_chars);
3170
3171    evas_textblock_cursor_range_delete(del_start, del_end);
3172
3173    evas_textblock_cursor_free(del_start);
3174    evas_textblock_cursor_free(del_end);
3175
3176    return ECORE_CALLBACK_DONE;
3177 }
3178 #endif
3179
3180 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/