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