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