[Genlist][Nabi:S1-1013] bug fix, Abnormality is displayed when selecting Type while...
[framework/uifw/elementary.git] / src / lib / elm_entry.c
1 #include <Elementary.h>
2 #include <Elementary_Cursor.h>
3 #include "elm_priv.h"
4 #include "elm_module_priv.h"
5 #include "els_scroller.h"
6
7
8 /* Maximum chunk size to be inserted to the entry at once
9  * FIXME: This size is arbitrary, should probably choose a better size.
10  * Possibly also find a way to set it to a low value for weak computers,
11  * and to a big value for better computers. */
12 #define _CHUNK_SIZE 10000
13
14 typedef struct _Mod_Api Mod_Api;
15
16 typedef struct _Widget_Data Widget_Data;
17 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
18 typedef struct _Elm_Entry_Item_Provider Elm_Entry_Item_Provider;
19 typedef struct _Elm_Entry_Markup_Filter Elm_Entry_Markup_Filter;
20
21 struct _Widget_Data
22 {
23    Evas_Object *ent, *scroller;
24    Evas_Object *hoversel;
25    Ecore_Job *deferred_recalc_job;
26    Ecore_Event_Handler *sel_notify_handler;
27    Ecore_Event_Handler *sel_clear_handler;
28    Ecore_Timer *longpress_timer;
29    Ecore_Timer *delay_write;
30    /* for deferred appending */
31    Ecore_Idler *append_text_idler;
32    char *append_text_left;
33    int append_text_position;
34    int append_text_len;
35    /* Only for clipboard */
36    const char *cut_sel;
37    const char *text;
38    const char *file;
39    Elm_Text_Format format;
40    Evas_Coord lastw, entmw, entmh;
41    Evas_Coord downx, downy;
42    Eina_List *items;
43    Eina_List *item_providers;
44    Eina_List *text_filters;
45    Eina_List *markup_filters;
46    Ecore_Job *hovdeljob;
47    Mod_Api *api; // module api if supplied
48    int cursor_pos;
49    Elm_Scroller_Policy policy_h, policy_v;
50    Elm_Wrap_Type linewrap;
51    Elm_Input_Panel_Layout input_panel_layout;
52    Elm_Autocapital_Type autocapital_type;
53    Elm_Input_Panel_Lang input_panel_lang;
54    Elm_Input_Panel_Return_Key_Type input_panel_return_key_type;
55    void *input_panel_imdata;
56    int input_panel_imdata_len;
57    struct
58      {
59         Evas_Object *hover_parent;
60         Evas_Object *pop, *hover;
61         const char *hover_style;
62      } anchor_hover;
63    Eina_Bool changed : 1;
64    Eina_Bool single_line : 1;
65    Eina_Bool password : 1;
66    Eina_Bool editable : 1;
67    Eina_Bool selection_asked : 1;
68    Eina_Bool have_selection : 1;
69    Eina_Bool selmode : 1;
70    Eina_Bool deferred_cur : 1;
71    Eina_Bool cur_changed : 1;
72    Eina_Bool disabled : 1;
73    Eina_Bool context_menu : 1;
74    Eina_Bool drag_selection_asked : 1;
75    Eina_Bool can_write : 1;
76    Eina_Bool autosave : 1;
77    Eina_Bool usedown : 1;
78    Eina_Bool scroll : 1;
79    Eina_Bool h_bounce : 1;
80    Eina_Bool v_bounce : 1;
81    Eina_Bool input_panel_enable : 1;
82    Eina_Bool prediction_allow : 1;
83    Eina_Bool input_panel_return_key_disabled : 1;
84    Eina_Bool autoreturnkey : 1;
85    Elm_Cnp_Mode cnp_mode : 2;
86 //// TIZEN ONLY
87    Evas_Object *mgf_proxy;
88    Evas_Object *mgf_clip;
89    Evas_Object *mgf_bg;
90    Evas_Coord mgf_height;
91    float mgf_scale;
92    int mgf_type;
93    Ecore_Job *region_get_job;
94    Ecore_Job *region_recalc_job;
95    const char *password_text;
96    Evas_Coord cx, cy, cw, ch;
97    Eina_Bool double_clicked : 1;
98    Eina_Bool long_pressed : 1;
99    Eina_Bool magnifier_enabled : 1;
100 //
101 };
102
103 struct _Elm_Entry_Context_Menu_Item
104 {
105    Evas_Object *obj;
106    const char *label;
107    const char *icon_file;
108    const char *icon_group;
109    Elm_Icon_Type icon_type;
110    Evas_Smart_Cb func;
111    void *data;
112 };
113
114 struct _Elm_Entry_Item_Provider
115 {
116    Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
117    void *data;
118 };
119
120 struct _Elm_Entry_Markup_Filter
121 {
122    Elm_Entry_Filter_Cb func;
123    void *data;
124 };
125
126 typedef enum _Length_Unit
127 {
128    LENGTH_UNIT_CHAR,
129    LENGTH_UNIT_BYTE,
130    LENGTH_UNIT_LAST
131 } Length_Unit;
132
133 static const char *widtype = NULL;
134 // start for cbhm
135 static Evas_Object *cnpwidgetdata = NULL;
136 // end for cbhm
137
138 #ifdef HAVE_ELEMENTARY_X
139 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
140 #endif
141 static void _del_hook(Evas_Object *obj);
142 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
143 static void _theme_hook(Evas_Object *obj);
144 static void _disable_hook(Evas_Object *obj);
145 static void _sizing_eval(Evas_Object *obj);
146 static void _on_focus_hook(void *data, Evas_Object *obj);
147 static void _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content);
148 static Evas_Object *_content_unset_hook(Evas_Object *obj, const char *part);
149 static Evas_Object *_content_get_hook(const Evas_Object *obj, const char *part);
150 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src, Evas_Callback_Type type, void *event_info);
151 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
152 static const char *_getbase(Evas_Object *obj);
153 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
154 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
155 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
156 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
157 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
158 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
159 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
160 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
161 static void _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit);
162 static void _entry_hover_anchor_clicked(void *data, Evas_Object *obj, void *event_info);
163 //// TIZEN ONLY
164 static void _signal_selection_end(void *data, Evas_Object *obj, const char *emission, const char *source);
165 static void _signal_handler_move_start(void *data, Evas_Object *obj, const char *emission, const char *source);
166 static void _signal_handler_move_end(void *data, Evas_Object *obj, const char *emission, const char *source);
167 static void _signal_handler_moving(void *data, Evas_Object *obj, const char *emission, const char *source);
168 static void _magnifier_create(void *data);
169 static void _magnifier_show(void *data);
170 static void _magnifier_hide(void *data);
171 static void _magnifier_move(void *data);
172 static Evas_Coord_Rectangle _layout_region_get(Evas_Object *data);
173 static Evas_Coord_Rectangle _viewport_region_get(Evas_Object *data);
174 static void _region_get_job(void *data);
175 static void _region_recalc_job(void *data);
176 //
177
178 static const char SIG_CHANGED[] = "changed";
179 static const char SIG_CHANGED_USER[] = "changed,user";
180 static const char SIG_ACTIVATED[] = "activated";
181 static const char SIG_PRESS[] = "press";
182 static const char SIG_LONGPRESSED[] = "longpressed";
183 static const char SIG_CLICKED[] = "clicked";
184 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
185 static const char SIG_CLICKED_TRIPLE[] = "clicked,triple";
186 static const char SIG_FOCUSED[] = "focused";
187 static const char SIG_UNFOCUSED[] = "unfocused";
188 static const char SIG_SELECTION_PASTE[] = "selection,paste";
189 static const char SIG_SELECTION_COPY[] = "selection,copy";
190 static const char SIG_SELECTION_CUT[] = "selection,cut";
191 static const char SIG_SELECTION_START[] = "selection,start";
192 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
193 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
194 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
195 static const char SIG_CURSOR_CHANGED_MANUAL[] = "cursor,changed,manual";
196 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
197 static const char SIG_ANCHOR_HOVER_OPENED[] = "anchor,hover,opened";
198 static const char SIG_ANCHOR_DOWN[] = "anchor,down";
199 static const char SIG_ANCHOR_UP[] = "anchor,up";
200 static const char SIG_ANCHOR_IN[] = "anchor,in";
201 static const char SIG_ANCHOR_OUT[] = "anchor,out";
202 static const char SIG_PREEDIT_CHANGED[] = "preedit,changed";
203 static const char SIG_UNDO_REQUEST[] = "undo,request";
204 static const char SIG_REDO_REQUEST[] = "redo,request";
205 static const Evas_Smart_Cb_Description _signals[] = {
206        {SIG_CHANGED, ""},
207        {SIG_ACTIVATED, ""},
208        {SIG_PRESS, ""},
209        {SIG_LONGPRESSED, ""},
210        {SIG_CLICKED, ""},
211        {SIG_CLICKED_DOUBLE, ""},
212        {SIG_CLICKED_TRIPLE, ""},
213        {SIG_FOCUSED, ""},
214        {SIG_UNFOCUSED, ""},
215        {SIG_SELECTION_PASTE, ""},
216        {SIG_SELECTION_COPY, ""},
217        {SIG_SELECTION_CUT, ""},
218        {SIG_SELECTION_START, ""},
219        {SIG_SELECTION_CHANGED, ""},
220        {SIG_SELECTION_CLEARED, ""},
221        {SIG_CURSOR_CHANGED, ""},
222        {SIG_CURSOR_CHANGED_MANUAL, ""},
223        {SIG_ANCHOR_CLICKED, ""},
224        {SIG_ANCHOR_HOVER_OPENED, ""},
225        {SIG_ANCHOR_DOWN, ""},
226        {SIG_ANCHOR_UP, ""},
227        {SIG_ANCHOR_IN, ""},
228        {SIG_ANCHOR_OUT, ""},
229        {SIG_PREEDIT_CHANGED, ""},
230        {SIG_CHANGED_USER, ""},
231        {SIG_UNDO_REQUEST, ""},
232        {SIG_REDO_REQUEST, ""},
233        {NULL, NULL}
234 };
235
236 typedef enum _Elm_Entry_Magnifier_Type
237 {
238    _ENTRY_MAGNIFIER_FIXEDSIZE = 0,
239    _ENTRY_MAGNIFIER_FILLWIDTH,
240    _ENTRY_MAGNIFIER_CIRCULAR,
241 } Elm_Entry_Magnifier_Type;
242
243 static Eina_List *entries = NULL;
244
245 struct _Mod_Api
246 {
247    void (*obj_hook) (Evas_Object *obj);
248    void (*obj_unhook) (Evas_Object *obj);
249    void (*obj_longpress) (Evas_Object *obj);
250    void (*obj_hidemenu) (Evas_Object *obj);
251    void (*obj_mouseup) (Evas_Object *obj);
252 };
253
254 static Mod_Api *
255 _module(Evas_Object *obj __UNUSED__)
256 {
257    static Elm_Module *m = NULL;
258    if (m) goto ok; // already found - just use
259    if (!(m = _elm_module_find_as("entry/api"))) return NULL;
260    // get module api
261    m->api = malloc(sizeof(Mod_Api));
262    if (!m->api) return NULL;
263    ((Mod_Api *)(m->api)      )->obj_hook = // called on creation
264       _elm_module_symbol_get(m, "obj_hook");
265    ((Mod_Api *)(m->api)      )->obj_unhook = // called on deletion
266       _elm_module_symbol_get(m, "obj_unhook");
267    ((Mod_Api *)(m->api)      )->obj_longpress = // called on long press menu
268       _elm_module_symbol_get(m, "obj_longpress");
269    ((Mod_Api *)(m->api)      )->obj_hidemenu = // called on hide menu
270       _elm_module_symbol_get(m, "obj_hidemenu");
271    ((Mod_Api *)(m->api)      )->obj_mouseup = // called on mouseup
272       _elm_module_symbol_get(m, "obj_mouseup");
273 ok: // ok - return api
274    return m->api;
275 }
276
277 static char *
278 _buf_append(char *buf, const char *str, int *len, int *alloc)
279 {
280    int len2 = strlen(str);
281    if ((*len + len2) >= *alloc)
282      {
283         char *buf2 = realloc(buf, *alloc + len2 + 512);
284         if (!buf2) return NULL;
285         buf = buf2;
286         *alloc += (512 + len2);
287      }
288    strcpy(buf + *len, str);
289    *len += len2;
290    return buf;
291 }
292
293 static char *
294 _load_file(const char *file)
295 {
296    FILE *f;
297    size_t size;
298    int alloc = 0, len = 0;
299    char *text = NULL, buf[16384 + 1];
300
301    f = fopen(file, "rb");
302    if (!f) return NULL;
303    while ((size = fread(buf, 1, sizeof(buf) - 1, f)))
304      {
305         char *tmp_text;
306         buf[size] = 0;
307         tmp_text = _buf_append(text, buf, &len, &alloc);
308         if (!tmp_text) break;
309         text = tmp_text;
310      }
311    fclose(f);
312    return text;
313 }
314
315 static char *
316 _load_plain(const char *file)
317 {
318    char *text;
319
320    text = _load_file(file);
321    if (text)
322      {
323         char *text2;
324
325         text2 = elm_entry_utf8_to_markup(text);
326         free(text);
327         return text2;
328      }
329    return NULL;
330 }
331
332 static Eina_Bool
333 _load(Evas_Object *obj)
334 {
335    Widget_Data *wd = elm_widget_data_get(obj);
336    char *text;
337    if (!wd) return EINA_FALSE;
338    if (!wd->file)
339      {
340         elm_object_text_set(obj, "");
341         return EINA_TRUE;
342      }
343    switch (wd->format)
344      {
345       case ELM_TEXT_FORMAT_PLAIN_UTF8:
346          text = _load_plain(wd->file);
347          break;
348       case ELM_TEXT_FORMAT_MARKUP_UTF8:
349          text = _load_file(wd->file);
350          break;
351       default:
352          text = NULL;
353          break;
354      }
355    if (text)
356      {
357         elm_object_text_set(obj, text);
358         free(text);
359         return EINA_TRUE;
360      }
361    else
362      {
363         elm_object_text_set(obj, "");
364         return EINA_FALSE;
365      }
366 }
367
368 static void
369 _save_markup_utf8(const char *file, const char *text)
370 {
371    FILE *f;
372
373    if ((!text) || (!text[0]))
374      {
375         ecore_file_unlink(file);
376         return;
377      }
378    f = fopen(file, "wb");
379    if (!f)
380      {
381         // FIXME: report a write error
382         return;
383      }
384    fputs(text, f); // FIXME: catch error
385    fclose(f);
386 }
387
388 static void
389 _save_plain_utf8(const char *file, const char *text)
390 {
391    char *text2;
392
393    text2 = elm_entry_markup_to_utf8(text);
394    if (!text2)
395      return;
396    _save_markup_utf8(file, text2);
397    free(text2);
398 }
399
400 static void
401 _save(Evas_Object *obj)
402 {
403    Widget_Data *wd = elm_widget_data_get(obj);
404    if (!wd) return;
405    if (!wd->file) return;
406    switch (wd->format)
407      {
408       case ELM_TEXT_FORMAT_PLAIN_UTF8:
409          _save_plain_utf8(wd->file, elm_object_text_get(obj));
410          break;
411       case ELM_TEXT_FORMAT_MARKUP_UTF8:
412          _save_markup_utf8(wd->file, elm_object_text_get(obj));
413          break;
414       default:
415          break;
416      }
417 }
418
419 static Eina_Bool
420 _delay_write(void *data)
421 {
422    Widget_Data *wd = elm_widget_data_get(data);
423    if (!wd) return ECORE_CALLBACK_CANCEL;
424    _save(data);
425    wd->delay_write = NULL;
426    return ECORE_CALLBACK_CANCEL;
427 }
428
429 static Elm_Entry_Markup_Filter *
430 _filter_new(Elm_Entry_Filter_Cb func, void *data)
431 {
432    Elm_Entry_Markup_Filter *tf = ELM_NEW(Elm_Entry_Markup_Filter);
433    if (!tf) return NULL;
434
435    tf->func = func;
436    if (func == elm_entry_filter_limit_size)
437      {
438         Elm_Entry_Filter_Limit_Size *lim = data, *lim2;
439
440         if (!data)
441           {
442              free(tf);
443              return NULL;
444           }
445         lim2 = malloc(sizeof(Elm_Entry_Filter_Limit_Size));
446         if (!lim2)
447           {
448              free(tf);
449              return NULL;
450           }
451         memcpy(lim2, lim, sizeof(Elm_Entry_Filter_Limit_Size));
452         tf->data = lim2;
453      }
454    else if (func == elm_entry_filter_accept_set)
455      {
456         Elm_Entry_Filter_Accept_Set *as = data, *as2;
457
458         if (!data)
459           {
460              free(tf);
461              return NULL;
462           }
463         as2 = malloc(sizeof(Elm_Entry_Filter_Accept_Set));
464         if (!as2)
465           {
466              free(tf);
467              return NULL;
468           }
469         if (as->accepted)
470           as2->accepted = eina_stringshare_add(as->accepted);
471         else
472           as2->accepted = NULL;
473         if (as->rejected)
474           as2->rejected = eina_stringshare_add(as->rejected);
475         else
476           as2->rejected = NULL;
477         tf->data = as2;
478      }
479    else
480      tf->data = data;
481    return tf;
482 }
483
484 static void
485 _filter_free(Elm_Entry_Markup_Filter *tf)
486 {
487    if (tf->func == elm_entry_filter_limit_size)
488      {
489         Elm_Entry_Filter_Limit_Size *lim = tf->data;
490         if (lim) free(lim);
491      }
492    else if (tf->func == elm_entry_filter_accept_set)
493      {
494         Elm_Entry_Filter_Accept_Set *as = tf->data;
495         if (as)
496           {
497              if (as->accepted) eina_stringshare_del(as->accepted);
498              if (as->rejected) eina_stringshare_del(as->rejected);
499              free(as);
500           }
501      }
502    free(tf);
503 }
504
505 static void
506 _del_pre_hook(Evas_Object *obj)
507 {
508    Widget_Data *wd = elm_widget_data_get(obj);
509    if (!wd) return;
510    if (wd->delay_write)
511      {
512         ecore_timer_del(wd->delay_write);
513         wd->delay_write = NULL;
514         if (wd->autosave) _save(obj);
515      }
516    elm_entry_anchor_hover_end(obj);
517    elm_entry_anchor_hover_parent_set(obj, NULL);
518 }
519
520 static void
521 _del_hook(Evas_Object *obj)
522 {
523    Widget_Data *wd = elm_widget_data_get(obj);
524    Elm_Entry_Context_Menu_Item *it;
525    Elm_Entry_Item_Provider *ip;
526    Elm_Entry_Markup_Filter *tf;
527
528    evas_event_freeze(evas_object_evas_get(obj));
529
530    if (wd->file) eina_stringshare_del(wd->file);
531
532    if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
533    if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
534
535    entries = eina_list_remove(entries, obj);
536 #ifdef HAVE_ELEMENTARY_X
537    if (wd->sel_notify_handler)
538      ecore_event_handler_del(wd->sel_notify_handler);
539    if (wd->sel_clear_handler)
540      ecore_event_handler_del(wd->sel_clear_handler);
541 #endif
542    if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
543    if (wd->text) eina_stringshare_del(wd->text);
544    if (wd->password_text) eina_stringshare_del(wd->password_text);
545    if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
546    if (wd->region_get_job) ecore_job_del(wd->region_get_job);
547    if (wd->region_recalc_job) ecore_job_del(wd->region_recalc_job);
548    if (wd->append_text_idler)
549      {
550         ecore_idler_del(wd->append_text_idler);
551         free(wd->append_text_left);
552         wd->append_text_left = NULL;
553         wd->append_text_idler = NULL;
554      }
555    if (wd->mgf_proxy) evas_object_del(wd->mgf_proxy);
556    if (wd->mgf_bg) evas_object_del(wd->mgf_bg);
557    if (wd->mgf_clip) evas_object_del(wd->mgf_clip);
558    if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
559    EINA_LIST_FREE(wd->items, it)
560      {
561         eina_stringshare_del(it->label);
562         eina_stringshare_del(it->icon_file);
563         eina_stringshare_del(it->icon_group);
564         free(it);
565      }
566    EINA_LIST_FREE(wd->item_providers, ip)
567      {
568         free(ip);
569      }
570    EINA_LIST_FREE(wd->text_filters, tf)
571      {
572         _filter_free(tf);
573      }
574    EINA_LIST_FREE(wd->markup_filters, tf)
575      {
576         _filter_free(tf);
577      }
578    if (wd->delay_write) ecore_timer_del(wd->delay_write);
579    if (wd->input_panel_imdata) free(wd->input_panel_imdata);
580
581    if (wd->anchor_hover.hover_style) eina_stringshare_del(wd->anchor_hover.hover_style);
582    evas_event_thaw(evas_object_evas_get(obj));
583    evas_event_thaw_eval(evas_object_evas_get(obj));
584    free(wd);
585 }
586
587 static void
588 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
589 {
590    Widget_Data *wd = elm_widget_data_get(obj);
591    edje_object_mirrored_set(wd->ent, rtl);
592    if (wd->anchor_hover.hover)
593       elm_widget_mirrored_set(wd->anchor_hover.hover, rtl);
594 }
595
596 static void
597 _theme_hook(Evas_Object *obj)
598 {
599    Widget_Data *wd = elm_widget_data_get(obj);
600    const char *t;
601
602    evas_event_freeze(evas_object_evas_get(obj));
603    _elm_widget_mirrored_reload(obj);
604    _mirrored_set(obj, elm_widget_mirrored_get(obj));
605
606    t = eina_stringshare_add(elm_object_text_get(obj));
607    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
608    if (_elm_config->desktop_entry)
609      edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
610    elm_object_text_set(obj, t);
611    eina_stringshare_del(t);
612    if (elm_widget_disabled_get(obj))
613      edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
614    edje_object_part_text_input_panel_layout_set(wd->ent, "elm.text", wd->input_panel_layout);
615    edje_object_part_text_autocapital_type_set(wd->ent, "elm.text", wd->autocapital_type);
616    edje_object_part_text_prediction_allow_set(wd->ent, "elm.text", wd->prediction_allow);
617    edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", wd->input_panel_enable);
618    edje_object_part_text_input_panel_imdata_set(wd->ent, "elm.text", wd->input_panel_imdata, wd->input_panel_imdata_len);
619    edje_object_part_text_input_panel_return_key_type_set(wd->ent, "elm.text", wd->input_panel_return_key_type);
620    edje_object_part_text_input_panel_return_key_disabled_set(wd->ent, "elm.text", wd->input_panel_return_key_disabled);
621
622    if (wd->cursor_pos != 0)
623      elm_entry_cursor_pos_set(obj, wd->cursor_pos);
624    if (elm_widget_focus_get(obj))
625      edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
626    edje_object_message_signal_process(wd->ent);
627    edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
628    if (wd->scroll)
629      {
630         const char *str;
631         Evas_Object *edj;
632
633         elm_smart_scroller_mirrored_set(wd->scroller, elm_widget_mirrored_get(obj));
634         elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
635                                        elm_widget_style_get(obj));
636         edj = elm_smart_scroller_edje_object_get(wd->scroller);
637         str = edje_object_data_get(edj, "focus_highlight");
638         if ((str) && (!strcmp(str, "on")))
639           elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
640         else
641           elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
642      }
643    _sizing_eval(obj);
644    evas_event_thaw(evas_object_evas_get(obj));
645    evas_event_thaw_eval(evas_object_evas_get(obj));
646 }
647
648 static void
649 _disable_hook(Evas_Object *obj)
650 {
651    Widget_Data *wd = elm_widget_data_get(obj);
652
653    if (elm_widget_disabled_get(obj))
654      {
655         edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
656         wd->disabled = EINA_TRUE;
657      }
658    else
659      {
660         edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
661         wd->disabled = EINA_FALSE;
662      }
663 }
664
665 static void
666 _recalc_cursor_geometry(Evas_Object *obj)
667 {
668    Widget_Data *wd = elm_widget_data_get(obj);
669    if (!wd) return;
670    evas_object_smart_callback_call(obj, SIG_CURSOR_CHANGED, NULL);
671    if (!wd->deferred_recalc_job)
672      {
673         Evas_Coord cx, cy, cw, ch;
674         edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
675                                                   &cx, &cy, &cw, &ch);
676         if (wd->cur_changed)
677           {
678              elm_widget_show_region_set(obj, cx, cy, cw, ch, EINA_FALSE);
679              wd->cur_changed = EINA_FALSE;
680           }
681      }
682    else
683      wd->deferred_cur = EINA_TRUE;
684 }
685
686 static void
687 _elm_deferred_recalc_job(void *data)
688 {
689    Widget_Data *wd = elm_widget_data_get(data);
690    Evas_Coord minh = -1, resw = -1, minw = -1, fw = 0, fh = 0;
691    if (!wd) return;
692    wd->deferred_recalc_job = NULL;
693
694    evas_object_geometry_get(wd->ent, NULL, NULL, &resw, NULL);
695    edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
696    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
697    /* This is a hack to workaround the way min size hints are treated.
698     * If the minimum width is smaller than the restricted width, it means
699     * the mininmum doesn't matter. */
700    if (minw <= resw)
701      {
702         Evas_Coord ominw = -1;
703         evas_object_size_hint_min_get(data, &ominw, NULL);
704         minw = ominw;
705      }
706
707    wd->entmw = minw;
708    wd->entmh = minh;
709
710    elm_coords_finger_size_adjust(1, &fw, 1, &fh);
711    if (wd->scroll)
712      {
713         Evas_Coord vmw = 0, vmh = 0;
714
715         edje_object_size_min_calc
716            (elm_smart_scroller_edje_object_get(wd->scroller),
717                &vmw, &vmh);
718         if (wd->single_line)
719           {
720              evas_object_size_hint_min_set(data, vmw, minh + vmh);
721              evas_object_size_hint_max_set(data, -1, minh + vmh);
722           }
723         else
724           {
725              evas_object_size_hint_min_set(data, vmw, vmh);
726              evas_object_size_hint_max_set(data, -1, -1);
727           }
728      }
729    else
730      {
731         if (wd->single_line)
732           {
733              evas_object_size_hint_min_set(data, minw, minh);
734              evas_object_size_hint_max_set(data, -1, minh);
735           }
736         else
737           {
738              evas_object_size_hint_min_set(data, fw, minh);
739              evas_object_size_hint_max_set(data, -1, -1);
740           }
741      }
742
743    if (wd->deferred_cur)
744      {
745         Evas_Coord cx, cy, cw, ch;
746         edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
747                                                   &cx, &cy, &cw, &ch);
748         if (wd->cur_changed)
749           {
750              elm_widget_show_region_set(data, cx, cy, cw, ch, EINA_FALSE);
751              wd->cur_changed = EINA_FALSE;
752           }
753      }
754 }
755
756 static void
757 _sizing_eval(Evas_Object *obj)
758 {
759    Widget_Data *wd = elm_widget_data_get(obj);
760    Evas_Coord minw = -1, minh = -1;
761    Evas_Coord resw, resh;
762    if (!wd) return;
763
764    evas_object_geometry_get(obj, NULL, NULL, &resw, &resh);
765    if (wd->linewrap)
766      {
767         if ((resw == wd->lastw) && (!wd->changed)) return;
768         evas_event_freeze(evas_object_evas_get(obj));
769         wd->changed = EINA_FALSE;
770         wd->lastw = resw;
771         if (wd->scroll)
772           {
773              Evas_Coord vw = 0, vh = 0, vmw = 0, vmh = 0, w = -1, h = -1;
774
775              evas_object_resize(wd->scroller, resw, resh);
776              edje_object_size_min_calc
777                 (elm_smart_scroller_edje_object_get(wd->scroller),
778                  &vmw, &vmh);
779              elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
780              edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, vw, 0);
781              elm_coords_finger_size_adjust(1, &minw, 1, &minh);
782              /* This is a hack to workaround the way min size hints are treated.
783               * If the minimum width is smaller than the restricted width, it means
784               * the mininmum doesn't matter. */
785              if (minw <= vw)
786                {
787                   Evas_Coord ominw = -1;
788                   evas_object_size_hint_min_get(wd->ent, &ominw, NULL);
789                   minw = ominw;
790                }
791              wd->entmw = minw;
792              wd->entmh = minh;
793
794              if ((minw > 0) && (vw < minw)) vw = minw;
795              if (minh > vh) vh = minh;
796
797              if (wd->single_line) h = vmh + minh;
798              else h = vmh;
799              evas_object_resize(wd->ent, vw, vh);
800              evas_object_size_hint_min_set(obj, w, h);
801              if (wd->single_line)
802                evas_object_size_hint_max_set(obj, -1, h);
803              else
804                evas_object_size_hint_max_set(obj, -1, -1);
805           }
806         else
807           {
808              if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
809              wd->deferred_recalc_job = ecore_job_add(_elm_deferred_recalc_job, obj);
810           }
811         evas_event_thaw(evas_object_evas_get(obj));
812         evas_event_thaw_eval(evas_object_evas_get(obj));
813      }
814    else
815      {
816         if (!wd->changed) return;
817         evas_event_freeze(evas_object_evas_get(obj));
818         wd->changed = EINA_FALSE;
819         wd->lastw = resw;
820         if (wd->scroll)
821           {
822              Evas_Coord vw = 0, vh = 0, vmw = 0, vmh = 0, w = -1, h = -1;
823
824              edje_object_size_min_calc(wd->ent, &minw, &minh);
825              wd->entmw = minw;
826              wd->entmh = minh;
827              elm_coords_finger_size_adjust(1, &minw, 1, &minh);
828
829              elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
830
831              if (minw > vw) vw = minw;
832              if (minh > vh) vh = minh;
833
834              evas_object_resize(wd->ent, vw, vh);
835              edje_object_size_min_calc
836                 (elm_smart_scroller_edje_object_get(wd->scroller),
837                  &vmw, &vmh);
838              if (wd->single_line) h = vmh + minh;
839              else h = vmh;
840              evas_object_size_hint_min_set(obj, w, h);
841              if (wd->single_line)
842                evas_object_size_hint_max_set(obj, -1, h);
843              else
844                evas_object_size_hint_max_set(obj, -1, -1);
845           }
846         else
847           {
848              edje_object_size_min_calc(wd->ent, &minw, &minh);
849              wd->entmw = minw;
850              wd->entmh = minh;
851              elm_coords_finger_size_adjust(1, &minw, 1, &minh);
852              evas_object_size_hint_min_set(obj, minw, minh);
853              if (wd->single_line)
854                evas_object_size_hint_max_set(obj, -1, minh);
855              else
856                evas_object_size_hint_max_set(obj, -1, -1);
857           }
858         evas_event_thaw(evas_object_evas_get(obj));
859         evas_event_thaw_eval(evas_object_evas_get(obj));
860      }
861
862    _recalc_cursor_geometry(obj);
863 }
864
865 static void
866 _check_enable_return_key(Evas_Object *obj)
867 {
868    Widget_Data *wd = elm_widget_data_get(obj);
869    Eina_Bool return_key_disabled = EINA_FALSE;
870    if (!wd) return;
871
872    if (!wd->autoreturnkey) return;
873
874    if (elm_entry_is_empty(obj) == EINA_TRUE)
875      return_key_disabled = EINA_TRUE;
876
877    elm_entry_input_panel_return_key_disabled_set(obj, return_key_disabled);
878 }
879
880 static void
881 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
882 {
883    Widget_Data *wd = elm_widget_data_get(obj);
884    Evas_Object *top = elm_widget_top_get(obj);
885    if (!wd) return;
886    if (!wd->editable)
887      {
888         if ((!elm_widget_focus_get(obj)) && (wd->api) && (wd->api->obj_hidemenu))
889           wd->api->obj_hidemenu(obj);
890         return;
891      }
892    if (elm_widget_focus_get(obj))
893      {
894         printf("[Elm_entry::Focused] obj : %p\n", obj);
895         evas_object_focus_set(wd->ent, EINA_TRUE);
896         edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
897         if (top && wd->input_panel_enable)
898           elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
899         evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
900         _check_enable_return_key(obj);
901         wd->mgf_type = _ENTRY_MAGNIFIER_FIXEDSIZE;
902      }
903    else
904      {
905         printf("[Elm_entry::Unfocused] obj : %p\n", obj);
906         edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
907         evas_object_focus_set(wd->ent, EINA_FALSE);
908         if (top && wd->input_panel_enable)
909           elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
910         evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
911
912         if ((wd->api) && (wd->api->obj_hidemenu))
913           {
914              wd->api->obj_hidemenu(obj);
915           }
916      }
917 }
918
919 static void
920 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
921 {
922    Widget_Data *wd = elm_widget_data_get(obj);
923    Evas_Object *edje;
924    Evas_Object *prev_content;
925    if ((!wd) || (!content)) return;
926
927    if (wd->scroll)
928       edje = elm_smart_scroller_edje_object_get(wd->scroller);
929    else
930       edje = wd->ent;
931
932    if (!part || !strcmp(part, "icon"))
933      {
934         prev_content = edje_object_part_swallow_get(edje, "elm.swallow.icon");
935         edje_object_signal_emit(edje, "elm,action,show,icon", "elm");
936      }
937    else if (!strcmp(part, "end"))
938      {
939         prev_content = edje_object_part_swallow_get(edje, "elm.swallow.end");
940         edje_object_signal_emit(edje, "elm,action,show,end", "elm");
941      }
942    else
943      prev_content = edje_object_part_swallow_get(edje, part);
944
945    if (prev_content) evas_object_del(prev_content);
946
947    evas_event_freeze(evas_object_evas_get(obj));
948    elm_widget_sub_object_add(obj, content);
949
950    if (!part || !strcmp(part, "icon"))
951      edje_object_part_swallow(edje, "elm.swallow.icon", content);
952    else if (!strcmp(part, "end"))
953      edje_object_part_swallow(edje, "elm.swallow.end", content);
954    else
955      edje_object_part_swallow(edje, part, content);
956
957    _sizing_eval(obj);
958    evas_event_thaw(evas_object_evas_get(obj));
959    evas_event_thaw_eval(evas_object_evas_get(obj));
960 }
961
962 static Evas_Object *
963 _content_unset_hook(Evas_Object *obj, const char *part)
964 {
965    Widget_Data *wd = elm_widget_data_get(obj);
966    Evas_Object *content, *edje;
967    if (!wd) return NULL;
968
969    if (wd->scroll)
970       edje = elm_smart_scroller_edje_object_get(wd->scroller);
971    else
972       edje = wd->ent;
973
974    if (!part || !strcmp(part, "icon"))
975      {
976         edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
977         content = edje_object_part_swallow_get(edje, "elm.swallow.icon");
978      }
979    else if (!strcmp(part, "end"))
980      {
981         edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
982         content = edje_object_part_swallow_get(edje, "elm.swallow.end");
983      }
984    else
985      content = edje_object_part_swallow_get(edje, part);
986
987    edje_object_part_swallow(edje, part, NULL);
988    if (!content) return NULL;
989    evas_event_freeze(evas_object_evas_get(obj));
990    elm_widget_sub_object_del(obj, content);
991    edje_object_part_unswallow(wd->ent, content);
992    _sizing_eval(obj);
993    evas_event_thaw(evas_object_evas_get(obj));
994    evas_event_thaw_eval(evas_object_evas_get(obj));
995
996    return content;
997 }
998
999 static Evas_Object *
1000 _content_get_hook(const Evas_Object *obj, const char *part)
1001 {
1002    Widget_Data *wd = elm_widget_data_get(obj);
1003    Evas_Object *content = NULL, *edje;
1004    if (!wd) return NULL;
1005
1006    if (wd->scroll)
1007       edje = elm_smart_scroller_edje_object_get(wd->scroller);
1008    else
1009       edje = wd->ent;
1010
1011    if (!edje) return NULL;
1012
1013    if (!part || !strcmp(part, "icon"))
1014      content = edje_object_part_swallow_get(edje, "elm.swallow.icon");
1015    else if (!strcmp(part, "end"))
1016      content = edje_object_part_swallow_get(edje, "elm.swallow.end");
1017    else
1018      content = edje_object_part_swallow_get(edje, part);
1019
1020    return content;
1021 }
1022
1023 static void
1024 _translate_hook(Evas_Object *obj)
1025 {
1026    evas_object_smart_callback_call(obj, "language,changed", NULL);
1027 }
1028
1029 static Eina_Bool
1030 _event_hook(Evas_Object *obj, Evas_Object *src, Evas_Callback_Type type, void *event_info)
1031 {
1032    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
1033    Evas_Event_Key_Down *ev = event_info;
1034    Widget_Data *wd = elm_widget_data_get(obj);
1035    if (!wd) return EINA_FALSE;
1036    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
1037    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
1038    return EINA_TRUE;
1039 }
1040
1041 static void
1042 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
1043 {
1044    Widget_Data *wd = elm_widget_data_get(obj);
1045    if (!wd) return;
1046    edje_object_signal_emit(wd->ent, emission, source);
1047    if (wd->scroller)
1048      edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scroller),
1049                              emission, source);
1050 }
1051
1052 static void
1053 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
1054 {
1055    Widget_Data *wd = elm_widget_data_get(obj);
1056    if (!wd) return;
1057    edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
1058    if (wd->scroller)
1059      edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scroller),
1060                                      emission, source, func_cb, data);
1061 }
1062
1063 static void
1064 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
1065 {
1066    Widget_Data *wd = elm_widget_data_get(obj);
1067    edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
1068                                         data);
1069    if (wd->scroller)
1070      edje_object_signal_callback_del_full(elm_smart_scroller_edje_object_get(wd->scroller),
1071                                           emission, source, func_cb, data);
1072 }
1073
1074 static void
1075 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1076 {
1077    Widget_Data *wd = elm_widget_data_get(obj);
1078    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
1079 }
1080
1081 static void
1082 _focus_region_hook(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
1083 {
1084    Widget_Data *wd = elm_widget_data_get(obj);
1085    if (wd->scroll)
1086      elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
1087 }
1088
1089 static void
1090 _show_region_hook(void *data, Evas_Object *obj)
1091 {
1092    Widget_Data *wd = elm_widget_data_get(data);
1093    Evas_Coord x, y, w, h;
1094    if (!wd) return;
1095    elm_widget_show_region_get(obj, &x, &y, &w, &h);
1096    if (wd->scroll)
1097      elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
1098 }
1099
1100 static void
1101 _sub_del(void *data, Evas_Object *obj, void *event_info)
1102 {
1103    Widget_Data *wd = data;
1104    Evas_Object *sub = event_info;
1105    Evas_Object *edje;
1106
1107    if (wd->scroll)
1108       edje = elm_smart_scroller_edje_object_get(wd->scroller);
1109    else
1110       edje = wd->ent;
1111
1112    if (sub == edje_object_part_swallow_get(edje, "elm.swallow.icon"))
1113      {
1114         edje_object_part_unswallow(edje, sub);
1115         if (edje)
1116           edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
1117      }
1118    else if (sub == edje_object_part_swallow_get(edje, "elm.swallow.end"))
1119      {
1120         edje_object_part_unswallow(edje, sub);
1121         if (edje)
1122           edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
1123      }
1124    _sizing_eval(obj);
1125 }
1126
1127 static void
1128 _hoversel_position(Evas_Object *obj)
1129 {
1130    Widget_Data *wd = elm_widget_data_get(obj);
1131    Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
1132    if (!wd) return;
1133
1134    cx = cy = 0;
1135    cw = ch = 1;
1136    evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1137    if (wd->usedown)
1138      {
1139         cx = wd->downx - x;
1140         cy = wd->downy - y;
1141         cw = 1;
1142         ch = 1;
1143      }
1144    else
1145      edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1146                                                &cx, &cy, &cw, &ch);
1147    evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
1148    if (cw < mw)
1149      {
1150         cx += (cw - mw) / 2;
1151         cw = mw;
1152      }
1153    if (ch < mh)
1154      {
1155         cy += (ch - mh) / 2;
1156         ch = mh;
1157      }
1158    evas_object_move(wd->hoversel, x + cx, y + cy);
1159    evas_object_resize(wd->hoversel, cw, ch);
1160 }
1161
1162 static void
1163 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1164 {
1165    Widget_Data *wd = elm_widget_data_get(data);
1166
1167    if (wd->hoversel) _hoversel_position(data);
1168
1169    if (!_elm_config->desktop_entry)
1170      {
1171         if (wd->region_get_job) ecore_job_del(wd->region_get_job);
1172         wd->region_get_job = ecore_job_add(_region_get_job, data);
1173      }
1174 }
1175
1176 static void
1177 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1178 {
1179    Widget_Data *wd = elm_widget_data_get(data);
1180    if (!wd) return;
1181
1182    if (wd->linewrap)
1183      {
1184         _sizing_eval(data);
1185      }
1186    else if (wd->scroll)
1187      {
1188         Evas_Coord vw = 0, vh = 0;
1189
1190         elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
1191         if (vw < wd->entmw) vw = wd->entmw;
1192         if (vh < wd->entmh) vh = wd->entmh;
1193         evas_object_resize(wd->ent, vw, vh);
1194      }
1195    if (wd->hoversel) _hoversel_position(data);
1196
1197    if (!_elm_config->desktop_entry)
1198      {
1199         if (wd->region_get_job) ecore_job_del(wd->region_get_job);
1200         wd->region_get_job = ecore_job_add(_region_get_job, data);
1201      }
1202 }
1203
1204 static void
1205 _hover_del(void *data)
1206 {
1207    Widget_Data *wd = elm_widget_data_get(data);
1208    if (!wd) return;
1209
1210    if (wd->hoversel)
1211      {
1212         evas_object_del(wd->hoversel);
1213         wd->hoversel = NULL;
1214      }
1215    wd->hovdeljob = NULL;
1216 }
1217
1218 static void
1219 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1220 {
1221    Widget_Data *wd = elm_widget_data_get(data);
1222    if (!wd) return;
1223    wd->usedown = 0;
1224    if (wd->hoversel) evas_object_hide(wd->hoversel);
1225    if (wd->selmode)
1226      {
1227         if (!_elm_config->desktop_entry)
1228           {
1229              if (!wd->password)
1230                edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
1231           }
1232      }
1233    elm_widget_scroll_freeze_pop(data);
1234    if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
1235    wd->hovdeljob = ecore_job_add(_hover_del, data);
1236 }
1237
1238 static void
1239 _selectall(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1240 {
1241    Widget_Data *wd = elm_widget_data_get(data);
1242    if (!wd) return;
1243    wd->selmode = EINA_TRUE;
1244    edje_object_part_text_select_none(wd->ent, "elm.text");
1245    edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
1246    edje_object_part_text_select_all(wd->ent, "elm.text");
1247    elm_object_scroll_freeze_pop(data);
1248 }
1249
1250 static void
1251 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1252 {
1253    Widget_Data *wd = elm_widget_data_get(data);
1254    if (!wd) return;
1255    wd->selmode = EINA_TRUE;
1256    edje_object_part_text_select_none(wd->ent, "elm.text");
1257    if (!_elm_config->desktop_entry)
1258      {
1259         if (!wd->password)
1260           edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
1261      }
1262    edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
1263    if (!_elm_config->desktop_entry)
1264       elm_object_scroll_freeze_pop(data);  // TIZEN ONLY
1265       //elm_widget_scroll_hold_push(data);
1266 }
1267
1268 static char *
1269 _remove_item_tags(const char *str)
1270 {
1271    char *ret;
1272    if (!str)
1273      return NULL;
1274
1275    Eina_Strbuf *buf = eina_strbuf_new();
1276    if (!buf)
1277      return NULL;
1278
1279    if (!eina_strbuf_append(buf, str))
1280      return NULL;
1281
1282    while (EINA_TRUE)
1283      {
1284         const char *temp = eina_strbuf_string_get(buf);
1285
1286         char *startTag = NULL;
1287         char *endTag = NULL;
1288
1289         startTag = strstr(temp, "<item");
1290         if (!startTag)
1291           startTag = strstr(temp, "</item");
1292         if (startTag)
1293           endTag = strstr(startTag, ">");
1294         else
1295           break;
1296         if (!endTag || startTag > endTag)
1297           break;
1298
1299         size_t sindex = startTag - temp;
1300         size_t eindex = endTag - temp + 1;
1301         if (!eina_strbuf_remove(buf, sindex, eindex))
1302           break;
1303      }
1304    ret = eina_strbuf_string_steal(buf);
1305    eina_strbuf_free(buf);
1306    return ret;
1307 }
1308
1309 void
1310 _elm_entry_entry_paste(Evas_Object *obj, const char *entry)
1311 {
1312    Widget_Data *wd = elm_widget_data_get(obj);
1313    char *str = NULL;
1314
1315    if (wd->cnp_mode == ELM_CNP_MODE_NO_IMAGE)
1316      {
1317         str = _remove_item_tags(entry);
1318         if (!str) str = strdup(entry);
1319      }
1320    else
1321      str = strdup(entry);
1322    if (!str) str = (char *)entry;
1323
1324    edje_object_part_text_user_insert(wd->ent, "elm.text", str);
1325    if (str != entry) free(str);
1326
1327    // start for cbhm
1328 #ifdef HAVE_ELEMENTARY_X
1329    if (cnpwidgetdata == obj)
1330       ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
1331 #endif
1332    // end for cbhm
1333 }
1334
1335 static void
1336 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1337 {
1338    Widget_Data *wd = elm_widget_data_get(data);
1339    if (!wd) return;
1340    evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1341    if (wd->sel_notify_handler)
1342      {
1343 #ifdef HAVE_ELEMENTARY_X
1344         Elm_Sel_Format formats = ELM_SEL_FORMAT_MARKUP;
1345         wd->selection_asked = EINA_TRUE;
1346         if (wd->cnp_mode == ELM_CNP_MODE_PLAINTEXT)
1347           formats = ELM_SEL_FORMAT_TEXT;
1348         else if (wd->cnp_mode != ELM_CNP_MODE_NO_IMAGE)
1349           formats |= ELM_SEL_FORMAT_IMAGE;
1350         elm_cnp_selection_get(data, ELM_SEL_TYPE_CLIPBOARD, formats, NULL, NULL);
1351 #endif
1352      }
1353 }
1354
1355 static void
1356 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
1357 {
1358    Widget_Data *wd = elm_widget_data_get(obj);
1359    const char *sel;
1360
1361    if (!wd) return;
1362    sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
1363    if ((!sel) || (!sel[0])) return; /* avoid deleting our own selection */
1364    elm_cnp_selection_set(obj, seltype, ELM_SEL_FORMAT_MARKUP, sel, strlen(sel));
1365    if (seltype == ELM_SEL_TYPE_CLIPBOARD)
1366      eina_stringshare_replace(&wd->cut_sel, sel);
1367 }
1368
1369 static void
1370 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1371 {
1372    Widget_Data *wd = elm_widget_data_get(data);
1373
1374    /* Store it */
1375    wd->selmode = EINA_FALSE;
1376    if (!_elm_config->desktop_entry)
1377      edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1378    edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1379    if (!_elm_config->desktop_entry)
1380      elm_widget_scroll_hold_pop(data);
1381    _store_selection(ELM_SEL_TYPE_CLIPBOARD, data);
1382    edje_object_part_text_user_insert(wd->ent, "elm.text", "");
1383    _sizing_eval(data);
1384 }
1385
1386 static void
1387 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1388 {
1389    Widget_Data *wd = elm_widget_data_get(data);
1390    if (!wd) return;
1391    wd->selmode = EINA_FALSE;
1392    if (!_elm_config->desktop_entry)
1393      {
1394         edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1395         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1396         elm_widget_scroll_hold_pop(data);
1397      }
1398    _store_selection(ELM_SEL_TYPE_CLIPBOARD, data);
1399    //   edje_object_part_text_select_none(wd->ent, "elm.text");
1400 }
1401
1402 static void
1403 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1404 {
1405    Widget_Data *wd = elm_widget_data_get(data);
1406    if (!wd) return;
1407    wd->selmode = EINA_FALSE;
1408    if (!_elm_config->desktop_entry)
1409      edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1410    edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1411    if (!_elm_config->desktop_entry)
1412      elm_widget_scroll_hold_pop(data);
1413    edje_object_part_text_select_none(wd->ent, "elm.text");
1414 }
1415
1416 // start for cbhm
1417 static void
1418 _cnpinit(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1419 {
1420    Widget_Data *wd = elm_widget_data_get(data);
1421    if (!wd) return;
1422    cnpwidgetdata = data;
1423 }
1424 // end for cbhm
1425
1426
1427 static void
1428 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1429 {
1430    Elm_Entry_Context_Menu_Item *it = data;
1431    Evas_Object *obj2 = it->obj;
1432    if (it->func) it->func(it->data, obj2, NULL);
1433 }
1434
1435 static void
1436 _menu_press(Evas_Object *obj)
1437 {
1438    Widget_Data *wd = elm_widget_data_get(obj);
1439    Evas_Object *top;
1440    const Eina_List *l;
1441    const Elm_Entry_Context_Menu_Item *it;
1442    if (!wd) return;
1443    if ((wd->api) && (wd->api->obj_longpress))
1444      {
1445         wd->api->obj_longpress(obj);
1446      }
1447    else if (wd->context_menu)
1448      {
1449         const char *context_menu_orientation;
1450
1451         if (wd->hoversel) evas_object_del(wd->hoversel);
1452         else elm_widget_scroll_freeze_push(obj);
1453         wd->hoversel = elm_hoversel_add(obj);
1454         context_menu_orientation = edje_object_data_get
1455            (wd->ent, "context_menu_orientation");
1456         if ((context_menu_orientation) &&
1457             (!strcmp(context_menu_orientation, "horizontal")))
1458           elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
1459         elm_object_style_set(wd->hoversel, "entry");
1460         elm_widget_sub_object_add(obj, wd->hoversel);
1461         elm_object_text_set(wd->hoversel, "Text");
1462         top = elm_widget_top_get(obj);
1463         if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
1464         evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, obj);
1465         if (wd->have_selection)
1466           {
1467              if (!wd->password)
1468                {
1469                   if (wd->have_selection)
1470                     {
1471                        elm_hoversel_item_add(wd->hoversel, E_("Copy"), NULL, ELM_ICON_NONE,
1472                                              _copy, obj);
1473                        if (wd->editable)
1474                          elm_hoversel_item_add(wd->hoversel, E_("Cut"), NULL, ELM_ICON_NONE,
1475                                                _cut, obj);
1476                     }
1477                   elm_hoversel_item_add(wd->hoversel, E_("Cancel"), NULL, ELM_ICON_NONE,
1478                                         _cancel, obj);
1479                }
1480           }
1481         else
1482           {
1483              if (!wd->selmode)
1484                {
1485                   if (!_elm_config->desktop_entry)
1486                     {
1487                        if (!wd->password)
1488                          elm_hoversel_item_add(wd->hoversel, E_("Select"), NULL, ELM_ICON_NONE,
1489                                                _select, obj);
1490                     }
1491                   if (elm_selection_selection_has_owner())
1492                     {
1493                        if (wd->editable)
1494                          elm_hoversel_item_add(wd->hoversel, E_("Paste"), NULL, ELM_ICON_NONE,
1495                                                _paste, obj);
1496                     }
1497                }
1498           }
1499         EINA_LIST_FOREACH(wd->items, l, it)
1500           {
1501              elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
1502                                    it->icon_type, _item_clicked, it);
1503           }
1504         if (wd->hoversel)
1505           {
1506              _hoversel_position(obj);
1507              evas_object_show(wd->hoversel);
1508              elm_hoversel_hover_begin(wd->hoversel);
1509           }
1510         if (!_elm_config->desktop_entry)
1511           {
1512              edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1513              edje_object_part_text_select_abort(wd->ent, "elm.text");
1514           }
1515      }
1516 }
1517
1518 static void
1519 _magnifier_hide(void *data)
1520 {
1521    Widget_Data *wd = elm_widget_data_get(data);
1522    if (!wd) return;
1523
1524    evas_object_hide(wd->mgf_bg);
1525    evas_object_hide(wd->mgf_clip);
1526
1527    if (wd->scroll)
1528      elm_smart_scroller_freeze_set(wd->scroller, EINA_FALSE);
1529 }
1530
1531 static void
1532 _magnifier_show(void *data)
1533 {
1534    Widget_Data *wd = elm_widget_data_get(data);
1535    if (!wd) return;
1536
1537    evas_object_show(wd->mgf_bg);
1538    evas_object_show(wd->mgf_clip);
1539 }
1540
1541 static void
1542 _magnifier_move(void *data)
1543 {
1544    Widget_Data *wd = elm_widget_data_get(data);
1545    if (!wd) return;
1546
1547    Evas_Coord x, y, w, h;
1548    Evas_Coord cx, cy, cw, ch, ox, oy;
1549
1550    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1551
1552    if (wd->scroll)
1553      {
1554         evas_object_geometry_get(wd->scroller, &x, &y, &w, &h);
1555         elm_smart_scroller_child_pos_get(wd->scroller, &ox, &oy);
1556         cx -= ox;
1557         cy -= oy;
1558      }
1559    else
1560      evas_object_geometry_get(data, &x, &y, &w, &h);
1561
1562    ox = oy = 0;
1563
1564    if ((cy + y) - wd->mgf_height < 0)
1565      oy = -1 * ((cy + y) - wd->mgf_height);
1566
1567    if (wd->mgf_type == _ENTRY_MAGNIFIER_FIXEDSIZE)
1568      evas_object_move(wd->mgf_bg, (cx + x + cw/2) + ox, (cy + y) - wd->mgf_height + oy);
1569    else if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1570      evas_object_move(wd->mgf_bg, x, (cy + y) - wd->mgf_height + oy);
1571    else
1572      return;
1573
1574    evas_object_move(wd->mgf_proxy, (1 - wd->mgf_scale) * cx + x + ox, (1 - wd->mgf_scale) * cy + y - wd->mgf_height/2 - ch/2 + oy);
1575 }
1576
1577 static void
1578 _magnifier_create(void *data)
1579 {
1580    Widget_Data *wd = elm_widget_data_get(data);
1581    Evas_Coord x, y, w, h, mw, mh;
1582    const char* key_data = NULL;
1583    double elm_scale;
1584
1585    if (!wd) return;
1586
1587    if (wd->mgf_proxy)
1588      {
1589         evas_object_image_source_unset(wd->mgf_proxy);
1590         evas_object_color_set(wd->mgf_proxy, 255, 255, 255, 0);
1591         evas_object_hide(wd->mgf_proxy);
1592         evas_object_clip_unset(wd->mgf_proxy);
1593         evas_object_del(wd->mgf_proxy);
1594      }
1595    if (wd->mgf_bg) evas_object_del(wd->mgf_bg);
1596    if (wd->mgf_clip) evas_object_del(wd->mgf_clip);
1597
1598    if (wd->scroll)
1599      evas_object_geometry_get(wd->scroller, &x, &y, &w, &h);
1600    else
1601      evas_object_geometry_get(data, &x, &y, &w, &h);
1602
1603    if ((w <= 0) || (h <= 0))
1604      return;
1605
1606    wd->mgf_bg = edje_object_add(evas_object_evas_get(data));
1607
1608    if (wd->mgf_type == _ENTRY_MAGNIFIER_FIXEDSIZE)
1609      _elm_theme_object_set(data, wd->mgf_bg, "entry", "magnifier", "fixed-size");
1610    else if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1611      _elm_theme_object_set(data, wd->mgf_bg, "entry", "magnifier", "fill-width");
1612    else
1613      return;
1614
1615    wd->mgf_clip = evas_object_rectangle_add(evas_object_evas_get(data));
1616    evas_object_color_set(wd->mgf_clip, 255, 255, 255, 255);
1617    edje_object_part_swallow(wd->mgf_bg, "swallow", wd->mgf_clip);
1618
1619    key_data = edje_object_data_get(wd->mgf_bg, "height");
1620    if (key_data) wd->mgf_height = atoi(key_data);
1621    key_data = edje_object_data_get(wd->mgf_bg, "scale");
1622    if (key_data) wd->mgf_scale = atof(key_data);
1623
1624    elm_scale = elm_config_scale_get();
1625    wd->mgf_height = (int)((float)wd->mgf_height * elm_scale);
1626
1627    if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1628      evas_object_resize(wd->mgf_bg, w, wd->mgf_height);
1629
1630    if (wd->scroll)
1631      {
1632         elm_smart_scroller_freeze_set(wd->scroller, EINA_TRUE);
1633         wd->mgf_proxy = evas_object_image_add(evas_object_evas_get(wd->scroller));
1634         evas_object_image_source_set(wd->mgf_proxy, wd->scroller);
1635      }
1636    else
1637      {
1638         wd->mgf_proxy = evas_object_image_add(evas_object_evas_get(data));
1639         evas_object_image_source_set(wd->mgf_proxy, data);
1640      }
1641
1642    mw = (Evas_Coord)((float)w * wd->mgf_scale);
1643    mh = (Evas_Coord)((float)h * wd->mgf_scale);
1644    if ((mw <= 0) || (mh <= 0))
1645      return;
1646
1647    evas_object_resize(wd->mgf_proxy, mw, mh);
1648    evas_object_image_fill_set(wd->mgf_proxy, 0, 0, mw, mh);
1649    evas_object_color_set(wd->mgf_proxy, 255, 255, 255, 255);
1650    evas_object_pass_events_set(wd->mgf_proxy, EINA_TRUE);
1651    evas_object_show(wd->mgf_proxy);
1652    evas_object_clip_set(wd->mgf_proxy, wd->mgf_clip);
1653
1654    evas_object_layer_set(wd->mgf_bg, EVAS_LAYER_MAX);
1655    evas_object_layer_set(wd->mgf_proxy, EVAS_LAYER_MAX);
1656 }
1657
1658 static void
1659 _signal_long_pressed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1660 {
1661    Widget_Data *wd = elm_widget_data_get(data);
1662
1663    if (!wd) return;
1664    wd->long_pressed = EINA_TRUE;
1665    _cancel(data, NULL, NULL);
1666    if (wd->magnifier_enabled)
1667      {
1668         _magnifier_create(data);
1669         _magnifier_move(data);
1670         _magnifier_show(data);
1671         elm_object_scroll_freeze_push(data);
1672      }
1673 }
1674
1675 static Eina_Bool
1676 _long_press(void *data)
1677 {
1678    Widget_Data *wd = elm_widget_data_get(data);
1679    if (!wd) return ECORE_CALLBACK_CANCEL;
1680    if ((!_elm_config->desktop_entry) && (!wd->magnifier_enabled))
1681      _menu_press(data); /////// TIZEN ONLY
1682    wd->longpress_timer = NULL;
1683    evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
1684    return ECORE_CALLBACK_CANCEL;
1685 }
1686
1687 static void
1688 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1689 {
1690    Widget_Data *wd = elm_widget_data_get(data);
1691    Evas_Event_Mouse_Down *ev = event_info;
1692    if (!wd) return;
1693    if (wd->disabled) return;
1694    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1695    wd->downx = ev->canvas.x;
1696    wd->downy = ev->canvas.y;
1697    wd->long_pressed = EINA_FALSE;
1698    if (ev->button == 1)
1699      {
1700         if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
1701         wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1702      }
1703 }
1704
1705 static void
1706 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1707 {
1708    Widget_Data *wd = elm_widget_data_get(data);
1709    Evas_Event_Mouse_Up *ev = event_info;
1710    if (!wd) return;
1711    if (wd->disabled) return;
1712    if (ev->button == 1)
1713      {
1714         if (!wd->double_clicked)
1715           {
1716              if ((wd->api) && (wd->api->obj_mouseup))
1717                wd->api->obj_mouseup(data);
1718           }
1719         if (wd->magnifier_enabled)
1720           {
1721              _magnifier_hide(data);
1722              elm_object_scroll_freeze_pop(data);
1723              if (wd->long_pressed) _menu_press(data);
1724           }
1725         if (wd->longpress_timer)
1726           {
1727              ecore_timer_del(wd->longpress_timer);
1728              wd->longpress_timer = NULL;
1729           }
1730      }
1731    else if ((ev->button == 3) && (!_elm_config->desktop_entry))
1732      {
1733         wd->usedown = 1;
1734         _menu_press(data);
1735      }
1736 }
1737
1738 static void
1739 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1740 {
1741    Widget_Data *wd = elm_widget_data_get(data);
1742    Evas_Event_Mouse_Move *ev = event_info;
1743    if (!wd) return;
1744    if (wd->disabled) return;
1745
1746    if (ev->buttons == 1)
1747      {
1748         if ((wd->long_pressed) && (wd->magnifier_enabled))
1749           {
1750              _magnifier_show(data);
1751              _magnifier_move(data);
1752           }
1753      }
1754    if (!wd->selmode)
1755      {
1756         if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1757           {
1758              if (wd->longpress_timer)
1759                {
1760                   ecore_timer_del(wd->longpress_timer);
1761                   wd->longpress_timer = NULL;
1762                }
1763           }
1764         else if (wd->longpress_timer)
1765           {
1766              Evas_Coord dx, dy;
1767
1768              dx = wd->downx - ev->cur.canvas.x;
1769              dx *= dx;
1770              dy = wd->downy - ev->cur.canvas.y;
1771              dy *= dy;
1772              if ((dx + dy) >
1773                  ((_elm_config->finger_size / 2) *
1774                   (_elm_config->finger_size / 2)))
1775                {
1776                   ecore_timer_del(wd->longpress_timer);
1777                   wd->longpress_timer = NULL;
1778                }
1779           }
1780      }
1781    else if (wd->longpress_timer)
1782      {
1783         Evas_Coord dx, dy;
1784
1785         dx = wd->downx - ev->cur.canvas.x;
1786         dx *= dx;
1787         dy = wd->downy - ev->cur.canvas.y;
1788         dy *= dy;
1789         if ((dx + dy) >
1790             ((_elm_config->finger_size / 2) *
1791              (_elm_config->finger_size / 2)))
1792           {
1793              ecore_timer_del(wd->longpress_timer);
1794              wd->longpress_timer = NULL;
1795           }
1796      }
1797 }
1798
1799 static const char *
1800 _getbase(Evas_Object *obj)
1801 {
1802    Widget_Data *wd = elm_widget_data_get(obj);
1803    if (!wd) return "base";
1804    if (wd->editable)
1805      {
1806         if (wd->password) return "base-password";
1807         else
1808           {
1809              if (wd->single_line) return "base-single";
1810              else
1811                {
1812                   switch (wd->linewrap)
1813                     {
1814                      case ELM_WRAP_CHAR:
1815                         return "base-charwrap";
1816                      case ELM_WRAP_WORD:
1817                         return "base";
1818                      case ELM_WRAP_MIXED:
1819                         return "base-mixedwrap";
1820                      case ELM_WRAP_NONE:
1821                      default:
1822                         return "base-nowrap";
1823                     }
1824                }
1825           }
1826      }
1827    else
1828      {
1829         if (wd->password) return "base-password";
1830         else
1831           {
1832              if (wd->single_line) return "base-single-noedit";
1833              else
1834                {
1835                   switch (wd->linewrap)
1836                     {
1837                      case ELM_WRAP_CHAR:
1838                         return "base-noedit-charwrap";
1839                      case ELM_WRAP_WORD:
1840                         return "base-noedit";
1841                      case ELM_WRAP_MIXED:
1842                         return "base-noedit-mixedwrap";
1843                      case ELM_WRAP_NONE:
1844                      default:
1845                         return "base-nowrap-noedit";
1846                     }
1847                }
1848           }
1849      }
1850 }
1851
1852 static void
1853 _entry_changed_common_handling(void *data, const char *event)
1854 {
1855    Widget_Data *wd = elm_widget_data_get(data);
1856    Evas_Coord minh;
1857    if (!wd) return;
1858    evas_event_freeze(evas_object_evas_get(data));
1859    wd->changed = EINA_TRUE;
1860    /* Reset the size hints which are no more relevant.
1861     * Keep the height, this is a hack, but doesn't really matter
1862     * cause we'll re-eval in a moment. */
1863    evas_object_size_hint_min_get(data, NULL, &minh);
1864    evas_object_size_hint_min_set(data, -1, minh);
1865    _sizing_eval(data);
1866    if (wd->text) eina_stringshare_del(wd->text);
1867    wd->text = NULL;
1868    if (wd->password_text) eina_stringshare_del(wd->password_text);
1869    wd->password_text = NULL;
1870    if (wd->delay_write)
1871      {
1872         ecore_timer_del(wd->delay_write);
1873         wd->delay_write = NULL;
1874      }
1875
1876    if ((wd->api) && (wd->api->obj_hidemenu))
1877      wd->api->obj_hidemenu(data);
1878
1879    evas_event_thaw(evas_object_evas_get(data));
1880    evas_event_thaw_eval(evas_object_evas_get(data));
1881    if ((wd->autosave) && (wd->file))
1882      wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1883    /* callback - this could call callbacks that delete the entry... thus...
1884     * any access to wd after this could be invalid */
1885    evas_object_smart_callback_call(data, event, NULL);
1886    _check_enable_return_key(data);
1887 }
1888
1889 static void
1890 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1891 {
1892    _entry_changed_common_handling(data, SIG_CHANGED);
1893 }
1894
1895 static void
1896 _signal_handler_move_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1897 {
1898    Widget_Data *wd = elm_widget_data_get(data);
1899    if (!wd) return;
1900
1901    elm_object_scroll_freeze_push(data);
1902
1903    if ((wd->api) && (wd->api->obj_hidemenu))
1904      wd->api->obj_hidemenu(data);
1905
1906    if (wd->magnifier_enabled)
1907      {
1908         _magnifier_create(data);
1909         _magnifier_move(data);
1910         _magnifier_show(data);
1911      }
1912 }
1913
1914 static void
1915 _signal_handler_move_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1916 {
1917    Widget_Data *wd = elm_widget_data_get(data);
1918    if (!wd) return;
1919
1920    elm_object_scroll_freeze_pop(data);
1921
1922    if (wd->have_selection)
1923      {
1924         _magnifier_hide(data);
1925         _menu_press(data);
1926      }
1927 }
1928
1929 static void
1930 _signal_handler_moving(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1931 {
1932    Widget_Data *wd = elm_widget_data_get(data);
1933    if (!wd) return;
1934
1935    if (wd->magnifier_enabled)
1936      {
1937         _magnifier_move(data);
1938         _magnifier_show(data);
1939      }
1940 }
1941
1942 static Evas_Coord_Rectangle
1943 _intersection_region_get(Evas_Coord_Rectangle rect1, Evas_Coord_Rectangle rect2)
1944 {
1945    Evas_Coord_Rectangle ret_rect;
1946    Evas_Coord_Point l1, l2, r1, r2, p1, p2;
1947
1948    l1.x = rect1.x;
1949    l1.y = rect1.y;
1950    r1.x = rect1.x + rect1.w;
1951    r1.y = rect1.y + rect1.h;
1952
1953    l2.x = rect2.x;
1954    l2.y = rect2.y;
1955    r2.x = rect2.x + rect2.w;
1956    r2.y = rect2.y + rect2.h;
1957
1958    p1.x = (l1.x > l2.x) ? l1.x : l2.x;
1959    p1.y = (l1.y > l2.y) ? l1.y : l2.y;
1960    p2.x = (r1.x < r2.x) ? r1.x : r2.x;
1961    p2.y = (r1.y < r2.y) ? r1.y : r2.y;
1962
1963    ret_rect.x = p1.x;
1964    ret_rect.y = p1.y;
1965    ret_rect.w = (p2.x > p1.x) ? p2.x - p1.x : -1;
1966    ret_rect.h = (p2.y > p1.y) ? p2.y - p1.y : -1;
1967
1968    return ret_rect;
1969 }
1970
1971 static Evas_Coord_Rectangle
1972 _viewport_region_get(Evas_Object *data)
1973 {
1974    Evas_Coord_Rectangle geometry, ret_rect;
1975    geometry.x = geometry.y = geometry.w = geometry.h = -1;
1976    ret_rect = geometry;
1977
1978    Widget_Data *wd = elm_widget_data_get(data);
1979    if (!wd) return geometry;
1980    if (!data || !strlen(elm_widget_type_get(data))) return geometry;
1981
1982    if (wd->scroll)
1983      {
1984         evas_object_geometry_get(wd->scroller, &geometry.x, &geometry.y, &geometry.w, &geometry.h);
1985         ret_rect = geometry;
1986      }
1987
1988    Evas_Object *parent_obj = data;
1989
1990    while ((parent_obj = elm_widget_parent_get(parent_obj)))
1991      {
1992         if (!strcmp(elm_widget_type_get(parent_obj), "scroller") ||
1993             !strcmp(elm_widget_type_get(parent_obj), "genlist"))
1994           {
1995              evas_object_geometry_get(parent_obj, &geometry.x, &geometry.y, &geometry.w, &geometry.h);
1996              if ((ret_rect.w == -1) && (ret_rect.h == -1)) ret_rect = geometry;
1997              ret_rect = _intersection_region_get(geometry, ret_rect);
1998           }
1999      }
2000
2001    return ret_rect;
2002 }
2003
2004 static Evas_Coord_Rectangle
2005 _layout_region_get(Evas_Object *data)
2006 {
2007    Evas_Coord_Rectangle geometry;
2008    geometry.x = geometry.y = geometry.w = geometry.h = -1;
2009
2010    Widget_Data *wd = elm_widget_data_get(data);
2011    if (!wd) return geometry;
2012    if (!data || !strlen(elm_widget_type_get(data))) return geometry;
2013
2014    Evas_Object *child_obj = data;
2015    Evas_Object *parent_obj;
2016
2017    while ((parent_obj = elm_widget_parent_get(child_obj)))
2018      {
2019         if (!strcmp(elm_widget_type_get(parent_obj), "conformant"))
2020           {
2021              evas_object_geometry_get(child_obj, &geometry.x, &geometry.y, &geometry.w, &geometry.h);
2022              return geometry;
2023           }
2024         child_obj = parent_obj;
2025      }
2026
2027    return geometry;
2028 }
2029
2030 static void
2031 _region_get_job(void *data)
2032 {
2033    Widget_Data *wd = elm_widget_data_get(data);
2034    if (!wd) return;
2035    wd->region_get_job = NULL;
2036
2037    if (!_elm_config->desktop_entry)
2038      {
2039         if (wd->region_recalc_job) ecore_job_del(wd->region_recalc_job);
2040         wd->region_recalc_job = ecore_job_add(_region_recalc_job, data);
2041
2042         evas_smart_objects_calculate(evas_object_evas_get(data));
2043      }
2044 }
2045
2046 static void
2047 _region_recalc_job(void *data)
2048 {
2049    Widget_Data *wd = elm_widget_data_get(data);
2050    Evas_Coord_Rectangle ret_rect;
2051    if (!wd) return;
2052    wd->region_recalc_job = NULL;
2053
2054    if (!_elm_config->desktop_entry)
2055      {
2056         ret_rect = _viewport_region_get(data);
2057         edje_object_part_text_viewport_region_set(wd->ent, "elm.text", ret_rect.x, ret_rect.y, ret_rect.w, ret_rect.h);
2058         ret_rect = _layout_region_get(data);
2059         edje_object_part_text_layout_region_set(wd->ent, "elm.text", ret_rect.x, ret_rect.y, ret_rect.w, ret_rect.h);
2060      }
2061 }
2062
2063 static void
2064 _signal_selection_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2065 {
2066    Widget_Data *wd = elm_widget_data_get(data);
2067    if (!wd) return;
2068
2069    if (wd->magnifier_enabled)
2070      _magnifier_hide(data);
2071    _menu_press(data);
2072 }
2073
2074 static void
2075 _signal_entry_changed_user(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2076 {
2077    Elm_Entry_Change_Info info;
2078    Edje_Entry_Change_Info *edje_info = (Edje_Entry_Change_Info *)
2079       edje_object_signal_callback_extra_data_get();
2080    if (edje_info)
2081      {
2082         memcpy(&info, edje_info, sizeof(info));
2083         evas_object_smart_callback_call(data, SIG_CHANGED_USER, &info);
2084      }
2085    else
2086      {
2087         evas_object_smart_callback_call(data, SIG_CHANGED_USER, NULL);
2088      }
2089 }
2090
2091 static void
2092 _signal_preedit_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2093 {
2094    _entry_changed_common_handling(data, SIG_PREEDIT_CHANGED);
2095 }
2096
2097 static void
2098 _signal_undo_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2099 {
2100    evas_object_smart_callback_call(data, SIG_UNDO_REQUEST, NULL);
2101 }
2102
2103 static void
2104 _signal_redo_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2105 {
2106    evas_object_smart_callback_call(data, SIG_REDO_REQUEST, NULL);
2107 }
2108
2109 static void
2110 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2111 {
2112    Widget_Data *wd = elm_widget_data_get(data);
2113    const Eina_List *l;
2114    Evas_Object *entry;
2115    if (!wd) return;
2116    EINA_LIST_FOREACH(entries, l, entry)
2117      {
2118         if (entry != data) elm_entry_select_none(entry);
2119      }
2120    wd->have_selection = EINA_TRUE;
2121    wd->selmode = EINA_TRUE;
2122    evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
2123 #ifdef HAVE_ELEMENTARY_X
2124    if (wd->sel_notify_handler)
2125      {
2126         const char *txt = elm_entry_selection_get(data);
2127         Evas_Object *top;
2128
2129         top = elm_widget_top_get(data);
2130         if (txt && top && (elm_win_xwindow_get(top)))
2131           elm_cnp_selection_set(data, ELM_SEL_TYPE_PRIMARY,
2132                                 ELM_SEL_FORMAT_MARKUP, txt, strlen(txt));
2133      }
2134 #endif
2135 }
2136
2137 static void
2138 _signal_magnifier_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2139 {
2140    Evas_Coord cx, cy, cw, ch;
2141    Widget_Data *wd = elm_widget_data_get(data);
2142    if (!wd) return;
2143
2144    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
2145    if (!wd->deferred_recalc_job)
2146      elm_widget_show_region_set(data, cx, cy, cw, ch, EINA_FALSE);
2147    else
2148      {
2149         wd->deferred_cur = EINA_TRUE;
2150         wd->cx = cx;
2151         wd->cy = cy;
2152         wd->cw = cw;
2153         wd->ch = ch;
2154      }
2155 }
2156
2157 static void
2158 _signal_selection_all(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2159 {
2160    Widget_Data *wd = elm_widget_data_get(data);
2161    if (!wd) return;
2162    elm_entry_select_all(data);
2163 }
2164
2165 static void
2166 _signal_selection_none(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2167 {
2168    Widget_Data *wd = elm_widget_data_get(data);
2169    if (!wd) return;
2170    elm_entry_select_none(data);
2171 }
2172
2173 static void
2174 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2175 {
2176    Evas_Coord cx, cy, cw, ch;
2177    Widget_Data *wd = elm_widget_data_get(data);
2178    if (!wd) return;
2179    wd->have_selection = EINA_TRUE;
2180    wd->selmode = EINA_TRUE;
2181    evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
2182    _store_selection(ELM_SEL_TYPE_PRIMARY, data);
2183
2184 // TIZEN ONLY
2185    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
2186    if (!wd->deferred_recalc_job)
2187      elm_widget_show_region_set(data, cx, cy, cw, ch, EINA_FALSE);
2188    else
2189      {
2190         wd->deferred_cur = EINA_TRUE;
2191         wd->cx = cx;
2192         wd->cy = cy;
2193         wd->cw = cw;
2194         wd->ch = ch;
2195      }
2196 //
2197 }
2198
2199 static void
2200 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2201 {
2202    Widget_Data *wd = elm_widget_data_get(data);
2203    if (!wd) return;
2204    if (!wd->have_selection) return;
2205    wd->have_selection = EINA_FALSE;
2206    wd->selmode = EINA_FALSE;   /////////////// exist in ours only - necessary ? 
2207    evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
2208    if (wd->sel_notify_handler)
2209      {
2210         if (wd->cut_sel)
2211           {
2212 #ifdef HAVE_ELEMENTARY_X
2213              Evas_Object *top;
2214
2215              top = elm_widget_top_get(data);
2216              if ((top) && (elm_win_xwindow_get(top)))
2217                elm_cnp_selection_set(data, ELM_SEL_TYPE_PRIMARY,
2218                                      ELM_SEL_FORMAT_MARKUP, wd->cut_sel,
2219                                      strlen(wd->cut_sel));
2220 #endif
2221              eina_stringshare_del(wd->cut_sel);
2222              wd->cut_sel = NULL;
2223           }
2224         else
2225           {
2226 #ifdef HAVE_ELEMENTARY_X
2227              Evas_Object *top;
2228
2229              top = elm_widget_top_get(data);
2230              if ((top) && (elm_win_xwindow_get(top)))
2231                elm_object_cnp_selection_clear(data, ELM_SEL_TYPE_PRIMARY);
2232 #endif
2233           }
2234      }
2235
2236    if ((wd->api) && (wd->api->obj_hidemenu))
2237      {
2238         wd->api->obj_hidemenu(data);
2239      }
2240 }
2241
2242 static void
2243 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
2244 {
2245    Widget_Data *wd = elm_widget_data_get(data);
2246 #ifdef HAVE_ELEMENTARY_X
2247    Elm_Sel_Type type = (emission[sizeof("ntry,paste,request,")] == '1') ?
2248      ELM_SEL_TYPE_PRIMARY : ELM_SEL_TYPE_CLIPBOARD;
2249 #endif
2250
2251    if (!wd) return;
2252    if (!wd->editable) return;
2253    evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
2254    if (wd->sel_notify_handler)
2255      {
2256 #ifdef HAVE_ELEMENTARY_X
2257         Evas_Object *top;
2258
2259         top = elm_widget_top_get(data);
2260         if ((top) && (elm_win_xwindow_get(top)))
2261           {
2262              wd->selection_asked = EINA_TRUE;
2263              Elm_Sel_Format formats = ELM_SEL_FORMAT_MARKUP;
2264              if (wd->cnp_mode == ELM_CNP_MODE_PLAINTEXT)
2265                formats = ELM_SEL_FORMAT_TEXT;
2266              else if (wd->cnp_mode != ELM_CNP_MODE_NO_IMAGE)
2267                formats |= ELM_SEL_FORMAT_IMAGE;
2268              elm_cnp_selection_get(data, type, formats,
2269                                    NULL, NULL);
2270           }
2271 #endif
2272      }
2273 }
2274
2275 static void
2276 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2277 {
2278    evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
2279    _copy(data, NULL, NULL);
2280 }
2281
2282 static void
2283 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2284 {
2285    evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
2286    _cut(data, NULL, NULL);
2287 }
2288
2289 static void
2290 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2291 {
2292    Widget_Data *wd = elm_widget_data_get(data);
2293    if (!wd) return;
2294    wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2295    wd->cur_changed = EINA_TRUE;
2296    _recalc_cursor_geometry(data);
2297 }
2298
2299 static void
2300 _signal_cursor_changed_manual(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2301 {
2302    evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED_MANUAL, NULL);
2303 }
2304
2305
2306 static void
2307 _signal_anchor_geoms_do_things_with(Widget_Data *wd, Elm_Entry_Anchor_Info *ei)
2308 {
2309    const Eina_List *geoms, *l;
2310    Evas_Textblock_Rectangle *r;
2311    Evas_Coord px, py, x, y;
2312
2313    geoms = edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei->name);
2314    if (!geoms) return;
2315
2316
2317    evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
2318    evas_pointer_canvas_xy_get(evas_object_evas_get(wd->ent), &px, &py);
2319    EINA_LIST_FOREACH(geoms, l, r)
2320      {
2321         if (((r->x + x) <= px) && ((r->y + y) <= py) &&
2322             ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
2323           {
2324              ei->x = r->x + x;
2325              ei->y = r->y + y;
2326              ei->w = r->w;
2327              ei->h = r->h;
2328              break;
2329           }
2330      }
2331 }
2332
2333 static void
2334 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2335 {
2336    Widget_Data *wd = elm_widget_data_get(data);
2337    Elm_Entry_Anchor_Info ei;
2338    const char *p;
2339    char *p2;
2340    if (!wd) return;
2341    p = emission + sizeof("nchor,mouse,down,");
2342    ei.button = strtol(p, &p2, 10);
2343    ei.name = p2 + 1;
2344    ei.x = ei.y = ei.w = ei.h = 0;
2345
2346    _signal_anchor_geoms_do_things_with(wd, &ei);
2347
2348    if (!wd->disabled)
2349      evas_object_smart_callback_call(data, SIG_ANCHOR_DOWN, &ei);
2350 }
2351
2352 static void
2353 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2354 {
2355    Widget_Data *wd = elm_widget_data_get(data);
2356    Elm_Entry_Anchor_Info ei;
2357    const char *p;
2358    char *p2;
2359    if (!wd) return;
2360    p = emission + sizeof("nchor,mouse,up,");
2361    ei.button = strtol(p, &p2, 10);
2362    ei.name = p2 + 1;
2363    ei.x = ei.y = ei.w = ei.h = 0;
2364
2365    _signal_anchor_geoms_do_things_with(wd, &ei);
2366
2367    if (!wd->disabled)
2368      evas_object_smart_callback_call(data, SIG_ANCHOR_UP, &ei);
2369 }
2370
2371 static void
2372 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
2373 {
2374    Widget_Data *wd = elm_widget_data_get(data);
2375    Elm_Entry_Anchor_Info ei;
2376    const char *p;
2377    char *p2;
2378    if (!wd) return;
2379    p = emission + sizeof("nchor,mouse,clicked,");
2380    ei.button = strtol(p, &p2, 10);
2381    ei.name = p2 + 1;
2382    ei.x = ei.y = ei.w = ei.h = 0;
2383
2384    _signal_anchor_geoms_do_things_with(wd, &ei);
2385
2386    if (!wd->disabled)
2387      {
2388         evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
2389
2390         if (!_elm_config->desktop_entry)
2391           _entry_hover_anchor_clicked(data, data, &ei);
2392      }
2393 }
2394
2395 static void
2396 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2397 {
2398    Widget_Data *wd = elm_widget_data_get(data);
2399    if (!wd) return;
2400 }
2401
2402 static void
2403 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2404 {
2405    Widget_Data *wd = elm_widget_data_get(data);
2406    Elm_Entry_Anchor_Info ei;
2407    if (!wd) return;
2408    ei.name = emission + sizeof("nchor,mouse,in,");
2409    ei.button = 0;
2410    ei.x = ei.y = ei.w = ei.h = 0;
2411
2412    _signal_anchor_geoms_do_things_with(wd, &ei);
2413
2414    if (!wd->disabled)
2415      evas_object_smart_callback_call(data, SIG_ANCHOR_IN, &ei);
2416 }
2417
2418 static void
2419 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2420 {
2421    Widget_Data *wd = elm_widget_data_get(data);
2422    Elm_Entry_Anchor_Info ei;
2423    if (!wd) return;
2424    ei.name = emission + sizeof("nchor,mouse,out,");
2425    ei.button = 0;
2426    ei.x = ei.y = ei.w = ei.h = 0;
2427
2428    _signal_anchor_geoms_do_things_with(wd, &ei);
2429
2430    if (!wd->disabled)
2431      evas_object_smart_callback_call(data, SIG_ANCHOR_OUT, &ei);
2432 }
2433
2434 static void
2435 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2436 {
2437    Widget_Data *wd = elm_widget_data_get(data);
2438    if (!wd) return;
2439    evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
2440 }
2441
2442 static void
2443 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2444 {
2445    Widget_Data *wd = elm_widget_data_get(data);
2446    if (!wd) return;
2447    wd->double_clicked = EINA_FALSE;
2448    evas_object_smart_callback_call(data, SIG_PRESS, NULL);
2449
2450    if ((wd->api) && (wd->api->obj_hidemenu))
2451      wd->api->obj_hidemenu(data);
2452 }
2453
2454 static void
2455 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2456 {
2457    Widget_Data *wd = elm_widget_data_get(data);
2458    if (!wd) return;
2459    evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
2460
2461    if (!_elm_config->desktop_entry && !wd->double_clicked)
2462      _cancel(data, NULL, NULL);
2463 }
2464
2465 static void
2466 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2467 {
2468    Widget_Data *wd = elm_widget_data_get(data);
2469    if (!wd) return;
2470    wd->double_clicked = EINA_TRUE;
2471    evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
2472 }
2473
2474 static void
2475 _signal_mouse_triple(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2476 {
2477    Widget_Data *wd = elm_widget_data_get(data);
2478    if (!wd) return;
2479    evas_object_smart_callback_call(data, SIG_CLICKED_TRIPLE, NULL);
2480 }
2481
2482 #ifdef HAVE_ELEMENTARY_X
2483 static Eina_Bool
2484 _event_selection_notify(void *data, int type __UNUSED__, void *event)
2485 {
2486    Widget_Data *wd = elm_widget_data_get(data);
2487    Ecore_X_Event_Selection_Notify *ev = event;
2488    if (!wd) return ECORE_CALLBACK_PASS_ON;
2489    if ((!wd->selection_asked) && (!wd->drag_selection_asked))
2490      return ECORE_CALLBACK_PASS_ON;
2491
2492    if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
2493        (ev->selection == ECORE_X_SELECTION_PRIMARY))
2494      {
2495         Ecore_X_Selection_Data_Text *text_data;
2496
2497         text_data = ev->data;
2498         if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
2499           {
2500              if (text_data->text)
2501                {
2502                   char *txt = _elm_util_text_to_mkup(text_data->text);
2503
2504                   if (txt)
2505                     {
2506                        elm_entry_entry_insert(data, txt);
2507                        free(txt);
2508                     }
2509                }
2510           }
2511         wd->selection_asked = EINA_FALSE;
2512      }
2513    else if (ev->selection == ECORE_X_SELECTION_XDND)
2514      {
2515         Ecore_X_Selection_Data_Text *text_data;
2516
2517         text_data = ev->data;
2518         if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
2519           {
2520              if (text_data->text)
2521                {
2522                   char *txt = _elm_util_text_to_mkup(text_data->text);
2523
2524                   if (txt)
2525                     {
2526                        /* Massive FIXME: this should be at the drag point */
2527                        elm_entry_entry_insert(data, txt);
2528                        free(txt);
2529                     }
2530                }
2531           }
2532         wd->drag_selection_asked = EINA_FALSE;
2533
2534         ecore_x_dnd_send_finished();
2535
2536      }
2537    return ECORE_CALLBACK_PASS_ON;
2538 }
2539
2540 static Eina_Bool
2541 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
2542 {
2543 #if 0
2544    Widget_Data *wd = elm_widget_data_get(data);
2545    Ecore_X_Event_Selection_Clear *ev = event;
2546    if (!wd) return ECORE_CALLBACK_PASS_ON;
2547    if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
2548    if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
2549        (ev->selection == ECORE_X_SELECTION_PRIMARY))
2550      {
2551         elm_entry_select_none(data);
2552      }
2553 #else
2554
2555    // start for cbhm
2556    Evas_Object *top = elm_widget_top_get(data);
2557    Ecore_X_Event_Selection_Clear *ev = event;
2558
2559    if (!top)
2560       return ECORE_CALLBACK_PASS_ON;
2561
2562    if (ev->selection != ECORE_X_SELECTION_SECONDARY)
2563      {
2564         return ECORE_CALLBACK_PASS_ON;
2565      }
2566
2567    if (cnpwidgetdata == data)
2568      {
2569         Widget_Data *wd = elm_widget_data_get(data);
2570         Elm_Sel_Format formats = ELM_SEL_FORMAT_MARKUP;
2571         evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
2572         if (wd->cnp_mode == ELM_CNP_MODE_PLAINTEXT)
2573           formats = ELM_SEL_FORMAT_TEXT;
2574         else if (wd->cnp_mode != ELM_CNP_MODE_NO_IMAGE)
2575           formats |= ELM_SEL_FORMAT_IMAGE;
2576         elm_cnp_selection_get(data, ELM_SEL_TYPE_SECONDARY, formats, NULL, NULL);
2577      }
2578
2579    // end for cbhm
2580 #endif
2581    return ECORE_CALLBACK_PASS_ON;
2582 }
2583
2584 static Eina_Bool
2585 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
2586 {
2587    Widget_Data *wd;
2588    Eina_Bool rv;
2589
2590    wd = elm_widget_data_get(obj);
2591    if (!wd) return EINA_FALSE;
2592    printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
2593
2594    edje_object_part_text_cursor_copy(wd->ent, "elm.text",
2595                                      EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
2596    rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
2597                                                EDJE_CURSOR_MAIN,drop->x,drop->y);
2598    if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
2599    elm_entry_entry_insert(obj, drop->data);
2600    edje_object_part_text_cursor_copy(wd->ent, "elm.text",
2601                                      EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
2602
2603    return EINA_TRUE;
2604 }
2605 #endif
2606
2607 static Evas_Object *
2608 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
2609 {
2610    Widget_Data *wd = elm_widget_data_get(data);
2611    Evas_Object *o;
2612    Eina_List *l;
2613    Elm_Entry_Item_Provider *ip;
2614
2615    EINA_LIST_FOREACH(wd->item_providers, l, ip)
2616      {
2617         o = ip->func(ip->data, data, item);
2618         if (o) return o;
2619      }
2620    if (!strncmp(item, "file://", 7))
2621      {
2622         const char *fname = item + 7;
2623
2624         o = evas_object_image_filled_add(evas_object_evas_get(data));
2625         evas_object_image_file_set(o, fname, NULL);
2626         if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
2627           {
2628              evas_object_show(o);
2629           }
2630         else
2631           {
2632              evas_object_del(o);
2633              o = edje_object_add(evas_object_evas_get(data));
2634              _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
2635           }
2636         return o;
2637      }
2638    o = edje_object_add(evas_object_evas_get(data));
2639    if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
2640      _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
2641    return o;
2642 }
2643
2644 static void
2645 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
2646 {
2647    Widget_Data *wd = elm_widget_data_get(data);
2648    Eina_List *l;
2649    Elm_Entry_Markup_Filter *tf;
2650
2651    if (type == EDJE_TEXT_FILTER_FORMAT)
2652      return;
2653
2654    EINA_LIST_FOREACH(wd->text_filters, l, tf)
2655      {
2656         tf->func(tf->data, data, text);
2657         if (!*text)
2658           break;
2659      }
2660 }
2661
2662 static void
2663 _markup_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, char **text)
2664 {
2665    Widget_Data *wd = elm_widget_data_get(data);
2666    Eina_List *l;
2667    Elm_Entry_Markup_Filter *tf;
2668
2669    EINA_LIST_FOREACH(wd->markup_filters, l, tf)
2670      {
2671         tf->func(tf->data, data, text);
2672         if (!*text)
2673           break;
2674      }
2675 }
2676
2677 /* This function is used to insert text by chunks in jobs */
2678 static Eina_Bool
2679 _text_append_idler(void *data)
2680 {
2681    int start;
2682    char backup;
2683    Evas_Object *obj = (Evas_Object *) data;
2684    Widget_Data *wd = elm_widget_data_get(obj);
2685    if (wd->text) eina_stringshare_del(wd->text);
2686    wd->text = NULL;
2687    if (wd->password_text) eina_stringshare_del(wd->password_text);
2688    wd->password_text = NULL;
2689    evas_event_freeze(evas_object_evas_get(obj));
2690    wd->changed = EINA_TRUE;
2691
2692    start = wd->append_text_position;
2693    if (start + _CHUNK_SIZE < wd->append_text_len)
2694      {
2695         int pos = start;
2696         int tag_start, esc_start;
2697
2698         tag_start = esc_start = -1;
2699         /* Find proper markup cut place */
2700         while (pos - start < _CHUNK_SIZE)
2701           {
2702              int prev_pos = pos;
2703              Eina_Unicode tmp =
2704                 eina_unicode_utf8_get_next(wd->append_text_left, &pos);
2705              if (esc_start == -1)
2706                {
2707                   if (tmp == '<')
2708                      tag_start = prev_pos;
2709                   else if (tmp == '>')
2710                      tag_start = -1;
2711                }
2712              if (tag_start == -1)
2713                {
2714                   if (tmp == '&')
2715                      esc_start = prev_pos;
2716                   else if (tmp == ';')
2717                      esc_start = -1;
2718                }
2719           }
2720
2721         if (tag_start >= 0)
2722           {
2723              wd->append_text_position = tag_start;
2724           }
2725         else if (esc_start >= 0)
2726           {
2727              wd->append_text_position = esc_start;
2728           }
2729         else
2730           {
2731              wd->append_text_position = pos;
2732           }
2733      }
2734    else
2735      {
2736         wd->append_text_position = wd->append_text_len;
2737      }
2738
2739    backup = wd->append_text_left[wd->append_text_position];
2740    wd->append_text_left[wd->append_text_position] = '\0';
2741
2742    edje_object_part_text_append(wd->ent, "elm.text",
2743                                 wd->append_text_left + start);
2744
2745    wd->append_text_left[wd->append_text_position] = backup;
2746
2747    evas_event_thaw(evas_object_evas_get(obj));
2748    evas_event_thaw_eval(evas_object_evas_get(obj));
2749
2750    /* If there's still more to go, renew the idler, else, cleanup */
2751    if (wd->append_text_position < wd->append_text_len)
2752      {
2753         return ECORE_CALLBACK_RENEW;
2754      }
2755    else
2756      {
2757         free(wd->append_text_left);
2758         wd->append_text_left = NULL;
2759         wd->append_text_idler = NULL;
2760         return ECORE_CALLBACK_CANCEL;
2761      }
2762 }
2763
2764 static void
2765 _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit)
2766 {
2767    int i = 0, current_len = 0;
2768    char *new_text;
2769
2770    if (!*text) return;
2771    if (unit >= LENGTH_UNIT_LAST) return;
2772    new_text = *text;
2773    current_len = strlen(*text);
2774    while (*new_text)
2775      {
2776         int idx = 0, unit_size = 0;
2777         char *markup, *utfstr;
2778         if (*new_text == '<')
2779           {
2780              while (*(new_text + idx) != '>')
2781                {
2782                   idx++;
2783                   if (!*(new_text + idx)) break;
2784                }
2785           }
2786         else if (*new_text == '&')
2787           {
2788              while (*(new_text + idx) != ';')
2789                {
2790                   idx++;
2791                   if (!*(new_text + idx)) break;
2792                }
2793           }
2794         idx = evas_string_char_next_get(new_text, idx, NULL);
2795         markup = malloc(idx + 1);
2796         if (markup)
2797           {
2798              strncpy(markup, new_text, idx);
2799              markup[idx] = 0;
2800              utfstr = elm_entry_markup_to_utf8(markup);
2801              if (utfstr)
2802                {
2803                   if (unit == LENGTH_UNIT_BYTE)
2804                     unit_size = strlen(utfstr);
2805                   else if (unit == LENGTH_UNIT_CHAR)
2806                     unit_size = evas_string_char_len_get(utfstr);
2807                   free(utfstr);
2808                   utfstr = NULL;
2809                }
2810              free(markup);
2811              markup = NULL;
2812           }
2813         if (can_add < unit_size)
2814           {
2815              if (!i)
2816                {
2817                   evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
2818                   free(*text);
2819                   *text = NULL;
2820                   return;
2821                }
2822              can_add = 0;
2823              strncpy(new_text, new_text + idx, current_len - ((new_text + idx) - *text));
2824              current_len -= idx;
2825              (*text)[current_len] = 0;
2826           }
2827         else
2828           {
2829              new_text += idx;
2830              can_add -= unit_size;
2831           }
2832         i++;
2833      }
2834    evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
2835 }
2836
2837 static void
2838 _elm_entry_text_set(Evas_Object *obj, const char *item, const char *entry)
2839 {
2840    int len = 0;
2841    ELM_CHECK_WIDTYPE(obj, widtype);
2842    Widget_Data *wd = elm_widget_data_get(obj);
2843    if (!wd) return;
2844    evas_event_freeze(evas_object_evas_get(obj));
2845    if (!entry) entry = "";
2846    if (item && strcmp(item, "default"))
2847      {
2848         edje_object_part_text_set(wd->ent, item, entry);
2849         return;
2850      }
2851
2852    if (wd->text) eina_stringshare_del(wd->text);
2853    wd->text = NULL;
2854    if (wd->password_text) eina_stringshare_del(wd->password_text);
2855    wd->password_text = NULL;
2856    wd->changed = EINA_TRUE;
2857
2858    /* Clear currently pending job if there is one */
2859    if (wd->append_text_idler)
2860      {
2861         ecore_idler_del(wd->append_text_idler);
2862         free(wd->append_text_left);
2863         wd->append_text_left = NULL;
2864         wd->append_text_idler = NULL;
2865      }
2866
2867    len = strlen(entry);
2868    /* Split to ~_CHUNK_SIZE chunks */
2869    if (len > _CHUNK_SIZE)
2870      {
2871         wd->append_text_left = (char *) malloc(len + 1);
2872      }
2873
2874    /* If we decided to use the idler */
2875    if (wd->append_text_left)
2876      {
2877         /* Need to clear the entry first */
2878         edje_object_part_text_set(wd->ent, "elm.text", "");
2879         memcpy(wd->append_text_left, entry, len + 1);
2880         wd->append_text_position = 0;
2881         wd->append_text_len = len;
2882         wd->append_text_idler = ecore_idler_add(_text_append_idler, obj);
2883      }
2884    else
2885      {
2886         edje_object_part_text_set(wd->ent, "elm.text", entry);
2887      }
2888    evas_event_thaw(evas_object_evas_get(obj));
2889    evas_event_thaw_eval(evas_object_evas_get(obj));
2890 }
2891
2892 static const char *
2893 _elm_entry_text_get(const Evas_Object *obj, const char *item)
2894 {
2895    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2896    Widget_Data *wd = elm_widget_data_get(obj);
2897    if (item && strcmp(item, "default")) return NULL;
2898    const char *text;
2899    if (!wd) return NULL;
2900
2901    text = edje_object_part_text_get(wd->ent, "elm.text");
2902    if (!text)
2903      {
2904         ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2905         return NULL;
2906      }
2907
2908    if (wd->append_text_len > 0)
2909      {
2910         char *tmpbuf;
2911         size_t tlen;
2912         tlen = strlen(text);
2913         tmpbuf = malloc(tlen + wd->append_text_len + 1);
2914         if (!tmpbuf)
2915           {
2916              ERR("Failed to allocate memory for entry's text %p", obj);
2917              return NULL;
2918           }
2919         memcpy(tmpbuf, text, tlen);
2920         if (wd->append_text_left)
2921           memcpy(tmpbuf + tlen, wd->append_text_left, strlen(wd->append_text_left));
2922         tmpbuf[tlen + wd->append_text_len] = '\0';
2923         eina_stringshare_replace(&wd->text, tmpbuf);
2924         free(tmpbuf);
2925      }
2926    else
2927      {
2928         eina_stringshare_replace(&wd->text, text);
2929      }
2930    if (wd->password)
2931      {
2932         char *pw_text;
2933         pw_text = elm_entry_markup_to_utf8(wd->text);
2934         if (pw_text)
2935           {
2936              eina_stringshare_replace(&wd->password_text, pw_text);
2937              free(pw_text);
2938              return wd->password_text;
2939           }
2940      }
2941    return wd->text;
2942 }
2943
2944 EAPI Evas_Object *
2945 elm_entry_add(Evas_Object *parent)
2946 {
2947 #ifdef HAVE_ELEMENTARY_X
2948    Evas_Object *top;
2949 #endif
2950    Evas_Object *obj;
2951    Evas *e;
2952    Widget_Data *wd;
2953
2954    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
2955
2956    ELM_SET_WIDTYPE(widtype, "entry");
2957    elm_widget_type_set(obj, "entry");
2958    elm_widget_sub_object_add(parent, obj);
2959    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2960    elm_widget_data_set(obj, wd);
2961    elm_widget_del_hook_set(obj, _del_hook);
2962    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2963    elm_widget_theme_hook_set(obj, _theme_hook);
2964    elm_widget_disable_hook_set(obj, _disable_hook);
2965    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2966    elm_widget_focus_region_hook_set(obj, _focus_region_hook);
2967    elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
2968    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
2969    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
2970    elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
2971    elm_widget_can_focus_set(obj, EINA_TRUE);
2972    elm_widget_text_set_hook_set(obj, _elm_entry_text_set);
2973    elm_widget_text_get_hook_set(obj, _elm_entry_text_get);
2974    elm_widget_content_set_hook_set(obj, _content_set_hook);
2975    elm_widget_content_unset_hook_set(obj, _content_unset_hook);
2976    elm_widget_content_get_hook_set(obj, _content_get_hook);
2977    elm_widget_translate_hook_set(obj, _translate_hook);
2978    elm_widget_event_hook_set(obj, _event_hook);
2979
2980    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, wd);
2981
2982    wd->linewrap     = ELM_WRAP_WORD;
2983    wd->editable     = EINA_TRUE;
2984    wd->disabled     = EINA_FALSE;
2985    wd->context_menu = EINA_TRUE;
2986    wd->autosave     = EINA_TRUE;
2987    wd->cnp_mode     = ELM_CNP_MODE_MARKUP;
2988    wd->scroll       = EINA_FALSE;
2989    wd->input_panel_imdata = NULL;
2990 //TIZEN ONLY
2991    wd->magnifier_enabled = EINA_TRUE;
2992 //
2993
2994    wd->ent = edje_object_add(e);
2995    edje_object_item_provider_set(wd->ent, _get_item, obj);
2996    edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
2997    edje_object_text_markup_filter_callback_add(wd->ent,"elm.text", _markup_filter, obj);
2998    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
2999    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
3000                                   _mouse_down, obj);
3001    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
3002                                   _mouse_up, obj);
3003    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
3004                                   _mouse_move, obj);
3005    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
3006
3007    _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
3008    edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
3009                                    _signal_entry_changed, obj);
3010    edje_object_signal_callback_add(wd->ent, "entry,changed,user", "elm.text",
3011                                    _signal_entry_changed_user, obj);
3012    edje_object_signal_callback_add(wd->ent, "preedit,changed", "elm.text",
3013                                    _signal_preedit_changed, obj);
3014    edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
3015                                    _signal_selection_start, obj);
3016    edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
3017                                    _signal_selection_changed, obj);
3018    edje_object_signal_callback_add(wd->ent, "entry,selection,all,request", "elm.text",
3019                                    _signal_selection_all, obj);
3020    edje_object_signal_callback_add(wd->ent, "entry,selection,none,request", "elm.text",
3021                                    _signal_selection_none, obj);
3022    edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
3023                                    _signal_selection_cleared, obj);
3024    edje_object_signal_callback_add(wd->ent, "entry,paste,request,*", "elm.text",
3025                                    _signal_entry_paste_request, obj);
3026    edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
3027                                    _signal_entry_copy_notify, obj);
3028    edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
3029                                    _signal_entry_cut_notify, obj);
3030    edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
3031                                    _signal_cursor_changed, obj);
3032    edje_object_signal_callback_add(wd->ent, "cursor,changed,manual", "elm.text",
3033                                    _signal_cursor_changed_manual, obj);
3034    edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
3035                                    _signal_anchor_down, obj);
3036    edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
3037                                    _signal_anchor_up, obj);
3038    edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
3039                                    _signal_anchor_clicked, obj);
3040    edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
3041                                    _signal_anchor_move, obj);
3042    edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
3043                                    _signal_anchor_in, obj);
3044    edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
3045                                    _signal_anchor_out, obj);
3046    edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
3047                                    _signal_key_enter, obj);
3048    edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
3049                                    _signal_mouse_down, obj);
3050    edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
3051                                    _signal_mouse_clicked, obj);
3052    edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
3053                                    _signal_mouse_double, obj);
3054    edje_object_signal_callback_add(wd->ent, "mouse,down,1,triple", "elm.text",
3055                                    _signal_mouse_triple, obj);
3056    edje_object_signal_callback_add(wd->ent, "entry,undo,request", "elm.text",
3057                                    _signal_undo_request, obj);
3058    edje_object_signal_callback_add(wd->ent, "entry,redo,request", "elm.text",
3059                                    _signal_redo_request, obj);
3060 // TIZEN ONLY
3061    edje_object_signal_callback_add(wd->ent, "handler,move,start", "elm.text",
3062                                    _signal_handler_move_start, obj);
3063    edje_object_signal_callback_add(wd->ent, "handler,move,end", "elm.text",
3064                                    _signal_handler_move_end, obj);
3065    edje_object_signal_callback_add(wd->ent, "handler,moving", "elm.text",
3066                                    _signal_handler_moving, obj);
3067    edje_object_signal_callback_add(wd->ent, "selection,end", "elm.text",
3068                                    _signal_selection_end, obj);
3069    edje_object_signal_callback_add(wd->ent, "long,pressed", "elm.text",
3070                                    _signal_long_pressed, obj);
3071    edje_object_signal_callback_add(wd->ent, "magnifier,changed", "elm.text",
3072                                    _signal_magnifier_changed, obj);
3073 //
3074    edje_object_part_text_set(wd->ent, "elm.text", "");
3075    if (_elm_config->desktop_entry)
3076      edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
3077    else
3078      {
3079         edje_object_part_text_copy_paste_disabled_set(wd->ent, "elm.text", EINA_FALSE);
3080         edje_object_part_text_viewport_region_set(wd->ent, "elm.text", -1, -1, -1, -1);
3081         edje_object_part_text_layout_region_set(wd->ent, "elm.text", -1, -1, -1, -1);
3082      }
3083    elm_widget_resize_object_set(obj, wd->ent);
3084    _sizing_eval(obj);
3085
3086    elm_entry_input_panel_layout_set(obj, ELM_INPUT_PANEL_LAYOUT_NORMAL);
3087
3088    elm_entry_input_panel_enabled_set(obj, EINA_TRUE);
3089    elm_entry_prediction_allow_set(obj, EINA_TRUE);
3090
3091    wd->autocapital_type = edje_object_part_text_autocapital_type_get(wd->ent, "elm.text");
3092
3093 #ifdef HAVE_ELEMENTARY_X
3094    top = elm_widget_top_get(obj);
3095    if ((top) && (elm_win_xwindow_get(top)))
3096      {
3097         wd->sel_notify_handler =
3098            ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
3099                                    _event_selection_notify, obj);
3100         wd->sel_clear_handler =
3101            ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
3102                                    _event_selection_clear, obj);
3103      }
3104
3105    elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
3106                        _drag_drop_cb, NULL);
3107 #endif
3108
3109    entries = eina_list_prepend(entries, obj);
3110
3111    // module - find module for entry
3112    wd->api = _module(obj);
3113    // if found - hook in
3114    if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
3115
3116    _mirrored_set(obj, elm_widget_mirrored_get(obj));
3117    // TODO: convert Elementary to subclassing of Evas_Smart_Class
3118    // TODO: and save some bytes, making descriptions per-class and not instance!
3119    evas_object_smart_callbacks_descriptions_set(obj, _signals);
3120    return obj;
3121 }
3122
3123 void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
3124 {
3125    ELM_CHECK_WIDTYPE(obj, widtype);
3126    Widget_Data *wd = elm_widget_data_get(obj);
3127    if (!wd) return;
3128    ext_mod->cancel = _cancel;
3129    ext_mod->copy = _copy;
3130    ext_mod->cut = _cut;
3131    ext_mod->paste = _paste;
3132    ext_mod->select = _select;
3133    ext_mod->selectall = _selectall;
3134    ext_mod->ent = wd->ent;
3135    ext_mod->items = wd->items;
3136    ext_mod->editable = wd->editable;
3137    ext_mod->have_selection = wd->have_selection;
3138    ext_mod->password = wd->password;
3139    ext_mod->selmode = wd->selmode;
3140    ext_mod->cnpinit = _cnpinit;
3141    ext_mod->context_menu = wd->context_menu;
3142    ext_mod->cnp_mode = wd->cnp_mode;
3143    ext_mod->viewport_rect = _viewport_region_get(obj);
3144 }
3145
3146 EAPI void
3147 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
3148 {
3149    ELM_CHECK_WIDTYPE(obj, widtype);
3150    Widget_Data *wd = elm_widget_data_get(obj);
3151    if (!wd) return;
3152    if (wd->single_line == single_line) return;
3153    wd->single_line = single_line;
3154    wd->linewrap = ELM_WRAP_NONE;
3155    elm_entry_cnp_mode_set(obj, ELM_CNP_MODE_NO_IMAGE);
3156    _theme_hook(obj);
3157    if (wd->scroller)
3158      {
3159         if (wd->single_line)
3160           {
3161              elm_smart_scroller_policy_set(wd->scroller,
3162                                            ELM_SMART_SCROLLER_POLICY_OFF,
3163                                            ELM_SMART_SCROLLER_POLICY_OFF);
3164              elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE); // TIZEN ONLY
3165           }
3166         else
3167           {
3168              const Elm_Scroller_Policy map[3] =
3169                {
3170                   ELM_SMART_SCROLLER_POLICY_AUTO,
3171                   ELM_SMART_SCROLLER_POLICY_ON,
3172                   ELM_SMART_SCROLLER_POLICY_OFF
3173                };
3174              elm_smart_scroller_policy_set(wd->scroller,
3175                                            map[wd->policy_h],
3176                                            map[wd->policy_v]);
3177              elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE); // TIZEN ONLY
3178           }
3179         _sizing_eval(obj);
3180      }
3181 }
3182
3183 EAPI Eina_Bool
3184 elm_entry_single_line_get(const Evas_Object *obj)
3185 {
3186    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3187    Widget_Data *wd = elm_widget_data_get(obj);
3188    if (!wd) return EINA_FALSE;
3189    return wd->single_line;
3190 }
3191
3192 EAPI void
3193 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
3194 {
3195    ELM_CHECK_WIDTYPE(obj, widtype);
3196    Widget_Data *wd = elm_widget_data_get(obj);
3197    if (!wd) return;
3198    if (wd->password == password) return;
3199    wd->password = password;
3200    if (password)
3201      {
3202         wd->single_line = EINA_TRUE;
3203         wd->linewrap = ELM_WRAP_NONE;
3204 #ifdef HAVE_ELEMENTARY_X
3205         elm_drop_target_del(obj);
3206 #endif
3207         edje_object_signal_callback_del_full(wd->ent, "selection,start", "elm.text",
3208                                         _signal_selection_start, obj);
3209         edje_object_signal_callback_del_full(wd->ent, "selection,changed", "elm.text",
3210                                         _signal_selection_changed, obj);
3211         edje_object_signal_callback_del_full(wd->ent, "entry,selection,all,request", "elm.text",
3212                                         _signal_selection_all, obj);
3213         edje_object_signal_callback_del_full(wd->ent, "entry,selection,none,request", "elm.text",
3214                                         _signal_selection_none, obj);
3215         edje_object_signal_callback_del_full(wd->ent, "selection,cleared", "elm.text",
3216                                         _signal_selection_cleared, obj);
3217         edje_object_signal_callback_del_full(wd->ent, "entry,paste,request,*", "elm.text",
3218                                         _signal_entry_paste_request, obj);
3219         edje_object_signal_callback_del_full(wd->ent, "entry,copy,notify", "elm.text",
3220                                         _signal_entry_copy_notify, obj);
3221         edje_object_signal_callback_del_full(wd->ent, "entry,cut,notify", "elm.text",
3222                                         _signal_entry_cut_notify, obj);
3223      }
3224    else
3225      {
3226 #ifdef HAVE_ELEMENTARY_X
3227         elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
3228 #endif
3229         edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
3230                                         _signal_selection_start, obj);
3231         edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
3232                                         _signal_selection_changed, obj);
3233         edje_object_signal_callback_add(wd->ent, "entry,selection,all,request", "elm.text",
3234                                         _signal_selection_all, obj);
3235         edje_object_signal_callback_add(wd->ent, "entry,selection,none,request", "elm.text",
3236                                         _signal_selection_none, obj);
3237         edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
3238                                         _signal_selection_cleared, obj);
3239         edje_object_signal_callback_add(wd->ent, "entry,paste,request,*", "elm.text",
3240                                         _signal_entry_paste_request, obj);
3241         edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
3242                                         _signal_entry_copy_notify, obj);
3243         edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
3244                                         _signal_entry_cut_notify, obj);
3245      }
3246    _theme_hook(obj);
3247 }
3248
3249 EAPI Eina_Bool
3250 elm_entry_password_get(const Evas_Object *obj)
3251 {
3252    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3253    Widget_Data *wd = elm_widget_data_get(obj);
3254    if (!wd) return EINA_FALSE;
3255    return wd->password;
3256 }
3257
3258 EAPI void
3259 elm_entry_entry_set(Evas_Object *obj, const char *entry)
3260 {
3261    _elm_entry_text_set(obj, NULL, entry);
3262 }
3263
3264 EAPI const char *
3265 elm_entry_entry_get(const Evas_Object *obj)
3266 {
3267    return _elm_entry_text_get(obj, NULL);
3268 }
3269
3270 EAPI void
3271 elm_entry_entry_append(Evas_Object *obj, const char *entry)
3272 {
3273    int len = 0;
3274    ELM_CHECK_WIDTYPE(obj, widtype);
3275    Widget_Data *wd = elm_widget_data_get(obj);
3276    if (!wd) return;
3277    if (!entry) entry = "";
3278    wd->changed = EINA_TRUE;
3279
3280    len = strlen(entry);
3281    if (wd->append_text_left)
3282      {
3283         char *tmpbuf;
3284         tmpbuf = realloc(wd->append_text_left, wd->append_text_len + len + 1);
3285         if (!tmpbuf)
3286           {
3287              /* Do something */
3288              return;
3289           }
3290         wd->append_text_left = tmpbuf;
3291         memcpy(wd->append_text_left + wd->append_text_len, entry, len + 1);
3292         wd->append_text_len += len;
3293      }
3294    else
3295      {
3296         /* FIXME: Add chunked appending here (like in entry_set) */
3297         edje_object_part_text_append(wd->ent, "elm.text", entry);
3298      }
3299 }
3300
3301 EAPI Eina_Bool
3302 elm_entry_is_empty(const Evas_Object *obj)
3303 {
3304    /* FIXME: until there's support for that in textblock, we just check
3305     * to see if the there is text or not. */
3306    ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
3307    Widget_Data *wd = elm_widget_data_get(obj);
3308    const Evas_Object *tb;
3309    Evas_Textblock_Cursor *cur;
3310    Eina_Bool ret;
3311    if (!wd) return EINA_TRUE;
3312
3313    if (0) {  // TIZEN ONLY
3314    /* It's a hack until we get the support suggested above.
3315     * We just create a cursor, point it to the begining, and then
3316     * try to advance it, if it can advance, the tb is not empty,
3317     * otherwise it is. */
3318    tb = edje_object_part_object_get(wd->ent, "elm.text");
3319    cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
3320                                                                   actually, ok for the time being, thsese hackish stuff will be removed
3321                                                                   once evas 1.0 is out*/
3322    evas_textblock_cursor_pos_set(cur, 0);
3323    ret = evas_textblock_cursor_char_next(cur);
3324    evas_textblock_cursor_free(cur);
3325
3326    return !ret;
3327    }
3328
3329    char *str = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
3330    if (!str) return EINA_TRUE;
3331
3332    ret = (strlen(str) == 0);
3333
3334    free(str);
3335    return ret;
3336 }
3337
3338 EAPI Evas_Object *
3339 elm_entry_textblock_get(Evas_Object *obj)
3340 {
3341    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3342    Widget_Data *wd = elm_widget_data_get(obj);
3343    if (!wd) return NULL;
3344
3345    return (Evas_Object *) edje_object_part_object_get(wd->ent, "elm.text");
3346 }
3347
3348 EAPI void
3349 elm_entry_calc_force(Evas_Object *obj)
3350 {
3351    ELM_CHECK_WIDTYPE(obj, widtype);
3352    Widget_Data *wd = elm_widget_data_get(obj);
3353    if (!wd) return;
3354
3355    edje_object_calc_force(wd->ent);
3356    wd->changed = EINA_TRUE;
3357    _sizing_eval(obj);
3358 }
3359
3360
3361 EAPI const char *
3362 elm_entry_selection_get(const Evas_Object *obj)
3363 {
3364    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3365    Widget_Data *wd = elm_widget_data_get(obj);
3366    if ((!wd) || (wd->password)) return NULL;
3367    return edje_object_part_text_selection_get(wd->ent, "elm.text");
3368 }
3369
3370 EAPI void
3371 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
3372 {
3373    ELM_CHECK_WIDTYPE(obj, widtype);
3374    Widget_Data *wd = elm_widget_data_get(obj);
3375    if (!wd) return;
3376    edje_object_part_text_insert(wd->ent, "elm.text", entry);
3377    // start for cbhm
3378 #ifdef HAVE_ELEMENTARY_X
3379    if (cnpwidgetdata == obj)
3380       ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
3381 #endif
3382    // end for cbhm
3383    wd->changed = EINA_TRUE;
3384    _sizing_eval(obj);
3385 }
3386
3387 EAPI void
3388 elm_entry_line_wrap_set(Evas_Object *obj, Elm_Wrap_Type wrap)
3389 {
3390    ELM_CHECK_WIDTYPE(obj, widtype);
3391    Widget_Data *wd = elm_widget_data_get(obj);
3392    if (!wd) return;
3393    if (wd->linewrap == wrap) return;
3394    wd->lastw = -1;
3395    wd->linewrap = wrap;
3396    _theme_hook(obj);
3397 }
3398
3399 EAPI Elm_Wrap_Type
3400 elm_entry_line_wrap_get(const Evas_Object *obj)
3401 {
3402    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3403    Widget_Data *wd = elm_widget_data_get(obj);
3404    if (!wd) return EINA_FALSE;
3405    return wd->linewrap;
3406 }
3407
3408 EAPI void
3409 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
3410 {
3411    ELM_CHECK_WIDTYPE(obj, widtype);
3412    Widget_Data *wd = elm_widget_data_get(obj);
3413    if (!wd) return;
3414    if (wd->editable == editable) return;
3415    wd->editable = editable;
3416    _theme_hook(obj);
3417
3418 #ifdef HAVE_ELEMENTARY_X
3419    if (editable)
3420      elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
3421    else
3422      elm_drop_target_del(obj);
3423 #endif
3424 }
3425
3426 EAPI Eina_Bool
3427 elm_entry_editable_get(const Evas_Object *obj)
3428 {
3429    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3430    Widget_Data *wd = elm_widget_data_get(obj);
3431    if (!wd) return EINA_FALSE;
3432    return wd->editable;
3433 }
3434
3435 EAPI void
3436 elm_entry_select_none(Evas_Object *obj)
3437 {
3438    ELM_CHECK_WIDTYPE(obj, widtype);
3439    Widget_Data *wd = elm_widget_data_get(obj);
3440    if ((!wd) || (wd->password)) return;
3441    if (wd->selmode)
3442      {
3443         wd->selmode = EINA_FALSE;
3444         if (!_elm_config->desktop_entry)
3445           edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
3446         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
3447      }
3448    wd->have_selection = EINA_FALSE;
3449    edje_object_part_text_select_none(wd->ent, "elm.text");
3450 }
3451
3452 EAPI void
3453 elm_entry_select_all(Evas_Object *obj)
3454 {
3455    ELM_CHECK_WIDTYPE(obj, widtype);
3456    Widget_Data *wd = elm_widget_data_get(obj);
3457    if ((!wd) || (wd->password)) return;
3458    if (wd->selmode)
3459      {
3460         wd->selmode = EINA_FALSE;
3461         if (!_elm_config->desktop_entry)
3462           edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
3463         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
3464      }
3465    wd->have_selection = EINA_TRUE;
3466    edje_object_part_text_select_all(wd->ent, "elm.text");
3467 }
3468
3469 EAPI Eina_Bool
3470 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
3471 {
3472    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3473    Widget_Data *wd = elm_widget_data_get(obj);
3474    if (!wd) return EINA_FALSE;
3475    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
3476    return EINA_TRUE;
3477 }
3478
3479 EAPI Eina_Bool
3480 elm_entry_cursor_next(Evas_Object *obj)
3481 {
3482    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3483    Widget_Data *wd = elm_widget_data_get(obj);
3484    if (!wd) return EINA_FALSE;
3485    return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3486 }
3487
3488 EAPI Eina_Bool
3489 elm_entry_cursor_prev(Evas_Object *obj)
3490 {
3491    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3492    Widget_Data *wd = elm_widget_data_get(obj);
3493    if (!wd) return EINA_FALSE;
3494    return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3495 }
3496
3497 EAPI Eina_Bool
3498 elm_entry_cursor_up(Evas_Object *obj)
3499 {
3500    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3501    Widget_Data *wd = elm_widget_data_get(obj);
3502    if (!wd) return EINA_FALSE;
3503    return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3504 }
3505
3506 EAPI Eina_Bool
3507 elm_entry_cursor_down(Evas_Object *obj)
3508 {
3509    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3510    Widget_Data *wd = elm_widget_data_get(obj);
3511    if (!wd) return EINA_FALSE;
3512    return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3513 }
3514
3515 EAPI void
3516 elm_entry_cursor_begin_set(Evas_Object *obj)
3517 {
3518    ELM_CHECK_WIDTYPE(obj, widtype);
3519    Widget_Data *wd = elm_widget_data_get(obj);
3520    if (!wd) return;
3521    edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3522 }
3523
3524 EAPI void
3525 elm_entry_cursor_end_set(Evas_Object *obj)
3526 {
3527    ELM_CHECK_WIDTYPE(obj, widtype);
3528    Widget_Data *wd = elm_widget_data_get(obj);
3529    if (!wd) return;
3530    edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3531 }
3532
3533 EAPI void
3534 elm_entry_cursor_line_begin_set(Evas_Object *obj)
3535 {
3536    ELM_CHECK_WIDTYPE(obj, widtype);
3537    Widget_Data *wd = elm_widget_data_get(obj);
3538    if (!wd) return;
3539    edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3540 }
3541
3542 EAPI void
3543 elm_entry_cursor_line_end_set(Evas_Object *obj)
3544 {
3545    ELM_CHECK_WIDTYPE(obj, widtype);
3546    Widget_Data *wd = elm_widget_data_get(obj);
3547    if (!wd) return;
3548    edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3549 }
3550
3551 EAPI void
3552 elm_entry_cursor_selection_begin(Evas_Object *obj)
3553 {
3554    ELM_CHECK_WIDTYPE(obj, widtype);
3555    Widget_Data *wd = elm_widget_data_get(obj);
3556    if (!wd) return;
3557    edje_object_part_text_select_begin(wd->ent, "elm.text");
3558 }
3559
3560 EAPI void
3561 elm_entry_cursor_selection_end(Evas_Object *obj)
3562 {
3563    ELM_CHECK_WIDTYPE(obj, widtype);
3564    Widget_Data *wd = elm_widget_data_get(obj);
3565    if (!wd) return;
3566    edje_object_part_text_select_extend(wd->ent, "elm.text");
3567 }
3568
3569 EAPI Eina_Bool
3570 elm_entry_cursor_is_format_get(const Evas_Object *obj)
3571 {
3572    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3573    Widget_Data *wd = elm_widget_data_get(obj);
3574    if (!wd) return EINA_FALSE;
3575    return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3576 }
3577
3578 EAPI Eina_Bool
3579 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
3580 {
3581    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3582    Widget_Data *wd = elm_widget_data_get(obj);
3583    if (!wd) return EINA_FALSE;
3584    return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3585 }
3586
3587 EAPI char *
3588 elm_entry_cursor_content_get(const Evas_Object *obj)
3589 {
3590    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3591    Widget_Data *wd = elm_widget_data_get(obj);
3592    if (!wd) return NULL;
3593    return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3594 }
3595
3596 EAPI void
3597 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
3598 {
3599    ELM_CHECK_WIDTYPE(obj, widtype);
3600    Widget_Data *wd = elm_widget_data_get(obj);
3601    if (!wd) return;
3602    edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
3603    edje_object_message_signal_process(wd->ent);
3604 }
3605
3606 EAPI int
3607 elm_entry_cursor_pos_get(const Evas_Object *obj)
3608 {
3609    ELM_CHECK_WIDTYPE(obj, widtype) 0;
3610    Widget_Data *wd = elm_widget_data_get(obj);
3611    if (!wd) return 0;
3612    return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3613 }
3614
3615 EAPI void
3616 elm_entry_selection_cut(Evas_Object *obj)
3617 {
3618    ELM_CHECK_WIDTYPE(obj, widtype);
3619    Widget_Data *wd = elm_widget_data_get(obj);
3620    if ((!wd) || (wd->password)) return;
3621    _cut(obj, NULL, NULL);
3622 }
3623
3624 EAPI void
3625 elm_entry_selection_copy(Evas_Object *obj)
3626 {
3627    ELM_CHECK_WIDTYPE(obj, widtype);
3628    Widget_Data *wd = elm_widget_data_get(obj);
3629    if ((!wd) || (wd->password)) return;
3630    _copy(obj, NULL, NULL);
3631 }
3632
3633 EAPI void
3634 elm_entry_selection_paste(Evas_Object *obj)
3635 {
3636    ELM_CHECK_WIDTYPE(obj, widtype);
3637    Widget_Data *wd = elm_widget_data_get(obj);
3638    if ((!wd) || (wd->password)) return;
3639    _paste(obj, NULL, NULL);
3640 }
3641
3642 EAPI void
3643 elm_entry_context_menu_clear(Evas_Object *obj)
3644 {
3645    ELM_CHECK_WIDTYPE(obj, widtype);
3646    Widget_Data *wd = elm_widget_data_get(obj);
3647    Elm_Entry_Context_Menu_Item *it;
3648    if (!wd) return;
3649    EINA_LIST_FREE(wd->items, it)
3650      {
3651         eina_stringshare_del(it->label);
3652         eina_stringshare_del(it->icon_file);
3653         eina_stringshare_del(it->icon_group);
3654         free(it);
3655      }
3656 }
3657
3658 EAPI void
3659 elm_entry_context_menu_item_add(Evas_Object *obj, const char *label, const char *icon_file, Elm_Icon_Type icon_type, Evas_Smart_Cb func, const void *data)
3660 {
3661    ELM_CHECK_WIDTYPE(obj, widtype);
3662    Widget_Data *wd = elm_widget_data_get(obj);
3663    Elm_Entry_Context_Menu_Item *it;
3664    if (!wd) return;
3665    it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
3666    if (!it) return;
3667    wd->items = eina_list_append(wd->items, it);
3668    it->obj = obj;
3669    it->label = eina_stringshare_add(label);
3670    it->icon_file = eina_stringshare_add(icon_file);
3671    it->icon_type = icon_type;
3672    it->func = func;
3673    it->data = (void *)data;
3674 }
3675
3676 EAPI void
3677 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
3678 {
3679    ELM_CHECK_WIDTYPE(obj, widtype);
3680    Widget_Data *wd = elm_widget_data_get(obj);
3681    if (!wd) return;
3682    if (wd->context_menu == !disabled) return;
3683    wd->context_menu = !disabled;
3684
3685    if (!_elm_config->desktop_entry) // TIZEN ONLY : commit ? 
3686      edje_object_part_text_copy_paste_disabled_set(wd->ent, "elm.text", disabled);
3687 }
3688
3689 EAPI Eina_Bool
3690 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
3691 {
3692    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3693    Widget_Data *wd = elm_widget_data_get(obj);
3694    if (!wd) return EINA_FALSE;
3695    return !wd->context_menu;
3696 }
3697
3698 EAPI void
3699 elm_entry_item_provider_append(Evas_Object *obj, Elm_Entry_Item_Provider_Cb func, void *data)
3700 {
3701    ELM_CHECK_WIDTYPE(obj, widtype);
3702    Widget_Data *wd = elm_widget_data_get(obj);
3703    if (!wd) return;
3704    EINA_SAFETY_ON_NULL_RETURN(func);
3705    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3706    if (!ip) return;
3707    ip->func = func;
3708    ip->data = data;
3709    wd->item_providers = eina_list_append(wd->item_providers, ip);
3710 }
3711
3712 EAPI void
3713 elm_entry_item_provider_prepend(Evas_Object *obj, Elm_Entry_Item_Provider_Cb func, void *data)
3714 {
3715    ELM_CHECK_WIDTYPE(obj, widtype);
3716    Widget_Data *wd = elm_widget_data_get(obj);
3717    if (!wd) return;
3718    EINA_SAFETY_ON_NULL_RETURN(func);
3719    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3720    if (!ip) return;
3721    ip->func = func;
3722    ip->data = data;
3723    wd->item_providers = eina_list_prepend(wd->item_providers, ip);
3724 }
3725
3726 EAPI void
3727 elm_entry_item_provider_remove(Evas_Object *obj, Elm_Entry_Item_Provider_Cb func, void *data)
3728 {
3729    ELM_CHECK_WIDTYPE(obj, widtype);
3730    Widget_Data *wd = elm_widget_data_get(obj);
3731    Eina_List *l;
3732    Elm_Entry_Item_Provider *ip;
3733    if (!wd) return;
3734    EINA_SAFETY_ON_NULL_RETURN(func);
3735    EINA_LIST_FOREACH(wd->item_providers, l, ip)
3736      {
3737         if ((ip->func == func) && ((!data) || (ip->data == data)))
3738           {
3739              wd->item_providers = eina_list_remove_list(wd->item_providers, l);
3740              free(ip);
3741              return;
3742           }
3743      }
3744 }
3745
3746 EAPI void
3747 elm_entry_markup_filter_append(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
3748 {
3749    Widget_Data *wd;
3750    Elm_Entry_Markup_Filter *tf;
3751    ELM_CHECK_WIDTYPE(obj, widtype);
3752
3753    wd = elm_widget_data_get(obj);
3754
3755    EINA_SAFETY_ON_NULL_RETURN(func);
3756
3757    tf = _filter_new(func, data);
3758    if (!tf) return;
3759
3760    wd->markup_filters = eina_list_append(wd->markup_filters, tf);
3761 }
3762
3763 EAPI void
3764 elm_entry_markup_filter_prepend(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
3765 {
3766    Widget_Data *wd;
3767    Elm_Entry_Markup_Filter *tf;
3768    ELM_CHECK_WIDTYPE(obj, widtype);
3769
3770    wd = elm_widget_data_get(obj);
3771
3772    EINA_SAFETY_ON_NULL_RETURN(func);
3773
3774    tf = _filter_new(func, data);
3775    if (!tf) return;
3776
3777    wd->markup_filters = eina_list_prepend(wd->markup_filters, tf);
3778 }
3779
3780 EAPI void
3781 elm_entry_markup_filter_remove(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
3782 {
3783    Widget_Data *wd;
3784    Eina_List *l;
3785    Elm_Entry_Markup_Filter *tf;
3786    ELM_CHECK_WIDTYPE(obj, widtype);
3787
3788    wd = elm_widget_data_get(obj);
3789
3790    EINA_SAFETY_ON_NULL_RETURN(func);
3791
3792    EINA_LIST_FOREACH(wd->markup_filters, l, tf)
3793      {
3794         if ((tf->func == func) && ((!data) || (tf->data == data)))
3795           {
3796              wd->markup_filters = eina_list_remove_list(wd->markup_filters, l);
3797              _filter_free(tf);
3798              return;
3799           }
3800      }
3801 }
3802
3803 EAPI char *
3804 elm_entry_markup_to_utf8(const char *s)
3805 {
3806    char *ss = _elm_util_mkup_to_text(s);
3807    if (!ss) ss = strdup("");
3808    return ss;
3809 }
3810
3811 EAPI char *
3812 elm_entry_utf8_to_markup(const char *s)
3813 {
3814    char *ss = _elm_util_text_to_mkup(s);
3815    if (!ss) ss = strdup("");
3816    return ss;
3817 }
3818
3819 static const char *
3820 _text_get(const Evas_Object *obj)
3821 {
3822    return elm_object_text_get(obj);
3823 }
3824
3825 EAPI void
3826 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
3827 {
3828    Elm_Entry_Filter_Limit_Size *lim = data;
3829    char *current, *utfstr;
3830    int len, newlen;
3831    const char *(*text_get)(const Evas_Object *);
3832
3833    EINA_SAFETY_ON_NULL_RETURN(data);
3834    EINA_SAFETY_ON_NULL_RETURN(entry);
3835    EINA_SAFETY_ON_NULL_RETURN(text);
3836
3837    /* hack. I don't want to copy the entire function to work with
3838     * scrolled_entry */
3839    text_get = _text_get;
3840
3841    current = elm_entry_markup_to_utf8(text_get(entry));
3842    utfstr = elm_entry_markup_to_utf8(*text);
3843
3844    if (lim->max_char_count > 0)
3845      {
3846         len = evas_string_char_len_get(current);
3847         newlen = evas_string_char_len_get(utfstr);
3848         if ((len >= lim->max_char_count) && (newlen > 0))
3849           {
3850              evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3851              free(*text);
3852              *text = NULL;
3853              free(current);
3854              free(utfstr);
3855              return;
3856           }
3857         if ((len + newlen) > lim->max_char_count)
3858           _add_chars_till_limit(entry, text, (lim->max_char_count - len), LENGTH_UNIT_CHAR);
3859      }
3860    else if (lim->max_byte_count > 0)
3861      {
3862         len = strlen(current);
3863         newlen = strlen(utfstr);
3864         if ((len >= lim->max_byte_count) && (newlen > 0))
3865           {
3866              evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3867              free(*text);
3868              *text = NULL;
3869              free(current);
3870              free(utfstr);
3871              return;
3872           }
3873         if ((len + newlen) > lim->max_byte_count)
3874           _add_chars_till_limit(entry, text, (lim->max_byte_count - len), LENGTH_UNIT_BYTE);
3875      }
3876    free(current);
3877    free(utfstr);
3878 }
3879
3880 EAPI void
3881 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
3882 {
3883    Elm_Entry_Filter_Accept_Set *as = data;
3884    const char *set;
3885    char *insert;
3886    Eina_Bool goes_in;
3887    int read_idx, last_read_idx = 0, read_char;
3888
3889    EINA_SAFETY_ON_NULL_RETURN(data);
3890    EINA_SAFETY_ON_NULL_RETURN(text);
3891
3892    if ((!as->accepted) && (!as->rejected))
3893      return;
3894
3895    if (as->accepted)
3896      {
3897         set = as->accepted;
3898         goes_in = EINA_TRUE;
3899      }
3900    else
3901      {
3902         set = as->rejected;
3903         goes_in = EINA_FALSE;
3904      }
3905
3906    insert = *text;
3907    read_idx = evas_string_char_next_get(*text, 0, &read_char);
3908    while (read_char)
3909      {
3910         int cmp_idx, cmp_char;
3911         Eina_Bool in_set = EINA_FALSE;
3912
3913         cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
3914         while (cmp_char)
3915           {
3916              if (read_char == cmp_char)
3917                {
3918                   in_set = EINA_TRUE;
3919                   break;
3920                }
3921              cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
3922           }
3923         if (in_set == goes_in)
3924           {
3925              int size = read_idx - last_read_idx;
3926              const char *src = (*text) + last_read_idx;
3927              if (src != insert)
3928                memcpy(insert, *text + last_read_idx, size);
3929              insert += size;
3930           }
3931         last_read_idx = read_idx;
3932         read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
3933      }
3934    *insert = 0;
3935 }
3936
3937 EAPI Eina_Bool
3938 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
3939 {
3940    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3941    Widget_Data *wd = elm_widget_data_get(obj);
3942    if (!wd) return EINA_FALSE;
3943    if (wd->delay_write)
3944      {
3945         ecore_timer_del(wd->delay_write);
3946         wd->delay_write = NULL;
3947      }
3948    if (wd->autosave) _save(obj);
3949    eina_stringshare_replace(&wd->file, file);
3950    wd->format = format;
3951    return _load(obj);
3952 }
3953
3954 EAPI void
3955 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
3956 {
3957    ELM_CHECK_WIDTYPE(obj, widtype);
3958    Widget_Data *wd = elm_widget_data_get(obj);
3959    if (!wd) return;
3960    if (file) *file = wd->file;
3961    if (format) *format = wd->format;
3962 }
3963
3964 EAPI void
3965 elm_entry_file_save(Evas_Object *obj)
3966 {
3967    ELM_CHECK_WIDTYPE(obj, widtype);
3968    Widget_Data *wd = elm_widget_data_get(obj);
3969    if (!wd) return;
3970    if (wd->delay_write)
3971      {
3972         ecore_timer_del(wd->delay_write);
3973         wd->delay_write = NULL;
3974      }
3975    _save(obj);
3976    wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
3977 }
3978
3979 EAPI void
3980 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
3981 {
3982    ELM_CHECK_WIDTYPE(obj, widtype);
3983    Widget_Data *wd = elm_widget_data_get(obj);
3984    if (!wd) return;
3985    wd->autosave = !!autosave;
3986 }
3987
3988 EAPI Eina_Bool
3989 elm_entry_autosave_get(const Evas_Object *obj)
3990 {
3991    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3992    Widget_Data *wd = elm_widget_data_get(obj);
3993    if (!wd) return EINA_FALSE;
3994    return wd->autosave;
3995 }
3996
3997 EINA_DEPRECATED EAPI void
3998 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
3999 {
4000    ELM_CHECK_WIDTYPE(obj, widtype);
4001    Elm_Cnp_Mode cnp_mode = ELM_CNP_MODE_MARKUP;
4002    if (textonly)
4003      cnp_mode = ELM_CNP_MODE_NO_IMAGE;
4004    elm_entry_cnp_mode_set(obj, cnp_mode);
4005 }
4006
4007 EINA_DEPRECATED EAPI Eina_Bool
4008 elm_entry_cnp_textonly_get(const Evas_Object *obj)
4009 {
4010    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4011    return elm_entry_cnp_mode_get(obj) != ELM_CNP_MODE_MARKUP;
4012 }
4013
4014 EAPI void
4015 elm_entry_cnp_mode_set(Evas_Object *obj, Elm_Cnp_Mode cnp_mode)
4016 {
4017    Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
4018    ELM_CHECK_WIDTYPE(obj, widtype);
4019    Widget_Data *wd = elm_widget_data_get(obj);
4020    if (!wd) return;
4021    if (wd->cnp_mode == cnp_mode) return;
4022    wd->cnp_mode = cnp_mode;
4023    if (wd->cnp_mode == ELM_CNP_MODE_PLAINTEXT)
4024      format = ELM_SEL_FORMAT_TEXT;
4025    else if (cnp_mode == ELM_CNP_MODE_MARKUP) format |= ELM_SEL_FORMAT_IMAGE;
4026 #ifdef HAVE_ELEMENTARY_X
4027    elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
4028 #endif
4029 }
4030
4031 EAPI Elm_Cnp_Mode
4032 elm_entry_cnp_mode_get(const Evas_Object *obj)
4033 {
4034    ELM_CHECK_WIDTYPE(obj, widtype) ELM_CNP_MODE_MARKUP;
4035    Widget_Data *wd = elm_widget_data_get(obj);
4036    if (!wd) return ELM_CNP_MODE_MARKUP;
4037    return wd->cnp_mode;
4038 }
4039
4040 EAPI void
4041 elm_entry_scrollable_set(Evas_Object *obj, Eina_Bool scroll)
4042 {
4043    ELM_CHECK_WIDTYPE(obj, widtype);
4044    Widget_Data *wd = elm_widget_data_get(obj);
4045    const Elm_Scroller_Policy map[3] =
4046      {
4047         ELM_SMART_SCROLLER_POLICY_AUTO,
4048         ELM_SMART_SCROLLER_POLICY_ON,
4049         ELM_SMART_SCROLLER_POLICY_OFF
4050      };
4051    if (!wd) return;
4052    scroll = !!scroll;
4053    if (wd->scroll == scroll) return;
4054    wd->scroll = scroll;
4055    if (wd->scroll)
4056      {
4057         if (!wd->scroller)
4058           {
4059              wd->scroller = elm_smart_scroller_add(evas_object_evas_get(obj));
4060              elm_widget_resize_object_set(obj, wd->scroller);
4061              elm_smart_scroller_widget_set(wd->scroller, obj);
4062              elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
4063                                                  elm_widget_style_get(obj));
4064              evas_object_size_hint_weight_set(wd->scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
4065              evas_object_size_hint_align_set(wd->scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
4066              evas_object_propagate_events_set(wd->scroller, EINA_TRUE);
4067              evas_object_propagate_events_set(elm_smart_scroller_edje_object_get(wd->scroller),
4068                                               EINA_TRUE);
4069           }
4070         elm_smart_scroller_bounce_allow_set(wd->scroller, wd->h_bounce, wd->v_bounce);
4071         if (wd->single_line)
4072           elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
4073                                         ELM_SMART_SCROLLER_POLICY_OFF);
4074         else
4075           elm_smart_scroller_policy_set(wd->scroller, map[wd->policy_h], map[wd->policy_v]);
4076         elm_widget_sub_object_add(obj, wd->ent);
4077         elm_smart_scroller_child_set(wd->scroller, wd->ent);
4078         evas_object_show(wd->scroller);
4079         elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
4080      }
4081    else
4082      {
4083         if (wd->scroller)
4084           {
4085              elm_smart_scroller_child_set(wd->scroller, NULL);
4086              evas_object_smart_member_add(wd->scroller, obj);
4087              elm_widget_sub_object_add(obj, wd->scroller);
4088              evas_object_hide(wd->scroller);
4089           }
4090         elm_widget_sub_object_del(obj, wd->ent);
4091         elm_widget_resize_object_set(obj, wd->ent);
4092         elm_widget_on_show_region_hook_set(obj, NULL, NULL);
4093      }
4094    wd->lastw = -1;
4095    _theme_hook(obj);
4096 }
4097
4098 EAPI Eina_Bool
4099 elm_entry_scrollable_get(const Evas_Object *obj)
4100 {
4101    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4102    Widget_Data *wd = elm_widget_data_get(obj);
4103    if (!wd) return EINA_FALSE;
4104    return wd->scroll;
4105 }
4106
4107 EAPI void
4108 elm_entry_icon_visible_set(Evas_Object *obj, Eina_Bool setting)
4109 {
4110    ELM_CHECK_WIDTYPE(obj, widtype);
4111    Widget_Data *wd = elm_widget_data_get(obj);
4112    Evas_Object *edje;
4113    if (!wd) return;
4114    if (wd->scroll)
4115       edje = elm_smart_scroller_edje_object_get(wd->scroller);
4116    else
4117       edje = wd->ent;
4118
4119    if ((!edje) || (!edje_object_part_swallow_get(edje, "elm.swallow.icon"))) return;
4120    if (setting)
4121      edje_object_signal_emit(edje, "elm,action,show,icon", "elm");
4122    else
4123      edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
4124    _sizing_eval(obj);
4125 }
4126
4127 EAPI void
4128 elm_entry_end_visible_set(Evas_Object *obj, Eina_Bool setting)
4129 {
4130    ELM_CHECK_WIDTYPE(obj, widtype);
4131    Widget_Data *wd = elm_widget_data_get(obj);
4132    Evas_Object *edje;
4133    if (!wd) return;
4134    if (wd->scroll)
4135       edje = elm_smart_scroller_edje_object_get(wd->scroller);
4136    else
4137       edje = wd->ent;
4138
4139    if ((!edje) || (!edje_object_part_swallow_get(edje, "elm.swallow.icon"))) return;
4140    if (setting)
4141      edje_object_signal_emit(edje, "elm,action,show,end", "elm");
4142    else
4143      edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
4144    _sizing_eval(obj);
4145 }
4146
4147 EAPI void
4148 elm_entry_scrollbar_policy_set(Evas_Object *obj, Elm_Scroller_Policy h, Elm_Scroller_Policy v)
4149 {
4150    ELM_CHECK_WIDTYPE(obj, widtype);
4151    Widget_Data *wd = elm_widget_data_get(obj);
4152    const Elm_Scroller_Policy map[3] =
4153      {
4154         ELM_SMART_SCROLLER_POLICY_AUTO,
4155         ELM_SMART_SCROLLER_POLICY_ON,
4156         ELM_SMART_SCROLLER_POLICY_OFF
4157      };
4158    if (!wd) return;
4159    wd->policy_h = h;
4160    wd->policy_v = v;
4161    elm_smart_scroller_policy_set(wd->scroller,
4162                                  map[wd->policy_h],
4163                                  map[wd->policy_v]);
4164 }
4165
4166 EAPI void
4167 elm_entry_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
4168 {
4169    ELM_CHECK_WIDTYPE(obj, widtype);
4170    Widget_Data *wd = elm_widget_data_get(obj);
4171    if (!wd) return;
4172    wd->h_bounce = h_bounce;
4173    wd->v_bounce = v_bounce;
4174    elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
4175 }
4176
4177 EAPI void
4178 elm_entry_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
4179 {
4180    ELM_CHECK_WIDTYPE(obj, widtype);
4181    Widget_Data *wd = elm_widget_data_get(obj);
4182    if (!wd) return;
4183    elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
4184 }
4185
4186 EAPI void
4187 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
4188 {
4189    ELM_CHECK_WIDTYPE(obj, widtype);
4190    Widget_Data *wd = elm_widget_data_get(obj);
4191    if (!wd) return;
4192
4193    wd->input_panel_layout = layout;
4194
4195    edje_object_part_text_input_panel_layout_set(wd->ent, "elm.text", layout);
4196 }
4197
4198 EAPI Elm_Input_Panel_Layout
4199 elm_entry_input_panel_layout_get(const Evas_Object *obj)
4200 {
4201    ELM_CHECK_WIDTYPE(obj, widtype) ELM_INPUT_PANEL_LAYOUT_INVALID;
4202    Widget_Data *wd = elm_widget_data_get(obj);
4203    if (!wd) return ELM_INPUT_PANEL_LAYOUT_INVALID;
4204
4205    return wd->input_panel_layout;
4206 }
4207
4208 EAPI void
4209 elm_entry_autocapital_type_set(Evas_Object *obj, Elm_Autocapital_Type autocapital_type)
4210 {
4211    ELM_CHECK_WIDTYPE(obj, widtype);
4212    Widget_Data *wd = elm_widget_data_get(obj);
4213    if (!wd) return;
4214
4215    wd->autocapital_type = autocapital_type;
4216    edje_object_part_text_autocapital_type_set(wd->ent, "elm.text", autocapital_type);
4217 }
4218
4219 EAPI Elm_Autocapital_Type
4220 elm_entry_autocapital_type_get(const Evas_Object *obj)
4221 {
4222    ELM_CHECK_WIDTYPE(obj, widtype) ELM_AUTOCAPITAL_TYPE_NONE;
4223    Widget_Data *wd = elm_widget_data_get(obj);
4224    if (!wd) return ELM_AUTOCAPITAL_TYPE_NONE;
4225
4226    return wd->autocapital_type;
4227 }
4228
4229 EAPI void
4230 elm_entry_prediction_allow_set(Evas_Object *obj, Eina_Bool prediction)
4231 {
4232    ELM_CHECK_WIDTYPE(obj, widtype);
4233    Widget_Data *wd = elm_widget_data_get(obj);
4234    if (!wd) return;
4235
4236    wd->prediction_allow = prediction;
4237    edje_object_part_text_prediction_allow_set(wd->ent, "elm.text", prediction);
4238 }
4239
4240 EAPI Eina_Bool
4241 elm_entry_prediction_allow_get(const Evas_Object *obj)
4242 {
4243    ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
4244    Widget_Data *wd = elm_widget_data_get(obj);
4245    if (!wd) return EINA_TRUE;
4246
4247    return wd->prediction_allow;
4248 }
4249
4250 EAPI void
4251 elm_entry_imf_context_reset(Evas_Object *obj)
4252 {
4253    ELM_CHECK_WIDTYPE(obj, widtype);
4254    Widget_Data *wd = elm_widget_data_get(obj);
4255    if (!wd) return;
4256
4257    edje_object_part_text_imf_context_reset(wd->ent, "elm.text");
4258 }
4259
4260 EAPI void
4261 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
4262 {
4263    ELM_CHECK_WIDTYPE(obj, widtype);
4264    Widget_Data *wd = elm_widget_data_get(obj);
4265    if (!wd) return;
4266
4267    wd->input_panel_enable = enabled;
4268    edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
4269 }
4270
4271 EAPI Eina_Bool
4272 elm_entry_input_panel_enabled_get(const Evas_Object *obj)
4273 {
4274    ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
4275    Widget_Data *wd = elm_widget_data_get(obj);
4276    if (!wd) return EINA_TRUE;
4277
4278    return wd->input_panel_enable;
4279 }
4280
4281 EAPI void
4282 elm_entry_input_panel_show(Evas_Object *obj)
4283 {
4284    ELM_CHECK_WIDTYPE(obj, widtype);
4285    Widget_Data *wd = elm_widget_data_get(obj);
4286    if (!wd) return;
4287
4288    edje_object_part_text_input_panel_show(wd->ent, "elm.text");
4289 }
4290
4291 EAPI void
4292 elm_entry_input_panel_hide(Evas_Object *obj)
4293 {
4294    ELM_CHECK_WIDTYPE(obj, widtype);
4295    Widget_Data *wd = elm_widget_data_get(obj);
4296    if (!wd) return;
4297
4298    edje_object_part_text_input_panel_hide(wd->ent, "elm.text");
4299 }
4300
4301 EAPI void
4302 elm_entry_input_panel_language_set(Evas_Object *obj, Elm_Input_Panel_Lang lang)
4303 {
4304    ELM_CHECK_WIDTYPE(obj, widtype);
4305    Widget_Data *wd = elm_widget_data_get(obj);
4306    if (!wd) return;
4307
4308    wd->input_panel_lang = lang;
4309    edje_object_part_text_input_panel_language_set(wd->ent, "elm.text", lang);
4310 }
4311
4312 EAPI Elm_Input_Panel_Lang
4313 elm_entry_input_panel_language_get(const Evas_Object *obj)
4314 {
4315    ELM_CHECK_WIDTYPE(obj, widtype) ELM_INPUT_PANEL_LANG_AUTOMATIC;
4316    Widget_Data *wd = elm_widget_data_get(obj);
4317    if (!wd) return ELM_INPUT_PANEL_LANG_AUTOMATIC;
4318
4319    return wd->input_panel_lang;
4320 }
4321
4322 EAPI void
4323 elm_entry_input_panel_imdata_set(Evas_Object *obj, const void *data, int len)
4324 {
4325    ELM_CHECK_WIDTYPE(obj, widtype);
4326    Widget_Data *wd = elm_widget_data_get(obj);
4327    if (!wd) return;
4328
4329    if (wd->input_panel_imdata)
4330      free(wd->input_panel_imdata);
4331
4332    wd->input_panel_imdata = calloc(1, len);
4333    wd->input_panel_imdata_len = len;
4334    memcpy(wd->input_panel_imdata, data, len);
4335
4336    edje_object_part_text_input_panel_imdata_set(wd->ent, "elm.text", wd->input_panel_imdata, wd->input_panel_imdata_len);
4337 }
4338
4339 EAPI void
4340 elm_entry_input_panel_imdata_get(const Evas_Object *obj, void *data, int *len)
4341 {
4342    ELM_CHECK_WIDTYPE(obj, widtype);
4343    Widget_Data *wd = elm_widget_data_get(obj);
4344    if (!wd) return;
4345
4346    edje_object_part_text_input_panel_imdata_get(wd->ent, "elm.text", data, len);
4347 }
4348
4349 EAPI void
4350 elm_entry_input_panel_return_key_type_set(Evas_Object *obj, Elm_Input_Panel_Return_Key_Type return_key_type)
4351 {
4352    ELM_CHECK_WIDTYPE(obj, widtype);
4353    Widget_Data *wd = elm_widget_data_get(obj);
4354    if (!wd) return;
4355
4356    wd->input_panel_return_key_type = return_key_type;
4357
4358    edje_object_part_text_input_panel_return_key_type_set(wd->ent, "elm.text", return_key_type);
4359 }
4360
4361 EAPI Elm_Input_Panel_Return_Key_Type
4362 elm_entry_input_panel_return_key_type_get(const Evas_Object *obj)
4363 {
4364    ELM_CHECK_WIDTYPE(obj, widtype) ELM_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT;
4365    Widget_Data *wd = elm_widget_data_get(obj);
4366    if (!wd) return ELM_INPUT_PANEL_RETURN_KEY_TYPE_DEFAULT;
4367
4368    return wd->input_panel_return_key_type;
4369 }
4370
4371 EAPI void
4372 elm_entry_input_panel_return_key_disabled_set(Evas_Object *obj, Eina_Bool disabled)
4373 {
4374    ELM_CHECK_WIDTYPE(obj, widtype);
4375    Widget_Data *wd = elm_widget_data_get(obj);
4376    if (!wd) return;
4377
4378    wd->input_panel_return_key_disabled = disabled;
4379
4380    edje_object_part_text_input_panel_return_key_disabled_set(wd->ent, "elm.text", disabled);
4381 }
4382
4383 EAPI Eina_Bool
4384 elm_entry_input_panel_return_key_disabled_get(const Evas_Object *obj)
4385 {
4386    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4387    Widget_Data *wd = elm_widget_data_get(obj);
4388    if (!wd) return EINA_FALSE;
4389
4390    return wd->input_panel_return_key_disabled;
4391 }
4392
4393 EAPI void
4394 elm_entry_input_panel_return_key_autoenabled_set(Evas_Object *obj, Eina_Bool enabled)
4395 {
4396    ELM_CHECK_WIDTYPE(obj, widtype);
4397    Widget_Data *wd = elm_widget_data_get(obj);
4398    if (!wd) return;
4399
4400    wd->autoreturnkey = enabled;
4401    _check_enable_return_key(obj);
4402 }
4403
4404 EAPI void*
4405 elm_entry_imf_context_get(Evas_Object *obj)
4406 {
4407    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4408    Widget_Data *wd = elm_widget_data_get(obj);
4409    if (!wd) return NULL;
4410
4411    return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
4412 }
4413
4414 /* START - ANCHOR HOVER */
4415 static void
4416 _parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
4417 {
4418    Widget_Data *wd = elm_widget_data_get(data);
4419    if (!wd) return;
4420    wd->anchor_hover.hover_parent = NULL;
4421 }
4422
4423 EAPI void
4424 elm_entry_anchor_hover_parent_set(Evas_Object *obj, Evas_Object *parent)
4425 {
4426    ELM_CHECK_WIDTYPE(obj, widtype);
4427    Widget_Data *wd = elm_widget_data_get(obj);
4428    if (!wd) return;
4429    if (wd->anchor_hover.hover_parent)
4430      evas_object_event_callback_del_full(wd->anchor_hover.hover_parent, EVAS_CALLBACK_DEL, _parent_del, obj);
4431    wd->anchor_hover.hover_parent = parent;
4432    if (wd->anchor_hover.hover_parent)
4433      evas_object_event_callback_add(wd->anchor_hover.hover_parent, EVAS_CALLBACK_DEL, _parent_del, obj);
4434 }
4435
4436 EAPI Evas_Object *
4437 elm_entry_anchor_hover_parent_get(const Evas_Object *obj)
4438 {
4439    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4440    Widget_Data *wd = elm_widget_data_get(obj);
4441    if (!wd) return NULL;
4442    return wd->anchor_hover.hover_parent;
4443 }
4444
4445 EAPI void
4446 elm_entry_anchor_hover_style_set(Evas_Object *obj, const char *style)
4447 {
4448    ELM_CHECK_WIDTYPE(obj, widtype);
4449    Widget_Data *wd = elm_widget_data_get(obj);
4450    if (!wd) return;
4451    eina_stringshare_replace(&wd->anchor_hover.hover_style, style);
4452 }
4453
4454 EAPI const char *
4455 elm_entry_anchor_hover_style_get(const Evas_Object *obj)
4456 {
4457    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4458    Widget_Data *wd = elm_widget_data_get(obj);
4459    if (!wd) return NULL;
4460    return wd->anchor_hover.hover_style;
4461 }
4462
4463 EAPI void
4464 elm_entry_anchor_hover_end(Evas_Object *obj)
4465 {
4466    ELM_CHECK_WIDTYPE(obj, widtype);
4467    Widget_Data *wd = elm_widget_data_get(obj);
4468    if (!wd) return;
4469    if (wd->anchor_hover.hover) evas_object_del(wd->anchor_hover.hover);
4470    if (wd->anchor_hover.pop) evas_object_del(wd->anchor_hover.pop);
4471    wd->anchor_hover.hover = NULL;
4472    wd->anchor_hover.pop = NULL;
4473 }
4474
4475
4476 static void
4477 _anchor_hover_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
4478 {
4479    elm_entry_anchor_hover_end(data);
4480 }
4481
4482 static void
4483 _entry_hover_anchor_clicked(void *data, Evas_Object *obj, void *event_info)
4484 {
4485    Widget_Data *wd = elm_widget_data_get(obj);
4486    Elm_Entry_Anchor_Info *info = event_info;
4487    Evas_Object *hover_parent;
4488    Elm_Entry_Anchor_Hover_Info ei;
4489    Evas_Coord x, w, y, h, px, py;
4490    if (!wd) return;
4491
4492    ei.anchor_info = event_info;
4493
4494    wd->anchor_hover.pop = elm_icon_add(obj);
4495    evas_object_move(wd->anchor_hover.pop, info->x, info->y);
4496    evas_object_resize(wd->anchor_hover.pop, info->w, info->h);
4497
4498    wd->anchor_hover.hover = elm_hover_add(obj);
4499    elm_widget_mirrored_set(wd->anchor_hover.hover, elm_widget_mirrored_get(obj));
4500    if (wd->anchor_hover.hover_style)
4501      elm_object_style_set(wd->anchor_hover.hover, wd->anchor_hover.hover_style);
4502
4503    hover_parent = wd->anchor_hover.hover_parent;
4504    if (!hover_parent) hover_parent = obj;
4505    elm_hover_parent_set(wd->anchor_hover.hover, hover_parent);
4506    elm_hover_target_set(wd->anchor_hover.hover, wd->anchor_hover.pop);
4507    ei.hover = wd->anchor_hover.hover;
4508
4509    evas_object_geometry_get(hover_parent, &x, &y, &w, &h);
4510    ei.hover_parent.x = x;
4511    ei.hover_parent.y = y;
4512    ei.hover_parent.w = w;
4513    ei.hover_parent.h = h;
4514    px = info->x + (info->w / 2);
4515    py = info->y + (info->h / 2);
4516    ei.hover_left = 1;
4517    if (px < (x + (w / 3))) ei.hover_left = 0;
4518    ei.hover_right = 1;
4519    if (px > (x + ((w * 2) / 3))) ei.hover_right = 0;
4520    ei.hover_top = 1;
4521    if (py < (y + (h / 3))) ei.hover_top = 0;
4522    ei.hover_bottom = 1;
4523    if (py > (y + ((h * 2) / 3))) ei.hover_bottom = 0;
4524
4525    if (elm_widget_mirrored_get(wd->anchor_hover.hover))
4526      {  /* Swap right and left because they switch sides in RTL */
4527         Eina_Bool tmp = ei.hover_left;
4528         ei.hover_left = ei.hover_right;
4529         ei.hover_right = tmp;
4530      }
4531
4532    evas_object_smart_callback_call(data, SIG_ANCHOR_HOVER_OPENED, &ei);
4533    evas_object_smart_callback_add(wd->anchor_hover.hover, "clicked", _anchor_hover_clicked, data);
4534
4535    /* FIXME: Should just check if there's any callback registered to the smart
4536     * events instead.
4537     * This is used to determine if anyone cares about the hover or not. */
4538    if (!elm_object_part_content_get(wd->anchor_hover.hover, "middle") &&
4539          !elm_object_part_content_get(wd->anchor_hover.hover, "left") &&
4540          !elm_object_part_content_get(wd->anchor_hover.hover, "right") &&
4541          !elm_object_part_content_get(wd->anchor_hover.hover, "top") &&
4542          !elm_object_part_content_get(wd->anchor_hover.hover, "bottom"))
4543      {
4544         evas_object_del(wd->anchor_hover.hover);
4545      }
4546    else
4547      {
4548         evas_object_show(wd->anchor_hover.hover);
4549      }
4550 }
4551 /* END - ANCHOR HOVER */
4552
4553 EAPI void
4554 elm_entry_magnifier_disabled_set(Evas_Object *obj, Eina_Bool disabled)
4555 {
4556    ELM_CHECK_WIDTYPE(obj, widtype);
4557    Widget_Data *wd = elm_widget_data_get(obj);
4558    if (!wd) return;
4559    if (wd->magnifier_enabled == !disabled) return;
4560    wd->magnifier_enabled = !disabled;
4561 }
4562
4563 EAPI Eina_Bool
4564 elm_entry_magnifier_disabled_get(const Evas_Object *obj)
4565 {
4566    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4567    Widget_Data *wd = elm_widget_data_get(obj);
4568    if (!wd) return EINA_FALSE;
4569    return !wd->magnifier_enabled;
4570 }
4571
4572 EAPI void
4573 elm_entry_magnifier_type_set(Evas_Object *obj, int type)
4574 {
4575    ELM_CHECK_WIDTYPE(obj, widtype);
4576    Widget_Data *wd = elm_widget_data_get(obj);
4577    if (!wd) return;
4578
4579    wd->mgf_type = type;
4580    _magnifier_create(obj);
4581 }