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