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