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