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