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