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