elementary: add elm_entry_line_wrap_get
[framework/uifw/elementary.git] / src / lib / elm_entry.c
1 #include <Elementary.h>
2 #include <Elementary_Cursor.h>
3 #include "elm_priv.h"
4
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 && strcmp(item, "default")) 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 && strcmp(item, "default")) 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  * Get the wrapping behavior of the entry.
2339  * See also elm_entry_line_wrap_set().
2340  *
2341  * @param obj The entry object
2342  * @return Wrap type
2343  *
2344  * @ingroup Entry
2345  */
2346 EAPI Elm_Wrap_Type
2347 elm_entry_line_wrap_get(const Evas_Object *obj)
2348 {
2349    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2350    Widget_Data *wd = elm_widget_data_get(obj);
2351    if (!wd) return EINA_FALSE;
2352    return wd->linewrap;
2353 }
2354
2355 /**
2356  * This sets the editable attribute of the entry.
2357  *
2358  * @param obj The entry object
2359  * @param editable If true, the entry will be editable by the user.
2360  * If false, it will be set to the disabled state.
2361  *
2362  * @ingroup Entry
2363  */
2364 EAPI void
2365 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2366 {
2367    ELM_CHECK_WIDTYPE(obj, widtype);
2368    Widget_Data *wd = elm_widget_data_get(obj);
2369    if (!wd) return;
2370    if (wd->editable == editable) return;
2371    wd->editable = editable;
2372    _theme_hook(obj);
2373
2374 #ifdef HAVE_ELEMENTARY_X
2375    if (editable)
2376      elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2377    else
2378      elm_drop_target_del(obj);
2379 #endif
2380 }
2381
2382 /**
2383  * This gets the editable attribute of the entry.
2384  * See also elm_entry_editable_set().
2385  *
2386  * @param obj The entry object
2387  * @return If true, the entry is editable by the user.
2388  * If false, it is not editable by the user
2389  *
2390  * @ingroup Entry
2391  */
2392 EAPI Eina_Bool
2393 elm_entry_editable_get(const Evas_Object *obj)
2394 {
2395    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2396    Widget_Data *wd = elm_widget_data_get(obj);
2397    if (!wd) return EINA_FALSE;
2398    return wd->editable;
2399 }
2400
2401 /**
2402  * This drops any existing text selection within the entry.
2403  *
2404  * @param obj The entry object
2405  *
2406  * @ingroup Entry
2407  */
2408 EAPI void
2409 elm_entry_select_none(Evas_Object *obj)
2410 {
2411    ELM_CHECK_WIDTYPE(obj, widtype);
2412    Widget_Data *wd = elm_widget_data_get(obj);
2413    if (!wd) return;
2414    if (wd->selmode)
2415      {
2416         wd->selmode = EINA_FALSE;
2417         if (!_elm_config->desktop_entry)
2418           edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2419         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2420      }
2421    wd->have_selection = EINA_FALSE;
2422    edje_object_part_text_select_none(wd->ent, "elm.text");
2423 }
2424
2425 /**
2426  * This selects all text within the entry.
2427  *
2428  * @param obj The entry object
2429  *
2430  * @ingroup Entry
2431  */
2432 EAPI void
2433 elm_entry_select_all(Evas_Object *obj)
2434 {
2435    ELM_CHECK_WIDTYPE(obj, widtype);
2436    Widget_Data *wd = elm_widget_data_get(obj);
2437    if (!wd) return;
2438    if (wd->selmode)
2439      {
2440         wd->selmode = EINA_FALSE;
2441         if (!_elm_config->desktop_entry)
2442           edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2443         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2444      }
2445    wd->have_selection = EINA_TRUE;
2446    edje_object_part_text_select_all(wd->ent, "elm.text");
2447 }
2448
2449 /**
2450  * This function returns the geometry of the cursor.
2451  *
2452  * It's useful if you want to draw something on the cursor (or where it is),
2453  * or for example in the case of scrolled entry where you want to show the
2454  * cursor.
2455  *
2456  * @param obj The entry object
2457  * @param x returned geometry
2458  * @param y returned geometry
2459  * @param w returned geometry
2460  * @param h returned geometry
2461  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2462  *
2463  * @ingroup Entry
2464  */
2465 EAPI Eina_Bool
2466 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
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    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
2472    return EINA_TRUE;
2473 }
2474
2475 /**
2476  * This moves the cursor one place to the right within the entry.
2477  *
2478  * @param obj The entry object
2479  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2480  *
2481  * @ingroup Entry
2482  */
2483 EAPI Eina_Bool
2484 elm_entry_cursor_next(Evas_Object *obj)
2485 {
2486    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2487    Widget_Data *wd = elm_widget_data_get(obj);
2488    if (!wd) return EINA_FALSE;
2489    return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2490 }
2491
2492 /**
2493  * This moves the cursor one place to the left within the entry.
2494  *
2495  * @param obj The entry object
2496  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2497  *
2498  * @ingroup Entry
2499  */
2500 EAPI Eina_Bool
2501 elm_entry_cursor_prev(Evas_Object *obj)
2502 {
2503    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2504    Widget_Data *wd = elm_widget_data_get(obj);
2505    if (!wd) return EINA_FALSE;
2506    return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2507 }
2508
2509 /**
2510  * This moves the cursor one line up within the entry.
2511  *
2512  * @param obj The entry object
2513  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2514  *
2515  * @ingroup Entry
2516  */
2517 EAPI Eina_Bool
2518 elm_entry_cursor_up(Evas_Object *obj)
2519 {
2520    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2521    Widget_Data *wd = elm_widget_data_get(obj);
2522    if (!wd) return EINA_FALSE;
2523    return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2524 }
2525
2526 /**
2527  * This moves the cursor one line down within the entry.
2528  *
2529  * @param obj The entry object
2530  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2531  *
2532  * @ingroup Entry
2533  */
2534 EAPI Eina_Bool
2535 elm_entry_cursor_down(Evas_Object *obj)
2536 {
2537    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2538    Widget_Data *wd = elm_widget_data_get(obj);
2539    if (!wd) return EINA_FALSE;
2540    return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2541 }
2542
2543 /**
2544  * This moves the cursor to the beginning of the entry.
2545  *
2546  * @param obj The entry object
2547  *
2548  * @ingroup Entry
2549  */
2550 EAPI void
2551 elm_entry_cursor_begin_set(Evas_Object *obj)
2552 {
2553    ELM_CHECK_WIDTYPE(obj, widtype);
2554    Widget_Data *wd = elm_widget_data_get(obj);
2555    if (!wd) return;
2556    edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2557 }
2558
2559 /**
2560  * This moves the cursor to the end of the entry.
2561  *
2562  * @param obj The entry object
2563  *
2564  * @ingroup Entry
2565  */
2566 EAPI void
2567 elm_entry_cursor_end_set(Evas_Object *obj)
2568 {
2569    ELM_CHECK_WIDTYPE(obj, widtype);
2570    Widget_Data *wd = elm_widget_data_get(obj);
2571    if (!wd) return;
2572    int x, y, w, h;
2573    edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2574    if (wd->scroll)
2575      {
2576         elm_widget_show_region_get(wd->ent, &x, &y, &w, &h);
2577         elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
2578      }
2579 }
2580
2581 /**
2582  * This moves the cursor to the beginning of the current line.
2583  *
2584  * @param obj The entry object
2585  *
2586  * @ingroup Entry
2587  */
2588 EAPI void
2589 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2590 {
2591    ELM_CHECK_WIDTYPE(obj, widtype);
2592    Widget_Data *wd = elm_widget_data_get(obj);
2593    if (!wd) return;
2594    edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2595 }
2596
2597 /**
2598  * This moves the cursor to the end of the current line.
2599  *
2600  * @param obj The entry object
2601  *
2602  * @ingroup Entry
2603  */
2604 EAPI void
2605 elm_entry_cursor_line_end_set(Evas_Object *obj)
2606 {
2607    ELM_CHECK_WIDTYPE(obj, widtype);
2608    Widget_Data *wd = elm_widget_data_get(obj);
2609    if (!wd) return;
2610    edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2611 }
2612
2613 /**
2614  * This begins a selection within the entry as though
2615  * the user were holding down the mouse button to make a selection.
2616  *
2617  * @param obj The entry object
2618  *
2619  * @ingroup Entry
2620  */
2621 EAPI void
2622 elm_entry_cursor_selection_begin(Evas_Object *obj)
2623 {
2624    ELM_CHECK_WIDTYPE(obj, widtype);
2625    Widget_Data *wd = elm_widget_data_get(obj);
2626    if (!wd) return;
2627    edje_object_part_text_select_begin(wd->ent, "elm.text");
2628 }
2629
2630 /**
2631  * This ends a selection within the entry as though
2632  * the user had just released the mouse button while making a selection.
2633  *
2634  * @param obj The entry object
2635  *
2636  * @ingroup Entry
2637  */
2638 EAPI void
2639 elm_entry_cursor_selection_end(Evas_Object *obj)
2640 {
2641    ELM_CHECK_WIDTYPE(obj, widtype);
2642    Widget_Data *wd = elm_widget_data_get(obj);
2643    if (!wd) return;
2644    edje_object_part_text_select_extend(wd->ent, "elm.text");
2645 }
2646
2647 /**
2648  * TODO: fill this in
2649  *
2650  * @param obj The entry object
2651  * @return TODO: fill this in
2652  *
2653  * @ingroup Entry
2654  */
2655 EAPI Eina_Bool
2656 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2657 {
2658    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2659    Widget_Data *wd = elm_widget_data_get(obj);
2660    if (!wd) return EINA_FALSE;
2661    return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2662 }
2663
2664 /**
2665  * This returns whether the cursor is visible.
2666  *
2667  * @param obj The entry object
2668  * @return If true, the cursor is visible.
2669  *
2670  * @ingroup Entry
2671  */
2672 EAPI Eina_Bool
2673 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2674 {
2675    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2676    Widget_Data *wd = elm_widget_data_get(obj);
2677    if (!wd) return EINA_FALSE;
2678    return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2679 }
2680
2681 /**
2682  * TODO: fill this in
2683  *
2684  * @param obj The entry object
2685  * @return TODO: fill this in
2686  *
2687  * @ingroup Entry
2688  */
2689 EAPI const char *
2690 elm_entry_cursor_content_get(const Evas_Object *obj)
2691 {
2692    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2693    Widget_Data *wd = elm_widget_data_get(obj);
2694    if (!wd) return NULL;
2695    return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2696 }
2697
2698 /**
2699  * Sets the cursor position in the entry to the given value
2700  *
2701  * @param obj The entry object
2702  * @param pos The position of the cursor
2703  *
2704  * @ingroup Entry
2705  */
2706 EAPI void
2707 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
2708 {
2709    ELM_CHECK_WIDTYPE(obj, widtype);
2710    Widget_Data *wd = elm_widget_data_get(obj);
2711    if (!wd) return;
2712    edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
2713    edje_object_message_signal_process(wd->ent);
2714 }
2715
2716 /**
2717  * Retrieves the current position of the cursor in the entry
2718  *
2719  * @param obj The entry object
2720  * @return The cursor position
2721  *
2722  * @ingroup Entry
2723  */
2724 EAPI int
2725 elm_entry_cursor_pos_get(const Evas_Object *obj)
2726 {
2727    ELM_CHECK_WIDTYPE(obj, widtype) 0;
2728    Widget_Data *wd = elm_widget_data_get(obj);
2729    if (!wd) return 0;
2730    return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2731 }
2732
2733 /**
2734  * This executes a "cut" action on the selected text in the entry.
2735  *
2736  * @param obj The entry object
2737  *
2738  * @ingroup Entry
2739  */
2740 EAPI void
2741 elm_entry_selection_cut(Evas_Object *obj)
2742 {
2743    ELM_CHECK_WIDTYPE(obj, widtype);
2744    Widget_Data *wd = elm_widget_data_get(obj);
2745    if (!wd) return;
2746    _cut(obj, NULL, NULL);
2747 }
2748
2749 /**
2750  * This executes a "copy" action on the selected text in the entry.
2751  *
2752  * @param obj The entry object
2753  *
2754  * @ingroup Entry
2755  */
2756 EAPI void
2757 elm_entry_selection_copy(Evas_Object *obj)
2758 {
2759    ELM_CHECK_WIDTYPE(obj, widtype);
2760    Widget_Data *wd = elm_widget_data_get(obj);
2761    if (!wd) return;
2762    _copy(obj, NULL, NULL);
2763 }
2764
2765 /**
2766  * This executes a "paste" action in the entry.
2767  *
2768  * @param obj The entry object
2769  *
2770  * @ingroup Entry
2771  */
2772 EAPI void
2773 elm_entry_selection_paste(Evas_Object *obj)
2774 {
2775    ELM_CHECK_WIDTYPE(obj, widtype);
2776    Widget_Data *wd = elm_widget_data_get(obj);
2777    if (!wd) return;
2778    _paste(obj, NULL, NULL);
2779 }
2780
2781 /**
2782  * This clears and frees the items in a entry's contextual (right click) menu.
2783  *
2784  * @param obj The entry object
2785  *
2786  * @ingroup Entry
2787  */
2788 EAPI void
2789 elm_entry_context_menu_clear(Evas_Object *obj)
2790 {
2791    ELM_CHECK_WIDTYPE(obj, widtype);
2792    Widget_Data *wd = elm_widget_data_get(obj);
2793    Elm_Entry_Context_Menu_Item *it;
2794    if (!wd) return;
2795    EINA_LIST_FREE(wd->items, it)
2796      {
2797         eina_stringshare_del(it->label);
2798         eina_stringshare_del(it->icon_file);
2799         eina_stringshare_del(it->icon_group);
2800         free(it);
2801      }
2802 }
2803
2804 /**
2805  * This adds an item to the entry's contextual menu.
2806  *
2807  * @param obj The entry object
2808  * @param label The item's text label
2809  * @param icon_file The item's icon file
2810  * @param icon_type The item's icon type
2811  * @param func The callback to execute when the item is clicked
2812  * @param data The data to associate with the item for related functions
2813  *
2814  * @ingroup Entry
2815  */
2816 EAPI void
2817 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)
2818 {
2819    ELM_CHECK_WIDTYPE(obj, widtype);
2820    Widget_Data *wd = elm_widget_data_get(obj);
2821    Elm_Entry_Context_Menu_Item *it;
2822    if (!wd) return;
2823    it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2824    if (!it) return;
2825    wd->items = eina_list_append(wd->items, it);
2826    it->obj = obj;
2827    it->label = eina_stringshare_add(label);
2828    it->icon_file = eina_stringshare_add(icon_file);
2829    it->icon_type = icon_type;
2830    it->func = func;
2831    it->data = (void *)data;
2832 }
2833
2834 /**
2835  * This disables the entry's contextual (right click) menu.
2836  *
2837  * @param obj The entry object
2838  * @param disabled If true, the menu is disabled
2839  *
2840  * @ingroup Entry
2841  */
2842 EAPI void
2843 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2844 {
2845    ELM_CHECK_WIDTYPE(obj, widtype);
2846    Widget_Data *wd = elm_widget_data_get(obj);
2847    if (!wd) return;
2848    if (wd->context_menu == !disabled) return;
2849    wd->context_menu = !disabled;
2850 }
2851
2852 /**
2853  * This returns whether the entry's contextual (right click) menu is disabled.
2854  *
2855  * @param obj The entry object
2856  * @return If true, the menu is disabled
2857  *
2858  * @ingroup Entry
2859  */
2860 EAPI Eina_Bool
2861 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2862 {
2863    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2864    Widget_Data *wd = elm_widget_data_get(obj);
2865    if (!wd) return EINA_FALSE;
2866    return !wd->context_menu;
2867 }
2868
2869 /**
2870  * This appends a custom item provider to the list for that entry
2871  *
2872  * This appends the given callback. The list is walked from beginning to end
2873  * with each function called given the item href string in the text. If the
2874  * function returns an object handle other than NULL (it should create an
2875  * and object to do this), then this object is used to replace that item. If
2876  * not the next provider is called until one provides an item object, or the
2877  * default provider in entry does.
2878  *
2879  * @param obj The entry object
2880  * @param func The function called to provide the item object
2881  * @param data The data passed to @p func
2882  *
2883  * @ingroup Entry
2884  */
2885 EAPI void
2886 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2887 {
2888    ELM_CHECK_WIDTYPE(obj, widtype);
2889    Widget_Data *wd = elm_widget_data_get(obj);
2890    if (!wd) return;
2891    EINA_SAFETY_ON_NULL_RETURN(func);
2892    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2893    if (!ip) return;
2894    ip->func = func;
2895    ip->data = data;
2896    wd->item_providers = eina_list_append(wd->item_providers, ip);
2897 }
2898
2899 /**
2900  * This prepends a custom item provider to the list for that entry
2901  *
2902  * This prepends the given callback. See elm_entry_item_provider_append() for
2903  * more information
2904  *
2905  * @param obj The entry object
2906  * @param func The function called to provide the item object
2907  * @param data The data passed to @p func
2908  *
2909  * @ingroup Entry
2910  */
2911 EAPI void
2912 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2913 {
2914    ELM_CHECK_WIDTYPE(obj, widtype);
2915    Widget_Data *wd = elm_widget_data_get(obj);
2916    if (!wd) return;
2917    EINA_SAFETY_ON_NULL_RETURN(func);
2918    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2919    if (!ip) return;
2920    ip->func = func;
2921    ip->data = data;
2922    wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2923 }
2924
2925 /**
2926  * This removes a custom item provider to the list for that entry
2927  *
2928  * This removes the given callback. See elm_entry_item_provider_append() for
2929  * more information
2930  *
2931  * @param obj The entry object
2932  * @param func The function called to provide the item object
2933  * @param data The data passed to @p func
2934  *
2935  * @ingroup Entry
2936  */
2937 EAPI void
2938 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2939 {
2940    ELM_CHECK_WIDTYPE(obj, widtype);
2941    Widget_Data *wd = elm_widget_data_get(obj);
2942    Eina_List *l;
2943    Elm_Entry_Item_Provider *ip;
2944    if (!wd) return;
2945    EINA_SAFETY_ON_NULL_RETURN(func);
2946    EINA_LIST_FOREACH(wd->item_providers, l, ip)
2947      {
2948         if ((ip->func == func) && ((!data) || (ip->data == data)))
2949           {
2950              wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2951              free(ip);
2952              return;
2953           }
2954      }
2955 }
2956
2957 /**
2958  * Append a filter function for text inserted in the entry
2959  *
2960  * Append the given callback to the list. This functions will be called
2961  * whenever any text is inserted into the entry, with the text to be inserted
2962  * as a parameter. The callback function is free to alter the text in any way
2963  * it wants, but it must remember to free the given pointer and update it.
2964  * If the new text is to be discarded, the function can free it and set it text
2965  * parameter to NULL. This will also prevent any following filters from being
2966  * called.
2967  *
2968  * @param obj The entry object
2969  * @param func The function to use as text filter
2970  * @param data User data to pass to @p func
2971  *
2972  * @ingroup Entry
2973  */
2974 EAPI void
2975 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2976 {
2977    Widget_Data *wd;
2978    Elm_Entry_Text_Filter *tf;
2979    ELM_CHECK_WIDTYPE(obj, widtype);
2980
2981    wd = elm_widget_data_get(obj);
2982
2983    EINA_SAFETY_ON_NULL_RETURN(func);
2984
2985    tf = _filter_new(func, data);
2986    if (!tf) return;
2987
2988    wd->text_filters = eina_list_append(wd->text_filters, tf);
2989 }
2990
2991 /**
2992  * Prepend a filter function for text insdrted in the entry
2993  *
2994  * Prepend the given callback to the list. See elm_entry_text_filter_append()
2995  * for more information
2996  *
2997  * @param obj The entry object
2998  * @param func The function to use as text filter
2999  * @param data User data to pass to @p func
3000  *
3001  * @ingroup Entry
3002  */
3003 EAPI void
3004 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3005 {
3006    Widget_Data *wd;
3007    Elm_Entry_Text_Filter *tf;
3008    ELM_CHECK_WIDTYPE(obj, widtype);
3009
3010    wd = elm_widget_data_get(obj);
3011
3012    EINA_SAFETY_ON_NULL_RETURN(func);
3013
3014    tf = _filter_new(func, data);
3015    if (!tf) return;
3016
3017    wd->text_filters = eina_list_prepend(wd->text_filters, tf);
3018 }
3019
3020 /**
3021  * Remove a filter from the list
3022  *
3023  * Removes the given callback from the filter list. See elm_entry_text_filter_append()
3024  * for more information.
3025  *
3026  * @param obj The entry object
3027  * @param func The filter function to remove
3028  * @param data The user data passed when adding the function
3029  *
3030  * @ingroup Entry
3031  */
3032 EAPI void
3033 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3034 {
3035    Widget_Data *wd;
3036    Eina_List *l;
3037    Elm_Entry_Text_Filter *tf;
3038    ELM_CHECK_WIDTYPE(obj, widtype);
3039
3040    wd = elm_widget_data_get(obj);
3041
3042    EINA_SAFETY_ON_NULL_RETURN(func);
3043
3044    EINA_LIST_FOREACH(wd->text_filters, l, tf)
3045      {
3046         if ((tf->func == func) && ((!data) || (tf->data == data)))
3047           {
3048              wd->text_filters = eina_list_remove_list(wd->text_filters, l);
3049              _filter_free(tf);
3050              return;
3051           }
3052      }
3053 }
3054
3055 /**
3056  * This converts a markup (HTML-like) string into UTF-8.
3057  * Returning string is obtained with malloc.
3058  * After use the returned string, it should be freed.
3059  *
3060  * @param s The string (in markup) to be converted
3061  * @return The converted string (in UTF-8). It should be freed.
3062  *
3063  * @ingroup Entry
3064  */
3065 EAPI char *
3066 elm_entry_markup_to_utf8(const char *s)
3067 {
3068    char *ss = _elm_util_mkup_to_text(s);
3069    if (!ss) ss = strdup("");
3070    return ss;
3071 }
3072
3073 /**
3074  * This converts a UTF-8 string into markup (HTML-like).
3075  * Returning string is obtained with malloc.
3076  * After use the returned string, it should be freed.
3077  *
3078  * @param s The string (in UTF-8) to be converted
3079  * @return The converted string (in markup). It should be freed.
3080  *
3081  * @ingroup Entry
3082  */
3083 EAPI char *
3084 elm_entry_utf8_to_markup(const char *s)
3085 {
3086    char *ss = _elm_util_text_to_mkup(s);
3087    if (!ss) ss = strdup("");
3088    return ss;
3089 }
3090
3091 /**
3092  * Filter inserted text based on user defined character and byte limits
3093  *
3094  * Add this filter to an entry to limit the characters that it will accept
3095  * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
3096  * The funtion works on the UTF-8 representation of the string, converting
3097  * it from the set markup, thus not accounting for any format in it.
3098  *
3099  * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
3100  * it as data when setting the filter. In it it's possible to set limits
3101  * by character count or bytes (any of them is disabled if 0), and both can
3102  * be set at the same time. In that case, it first checks for characters,
3103  * then bytes.
3104  *
3105  * The function will cut the inserted text in order to allow only the first
3106  * number of characters that are still allowed. The cut is made in
3107  * characters, even when limiting by bytes, in order to always contain
3108  * valid ones and avoid half unicode characters making it in.
3109  *
3110  * @ingroup Entry
3111  */
3112 EAPI void
3113 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
3114 {
3115    Elm_Entry_Filter_Limit_Size *lim = data;
3116    char *current;
3117    int len, newlen;
3118    const char *(*text_get)(const Evas_Object *);
3119    const char *widget_type;
3120
3121    EINA_SAFETY_ON_NULL_RETURN(data);
3122    EINA_SAFETY_ON_NULL_RETURN(entry);
3123    EINA_SAFETY_ON_NULL_RETURN(text);
3124
3125    /* hack. I don't want to copy the entire function to work with
3126     * scrolled_entry */
3127    widget_type = elm_widget_type_get(entry);
3128    if (!strcmp(widget_type, "entry"))
3129      text_get = elm_entry_entry_get;
3130    else /* huh? */
3131      return;
3132
3133    current = elm_entry_markup_to_utf8(text_get(entry));
3134
3135    if (lim->max_char_count > 0)
3136      {
3137         len = evas_string_char_len_get(current);
3138         if (len >= lim->max_char_count)
3139           {
3140              evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3141              free(*text);
3142              free(current);
3143              *text = NULL;
3144              return;
3145           }
3146         newlen = evas_string_char_len_get(elm_entry_markup_to_utf8(*text));
3147         if ((len + newlen) > lim->max_char_count)
3148           _add_chars_till_limit(entry, text, (lim->max_char_count - len), LENGTH_UNIT_CHAR);
3149      }
3150    else if (lim->max_byte_count > 0)
3151      {
3152         len = strlen(current);
3153         if (len >= lim->max_byte_count)
3154           {
3155              evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3156              free(*text);
3157              free(current);
3158              *text = NULL;
3159              return;
3160           }
3161         newlen = strlen(elm_entry_markup_to_utf8(*text));
3162         if ((len + newlen) > lim->max_byte_count)
3163           _add_chars_till_limit(entry, text, (lim->max_byte_count - len), LENGTH_UNIT_BYTE);
3164      }
3165    free(current);
3166 }
3167
3168 /**
3169  * Filter inserted text based on accepted or rejected sets of characters
3170  *
3171  * Add this filter to an entry to restrict the set of accepted characters
3172  * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
3173  * This structure contains both accepted and rejected sets, but they are
3174  * mutually exclusive. If accepted is set, it will be used, otherwise it
3175  * goes on to the rejected set.
3176  */
3177 EAPI void
3178 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
3179 {
3180    Elm_Entry_Filter_Accept_Set *as = data;
3181    const char *set;
3182    char *insert;
3183    Eina_Bool goes_in;
3184    int read_idx, last_read_idx = 0, read_char;
3185
3186    EINA_SAFETY_ON_NULL_RETURN(data);
3187    EINA_SAFETY_ON_NULL_RETURN(text);
3188
3189    if ((!as->accepted) && (!as->rejected))
3190      return;
3191
3192    if (as->accepted)
3193      {
3194         set = as->accepted;
3195         goes_in = EINA_TRUE;
3196      }
3197    else
3198      {
3199         set = as->rejected;
3200         goes_in = EINA_FALSE;
3201      }
3202
3203    insert = *text;
3204    read_idx = evas_string_char_next_get(*text, 0, &read_char);
3205    while (read_char)
3206      {
3207         int cmp_idx, cmp_char;
3208         Eina_Bool in_set = EINA_FALSE;
3209
3210         cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
3211         while (cmp_char)
3212           {
3213              if (read_char == cmp_char)
3214                {
3215                   in_set = EINA_TRUE;
3216                   break;
3217                }
3218              cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
3219           }
3220         if (in_set == goes_in)
3221           {
3222              int size = read_idx - last_read_idx;
3223              const char *src = (*text) + last_read_idx;
3224              if (src != insert)
3225                memcpy(insert, *text + last_read_idx, size);
3226              insert += size;
3227           }
3228         last_read_idx = read_idx;
3229         read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
3230      }
3231    *insert = 0;
3232 }
3233
3234 /**
3235  * This sets the file (and implicitly loads it) for the text to display and
3236  * then edit. All changes are written back to the file after a short delay if
3237  * the entry object is set to autosave.
3238  *
3239  * @param obj The entry object
3240  * @param file The path to the file to load and save
3241  * @param format The file format
3242  *
3243  * @ingroup Entry
3244  */
3245 EAPI void
3246 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
3247 {
3248    ELM_CHECK_WIDTYPE(obj, widtype);
3249    Widget_Data *wd = elm_widget_data_get(obj);
3250    if (!wd) return;
3251    if (wd->delay_write)
3252      {
3253         ecore_timer_del(wd->delay_write);
3254         wd->delay_write = NULL;
3255      }
3256    if (wd->autosave) _save(obj);
3257    eina_stringshare_replace(&wd->file, file);
3258    wd->format = format;
3259    _load(obj);
3260 }
3261
3262 /**
3263  * Gets the file to load and save and the file format
3264  *
3265  * @param obj The entry object
3266  * @param file The path to the file to load and save
3267  * @param format The file format
3268  *
3269  * @ingroup Entry
3270  */
3271 EAPI void
3272 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
3273 {
3274    ELM_CHECK_WIDTYPE(obj, widtype);
3275    Widget_Data *wd = elm_widget_data_get(obj);
3276    if (!wd) return;
3277    if (file) *file = wd->file;
3278    if (format) *format = wd->format;
3279 }
3280
3281 /**
3282  * This function writes any changes made to the file set with
3283  * elm_entry_file_set()
3284  *
3285  * @param obj The entry object
3286  *
3287  * @ingroup Entry
3288  */
3289 EAPI void
3290 elm_entry_file_save(Evas_Object *obj)
3291 {
3292    ELM_CHECK_WIDTYPE(obj, widtype);
3293    Widget_Data *wd = elm_widget_data_get(obj);
3294    if (!wd) return;
3295    if (wd->delay_write)
3296      {
3297         ecore_timer_del(wd->delay_write);
3298         wd->delay_write = NULL;
3299      }
3300    _save(obj);
3301    wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
3302 }
3303
3304 /**
3305  * This sets the entry object to 'autosave' the loaded text file or not.
3306  *
3307  * @param obj The entry object
3308  * @param autosave Autosave the loaded file or not
3309  *
3310  * @ingroup Entry
3311  */
3312 EAPI void
3313 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
3314 {
3315    ELM_CHECK_WIDTYPE(obj, widtype);
3316    Widget_Data *wd = elm_widget_data_get(obj);
3317    if (!wd) return;
3318    wd->autosave = !!autosave;
3319 }
3320
3321 /**
3322  * This gets the entry object's 'autosave' status.
3323  *
3324  * @param obj The entry object
3325  * @return Autosave the loaded file or not
3326  *
3327  * @ingroup Entry
3328  */
3329 EAPI Eina_Bool
3330 elm_entry_autosave_get(const Evas_Object *obj)
3331 {
3332    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3333    Widget_Data *wd = elm_widget_data_get(obj);
3334    if (!wd) return EINA_FALSE;
3335    return wd->autosave;
3336 }
3337
3338 /**
3339  * Control pasting of text and images for the widget.
3340  *
3341  * Normally the entry allows both text and images to be pasted.  By setting
3342  * textonly to be true, this prevents images from being pasted.
3343  *
3344  * Note this only changes the behaviour of text.
3345  *
3346  * @param obj The entry object
3347  * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is text+image+other.
3348  *
3349  * @ingroup Entry
3350  */
3351 EAPI void
3352 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
3353 {
3354    Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
3355    ELM_CHECK_WIDTYPE(obj, widtype);
3356    Widget_Data *wd = elm_widget_data_get(obj);
3357    if (!wd) return;
3358    textonly = !!textonly;
3359    if (wd->textonly == textonly) return;
3360    wd->textonly = !!textonly;
3361    if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
3362 #ifdef HAVE_ELEMENTARY_X
3363    elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
3364 #endif
3365 }
3366
3367 /**
3368  * Getting elm_entry text paste/drop mode.
3369  *
3370  * In textonly mode, only text may be pasted or dropped into the widget.
3371  *
3372  * @param obj The entry object
3373  * @return If the widget only accepts text from pastes.
3374  *
3375  * @ingroup Entry
3376  */
3377 EAPI Eina_Bool
3378 elm_entry_cnp_textonly_get(const Evas_Object *obj)
3379 {
3380    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3381    Widget_Data *wd = elm_widget_data_get(obj);
3382    if (!wd) return EINA_FALSE;
3383    return wd->textonly;
3384 }
3385
3386 /**
3387  * Enable or disable scrolling in entry
3388  *
3389  * Normally the entry is not scrollable unless you enable it with this call.
3390  *
3391  * @param obj The entry object
3392  * @param scroll EINA_TRUE if it is to be scrollable, EINA_FALSE otherwise
3393  *
3394  * @ingroup Entry
3395  */
3396 EAPI void
3397 elm_entry_scrollable_set(Evas_Object *obj, Eina_Bool scroll)
3398 {
3399    ELM_CHECK_WIDTYPE(obj, widtype);
3400    Widget_Data *wd = elm_widget_data_get(obj);
3401    if (!wd) return;
3402    scroll = !!scroll;
3403    if (wd->scroll == scroll) return;
3404    wd->scroll = scroll;
3405    if (wd->scroll)
3406      {
3407         elm_widget_sub_object_del(obj, wd->scroller);
3408         elm_widget_resize_object_set(obj, wd->scroller);
3409         elm_widget_sub_object_add(obj, wd->ent);
3410         elm_smart_scroller_child_set(wd->scroller, wd->ent);
3411         evas_object_show(wd->scroller);
3412         elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
3413      }
3414    else
3415      {
3416         elm_smart_scroller_child_set(wd->scroller, NULL);
3417         elm_widget_sub_object_del(obj, wd->ent);
3418         elm_widget_resize_object_set(obj, wd->ent);
3419         evas_object_smart_member_add(wd->scroller, obj);
3420         elm_widget_sub_object_add(obj, wd->scroller);
3421         evas_object_hide(wd->scroller);
3422         elm_widget_on_show_region_hook_set(obj, NULL, NULL);
3423      }
3424    wd->lastw = -1;
3425    _theme_hook(obj);
3426 }
3427
3428 /**
3429  * Get the scrollable state of the entry
3430  *
3431  * Normally the entry is not scrollable. This gets the scrollable state
3432  * of the entry. See elm_entry_scrollable_set() for more information.
3433  *
3434  * @param obj The entry object
3435  * @return The scrollable state
3436  *
3437  * @ingroup Entry
3438  */
3439 EAPI Eina_Bool
3440 elm_entry_scrollable_get(const Evas_Object *obj)
3441 {
3442    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3443    Widget_Data *wd = elm_widget_data_get(obj);
3444    if (!wd) return EINA_FALSE;
3445    return wd->scroll;
3446 }
3447
3448 /**
3449  * This sets a widget to be displayed to the left of a scrolled entry.
3450  *
3451  * @param obj The scrolled entry object
3452  * @param icon The widget to display on the left side of the scrolled
3453  * entry.
3454  *
3455  * @note A previously set widget will be destroyed.
3456  * @note If the object being set does not have minimum size hints set,
3457  * it won't get properly displayed.
3458  *
3459  * @ingroup Entry
3460  * @see elm_entry_end_set
3461  */
3462 EAPI void
3463 elm_entry_icon_set(Evas_Object *obj, Evas_Object *icon)
3464 {
3465    ELM_CHECK_WIDTYPE(obj, widtype);
3466    Widget_Data *wd = elm_widget_data_get(obj);
3467    Evas_Object *edje;
3468    if (!wd) return;
3469    EINA_SAFETY_ON_NULL_RETURN(icon);
3470    if (wd->icon == icon) return;
3471    if (wd->icon) evas_object_del(wd->icon);
3472    wd->icon = icon;
3473    edje = elm_smart_scroller_edje_object_get(wd->scroller);
3474    if (!edje) return;
3475    edje_object_part_swallow(edje, "elm.swallow.icon", wd->icon);
3476    edje_object_signal_emit(edje, "elm,action,show,icon", "elm");
3477    _sizing_eval(obj);
3478 }
3479
3480 /**
3481  * Gets the leftmost widget of the scrolled entry. This object is
3482  * owned by the scrolled entry and should not be modified.
3483  *
3484  * @param obj The scrolled entry object
3485  * @return the left widget inside the scroller
3486  *
3487  * @ingroup Entry
3488  */
3489 EAPI Evas_Object *
3490 elm_entry_icon_get(const Evas_Object *obj)
3491 {
3492    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3493    Widget_Data *wd = elm_widget_data_get(obj);
3494    if (!wd) return NULL;
3495    return wd->icon;
3496 }
3497
3498 /**
3499  * Unset the leftmost widget of the scrolled entry, unparenting and
3500  * returning it.
3501  *
3502  * @param obj The scrolled entry object
3503  * @return the previously set icon sub-object of this entry, on
3504  * success.
3505  *
3506  * @see elm_entry_icon_set()
3507  *
3508  * @ingroup Entry
3509  */
3510 EAPI Evas_Object *
3511 elm_entry_icon_unset(Evas_Object *obj)
3512 {
3513    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3514    Widget_Data *wd = elm_widget_data_get(obj);
3515    Evas_Object *ret = NULL;
3516    if (!wd) return NULL;
3517    if (wd->icon)
3518      {
3519         Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
3520         if (!edje) return NULL;
3521         ret = wd->icon;
3522         edje_object_part_unswallow(edje, wd->icon);
3523         edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
3524         wd->icon = NULL;
3525         _sizing_eval(obj);
3526      }
3527    return ret;
3528 }
3529
3530 /**
3531  * Sets the visibility of the left-side widget of the scrolled entry,
3532  * set by @elm_entry_icon_set().
3533  *
3534  * @param obj The scrolled entry object
3535  * @param setting EINA_TRUE if the object should be displayed,
3536  * EINA_FALSE if not.
3537  *
3538  * @ingroup Entry
3539  */
3540 EAPI void
3541 elm_entry_icon_visible_set(Evas_Object *obj, Eina_Bool setting)
3542 {
3543    ELM_CHECK_WIDTYPE(obj, widtype);
3544    Widget_Data *wd = elm_widget_data_get(obj);
3545    if ((!wd) || (!wd->icon)) return;
3546    if (setting)
3547       evas_object_hide(wd->icon);
3548    else
3549       evas_object_show(wd->icon);
3550    _sizing_eval(obj);
3551 }
3552
3553 /**
3554  * This sets a widget to be displayed to the end of a scrolled entry.
3555  *
3556  * @param obj The scrolled entry object
3557  * @param end The widget to display on the right side of the scrolled
3558  * entry.
3559  *
3560  * @note A previously set widget will be destroyed.
3561  * @note If the object being set does not have minimum size hints set,
3562  * it won't get properly displayed.
3563  *
3564  * @ingroup Entry
3565  * @see elm_entry_icon_set
3566  */
3567 EAPI void
3568 elm_entry_end_set(Evas_Object *obj, Evas_Object *end)
3569 {
3570    ELM_CHECK_WIDTYPE(obj, widtype);
3571    Widget_Data *wd = elm_widget_data_get(obj);
3572    Evas_Object *edje;
3573    if (!wd) return;
3574    EINA_SAFETY_ON_NULL_RETURN(end);
3575    if (wd->end == end) return;
3576    if (wd->end) evas_object_del(wd->end);
3577    wd->end = end;
3578    edje = elm_smart_scroller_edje_object_get(wd->scroller);
3579    if (!edje) return;
3580    edje_object_part_swallow(edje, "elm.swallow.end", wd->end);
3581    edje_object_signal_emit(edje, "elm,action,show,end", "elm");
3582    _sizing_eval(obj);
3583 }
3584
3585 /**
3586  * Gets the endmost widget of the scrolled entry. This object is owned
3587  * by the scrolled entry and should not be modified.
3588  *
3589  * @param obj The scrolled entry object
3590  * @return the right widget inside the scroller
3591  *
3592  * @ingroup Entry
3593  */
3594 EAPI Evas_Object *
3595 elm_entry_end_get(const Evas_Object *obj)
3596 {
3597    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3598    Widget_Data *wd = elm_widget_data_get(obj);
3599    if (!wd) return NULL;
3600    return wd->end;
3601 }
3602
3603 /**
3604  * Unset the endmost widget of the scrolled entry, unparenting and
3605  * returning it.
3606  *
3607  * @param obj The scrolled entry object
3608  * @return the previously set icon sub-object of this entry, on
3609  * success.
3610  *
3611  * @see elm_entry_icon_set()
3612  *
3613  * @ingroup Entry
3614  */
3615 EAPI Evas_Object *
3616 elm_entry_end_unset(Evas_Object *obj)
3617 {
3618    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3619    Widget_Data *wd = elm_widget_data_get(obj);
3620    Evas_Object *ret = NULL;
3621    if (!wd) return NULL;
3622    if (wd->end)
3623      {
3624         Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
3625         if (!edje) return NULL;
3626         ret = wd->end;
3627         edje_object_part_unswallow(edje, wd->end);
3628         edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
3629         wd->end = NULL;
3630         _sizing_eval(obj);
3631      }
3632    return ret;
3633 }
3634
3635 /**
3636  * Sets the visibility of the end widget of the scrolled entry, set by
3637  * @elm_entry_end_set().
3638  *
3639  * @param obj The scrolled entry object
3640  * @param setting EINA_TRUE if the object should be displayed,
3641  * EINA_FALSE if not.
3642  *
3643  * @ingroup Entry
3644  */
3645 EAPI void
3646 elm_entry_end_visible_set(Evas_Object *obj, Eina_Bool setting)
3647 {
3648    ELM_CHECK_WIDTYPE(obj, widtype);
3649    Widget_Data *wd = elm_widget_data_get(obj);
3650    if ((!wd) || (!wd->end)) return;
3651    if (setting)
3652       evas_object_hide(wd->end);
3653    else
3654       evas_object_show(wd->end);
3655    _sizing_eval(obj);
3656 }
3657
3658 /**
3659  * This sets the scrolled entry's scrollbar policy (ie. enabling/disabling them).
3660  *
3661  * @param obj The scrolled entry object
3662  * @param h The horizontal scrollbar policy to apply
3663  * @param v The vertical scrollbar policy to apply
3664  *
3665  * @ingroup Entry
3666  */
3667 EAPI void
3668 elm_entry_scrollbar_policy_set(Evas_Object *obj, Elm_Scroller_Policy h, Elm_Scroller_Policy v)
3669 {
3670    ELM_CHECK_WIDTYPE(obj, widtype);
3671    Widget_Data *wd = elm_widget_data_get(obj);
3672    const Elm_Scroller_Policy map[3] =
3673      {
3674         ELM_SMART_SCROLLER_POLICY_AUTO,
3675         ELM_SMART_SCROLLER_POLICY_ON,
3676         ELM_SMART_SCROLLER_POLICY_OFF
3677      };
3678    if (!wd) return;
3679    wd->policy_h = h;
3680    wd->policy_v = v;
3681    elm_smart_scroller_policy_set(wd->scroller,
3682                                  map[wd->policy_h],
3683                                  map[wd->policy_v]);
3684 }
3685
3686 /**
3687  * This enables/disables bouncing within the entry.
3688  *
3689  * @param obj The scrolled entry object
3690  * @param h The horizontal bounce state
3691  * @param v The vertical bounce state
3692  *
3693  * @ingroup Entry
3694  */
3695 EAPI void
3696 elm_entry_bounce_set(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_set(wd->scroller, h_bounce, v_bounce);
3702 }
3703
3704 /**
3705  * Get the bounce mode
3706  *
3707  * @param obj The Entry object
3708  * @param h_bounce Allow bounce horizontally
3709  * @param v_bounce Allow bounce vertically
3710  *
3711  * @ingroup Entry
3712  */
3713 EAPI void
3714 elm_entry_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
3715 {
3716    ELM_CHECK_WIDTYPE(obj, widtype);
3717    Widget_Data *wd = elm_widget_data_get(obj);
3718    if (!wd) return;
3719    elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
3720 }