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