8314d05083732285a30c9c59a4ae36e4716ca03b
[framework/uifw/edje.git] / src / lib / edje_entry.c
1 #include "edje_private.h"
2 #include <ctype.h>
3
4 #ifdef HAVE_ECORE_IMF
5 static Eina_Bool _edje_entry_imf_retrieve_surrounding_cb(void *data, Ecore_IMF_Context *ctx, char **text, int *cursor_pos);
6 static void      _edje_entry_imf_event_commit_cb(void *data, Ecore_IMF_Context *ctx, void *event_info);
7 static void      _edje_entry_imf_event_preedit_changed_cb(void *data, Ecore_IMF_Context *ctx, void *event_info);
8 static void      _edje_entry_imf_event_delete_surrounding_cb(void *data, Ecore_IMF_Context *ctx, void *event);
9 #endif
10
11 // TIZEN ONLY - START
12 static void _edje_entry_start_handler_mouse_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
13 static void _edje_entry_start_handler_mouse_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
14 static void _edje_entry_start_handler_mouse_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
15
16 static void _edje_entry_end_handler_mouse_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
17 static void _edje_entry_end_handler_mouse_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
18 static void _edje_entry_end_handler_mouse_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
19
20 static void _edje_entry_cursor_handler_mouse_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
21 static void _edje_entry_cursor_handler_mouse_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
22 static void _edje_entry_cursor_handler_mouse_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info);
23 // TIZEN ONLY - END
24
25 typedef struct _Entry Entry;
26 typedef struct _Sel Sel;
27 typedef struct _Anchor Anchor;
28
29 // TIZEN ONLY - START
30 typedef enum _Entry_Long_Press_State
31 {
32    _ENTRY_LONG_PRESSING,
33    _ENTRY_LONG_PRESSED,
34    _ENTRY_LONG_PRESS_RELEASED
35 } Entry_Long_Press_State;
36 // TIZEN ONLY - END
37
38 static void _edje_entry_imf_cursor_location_set(Entry *en);
39 static void _edje_entry_imf_cursor_info_set(Entry *en);
40
41 struct _Entry
42 {
43    Edje_Real_Part *rp;
44    Evas_Coord ox, oy; // TIZEN ONLY
45    Evas_Coord sx, sy; // TIZEN ONLY
46    Evas_Coord rx, ry; // TIZEN ONLY
47    Evas_Coord dx, dy; // TIZEN ONLY
48    Evas_Coord_Rectangle layout_region; // TIZEN ONLY
49    Evas_Coord_Rectangle viewport_region; // TIZEN ONLY
50    Evas_Object *cursor_bg;
51    Evas_Object *cursor_fg, *cursor_fg2;
52    Evas_Object *sel_handler_start; // TIZEN ONLY
53    Evas_Object *sel_handler_end; // TIZEN ONLY
54    Evas_Object *sel_handler_edge_start; // TIZEN ONLY
55    Evas_Object *sel_handler_edge_end; // TIZEN ONLY
56    Evas_Object *cursor_handler; // TIZEN ONLY
57    Evas_Textblock_Cursor *cursor;
58    Evas_Textblock_Cursor *sel_start, *sel_end;
59    Evas_Textblock_Cursor *cursor_user, *cursor_user_extra;
60    Evas_Textblock_Cursor *preedit_start, *preedit_end;
61    Ecore_Timer *pw_timer;
62    Eina_List *sel;
63    Eina_List *anchors;
64    Eina_List *anchorlist;
65    Eina_List *itemlist;
66    Eina_List *seq;
67    char *selection;
68    Edje_Input_Panel_Lang input_panel_lang;
69    Eina_Bool composing : 1;
70    Eina_Bool selecting : 1;
71    Eina_Bool have_selection : 1;
72    Eina_Bool select_allow : 1;
73    Eina_Bool select_mod_start : 1;
74    Eina_Bool select_mod_end : 1;
75    Eina_Bool handler_bypassing: 1; // TIZEN ONLY
76    Eina_Bool cursor_handler_disabled: 1; // TIZEN ONLY
77    Eina_Bool cursor_handler_show : 1; // TIZEN ONLY
78    Eina_Bool had_sel : 1;
79    Eina_Bool input_panel_enable : 1;
80    Eina_Bool prediction_allow : 1;
81    Eina_Bool focused : 1; // TIZEN ONLY
82    Eina_Bool vp_updated : 1; // TIZEN ONLY
83    Eina_Bool sh_start_normal_pos : 1; // TIZEN ONLY
84    Eina_Bool sh_end_normal_pos : 1; // TIZEN ONLY
85    // TIZEN ONLY(130129) : Currently, for freezing cursor movement.
86    Eina_Bool freeze : 1;
87    //
88    int select_dragging_state;
89
90 #ifdef HAVE_ECORE_IMF
91    Eina_Bool have_preedit : 1;
92    Eina_Bool commit_cancel : 1; // For skipping useless commit
93    Ecore_IMF_Context *imf_context;
94 #endif
95
96    Ecore_Timer *long_press_timer; // TIZEN ONLY
97    Ecore_Timer *cursor_handler_click_timer; // TIZEN ONLY
98    Entry_Long_Press_State long_press_state; // TIZEN ONLY
99 };
100
101 struct _Sel
102 {
103    Evas_Textblock_Rectangle rect;
104    Evas_Object *obj_fg, *obj_bg, *obj, *sobj;
105 };
106
107 struct _Anchor
108 {
109    Entry *en;
110    char *name;
111    Evas_Textblock_Cursor *start, *end;
112    Eina_List *sel;
113    Eina_Bool item : 1;
114 };
115
116 #ifdef HAVE_ECORE_IMF
117 static void
118 _preedit_clear(Entry *en)
119 {
120    if (en->preedit_start)
121      {
122         evas_textblock_cursor_free(en->preedit_start);
123         en->preedit_start = NULL;
124      }
125
126    if (en->preedit_end)
127      {
128         evas_textblock_cursor_free(en->preedit_end);
129         en->preedit_end = NULL;
130      }
131
132    en->have_preedit = EINA_FALSE;
133 }
134
135 static void
136 _preedit_del(Entry *en)
137 {
138    if (!en || !en->have_preedit) return;
139    if (!en->preedit_start || !en->preedit_end) return;
140    if (!evas_textblock_cursor_compare(en->preedit_start, en->preedit_end)) return;
141
142    /* delete the preedit characters */
143    evas_textblock_cursor_range_delete(en->preedit_start, en->preedit_end);
144 }
145
146 static void
147 _edje_entry_focus_in_cb(void *data, Evas_Object *o __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
148 {
149    Edje_Real_Part *rp;
150    Entry *en;
151
152    rp = data;
153    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
154        (!rp->typedata.text)) return;
155    if (!rp || !rp->typedata.text->entry_data || !rp->edje || !rp->edje->obj) return;
156
157    en = rp->typedata.text->entry_data;
158    if (!en || !en->imf_context) return;
159
160    if (evas_object_focus_get(rp->edje->obj))
161      {
162         // TIZEN ONLY - START
163         if ((!en->sel_handler_start) && (!en->sel_handler_end) &&
164             (en->rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_BLOCK_HANDLE))
165           {
166              if (rp->part->source8)
167                {
168                   en->sel_handler_end = edje_object_add(en->rp->edje->base.evas);
169                   edje_object_file_set(en->sel_handler_end, en->rp->edje->path, en->rp->part->source8);
170
171                   en->rp->edje->subobjs = eina_list_append(en->rp->edje->subobjs, en->sel_handler_end);
172                   evas_object_event_callback_add(en->sel_handler_end, EVAS_CALLBACK_MOUSE_DOWN, _edje_entry_end_handler_mouse_down_cb, en->rp);
173                   evas_object_event_callback_add(en->sel_handler_end, EVAS_CALLBACK_MOUSE_UP, _edje_entry_end_handler_mouse_up_cb, en->rp);
174                   evas_object_event_callback_add(en->sel_handler_end, EVAS_CALLBACK_MOUSE_MOVE, _edje_entry_end_handler_mouse_move_cb, en->rp);
175                }
176
177              if (rp->part->source7)
178                {
179                   en->sel_handler_start = edje_object_add(en->rp->edje->base.evas);
180                   edje_object_file_set(en->sel_handler_start, en->rp->edje->path, en->rp->part->source7);
181                   en->rp->edje->subobjs = eina_list_append(en->rp->edje->subobjs, en->sel_handler_start);
182                   evas_object_event_callback_add(en->sel_handler_start, EVAS_CALLBACK_MOUSE_DOWN, _edje_entry_start_handler_mouse_down_cb, en->rp);
183                   evas_object_event_callback_add(en->sel_handler_start, EVAS_CALLBACK_MOUSE_UP, _edje_entry_start_handler_mouse_up_cb, en->rp);
184                   evas_object_event_callback_add(en->sel_handler_start, EVAS_CALLBACK_MOUSE_MOVE, _edje_entry_start_handler_mouse_move_cb, en->rp);
185                }
186
187              //start edge handler
188              if (rp->part->source10)
189                {
190                   en->sel_handler_edge_start = edje_object_add(en->rp->edje->base.evas);
191                   edje_object_file_set(en->sel_handler_edge_start, en->rp->edje->path, en->rp->part->source10);
192                   en->rp->edje->subobjs = eina_list_append(en->rp->edje->subobjs, en->sel_handler_edge_start);
193                   evas_object_clip_set(en->sel_handler_edge_start, evas_object_clip_get(rp->object));
194                   if (en->sel_handler_start)
195                      evas_object_stack_below(en->sel_handler_edge_start, en->sel_handler_start);
196                   if (en->sel_handler_end)
197                      evas_object_stack_below(en->sel_handler_edge_start, en->sel_handler_end);
198                }
199
200              //end edge handler
201              if (rp->part->source11)
202                {
203                   en->sel_handler_edge_end = edje_object_add(en->rp->edje->base.evas);
204                   edje_object_file_set(en->sel_handler_edge_end, en->rp->edje->path, en->rp->part->source11);
205                   en->rp->edje->subobjs = eina_list_append(en->rp->edje->subobjs, en->sel_handler_edge_end);
206                   evas_object_clip_set(en->sel_handler_edge_end, evas_object_clip_get(rp->object));
207                   if (en->sel_handler_start)
208                      evas_object_stack_below(en->sel_handler_edge_end, en->sel_handler_start);
209                   if (en->sel_handler_end)
210                      evas_object_stack_below(en->sel_handler_edge_end, en->sel_handler_end);
211                }
212           }
213         if (en->sel_handler_start)
214            edje_object_signal_emit(en->sel_handler_start, "edje,focus,in", "edje");
215         if (en->sel_handler_end)
216            edje_object_signal_emit(en->sel_handler_end, "edje,focus,in", "edje");
217         if (en->cursor_handler)
218            edje_object_signal_emit(en->cursor_handler, "edje,focus,in", "edje");
219         if (en->sel_handler_edge_start)
220            edje_object_signal_emit(en->sel_handler_edge_start, "edje,focus,in", "edje");
221         if (en->sel_handler_edge_end)
222            edje_object_signal_emit(en->sel_handler_edge_end, "edje,focus,in", "edje");
223         // TIZEN ONLY - END
224
225         ecore_imf_context_reset(en->imf_context);
226         ecore_imf_context_focus_in(en->imf_context);
227         _edje_entry_imf_cursor_info_set(en);
228         en->focused = EINA_TRUE;
229      }
230 }
231
232 static void
233 _edje_entry_focus_out_cb(void *data, Evas_Object *o __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
234 {
235    Edje_Real_Part *rp;
236    Entry *en;
237
238    rp = data;
239    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
240        (!rp->typedata.text)) return;
241    if (!rp || !rp->typedata.text->entry_data) return;
242
243    en = rp->typedata.text->entry_data;
244    if (!en || !en->imf_context) return;
245
246    // TIZEN ONLY - START
247    if (en->sel_handler_start)
248      edje_object_signal_emit(en->sel_handler_start, "edje,focus,out", "edje");
249    if (en->sel_handler_end)
250      edje_object_signal_emit(en->sel_handler_end, "edje,focus,out", "edje");
251    if (en->cursor_handler)
252       edje_object_signal_emit(en->cursor_handler, "edje,focus,out", "edje");
253    if (en->sel_handler_edge_start)
254      edje_object_signal_emit(en->sel_handler_edge_start, "edje,focus,out", "edje");
255    if (en->sel_handler_edge_end)
256      edje_object_signal_emit(en->sel_handler_edge_end, "edje,focus,out", "edje");
257    // TIZEN ONLY - END
258
259    ecore_imf_context_reset(en->imf_context);
260    ecore_imf_context_focus_out(en->imf_context);
261 }
262 #endif
263
264 static void
265 _edje_focus_in_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
266 {
267    Edje *ed = data;
268 #ifdef HAVE_ECORE_IMF
269    Edje_Real_Part *rp;
270    Entry *en;
271 #endif
272
273    _edje_emit(ed, "focus,in", "");
274
275    rp = ed->focused_part;
276    if (!rp) return;
277
278    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
279        (!rp->typedata.text)) return;
280    en = rp->typedata.text->entry_data;
281    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
282        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE))   //  TIZEN ONLY
283      return;
284
285    // TIZEN ONLY - START
286    if ((!en->sel_handler_start) && (!en->sel_handler_end) &&
287        (en->rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_BLOCK_HANDLE))
288      {
289         if (rp->part->source8)
290           {
291              en->sel_handler_end = edje_object_add(en->rp->edje->base.evas);
292              edje_object_file_set(en->sel_handler_end, en->rp->edje->path, en->rp->part->source8);
293
294              en->rp->edje->subobjs = eina_list_append(en->rp->edje->subobjs, en->sel_handler_end);
295              evas_object_event_callback_add(en->sel_handler_end, EVAS_CALLBACK_MOUSE_DOWN, _edje_entry_end_handler_mouse_down_cb, en->rp);
296              evas_object_event_callback_add(en->sel_handler_end, EVAS_CALLBACK_MOUSE_UP, _edje_entry_end_handler_mouse_up_cb, en->rp);
297              evas_object_event_callback_add(en->sel_handler_end, EVAS_CALLBACK_MOUSE_MOVE, _edje_entry_end_handler_mouse_move_cb, en->rp);
298           }
299
300         if (rp->part->source7)
301           {
302              en->sel_handler_start = edje_object_add(en->rp->edje->base.evas);
303              edje_object_file_set(en->sel_handler_start, en->rp->edje->path, en->rp->part->source7);
304              en->rp->edje->subobjs = eina_list_append(en->rp->edje->subobjs, en->sel_handler_start);
305              evas_object_event_callback_add(en->sel_handler_start, EVAS_CALLBACK_MOUSE_DOWN, _edje_entry_start_handler_mouse_down_cb, en->rp);
306              evas_object_event_callback_add(en->sel_handler_start, EVAS_CALLBACK_MOUSE_UP, _edje_entry_start_handler_mouse_up_cb, en->rp);
307              evas_object_event_callback_add(en->sel_handler_start, EVAS_CALLBACK_MOUSE_MOVE, _edje_entry_start_handler_mouse_move_cb, en->rp);
308           }
309
310         //start edge handler
311         if (rp->part->source10)
312           {
313              en->sel_handler_edge_start = edje_object_add(en->rp->edje->base.evas);
314              edje_object_file_set(en->sel_handler_edge_start, en->rp->edje->path, en->rp->part->source10);
315              en->rp->edje->subobjs = eina_list_append(en->rp->edje->subobjs, en->sel_handler_edge_start);
316              evas_object_clip_set(en->sel_handler_edge_start, evas_object_clip_get(rp->object));
317              if (en->sel_handler_start)
318                 evas_object_stack_below(en->sel_handler_edge_start, en->sel_handler_start);
319              if (en->sel_handler_end)
320                 evas_object_stack_below(en->sel_handler_edge_start, en->sel_handler_end);
321           }
322
323         //end edge handler
324         if (rp->part->source11)
325           {
326              en->sel_handler_edge_end = edje_object_add(en->rp->edje->base.evas);
327              edje_object_file_set(en->sel_handler_edge_end, en->rp->edje->path, en->rp->part->source11);
328              en->rp->edje->subobjs = eina_list_append(en->rp->edje->subobjs, en->sel_handler_edge_end);
329              evas_object_clip_set(en->sel_handler_edge_end, evas_object_clip_get(rp->object));
330              if (en->sel_handler_start)
331                 evas_object_stack_below(en->sel_handler_edge_end, en->sel_handler_start);
332              if (en->sel_handler_end)
333                 evas_object_stack_below(en->sel_handler_edge_end, en->sel_handler_end);
334           }
335      }
336    if (en->sel_handler_start)
337       edje_object_signal_emit(en->sel_handler_start, "edje,focus,in", "edje");
338    if (en->sel_handler_end)
339       edje_object_signal_emit(en->sel_handler_end, "edje,focus,in", "edje");
340    if (en->cursor_handler)
341       edje_object_signal_emit(en->cursor_handler, "edje,focus,in", "edje");
342    if (en->sel_handler_edge_start)
343       edje_object_signal_emit(en->sel_handler_edge_start, "edje,focus,in", "edje");
344    if (en->sel_handler_edge_end)
345       edje_object_signal_emit(en->sel_handler_edge_end, "edje,focus,in", "edje");
346
347    en->focused = EINA_TRUE;
348    if (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_EDITABLE) return;
349    // TIZEN ONLY - END
350
351 #ifdef HAVE_ECORE_IMF
352    if (!en->imf_context) return;
353
354    ecore_imf_context_reset(en->imf_context);
355    ecore_imf_context_focus_in(en->imf_context);
356    _edje_entry_imf_cursor_info_set(en);
357 #endif
358 }
359
360 static void
361 _edje_focus_out_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
362 {
363    Edje *ed = data;
364 #ifdef HAVE_ECORE_IMF
365    Edje_Real_Part *rp = ed->focused_part;
366    Entry *en;
367 #endif
368
369    _edje_emit(ed, "focus,out", "");
370
371 #ifdef HAVE_ECORE_IMF
372    if (!rp) return;
373    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
374        (!rp->typedata.text)) return;
375    en = rp->typedata.text->entry_data;
376    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
377        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE))  // TIZEN ONLY
378      return;
379
380    // TIZEN ONLY - START
381    if (en->sel_handler_start)
382      edje_object_signal_emit(en->sel_handler_start, "edje,focus,out", "edje");
383    if (en->sel_handler_end)
384      edje_object_signal_emit(en->sel_handler_end, "edje,focus,out", "edje");
385    if (en->cursor_handler)
386       edje_object_signal_emit(en->cursor_handler, "edje,focus,out", "edje");
387    if (en->sel_handler_edge_start)
388      edje_object_signal_emit(en->sel_handler_edge_start, "edje,focus,out", "edje");
389    if (en->sel_handler_edge_end)
390      edje_object_signal_emit(en->sel_handler_edge_end, "edje,focus,out", "edje");
391    en->focused = EINA_FALSE;
392    if (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_EDITABLE) return;
393    // TIZEN ONLY - END
394
395    if (!en->imf_context) return;
396
397    ecore_imf_context_reset(en->imf_context);
398    ecore_imf_context_focus_out(en->imf_context);
399 #endif
400 }
401
402 static void
403 _text_filter_markup_prepend_internal(Entry *en, Evas_Textblock_Cursor *c, char *text)
404 {
405    Edje_Markup_Filter_Callback *cb;
406    Eina_List *l;
407
408    EINA_LIST_FOREACH(en->rp->edje->markup_filter_callbacks, l, cb)
409      {
410         if (!strcmp(cb->part, en->rp->part->name))
411           {
412              cb->func(cb->data, en->rp->edje->obj, cb->part, &text);
413              if (!text) break;
414           }
415      }
416 #ifdef HAVE_ECORE_IMF
417    // For skipping useless commit
418    if (en->have_preedit && (!text || !strcmp(text, "")))
419      en->commit_cancel = EINA_TRUE;
420    else
421      en->commit_cancel = EINA_FALSE;
422 #endif
423    if (text)
424      {
425         evas_object_textblock_text_markup_prepend(c, text);
426         free(text);
427      }
428 }
429
430 static void
431 _text_filter_text_prepend(Entry *en, Evas_Textblock_Cursor *c, const char *text)
432 {
433    char *text2;
434    Edje_Text_Insert_Filter_Callback *cb;
435    Eina_List *l;
436
437    text2 = strdup(text);
438    EINA_LIST_FOREACH(en->rp->edje->text_insert_filter_callbacks, l, cb)
439      {
440         if (!strcmp(cb->part, en->rp->part->name))
441           {
442              cb->func(cb->data, en->rp->edje->obj, cb->part, EDJE_TEXT_FILTER_TEXT, &text2);
443              if (!text2) break;
444           }
445      }
446    if (text2)
447      {
448         char *markup_text;
449         markup_text = evas_textblock_text_utf8_to_markup(NULL, text2);
450         free(text2);
451         if (markup_text)
452           _text_filter_markup_prepend_internal(en, c, markup_text);
453      }
454 }
455
456 static void
457 _text_filter_format_prepend(Entry *en, Evas_Textblock_Cursor *c, const char *text)
458 {
459    char *text2;
460    Edje_Text_Insert_Filter_Callback *cb;
461    Eina_List *l;
462
463    text2 = strdup(text);
464    EINA_LIST_FOREACH(en->rp->edje->text_insert_filter_callbacks, l, cb)
465      {
466         if (!strcmp(cb->part, en->rp->part->name))
467           {
468              cb->func(cb->data, en->rp->edje->obj, cb->part, EDJE_TEXT_FILTER_FORMAT, &text2);
469              if (!text2) break;
470           }
471      }
472    if (text2)
473      {
474         char *s, *markup_text;
475
476         s = text2;
477         if (*s == '+')
478           {
479              s++;
480              while (*s == ' ') s++;
481              if (!s)
482                {
483                   free(text2);
484                   return;
485                }
486              markup_text = (char*) malloc(strlen(s) + 3);
487              if (markup_text)
488                {
489                   *(markup_text) = '<';
490                   strncpy((markup_text + 1), s, strlen(s));
491                   *(markup_text + strlen(s) + 1) = '>';
492                   *(markup_text + strlen(s) + 2) = '\0';
493                }
494           }
495         else if (s[0] == '-')
496           {
497              s++;
498              while (*s == ' ') s++;
499              if (!s)
500                {
501                   free(text2);
502                   return;
503                }
504              markup_text = (char*) malloc(strlen(s) + 4);
505              if (markup_text)
506                {
507                   *(markup_text) = '<';
508                   *(markup_text + 1) = '/';
509                   strncpy((markup_text + 2), s, strlen(s));
510                   *(markup_text + strlen(s) + 2) = '>';
511                   *(markup_text + strlen(s) + 3) = '\0';
512                }
513           }
514         else
515           {
516              markup_text = (char*) malloc(strlen(s) + 4);
517              if (markup_text)
518                {
519                   *(markup_text) = '<';
520                   strncpy((markup_text + 1), s, strlen(s));
521                   *(markup_text + strlen(s) + 1) = '/';
522                   *(markup_text + strlen(s) + 2) = '>';
523                   *(markup_text + strlen(s) + 3) = '\0';
524                }
525           }
526         free(text2);
527         if (markup_text)
528           _text_filter_markup_prepend_internal(en, c, markup_text);
529      }
530 }
531
532 static void
533 _text_filter_markup_prepend(Entry *en, Evas_Textblock_Cursor *c, const char *text)
534 {
535    char *text2;
536    Edje_Text_Insert_Filter_Callback *cb;
537    Eina_List *l;
538
539    text2 = strdup(text);
540    EINA_LIST_FOREACH(en->rp->edje->text_insert_filter_callbacks, l, cb)
541      {
542         if (!strcmp(cb->part, en->rp->part->name))
543           {
544              cb->func(cb->data, en->rp->edje->obj, cb->part, EDJE_TEXT_FILTER_MARKUP, &text2);
545              if (!text2) break;
546           }
547      }
548    if (text2)
549      _text_filter_markup_prepend_internal(en, c, text2);
550 }
551
552 static void
553 _curs_update_from_curs(Evas_Textblock_Cursor *c, Evas_Object *o __UNUSED__, Entry *en, Evas_Coord *cx, Evas_Coord *cy)
554 {
555    Evas_Coord cw, ch;
556    Evas_Textblock_Cursor_Type cur_type;
557    if (c != en->cursor) return;
558    switch (en->rp->part->cursor_mode)
559      {
560       case EDJE_ENTRY_CURSOR_MODE_BEFORE:
561          cur_type = EVAS_TEXTBLOCK_CURSOR_BEFORE;
562          break;
563       case EDJE_ENTRY_CURSOR_MODE_UNDER:
564          /* no break for a resaon */
565       default:
566          cur_type = EVAS_TEXTBLOCK_CURSOR_UNDER;
567      }
568    evas_textblock_cursor_geometry_get(c, cx, cy, &cw, &ch, NULL, cur_type);
569    *cx += (cw / 2);
570    *cy += (ch / 2);
571 }
572
573 static int
574 _curs_line_last_get(Evas_Textblock_Cursor *c __UNUSED__, Evas_Object *o, Entry *en __UNUSED__)
575 {
576    Evas_Textblock_Cursor *cc;
577    int ln;
578
579    cc = evas_object_textblock_cursor_new(o);
580    evas_textblock_cursor_paragraph_last(cc);
581    ln = evas_textblock_cursor_line_geometry_get(cc, NULL, NULL, NULL, NULL);
582    evas_textblock_cursor_free(cc);
583    return ln;
584 }
585
586 static void
587 _curs_lin_start(Evas_Textblock_Cursor *c, Evas_Object *o __UNUSED__,
588                 Entry *en __UNUSED__)
589 {
590    evas_textblock_cursor_line_char_first(c);
591 }
592
593 static void
594 _curs_lin_end(Evas_Textblock_Cursor *c, Evas_Object *o __UNUSED__,
595               Entry *en __UNUSED__)
596 {
597    evas_textblock_cursor_line_char_last(c);
598 }
599
600 static void
601 _curs_start(Evas_Textblock_Cursor *c, Evas_Object *o __UNUSED__,
602             Entry *en __UNUSED__)
603 {
604    evas_textblock_cursor_paragraph_first(c);
605 }
606
607 static void
608 _curs_end(Evas_Textblock_Cursor *c, Evas_Object *o __UNUSED__, Entry *en __UNUSED__)
609 {
610    evas_textblock_cursor_paragraph_last(c);
611 }
612
613 static Eina_Bool
614 _curs_jump_line(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en, int ln)
615 {
616    Evas_Coord cx, cy;
617    Evas_Coord lx, ly, lw, lh;
618    int last = _curs_line_last_get(c, o, en);
619
620    if (ln < 0) return EINA_FALSE;
621    if (ln > last) return EINA_FALSE;
622
623    _curs_update_from_curs(c, o, en, &cx, &cy);
624
625    if (!evas_object_textblock_line_number_geometry_get(o, ln, &lx, &ly, &lw, &lh))
626      return EINA_FALSE;
627    if (evas_textblock_cursor_char_coord_set(c, cx, ly + (lh / 2)))
628      return EINA_TRUE;
629    evas_textblock_cursor_line_set(c, ln);
630    if (cx < (lx + (lw / 2)))
631      {
632         if (ln == last) _curs_end(c, o, en);
633         _curs_lin_start(c, o, en);
634      }
635    else
636      {
637         if (ln == last)
638           _curs_end(c, o, en);
639         else
640           _curs_lin_end(c, o, en);
641      }
642    return EINA_TRUE;
643 }
644
645 static Eina_Bool
646 _curs_jump_line_by(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en, int by)
647 {
648    int ln;
649
650    ln = evas_textblock_cursor_line_geometry_get(c, NULL, NULL, NULL, NULL) + by;
651    return _curs_jump_line(c, o, en, ln);
652 }
653
654 static Eina_Bool
655 _curs_up(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en)
656 {
657    return _curs_jump_line_by(c, o, en, -1);
658 }
659
660 static Eina_Bool
661 _curs_down(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en)
662 {
663    return _curs_jump_line_by(c, o, en, 1);
664 }
665
666 static void
667 _sel_start(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en)
668 {
669    if (en->sel_start) return;
670    en->sel_start = evas_object_textblock_cursor_new(o);
671    evas_textblock_cursor_copy(c, en->sel_start);
672    en->sel_end = evas_object_textblock_cursor_new(o);
673    evas_textblock_cursor_copy(c, en->sel_end);
674
675    en->have_selection = EINA_FALSE;
676    if (en->selection)
677      {
678         free(en->selection);
679         en->selection = NULL;
680      }
681 }
682
683 static void
684 _sel_enable(Evas_Textblock_Cursor *c __UNUSED__, Evas_Object *o __UNUSED__, Entry *en)
685 {
686    if (en->have_selection) return;
687    en->have_selection = EINA_TRUE;
688    if (en->selection)
689      {
690         free(en->selection);
691         en->selection = NULL;
692      }
693
694    _edje_entry_imf_context_reset(en->rp);
695    _edje_emit(en->rp->edje, "selection,start", en->rp->part->name);
696 }
697
698 static void
699 _sel_extend(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en)
700 {
701    if (!en->sel_end) return;
702    _sel_enable(c, o, en);
703    if (!evas_textblock_cursor_compare(c, en->sel_end)) return;
704
705    evas_textblock_cursor_copy(c, en->sel_end);
706
707    _edje_entry_imf_cursor_info_set(en);
708
709    if (en->selection)
710      {
711         free(en->selection);
712         en->selection = NULL;
713      }
714    _edje_emit(en->rp->edje, "selection,changed", en->rp->part->name);
715    // TIZEN ONLY - start
716    if (en->cursor_handler_show)
717      {
718         evas_object_hide(en->cursor_handler);
719         en->cursor_handler_show = EINA_FALSE;
720      }
721    // TIZEN ONLY - end
722 }
723
724 static void
725 _sel_preextend(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en)
726 {
727    if (!en->sel_end) return;
728    _sel_enable(c, o, en);
729    if (!evas_textblock_cursor_compare(c, en->sel_start)) return;
730
731    evas_textblock_cursor_copy(c, en->sel_start);
732
733    _edje_entry_imf_cursor_info_set(en);
734
735    if (en->selection)
736      {
737         free(en->selection);
738         en->selection = NULL;
739      }
740    _edje_emit(en->rp->edje, "selection,changed", en->rp->part->name);
741    // TIZEN ONLY - start
742    if (en->cursor_handler_show)
743      {
744         evas_object_hide(en->cursor_handler);
745         en->cursor_handler_show = EINA_FALSE;
746      }
747    // TIZEN ONLY - end
748 }
749
750 static void
751 _sel_clear(Evas_Textblock_Cursor *c __UNUSED__, Evas_Object *o __UNUSED__, Entry *en)
752 {
753    en->had_sel = EINA_FALSE;
754    if (en->sel_start)
755      {
756         evas_textblock_cursor_free(en->sel_start);
757         evas_textblock_cursor_free(en->sel_end);
758         en->sel_start = NULL;
759         en->sel_end = NULL;
760      }
761    if (en->selection)
762      {
763         free(en->selection);
764         en->selection = NULL;
765      }
766    while (en->sel)
767      {
768         Sel *sel;
769
770         sel = en->sel->data;
771         if (sel->obj_bg) evas_object_del(sel->obj_bg);
772         if (sel->obj_fg) evas_object_del(sel->obj_fg);
773
774         // TIZEN ONLY - START
775         if (en->rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_BLOCK_HANDLE)
776           {
777              evas_object_hide(en->sel_handler_start);
778              evas_object_hide(en->sel_handler_end);
779
780              evas_object_hide(en->sel_handler_edge_start);
781              evas_object_hide(en->sel_handler_edge_end);
782           }
783         // TIZEN ONLY - END
784         free(sel);
785         en->sel = eina_list_remove_list(en->sel, en->sel);
786      }
787    if (en->have_selection)
788      {
789         en->have_selection = EINA_FALSE;
790         evas_object_show(en->cursor_fg);
791         _edje_emit(en->rp->edje, "selection,cleared", en->rp->part->name);
792      }
793 }
794
795 static void
796 _sel_update(Evas_Textblock_Cursor *c __UNUSED__, Evas_Object *o, Entry *en)
797 {
798    Eina_List *range = NULL, *l;
799    Sel *sel;
800    Evas_Coord x, y, w, h;
801    Evas_Object *smart, *clip;
802
803    smart = evas_object_smart_parent_get(o);
804    clip = evas_object_clip_get(o);
805    if (en->sel_start)
806      {
807         range = evas_textblock_cursor_range_geometry_get(en->sel_start, en->sel_end);
808         if (!range) return;
809      }
810    else
811      return;
812    if (eina_list_count(range) != eina_list_count(en->sel))
813      {
814         while (en->sel)
815           {
816              sel = en->sel->data;
817              if (sel->obj_bg) evas_object_del(sel->obj_bg);
818              if (sel->obj_fg) evas_object_del(sel->obj_fg);
819              free(sel);
820              en->sel = eina_list_remove_list(en->sel, en->sel);
821           }
822         if (en->have_selection)
823           {
824              for (l = range; l; l = eina_list_next(l))
825                {
826                   Evas_Object *ob;
827
828                   sel = calloc(1, sizeof(Sel));
829                   en->sel = eina_list_append(en->sel, sel);
830                   ob = edje_object_add(en->rp->edje->base.evas);
831                   edje_object_file_set(ob, en->rp->edje->path, en->rp->part->source);
832                   evas_object_smart_member_add(ob, smart);
833                   evas_object_stack_below(ob, o);
834                   evas_object_clip_set(ob, clip);
835                   evas_object_pass_events_set(ob, EINA_TRUE);
836                   evas_object_show(ob);
837                   sel->obj_bg = ob;
838                   _edje_subobj_register(en->rp->edje, sel->obj_bg);
839
840                   ob = edje_object_add(en->rp->edje->base.evas);
841                   edje_object_file_set(ob, en->rp->edje->path, en->rp->part->source2);
842                   evas_object_smart_member_add(ob, smart);
843                   evas_object_stack_above(ob, o);
844                   evas_object_clip_set(ob, clip);
845                   evas_object_pass_events_set(ob, EINA_TRUE);
846                   evas_object_show(ob);
847                   sel->obj_fg = ob;
848                   _edje_subobj_register(en->rp->edje, sel->obj_fg);
849                }
850           }
851      }
852    x = y = w = h = -1;
853    evas_object_geometry_get(o, &x, &y, &w, &h);
854    if (en->have_selection)
855      {
856         // TIZEN ONLY - START
857         int list_cnt, list_idx;
858
859         list_cnt = eina_list_count(en->sel);
860         list_idx = 0;
861         evas_object_hide(en->cursor_fg);
862         evas_object_hide(en->cursor_bg);
863         // TIZEN ONLY - END
864
865         EINA_LIST_FOREACH(en->sel, l, sel)
866           {
867              Evas_Textblock_Rectangle *r;
868              list_idx++; // TIZEN ONLY
869
870              r = range->data;
871              if (sel->obj_bg)
872                {
873                   evas_object_move(sel->obj_bg, x + r->x, y + r->y);
874                   evas_object_resize(sel->obj_bg, r->w, r->h);
875                }
876              if (sel->obj_fg)
877                {
878                   evas_object_move(sel->obj_fg, x + r->x, y + r->y);
879                   evas_object_resize(sel->obj_fg, r->w, r->h);
880                }
881              // TIZEN ONLY - START
882              if (en->rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_BLOCK_HANDLE)
883                {
884                   int fh_idx, eh_idx;
885                   const char *gc = edje_object_data_get(en->sel_handler_start, "gap");
886                   int bh_gap = 0;
887                   if (gc) bh_gap = atoi(gc);
888
889                   if (en->handler_bypassing)
890                     {
891                        fh_idx = list_cnt;
892                        eh_idx = 1;
893                     }
894                   else
895                     {
896                        fh_idx = 1;
897                        eh_idx = list_cnt;
898                     }
899
900                   if (list_idx == fh_idx)
901                     {
902                        Evas_Coord nx, ny, handler_height = 0;
903                        Evas_Coord edge_w;
904                        Evas_Coord moving = 0;
905                        edje_object_part_geometry_get(en->sel_handler_start, "handle", NULL, NULL, NULL, &handler_height);
906
907                        //keep same touch pos when by passing
908                        if (en->handler_bypassing)
909                          {
910                             nx = x + r->x + r->w;
911                             ny = y + r->y + r->h;
912                          }
913                        else
914                          {
915                             nx = x + r->x;
916                             ny = y + r->y + r->h;
917                          }
918                        evas_object_hide(en->sel_handler_start);
919
920                        edje_object_size_min_calc(en->sel_handler_edge_start, &edge_w, NULL);
921                        evas_object_move(en->sel_handler_edge_start, nx, ny - r->h);
922                        evas_object_resize(en->sel_handler_edge_start, edge_w, r->h);
923
924                        if (!en->vp_updated && en->sh_start_normal_pos)
925                          {
926                             /* to avoid blinking when moving */
927                             moving = r->h;
928                          }
929
930                        evas_object_hide(en->sel_handler_edge_start);
931
932                        // if viewport region is not set, show handlers
933                        if (en->viewport_region.x == -1 && en->viewport_region.y == -1 &&
934                            en->viewport_region.w == -1 && en->viewport_region.h == -1)
935                          {
936                             evas_object_hide(en->sel_handler_start);
937                             evas_object_move(en->sel_handler_start, nx, ny);
938                             edje_object_signal_emit(en->sel_handler_start, "elm,state,bottom", "elm");
939                             evas_object_show(en->sel_handler_start);
940
941                             evas_object_show(en->sel_handler_edge_start);
942                          }
943                        else
944                          {
945                             if ((en->viewport_region.w > 0 && en->viewport_region.h > 0) &&
946                                 (nx >= en->viewport_region.x) && (nx <= (en->viewport_region.x + en->viewport_region.w)) &&
947                                 (ny >= en->viewport_region.y) && (ny - r->h <= (en->viewport_region.y + en->viewport_region.h)))
948                               {
949                                  if ((en->layout_region.w != -1) && (en->layout_region.h != -1) &&
950                                      (((ny + handler_height) > (en->layout_region.y + en->layout_region.h))
951                                       || (ny > en->viewport_region.y + en->viewport_region.h + moving)))
952                                    {
953                                       evas_object_move(en->sel_handler_start, nx, ny - r->h);
954                                       if (nx <= en->layout_region.x + bh_gap)
955                                          edje_object_signal_emit(en->sel_handler_start, "elm,state,top,reversed", "elm");
956                                       else
957                                          edje_object_signal_emit(en->sel_handler_start, "elm,state,top", "elm");
958                                       en->sh_start_normal_pos = EINA_FALSE;
959                                    }
960                                  else
961                                    {
962                                       evas_object_move(en->sel_handler_start, nx, ny);
963                                       if (nx <= en->layout_region.x + bh_gap)
964                                          edje_object_signal_emit(en->sel_handler_start, "elm,state,bottom,reversed", "elm");
965                                       else
966                                          edje_object_signal_emit(en->sel_handler_start, "elm,state,bottom", "elm");
967                                       en->sh_start_normal_pos = EINA_TRUE;
968                                    }
969
970                                  evas_object_show(en->sel_handler_start);
971                                  evas_object_show(en->sel_handler_edge_start);
972                               }
973                          }
974                     }
975                   if (list_idx == eh_idx)
976                     {
977                        Evas_Coord nx, ny, handler_height = 0;
978                        Evas_Coord edge_w;
979                        Evas_Coord moving = 0;
980
981                        edje_object_part_geometry_get(en->sel_handler_end, "handle", NULL, NULL, NULL, &handler_height);
982
983                        //keep pos when bypassing
984                        if (en->handler_bypassing)
985                          {
986                             nx = x + r->x;
987                             ny = y + r->y + r->h;
988                          }
989                        else
990                          {
991                             nx = x + r->x + r->w;
992                             ny = y + r->y + r->h;
993                          }
994
995                        evas_object_hide(en->sel_handler_end);
996
997                        edje_object_size_min_calc(en->sel_handler_edge_end, &edge_w, NULL);
998                        evas_object_move(en->sel_handler_edge_end, nx, ny - r->h);
999                        evas_object_resize(en->sel_handler_edge_end, edge_w, r->h);
1000
1001                        if (!en->vp_updated && en->sh_end_normal_pos)
1002                          {
1003                             /* to avoid blinking when moving */
1004                             moving = r->h;
1005                          }
1006
1007                        evas_object_hide(en->sel_handler_edge_end);
1008
1009                        // if viewport region is not set, show handlers
1010                        if (en->viewport_region.x == -1 && en->viewport_region.y == -1 &&
1011                            en->viewport_region.w == -1 && en->viewport_region.h == -1)
1012                          {
1013                             evas_object_move(en->sel_handler_end, nx, ny);
1014                             evas_object_move(en->sel_handler_end, nx, ny);
1015                             edje_object_signal_emit(en->sel_handler_end, "elm,state,bottom", "elm");
1016                             evas_object_show(en->sel_handler_end);
1017
1018                             evas_object_show(en->sel_handler_edge_end);
1019                          }
1020                        else
1021                          {
1022                             if ((en->viewport_region.w > 0 && en->viewport_region.h > 0) &&
1023                                 (nx >= en->viewport_region.x) && (nx <= (en->viewport_region.x + en->viewport_region.w)) &&
1024                                 (ny >= en->viewport_region.y) && (ny - r->h <= (en->viewport_region.y + en->viewport_region.h)))
1025                               {
1026                                  evas_object_move(en->sel_handler_end, nx, ny - r->h);
1027                                  if (en->layout_region.w != -1 && en->layout_region.h != -1 &&
1028                                      (((ny + handler_height) > (en->layout_region.y + en->layout_region.h))
1029                                      || (ny > en->viewport_region.y + en->viewport_region.h + moving)))
1030                                    {
1031                                       if (nx >= en->layout_region.w - bh_gap)
1032                                          edje_object_signal_emit(en->sel_handler_end, "elm,state,top,reversed", "elm");
1033                                       else
1034                                          edje_object_signal_emit(en->sel_handler_end, "elm,state,top", "elm");
1035                                       en->sh_end_normal_pos = EINA_FALSE;
1036                                    }
1037                                  else
1038                                    {
1039                                       evas_object_move(en->sel_handler_end, nx, ny);
1040
1041                                       if (nx >= en->layout_region.w - bh_gap)
1042                                          edje_object_signal_emit(en->sel_handler_end, "elm,state,bottom,reversed", "elm");
1043                                       else
1044                                          edje_object_signal_emit(en->sel_handler_end, "elm,state,bottom", "elm");
1045                                       en->sh_end_normal_pos = EINA_TRUE;
1046                                    }
1047
1048                                  evas_object_show(en->sel_handler_end);
1049
1050                                  evas_object_show(en->sel_handler_edge_end);
1051                               }
1052                          }
1053                     }
1054                }
1055              // TIZEN ONLY - END
1056
1057              *(&(sel->rect)) = *r;
1058              range = eina_list_remove_list(range, range);
1059              free(r);
1060           }
1061      }
1062    else
1063      {
1064         while (range)
1065           {
1066              free(range->data);
1067              range = eina_list_remove_list(range, range);
1068           }
1069      }
1070    en->vp_updated = EINA_FALSE;
1071 }
1072
1073 static void
1074 _edje_anchor_mouse_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1075 {
1076    Anchor *an = data;
1077    Evas_Event_Mouse_Down *ev = event_info;
1078    Edje_Real_Part *rp = an->en->rp;
1079    char *buf, *n;
1080    size_t len;
1081    int ignored;
1082    Entry *en;
1083
1084    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
1085        (!rp->typedata.text)) return;
1086    en = rp->typedata.text->entry_data;
1087    if (((rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_EXPLICIT) ||
1088         (rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_BLOCK_HANDLE)) &&
1089        (en->select_allow))
1090      return;
1091    ignored = rp->part->ignore_flags & ev->event_flags;
1092    if ((!ev->event_flags) || (!ignored))
1093      {
1094         n = an->name;
1095         if (!n) n = "";
1096         len = 200 + strlen(n);
1097         buf = alloca(len);
1098         if (ev->flags & EVAS_BUTTON_TRIPLE_CLICK)
1099           snprintf(buf, len, "anchor,mouse,down,%i,%s,triple", ev->button, n);
1100         else if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
1101           snprintf(buf, len, "anchor,mouse,down,%i,%s,double", ev->button, n);
1102         else
1103           snprintf(buf, len, "anchor,mouse,down,%i,%s", ev->button, n);
1104         _edje_emit(rp->edje, buf, rp->part->name);
1105      }
1106 }
1107
1108 static void
1109 _edje_anchor_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1110 {
1111    Anchor *an = data;
1112    Evas_Event_Mouse_Up *ev = event_info;
1113    Edje_Real_Part *rp = an->en->rp;
1114    char *buf, *n;
1115    size_t len;
1116    int ignored;
1117    Entry *en;
1118
1119    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
1120        (!rp->typedata.text)) return;
1121    en = rp->typedata.text->entry_data;
1122    ignored = rp->part->ignore_flags & ev->event_flags;
1123    if (((rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_EXPLICIT) ||
1124         (rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_BLOCK_HANDLE)) &&
1125        (en->select_allow))
1126      return;
1127    n = an->name;
1128    if (!n) n = "";
1129    len = 200 + strlen(n);
1130    buf = alloca(len);
1131    if ((!ev->event_flags) || (!ignored))
1132      {
1133         snprintf(buf, len, "anchor,mouse,up,%i,%s", ev->button, n);
1134         _edje_emit(rp->edje, buf, rp->part->name);
1135      }
1136    if ((rp->still_in) && (rp->clicked_button == ev->button) && (!ignored))
1137      {
1138         snprintf(buf, len, "anchor,mouse,clicked,%i,%s", ev->button, n);
1139         _edje_emit(rp->edje, buf, rp->part->name);
1140      }
1141 }
1142
1143 static void
1144 _edje_anchor_mouse_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1145 {
1146    Anchor *an = data;
1147    Evas_Event_Mouse_Move *ev = event_info;
1148    Edje_Real_Part *rp = an->en->rp;
1149    char *buf, *n;
1150    size_t len;
1151    int ignored;
1152    Entry *en;
1153
1154    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
1155        (!rp->typedata.text)) return;
1156    en = rp->typedata.text->entry_data;
1157    if (((rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_EXPLICIT) ||
1158         (rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_BLOCK_HANDLE)) &&
1159        (en->select_allow))
1160      return;
1161    ignored = rp->part->ignore_flags & ev->event_flags;
1162    if ((!ev->event_flags) || (!ignored))
1163      {
1164         n = an->name;
1165         if (!n) n = "";
1166         len = 200 + strlen(n);
1167         buf = alloca(len);
1168         snprintf(buf, len, "anchor,mouse,move,%s", n);
1169         _edje_emit(rp->edje, buf, rp->part->name);
1170      }
1171 }
1172
1173 static void
1174 _edje_anchor_mouse_in_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1175 {
1176    Anchor *an = data;
1177    Evas_Event_Mouse_In *ev = event_info;
1178    Edje_Real_Part *rp = an->en->rp;
1179    char *buf, *n;
1180    size_t len;
1181    int ignored;
1182
1183    ignored = rp->part->ignore_flags & ev->event_flags;
1184    if ((!ev->event_flags) || (!ignored))
1185      {
1186         n = an->name;
1187         if (!n) n = "";
1188         len = 200 + strlen(n);
1189         buf = alloca(len);
1190         snprintf(buf, len, "anchor,mouse,in,%s", n);
1191         _edje_emit(rp->edje, buf, rp->part->name);
1192      }
1193 }
1194
1195 static void
1196 _edje_anchor_mouse_out_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1197 {
1198    Anchor *an = data;
1199    Evas_Event_Mouse_Out *ev = event_info;
1200    Edje_Real_Part *rp = an->en->rp;
1201    char *buf, *n;
1202    size_t len;
1203    int ignored;
1204
1205    ignored = rp->part->ignore_flags & ev->event_flags;
1206    if ((!ev->event_flags) || (!ignored))
1207      {
1208         n = an->name;
1209         if (!n) n = "";
1210         len = 200 + strlen(n);
1211         buf = alloca(len);
1212         snprintf(buf, len, "anchor,mouse,out,%s", n);
1213         _edje_emit(rp->edje, buf, rp->part->name);
1214      }
1215 }
1216
1217 static void
1218 _anchors_update(Evas_Textblock_Cursor *c __UNUSED__, Evas_Object *o, Entry *en)
1219 {
1220    Eina_List *l, *ll, *range = NULL;
1221    Evas_Coord x, y, w, h;
1222    Evas_Object *smart, *clip;
1223    Sel *sel;
1224    Anchor *an;
1225
1226    smart = evas_object_smart_parent_get(o);
1227    clip = evas_object_clip_get(o);
1228    x = y = w = h = -1;
1229    evas_object_geometry_get(o, &x, &y, &w, &h);
1230    EINA_LIST_FOREACH(en->anchors, l, an)
1231      {
1232         // for item anchors
1233         if (an->item)
1234           {
1235              Evas_Object *ob;
1236
1237              if (!an->sel)
1238                {
1239                   while (an->sel)
1240                     {
1241                        sel = an->sel->data;
1242                        if (sel->obj_bg) evas_object_del(sel->obj_bg);
1243                        if (sel->obj_fg) evas_object_del(sel->obj_fg);
1244                        if (sel->obj) evas_object_del(sel->obj);
1245                        free(sel);
1246                        an->sel = eina_list_remove_list(an->sel, an->sel);
1247                     }
1248
1249                   sel = calloc(1, sizeof(Sel));
1250                   an->sel = eina_list_append(an->sel, sel);
1251
1252                   if (en->rp->edje->item_provider.func)
1253                     {
1254                        ob = en->rp->edje->item_provider.func
1255                          (en->rp->edje->item_provider.data, smart,
1256                              en->rp->part->name, an->name);
1257                        evas_object_smart_member_add(ob, smart);
1258                        evas_object_stack_above(ob, o);
1259                        evas_object_clip_set(ob, clip);
1260                        evas_object_pass_events_set(ob, EINA_TRUE);
1261                        evas_object_show(ob);
1262                        sel->obj = ob;
1263                     }
1264                }
1265           }
1266         // for link anchors
1267         else
1268           {
1269              range =
1270                evas_textblock_cursor_range_geometry_get(an->start, an->end);
1271              if (eina_list_count(range) != eina_list_count(an->sel))
1272                {
1273                   while (an->sel)
1274                     {
1275                        sel = an->sel->data;
1276                        if (sel->obj_bg) evas_object_del(sel->obj_bg);
1277                        if (sel->obj_fg) evas_object_del(sel->obj_fg);
1278                        if (sel->obj) evas_object_del(sel->obj);
1279                        free(sel);
1280                        an->sel = eina_list_remove_list(an->sel, an->sel);
1281                     }
1282                   for (ll = range; ll; ll = eina_list_next(ll))
1283                     {
1284                        Evas_Object *ob;
1285
1286                        sel = calloc(1, sizeof(Sel));
1287                        an->sel = eina_list_append(an->sel, sel);
1288                        ob = edje_object_add(en->rp->edje->base.evas);
1289                        edje_object_file_set(ob, en->rp->edje->path, en->rp->part->source5);
1290                        evas_object_smart_member_add(ob, smart);
1291                        evas_object_stack_below(ob, o);
1292                        evas_object_clip_set(ob, clip);
1293                        evas_object_pass_events_set(ob, EINA_TRUE);
1294                        evas_object_show(ob);
1295                        sel->obj_bg = ob;
1296                        _edje_subobj_register(en->rp->edje, sel->obj_bg);
1297
1298                        ob = edje_object_add(en->rp->edje->base.evas);
1299                        edje_object_file_set(ob, en->rp->edje->path, en->rp->part->source6);
1300                        evas_object_smart_member_add(ob, smart);
1301                        evas_object_stack_above(ob, o);
1302                        evas_object_clip_set(ob, clip);
1303                        evas_object_pass_events_set(ob, EINA_TRUE);
1304                        evas_object_show(ob);
1305                        sel->obj_fg = ob;
1306                        _edje_subobj_register(en->rp->edje, sel->obj_fg);
1307
1308                        ob = evas_object_rectangle_add(en->rp->edje->base.evas);
1309                        evas_object_color_set(ob, 0, 0, 0, 0);
1310                        evas_object_smart_member_add(ob, smart);
1311                        evas_object_stack_above(ob, o);
1312                        evas_object_clip_set(ob, clip);
1313                        evas_object_repeat_events_set(ob, EINA_TRUE);
1314                        evas_object_event_callback_add(ob, EVAS_CALLBACK_MOUSE_DOWN, _edje_anchor_mouse_down_cb, an);
1315                        evas_object_event_callback_add(ob, EVAS_CALLBACK_MOUSE_UP, _edje_anchor_mouse_up_cb, an);
1316                        evas_object_event_callback_add(ob, EVAS_CALLBACK_MOUSE_MOVE, _edje_anchor_mouse_move_cb, an);
1317                        evas_object_event_callback_add(ob, EVAS_CALLBACK_MOUSE_IN, _edje_anchor_mouse_in_cb, an);
1318                        evas_object_event_callback_add(ob, EVAS_CALLBACK_MOUSE_OUT, _edje_anchor_mouse_out_cb, an);
1319                        evas_object_show(ob);
1320                        sel->obj = ob;
1321                     }
1322                }
1323           }
1324         EINA_LIST_FOREACH(an->sel, ll, sel)
1325           {
1326              if (an->item)
1327                {
1328                   Evas_Coord cx, cy, cw, ch;
1329
1330                   if (!evas_textblock_cursor_format_item_geometry_get
1331                       (an->start, &cx, &cy, &cw, &ch))
1332                     continue;
1333                   evas_object_move(sel->obj, x + cx, y + cy);
1334                   evas_object_resize(sel->obj, cw, ch);
1335                }
1336              else
1337                {
1338                   Evas_Textblock_Rectangle *r;
1339
1340                   r = range->data;
1341                   *(&(sel->rect)) = *r;
1342                   if (sel->obj_bg)
1343                     {
1344                        evas_object_move(sel->obj_bg, x + r->x, y + r->y);
1345                        evas_object_resize(sel->obj_bg, r->w, r->h);
1346                     }
1347                   if (sel->obj_fg)
1348                     {
1349                        evas_object_move(sel->obj_fg, x + r->x, y + r->y);
1350                        evas_object_resize(sel->obj_fg, r->w, r->h);
1351                     }
1352                   if (sel->obj)
1353                     {
1354                        evas_object_move(sel->obj, x + r->x, y + r->y);
1355                        evas_object_resize(sel->obj, r->w, r->h);
1356                     }
1357                   range = eina_list_remove_list(range, range);
1358                   free(r);
1359                }
1360           }
1361      }
1362 }
1363
1364 static void
1365 _anchors_clear(Evas_Textblock_Cursor *c __UNUSED__, Evas_Object *o __UNUSED__, Entry *en)
1366 {
1367    while (en->anchorlist)
1368      {
1369         free(en->anchorlist->data);
1370         en->anchorlist = eina_list_remove_list(en->anchorlist, en->anchorlist);
1371      }
1372    while (en->itemlist)
1373      {
1374         free(en->itemlist->data);
1375         en->itemlist = eina_list_remove_list(en->itemlist, en->itemlist);
1376      }
1377    while (en->anchors)
1378      {
1379         Anchor *an = en->anchors->data;
1380
1381         evas_textblock_cursor_free(an->start);
1382         evas_textblock_cursor_free(an->end);
1383         while (an->sel)
1384           {
1385              Sel *sel = an->sel->data;
1386              if (sel->obj_bg) evas_object_del(sel->obj_bg);
1387              if (sel->obj_fg) evas_object_del(sel->obj_fg);
1388              if (sel->obj) evas_object_del(sel->obj);
1389              free(sel);
1390              an->sel = eina_list_remove_list(an->sel, an->sel);
1391           }
1392         free(an->name);
1393         free(an);
1394         en->anchors = eina_list_remove_list(en->anchors, en->anchors);
1395      }
1396 }
1397
1398 static void
1399 _anchors_get(Evas_Textblock_Cursor *c, Evas_Object *o, Entry *en)
1400 {
1401    const Eina_List *anchors_a, *anchors_item;
1402    Anchor *an = NULL;
1403    _anchors_clear(c, o, en);
1404
1405    anchors_a = evas_textblock_node_format_list_get(o, "a");
1406    anchors_item = evas_textblock_node_format_list_get(o, "item");
1407
1408    if (anchors_a)
1409      {
1410         const Evas_Object_Textblock_Node_Format *node;
1411         const Eina_List *itr;
1412         EINA_LIST_FOREACH(anchors_a, itr, node)
1413           {
1414              const char *s = evas_textblock_node_format_text_get(node);
1415              char *p;
1416              an = calloc(1, sizeof(Anchor));
1417              if (!an)
1418                break;
1419
1420              an->en = en;
1421              p = strstr(s, "href=");
1422              if (p)
1423                {
1424                   an->name = strdup(p + 5);
1425                }
1426              en->anchors = eina_list_append(en->anchors, an);
1427              an->start = evas_object_textblock_cursor_new(o);
1428              an->end = evas_object_textblock_cursor_new(o);
1429              evas_textblock_cursor_at_format_set(an->start, node);
1430              evas_textblock_cursor_copy(an->start, an->end);
1431
1432              /* Close the anchor, if the anchor was without text,
1433               * free it as well */
1434              node = evas_textblock_node_format_next_get(node);
1435              for (; node; node = evas_textblock_node_format_next_get(node))
1436                {
1437                   s = evas_textblock_node_format_text_get(node);
1438                   if ((!strcmp(s, "- a")) || (!strcmp(s, "-a")))
1439                     break;
1440                }
1441
1442              if (node)
1443                {
1444                   evas_textblock_cursor_at_format_set(an->end, node);
1445                }
1446              else if (!evas_textblock_cursor_compare(an->start, an->end))
1447                {
1448                   if (an->name) free(an->name);
1449                   evas_textblock_cursor_free(an->start);
1450                   evas_textblock_cursor_free(an->end);
1451                   en->anchors = eina_list_remove(en->anchors, an);
1452                   free(an);
1453                }
1454              an = NULL;
1455           }
1456      }
1457
1458    if (anchors_item)
1459      {
1460         const Evas_Object_Textblock_Node_Format *node;
1461         const Eina_List *itr;
1462         EINA_LIST_FOREACH(anchors_item, itr, node)
1463           {
1464              const char *s = evas_textblock_node_format_text_get(node);
1465              char *p;
1466              an = calloc(1, sizeof(Anchor));
1467              if (!an)
1468                break;
1469
1470              an->en = en;
1471              an->item = 1;
1472              p = strstr(s, "href=");
1473              if (p)
1474                {
1475                   an->name = strdup(p + 5);
1476                }
1477              en->anchors = eina_list_append(en->anchors, an);
1478              an->start = evas_object_textblock_cursor_new(o);
1479              an->end = evas_object_textblock_cursor_new(o);
1480              evas_textblock_cursor_at_format_set(an->start, node);
1481              evas_textblock_cursor_copy(an->start, an->end);
1482              /* Although needed in textblock, don't bother with finding the end
1483               * here cause it doesn't really matter. */
1484           }
1485      }
1486 }
1487
1488 static void
1489 _free_entry_change_info(void *_info)
1490 {
1491    Edje_Entry_Change_Info *info = (Edje_Entry_Change_Info *) _info;
1492    if (info->insert)
1493      {
1494         eina_stringshare_del(info->change.insert.content);
1495      }
1496    else
1497      {
1498         eina_stringshare_del(info->change.del.content);
1499      }
1500    free(info);
1501 }
1502
1503 static void
1504 _range_del_emit(Edje *ed, Evas_Textblock_Cursor *c __UNUSED__, Evas_Object *o __UNUSED__, Entry *en)
1505 {
1506    size_t start, end;
1507    char *tmp;
1508    Edje_Entry_Change_Info *info;
1509
1510    start = evas_textblock_cursor_pos_get(en->sel_start);
1511    end = evas_textblock_cursor_pos_get(en->sel_end);
1512    if (start == end)
1513       goto noop;
1514
1515    info = calloc(1, sizeof(*info));
1516    info->insert = EINA_FALSE;
1517    info->change.del.start = start;
1518    info->change.del.end = end;
1519
1520    tmp = evas_textblock_cursor_range_text_get(en->sel_start, en->sel_end, EVAS_TEXTBLOCK_TEXT_MARKUP);
1521    info->change.del.content = eina_stringshare_add(tmp);
1522    if (tmp) free(tmp);
1523    evas_textblock_cursor_range_delete(en->sel_start, en->sel_end);
1524    _edje_emit(ed, "entry,changed", en->rp->part->name);
1525    _edje_emit_full(ed, "entry,changed,user", en->rp->part->name, info,
1526                    _free_entry_change_info);
1527 noop:
1528    _sel_clear(en->cursor, en->rp->object, en);
1529 }
1530
1531 static void
1532 _range_del(Evas_Textblock_Cursor *c __UNUSED__, Evas_Object *o __UNUSED__, Entry *en)
1533 {
1534    evas_textblock_cursor_range_delete(en->sel_start, en->sel_end);
1535    _sel_clear(en->cursor, en->rp->object, en);
1536 }
1537
1538 static void
1539 _delete_emit(Edje *ed, Evas_Textblock_Cursor *c, Entry *en, size_t pos,
1540              Eina_Bool backspace)
1541 {
1542    if (!evas_textblock_cursor_char_next(c))
1543      {
1544         return;
1545      }
1546    evas_textblock_cursor_char_prev(c);
1547
1548    Edje_Entry_Change_Info *info = calloc(1, sizeof(*info));
1549    char *tmp = evas_textblock_cursor_content_get(c);
1550
1551    info->insert = EINA_FALSE;
1552    if (backspace)
1553      {
1554         info->change.del.start = pos - 1;
1555         info->change.del.end = pos;
1556      }
1557    else
1558      {
1559         info->change.del.start = pos + 1;
1560         info->change.del.end = pos;
1561      }
1562
1563    info->change.del.content = eina_stringshare_add(tmp);
1564    if (tmp) free(tmp);
1565
1566    evas_textblock_cursor_char_delete(c);
1567    _edje_emit(ed, "entry,changed", en->rp->part->name);
1568    _edje_emit_full(ed, "entry,changed,user", en->rp->part->name,
1569                    info, _free_entry_change_info);
1570 }
1571
1572 static void
1573 _edje_entry_hide_visible_password(Edje_Real_Part *rp)
1574 {
1575    const Evas_Object_Textblock_Node_Format *node;
1576    node = evas_textblock_node_format_first_get(rp->object);
1577    for (; node; node = evas_textblock_node_format_next_get(node))
1578      {
1579         const char *text = evas_textblock_node_format_text_get(node);
1580         if (text)
1581           {
1582              if (!strcmp(text, "+ password=off"))
1583                {
1584                   evas_textblock_node_format_remove_pair(rp->object,
1585                                                          (Evas_Object_Textblock_Node_Format *) node);
1586                   break;
1587                }
1588           }
1589      }
1590    _edje_entry_real_part_configure(rp);
1591    _edje_emit(rp->edje, "entry,changed", rp->part->name);
1592 }
1593
1594 static Eina_Bool
1595 _password_timer_cb(void *data)
1596 {
1597    Entry *en = (Entry *)data;
1598    _edje_entry_hide_visible_password(en->rp);
1599    en->pw_timer = NULL;
1600    return ECORE_CALLBACK_CANCEL;
1601 }
1602
1603 static Eina_Bool
1604 _is_modifier(const char *key)
1605 {
1606    if ((!strncmp(key, "Shift", 5)) ||
1607        (!strncmp(key, "Control", 7)) ||
1608        (!strncmp(key, "Alt", 3)) ||
1609        (!strncmp(key, "Meta", 4)) ||
1610        (!strncmp(key, "Super", 5)) ||
1611        (!strncmp(key, "Hyper", 5)) ||
1612        (!strcmp(key, "Scroll_Lock")) ||
1613        (!strcmp(key, "Num_Lock")) ||
1614        (!strcmp(key, "Caps_Lock")))
1615      return EINA_TRUE;
1616    return EINA_FALSE;
1617 }
1618
1619 static void
1620 _compose_seq_reset(Entry *en)
1621 {
1622    char *str;
1623    
1624    EINA_LIST_FREE(en->seq, str) eina_stringshare_del(str);
1625    en->composing = EINA_FALSE;
1626 }
1627
1628 static void
1629 _edje_key_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1630 {
1631    Edje *ed = data;
1632    Evas_Event_Key_Down *ev = event_info;
1633    Edje_Real_Part *rp = ed->focused_part;
1634    Entry *en;
1635    Eina_Bool control, alt, shift;
1636    Eina_Bool multiline;
1637    Eina_Bool cursor_changed;
1638    int old_cur_pos;
1639    if (!rp) return;
1640    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
1641        (!rp->typedata.text)) return;
1642    en = rp->typedata.text->entry_data;
1643    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
1644        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_EDITABLE))
1645      return;
1646    if (!ev->keyname) return;
1647
1648    // TIZEN ONLY - START
1649    if (en->cursor_handler_show)
1650      {
1651         evas_object_hide(en->cursor_handler);
1652         en->cursor_handler_show = EINA_FALSE;
1653      }
1654    // TIZEN ONLY - END
1655
1656 #ifdef HAVE_ECORE_IMF
1657    if (en->imf_context)
1658      {
1659         Ecore_IMF_Event_Key_Down ecore_ev;
1660         Eina_Bool filter_ret;
1661         ecore_imf_evas_event_key_down_wrap(ev, &ecore_ev);
1662         if (!en->composing)
1663           {
1664              filter_ret = ecore_imf_context_filter_event(en->imf_context,
1665                                                          ECORE_IMF_EVENT_KEY_DOWN,
1666                                                          (Ecore_IMF_Event *)&ecore_ev);
1667
1668              if (en->have_preedit)
1669                {
1670                   if (!strcmp(ev->keyname, "Down") ||
1671                       (!strcmp(ev->keyname, "KP_Down") && !ev->string) ||
1672                       !strcmp(ev->keyname, "Up") ||
1673                       (!strcmp(ev->keyname, "KP_Up") && !ev->string) ||
1674                       !strcmp(ev->keyname, "Next") ||
1675                       (!strcmp(ev->keyname, "KP_Next") && !ev->string) ||
1676                       !strcmp(ev->keyname, "Prior") ||
1677                       (!strcmp(ev->keyname, "KP_Prior") && !ev->string) ||
1678                       !strcmp(ev->keyname, "Home") ||
1679                       (!strcmp(ev->keyname, "KP_Home") && !ev->string) ||
1680                       !strcmp(ev->keyname, "End") ||
1681                       (!strcmp(ev->keyname, "KP_End") && !ev->string))
1682                     ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1683                }
1684
1685              if (filter_ret)
1686                return;
1687           }
1688      }
1689 #endif
1690
1691    old_cur_pos = evas_textblock_cursor_pos_get(en->cursor);
1692
1693    control = evas_key_modifier_is_set(ev->modifiers, "Control");
1694    alt = evas_key_modifier_is_set(ev->modifiers, "Alt");
1695    shift = evas_key_modifier_is_set(ev->modifiers, "Shift");
1696    multiline = rp->part->multiline;
1697    cursor_changed = EINA_FALSE;
1698    if (!strcmp(ev->keyname, "Escape"))
1699      {
1700         _compose_seq_reset(en);
1701         // dead keys here. Escape for now (should emit these)
1702         _edje_emit(ed, "entry,key,escape", rp->part->name);
1703         // TIZEN ONLY (20130327) : This code is doing nothing for entry now.
1704         //                         And for Tizen "ESC" is used for another purpose.
1705         //ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1706      }
1707    else if (!strcmp(ev->keyname, "Up") ||
1708             (!strcmp(ev->keyname, "KP_Up") && !ev->string))
1709      {
1710         _compose_seq_reset(en);
1711         if (multiline)
1712           {
1713              if (en->have_selection &&
1714                  (evas_textblock_cursor_pos_get(en->sel_start) != evas_textblock_cursor_pos_get(en->sel_end)))
1715                ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1716              if (en->select_allow)
1717                {
1718                   if (shift)
1719                     {
1720                        _sel_start(en->cursor, rp->object, en);
1721                        ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1722                     }
1723                   else _sel_clear(en->cursor, rp->object, en);
1724                }
1725              if (_curs_up(en->cursor, rp->object, en))
1726                ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1727              if (en->select_allow)
1728                {
1729                   if (shift) _sel_extend(en->cursor, rp->object, en);
1730                   else _sel_clear(en->cursor, rp->object, en);
1731                }
1732           }
1733         _edje_emit(ed, "entry,key,up", rp->part->name);
1734         _edje_emit(rp->edje, "cursor,changed,manual", rp->part->name);
1735      }
1736    else if (!strcmp(ev->keyname, "Down") ||
1737             (!strcmp(ev->keyname, "KP_Down") && !ev->string))
1738      {
1739         _compose_seq_reset(en);
1740         if (multiline)
1741           {
1742              if (en->have_selection &&
1743                  (evas_textblock_cursor_pos_get(en->sel_start) != evas_textblock_cursor_pos_get(en->sel_end)))
1744                ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1745              if (en->select_allow)
1746                {
1747                   if (shift)
1748                     {
1749                        _sel_start(en->cursor, rp->object, en);
1750                        ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1751                     }
1752                   else _sel_clear(en->cursor, rp->object, en);
1753                }
1754              if (_curs_down(en->cursor, rp->object, en))
1755                ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1756              if (en->select_allow)
1757                {
1758                   if (shift) _sel_extend(en->cursor, rp->object, en);
1759                   else _sel_clear(en->cursor, rp->object, en);
1760                }
1761           }
1762         _edje_emit(ed, "entry,key,down", rp->part->name);
1763         _edje_emit(rp->edje, "cursor,changed,manual", rp->part->name);
1764      }
1765    else if (!strcmp(ev->keyname, "Left") ||
1766             (!strcmp(ev->keyname, "KP_Left") && !ev->string))
1767      {
1768         _compose_seq_reset(en);
1769         if (en->have_selection &&
1770             (evas_textblock_cursor_pos_get(en->sel_start) != evas_textblock_cursor_pos_get(en->sel_end)))
1771           ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1772         if (en->select_allow)
1773           {
1774              if (shift)
1775                {
1776                   _sel_start(en->cursor, rp->object, en);
1777                   ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1778                }
1779              else _sel_clear(en->cursor, rp->object, en);
1780           }
1781         if (evas_textblock_cursor_char_prev(en->cursor))
1782           ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1783         /* If control is pressed, go to the start of the word */
1784         if (control) evas_textblock_cursor_word_start(en->cursor);
1785         if (en->select_allow)
1786           {
1787              if (shift) _sel_extend(en->cursor, rp->object, en);
1788              else _sel_clear(en->cursor, rp->object, en);
1789           }
1790         _edje_emit(ed, "entry,key,left", rp->part->name);
1791         _edje_emit(rp->edje, "cursor,changed,manual", rp->part->name);
1792      }
1793    else if (!strcmp(ev->keyname, "Right") ||
1794             (!strcmp(ev->keyname, "KP_Right") && !ev->string))
1795      {
1796         _compose_seq_reset(en);
1797         if (en->have_selection &&
1798             (evas_textblock_cursor_pos_get(en->sel_start) != evas_textblock_cursor_pos_get(en->sel_end)))
1799           ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1800         if (en->select_allow)
1801           {
1802              if (shift)
1803                {
1804                   _sel_start(en->cursor, rp->object, en);
1805                   ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1806                }
1807              else _sel_clear(en->cursor, rp->object, en);
1808           }
1809         /* If control is pressed, go to the end of the word */
1810         if (control) evas_textblock_cursor_word_end(en->cursor);
1811         if (evas_textblock_cursor_char_next(en->cursor))
1812           ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1813         if (en->select_allow)
1814           {
1815              if (shift) _sel_extend(en->cursor, rp->object, en);
1816              else _sel_clear(en->cursor, rp->object, en);
1817           }
1818         _edje_emit(ed, "entry,key,right", rp->part->name);
1819         _edje_emit(rp->edje, "cursor,changed,manual", rp->part->name);
1820      }
1821    else if (!strcmp(ev->keyname, "BackSpace"))
1822      {
1823         _compose_seq_reset(en);
1824         if (control && !en->have_selection)
1825           {
1826              // del to start of previous word
1827              _sel_start(en->cursor, rp->object, en);
1828
1829              evas_textblock_cursor_char_prev(en->cursor);
1830              evas_textblock_cursor_word_start(en->cursor);
1831
1832              _sel_preextend(en->cursor, rp->object, en);
1833
1834              _range_del_emit(ed, en->cursor, rp->object, en);
1835           }
1836         else if ((alt) && (shift))
1837           {
1838              // undo last action
1839           }
1840         else
1841           {
1842              if (en->have_selection)
1843                {
1844                   _range_del_emit(ed, en->cursor, rp->object, en);
1845                }
1846              else
1847                {
1848                   if (evas_textblock_cursor_char_prev(en->cursor))
1849                     {
1850                        _delete_emit(ed, en->cursor, en, old_cur_pos, EINA_TRUE);
1851                     }
1852                }
1853           }
1854         _sel_clear(en->cursor, rp->object, en);
1855         _anchors_get(en->cursor, rp->object, en);
1856         _edje_emit(ed, "entry,key,backspace", rp->part->name);
1857         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1858      }
1859    else if (!strcmp(ev->keyname, "Delete") ||
1860             (!strcmp(ev->keyname, "KP_Delete") && !ev->string))
1861      {
1862         _compose_seq_reset(en);
1863         if (control)
1864           {
1865              // del to end of next word
1866              _sel_start(en->cursor, rp->object, en);
1867
1868              evas_textblock_cursor_word_end(en->cursor);
1869              evas_textblock_cursor_char_next(en->cursor);
1870
1871              _sel_extend(en->cursor, rp->object, en);
1872
1873              _range_del_emit(ed, en->cursor, rp->object, en);
1874           }
1875         else if (shift)
1876           {
1877              // cut
1878           }
1879         else
1880           {
1881              if (en->have_selection)
1882                {
1883                   _range_del_emit(ed, en->cursor, rp->object, en);
1884                }
1885              else
1886                {
1887                   _delete_emit(ed, en->cursor, en, old_cur_pos, EINA_FALSE);
1888                }
1889           }
1890         _sel_clear(en->cursor, rp->object, en);
1891         _anchors_get(en->cursor, rp->object, en);
1892         _edje_emit(ed, "entry,key,delete", rp->part->name);
1893         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1894      }
1895    else if (!strcmp(ev->keyname, "Home") ||
1896             ((!strcmp(ev->keyname, "KP_Home")) && !ev->string))
1897      {
1898         _compose_seq_reset(en);
1899         if (en->select_allow)
1900           {
1901              if (shift) _sel_start(en->cursor, rp->object, en);
1902              else _sel_clear(en->cursor, rp->object, en);
1903           }
1904         if ((control) && (multiline))
1905           _curs_start(en->cursor, rp->object, en);
1906         else
1907           _curs_lin_start(en->cursor, rp->object, en);
1908         if (en->select_allow)
1909           {
1910              if (shift) _sel_extend(en->cursor, rp->object, en);
1911           }
1912         _edje_emit(ed, "entry,key,home", rp->part->name);
1913         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1914      }
1915    else if (!strcmp(ev->keyname, "End") ||
1916             ((!strcmp(ev->keyname, "KP_End")) && !ev->string))
1917      {
1918         _compose_seq_reset(en);
1919         if (en->select_allow)
1920           {
1921              if (shift) _sel_start(en->cursor, rp->object, en);
1922              else _sel_clear(en->cursor, rp->object, en);
1923           }
1924         if ((control) && (multiline))
1925           _curs_end(en->cursor, rp->object, en);
1926         else
1927           _curs_lin_end(en->cursor, rp->object, en);
1928         if (en->select_allow)
1929           {
1930              if (shift) _sel_extend(en->cursor, rp->object, en);
1931           }
1932         _edje_emit(ed, "entry,key,end", rp->part->name);
1933         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1934      }
1935    else if ((control) && (!shift) && (!strcmp(ev->keyname, "v")))
1936      {
1937         _compose_seq_reset(en);
1938         _edje_emit(ed, "entry,paste,request", rp->part->name);
1939         _edje_emit(ed, "entry,paste,request,3", rp->part->name);
1940         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1941      }
1942    else if ((control) && (!strcmp(ev->keyname, "a")))
1943      {
1944         _compose_seq_reset(en);
1945         if (shift)
1946           {
1947              _edje_emit(ed, "entry,selection,none,request", rp->part->name);
1948              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1949           }
1950         else
1951           {
1952              if (en->select_allow) // TIZEN ONLY
1953                 _edje_emit(ed, "entry,selection,all,request", rp->part->name);
1954              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1955           }
1956      }
1957    else if ((control) && (((!shift) && !strcmp(ev->keyname, "c")) || !strcmp(ev->keyname, "Insert")))
1958      {
1959         _compose_seq_reset(en);
1960         _edje_emit(ed, "entry,copy,notify", rp->part->name);
1961         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1962      }
1963    else if ((control) && (!shift) && ((!strcmp(ev->keyname, "x") || (!strcmp(ev->keyname, "m")))))
1964      {
1965         _compose_seq_reset(en);
1966         _edje_emit(ed, "entry,cut,notify", rp->part->name);
1967         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1968      }
1969    else if ((control) && (!strcmp(ev->keyname, "z")))
1970      {
1971         _compose_seq_reset(en);
1972         if (shift)
1973           {
1974              // redo
1975              _edje_emit(ed, "entry,redo,request", rp->part->name);
1976           }
1977         else
1978           {
1979              // undo
1980              _edje_emit(ed, "entry,undo,request", rp->part->name);
1981           }
1982         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1983      }
1984    else if ((control) && (!shift) && (!strcmp(ev->keyname, "y")))
1985      {
1986         _compose_seq_reset(en);
1987         // redo
1988         _edje_emit(ed, "entry,redo,request", rp->part->name);
1989         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1990      }
1991    else if ((control) && (!shift) && (!strcmp(ev->keyname, "w")))
1992      {
1993         _compose_seq_reset(en);
1994         _sel_clear(en->cursor, rp->object, en);
1995         // select current word?
1996         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1997      }
1998    else if (!strcmp(ev->keyname, "Tab"))
1999      {
2000         _compose_seq_reset(en);
2001         if (multiline)
2002           {
2003              if (shift)
2004                {
2005                   // remove a tab
2006                }
2007              else
2008                {
2009                   Edje_Entry_Change_Info *info = calloc(1, sizeof(*info));
2010                   info->insert = EINA_TRUE;
2011                   info->change.insert.plain_length = 1;
2012
2013                   if (en->have_selection)
2014                     {
2015                        _range_del_emit(ed, en->cursor, rp->object, en);
2016                        info->merge = EINA_TRUE;
2017                     }
2018                   info->change.insert.pos =
2019                      evas_textblock_cursor_pos_get(en->cursor);
2020                   info->change.insert.content = eina_stringshare_add("<tab/>");
2021                   //yy
2022 //                  evas_textblock_cursor_format_prepend(en->cursor, "tab");
2023                   _text_filter_format_prepend(en, en->cursor, "tab");
2024                   _anchors_get(en->cursor, rp->object, en);
2025                   _edje_emit(ed, "entry,changed", rp->part->name);
2026                   _edje_emit_full(ed, "entry,changed,user", rp->part->name,
2027                                   info, _free_entry_change_info);
2028                }
2029              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2030           }
2031         _edje_emit(ed, "entry,key,tab", rp->part->name);
2032      }
2033    else if ((!strcmp(ev->keyname, "ISO_Left_Tab")) && (multiline))
2034      {
2035         _compose_seq_reset(en);
2036         // remove a tab
2037         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2038      }
2039    else if (!strcmp(ev->keyname, "Prior") ||
2040             (!strcmp(ev->keyname, "KP_Prior") && !ev->string))
2041      {
2042         _compose_seq_reset(en);
2043         if (en->select_allow)
2044           {
2045              if (shift) _sel_start(en->cursor, rp->object, en);
2046              else _sel_clear(en->cursor, rp->object, en);
2047           }
2048         _curs_jump_line_by(en->cursor, rp->object, en, -10);
2049         if (en->select_allow)
2050           {
2051              if (shift) _sel_extend(en->cursor, rp->object, en);
2052              else _sel_clear(en->cursor, rp->object, en);
2053           }
2054         _edje_emit(ed, "entry,key,pgup", rp->part->name);
2055         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2056      }
2057    else if (!strcmp(ev->keyname, "Next") ||
2058             (!strcmp(ev->keyname, "KP_Next") && !ev->string))
2059      {
2060         _compose_seq_reset(en);
2061         if (en->select_allow)
2062           {
2063              if (shift) _sel_start(en->cursor, rp->object, en);
2064              else _sel_clear(en->cursor, rp->object, en);
2065           }
2066         _curs_jump_line_by(en->cursor, rp->object, en, 10);
2067         if (en->select_allow)
2068           {
2069              if (shift) _sel_extend(en->cursor, rp->object, en);
2070              else _sel_clear(en->cursor, rp->object, en);
2071           }
2072         _edje_emit(ed, "entry,key,pgdn", rp->part->name);
2073         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2074      }
2075    else if ((!strcmp(ev->keyname, "Return")) || (!strcmp(ev->keyname, "KP_Enter")))
2076      {
2077         _compose_seq_reset(en);
2078         if (multiline)
2079           {
2080              Edje_Entry_Change_Info *info = calloc(1, sizeof(*info));
2081              info->insert = EINA_TRUE;
2082              info->change.insert.plain_length = 1;
2083              if (en->have_selection)
2084                {
2085                   _range_del_emit(ed, en->cursor, rp->object, en);
2086                   info->merge = EINA_TRUE;
2087                }
2088
2089              info->change.insert.pos =
2090                 evas_textblock_cursor_pos_get(en->cursor);
2091              if (shift ||
2092                  evas_object_textblock_legacy_newline_get(rp->object))
2093                {
2094                   //yy
2095 //                  evas_textblock_cursor_format_prepend(en->cursor, "br");
2096                   _text_filter_format_prepend(en, en->cursor, "br");
2097                   info->change.insert.content = eina_stringshare_add("<br/>");
2098                }
2099              else
2100                {
2101                   //yy
2102 //                  evas_textblock_cursor_format_prepend(en->cursor, "ps");
2103                   _text_filter_format_prepend(en, en->cursor, "ps");
2104                   info->change.insert.content = eina_stringshare_add("<ps/>");
2105                }
2106              _anchors_get(en->cursor, rp->object, en);
2107              _edje_emit(ed, "entry,changed", rp->part->name);
2108              _edje_emit_full(ed, "entry,changed,user", rp->part->name,
2109                              info, _free_entry_change_info);
2110              _edje_emit(ed, "cursor,changed", rp->part->name);
2111              cursor_changed = EINA_TRUE;
2112              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2113           }
2114         _edje_emit(ed, "entry,key,enter", rp->part->name);
2115      }
2116    else
2117      {
2118         char *compres = NULL, *string = (char *)ev->string;
2119         Eina_Bool free_string = EINA_FALSE;
2120         Ecore_Compose_State state;
2121         
2122         if (!en->composing)
2123           {
2124              _compose_seq_reset(en);
2125              en->seq = eina_list_append(en->seq, eina_stringshare_add(ev->key));
2126              state = ecore_compose_get(en->seq, &compres);
2127              if (state == ECORE_COMPOSE_MIDDLE) en->composing = EINA_TRUE;
2128              else en->composing = EINA_FALSE;
2129              if (!en->composing) _compose_seq_reset(en);
2130              else goto end;
2131           }
2132         else
2133           {
2134              if (_is_modifier(ev->key)) goto end;
2135              en->seq = eina_list_append(en->seq, eina_stringshare_add(ev->key));
2136              state = ecore_compose_get(en->seq, &compres);
2137              if (state == ECORE_COMPOSE_NONE) _compose_seq_reset(en);
2138              else if (state == ECORE_COMPOSE_DONE)
2139                {
2140                   _compose_seq_reset(en);
2141                   if (compres)
2142                     {
2143                        string = compres;
2144                        free_string = EINA_TRUE;
2145                     }
2146                }
2147              else goto end;
2148           }
2149         if (string)
2150           {
2151              Edje_Entry_Change_Info *info = calloc(1, sizeof(*info));
2152              info->insert = EINA_TRUE;
2153              info->change.insert.plain_length = 1;
2154              info->change.insert.content = eina_stringshare_add(string);
2155
2156              if (en->have_selection)
2157                {
2158                   _range_del_emit(ed, en->cursor, rp->object, en);
2159                   info->merge = EINA_TRUE;
2160                }
2161
2162              info->change.insert.pos =
2163                 evas_textblock_cursor_pos_get(en->cursor);
2164              // if PASSWORD_SHOW_LAST mode, appending text with password=off tag
2165              if ((rp->part->entry_mode == EDJE_ENTRY_EDIT_MODE_PASSWORD) &&
2166                  _edje_password_show_last)
2167                {
2168                   _edje_entry_hide_visible_password(en->rp);
2169                   _text_filter_format_prepend(en, en->cursor, "+ password=off");
2170                   _text_filter_text_prepend(en, en->cursor, string);
2171                   _text_filter_format_prepend(en, en->cursor, "- password");
2172                   if (en->pw_timer)
2173                     {
2174                        ecore_timer_del(en->pw_timer);
2175                        en->pw_timer = NULL;
2176                     }
2177                   en->pw_timer = ecore_timer_add(TO_DOUBLE(_edje_password_show_last_timeout),
2178                                                  _password_timer_cb, en);
2179                }
2180              else
2181                _text_filter_text_prepend(en, en->cursor, string);
2182              _anchors_get(en->cursor, rp->object, en);
2183              _edje_emit(ed, "entry,changed", rp->part->name);
2184              _edje_emit_full(ed, "entry,changed,user", rp->part->name,
2185                              info, _free_entry_change_info);
2186              _edje_emit(ed, "cursor,changed", rp->part->name);
2187              cursor_changed = EINA_TRUE;
2188              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2189           }
2190         if (free_string) free(string);
2191      }
2192 end:
2193    if (!cursor_changed && (old_cur_pos != evas_textblock_cursor_pos_get(en->cursor)))
2194      _edje_emit(ed, "cursor,changed", rp->part->name);
2195
2196    _edje_entry_imf_cursor_info_set(en);
2197    _edje_entry_real_part_configure(rp);
2198 }
2199
2200 static void
2201 _edje_key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
2202 {
2203    Edje *ed = data;
2204    Edje_Real_Part *rp = ed->focused_part;
2205    Entry *en;
2206
2207    if (!rp) return;
2208    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
2209        (!rp->typedata.text)) return;
2210    en = rp->typedata.text->entry_data;
2211    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
2212        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_EDITABLE))
2213      return;
2214
2215 #ifdef HAVE_ECORE_IMF
2216    if (en->imf_context)
2217      {
2218         Evas_Event_Key_Up *ev = event_info;
2219         Ecore_IMF_Event_Key_Up ecore_ev;
2220
2221         ecore_imf_evas_event_key_up_wrap(ev, &ecore_ev);
2222         if (ecore_imf_context_filter_event(en->imf_context,
2223                                            ECORE_IMF_EVENT_KEY_UP,
2224                                            (Ecore_IMF_Event *)&ecore_ev))
2225           return;
2226      }
2227 #else
2228    (void) event_info;
2229 #endif
2230 }
2231
2232 // TIZEN ONLY - START
2233 Eina_Bool
2234 _edje_entry_select_word(Edje_Real_Part *rp)
2235 {
2236    Entry *en;
2237    if (!rp) return EINA_FALSE;
2238    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
2239        (!rp->typedata.text)) return EINA_FALSE;
2240
2241    en = rp->typedata.text->entry_data;
2242    if (!en) return EINA_FALSE;
2243
2244    if (en->cursor_fg) evas_object_hide(en->cursor_fg);
2245    if (en->cursor_bg) evas_object_hide(en->cursor_bg);
2246
2247    evas_textblock_cursor_word_start(en->cursor);
2248
2249    if (evas_textblock_cursor_eol_get(en->cursor))
2250      {
2251         evas_textblock_cursor_char_prev(en->cursor);
2252         evas_textblock_cursor_word_start(en->cursor);
2253      }
2254
2255    _sel_clear(en->cursor, rp->object, en);
2256    _sel_enable(en->cursor, rp->object, en);
2257    _sel_start(en->cursor, rp->object, en);
2258
2259    evas_textblock_cursor_word_end(en->cursor);
2260    evas_textblock_cursor_char_next(en->cursor);
2261
2262    _sel_extend(en->cursor, rp->object, en);
2263    _edje_entry_real_part_configure(rp);
2264
2265    en->had_sel = EINA_TRUE;
2266    en->selecting = EINA_FALSE;
2267
2268    return EINA_TRUE;
2269 }
2270
2271 static Eina_Bool
2272 _long_press_cb(void *data)
2273 {
2274    Edje_Real_Part *rp = data;
2275    Entry *en;
2276    if (!rp) return ECORE_CALLBACK_CANCEL;
2277    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
2278        (!rp->typedata.text)) return ECORE_CALLBACK_CANCEL;
2279
2280    en = rp->typedata.text->entry_data;
2281    if (!en) return ECORE_CALLBACK_CANCEL;
2282
2283    if (en->long_press_timer)
2284      {
2285         ecore_timer_del(en->long_press_timer);
2286         en->long_press_timer = NULL;
2287      }
2288
2289    en->long_press_state = _ENTRY_LONG_PRESSED;
2290    en->long_press_timer = NULL;
2291
2292    _edje_emit(en->rp->edje, "long,pressed", en->rp->part->name);
2293
2294    if ((en->cursor_handler) && (!en->cursor_handler_disabled) && (en->focused))
2295      {
2296         edje_object_signal_emit(en->cursor_handler, "edje,cursor,handle,show", "edje");
2297         evas_object_show(en->cursor_handler);
2298         en->cursor_handler_show = EINA_TRUE;
2299      }
2300    return ECORE_CALLBACK_CANCEL;
2301 }
2302 // TIZEN ONLY - END
2303
2304 static void
2305 _edje_part_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
2306 {
2307    Edje_Real_Part *rp = data;
2308    Entry *en;
2309    if (!rp) return;
2310    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
2311        (!rp->typedata.text)) return;
2312    en = rp->typedata.text->entry_data;
2313    if (!en) return;
2314    _edje_entry_imf_cursor_location_set(en);
2315 }
2316
2317 static void
2318 _edje_part_mouse_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
2319 {
2320    Evas_Coord cx, cy;
2321    Edje_Real_Part *rp = data;
2322    Evas_Event_Mouse_Down *ev = event_info;
2323    Entry *en;
2324    Evas_Coord x, y, w, h;
2325    //   Eina_Bool multiline;
2326    Evas_Textblock_Cursor *tc = NULL;
2327    Eina_Bool dosel = EINA_FALSE;
2328    Eina_Bool shift;
2329    if (!rp) return;
2330    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
2331    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
2332        (!rp->typedata.text)) return;
2333    en = rp->typedata.text->entry_data;
2334    en->long_press_state = _ENTRY_LONG_PRESSING; // TIZEN ONLY
2335    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
2336        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE))
2337      return;
2338    if ((ev->button != 1) && (ev->button != 2)) return;
2339
2340    // TIZEN ONLY - START
2341    en->dx = ev->canvas.x;
2342    en->dy = ev->canvas.y;
2343    // TIZEN ONLY - END
2344
2345 #ifdef HAVE_ECORE_IMF
2346    if (en->imf_context)
2347      {
2348         Ecore_IMF_Event_Mouse_Down ecore_ev;
2349         ecore_imf_evas_event_mouse_down_wrap(ev, &ecore_ev);
2350         if (ecore_imf_context_filter_event(en->imf_context,
2351                                            ECORE_IMF_EVENT_MOUSE_DOWN,
2352                                            (Ecore_IMF_Event *)&ecore_ev))
2353           return;
2354      }
2355 #endif
2356
2357    _edje_entry_imf_context_reset(rp);
2358
2359    shift = evas_key_modifier_is_set(ev->modifiers, "Shift");
2360    en->select_mod_start = EINA_FALSE;
2361    en->select_mod_end = EINA_FALSE;
2362    if (rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_DEFAULT)
2363       dosel = EINA_TRUE;
2364    else if ((rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_EXPLICIT) ||
2365             (rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_BLOCK_HANDLE))
2366      {
2367         if (en->select_allow) dosel = EINA_TRUE;
2368      }
2369    if (ev->button == 2) dosel = EINA_FALSE;
2370    if (dosel)
2371      {
2372         evas_object_geometry_get(rp->object, &x, &y, &w, &h);
2373         cx = ev->canvas.x - x;
2374         cy = ev->canvas.y - y;
2375         if (ev->flags & EVAS_BUTTON_TRIPLE_CLICK)
2376           {
2377              if (shift)
2378                {
2379                   tc = evas_object_textblock_cursor_new(rp->object);
2380                   evas_textblock_cursor_copy(en->cursor, tc);
2381                   if (evas_textblock_cursor_compare(en->cursor, en->sel_start) < 0)
2382                     evas_textblock_cursor_line_char_first(en->cursor);
2383                   else
2384                     evas_textblock_cursor_line_char_last(en->cursor);
2385                   _sel_extend(en->cursor, rp->object, en);
2386                }
2387              else
2388                {
2389                   en->have_selection = EINA_FALSE;
2390                   en->selecting = EINA_FALSE;
2391                   _sel_clear(en->cursor, rp->object, en);
2392                   tc = evas_object_textblock_cursor_new(rp->object);
2393                   evas_textblock_cursor_copy(en->cursor, tc);
2394                   evas_textblock_cursor_line_char_first(en->cursor);
2395                   _sel_start(en->cursor, rp->object, en);
2396                   evas_textblock_cursor_line_char_last(en->cursor);
2397                   _sel_extend(en->cursor, rp->object, en);
2398                }
2399              goto end;
2400           }
2401         else if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
2402           {
2403              if (shift)
2404                {
2405                   tc = evas_object_textblock_cursor_new(rp->object);
2406                   evas_textblock_cursor_copy(en->cursor, tc);
2407                   if (evas_textblock_cursor_compare(en->cursor, en->sel_start) < 0)
2408                     evas_textblock_cursor_word_start(en->cursor);
2409                   else
2410                     {
2411                        evas_textblock_cursor_word_end(en->cursor);
2412                        evas_textblock_cursor_char_next(en->cursor);
2413                     }
2414                   _sel_extend(en->cursor, rp->object, en);
2415                }
2416              else
2417                {
2418                   en->have_selection = EINA_FALSE;
2419                   en->selecting = EINA_FALSE;
2420                   _sel_clear(en->cursor, rp->object, en);
2421                   tc = evas_object_textblock_cursor_new(rp->object);
2422                   evas_textblock_cursor_copy(en->cursor, tc);
2423                   evas_textblock_cursor_word_start(en->cursor);
2424                   _sel_start(en->cursor, rp->object, en);
2425                   evas_textblock_cursor_word_end(en->cursor);
2426                   evas_textblock_cursor_char_next(en->cursor);
2427                   _sel_extend(en->cursor, rp->object, en);
2428                }
2429              goto end;
2430           }
2431      }
2432    tc = evas_object_textblock_cursor_new(rp->object);
2433    evas_textblock_cursor_copy(en->cursor, tc);
2434    //   multiline = rp->part->multiline;
2435    evas_object_geometry_get(rp->object, &x, &y, &w, &h);
2436    cx = ev->canvas.x - x;
2437    cy = ev->canvas.y - y;
2438    if (en->rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_BLOCK_HANDLE)
2439      {
2440         evas_textblock_cursor_char_coord_set(en->cursor, cx, cy);
2441      }
2442    else
2443      {
2444         if (!evas_textblock_cursor_char_coord_set(en->cursor, cx, cy))
2445           {
2446              Evas_Coord lx, ly, lw, lh;
2447              int line;
2448
2449              line = evas_textblock_cursor_line_coord_set(en->cursor, cy);
2450              if (line == -1)
2451                {
2452                   if (rp->part->multiline)
2453                      _curs_end(en->cursor, rp->object, en);
2454                   else
2455                     {
2456                        evas_textblock_cursor_paragraph_first(en->cursor);
2457                        evas_textblock_cursor_line_geometry_get(en->cursor, &lx, &ly, &lw, &lh);
2458                        if (!evas_textblock_cursor_char_coord_set(en->cursor, cx, ly + (lh / 2)))
2459                           _curs_end(en->cursor, rp->object, en);
2460                     }
2461                }
2462              else
2463                {
2464                   int lnum;
2465
2466                   lnum = evas_textblock_cursor_line_geometry_get(en->cursor, &lx, &ly, &lw, &lh);
2467                   if (lnum < 0)
2468                     {
2469                        _curs_lin_start(en->cursor, rp->object, en);
2470                     }
2471                   else
2472                     {
2473                        if (cx <= lx)
2474                           _curs_lin_start(en->cursor, rp->object, en);
2475                        else
2476                           _curs_lin_end(en->cursor, rp->object, en);
2477                     }
2478                }
2479           }
2480      }
2481    if (dosel)
2482      {
2483         if ((en->have_selection) &&
2484             (rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_EXPLICIT))
2485           {
2486              if (shift)
2487                _sel_extend(en->cursor, rp->object, en);
2488              else
2489                {
2490                   Eina_List *first, *last;
2491                   FLOAT_T sc;
2492
2493                   first = en->sel;
2494                   last = eina_list_last(en->sel);
2495                   if (first && last)
2496                     {
2497                        Evas_Textblock_Rectangle *r1, *r2;
2498                        Evas_Coord d, d1, d2;
2499                        
2500                        r1 = first->data;
2501                        r2 = last->data;
2502                        d = r1->x - cx;
2503                        d1 = d * d;
2504                        d = (r1->y + (r1->h / 2)) - cy;
2505                        d1 += d * d;
2506                        d = r2->x + r2->w - 1 - cx;
2507                        d2 = d * d;
2508                        d = (r2->y + (r2->h / 2)) - cy;
2509                        d2 += d * d;
2510                        sc = rp->edje->scale;
2511                        if (sc == ZERO) sc = _edje_scale;
2512                        d = (Evas_Coord)MUL(FROM_INT(20), sc); // FIXME: maxing number!
2513                        d = d * d;
2514                        if (d1 < d2)
2515                          {
2516                             if (d1 <= d)
2517                               {
2518                                  en->select_mod_start = EINA_TRUE;
2519                                  en->selecting = EINA_TRUE;
2520                               }
2521                          }
2522                        else
2523                          {
2524                             if (d2 <= d)
2525                               {
2526                                  en->select_mod_end = EINA_TRUE;
2527                                  en->selecting = EINA_TRUE;
2528                               }
2529                          }
2530                     }
2531                }
2532           }
2533         else if ((en->have_selection) &&
2534                  (rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_BLOCK_HANDLE))
2535           { // TIZEN ONLY - START
2536              if (shift)
2537                 _sel_extend(en->cursor, rp->object, en);
2538           } // TIZEN ONLY - END
2539         else
2540           {
2541              if ((en->have_selection) && (shift))
2542                _sel_extend(en->cursor, rp->object, en);
2543              else
2544                {
2545                   en->selecting = EINA_TRUE;
2546                   _sel_clear(en->cursor, rp->object, en);
2547                   if (en->select_allow)
2548                     {
2549                        _sel_start(en->cursor, rp->object, en);
2550                     }
2551                }
2552           }
2553      }
2554  end:
2555    if (evas_textblock_cursor_compare(tc, en->cursor))
2556      {
2557         _edje_emit(rp->edje, "cursor,changed", rp->part->name);
2558         _edje_emit(rp->edje, "cursor,changed,manual", rp->part->name);
2559      }
2560    evas_textblock_cursor_free(tc);
2561
2562    // TIZEN ONLY - START
2563    if (en->rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_BLOCK_HANDLE)
2564      {
2565         if (en->long_press_timer) ecore_timer_del(en->long_press_timer);
2566         en->long_press_timer = ecore_timer_add(0.5, _long_press_cb, data); //FIXME: timer value
2567      }
2568    else
2569       _edje_entry_real_part_configure(rp);
2570    if (ev->button == 2)
2571      {
2572         _edje_emit(rp->edje, "entry,paste,request", rp->part->name);
2573         _edje_emit(rp->edje, "entry,paste,request,1", rp->part->name);
2574      }
2575 }
2576
2577 static void
2578 _edje_part_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
2579 {
2580    Evas_Coord cx, cy;
2581    Edje_Real_Part *rp = data;
2582    Evas_Event_Mouse_Up *ev = event_info;
2583    Entry *en;
2584    Evas_Coord x, y, w, h;
2585    Evas_Textblock_Cursor *tc;
2586    if (ev->button != 1) return;
2587    if (!rp) return;
2588    //if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return; //TIZEN ONLY
2589    //if (ev->flags & EVAS_BUTTON_TRIPLE_CLICK) return; // TIZEN ONLY
2590    //if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK) return; // TIZEN ONLY
2591    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
2592        (!rp->typedata.text)) return;
2593    en = rp->typedata.text->entry_data;
2594    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
2595        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE))
2596      return;
2597
2598    // TIZEN ONLY - START
2599    if (en->long_press_timer)
2600      {
2601         ecore_timer_del(en->long_press_timer);
2602         en->long_press_timer = NULL;
2603      }
2604
2605    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
2606      {
2607         _edje_entry_imf_cursor_info_set(en);
2608         return;
2609      }
2610
2611    if (ev->flags & EVAS_BUTTON_TRIPLE_CLICK) return;
2612    if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK) return;
2613
2614    if (en->long_press_state == _ENTRY_LONG_PRESSED)
2615      {
2616         en->long_press_state = _ENTRY_LONG_PRESS_RELEASED;
2617         _edje_entry_imf_cursor_info_set(en);
2618
2619         if ((strcmp(_edje_entry_text_get(rp), "") == 0) && (en->cursor_handler_show))
2620           {
2621              evas_object_hide(en->cursor_handler);
2622              en->cursor_handler_show = EINA_FALSE;
2623           }
2624         return;
2625      }
2626    en->long_press_state = _ENTRY_LONG_PRESS_RELEASED;
2627
2628    if ((en->cursor_handler) && (!en->cursor_handler_disabled) && (!en->have_selection))
2629      {
2630         evas_object_show(en->cursor_handler);
2631         en->cursor_handler_show = EINA_TRUE;
2632      }
2633    // TIZEN ONLY - END
2634
2635 #ifdef HAVE_ECORE_IMF
2636    if (en->imf_context)
2637      {
2638         Ecore_IMF_Event_Mouse_Up ecore_ev;
2639         ecore_imf_evas_event_mouse_up_wrap(ev, &ecore_ev);
2640         if (ecore_imf_context_filter_event(en->imf_context,
2641                                            ECORE_IMF_EVENT_MOUSE_UP,
2642                                            (Ecore_IMF_Event *)&ecore_ev))
2643           return;
2644      }
2645 #endif
2646
2647    tc = evas_object_textblock_cursor_new(rp->object);
2648    evas_textblock_cursor_copy(en->cursor, tc);
2649    evas_object_geometry_get(rp->object, &x, &y, &w, &h);
2650    cx = ev->canvas.x - x;
2651    cy = ev->canvas.y - y;
2652    if (!evas_textblock_cursor_char_coord_set(en->cursor, cx, cy))
2653      {
2654         Evas_Coord lx, ly, lw, lh;
2655         int line;
2656
2657         line = evas_textblock_cursor_line_coord_set(en->cursor, cy);
2658         if (line == -1)
2659           {
2660              if (rp->part->multiline)
2661                _curs_end(en->cursor, rp->object, en);
2662              else
2663                {
2664                   evas_textblock_cursor_paragraph_first(en->cursor);
2665                   evas_textblock_cursor_line_geometry_get(en->cursor, &lx, &ly, &lw, &lh);
2666                   if (!evas_textblock_cursor_char_coord_set(en->cursor, cx, ly + (lh / 2)))
2667                     _curs_end(en->cursor, rp->object, en);
2668                }
2669           }
2670         else
2671           {
2672              int lnum;
2673
2674              lnum = evas_textblock_cursor_line_geometry_get(en->cursor, &lx, &ly, &lw, &lh);
2675              if (lnum < 0)
2676                {
2677                   _curs_lin_start(en->cursor, rp->object, en);
2678                }
2679              else
2680                {
2681                   if (cx <= lx)
2682                     _curs_lin_start(en->cursor, rp->object, en);
2683                   else
2684                     _curs_lin_end(en->cursor, rp->object, en);
2685                }
2686           }
2687      }
2688    if (rp->part->select_mode != EDJE_ENTRY_SELECTION_MODE_BLOCK_HANDLE)
2689      {
2690        if ((rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_EXPLICIT))
2691          {
2692            if (en->select_allow)
2693              {
2694                if (en->had_sel)
2695                  {
2696                    if (en->select_mod_end)
2697                      _sel_extend(en->cursor, rp->object, en);
2698                    else if (en->select_mod_start)
2699                      _sel_preextend(en->cursor, rp->object, en);
2700                  }
2701                else
2702                  _sel_extend(en->cursor, rp->object, en);
2703                //evas_textblock_cursor_copy(en->cursor, en->sel_end);
2704              }
2705          }
2706        else
2707          evas_textblock_cursor_copy(en->cursor, en->sel_end);
2708
2709        if (en->selecting)
2710          {
2711            if (en->have_selection)
2712              en->had_sel = EINA_TRUE;
2713            en->selecting = EINA_FALSE;
2714          }
2715      }
2716    else // TIZEN ONLY - START
2717      {
2718         Evas_Coord dx, dy;
2719
2720         dx = en->dx - ev->canvas.x;
2721         dy = en->dy - ev->canvas.y;
2722         if (((dx * dx) + (dy * dy)) < (40 * 40)) //FIXME: maxing number!
2723           {
2724              _sel_clear(en->cursor, en->rp->object, en);
2725           }
2726      } // TIZEN ONLY - END
2727
2728    if (evas_textblock_cursor_compare(tc, en->cursor))
2729      {
2730         _edje_emit(rp->edje, "cursor,changed", rp->part->name);
2731         _edje_emit(rp->edje, "cursor,changed,manual", rp->part->name);
2732      }
2733
2734    _edje_entry_imf_cursor_info_set(en);
2735
2736    evas_textblock_cursor_free(tc);
2737
2738    _edje_entry_real_part_configure(rp);
2739 }
2740
2741 static void
2742 _edje_part_mouse_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
2743 {
2744    Evas_Coord cx, cy;
2745    Edje_Real_Part *rp = data;
2746    Evas_Event_Mouse_Move *ev = event_info;
2747    Entry *en;
2748    Evas_Coord x, y, w, h;
2749    Evas_Textblock_Cursor *tc;
2750    if (!rp) return;
2751    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
2752        (!rp->typedata.text)) return;
2753    en = rp->typedata.text->entry_data;
2754    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
2755        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE))
2756      return;
2757
2758 #ifdef HAVE_ECORE_IMF
2759    if (en->imf_context)
2760      {
2761         Ecore_IMF_Event_Mouse_Move ecore_ev;
2762         ecore_imf_evas_event_mouse_move_wrap(ev, &ecore_ev);
2763         if (ecore_imf_context_filter_event(en->imf_context,
2764                                            ECORE_IMF_EVENT_MOUSE_MOVE,
2765                                            (Ecore_IMF_Event *)&ecore_ev))
2766           return;
2767      }
2768 #endif
2769
2770    // TIZEN ONLY - START
2771    if (rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_BLOCK_HANDLE)
2772      {
2773         _edje_entry_real_part_configure(rp);
2774
2775         if (en->long_press_state == _ENTRY_LONG_PRESSING)
2776           {
2777              Evas_Coord dx, dy;
2778
2779              dx = en->dx - ev->cur.canvas.x;
2780              dy = en->dy - ev->cur.canvas.y;
2781
2782              /* FIXME: Magic number 40 is used to ignore finger move while detecting long press.              */
2783              /*        This should be replaced with the constant or variable relevant to the elm_finger_size. */
2784              if (((dx*dx) + (dy*dy)) > (40*40))
2785                {
2786                   en->long_press_state = _ENTRY_LONG_PRESS_RELEASED;
2787                   if (en->long_press_timer)
2788                     {
2789                        ecore_timer_del(en->long_press_timer);
2790                        en->long_press_timer = NULL;
2791                     }
2792                }
2793           }
2794         else if (en->long_press_state == _ENTRY_LONG_PRESSED)
2795           {
2796              Evas_Coord flx, fly, flh;
2797              Evas_Coord cnx, cny;
2798              int old_cur_pos;
2799
2800              tc = evas_object_textblock_cursor_new(rp->object);
2801              evas_textblock_cursor_copy(en->cursor, tc);
2802              evas_object_geometry_get(rp->object, &x, &y, &w, &h);
2803
2804              cx = ev->cur.canvas.x - x;
2805              cy = ev->cur.canvas.y - y;
2806
2807              old_cur_pos = evas_textblock_cursor_pos_get(en->cursor);
2808              evas_textblock_cursor_char_coord_set(en->cursor, cx, cy);
2809
2810              /* handle the special cases in which pressed position is above the first line or below the last line  */
2811              evas_object_textblock_line_number_geometry_get(rp->object, 0, &flx, &fly, NULL, &flh);
2812              evas_textblock_cursor_line_geometry_get(en->cursor, &cnx, &cny, NULL, NULL);
2813              if ((cnx == flx) && (cny == fly))
2814                {
2815                   /* cursor is in the first line */
2816                   if (!evas_textblock_cursor_char_coord_set(en->cursor, cx, fly + flh / 2))
2817                      evas_textblock_cursor_pos_set(en->cursor, old_cur_pos);
2818                }
2819              else
2820                {
2821                   Evas_Textblock_Cursor *lc;
2822                   Evas_Coord llx, lly, llh;
2823
2824                   lc = evas_object_textblock_cursor_new(rp->object);
2825                   evas_textblock_cursor_copy(en->cursor, lc);
2826                   evas_textblock_cursor_paragraph_last(lc);
2827                   evas_textblock_cursor_line_geometry_get(lc, &llx, &lly, NULL, &llh);
2828                   if ((cnx == llx) && (cny == lly))
2829                     {
2830                        /* cursor is in the last line */
2831                        if (!evas_textblock_cursor_char_coord_set(en->cursor, cx, lly + llh / 2))
2832                           evas_textblock_cursor_pos_set(en->cursor, old_cur_pos);
2833                     }
2834                   evas_textblock_cursor_free(lc);
2835                }
2836              if (evas_textblock_cursor_line_geometry_get(en->cursor, NULL, NULL, NULL, NULL) == -1)
2837                 evas_textblock_cursor_pos_set(en->cursor, old_cur_pos);
2838
2839              if (evas_textblock_cursor_compare(tc, en->cursor))
2840                {
2841                   _edje_emit(rp->edje, "cursor,changed", rp->part->name);
2842                }
2843              evas_textblock_cursor_free(tc);
2844
2845              //_edje_emit(en->rp->edje, "magnifier,changed", en->rp->part->name);
2846           }
2847      } // TIZEN ONLY - END
2848    else
2849      {
2850         if (en->selecting)
2851           {
2852              tc = evas_object_textblock_cursor_new(rp->object);
2853              evas_textblock_cursor_copy(en->cursor, tc);
2854              evas_object_geometry_get(rp->object, &x, &y, &w, &h);
2855              cx = ev->cur.canvas.x - x;
2856              cy = ev->cur.canvas.y - y;
2857              if (!evas_textblock_cursor_char_coord_set(en->cursor, cx, cy))
2858                {
2859                   Evas_Coord lx, ly, lw, lh;
2860
2861                   if (evas_textblock_cursor_line_coord_set(en->cursor, cy) < 0)
2862                     {
2863                        if (rp->part->multiline)
2864                          _curs_end(en->cursor, rp->object, en);
2865                        else
2866                          {
2867                             evas_textblock_cursor_paragraph_first(en->cursor);
2868                             evas_textblock_cursor_line_geometry_get(en->cursor, &lx, &ly, &lw, &lh);
2869                             if (!evas_textblock_cursor_char_coord_set(en->cursor, cx, ly + (lh / 2)))
2870                               _curs_end(en->cursor, rp->object, en);
2871                          }
2872                     }
2873                   else
2874                     {
2875                        evas_textblock_cursor_line_geometry_get(en->cursor, &lx, &ly, &lw, &lh);
2876                        if (cx <= lx)
2877                          _curs_lin_start(en->cursor, rp->object, en);
2878                        else
2879                          _curs_lin_end(en->cursor, rp->object, en);
2880                     }
2881                }
2882
2883              if ((rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_EXPLICIT) ||
2884                  (rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_BLOCK_HANDLE))
2885                {
2886                   if (en->select_allow)
2887                     {
2888                        if (en->had_sel)
2889                          {
2890                             if (en->select_mod_end)
2891                               _sel_extend(en->cursor, rp->object, en);
2892                             else if (en->select_mod_start)
2893                               _sel_preextend(en->cursor, rp->object, en);
2894                          }
2895                        else
2896                          _sel_extend(en->cursor, rp->object, en);
2897                     }
2898                }
2899              else
2900                {
2901                   _sel_extend(en->cursor, rp->object, en);
2902                }
2903              if (en->select_allow)
2904                {
2905                   if (evas_textblock_cursor_compare(en->sel_start, en->sel_end) != 0)
2906                     _sel_enable(en->cursor, rp->object, en);
2907                   if (en->have_selection)
2908                     _sel_update(en->cursor, rp->object, en);
2909                }
2910              if (evas_textblock_cursor_compare(tc, en->cursor))
2911                {
2912                   _edje_emit(rp->edje, "cursor,changed", rp->part->name);
2913                   _edje_emit(rp->edje, "cursor,changed,manual", rp->part->name);
2914                }
2915              evas_textblock_cursor_free(tc);
2916
2917              _edje_entry_real_part_configure(rp);
2918           }
2919      }
2920 }
2921
2922 // TIZEN ONLY - START
2923 static Eina_Bool
2924 _cursor_handler_click_cb(void *data)
2925 {
2926    Edje_Real_Part *rp = data;
2927    Entry *en;
2928    if (!rp) return ECORE_CALLBACK_CANCEL;
2929    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
2930        (!rp->typedata.text)) return ECORE_CALLBACK_CANCEL;
2931    en = rp->typedata.text->entry_data;
2932    if (!en) return ECORE_CALLBACK_CANCEL;
2933
2934    if (en->cursor_handler_click_timer)
2935      {
2936         ecore_timer_del(en->cursor_handler_click_timer);
2937         en->cursor_handler_click_timer = NULL;
2938      }
2939    en->cursor_handler_click_timer = NULL;
2940
2941    return ECORE_CALLBACK_CANCEL;
2942 }
2943
2944 static void
2945 _edje_entry_cursor_handler_mouse_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info)
2946 {
2947    Entry *en;
2948    Edje_Real_Part *rp = data;
2949    Evas_Event_Mouse_Down *ev = event_info;
2950    Evas_Coord ox, oy, ow, oh;
2951    Evas_Coord lx, ly, lw, lh;
2952
2953    if (!rp) return;
2954    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
2955        (!rp->typedata.text)) return;
2956    en = rp->typedata.text->entry_data;
2957
2958    if (ev->button != 1) return;
2959
2960    en->rx = en->sx = ev->canvas.x;
2961    en->ry = en->sy = ev->canvas.y;
2962
2963    evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
2964    edje_object_size_min_calc(obj, &ow, &oh);
2965    evas_textblock_cursor_line_geometry_get(en->cursor, &lx, &ly, &lw, &lh);
2966
2967    en->ox = ox + ow/2 - en->rx;
2968    en->oy = oy - en->ry - lh/2;
2969
2970    _edje_emit(rp->edje, "cursor,handler,move,start", en->rp->part->name);
2971
2972    if (en->cursor_handler_click_timer) ecore_timer_del(en->cursor_handler_click_timer);
2973    en->cursor_handler_click_timer = ecore_timer_add(0.1, _cursor_handler_click_cb, data); //FIXME: timer value
2974 }
2975
2976 static void
2977 _edje_entry_cursor_handler_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
2978 {
2979    Entry *en;
2980    Edje_Real_Part *rp = data;
2981    Evas_Event_Mouse_Up *ev = event_info;
2982
2983    if (!rp) return;
2984    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
2985        (!rp->typedata.text)) return;
2986    en = rp->typedata.text->entry_data;
2987
2988    if (ev->button != 1) return;
2989
2990    if (en->cursor_handler_click_timer)
2991      {
2992         ecore_timer_del(en->cursor_handler_click_timer);
2993         en->cursor_handler_click_timer = NULL;
2994
2995         _edje_emit(rp->edje, "cursor,handler,clicked", rp->part->name);
2996      }
2997    else
2998      {
2999       _edje_entry_imf_cursor_info_set(en);
3000       _edje_emit(rp->edje, "cursor,handler,move,end", en->rp->part->name);
3001      }
3002 }
3003
3004 static void
3005 _edje_entry_cursor_handler_mouse_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
3006 {
3007    Entry *en;
3008    Edje_Real_Part *rp = data;
3009    Evas_Event_Mouse_Move *ev = event_info;
3010    Evas_Coord x, y, tx, ty, tw, th;
3011    Evas_Coord cx, cy;
3012    Evas_Coord lh;
3013    int old_cur_pos;
3014
3015    if (!rp) return;
3016    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
3017        (!rp->typedata.text)) return;
3018    en = rp->typedata.text->entry_data;
3019
3020    if (ev->buttons != 1) return;
3021
3022    x = ev->cur.canvas.x;
3023    y = ev->cur.canvas.y;
3024
3025    en->rx += (x - en->sx);
3026    en->ry += (y - en->sy);
3027    en->sx = ev->cur.canvas.x;
3028    en->sy = ev->cur.canvas.y;
3029
3030    evas_object_geometry_get(rp->object, &tx, &ty, NULL, NULL);
3031    evas_object_textblock_size_formatted_get(rp->object, &tw, &th);
3032
3033    cx = en->rx + en->ox - tx;
3034    cy = en->ry + en->oy - ty;
3035
3036    evas_textblock_cursor_line_geometry_get(en->cursor, NULL, NULL, NULL, &lh);
3037    if (cx <= 0) cx = 1;
3038    if (cy <= 0) cy = lh / 2;
3039    if (cy > th) cy = th - 1;
3040
3041    old_cur_pos = evas_textblock_cursor_pos_get(en->cursor);
3042    if (!evas_textblock_cursor_char_coord_set(en->cursor, cx, cy))
3043      {
3044         evas_textblock_cursor_pos_set(en->cursor, old_cur_pos);
3045      }
3046    else if (evas_textblock_cursor_line_geometry_get(en->cursor, NULL, NULL, NULL, NULL) == -1)
3047      {
3048         evas_textblock_cursor_pos_set(en->cursor, old_cur_pos);
3049      }
3050
3051    //_edje_entry_imf_cursor_info_set(en);
3052    _edje_emit(rp->edje, "cursor,changed", rp->part->name); //to scroll scroller
3053    _edje_entry_real_part_configure(rp);
3054
3055    _edje_emit(rp->edje, "cursor,handler,moving", rp->part->name);
3056 }
3057
3058 static void
3059 _edje_entry_start_handler_mouse_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info)
3060 {
3061    Evas_Event_Mouse_Down *ev = event_info;
3062    Evas_Coord ox, oy, ow, oh;
3063    Evas_Coord lx, ly, lw, lh;
3064    Edje_Real_Part *rp = data;
3065    Entry *en = rp->typedata.text->entry_data;
3066
3067    if (ev->button != 1) return;
3068
3069    _edje_entry_cursor_copy(rp, EDJE_CURSOR_SELECTION_BEGIN, EDJE_CURSOR_MAIN);
3070    en->rx = en->sx = ev->canvas.x;
3071    en->ry = en->sy = ev->canvas.y;
3072
3073    evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
3074    edje_object_size_min_calc(obj, &ow, &oh);
3075    evas_textblock_cursor_line_geometry_get(en->cursor, &lx, &ly, &lw, &lh);
3076
3077    en->ox = ox + ow/2 - en->rx;
3078    //en->oy = oy + oh - en->ry + lh/2;
3079    en->oy = oy + oh - en->ry - lh/2;
3080
3081    en->select_mod_start = EINA_TRUE;
3082    en->selecting = EINA_TRUE;
3083
3084    _edje_emit(en->rp->edje, "handler,move,start", en->rp->part->name);
3085 }
3086
3087 static void
3088 _edje_entry_start_handler_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
3089 {
3090    Edje_Real_Part *rp = data;
3091    Entry *en = rp->typedata.text->entry_data;
3092
3093    //switch sel_start,end
3094    if (evas_textblock_cursor_compare(en->sel_start, en->sel_end) >= 0)
3095      {
3096         Evas_Textblock_Cursor *tc;
3097         tc = evas_object_textblock_cursor_new(rp->object);
3098         evas_textblock_cursor_copy(en->sel_start, tc);
3099         evas_textblock_cursor_copy(en->sel_end, en->sel_start);
3100         evas_textblock_cursor_copy(tc, en->sel_end);
3101         evas_textblock_cursor_free(tc);
3102      }
3103    //update handlers
3104    en->handler_bypassing = EINA_FALSE;
3105    _edje_entry_real_part_configure(rp);
3106
3107    _edje_emit(en->rp->edje, "handler,move,end", en->rp->part->name);
3108 }
3109
3110 static void
3111 _edje_entry_start_handler_mouse_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
3112 {
3113    Evas_Event_Mouse_Move *ev = event_info;
3114    Edje_Real_Part *rp = data;
3115    Entry *en = rp->typedata.text->entry_data;
3116    Evas_Coord x, y, tx, ty, tw, th;
3117    Evas_Coord cx, cy;
3118    Evas_Coord lh;
3119    Evas_Textblock_Cursor_Type cur_type;
3120    Evas_Coord sx, sy;
3121    int old_cur_pos;
3122
3123    if (ev->buttons != 1) return;
3124
3125    x = ev->cur.canvas.x;
3126    y = ev->cur.canvas.y;
3127
3128    en->rx += (x - en->sx);
3129    en->ry += (y - en->sy);
3130    en->sx = ev->cur.canvas.x;
3131    en->sy = ev->cur.canvas.y;
3132
3133    evas_object_geometry_get(rp->object, &tx, &ty, NULL, NULL);
3134    evas_object_textblock_size_formatted_get(rp->object, &tw, &th);
3135
3136    cx = en->rx + en->ox - tx;
3137    cy = en->ry + en->oy - ty;
3138
3139    evas_textblock_cursor_line_geometry_get(en->cursor, NULL, NULL, NULL, &lh);
3140    if (cx <= 0) cx = 1;
3141    if (cy < lh / 2) cy = lh / 2;
3142    if (cy > th) cy = th - 1;
3143
3144    switch (rp->part->cursor_mode)
3145      {
3146       case EDJE_ENTRY_CURSOR_MODE_BEFORE:
3147          cur_type = EVAS_TEXTBLOCK_CURSOR_BEFORE;
3148          break;
3149       case EDJE_ENTRY_CURSOR_MODE_UNDER:
3150       default:
3151          cur_type = EVAS_TEXTBLOCK_CURSOR_UNDER;
3152      }
3153
3154    evas_textblock_cursor_geometry_get(en->sel_end, &sx, &sy, NULL, NULL, NULL, cur_type);
3155    old_cur_pos = evas_textblock_cursor_pos_get(en->cursor);
3156    if (!evas_textblock_cursor_char_coord_set(en->cursor, cx, cy))
3157      {
3158         evas_textblock_cursor_pos_set(en->cursor, old_cur_pos);
3159      }
3160    else if (evas_textblock_cursor_line_geometry_get(en->cursor, NULL, NULL, NULL, NULL) == -1)
3161      {
3162         evas_textblock_cursor_pos_set(en->cursor, old_cur_pos);
3163      }
3164
3165    // by passing
3166    if (evas_textblock_cursor_compare(en->cursor, en->sel_end) >= 0)
3167       en->handler_bypassing = EINA_TRUE;
3168    else
3169       en->handler_bypassing = EINA_FALSE;
3170    //
3171
3172    if (en->select_allow)
3173      {
3174         if (en->had_sel)
3175           {
3176              if (en->select_mod_start)
3177                _sel_preextend(en->cursor, rp->object, en);
3178           }
3179      }
3180    _edje_entry_real_part_configure(rp);
3181    _edje_emit(en->rp->edje, "handler,moving", en->rp->part->name);
3182 }
3183
3184 static void
3185 _edje_entry_end_handler_mouse_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
3186 {
3187    Evas_Event_Mouse_Down *ev = event_info;
3188    Evas_Coord ox, oy, ow, oh;
3189    Evas_Coord lx, ly, lw, lh;
3190    Edje_Real_Part *rp = data;
3191    Entry *en = rp->typedata.text->entry_data;
3192
3193    if (ev->button != 1) return;
3194
3195    _edje_entry_cursor_copy(rp, EDJE_CURSOR_SELECTION_END, EDJE_CURSOR_MAIN);
3196    en->rx = en->sx = ev->canvas.x;
3197    en->ry = en->sy = ev->canvas.y;
3198
3199    evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
3200    edje_object_size_min_calc(obj, &ow, &oh);
3201    evas_textblock_cursor_line_geometry_get(en->cursor, &lx, &ly, &lw, &lh);
3202
3203    en->ox = ox + ow/2 - en->rx;
3204    en->oy = oy - en->ry - lh/2;
3205
3206    en->select_mod_end = EINA_TRUE;
3207    en->selecting = EINA_TRUE;
3208
3209    _edje_emit(en->rp->edje, "handler,move,start", en->rp->part->name);
3210 }
3211
3212 static void
3213 _edje_entry_end_handler_mouse_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
3214 {
3215    Edje_Real_Part *rp = data;
3216    Entry *en = rp->typedata.text->entry_data;
3217
3218    //switch sel_start,end
3219    if (evas_textblock_cursor_compare(en->sel_start, en->sel_end) >= 0)
3220      {
3221         Evas_Textblock_Cursor *tc;
3222         tc = evas_object_textblock_cursor_new(rp->object);
3223         evas_textblock_cursor_copy(en->sel_start, tc);
3224         evas_textblock_cursor_copy(en->sel_end, en->sel_start);
3225         evas_textblock_cursor_copy(tc, en->sel_end);
3226         // first char case
3227         if (evas_textblock_cursor_compare(en->sel_start, en->sel_end) == 0)
3228           {
3229              evas_textblock_cursor_char_next(en->sel_end);
3230           }
3231         evas_textblock_cursor_free(tc);
3232      }
3233    //update handlers
3234    en->handler_bypassing = EINA_FALSE;
3235    _edje_entry_real_part_configure(rp);
3236
3237    _edje_emit(en->rp->edje, "handler,move,end", en->rp->part->name);
3238 }
3239
3240 static void
3241 _edje_entry_end_handler_mouse_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
3242 {
3243    Evas_Event_Mouse_Move *ev = event_info;
3244    Edje_Real_Part *rp = data;
3245    Entry *en = rp->typedata.text->entry_data;
3246    Evas_Coord x, y, tx, ty, tw, th;
3247    Evas_Coord cx, cy;
3248    Evas_Coord lh;
3249    Evas_Textblock_Cursor_Type cur_type;
3250    Evas_Coord sx, sy;
3251    int old_cur_pos;
3252
3253    if (ev->buttons != 1) return;
3254
3255    x = ev->cur.canvas.x;
3256    y = ev->cur.canvas.y;
3257
3258    en->rx += (x - en->sx);
3259    en->ry += (y - en->sy);
3260    en->sx = ev->cur.canvas.x;
3261    en->sy = ev->cur.canvas.y;
3262
3263    evas_object_geometry_get(rp->object, &tx, &ty, NULL, NULL);
3264    evas_object_textblock_size_formatted_get(rp->object, &tw, &th);
3265
3266    cx = en->rx + en->ox - tx;
3267    cy = en->ry + en->oy - ty;
3268
3269    evas_textblock_cursor_line_geometry_get(en->cursor, NULL, NULL, NULL, &lh);
3270    if (cx < 0) cx = 0;
3271    if (cy < lh / 2) cy = lh / 2;
3272    if (cy > th) cy = th - 1;
3273
3274    switch (rp->part->cursor_mode)
3275      {
3276       case EDJE_ENTRY_CURSOR_MODE_BEFORE:
3277          cur_type = EVAS_TEXTBLOCK_CURSOR_BEFORE;
3278          break;
3279       case EDJE_ENTRY_CURSOR_MODE_UNDER:
3280       default:
3281          cur_type = EVAS_TEXTBLOCK_CURSOR_UNDER;
3282      }
3283
3284    evas_textblock_cursor_geometry_get(en->sel_start, &sx, &sy, NULL, NULL, NULL, cur_type);
3285    old_cur_pos = evas_textblock_cursor_pos_get(en->cursor);
3286    if (!evas_textblock_cursor_char_coord_set(en->cursor, cx, cy))
3287      {
3288         evas_textblock_cursor_pos_set(en->cursor, old_cur_pos);
3289      }
3290    else if (evas_textblock_cursor_line_geometry_get(en->cursor, NULL, NULL, NULL, NULL) == -1)
3291      {
3292         evas_textblock_cursor_pos_set(en->cursor, old_cur_pos);
3293      }
3294
3295    // by passing
3296    if (evas_textblock_cursor_compare(en->cursor, en->sel_start) <= 0)
3297       en->handler_bypassing = EINA_TRUE;
3298    else
3299       en->handler_bypassing = EINA_FALSE;
3300    //
3301
3302    if (en->select_allow)
3303      {
3304         if (en->had_sel)
3305           {
3306              if (en->select_mod_end)
3307                _sel_extend(en->cursor, rp->object, en);
3308           }
3309      }
3310    _edje_entry_real_part_configure(rp);
3311    _edje_emit(en->rp->edje, "handler,moving", en->rp->part->name);
3312 }
3313 // TIZEN ONLY - END
3314
3315 static void
3316 _evas_focus_in_cb(void *data, Evas *e, __UNUSED__ void *event_info)
3317 {
3318    Edje *ed = (Edje *)data;
3319
3320    if (evas_focus_get(e) == ed->obj)
3321      {
3322         _edje_focus_in_cb(data, NULL, NULL, NULL);
3323      }
3324 }
3325
3326 static void
3327 _evas_focus_out_cb(void *data, Evas *e, __UNUSED__ void *event_info)
3328 {
3329    Edje *ed = (Edje *)data;
3330
3331    if (evas_focus_get(e) == ed->obj)
3332      {
3333         _edje_focus_out_cb(data, NULL, NULL, NULL);
3334      }
3335 }
3336
3337 /***************************************************************/
3338 void
3339 _edje_entry_init(Edje *ed)
3340 {
3341    if (!ed->has_entries)
3342      return;
3343    if (ed->entries_inited)
3344      return;
3345    ed->entries_inited = EINA_TRUE;
3346
3347    evas_object_event_callback_add(ed->obj, EVAS_CALLBACK_FOCUS_IN, _edje_focus_in_cb, ed);
3348    evas_object_event_callback_add(ed->obj, EVAS_CALLBACK_FOCUS_OUT, _edje_focus_out_cb, ed);
3349    evas_object_event_callback_add(ed->obj, EVAS_CALLBACK_KEY_DOWN, _edje_key_down_cb, ed);
3350    evas_object_event_callback_add(ed->obj, EVAS_CALLBACK_KEY_UP, _edje_key_up_cb, ed);
3351    evas_event_callback_add(ed->base.evas, EVAS_CALLBACK_CANVAS_FOCUS_IN, _evas_focus_in_cb, ed);
3352    evas_event_callback_add(ed->base.evas, EVAS_CALLBACK_CANVAS_FOCUS_OUT, _evas_focus_out_cb, ed);
3353 }
3354
3355 void
3356 _edje_entry_shutdown(Edje *ed)
3357 {
3358    if (!ed->has_entries)
3359      return;
3360    if (!ed->entries_inited)
3361      return;
3362    ed->entries_inited = EINA_FALSE;
3363
3364    evas_object_event_callback_del(ed->obj, EVAS_CALLBACK_FOCUS_IN, _edje_focus_in_cb);
3365    evas_object_event_callback_del(ed->obj, EVAS_CALLBACK_FOCUS_OUT, _edje_focus_out_cb);
3366    evas_object_event_callback_del(ed->obj, EVAS_CALLBACK_KEY_DOWN, _edje_key_down_cb);
3367    evas_object_event_callback_del(ed->obj, EVAS_CALLBACK_KEY_UP, _edje_key_up_cb);
3368    if (evas_event_callback_del_full(ed->base.evas, EVAS_CALLBACK_CANVAS_FOCUS_IN, _evas_focus_in_cb, ed) != ed)
3369      ERR("could not unregister EVAS_CALLBACK_FOCUS_IN");
3370    if (evas_event_callback_del_full(ed->base.evas, EVAS_CALLBACK_CANVAS_FOCUS_OUT, _evas_focus_out_cb, ed) != ed)
3371      ERR("could not unregister EVAS_CALLBACK_FOCUS_OUT");
3372 }
3373
3374 void
3375 _edje_entry_real_part_init(Edje_Real_Part *rp)
3376 {
3377    Entry *en;
3378 #ifdef HAVE_ECORE_IMF
3379    const char *ctx_id;
3380    const Ecore_IMF_Context_Info *ctx_info;
3381 #endif
3382
3383    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
3384        (!rp->typedata.text)) return;
3385    en = calloc(1, sizeof(Entry));
3386    if (!en) return;
3387    rp->typedata.text->entry_data = en;
3388    en->rp = rp;
3389    en->vp_updated = EINA_FALSE;
3390
3391    evas_object_event_callback_add(rp->object, EVAS_CALLBACK_MOVE, _edje_part_move_cb, rp);
3392
3393    evas_object_event_callback_add(rp->object, EVAS_CALLBACK_MOUSE_DOWN, _edje_part_mouse_down_cb, rp);
3394    evas_object_event_callback_add(rp->object, EVAS_CALLBACK_MOUSE_UP, _edje_part_mouse_up_cb, rp);
3395    evas_object_event_callback_add(rp->object, EVAS_CALLBACK_MOUSE_MOVE, _edje_part_mouse_move_cb, rp);
3396
3397    if (rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_DEFAULT)
3398      en->select_allow = EINA_TRUE;
3399
3400    if (rp->part->entry_mode == EDJE_ENTRY_EDIT_MODE_PASSWORD)
3401      {
3402         Edje_Part_Description_Text *txt;
3403
3404         txt = (Edje_Part_Description_Text *)rp->chosen_description;
3405
3406         en->select_allow = EINA_FALSE;
3407         if (txt && edje_string_get(&txt->text.repch))
3408           evas_object_textblock_replace_char_set(rp->object, edje_string_get(&txt->text.repch));
3409         else
3410           evas_object_textblock_replace_char_set(rp->object, "*");
3411      }
3412
3413    en->cursor_bg = edje_object_add(rp->edje->base.evas);
3414    edje_object_file_set(en->cursor_bg, rp->edje->path, rp->part->source3);
3415    evas_object_smart_member_add(en->cursor_bg, rp->edje->obj);
3416    evas_object_stack_below(en->cursor_bg, rp->object);
3417    evas_object_clip_set(en->cursor_bg, evas_object_clip_get(rp->object));
3418    evas_object_pass_events_set(en->cursor_bg, EINA_TRUE);
3419    _edje_subobj_register(en->rp->edje, en->cursor_bg);
3420
3421    en->cursor_fg = edje_object_add(rp->edje->base.evas);
3422    edje_object_file_set(en->cursor_fg, rp->edje->path, rp->part->source4);
3423    evas_object_smart_member_add(en->cursor_fg, rp->edje->obj);
3424    evas_object_stack_above(en->cursor_fg, rp->object);
3425    evas_object_clip_set(en->cursor_fg, evas_object_clip_get(rp->object));
3426    evas_object_pass_events_set(en->cursor_fg, EINA_TRUE);
3427    _edje_subobj_register(en->rp->edje, en->cursor_fg);
3428
3429    /* A proxy to the main cursor. */
3430    if (rp->part->cursor_mode == EDJE_ENTRY_CURSOR_MODE_BEFORE)
3431      {
3432         en->cursor_fg2 = evas_object_image_add(rp->edje->base.evas);
3433         evas_object_image_source_set(en->cursor_fg2, en->cursor_fg);
3434         evas_object_image_fill_set(en->cursor_fg2, 0, 0, 1, 1);
3435         evas_object_smart_member_add(en->cursor_fg2, rp->edje->obj);
3436         evas_object_stack_above(en->cursor_fg2, rp->object);
3437         evas_object_clip_set(en->cursor_fg2, evas_object_clip_get(rp->object));
3438         evas_object_pass_events_set(en->cursor_fg2, EINA_TRUE);
3439         _edje_subobj_register(en->rp->edje, en->cursor_fg2);
3440      }
3441
3442    // TIZEN ONLY - START
3443    //cursor handler
3444    en->cursor_handler_disabled = EINA_FALSE;
3445    en->cursor_handler = NULL;
3446    if (rp->part->source9)
3447      {
3448         en->cursor_handler = edje_object_add(en->rp->edje->base.evas);
3449         edje_object_file_set(en->cursor_handler , en->rp->edje->path, rp->part->source9);
3450
3451         en->rp->edje->subobjs = eina_list_append(en->rp->edje->subobjs, en->cursor_handler );
3452
3453         evas_object_event_callback_add(en->cursor_handler , EVAS_CALLBACK_MOUSE_DOWN, _edje_entry_cursor_handler_mouse_down_cb, en->rp);
3454         evas_object_event_callback_add(en->cursor_handler , EVAS_CALLBACK_MOUSE_UP, _edje_entry_cursor_handler_mouse_up_cb, en->rp);
3455         evas_object_event_callback_add(en->cursor_handler , EVAS_CALLBACK_MOUSE_MOVE, _edje_entry_cursor_handler_mouse_move_cb, en->rp);
3456      }
3457    en->cursor_handler_show = EINA_FALSE;
3458    // TIZEN ONLY - END
3459    en->focused = EINA_FALSE;
3460
3461    evas_object_textblock_legacy_newline_set(rp->object, EINA_TRUE);
3462
3463    if (rp->part->entry_mode >= EDJE_ENTRY_EDIT_MODE_EDITABLE)
3464      {
3465         evas_object_show(en->cursor_bg);
3466         evas_object_show(en->cursor_fg);
3467         evas_object_show(en->cursor_fg2);
3468         en->input_panel_enable = EINA_TRUE;
3469
3470 #ifdef HAVE_ECORE_IMF
3471         ecore_imf_init();
3472
3473         en->commit_cancel = EINA_FALSE;
3474
3475         edje_object_signal_callback_add(rp->edje->obj, "focus,part,in", rp->part->name, _edje_entry_focus_in_cb, rp);
3476         edje_object_signal_callback_add(rp->edje->obj, "focus,part,out", rp->part->name, _edje_entry_focus_out_cb, rp);
3477
3478         ctx_id = ecore_imf_context_default_id_get();
3479         if (ctx_id)
3480           {
3481              ctx_info = ecore_imf_context_info_by_id_get(ctx_id);
3482              if (!ctx_info->canvas_type ||
3483                  strcmp(ctx_info->canvas_type, "evas") == 0)
3484                {
3485                   en->imf_context = ecore_imf_context_add(ctx_id);
3486                }
3487              else
3488                {
3489                   ctx_id = ecore_imf_context_default_id_by_canvas_type_get("evas");
3490                   if (ctx_id)
3491                     {
3492                        en->imf_context = ecore_imf_context_add(ctx_id);
3493                     }
3494                }
3495           }
3496         else
3497           en->imf_context = NULL;
3498
3499         if (!en->imf_context) goto done;
3500
3501         ecore_imf_context_client_window_set
3502            (en->imf_context,
3503                (void *)ecore_evas_window_get
3504                (ecore_evas_ecore_evas_get(rp->edje->base.evas)));
3505         ecore_imf_context_client_canvas_set(en->imf_context, rp->edje->base.evas);
3506
3507         ecore_imf_context_retrieve_surrounding_callback_set(en->imf_context,
3508                                                             _edje_entry_imf_retrieve_surrounding_cb, rp->edje);
3509         ecore_imf_context_event_callback_add(en->imf_context, ECORE_IMF_CALLBACK_COMMIT, _edje_entry_imf_event_commit_cb, rp->edje);
3510         ecore_imf_context_event_callback_add(en->imf_context, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, _edje_entry_imf_event_delete_surrounding_cb, rp->edje);
3511         ecore_imf_context_event_callback_add(en->imf_context, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, _edje_entry_imf_event_preedit_changed_cb, rp->edje);
3512         ecore_imf_context_input_mode_set(en->imf_context,
3513                                          rp->part->entry_mode == EDJE_ENTRY_EDIT_MODE_PASSWORD ?
3514                                          ECORE_IMF_INPUT_MODE_INVISIBLE : ECORE_IMF_INPUT_MODE_FULL);
3515
3516         if (rp->part->entry_mode == EDJE_ENTRY_EDIT_MODE_PASSWORD)
3517           ecore_imf_context_input_panel_language_set(en->imf_context, ECORE_IMF_INPUT_PANEL_LANG_ALPHABET);
3518 #endif
3519      }
3520 #ifdef HAVE_ECORE_IMF
3521 done:
3522 #endif
3523    en->cursor = (Evas_Textblock_Cursor *)evas_object_textblock_cursor_get(rp->object);
3524 }
3525
3526 void
3527 _edje_entry_real_part_shutdown(Edje_Real_Part *rp)
3528 {
3529    Entry *en;
3530    
3531    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
3532        (!rp->typedata.text)) return;
3533    en = rp->typedata.text->entry_data;
3534    if (!en) return;
3535    rp->typedata.text->entry_data = NULL;
3536    _sel_clear(en->cursor, rp->object, en);
3537    _anchors_clear(en->cursor, rp->object, en);
3538 #ifdef HAVE_ECORE_IMF
3539    _preedit_clear(en);
3540 #endif
3541    // TIZEN ONLY - START
3542    rp->edje->subobjs = eina_list_remove(rp->edje->subobjs, en->cursor_bg);
3543    rp->edje->subobjs = eina_list_remove(rp->edje->subobjs, en->cursor_fg);
3544    rp->edje->subobjs = eina_list_remove(rp->edje->subobjs, en->sel_handler_start);
3545    rp->edje->subobjs = eina_list_remove(rp->edje->subobjs, en->sel_handler_end);
3546    rp->edje->subobjs = eina_list_remove(rp->edje->subobjs, en->sel_handler_edge_start);
3547    rp->edje->subobjs = eina_list_remove(rp->edje->subobjs, en->sel_handler_edge_end);
3548    rp->edje->subobjs = eina_list_remove(rp->edje->subobjs, en->cursor_handler);
3549    // TIZEN ONLY - END
3550    evas_object_del(en->cursor_bg);
3551    evas_object_del(en->cursor_fg);
3552    evas_object_del(en->cursor_fg2);
3553
3554    // TIZEN ONLY - START
3555    if (en->sel_handler_start)
3556      {
3557         evas_object_del(en->sel_handler_start);
3558         en->sel_handler_start = NULL;
3559      }
3560    if (en->sel_handler_end)
3561      {
3562         evas_object_del(en->sel_handler_end);
3563         en->sel_handler_end = NULL;
3564      }
3565    if (en->cursor_handler)
3566      {
3567         evas_object_del(en->cursor_handler);
3568         en->cursor_handler = NULL;
3569      }
3570    if (en->sel_handler_edge_start)
3571      {
3572         evas_object_del(en->sel_handler_edge_start);
3573         en->sel_handler_edge_start = NULL;
3574      }
3575    if (en->sel_handler_edge_end)
3576      {
3577         evas_object_del(en->sel_handler_edge_end);
3578         en->sel_handler_edge_end = NULL;
3579      }
3580
3581    if (en->long_press_timer)
3582      {
3583         ecore_timer_del(en->long_press_timer);
3584         en->long_press_timer = NULL;
3585      }
3586    if (en->cursor_handler_click_timer)
3587      {
3588         ecore_timer_del(en->cursor_handler_click_timer);
3589         en->cursor_handler_click_timer = NULL;
3590      }
3591    // TIZEN ONLY - END
3592
3593    if (en->pw_timer)
3594      {
3595         ecore_timer_del(en->pw_timer);
3596         en->pw_timer = NULL;
3597      }
3598
3599 #ifdef HAVE_ECORE_IMF
3600    if (rp->part->entry_mode >= EDJE_ENTRY_EDIT_MODE_EDITABLE)
3601      {
3602         if (en->imf_context)
3603           {
3604              ecore_imf_context_event_callback_del(en->imf_context, ECORE_IMF_CALLBACK_COMMIT, _edje_entry_imf_event_commit_cb);
3605              ecore_imf_context_event_callback_del(en->imf_context, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, _edje_entry_imf_event_delete_surrounding_cb);
3606              ecore_imf_context_event_callback_del(en->imf_context, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, _edje_entry_imf_event_preedit_changed_cb);
3607
3608              ecore_imf_context_del(en->imf_context);
3609              en->imf_context = NULL;
3610           }
3611
3612         edje_object_signal_callback_del(rp->edje->obj, "focus,part,in", rp->part->name, _edje_entry_focus_in_cb);
3613         edje_object_signal_callback_del(rp->edje->obj, "focus,part,out", rp->part->name, _edje_entry_focus_out_cb);
3614         ecore_imf_shutdown();
3615      }
3616 #endif
3617    _compose_seq_reset(en);
3618    
3619    free(en);
3620 }
3621
3622 void
3623 _edje_entry_real_part_configure(Edje_Real_Part *rp)
3624 {
3625    Evas_Coord x, y, w, h, xx, yy, ww, hh, xx2, yy2;
3626    Entry *en;
3627    Evas_Textblock_Cursor_Type cur_type;
3628    Eina_Bool bidi_cursor = EINA_FALSE;
3629    
3630    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
3631        (!rp->typedata.text)) return;
3632    en = rp->typedata.text->entry_data;
3633    if (!en) return;
3634    switch (rp->part->cursor_mode)
3635      {
3636       case EDJE_ENTRY_CURSOR_MODE_BEFORE:
3637          cur_type = EVAS_TEXTBLOCK_CURSOR_BEFORE;
3638          break;
3639       case EDJE_ENTRY_CURSOR_MODE_UNDER:
3640          /* no break for a resaon */
3641       default:
3642          cur_type = EVAS_TEXTBLOCK_CURSOR_UNDER;
3643      }
3644
3645    _sel_update(en->cursor, rp->object, en);
3646    _anchors_update(en->cursor, rp->object, en);
3647    x = y = w = h = -1;
3648    xx = yy = ww = hh = -1;
3649    evas_object_geometry_get(rp->object, &x, &y, &w, &h);
3650    /* For split cursor need to assign return value to bidi_cursor.
3651     * bidi_cursor = evas_textblock_geometry_bidi_get() */
3652    evas_textblock_cursor_geometry_bidi_get(en->cursor, &xx, &yy, &ww, &hh, &xx2, &yy2, NULL, NULL, cur_type);
3653    if (ww < 1) ww = 1;
3654    if (hh < 1) hh = 1;
3655    if (en->cursor_bg)
3656      {
3657         evas_object_move(en->cursor_bg, x + xx, y + yy);
3658         evas_object_resize(en->cursor_bg, ww, hh);
3659      }
3660    if (en->cursor_fg)
3661      {
3662         evas_object_move(en->cursor_fg, x + xx, y + yy);
3663         evas_object_resize(en->cursor_fg, ww, hh);
3664      }
3665
3666    if (en->cursor_fg2)
3667      {
3668         if (bidi_cursor)
3669           {
3670              evas_object_image_fill_set(en->cursor_fg2, 0, 0, ww, hh / 2);
3671              evas_object_move(en->cursor_fg2, x + xx2, y + yy2 + (hh / 2));
3672              evas_object_resize(en->cursor_fg, ww, hh / 2);
3673              evas_object_resize(en->cursor_fg2, ww, hh / 2);
3674
3675              evas_object_show(en->cursor_fg2);
3676           }
3677         else
3678           {
3679              evas_object_hide(en->cursor_fg2);
3680           }
3681      }
3682
3683    if (en->cursor_handler && (!en->cursor_handler_disabled || en->long_press_state == _ENTRY_LONG_PRESSED || en->long_press_state == _ENTRY_LONG_PRESSING))
3684      {
3685         Evas_Coord chh;
3686         Evas_Coord chx, chy;
3687
3688         chx = x + xx;
3689         chy = y + yy + hh;
3690         evas_object_move(en->cursor_handler, chx, chy);
3691         edje_object_size_min_calc(en->cursor_handler, NULL, &chh);
3692         if (en->cursor_handler_show)
3693           {
3694              if (((chx < en->viewport_region.x) || (chy < en->viewport_region.y) ||
3695                   (chx > en->viewport_region.x + en->viewport_region.w) || (chy > en->viewport_region.y + en->viewport_region.h)))
3696                {
3697                   evas_object_hide(en->cursor_handler);
3698                   en->cursor_handler_show = EINA_FALSE;
3699                }
3700              else if (en->focused)
3701                {
3702                   if (chy + chh > en->layout_region.y + en->layout_region.h)
3703                     {
3704                        evas_object_move(en->cursor_handler, x + xx, y + yy);
3705                        edje_object_signal_emit(en->cursor_handler, "edje,cursor,handle,top", "edje");
3706                     }
3707                   else
3708                     {
3709                        edje_object_signal_emit(en->cursor_handler, "edje,cursor,handle,show", "edje");
3710                     }
3711                }
3712           }
3713      }
3714 }
3715
3716 const char *
3717 _edje_entry_selection_get(Edje_Real_Part *rp)
3718 {
3719    Entry *en;
3720    
3721    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
3722        (!rp->typedata.text)) return NULL;
3723    en = rp->typedata.text->entry_data;
3724    if (!en) return NULL;
3725    // get selection - convert to markup
3726    if ((!en->selection) && (en->have_selection))
3727      en->selection = evas_textblock_cursor_range_text_get
3728         (en->sel_start, en->sel_end, EVAS_TEXTBLOCK_TEXT_MARKUP);
3729    return en->selection;
3730 }
3731
3732 const char *
3733 _edje_entry_text_get(Edje_Real_Part *rp)
3734 {
3735    Entry *en;
3736    
3737    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
3738        (!rp->typedata.text)) return NULL;
3739    en = rp->typedata.text->entry_data;
3740    if (!en) return NULL;
3741    // get text - convert to markup
3742    return evas_object_textblock_text_markup_get(rp->object);
3743 }
3744
3745 void
3746 _edje_entry_text_markup_set(Edje_Real_Part *rp, const char *text)
3747 {
3748    Entry *en;
3749    
3750    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
3751        (!rp->typedata.text)) return;
3752    en = rp->typedata.text->entry_data;
3753    if (!en) return;
3754    _edje_entry_imf_context_reset(rp);
3755    // set text as markup
3756    _sel_clear(en->cursor, rp->object, en);
3757    evas_object_textblock_text_markup_set(rp->object, text);
3758    _edje_entry_set_cursor_start(rp);
3759
3760    _anchors_get(en->cursor, rp->object, en);
3761    _edje_emit(rp->edje, "entry,changed", rp->part->name);
3762
3763    // TIZEN ONLY(130129) : Currently, for freezing cursor movement.
3764    if (!en->freeze)
3765      {
3766         _edje_entry_imf_cursor_info_set(en);
3767         _edje_entry_real_part_configure(rp);
3768      }
3769    //
3770
3771 #if 0
3772    /* Don't emit cursor changed cause it didn't. It's just init to 0. */
3773    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
3774 #endif
3775 }
3776
3777 void
3778 _edje_entry_text_markup_append(Edje_Real_Part *rp, const char *text)
3779 {
3780    Entry *en;
3781    
3782    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
3783        (!rp->typedata.text)) return;
3784    en = rp->typedata.text->entry_data;
3785    Evas_Textblock_Cursor *end_cur;
3786    if (!en) return;
3787    end_cur = evas_object_textblock_cursor_new(rp->object);
3788    evas_textblock_cursor_paragraph_last(end_cur);
3789
3790    _text_filter_markup_prepend(en, end_cur, text);
3791    evas_textblock_cursor_free(end_cur);
3792
3793    /* We are updating according to the real cursor on purpose */
3794    _anchors_get(en->cursor, rp->object, en);
3795    _edje_emit(rp->edje, "entry,changed", rp->part->name);
3796
3797    _edje_entry_real_part_configure(rp);
3798 }
3799
3800 void
3801 _edje_entry_text_markup_insert(Edje_Real_Part *rp, const char *text)
3802 {
3803    Entry *en;
3804    
3805    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
3806        (!rp->typedata.text)) return;
3807    en = rp->typedata.text->entry_data;
3808    if (!en) return;
3809    _edje_entry_imf_context_reset(rp);
3810
3811    // prepend markup @ cursor pos
3812    if (en->have_selection)
3813      _range_del(en->cursor, rp->object, en);
3814    //xx
3815 //   evas_object_textblock_text_markup_prepend(en->cursor, text);
3816    _text_filter_markup_prepend(en, en->cursor, text);
3817    _anchors_get(en->cursor, rp->object, en);
3818    // TIZEN ONLY - START
3819    if (en->cursor_handler_show)
3820      {
3821         evas_object_hide(en->cursor_handler);
3822         en->cursor_handler_show = EINA_FALSE;
3823      }
3824    // TIZEN ONLY - END
3825    _edje_emit(rp->edje, "entry,changed", rp->part->name);
3826    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
3827
3828    _edje_entry_imf_cursor_info_set(en);
3829    _edje_entry_real_part_configure(rp);
3830 }
3831
3832 void
3833 _edje_entry_set_cursor_start(Edje_Real_Part *rp)
3834 {
3835    Entry *en;
3836    
3837    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
3838        (!rp->typedata.text)) return;
3839    en = rp->typedata.text->entry_data;
3840    if (!en) return;
3841    _curs_start(en->cursor, rp->object, en);
3842
3843    // TIZEN ONLY(130129) : Currently, for freezing cursor movement.
3844    if (!en->freeze)
3845       _edje_entry_imf_cursor_info_set(en);
3846 }
3847
3848 void
3849 _edje_entry_set_cursor_end(Edje_Real_Part *rp)
3850 {
3851    Entry *en;
3852    
3853    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
3854        (!rp->typedata.text)) return;
3855    en = rp->typedata.text->entry_data;
3856    if (!en) return;
3857    _curs_end(en->cursor, rp->object, en);
3858
3859    _edje_entry_imf_cursor_info_set(en);
3860 }
3861
3862 void
3863 _edje_entry_select_none(Edje_Real_Part *rp)
3864 {
3865    Entry *en;
3866    
3867    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
3868        (!rp->typedata.text)) return;
3869    en = rp->typedata.text->entry_data;
3870    if (!en) return;
3871    _sel_clear(en->cursor, rp->object, en);
3872 }
3873
3874 void
3875 _edje_entry_select_all(Edje_Real_Part *rp)
3876 {
3877    Entry *en;
3878    
3879    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
3880        (!rp->typedata.text)) return;
3881    en = rp->typedata.text->entry_data;
3882    if (!en) return;
3883
3884    _edje_entry_imf_context_reset(rp);
3885
3886    _sel_clear(en->cursor, rp->object, en);
3887    _curs_start(en->cursor, rp->object, en);
3888    _sel_enable(en->cursor, rp->object, en);
3889    _sel_start(en->cursor, rp->object, en);
3890    _curs_end(en->cursor, rp->object, en);
3891    _sel_extend(en->cursor, rp->object, en);
3892
3893    _edje_entry_real_part_configure(rp);
3894
3895    // TIZEN ONLY - START
3896    en->select_allow = EINA_TRUE;
3897    en->had_sel = EINA_TRUE;
3898
3899    _edje_emit(en->rp->edje, "selection,end", en->rp->part->name);
3900    // TIZEN ONLY - END
3901 }
3902
3903 void
3904 _edje_entry_select_begin(Edje_Real_Part *rp)
3905 {
3906    Entry *en;
3907    
3908    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
3909        (!rp->typedata.text)) return;
3910    en = rp->typedata.text->entry_data;
3911    if (!en) return;
3912
3913    _sel_clear(en->cursor, rp->object, en);
3914    _sel_enable(en->cursor, rp->object, en);
3915    _sel_start(en->cursor, rp->object, en);
3916    _sel_extend(en->cursor, rp->object, en);
3917
3918    _edje_entry_real_part_configure(rp);
3919 }
3920
3921 void
3922 _edje_entry_select_extend(Edje_Real_Part *rp)
3923 {
3924    Entry *en;
3925    
3926    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
3927        (!rp->typedata.text)) return;
3928    en = rp->typedata.text->entry_data;
3929    if (!en) return;
3930    _sel_extend(en->cursor, rp->object, en);
3931
3932    _edje_entry_real_part_configure(rp);
3933 }
3934
3935 const Eina_List *
3936 _edje_entry_anchor_geometry_get(Edje_Real_Part *rp, const char *anchor)
3937 {
3938    Entry *en;
3939    Eina_List *l;
3940    Anchor *an;
3941
3942    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
3943        (!rp->typedata.text)) return NULL;
3944    en = rp->typedata.text->entry_data;
3945    if (!en) return NULL;
3946    EINA_LIST_FOREACH(en->anchors, l, an)
3947      {
3948         if (an->item) continue;
3949         if (!strcmp(anchor, an->name))
3950           return an->sel;
3951      }
3952    return NULL;
3953 }
3954
3955 const Eina_List *
3956 _edje_entry_anchors_list(Edje_Real_Part *rp)
3957 {
3958    Entry *en;
3959    Eina_List *l, *anchors = NULL;
3960    Anchor *an;
3961
3962    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
3963        (!rp->typedata.text)) return NULL;
3964    en = rp->typedata.text->entry_data;
3965    if (!en) return NULL;
3966    if (!en->anchorlist)
3967      {
3968         EINA_LIST_FOREACH(en->anchors, l, an)
3969           {
3970              const char *n = an->name;
3971              if (an->item) continue;
3972              if (!n) n = "";
3973              anchors = eina_list_append(anchors, strdup(n));
3974           }
3975         en->anchorlist = anchors;
3976      }
3977    return en->anchorlist;
3978 }
3979
3980 Eina_Bool
3981 _edje_entry_item_geometry_get(Edje_Real_Part *rp, const char *item, Evas_Coord *cx, Evas_Coord *cy, Evas_Coord *cw, Evas_Coord *ch)
3982 {
3983    Entry *en;
3984    Eina_List *l;
3985    Anchor *an;
3986
3987    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
3988        (!rp->typedata.text)) return EINA_FALSE;
3989    en = rp->typedata.text->entry_data;
3990    if (!en) return EINA_FALSE;
3991    EINA_LIST_FOREACH(en->anchors, l, an)
3992      {
3993         if (an->item) continue;
3994         if (!strcmp(item, an->name))
3995           {
3996              evas_textblock_cursor_format_item_geometry_get(an->start, cx, cy, cw, ch);
3997              return EINA_TRUE;
3998           }
3999      }
4000    return EINA_FALSE;
4001 }
4002
4003 const Eina_List *
4004 _edje_entry_items_list(Edje_Real_Part *rp)
4005 {
4006    Entry *en;
4007    Eina_List *l, *items = NULL;
4008    Anchor *an;
4009
4010    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4011        (!rp->typedata.text)) return NULL;
4012    en = rp->typedata.text->entry_data;
4013    if (!en) return NULL;
4014    if (!en->itemlist)
4015      {
4016         EINA_LIST_FOREACH(en->anchors, l, an)
4017           {
4018              const char *n = an->name;
4019              if (an->item) continue;
4020              if (!n) n = "";
4021              items = eina_list_append(items, strdup(n));
4022           }
4023         en->itemlist = items;
4024      }
4025    return en->itemlist;
4026 }
4027
4028 // TIZEN ONLY - START
4029 void
4030 _edje_entry_layout_region_set(Edje_Real_Part *rp, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
4031 {
4032    Entry *en;
4033
4034    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4035        (!rp->typedata.text)) return;
4036    en = rp->typedata.text->entry_data;
4037    if (!en) return;
4038
4039    en->layout_region.x = x;
4040    en->layout_region.y = y;
4041    en->layout_region.w = w;
4042    en->layout_region.h = h;
4043    _sel_update(en->cursor, rp->object, en);
4044 }
4045
4046 void
4047 _edje_entry_viewport_region_set(Edje_Real_Part *rp, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
4048 {
4049    Entry *en;
4050    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4051        (!rp->typedata.text)) return;
4052    en = rp->typedata.text->entry_data;
4053    if (!en) return;
4054
4055    en->viewport_region.x = x;
4056    en->viewport_region.y = y;
4057    en->viewport_region.w = w;
4058    en->viewport_region.h = h;
4059    en->vp_updated = EINA_TRUE;
4060    _sel_update(en->cursor, rp->object, en);
4061 }
4062
4063 void
4064 _edje_entry_selection_handler_geometry_get(Edje_Real_Part *rp, Edje_Selection_Handler type, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
4065 {
4066    Entry *en;
4067    Evas_Coord ex, ey, hx, hy, edx, edy, edw, edh;
4068    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4069        (!rp->typedata.text)) return;
4070    en = rp->typedata.text->entry_data;
4071    if (!en) return;
4072
4073    evas_object_geometry_get(rp->object, &ex, &ey, NULL, NULL);
4074    switch (type)
4075      {
4076       case EDJE_SELECTION_HANDLER_START:
4077          if (en->sel_handler_start)
4078            {
4079               evas_object_geometry_get(en->sel_handler_start, &hx, &hy, NULL, NULL);
4080               edje_object_part_geometry_get(en->sel_handler_start, "handle", &edx, &edy, &edw, &edh);
4081               hx = hx - ex + edx;
4082               hy = hy - ey + edy;
4083            }
4084          break;
4085       case EDJE_SELECTION_HANDLER_END:
4086          if (en->sel_handler_end)
4087            {
4088               evas_object_geometry_get(en->sel_handler_end, &hx, &hy, NULL, NULL);
4089               edje_object_part_geometry_get(en->sel_handler_end, "handle", &edx, &edy, &edw, &edh);
4090               hx = hx - ex + edx;
4091               hy = hy - ey + edy;
4092            }
4093          break;
4094       default:
4095          break;
4096      }
4097
4098    if (x) *x = hx;
4099    if (y) *y = hy;
4100    if (w) *w = edw;
4101    if (h) *h = edh;
4102 }
4103
4104 Eina_Bool
4105 _edje_entry_cursor_handler_disabled_get(Edje_Real_Part *rp)
4106 {
4107    Entry *en;
4108    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4109        (!rp->typedata.text)) return EINA_FALSE;
4110    en = rp->typedata.text->entry_data;
4111    if (!en) return EINA_FALSE;
4112    return en->cursor_handler_disabled;
4113 }
4114
4115 void
4116 _edje_entry_cursor_handler_disabled_set(Edje_Real_Part *rp, Eina_Bool disabled)
4117 {
4118    Entry *en;
4119    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4120        (!rp->typedata.text)) return;
4121    en = rp->typedata.text->entry_data;
4122    if (!en) return;
4123
4124    en->cursor_handler_disabled = disabled;
4125 }
4126 // TIZEN ONLY - END
4127
4128 void
4129 _edje_entry_cursor_geometry_get(Edje_Real_Part *rp, Evas_Coord *cx, Evas_Coord *cy, Evas_Coord *cw, Evas_Coord *ch)
4130 {
4131    Evas_Coord x, y, w, h, xx, yy, ww, hh;
4132    Entry *en;
4133    Evas_Textblock_Cursor_Type cur_type;
4134    
4135    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4136        (!rp->typedata.text)) return;
4137    en = rp->typedata.text->entry_data;
4138    if (!en) return;
4139    switch (rp->part->cursor_mode)
4140      {
4141       case EDJE_ENTRY_CURSOR_MODE_BEFORE:
4142          cur_type = EVAS_TEXTBLOCK_CURSOR_BEFORE;
4143          break;
4144       case EDJE_ENTRY_CURSOR_MODE_UNDER:
4145          /* no break for a resaon */
4146       default:
4147          cur_type = EVAS_TEXTBLOCK_CURSOR_UNDER;
4148      }
4149
4150    x = y = w = h = -1;
4151    xx = yy = ww = hh = -1;
4152    evas_object_geometry_get(rp->object, &x, &y, &w, &h);
4153    evas_textblock_cursor_geometry_get(en->cursor, &xx, &yy, &ww, &hh, NULL, cur_type);
4154    if (ww < 1) ww = 1;
4155    if (rp->part->cursor_mode == EDJE_ENTRY_CURSOR_MODE_BEFORE)
4156      edje_object_size_min_restricted_calc(en->cursor_fg, &ww, NULL, ww, 0);
4157    if (hh < 1) hh = 1;
4158    if (cx) *cx = x + xx;
4159    if (cy) *cy = y + yy;
4160    if (cw) *cw = ww;
4161    if (ch) *ch = hh;
4162 }
4163
4164 void
4165 _edje_entry_user_insert(Edje_Real_Part *rp, const char *text)
4166 {
4167    Entry *en;
4168    Edje_Entry_Change_Info *info;
4169
4170    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4171        (!rp->typedata.text)) return;
4172    en = rp->typedata.text->entry_data;
4173    if (!en) return;
4174    info = calloc(1, sizeof(*info));
4175    if (!info) return;
4176    info->insert = EINA_TRUE;
4177    info->change.insert.plain_length = 1;
4178    info->change.insert.content = eina_stringshare_add(text);
4179      {
4180         char *tmp;
4181         tmp = evas_textblock_text_markup_to_utf8(rp->object,
4182                                                  info->change.insert.content);
4183         info->change.insert.plain_length = eina_unicode_utf8_get_len(tmp);
4184         free(tmp);
4185      }
4186
4187    if (en->have_selection)
4188      {
4189         _range_del_emit(rp->edje, en->cursor, rp->object, en);
4190         info->merge = EINA_TRUE;
4191      }
4192    info->change.insert.pos = evas_textblock_cursor_pos_get(en->cursor);
4193    _text_filter_markup_prepend(en, en->cursor, text);
4194    _anchors_get(en->cursor, rp->object, en);
4195    // TIZEN ONLY - START
4196    if (en->cursor_handler_show)
4197      {
4198         evas_object_hide(en->cursor_handler);
4199         en->cursor_handler_show = EINA_FALSE;
4200      }
4201    // TIZEN ONLY - END
4202    _edje_emit(rp->edje, "entry,changed", rp->part->name);
4203    _edje_emit_full(rp->edje, "entry,changed,user", rp->part->name,
4204                    info, _free_entry_change_info);
4205    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
4206
4207    _edje_entry_imf_cursor_info_set(en);
4208    _edje_entry_real_part_configure(rp);
4209 }
4210
4211 void
4212 _edje_entry_select_allow_set(Edje_Real_Part *rp, Eina_Bool allow)
4213 {
4214    Entry *en;
4215    
4216    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4217        (!rp->typedata.text)) return;
4218    en = rp->typedata.text->entry_data;
4219    if (!en) return;
4220    if (rp->part->select_mode == EDJE_ENTRY_SELECTION_MODE_DEFAULT)
4221      return;
4222    en->select_allow = allow;
4223 }
4224
4225 Eina_Bool
4226 _edje_entry_select_allow_get(const Edje_Real_Part *rp)
4227 {
4228    Entry *en;
4229    
4230    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4231        (!rp->typedata.text)) return EINA_FALSE;
4232    en = rp->typedata.text->entry_data;
4233    if (!en) return EINA_FALSE;
4234    return en->select_allow;
4235 }
4236
4237 void
4238 _edje_entry_select_abort(Edje_Real_Part *rp)
4239 {
4240    Entry *en;
4241    
4242    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4243        (!rp->typedata.text)) return;
4244    en = rp->typedata.text->entry_data;
4245    if (!en) return;
4246    if (en->selecting)
4247      {
4248         en->selecting = EINA_FALSE;
4249
4250         _edje_entry_imf_context_reset(rp);
4251         _edje_entry_imf_cursor_info_set(en);
4252         _edje_entry_real_part_configure(rp);
4253      }
4254 }
4255
4256 // TIZEN ONLY - START
4257 Eina_Bool
4258 _edje_entry_selection_geometry_get(Edje_Real_Part *rp, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
4259 {
4260    Entry *en = rp->typedata.text->entry_data;
4261    if (!en || !en->have_selection || !en->sel)
4262      return EINA_FALSE;
4263
4264    Sel *sel;
4265    Eina_List *l;
4266    Evas_Textblock_Rectangle rect;
4267    Evas_Coord tx, ty, tw, th;
4268
4269    l = en->sel;
4270    if (!l) return EINA_FALSE;
4271    sel = eina_list_data_get(l);
4272    if (!sel) return EINA_FALSE;
4273    rect = sel->rect;
4274    ty = rect.y;
4275    tw = rect.w;
4276
4277    l = eina_list_last(en->sel);
4278    if (!l) return EINA_FALSE;
4279    sel = eina_list_data_get(l);
4280    if (!sel) return EINA_FALSE;
4281    rect = sel->rect;
4282
4283    tx = rect.x;
4284    th = rect.y - ty + rect.h;
4285
4286    EINA_LIST_FOREACH(en->sel, l, sel)
4287      {
4288         if (sel)
4289           {
4290              if (tw < sel->rect.w) tw = sel->rect.w;
4291              if (sel->rect.x < tx) tx = sel->rect.x;
4292           }
4293      }
4294
4295    Evas_Coord vx, vy;
4296    evas_object_geometry_get(rp->object, &vx, &vy, NULL, NULL);
4297    tx += vx;
4298    ty += vy;
4299
4300    if (x) *x = tx;
4301    if (y) *y = ty;
4302    if (w) *w = tw;
4303    if (h) *h = th;
4304
4305    return EINA_TRUE;
4306 }
4307 // TIZEN ONLY - END
4308
4309 void *
4310 _edje_entry_imf_context_get(Edje_Real_Part *rp)
4311 {
4312    Entry *en;
4313    
4314    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4315        (!rp->typedata.text)) return NULL;
4316    en = rp->typedata.text->entry_data;
4317    if (!en) return NULL;
4318
4319 #ifdef HAVE_ECORE_IMF
4320    return en->imf_context;
4321 #else
4322    return NULL;
4323 #endif
4324 }
4325
4326 void
4327 _edje_entry_autocapital_type_set(Edje_Real_Part *rp, Edje_Text_Autocapital_Type autocapital_type)
4328 {
4329    Entry *en;
4330    
4331    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4332        (!rp->typedata.text)) return;
4333    en = rp->typedata.text->entry_data;
4334    if (!en) return;
4335
4336    if (rp->part->entry_mode == EDJE_ENTRY_EDIT_MODE_PASSWORD)
4337      autocapital_type = EDJE_TEXT_AUTOCAPITAL_TYPE_NONE;
4338
4339 #ifdef HAVE_ECORE_IMF
4340    if (en->imf_context)
4341      ecore_imf_context_autocapital_type_set(en->imf_context, autocapital_type);
4342 #endif
4343 }
4344
4345 Edje_Text_Autocapital_Type
4346 _edje_entry_autocapital_type_get(Edje_Real_Part *rp)
4347 {
4348    Entry *en;
4349    
4350    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4351        (!rp->typedata.text)) return EDJE_TEXT_AUTOCAPITAL_TYPE_NONE;
4352    en = rp->typedata.text->entry_data;
4353    if (!en) return EDJE_TEXT_AUTOCAPITAL_TYPE_NONE;
4354
4355 #ifdef HAVE_ECORE_IMF
4356    if (en->imf_context)
4357      return ecore_imf_context_autocapital_type_get(en->imf_context);
4358 #endif
4359
4360    return EDJE_TEXT_AUTOCAPITAL_TYPE_NONE;
4361 }
4362
4363 void
4364 _edje_entry_prediction_allow_set(Edje_Real_Part *rp, Eina_Bool prediction)
4365 {
4366    Entry *en;
4367    
4368    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4369        (!rp->typedata.text)) return;
4370    en = rp->typedata.text->entry_data;
4371    if (!en) return;
4372    en->prediction_allow = prediction;
4373 #ifdef HAVE_ECORE_IMF
4374    if (en->imf_context)
4375      ecore_imf_context_prediction_allow_set(en->imf_context, prediction);
4376 #endif
4377 }
4378
4379 Eina_Bool
4380 _edje_entry_prediction_allow_get(Edje_Real_Part *rp)
4381 {
4382    Entry *en;
4383    
4384    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4385        (!rp->typedata.text)) return EINA_FALSE;
4386    en = rp->typedata.text->entry_data;
4387    if (!en) return EINA_FALSE;
4388    return en->prediction_allow;
4389 }
4390
4391 void
4392 _edje_entry_input_panel_enabled_set(Edje_Real_Part *rp, Eina_Bool enabled)
4393 {
4394    Entry *en;
4395    
4396    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4397        (!rp->typedata.text)) return;
4398    en = rp->typedata.text->entry_data;
4399    if (!en) return;
4400    en->input_panel_enable = enabled;
4401 #ifdef HAVE_ECORE_IMF
4402    if (en->imf_context)
4403      ecore_imf_context_input_panel_enabled_set(en->imf_context, enabled);
4404 #endif
4405 }
4406
4407 Eina_Bool
4408 _edje_entry_input_panel_enabled_get(Edje_Real_Part *rp)
4409 {
4410    Entry *en;
4411    
4412    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4413        (!rp->typedata.text)) return EINA_FALSE;
4414    en = rp->typedata.text->entry_data;
4415    if (!en) return EINA_FALSE;
4416    return en->input_panel_enable;
4417 }
4418
4419 void
4420 _edje_entry_input_panel_show(Edje_Real_Part *rp)
4421 {
4422    Entry *en;
4423    
4424    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4425        (!rp->typedata.text)) return;
4426    en = rp->typedata.text->entry_data;
4427    if (!en) return;
4428 #ifdef HAVE_ECORE_IMF
4429    if (en->imf_context)
4430      ecore_imf_context_input_panel_show(en->imf_context);
4431 #endif
4432 }
4433
4434 void
4435 _edje_entry_input_panel_hide(Edje_Real_Part *rp)
4436 {
4437    Entry *en;
4438    
4439    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4440        (!rp->typedata.text)) return;
4441    en = rp->typedata.text->entry_data;
4442    if (!en) return;
4443 #ifdef HAVE_ECORE_IMF
4444    if (en->imf_context)
4445      ecore_imf_context_input_panel_hide(en->imf_context);
4446 #endif
4447 }
4448
4449 void
4450 _edje_entry_input_panel_language_set(Edje_Real_Part *rp, Edje_Input_Panel_Lang lang)
4451 {
4452    Entry *en;
4453    
4454    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4455        (!rp->typedata.text)) return;
4456    en = rp->typedata.text->entry_data;
4457    if (!en) return;
4458    en->input_panel_lang = lang;
4459 #ifdef HAVE_ECORE_IMF
4460    if (en->imf_context)
4461      ecore_imf_context_input_panel_language_set(en->imf_context, lang);
4462 #endif
4463 }
4464
4465 Edje_Input_Panel_Lang
4466 _edje_entry_input_panel_language_get(Edje_Real_Part *rp)
4467 {
4468    Entry *en;
4469    
4470    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4471        (!rp->typedata.text)) return EDJE_INPUT_PANEL_LANG_AUTOMATIC;
4472    en = rp->typedata.text->entry_data;
4473    if (!en) return EDJE_INPUT_PANEL_LANG_AUTOMATIC;
4474    return en->input_panel_lang;
4475 }
4476
4477 #ifdef HAVE_ECORE_IMF
4478 void
4479 _edje_entry_input_panel_imdata_set(Edje_Real_Part *rp, const void *data, int len)
4480 #else
4481 void
4482 _edje_entry_input_panel_imdata_set(Edje_Real_Part *rp, const void *data __UNUSED__, int len __UNUSED__)
4483 #endif
4484 {
4485    Entry *en;
4486    
4487    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4488        (!rp->typedata.text)) return;
4489    en = rp->typedata.text->entry_data;
4490    if (!en) return;
4491 #ifdef HAVE_ECORE_IMF
4492    if (en->imf_context)
4493      ecore_imf_context_input_panel_imdata_set(en->imf_context, data, len);
4494 #endif
4495 }
4496
4497 #ifdef HAVE_ECORE_IMF
4498 void
4499 _edje_entry_input_panel_imdata_get(Edje_Real_Part *rp, void *data, int *len)
4500 #else
4501 void
4502 _edje_entry_input_panel_imdata_get(Edje_Real_Part *rp, void *data __UNUSED__, int *len __UNUSED__)
4503 #endif
4504 {
4505    Entry *en;
4506    
4507    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4508        (!rp->typedata.text)) return;
4509    en = rp->typedata.text->entry_data;
4510    if (!en) return;
4511 #ifdef HAVE_ECORE_IMF
4512    if (en->imf_context)
4513      ecore_imf_context_input_panel_imdata_get(en->imf_context, data, len);
4514 #endif
4515 }
4516
4517 #ifdef HAVE_ECORE_IMF
4518 void
4519 _edje_entry_input_panel_return_key_type_set(Edje_Real_Part *rp, Edje_Input_Panel_Return_Key_Type return_key_type)
4520 #else
4521 void
4522 _edje_entry_input_panel_return_key_type_set(Edje_Real_Part *rp, Edje_Input_Panel_Return_Key_Type return_key_type __UNUSED__)
4523 #endif
4524 {
4525    Entry *en;
4526    
4527    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4528        (!rp->typedata.text)) return;
4529    en = rp->typedata.text->entry_data;
4530    if (!en) return;
4531 #ifdef HAVE_ECORE_IMF
4532    if (en->imf_context)
4533      ecore_imf_context_input_panel_return_key_type_set(en->imf_context, return_key_type);
4534 #endif
4535 }
4536
4537 Edje_Input_Panel_Return_Key_Type
4538 _edje_entry_input_panel_return_key_type_get(Edje_Real_Part *rp)
4539 {
4540    Entry *en;
4541    
4542    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4543        (!rp->typedata.text)) return EDJE_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT;
4544    en = rp->typedata.text->entry_data;
4545    if (!en) return EDJE_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT;
4546 #ifdef HAVE_ECORE_IMF
4547    if (en->imf_context)
4548      return ecore_imf_context_input_panel_return_key_type_get(en->imf_context);
4549 #endif
4550    return EDJE_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT;
4551 }
4552
4553 #ifdef HAVE_ECORE_IMF
4554 void
4555 _edje_entry_input_panel_return_key_disabled_set(Edje_Real_Part *rp, Eina_Bool disabled)
4556 #else
4557 void
4558 _edje_entry_input_panel_return_key_disabled_set(Edje_Real_Part *rp, Eina_Bool disabled __UNUSED__)
4559 #endif
4560 {
4561    Entry *en;
4562    
4563    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4564        (!rp->typedata.text)) return;
4565    en = rp->typedata.text->entry_data;
4566    if (!en) return;
4567 #ifdef HAVE_ECORE_IMF
4568    if (en->imf_context)
4569      ecore_imf_context_input_panel_return_key_disabled_set(en->imf_context, disabled);
4570 #endif
4571 }
4572
4573 Eina_Bool
4574 _edje_entry_input_panel_return_key_disabled_get(Edje_Real_Part *rp)
4575 {
4576    Entry *en;
4577    
4578    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4579        (!rp->typedata.text)) return EINA_FALSE;
4580    en = rp->typedata.text->entry_data;
4581    if (!en) return EINA_FALSE;
4582 #ifdef HAVE_ECORE_IMF
4583    if (en->imf_context)
4584      return ecore_imf_context_input_panel_return_key_disabled_get(en->imf_context);
4585 #endif
4586    return EINA_FALSE;
4587 }
4588
4589 static Evas_Textblock_Cursor *
4590 _cursor_get(Edje_Real_Part *rp, Edje_Cursor cur)
4591 {
4592    Entry *en;
4593    
4594    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4595        (!rp->typedata.text)) return NULL;
4596    en = rp->typedata.text->entry_data;
4597    if (!en) return NULL;
4598    switch (cur)
4599      {
4600       case EDJE_CURSOR_MAIN:
4601          return en->cursor;
4602       case EDJE_CURSOR_SELECTION_BEGIN:
4603          return en->sel_start;
4604       case EDJE_CURSOR_SELECTION_END:
4605          return en->sel_end;
4606       case EDJE_CURSOR_PREEDIT_START:
4607          if (!en->preedit_start)
4608            en->preedit_start = evas_object_textblock_cursor_new(rp->object);
4609          return en->preedit_start;
4610       case EDJE_CURSOR_PREEDIT_END:
4611          if (!en->preedit_end)
4612            en->preedit_end = evas_object_textblock_cursor_new(rp->object);
4613          return en->preedit_end;
4614       case EDJE_CURSOR_USER:
4615          if (!en->cursor_user)
4616            en->cursor_user = evas_object_textblock_cursor_new(rp->object);
4617          return en->cursor_user;
4618       case EDJE_CURSOR_USER_EXTRA:
4619          if (!en->cursor_user_extra)
4620            en->cursor_user_extra = evas_object_textblock_cursor_new(rp->object);
4621          return en->cursor_user_extra;
4622       default:
4623          break;
4624      }
4625    return NULL;
4626 }
4627
4628 Eina_Bool
4629 _edje_entry_cursor_next(Edje_Real_Part *rp, Edje_Cursor cur)
4630 {
4631    Entry *en;
4632    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
4633    
4634    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4635        (!rp->typedata.text)) return EINA_FALSE;
4636    en = rp->typedata.text->entry_data;
4637    if (!en) return EINA_FALSE;
4638    
4639    if (!c) return EINA_FALSE;
4640
4641    _edje_entry_imf_context_reset(rp);
4642
4643    if (!evas_textblock_cursor_char_next(c))
4644      {
4645         return EINA_FALSE;
4646      }
4647    _sel_update(c, rp->object, rp->typedata.text->entry_data);
4648    _edje_entry_imf_cursor_info_set(en);
4649
4650    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
4651    _edje_entry_real_part_configure(rp);
4652    return EINA_TRUE;
4653 }
4654
4655 Eina_Bool
4656 _edje_entry_cursor_prev(Edje_Real_Part *rp, Edje_Cursor cur)
4657 {
4658    Entry *en;
4659    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
4660    
4661    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4662        (!rp->typedata.text)) return EINA_FALSE;
4663    en = rp->typedata.text->entry_data;
4664    if (!en) return EINA_FALSE;
4665    if (!c) return EINA_FALSE;
4666
4667    _edje_entry_imf_context_reset(rp);
4668
4669    if (!evas_textblock_cursor_char_prev(c))
4670      {
4671         if (evas_textblock_cursor_paragraph_prev(c)) goto ok;
4672         else return EINA_FALSE;
4673      }
4674 ok:
4675    _sel_update(c, rp->object, rp->typedata.text->entry_data);
4676
4677    _edje_entry_imf_cursor_info_set(en);
4678
4679    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
4680    _edje_entry_real_part_configure(rp);
4681    return EINA_TRUE;
4682 }
4683
4684 Eina_Bool
4685 _edje_entry_cursor_up(Edje_Real_Part *rp, Edje_Cursor cur)
4686 {
4687    Entry *en;
4688    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
4689    Evas_Coord lx, ly, lw, lh, cx, cy, cw, ch;
4690    int ln;
4691    
4692    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4693        (!rp->typedata.text)) return EINA_FALSE;
4694    en = rp->typedata.text->entry_data;
4695    if (!en) return EINA_FALSE;
4696    if (!c) return EINA_FALSE;
4697
4698    _edje_entry_imf_context_reset(rp);
4699
4700    ln = evas_textblock_cursor_line_geometry_get(c, NULL, NULL, NULL, NULL);
4701    ln--;
4702    if (ln < 0) return EINA_FALSE;
4703    if (!evas_object_textblock_line_number_geometry_get(rp->object, ln,
4704                                                        &lx, &ly, &lw, &lh))
4705      return EINA_FALSE;
4706    evas_textblock_cursor_char_geometry_get(c, &cx, &cy, &cw, &ch);
4707    if (!evas_textblock_cursor_char_coord_set(c, cx, ly + (lh / 2)))
4708      {
4709         if (cx < (lx + (lw / 2)))
4710           evas_textblock_cursor_line_char_last(c);
4711         else
4712           evas_textblock_cursor_line_char_last(c);
4713      }
4714    _sel_update(c, rp->object, rp->typedata.text->entry_data);
4715
4716    _edje_entry_imf_cursor_info_set(en);
4717
4718    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
4719    _edje_entry_real_part_configure(rp);
4720    return EINA_TRUE;
4721 }
4722
4723 Eina_Bool
4724 _edje_entry_cursor_down(Edje_Real_Part *rp, Edje_Cursor cur)
4725 {
4726    Entry *en;
4727    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
4728    Evas_Coord lx, ly, lw, lh, cx, cy, cw, ch;
4729    int ln;
4730
4731    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4732        (!rp->typedata.text)) return EINA_FALSE;
4733    en = rp->typedata.text->entry_data;
4734    if (!en) return EINA_FALSE;
4735    if (!c) return EINA_FALSE;
4736
4737    _edje_entry_imf_context_reset(rp);
4738
4739    ln = evas_textblock_cursor_line_geometry_get(c, NULL, NULL, NULL, NULL);
4740    ln++;
4741    if (!evas_object_textblock_line_number_geometry_get(rp->object, ln,
4742                                                        &lx, &ly, &lw, &lh))
4743      return EINA_FALSE;
4744    evas_textblock_cursor_char_geometry_get(c, &cx, &cy, &cw, &ch);
4745    if (!evas_textblock_cursor_char_coord_set(c, cx, ly + (lh / 2)))
4746      {
4747         if (cx < (lx + (lw / 2)))
4748           evas_textblock_cursor_line_char_last(c);
4749         else
4750           evas_textblock_cursor_line_char_last(c);
4751      }
4752    _sel_update(c, rp->object, rp->typedata.text->entry_data);
4753
4754    _edje_entry_imf_cursor_info_set(en);
4755    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
4756    _edje_entry_real_part_configure(rp);
4757    return EINA_TRUE;
4758 }
4759
4760 void
4761 _edje_entry_cursor_begin(Edje_Real_Part *rp, Edje_Cursor cur)
4762 {
4763    Entry *en;
4764    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
4765    
4766    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4767        (!rp->typedata.text)) return;
4768    en = rp->typedata.text->entry_data;
4769    if (!en) return;
4770    if (!c) return;
4771
4772    _edje_entry_imf_context_reset(rp);
4773
4774    evas_textblock_cursor_paragraph_first(c);
4775    _sel_update(c, rp->object, rp->typedata.text->entry_data);
4776
4777    _edje_entry_imf_cursor_info_set(en);
4778    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
4779    _edje_entry_real_part_configure(rp);
4780 }
4781
4782 void
4783 _edje_entry_cursor_end(Edje_Real_Part *rp, Edje_Cursor cur)
4784 {
4785    Entry *en;
4786    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
4787    
4788    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4789        (!rp->typedata.text)) return;
4790    en = rp->typedata.text->entry_data;
4791    if (!en) return;
4792    if (!c) return;
4793
4794    _edje_entry_imf_context_reset(rp);
4795
4796    _curs_end(c, rp->object, rp->typedata.text->entry_data);
4797    _sel_update(c, rp->object, rp->typedata.text->entry_data);
4798
4799    _edje_entry_imf_cursor_info_set(en);
4800
4801    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
4802    _edje_entry_real_part_configure(rp);
4803 }
4804
4805 void
4806 _edje_entry_cursor_copy(Edje_Real_Part *rp, Edje_Cursor cur, Edje_Cursor dst)
4807 {
4808    Entry *en;
4809    Evas_Textblock_Cursor *c;
4810    Evas_Textblock_Cursor *d;
4811
4812    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4813        (!rp->typedata.text)) return;
4814    en = rp->typedata.text->entry_data;
4815    if (!en) return;
4816    c = _cursor_get(rp, cur);
4817    if (!c) return;
4818    d = _cursor_get(rp, dst);
4819    if (!d) return;
4820    evas_textblock_cursor_copy(c, d);
4821    _sel_update(c, rp->object, rp->typedata.text->entry_data);
4822
4823    _edje_entry_imf_context_reset(rp);
4824    _edje_entry_imf_cursor_info_set(en);
4825    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
4826    _edje_entry_real_part_configure(rp);
4827 }
4828
4829 void
4830 _edje_entry_cursor_line_begin(Edje_Real_Part *rp, Edje_Cursor cur)
4831 {
4832    Entry *en;
4833    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
4834    
4835    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4836        (!rp->typedata.text)) return;
4837    en = rp->typedata.text->entry_data;
4838    if (!en) return;
4839    if (!c) return;
4840    _edje_entry_imf_context_reset(rp);
4841
4842    evas_textblock_cursor_line_char_first(c);
4843    _sel_update(c, rp->object, rp->typedata.text->entry_data);
4844
4845    _edje_entry_imf_cursor_info_set(en);
4846
4847    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
4848    _edje_entry_real_part_configure(rp);
4849 }
4850
4851 void
4852 _edje_entry_cursor_line_end(Edje_Real_Part *rp, Edje_Cursor cur)
4853 {
4854    Entry *en;
4855    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
4856    
4857    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4858        (!rp->typedata.text)) return;
4859    en = rp->typedata.text->entry_data;
4860    if (!en) return;
4861    if (!c) return;
4862    _edje_entry_imf_context_reset(rp);
4863    evas_textblock_cursor_line_char_last(c);
4864    _sel_update(c, rp->object, rp->typedata.text->entry_data);
4865
4866    _edje_entry_imf_cursor_info_set(en);
4867    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
4868    _edje_entry_real_part_configure(rp);
4869 }
4870
4871 Eina_Bool
4872 _edje_entry_cursor_coord_set(Edje_Real_Part *rp, Edje_Cursor cur,
4873                              Evas_Coord x, Evas_Coord y)
4874 {
4875    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
4876    if (!c) return EINA_FALSE;
4877    return evas_textblock_cursor_char_coord_set(c, x, y);
4878 }
4879
4880 Eina_Bool
4881 _edje_entry_cursor_is_format_get(Edje_Real_Part *rp, Edje_Cursor cur)
4882 {
4883    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
4884    if (!c) return EINA_FALSE;
4885    if (evas_textblock_cursor_is_format(c)) return EINA_TRUE;
4886    return EINA_FALSE;
4887 }
4888
4889 Eina_Bool
4890 _edje_entry_cursor_is_visible_format_get(Edje_Real_Part *rp, Edje_Cursor cur)
4891 {
4892    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
4893    if (!c) return EINA_FALSE;
4894    return evas_textblock_cursor_format_is_visible_get(c);
4895 }
4896
4897 char *
4898 _edje_entry_cursor_content_get(Edje_Real_Part *rp, Edje_Cursor cur)
4899 {
4900    static char *s = NULL;
4901    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
4902
4903    if (!c) return NULL;
4904    if (s)
4905      {
4906         free(s);
4907         s = NULL;
4908      }
4909
4910    s = evas_textblock_cursor_content_get(c);
4911    return s;
4912 }
4913
4914 void
4915 _edje_entry_cursor_pos_set(Edje_Real_Part *rp, Edje_Cursor cur, int pos)
4916 {
4917    Entry *en;
4918    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
4919    
4920    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4921        (!rp->typedata.text)) return;
4922    en = rp->typedata.text->entry_data;
4923    if (!en) return;
4924    if (!c) return;
4925    /* Abort if cursor position didn't really change */
4926    if (evas_textblock_cursor_pos_get(c) == pos)
4927      return;
4928
4929    _edje_entry_imf_context_reset(rp);
4930    evas_textblock_cursor_pos_set(c, pos);
4931    _sel_update(c, rp->object, rp->typedata.text->entry_data);
4932
4933    _edje_emit(rp->edje, "cursor,changed", rp->part->name);
4934    // TIZEN ONLY(130129) : Currently, for freezing cursor movement.
4935    if (!en->freeze)
4936      {
4937         _edje_entry_imf_cursor_info_set(en);
4938         _edje_entry_real_part_configure(rp);
4939      }
4940    //
4941 }
4942
4943 int
4944 _edje_entry_cursor_pos_get(Edje_Real_Part *rp, Edje_Cursor cur)
4945 {
4946    Evas_Textblock_Cursor *c = _cursor_get(rp, cur);
4947    if (!c) return 0;
4948    return evas_textblock_cursor_pos_get(c);
4949 }
4950
4951 void
4952 _edje_entry_input_panel_layout_set(Edje_Real_Part *rp, Edje_Input_Panel_Layout layout)
4953 {
4954    Entry *en;
4955    
4956    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4957        (!rp->typedata.text)) return;
4958    en = rp->typedata.text->entry_data;
4959    if (!en) return;
4960 #ifdef HAVE_ECORE_IMF
4961    if (en->imf_context)
4962      ecore_imf_context_input_panel_layout_set(en->imf_context, layout);
4963 #else
4964    (void) layout;
4965 #endif
4966 }
4967
4968 Edje_Input_Panel_Layout
4969 _edje_entry_input_panel_layout_get(Edje_Real_Part *rp)
4970 {
4971    Entry *en;
4972    
4973    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4974        (!rp->typedata.text)) return EDJE_INPUT_PANEL_LAYOUT_INVALID;
4975    en = rp->typedata.text->entry_data;
4976    if (!en) return EDJE_INPUT_PANEL_LAYOUT_INVALID;
4977 #ifdef HAVE_ECORE_IMF
4978    if (en->imf_context)
4979      return ecore_imf_context_input_panel_layout_get(en->imf_context);
4980 #endif
4981
4982    return EDJE_INPUT_PANEL_LAYOUT_INVALID;
4983 }
4984
4985 void
4986 _edje_entry_input_panel_layout_variation_set(Edje_Real_Part *rp, int variation)
4987 {
4988    Entry *en;
4989
4990    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
4991        (!rp->typedata.text)) return;
4992    en = rp->typedata.text->entry_data;
4993    if (!en) return;
4994 #ifdef HAVE_ECORE_IMF
4995    if (en->imf_context)
4996      ecore_imf_context_input_panel_layout_variation_set(en->imf_context, variation);
4997 #else
4998    (void) variation;
4999 #endif
5000 }
5001
5002 int
5003 _edje_entry_input_panel_layout_variation_get(Edje_Real_Part *rp)
5004 {
5005    Entry *en;
5006
5007    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
5008        (!rp->typedata.text)) return 0;
5009    en = rp->typedata.text->entry_data;
5010    if (!en) return 0;
5011 #ifdef HAVE_ECORE_IMF
5012    if (en->imf_context)
5013      return ecore_imf_context_input_panel_layout_variation_get(en->imf_context);
5014 #endif
5015
5016    return 0;
5017 }
5018
5019 void
5020 _edje_entry_imf_context_reset(Edje_Real_Part *rp)
5021 {
5022    Entry *en;
5023    
5024    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
5025        (!rp->typedata.text)) return;
5026    en = rp->typedata.text->entry_data;
5027    if (!en) return;
5028 #ifdef HAVE_ECORE_IMF
5029    if (en->imf_context)
5030      ecore_imf_context_reset(en->imf_context);
5031    if (en->commit_cancel)
5032       en->commit_cancel = EINA_FALSE;
5033 #endif
5034 }
5035
5036 static void
5037 _edje_entry_imf_cursor_location_set(Entry *en)
5038 {
5039 #ifdef HAVE_ECORE_IMF
5040    Evas_Coord cx, cy, cw, ch;
5041    if (!en || !en->rp || !en->imf_context) return;
5042
5043    _edje_entry_cursor_geometry_get(en->rp, &cx, &cy, &cw, &ch);
5044    ecore_imf_context_cursor_location_set(en->imf_context, cx, cy, cw, ch);
5045 #else
5046    (void) en;
5047 #endif
5048 }
5049
5050 static void
5051 _edje_entry_imf_cursor_info_set(Entry *en)
5052 {
5053    int cursor_pos;
5054
5055 #ifdef HAVE_ECORE_IMF
5056    if (!en || !en->rp || !en->imf_context) return;
5057
5058    if (en->have_selection)
5059      {
5060         if (evas_textblock_cursor_compare(en->sel_start, en->sel_end) < 0)
5061           cursor_pos = evas_textblock_cursor_pos_get(en->sel_start);
5062         else
5063           cursor_pos = evas_textblock_cursor_pos_get(en->sel_end);
5064      }
5065    else
5066      cursor_pos = evas_textblock_cursor_pos_get(en->cursor);
5067
5068    ecore_imf_context_cursor_position_set(en->imf_context, cursor_pos);
5069
5070    _edje_entry_imf_cursor_location_set(en);
5071 #else
5072    (void) en;
5073 #endif
5074 }
5075
5076 #ifdef HAVE_ECORE_IMF
5077 static Eina_Bool
5078 _edje_entry_imf_retrieve_surrounding_cb(void *data, Ecore_IMF_Context *ctx __UNUSED__, char **text, int *cursor_pos)
5079 {
5080    Edje *ed = data;
5081    Edje_Real_Part *rp = ed->focused_part;
5082    Entry *en = NULL;
5083    const char *str;
5084    char *plain_text;
5085    Eina_Strbuf *buf = NULL;
5086
5087    if (!rp) return EINA_FALSE;
5088    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
5089        (!rp->typedata.text)) return EINA_FALSE;
5090    else
5091      en = rp->typedata.text->entry_data;
5092    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
5093        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE))
5094      return EINA_FALSE;
5095
5096    if (text)
5097      {
5098         str = _edje_entry_text_get(rp);
5099         if (str)
5100           {
5101              plain_text = evas_textblock_text_markup_to_utf8(NULL, str);
5102
5103              if (plain_text)
5104                {
5105                   if (en->have_selection)
5106                     {
5107                        buf = eina_strbuf_new();
5108
5109                        if (en->sel_start)
5110                          eina_strbuf_append_n(buf, plain_text, evas_textblock_cursor_pos_get(en->sel_start));
5111                        else
5112                          eina_strbuf_append(buf, plain_text);
5113
5114                        *text = strdup(eina_strbuf_string_get(buf));
5115                        eina_strbuf_free(buf);
5116                     }
5117                   else
5118                     *text = strdup(plain_text);
5119
5120                   free(plain_text);
5121                   plain_text = NULL;
5122                }
5123              else
5124                *text = strdup("");
5125           }
5126         else
5127           *text = strdup("");
5128      }
5129
5130    if (cursor_pos)
5131      {
5132         if (en->have_selection && en->sel_start)
5133           *cursor_pos = evas_textblock_cursor_pos_get(en->sel_start);
5134         else if (en->cursor)
5135           *cursor_pos = evas_textblock_cursor_pos_get(en->cursor);
5136         else
5137           *cursor_pos = 0;
5138      }
5139
5140    return EINA_TRUE;
5141 }
5142
5143 static void
5144 _edje_entry_imf_event_commit_cb(void *data, Ecore_IMF_Context *ctx __UNUSED__, void *event_info)
5145 {
5146    Edje *ed = data;
5147    Edje_Real_Part *rp = ed->focused_part;
5148    Entry *en = NULL;
5149    char *commit_str = event_info;
5150    int start_pos;
5151
5152    if ((!rp)) return;
5153    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
5154        (!rp->typedata.text)) return;
5155    else
5156      en = rp->typedata.text->entry_data;
5157    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
5158        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE))
5159      return;
5160
5161    if (en->have_selection)
5162      {
5163         if (strcmp(commit_str, ""))
5164           {
5165              /* delete selected characters */
5166              _range_del_emit(ed, en->cursor, rp->object, en);
5167              _sel_clear(en->cursor, rp->object, en);
5168           }
5169      }
5170
5171    start_pos = evas_textblock_cursor_pos_get(en->cursor);
5172
5173    /* delete preedit characters */
5174    _preedit_del(en);
5175    _preedit_clear(en);
5176
5177    // Skipping commit process when it is useless
5178    if (en->commit_cancel)
5179      {
5180         en->commit_cancel = EINA_FALSE;
5181         return;
5182      }
5183
5184    if ((rp->part->entry_mode == EDJE_ENTRY_EDIT_MODE_PASSWORD) &&
5185        _edje_password_show_last)
5186      _edje_entry_hide_visible_password(en->rp);
5187    if ((rp->part->entry_mode == EDJE_ENTRY_EDIT_MODE_PASSWORD) &&
5188        _edje_password_show_last && (!en->preedit_start))
5189      {
5190         _text_filter_format_prepend(en, en->cursor, "+ password=off");
5191         _text_filter_text_prepend(en, en->cursor, commit_str);
5192         _text_filter_format_prepend(en, en->cursor, "- password");
5193
5194         if (en->pw_timer)
5195           {
5196              ecore_timer_del(en->pw_timer);
5197              en->pw_timer = NULL;
5198           }
5199         en->pw_timer = ecore_timer_add(TO_DOUBLE(_edje_password_show_last_timeout),
5200                                        _password_timer_cb, en);
5201      }
5202    else
5203      _text_filter_text_prepend(en, en->cursor, commit_str);
5204
5205
5206    _edje_entry_imf_cursor_info_set(en);
5207    _anchors_get(en->cursor, rp->object, en);
5208    // TIZEN ONLY - START
5209    if (en->cursor_handler_show)
5210      {
5211         evas_object_hide(en->cursor_handler);
5212         en->cursor_handler_show = EINA_FALSE;
5213      }
5214    // TIZEN ONLY - END
5215    _edje_emit(rp->edje, "entry,changed", rp->part->name);
5216
5217      {
5218         Edje_Entry_Change_Info *info = calloc(1, sizeof(*info));
5219         info->insert = EINA_TRUE;
5220         info->change.insert.pos = start_pos;
5221         info->change.insert.content = eina_stringshare_add(commit_str);
5222         info->change.insert.plain_length =
5223            eina_unicode_utf8_get_len(info->change.insert.content);
5224         _edje_emit_full(ed, "entry,changed,user", rp->part->name,
5225                         info, _free_entry_change_info);
5226         _edje_emit(ed, "cursor,changed", rp->part->name);
5227      }
5228
5229    _edje_entry_imf_cursor_info_set(en);
5230    _edje_entry_real_part_configure(rp);
5231 }
5232
5233 static void
5234 _edje_entry_imf_event_preedit_changed_cb(void *data, Ecore_IMF_Context *ctx __UNUSED__, void *event_info __UNUSED__)
5235 {
5236    Edje *ed = data;
5237    Edje_Real_Part *rp = ed->focused_part;
5238    Entry *en = NULL;
5239    int cursor_pos;
5240    int preedit_start_pos, preedit_end_pos;
5241    char *preedit_string;
5242    char *preedit_tag_index;
5243    char *pretag = NULL;
5244    char *markup_txt = NULL;
5245    char *tagname[] = {NULL, "preedit", "preedit_sel", "preedit_sel",
5246                       "preedit_sub1", "preedit_sub2", "preedit_sub3", "preedit_sub4"};
5247    int i;
5248    size_t preedit_type_size = sizeof(tagname) / sizeof(tagname[0]);
5249    Eina_Bool preedit_end_state = EINA_FALSE;
5250    Eina_List *attrs = NULL, *l = NULL;
5251    Ecore_IMF_Preedit_Attr *attr;
5252    Eina_Strbuf *buf;
5253    Eina_Strbuf *preedit_attr_str;
5254
5255    if ((!rp)) return;
5256
5257    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
5258        (!rp->typedata.text)) return;
5259    else
5260      en = rp->typedata.text->entry_data;
5261    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
5262        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE))
5263      return;
5264
5265    if (!en->imf_context) return;
5266    // TIZEN ONLY - START
5267    if (en->cursor_handler_show)
5268      {
5269         evas_object_hide(en->cursor_handler);
5270         en->cursor_handler_show = EINA_FALSE;
5271      }
5272    // TIZEN ONLY - END
5273
5274    ecore_imf_context_preedit_string_with_attributes_get(en->imf_context,
5275                                                         &preedit_string,
5276                                                         &attrs, &cursor_pos);
5277    if (!preedit_string) return;
5278
5279    if (!strcmp(preedit_string, ""))
5280      preedit_end_state = EINA_TRUE;
5281
5282    if (en->have_selection && !preedit_end_state)
5283      {
5284         /* delete selected characters */
5285         _range_del_emit(ed, en->cursor, rp->object, en);
5286      }
5287
5288    if (en->preedit_start && en->preedit_end)
5289      {
5290         /* extract the tag string */
5291         char *str = evas_textblock_cursor_range_text_get(en->preedit_start, en->preedit_end, EVAS_TEXTBLOCK_TEXT_MARKUP);
5292
5293         if (str)
5294           {
5295              preedit_tag_index = strstr(str, "<preedit");
5296
5297              if ((preedit_tag_index - str) > 0)
5298                {
5299                   pretag = calloc(1, sizeof(char)*(preedit_tag_index-str+1));
5300                   if (preedit_tag_index)
5301                     {
5302                        strncpy(pretag, str, preedit_tag_index-str);
5303                     }
5304                }
5305              free(str);
5306           }
5307      }
5308
5309    /* delete preedit characters */
5310    _preedit_del(en);
5311
5312    preedit_start_pos = evas_textblock_cursor_pos_get(en->cursor);
5313
5314    /* restore previous tag */
5315    if (pretag)
5316      {
5317         _text_filter_markup_prepend(en, en->cursor, pretag);
5318         free(pretag);
5319      }
5320
5321    /* insert preedit character(s) */
5322    if (strlen(preedit_string) > 0)
5323      {
5324         buf = eina_strbuf_new();
5325         if (attrs)
5326           {
5327              EINA_LIST_FOREACH(attrs, l, attr)
5328                {
5329                   if (attr->preedit_type <= preedit_type_size &&
5330                       tagname[attr->preedit_type])
5331                     {
5332                        preedit_attr_str = eina_strbuf_new();
5333                        if (preedit_attr_str)
5334                          {
5335                             eina_strbuf_append_n(preedit_attr_str, preedit_string + attr->start_index, attr->end_index - attr->start_index);
5336                             markup_txt = evas_textblock_text_utf8_to_markup(NULL, eina_strbuf_string_get(preedit_attr_str));
5337
5338                             if (markup_txt)
5339                               {
5340                                  eina_strbuf_append_printf(buf, "<%s>%s</%s>", tagname[attr->preedit_type], markup_txt, tagname[attr->preedit_type]);
5341                                  free(markup_txt);
5342                               }
5343                             eina_strbuf_free(preedit_attr_str);
5344                          }
5345                     }
5346                   else
5347                     eina_strbuf_append(buf, preedit_string);
5348                }
5349           }
5350         else
5351           {
5352              eina_strbuf_append(buf, preedit_string);
5353           }
5354
5355         // For skipping useless commit
5356         if (!preedit_end_state)
5357            en->have_preedit = EINA_TRUE;
5358
5359         if ((rp->part->entry_mode == EDJE_ENTRY_EDIT_MODE_PASSWORD) &&
5360             _edje_password_show_last)
5361           {
5362              _edje_entry_hide_visible_password(en->rp);
5363              _text_filter_format_prepend(en, en->cursor, "+ password=off");
5364              _text_filter_markup_prepend(en, en->cursor, eina_strbuf_string_get(buf));
5365              _text_filter_format_prepend(en, en->cursor, "- password");
5366              if (en->pw_timer)
5367                {
5368                   ecore_timer_del(en->pw_timer);
5369                   en->pw_timer = NULL;
5370                }
5371              en->pw_timer = ecore_timer_add(TO_DOUBLE(_edje_password_show_last_timeout),
5372                                             _password_timer_cb, en);
5373           }
5374         else
5375           {
5376              _text_filter_markup_prepend(en, en->cursor, eina_strbuf_string_get(buf));
5377           }
5378         eina_strbuf_free(buf);
5379      }
5380
5381    if (!preedit_end_state)
5382      {
5383         /* set preedit start cursor */
5384         if (!en->preedit_start)
5385           en->preedit_start = evas_object_textblock_cursor_new(rp->object);
5386         evas_textblock_cursor_copy(en->cursor, en->preedit_start);
5387
5388         /* set preedit end cursor */
5389         if (!en->preedit_end)
5390           en->preedit_end = evas_object_textblock_cursor_new(rp->object);
5391         evas_textblock_cursor_copy(en->cursor, en->preedit_end);
5392
5393         preedit_end_pos = evas_textblock_cursor_pos_get(en->cursor);
5394
5395         for (i = 0; i < (preedit_end_pos - preedit_start_pos); i++)
5396           {
5397              evas_textblock_cursor_char_prev(en->preedit_start);
5398           }
5399
5400         en->have_preedit = EINA_TRUE;
5401
5402         /* set cursor position */
5403         evas_textblock_cursor_pos_set(en->cursor, preedit_start_pos + cursor_pos);
5404      }
5405
5406    _edje_entry_imf_cursor_info_set(en);
5407    _anchors_get(en->cursor, rp->object, en);
5408    _edje_emit(rp->edje, "preedit,changed", rp->part->name);
5409    _edje_emit(ed, "cursor,changed", rp->part->name);
5410
5411    /* delete attribute list */
5412    if (attrs)
5413      {
5414         EINA_LIST_FREE(attrs, attr) free(attr);
5415      }
5416
5417    free(preedit_string);
5418 }
5419
5420 static void
5421 _edje_entry_imf_event_delete_surrounding_cb(void *data, Ecore_IMF_Context *ctx __UNUSED__, void *event_info)
5422 {
5423    Edje *ed = data;
5424    Edje_Real_Part *rp = ed->focused_part;
5425    Entry *en = NULL;
5426    Ecore_IMF_Event_Delete_Surrounding *ev = event_info;
5427    Evas_Textblock_Cursor *del_start, *del_end;
5428    int cursor_pos;
5429
5430    if ((!rp) || (!ev)) return;
5431    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
5432        (!rp->typedata.text)) return;
5433    else
5434      en = rp->typedata.text->entry_data;
5435    if ((!en) || (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) ||
5436        (rp->part->entry_mode < EDJE_ENTRY_EDIT_MODE_SELECTABLE))
5437      return;
5438
5439    cursor_pos = evas_textblock_cursor_pos_get(en->cursor);
5440
5441    del_start = evas_object_textblock_cursor_new(en->rp->object);
5442    evas_textblock_cursor_pos_set(del_start, cursor_pos + ev->offset);
5443
5444    del_end = evas_object_textblock_cursor_new(en->rp->object);
5445    evas_textblock_cursor_pos_set(del_end, cursor_pos + ev->offset + ev->n_chars);
5446
5447    evas_textblock_cursor_range_delete(del_start, del_end);
5448
5449    evas_textblock_cursor_free(del_start);
5450    evas_textblock_cursor_free(del_end);
5451 }
5452 #endif
5453
5454
5455 //////////////////////////////////////  TIZEN ONLY(130129)  : START //////////////////////////////////
5456 void _edje_entry_freeze(Edje_Real_Part *rp)
5457 {
5458    Entry *en = NULL;
5459
5460    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
5461        (!rp->typedata.text)) return;
5462
5463    en = rp->typedata.text->entry_data;
5464    if (!en) return;
5465
5466    en->freeze = EINA_TRUE;
5467 }
5468
5469 void _edje_entry_thaw(Edje_Real_Part *rp)
5470 {
5471    Entry *en = NULL;
5472
5473    if ((rp->type != EDJE_RP_TYPE_TEXT) ||
5474        (!rp->typedata.text)) return;
5475
5476    en = rp->typedata.text->entry_data;
5477    if (!en) return;
5478
5479    en->freeze = EINA_FALSE;
5480
5481    _edje_entry_imf_cursor_info_set(en);
5482    _edje_entry_real_part_configure(rp);
5483 }
5484 ///////////////////////////////////////////  TIZEN ONLY : END   ////////////////////////////////////////
5485
5486 /* vim:set ts=8 sw=3 sts=3 expandtab cino=>5n-2f0^-2{2(0W1st0 :*/