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