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