Add elm_entry_prediction_allow_set/get
[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 "els_scroller.h"
5
6
7 /* Maximum chunk size to be inserted to the entry at once
8  * FIXME: This size is arbitrary, should probably choose a better size.
9  * Possibly also find a way to set it to a low value for weak computers,
10  * and to a big value for better computers. */
11 #define _CHUNK_SIZE 10000
12
13 typedef struct _Mod_Api Mod_Api;
14
15 typedef struct _Widget_Data Widget_Data;
16 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
17 typedef struct _Elm_Entry_Item_Provider Elm_Entry_Item_Provider;
18 typedef struct _Elm_Entry_Markup_Filter Elm_Entry_Markup_Filter;
19
20 struct _Widget_Data
21 {
22    Evas_Object *ent, *scroller;
23    Evas_Object *hoversel;
24    Ecore_Job *deferred_recalc_job;
25    Ecore_Event_Handler *sel_notify_handler;
26    Ecore_Event_Handler *sel_clear_handler;
27    Ecore_Timer *longpress_timer;
28    Ecore_Timer *delay_write;
29    /* for deferred appending */
30    Ecore_Idler *append_text_idler;
31    char *append_text_left;
32    int append_text_position;
33    int append_text_len;
34    /* Only for clipboard */
35    const char *cut_sel;
36    const char *text;
37    const char *file;
38    Elm_Text_Format format;
39    Evas_Coord lastw, entmw, entmh;
40    Evas_Coord downx, downy;
41    Eina_List *items;
42    Eina_List *item_providers;
43    Eina_List *text_filters;
44    Eina_List *markup_filters;
45    Ecore_Job *hovdeljob;
46    Mod_Api *api; // module api if supplied
47    int cursor_pos;
48    Elm_Scroller_Policy policy_h, policy_v;
49    Elm_Wrap_Type linewrap;
50    Elm_Input_Panel_Layout input_panel_layout;
51    Elm_Autocapital_Type autocapital_type;
52    Eina_Bool changed : 1;
53    Eina_Bool single_line : 1;
54    Eina_Bool password : 1;
55    Eina_Bool editable : 1;
56    Eina_Bool selection_asked : 1;
57    Eina_Bool have_selection : 1;
58    Eina_Bool selmode : 1;
59    Eina_Bool deferred_cur : 1;
60    Eina_Bool cur_changed : 1;
61    Eina_Bool disabled : 1;
62    Eina_Bool context_menu : 1;
63    Eina_Bool drag_selection_asked : 1;
64    Eina_Bool can_write : 1;
65    Eina_Bool autosave : 1;
66    Eina_Bool textonly : 1;
67    Eina_Bool usedown : 1;
68    Eina_Bool scroll : 1;
69    Eina_Bool h_bounce : 1;
70    Eina_Bool v_bounce : 1;
71    Eina_Bool input_panel_enable : 1;
72    Eina_Bool prediction_allow : 1;
73 };
74
75 struct _Elm_Entry_Context_Menu_Item
76 {
77    Evas_Object *obj;
78    const char *label;
79    const char *icon_file;
80    const char *icon_group;
81    Elm_Icon_Type icon_type;
82    Evas_Smart_Cb func;
83    void *data;
84 };
85
86 struct _Elm_Entry_Item_Provider
87 {
88    Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
89    void *data;
90 };
91
92 struct _Elm_Entry_Markup_Filter
93 {
94    Elm_Entry_Filter_Cb func;
95    void *data;
96 };
97
98 typedef enum _Length_Unit
99 {
100    LENGTH_UNIT_CHAR,
101    LENGTH_UNIT_BYTE,
102    LENGTH_UNIT_LAST
103 } Length_Unit;
104
105 static const char *widtype = NULL;
106
107 #ifdef HAVE_ELEMENTARY_X
108 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
109 #endif
110 static void _del_hook(Evas_Object *obj);
111 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
112 static void _theme_hook(Evas_Object *obj);
113 static void _disable_hook(Evas_Object *obj);
114 static void _sizing_eval(Evas_Object *obj);
115 static void _on_focus_hook(void *data, Evas_Object *obj);
116 static void _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content);
117 static Evas_Object *_content_unset_hook(Evas_Object *obj, const char *part);
118 static Evas_Object *_content_get_hook(const Evas_Object *obj, const char *part);
119 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
120 static const char *_getbase(Evas_Object *obj);
121 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
122 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
123 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
124 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
125 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
126 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
127 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
128 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
129 static void _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit);
130
131 static const char SIG_CHANGED[] = "changed";
132 static const char SIG_CHANGED_USER[] = "changed,user";
133 static const char SIG_ACTIVATED[] = "activated";
134 static const char SIG_PRESS[] = "press";
135 static const char SIG_LONGPRESSED[] = "longpressed";
136 static const char SIG_CLICKED[] = "clicked";
137 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
138 static const char SIG_CLICKED_TRIPLE[] = "clicked,triple";
139 static const char SIG_FOCUSED[] = "focused";
140 static const char SIG_UNFOCUSED[] = "unfocused";
141 static const char SIG_SELECTION_PASTE[] = "selection,paste";
142 static const char SIG_SELECTION_COPY[] = "selection,copy";
143 static const char SIG_SELECTION_CUT[] = "selection,cut";
144 static const char SIG_SELECTION_START[] = "selection,start";
145 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
146 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
147 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
148 static const char SIG_CURSOR_CHANGED_MANUAL[] = "cursor,changed,manual";
149 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
150 static const char SIG_ANCHOR_DOWN[] = "anchor,down";
151 static const char SIG_ANCHOR_UP[] = "anchor,up";
152 static const char SIG_ANCHOR_IN[] = "anchor,in";
153 static const char SIG_ANCHOR_OUT[] = "anchor,out";
154 static const char SIG_PREEDIT_CHANGED[] = "preedit,changed";
155 static const char SIG_UNDO_REQUEST[] = "undo,request";
156 static const char SIG_REDO_REQUEST[] = "redo,request";
157 static const Evas_Smart_Cb_Description _signals[] = {
158        {SIG_CHANGED, ""},
159        {SIG_ACTIVATED, ""},
160        {SIG_PRESS, ""},
161        {SIG_LONGPRESSED, ""},
162        {SIG_CLICKED, ""},
163        {SIG_CLICKED_DOUBLE, ""},
164        {SIG_CLICKED_TRIPLE, ""},
165        {SIG_FOCUSED, ""},
166        {SIG_UNFOCUSED, ""},
167        {SIG_SELECTION_PASTE, ""},
168        {SIG_SELECTION_COPY, ""},
169        {SIG_SELECTION_CUT, ""},
170        {SIG_SELECTION_START, ""},
171        {SIG_SELECTION_CHANGED, ""},
172        {SIG_SELECTION_CLEARED, ""},
173        {SIG_CURSOR_CHANGED, ""},
174        {SIG_CURSOR_CHANGED_MANUAL, ""},
175        {SIG_ANCHOR_CLICKED, ""},
176        {SIG_ANCHOR_DOWN, ""},
177        {SIG_ANCHOR_UP, ""},
178        {SIG_ANCHOR_IN, ""},
179        {SIG_ANCHOR_OUT, ""},
180        {SIG_PREEDIT_CHANGED, ""},
181        {SIG_CHANGED_USER, ""},
182        {SIG_UNDO_REQUEST, ""},
183        {SIG_REDO_REQUEST, ""},
184        {NULL, NULL}
185 };
186
187 static Eina_List *entries = NULL;
188
189 struct _Mod_Api
190 {
191    void (*obj_hook) (Evas_Object *obj);
192    void (*obj_unhook) (Evas_Object *obj);
193    void (*obj_longpress) (Evas_Object *obj);
194 };
195
196 static Mod_Api *
197 _module(Evas_Object *obj __UNUSED__)
198 {
199    static Elm_Module *m = NULL;
200    if (m) goto ok; // already found - just use
201    if (!(m = _elm_module_find_as("entry/api"))) return NULL;
202    // get module api
203    m->api = malloc(sizeof(Mod_Api));
204    if (!m->api) return NULL;
205    ((Mod_Api *)(m->api)      )->obj_hook = // called on creation
206       _elm_module_symbol_get(m, "obj_hook");
207    ((Mod_Api *)(m->api)      )->obj_unhook = // called on deletion
208       _elm_module_symbol_get(m, "obj_unhook");
209    ((Mod_Api *)(m->api)      )->obj_longpress = // called on long press menu
210       _elm_module_symbol_get(m, "obj_longpress");
211 ok: // ok - return api
212    return m->api;
213 }
214
215 static char *
216 _buf_append(char *buf, const char *str, int *len, int *alloc)
217 {
218    int len2 = strlen(str);
219    if ((*len + len2) >= *alloc)
220      {
221         char *buf2 = realloc(buf, *alloc + len2 + 512);
222         if (!buf2) return NULL;
223         buf = buf2;
224         *alloc += (512 + len2);
225      }
226    strcpy(buf + *len, str);
227    *len += len2;
228    return buf;
229 }
230
231 static char *
232 _load_file(const char *file)
233 {
234    FILE *f;
235    size_t size;
236    int alloc = 0, len = 0;
237    char *text = NULL, buf[16384 + 1];
238
239    f = fopen(file, "rb");
240    if (!f) return NULL;
241    while ((size = fread(buf, 1, sizeof(buf) - 1, f)))
242      {
243         char *tmp_text;
244         buf[size] = 0;
245         tmp_text = _buf_append(text, buf, &len, &alloc);
246         if (!tmp_text) break;
247         text = tmp_text;
248      }
249    fclose(f);
250    return text;
251 }
252
253 static char *
254 _load_plain(const char *file)
255 {
256    char *text;
257
258    text = _load_file(file);
259    if (text)
260      {
261         char *text2;
262
263         text2 = elm_entry_utf8_to_markup(text);
264         free(text);
265         return text2;
266      }
267    return NULL;
268 }
269
270 static void
271 _load(Evas_Object *obj)
272 {
273    Widget_Data *wd = elm_widget_data_get(obj);
274    char *text;
275    if (!wd) return;
276    if (!wd->file)
277      {
278         elm_object_text_set(obj, "");
279         return;
280      }
281    switch (wd->format)
282      {
283       case ELM_TEXT_FORMAT_PLAIN_UTF8:
284          text = _load_plain(wd->file);
285          break;
286       case ELM_TEXT_FORMAT_MARKUP_UTF8:
287          text = _load_file(wd->file);
288          break;
289       default:
290          text = NULL;
291          break;
292      }
293    if (text)
294      {
295         elm_object_text_set(obj, text);
296         free(text);
297      }
298    else
299      elm_object_text_set(obj, "");
300 }
301
302 static void
303 _save_markup_utf8(const char *file, const char *text)
304 {
305    FILE *f;
306
307    if ((!text) || (!text[0]))
308      {
309         ecore_file_unlink(file);
310         return;
311      }
312    f = fopen(file, "wb");
313    if (!f)
314      {
315         // FIXME: report a write error
316         return;
317      }
318    fputs(text, f); // FIXME: catch error
319    fclose(f);
320 }
321
322 static void
323 _save_plain_utf8(const char *file, const char *text)
324 {
325    char *text2;
326
327    text2 = elm_entry_markup_to_utf8(text);
328    if (!text2)
329      return;
330    _save_markup_utf8(file, text2);
331    free(text2);
332 }
333
334 static void
335 _save(Evas_Object *obj)
336 {
337    Widget_Data *wd = elm_widget_data_get(obj);
338    if (!wd) return;
339    if (!wd->file) return;
340    switch (wd->format)
341      {
342       case ELM_TEXT_FORMAT_PLAIN_UTF8:
343          _save_plain_utf8(wd->file, elm_object_text_get(obj));
344          break;
345       case ELM_TEXT_FORMAT_MARKUP_UTF8:
346          _save_markup_utf8(wd->file, elm_object_text_get(obj));
347          break;
348       default:
349          break;
350      }
351 }
352
353 static Eina_Bool
354 _delay_write(void *data)
355 {
356    Widget_Data *wd = elm_widget_data_get(data);
357    if (!wd) return ECORE_CALLBACK_CANCEL;
358    _save(data);
359    wd->delay_write = NULL;
360    return ECORE_CALLBACK_CANCEL;
361 }
362
363 static Elm_Entry_Markup_Filter *
364 _filter_new(Elm_Entry_Filter_Cb func, void *data)
365 {
366    Elm_Entry_Markup_Filter *tf = ELM_NEW(Elm_Entry_Markup_Filter);
367    if (!tf) return NULL;
368
369    tf->func = func;
370    if (func == elm_entry_filter_limit_size)
371      {
372         Elm_Entry_Filter_Limit_Size *lim = data, *lim2;
373
374         if (!data)
375           {
376              free(tf);
377              return NULL;
378           }
379         lim2 = malloc(sizeof(Elm_Entry_Filter_Limit_Size));
380         if (!lim2)
381           {
382              free(tf);
383              return NULL;
384           }
385         memcpy(lim2, lim, sizeof(Elm_Entry_Filter_Limit_Size));
386         tf->data = lim2;
387      }
388    else if (func == elm_entry_filter_accept_set)
389      {
390         Elm_Entry_Filter_Accept_Set *as = data, *as2;
391
392         if (!data)
393           {
394              free(tf);
395              return NULL;
396           }
397         as2 = malloc(sizeof(Elm_Entry_Filter_Accept_Set));
398         if (!as2)
399           {
400              free(tf);
401              return NULL;
402           }
403         if (as->accepted)
404           as2->accepted = eina_stringshare_add(as->accepted);
405         else
406           as2->accepted = NULL;
407         if (as->rejected)
408           as2->rejected = eina_stringshare_add(as->rejected);
409         else
410           as2->rejected = NULL;
411         tf->data = as2;
412      }
413    else
414      tf->data = data;
415    return tf;
416 }
417
418 static void
419 _filter_free(Elm_Entry_Markup_Filter *tf)
420 {
421    if (tf->func == elm_entry_filter_limit_size)
422      {
423         Elm_Entry_Filter_Limit_Size *lim = tf->data;
424         if (lim) free(lim);
425      }
426    else if (tf->func == elm_entry_filter_accept_set)
427      {
428         Elm_Entry_Filter_Accept_Set *as = tf->data;
429         if (as)
430           {
431              if (as->accepted) eina_stringshare_del(as->accepted);
432              if (as->rejected) eina_stringshare_del(as->rejected);
433              free(as);
434           }
435      }
436    free(tf);
437 }
438
439 static void
440 _del_pre_hook(Evas_Object *obj)
441 {
442    Widget_Data *wd = elm_widget_data_get(obj);
443    if (!wd) return;
444    if (wd->delay_write)
445      {
446         ecore_timer_del(wd->delay_write);
447         wd->delay_write = NULL;
448         if (wd->autosave) _save(obj);
449      }
450 }
451
452 static void
453 _del_hook(Evas_Object *obj)
454 {
455    Widget_Data *wd = elm_widget_data_get(obj);
456    Elm_Entry_Context_Menu_Item *it;
457    Elm_Entry_Item_Provider *ip;
458    Elm_Entry_Markup_Filter *tf;
459
460    evas_event_freeze(evas_object_evas_get(obj));
461
462    if (wd->file) eina_stringshare_del(wd->file);
463
464    if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
465    if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
466
467    entries = eina_list_remove(entries, obj);
468 #ifdef HAVE_ELEMENTARY_X
469    if (wd->sel_notify_handler)
470      ecore_event_handler_del(wd->sel_notify_handler);
471    if (wd->sel_clear_handler)
472      ecore_event_handler_del(wd->sel_clear_handler);
473 #endif
474    if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
475    if (wd->text) eina_stringshare_del(wd->text);
476    if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
477    if (wd->append_text_idler)
478      {
479         ecore_idler_del(wd->append_text_idler);
480         free(wd->append_text_left);
481         wd->append_text_left = NULL;
482         wd->append_text_idler = NULL;
483      }
484    if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
485    EINA_LIST_FREE(wd->items, it)
486      {
487         eina_stringshare_del(it->label);
488         eina_stringshare_del(it->icon_file);
489         eina_stringshare_del(it->icon_group);
490         free(it);
491      }
492    EINA_LIST_FREE(wd->item_providers, ip)
493      {
494         free(ip);
495      }
496    EINA_LIST_FREE(wd->text_filters, tf)
497      {
498         _filter_free(tf);
499      }
500    EINA_LIST_FREE(wd->markup_filters, tf)
501      {
502         _filter_free(tf);
503      }
504    if (wd->delay_write) ecore_timer_del(wd->delay_write);
505    free(wd);
506
507    evas_event_thaw(evas_object_evas_get(obj));
508    evas_event_thaw_eval(evas_object_evas_get(obj));
509 }
510
511 static void
512 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
513 {
514    Widget_Data *wd = elm_widget_data_get(obj);
515    edje_object_mirrored_set(wd->ent, rtl);
516 }
517
518 static void
519 _theme_hook(Evas_Object *obj)
520 {
521    Widget_Data *wd = elm_widget_data_get(obj);
522    const char *t;
523
524    evas_event_freeze(evas_object_evas_get(obj));
525    _elm_widget_mirrored_reload(obj);
526    _mirrored_set(obj, elm_widget_mirrored_get(obj));
527
528    t = eina_stringshare_add(elm_object_text_get(obj));
529    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
530    if (_elm_config->desktop_entry)
531      edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
532    elm_object_text_set(obj, t);
533    eina_stringshare_del(t);
534    if (elm_widget_disabled_get(obj))
535      edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
536    edje_object_part_text_input_panel_layout_set(wd->ent, "elm.text", wd->input_panel_layout);
537    edje_object_part_text_autocapital_type_set(wd->ent, "elm.text", wd->autocapital_type);
538    edje_object_part_text_prediction_allow_set(wd->ent, "elm.text", wd->prediction_allow);
539    edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", wd->input_panel_enable);
540
541    if (wd->cursor_pos != 0)
542      elm_entry_cursor_pos_set(obj, wd->cursor_pos);
543    if (elm_widget_focus_get(obj))
544      edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
545    edje_object_message_signal_process(wd->ent);
546    edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
547    if (wd->scroll)
548      {
549         const char *str;
550         Evas_Object *edj;
551
552         elm_smart_scroller_mirrored_set(wd->scroller, elm_widget_mirrored_get(obj));
553         elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
554                                        elm_widget_style_get(obj));
555         edj = elm_smart_scroller_edje_object_get(wd->scroller);
556         str = edje_object_data_get(edj, "focus_highlight");
557         if ((str) && (!strcmp(str, "on")))
558           elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
559         else
560           elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
561      }
562    _sizing_eval(obj);
563    evas_event_thaw(evas_object_evas_get(obj));
564    evas_event_thaw_eval(evas_object_evas_get(obj));
565 }
566
567 static void
568 _disable_hook(Evas_Object *obj)
569 {
570    Widget_Data *wd = elm_widget_data_get(obj);
571
572    if (elm_widget_disabled_get(obj))
573      {
574         edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
575         wd->disabled = EINA_TRUE;
576      }
577    else
578      {
579         edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
580         wd->disabled = EINA_FALSE;
581      }
582 }
583
584 static void
585 _recalc_cursor_geometry(Evas_Object *obj)
586 {
587    Widget_Data *wd = elm_widget_data_get(obj);
588    if (!wd) return;
589    evas_object_smart_callback_call(obj, SIG_CURSOR_CHANGED, NULL);
590    if (!wd->deferred_recalc_job)
591      {
592         Evas_Coord cx, cy, cw, ch;
593         edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
594                                                   &cx, &cy, &cw, &ch);
595         if (wd->cur_changed)
596           {
597              elm_widget_show_region_set(obj, cx, cy, cw, ch, EINA_FALSE);
598              wd->cur_changed = EINA_FALSE;
599           }
600      }
601    else
602      wd->deferred_cur = EINA_TRUE;
603 }
604
605 static void
606 _elm_deferred_recalc_job(void *data)
607 {
608    Widget_Data *wd = elm_widget_data_get(data);
609    Evas_Coord minh = -1, resw = -1, minw = -1, fw = 0, fh = 0;
610    if (!wd) return;
611    wd->deferred_recalc_job = NULL;
612
613    evas_object_geometry_get(wd->ent, NULL, NULL, &resw, NULL);
614    edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
615    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
616    /* This is a hack to workaround the way min size hints are treated.
617     * If the minimum width is smaller than the restricted width, it means
618     * the mininmum doesn't matter. */
619    if (minw <= resw)
620      {
621         Evas_Coord ominw = -1;
622         evas_object_size_hint_min_get(data, &ominw, NULL);
623         minw = ominw;
624      }
625
626    wd->entmw = minw;
627    wd->entmh = minh;
628
629    elm_coords_finger_size_adjust(1, &fw, 1, &fh);
630    if (wd->scroll)
631      {
632         Evas_Coord vmw = 0, vmh = 0;
633
634         edje_object_size_min_calc
635            (elm_smart_scroller_edje_object_get(wd->scroller),
636                &vmw, &vmh);
637         if (wd->single_line)
638           {
639              evas_object_size_hint_min_set(data, vmw, minh + vmh);
640              evas_object_size_hint_max_set(data, -1, minh + vmh);
641           }
642         else
643           {
644              evas_object_size_hint_min_set(data, vmw, vmh);
645              evas_object_size_hint_max_set(data, -1, -1);
646           }
647      }
648    else
649      {
650         if (wd->single_line)
651           {
652              evas_object_size_hint_min_set(data, minw, minh);
653              evas_object_size_hint_max_set(data, -1, minh);
654           }
655         else
656           {
657              evas_object_size_hint_min_set(data, fw, minh);
658              evas_object_size_hint_max_set(data, -1, -1);
659           }
660      }
661
662    if (wd->deferred_cur)
663      {
664         Evas_Coord cx, cy, cw, ch;
665         edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
666                                                   &cx, &cy, &cw, &ch);
667         if (wd->cur_changed)
668           {
669              elm_widget_show_region_set(data, cx, cy, cw, ch, EINA_FALSE);
670              wd->cur_changed = EINA_FALSE;
671           }
672      }
673 }
674
675 static void
676 _sizing_eval(Evas_Object *obj)
677 {
678    Widget_Data *wd = elm_widget_data_get(obj);
679    Evas_Coord minw = -1, minh = -1;
680    Evas_Coord resw, resh;
681    if (!wd) return;
682
683    evas_object_geometry_get(obj, NULL, NULL, &resw, &resh);
684    if (wd->linewrap)
685      {
686         if ((resw == wd->lastw) && (!wd->changed)) return;
687         evas_event_freeze(evas_object_evas_get(obj));
688         wd->changed = EINA_FALSE;
689         wd->lastw = resw;
690         if (wd->scroll)
691           {
692              Evas_Coord vw = 0, vh = 0, vmw = 0, vmh = 0, w = -1, h = -1;
693
694              evas_object_resize(wd->scroller, resw, resh);
695              edje_object_size_min_calc
696                 (elm_smart_scroller_edje_object_get(wd->scroller),
697                  &vmw, &vmh);
698              elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
699              edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, vw, 0);
700              elm_coords_finger_size_adjust(1, &minw, 1, &minh);
701              /* This is a hack to workaround the way min size hints are treated.
702               * If the minimum width is smaller than the restricted width, it means
703               * the mininmum doesn't matter. */
704              if (minw <= vw)
705                {
706                   Evas_Coord ominw = -1;
707                   evas_object_size_hint_min_get(wd->ent, &ominw, NULL);
708                   minw = ominw;
709                }
710              wd->entmw = minw;
711              wd->entmh = minh;
712
713              if ((minw > 0) && (vw < minw)) vw = minw;
714              if (minh > vh) vh = minh;
715
716              if (wd->single_line) h = vmh + minh;
717              else h = vmh;
718              evas_object_resize(wd->ent, vw, vh);
719              evas_object_size_hint_min_set(obj, w, h);
720              if (wd->single_line)
721                evas_object_size_hint_max_set(obj, -1, h);
722              else
723                evas_object_size_hint_max_set(obj, -1, -1);
724           }
725         else
726           {
727              if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
728              wd->deferred_recalc_job = ecore_job_add(_elm_deferred_recalc_job, obj);
729           }
730         evas_event_thaw(evas_object_evas_get(obj));
731         evas_event_thaw_eval(evas_object_evas_get(obj));
732      }
733    else
734      {
735         if (!wd->changed) return;
736         evas_event_freeze(evas_object_evas_get(obj));
737         wd->changed = EINA_FALSE;
738         wd->lastw = resw;
739         if (wd->scroll)
740           {
741              Evas_Coord vw = 0, vh = 0, vmw = 0, vmh = 0, w = -1, h = -1;
742
743              edje_object_size_min_calc(wd->ent, &minw, &minh);
744              wd->entmw = minw;
745              wd->entmh = minh;
746              elm_coords_finger_size_adjust(1, &minw, 1, &minh);
747
748              elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
749
750              if (minw > vw) vw = minw;
751              if (minh > vh) vh = minh;
752
753              evas_object_resize(wd->ent, vw, vh);
754              edje_object_size_min_calc
755                 (elm_smart_scroller_edje_object_get(wd->scroller),
756                  &vmw, &vmh);
757              if (wd->single_line) h = vmh + minh;
758              else h = vmh;
759              evas_object_size_hint_min_set(obj, w, h);
760              if (wd->single_line)
761                evas_object_size_hint_max_set(obj, -1, h);
762              else
763                evas_object_size_hint_max_set(obj, -1, -1);
764           }
765         else
766           {
767              edje_object_size_min_calc(wd->ent, &minw, &minh);
768              wd->entmw = minw;
769              wd->entmh = minh;
770              elm_coords_finger_size_adjust(1, &minw, 1, &minh);
771              evas_object_size_hint_min_set(obj, minw, minh);
772              if (wd->single_line)
773                evas_object_size_hint_max_set(obj, -1, minh);
774              else
775                evas_object_size_hint_max_set(obj, -1, -1);
776           }
777         evas_event_thaw(evas_object_evas_get(obj));
778         evas_event_thaw_eval(evas_object_evas_get(obj));
779      }
780
781    _recalc_cursor_geometry(obj);
782 }
783
784 static void
785 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
786 {
787    Widget_Data *wd = elm_widget_data_get(obj);
788    Evas_Object *top = elm_widget_top_get(obj);
789    if (!wd) return;
790    if (!wd->editable) return;
791    if (elm_widget_focus_get(obj))
792      {
793         evas_object_focus_set(wd->ent, EINA_TRUE);
794         edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
795         if (top && wd->input_panel_enable)
796           elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
797         evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
798      }
799    else
800      {
801         edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
802         evas_object_focus_set(wd->ent, EINA_FALSE);
803         if (top && wd->input_panel_enable)
804           elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
805         evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
806      }
807 }
808
809 static void
810 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
811 {
812    Widget_Data *wd = elm_widget_data_get(obj);
813    Evas_Object *edje;
814    if ((!wd) || (!content)) return;
815
816    if (wd->scroll)
817       edje = elm_smart_scroller_edje_object_get(wd->scroller);
818    else
819       edje = wd->ent;
820
821    /* Delete the currently swallowed object */
822    Evas_Object *cswallow;
823
824    if (!part || !strcmp(part, "icon"))
825      {
826         cswallow = edje_object_part_swallow_get(edje, "elm.swallow.icon");
827         edje_object_signal_emit(edje, "elm,action,show,icon", "elm");
828      }
829    else if (!strcmp(part, "end"))
830      {
831         cswallow = edje_object_part_swallow_get(edje, "elm.swallow.end");
832         edje_object_signal_emit(edje, "elm,action,show,end", "elm");
833      }
834    else
835      cswallow = edje_object_part_swallow_get(edje, part);
836
837    if (cswallow) evas_object_del(cswallow);
838
839    evas_event_freeze(evas_object_evas_get(obj));
840    elm_widget_sub_object_add(obj, content);
841
842    if (!part || !strcmp(part, "icon"))
843      edje_object_part_swallow(edje, "elm.swallow.icon", content);
844    else if (!strcmp(part, "end"))
845      edje_object_part_swallow(edje, "elm.swallow.end", content);
846    else
847      edje_object_part_swallow(edje, part, content);
848
849    _sizing_eval(obj);
850    evas_event_thaw(evas_object_evas_get(obj));
851    evas_event_thaw_eval(evas_object_evas_get(obj));
852 }
853
854 static Evas_Object *
855 _content_unset_hook(Evas_Object *obj, const char *part)
856 {
857    Widget_Data *wd = elm_widget_data_get(obj);
858    Evas_Object *content, *edje;
859    if (!wd) return NULL;
860
861    if (wd->scroll)
862       edje = elm_smart_scroller_edje_object_get(wd->scroller);
863    else
864       edje = wd->ent;
865
866    if (!part || !strcmp(part, "icon"))
867      {
868         edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
869         content = edje_object_part_swallow_get(edje, "elm.swallow.icon");
870      }
871    else if (!strcmp(part, "end"))
872      {
873         edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
874         content = edje_object_part_swallow_get(edje, "elm.swallow.end");
875      }
876    else
877      content = edje_object_part_swallow_get(edje, part);
878
879    edje_object_part_swallow(edje, part, NULL);
880    if (!content) return NULL;
881    evas_event_freeze(evas_object_evas_get(obj));
882    elm_widget_sub_object_del(obj, content);
883    edje_object_part_unswallow(wd->ent, content);
884    _sizing_eval(obj);
885    evas_event_thaw(evas_object_evas_get(obj));
886    evas_event_thaw_eval(evas_object_evas_get(obj));
887
888    return content;
889 }
890
891 static Evas_Object *
892 _content_get_hook(const Evas_Object *obj, const char *part)
893 {
894    Widget_Data *wd = elm_widget_data_get(obj);
895    Evas_Object *content = NULL, *edje;
896    if (!wd) return NULL;
897
898    if (wd->scroll)
899       edje = elm_smart_scroller_edje_object_get(wd->scroller);
900    else
901       edje = wd->ent;
902
903    if (!edje) return NULL;
904
905    if (!part || !strcmp(part, "icon"))
906      content = edje_object_part_swallow_get(edje, "elm.swallow.icon");
907    else if (!strcmp(part, "end"))
908      content = edje_object_part_swallow_get(edje, "elm.swallow.end");
909    else
910      content = edje_object_part_swallow_get(edje, part);
911
912    return content;
913 }
914
915 static void
916 _translate_hook(Evas_Object *obj)
917 {
918    evas_object_smart_callback_call(obj, "language,changed", NULL);
919 }
920
921 static void
922 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
923 {
924    Widget_Data *wd = elm_widget_data_get(obj);
925    if (!wd) return;
926    edje_object_signal_emit(wd->ent, emission, source);
927    if (wd->scroller)
928      edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scroller),
929                              emission, source);
930 }
931
932 static void
933 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
934 {
935    Widget_Data *wd = elm_widget_data_get(obj);
936    if (!wd) return;
937    edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
938    if (wd->scroller)
939      edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scroller),
940                                      emission, source, func_cb, data);
941 }
942
943 static void
944 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
945 {
946    Widget_Data *wd = elm_widget_data_get(obj);
947    edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
948                                         data);
949    if (wd->scroller)
950      edje_object_signal_callback_del_full(elm_smart_scroller_edje_object_get(wd->scroller),
951                                           emission, source, func_cb, data);
952 }
953
954 static void
955 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
956 {
957    Widget_Data *wd = elm_widget_data_get(obj);
958    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
959 }
960
961 static void
962 _focus_region_hook(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
963 {
964    Widget_Data *wd = elm_widget_data_get(obj);
965    if (wd->scroll)
966      elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
967 }
968
969 static void
970 _show_region_hook(void *data, Evas_Object *obj)
971 {
972    Widget_Data *wd = elm_widget_data_get(data);
973    Evas_Coord x, y, w, h;
974    if (!wd) return;
975    elm_widget_show_region_get(obj, &x, &y, &w, &h);
976    if (wd->scroll)
977      elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
978 }
979
980 static void
981 _sub_del(void *data, Evas_Object *obj, void *event_info)
982 {
983    Widget_Data *wd = data;
984    Evas_Object *sub = event_info;
985    Evas_Object *edje;
986
987    if (wd->scroll)
988       edje = elm_smart_scroller_edje_object_get(wd->scroller);
989    else
990       edje = wd->ent;
991
992    if (sub == edje_object_part_swallow_get(edje, "elm.swallow.icon"))
993      {
994         edje_object_part_unswallow(edje, sub);
995         if (edje)
996           edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
997      }
998    else if (sub == edje_object_part_swallow_get(edje, "elm.swallow.end"))
999      {
1000         edje_object_part_unswallow(edje, sub);
1001         if (edje)
1002           edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
1003      }
1004    _sizing_eval(obj);
1005 }
1006
1007 static void
1008 _hoversel_position(Evas_Object *obj)
1009 {
1010    Widget_Data *wd = elm_widget_data_get(obj);
1011    Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
1012    if (!wd) return;
1013
1014    cx = cy = 0;
1015    cw = ch = 1;
1016    evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1017    if (wd->usedown)
1018      {
1019         cx = wd->downx - x;
1020         cy = wd->downy - y;
1021         cw = 1;
1022         ch = 1;
1023      }
1024    else
1025      edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1026                                                &cx, &cy, &cw, &ch);
1027    evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
1028    if (cw < mw)
1029      {
1030         cx += (cw - mw) / 2;
1031         cw = mw;
1032      }
1033    if (ch < mh)
1034      {
1035         cy += (ch - mh) / 2;
1036         ch = mh;
1037      }
1038    evas_object_move(wd->hoversel, x + cx, y + cy);
1039    evas_object_resize(wd->hoversel, cw, ch);
1040 }
1041
1042 static void
1043 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1044 {
1045    Widget_Data *wd = elm_widget_data_get(data);
1046
1047    if (wd->hoversel) _hoversel_position(data);
1048 }
1049
1050 static void
1051 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1052 {
1053    Widget_Data *wd = elm_widget_data_get(data);
1054    if (!wd) return;
1055
1056    if (wd->linewrap)
1057      {
1058         _sizing_eval(data);
1059      }
1060    else if (wd->scroll)
1061      {
1062         Evas_Coord vw = 0, vh = 0;
1063
1064         elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
1065         if (vw < wd->entmw) vw = wd->entmw;
1066         if (vh < wd->entmh) vh = wd->entmh;
1067         evas_object_resize(wd->ent, vw, vh);
1068      }
1069    if (wd->hoversel) _hoversel_position(data);
1070 }
1071
1072 static void
1073 _hover_del(void *data)
1074 {
1075    Widget_Data *wd = elm_widget_data_get(data);
1076    if (!wd) return;
1077
1078    if (wd->hoversel)
1079      {
1080         evas_object_del(wd->hoversel);
1081         wd->hoversel = NULL;
1082      }
1083    wd->hovdeljob = NULL;
1084 }
1085
1086 static void
1087 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1088 {
1089    Widget_Data *wd = elm_widget_data_get(data);
1090    if (!wd) return;
1091    wd->usedown = 0;
1092    if (wd->hoversel) evas_object_hide(wd->hoversel);
1093    if (wd->selmode)
1094      {
1095         if (!_elm_config->desktop_entry)
1096           {
1097              if (!wd->password)
1098                edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
1099           }
1100      }
1101    elm_widget_scroll_freeze_pop(data);
1102    if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
1103    wd->hovdeljob = ecore_job_add(_hover_del, data);
1104 }
1105
1106 static void
1107 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1108 {
1109    Widget_Data *wd = elm_widget_data_get(data);
1110    if (!wd) return;
1111    wd->selmode = EINA_TRUE;
1112    edje_object_part_text_select_none(wd->ent, "elm.text");
1113    if (!_elm_config->desktop_entry)
1114      {
1115         if (!wd->password)
1116           edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
1117      }
1118    edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
1119    if (!_elm_config->desktop_entry)
1120      elm_widget_scroll_hold_push(data);
1121 }
1122
1123 void
1124 _elm_entry_entry_paste(Evas_Object *obj, const char *entry)
1125 {
1126    Elm_Entry_Change_Info info;
1127    info.merge = EINA_FALSE;
1128    info.insert = EINA_TRUE;
1129    info.change.insert.pos = elm_entry_cursor_pos_get(obj);
1130    info.change.insert.content = eina_stringshare_add(entry);
1131      {
1132         char *tmp;
1133         tmp = evas_textblock_text_markup_to_utf8(elm_entry_textblock_get(obj),
1134               info.change.insert.content);
1135         info.change.insert.plain_length = eina_unicode_utf8_get_len(tmp);
1136         free(tmp);
1137      }
1138
1139    elm_entry_entry_insert(obj, entry);
1140    evas_object_smart_callback_call(obj, SIG_CHANGED_USER, &info);
1141
1142    eina_stringshare_del(info.change.insert.content);
1143 }
1144
1145 static void
1146 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1147 {
1148    Widget_Data *wd = elm_widget_data_get(data);
1149    if (!wd) return;
1150    evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1151    if (wd->sel_notify_handler)
1152      {
1153 #ifdef HAVE_ELEMENTARY_X
1154         Elm_Sel_Format formats;
1155         wd->selection_asked = EINA_TRUE;
1156         formats = ELM_SEL_FORMAT_MARKUP;
1157         if (!wd->textonly)
1158           formats |= ELM_SEL_FORMAT_IMAGE;
1159         elm_cnp_selection_get(ELM_SEL_TYPE_CLIPBOARD, formats, data, NULL, NULL);
1160 #endif
1161      }
1162 }
1163
1164 static void
1165 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
1166 {
1167    Widget_Data *wd = elm_widget_data_get(obj);
1168    const char *sel;
1169
1170    if (!wd) return;
1171    sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
1172    if ((!sel) || (!sel[0])) return; /* avoid deleting our own selection */
1173    elm_cnp_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel, strlen(sel));
1174    if (seltype == ELM_SEL_TYPE_CLIPBOARD)
1175      eina_stringshare_replace(&wd->cut_sel, sel);
1176 }
1177
1178 static void
1179 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1180 {
1181    Widget_Data *wd = elm_widget_data_get(data);
1182
1183    /* Store it */
1184    wd->selmode = EINA_FALSE;
1185    if (!_elm_config->desktop_entry)
1186      edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1187    edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1188    if (!_elm_config->desktop_entry)
1189      elm_widget_scroll_hold_pop(data);
1190    _store_selection(ELM_SEL_TYPE_CLIPBOARD, data);
1191    edje_object_part_text_insert(wd->ent, "elm.text", "");
1192    edje_object_part_text_select_none(wd->ent, "elm.text");
1193    _sizing_eval(data);
1194 }
1195
1196 static void
1197 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1198 {
1199    Widget_Data *wd = elm_widget_data_get(data);
1200    if (!wd) return;
1201    wd->selmode = EINA_FALSE;
1202    if (!_elm_config->desktop_entry)
1203      {
1204         edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1205         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1206         elm_widget_scroll_hold_pop(data);
1207      }
1208    _store_selection(ELM_SEL_TYPE_CLIPBOARD, data);
1209    //   edje_object_part_text_select_none(wd->ent, "elm.text");
1210 }
1211
1212 static void
1213 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1214 {
1215    Widget_Data *wd = elm_widget_data_get(data);
1216    if (!wd) return;
1217    wd->selmode = EINA_FALSE;
1218    if (!_elm_config->desktop_entry)
1219      edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1220    edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1221    if (!_elm_config->desktop_entry)
1222      elm_widget_scroll_hold_pop(data);
1223    edje_object_part_text_select_none(wd->ent, "elm.text");
1224 }
1225
1226 static void
1227 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1228 {
1229    Elm_Entry_Context_Menu_Item *it = data;
1230    Evas_Object *obj2 = it->obj;
1231    if (it->func) it->func(it->data, obj2, NULL);
1232 }
1233
1234 static void
1235 _menu_press(Evas_Object *obj)
1236 {
1237    Widget_Data *wd = elm_widget_data_get(obj);
1238    Evas_Object *top;
1239    const Eina_List *l;
1240    const Elm_Entry_Context_Menu_Item *it;
1241    if (!wd) return;
1242    if ((wd->api) && (wd->api->obj_longpress))
1243      {
1244         wd->api->obj_longpress(obj);
1245      }
1246    else if (wd->context_menu)
1247      {
1248         const char *context_menu_orientation;
1249
1250         if (wd->hoversel) evas_object_del(wd->hoversel);
1251         else elm_widget_scroll_freeze_push(obj);
1252         wd->hoversel = elm_hoversel_add(obj);
1253         context_menu_orientation = edje_object_data_get
1254            (wd->ent, "context_menu_orientation");
1255         if ((context_menu_orientation) &&
1256             (!strcmp(context_menu_orientation, "horizontal")))
1257           elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
1258         elm_object_style_set(wd->hoversel, "entry");
1259         elm_widget_sub_object_add(obj, wd->hoversel);
1260         elm_object_text_set(wd->hoversel, "Text");
1261         top = elm_widget_top_get(obj);
1262         if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
1263         evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, obj);
1264         if (wd->have_selection)
1265           {
1266              if (!wd->password)
1267                {
1268                   if (wd->have_selection)
1269                     {
1270                        elm_hoversel_item_add(wd->hoversel, E_("Copy"), NULL, ELM_ICON_NONE,
1271                                              _copy, obj);
1272                        if (wd->editable)
1273                          elm_hoversel_item_add(wd->hoversel, E_("Cut"), NULL, ELM_ICON_NONE,
1274                                                _cut, obj);
1275                     }
1276                   elm_hoversel_item_add(wd->hoversel, E_("Cancel"), NULL, ELM_ICON_NONE,
1277                                         _cancel, obj);
1278                }
1279           }
1280         else
1281           {
1282              if (!wd->selmode)
1283                {
1284                   if (!_elm_config->desktop_entry)
1285                     {
1286                        if (!wd->password)
1287                          elm_hoversel_item_add(wd->hoversel, E_("Select"), NULL, ELM_ICON_NONE,
1288                                                _select, obj);
1289                     }
1290                   if (elm_selection_selection_has_owner())
1291                     {
1292                        if (wd->editable)
1293                          elm_hoversel_item_add(wd->hoversel, E_("Paste"), NULL, ELM_ICON_NONE,
1294                                                _paste, obj);
1295                     }
1296                }
1297           }
1298         EINA_LIST_FOREACH(wd->items, l, it)
1299           {
1300              elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
1301                                    it->icon_type, _item_clicked, it);
1302           }
1303         if (wd->hoversel)
1304           {
1305              _hoversel_position(obj);
1306              evas_object_show(wd->hoversel);
1307              elm_hoversel_hover_begin(wd->hoversel);
1308           }
1309         if (!_elm_config->desktop_entry)
1310           {
1311              edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1312              edje_object_part_text_select_abort(wd->ent, "elm.text");
1313           }
1314      }
1315 }
1316
1317 static Eina_Bool
1318 _long_press(void *data)
1319 {
1320    Widget_Data *wd = elm_widget_data_get(data);
1321    if (!wd) return ECORE_CALLBACK_CANCEL;
1322    _menu_press(data);
1323    wd->longpress_timer = NULL;
1324    evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
1325    return ECORE_CALLBACK_CANCEL;
1326 }
1327
1328 static void
1329 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1330 {
1331    Widget_Data *wd = elm_widget_data_get(data);
1332    Evas_Event_Mouse_Down *ev = event_info;
1333    if (!wd) return;
1334    if (wd->disabled) return;
1335    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1336    wd->downx = ev->canvas.x;
1337    wd->downy = ev->canvas.y;
1338    if (ev->button == 1)
1339      {
1340         if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
1341         wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1342      }
1343 }
1344
1345 static void
1346 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1347 {
1348    Widget_Data *wd = elm_widget_data_get(data);
1349    Evas_Event_Mouse_Up *ev = event_info;
1350    if (!wd) return;
1351    if (wd->disabled) return;
1352    if (ev->button == 1)
1353      {
1354         if (wd->longpress_timer)
1355           {
1356              ecore_timer_del(wd->longpress_timer);
1357              wd->longpress_timer = NULL;
1358           }
1359      }
1360    else if (ev->button == 3)
1361      {
1362         wd->usedown = 1;
1363         _menu_press(data);
1364      }
1365 }
1366
1367 static void
1368 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1369 {
1370    Widget_Data *wd = elm_widget_data_get(data);
1371    Evas_Event_Mouse_Move *ev = event_info;
1372    if (!wd) return;
1373    if (wd->disabled) return;
1374    if (!wd->selmode)
1375      {
1376         if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1377           {
1378              if (wd->longpress_timer)
1379                {
1380                   ecore_timer_del(wd->longpress_timer);
1381                   wd->longpress_timer = NULL;
1382                }
1383           }
1384         else if (wd->longpress_timer)
1385           {
1386              Evas_Coord dx, dy;
1387
1388              dx = wd->downx - ev->cur.canvas.x;
1389              dx *= dx;
1390              dy = wd->downy - ev->cur.canvas.y;
1391              dy *= dy;
1392              if ((dx + dy) >
1393                  ((_elm_config->finger_size / 2) *
1394                   (_elm_config->finger_size / 2)))
1395                {
1396                   ecore_timer_del(wd->longpress_timer);
1397                   wd->longpress_timer = NULL;
1398                }
1399           }
1400      }
1401    else if (wd->longpress_timer)
1402      {
1403         Evas_Coord dx, dy;
1404
1405         dx = wd->downx - ev->cur.canvas.x;
1406         dx *= dx;
1407         dy = wd->downy - ev->cur.canvas.y;
1408         dy *= dy;
1409         if ((dx + dy) >
1410             ((_elm_config->finger_size / 2) *
1411              (_elm_config->finger_size / 2)))
1412           {
1413              ecore_timer_del(wd->longpress_timer);
1414              wd->longpress_timer = NULL;
1415           }
1416      }
1417 }
1418
1419 static const char *
1420 _getbase(Evas_Object *obj)
1421 {
1422    Widget_Data *wd = elm_widget_data_get(obj);
1423    if (!wd) return "base";
1424    if (wd->editable)
1425      {
1426         if (wd->password) return "base-password";
1427         else
1428           {
1429              if (wd->single_line) return "base-single";
1430              else
1431                {
1432                   switch (wd->linewrap)
1433                     {
1434                      case ELM_WRAP_CHAR:
1435                         return "base-charwrap";
1436                      case ELM_WRAP_WORD:
1437                         return "base";
1438                      case ELM_WRAP_MIXED:
1439                         return "base-mixedwrap";
1440                      case ELM_WRAP_NONE:
1441                      default:
1442                         return "base-nowrap";
1443                     }
1444                }
1445           }
1446      }
1447    else
1448      {
1449         if (wd->password) return "base-password";
1450         else
1451           {
1452              if (wd->single_line) return "base-single-noedit";
1453              else
1454                {
1455                   switch (wd->linewrap)
1456                     {
1457                      case ELM_WRAP_CHAR:
1458                         return "base-noedit-charwrap";
1459                      case ELM_WRAP_WORD:
1460                         return "base-noedit";
1461                      case ELM_WRAP_MIXED:
1462                         return "base-noedit-mixedwrap";
1463                      case ELM_WRAP_NONE:
1464                      default:
1465                         return "base-nowrap-noedit";
1466                     }
1467                }
1468           }
1469      }
1470 }
1471
1472 static void
1473 _entry_changed_common_handling(void *data, const char *event)
1474 {
1475    Widget_Data *wd = elm_widget_data_get(data);
1476    Evas_Coord minh;
1477    if (!wd) return;
1478    evas_event_freeze(evas_object_evas_get(data));
1479    wd->changed = EINA_TRUE;
1480    /* Reset the size hints which are no more relevant.
1481     * Keep the height, this is a hack, but doesn't really matter
1482     * cause we'll re-eval in a moment. */
1483    evas_object_size_hint_min_get(data, NULL, &minh);
1484    evas_object_size_hint_min_set(data, -1, minh);
1485    _sizing_eval(data);
1486    if (wd->text) eina_stringshare_del(wd->text);
1487    wd->text = NULL;
1488    if (wd->delay_write)
1489      {
1490         ecore_timer_del(wd->delay_write);
1491         wd->delay_write = NULL;
1492      }
1493    evas_event_thaw(evas_object_evas_get(data));
1494    evas_event_thaw_eval(evas_object_evas_get(data));
1495    if ((wd->autosave) && (wd->file))
1496      wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1497    /* callback - this could call callbacks that delete the entry... thus...
1498     * any access to wd after this could be invalid */
1499    evas_object_smart_callback_call(data, event, NULL);
1500 }
1501
1502 static void
1503 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1504 {
1505    _entry_changed_common_handling(data, SIG_CHANGED);
1506 }
1507
1508 static void
1509 _signal_entry_changed_user(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1510 {
1511    Elm_Entry_Change_Info info;
1512    Edje_Entry_Change_Info *edje_info = (Edje_Entry_Change_Info *)
1513       edje_object_signal_callback_extra_data_get();
1514    if (edje_info)
1515      {
1516         memcpy(&info, edje_info, sizeof(info));
1517         evas_object_smart_callback_call(data, SIG_CHANGED_USER, &info);
1518      }
1519    else
1520      {
1521         evas_object_smart_callback_call(data, SIG_CHANGED_USER, NULL);
1522      }
1523 }
1524
1525 static void
1526 _signal_preedit_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1527 {
1528    _entry_changed_common_handling(data, SIG_PREEDIT_CHANGED);
1529 }
1530
1531 static void
1532 _signal_undo_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1533 {
1534    evas_object_smart_callback_call(data, SIG_UNDO_REQUEST, NULL);
1535 }
1536
1537 static void
1538 _signal_redo_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1539 {
1540    evas_object_smart_callback_call(data, SIG_REDO_REQUEST, NULL);
1541 }
1542
1543 static void
1544 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1545 {
1546    Widget_Data *wd = elm_widget_data_get(data);
1547    const Eina_List *l;
1548    Evas_Object *entry;
1549    if (!wd) return;
1550    EINA_LIST_FOREACH(entries, l, entry)
1551      {
1552         if (entry != data) elm_entry_select_none(entry);
1553      }
1554    wd->have_selection = EINA_TRUE;
1555    evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1556 #ifdef HAVE_ELEMENTARY_X
1557    if (wd->sel_notify_handler)
1558      {
1559         const char *txt = elm_entry_selection_get(data);
1560         Evas_Object *top;
1561
1562         top = elm_widget_top_get(data);
1563         if (txt && top && (elm_win_xwindow_get(top)))
1564           elm_cnp_selection_set(ELM_SEL_TYPE_PRIMARY, data,
1565                                 ELM_SEL_FORMAT_MARKUP, txt, strlen(txt));
1566      }
1567 #endif
1568 }
1569
1570 static void
1571 _signal_selection_all(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1572 {
1573    Widget_Data *wd = elm_widget_data_get(data);
1574    if (!wd) return;
1575    elm_entry_select_all(data);
1576 }
1577
1578 static void
1579 _signal_selection_none(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1580 {
1581    Widget_Data *wd = elm_widget_data_get(data);
1582    if (!wd) return;
1583    elm_entry_select_none(data);
1584 }
1585
1586 static void
1587 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1588 {
1589    Widget_Data *wd = elm_widget_data_get(data);
1590    if (!wd) return;
1591    wd->have_selection = EINA_TRUE;
1592    evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1593    _store_selection(ELM_SEL_TYPE_PRIMARY, data);
1594 }
1595
1596 static void
1597 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1598 {
1599    Widget_Data *wd = elm_widget_data_get(data);
1600    if (!wd) return;
1601    if (!wd->have_selection) return;
1602    wd->have_selection = EINA_FALSE;
1603    evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1604    if (wd->sel_notify_handler)
1605      {
1606         if (wd->cut_sel)
1607           {
1608 #ifdef HAVE_ELEMENTARY_X
1609              Evas_Object *top;
1610
1611              top = elm_widget_top_get(data);
1612              if ((top) && (elm_win_xwindow_get(top)))
1613                elm_cnp_selection_set(ELM_SEL_TYPE_PRIMARY, data,
1614                                      ELM_SEL_FORMAT_MARKUP, wd->cut_sel,
1615                                      strlen(wd->cut_sel));
1616 #endif
1617              eina_stringshare_del(wd->cut_sel);
1618              wd->cut_sel = NULL;
1619           }
1620         else
1621           {
1622 #ifdef HAVE_ELEMENTARY_X
1623              Evas_Object *top;
1624
1625              top = elm_widget_top_get(data);
1626              if ((top) && (elm_win_xwindow_get(top)))
1627                elm_cnp_selection_clear(ELM_SEL_TYPE_PRIMARY, data);
1628 #endif
1629           }
1630      }
1631 }
1632
1633 static void
1634 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1635 {
1636    Widget_Data *wd = elm_widget_data_get(data);
1637    Elm_Sel_Type type = (emission[sizeof("ntry,paste,request,")] == '1') ?
1638      ELM_SEL_TYPE_PRIMARY : ELM_SEL_TYPE_CLIPBOARD;
1639    if (!wd) return;
1640    evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1641    if (wd->sel_notify_handler)
1642      {
1643 #ifdef HAVE_ELEMENTARY_X
1644         Evas_Object *top;
1645
1646         top = elm_widget_top_get(data);
1647         if ((top) && (elm_win_xwindow_get(top)))
1648           {
1649              wd->selection_asked = EINA_TRUE;
1650              elm_cnp_selection_get(type, ELM_SEL_FORMAT_MARKUP, data,
1651                                NULL, NULL);
1652           }
1653 #endif
1654      }
1655 }
1656
1657 static void
1658 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1659 {
1660    evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1661    _copy(data, NULL, NULL);
1662 }
1663
1664 static void
1665 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1666 {
1667    evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1668    _cut(data, NULL, NULL);
1669 }
1670
1671 static void
1672 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1673 {
1674    Widget_Data *wd = elm_widget_data_get(data);
1675    if (!wd) return;
1676    wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1677    wd->cur_changed = EINA_TRUE;
1678    _recalc_cursor_geometry(data);
1679 }
1680
1681 static void
1682 _signal_cursor_changed_manual(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1683 {
1684    evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED_MANUAL, NULL);
1685 }
1686
1687
1688 static void
1689 _signal_anchor_geoms_do_things_with(Widget_Data *wd, Elm_Entry_Anchor_Info *ei)
1690 {
1691    const Eina_List *geoms, *l;
1692    Evas_Textblock_Rectangle *r;
1693    Evas_Coord px, py, x, y;
1694
1695    geoms = edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei->name);
1696    if (!geoms) return;
1697
1698
1699    evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1700    evas_pointer_canvas_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1701    EINA_LIST_FOREACH(geoms, l, r)
1702      {
1703         if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1704             ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1705           {
1706              ei->x = r->x + x;
1707              ei->y = r->y + y;
1708              ei->w = r->w;
1709              ei->h = r->h;
1710              break;
1711           }
1712      }
1713 }
1714
1715 static void
1716 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1717 {
1718    Widget_Data *wd = elm_widget_data_get(data);
1719    Elm_Entry_Anchor_Info ei;
1720    const char *p;
1721    char *p2;
1722    if (!wd) return;
1723    p = emission + sizeof("nchor,mouse,down,");
1724    ei.button = strtol(p, &p2, 10);
1725    ei.name = p2 + 1;
1726    ei.x = ei.y = ei.w = ei.h = 0;
1727
1728    _signal_anchor_geoms_do_things_with(wd, &ei);
1729
1730    if (!wd->disabled)
1731      evas_object_smart_callback_call(data, SIG_ANCHOR_DOWN, &ei);
1732 }
1733
1734 static void
1735 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1736 {
1737    Widget_Data *wd = elm_widget_data_get(data);
1738    Elm_Entry_Anchor_Info ei;
1739    const char *p;
1740    char *p2;
1741    if (!wd) return;
1742    p = emission + sizeof("nchor,mouse,up,");
1743    ei.button = strtol(p, &p2, 10);
1744    ei.name = p2 + 1;
1745    ei.x = ei.y = ei.w = ei.h = 0;
1746
1747    _signal_anchor_geoms_do_things_with(wd, &ei);
1748
1749    if (!wd->disabled)
1750      evas_object_smart_callback_call(data, SIG_ANCHOR_UP, &ei);
1751 }
1752
1753 static void
1754 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1755 {
1756    Widget_Data *wd = elm_widget_data_get(data);
1757    Elm_Entry_Anchor_Info ei;
1758    const char *p;
1759    char *p2;
1760    if (!wd) return;
1761    p = emission + sizeof("nchor,mouse,clicked,");
1762    ei.button = strtol(p, &p2, 10);
1763    ei.name = p2 + 1;
1764    ei.x = ei.y = ei.w = ei.h = 0;
1765
1766    _signal_anchor_geoms_do_things_with(wd, &ei);
1767
1768    if (!wd->disabled)
1769      evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1770 }
1771
1772 static void
1773 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1774 {
1775    Widget_Data *wd = elm_widget_data_get(data);
1776    if (!wd) return;
1777 }
1778
1779 static void
1780 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1781 {
1782    Widget_Data *wd = elm_widget_data_get(data);
1783    Elm_Entry_Anchor_Info ei;
1784    if (!wd) return;
1785    ei.name = emission + sizeof("nchor,mouse,in,");
1786    ei.button = 0;
1787    ei.x = ei.y = ei.w = ei.h = 0;
1788
1789    _signal_anchor_geoms_do_things_with(wd, &ei);
1790
1791    if (!wd->disabled)
1792      evas_object_smart_callback_call(data, SIG_ANCHOR_IN, &ei);
1793 }
1794
1795 static void
1796 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1797 {
1798    Widget_Data *wd = elm_widget_data_get(data);
1799    Elm_Entry_Anchor_Info ei;
1800    if (!wd) return;
1801    ei.name = emission + sizeof("nchor,mouse,out,");
1802    ei.button = 0;
1803    ei.x = ei.y = ei.w = ei.h = 0;
1804
1805    _signal_anchor_geoms_do_things_with(wd, &ei);
1806
1807    if (!wd->disabled)
1808      evas_object_smart_callback_call(data, SIG_ANCHOR_OUT, &ei);
1809 }
1810
1811 static void
1812 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1813 {
1814    Widget_Data *wd = elm_widget_data_get(data);
1815    if (!wd) return;
1816    evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1817 }
1818
1819 static void
1820 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1821 {
1822    Widget_Data *wd = elm_widget_data_get(data);
1823    if (!wd) return;
1824    evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1825 }
1826
1827 static void
1828 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1829 {
1830    Widget_Data *wd = elm_widget_data_get(data);
1831    if (!wd) return;
1832    evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1833 }
1834
1835 static void
1836 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1837 {
1838    Widget_Data *wd = elm_widget_data_get(data);
1839    if (!wd) return;
1840    evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1841 }
1842
1843 static void
1844 _signal_mouse_triple(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1845 {
1846    Widget_Data *wd = elm_widget_data_get(data);
1847    if (!wd) return;
1848    evas_object_smart_callback_call(data, SIG_CLICKED_TRIPLE, NULL);
1849 }
1850
1851 #ifdef HAVE_ELEMENTARY_X
1852 static Eina_Bool
1853 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1854 {
1855    Widget_Data *wd = elm_widget_data_get(data);
1856    Ecore_X_Event_Selection_Notify *ev = event;
1857    if (!wd) return ECORE_CALLBACK_PASS_ON;
1858    if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1859      return ECORE_CALLBACK_PASS_ON;
1860
1861    if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1862        (ev->selection == ECORE_X_SELECTION_PRIMARY))
1863      {
1864         Ecore_X_Selection_Data_Text *text_data;
1865
1866         text_data = ev->data;
1867         if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1868           {
1869              if (text_data->text)
1870                {
1871                   char *txt = _elm_util_text_to_mkup(text_data->text);
1872
1873                   if (txt)
1874                     {
1875                        elm_entry_entry_insert(data, txt);
1876                        free(txt);
1877                     }
1878                }
1879           }
1880         wd->selection_asked = EINA_FALSE;
1881      }
1882    else if (ev->selection == ECORE_X_SELECTION_XDND)
1883      {
1884         Ecore_X_Selection_Data_Text *text_data;
1885
1886         text_data = ev->data;
1887         if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1888           {
1889              if (text_data->text)
1890                {
1891                   char *txt = _elm_util_text_to_mkup(text_data->text);
1892
1893                   if (txt)
1894                     {
1895                        /* Massive FIXME: this should be at the drag point */
1896                        elm_entry_entry_insert(data, txt);
1897                        free(txt);
1898                     }
1899                }
1900           }
1901         wd->drag_selection_asked = EINA_FALSE;
1902
1903         ecore_x_dnd_send_finished();
1904
1905      }
1906    return ECORE_CALLBACK_PASS_ON;
1907 }
1908
1909 static Eina_Bool
1910 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1911 {
1912    Widget_Data *wd = elm_widget_data_get(data);
1913    Ecore_X_Event_Selection_Clear *ev = event;
1914    if (!wd) return ECORE_CALLBACK_PASS_ON;
1915    if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1916    if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1917        (ev->selection == ECORE_X_SELECTION_PRIMARY))
1918      {
1919         elm_entry_select_none(data);
1920      }
1921    return ECORE_CALLBACK_PASS_ON;
1922 }
1923
1924 static Eina_Bool
1925 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1926 {
1927    Widget_Data *wd;
1928    Eina_Bool rv;
1929
1930    wd = elm_widget_data_get(obj);
1931    if (!wd) return EINA_FALSE;
1932    printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1933
1934    edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1935                                      EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1936    rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1937                                                EDJE_CURSOR_MAIN,drop->x,drop->y);
1938    if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1939    elm_entry_entry_insert(obj, drop->data);
1940    edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1941                                      EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1942
1943    return EINA_TRUE;
1944 }
1945 #endif
1946
1947 static Evas_Object *
1948 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1949 {
1950    Widget_Data *wd = elm_widget_data_get(data);
1951    Evas_Object *o;
1952    Eina_List *l;
1953    Elm_Entry_Item_Provider *ip;
1954
1955    EINA_LIST_FOREACH(wd->item_providers, l, ip)
1956      {
1957         o = ip->func(ip->data, data, item);
1958         if (o) return o;
1959      }
1960    if (!strncmp(item, "file://", 7))
1961      {
1962         const char *fname = item + 7;
1963
1964         o = evas_object_image_filled_add(evas_object_evas_get(data));
1965         evas_object_image_file_set(o, fname, NULL);
1966         if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1967           {
1968              evas_object_show(o);
1969           }
1970         else
1971           {
1972              evas_object_del(o);
1973              o = edje_object_add(evas_object_evas_get(data));
1974              _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1975           }
1976         return o;
1977      }
1978    o = edje_object_add(evas_object_evas_get(data));
1979    if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1980      _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1981    return o;
1982 }
1983
1984 static void
1985 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
1986 {
1987    Widget_Data *wd = elm_widget_data_get(data);
1988    Eina_List *l;
1989    Elm_Entry_Markup_Filter *tf;
1990
1991    if (type == EDJE_TEXT_FILTER_FORMAT)
1992      return;
1993
1994    EINA_LIST_FOREACH(wd->text_filters, l, tf)
1995      {
1996         tf->func(tf->data, data, text);
1997         if (!*text)
1998           break;
1999      }
2000 }
2001
2002 static void
2003 _markup_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, char **text)
2004 {
2005    Widget_Data *wd = elm_widget_data_get(data);
2006    Eina_List *l;
2007    Elm_Entry_Markup_Filter *tf;
2008
2009    EINA_LIST_FOREACH(wd->markup_filters, l, tf)
2010      {
2011         tf->func(tf->data, data, text);
2012         if (!*text)
2013           break;
2014      }
2015 }
2016
2017 /* This function is used to insert text by chunks in jobs */
2018 static Eina_Bool
2019 _text_append_idler(void *data)
2020 {
2021    int start;
2022    char backup;
2023    Evas_Object *obj = (Evas_Object *) data;
2024    Widget_Data *wd = elm_widget_data_get(obj);
2025    evas_event_freeze(evas_object_evas_get(obj));
2026    if (wd->text) eina_stringshare_del(wd->text);
2027    wd->text = NULL;
2028    wd->changed = EINA_TRUE;
2029
2030    start = wd->append_text_position;
2031    if (start + _CHUNK_SIZE < wd->append_text_len)
2032      {
2033         int pos = start;
2034         int tag_start, esc_start;
2035
2036         tag_start = esc_start = -1;
2037         /* Find proper markup cut place */
2038         while (pos - start < _CHUNK_SIZE)
2039           {
2040              int prev_pos = pos;
2041              Eina_Unicode tmp =
2042                 eina_unicode_utf8_get_next(wd->append_text_left, &pos);
2043              if (esc_start == -1)
2044                {
2045                   if (tmp == '<')
2046                      tag_start = prev_pos;
2047                   else if (tmp == '>')
2048                      tag_start = -1;
2049                }
2050              if (tag_start == -1)
2051                {
2052                   if (tmp == '&')
2053                      esc_start = prev_pos;
2054                   else if (tmp == ';')
2055                      esc_start = -1;
2056                }
2057           }
2058
2059         if (tag_start >= 0)
2060           {
2061              wd->append_text_position = tag_start;
2062           }
2063         else if (esc_start >= 0)
2064           {
2065              wd->append_text_position = esc_start;
2066           }
2067         else
2068           {
2069              wd->append_text_position = pos;
2070           }
2071      }
2072    else
2073      {
2074         wd->append_text_position = wd->append_text_len;
2075      }
2076
2077    backup = wd->append_text_left[wd->append_text_position];
2078    wd->append_text_left[wd->append_text_position] = '\0';
2079
2080    edje_object_part_text_append(wd->ent, "elm.text",
2081                                 wd->append_text_left + start);
2082
2083    wd->append_text_left[wd->append_text_position] = backup;
2084
2085    evas_event_thaw(evas_object_evas_get(obj));
2086    evas_event_thaw_eval(evas_object_evas_get(obj));
2087
2088    /* If there's still more to go, renew the idler, else, cleanup */
2089    if (wd->append_text_position < wd->append_text_len)
2090      {
2091         return ECORE_CALLBACK_RENEW;
2092      }
2093    else
2094      {
2095         free(wd->append_text_left);
2096         wd->append_text_left = NULL;
2097         wd->append_text_idler = NULL;
2098         return ECORE_CALLBACK_CANCEL;
2099      }
2100 }
2101
2102 static void
2103 _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit)
2104 {
2105    int i = 0, current_len = 0;
2106    char *new_text;
2107
2108    if (!*text) return;
2109    if (unit >= LENGTH_UNIT_LAST) return;
2110    new_text = *text;
2111    current_len = strlen(*text);
2112    while (*new_text)
2113      {
2114         int idx = 0, unit_size = 0;
2115         char *markup, *utfstr;
2116         if (*new_text == '<')
2117           {
2118              while (*(new_text + idx) != '>')
2119                {
2120                   idx++;
2121                   if (!*(new_text + idx)) break;
2122                }
2123           }
2124         else if (*new_text == '&')
2125           {
2126              while (*(new_text + idx) != ';')
2127                {
2128                   idx++;
2129                   if (!*(new_text + idx)) break;
2130                }
2131           }
2132         idx = evas_string_char_next_get(new_text, idx, NULL);
2133         markup = malloc(idx + 1);
2134         if (markup)
2135           {
2136              strncpy(markup, new_text, idx);
2137              markup[idx] = 0;
2138              utfstr = elm_entry_markup_to_utf8(markup);
2139              if (utfstr)
2140                {
2141                   if (unit == LENGTH_UNIT_BYTE)
2142                     unit_size = strlen(utfstr);
2143                   else if (unit == LENGTH_UNIT_CHAR)
2144                     unit_size = evas_string_char_len_get(utfstr);
2145                   free(utfstr);
2146                   utfstr = NULL;
2147                }
2148              free(markup);
2149              markup = NULL;
2150           }
2151         if (can_add < unit_size)
2152           {
2153              if (!i)
2154                {
2155                   evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
2156                   free(*text);
2157                   *text = NULL;
2158                   return;
2159                }
2160              can_add = 0;
2161              strncpy(new_text, new_text + idx, current_len - ((new_text + idx) - *text));
2162              current_len -= idx;
2163              (*text)[current_len] = 0;
2164           }
2165         else
2166           {
2167              new_text += idx;
2168              can_add -= unit_size;
2169           }
2170         i++;
2171      }
2172    evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
2173 }
2174
2175 static void
2176 _elm_entry_text_set(Evas_Object *obj, const char *item, const char *entry)
2177 {
2178    int len = 0;
2179    ELM_CHECK_WIDTYPE(obj, widtype);
2180    Widget_Data *wd = elm_widget_data_get(obj);
2181    if (!wd) return;
2182    evas_event_freeze(evas_object_evas_get(obj));
2183    if (!entry) entry = "";
2184    if (item && strcmp(item, "default"))
2185      {
2186         edje_object_part_text_set(wd->ent, item, entry);
2187         return;
2188      }
2189
2190    if (wd->text) eina_stringshare_del(wd->text);
2191    wd->text = NULL;
2192    wd->changed = EINA_TRUE;
2193
2194    /* Clear currently pending job if there is one */
2195    if (wd->append_text_idler)
2196      {
2197         ecore_idler_del(wd->append_text_idler);
2198         free(wd->append_text_left);
2199         wd->append_text_left = NULL;
2200         wd->append_text_idler = NULL;
2201      }
2202
2203    len = strlen(entry);
2204    /* Split to ~_CHUNK_SIZE chunks */
2205    if (len > _CHUNK_SIZE)
2206      {
2207         wd->append_text_left = (char *) malloc(len + 1);
2208      }
2209
2210    /* If we decided to use the idler */
2211    if (wd->append_text_left)
2212      {
2213         /* Need to clear the entry first */
2214         edje_object_part_text_set(wd->ent, "elm.text", "");
2215         memcpy(wd->append_text_left, entry, len + 1);
2216         wd->append_text_position = 0;
2217         wd->append_text_len = len;
2218         wd->append_text_idler = ecore_idler_add(_text_append_idler, obj);
2219      }
2220    else
2221      {
2222         edje_object_part_text_set(wd->ent, "elm.text", entry);
2223      }
2224    evas_event_thaw(evas_object_evas_get(obj));
2225    evas_event_thaw_eval(evas_object_evas_get(obj));
2226 }
2227
2228 static const char *
2229 _elm_entry_text_get(const Evas_Object *obj, const char *item)
2230 {
2231    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2232    Widget_Data *wd = elm_widget_data_get(obj);
2233    if (item && strcmp(item, "default")) return NULL;
2234    const char *text;
2235    if (!wd) return NULL;
2236    if (wd->text) return wd->text;
2237    text = edje_object_part_text_get(wd->ent, "elm.text");
2238    if (!text)
2239      {
2240         ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2241         return NULL;
2242      }
2243
2244    if (wd->append_text_len > 0)
2245      {
2246         char *tmpbuf;
2247         size_t tlen;
2248         tlen = strlen(text);
2249         tmpbuf = malloc(tlen + wd->append_text_len + 1);
2250         if (!tmpbuf)
2251           {
2252              ERR("Failed to allocate memory for entry's text %p", obj);
2253              return NULL;
2254           }
2255         memcpy(tmpbuf, text, tlen);
2256         memcpy(tmpbuf + tlen, wd->append_text_left, wd->append_text_len);
2257         tmpbuf[tlen + wd->append_text_len] = '\0';
2258         eina_stringshare_replace(&wd->text, tmpbuf);
2259         free(tmpbuf);
2260      }
2261    else
2262      {
2263         eina_stringshare_replace(&wd->text, text);
2264      }
2265    return wd->text;
2266 }
2267
2268 EAPI Evas_Object *
2269 elm_entry_add(Evas_Object *parent)
2270 {
2271    Evas_Object *obj, *top;
2272    Evas *e;
2273    Widget_Data *wd;
2274
2275    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
2276
2277    ELM_SET_WIDTYPE(widtype, "entry");
2278    elm_widget_type_set(obj, "entry");
2279    elm_widget_sub_object_add(parent, obj);
2280    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2281    elm_widget_data_set(obj, wd);
2282    elm_widget_del_hook_set(obj, _del_hook);
2283    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2284    elm_widget_theme_hook_set(obj, _theme_hook);
2285    elm_widget_disable_hook_set(obj, _disable_hook);
2286    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2287    elm_widget_focus_region_hook_set(obj, _focus_region_hook);
2288    elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
2289    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
2290    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
2291    elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
2292    elm_widget_can_focus_set(obj, EINA_TRUE);
2293    elm_widget_highlight_ignore_set(obj, EINA_TRUE);
2294    elm_widget_text_set_hook_set(obj, _elm_entry_text_set);
2295    elm_widget_text_get_hook_set(obj, _elm_entry_text_get);
2296    elm_widget_content_set_hook_set(obj, _content_set_hook);
2297    elm_widget_content_unset_hook_set(obj, _content_unset_hook);
2298    elm_widget_content_get_hook_set(obj, _content_get_hook);
2299    elm_widget_translate_hook_set(obj, _translate_hook);
2300
2301    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, wd);
2302
2303    wd->linewrap     = ELM_WRAP_WORD;
2304    wd->editable     = EINA_TRUE;
2305    wd->disabled     = EINA_FALSE;
2306    wd->context_menu = EINA_TRUE;
2307    wd->autosave     = EINA_TRUE;
2308    wd->textonly     = EINA_FALSE;
2309    wd->scroll       = EINA_FALSE;
2310
2311    wd->ent = edje_object_add(e);
2312    edje_object_item_provider_set(wd->ent, _get_item, obj);
2313    edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
2314    edje_object_markup_filter_callback_add(wd->ent,"elm.text", _markup_filter, obj);
2315    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
2316    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
2317                                   _mouse_down, obj);
2318    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
2319                                   _mouse_up, obj);
2320    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
2321                                   _mouse_move, obj);
2322    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
2323
2324    _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
2325    edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
2326                                    _signal_entry_changed, obj);
2327    edje_object_signal_callback_add(wd->ent, "entry,changed,user", "elm.text",
2328                                    _signal_entry_changed_user, obj);
2329    edje_object_signal_callback_add(wd->ent, "preedit,changed", "elm.text",
2330                                    _signal_preedit_changed, obj);
2331    edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
2332                                    _signal_selection_start, obj);
2333    edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
2334                                    _signal_selection_changed, obj);
2335    edje_object_signal_callback_add(wd->ent, "entry,selection,all,request", "elm.text",
2336                                    _signal_selection_all, obj);
2337    edje_object_signal_callback_add(wd->ent, "entry,selection,none,request", "elm.text",
2338                                    _signal_selection_none, obj);
2339    edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2340                                    _signal_selection_cleared, obj);
2341    edje_object_signal_callback_add(wd->ent, "entry,paste,request,*", "elm.text",
2342                                    _signal_entry_paste_request, obj);
2343    edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2344                                    _signal_entry_copy_notify, obj);
2345    edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2346                                    _signal_entry_cut_notify, obj);
2347    edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2348                                    _signal_cursor_changed, obj);
2349    edje_object_signal_callback_add(wd->ent, "cursor,changed,manual", "elm.text",
2350                                    _signal_cursor_changed_manual, obj);
2351    edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2352                                    _signal_anchor_down, obj);
2353    edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2354                                    _signal_anchor_up, obj);
2355    edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
2356                                    _signal_anchor_clicked, obj);
2357    edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2358                                    _signal_anchor_move, obj);
2359    edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2360                                    _signal_anchor_in, obj);
2361    edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2362                                    _signal_anchor_out, obj);
2363    edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2364                                    _signal_key_enter, obj);
2365    edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2366                                    _signal_mouse_down, obj);
2367    edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2368                                    _signal_mouse_clicked, obj);
2369    edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2370                                    _signal_mouse_double, obj);
2371    edje_object_signal_callback_add(wd->ent, "mouse,down,1,triple", "elm.text",
2372                                    _signal_mouse_triple, obj);
2373    edje_object_signal_callback_add(wd->ent, "entry,undo,request", "elm.text",
2374                                    _signal_undo_request, obj);
2375    edje_object_signal_callback_add(wd->ent, "entry,redo,request", "elm.text",
2376                                    _signal_redo_request, obj);
2377    edje_object_part_text_set(wd->ent, "elm.text", "");
2378    if (_elm_config->desktop_entry)
2379      edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
2380    elm_widget_resize_object_set(obj, wd->ent);
2381    _sizing_eval(obj);
2382
2383    elm_entry_input_panel_layout_set(obj, ELM_INPUT_PANEL_LAYOUT_NORMAL);
2384    elm_entry_input_panel_enabled_set(obj, EINA_TRUE);
2385    elm_entry_prediction_allow_set(obj, EINA_TRUE);
2386
2387    wd->autocapital_type = edje_object_part_text_autocapital_type_get(wd->ent, "elm.text");
2388
2389 #ifdef HAVE_ELEMENTARY_X
2390    top = elm_widget_top_get(obj);
2391    if ((top) && (elm_win_xwindow_get(top)))
2392      {
2393         wd->sel_notify_handler =
2394            ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2395                                    _event_selection_notify, obj);
2396         wd->sel_clear_handler =
2397            ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2398                                    _event_selection_clear, obj);
2399      }
2400
2401    elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
2402                        _drag_drop_cb, NULL);
2403 #endif
2404
2405    entries = eina_list_prepend(entries, obj);
2406
2407    // module - find module for entry
2408    wd->api = _module(obj);
2409    // if found - hook in
2410    if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2411
2412    _mirrored_set(obj, elm_widget_mirrored_get(obj));
2413    // TODO: convert Elementary to subclassing of Evas_Smart_Class
2414    // TODO: and save some bytes, making descriptions per-class and not instance!
2415    evas_object_smart_callbacks_descriptions_set(obj, _signals);
2416    return obj;
2417 }
2418
2419 EAPI void
2420 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2421 {
2422    ELM_CHECK_WIDTYPE(obj, widtype);
2423    Widget_Data *wd = elm_widget_data_get(obj);
2424    if (!wd) return;
2425    if (wd->single_line == single_line) return;
2426    wd->single_line = single_line;
2427    wd->linewrap = ELM_WRAP_NONE;
2428    elm_entry_cnp_textonly_set(obj, EINA_TRUE);
2429    _theme_hook(obj);
2430    if (wd->scroller)
2431      {
2432         if (wd->single_line)
2433           elm_smart_scroller_policy_set(wd->scroller,
2434                                         ELM_SMART_SCROLLER_POLICY_OFF,
2435                                         ELM_SMART_SCROLLER_POLICY_OFF);
2436         else
2437           {
2438              const Elm_Scroller_Policy map[3] =
2439                {
2440                   ELM_SMART_SCROLLER_POLICY_AUTO,
2441                   ELM_SMART_SCROLLER_POLICY_ON,
2442                   ELM_SMART_SCROLLER_POLICY_OFF
2443                };
2444              elm_smart_scroller_policy_set(wd->scroller,
2445                                            map[wd->policy_h],
2446                                            map[wd->policy_v]);
2447           }
2448         _sizing_eval(obj);
2449      }
2450 }
2451
2452 EAPI Eina_Bool
2453 elm_entry_single_line_get(const Evas_Object *obj)
2454 {
2455    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2456    Widget_Data *wd = elm_widget_data_get(obj);
2457    if (!wd) return EINA_FALSE;
2458    return wd->single_line;
2459 }
2460
2461 EAPI void
2462 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2463 {
2464    ELM_CHECK_WIDTYPE(obj, widtype);
2465    Widget_Data *wd = elm_widget_data_get(obj);
2466    if (!wd) return;
2467    if (wd->password == password) return;
2468    wd->password = password;
2469    if (password)
2470      {
2471         wd->single_line = EINA_TRUE;
2472         wd->linewrap = ELM_WRAP_NONE;
2473 #ifdef HAVE_ELEMENTARY_X
2474         elm_drop_target_del(obj);
2475 #endif
2476         edje_object_signal_callback_del_full(wd->ent, "selection,start", "elm.text",
2477                                         _signal_selection_start, obj);
2478         edje_object_signal_callback_del_full(wd->ent, "selection,changed", "elm.text",
2479                                         _signal_selection_changed, obj);
2480         edje_object_signal_callback_del_full(wd->ent, "entry,selection,all,request", "elm.text",
2481                                         _signal_selection_all, obj);
2482         edje_object_signal_callback_del_full(wd->ent, "entry,selection,none,request", "elm.text",
2483                                         _signal_selection_none, obj);
2484         edje_object_signal_callback_del_full(wd->ent, "selection,cleared", "elm.text",
2485                                         _signal_selection_cleared, obj);
2486         edje_object_signal_callback_del_full(wd->ent, "entry,paste,request,*", "elm.text",
2487                                         _signal_entry_paste_request, obj);
2488         edje_object_signal_callback_del_full(wd->ent, "entry,copy,notify", "elm.text",
2489                                         _signal_entry_copy_notify, obj);
2490         edje_object_signal_callback_del_full(wd->ent, "entry,cut,notify", "elm.text",
2491                                         _signal_entry_cut_notify, obj);
2492      }
2493    else
2494      {
2495 #ifdef HAVE_ELEMENTARY_X
2496         elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2497 #endif
2498         edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
2499                                         _signal_selection_start, obj);
2500         edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
2501                                         _signal_selection_changed, obj);
2502         edje_object_signal_callback_add(wd->ent, "entry,selection,all,request", "elm.text",
2503                                         _signal_selection_all, obj);
2504         edje_object_signal_callback_add(wd->ent, "entry,selection,none,request", "elm.text",
2505                                         _signal_selection_none, obj);
2506         edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2507                                         _signal_selection_cleared, obj);
2508         edje_object_signal_callback_add(wd->ent, "entry,paste,request,*", "elm.text",
2509                                         _signal_entry_paste_request, obj);
2510         edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2511                                         _signal_entry_copy_notify, obj);
2512         edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2513                                         _signal_entry_cut_notify, obj);
2514      }
2515    _theme_hook(obj);
2516 }
2517
2518 EAPI Eina_Bool
2519 elm_entry_password_get(const Evas_Object *obj)
2520 {
2521    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2522    Widget_Data *wd = elm_widget_data_get(obj);
2523    if (!wd) return EINA_FALSE;
2524    return wd->password;
2525 }
2526
2527 EAPI void
2528 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2529 {
2530    _elm_entry_text_set(obj, NULL, entry);
2531 }
2532
2533 EAPI const char *
2534 elm_entry_entry_get(const Evas_Object *obj)
2535 {
2536    return _elm_entry_text_get(obj, NULL);
2537 }
2538
2539 EAPI void
2540 elm_entry_entry_append(Evas_Object *obj, const char *entry)
2541 {
2542    int len = 0;
2543    ELM_CHECK_WIDTYPE(obj, widtype);
2544    Widget_Data *wd = elm_widget_data_get(obj);
2545    if (!wd) return;
2546    if (!entry) entry = "";
2547    wd->changed = EINA_TRUE;
2548
2549    len = strlen(entry);
2550    if (wd->append_text_left)
2551      {
2552         char *tmpbuf;
2553         tmpbuf = realloc(wd->append_text_left, wd->append_text_len + len + 1);
2554         if (!tmpbuf)
2555           {
2556              /* Do something */
2557              return;
2558           }
2559         wd->append_text_left = tmpbuf;
2560         memcpy(wd->append_text_left + wd->append_text_len, entry, len + 1);
2561         wd->append_text_len += len;
2562      }
2563    else
2564      {
2565         /* FIXME: Add chunked appending here (like in entry_set) */
2566         edje_object_part_text_append(wd->ent, "elm.text", entry);
2567      }
2568 }
2569
2570 EAPI Eina_Bool
2571 elm_entry_is_empty(const Evas_Object *obj)
2572 {
2573    /* FIXME: until there's support for that in textblock, we just check
2574     * to see if the there is text or not. */
2575    ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
2576    Widget_Data *wd = elm_widget_data_get(obj);
2577    const Evas_Object *tb;
2578    Evas_Textblock_Cursor *cur;
2579    Eina_Bool ret;
2580    if (!wd) return EINA_TRUE;
2581    /* It's a hack until we get the support suggested above.
2582     * We just create a cursor, point it to the begining, and then
2583     * try to advance it, if it can advance, the tb is not empty,
2584     * otherwise it is. */
2585    tb = edje_object_part_object_get(wd->ent, "elm.text");
2586    cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
2587                                                                   actually, ok for the time being, thsese hackish stuff will be removed
2588                                                                   once evas 1.0 is out*/
2589    evas_textblock_cursor_pos_set(cur, 0);
2590    ret = evas_textblock_cursor_char_next(cur);
2591    evas_textblock_cursor_free(cur);
2592
2593    return !ret;
2594 }
2595
2596 EAPI Evas_Object *
2597 elm_entry_textblock_get(Evas_Object *obj)
2598 {
2599    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2600    Widget_Data *wd = elm_widget_data_get(obj);
2601    if (!wd) return NULL;
2602
2603    return (Evas_Object *) edje_object_part_object_get(wd->ent, "elm.text");
2604 }
2605
2606 EAPI void
2607 elm_entry_calc_force(Evas_Object *obj)
2608 {
2609    ELM_CHECK_WIDTYPE(obj, widtype);
2610    Widget_Data *wd = elm_widget_data_get(obj);
2611    if (!wd) return;
2612
2613    edje_object_calc_force(wd->ent);
2614    wd->changed = EINA_TRUE;
2615    _sizing_eval(obj);
2616 }
2617
2618
2619 EAPI const char *
2620 elm_entry_selection_get(const Evas_Object *obj)
2621 {
2622    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2623    Widget_Data *wd = elm_widget_data_get(obj);
2624    if ((!wd) || (wd->password)) return NULL;
2625    return edje_object_part_text_selection_get(wd->ent, "elm.text");
2626 }
2627
2628 EAPI void
2629 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2630 {
2631    ELM_CHECK_WIDTYPE(obj, widtype);
2632    Widget_Data *wd = elm_widget_data_get(obj);
2633    if (!wd) return;
2634    edje_object_part_text_insert(wd->ent, "elm.text", entry);
2635    wd->changed = EINA_TRUE;
2636    _sizing_eval(obj);
2637 }
2638
2639 EAPI void
2640 elm_entry_line_wrap_set(Evas_Object *obj, Elm_Wrap_Type wrap)
2641 {
2642    ELM_CHECK_WIDTYPE(obj, widtype);
2643    Widget_Data *wd = elm_widget_data_get(obj);
2644    if (!wd) return;
2645    if (wd->linewrap == wrap) return;
2646    wd->lastw = -1;
2647    wd->linewrap = wrap;
2648    _theme_hook(obj);
2649 }
2650
2651 EAPI Elm_Wrap_Type
2652 elm_entry_line_wrap_get(const Evas_Object *obj)
2653 {
2654    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2655    Widget_Data *wd = elm_widget_data_get(obj);
2656    if (!wd) return EINA_FALSE;
2657    return wd->linewrap;
2658 }
2659
2660 EAPI void
2661 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2662 {
2663    ELM_CHECK_WIDTYPE(obj, widtype);
2664    Widget_Data *wd = elm_widget_data_get(obj);
2665    if (!wd) return;
2666    if (wd->editable == editable) return;
2667    wd->editable = editable;
2668    _theme_hook(obj);
2669
2670 #ifdef HAVE_ELEMENTARY_X
2671    if (editable)
2672      elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2673    else
2674      elm_drop_target_del(obj);
2675 #endif
2676 }
2677
2678 EAPI Eina_Bool
2679 elm_entry_editable_get(const Evas_Object *obj)
2680 {
2681    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2682    Widget_Data *wd = elm_widget_data_get(obj);
2683    if (!wd) return EINA_FALSE;
2684    return wd->editable;
2685 }
2686
2687 EAPI void
2688 elm_entry_select_none(Evas_Object *obj)
2689 {
2690    ELM_CHECK_WIDTYPE(obj, widtype);
2691    Widget_Data *wd = elm_widget_data_get(obj);
2692    if ((!wd) || (wd->password)) return;
2693    if (wd->selmode)
2694      {
2695         wd->selmode = EINA_FALSE;
2696         if (!_elm_config->desktop_entry)
2697           edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2698         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2699      }
2700    wd->have_selection = EINA_FALSE;
2701    edje_object_part_text_select_none(wd->ent, "elm.text");
2702 }
2703
2704 EAPI void
2705 elm_entry_select_all(Evas_Object *obj)
2706 {
2707    ELM_CHECK_WIDTYPE(obj, widtype);
2708    Widget_Data *wd = elm_widget_data_get(obj);
2709    if ((!wd) || (wd->password)) return;
2710    if (wd->selmode)
2711      {
2712         wd->selmode = EINA_FALSE;
2713         if (!_elm_config->desktop_entry)
2714           edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2715         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2716      }
2717    wd->have_selection = EINA_TRUE;
2718    edje_object_part_text_select_all(wd->ent, "elm.text");
2719 }
2720
2721 EAPI Eina_Bool
2722 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
2723 {
2724    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2725    Widget_Data *wd = elm_widget_data_get(obj);
2726    if (!wd) return EINA_FALSE;
2727    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
2728    return EINA_TRUE;
2729 }
2730
2731 EAPI Eina_Bool
2732 elm_entry_cursor_next(Evas_Object *obj)
2733 {
2734    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2735    Widget_Data *wd = elm_widget_data_get(obj);
2736    if (!wd) return EINA_FALSE;
2737    return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2738 }
2739
2740 EAPI Eina_Bool
2741 elm_entry_cursor_prev(Evas_Object *obj)
2742 {
2743    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2744    Widget_Data *wd = elm_widget_data_get(obj);
2745    if (!wd) return EINA_FALSE;
2746    return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2747 }
2748
2749 EAPI Eina_Bool
2750 elm_entry_cursor_up(Evas_Object *obj)
2751 {
2752    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2753    Widget_Data *wd = elm_widget_data_get(obj);
2754    if (!wd) return EINA_FALSE;
2755    return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2756 }
2757
2758 EAPI Eina_Bool
2759 elm_entry_cursor_down(Evas_Object *obj)
2760 {
2761    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2762    Widget_Data *wd = elm_widget_data_get(obj);
2763    if (!wd) return EINA_FALSE;
2764    return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2765 }
2766
2767 EAPI void
2768 elm_entry_cursor_begin_set(Evas_Object *obj)
2769 {
2770    ELM_CHECK_WIDTYPE(obj, widtype);
2771    Widget_Data *wd = elm_widget_data_get(obj);
2772    if (!wd) return;
2773    edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2774 }
2775
2776 EAPI void
2777 elm_entry_cursor_end_set(Evas_Object *obj)
2778 {
2779    ELM_CHECK_WIDTYPE(obj, widtype);
2780    Widget_Data *wd = elm_widget_data_get(obj);
2781    if (!wd) return;
2782    edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2783 }
2784
2785 EAPI void
2786 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2787 {
2788    ELM_CHECK_WIDTYPE(obj, widtype);
2789    Widget_Data *wd = elm_widget_data_get(obj);
2790    if (!wd) return;
2791    edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2792 }
2793
2794 EAPI void
2795 elm_entry_cursor_line_end_set(Evas_Object *obj)
2796 {
2797    ELM_CHECK_WIDTYPE(obj, widtype);
2798    Widget_Data *wd = elm_widget_data_get(obj);
2799    if (!wd) return;
2800    edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2801 }
2802
2803 EAPI void
2804 elm_entry_cursor_selection_begin(Evas_Object *obj)
2805 {
2806    ELM_CHECK_WIDTYPE(obj, widtype);
2807    Widget_Data *wd = elm_widget_data_get(obj);
2808    if (!wd) return;
2809    edje_object_part_text_select_begin(wd->ent, "elm.text");
2810 }
2811
2812 EAPI void
2813 elm_entry_cursor_selection_end(Evas_Object *obj)
2814 {
2815    ELM_CHECK_WIDTYPE(obj, widtype);
2816    Widget_Data *wd = elm_widget_data_get(obj);
2817    if (!wd) return;
2818    edje_object_part_text_select_extend(wd->ent, "elm.text");
2819 }
2820
2821 EAPI Eina_Bool
2822 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2823 {
2824    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2825    Widget_Data *wd = elm_widget_data_get(obj);
2826    if (!wd) return EINA_FALSE;
2827    return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2828 }
2829
2830 EAPI Eina_Bool
2831 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2832 {
2833    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2834    Widget_Data *wd = elm_widget_data_get(obj);
2835    if (!wd) return EINA_FALSE;
2836    return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2837 }
2838
2839 EAPI char *
2840 elm_entry_cursor_content_get(const Evas_Object *obj)
2841 {
2842    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2843    Widget_Data *wd = elm_widget_data_get(obj);
2844    if (!wd) return NULL;
2845    return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2846 }
2847
2848 EAPI void
2849 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
2850 {
2851    ELM_CHECK_WIDTYPE(obj, widtype);
2852    Widget_Data *wd = elm_widget_data_get(obj);
2853    if (!wd) return;
2854    edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
2855    edje_object_message_signal_process(wd->ent);
2856 }
2857
2858 EAPI int
2859 elm_entry_cursor_pos_get(const Evas_Object *obj)
2860 {
2861    ELM_CHECK_WIDTYPE(obj, widtype) 0;
2862    Widget_Data *wd = elm_widget_data_get(obj);
2863    if (!wd) return 0;
2864    return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2865 }
2866
2867 EAPI void
2868 elm_entry_selection_cut(Evas_Object *obj)
2869 {
2870    ELM_CHECK_WIDTYPE(obj, widtype);
2871    Widget_Data *wd = elm_widget_data_get(obj);
2872    if ((!wd) || (wd->password)) return;
2873    _cut(obj, NULL, NULL);
2874 }
2875
2876 EAPI void
2877 elm_entry_selection_copy(Evas_Object *obj)
2878 {
2879    ELM_CHECK_WIDTYPE(obj, widtype);
2880    Widget_Data *wd = elm_widget_data_get(obj);
2881    if ((!wd) || (wd->password)) return;
2882    _copy(obj, NULL, NULL);
2883 }
2884
2885 EAPI void
2886 elm_entry_selection_paste(Evas_Object *obj)
2887 {
2888    ELM_CHECK_WIDTYPE(obj, widtype);
2889    Widget_Data *wd = elm_widget_data_get(obj);
2890    if ((!wd) || (wd->password)) return;
2891    _paste(obj, NULL, NULL);
2892 }
2893
2894 EAPI void
2895 elm_entry_context_menu_clear(Evas_Object *obj)
2896 {
2897    ELM_CHECK_WIDTYPE(obj, widtype);
2898    Widget_Data *wd = elm_widget_data_get(obj);
2899    Elm_Entry_Context_Menu_Item *it;
2900    if (!wd) return;
2901    EINA_LIST_FREE(wd->items, it)
2902      {
2903         eina_stringshare_del(it->label);
2904         eina_stringshare_del(it->icon_file);
2905         eina_stringshare_del(it->icon_group);
2906         free(it);
2907      }
2908 }
2909
2910 EAPI void
2911 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)
2912 {
2913    ELM_CHECK_WIDTYPE(obj, widtype);
2914    Widget_Data *wd = elm_widget_data_get(obj);
2915    Elm_Entry_Context_Menu_Item *it;
2916    if (!wd) return;
2917    it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2918    if (!it) return;
2919    wd->items = eina_list_append(wd->items, it);
2920    it->obj = obj;
2921    it->label = eina_stringshare_add(label);
2922    it->icon_file = eina_stringshare_add(icon_file);
2923    it->icon_type = icon_type;
2924    it->func = func;
2925    it->data = (void *)data;
2926 }
2927
2928 EAPI void
2929 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2930 {
2931    ELM_CHECK_WIDTYPE(obj, widtype);
2932    Widget_Data *wd = elm_widget_data_get(obj);
2933    if (!wd) return;
2934    if (wd->context_menu == !disabled) return;
2935    wd->context_menu = !disabled;
2936 }
2937
2938 EAPI Eina_Bool
2939 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2940 {
2941    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2942    Widget_Data *wd = elm_widget_data_get(obj);
2943    if (!wd) return EINA_FALSE;
2944    return !wd->context_menu;
2945 }
2946
2947 EAPI void
2948 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2949 {
2950    ELM_CHECK_WIDTYPE(obj, widtype);
2951    Widget_Data *wd = elm_widget_data_get(obj);
2952    if (!wd) return;
2953    EINA_SAFETY_ON_NULL_RETURN(func);
2954    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2955    if (!ip) return;
2956    ip->func = func;
2957    ip->data = data;
2958    wd->item_providers = eina_list_append(wd->item_providers, ip);
2959 }
2960
2961 EAPI void
2962 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2963 {
2964    ELM_CHECK_WIDTYPE(obj, widtype);
2965    Widget_Data *wd = elm_widget_data_get(obj);
2966    if (!wd) return;
2967    EINA_SAFETY_ON_NULL_RETURN(func);
2968    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2969    if (!ip) return;
2970    ip->func = func;
2971    ip->data = data;
2972    wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2973 }
2974
2975 EAPI void
2976 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2977 {
2978    ELM_CHECK_WIDTYPE(obj, widtype);
2979    Widget_Data *wd = elm_widget_data_get(obj);
2980    Eina_List *l;
2981    Elm_Entry_Item_Provider *ip;
2982    if (!wd) return;
2983    EINA_SAFETY_ON_NULL_RETURN(func);
2984    EINA_LIST_FOREACH(wd->item_providers, l, ip)
2985      {
2986         if ((ip->func == func) && ((!data) || (ip->data == data)))
2987           {
2988              wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2989              free(ip);
2990              return;
2991           }
2992      }
2993 }
2994
2995 EAPI void
2996 elm_entry_text_filter_append(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
2997 {
2998    Widget_Data *wd;
2999    Elm_Entry_Markup_Filter *tf;
3000    ELM_CHECK_WIDTYPE(obj, widtype);
3001
3002    wd = elm_widget_data_get(obj);
3003
3004    EINA_SAFETY_ON_NULL_RETURN(func);
3005
3006    tf = _filter_new(func, data);
3007    if (!tf) return;
3008
3009    wd->text_filters = eina_list_append(wd->text_filters, tf);
3010 }
3011
3012 EAPI void
3013 elm_entry_text_filter_prepend(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
3014 {
3015    Widget_Data *wd;
3016    Elm_Entry_Markup_Filter *tf;
3017    ELM_CHECK_WIDTYPE(obj, widtype);
3018
3019    wd = elm_widget_data_get(obj);
3020
3021    EINA_SAFETY_ON_NULL_RETURN(func);
3022
3023    tf = _filter_new(func, data);
3024    if (!tf) return;
3025
3026    wd->text_filters = eina_list_prepend(wd->text_filters, tf);
3027 }
3028
3029 EAPI void
3030 elm_entry_text_filter_remove(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
3031 {
3032    Widget_Data *wd;
3033    Eina_List *l;
3034    Elm_Entry_Markup_Filter *tf;
3035    ELM_CHECK_WIDTYPE(obj, widtype);
3036
3037    wd = elm_widget_data_get(obj);
3038
3039    EINA_SAFETY_ON_NULL_RETURN(func);
3040
3041    EINA_LIST_FOREACH(wd->text_filters, l, tf)
3042      {
3043         if ((tf->func == func) && ((!data) || (tf->data == data)))
3044           {
3045              wd->text_filters = eina_list_remove_list(wd->text_filters, l);
3046              _filter_free(tf);
3047              return;
3048           }
3049      }
3050 }
3051
3052 EAPI void
3053 elm_entry_markup_filter_append(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
3054 {
3055    Widget_Data *wd;
3056    Elm_Entry_Markup_Filter *tf;
3057    ELM_CHECK_WIDTYPE(obj, widtype);
3058
3059    wd = elm_widget_data_get(obj);
3060
3061    EINA_SAFETY_ON_NULL_RETURN(func);
3062
3063    tf = _filter_new(func, data);
3064    if (!tf) return;
3065
3066    wd->markup_filters = eina_list_append(wd->markup_filters, tf);
3067 }
3068
3069 EAPI void
3070 elm_entry_markup_filter_prepend(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
3071 {
3072    Widget_Data *wd;
3073    Elm_Entry_Markup_Filter *tf;
3074    ELM_CHECK_WIDTYPE(obj, widtype);
3075
3076    wd = elm_widget_data_get(obj);
3077
3078    EINA_SAFETY_ON_NULL_RETURN(func);
3079
3080    tf = _filter_new(func, data);
3081    if (!tf) return;
3082
3083    wd->markup_filters = eina_list_prepend(wd->markup_filters, tf);
3084 }
3085
3086 EAPI void
3087 elm_entry_markup_filter_remove(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
3088 {
3089    Widget_Data *wd;
3090    Eina_List *l;
3091    Elm_Entry_Markup_Filter *tf;
3092    ELM_CHECK_WIDTYPE(obj, widtype);
3093
3094    wd = elm_widget_data_get(obj);
3095
3096    EINA_SAFETY_ON_NULL_RETURN(func);
3097
3098    EINA_LIST_FOREACH(wd->markup_filters, l, tf)
3099      {
3100         if ((tf->func == func) && ((!data) || (tf->data == data)))
3101           {
3102              wd->markup_filters = eina_list_remove_list(wd->markup_filters, l);
3103              _filter_free(tf);
3104              return;
3105           }
3106      }
3107 }
3108
3109 EAPI char *
3110 elm_entry_markup_to_utf8(const char *s)
3111 {
3112    char *ss = _elm_util_mkup_to_text(s);
3113    if (!ss) ss = strdup("");
3114    return ss;
3115 }
3116
3117 EAPI char *
3118 elm_entry_utf8_to_markup(const char *s)
3119 {
3120    char *ss = _elm_util_text_to_mkup(s);
3121    if (!ss) ss = strdup("");
3122    return ss;
3123 }
3124
3125 static const char *
3126 _text_get(const Evas_Object *obj)
3127 {
3128    return elm_object_text_get(obj);
3129 }
3130
3131 EAPI void
3132 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
3133 {
3134    Elm_Entry_Filter_Limit_Size *lim = data;
3135    char *current, *utfstr;
3136    int len, newlen;
3137    const char *(*text_get)(const Evas_Object *);
3138
3139    EINA_SAFETY_ON_NULL_RETURN(data);
3140    EINA_SAFETY_ON_NULL_RETURN(entry);
3141    EINA_SAFETY_ON_NULL_RETURN(text);
3142
3143    /* hack. I don't want to copy the entire function to work with
3144     * scrolled_entry */
3145    text_get = _text_get;
3146
3147    current = elm_entry_markup_to_utf8(text_get(entry));
3148    utfstr = elm_entry_markup_to_utf8(*text);
3149
3150    if (lim->max_char_count > 0)
3151      {
3152         len = evas_string_char_len_get(current);
3153         if (len >= lim->max_char_count)
3154           {
3155              evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3156              free(*text);
3157              *text = NULL;
3158              free(current);
3159              free(utfstr);
3160              return;
3161           }
3162         newlen = evas_string_char_len_get(utfstr);
3163         if ((len + newlen) > lim->max_char_count)
3164           _add_chars_till_limit(entry, text, (lim->max_char_count - len), LENGTH_UNIT_CHAR);
3165      }
3166    else if (lim->max_byte_count > 0)
3167      {
3168         len = strlen(current);
3169         if (len >= lim->max_byte_count)
3170           {
3171              evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3172              free(*text);
3173              *text = NULL;
3174              free(current);
3175              free(utfstr);
3176              return;
3177           }
3178         newlen = strlen(utfstr);
3179         if ((len + newlen) > lim->max_byte_count)
3180           _add_chars_till_limit(entry, text, (lim->max_byte_count - len), LENGTH_UNIT_BYTE);
3181      }
3182    free(current);
3183    free(utfstr);
3184 }
3185
3186 EAPI void
3187 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
3188 {
3189    Elm_Entry_Filter_Accept_Set *as = data;
3190    const char *set;
3191    char *insert;
3192    Eina_Bool goes_in;
3193    int read_idx, last_read_idx = 0, read_char;
3194
3195    EINA_SAFETY_ON_NULL_RETURN(data);
3196    EINA_SAFETY_ON_NULL_RETURN(text);
3197
3198    if ((!as->accepted) && (!as->rejected))
3199      return;
3200
3201    if (as->accepted)
3202      {
3203         set = as->accepted;
3204         goes_in = EINA_TRUE;
3205      }
3206    else
3207      {
3208         set = as->rejected;
3209         goes_in = EINA_FALSE;
3210      }
3211
3212    insert = *text;
3213    read_idx = evas_string_char_next_get(*text, 0, &read_char);
3214    while (read_char)
3215      {
3216         int cmp_idx, cmp_char;
3217         Eina_Bool in_set = EINA_FALSE;
3218
3219         cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
3220         while (cmp_char)
3221           {
3222              if (read_char == cmp_char)
3223                {
3224                   in_set = EINA_TRUE;
3225                   break;
3226                }
3227              cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
3228           }
3229         if (in_set == goes_in)
3230           {
3231              int size = read_idx - last_read_idx;
3232              const char *src = (*text) + last_read_idx;
3233              if (src != insert)
3234                memcpy(insert, *text + last_read_idx, size);
3235              insert += size;
3236           }
3237         last_read_idx = read_idx;
3238         read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
3239      }
3240    *insert = 0;
3241 }
3242
3243 EAPI void
3244 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
3245 {
3246    ELM_CHECK_WIDTYPE(obj, widtype);
3247    Widget_Data *wd = elm_widget_data_get(obj);
3248    if (!wd) return;
3249    if (wd->delay_write)
3250      {
3251         ecore_timer_del(wd->delay_write);
3252         wd->delay_write = NULL;
3253      }
3254    if (wd->autosave) _save(obj);
3255    eina_stringshare_replace(&wd->file, file);
3256    wd->format = format;
3257    _load(obj);
3258 }
3259
3260 EAPI void
3261 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
3262 {
3263    ELM_CHECK_WIDTYPE(obj, widtype);
3264    Widget_Data *wd = elm_widget_data_get(obj);
3265    if (!wd) return;
3266    if (file) *file = wd->file;
3267    if (format) *format = wd->format;
3268 }
3269
3270 EAPI void
3271 elm_entry_file_save(Evas_Object *obj)
3272 {
3273    ELM_CHECK_WIDTYPE(obj, widtype);
3274    Widget_Data *wd = elm_widget_data_get(obj);
3275    if (!wd) return;
3276    if (wd->delay_write)
3277      {
3278         ecore_timer_del(wd->delay_write);
3279         wd->delay_write = NULL;
3280      }
3281    _save(obj);
3282    wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
3283 }
3284
3285 EAPI void
3286 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
3287 {
3288    ELM_CHECK_WIDTYPE(obj, widtype);
3289    Widget_Data *wd = elm_widget_data_get(obj);
3290    if (!wd) return;
3291    wd->autosave = !!autosave;
3292 }
3293
3294 EAPI Eina_Bool
3295 elm_entry_autosave_get(const Evas_Object *obj)
3296 {
3297    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3298    Widget_Data *wd = elm_widget_data_get(obj);
3299    if (!wd) return EINA_FALSE;
3300    return wd->autosave;
3301 }
3302
3303 EAPI void
3304 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
3305 {
3306    Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
3307    ELM_CHECK_WIDTYPE(obj, widtype);
3308    Widget_Data *wd = elm_widget_data_get(obj);
3309    if (!wd) return;
3310    textonly = !!textonly;
3311    if (wd->textonly == textonly) return;
3312    wd->textonly = !!textonly;
3313    if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
3314 #ifdef HAVE_ELEMENTARY_X
3315    elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
3316 #endif
3317 }
3318
3319 EAPI Eina_Bool
3320 elm_entry_cnp_textonly_get(const Evas_Object *obj)
3321 {
3322    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3323    Widget_Data *wd = elm_widget_data_get(obj);
3324    if (!wd) return EINA_FALSE;
3325    return wd->textonly;
3326 }
3327
3328 EAPI void
3329 elm_entry_scrollable_set(Evas_Object *obj, Eina_Bool scroll)
3330 {
3331    ELM_CHECK_WIDTYPE(obj, widtype);
3332    Widget_Data *wd = elm_widget_data_get(obj);
3333    const Elm_Scroller_Policy map[3] =
3334      {
3335         ELM_SMART_SCROLLER_POLICY_AUTO,
3336         ELM_SMART_SCROLLER_POLICY_ON,
3337         ELM_SMART_SCROLLER_POLICY_OFF
3338      };
3339    if (!wd) return;
3340    scroll = !!scroll;
3341    if (wd->scroll == scroll) return;
3342    wd->scroll = scroll;
3343    if (wd->scroll)
3344      {
3345         if (!wd->scroller)
3346           {
3347              wd->scroller = elm_smart_scroller_add(evas_object_evas_get(obj));
3348              elm_widget_resize_object_set(obj, wd->scroller);
3349              elm_smart_scroller_widget_set(wd->scroller, obj);
3350              elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
3351                                                  elm_widget_style_get(obj));
3352              evas_object_size_hint_weight_set(wd->scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3353              evas_object_size_hint_align_set(wd->scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
3354              evas_object_propagate_events_set(wd->scroller, EINA_TRUE);
3355              evas_object_propagate_events_set(elm_smart_scroller_edje_object_get(wd->scroller),
3356                                               EINA_TRUE);
3357           }
3358         elm_smart_scroller_bounce_allow_set(wd->scroller, wd->h_bounce, wd->v_bounce);
3359         if (wd->single_line)
3360           elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
3361                                         ELM_SMART_SCROLLER_POLICY_OFF);
3362         else
3363           elm_smart_scroller_policy_set(wd->scroller, map[wd->policy_h], map[wd->policy_v]);
3364         elm_widget_sub_object_add(obj, wd->ent);
3365         elm_smart_scroller_child_set(wd->scroller, wd->ent);
3366         evas_object_show(wd->scroller);
3367         elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
3368      }
3369    else
3370      {
3371         if (wd->scroller)
3372           {
3373              elm_smart_scroller_child_set(wd->scroller, NULL);
3374              evas_object_smart_member_add(wd->scroller, obj);
3375              elm_widget_sub_object_add(obj, wd->scroller);
3376              evas_object_hide(wd->scroller);
3377           }
3378         elm_widget_sub_object_del(obj, wd->ent);
3379         elm_widget_resize_object_set(obj, wd->ent);
3380         elm_widget_on_show_region_hook_set(obj, NULL, NULL);
3381      }
3382    wd->lastw = -1;
3383    _theme_hook(obj);
3384 }
3385
3386 EAPI Eina_Bool
3387 elm_entry_scrollable_get(const Evas_Object *obj)
3388 {
3389    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3390    Widget_Data *wd = elm_widget_data_get(obj);
3391    if (!wd) return EINA_FALSE;
3392    return wd->scroll;
3393 }
3394
3395 EAPI void
3396 elm_entry_icon_set(Evas_Object *obj, Evas_Object *icon)
3397 {
3398    ELM_CHECK_WIDTYPE(obj, widtype);
3399    EINA_SAFETY_ON_NULL_RETURN(icon);
3400    _content_set_hook(obj, NULL, icon);
3401 }
3402
3403 EAPI Evas_Object *
3404 elm_entry_icon_get(const Evas_Object *obj)
3405 {
3406    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3407    return _content_get_hook(obj, NULL);
3408 }
3409
3410 EAPI Evas_Object *
3411 elm_entry_icon_unset(Evas_Object *obj)
3412 {
3413    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3414    return _content_unset_hook(obj, NULL);
3415 }
3416
3417 EAPI void
3418 elm_entry_icon_visible_set(Evas_Object *obj, Eina_Bool setting)
3419 {
3420    ELM_CHECK_WIDTYPE(obj, widtype);
3421    Widget_Data *wd = elm_widget_data_get(obj);
3422    Evas_Object *edje;
3423    if (!wd) return;
3424    if (wd->scroll)
3425       edje = elm_smart_scroller_edje_object_get(wd->scroller);
3426    else
3427       edje = wd->ent;
3428
3429    if ((!edje) || (!edje_object_part_swallow_get(edje, "elm.swallow.icon"))) return;
3430    if (setting)
3431      edje_object_signal_emit(edje, "elm,action,show,icon", "elm");
3432    else
3433      edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
3434    _sizing_eval(obj);
3435 }
3436
3437 EAPI void
3438 elm_entry_end_set(Evas_Object *obj, Evas_Object *end)
3439 {
3440    ELM_CHECK_WIDTYPE(obj, widtype);
3441    EINA_SAFETY_ON_NULL_RETURN(end);
3442    _content_set_hook(obj, "end", end);
3443 }
3444
3445 EAPI Evas_Object *
3446 elm_entry_end_get(const Evas_Object *obj)
3447 {
3448    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3449    return _content_get_hook(obj, "end");
3450 }
3451
3452 EAPI Evas_Object *
3453 elm_entry_end_unset(Evas_Object *obj)
3454 {
3455    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3456    return _content_unset_hook(obj, "end");
3457 }
3458
3459 EAPI void
3460 elm_entry_end_visible_set(Evas_Object *obj, Eina_Bool setting)
3461 {
3462    ELM_CHECK_WIDTYPE(obj, widtype);
3463    Widget_Data *wd = elm_widget_data_get(obj);
3464    Evas_Object *edje;
3465    if (!wd) return;
3466    if (wd->scroll)
3467       edje = elm_smart_scroller_edje_object_get(wd->scroller);
3468    else
3469       edje = wd->ent;
3470
3471    if ((!edje) || (!edje_object_part_swallow_get(edje, "elm.swallow.icon"))) return;
3472    if (setting)
3473      edje_object_signal_emit(edje, "elm,action,show,end", "elm");
3474    else
3475      edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
3476    _sizing_eval(obj);
3477 }
3478
3479 EAPI void
3480 elm_entry_scrollbar_policy_set(Evas_Object *obj, Elm_Scroller_Policy h, Elm_Scroller_Policy v)
3481 {
3482    ELM_CHECK_WIDTYPE(obj, widtype);
3483    Widget_Data *wd = elm_widget_data_get(obj);
3484    const Elm_Scroller_Policy map[3] =
3485      {
3486         ELM_SMART_SCROLLER_POLICY_AUTO,
3487         ELM_SMART_SCROLLER_POLICY_ON,
3488         ELM_SMART_SCROLLER_POLICY_OFF
3489      };
3490    if (!wd) return;
3491    wd->policy_h = h;
3492    wd->policy_v = v;
3493    elm_smart_scroller_policy_set(wd->scroller,
3494                                  map[wd->policy_h],
3495                                  map[wd->policy_v]);
3496 }
3497
3498 EAPI void
3499 elm_entry_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
3500 {
3501    ELM_CHECK_WIDTYPE(obj, widtype);
3502    Widget_Data *wd = elm_widget_data_get(obj);
3503    if (!wd) return;
3504    wd->h_bounce = h_bounce;
3505    wd->v_bounce = v_bounce;
3506    elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
3507 }
3508
3509 EAPI void
3510 elm_entry_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
3511 {
3512    ELM_CHECK_WIDTYPE(obj, widtype);
3513    Widget_Data *wd = elm_widget_data_get(obj);
3514    if (!wd) return;
3515    elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
3516 }
3517
3518 EAPI void
3519 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
3520 {
3521    ELM_CHECK_WIDTYPE(obj, widtype);
3522    Widget_Data *wd = elm_widget_data_get(obj);
3523    if (!wd) return;
3524
3525    wd->input_panel_layout = layout;
3526
3527    edje_object_part_text_input_panel_layout_set(wd->ent, "elm.text", layout);
3528 }
3529
3530 EAPI Elm_Input_Panel_Layout
3531 elm_entry_input_panel_layout_get(Evas_Object *obj)
3532 {
3533    ELM_CHECK_WIDTYPE(obj, widtype) ELM_INPUT_PANEL_LAYOUT_INVALID;
3534    Widget_Data *wd = elm_widget_data_get(obj);
3535    if (!wd) return ELM_INPUT_PANEL_LAYOUT_INVALID;
3536
3537    return wd->input_panel_layout;
3538 }
3539
3540 EAPI void
3541 elm_entry_autocapital_type_set(Evas_Object *obj, Elm_Autocapital_Type autocapital_type)
3542 {
3543    ELM_CHECK_WIDTYPE(obj, widtype);
3544    Widget_Data *wd = elm_widget_data_get(obj);
3545    if (!wd) return;
3546
3547    wd->autocapital_type = autocapital_type;
3548    edje_object_part_text_autocapital_type_set(wd->ent, "elm.text", autocapital_type);
3549 }
3550
3551 EAPI Elm_Autocapital_Type
3552 elm_entry_autocapital_type_get(Evas_Object *obj)
3553 {
3554    ELM_CHECK_WIDTYPE(obj, widtype) ELM_AUTOCAPITAL_TYPE_NONE;
3555    Widget_Data *wd = elm_widget_data_get(obj);
3556    if (!wd) return ELM_AUTOCAPITAL_TYPE_NONE;
3557
3558    return wd->autocapital_type;
3559 }
3560
3561 EAPI void
3562 elm_entry_prediction_allow_set(Evas_Object *obj, Eina_Bool prediction)
3563 {
3564    ELM_CHECK_WIDTYPE(obj, widtype);
3565    Widget_Data *wd = elm_widget_data_get(obj);
3566    if (!wd) return;
3567
3568    wd->prediction_allow = prediction;
3569    edje_object_part_text_prediction_allow_set(wd->ent, "elm.text", prediction);
3570 }
3571
3572 EAPI Eina_Bool
3573 elm_entry_prediction_allow_get(Evas_Object *obj)
3574 {
3575    ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
3576    Widget_Data *wd = elm_widget_data_get(obj);
3577    if (!wd) return EINA_TRUE;
3578
3579    return wd->prediction_allow;
3580 }
3581
3582 EAPI void
3583 elm_entry_imf_context_reset(Evas_Object *obj)
3584 {
3585    ELM_CHECK_WIDTYPE(obj, widtype);
3586    Widget_Data *wd = elm_widget_data_get(obj);
3587    if (!wd) return;
3588
3589    edje_object_part_text_imf_context_reset(wd->ent, "elm.text");
3590 }
3591
3592 EAPI void
3593 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
3594 {
3595    ELM_CHECK_WIDTYPE(obj, widtype);
3596    Widget_Data *wd = elm_widget_data_get(obj);
3597    if (!wd) return;
3598
3599    wd->input_panel_enable = enabled;
3600    edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
3601 }
3602
3603 EAPI Eina_Bool
3604 elm_entry_input_panel_enabled_get(Evas_Object *obj)
3605 {
3606    ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
3607    Widget_Data *wd = elm_widget_data_get(obj);
3608    if (!wd) return EINA_TRUE;
3609
3610    return wd->input_panel_enable;
3611 }
3612
3613 EAPI void
3614 elm_entry_input_panel_show(Evas_Object *obj)
3615 {
3616    ELM_CHECK_WIDTYPE(obj, widtype);
3617    Widget_Data *wd = elm_widget_data_get(obj);
3618    if (!wd) return;
3619
3620    edje_object_part_text_input_panel_show(wd->ent, "elm.text");
3621 }
3622
3623 EAPI void
3624 elm_entry_input_panel_hide(Evas_Object *obj)
3625 {
3626    ELM_CHECK_WIDTYPE(obj, widtype);
3627    Widget_Data *wd = elm_widget_data_get(obj);
3628    if (!wd) return;
3629
3630    edje_object_part_text_input_panel_hide(wd->ent, "elm.text");
3631 }
3632
3633