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