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