d9d44008372178ce42953395fe44e42db0d014d3
[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 > vw) vw = minw;
743              if (minh > vh) 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.merge = EINA_FALSE;
1120    info.insert = EINA_TRUE;
1121    info.change.insert.pos = elm_entry_cursor_pos_get(obj);
1122    info.change.insert.content = eina_stringshare_add(entry);
1123      {
1124         char *tmp;
1125         tmp = evas_textblock_text_markup_to_utf8(elm_entry_textblock_get(obj),
1126               info.change.insert.content);
1127         info.change.insert.plain_length = eina_unicode_utf8_get_len(tmp);
1128         free(tmp);
1129      }
1130
1131    elm_entry_entry_insert(obj, entry);
1132    evas_object_smart_callback_call(obj, SIG_CHANGED_USER, &info);
1133
1134    eina_stringshare_del(info.change.insert.content);
1135 }
1136
1137 static void
1138 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1139 {
1140    Widget_Data *wd = elm_widget_data_get(data);
1141    if (!wd) return;
1142    evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1143    if (wd->sel_notify_handler)
1144      {
1145 #ifdef HAVE_ELEMENTARY_X
1146         Elm_Sel_Format formats;
1147         wd->selection_asked = EINA_TRUE;
1148         formats = ELM_SEL_FORMAT_MARKUP;
1149         if (!wd->textonly)
1150           formats |= ELM_SEL_FORMAT_IMAGE;
1151         elm_cnp_selection_get(ELM_SEL_TYPE_CLIPBOARD, formats, data, NULL, NULL);
1152 #endif
1153      }
1154 }
1155
1156 static void
1157 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
1158 {
1159    Widget_Data *wd = elm_widget_data_get(obj);
1160    const char *sel;
1161
1162    if (!wd) return;
1163    sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
1164    if ((!sel) || (!sel[0])) return; /* avoid deleting our own selection */
1165    elm_cnp_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel, strlen(sel));
1166    if (seltype == ELM_SEL_TYPE_CLIPBOARD)
1167      eina_stringshare_replace(&wd->cut_sel, sel);
1168 }
1169
1170 static void
1171 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1172 {
1173    Widget_Data *wd = elm_widget_data_get(data);
1174
1175    /* Store it */
1176    wd->selmode = EINA_FALSE;
1177    if (!_elm_config->desktop_entry)
1178      edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1179    edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1180    if (!_elm_config->desktop_entry)
1181      elm_widget_scroll_hold_pop(data);
1182    _store_selection(ELM_SEL_TYPE_CLIPBOARD, data);
1183    edje_object_part_text_insert(wd->ent, "elm.text", "");
1184    edje_object_part_text_select_none(wd->ent, "elm.text");
1185    _sizing_eval(data);
1186 }
1187
1188 static void
1189 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1190 {
1191    Widget_Data *wd = elm_widget_data_get(data);
1192    if (!wd) return;
1193    wd->selmode = EINA_FALSE;
1194    if (!_elm_config->desktop_entry)
1195      {
1196         edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1197         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1198         elm_widget_scroll_hold_pop(data);
1199      }
1200    _store_selection(ELM_SEL_TYPE_CLIPBOARD, data);
1201    //   edje_object_part_text_select_none(wd->ent, "elm.text");
1202 }
1203
1204 static void
1205 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1206 {
1207    Widget_Data *wd = elm_widget_data_get(data);
1208    if (!wd) return;
1209    wd->selmode = EINA_FALSE;
1210    if (!_elm_config->desktop_entry)
1211      edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1212    edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1213    if (!_elm_config->desktop_entry)
1214      elm_widget_scroll_hold_pop(data);
1215    edje_object_part_text_select_none(wd->ent, "elm.text");
1216 }
1217
1218 static void
1219 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1220 {
1221    Elm_Entry_Context_Menu_Item *it = data;
1222    Evas_Object *obj2 = it->obj;
1223    if (it->func) it->func(it->data, obj2, NULL);
1224 }
1225
1226 static void
1227 _menu_press(Evas_Object *obj)
1228 {
1229    Widget_Data *wd = elm_widget_data_get(obj);
1230    Evas_Object *top;
1231    const Eina_List *l;
1232    const Elm_Entry_Context_Menu_Item *it;
1233    if (!wd) return;
1234    if ((wd->api) && (wd->api->obj_longpress))
1235      {
1236         wd->api->obj_longpress(obj);
1237      }
1238    else if (wd->context_menu)
1239      {
1240         const char *context_menu_orientation;
1241
1242         if (wd->hoversel) evas_object_del(wd->hoversel);
1243         else elm_widget_scroll_freeze_push(obj);
1244         wd->hoversel = elm_hoversel_add(obj);
1245         context_menu_orientation = edje_object_data_get
1246            (wd->ent, "context_menu_orientation");
1247         if ((context_menu_orientation) &&
1248             (!strcmp(context_menu_orientation, "horizontal")))
1249           elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
1250         elm_object_style_set(wd->hoversel, "entry");
1251         elm_widget_sub_object_add(obj, wd->hoversel);
1252         elm_object_text_set(wd->hoversel, "Text");
1253         top = elm_widget_top_get(obj);
1254         if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
1255         evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, obj);
1256         if (wd->have_selection)
1257           {
1258              if (!wd->password)
1259                {
1260                   if (wd->have_selection)
1261                     {
1262                        elm_hoversel_item_add(wd->hoversel, E_("Copy"), NULL, ELM_ICON_NONE,
1263                                              _copy, obj);
1264                        if (wd->editable)
1265                          elm_hoversel_item_add(wd->hoversel, E_("Cut"), NULL, ELM_ICON_NONE,
1266                                                _cut, obj);
1267                     }
1268                   elm_hoversel_item_add(wd->hoversel, E_("Cancel"), NULL, ELM_ICON_NONE,
1269                                         _cancel, obj);
1270                }
1271           }
1272         else
1273           {
1274              if (!wd->selmode)
1275                {
1276                   if (!_elm_config->desktop_entry)
1277                     {
1278                        if (!wd->password)
1279                          elm_hoversel_item_add(wd->hoversel, E_("Select"), NULL, ELM_ICON_NONE,
1280                                                _select, obj);
1281                     }
1282                   if (elm_selection_selection_has_owner())
1283                     {
1284                        if (wd->editable)
1285                          elm_hoversel_item_add(wd->hoversel, E_("Paste"), NULL, ELM_ICON_NONE,
1286                                                _paste, obj);
1287                     }
1288                }
1289           }
1290         EINA_LIST_FOREACH(wd->items, l, it)
1291           {
1292              elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
1293                                    it->icon_type, _item_clicked, it);
1294           }
1295         if (wd->hoversel)
1296           {
1297              _hoversel_position(obj);
1298              evas_object_show(wd->hoversel);
1299              elm_hoversel_hover_begin(wd->hoversel);
1300           }
1301         if (!_elm_config->desktop_entry)
1302           {
1303              edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1304              edje_object_part_text_select_abort(wd->ent, "elm.text");
1305           }
1306      }
1307 }
1308
1309 static Eina_Bool
1310 _long_press(void *data)
1311 {
1312    Widget_Data *wd = elm_widget_data_get(data);
1313    if (!wd) return ECORE_CALLBACK_CANCEL;
1314    _menu_press(data);
1315    wd->longpress_timer = NULL;
1316    evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
1317    return ECORE_CALLBACK_CANCEL;
1318 }
1319
1320 static void
1321 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1322 {
1323    Widget_Data *wd = elm_widget_data_get(data);
1324    Evas_Event_Mouse_Down *ev = event_info;
1325    if (!wd) return;
1326    if (wd->disabled) return;
1327    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1328    wd->downx = ev->canvas.x;
1329    wd->downy = ev->canvas.y;
1330    if (ev->button == 1)
1331      {
1332         if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
1333         wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1334      }
1335 }
1336
1337 static void
1338 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1339 {
1340    Widget_Data *wd = elm_widget_data_get(data);
1341    Evas_Event_Mouse_Up *ev = event_info;
1342    if (!wd) return;
1343    if (wd->disabled) return;
1344    if (ev->button == 1)
1345      {
1346         if (wd->longpress_timer)
1347           {
1348              ecore_timer_del(wd->longpress_timer);
1349              wd->longpress_timer = NULL;
1350           }
1351      }
1352    else if (ev->button == 3)
1353      {
1354         wd->usedown = 1;
1355         _menu_press(data);
1356      }
1357 }
1358
1359 static void
1360 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1361 {
1362    Widget_Data *wd = elm_widget_data_get(data);
1363    Evas_Event_Mouse_Move *ev = event_info;
1364    if (!wd) return;
1365    if (wd->disabled) return;
1366    if (!wd->selmode)
1367      {
1368         if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1369           {
1370              if (wd->longpress_timer)
1371                {
1372                   ecore_timer_del(wd->longpress_timer);
1373                   wd->longpress_timer = NULL;
1374                }
1375           }
1376         else if (wd->longpress_timer)
1377           {
1378              Evas_Coord dx, dy;
1379
1380              dx = wd->downx - ev->cur.canvas.x;
1381              dx *= dx;
1382              dy = wd->downy - ev->cur.canvas.y;
1383              dy *= dy;
1384              if ((dx + dy) >
1385                  ((_elm_config->finger_size / 2) *
1386                   (_elm_config->finger_size / 2)))
1387                {
1388                   ecore_timer_del(wd->longpress_timer);
1389                   wd->longpress_timer = NULL;
1390                }
1391           }
1392      }
1393    else if (wd->longpress_timer)
1394      {
1395         Evas_Coord dx, dy;
1396
1397         dx = wd->downx - ev->cur.canvas.x;
1398         dx *= dx;
1399         dy = wd->downy - ev->cur.canvas.y;
1400         dy *= dy;
1401         if ((dx + dy) >
1402             ((_elm_config->finger_size / 2) *
1403              (_elm_config->finger_size / 2)))
1404           {
1405              ecore_timer_del(wd->longpress_timer);
1406              wd->longpress_timer = NULL;
1407           }
1408      }
1409 }
1410
1411 static const char *
1412 _getbase(Evas_Object *obj)
1413 {
1414    Widget_Data *wd = elm_widget_data_get(obj);
1415    if (!wd) return "base";
1416    if (wd->editable)
1417      {
1418         if (wd->password) return "base-password";
1419         else
1420           {
1421              if (wd->single_line) return "base-single";
1422              else
1423                {
1424                   switch (wd->linewrap)
1425                     {
1426                      case ELM_WRAP_CHAR:
1427                         return "base-charwrap";
1428                      case ELM_WRAP_WORD:
1429                         return "base";
1430                      case ELM_WRAP_MIXED:
1431                         return "base-mixedwrap";
1432                      case ELM_WRAP_NONE:
1433                      default:
1434                         return "base-nowrap";
1435                     }
1436                }
1437           }
1438      }
1439    else
1440      {
1441         if (wd->password) return "base-password";
1442         else
1443           {
1444              if (wd->single_line) return "base-single-noedit";
1445              else
1446                {
1447                   switch (wd->linewrap)
1448                     {
1449                      case ELM_WRAP_CHAR:
1450                         return "base-noedit-charwrap";
1451                      case ELM_WRAP_WORD:
1452                         return "base-noedit";
1453                      case ELM_WRAP_MIXED:
1454                         return "base-noedit-mixedwrap";
1455                      case ELM_WRAP_NONE:
1456                      default:
1457                         return "base-nowrap-noedit";
1458                     }
1459                }
1460           }
1461      }
1462 }
1463
1464 static void
1465 _entry_changed_common_handling(void *data, const char *event)
1466 {
1467    Widget_Data *wd = elm_widget_data_get(data);
1468    Evas_Coord minh;
1469    if (!wd) return;
1470    evas_event_freeze(evas_object_evas_get(data));
1471    wd->changed = EINA_TRUE;
1472    /* Reset the size hints which are no more relevant.
1473     * Keep the height, this is a hack, but doesn't really matter
1474     * cause we'll re-eval in a moment. */
1475    evas_object_size_hint_min_get(data, NULL, &minh);
1476    evas_object_size_hint_min_set(data, -1, minh);
1477    _sizing_eval(data);
1478    if (wd->text) eina_stringshare_del(wd->text);
1479    wd->text = NULL;
1480    if (wd->delay_write)
1481      {
1482         ecore_timer_del(wd->delay_write);
1483         wd->delay_write = NULL;
1484      }
1485    evas_event_thaw(evas_object_evas_get(data));
1486    evas_event_thaw_eval(evas_object_evas_get(data));
1487    if ((wd->autosave) && (wd->file))
1488      wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1489    /* callback - this could call callbacks that delete the entry... thus...
1490     * any access to wd after this could be invalid */
1491    evas_object_smart_callback_call(data, event, NULL);
1492 }
1493
1494 static void
1495 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1496 {
1497    _entry_changed_common_handling(data, SIG_CHANGED);
1498 }
1499
1500 static void
1501 _signal_entry_changed_user(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1502 {
1503    Elm_Entry_Change_Info info;
1504    Edje_Entry_Change_Info *edje_info = (Edje_Entry_Change_Info *)
1505       edje_object_signal_callback_extra_data_get();
1506    if (edje_info)
1507      {
1508         memcpy(&info, edje_info, sizeof(info));
1509         evas_object_smart_callback_call(data, SIG_CHANGED_USER, &info);
1510      }
1511    else
1512      {
1513         evas_object_smart_callback_call(data, SIG_CHANGED_USER, NULL);
1514      }
1515 }
1516
1517 static void
1518 _signal_preedit_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1519 {
1520    _entry_changed_common_handling(data, SIG_PREEDIT_CHANGED);
1521 }
1522
1523 static void
1524 _signal_undo_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1525 {
1526    evas_object_smart_callback_call(data, SIG_UNDO_REQUEST, NULL);
1527 }
1528
1529 static void
1530 _signal_redo_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1531 {
1532    evas_object_smart_callback_call(data, SIG_REDO_REQUEST, NULL);
1533 }
1534
1535 static void
1536 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1537 {
1538    Widget_Data *wd = elm_widget_data_get(data);
1539    const Eina_List *l;
1540    Evas_Object *entry;
1541    if (!wd) return;
1542    EINA_LIST_FOREACH(entries, l, entry)
1543      {
1544         if (entry != data) elm_entry_select_none(entry);
1545      }
1546    wd->have_selection = EINA_TRUE;
1547    evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1548 #ifdef HAVE_ELEMENTARY_X
1549    if (wd->sel_notify_handler)
1550      {
1551         const char *txt = elm_entry_selection_get(data);
1552         Evas_Object *top;
1553
1554         top = elm_widget_top_get(data);
1555         if (txt && top && (elm_win_xwindow_get(top)))
1556           elm_cnp_selection_set(ELM_SEL_TYPE_PRIMARY, data,
1557                                 ELM_SEL_FORMAT_MARKUP, txt, strlen(txt));
1558      }
1559 #endif
1560 }
1561
1562 static void
1563 _signal_selection_all(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1564 {
1565    Widget_Data *wd = elm_widget_data_get(data);
1566    if (!wd) return;
1567    elm_entry_select_all(data);
1568 }
1569
1570 static void
1571 _signal_selection_none(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1572 {
1573    Widget_Data *wd = elm_widget_data_get(data);
1574    if (!wd) return;
1575    elm_entry_select_none(data);
1576 }
1577
1578 static void
1579 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1580 {
1581    Widget_Data *wd = elm_widget_data_get(data);
1582    if (!wd) return;
1583    wd->have_selection = EINA_TRUE;
1584    evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1585    _store_selection(ELM_SEL_TYPE_PRIMARY, data);
1586 }
1587
1588 static void
1589 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1590 {
1591    Widget_Data *wd = elm_widget_data_get(data);
1592    if (!wd) return;
1593    if (!wd->have_selection) return;
1594    wd->have_selection = EINA_FALSE;
1595    evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1596    if (wd->sel_notify_handler)
1597      {
1598         if (wd->cut_sel)
1599           {
1600 #ifdef HAVE_ELEMENTARY_X
1601              Evas_Object *top;
1602
1603              top = elm_widget_top_get(data);
1604              if ((top) && (elm_win_xwindow_get(top)))
1605                elm_cnp_selection_set(ELM_SEL_TYPE_PRIMARY, data,
1606                                      ELM_SEL_FORMAT_MARKUP, wd->cut_sel,
1607                                      strlen(wd->cut_sel));
1608 #endif
1609              eina_stringshare_del(wd->cut_sel);
1610              wd->cut_sel = NULL;
1611           }
1612         else
1613           {
1614 #ifdef HAVE_ELEMENTARY_X
1615              Evas_Object *top;
1616
1617              top = elm_widget_top_get(data);
1618              if ((top) && (elm_win_xwindow_get(top)))
1619                elm_cnp_selection_clear(ELM_SEL_TYPE_PRIMARY, data);
1620 #endif
1621           }
1622      }
1623 }
1624
1625 static void
1626 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1627 {
1628    Widget_Data *wd = elm_widget_data_get(data);
1629    Elm_Sel_Type type = (emission[sizeof("ntry,paste,request,")] == '1') ?
1630      ELM_SEL_TYPE_PRIMARY : ELM_SEL_TYPE_CLIPBOARD;
1631    if (!wd) return;
1632    evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1633    if (wd->sel_notify_handler)
1634      {
1635 #ifdef HAVE_ELEMENTARY_X
1636         Evas_Object *top;
1637
1638         top = elm_widget_top_get(data);
1639         if ((top) && (elm_win_xwindow_get(top)))
1640           {
1641              wd->selection_asked = EINA_TRUE;
1642              elm_cnp_selection_get(type, ELM_SEL_FORMAT_MARKUP, data,
1643                                NULL, NULL);
1644           }
1645 #endif
1646      }
1647 }
1648
1649 static void
1650 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1651 {
1652    _copy(data, NULL, NULL);
1653 }
1654
1655 static void
1656 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1657 {
1658    _cut(data, NULL, NULL);
1659 }
1660
1661 static void
1662 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1663 {
1664    Widget_Data *wd = elm_widget_data_get(data);
1665    if (!wd) return;
1666    wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1667    wd->cur_changed = EINA_TRUE;
1668    _recalc_cursor_geometry(data);
1669 }
1670
1671 static void
1672 _signal_cursor_changed_manual(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1673 {
1674    evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED_MANUAL, NULL);
1675 }
1676
1677
1678 static void
1679 _signal_anchor_geoms_do_things_with(Widget_Data *wd, Elm_Entry_Anchor_Info *ei)
1680 {
1681    const Eina_List *geoms, *l;
1682    Evas_Textblock_Rectangle *r;
1683    Evas_Coord px, py, x, y;
1684
1685    geoms = edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei->name);
1686    if (!geoms) return;
1687
1688
1689    evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1690    evas_pointer_canvas_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1691    EINA_LIST_FOREACH(geoms, l, r)
1692      {
1693         if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1694             ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1695           {
1696              ei->x = r->x + x;
1697              ei->y = r->y + y;
1698              ei->w = r->w;
1699              ei->h = r->h;
1700              break;
1701           }
1702      }
1703 }
1704
1705 static void
1706 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1707 {
1708    Widget_Data *wd = elm_widget_data_get(data);
1709    Elm_Entry_Anchor_Info ei;
1710    const char *p;
1711    char *p2;
1712    if (!wd) return;
1713    p = emission + sizeof("nchor,mouse,down,");
1714    ei.button = strtol(p, &p2, 10);
1715    ei.name = p2 + 1;
1716    ei.x = ei.y = ei.w = ei.h = 0;
1717
1718    _signal_anchor_geoms_do_things_with(wd, &ei);
1719
1720    if (!wd->disabled)
1721      evas_object_smart_callback_call(data, SIG_ANCHOR_DOWN, &ei);
1722 }
1723
1724 static void
1725 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1726 {
1727    Widget_Data *wd = elm_widget_data_get(data);
1728    Elm_Entry_Anchor_Info ei;
1729    const char *p;
1730    char *p2;
1731    if (!wd) return;
1732    p = emission + sizeof("nchor,mouse,up,");
1733    ei.button = strtol(p, &p2, 10);
1734    ei.name = p2 + 1;
1735    ei.x = ei.y = ei.w = ei.h = 0;
1736
1737    _signal_anchor_geoms_do_things_with(wd, &ei);
1738
1739    if (!wd->disabled)
1740      evas_object_smart_callback_call(data, SIG_ANCHOR_UP, &ei);
1741 }
1742
1743 static void
1744 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1745 {
1746    Widget_Data *wd = elm_widget_data_get(data);
1747    Elm_Entry_Anchor_Info ei;
1748    const char *p;
1749    char *p2;
1750    if (!wd) return;
1751    p = emission + sizeof("nchor,mouse,clicked,");
1752    ei.button = strtol(p, &p2, 10);
1753    ei.name = p2 + 1;
1754    ei.x = ei.y = ei.w = ei.h = 0;
1755
1756    _signal_anchor_geoms_do_things_with(wd, &ei);
1757
1758    if (!wd->disabled)
1759      evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1760 }
1761
1762 static void
1763 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1764 {
1765    Widget_Data *wd = elm_widget_data_get(data);
1766    if (!wd) return;
1767 }
1768
1769 static void
1770 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1771 {
1772    Widget_Data *wd = elm_widget_data_get(data);
1773    Elm_Entry_Anchor_Info ei;
1774    if (!wd) return;
1775    ei.name = emission + sizeof("nchor,mouse,in,");
1776    ei.button = 0;
1777    ei.x = ei.y = ei.w = ei.h = 0;
1778
1779    _signal_anchor_geoms_do_things_with(wd, &ei);
1780
1781    if (!wd->disabled)
1782      evas_object_smart_callback_call(data, SIG_ANCHOR_IN, &ei);
1783 }
1784
1785 static void
1786 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1787 {
1788    Widget_Data *wd = elm_widget_data_get(data);
1789    Elm_Entry_Anchor_Info ei;
1790    if (!wd) return;
1791    ei.name = emission + sizeof("nchor,mouse,out,");
1792    ei.button = 0;
1793    ei.x = ei.y = ei.w = ei.h = 0;
1794
1795    _signal_anchor_geoms_do_things_with(wd, &ei);
1796
1797    if (!wd->disabled)
1798      evas_object_smart_callback_call(data, SIG_ANCHOR_OUT, &ei);
1799 }
1800
1801 static void
1802 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1803 {
1804    Widget_Data *wd = elm_widget_data_get(data);
1805    if (!wd) return;
1806    evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1807 }
1808
1809 static void
1810 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1811 {
1812    Widget_Data *wd = elm_widget_data_get(data);
1813    if (!wd) return;
1814    evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1815 }
1816
1817 static void
1818 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1819 {
1820    Widget_Data *wd = elm_widget_data_get(data);
1821    if (!wd) return;
1822    evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1823 }
1824
1825 static void
1826 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1827 {
1828    Widget_Data *wd = elm_widget_data_get(data);
1829    if (!wd) return;
1830    evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1831 }
1832
1833 static void
1834 _signal_mouse_triple(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1835 {
1836    Widget_Data *wd = elm_widget_data_get(data);
1837    if (!wd) return;
1838    evas_object_smart_callback_call(data, SIG_CLICKED_TRIPLE, NULL);
1839 }
1840
1841 #ifdef HAVE_ELEMENTARY_X
1842 static Eina_Bool
1843 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1844 {
1845    Widget_Data *wd = elm_widget_data_get(data);
1846    Ecore_X_Event_Selection_Notify *ev = event;
1847    if (!wd) return ECORE_CALLBACK_PASS_ON;
1848    if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1849      return ECORE_CALLBACK_PASS_ON;
1850
1851    if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1852        (ev->selection == ECORE_X_SELECTION_PRIMARY))
1853      {
1854         Ecore_X_Selection_Data_Text *text_data;
1855
1856         text_data = ev->data;
1857         if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1858           {
1859              if (text_data->text)
1860                {
1861                   char *txt = _elm_util_text_to_mkup(text_data->text);
1862
1863                   if (txt)
1864                     {
1865                        elm_entry_entry_insert(data, txt);
1866                        free(txt);
1867                     }
1868                }
1869           }
1870         wd->selection_asked = EINA_FALSE;
1871      }
1872    else if (ev->selection == ECORE_X_SELECTION_XDND)
1873      {
1874         Ecore_X_Selection_Data_Text *text_data;
1875
1876         text_data = ev->data;
1877         if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1878           {
1879              if (text_data->text)
1880                {
1881                   char *txt = _elm_util_text_to_mkup(text_data->text);
1882
1883                   if (txt)
1884                     {
1885                        /* Massive FIXME: this should be at the drag point */
1886                        elm_entry_entry_insert(data, txt);
1887                        free(txt);
1888                     }
1889                }
1890           }
1891         wd->drag_selection_asked = EINA_FALSE;
1892
1893         ecore_x_dnd_send_finished();
1894
1895      }
1896    return ECORE_CALLBACK_PASS_ON;
1897 }
1898
1899 static Eina_Bool
1900 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1901 {
1902    Widget_Data *wd = elm_widget_data_get(data);
1903    Ecore_X_Event_Selection_Clear *ev = event;
1904    if (!wd) return ECORE_CALLBACK_PASS_ON;
1905    if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1906    if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1907        (ev->selection == ECORE_X_SELECTION_PRIMARY))
1908      {
1909         elm_entry_select_none(data);
1910      }
1911    return ECORE_CALLBACK_PASS_ON;
1912 }
1913
1914 static Eina_Bool
1915 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1916 {
1917    Widget_Data *wd;
1918    Eina_Bool rv;
1919
1920    wd = elm_widget_data_get(obj);
1921    if (!wd) return EINA_FALSE;
1922    printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1923
1924    edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1925                                      EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1926    rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1927                                                EDJE_CURSOR_MAIN,drop->x,drop->y);
1928    if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1929    elm_entry_entry_insert(obj, drop->data);
1930    edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1931                                      EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1932
1933    return EINA_TRUE;
1934 }
1935 #endif
1936
1937 static Evas_Object *
1938 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1939 {
1940    Widget_Data *wd = elm_widget_data_get(data);
1941    Evas_Object *o;
1942    Eina_List *l;
1943    Elm_Entry_Item_Provider *ip;
1944
1945    EINA_LIST_FOREACH(wd->item_providers, l, ip)
1946      {
1947         o = ip->func(ip->data, data, item);
1948         if (o) return o;
1949      }
1950    if (!strncmp(item, "file://", 7))
1951      {
1952         const char *fname = item + 7;
1953
1954         o = evas_object_image_filled_add(evas_object_evas_get(data));
1955         evas_object_image_file_set(o, fname, NULL);
1956         if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1957           {
1958              evas_object_show(o);
1959           }
1960         else
1961           {
1962              evas_object_del(o);
1963              o = edje_object_add(evas_object_evas_get(data));
1964              _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1965           }
1966         return o;
1967      }
1968    o = edje_object_add(evas_object_evas_get(data));
1969    if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1970      _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1971    return o;
1972 }
1973
1974 static void
1975 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
1976 {
1977    Widget_Data *wd = elm_widget_data_get(data);
1978    Eina_List *l;
1979    Elm_Entry_Text_Filter *tf;
1980
1981    if (type == EDJE_TEXT_FILTER_FORMAT)
1982      return;
1983
1984    EINA_LIST_FOREACH(wd->text_filters, l, tf)
1985      {
1986         tf->func(tf->data, data, text);
1987         if (!*text)
1988           break;
1989      }
1990 }
1991
1992 /* This function is used to insert text by chunks in jobs */
1993 static Eina_Bool
1994 _text_append_idler(void *data)
1995 {
1996    int start;
1997    char backup;
1998    Evas_Object *obj = (Evas_Object *) data;
1999    Widget_Data *wd = elm_widget_data_get(obj);
2000    evas_event_freeze(evas_object_evas_get(obj));
2001    if (wd->text) eina_stringshare_del(wd->text);
2002    wd->text = NULL;
2003    wd->changed = EINA_TRUE;
2004
2005    start = wd->append_text_position;
2006    if (start + _CHUNK_SIZE < wd->append_text_len)
2007      {
2008         int pos = start;
2009         int tag_start, esc_start;
2010
2011         tag_start = esc_start = -1;
2012         /* Find proper markup cut place */
2013         while (pos - start < _CHUNK_SIZE)
2014           {
2015              int prev_pos = pos;
2016              Eina_Unicode tmp =
2017                 eina_unicode_utf8_get_next(wd->append_text_left, &pos);
2018              if (esc_start == -1)
2019                {
2020                   if (tmp == '<')
2021                      tag_start = prev_pos;
2022                   else if (tmp == '>')
2023                      tag_start = -1;
2024                }
2025              if (tag_start == -1)
2026                {
2027                   if (tmp == '&')
2028                      esc_start = prev_pos;
2029                   else if (tmp == ';')
2030                      esc_start = -1;
2031                }
2032           }
2033
2034         if (tag_start >= 0)
2035           {
2036              wd->append_text_position = tag_start;
2037           }
2038         else if (esc_start >= 0)
2039           {
2040              wd->append_text_position = esc_start;
2041           }
2042         else
2043           {
2044              wd->append_text_position = pos;
2045           }
2046      }
2047    else
2048      {
2049         wd->append_text_position = wd->append_text_len;
2050      }
2051
2052    backup = wd->append_text_left[wd->append_text_position];
2053    wd->append_text_left[wd->append_text_position] = '\0';
2054
2055    edje_object_part_text_append(wd->ent, "elm.text",
2056                                 wd->append_text_left + start);
2057
2058    wd->append_text_left[wd->append_text_position] = backup;
2059
2060    evas_event_thaw(evas_object_evas_get(obj));
2061    evas_event_thaw_eval(evas_object_evas_get(obj));
2062
2063    /* If there's still more to go, renew the idler, else, cleanup */
2064    if (wd->append_text_position < wd->append_text_len)
2065      {
2066         return ECORE_CALLBACK_RENEW;
2067      }
2068    else
2069      {
2070         free(wd->append_text_left);
2071         wd->append_text_left = NULL;
2072         wd->append_text_idler = NULL;
2073         return ECORE_CALLBACK_CANCEL;
2074      }
2075 }
2076
2077 static void
2078 _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit)
2079 {
2080    int i = 0, current_len = 0;
2081    char *new_text;
2082
2083    if (!*text) return;
2084    if (unit >= LENGTH_UNIT_LAST) return;
2085    new_text = *text;
2086    current_len = strlen(*text);
2087    while (*new_text)
2088      {
2089         int idx = 0, unit_size = 0;
2090         char *markup, *utfstr;
2091         if (*new_text == '<')
2092           {
2093              while (*(new_text + idx) != '>')
2094                {
2095                   idx++;
2096                   if (!*(new_text + idx)) break;
2097                }
2098           }
2099         else if (*new_text == '&')
2100           {
2101              while (*(new_text + idx) != ';')
2102                {
2103                   idx++;
2104                   if (!*(new_text + idx)) break;
2105                }
2106           }
2107         idx = evas_string_char_next_get(new_text, idx, NULL);
2108         markup = malloc(idx + 1);
2109         if (markup)
2110           {
2111              strncpy(markup, new_text, idx);
2112              markup[idx] = 0;
2113              utfstr = elm_entry_markup_to_utf8(markup);
2114              if (utfstr)
2115                {
2116                   if (unit == LENGTH_UNIT_BYTE)
2117                     unit_size = strlen(utfstr);
2118                   else if (unit == LENGTH_UNIT_CHAR)
2119                     unit_size = evas_string_char_len_get(utfstr);
2120                   free(utfstr);
2121                   utfstr = NULL;
2122                }
2123              free(markup);
2124              markup = NULL;
2125           }
2126         if (can_add < unit_size)
2127           {
2128              if (!i)
2129                {
2130                   evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
2131                   free(*text);
2132                   *text = NULL;
2133                   return;
2134                }
2135              can_add = 0;
2136              strncpy(new_text, new_text + idx, current_len - ((new_text + idx) - *text));
2137              current_len -= idx;
2138              (*text)[current_len] = 0;
2139           }
2140         else
2141           {
2142              new_text += idx;
2143              can_add -= unit_size;
2144           }
2145         i++;
2146      }
2147    evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
2148 }
2149
2150 static void
2151 _elm_entry_text_set(Evas_Object *obj, const char *item, const char *entry)
2152 {
2153    int len = 0;
2154    ELM_CHECK_WIDTYPE(obj, widtype);
2155    Widget_Data *wd = elm_widget_data_get(obj);
2156    if (!wd) return;
2157    evas_event_freeze(evas_object_evas_get(obj));
2158    if (!entry) entry = "";
2159    if (item && strcmp(item, "default"))
2160      {
2161         edje_object_part_text_set(wd->ent, item, entry);
2162         return;
2163      }
2164
2165    if (wd->text) eina_stringshare_del(wd->text);
2166    wd->text = NULL;
2167    wd->changed = EINA_TRUE;
2168
2169    /* Clear currently pending job if there is one */
2170    if (wd->append_text_idler)
2171      {
2172         ecore_idler_del(wd->append_text_idler);
2173         free(wd->append_text_left);
2174         wd->append_text_left = NULL;
2175         wd->append_text_idler = NULL;
2176      }
2177
2178    len = strlen(entry);
2179    /* Split to ~_CHUNK_SIZE chunks */
2180    if (len > _CHUNK_SIZE)
2181      {
2182         wd->append_text_left = (char *) malloc(len + 1);
2183      }
2184
2185    /* If we decided to use the idler */
2186    if (wd->append_text_left)
2187      {
2188         /* Need to clear the entry first */
2189         edje_object_part_text_set(wd->ent, "elm.text", "");
2190         memcpy(wd->append_text_left, entry, len + 1);
2191         wd->append_text_position = 0;
2192         wd->append_text_len = len;
2193         wd->append_text_idler = ecore_idler_add(_text_append_idler, obj);
2194      }
2195    else
2196      {
2197         edje_object_part_text_set(wd->ent, "elm.text", entry);
2198      }
2199    evas_event_thaw(evas_object_evas_get(obj));
2200    evas_event_thaw_eval(evas_object_evas_get(obj));
2201 }
2202
2203 static const char *
2204 _elm_entry_text_get(const Evas_Object *obj, const char *item)
2205 {
2206    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2207    Widget_Data *wd = elm_widget_data_get(obj);
2208    if (item && strcmp(item, "default")) return NULL;
2209    const char *text;
2210    if (!wd) return NULL;
2211    if (wd->text) return wd->text;
2212    text = edje_object_part_text_get(wd->ent, "elm.text");
2213    if (!text)
2214      {
2215         ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2216         return NULL;
2217      }
2218
2219    if (wd->append_text_len > 0)
2220      {
2221         char *tmpbuf;
2222         size_t tlen;
2223         tlen = strlen(text);
2224         tmpbuf = malloc(tlen + wd->append_text_len + 1);
2225         if (!tmpbuf)
2226           {
2227              ERR("Failed to allocate memory for entry's text %p", obj);
2228              return NULL;
2229           }
2230         memcpy(tmpbuf, text, tlen);
2231         memcpy(tmpbuf + tlen, wd->append_text_left, wd->append_text_len);
2232         tmpbuf[tlen + wd->append_text_len] = '\0';
2233         eina_stringshare_replace(&wd->text, tmpbuf);
2234         free(tmpbuf);
2235      }
2236    else
2237      {
2238         eina_stringshare_replace(&wd->text, text);
2239      }
2240    return wd->text;
2241 }
2242
2243 EAPI Evas_Object *
2244 elm_entry_add(Evas_Object *parent)
2245 {
2246    Evas_Object *obj, *top;
2247    Evas *e;
2248    Widget_Data *wd;
2249
2250    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
2251
2252    ELM_SET_WIDTYPE(widtype, "entry");
2253    elm_widget_type_set(obj, "entry");
2254    elm_widget_sub_object_add(parent, obj);
2255    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2256    elm_widget_data_set(obj, wd);
2257    elm_widget_del_hook_set(obj, _del_hook);
2258    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2259    elm_widget_theme_hook_set(obj, _theme_hook);
2260    elm_widget_disable_hook_set(obj, _disable_hook);
2261    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2262    elm_widget_focus_region_hook_set(obj, _focus_region_hook);
2263    elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
2264    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
2265    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
2266    elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
2267    elm_widget_can_focus_set(obj, EINA_TRUE);
2268    elm_widget_highlight_ignore_set(obj, EINA_TRUE);
2269    elm_widget_text_set_hook_set(obj, _elm_entry_text_set);
2270    elm_widget_text_get_hook_set(obj, _elm_entry_text_get);
2271    elm_widget_content_set_hook_set(obj, _content_set_hook);
2272    elm_widget_content_unset_hook_set(obj, _content_unset_hook);
2273    elm_widget_content_get_hook_set(obj, _content_get_hook);
2274    elm_widget_translate_hook_set(obj, _translate_hook);
2275
2276    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, wd);
2277
2278    wd->linewrap     = ELM_WRAP_WORD;
2279    wd->editable     = EINA_TRUE;
2280    wd->disabled     = EINA_FALSE;
2281    wd->context_menu = EINA_TRUE;
2282    wd->autosave     = EINA_TRUE;
2283    wd->textonly     = EINA_FALSE;
2284    wd->scroll       = EINA_FALSE;
2285
2286    wd->ent = edje_object_add(e);
2287    edje_object_item_provider_set(wd->ent, _get_item, obj);
2288    edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
2289    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
2290    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
2291                                   _mouse_down, obj);
2292    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
2293                                   _mouse_up, obj);
2294    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
2295                                   _mouse_move, obj);
2296    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
2297
2298    _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
2299    edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
2300                                    _signal_entry_changed, obj);
2301    edje_object_signal_callback_add(wd->ent, "entry,changed,user", "elm.text",
2302                                    _signal_entry_changed_user, obj);
2303    edje_object_signal_callback_add(wd->ent, "preedit,changed", "elm.text",
2304                                    _signal_preedit_changed, obj);
2305    edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
2306                                    _signal_selection_start, obj);
2307    edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
2308                                    _signal_selection_changed, obj);
2309    edje_object_signal_callback_add(wd->ent, "entry,selection,all,request", "elm.text",
2310                                    _signal_selection_all, obj);
2311    edje_object_signal_callback_add(wd->ent, "entry,selection,none,request", "elm.text",
2312                                    _signal_selection_none, obj);
2313    edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2314                                    _signal_selection_cleared, obj);
2315    edje_object_signal_callback_add(wd->ent, "entry,paste,request,*", "elm.text",
2316                                    _signal_entry_paste_request, obj);
2317    edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2318                                    _signal_entry_copy_notify, obj);
2319    edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2320                                    _signal_entry_cut_notify, obj);
2321    edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2322                                    _signal_cursor_changed, obj);
2323    edje_object_signal_callback_add(wd->ent, "cursor,changed,manual", "elm.text",
2324                                    _signal_cursor_changed_manual, obj);
2325    edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2326                                    _signal_anchor_down, obj);
2327    edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2328                                    _signal_anchor_up, obj);
2329    edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
2330                                    _signal_anchor_clicked, obj);
2331    edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2332                                    _signal_anchor_move, obj);
2333    edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2334                                    _signal_anchor_in, obj);
2335    edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2336                                    _signal_anchor_out, obj);
2337    edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2338                                    _signal_key_enter, obj);
2339    edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2340                                    _signal_mouse_down, obj);
2341    edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2342                                    _signal_mouse_clicked, obj);
2343    edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2344                                    _signal_mouse_double, obj);
2345    edje_object_signal_callback_add(wd->ent, "mouse,down,1,triple", "elm.text",
2346                                    _signal_mouse_triple, obj);
2347    edje_object_signal_callback_add(wd->ent, "entry,undo,request", "elm.text",
2348                                    _signal_undo_request, obj);
2349    edje_object_signal_callback_add(wd->ent, "entry,redo,request", "elm.text",
2350                                    _signal_redo_request, obj);
2351    edje_object_part_text_set(wd->ent, "elm.text", "");
2352    if (_elm_config->desktop_entry)
2353      edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
2354    elm_widget_resize_object_set(obj, wd->ent);
2355    _sizing_eval(obj);
2356
2357    elm_entry_input_panel_layout_set(obj, ELM_INPUT_PANEL_LAYOUT_NORMAL);
2358
2359    wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
2360    wd->autocapital_type = edje_object_part_text_autocapital_type_get(wd->ent, "elm.text");
2361
2362 #ifdef HAVE_ELEMENTARY_X
2363    top = elm_widget_top_get(obj);
2364    if ((top) && (elm_win_xwindow_get(top)))
2365      {
2366         wd->sel_notify_handler =
2367            ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2368                                    _event_selection_notify, obj);
2369         wd->sel_clear_handler =
2370            ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2371                                    _event_selection_clear, obj);
2372      }
2373
2374    elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
2375                        _drag_drop_cb, NULL);
2376 #endif
2377
2378    entries = eina_list_prepend(entries, obj);
2379
2380    // module - find module for entry
2381    wd->api = _module(obj);
2382    // if found - hook in
2383    if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2384
2385    _mirrored_set(obj, elm_widget_mirrored_get(obj));
2386    // TODO: convert Elementary to subclassing of Evas_Smart_Class
2387    // TODO: and save some bytes, making descriptions per-class and not instance!
2388    evas_object_smart_callbacks_descriptions_set(obj, _signals);
2389    return obj;
2390 }
2391
2392 EAPI void
2393 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2394 {
2395    ELM_CHECK_WIDTYPE(obj, widtype);
2396    Widget_Data *wd = elm_widget_data_get(obj);
2397    if (!wd) return;
2398    if (wd->single_line == single_line) return;
2399    wd->single_line = single_line;
2400    wd->linewrap = ELM_WRAP_NONE;
2401    elm_entry_cnp_textonly_set(obj, EINA_TRUE);
2402    _theme_hook(obj);
2403    if (wd->scroller)
2404      {
2405         if (wd->single_line)
2406           elm_smart_scroller_policy_set(wd->scroller,
2407                                         ELM_SMART_SCROLLER_POLICY_OFF,
2408                                         ELM_SMART_SCROLLER_POLICY_OFF);
2409         else
2410           {
2411              const Elm_Scroller_Policy map[3] =
2412                {
2413                   ELM_SMART_SCROLLER_POLICY_AUTO,
2414                   ELM_SMART_SCROLLER_POLICY_ON,
2415                   ELM_SMART_SCROLLER_POLICY_OFF
2416                };
2417              elm_smart_scroller_policy_set(wd->scroller,
2418                                            map[wd->policy_h],
2419                                            map[wd->policy_v]);
2420           }
2421         _sizing_eval(obj);
2422      }
2423 }
2424
2425 EAPI Eina_Bool
2426 elm_entry_single_line_get(const Evas_Object *obj)
2427 {
2428    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2429    Widget_Data *wd = elm_widget_data_get(obj);
2430    if (!wd) return EINA_FALSE;
2431    return wd->single_line;
2432 }
2433
2434 EAPI void
2435 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2436 {
2437    ELM_CHECK_WIDTYPE(obj, widtype);
2438    Widget_Data *wd = elm_widget_data_get(obj);
2439    if (!wd) return;
2440    if (wd->password == password) return;
2441    wd->password = password;
2442    if (password)
2443      {
2444         wd->single_line = EINA_TRUE;
2445         wd->linewrap = ELM_WRAP_NONE;
2446 #ifdef HAVE_ELEMENTARY_X
2447         elm_drop_target_del(obj);
2448 #endif
2449         edje_object_signal_callback_del_full(wd->ent, "selection,start", "elm.text",
2450                                         _signal_selection_start, obj);
2451         edje_object_signal_callback_del_full(wd->ent, "selection,changed", "elm.text",
2452                                         _signal_selection_changed, obj);
2453         edje_object_signal_callback_del_full(wd->ent, "entry,selection,all,request", "elm.text",
2454                                         _signal_selection_all, obj);
2455         edje_object_signal_callback_del_full(wd->ent, "entry,selection,none,request", "elm.text",
2456                                         _signal_selection_none, obj);
2457         edje_object_signal_callback_del_full(wd->ent, "selection,cleared", "elm.text",
2458                                         _signal_selection_cleared, obj);
2459         edje_object_signal_callback_del_full(wd->ent, "entry,paste,request,*", "elm.text",
2460                                         _signal_entry_paste_request, obj);
2461         edje_object_signal_callback_del_full(wd->ent, "entry,copy,notify", "elm.text",
2462                                         _signal_entry_copy_notify, obj);
2463         edje_object_signal_callback_del_full(wd->ent, "entry,cut,notify", "elm.text",
2464                                         _signal_entry_cut_notify, obj);
2465      }
2466    else
2467      {
2468 #ifdef HAVE_ELEMENTARY_X
2469         elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2470 #endif
2471         edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
2472                                         _signal_selection_start, obj);
2473         edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
2474                                         _signal_selection_changed, obj);
2475         edje_object_signal_callback_add(wd->ent, "entry,selection,all,request", "elm.text",
2476                                         _signal_selection_all, obj);
2477         edje_object_signal_callback_add(wd->ent, "entry,selection,none,request", "elm.text",
2478                                         _signal_selection_none, obj);
2479         edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2480                                         _signal_selection_cleared, obj);
2481         edje_object_signal_callback_add(wd->ent, "entry,paste,request,*", "elm.text",
2482                                         _signal_entry_paste_request, obj);
2483         edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2484                                         _signal_entry_copy_notify, obj);
2485         edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2486                                         _signal_entry_cut_notify, obj);
2487      }
2488    _theme_hook(obj);
2489 }
2490
2491 EAPI Eina_Bool
2492 elm_entry_password_get(const Evas_Object *obj)
2493 {
2494    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2495    Widget_Data *wd = elm_widget_data_get(obj);
2496    if (!wd) return EINA_FALSE;
2497    return wd->password;
2498 }
2499
2500 EAPI void
2501 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2502 {
2503    _elm_entry_text_set(obj, NULL, entry);
2504 }
2505
2506 EAPI const char *
2507 elm_entry_entry_get(const Evas_Object *obj)
2508 {
2509    return _elm_entry_text_get(obj, NULL);
2510 }
2511
2512 EAPI void
2513 elm_entry_entry_append(Evas_Object *obj, const char *entry)
2514 {
2515    int len = 0;
2516    ELM_CHECK_WIDTYPE(obj, widtype);
2517    Widget_Data *wd = elm_widget_data_get(obj);
2518    if (!wd) return;
2519    if (!entry) entry = "";
2520    wd->changed = EINA_TRUE;
2521
2522    len = strlen(entry);
2523    if (wd->append_text_left)
2524      {
2525         char *tmpbuf;
2526         tmpbuf = realloc(wd->append_text_left, wd->append_text_len + len + 1);
2527         if (!tmpbuf)
2528           {
2529              /* Do something */
2530              return;
2531           }
2532         wd->append_text_left = tmpbuf;
2533         memcpy(wd->append_text_left + wd->append_text_len, entry, len + 1);
2534         wd->append_text_len += len;
2535      }
2536    else
2537      {
2538         /* FIXME: Add chunked appending here (like in entry_set) */
2539         edje_object_part_text_append(wd->ent, "elm.text", entry);
2540      }
2541 }
2542
2543 EAPI Eina_Bool
2544 elm_entry_is_empty(const Evas_Object *obj)
2545 {
2546    /* FIXME: until there's support for that in textblock, we just check
2547     * to see if the there is text or not. */
2548    ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
2549    Widget_Data *wd = elm_widget_data_get(obj);
2550    const Evas_Object *tb;
2551    Evas_Textblock_Cursor *cur;
2552    Eina_Bool ret;
2553    if (!wd) return EINA_TRUE;
2554    /* It's a hack until we get the support suggested above.
2555     * We just create a cursor, point it to the begining, and then
2556     * try to advance it, if it can advance, the tb is not empty,
2557     * otherwise it is. */
2558    tb = edje_object_part_object_get(wd->ent, "elm.text");
2559    cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
2560                                                                   actually, ok for the time being, thsese hackish stuff will be removed
2561                                                                   once evas 1.0 is out*/
2562    evas_textblock_cursor_pos_set(cur, 0);
2563    ret = evas_textblock_cursor_char_next(cur);
2564    evas_textblock_cursor_free(cur);
2565
2566    return !ret;
2567 }
2568
2569 EAPI Evas_Object *
2570 elm_entry_textblock_get(Evas_Object *obj)
2571 {
2572    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2573    Widget_Data *wd = elm_widget_data_get(obj);
2574    if (!wd) return NULL;
2575
2576    return (Evas_Object *) edje_object_part_object_get(wd->ent, "elm.text");
2577 }
2578
2579 EAPI void
2580 elm_entry_calc_force(Evas_Object *obj)
2581 {
2582    ELM_CHECK_WIDTYPE(obj, widtype);
2583    Widget_Data *wd = elm_widget_data_get(obj);
2584    if (!wd) return;
2585
2586    edje_object_calc_force(wd->ent);
2587    wd->changed = EINA_TRUE;
2588    _sizing_eval(obj);
2589 }
2590
2591
2592 EAPI const char *
2593 elm_entry_selection_get(const Evas_Object *obj)
2594 {
2595    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2596    Widget_Data *wd = elm_widget_data_get(obj);
2597    if ((!wd) || (wd->password)) return NULL;
2598    return edje_object_part_text_selection_get(wd->ent, "elm.text");
2599 }
2600
2601 EAPI void
2602 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2603 {
2604    ELM_CHECK_WIDTYPE(obj, widtype);
2605    Widget_Data *wd = elm_widget_data_get(obj);
2606    if (!wd) return;
2607    edje_object_part_text_insert(wd->ent, "elm.text", entry);
2608    wd->changed = EINA_TRUE;
2609    _sizing_eval(obj);
2610 }
2611
2612 EAPI void
2613 elm_entry_line_wrap_set(Evas_Object *obj, Elm_Wrap_Type wrap)
2614 {
2615    ELM_CHECK_WIDTYPE(obj, widtype);
2616    Widget_Data *wd = elm_widget_data_get(obj);
2617    if (!wd) return;
2618    if (wd->linewrap == wrap) return;
2619    wd->lastw = -1;
2620    wd->linewrap = wrap;
2621    _theme_hook(obj);
2622 }
2623
2624 EAPI Elm_Wrap_Type
2625 elm_entry_line_wrap_get(const Evas_Object *obj)
2626 {
2627    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2628    Widget_Data *wd = elm_widget_data_get(obj);
2629    if (!wd) return EINA_FALSE;
2630    return wd->linewrap;
2631 }
2632
2633 EAPI void
2634 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2635 {
2636    ELM_CHECK_WIDTYPE(obj, widtype);
2637    Widget_Data *wd = elm_widget_data_get(obj);
2638    if (!wd) return;
2639    if (wd->editable == editable) return;
2640    wd->editable = editable;
2641    _theme_hook(obj);
2642
2643 #ifdef HAVE_ELEMENTARY_X
2644    if (editable)
2645      elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2646    else
2647      elm_drop_target_del(obj);
2648 #endif
2649 }
2650
2651 EAPI Eina_Bool
2652 elm_entry_editable_get(const Evas_Object *obj)
2653 {
2654    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2655    Widget_Data *wd = elm_widget_data_get(obj);
2656    if (!wd) return EINA_FALSE;
2657    return wd->editable;
2658 }
2659
2660 EAPI void
2661 elm_entry_select_none(Evas_Object *obj)
2662 {
2663    ELM_CHECK_WIDTYPE(obj, widtype);
2664    Widget_Data *wd = elm_widget_data_get(obj);
2665    if ((!wd) || (wd->password)) return;
2666    if (wd->selmode)
2667      {
2668         wd->selmode = EINA_FALSE;
2669         if (!_elm_config->desktop_entry)
2670           edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2671         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2672      }
2673    wd->have_selection = EINA_FALSE;
2674    edje_object_part_text_select_none(wd->ent, "elm.text");
2675 }
2676
2677 EAPI void
2678 elm_entry_select_all(Evas_Object *obj)
2679 {
2680    ELM_CHECK_WIDTYPE(obj, widtype);
2681    Widget_Data *wd = elm_widget_data_get(obj);
2682    if ((!wd) || (wd->password)) return;
2683    if (wd->selmode)
2684      {
2685         wd->selmode = EINA_FALSE;
2686         if (!_elm_config->desktop_entry)
2687           edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2688         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2689      }
2690    wd->have_selection = EINA_TRUE;
2691    edje_object_part_text_select_all(wd->ent, "elm.text");
2692 }
2693
2694 EAPI Eina_Bool
2695 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
2696 {
2697    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2698    Widget_Data *wd = elm_widget_data_get(obj);
2699    if (!wd) return EINA_FALSE;
2700    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
2701    return EINA_TRUE;
2702 }
2703
2704 EAPI Eina_Bool
2705 elm_entry_cursor_next(Evas_Object *obj)
2706 {
2707    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2708    Widget_Data *wd = elm_widget_data_get(obj);
2709    if (!wd) return EINA_FALSE;
2710    return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2711 }
2712
2713 EAPI Eina_Bool
2714 elm_entry_cursor_prev(Evas_Object *obj)
2715 {
2716    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2717    Widget_Data *wd = elm_widget_data_get(obj);
2718    if (!wd) return EINA_FALSE;
2719    return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2720 }
2721
2722 EAPI Eina_Bool
2723 elm_entry_cursor_up(Evas_Object *obj)
2724 {
2725    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2726    Widget_Data *wd = elm_widget_data_get(obj);
2727    if (!wd) return EINA_FALSE;
2728    return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2729 }
2730
2731 EAPI Eina_Bool
2732 elm_entry_cursor_down(Evas_Object *obj)
2733 {
2734    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2735    Widget_Data *wd = elm_widget_data_get(obj);
2736    if (!wd) return EINA_FALSE;
2737    return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2738 }
2739
2740 EAPI void
2741 elm_entry_cursor_begin_set(Evas_Object *obj)
2742 {
2743    ELM_CHECK_WIDTYPE(obj, widtype);
2744    Widget_Data *wd = elm_widget_data_get(obj);
2745    if (!wd) return;
2746    edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2747 }
2748
2749 EAPI void
2750 elm_entry_cursor_end_set(Evas_Object *obj)
2751 {
2752    ELM_CHECK_WIDTYPE(obj, widtype);
2753    Widget_Data *wd = elm_widget_data_get(obj);
2754    if (!wd) return;
2755    int x, y, w, h;
2756    x = y = w = h = 1;
2757    edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2758    if (wd->scroll)
2759      {
2760         elm_widget_show_region_get(obj, &x, &y, &w, &h);
2761         elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
2762      }
2763 }
2764
2765 EAPI void
2766 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2767 {
2768    ELM_CHECK_WIDTYPE(obj, widtype);
2769    Widget_Data *wd = elm_widget_data_get(obj);
2770    if (!wd) return;
2771    edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2772 }
2773
2774 EAPI void
2775 elm_entry_cursor_line_end_set(Evas_Object *obj)
2776 {
2777    ELM_CHECK_WIDTYPE(obj, widtype);
2778    Widget_Data *wd = elm_widget_data_get(obj);
2779    if (!wd) return;
2780    edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2781 }
2782
2783 EAPI void
2784 elm_entry_cursor_selection_begin(Evas_Object *obj)
2785 {
2786    ELM_CHECK_WIDTYPE(obj, widtype);
2787    Widget_Data *wd = elm_widget_data_get(obj);
2788    if (!wd) return;
2789    edje_object_part_text_select_begin(wd->ent, "elm.text");
2790 }
2791
2792 EAPI void
2793 elm_entry_cursor_selection_end(Evas_Object *obj)
2794 {
2795    ELM_CHECK_WIDTYPE(obj, widtype);
2796    Widget_Data *wd = elm_widget_data_get(obj);
2797    if (!wd) return;
2798    edje_object_part_text_select_extend(wd->ent, "elm.text");
2799 }
2800
2801 EAPI Eina_Bool
2802 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2803 {
2804    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2805    Widget_Data *wd = elm_widget_data_get(obj);
2806    if (!wd) return EINA_FALSE;
2807    return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2808 }
2809
2810 EAPI Eina_Bool
2811 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2812 {
2813    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2814    Widget_Data *wd = elm_widget_data_get(obj);
2815    if (!wd) return EINA_FALSE;
2816    return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2817 }
2818
2819 EAPI char *
2820 elm_entry_cursor_content_get(const Evas_Object *obj)
2821 {
2822    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2823    Widget_Data *wd = elm_widget_data_get(obj);
2824    if (!wd) return NULL;
2825    return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2826 }
2827
2828 EAPI void
2829 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
2830 {
2831    ELM_CHECK_WIDTYPE(obj, widtype);
2832    Widget_Data *wd = elm_widget_data_get(obj);
2833    if (!wd) return;
2834    edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
2835    edje_object_message_signal_process(wd->ent);
2836 }
2837
2838 EAPI int
2839 elm_entry_cursor_pos_get(const Evas_Object *obj)
2840 {
2841    ELM_CHECK_WIDTYPE(obj, widtype) 0;
2842    Widget_Data *wd = elm_widget_data_get(obj);
2843    if (!wd) return 0;
2844    return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2845 }
2846
2847 EAPI void
2848 elm_entry_selection_cut(Evas_Object *obj)
2849 {
2850    ELM_CHECK_WIDTYPE(obj, widtype);
2851    Widget_Data *wd = elm_widget_data_get(obj);
2852    if ((!wd) || (wd->password)) return;
2853    _cut(obj, NULL, NULL);
2854 }
2855
2856 EAPI void
2857 elm_entry_selection_copy(Evas_Object *obj)
2858 {
2859    ELM_CHECK_WIDTYPE(obj, widtype);
2860    Widget_Data *wd = elm_widget_data_get(obj);
2861    if ((!wd) || (wd->password)) return;
2862    _copy(obj, NULL, NULL);
2863 }
2864
2865 EAPI void
2866 elm_entry_selection_paste(Evas_Object *obj)
2867 {
2868    ELM_CHECK_WIDTYPE(obj, widtype);
2869    Widget_Data *wd = elm_widget_data_get(obj);
2870    if ((!wd) || (wd->password)) return;
2871    _paste(obj, NULL, NULL);
2872 }
2873
2874 EAPI void
2875 elm_entry_context_menu_clear(Evas_Object *obj)
2876 {
2877    ELM_CHECK_WIDTYPE(obj, widtype);
2878    Widget_Data *wd = elm_widget_data_get(obj);
2879    Elm_Entry_Context_Menu_Item *it;
2880    if (!wd) return;
2881    EINA_LIST_FREE(wd->items, it)
2882      {
2883         eina_stringshare_del(it->label);
2884         eina_stringshare_del(it->icon_file);
2885         eina_stringshare_del(it->icon_group);
2886         free(it);
2887      }
2888 }
2889
2890 EAPI void
2891 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)
2892 {
2893    ELM_CHECK_WIDTYPE(obj, widtype);
2894    Widget_Data *wd = elm_widget_data_get(obj);
2895    Elm_Entry_Context_Menu_Item *it;
2896    if (!wd) return;
2897    it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2898    if (!it) return;
2899    wd->items = eina_list_append(wd->items, it);
2900    it->obj = obj;
2901    it->label = eina_stringshare_add(label);
2902    it->icon_file = eina_stringshare_add(icon_file);
2903    it->icon_type = icon_type;
2904    it->func = func;
2905    it->data = (void *)data;
2906 }
2907
2908 EAPI void
2909 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2910 {
2911    ELM_CHECK_WIDTYPE(obj, widtype);
2912    Widget_Data *wd = elm_widget_data_get(obj);
2913    if (!wd) return;
2914    if (wd->context_menu == !disabled) return;
2915    wd->context_menu = !disabled;
2916 }
2917
2918 EAPI Eina_Bool
2919 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2920 {
2921    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2922    Widget_Data *wd = elm_widget_data_get(obj);
2923    if (!wd) return EINA_FALSE;
2924    return !wd->context_menu;
2925 }
2926
2927 EAPI void
2928 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2929 {
2930    ELM_CHECK_WIDTYPE(obj, widtype);
2931    Widget_Data *wd = elm_widget_data_get(obj);
2932    if (!wd) return;
2933    EINA_SAFETY_ON_NULL_RETURN(func);
2934    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2935    if (!ip) return;
2936    ip->func = func;
2937    ip->data = data;
2938    wd->item_providers = eina_list_append(wd->item_providers, ip);
2939 }
2940
2941 EAPI void
2942 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2943 {
2944    ELM_CHECK_WIDTYPE(obj, widtype);
2945    Widget_Data *wd = elm_widget_data_get(obj);
2946    if (!wd) return;
2947    EINA_SAFETY_ON_NULL_RETURN(func);
2948    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2949    if (!ip) return;
2950    ip->func = func;
2951    ip->data = data;
2952    wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2953 }
2954
2955 EAPI void
2956 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2957 {
2958    ELM_CHECK_WIDTYPE(obj, widtype);
2959    Widget_Data *wd = elm_widget_data_get(obj);
2960    Eina_List *l;
2961    Elm_Entry_Item_Provider *ip;
2962    if (!wd) return;
2963    EINA_SAFETY_ON_NULL_RETURN(func);
2964    EINA_LIST_FOREACH(wd->item_providers, l, ip)
2965      {
2966         if ((ip->func == func) && ((!data) || (ip->data == data)))
2967           {
2968              wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2969              free(ip);
2970              return;
2971           }
2972      }
2973 }
2974
2975 EAPI void
2976 elm_entry_text_filter_append(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
2977 {
2978    Widget_Data *wd;
2979    Elm_Entry_Text_Filter *tf;
2980    ELM_CHECK_WIDTYPE(obj, widtype);
2981
2982    wd = elm_widget_data_get(obj);
2983
2984    EINA_SAFETY_ON_NULL_RETURN(func);
2985
2986    tf = _filter_new(func, data);
2987    if (!tf) return;
2988
2989    wd->text_filters = eina_list_append(wd->text_filters, tf);
2990 }
2991
2992 EAPI void
2993 elm_entry_text_filter_prepend(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
2994 {
2995    Widget_Data *wd;
2996    Elm_Entry_Text_Filter *tf;
2997    ELM_CHECK_WIDTYPE(obj, widtype);
2998
2999    wd = elm_widget_data_get(obj);
3000
3001    EINA_SAFETY_ON_NULL_RETURN(func);
3002
3003    tf = _filter_new(func, data);
3004    if (!tf) return;
3005
3006    wd->text_filters = eina_list_prepend(wd->text_filters, tf);
3007 }
3008
3009 EAPI void
3010 elm_entry_text_filter_remove(Evas_Object *obj, Elm_Entry_Filter_Cb func, void *data)
3011 {
3012    Widget_Data *wd;
3013    Eina_List *l;
3014    Elm_Entry_Text_Filter *tf;
3015    ELM_CHECK_WIDTYPE(obj, widtype);
3016
3017    wd = elm_widget_data_get(obj);
3018
3019    EINA_SAFETY_ON_NULL_RETURN(func);
3020
3021    EINA_LIST_FOREACH(wd->text_filters, l, tf)
3022      {
3023         if ((tf->func == func) && ((!data) || (tf->data == data)))
3024           {
3025              wd->text_filters = eina_list_remove_list(wd->text_filters, l);
3026              _filter_free(tf);
3027              return;
3028           }
3029      }
3030 }
3031
3032 EAPI char *
3033 elm_entry_markup_to_utf8(const char *s)
3034 {
3035    char *ss = _elm_util_mkup_to_text(s);
3036    if (!ss) ss = strdup("");
3037    return ss;
3038 }
3039
3040 EAPI char *
3041 elm_entry_utf8_to_markup(const char *s)
3042 {
3043    char *ss = _elm_util_text_to_mkup(s);
3044    if (!ss) ss = strdup("");
3045    return ss;
3046 }
3047
3048 static const char *
3049 _text_get(const Evas_Object *obj)
3050 {
3051    return elm_object_text_get(obj);
3052 }
3053
3054 EAPI void
3055 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
3056 {
3057    Elm_Entry_Filter_Limit_Size *lim = data;
3058    char *current, *utfstr;
3059    int len, newlen;
3060    const char *(*text_get)(const Evas_Object *);
3061
3062    EINA_SAFETY_ON_NULL_RETURN(data);
3063    EINA_SAFETY_ON_NULL_RETURN(entry);
3064    EINA_SAFETY_ON_NULL_RETURN(text);
3065
3066    /* hack. I don't want to copy the entire function to work with
3067     * scrolled_entry */
3068    text_get = _text_get;
3069
3070    current = elm_entry_markup_to_utf8(text_get(entry));
3071    utfstr = elm_entry_markup_to_utf8(*text);
3072
3073    if (lim->max_char_count > 0)
3074      {
3075         len = evas_string_char_len_get(current);
3076         if (len >= lim->max_char_count)
3077           {
3078              evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3079              free(*text);
3080              *text = NULL;
3081              free(current);
3082              free(utfstr);
3083              return;
3084           }
3085         newlen = evas_string_char_len_get(utfstr);
3086         if ((len + newlen) > lim->max_char_count)
3087           _add_chars_till_limit(entry, text, (lim->max_char_count - len), LENGTH_UNIT_CHAR);
3088      }
3089    else if (lim->max_byte_count > 0)
3090      {
3091         len = strlen(current);
3092         if (len >= lim->max_byte_count)
3093           {
3094              evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3095              free(*text);
3096              *text = NULL;
3097              free(current);
3098              free(utfstr);
3099              return;
3100           }
3101         newlen = strlen(utfstr);
3102         if ((len + newlen) > lim->max_byte_count)
3103           _add_chars_till_limit(entry, text, (lim->max_byte_count - len), LENGTH_UNIT_BYTE);
3104      }
3105    free(current);
3106    free(utfstr);
3107 }
3108
3109 EAPI void
3110 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
3111 {
3112    Elm_Entry_Filter_Accept_Set *as = data;
3113    const char *set;
3114    char *insert;
3115    Eina_Bool goes_in;
3116    int read_idx, last_read_idx = 0, read_char;
3117
3118    EINA_SAFETY_ON_NULL_RETURN(data);
3119    EINA_SAFETY_ON_NULL_RETURN(text);
3120
3121    if ((!as->accepted) && (!as->rejected))
3122      return;
3123
3124    if (as->accepted)
3125      {
3126         set = as->accepted;
3127         goes_in = EINA_TRUE;
3128      }
3129    else
3130      {
3131         set = as->rejected;
3132         goes_in = EINA_FALSE;
3133      }
3134
3135    insert = *text;
3136    read_idx = evas_string_char_next_get(*text, 0, &read_char);
3137    while (read_char)
3138      {
3139         int cmp_idx, cmp_char;
3140         Eina_Bool in_set = EINA_FALSE;
3141
3142         cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
3143         while (cmp_char)
3144           {
3145              if (read_char == cmp_char)
3146                {
3147                   in_set = EINA_TRUE;
3148                   break;
3149                }
3150              cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
3151           }
3152         if (in_set == goes_in)
3153           {
3154              int size = read_idx - last_read_idx;
3155              const char *src = (*text) + last_read_idx;
3156              if (src != insert)
3157                memcpy(insert, *text + last_read_idx, size);
3158              insert += size;
3159           }
3160         last_read_idx = read_idx;
3161         read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
3162      }
3163    *insert = 0;
3164 }
3165
3166 EAPI void
3167 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
3168 {
3169    ELM_CHECK_WIDTYPE(obj, widtype);
3170    Widget_Data *wd = elm_widget_data_get(obj);
3171    if (!wd) return;
3172    if (wd->delay_write)
3173      {
3174         ecore_timer_del(wd->delay_write);
3175         wd->delay_write = NULL;
3176      }
3177    if (wd->autosave) _save(obj);
3178    eina_stringshare_replace(&wd->file, file);
3179    wd->format = format;
3180    _load(obj);
3181 }
3182
3183 EAPI void
3184 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
3185 {
3186    ELM_CHECK_WIDTYPE(obj, widtype);
3187    Widget_Data *wd = elm_widget_data_get(obj);
3188    if (!wd) return;
3189    if (file) *file = wd->file;
3190    if (format) *format = wd->format;
3191 }
3192
3193 EAPI void
3194 elm_entry_file_save(Evas_Object *obj)
3195 {
3196    ELM_CHECK_WIDTYPE(obj, widtype);
3197    Widget_Data *wd = elm_widget_data_get(obj);
3198    if (!wd) return;
3199    if (wd->delay_write)
3200      {
3201         ecore_timer_del(wd->delay_write);
3202         wd->delay_write = NULL;
3203      }
3204    _save(obj);
3205    wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
3206 }
3207
3208 EAPI void
3209 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
3210 {
3211    ELM_CHECK_WIDTYPE(obj, widtype);
3212    Widget_Data *wd = elm_widget_data_get(obj);
3213    if (!wd) return;
3214    wd->autosave = !!autosave;
3215 }
3216
3217 EAPI Eina_Bool
3218 elm_entry_autosave_get(const Evas_Object *obj)
3219 {
3220    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3221    Widget_Data *wd = elm_widget_data_get(obj);
3222    if (!wd) return EINA_FALSE;
3223    return wd->autosave;
3224 }
3225
3226 EAPI void
3227 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
3228 {
3229    Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
3230    ELM_CHECK_WIDTYPE(obj, widtype);
3231    Widget_Data *wd = elm_widget_data_get(obj);
3232    if (!wd) return;
3233    textonly = !!textonly;
3234    if (wd->textonly == textonly) return;
3235    wd->textonly = !!textonly;
3236    if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
3237 #ifdef HAVE_ELEMENTARY_X
3238    elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
3239 #endif
3240 }
3241
3242 EAPI Eina_Bool
3243 elm_entry_cnp_textonly_get(const Evas_Object *obj)
3244 {
3245    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3246    Widget_Data *wd = elm_widget_data_get(obj);
3247    if (!wd) return EINA_FALSE;
3248    return wd->textonly;
3249 }
3250
3251 EAPI void
3252 elm_entry_scrollable_set(Evas_Object *obj, Eina_Bool scroll)
3253 {
3254    ELM_CHECK_WIDTYPE(obj, widtype);
3255    Widget_Data *wd = elm_widget_data_get(obj);
3256    const Elm_Scroller_Policy map[3] =
3257      {
3258         ELM_SMART_SCROLLER_POLICY_AUTO,
3259         ELM_SMART_SCROLLER_POLICY_ON,
3260         ELM_SMART_SCROLLER_POLICY_OFF
3261      };
3262    if (!wd) return;
3263    scroll = !!scroll;
3264    if (wd->scroll == scroll) return;
3265    wd->scroll = scroll;
3266    if (wd->scroll)
3267      {
3268         if (!wd->scroller)
3269           {
3270              wd->scroller = elm_smart_scroller_add(evas_object_evas_get(obj));
3271              elm_widget_resize_object_set(obj, wd->scroller);
3272              elm_smart_scroller_widget_set(wd->scroller, obj);
3273              elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
3274                                                  elm_widget_style_get(obj));
3275              evas_object_size_hint_weight_set(wd->scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
3276              evas_object_size_hint_align_set(wd->scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
3277              evas_object_propagate_events_set(wd->scroller, EINA_TRUE);
3278              evas_object_propagate_events_set(elm_smart_scroller_edje_object_get(wd->scroller),
3279                                               EINA_TRUE);
3280           }
3281         elm_smart_scroller_bounce_allow_set(wd->scroller, wd->h_bounce, wd->v_bounce);
3282         if (wd->single_line)
3283           elm_smart_scroller_policy_set(wd->scroller, ELM_SMART_SCROLLER_POLICY_OFF,
3284                                         ELM_SMART_SCROLLER_POLICY_OFF);
3285         else
3286           elm_smart_scroller_policy_set(wd->scroller, map[wd->policy_h], map[wd->policy_v]);
3287         elm_widget_sub_object_add(obj, wd->ent);
3288         elm_smart_scroller_child_set(wd->scroller, wd->ent);
3289         evas_object_show(wd->scroller);
3290         elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
3291      }
3292    else
3293      {
3294         if (wd->scroller)
3295           {
3296              elm_smart_scroller_child_set(wd->scroller, NULL);
3297              evas_object_smart_member_add(wd->scroller, obj);
3298              elm_widget_sub_object_add(obj, wd->scroller);
3299              evas_object_hide(wd->scroller);
3300           }
3301         elm_widget_sub_object_del(obj, wd->ent);
3302         elm_widget_resize_object_set(obj, wd->ent);
3303         elm_widget_on_show_region_hook_set(obj, NULL, NULL);
3304      }
3305    wd->lastw = -1;
3306    _theme_hook(obj);
3307 }
3308
3309 EAPI Eina_Bool
3310 elm_entry_scrollable_get(const Evas_Object *obj)
3311 {
3312    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3313    Widget_Data *wd = elm_widget_data_get(obj);
3314    if (!wd) return EINA_FALSE;
3315    return wd->scroll;
3316 }
3317
3318 EAPI void
3319 elm_entry_icon_set(Evas_Object *obj, Evas_Object *icon)
3320 {
3321    ELM_CHECK_WIDTYPE(obj, widtype);
3322    EINA_SAFETY_ON_NULL_RETURN(icon);
3323    _content_set_hook(obj, NULL, icon);
3324 }
3325
3326 EAPI Evas_Object *
3327 elm_entry_icon_get(const Evas_Object *obj)
3328 {
3329    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3330    return _content_get_hook(obj, NULL);
3331 }
3332
3333 EAPI Evas_Object *
3334 elm_entry_icon_unset(Evas_Object *obj)
3335 {
3336    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3337    return _content_unset_hook(obj, NULL);
3338 }
3339
3340 EAPI void
3341 elm_entry_icon_visible_set(Evas_Object *obj, Eina_Bool setting)
3342 {
3343    ELM_CHECK_WIDTYPE(obj, widtype);
3344    Widget_Data *wd = elm_widget_data_get(obj);
3345    Evas_Object *edje;
3346    if (!wd) return;
3347    if (wd->scroll)
3348       edje = elm_smart_scroller_edje_object_get(wd->scroller);
3349    else
3350       edje = wd->ent;
3351
3352    if ((!edje) || (!edje_object_part_swallow_get(edje, "elm.swallow.icon"))) return;
3353    if (setting)
3354      edje_object_signal_emit(edje, "elm,action,show,icon", "elm");
3355    else
3356      edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
3357    _sizing_eval(obj);
3358 }
3359
3360 EAPI void
3361 elm_entry_end_set(Evas_Object *obj, Evas_Object *end)
3362 {
3363    ELM_CHECK_WIDTYPE(obj, widtype);
3364    EINA_SAFETY_ON_NULL_RETURN(end);
3365    _content_set_hook(obj, "end", end);
3366 }
3367
3368 EAPI Evas_Object *
3369 elm_entry_end_get(const Evas_Object *obj)
3370 {
3371    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3372    return _content_get_hook(obj, "end");
3373 }
3374
3375 EAPI Evas_Object *
3376 elm_entry_end_unset(Evas_Object *obj)
3377 {
3378    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3379    return _content_unset_hook(obj, "end");
3380 }
3381
3382 EAPI void
3383 elm_entry_end_visible_set(Evas_Object *obj, Eina_Bool setting)
3384 {
3385    ELM_CHECK_WIDTYPE(obj, widtype);
3386    Widget_Data *wd = elm_widget_data_get(obj);
3387    Evas_Object *edje;
3388    if (!wd) return;
3389    if (wd->scroll)
3390       edje = elm_smart_scroller_edje_object_get(wd->scroller);
3391    else
3392       edje = wd->ent;
3393
3394    if ((!edje) || (!edje_object_part_swallow_get(edje, "elm.swallow.icon"))) return;
3395    if (setting)
3396      edje_object_signal_emit(edje, "elm,action,show,end", "elm");
3397    else
3398      edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
3399    _sizing_eval(obj);
3400 }
3401
3402 EAPI void
3403 elm_entry_scrollbar_policy_set(Evas_Object *obj, Elm_Scroller_Policy h, Elm_Scroller_Policy v)
3404 {
3405    ELM_CHECK_WIDTYPE(obj, widtype);
3406    Widget_Data *wd = elm_widget_data_get(obj);
3407    const Elm_Scroller_Policy map[3] =
3408      {
3409         ELM_SMART_SCROLLER_POLICY_AUTO,
3410         ELM_SMART_SCROLLER_POLICY_ON,
3411         ELM_SMART_SCROLLER_POLICY_OFF
3412      };
3413    if (!wd) return;
3414    wd->policy_h = h;
3415    wd->policy_v = v;
3416    elm_smart_scroller_policy_set(wd->scroller,
3417                                  map[wd->policy_h],
3418                                  map[wd->policy_v]);
3419 }
3420
3421 EAPI void
3422 elm_entry_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
3423 {
3424    ELM_CHECK_WIDTYPE(obj, widtype);
3425    Widget_Data *wd = elm_widget_data_get(obj);
3426    if (!wd) return;
3427    wd->h_bounce = h_bounce;
3428    wd->v_bounce = v_bounce;
3429    elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
3430 }
3431
3432 EAPI void
3433 elm_entry_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
3434 {
3435    ELM_CHECK_WIDTYPE(obj, widtype);
3436    Widget_Data *wd = elm_widget_data_get(obj);
3437    if (!wd) return;
3438    elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
3439 }
3440
3441 EAPI void
3442 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
3443 {
3444    ELM_CHECK_WIDTYPE(obj, widtype);
3445    Widget_Data *wd = elm_widget_data_get(obj);
3446    if (!wd) return;
3447
3448    wd->input_panel_layout = layout;
3449
3450    edje_object_part_text_input_panel_layout_set(wd->ent, "elm.text", layout);
3451 }
3452
3453 EAPI Elm_Input_Panel_Layout
3454 elm_entry_input_panel_layout_get(Evas_Object *obj)
3455 {
3456    ELM_CHECK_WIDTYPE(obj, widtype) ELM_INPUT_PANEL_LAYOUT_INVALID;
3457    Widget_Data *wd = elm_widget_data_get(obj);
3458    if (!wd) return ELM_INPUT_PANEL_LAYOUT_INVALID;
3459
3460    return wd->input_panel_layout;
3461 }
3462
3463 EAPI void
3464 elm_entry_autocapital_type_set(Evas_Object *obj, Elm_Autocapital_Type autocapital_type)
3465 {
3466    ELM_CHECK_WIDTYPE(obj, widtype);
3467    Widget_Data *wd = elm_widget_data_get(obj);
3468    if (!wd) return;
3469
3470    wd->autocapital_type = autocapital_type;
3471    edje_object_part_text_autocapital_type_set(wd->ent, "elm.text", autocapital_type);
3472 }
3473
3474 EAPI Elm_Autocapital_Type
3475 elm_entry_autocapital_type_get(Evas_Object *obj)
3476 {
3477    ELM_CHECK_WIDTYPE(obj, widtype) ELM_AUTOCAPITAL_TYPE_NONE;
3478    Widget_Data *wd = elm_widget_data_get(obj);
3479    if (!wd) return ELM_AUTOCAPITAL_TYPE_NONE;
3480
3481    return wd->autocapital_type;
3482 }
3483
3484 EAPI void
3485 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
3486 {
3487    ELM_CHECK_WIDTYPE(obj, widtype);
3488    Widget_Data *wd = elm_widget_data_get(obj);
3489    if (!wd) return;
3490
3491    wd->input_panel_enable = enabled;
3492    edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
3493 }
3494