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