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