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