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