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