elm entry: add the elm_object_text_set/get hooks.
[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_object_text_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, event, 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 static void
1860 _elm_entry_text_set(Evas_Object *obj, const char *item, const char *entry)
1861 {
1862    int len = 0;
1863    ELM_CHECK_WIDTYPE(obj, widtype);
1864    if (item) return;
1865    Widget_Data *wd = elm_widget_data_get(obj);
1866    if (!wd) return;
1867    if (!entry) entry = "";
1868    if (wd->text) eina_stringshare_del(wd->text);
1869    wd->text = NULL;
1870    wd->changed = EINA_TRUE;
1871
1872    /* Clear currently pending job if there is one */
1873    if (wd->append_text_idler)
1874      {
1875         ecore_idler_del(wd->append_text_idler);
1876         free(wd->append_text_left);
1877         wd->append_text_left = NULL;
1878         wd->append_text_idler = NULL;
1879      }
1880
1881    len = strlen(entry);
1882    /* Split to ~_CHUNK_SIZE chunks */
1883    if (len > _CHUNK_SIZE)
1884      {
1885         wd->append_text_left = (char *) malloc(len + 1);
1886      }
1887
1888    /* If we decided to use the idler */
1889    if (wd->append_text_left)
1890      {
1891         /* Need to clear the entry first */
1892         edje_object_part_text_set(wd->ent, "elm.text", "");
1893         memcpy(wd->append_text_left, entry, len + 1);
1894         wd->append_text_position = 0;
1895         wd->append_text_len = len;
1896         wd->append_text_idler = ecore_idler_add(_text_append_idler, obj);
1897      }
1898    else
1899      {
1900         edje_object_part_text_set(wd->ent, "elm.text", entry);
1901      }
1902 }
1903
1904 static const char *
1905 _elm_entry_text_get(const Evas_Object *obj, const char *item)
1906 {
1907    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1908    Widget_Data *wd = elm_widget_data_get(obj);
1909    if (item) return NULL;
1910    const char *text;
1911    if (!wd) return NULL;
1912    if (wd->text) return wd->text;
1913    text = edje_object_part_text_get(wd->ent, "elm.text");
1914    if (!text)
1915      {
1916         ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
1917         return NULL;
1918      }
1919    eina_stringshare_replace(&wd->text, text);
1920    return wd->text;
1921 }
1922
1923 /**
1924  * This adds an entry to @p parent object.
1925  *
1926  * @param parent The parent object
1927  * @return The new object or NULL if it cannot be created
1928  *
1929  * @ingroup Entry
1930  */
1931 EAPI Evas_Object *
1932 elm_entry_add(Evas_Object *parent)
1933 {
1934    Evas_Object *obj, *top;
1935    Evas *e;
1936    Widget_Data *wd;
1937
1938    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1939
1940    ELM_SET_WIDTYPE(widtype, "entry");
1941    elm_widget_type_set(obj, "entry");
1942    elm_widget_sub_object_add(parent, obj);
1943    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1944    elm_widget_data_set(obj, wd);
1945    elm_widget_del_hook_set(obj, _del_hook);
1946    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1947    elm_widget_theme_hook_set(obj, _theme_hook);
1948    elm_widget_disable_hook_set(obj, _disable_hook);
1949    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1950    elm_widget_focus_region_hook_set(obj, _focus_region_hook);
1951    elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
1952    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1953    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1954    elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
1955    elm_widget_can_focus_set(obj, EINA_TRUE);
1956    elm_widget_highlight_ignore_set(obj, EINA_TRUE);
1957    elm_widget_text_set_hook_set(obj, _elm_entry_text_set);
1958    elm_widget_text_get_hook_set(obj, _elm_entry_text_get);
1959
1960    wd->scroller = elm_smart_scroller_add(e);
1961    elm_widget_sub_object_add(obj, wd->scroller);
1962    elm_smart_scroller_widget_set(wd->scroller, obj);
1963    elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
1964                                        elm_widget_style_get(obj));
1965    evas_object_size_hint_weight_set(wd->scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1966    evas_object_size_hint_align_set(wd->scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
1967    elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
1968    evas_object_propagate_events_set(wd->scroller, EINA_TRUE);
1969
1970    wd->linewrap     = ELM_WRAP_WORD;
1971    wd->editable     = EINA_TRUE;
1972    wd->disabled     = EINA_FALSE;
1973    wd->context_menu = EINA_TRUE;
1974    wd->autosave     = EINA_TRUE;
1975    wd->textonly     = EINA_FALSE;
1976
1977    wd->ent = edje_object_add(e);
1978    elm_widget_sub_object_add(obj, wd->ent);
1979    edje_object_item_provider_set(wd->ent, _get_item, obj);
1980    edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
1981    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1982    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1983                                   _mouse_down, obj);
1984    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1985                                   _mouse_up, obj);
1986    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1987                                   _mouse_move, obj);
1988    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
1989
1990    _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1991    edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1992                                    _signal_entry_changed, obj);
1993    edje_object_signal_callback_add(wd->ent, "preedit,changed", "elm.text",
1994                                    _signal_preedit_changed, obj);
1995    edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1996                                    _signal_selection_start, obj);
1997    edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1998                                    _signal_selection_changed, obj);
1999    edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2000                                    _signal_selection_cleared, obj);
2001    edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
2002                                    _signal_entry_paste_request, obj);
2003    edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2004                                    _signal_entry_copy_notify, obj);
2005    edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2006                                    _signal_entry_cut_notify, obj);
2007    edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2008                                    _signal_cursor_changed, obj);
2009    edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2010                                    _signal_anchor_down, obj);
2011    edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2012                                    _signal_anchor_up, obj);
2013    edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
2014                                    _signal_anchor_clicked, obj);
2015    edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2016                                    _signal_anchor_move, obj);
2017    edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2018                                    _signal_anchor_in, obj);
2019    edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2020                                    _signal_anchor_out, obj);
2021    edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2022                                    _signal_key_enter, obj);
2023    edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2024                                    _signal_mouse_down, obj);
2025    edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2026                                    _signal_mouse_clicked, obj);
2027    edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2028                                    _signal_mouse_double, obj);
2029    edje_object_part_text_set(wd->ent, "elm.text", "");
2030    if (_elm_config->desktop_entry)
2031      edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
2032    elm_widget_resize_object_set(obj, wd->ent);
2033    _sizing_eval(obj);
2034
2035 #ifdef HAVE_ELEMENTARY_X
2036    top = elm_widget_top_get(obj);
2037    if ((top) && (elm_win_xwindow_get(top)))
2038      {
2039         wd->sel_notify_handler =
2040            ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2041                                    _event_selection_notify, obj);
2042         wd->sel_clear_handler =
2043            ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2044                                    _event_selection_clear, obj);
2045      }
2046
2047    elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
2048                        _drag_drop_cb, NULL);
2049 #endif
2050
2051    entries = eina_list_prepend(entries, obj);
2052
2053    // module - find module for entry
2054    wd->api = _module(obj);
2055    // if found - hook in
2056    if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2057
2058    _mirrored_set(obj, elm_widget_mirrored_get(obj));
2059    // TODO: convert Elementary to subclassing of Evas_Smart_Class
2060    // TODO: and save some bytes, making descriptions per-class and not instance!
2061    evas_object_smart_callbacks_descriptions_set(obj, _signals);
2062    return obj;
2063 }
2064
2065 /**
2066  * This sets the entry object not to line wrap.  All input will
2067  * be on a single line, and the entry box will extend with user input.
2068  *
2069  * @param obj The entry object
2070  * @param single_line If true, the text in the entry
2071  * will be on a single line.
2072  *
2073  * @ingroup Entry
2074  */
2075 EAPI void
2076 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2077 {
2078    ELM_CHECK_WIDTYPE(obj, widtype);
2079    Widget_Data *wd = elm_widget_data_get(obj);
2080    if (!wd) return;
2081    if (wd->single_line == single_line) return;
2082    wd->single_line = single_line;
2083    wd->linewrap = ELM_WRAP_NONE;
2084    elm_entry_cnp_textonly_set(obj, EINA_TRUE);
2085    _theme_hook(obj);
2086    if (wd->scroller)
2087      {
2088         if (wd->single_line)
2089            elm_smart_scroller_policy_set(wd->scroller,
2090                                          ELM_SMART_SCROLLER_POLICY_OFF,
2091                                          ELM_SMART_SCROLLER_POLICY_OFF);
2092         else
2093           {
2094              const Elm_Scroller_Policy map[3] =
2095                {
2096                   ELM_SMART_SCROLLER_POLICY_AUTO,
2097                   ELM_SMART_SCROLLER_POLICY_ON,
2098                   ELM_SMART_SCROLLER_POLICY_OFF
2099                };
2100              elm_smart_scroller_policy_set(wd->scroller,
2101                                            map[wd->policy_h],
2102                                            map[wd->policy_v]);
2103           }
2104         _sizing_eval(obj);
2105      }
2106 }
2107
2108 /**
2109  * This returns true if the entry has been set to single line mode.
2110  * See also elm_entry_single_line_set().
2111  *
2112  * @param obj The entry object
2113  * @return single_line If true, the text in the entry is set to display
2114  * on a single line.
2115  *
2116  * @ingroup Entry
2117  */
2118 EAPI Eina_Bool
2119 elm_entry_single_line_get(const Evas_Object *obj)
2120 {
2121    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2122    Widget_Data *wd = elm_widget_data_get(obj);
2123    if (!wd) return EINA_FALSE;
2124    return wd->single_line;
2125 }
2126
2127 /**
2128  * This sets the entry object to password mode.  All text entered
2129  * and/or displayed within the widget will be replaced with asterisks (*).
2130  *
2131  * @param obj The entry object
2132  * @param password If true, password mode is enabled.
2133  *
2134  * @ingroup Entry
2135  */
2136 EAPI void
2137 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2138 {
2139    ELM_CHECK_WIDTYPE(obj, widtype);
2140    Widget_Data *wd = elm_widget_data_get(obj);
2141    if (!wd) return;
2142    if (wd->password == password) return;
2143    wd->password = password;
2144    wd->single_line = EINA_TRUE;
2145    wd->linewrap = ELM_WRAP_NONE;
2146    _theme_hook(obj);
2147 }
2148
2149 /**
2150  * This returns whether password mode is enabled.
2151  * See also elm_entry_password_set().
2152  *
2153  * @param obj The entry object
2154  * @return If true, the entry is set to display all characters
2155  * as asterisks (*).
2156  *
2157  * @ingroup Entry
2158  */
2159 EAPI Eina_Bool
2160 elm_entry_password_get(const Evas_Object *obj)
2161 {
2162    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2163    Widget_Data *wd = elm_widget_data_get(obj);
2164    if (!wd) return EINA_FALSE;
2165    return wd->password;
2166 }
2167
2168 /**
2169  * This sets the text displayed within the entry to @p entry.
2170  *
2171  * @param obj The entry object
2172  * @param entry The text to be displayed
2173  *
2174  * @ingroup Entry
2175  */
2176 EAPI void
2177 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2178 {
2179    _elm_entry_text_set(obj, NULL, entry);
2180 }
2181
2182 /**
2183  * This appends @p entry to the text of the entry.
2184  *
2185  * @param obj The entry object
2186  * @param entry The text to be displayed
2187  *
2188  * @ingroup Entry
2189  */
2190 EAPI void
2191 elm_entry_entry_append(Evas_Object *obj, const char *entry)
2192 {
2193    int len = 0;
2194    ELM_CHECK_WIDTYPE(obj, widtype);
2195    Widget_Data *wd = elm_widget_data_get(obj);
2196    if (!wd) return;
2197    if (!entry) entry = "";
2198    wd->changed = EINA_TRUE;
2199
2200    len = strlen(entry);
2201    if (wd->append_text_left)
2202      {
2203         char *tmpbuf;
2204         tmpbuf = realloc(wd->append_text_left, wd->append_text_len + len + 1);
2205         if (!tmpbuf)
2206           {
2207              /* Do something */
2208              return;
2209           }
2210         wd->append_text_left = tmpbuf;
2211         memcpy(wd->append_text_left + wd->append_text_len, entry, len + 1);
2212         wd->append_text_len += len;
2213      }
2214    else
2215      {
2216         /* FIXME: Add chunked appending here (like in entry_set) */
2217         edje_object_part_text_append(wd->ent, "elm.text", entry);
2218      }
2219 }
2220
2221 /**
2222  * This returns the text currently shown in object @p entry.
2223  * See also elm_entry_entry_set().
2224  *
2225  * @param obj The entry object
2226  * @return The currently displayed text or NULL on failure
2227  *
2228  * @ingroup Entry
2229  */
2230 EAPI const char *
2231 elm_entry_entry_get(const Evas_Object *obj)
2232 {
2233    return _elm_entry_text_get(obj, NULL);
2234 }
2235
2236 /**
2237  * This returns EINA_TRUE if the entry is empty/there was an error
2238  * and EINA_FALSE if it is not empty.
2239  *
2240  * @param obj The entry object
2241  * @return If the entry is empty or not.
2242  *
2243  * @ingroup Entry
2244  */
2245 EAPI Eina_Bool
2246 elm_entry_is_empty(const Evas_Object *obj)
2247 {
2248    /* FIXME: until there's support for that in textblock, we just check
2249     * to see if the there is text or not. */
2250    ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
2251    Widget_Data *wd = elm_widget_data_get(obj);
2252    const Evas_Object *tb;
2253    Evas_Textblock_Cursor *cur;
2254    Eina_Bool ret;
2255    if (!wd) return EINA_TRUE;
2256    /* It's a hack until we get the support suggested above.
2257     * We just create a cursor, point it to the begining, and then
2258     * try to advance it, if it can advance, the tb is not empty,
2259     * otherwise it is. */
2260    tb = edje_object_part_object_get(wd->ent, "elm.text");
2261    cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
2262                                                                   actually, ok for the time being, thsese hackish stuff will be removed
2263                                                                   once evas 1.0 is out*/
2264    evas_textblock_cursor_pos_set(cur, 0);
2265    ret = evas_textblock_cursor_char_next(cur);
2266    evas_textblock_cursor_free(cur);
2267
2268    return !ret;
2269 }
2270
2271 /**
2272  * This returns all selected text within the entry.
2273  *
2274  * @param obj The entry object
2275  * @return The selected text within the entry or NULL on failure
2276  *
2277  * @ingroup Entry
2278  */
2279 EAPI const char *
2280 elm_entry_selection_get(const Evas_Object *obj)
2281 {
2282    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2283    Widget_Data *wd = elm_widget_data_get(obj);
2284    if (!wd) return NULL;
2285    return edje_object_part_text_selection_get(wd->ent, "elm.text");
2286 }
2287
2288 /**
2289  * This inserts text in @p entry where the current cursor position.
2290  *
2291  * This inserts text at the cursor position is as if it was typed
2292  * by the user (note this also allows markup which a user
2293  * can't just "type" as it would be converted to escaped text, so this
2294  * call can be used to insert things like emoticon items or bold push/pop
2295  * tags, other font and color change tags etc.)
2296  *
2297  * @param obj The entry object
2298  * @param entry The text to insert
2299  *
2300  * @ingroup Entry
2301  */
2302 EAPI void
2303 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2304 {
2305    ELM_CHECK_WIDTYPE(obj, widtype);
2306    Widget_Data *wd = elm_widget_data_get(obj);
2307    if (!wd) return;
2308    edje_object_part_text_insert(wd->ent, "elm.text", entry);
2309    wd->changed = EINA_TRUE;
2310    _sizing_eval(obj);
2311 }
2312
2313 /**
2314  * This enables word line wrapping in the entry object.  It is the opposite
2315  * of elm_entry_single_line_set().  Additionally, setting this disables
2316  * character line wrapping.
2317  *
2318  * @param obj The entry object
2319  * @param wrap If true, the entry will be wrapped once it reaches the end
2320  * of the object. Wrapping will occur at the end of the word before the end of the
2321  * object.
2322  *
2323  * @ingroup Entry
2324  */
2325 EAPI void
2326 elm_entry_line_wrap_set(Evas_Object *obj, Elm_Wrap_Type wrap)
2327 {
2328    ELM_CHECK_WIDTYPE(obj, widtype);
2329    Widget_Data *wd = elm_widget_data_get(obj);
2330    if (!wd) return;
2331    if (wd->linewrap == wrap) return;
2332    wd->lastw = -1;
2333    wd->linewrap = wrap;
2334    _theme_hook(obj);
2335 }
2336
2337 /**
2338  * This sets the editable attribute of the entry.
2339  *
2340  * @param obj The entry object
2341  * @param editable If true, the entry will be editable by the user.
2342  * If false, it will be set to the disabled state.
2343  *
2344  * @ingroup Entry
2345  */
2346 EAPI void
2347 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2348 {
2349    ELM_CHECK_WIDTYPE(obj, widtype);
2350    Widget_Data *wd = elm_widget_data_get(obj);
2351    if (!wd) return;
2352    if (wd->editable == editable) return;
2353    wd->editable = editable;
2354    _theme_hook(obj);
2355
2356 #ifdef HAVE_ELEMENTARY_X
2357    if (editable)
2358      elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2359    else
2360      elm_drop_target_del(obj);
2361 #endif
2362 }
2363
2364 /**
2365  * This gets the editable attribute of the entry.
2366  * See also elm_entry_editable_set().
2367  *
2368  * @param obj The entry object
2369  * @return If true, the entry is editable by the user.
2370  * If false, it is not editable by the user
2371  *
2372  * @ingroup Entry
2373  */
2374 EAPI Eina_Bool
2375 elm_entry_editable_get(const Evas_Object *obj)
2376 {
2377    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2378    Widget_Data *wd = elm_widget_data_get(obj);
2379    if (!wd) return EINA_FALSE;
2380    return wd->editable;
2381 }
2382
2383 /**
2384  * This drops any existing text selection within the entry.
2385  *
2386  * @param obj The entry object
2387  *
2388  * @ingroup Entry
2389  */
2390 EAPI void
2391 elm_entry_select_none(Evas_Object *obj)
2392 {
2393    ELM_CHECK_WIDTYPE(obj, widtype);
2394    Widget_Data *wd = elm_widget_data_get(obj);
2395    if (!wd) return;
2396    if (wd->selmode)
2397      {
2398         wd->selmode = EINA_FALSE;
2399         if (!_elm_config->desktop_entry)
2400           edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2401         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2402      }
2403    wd->have_selection = EINA_FALSE;
2404    edje_object_part_text_select_none(wd->ent, "elm.text");
2405 }
2406
2407 /**
2408  * This selects all text within the entry.
2409  *
2410  * @param obj The entry object
2411  *
2412  * @ingroup Entry
2413  */
2414 EAPI void
2415 elm_entry_select_all(Evas_Object *obj)
2416 {
2417    ELM_CHECK_WIDTYPE(obj, widtype);
2418    Widget_Data *wd = elm_widget_data_get(obj);
2419    if (!wd) return;
2420    if (wd->selmode)
2421      {
2422         wd->selmode = EINA_FALSE;
2423         if (!_elm_config->desktop_entry)
2424           edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2425         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2426      }
2427    wd->have_selection = EINA_TRUE;
2428    edje_object_part_text_select_all(wd->ent, "elm.text");
2429 }
2430
2431 /**
2432  * This function returns the geometry of the cursor.
2433  *
2434  * It's useful if you want to draw something on the cursor (or where it is),
2435  * or for example in the case of scrolled entry where you want to show the
2436  * cursor.
2437  *
2438  * @param obj The entry object
2439  * @param x returned geometry
2440  * @param y returned geometry
2441  * @param w returned geometry
2442  * @param h returned geometry
2443  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2444  *
2445  * @ingroup Entry
2446  */
2447 EAPI Eina_Bool
2448 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
2449 {
2450    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2451    Widget_Data *wd = elm_widget_data_get(obj);
2452    if (!wd) return EINA_FALSE;
2453    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
2454    return EINA_TRUE;
2455 }
2456
2457 /**
2458  * This moves the cursor one place to the right within the entry.
2459  *
2460  * @param obj The entry object
2461  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2462  *
2463  * @ingroup Entry
2464  */
2465 EAPI Eina_Bool
2466 elm_entry_cursor_next(Evas_Object *obj)
2467 {
2468    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2469    Widget_Data *wd = elm_widget_data_get(obj);
2470    if (!wd) return EINA_FALSE;
2471    return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2472 }
2473
2474 /**
2475  * This moves the cursor one place to the left within the entry.
2476  *
2477  * @param obj The entry object
2478  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2479  *
2480  * @ingroup Entry
2481  */
2482 EAPI Eina_Bool
2483 elm_entry_cursor_prev(Evas_Object *obj)
2484 {
2485    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2486    Widget_Data *wd = elm_widget_data_get(obj);
2487    if (!wd) return EINA_FALSE;
2488    return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2489 }
2490
2491 /**
2492  * This moves the cursor one line up within the entry.
2493  *
2494  * @param obj The entry object
2495  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2496  *
2497  * @ingroup Entry
2498  */
2499 EAPI Eina_Bool
2500 elm_entry_cursor_up(Evas_Object *obj)
2501 {
2502    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2503    Widget_Data *wd = elm_widget_data_get(obj);
2504    if (!wd) return EINA_FALSE;
2505    return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2506 }
2507
2508 /**
2509  * This moves the cursor one line down within the entry.
2510  *
2511  * @param obj The entry object
2512  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2513  *
2514  * @ingroup Entry
2515  */
2516 EAPI Eina_Bool
2517 elm_entry_cursor_down(Evas_Object *obj)
2518 {
2519    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2520    Widget_Data *wd = elm_widget_data_get(obj);
2521    if (!wd) return EINA_FALSE;
2522    return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2523 }
2524
2525 /**
2526  * This moves the cursor to the beginning of the entry.
2527  *
2528  * @param obj The entry object
2529  *
2530  * @ingroup Entry
2531  */
2532 EAPI void
2533 elm_entry_cursor_begin_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    edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2539 }
2540
2541 /**
2542  * This moves the cursor to the end of the entry.
2543  *
2544  * @param obj The entry object
2545  *
2546  * @ingroup Entry
2547  */
2548 EAPI void
2549 elm_entry_cursor_end_set(Evas_Object *obj)
2550 {
2551    ELM_CHECK_WIDTYPE(obj, widtype);
2552    Widget_Data *wd = elm_widget_data_get(obj);
2553    if (!wd) return;
2554    int x, y, w, h;
2555    edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2556    if (wd->scroll)
2557      {
2558         elm_widget_show_region_get(wd->ent, &x, &y, &w, &h);
2559         elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
2560      }
2561 }
2562
2563 /**
2564  * This moves the cursor to the beginning of the current line.
2565  *
2566  * @param obj The entry object
2567  *
2568  * @ingroup Entry
2569  */
2570 EAPI void
2571 elm_entry_cursor_line_begin_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_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2577 }
2578
2579 /**
2580  * This moves the cursor to the end of the current line.
2581  *
2582  * @param obj The entry object
2583  *
2584  * @ingroup Entry
2585  */
2586 EAPI void
2587 elm_entry_cursor_line_end_set(Evas_Object *obj)
2588 {
2589    ELM_CHECK_WIDTYPE(obj, widtype);
2590    Widget_Data *wd = elm_widget_data_get(obj);
2591    if (!wd) return;
2592    edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2593 }
2594
2595 /**
2596  * This begins a selection within the entry as though
2597  * the user were holding down the mouse button to make a selection.
2598  *
2599  * @param obj The entry object
2600  *
2601  * @ingroup Entry
2602  */
2603 EAPI void
2604 elm_entry_cursor_selection_begin(Evas_Object *obj)
2605 {
2606    ELM_CHECK_WIDTYPE(obj, widtype);
2607    Widget_Data *wd = elm_widget_data_get(obj);
2608    if (!wd) return;
2609    edje_object_part_text_select_begin(wd->ent, "elm.text");
2610 }
2611
2612 /**
2613  * This ends a selection within the entry as though
2614  * the user had just released the mouse button while making a selection.
2615  *
2616  * @param obj The entry object
2617  *
2618  * @ingroup Entry
2619  */
2620 EAPI void
2621 elm_entry_cursor_selection_end(Evas_Object *obj)
2622 {
2623    ELM_CHECK_WIDTYPE(obj, widtype);
2624    Widget_Data *wd = elm_widget_data_get(obj);
2625    if (!wd) return;
2626    edje_object_part_text_select_extend(wd->ent, "elm.text");
2627 }
2628
2629 /**
2630  * TODO: fill this in
2631  *
2632  * @param obj The entry object
2633  * @return TODO: fill this in
2634  *
2635  * @ingroup Entry
2636  */
2637 EAPI Eina_Bool
2638 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2639 {
2640    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2641    Widget_Data *wd = elm_widget_data_get(obj);
2642    if (!wd) return EINA_FALSE;
2643    return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2644 }
2645
2646 /**
2647  * This returns whether the cursor is visible.
2648  *
2649  * @param obj The entry object
2650  * @return If true, the cursor is visible.
2651  *
2652  * @ingroup Entry
2653  */
2654 EAPI Eina_Bool
2655 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2656 {
2657    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2658    Widget_Data *wd = elm_widget_data_get(obj);
2659    if (!wd) return EINA_FALSE;
2660    return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2661 }
2662
2663 /**
2664  * TODO: fill this in
2665  *
2666  * @param obj The entry object
2667  * @return TODO: fill this in
2668  *
2669  * @ingroup Entry
2670  */
2671 EAPI const char *
2672 elm_entry_cursor_content_get(const Evas_Object *obj)
2673 {
2674    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2675    Widget_Data *wd = elm_widget_data_get(obj);
2676    if (!wd) return NULL;
2677    return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2678 }
2679
2680 /**
2681  * Sets the cursor position in the entry to the given value
2682  *
2683  * @param obj The entry object
2684  * @param pos The position of the cursor
2685  *
2686  * @ingroup Entry
2687  */
2688 EAPI void
2689 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
2690 {
2691    ELM_CHECK_WIDTYPE(obj, widtype);
2692    Widget_Data *wd = elm_widget_data_get(obj);
2693    if (!wd) return;
2694    edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
2695    edje_object_message_signal_process(wd->ent);
2696 }
2697
2698 /**
2699  * Retrieves the current position of the cursor in the entry
2700  *
2701  * @param obj The entry object
2702  * @return The cursor position
2703  *
2704  * @ingroup Entry
2705  */
2706 EAPI int
2707 elm_entry_cursor_pos_get(const Evas_Object *obj)
2708 {
2709    ELM_CHECK_WIDTYPE(obj, widtype) 0;
2710    Widget_Data *wd = elm_widget_data_get(obj);
2711    if (!wd) return 0;
2712    return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2713 }
2714
2715 /**
2716  * This executes a "cut" 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_cut(Evas_Object *obj)
2724 {
2725    ELM_CHECK_WIDTYPE(obj, widtype);
2726    Widget_Data *wd = elm_widget_data_get(obj);
2727    if (!wd) return;
2728    _cut(obj, NULL, NULL);
2729 }
2730
2731 /**
2732  * This executes a "copy" action on the selected text in the entry.
2733  *
2734  * @param obj The entry object
2735  *
2736  * @ingroup Entry
2737  */
2738 EAPI void
2739 elm_entry_selection_copy(Evas_Object *obj)
2740 {
2741    ELM_CHECK_WIDTYPE(obj, widtype);
2742    Widget_Data *wd = elm_widget_data_get(obj);
2743    if (!wd) return;
2744    _copy(obj, NULL, NULL);
2745 }
2746
2747 /**
2748  * This executes a "paste" action in the entry.
2749  *
2750  * @param obj The entry object
2751  *
2752  * @ingroup Entry
2753  */
2754 EAPI void
2755 elm_entry_selection_paste(Evas_Object *obj)
2756 {
2757    ELM_CHECK_WIDTYPE(obj, widtype);
2758    Widget_Data *wd = elm_widget_data_get(obj);
2759    if (!wd) return;
2760    _paste(obj, NULL, NULL);
2761 }
2762
2763 /**
2764  * This clears and frees the items in a entry's contextual (right click) menu.
2765  *
2766  * @param obj The entry object
2767  *
2768  * @ingroup Entry
2769  */
2770 EAPI void
2771 elm_entry_context_menu_clear(Evas_Object *obj)
2772 {
2773    ELM_CHECK_WIDTYPE(obj, widtype);
2774    Widget_Data *wd = elm_widget_data_get(obj);
2775    Elm_Entry_Context_Menu_Item *it;
2776    if (!wd) return;
2777    EINA_LIST_FREE(wd->items, it)
2778      {
2779         eina_stringshare_del(it->label);
2780         eina_stringshare_del(it->icon_file);
2781         eina_stringshare_del(it->icon_group);
2782         free(it);
2783      }
2784 }
2785
2786 /**
2787  * This adds an item to the entry's contextual menu.
2788  *
2789  * @param obj The entry object
2790  * @param label The item's text label
2791  * @param icon_file The item's icon file
2792  * @param icon_type The item's icon type
2793  * @param func The callback to execute when the item is clicked
2794  * @param data The data to associate with the item for related functions
2795  *
2796  * @ingroup Entry
2797  */
2798 EAPI void
2799 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)
2800 {
2801    ELM_CHECK_WIDTYPE(obj, widtype);
2802    Widget_Data *wd = elm_widget_data_get(obj);
2803    Elm_Entry_Context_Menu_Item *it;
2804    if (!wd) return;
2805    it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2806    if (!it) return;
2807    wd->items = eina_list_append(wd->items, it);
2808    it->obj = obj;
2809    it->label = eina_stringshare_add(label);
2810    it->icon_file = eina_stringshare_add(icon_file);
2811    it->icon_type = icon_type;
2812    it->func = func;
2813    it->data = (void *)data;
2814 }
2815
2816 /**
2817  * This disables the entry's contextual (right click) menu.
2818  *
2819  * @param obj The entry object
2820  * @param disabled If true, the menu is disabled
2821  *
2822  * @ingroup Entry
2823  */
2824 EAPI void
2825 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2826 {
2827    ELM_CHECK_WIDTYPE(obj, widtype);
2828    Widget_Data *wd = elm_widget_data_get(obj);
2829    if (!wd) return;
2830    if (wd->context_menu == !disabled) return;
2831    wd->context_menu = !disabled;
2832 }
2833
2834 /**
2835  * This returns whether the entry's contextual (right click) menu is disabled.
2836  *
2837  * @param obj The entry object
2838  * @return If true, the menu is disabled
2839  *
2840  * @ingroup Entry
2841  */
2842 EAPI Eina_Bool
2843 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2844 {
2845    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2846    Widget_Data *wd = elm_widget_data_get(obj);
2847    if (!wd) return EINA_FALSE;
2848    return !wd->context_menu;
2849 }
2850
2851 /**
2852  * This appends a custom item provider to the list for that entry
2853  *
2854  * This appends the given callback. The list is walked from beginning to end
2855  * with each function called given the item href string in the text. If the
2856  * function returns an object handle other than NULL (it should create an
2857  * and object to do this), then this object is used to replace that item. If
2858  * not the next provider is called until one provides an item object, or the
2859  * default provider in entry does.
2860  *
2861  * @param obj The entry object
2862  * @param func The function called to provide the item object
2863  * @param data The data passed to @p func
2864  *
2865  * @ingroup Entry
2866  */
2867 EAPI void
2868 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2869 {
2870    ELM_CHECK_WIDTYPE(obj, widtype);
2871    Widget_Data *wd = elm_widget_data_get(obj);
2872    if (!wd) return;
2873    EINA_SAFETY_ON_NULL_RETURN(func);
2874    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2875    if (!ip) return;
2876    ip->func = func;
2877    ip->data = data;
2878    wd->item_providers = eina_list_append(wd->item_providers, ip);
2879 }
2880
2881 /**
2882  * This prepends a custom item provider to the list for that entry
2883  *
2884  * This prepends the given callback. See elm_entry_item_provider_append() for
2885  * more information
2886  *
2887  * @param obj The entry object
2888  * @param func The function called to provide the item object
2889  * @param data The data passed to @p func
2890  *
2891  * @ingroup Entry
2892  */
2893 EAPI void
2894 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2895 {
2896    ELM_CHECK_WIDTYPE(obj, widtype);
2897    Widget_Data *wd = elm_widget_data_get(obj);
2898    if (!wd) return;
2899    EINA_SAFETY_ON_NULL_RETURN(func);
2900    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2901    if (!ip) return;
2902    ip->func = func;
2903    ip->data = data;
2904    wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2905 }
2906
2907 /**
2908  * This removes a custom item provider to the list for that entry
2909  *
2910  * This removes the given callback. See elm_entry_item_provider_append() for
2911  * more information
2912  *
2913  * @param obj The entry object
2914  * @param func The function called to provide the item object
2915  * @param data The data passed to @p func
2916  *
2917  * @ingroup Entry
2918  */
2919 EAPI void
2920 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2921 {
2922    ELM_CHECK_WIDTYPE(obj, widtype);
2923    Widget_Data *wd = elm_widget_data_get(obj);
2924    Eina_List *l;
2925    Elm_Entry_Item_Provider *ip;
2926    if (!wd) return;
2927    EINA_SAFETY_ON_NULL_RETURN(func);
2928    EINA_LIST_FOREACH(wd->item_providers, l, ip)
2929      {
2930         if ((ip->func == func) && ((!data) || (ip->data == data)))
2931           {
2932              wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2933              free(ip);
2934              return;
2935           }
2936      }
2937 }
2938
2939 /**
2940  * Append a filter function for text inserted in the entry
2941  *
2942  * Append the given callback to the list. This functions will be called
2943  * whenever any text is inserted into the entry, with the text to be inserted
2944  * as a parameter. The callback function is free to alter the text in any way
2945  * it wants, but it must remember to free the given pointer and update it.
2946  * If the new text is to be discarded, the function can free it and set it text
2947  * parameter to NULL. This will also prevent any following filters from being
2948  * called.
2949  *
2950  * @param obj The entry object
2951  * @param func The function to use as text filter
2952  * @param data User data to pass to @p func
2953  *
2954  * @ingroup Entry
2955  */
2956 EAPI void
2957 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2958 {
2959    Widget_Data *wd;
2960    Elm_Entry_Text_Filter *tf;
2961    ELM_CHECK_WIDTYPE(obj, widtype);
2962
2963    wd = elm_widget_data_get(obj);
2964
2965    EINA_SAFETY_ON_NULL_RETURN(func);
2966
2967    tf = _filter_new(func, data);
2968    if (!tf) return;
2969
2970    wd->text_filters = eina_list_append(wd->text_filters, tf);
2971 }
2972
2973 /**
2974  * Prepend a filter function for text insdrted in the entry
2975  *
2976  * Prepend the given callback to the list. See elm_entry_text_filter_append()
2977  * for more information
2978  *
2979  * @param obj The entry object
2980  * @param func The function to use as text filter
2981  * @param data User data to pass to @p func
2982  *
2983  * @ingroup Entry
2984  */
2985 EAPI void
2986 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2987 {
2988    Widget_Data *wd;
2989    Elm_Entry_Text_Filter *tf;
2990    ELM_CHECK_WIDTYPE(obj, widtype);
2991
2992    wd = elm_widget_data_get(obj);
2993
2994    EINA_SAFETY_ON_NULL_RETURN(func);
2995
2996    tf = _filter_new(func, data);
2997    if (!tf) return;
2998
2999    wd->text_filters = eina_list_prepend(wd->text_filters, tf);
3000 }
3001
3002 /**
3003  * Remove a filter from the list
3004  *
3005  * Removes the given callback from the filter list. See elm_entry_text_filter_append()
3006  * for more information.
3007  *
3008  * @param obj The entry object
3009  * @param func The filter function to remove
3010  * @param data The user data passed when adding the function
3011  *
3012  * @ingroup Entry
3013  */
3014 EAPI void
3015 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3016 {
3017    Widget_Data *wd;
3018    Eina_List *l;
3019    Elm_Entry_Text_Filter *tf;
3020    ELM_CHECK_WIDTYPE(obj, widtype);
3021
3022    wd = elm_widget_data_get(obj);
3023
3024    EINA_SAFETY_ON_NULL_RETURN(func);
3025
3026    EINA_LIST_FOREACH(wd->text_filters, l, tf)
3027      {
3028         if ((tf->func == func) && ((!data) || (tf->data == data)))
3029           {
3030              wd->text_filters = eina_list_remove_list(wd->text_filters, l);
3031              _filter_free(tf);
3032              return;
3033           }
3034      }
3035 }
3036
3037 /**
3038  * This converts a markup (HTML-like) string into UTF-8.
3039  * Returning string is obtained with malloc.
3040  * After use the returned string, it should be freed.
3041  *
3042  * @param s The string (in markup) to be converted
3043  * @return The converted string (in UTF-8). It should be freed.
3044  *
3045  * @ingroup Entry
3046  */
3047 EAPI char *
3048 elm_entry_markup_to_utf8(const char *s)
3049 {
3050    char *ss = _elm_util_mkup_to_text(s);
3051    if (!ss) ss = strdup("");
3052    return ss;
3053 }
3054
3055 /**
3056  * This converts a UTF-8 string into markup (HTML-like).
3057  * Returning string is obtained with malloc.
3058  * After use the returned string, it should be freed.
3059  *
3060  * @param s The string (in UTF-8) to be converted
3061  * @return The converted string (in markup). It should be freed.
3062  *
3063  * @ingroup Entry
3064  */
3065 EAPI char *
3066 elm_entry_utf8_to_markup(const char *s)
3067 {
3068    char *ss = _elm_util_text_to_mkup(s);
3069    if (!ss) ss = strdup("");
3070    return ss;
3071 }
3072
3073 /**
3074  * Filter inserted text based on user defined character and byte limits
3075  *
3076  * Add this filter to an entry to limit the characters that it will accept
3077  * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
3078  * The funtion works on the UTF-8 representation of the string, converting
3079  * it from the set markup, thus not accounting for any format in it.
3080  *
3081  * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
3082  * it as data when setting the filter. In it it's possible to set limits
3083  * by character count or bytes (any of them is disabled if 0), and both can
3084  * be set at the same time. In that case, it first checks for characters,
3085  * then bytes.
3086  *
3087  * The function will cut the inserted text in order to allow only the first
3088  * number of characters that are still allowed. The cut is made in
3089  * characters, even when limiting by bytes, in order to always contain
3090  * valid ones and avoid half unicode characters making it in.
3091  *
3092  * @ingroup Entry
3093  */
3094 EAPI void
3095 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
3096 {
3097    Elm_Entry_Filter_Limit_Size *lim = data;
3098    char *current;
3099    int len, newlen;
3100    const char *(*text_get)(const Evas_Object *);
3101    const char *widget_type;
3102
3103    EINA_SAFETY_ON_NULL_RETURN(data);
3104    EINA_SAFETY_ON_NULL_RETURN(entry);
3105    EINA_SAFETY_ON_NULL_RETURN(text);
3106
3107    /* hack. I don't want to copy the entire function to work with
3108     * scrolled_entry */
3109    widget_type = elm_widget_type_get(entry);
3110    if (!strcmp(widget_type, "entry"))
3111      text_get = elm_entry_entry_get;
3112    else /* huh? */
3113      return;
3114
3115    current = elm_entry_markup_to_utf8(text_get(entry));
3116
3117    if (lim->max_char_count > 0)
3118      {
3119         len = evas_string_char_len_get(current);
3120         if (len >= lim->max_char_count)
3121           {
3122              evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3123              free(*text);
3124              free(current);
3125              *text = NULL;
3126              return;
3127           }
3128         newlen = evas_string_char_len_get(elm_entry_markup_to_utf8(*text));
3129         if ((len + newlen) > lim->max_char_count)
3130           _add_chars_till_limit(entry, text, (lim->max_char_count - len), LENGTH_UNIT_CHAR);
3131      }
3132    else if (lim->max_byte_count > 0)
3133      {
3134         len = strlen(current);
3135         if (len >= lim->max_byte_count)
3136           {
3137              evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3138              free(*text);
3139              free(current);
3140              *text = NULL;
3141              return;
3142           }
3143         newlen = strlen(elm_entry_markup_to_utf8(*text));
3144         if ((len + newlen) > lim->max_byte_count)
3145           _add_chars_till_limit(entry, text, (lim->max_byte_count - len), LENGTH_UNIT_BYTE);
3146      }
3147    free(current);
3148 }
3149
3150 /**
3151  * Filter inserted text based on accepted or rejected sets of characters
3152  *
3153  * Add this filter to an entry to restrict the set of accepted characters
3154  * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
3155  * This structure contains both accepted and rejected sets, but they are
3156  * mutually exclusive. If accepted is set, it will be used, otherwise it
3157  * goes on to the rejected set.
3158  */
3159 EAPI void
3160 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
3161 {
3162    Elm_Entry_Filter_Accept_Set *as = data;
3163    const char *set;
3164    char *insert;
3165    Eina_Bool goes_in;
3166    int read_idx, last_read_idx = 0, read_char;
3167
3168    EINA_SAFETY_ON_NULL_RETURN(data);
3169    EINA_SAFETY_ON_NULL_RETURN(text);
3170
3171    if ((!as->accepted) && (!as->rejected))
3172      return;
3173
3174    if (as->accepted)
3175      {
3176         set = as->accepted;
3177         goes_in = EINA_TRUE;
3178      }
3179    else
3180      {
3181         set = as->rejected;
3182         goes_in = EINA_FALSE;
3183      }
3184
3185    insert = *text;
3186    read_idx = evas_string_char_next_get(*text, 0, &read_char);
3187    while (read_char)
3188      {
3189         int cmp_idx, cmp_char;
3190         Eina_Bool in_set = EINA_FALSE;
3191
3192         cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
3193         while (cmp_char)
3194           {
3195              if (read_char == cmp_char)
3196                {
3197                   in_set = EINA_TRUE;
3198                   break;
3199                }
3200              cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
3201           }
3202         if (in_set == goes_in)
3203           {
3204              int size = read_idx - last_read_idx;
3205              const char *src = (*text) + last_read_idx;
3206              if (src != insert)
3207                memcpy(insert, *text + last_read_idx, size);
3208              insert += size;
3209           }
3210         last_read_idx = read_idx;
3211         read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
3212      }
3213    *insert = 0;
3214 }
3215
3216 /**
3217  * This sets the file (and implicitly loads it) for the text to display and
3218  * then edit. All changes are written back to the file after a short delay if
3219  * the entry object is set to autosave.
3220  *
3221  * @param obj The entry object
3222  * @param file The path to the file to load and save
3223  * @param format The file format
3224  *
3225  * @ingroup Entry
3226  */
3227 EAPI void
3228 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
3229 {
3230    ELM_CHECK_WIDTYPE(obj, widtype);
3231    Widget_Data *wd = elm_widget_data_get(obj);
3232    if (!wd) return;
3233    if (wd->delay_write)
3234      {
3235         ecore_timer_del(wd->delay_write);
3236         wd->delay_write = NULL;
3237      }
3238    if (wd->autosave) _save(obj);
3239    eina_stringshare_replace(&wd->file, file);
3240    wd->format = format;
3241    _load(obj);
3242 }
3243
3244 /**
3245  * Gets the file to load and save and the file format
3246  *
3247  * @param obj The entry object
3248  * @param file The path to the file to load and save
3249  * @param format The file format
3250  *
3251  * @ingroup Entry
3252  */
3253 EAPI void
3254 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
3255 {
3256    ELM_CHECK_WIDTYPE(obj, widtype);
3257    Widget_Data *wd = elm_widget_data_get(obj);
3258    if (!wd) return;
3259    if (file) *file = wd->file;
3260    if (format) *format = wd->format;
3261 }
3262
3263 /**
3264  * This function writes any changes made to the file set with
3265  * elm_entry_file_set()
3266  *
3267  * @param obj The entry object
3268  *
3269  * @ingroup Entry
3270  */
3271 EAPI void
3272 elm_entry_file_save(Evas_Object *obj)
3273 {
3274    ELM_CHECK_WIDTYPE(obj, widtype);
3275    Widget_Data *wd = elm_widget_data_get(obj);
3276    if (!wd) return;
3277    if (wd->delay_write)
3278      {
3279         ecore_timer_del(wd->delay_write);
3280         wd->delay_write = NULL;
3281      }
3282    _save(obj);
3283    wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
3284 }
3285
3286 /**
3287  * This sets the entry object to 'autosave' the loaded text file or not.
3288  *
3289  * @param obj The entry object
3290  * @param autosave Autosave the loaded file or not
3291  *
3292  * @ingroup Entry
3293  */
3294 EAPI void
3295 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
3296 {
3297    ELM_CHECK_WIDTYPE(obj, widtype);
3298    Widget_Data *wd = elm_widget_data_get(obj);
3299    if (!wd) return;
3300    wd->autosave = !!autosave;
3301 }
3302
3303 /**
3304  * This gets the entry object's 'autosave' status.
3305  *
3306  * @param obj The entry object
3307  * @return Autosave the loaded file or not
3308  *
3309  * @ingroup Entry
3310  */
3311 EAPI Eina_Bool
3312 elm_entry_autosave_get(const Evas_Object *obj)
3313 {
3314    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3315    Widget_Data *wd = elm_widget_data_get(obj);
3316    if (!wd) return EINA_FALSE;
3317    return wd->autosave;
3318 }
3319
3320 /**
3321  * Control pasting of text and images for the widget.
3322  *
3323  * Normally the entry allows both text and images to be pasted.  By setting
3324  * textonly to be true, this prevents images from being pasted.
3325  *
3326  * Note this only changes the behaviour of text.
3327  *
3328  * @param obj The entry object
3329  * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is text+image+other.
3330  *
3331  * @ingroup Entry
3332  */
3333 EAPI void
3334 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
3335 {
3336    Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
3337    ELM_CHECK_WIDTYPE(obj, widtype);
3338    Widget_Data *wd = elm_widget_data_get(obj);
3339    if (!wd) return;
3340    textonly = !!textonly;
3341    if (wd->textonly == textonly) return;
3342    wd->textonly = !!textonly;
3343    if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
3344 #ifdef HAVE_ELEMENTARY_X
3345    elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
3346 #endif
3347 }
3348
3349 /**
3350  * Getting elm_entry text paste/drop mode.
3351  *
3352  * In textonly mode, only text may be pasted or dropped into the widget.
3353  *
3354  * @param obj The entry object
3355  * @return If the widget only accepts text from pastes.
3356  *
3357  * @ingroup Entry
3358  */
3359 EAPI Eina_Bool
3360 elm_entry_cnp_textonly_get(const Evas_Object *obj)
3361 {
3362    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3363    Widget_Data *wd = elm_widget_data_get(obj);
3364    if (!wd) return EINA_FALSE;
3365    return wd->textonly;
3366 }
3367
3368 /**
3369  * Enable or disable scrolling in entry
3370  *
3371  * Normally the entry is not scrollable unless you enable it with this call.
3372  *
3373  * @param obj The entry object
3374  * @param scroll EINA_TRUE if it is to be scrollable, EINA_FALSE otherwise
3375  *
3376  * @ingroup Entry
3377  */
3378 EAPI void
3379 elm_entry_scrollable_set(Evas_Object *obj, Eina_Bool scroll)
3380 {
3381    ELM_CHECK_WIDTYPE(obj, widtype);
3382    Widget_Data *wd = elm_widget_data_get(obj);
3383    if (!wd) return;
3384    scroll = !!scroll;
3385    if (wd->scroll == scroll) return;
3386    wd->scroll = scroll;
3387    if (wd->scroll)
3388      {
3389         elm_widget_sub_object_del(obj, wd->scroller);
3390         elm_widget_resize_object_set(obj, wd->scroller);
3391         elm_widget_sub_object_add(obj, wd->ent);
3392         elm_smart_scroller_child_set(wd->scroller, wd->ent);
3393         evas_object_show(wd->scroller);
3394         elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
3395      }
3396    else
3397      {
3398         elm_smart_scroller_child_set(wd->scroller, NULL);
3399         elm_widget_sub_object_del(obj, wd->ent);
3400         elm_widget_resize_object_set(obj, wd->ent);
3401         evas_object_smart_member_add(wd->scroller, obj);
3402         elm_widget_sub_object_add(obj, wd->scroller);
3403         evas_object_hide(wd->scroller);
3404         elm_widget_on_show_region_hook_set(obj, NULL, NULL);
3405      }
3406    wd->lastw = -1;
3407    _theme_hook(obj);
3408 }
3409
3410 /**
3411  * Get the scrollable state of the entry
3412  *
3413  * Normally the entry is not scrollable. This gets the scrollable state
3414  * of the entry. See elm_entry_scrollable_set() for more information.
3415  *
3416  * @param obj The entry object
3417  * @return The scrollable state
3418  *
3419  * @ingroup Entry
3420  */
3421 EAPI Eina_Bool
3422 elm_entry_scrollable_get(const Evas_Object *obj)
3423 {
3424    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3425    Widget_Data *wd = elm_widget_data_get(obj);
3426    if (!wd) return EINA_FALSE;
3427    return wd->scroll;
3428 }
3429
3430 /**
3431  * This sets a widget to be displayed to the left of a scrolled entry.
3432  *
3433  * @param obj The scrolled entry object
3434  * @param icon The widget to display on the left side of the scrolled
3435  * entry.
3436  *
3437  * @note A previously set widget will be destroyed.
3438  * @note If the object being set does not have minimum size hints set,
3439  * it won't get properly displayed.
3440  *
3441  * @ingroup Entry
3442  * @see elm_entry_end_set
3443  */
3444 EAPI void
3445 elm_entry_icon_set(Evas_Object *obj, Evas_Object *icon)
3446 {
3447    ELM_CHECK_WIDTYPE(obj, widtype);
3448    Widget_Data *wd = elm_widget_data_get(obj);
3449    Evas_Object *edje;
3450    if (!wd) return;
3451    EINA_SAFETY_ON_NULL_RETURN(icon);
3452    if (wd->icon == icon) return;
3453    if (wd->icon) evas_object_del(wd->icon);
3454    wd->icon = icon;
3455    edje = elm_smart_scroller_edje_object_get(wd->scroller);
3456    if (!edje) return;
3457    edje_object_part_swallow(edje, "elm.swallow.icon", wd->icon);
3458    edje_object_signal_emit(edje, "elm,action,show,icon", "elm");
3459    _sizing_eval(obj);
3460 }
3461
3462 /**
3463  * Gets the leftmost widget of the scrolled entry. This object is
3464  * owned by the scrolled entry and should not be modified.
3465  *
3466  * @param obj The scrolled entry object
3467  * @return the left widget inside the scroller
3468  *
3469  * @ingroup Entry
3470  */
3471 EAPI Evas_Object *
3472 elm_entry_icon_get(const Evas_Object *obj)
3473 {
3474    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3475    Widget_Data *wd = elm_widget_data_get(obj);
3476    if (!wd) return NULL;
3477    return wd->icon;
3478 }
3479
3480 /**
3481  * Unset the leftmost widget of the scrolled entry, unparenting and
3482  * returning it.
3483  *
3484  * @param obj The scrolled entry object
3485  * @return the previously set icon sub-object of this entry, on
3486  * success.
3487  *
3488  * @see elm_entry_icon_set()
3489  *
3490  * @ingroup Entry
3491  */
3492 EAPI Evas_Object *
3493 elm_entry_icon_unset(Evas_Object *obj)
3494 {
3495    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3496    Widget_Data *wd = elm_widget_data_get(obj);
3497    Evas_Object *ret = NULL;
3498    if (!wd) return NULL;
3499    if (wd->icon)
3500      {
3501         Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
3502         if (!edje) return NULL;
3503         ret = wd->icon;
3504         edje_object_part_unswallow(edje, wd->icon);
3505         edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
3506         wd->icon = NULL;
3507         _sizing_eval(obj);
3508      }
3509    return ret;
3510 }
3511
3512 /**
3513  * Sets the visibility of the left-side widget of the scrolled entry,
3514  * set by @elm_entry_icon_set().
3515  *
3516  * @param obj The scrolled entry object
3517  * @param setting EINA_TRUE if the object should be displayed,
3518  * EINA_FALSE if not.
3519  *
3520  * @ingroup Entry
3521  */
3522 EAPI void
3523 elm_entry_icon_visible_set(Evas_Object *obj, Eina_Bool setting)
3524 {
3525    ELM_CHECK_WIDTYPE(obj, widtype);
3526    Widget_Data *wd = elm_widget_data_get(obj);
3527    if ((!wd) || (!wd->icon)) return;
3528    if (setting)
3529       evas_object_hide(wd->icon);
3530    else
3531       evas_object_show(wd->icon);
3532    _sizing_eval(obj);
3533 }
3534
3535 /**
3536  * This sets a widget to be displayed to the end of a scrolled entry.
3537  *
3538  * @param obj The scrolled entry object
3539  * @param end The widget to display on the right side of the scrolled
3540  * entry.
3541  *
3542  * @note A previously set widget will be destroyed.
3543  * @note If the object being set does not have minimum size hints set,
3544  * it won't get properly displayed.
3545  *
3546  * @ingroup Entry
3547  * @see elm_entry_icon_set
3548  */
3549 EAPI void
3550 elm_entry_end_set(Evas_Object *obj, Evas_Object *end)
3551 {
3552    ELM_CHECK_WIDTYPE(obj, widtype);
3553    Widget_Data *wd = elm_widget_data_get(obj);
3554    Evas_Object *edje;
3555    if (!wd) return;
3556    EINA_SAFETY_ON_NULL_RETURN(end);
3557    if (wd->end == end) return;
3558    if (wd->end) evas_object_del(wd->end);
3559    wd->end = end;
3560    edje = elm_smart_scroller_edje_object_get(wd->scroller);
3561    if (!edje) return;
3562    edje_object_part_swallow(edje, "elm.swallow.end", wd->end);
3563    edje_object_signal_emit(edje, "elm,action,show,end", "elm");
3564    _sizing_eval(obj);
3565 }
3566
3567 /**
3568  * Gets the endmost widget of the scrolled entry. This object is owned
3569  * by the scrolled entry and should not be modified.
3570  *
3571  * @param obj The scrolled entry object
3572  * @return the right widget inside the scroller
3573  *
3574  * @ingroup Entry
3575  */
3576 EAPI Evas_Object *
3577 elm_entry_end_get(const Evas_Object *obj)
3578 {
3579    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3580    Widget_Data *wd = elm_widget_data_get(obj);
3581    if (!wd) return NULL;
3582    return wd->end;
3583 }
3584
3585 /**
3586  * Unset the endmost widget of the scrolled entry, unparenting and
3587  * returning it.
3588  *
3589  * @param obj The scrolled entry object
3590  * @return the previously set icon sub-object of this entry, on
3591  * success.
3592  *
3593  * @see elm_entry_icon_set()
3594  *
3595  * @ingroup Entry
3596  */
3597 EAPI Evas_Object *
3598 elm_entry_end_unset(Evas_Object *obj)
3599 {
3600    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3601    Widget_Data *wd = elm_widget_data_get(obj);
3602    Evas_Object *ret = NULL;
3603    if (!wd) return NULL;
3604    if (wd->end)
3605      {
3606         Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
3607         if (!edje) return NULL;
3608         ret = wd->end;
3609         edje_object_part_unswallow(edje, wd->end);
3610         edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
3611         wd->end = NULL;
3612         _sizing_eval(obj);
3613      }
3614    return ret;
3615 }
3616
3617 /**
3618  * Sets the visibility of the end widget of the scrolled entry, set by
3619  * @elm_entry_end_set().
3620  *
3621  * @param obj The scrolled entry object
3622  * @param setting EINA_TRUE if the object should be displayed,
3623  * EINA_FALSE if not.
3624  *
3625  * @ingroup Entry
3626  */
3627 EAPI void
3628 elm_entry_end_visible_set(Evas_Object *obj, Eina_Bool setting)
3629 {
3630    ELM_CHECK_WIDTYPE(obj, widtype);
3631    Widget_Data *wd = elm_widget_data_get(obj);
3632    if ((!wd) || (!wd->end)) return;
3633    if (setting)
3634       evas_object_hide(wd->end);
3635    else
3636       evas_object_show(wd->end);
3637    _sizing_eval(obj);
3638 }
3639
3640 /**
3641  * This sets the scrolled entry's scrollbar policy (ie. enabling/disabling them).
3642  *
3643  * @param obj The scrolled entry object
3644  * @param h The horizontal scrollbar policy to apply
3645  * @param v The vertical scrollbar policy to apply
3646  *
3647  * @ingroup Entry
3648  */
3649 EAPI void
3650 elm_entry_scrollbar_policy_set(Evas_Object *obj, Elm_Scroller_Policy h, Elm_Scroller_Policy v)
3651 {
3652    ELM_CHECK_WIDTYPE(obj, widtype);
3653    Widget_Data *wd = elm_widget_data_get(obj);
3654    const Elm_Scroller_Policy map[3] =
3655      {
3656         ELM_SMART_SCROLLER_POLICY_AUTO,
3657         ELM_SMART_SCROLLER_POLICY_ON,
3658         ELM_SMART_SCROLLER_POLICY_OFF
3659      };
3660    if (!wd) return;
3661    wd->policy_h = h;
3662    wd->policy_v = v;
3663    elm_smart_scroller_policy_set(wd->scroller,
3664                                  map[wd->policy_h],
3665                                  map[wd->policy_v]);
3666 }
3667
3668 /**
3669  * This enables/disables bouncing within the entry.
3670  *
3671  * @param obj The scrolled entry object
3672  * @param h The horizontal bounce state
3673  * @param v The vertical bounce state
3674  *
3675  * @ingroup Entry
3676  */
3677 EAPI void
3678 elm_entry_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
3679 {
3680    ELM_CHECK_WIDTYPE(obj, widtype);
3681    Widget_Data *wd = elm_widget_data_get(obj);
3682    if (!wd) return;
3683    elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
3684 }
3685
3686 /**
3687  * Get the bounce mode
3688  *
3689  * @param obj The Entry object
3690  * @param h_bounce Allow bounce horizontally
3691  * @param v_bounce Allow bounce vertically
3692  *
3693  * @ingroup Entry
3694  */
3695 EAPI void
3696 elm_entry_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
3697 {
3698    ELM_CHECK_WIDTYPE(obj, widtype);
3699    Widget_Data *wd = elm_widget_data_get(obj);
3700    if (!wd) return;
3701    elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
3702 }