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