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