[*][Patch for EFL core migration] Merge branch 'efl_core'
[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 "elm_module_priv.h"
5
6 /**
7  * @defgroup Entry Entry
8  *
9  * An entry is a convenience widget which shows
10  * a box that the user can enter text into.  Unlike a
11  * @ref Scrolled_Entry widget, entries DO NOT scroll with user
12  * input.  Entry widgets are capable of expanding past the
13  * boundaries of the window, thus resizing the window to its
14  * own length.
15  *
16  * You can also insert "items" in the entry with:
17  *
18  * \<item size=16x16 vsize=full href=emoticon/haha\>\</item\>
19  *
20  * for example. sizing can be set bu size=WxH, relsize=WxH or absize=WxH with
21  * vsize=ascent or vsize=full. the href=NAME sets the item name. Entry
22  * supports a list of emoticon names by default. These are:
23  *
24  * - emoticon/angry
25  * - emoticon/angry-shout
26  * - emoticon/crazy-laugh
27  * - emoticon/evil-laugh
28  * - emoticon/evil
29  * - emoticon/goggle-smile
30  * - emoticon/grumpy
31  * - emoticon/grumpy-smile
32  * - emoticon/guilty
33  * - emoticon/guilty-smile
34  * - emoticon/haha
35  * - emoticon/half-smile
36  * - emoticon/happy-panting
37  * - emoticon/happy
38  * - emoticon/indifferent
39  * - emoticon/kiss
40  * - emoticon/knowing-grin
41  * - emoticon/laugh
42  * - emoticon/little-bit-sorry
43  * - emoticon/love-lots
44  * - emoticon/love
45  * - emoticon/minimal-smile
46  * - emoticon/not-happy
47  * - emoticon/not-impressed
48  * - emoticon/omg
49  * - emoticon/opensmile
50  * - emoticon/smile
51  * - emoticon/sorry
52  * - emoticon/squint-laugh
53  * - emoticon/surprised
54  * - emoticon/suspicious
55  * - emoticon/tongue-dangling
56  * - emoticon/tongue-poke
57  * - emoticon/uh
58  * - emoticon/unhappy
59  * - emoticon/very-sorry
60  * - emoticon/what
61  * - emoticon/wink
62  * - emoticon/worried
63  * - emoticon/wtf
64  *
65  * These are built-in currently, but you can add your own item provieer that
66  * can create inlined objects in the text and fill the space allocated to the
67  * item with a custom object of your own.
68  *
69  * See the entry test for some more examples of use of this.
70  *
71  * Entries have functions to load a text file, display it,
72  * allowing editing of it and saving of changes back to the file loaded.
73  * Changes are written back to the original file after a short delay.
74  * The file to load and save to is specified by elm_entry_file_set().
75  *
76  * Signals that you can add callbacks for are:
77  *
78  * "changed" - The text within the entry was changed
79  * "activated" - The entry has had editing finished and changes are to be committed
80                  (generally when enter key is pressed)
81  * "press" - The entry has been clicked
82  * "longpressed" - The entry has been clicked for a couple seconds
83  * "clicked" - The entry has been clicked
84  * "clicked,double" - The entry has been double clicked
85  * "focused" - The entry has received focus
86  * "unfocused" - The entry has lost focus
87  * "selection,paste" - A paste action has occurred
88  * "selection,copy" - A copy action has occurred
89  * "selection,cut" - A cut action has occurred
90  * "selection,start" - A selection has begun
91  * "selection,changed" - The selection has changed
92  * "selection,cleared" - The selection has been cleared
93  * "cursor,changed" - The cursor has changed
94  * "anchor,clicked" - The anchor has been clicked
95  * "preedit,changed" - The preedit string has changed
96  */
97
98 /* Maximum chunk size to be inserted to the entry at once
99  * FIXME: This size is arbitrary, should probably choose a better size.
100  * Possibly also find a way to set it to a low value for weak computers,
101  * and to a big value for better computers. */
102 #define _CHUNK_SIZE 10000
103
104 typedef struct _Mod_Api Mod_Api;
105
106 typedef struct _Widget_Data Widget_Data;
107 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
108 typedef struct _Elm_Entry_Item_Provider Elm_Entry_Item_Provider;
109 typedef struct _Elm_Entry_Text_Filter Elm_Entry_Text_Filter;
110
111 struct _Widget_Data
112 {
113    Evas_Object *ent, *scroller, *end, *icon;
114    Evas_Object *bg;
115    Evas_Object *hoversel;
116    Evas_Object *hover;
117    Evas_Object *layout;
118    Evas_Object *list;
119    Evas_Object *mgf_proxy;
120    Evas_Object *mgf_clip;
121    Evas_Object *mgf_bg;
122    Evas_Coord mgf_height;
123    float mgf_scale;
124    int mgf_type;
125    Ecore_Job *deferred_recalc_job;
126    Ecore_Event_Handler *sel_notify_handler;
127    Ecore_Event_Handler *sel_clear_handler;
128    Ecore_Timer *longpress_timer;
129    Ecore_Timer *delay_write;
130    /* for deferred appending */
131    Ecore_Idler *append_text_idler;
132    char *append_text_left;
133    int append_text_position;
134    int append_text_len;
135    /* Only for clipboard */
136    const char *cut_sel;
137    const char *text;
138    const char *password_text;
139    Evas_Coord wrap_w;
140    const char *file;
141    Elm_Text_Format format;
142    Evas_Coord lastw, entmw, entmh;
143    Evas_Coord downx, downy;
144    Evas_Coord cx, cy, cw, ch;
145    Eina_List *items;
146    Eina_List *item_providers;
147    Eina_List *text_filters;
148    Eina_List *match_list;
149    Ecore_Job *matchlist_job;
150    int matchlist_threshold;
151    Ecore_Job *hovdeljob;
152    Mod_Api *api; // module api if supplied
153    int cursor_pos;
154    Elm_Scroller_Policy policy_h, policy_v;
155    Elm_Wrap_Type linewrap;
156    Elm_Input_Panel_Layout input_panel_layout;
157    Eina_Bool changed : 1;
158    Eina_Bool single_line : 1;
159    Eina_Bool password : 1;
160    Eina_Bool editable : 1;
161    Eina_Bool selection_asked : 1;
162    Eina_Bool have_selection : 1;
163    Eina_Bool selmode : 1;
164    Eina_Bool deferred_cur : 1;
165    Eina_Bool cur_changed : 1;
166    Eina_Bool disabled : 1;
167    Eina_Bool double_clicked : 1;
168    Eina_Bool long_pressed : 1;
169    Eina_Bool context_menu : 1;
170    Eina_Bool drag_selection_asked : 1;
171    Eina_Bool bgcolor : 1;
172    Eina_Bool can_write : 1;
173    Eina_Bool autosave : 1;
174    Eina_Bool textonly : 1;
175    Eina_Bool usedown : 1;
176    Eina_Bool scroll : 1;
177    Eina_Bool autoreturnkey : 1;
178    Eina_Bool input_panel_enable : 1;
179    Eina_Bool autocapital : 1;
180    Eina_Bool autoperiod : 1;
181    Eina_Bool matchlist_list_clicked : 1;
182    Eina_Bool matchlist_case_sensitive : 1;
183 };
184
185 struct _Elm_Entry_Context_Menu_Item
186 {
187    Evas_Object *obj;
188    const char *label;
189    const char *icon_file;
190    const char *icon_group;
191    Elm_Icon_Type icon_type;
192    Evas_Smart_Cb func;
193    void *data;
194 };
195
196 struct _Elm_Entry_Item_Provider
197 {
198    Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
199    void *data;
200 };
201
202 struct _Elm_Entry_Text_Filter
203 {
204    void (*func) (void *data, Evas_Object *entry, char **text);
205    void *data;
206 };
207
208 typedef enum _Length_Unit
209 {
210    LENGTH_UNIT_CHAR,
211    LENGTH_UNIT_BYTE,
212    LENGTH_UNIT_LAST
213 } Length_Unit;
214
215 static const char *widtype = NULL;
216 // start for cbhm
217 static Evas_Object *cnpwidgetdata = NULL;
218 // end for cbhm
219
220 #ifdef HAVE_ELEMENTARY_X
221 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
222 #endif
223 static void _del_hook(Evas_Object *obj);
224 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
225 static void _theme_hook(Evas_Object *obj);
226 static void _disable_hook(Evas_Object *obj);
227 static void _sizing_eval(Evas_Object *obj);
228 static void _on_focus_hook(void *data, Evas_Object *obj);
229 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
230 static const char *_getbase(Evas_Object *obj);
231 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
232 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
233 static void _signal_selection_end(void *data, Evas_Object *obj, const char *emission, const char *source);
234 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
235 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
236 static void _signal_handler_move_start(void *data, Evas_Object *obj, const char *emission, const char *source);
237 static void _signal_handler_move_end(void *data, Evas_Object *obj, const char *emission, const char *source);
238 static void _signal_handler_moving(void *data, Evas_Object *obj, const char *emission, const char *source);
239 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
240 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
241 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
242 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
243 static void _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit);
244 static int _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag);
245 static int _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag);
246 static int _entry_length_get(Evas_Object *obj);
247 static void _magnifier_create(void *data);
248 static void _magnifier_show(void *data);
249 static void _magnifier_hide(void *data);
250 static void _magnifier_move(void *data);
251
252 static const char SIG_CHANGED[] = "changed";
253 static const char SIG_ACTIVATED[] = "activated";
254 static const char SIG_PRESS[] = "press";
255 static const char SIG_LONGPRESSED[] = "longpressed";
256 static const char SIG_CLICKED[] = "clicked";
257 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
258 static const char SIG_FOCUSED[] = "focused";
259 static const char SIG_UNFOCUSED[] = "unfocused";
260 static const char SIG_SELECTION_PASTE[] = "selection,paste";
261 static const char SIG_SELECTION_COPY[] = "selection,copy";
262 static const char SIG_SELECTION_CUT[] = "selection,cut";
263 static const char SIG_SELECTION_START[] = "selection,start";
264 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
265 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
266 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
267 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
268 static const char SIG_MATCHLIST_CLICKED[] = "matchlist,clicked";
269 static const char SIG_PREEDIT_CHANGED[] = "preedit,changed";
270 static const Evas_Smart_Cb_Description _signals[] = {
271   {SIG_CHANGED, ""},
272   {SIG_ACTIVATED, ""},
273   {SIG_PRESS, ""},
274   {SIG_LONGPRESSED, ""},
275   {SIG_CLICKED, ""},
276   {SIG_CLICKED_DOUBLE, ""},
277   {SIG_FOCUSED, ""},
278   {SIG_UNFOCUSED, ""},
279   {SIG_SELECTION_PASTE, ""},
280   {SIG_SELECTION_COPY, ""},
281   {SIG_SELECTION_CUT, ""},
282   {SIG_SELECTION_START, ""},
283   {SIG_SELECTION_CHANGED, ""},
284   {SIG_SELECTION_CLEARED, ""},
285   {SIG_CURSOR_CHANGED, ""},
286   {SIG_ANCHOR_CLICKED, ""},
287   {SIG_PREEDIT_CHANGED, ""},
288   {SIG_MATCHLIST_CLICKED, ""},
289   {NULL, NULL}
290 };
291
292 typedef enum _Elm_Entry_Magnifier_Type
293 {
294    _ENTRY_MAGNIFIER_FIXEDSIZE = 0,
295    _ENTRY_MAGNIFIER_FILLWIDTH,
296    _ENTRY_MAGNIFIER_CIRCULAR,
297 } Elm_Entry_Magnifier_Type;
298
299
300 static Eina_List *entries = NULL;
301
302 struct _Mod_Api
303 {
304    void (*obj_hook) (Evas_Object *obj);
305    void (*obj_unhook) (Evas_Object *obj);
306    void (*obj_longpress) (Evas_Object *obj);
307    void (*obj_hidemenu) (Evas_Object *obj);
308    void (*obj_mouseup) (Evas_Object *obj);
309 };
310
311 static Mod_Api *
312 _module(Evas_Object *obj __UNUSED__)
313 {
314    static Elm_Module *m = NULL;
315    if (m) goto ok; // already found - just use
316    if (!(m = _elm_module_find_as("entry/api"))) return NULL;
317    // get module api
318    m->api = malloc(sizeof(Mod_Api));
319    if (!m->api) return NULL;
320    ((Mod_Api *)(m->api)      )->obj_hook = // called on creation
321       _elm_module_symbol_get(m, "obj_hook");
322    ((Mod_Api *)(m->api)      )->obj_unhook = // called on deletion
323       _elm_module_symbol_get(m, "obj_unhook");
324    ((Mod_Api *)(m->api)      )->obj_longpress = // called on long press menu
325       _elm_module_symbol_get(m, "obj_longpress");
326    ((Mod_Api *)(m->api)      )->obj_hidemenu = // called on hide menu
327       _elm_module_symbol_get(m, "obj_hidemenu");
328    ((Mod_Api *)(m->api)      )->obj_mouseup = // called on mouseup
329       _elm_module_symbol_get(m, "obj_mouseup");
330 ok: // ok - return api
331    return m->api;
332 }
333
334 static char *
335 _buf_append(char *buf, const char *str, int *len, int *alloc)
336 {
337    int len2 = strlen(str);
338    if ((*len + len2) >= *alloc)
339      {
340         char *buf2 = realloc(buf, *alloc + len2 + 512);
341         if (!buf2) return NULL;
342         buf = buf2;
343         *alloc += (512 + len2);
344      }
345    strcpy(buf + *len, str);
346    *len += len2;
347    return buf;
348 }
349
350 static char *
351 _load_file(const char *file)
352 {
353    FILE *f;
354    size_t size;
355    int alloc = 0, len = 0;
356    char *text = NULL, buf[16384 + 1];
357
358    f = fopen(file, "rb");
359    if (!f) return NULL;
360    while ((size = fread(buf, 1, sizeof(buf) - 1, f)))
361      {
362         char *tmp_text;
363         buf[size] = 0;
364         tmp_text = _buf_append(text, buf, &len, &alloc);
365         if (!tmp_text) break;
366         text = tmp_text;
367      }
368    fclose(f);
369    return text;
370 }
371
372 static char *
373 _load_plain(const char *file)
374 {
375    char *text;
376
377    text = _load_file(file);
378    if (text)
379      {
380         char *text2;
381
382         text2 = elm_entry_utf8_to_markup(text);
383         free(text);
384         return text2;
385      }
386    return NULL;
387 }
388
389 static void
390 _load(Evas_Object *obj)
391 {
392    Widget_Data *wd = elm_widget_data_get(obj);
393    char *text;
394    if (!wd) return;
395    if (!wd->file)
396      {
397         elm_entry_entry_set(obj, "");
398         return;
399      }
400    switch (wd->format)
401      {
402       case ELM_TEXT_FORMAT_PLAIN_UTF8:
403          text = _load_plain(wd->file);
404          break;
405       case ELM_TEXT_FORMAT_MARKUP_UTF8:
406          text = _load_file(wd->file);
407          break;
408       default:
409          text = NULL;
410          break;
411      }
412    if (text)
413      {
414         elm_entry_entry_set(obj, text);
415         free(text);
416      }
417    else
418      elm_entry_entry_set(obj, "");
419 }
420
421 static void
422 _save_markup_utf8(const char *file, const char *text)
423 {
424    FILE *f;
425
426    if ((!text) || (!text[0]))
427      {
428         ecore_file_unlink(file);
429         return;
430      }
431    f = fopen(file, "wb");
432    if (!f)
433      {
434         // FIXME: report a write error
435         return;
436      }
437    fputs(text, f); // FIXME: catch error
438    fclose(f);
439 }
440
441 static void
442 _save_plain_utf8(const char *file, const char *text)
443 {
444    char *text2;
445
446    text2 = elm_entry_markup_to_utf8(text);
447    if (!text2)
448      return;
449    _save_markup_utf8(file, text2);
450    free(text2);
451 }
452
453 static void
454 _save(Evas_Object *obj)
455 {
456    Widget_Data *wd = elm_widget_data_get(obj);
457    if (!wd) return;
458    if (!wd->file) return;
459    switch (wd->format)
460      {
461       case ELM_TEXT_FORMAT_PLAIN_UTF8:
462          _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
463          break;
464       case ELM_TEXT_FORMAT_MARKUP_UTF8:
465          _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
466          break;
467       default:
468          break;
469      }
470 }
471
472 static Eina_Bool
473 _delay_write(void *data)
474 {
475    Widget_Data *wd = elm_widget_data_get(data);
476    if (!wd) return ECORE_CALLBACK_CANCEL;
477    _save(data);
478    wd->delay_write = NULL;
479    return ECORE_CALLBACK_CANCEL;
480 }
481
482 static Elm_Entry_Text_Filter *
483 _filter_new(void (*func) (void *data, Evas_Object *entry, char **text), void *data)
484 {
485    Elm_Entry_Text_Filter *tf = ELM_NEW(Elm_Entry_Text_Filter);
486    if (!tf) return NULL;
487
488    tf->func = func;
489    if (func == elm_entry_filter_limit_size)
490      {
491         Elm_Entry_Filter_Limit_Size *lim = data, *lim2;
492
493         if (!data)
494           {
495              free(tf);
496              return NULL;
497           }
498         lim2 = malloc(sizeof(Elm_Entry_Filter_Limit_Size));
499         if (!lim2)
500           {
501              free(tf);
502              return NULL;
503           }
504         memcpy(lim2, lim, sizeof(Elm_Entry_Filter_Limit_Size));
505         tf->data = lim2;
506      }
507    else if (func == elm_entry_filter_accept_set)
508      {
509         Elm_Entry_Filter_Accept_Set *as = data, *as2;
510
511         if (!data)
512           {
513              free(tf);
514              return NULL;
515           }
516         as2 = malloc(sizeof(Elm_Entry_Filter_Accept_Set));
517         if (!as2)
518           {
519              free(tf);
520              return NULL;
521           }
522         if (as->accepted)
523           as2->accepted = eina_stringshare_add(as->accepted);
524         else
525           as2->accepted = NULL;
526         if (as->rejected)
527           as2->rejected = eina_stringshare_add(as->rejected);
528         else
529           as2->rejected = NULL;
530         tf->data = as2;
531      }
532    else
533      tf->data = data;
534    return tf;
535 }
536
537 static void
538 _filter_free(Elm_Entry_Text_Filter *tf)
539 {
540    if (tf->func == elm_entry_filter_limit_size)
541      {
542         Elm_Entry_Filter_Limit_Size *lim = tf->data;
543         if (lim) free(lim);
544      }
545    else if (tf->func == elm_entry_filter_accept_set)
546      {
547         Elm_Entry_Filter_Accept_Set *as = tf->data;
548         if (as)
549           {
550              if (as->accepted) eina_stringshare_del(as->accepted);
551              if (as->rejected) eina_stringshare_del(as->rejected);
552              free(as);
553           }
554      }
555    free(tf);
556 }
557
558 static void
559 _del_pre_hook(Evas_Object *obj)
560 {
561    Widget_Data *wd = elm_widget_data_get(obj);
562    if (!wd) return;
563    if (wd->delay_write)
564      {
565         ecore_timer_del(wd->delay_write);
566         wd->delay_write = NULL;
567         if (wd->autosave) _save(obj);
568      }
569 }
570
571 static void
572 _del_hook(Evas_Object *obj)
573 {
574    Widget_Data *wd = elm_widget_data_get(obj);
575    Elm_Entry_Context_Menu_Item *it;
576    Elm_Entry_Item_Provider *ip;
577    Elm_Entry_Text_Filter *tf;
578
579    if (wd->file) eina_stringshare_del(wd->file);
580
581    if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
582    if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
583
584    entries = eina_list_remove(entries, obj);
585 #ifdef HAVE_ELEMENTARY_X
586    if (wd->sel_notify_handler)
587      ecore_event_handler_del(wd->sel_notify_handler);
588    if (wd->sel_clear_handler)
589      ecore_event_handler_del(wd->sel_clear_handler);
590 #endif
591    if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
592    if (wd->text) eina_stringshare_del(wd->text);
593    if (wd->password_text) eina_stringshare_del(wd->password_text);
594    if (wd->bg) evas_object_del(wd->bg);
595    if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
596    if (wd->append_text_idler)
597      {
598         ecore_idler_del(wd->append_text_idler);
599         free(wd->append_text_left);
600         wd->append_text_left = NULL;
601         wd->append_text_idler = NULL;
602      }
603    if (wd->matchlist_job) ecore_job_del(wd->matchlist_job);
604    if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
605    if (wd->mgf_proxy) evas_object_del(wd->mgf_proxy);
606    if (wd->mgf_bg) evas_object_del(wd->mgf_bg);
607    if (wd->mgf_clip) evas_object_del(wd->mgf_clip);
608
609    EINA_LIST_FREE(wd->items, it)
610      {
611         eina_stringshare_del(it->label);
612         eina_stringshare_del(it->icon_file);
613         eina_stringshare_del(it->icon_group);
614         free(it);
615      }
616    EINA_LIST_FREE(wd->item_providers, ip)
617      {
618         free(ip);
619      }
620    EINA_LIST_FREE(wd->text_filters, tf)
621      {
622         _filter_free(tf);
623      }
624    free(wd);
625 }
626
627 static void
628 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
629 {
630    Widget_Data *wd = elm_widget_data_get(obj);
631    edje_object_mirrored_set(wd->ent, rtl);
632 }
633
634 static void
635 _theme_hook(Evas_Object *obj)
636 {
637    Widget_Data *wd = elm_widget_data_get(obj);
638    const char *t;
639    Ecore_IMF_Context *ic;
640    _elm_widget_mirrored_reload(obj);
641    _mirrored_set(obj, elm_widget_mirrored_get(obj));
642
643    t = eina_stringshare_add(elm_entry_entry_get(obj));
644    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
645    if (_elm_config->desktop_entry)
646      edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
647    elm_entry_entry_set(obj, t);
648    eina_stringshare_del(t);
649    if (elm_widget_disabled_get(obj))
650      edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
651    edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", wd->input_panel_enable);
652    elm_entry_cursor_pos_set(obj, wd->cursor_pos);
653    if (elm_widget_focus_get(obj))
654      edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
655    edje_object_message_signal_process(wd->ent);
656    edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
657    elm_smart_scroller_mirrored_set(wd->scroller, elm_widget_mirrored_get(obj));
658    elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
659                                        elm_widget_style_get(obj));
660    if (wd->scroll)
661      {
662         const char *str;
663         Evas_Object *edj;
664
665         edj = elm_smart_scroller_edje_object_get(wd->scroller);
666         str = edje_object_data_get(edj, "focus_highlight");
667         if ((str) && (!strcmp(str, "on")))
668            elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
669         else
670            elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
671      }
672
673    if (wd->password)
674      {
675         edje_object_part_text_autoperiod_set(wd->ent, "elm.text", EINA_FALSE);
676         edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", EINA_FALSE);
677      }
678    else
679      {
680         edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
681         edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
682      }
683
684    ic = edje_object_part_text_imf_context_get(wd->ent, "elm.text");
685    if (ic)
686      {
687         ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)wd->input_panel_layout);
688      }
689
690    _sizing_eval(obj);
691 }
692
693 static void
694 _disable_hook(Evas_Object *obj)
695 {
696    Widget_Data *wd = elm_widget_data_get(obj);
697
698    if (elm_widget_disabled_get(obj))
699      {
700         edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
701         wd->disabled = EINA_TRUE;
702      }
703    else
704      {
705         edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
706         wd->disabled = EINA_FALSE;
707      }
708 }
709
710 static void
711 _recalc_cursor_geometry(Evas_Object *obj)
712 {
713    Widget_Data *wd = elm_widget_data_get(obj);
714    if (!wd) return;
715    evas_object_smart_callback_call(obj, SIG_CURSOR_CHANGED, NULL);
716    if (!elm_object_focus_get(obj)) return;
717    if (!wd->deferred_recalc_job)
718      {
719         Evas_Coord cx, cy, cw, ch;
720         edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
721               &cx, &cy, &cw, &ch);
722         if (wd->cur_changed)
723           {
724              elm_widget_show_region_set(obj, cx, cy, cw, ch, EINA_FALSE);
725              wd->cur_changed = EINA_FALSE;
726           }
727      }
728    else
729       wd->deferred_cur = EINA_TRUE;
730 }
731
732 static void
733 _elm_win_recalc_job(void *data)
734 {
735    Widget_Data *wd = elm_widget_data_get(data);
736    Evas_Coord minh = -1, resw = -1, minw = -1, fw = 0, fh = 0;
737    if (!wd) return;
738    wd->deferred_recalc_job = NULL;
739
740    evas_object_geometry_get(wd->ent, NULL, NULL, &resw, NULL);
741    edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
742    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
743    wd->entmw = minw;
744    wd->entmh = minh;
745    /* This is a hack to workaround the way min size hints are treated.
746     * If the minimum width is smaller than the restricted width, it means
747     * the mininmum doesn't matter. */
748    if (minw <= resw)
749      {
750         Evas_Coord ominw = -1;
751         evas_object_size_hint_min_get(data, &ominw, NULL);
752         minw = ominw;
753      }
754
755    elm_coords_finger_size_adjust(1, &fw, 1, &fh);
756    if (wd->scroll)
757      {
758         Evas_Coord vmw = 0, vmh = 0;
759
760         edje_object_size_min_calc
761            (elm_smart_scroller_edje_object_get(wd->scroller),
762                &vmw, &vmh);
763         if (wd->single_line)
764           {
765              evas_object_size_hint_min_set(data, vmw, minh + vmh);
766              evas_object_size_hint_max_set(data, -1, minh + vmh);
767           }
768         else
769           {
770              evas_object_size_hint_min_set(data, vmw, vmh);
771              evas_object_size_hint_max_set(data, -1, -1);
772           }
773      }
774    else
775      {
776         if (wd->single_line)
777           {
778              evas_object_size_hint_min_set(data, minw, minh);
779              evas_object_size_hint_max_set(data, -1, minh);
780           }
781         else
782           {
783              evas_object_size_hint_min_set(data, fw, minh);
784              evas_object_size_hint_max_set(data, -1, -1);
785           }
786      }
787
788    if ((wd->deferred_cur) && (elm_object_focus_get(data)))
789      {
790         Evas_Coord cx, cy, cw, ch;
791         edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
792                                                   &cx, &cy, &cw, &ch);
793         if (wd->cur_changed)
794           {
795              elm_widget_show_region_set(data, cx, cy, cw, ch, EINA_FALSE);
796              wd->cur_changed = EINA_FALSE;
797           }
798      }
799 }
800
801 static void
802 _sizing_eval(Evas_Object *obj)
803 {
804    Widget_Data *wd = elm_widget_data_get(obj);
805    Evas_Coord minw = -1, minh = -1;
806    Evas_Coord resw, resh;
807    if (!wd) return;
808
809    evas_object_geometry_get(obj, NULL, NULL, &resw, &resh);
810    if (wd->linewrap)
811      {
812         if ((resw == wd->lastw) && (!wd->changed)) return;
813         wd->changed = EINA_FALSE;
814         wd->lastw = resw;
815         if (wd->scroll)
816           {
817              Evas_Coord vw = 0, vh = 0, vmw = 0, vmh = 0, w = -1, h = -1;
818
819              evas_object_resize(wd->scroller, resw, resh);
820              edje_object_size_min_calc
821                 (elm_smart_scroller_edje_object_get(wd->scroller),
822                     &vmw, &vmh);
823              elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
824              edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, vw, 0);
825              wd->entmw = minw;
826              wd->entmh = minh;
827              elm_coords_finger_size_adjust(1, &minw, 1, &minh);
828
829              if ((minw > 0) && (vw < minw)) vw = minw;
830              if (minh > vh) vh = minh;
831
832              if (wd->single_line) h = vmh + minh;
833              else h = vmh;
834              evas_object_resize(wd->ent, vw, vh);
835              evas_object_size_hint_min_get(obj, &w, NULL);
836              evas_object_size_hint_min_set(obj, w, h);
837              if (wd->single_line)
838                 evas_object_size_hint_max_set(obj, -1, h);
839              else
840                 evas_object_size_hint_max_set(obj, -1, -1);
841           }
842         else
843           {
844              if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
845              wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
846           }
847      }
848    else
849      {
850         if (!wd->changed) return;
851         wd->changed = EINA_FALSE;
852         wd->lastw = resw;
853         if (wd->scroll)
854           {
855              Evas_Coord vw = 0, vh = 0, vmw = 0, vmh = 0, w = -1, h = -1;
856
857              edje_object_size_min_calc(wd->ent, &minw, &minh);
858              wd->entmw = minw;
859              wd->entmh = minh;
860              elm_coords_finger_size_adjust(1, &minw, 1, &minh);
861
862              elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
863
864              if ((minw > 0) && (vw < minw)) vw = minw;
865              if (minh > 0) vh = minh;
866
867              evas_object_resize(wd->ent, vw, vh);
868              edje_object_size_min_calc
869                 (elm_smart_scroller_edje_object_get(wd->scroller),
870                     &vmw, &vmh);
871              if (wd->single_line) h = vmh + minh;
872              else h = vmh;
873              evas_object_size_hint_min_get(obj, &w, NULL);
874              evas_object_size_hint_min_set(obj, w, h);
875              if (wd->single_line)
876                 evas_object_size_hint_max_set(obj, -1, h);
877              else
878                 evas_object_size_hint_max_set(obj, -1, -1);
879           }
880         else
881           {
882              edje_object_size_min_calc(wd->ent, &minw, &minh);
883              wd->entmw = minw;
884              wd->entmh = minh;
885              elm_coords_finger_size_adjust(1, &minw, 1, &minh);
886              evas_object_size_hint_min_set(obj, minw, minh);
887              if (wd->single_line)
888                 evas_object_size_hint_max_set(obj, -1, minh);
889              else
890                 evas_object_size_hint_max_set(obj, -1, -1);
891           }
892      }
893
894    _recalc_cursor_geometry(obj);
895 }
896
897 static void
898 _check_enable_returnkey(Evas_Object *obj)
899 {
900    Widget_Data *wd = elm_widget_data_get(obj);
901    if (!wd) return;
902
903    Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
904    if (!ic) return;
905
906    if (!wd->autoreturnkey) return;
907
908    if (_entry_length_get(obj) == 0)
909      {
910         ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_TRUE);
911      }
912    else
913      {
914         ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_FALSE);
915      }
916 }
917
918 static void
919 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
920 {
921    Widget_Data *wd = elm_widget_data_get(obj);
922    Evas_Object *top = elm_widget_top_get(obj);
923    if (!wd) return;
924    if (!wd->editable) return;
925    if (elm_widget_focus_get(obj))
926      {
927         printf("[Elm_entry::Focused] obj : %p\n", obj);
928         evas_object_focus_set(wd->ent, EINA_TRUE);
929         edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
930         if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
931         evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
932         _check_enable_returnkey(obj);
933         wd->mgf_type = _ENTRY_MAGNIFIER_FIXEDSIZE;
934      }
935    else
936      {
937         printf("[Elm_entry::Unfocused] obj : %p\n", obj);
938         edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
939         evas_object_focus_set(wd->ent, EINA_FALSE);
940         if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
941         evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
942
943         if ((wd->api) && (wd->api->obj_hidemenu))
944           {
945              wd->api->obj_hidemenu(obj);
946           }
947      }
948 }
949
950 static void
951 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
952 {
953    Widget_Data *wd = elm_widget_data_get(obj);
954    if (!wd) return;
955    edje_object_signal_emit(wd->ent, emission, source);
956    if (wd->scroller)
957       edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scroller),
958                               emission, source);
959 }
960
961 static void
962 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
963 {
964    Widget_Data *wd = elm_widget_data_get(obj);
965    if (!wd) return;
966    edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
967    if (wd->scroller)
968       edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scroller),
969                                       emission, source, func_cb, data);
970 }
971
972 static void
973 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
974 {
975    Widget_Data *wd = elm_widget_data_get(obj);
976    edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
977                                         data);
978    if (wd->scroller)
979       edje_object_signal_callback_del_full(elm_smart_scroller_edje_object_get(wd->scroller),
980                                            emission, source, func_cb, data);
981 }
982
983 static void
984 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
985 {
986    Widget_Data *wd = elm_widget_data_get(obj);
987    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
988 }
989
990 static void
991 _focus_region_hook(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
992 {
993    Widget_Data *wd = elm_widget_data_get(obj);
994    if (wd->scroll)
995       elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
996 }
997
998 static void
999 _show_region_hook(void *data, Evas_Object *obj)
1000 {
1001    Widget_Data *wd = elm_widget_data_get(data);
1002    Evas_Coord x, y, w, h;
1003    if (!wd) return;
1004    elm_widget_show_region_get(obj, &x, &y, &w, &h);
1005    if (wd->scroll)
1006      elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
1007 }
1008
1009 static void
1010 _hoversel_position(Evas_Object *obj)
1011 {
1012    Widget_Data *wd = elm_widget_data_get(obj);
1013    Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
1014    if (!wd) return;
1015
1016    cx = cy = 0;
1017    cw = ch = 1;
1018    evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1019    if (wd->usedown)
1020      {
1021         cx = wd->downx - x;
1022         cy = wd->downy - y;
1023         cw = 1;
1024         ch = 1;
1025      }
1026    else
1027      edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1028                                                &cx, &cy, &cw, &ch);
1029    evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
1030    if (cw < mw)
1031      {
1032         cx += (cw - mw) / 2;
1033         cw = mw;
1034      }
1035    if (ch < mh)
1036      {
1037         cy += (ch - mh) / 2;
1038         ch = mh;
1039      }
1040    evas_object_move(wd->hoversel, x + cx, y + cy);
1041    evas_object_resize(wd->hoversel, cw, ch);
1042 }
1043
1044 static void
1045 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1046 {
1047    Widget_Data *wd = elm_widget_data_get(data);
1048
1049    if (wd->hoversel) _hoversel_position(data);
1050 }
1051
1052 static void
1053 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1054 {
1055    Widget_Data *wd = elm_widget_data_get(data);
1056    if (!wd) return;
1057
1058    if (wd->linewrap)
1059      {
1060         _sizing_eval(data);
1061      }
1062    else if (wd->scroll)
1063      {
1064         Evas_Coord vw = 0, vh = 0;
1065
1066         elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
1067         if (vw < wd->entmw) vw = wd->entmw;
1068         if (vh < wd->entmh) vh = wd->entmh;
1069         evas_object_resize(wd->ent, vw, vh);
1070      }
1071    if (wd->hoversel) _hoversel_position(data);
1072 }
1073
1074 static void
1075 _hover_del(void *data)
1076 {
1077    Widget_Data *wd = elm_widget_data_get(data);
1078    if (!wd) return;
1079
1080    if (wd->hoversel)
1081      {
1082         evas_object_del(wd->hoversel);
1083         wd->hoversel = NULL;
1084      }
1085    wd->hovdeljob = NULL;
1086 }
1087
1088 static void
1089 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1090 {
1091    Widget_Data *wd = elm_widget_data_get(data);
1092    if (!wd) return;
1093    wd->usedown = 0;
1094    if (wd->hoversel) evas_object_hide(wd->hoversel);
1095    if (wd->selmode)
1096      {
1097         if (!_elm_config->desktop_entry)
1098           {
1099              if (!wd->password)
1100                edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
1101           }
1102      }
1103    elm_widget_scroll_freeze_pop(data);
1104    if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
1105    wd->hovdeljob = ecore_job_add(_hover_del, data);
1106 }
1107
1108 static void
1109 _selectall(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1110 {
1111    Widget_Data *wd = elm_widget_data_get(data);
1112    if (!wd) return;
1113    wd->selmode = EINA_TRUE;
1114    edje_object_part_text_select_none(wd->ent, "elm.text");
1115    edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
1116    edje_object_part_text_select_all(wd->ent, "elm.text");
1117    elm_object_scroll_freeze_pop(data);
1118 }
1119
1120 static void
1121 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1122 {
1123    Widget_Data *wd = elm_widget_data_get(data);
1124    if (!wd) return;
1125    wd->selmode = EINA_TRUE;
1126    edje_object_part_text_select_none(wd->ent, "elm.text");
1127    if (!_elm_config->desktop_entry)
1128      {
1129         if (!wd->password)
1130           edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
1131      }
1132    edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
1133    if (!_elm_config->desktop_entry)
1134       elm_object_scroll_freeze_pop(data);
1135       //elm_widget_scroll_hold_push(data);
1136 }
1137
1138 static void
1139 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1140 {
1141    Widget_Data *wd = elm_widget_data_get(data);
1142    if (!wd) return;
1143    evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1144    if (wd->sel_notify_handler)
1145      {
1146 #ifdef HAVE_ELEMENTARY_X
1147         Elm_Sel_Format formats;
1148         wd->selection_asked = EINA_TRUE;
1149         formats = ELM_SEL_FORMAT_MARKUP;
1150         if (!wd->textonly)
1151           formats |= ELM_SEL_FORMAT_IMAGE;
1152         elm_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL);
1153 #endif
1154      }
1155 }
1156
1157 static void
1158 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
1159 {
1160    Widget_Data *wd = elm_widget_data_get(obj);
1161    const char *sel;
1162
1163    if (!wd) return;
1164    sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
1165    elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
1166    if (seltype == ELM_SEL_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_CLIPBOARD, data);
1183    edje_object_part_text_insert(wd->ent, "elm.text", "");
1184    edje_object_part_text_select_none(wd->ent, "elm.text");
1185 }
1186
1187 static void
1188 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1189 {
1190    Widget_Data *wd = elm_widget_data_get(data);
1191    if (!wd) return;
1192    wd->selmode = EINA_TRUE;
1193    if (!_elm_config->desktop_entry)
1194      {
1195         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1196         elm_widget_scroll_hold_pop(data);
1197      }
1198    _store_selection(ELM_SEL_CLIPBOARD, data);
1199 }
1200
1201 static void
1202 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1203 {
1204    Widget_Data *wd = elm_widget_data_get(data);
1205    if (!wd) return;
1206    wd->selmode = EINA_FALSE;
1207    if (!_elm_config->desktop_entry)
1208      edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1209    edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1210    if (!_elm_config->desktop_entry)
1211      elm_widget_scroll_hold_pop(data);
1212    edje_object_part_text_select_none(wd->ent, "elm.text");
1213 }
1214
1215 static void
1216 _clipboard_menu(void *data, Evas_Object *obj, void *event_info __UNUSED__)
1217 {
1218    Widget_Data *wd = elm_widget_data_get(data);
1219    if (!wd) return;
1220
1221    // start for cbhm
1222 #ifdef HAVE_ELEMENTARY_X
1223    ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
1224 #endif
1225    cnpwidgetdata = data;
1226    elm_cbhm_helper_init(obj);
1227    if (elm_entry_cnp_textonly_get(obj))
1228      elm_cbhm_send_raw_data("show0");
1229    else
1230      elm_cbhm_send_raw_data("show1");
1231    // end for cbhm
1232 }
1233
1234 // start for cbhm
1235 static void
1236 _cnpinit(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1237 {
1238    Widget_Data *wd = elm_widget_data_get(data);
1239    if (!wd) return;
1240    cnpwidgetdata = data;
1241 }
1242 // end for cbhm
1243
1244
1245 static void
1246 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1247 {
1248    Elm_Entry_Context_Menu_Item *it = data;
1249    Evas_Object *obj2 = it->obj;
1250    if (it->func) it->func(it->data, obj2, NULL);
1251 }
1252
1253 static void
1254 _menu_press(Evas_Object *obj)
1255 {
1256    Widget_Data *wd = elm_widget_data_get(obj);
1257    Evas_Object *top;
1258    const Eina_List *l;
1259    const Elm_Entry_Context_Menu_Item *it;
1260    if (!wd) return;
1261    if ((wd->api) && (wd->api->obj_longpress))
1262      {
1263         wd->api->obj_longpress(obj);
1264      }
1265    else if (wd->context_menu)
1266      {
1267         const char *context_menu_orientation;
1268
1269         if (wd->hoversel) evas_object_del(wd->hoversel);
1270         else elm_widget_scroll_freeze_push(obj);
1271         wd->hoversel = elm_hoversel_add(obj);
1272         context_menu_orientation = edje_object_data_get
1273            (wd->ent, "context_menu_orientation");
1274         if ((context_menu_orientation) &&
1275             (!strcmp(context_menu_orientation, "horizontal")))
1276           elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
1277         elm_object_style_set(wd->hoversel, "entry");
1278         elm_widget_sub_object_add(obj, wd->hoversel);
1279         elm_object_text_set(wd->hoversel, "Text");
1280         top = elm_widget_top_get(obj);
1281         if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
1282         evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, obj);
1283         if (!wd->selmode)
1284           {
1285              if (!wd->password)
1286                elm_hoversel_item_add(wd->hoversel, E_("Select"), NULL, ELM_ICON_NONE,
1287                                      _select, obj);
1288              if (1) // need way to detect if someone has a selection
1289                {
1290                   if (wd->editable)
1291                     elm_hoversel_item_add(wd->hoversel, E_("Paste"), NULL, ELM_ICON_NONE,
1292                                           _paste, obj);
1293                }
1294         // start for cbhm
1295              if ((!wd->password) && (wd->editable))
1296                elm_hoversel_item_add(wd->hoversel, E_("More"), NULL, ELM_ICON_NONE,
1297                                      _clipboard_menu, obj);
1298         // end for cbhm
1299           }
1300         else
1301           {
1302              if (!wd->password)
1303                {
1304                   if (wd->have_selection)
1305                     {
1306                        elm_hoversel_item_add(wd->hoversel, E_("Copy"), NULL, ELM_ICON_NONE,
1307                                              _copy, obj);
1308                        if (wd->editable)
1309                          elm_hoversel_item_add(wd->hoversel, E_("Cut"), NULL, ELM_ICON_NONE,
1310                                                _cut, obj);
1311                     }
1312                   elm_hoversel_item_add(wd->hoversel, E_("Cancel"), NULL, ELM_ICON_NONE,
1313                                         _cancel, obj);
1314         // start for cbhm
1315                   if (wd->editable)
1316                     elm_hoversel_item_add(wd->hoversel, E_("More"), NULL, ELM_ICON_NONE,
1317                                           _clipboard_menu, obj);
1318         // end for cbhm
1319                }
1320           }
1321         EINA_LIST_FOREACH(wd->items, l, it)
1322           {
1323              elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
1324                                    it->icon_type, _item_clicked, it);
1325           }
1326         if (wd->hoversel)
1327           {
1328              _hoversel_position(obj);
1329              evas_object_show(wd->hoversel);
1330              elm_hoversel_hover_begin(wd->hoversel);
1331           }
1332         if (!_elm_config->desktop_entry)
1333           {
1334              edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1335              edje_object_part_text_select_abort(wd->ent, "elm.text");
1336           }
1337      }
1338 }
1339
1340 static void
1341 _magnifier_hide(void *data)
1342 {
1343    Widget_Data *wd = elm_widget_data_get(data);
1344    if (!wd) return;
1345
1346    evas_object_hide(wd->mgf_bg);
1347    evas_object_hide(wd->mgf_clip);
1348
1349    if (wd->scroll)
1350      elm_smart_scroller_freeze_set(wd->scroller, EINA_FALSE);
1351 }
1352
1353 static void
1354 _magnifier_show(void *data)
1355 {
1356    Widget_Data *wd = elm_widget_data_get(data);
1357    if (!wd) return;
1358
1359    evas_object_show(wd->mgf_bg);
1360    evas_object_show(wd->mgf_clip);
1361 }
1362
1363 static void
1364 _magnifier_move(void *data)
1365 {
1366    Widget_Data *wd = elm_widget_data_get(data);
1367    if (!wd) return;
1368
1369    Evas_Coord x, y, w, h, fs;
1370    Evas_Coord cx, cy, cw, ch, ox, oy;
1371
1372    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1373
1374    if (wd->scroll)
1375      {
1376         evas_object_geometry_get(wd->scroller, &x, &y, &w, &h);
1377         elm_smart_scroller_child_pos_get(wd->scroller, &ox, &oy);
1378         cx -= ox;
1379         cy -= oy;
1380      }
1381    else
1382      evas_object_geometry_get(data, &x, &y, &w, &h);
1383
1384    ox = oy = 0;
1385    fs = elm_finger_size_get();
1386
1387    if ((cy + y) - wd->mgf_height - fs < 0)
1388      oy = -1 * ((cy + y) - wd->mgf_height - fs);
1389
1390    if (wd->mgf_type == _ENTRY_MAGNIFIER_FIXEDSIZE)
1391      evas_object_move(wd->mgf_bg, (cx + x + cw/2) + ox, (cy + y) - wd->mgf_height - fs + oy);
1392    else if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1393      evas_object_move(wd->mgf_bg, x, (cy + y) - wd->mgf_height - fs + oy);
1394    else
1395      return;
1396
1397    evas_object_move(wd->mgf_proxy, (1 - wd->mgf_scale) * cx + x + ox, (1 - wd->mgf_scale) * cy + y - wd->mgf_height/2 - ch/2 - fs + oy);
1398 }
1399
1400 static void
1401 _magnifier_create(void *data)
1402 {
1403    Widget_Data *wd = elm_widget_data_get(data);
1404    Evas_Coord x, y, w, h, mw, mh;
1405    const char* key_data = NULL;
1406
1407    if (!wd) return;
1408
1409    if (wd->mgf_proxy)
1410      {
1411         evas_object_image_source_unset(wd->mgf_proxy);
1412         evas_object_color_set(wd->mgf_proxy, 255, 255, 255, 0);
1413         evas_object_hide(wd->mgf_proxy);
1414         evas_object_clip_unset(wd->mgf_proxy);
1415         evas_object_del(wd->mgf_proxy);
1416      }
1417    if (wd->mgf_bg) evas_object_del(wd->mgf_bg);
1418    if (wd->mgf_clip) evas_object_del(wd->mgf_clip);
1419
1420    if (wd->scroll)
1421      evas_object_geometry_get(wd->scroller, &x, &y, &w, &h);
1422    else
1423      evas_object_geometry_get(data, &x, &y, &w, &h);
1424
1425    if ((w <= 0) || (h <= 0))
1426      return;
1427
1428    wd->mgf_bg = edje_object_add(evas_object_evas_get(data));
1429
1430    if (wd->mgf_type == _ENTRY_MAGNIFIER_FIXEDSIZE)
1431      _elm_theme_object_set(data, wd->mgf_bg, "entry", "magnifier", "fixed-size");
1432    else if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1433      _elm_theme_object_set(data, wd->mgf_bg, "entry", "magnifier", "fill-width");
1434    else
1435      return;
1436
1437    wd->mgf_clip = evas_object_rectangle_add(evas_object_evas_get(data));
1438    evas_object_color_set(wd->mgf_clip, 255, 255, 255, 255);
1439    edje_object_part_swallow(wd->mgf_bg, "swallow", wd->mgf_clip);
1440
1441    key_data = edje_object_data_get(wd->mgf_bg, "height");
1442    if (key_data) wd->mgf_height = atoi(key_data);
1443    key_data = edje_object_data_get(wd->mgf_bg, "scale");
1444    if (key_data) wd->mgf_scale = atof(key_data);
1445
1446    if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1447      evas_object_resize(wd->mgf_bg, w, wd->mgf_height);
1448
1449    if (wd->scroll)
1450      {
1451         elm_smart_scroller_freeze_set(wd->scroller, EINA_TRUE);
1452         wd->mgf_proxy = evas_object_image_add(evas_object_evas_get(wd->scroller));
1453         evas_object_image_source_set(wd->mgf_proxy, wd->scroller);
1454      }
1455    else
1456      {
1457         wd->mgf_proxy = evas_object_image_add(evas_object_evas_get(data));
1458         evas_object_image_source_set(wd->mgf_proxy, data);
1459      }
1460
1461    mw = (Evas_Coord)((float)w * wd->mgf_scale);
1462    mh = (Evas_Coord)((float)h * wd->mgf_scale);
1463    if ((mw <= 0) || (mh <= 0))
1464      return;
1465
1466    evas_object_resize(wd->mgf_proxy, mw, mh);
1467    evas_object_image_fill_set(wd->mgf_proxy, 0, 0, mw, mh);
1468    evas_object_color_set(wd->mgf_proxy, 255, 255, 255, 255);
1469    evas_object_pass_events_set(wd->mgf_proxy, EINA_TRUE);
1470    evas_object_show(wd->mgf_proxy);
1471    evas_object_clip_set(wd->mgf_proxy, wd->mgf_clip);
1472
1473    evas_object_layer_set(wd->mgf_bg, EVAS_LAYER_MAX);
1474    evas_object_layer_set(wd->mgf_proxy, EVAS_LAYER_MAX);
1475 }
1476
1477 static Eina_Bool
1478 _long_press(void *data)
1479 {
1480    Widget_Data *wd = elm_widget_data_get(data);
1481    if (!wd) return ECORE_CALLBACK_CANCEL;
1482
1483    wd->long_pressed = EINA_TRUE;
1484
1485    if (wd->longpress_timer)
1486      {
1487         ecore_timer_del(wd->longpress_timer);
1488         wd->longpress_timer = NULL;
1489      }
1490
1491    _cancel(data, NULL, NULL);
1492
1493    _magnifier_create(data);
1494    _magnifier_move(data);
1495    _magnifier_show(data);
1496    elm_object_scroll_freeze_push(data);
1497
1498    wd->longpress_timer = NULL;
1499    evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
1500    return ECORE_CALLBACK_CANCEL;
1501 }
1502
1503 static void
1504 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1505 {
1506    Widget_Data *wd = elm_widget_data_get(data);
1507    Evas_Event_Mouse_Down *ev = event_info;
1508    if (!wd) return;
1509    if (wd->disabled) return;
1510    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1511    wd->downx = ev->canvas.x;
1512    wd->downy = ev->canvas.y;
1513    wd->long_pressed = EINA_FALSE;
1514    if (ev->button == 1)
1515      {
1516         if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
1517         wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1518      }
1519 }
1520
1521 static void
1522 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1523 {
1524    Widget_Data *wd = elm_widget_data_get(data);
1525    Evas_Event_Mouse_Up *ev = event_info;
1526    if (!wd) return;
1527    if (wd->disabled) return;
1528    if (ev->button == 1)
1529      {
1530         if (!wd->double_clicked)
1531           {
1532              if ((wd->api) && (wd->api->obj_mouseup))
1533                {
1534                   wd->api->obj_mouseup(data);
1535                }
1536           }
1537
1538         if (wd->longpress_timer)
1539           {
1540              ecore_timer_del(wd->longpress_timer);
1541              wd->longpress_timer = NULL;
1542           }
1543
1544         _magnifier_hide(data);
1545         elm_object_scroll_freeze_pop(data);
1546
1547         if (wd->long_pressed)
1548           {
1549              _menu_press(data);
1550           }
1551
1552      }
1553    else if (ev->button == 3)
1554      {
1555         wd->usedown = 1;
1556         _menu_press(data);
1557      }
1558 }
1559
1560 static void
1561 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1562 {
1563    Widget_Data *wd = elm_widget_data_get(data);
1564    Evas_Event_Mouse_Move *ev = event_info;
1565    if (!wd) return;
1566    if (wd->disabled) return;
1567    if (!wd->selmode)
1568      {
1569         if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1570           {
1571              if (wd->longpress_timer)
1572                {
1573                   ecore_timer_del(wd->longpress_timer);
1574                   wd->longpress_timer = NULL;
1575                }
1576           }
1577         else if (wd->longpress_timer)
1578           {
1579              Evas_Coord dx, dy;
1580
1581              dx = wd->downx - ev->cur.canvas.x;
1582              dx *= dx;
1583              dy = wd->downy - ev->cur.canvas.y;
1584              dy *= dy;
1585              if ((dx + dy) >
1586                  ((_elm_config->finger_size / 2) *
1587                   (_elm_config->finger_size / 2)))
1588                {
1589                   ecore_timer_del(wd->longpress_timer);
1590                   wd->longpress_timer = NULL;
1591                }
1592           }
1593      }
1594    else if (wd->longpress_timer)
1595      {
1596         Evas_Coord dx, dy;
1597
1598         dx = wd->downx - ev->cur.canvas.x;
1599         dx *= dx;
1600         dy = wd->downy - ev->cur.canvas.y;
1601         dy *= dy;
1602         if ((dx + dy) >
1603             ((_elm_config->finger_size / 2) *
1604              (_elm_config->finger_size / 2)))
1605           {
1606              ecore_timer_del(wd->longpress_timer);
1607              wd->longpress_timer = NULL;
1608           }
1609      }
1610
1611    if (ev->buttons == 1)
1612      {
1613         if (wd->long_pressed)
1614           {
1615              _magnifier_show(data);
1616              _magnifier_move(data);
1617           }
1618      }
1619 }
1620
1621 static const char *
1622 _getbase(Evas_Object *obj)
1623 {
1624    Widget_Data *wd = elm_widget_data_get(obj);
1625    if (!wd) return "base";
1626    if (wd->editable)
1627      {
1628         if (wd->password) return "base-password";
1629         else
1630           {
1631              if (wd->single_line) return "base-single";
1632              else
1633                {
1634                   switch (wd->linewrap)
1635                     {
1636                      case ELM_WRAP_CHAR:
1637                         return "base-charwrap";
1638                      case ELM_WRAP_WORD:
1639                         return "base";
1640                      case ELM_WRAP_MIXED:
1641                         return "base-mixedwrap";
1642                      case ELM_WRAP_NONE:
1643                      default:
1644                         return "base-nowrap";
1645                     }
1646                }
1647           }
1648      }
1649    else
1650      {
1651         if (wd->password) return "base-password";
1652         else
1653           {
1654              if (wd->single_line) return "base-single-noedit";
1655              else
1656                {
1657                   switch (wd->linewrap)
1658                     {
1659                      case ELM_WRAP_CHAR:
1660                         return "base-noedit-charwrap";
1661                      case ELM_WRAP_WORD:
1662                         return "base-noedit";
1663                      case ELM_WRAP_MIXED:
1664                         return "base-noedit-mixedwrap";
1665                      case ELM_WRAP_NONE:
1666                      default:
1667                         return "base-nowrap-noedit";
1668                     }
1669                }
1670           }
1671      }
1672    return "base";
1673 }
1674
1675
1676 static int
1677 _entry_length_get(Evas_Object *obj)
1678 {
1679    int len;
1680    const char *str = elm_entry_entry_get(obj);
1681    if (!str) return 0;
1682
1683    char *plain_str = _elm_util_mkup_to_text(str);
1684    if (!plain_str) return 0;
1685
1686    len = strlen(plain_str);
1687    free(plain_str);
1688
1689    return len;
1690 }
1691
1692 #ifndef HAVE_STRCASESTR
1693 char* _strcasestr(const char *s, const char *find)
1694 {
1695    char c, sc;
1696    size_t len;
1697
1698    if ((c = *find++) != 0) {
1699       c = tolower((unsigned char) c);
1700       len = strlen(find);
1701       do {
1702          do {
1703             if( (sc = *s++) == 0)
1704                return NULL;
1705          } while ((char)tolower((unsigned char)sc) != c);
1706       } while (strncasecmp(s, find, len) != 0);
1707       s--;
1708    }
1709    return ((char*) s);
1710 }
1711 #endif
1712
1713 static void
1714 _matchlist_show(void *data)
1715 {
1716    Widget_Data *wd = elm_widget_data_get(data);
1717    const char *text = NULL;
1718    int textlen = 0;
1719    char *str_list = NULL, *str_result = NULL;
1720    char *str_mkup = NULL, *str_front = NULL, *str_mid = NULL;
1721
1722    Eina_List *l;
1723    Eina_Bool textfound = EINA_FALSE;
1724
1725    if (!wd) return;
1726    if (elm_widget_disabled_get(data)) return;
1727
1728    wd->matchlist_job = NULL;
1729
1730    if (wd->matchlist_list_clicked)
1731      {
1732         evas_object_hide(wd->hover);
1733         wd->matchlist_list_clicked = EINA_FALSE;
1734         return;
1735      }
1736    text = elm_entry_entry_get(data);
1737    if (text == NULL)
1738      return;
1739    textlen = strlen(text);
1740
1741    if (textlen < wd->matchlist_threshold)
1742      {
1743         evas_object_hide(wd->hover);
1744         return;
1745      }
1746
1747    evas_object_hide(wd->hover);
1748
1749    if (wd->match_list)
1750      {
1751         elm_list_clear(wd->list);
1752         EINA_LIST_FOREACH(wd->match_list, l, str_list)
1753           {
1754              if (wd->matchlist_case_sensitive)
1755                str_result = strstr(str_list, text);
1756              else
1757 #ifdef HAVE_STRCASESTR
1758                 str_result = strcasestr(str_list, text);
1759 #else
1760                 str_result = _strcasestr(str_list, text);
1761 #endif
1762
1763              if (str_result)
1764                {
1765                   str_mkup = malloc(strlen(str_list) + 16);
1766                   if (str_mkup == NULL) return;
1767
1768                   textlen = strlen(str_list) - strlen(str_result);
1769                   str_front = malloc(textlen + 1);
1770                   if (str_front == NULL) return;
1771
1772                   memset(str_front, 0, textlen + 1);
1773                   strncpy(str_front, str_list, textlen);
1774
1775                   textlen = strlen(text);
1776                   str_mid = malloc(textlen + 1);
1777                   if (str_mid == NULL) return;
1778
1779                   memset(str_mid, 0, textlen + 1);
1780                   strncpy(str_mid, str_list + strlen(str_front), textlen);
1781
1782                   sprintf(str_mkup, "%s<match>%s</match>%s", str_front, str_mid, str_result + strlen(text));
1783
1784                   elm_list_item_append(wd->list, str_mkup, NULL, NULL, NULL, NULL);
1785
1786                   if (str_mkup) free(str_mkup);
1787                   if (str_front) free(str_front);
1788                   if (str_mid) free(str_mid);
1789
1790                   textfound=EINA_TRUE;
1791                }
1792           }
1793      }
1794    else
1795      return;
1796
1797    if (textfound)
1798      {
1799         elm_list_go(wd->list);
1800         evas_object_show(wd->hover);
1801         evas_object_raise(wd->hover);
1802      }
1803 }
1804
1805 static void _matchlist_list_clicked( void *data, Evas_Object *obj, void *event_info )
1806 {
1807    Elm_List_Item *it = (Elm_List_Item *) elm_list_selected_item_get(obj);
1808    Widget_Data *wd = elm_widget_data_get(data);
1809    if ((it == NULL) || (wd == NULL))
1810      return;
1811
1812    const char *text = elm_list_item_label_get(it);
1813    evas_object_smart_callback_call((Evas_Object *)data, "selected", (void *)text);
1814    if (wd->match_list)
1815      {
1816         if (text != NULL)
1817           {
1818              elm_entry_entry_set(data, elm_entry_markup_to_utf8(text));
1819              elm_entry_cursor_end_set(data);
1820              wd->matchlist_list_clicked = EINA_TRUE;
1821
1822              evas_object_smart_callback_call(data, SIG_MATCHLIST_CLICKED, elm_entry_markup_to_utf8(text));
1823           }
1824      }
1825    elm_widget_focus_set(data, EINA_TRUE);
1826 }
1827
1828 static void
1829 _entry_changed_common_handling(void *data, const char *event)
1830 {
1831    Widget_Data *wd = elm_widget_data_get(data);
1832    Evas_Coord minw, minh;
1833    if (!wd) return;
1834    wd->changed = EINA_TRUE;
1835    /* Reset the size hints which are no more relevant.
1836     * Keep the height, this is a hack, but doesn't really matter
1837     * cause we'll re-eval in a moment. */
1838    if (wd->scroll)
1839      {
1840         evas_object_size_hint_min_get(data, &minw, &minh);
1841         evas_object_size_hint_min_set(data, minw, minh);
1842      }
1843    else
1844      {
1845         evas_object_size_hint_min_get(data, NULL, &minh);
1846         evas_object_size_hint_min_set(data, -1, minh);
1847      }
1848
1849    _sizing_eval(data);
1850    if (wd->text) eina_stringshare_del(wd->text);
1851    wd->text = NULL;
1852    if (wd->password_text) eina_stringshare_del(wd->password_text);
1853    wd->password_text = NULL;
1854    _check_enable_returnkey(data);
1855    evas_object_smart_callback_call(data, event, NULL);
1856    if (wd->delay_write)
1857      {
1858         ecore_timer_del(wd->delay_write);
1859         wd->delay_write = NULL;
1860      }
1861
1862    if ((wd->single_line) && (wd->match_list))
1863    {
1864         if (wd->matchlist_job) ecore_job_del(wd->matchlist_job);
1865         wd->matchlist_job = ecore_job_add(_matchlist_show, data);
1866    }
1867    if ((!wd->autosave) || (!wd->file)) return;
1868    wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1869 }
1870
1871 static void
1872 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1873 {
1874    _entry_changed_common_handling(data, SIG_CHANGED);
1875 }
1876
1877 static void
1878 _signal_preedit_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1879 {
1880    _entry_changed_common_handling(data, SIG_PREEDIT_CHANGED);
1881 }
1882
1883
1884 static void
1885 _signal_handler_move_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1886 {
1887    Widget_Data *wd = elm_widget_data_get(data);
1888    elm_object_scroll_freeze_push(data);
1889
1890    if ((wd->api) && (wd->api->obj_hidemenu))
1891      {
1892         wd->api->obj_hidemenu(data);
1893      }
1894
1895    _magnifier_create(data);
1896    _magnifier_move(data);
1897    _magnifier_show(data);
1898 }
1899
1900 static void
1901 _signal_handler_move_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1902 {
1903    Widget_Data *wd = elm_widget_data_get(data);
1904    elm_object_scroll_freeze_pop(data);
1905
1906    if (wd->have_selection)
1907      {
1908         _magnifier_hide(data);
1909         _menu_press(data);
1910      }
1911 }
1912
1913 static void
1914 _signal_handler_moving(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1915 {
1916    _magnifier_move(data);
1917    _magnifier_show(data);
1918 }
1919
1920 static void
1921 _signal_selection_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1922 {
1923    _magnifier_hide(data);
1924    _menu_press(data);
1925 }
1926
1927 static void
1928 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1929 {
1930    Widget_Data *wd = elm_widget_data_get(data);
1931    const Eina_List *l;
1932    Evas_Object *entry;
1933    if (!wd) return;
1934    EINA_LIST_FOREACH(entries, l, entry)
1935      {
1936         if (entry != data) elm_entry_select_none(entry);
1937      }
1938    wd->have_selection = EINA_TRUE;
1939    wd->selmode = EINA_TRUE;
1940    evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1941 #ifdef HAVE_ELEMENTARY_X
1942    if (wd->sel_notify_handler)
1943      {
1944         const char *txt = elm_entry_selection_get(data);
1945         Evas_Object *top;
1946
1947         top = elm_widget_top_get(data);
1948         if ((top) && (elm_win_xwindow_get(top)))
1949           elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1950      }
1951 #endif
1952 }
1953
1954 static void
1955 _signal_magnifier_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1956 {
1957    Evas_Coord cx, cy, cw, ch;
1958    Widget_Data *wd = elm_widget_data_get(data);
1959    if (!wd) return;
1960
1961    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1962    if (!wd->deferred_recalc_job)
1963      elm_widget_show_region_set(data, cx, cy, cw, ch, EINA_FALSE);
1964    else
1965      {
1966         wd->deferred_cur = EINA_TRUE;
1967         wd->cx = cx;
1968         wd->cy = cy;
1969         wd->cw = cw;
1970         wd->ch = ch + elm_finger_size_get();
1971      }
1972 }
1973
1974 static void
1975 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1976 {
1977    Evas_Coord cx, cy, cw, ch;
1978    Widget_Data *wd = elm_widget_data_get(data);
1979    if (!wd) return;
1980    wd->have_selection = EINA_TRUE;
1981    wd->selmode = EINA_TRUE;
1982    evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1983    elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1984                      elm_entry_selection_get(data));
1985
1986    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1987    if (!wd->deferred_recalc_job)
1988      elm_widget_show_region_set(data, cx, cy, cw, ch + elm_finger_size_get(), EINA_FALSE);
1989    else
1990      {
1991         wd->deferred_cur = EINA_TRUE;
1992         wd->cx = cx;
1993         wd->cy = cy;
1994         wd->cw = cw;
1995         wd->ch = ch + elm_finger_size_get();
1996      }
1997 }
1998
1999 static void
2000 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2001 {
2002    Widget_Data *wd = elm_widget_data_get(data);
2003    if (!wd) return;
2004    if (!wd->have_selection) return;
2005    wd->have_selection = EINA_FALSE;
2006    wd->selmode = EINA_FALSE;
2007    evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
2008    if (wd->sel_notify_handler)
2009      {
2010         if (wd->cut_sel)
2011           {
2012 #ifdef HAVE_ELEMENTARY_X
2013              Evas_Object *top;
2014
2015              top = elm_widget_top_get(data);
2016              if ((top) && (elm_win_xwindow_get(top)))
2017                elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
2018                                  wd->cut_sel);
2019 #endif
2020              eina_stringshare_del(wd->cut_sel);
2021              wd->cut_sel = NULL;
2022           }
2023         else
2024           {
2025 #ifdef HAVE_ELEMENTARY_X
2026              Evas_Object *top;
2027
2028              top = elm_widget_top_get(data);
2029              if ((top) && (elm_win_xwindow_get(top)))
2030                elm_selection_clear(ELM_SEL_PRIMARY, data);
2031 #endif
2032           }
2033      }
2034
2035    if ((wd->api) && (wd->api->obj_hidemenu))
2036      {
2037         wd->api->obj_hidemenu(data);
2038      }
2039 }
2040
2041 static void
2042 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2043 {
2044    Widget_Data *wd = elm_widget_data_get(data);
2045    if (!wd) return;
2046    evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
2047    if (wd->sel_notify_handler)
2048      {
2049 #ifdef HAVE_ELEMENTARY_X
2050         Evas_Object *top;
2051
2052         top = elm_widget_top_get(data);
2053         if ((top) && (elm_win_xwindow_get(top)))
2054           {
2055              wd->selection_asked = EINA_TRUE;
2056              elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
2057                                NULL, NULL);
2058           }
2059 #endif
2060      }
2061 }
2062
2063 static void
2064 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2065 {
2066    Widget_Data *wd = elm_widget_data_get(data);
2067    if (!wd) return;
2068    evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
2069    elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
2070                      elm_entry_selection_get(data));
2071 }
2072
2073 static void
2074 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2075 {
2076    Widget_Data *wd = elm_widget_data_get(data);
2077    if (!wd) return;
2078    evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
2079    elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
2080                      elm_entry_selection_get(data));
2081    edje_object_part_text_insert(wd->ent, "elm.text", "");
2082    wd->changed = EINA_TRUE;
2083    _sizing_eval(data);
2084 }
2085
2086 static void
2087 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2088 {
2089    Widget_Data *wd = elm_widget_data_get(data);
2090    if (!wd) return;
2091    wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2092    wd->cur_changed = EINA_TRUE;
2093    _recalc_cursor_geometry(data);
2094 }
2095
2096 static void
2097 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2098 {
2099    Widget_Data *wd = elm_widget_data_get(data);
2100    if (!wd) return;
2101 }
2102
2103 static void
2104 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2105 {
2106    Widget_Data *wd = elm_widget_data_get(data);
2107    if (!wd) return;
2108 }
2109
2110 static void
2111 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
2112 {
2113    Widget_Data *wd = elm_widget_data_get(data);
2114    Elm_Entry_Anchor_Info ei;
2115    char *buf2, *p, *p2, *n;
2116    if (!wd) return;
2117    p = strrchr(emission, ',');
2118    if (p)
2119      {
2120         const Eina_List *geoms;
2121
2122         n = p + 1;
2123         p2 = p -1;
2124         while (p2 >= emission)
2125           {
2126              if (*p2 == ',') break;
2127              p2--;
2128           }
2129         p2++;
2130         buf2 = alloca(5 + p - p2);
2131         strncpy(buf2, p2, p - p2);
2132         buf2[p - p2] = 0;
2133         ei.name = n;
2134         ei.button = atoi(buf2);
2135         ei.x = ei.y = ei.w = ei.h = 0;
2136         geoms =
2137            edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
2138         if (geoms)
2139           {
2140              Evas_Textblock_Rectangle *r;
2141              const Eina_List *l;
2142              Evas_Coord px, py, x, y;
2143
2144              evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
2145              evas_pointer_canvas_xy_get(evas_object_evas_get(wd->ent), &px, &py);
2146              EINA_LIST_FOREACH(geoms, l, r)
2147                {
2148                   if (((r->x + x) <= px) && ((r->y + y) <= py) &&
2149                       ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
2150                     {
2151                        ei.x = r->x + x;
2152                        ei.y = r->y + y;
2153                        ei.w = r->w;
2154                        ei.h = r->h;
2155                        break;
2156                     }
2157                }
2158           }
2159         if (!wd->disabled)
2160           evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
2161      }
2162 }
2163
2164 static void
2165 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2166 {
2167    Widget_Data *wd = elm_widget_data_get(data);
2168    if (!wd) return;
2169 }
2170
2171 static void
2172 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2173 {
2174    Widget_Data *wd = elm_widget_data_get(data);
2175    if (!wd) return;
2176 }
2177
2178 static void
2179 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2180 {
2181    Widget_Data *wd = elm_widget_data_get(data);
2182    if (!wd) return;
2183 }
2184
2185 static void
2186 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2187 {
2188    Widget_Data *wd = elm_widget_data_get(data);
2189    if (!wd) return;
2190    evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
2191 }
2192
2193 static void
2194 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2195 {
2196    Widget_Data *wd = elm_widget_data_get(data);
2197    if (!wd) return;
2198    wd->double_clicked = EINA_FALSE;
2199    evas_object_smart_callback_call(data, SIG_PRESS, NULL);
2200
2201    if ((wd->api) && (wd->api->obj_hidemenu))
2202      {
2203         wd->api->obj_hidemenu(data);
2204      }
2205 }
2206
2207 static void
2208 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2209 {
2210    Widget_Data *wd = elm_widget_data_get(data);
2211    if (!wd) return;
2212    evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
2213 }
2214
2215 static void
2216 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2217 {
2218    Widget_Data *wd = elm_widget_data_get(data);
2219    if (!wd) return;
2220    wd->double_clicked = EINA_TRUE;
2221    evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
2222 }
2223
2224 #ifdef HAVE_ELEMENTARY_X
2225 static Eina_Bool
2226 _event_selection_notify(void *data, int type __UNUSED__, void *event)
2227 {
2228    Widget_Data *wd = elm_widget_data_get(data);
2229    Ecore_X_Event_Selection_Notify *ev = event;
2230    if (!wd) return ECORE_CALLBACK_PASS_ON;
2231    if ((!wd->selection_asked) && (!wd->drag_selection_asked))
2232      return ECORE_CALLBACK_PASS_ON;
2233
2234    if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
2235        (ev->selection == ECORE_X_SELECTION_PRIMARY))
2236      {
2237         Ecore_X_Selection_Data_Text *text_data;
2238
2239         text_data = ev->data;
2240         if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
2241           {
2242              if (text_data->text)
2243                {
2244                   char *txt = _elm_util_text_to_mkup(text_data->text);
2245
2246                   if (txt)
2247                     {
2248                        elm_entry_entry_insert(data, txt);
2249                        free(txt);
2250                     }
2251                }
2252           }
2253         wd->selection_asked = EINA_FALSE;
2254      }
2255    else if (ev->selection == ECORE_X_SELECTION_XDND)
2256      {
2257         Ecore_X_Selection_Data_Text *text_data;
2258
2259         text_data = ev->data;
2260         if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
2261           {
2262              if (text_data->text)
2263                {
2264                   char *txt = _elm_util_text_to_mkup(text_data->text);
2265
2266                   if (txt)
2267                     {
2268                        /* Massive FIXME: this should be at the drag point */
2269                        elm_entry_entry_insert(data, txt);
2270                        free(txt);
2271                     }
2272                }
2273           }
2274         wd->drag_selection_asked = EINA_FALSE;
2275
2276         ecore_x_dnd_send_finished();
2277
2278      }
2279    return ECORE_CALLBACK_PASS_ON;
2280 }
2281
2282 static Eina_Bool
2283 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
2284 {
2285 /*
2286    Widget_Data *wd = elm_widget_data_get(data);
2287    Ecore_X_Event_Selection_Clear *ev = event;
2288    if (!wd) return ECORE_CALLBACK_PASS_ON;
2289    if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
2290    if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
2291        (ev->selection == ECORE_X_SELECTION_PRIMARY))
2292      {
2293         elm_entry_select_none(data);
2294      }
2295    return 1; */
2296
2297    // start for cbhm
2298    Evas_Object *top = elm_widget_top_get(data);
2299    Ecore_X_Event_Selection_Clear *ev = event;
2300
2301    if (!top)
2302       return ECORE_CALLBACK_PASS_ON;
2303
2304    if (ev->selection != ECORE_X_SELECTION_SECONDARY)
2305      {
2306         return ECORE_CALLBACK_PASS_ON;
2307      }
2308
2309    if (cnpwidgetdata == data)
2310      {
2311         elm_selection_get(ELM_SEL_SECONDARY,ELM_SEL_FORMAT_MARKUP,data,NULL,NULL);
2312      }
2313
2314    // end for cbhm
2315    return ECORE_CALLBACK_PASS_ON;
2316 }
2317
2318 static Eina_Bool
2319 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
2320 {
2321    Widget_Data *wd;
2322    Eina_Bool rv;
2323
2324    wd = elm_widget_data_get(obj);
2325    if (!wd) return EINA_FALSE;
2326    printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
2327
2328    edje_object_part_text_cursor_copy(wd->ent, "elm.text",
2329                                      EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
2330    rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
2331                                                EDJE_CURSOR_MAIN,drop->x,drop->y);
2332    if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
2333    elm_entry_entry_insert(obj, drop->data);
2334    edje_object_part_text_cursor_copy(wd->ent, "elm.text",
2335                                      EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
2336
2337    return EINA_TRUE;
2338 }
2339 #endif
2340
2341 static Evas_Object *
2342 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
2343 {
2344    Widget_Data *wd = elm_widget_data_get(data);
2345    Evas_Object *o;
2346    Eina_List *l;
2347    Elm_Entry_Item_Provider *ip;
2348
2349    EINA_LIST_FOREACH(wd->item_providers, l, ip)
2350      {
2351         o = ip->func(ip->data, data, item);
2352         if (o) return o;
2353      }
2354    if (!strncmp(item, "file://", 7))
2355      {
2356         const char *fname = item + 7;
2357
2358         o = evas_object_image_filled_add(evas_object_evas_get(data));
2359         evas_object_image_file_set(o, fname, NULL);
2360         if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
2361           {
2362              evas_object_show(o);
2363           }
2364         else
2365           {
2366              evas_object_del(o);
2367              o = edje_object_add(evas_object_evas_get(data));
2368              _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
2369           }
2370         return o;
2371      }
2372    o = edje_object_add(evas_object_evas_get(data));
2373    if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
2374      _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
2375    return o;
2376 }
2377
2378 static int
2379 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
2380 {
2381    const char *srcstring = NULL;
2382    Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
2383    char *curlocater, *replocater;
2384    char *starttag, *endtag;
2385    int tagtxtlen = 0, insertflag = 0;
2386
2387    srcstring = eina_strbuf_string_get(srcbuf);
2388    curlocater = strstr(srcstring, key);
2389
2390    if (!curlocater || !srcstring)
2391      {
2392        insertflag = 1;
2393      }
2394    else
2395      {
2396        do
2397          {
2398            starttag = strchr(srcstring, '<');
2399            endtag = strchr(srcstring, '>');
2400            tagtxtlen = endtag - starttag;
2401            if (tagtxtlen <= 0) tagtxtlen = 0;
2402            if (starttag < curlocater && curlocater < endtag) break;
2403            if (endtag != NULL && endtag+1 != NULL)
2404              srcstring = endtag+1;
2405            else
2406              break;
2407          } while (strlen(srcstring) > 1);
2408
2409        if (starttag && endtag && tagtxtlen > strlen(key))
2410          {
2411            repbuf = eina_strbuf_new();
2412            diffbuf = eina_strbuf_new();
2413            eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
2414            srcstring = eina_strbuf_string_get(repbuf);
2415            curlocater = strstr(srcstring, key);
2416
2417            if (curlocater != NULL)
2418              {
2419                replocater = curlocater + strlen(key) + 1;
2420
2421                while ((*replocater) && (*replocater != ' ') && (*replocater != '>'))
2422                  replocater++;
2423
2424                if (replocater-curlocater > strlen(key)+1)
2425                  {
2426                    eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
2427                  }
2428                else
2429                  insertflag = 1;
2430              }
2431            else
2432              {
2433                insertflag = 1;
2434              }
2435            eina_strbuf_reset(repbuf);
2436          }
2437        else
2438          {
2439            insertflag = 1;
2440          }
2441      }
2442
2443    if (repbuf == NULL) repbuf = eina_strbuf_new();
2444    if (diffbuf == NULL) diffbuf = eina_strbuf_new();
2445
2446    if (insertflag)
2447      {
2448        eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
2449        eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
2450      }
2451    else
2452      {
2453         if (deleteflag)
2454           {
2455             eina_strbuf_prepend(diffbuf, "<");
2456             eina_strbuf_append(diffbuf, ">");
2457             eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
2458           }
2459         else
2460           {
2461             eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
2462             eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
2463           }
2464      }
2465
2466    if (repbuf) eina_strbuf_free(repbuf);
2467    if (diffbuf) eina_strbuf_free(diffbuf);
2468
2469    return 0;
2470 }
2471
2472 static int
2473 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
2474 {
2475    Eina_Strbuf *sharebuf = NULL;
2476
2477    sharebuf = eina_strbuf_new();
2478    eina_strbuf_append(sharebuf, *srcstring);
2479    _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
2480    eina_stringshare_del(*srcstring);
2481    *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
2482    eina_strbuf_free(sharebuf);
2483
2484    return 0;
2485 }
2486
2487 static void
2488 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
2489 {
2490    Widget_Data *wd = elm_widget_data_get(data);
2491    Eina_List *l;
2492    Elm_Entry_Text_Filter *tf;
2493
2494    if (type == EDJE_TEXT_FILTER_FORMAT)
2495      return;
2496
2497    EINA_LIST_FOREACH(wd->text_filters, l, tf)
2498      {
2499         tf->func(tf->data, data, text);
2500         if (!*text)
2501           break;
2502      }
2503 }
2504
2505 /* This function is used to insert text by chunks in jobs */
2506 static Eina_Bool
2507 _text_append_idler(void *data)
2508 {
2509    int start;
2510    char backup;
2511    Evas_Object *obj = (Evas_Object *) data;
2512    Widget_Data *wd = elm_widget_data_get(obj);
2513    if (wd->text) eina_stringshare_del(wd->text);
2514    wd->text = NULL;
2515    if (wd->password_text) eina_stringshare_del(wd->password_text);
2516    wd->password_text = NULL;
2517    wd->changed = EINA_TRUE;
2518
2519    start = wd->append_text_position;
2520    if (start + _CHUNK_SIZE < wd->append_text_len)
2521      {
2522         int pos = start;
2523         int tag_start, esc_start;
2524
2525         tag_start = esc_start = -1;
2526         /* Find proper markup cut place */
2527         while (pos - start < _CHUNK_SIZE)
2528           {
2529              int prev_pos = pos;
2530              Eina_Unicode tmp =
2531                 eina_unicode_utf8_get_next(wd->append_text_left, &pos);
2532              if (esc_start == -1)
2533                {
2534                   if (tmp == '<')
2535                      tag_start = prev_pos;
2536                   else if (tmp == '>')
2537                      tag_start = -1;
2538                }
2539              else if (tag_start == -1)
2540                {
2541                   if (tmp == '&')
2542                      esc_start = prev_pos;
2543                   else if (tmp == ';')
2544                      esc_start = -1;
2545                }
2546           }
2547
2548         if (tag_start >= 0)
2549           {
2550              wd->append_text_position = tag_start;
2551           }
2552         else if (esc_start >= 0)
2553           {
2554              wd->append_text_position = esc_start;
2555           }
2556         else
2557           {
2558              wd->append_text_position = pos;
2559           }
2560      }
2561    else
2562      {
2563         wd->append_text_position = wd->append_text_len;
2564      }
2565
2566    backup = wd->append_text_left[wd->append_text_position];
2567    wd->append_text_left[wd->append_text_position] = '\0';
2568
2569    edje_object_part_text_append(wd->ent, "elm.text",
2570          wd->append_text_left + start);
2571
2572    wd->append_text_left[wd->append_text_position] = backup;
2573
2574    /* If there's still more to go, renew the idler, else, cleanup */
2575    if (wd->append_text_position < wd->append_text_len)
2576      {
2577         return ECORE_CALLBACK_RENEW;
2578      }
2579    else
2580      {
2581         free(wd->append_text_left);
2582         wd->append_text_left = NULL;
2583         wd->append_text_idler = NULL;
2584         return ECORE_CALLBACK_CANCEL;
2585      }
2586 }
2587
2588 static void
2589 _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit)
2590 {
2591    int i = 0, unit_size;
2592    int current_len = strlen(*text);
2593    char *new_text = *text;
2594    if (unit >= LENGTH_UNIT_LAST) return;
2595    while (*new_text)
2596      {
2597         if (*new_text == '<')
2598           {
2599              while (*new_text != '>')
2600                {
2601                   new_text++;
2602                   if (!*new_text) break;
2603                }
2604              new_text++;
2605           }
2606         else
2607           {
2608              int index = 0;
2609              if (*new_text == '&')
2610                {
2611                   while (*(new_text + index) != ';')
2612                     {
2613                        index++;
2614                        if (!*(new_text + index)) break;
2615                     }
2616                }
2617              char *markup;
2618              index = evas_string_char_next_get(new_text, index, NULL);
2619              markup = malloc(index + 1);
2620              strncpy(markup, new_text, index);
2621              markup[index] = 0;
2622              if (unit == LENGTH_UNIT_BYTE)
2623                unit_size = strlen(elm_entry_markup_to_utf8(markup));
2624              else if (unit == LENGTH_UNIT_CHAR)
2625                unit_size = evas_string_char_len_get(elm_entry_markup_to_utf8(markup));
2626              if (markup)
2627                {
2628                   free(markup);
2629                   markup = NULL;
2630                }
2631              if (can_add < unit_size)
2632                {
2633                   if (!i)
2634                     {
2635                        evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
2636                        free(*text);
2637                        *text = NULL;
2638                        return;
2639                     }
2640                   can_add = 0;
2641                   strncpy(new_text, new_text + index, current_len - ((new_text + index) - *text));
2642                   current_len -= index;
2643                   (*text)[current_len] = 0;
2644                }
2645              else
2646                {
2647                   new_text += index;
2648                   can_add -= unit_size;
2649                }
2650              i++;
2651           }
2652      }
2653    evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
2654 }
2655
2656 static void
2657 _elm_entry_text_set(Evas_Object *obj, const char *item, const char *entry)
2658 {
2659    int len = 0;
2660    ELM_CHECK_WIDTYPE(obj, widtype);
2661    if (item && strcmp(item, "default")) return;
2662    Widget_Data *wd = elm_widget_data_get(obj);
2663    if (!wd) return;
2664    if (!entry) entry = "";
2665    if (wd->text) eina_stringshare_del(wd->text);
2666    wd->text = NULL;
2667    if (wd->password_text) eina_stringshare_del(wd->password_text);
2668    wd->password_text = NULL;
2669    wd->changed = EINA_TRUE;
2670
2671    /* Clear currently pending job if there is one */
2672    if (wd->append_text_idler)
2673      {
2674         ecore_idler_del(wd->append_text_idler);
2675         free(wd->append_text_left);
2676         wd->append_text_left = NULL;
2677         wd->append_text_idler = NULL;
2678      }
2679
2680    len = strlen(entry);
2681    /* Split to ~_CHUNK_SIZE chunks */
2682    if (len > _CHUNK_SIZE)
2683      {
2684         wd->append_text_left = (char *) malloc(len + 1);
2685      }
2686
2687    /* If we decided to use the idler */
2688    if (wd->append_text_left)
2689      {
2690         /* Need to clear the entry first */
2691         edje_object_part_text_set(wd->ent, "elm.text", "");
2692         memcpy(wd->append_text_left, entry, len + 1);
2693         wd->append_text_position = 0;
2694         wd->append_text_len = len;
2695         wd->append_text_idler = ecore_idler_add(_text_append_idler, obj);
2696      }
2697    else
2698      {
2699         edje_object_part_text_set(wd->ent, "elm.text", entry);
2700      }
2701 }
2702
2703 static const char *
2704 _elm_entry_text_get(const Evas_Object *obj, const char *item)
2705 {
2706    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2707    Widget_Data *wd = elm_widget_data_get(obj);
2708    if (item && strcmp(item, "default")) return NULL;
2709    const char *text;
2710    if (!wd) return NULL;
2711    if (wd->password)
2712      {
2713         if(wd->password_text) return wd->password_text;
2714      }
2715    else if (wd->text) 
2716      {
2717         return wd->text;
2718      }
2719    text = edje_object_part_text_get(wd->ent, "elm.text");
2720    if (!text)
2721      {
2722         ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2723         return NULL;
2724      }
2725    eina_stringshare_replace(&wd->text, text);
2726    if (wd->password)
2727      {
2728         const char *pw_text;
2729         pw_text = elm_entry_markup_to_utf8(wd->text);
2730         if (pw_text)
2731           {
2732              eina_stringshare_replace(&wd->password_text, pw_text);
2733              free(pw_text);
2734              return wd->password_text;
2735           }
2736      }
2737    return wd->text;
2738 }
2739
2740 /**
2741  * This adds an entry to @p parent object.
2742  *
2743  * @param parent The parent object
2744  * @return The new object or NULL if it cannot be created
2745  *
2746  * @ingroup Entry
2747  */
2748 EAPI Evas_Object *
2749 elm_entry_add(Evas_Object *parent)
2750 {
2751    Evas_Object *obj, *top;
2752    Evas *e;
2753    Widget_Data *wd;
2754
2755    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
2756
2757    ELM_SET_WIDTYPE(widtype, "entry");
2758    elm_widget_type_set(obj, "entry");
2759    elm_widget_sub_object_add(parent, obj);
2760    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2761    elm_widget_data_set(obj, wd);
2762    elm_widget_del_hook_set(obj, _del_hook);
2763    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2764    elm_widget_theme_hook_set(obj, _theme_hook);
2765    elm_widget_disable_hook_set(obj, _disable_hook);
2766    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2767    elm_widget_focus_region_hook_set(obj, _focus_region_hook);
2768    elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
2769    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
2770    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
2771    elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
2772    elm_widget_can_focus_set(obj, EINA_TRUE);
2773    elm_widget_highlight_ignore_set(obj, EINA_TRUE);
2774    elm_widget_text_set_hook_set(obj, _elm_entry_text_set);
2775    elm_widget_text_get_hook_set(obj, _elm_entry_text_get);
2776
2777    wd->scroller = elm_smart_scroller_add(e);
2778    elm_widget_sub_object_add(obj, wd->scroller);
2779    elm_smart_scroller_widget_set(wd->scroller, obj);
2780    elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
2781                                        elm_widget_style_get(obj));
2782    evas_object_size_hint_weight_set(wd->scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2783    evas_object_size_hint_align_set(wd->scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
2784    elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
2785    elm_smart_scroller_propagate_events_set(wd->scroller, EINA_TRUE);
2786
2787    wd->linewrap     = ELM_WRAP_WORD;
2788    wd->editable     = EINA_TRUE;
2789    wd->disabled     = EINA_FALSE;
2790    wd->context_menu = EINA_TRUE;
2791    wd->autosave     = EINA_TRUE;
2792    wd->textonly     = EINA_FALSE;
2793    wd->autoperiod   = EINA_TRUE;
2794
2795    wd->ent = edje_object_add(e);
2796    elm_widget_sub_object_add(obj, wd->ent);
2797    edje_object_item_provider_set(wd->ent, _get_item, obj);
2798    edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
2799    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
2800    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
2801                                   _mouse_down, obj);
2802    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
2803                                   _mouse_up, obj);
2804    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
2805                                   _mouse_move, obj);
2806    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
2807
2808    _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
2809    edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
2810                                    _signal_entry_changed, obj);
2811    edje_object_signal_callback_add(wd->ent, "preedit,changed", "elm.text",
2812                                    _signal_preedit_changed, obj);
2813    edje_object_signal_callback_add(wd->ent, "handler,move,start", "elm.text",
2814                                    _signal_handler_move_start, obj);
2815    edje_object_signal_callback_add(wd->ent, "handler,move,end", "elm.text",
2816                                    _signal_handler_move_end, obj);
2817    edje_object_signal_callback_add(wd->ent, "handler,moving", "elm.text",
2818                                    _signal_handler_moving, obj);
2819    edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
2820                                    _signal_selection_start, obj);
2821    edje_object_signal_callback_add(wd->ent, "selection,end", "elm.text",
2822                                    _signal_selection_end, obj);
2823    edje_object_signal_callback_add(wd->ent, "magnifier,changed", "elm.text",
2824                                    _signal_magnifier_changed, obj);
2825    edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
2826                                    _signal_selection_changed, obj);
2827    edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2828                                    _signal_selection_cleared, obj);
2829    edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
2830                                    _signal_entry_paste_request, obj);
2831    edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2832                                    _signal_entry_copy_notify, obj);
2833    edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2834                                    _signal_entry_cut_notify, obj);
2835    edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2836                                    _signal_cursor_changed, obj);
2837    edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2838                                    _signal_anchor_down, obj);
2839    edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2840                                    _signal_anchor_up, obj);
2841    edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
2842                                    _signal_anchor_clicked, obj);
2843    edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2844                                    _signal_anchor_move, obj);
2845    edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2846                                    _signal_anchor_in, obj);
2847    edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2848                                    _signal_anchor_out, obj);
2849    edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2850                                    _signal_key_enter, obj);
2851    edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2852                                    _signal_mouse_down, obj);
2853    edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2854                                    _signal_mouse_clicked, obj);
2855    edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2856                                    _signal_mouse_double, obj);
2857    edje_object_part_text_set(wd->ent, "elm.text", "");
2858    if (_elm_config->desktop_entry)
2859      edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
2860    elm_widget_resize_object_set(obj, wd->ent);
2861    _sizing_eval(obj);
2862
2863    wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
2864
2865 #ifdef HAVE_ELEMENTARY_X
2866    top = elm_widget_top_get(obj);
2867    if ((top) && (elm_win_xwindow_get(top)))
2868      {
2869         wd->sel_notify_handler =
2870            ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2871                                    _event_selection_notify, obj);
2872         wd->sel_clear_handler =
2873            ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2874                                    _event_selection_clear, obj);
2875      }
2876
2877    elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
2878                        _drag_drop_cb, NULL);
2879 #endif
2880
2881    entries = eina_list_prepend(entries, obj);
2882
2883    // module - find module for entry
2884    wd->api = _module(obj);
2885    // if found - hook in
2886    if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2887
2888    _mirrored_set(obj, elm_widget_mirrored_get(obj));
2889    // TODO: convert Elementary to subclassing of Evas_Smart_Class
2890    // TODO: and save some bytes, making descriptions per-class and not instance!
2891    evas_object_smart_callbacks_descriptions_set(obj, _signals);
2892    return obj;
2893 }
2894
2895 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
2896 {
2897    ELM_CHECK_WIDTYPE(obj, widtype);
2898    Widget_Data *wd = elm_widget_data_get(obj);
2899    if (!wd) return;
2900    ext_mod->cancel = _cancel;
2901    ext_mod->copy = _copy;
2902    ext_mod->cut = _cut;
2903    ext_mod->paste = _paste;
2904    ext_mod->select = _select;
2905    ext_mod->selectall = _selectall;
2906    ext_mod->ent = wd->ent;
2907    ext_mod->items = wd->items;
2908    ext_mod->longpress_timer = wd->longpress_timer;
2909    ext_mod->editable = wd->editable;
2910    ext_mod->have_selection = wd->have_selection;
2911    ext_mod->password = wd->password;
2912    ext_mod->selmode = wd->selmode;
2913    ext_mod->cnpinit = _cnpinit;
2914    ext_mod->context_menu = wd->context_menu;
2915    ext_mod->textonly = wd->textonly;
2916 }
2917
2918 /**
2919  * This sets the entry object not to line wrap.  All input will
2920  * be on a single line, and the entry box will extend with user input.
2921  *
2922  * @param obj The entry object
2923  * @param single_line If true, the text in the entry
2924  * will be on a single line.
2925  *
2926  * @ingroup Entry
2927  */
2928 EAPI void
2929 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2930 {
2931    ELM_CHECK_WIDTYPE(obj, widtype);
2932    Widget_Data *wd = elm_widget_data_get(obj);
2933    if (!wd) return;
2934    if (wd->single_line == single_line) return;
2935    wd->single_line = single_line;
2936    wd->linewrap = ELM_WRAP_NONE;
2937    elm_entry_cnp_textonly_set(obj, EINA_TRUE);
2938    _theme_hook(obj);
2939    if (wd->scroller)
2940      {
2941         if (wd->single_line)
2942           {
2943              elm_smart_scroller_policy_set(wd->scroller,
2944                                            ELM_SMART_SCROLLER_POLICY_OFF,
2945                                            ELM_SMART_SCROLLER_POLICY_OFF);
2946              elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
2947           }
2948         else
2949           {
2950              const Elm_Scroller_Policy map[3] =
2951                {
2952                   ELM_SMART_SCROLLER_POLICY_AUTO,
2953                   ELM_SMART_SCROLLER_POLICY_ON,
2954                   ELM_SMART_SCROLLER_POLICY_OFF
2955                };
2956              elm_smart_scroller_policy_set(wd->scroller,
2957                                            map[wd->policy_h],
2958                                            map[wd->policy_v]);
2959              elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
2960           }
2961         _sizing_eval(obj);
2962      }
2963 }
2964
2965 /**
2966  * This returns true if the entry has been set to single line mode.
2967  * See also elm_entry_single_line_set().
2968  *
2969  * @param obj The entry object
2970  * @return single_line If true, the text in the entry is set to display
2971  * on a single line.
2972  *
2973  * @ingroup Entry
2974  */
2975 EAPI Eina_Bool
2976 elm_entry_single_line_get(const Evas_Object *obj)
2977 {
2978    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2979    Widget_Data *wd = elm_widget_data_get(obj);
2980    if (!wd) return EINA_FALSE;
2981    return wd->single_line;
2982 }
2983
2984 /**
2985  * This sets the entry object to password mode.  All text entered
2986  * and/or displayed within the widget will be replaced with asterisks (*).
2987  *
2988  * @param obj The entry object
2989  * @param password If true, password mode is enabled.
2990  *
2991  * @ingroup Entry
2992  */
2993 EAPI void
2994 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2995 {
2996    ELM_CHECK_WIDTYPE(obj, widtype);
2997    Widget_Data *wd = elm_widget_data_get(obj);
2998    if (!wd) return;
2999    if (wd->password == password) return;
3000    wd->password = password;
3001    wd->single_line = EINA_TRUE;
3002    wd->linewrap = ELM_WRAP_NONE;
3003    _theme_hook(obj);
3004 }
3005
3006 /**
3007  * This returns whether password mode is enabled.
3008  * See also elm_entry_password_set().
3009  *
3010  * @param obj The entry object
3011  * @return If true, the entry is set to display all characters
3012  * as asterisks (*).
3013  *
3014  * @ingroup Entry
3015  */
3016 EAPI Eina_Bool
3017 elm_entry_password_get(const Evas_Object *obj)
3018 {
3019    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3020    Widget_Data *wd = elm_widget_data_get(obj);
3021    if (!wd) return EINA_FALSE;
3022    return wd->password;
3023 }
3024
3025 /**
3026  * This sets the text displayed within the entry to @p entry.
3027  *
3028  * @param obj The entry object
3029  * @param entry The text to be displayed
3030  *
3031  * @ingroup Entry
3032  */
3033 EAPI void
3034 elm_entry_entry_set(Evas_Object *obj, const char *entry)
3035 {
3036    _elm_entry_text_set(obj, NULL, entry);
3037 }
3038
3039 /**
3040  * This appends @p entry to the text of the entry.
3041  *
3042  * @param obj The entry object
3043  * @param entry The text to be displayed
3044  *
3045  * @ingroup Entry
3046  */
3047 EAPI void
3048 elm_entry_entry_append(Evas_Object *obj, const char *entry)
3049 {
3050    int len = 0;
3051    ELM_CHECK_WIDTYPE(obj, widtype);
3052    Widget_Data *wd = elm_widget_data_get(obj);
3053    if (!wd) return;
3054    if (!entry) entry = "";
3055    wd->changed = EINA_TRUE;
3056
3057    len = strlen(entry);
3058    if (wd->append_text_left)
3059      {
3060         char *tmpbuf;
3061         tmpbuf = realloc(wd->append_text_left, wd->append_text_len + len + 1);
3062         if (!tmpbuf)
3063           {
3064              /* Do something */
3065              return;
3066           }
3067         wd->append_text_left = tmpbuf;
3068         memcpy(wd->append_text_left + wd->append_text_len, entry, len + 1);
3069         wd->append_text_len += len;
3070      }
3071    else
3072      {
3073         /* FIXME: Add chunked appending here (like in entry_set) */
3074         edje_object_part_text_append(wd->ent, "elm.text", entry);
3075      }
3076 }
3077
3078 /**
3079  * This returns the text currently shown in object @p entry.
3080  * See also elm_entry_entry_set().
3081  *
3082  * @param obj The entry object
3083  * @return The currently displayed text or NULL on failure
3084  *
3085  * @ingroup Entry
3086  */
3087 EAPI const char *
3088 elm_entry_entry_get(const Evas_Object *obj)
3089 {
3090    return _elm_entry_text_get(obj, NULL);
3091 }
3092
3093 /**
3094  * This returns EINA_TRUE if the entry is empty/there was an error
3095  * and EINA_FALSE if it is not empty.
3096  *
3097  * @param obj The entry object
3098  * @return If the entry is empty or not.
3099  *
3100  * @ingroup Entry
3101  */
3102 EAPI Eina_Bool
3103 elm_entry_is_empty(const Evas_Object *obj)
3104 {
3105    /* FIXME: until there's support for that in textblock, we just check
3106     * to see if the there is text or not. */
3107    ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
3108    Widget_Data *wd = elm_widget_data_get(obj);
3109    const Evas_Object *tb;
3110    //Evas_Textblock_Cursor *cur;
3111    Eina_Bool ret;
3112    if (!wd) return EINA_TRUE;
3113
3114 #if 0
3115    /* It's a hack until we get the support suggested above.
3116     * We just create a cursor, point it to the begining, and then
3117     * try to advance it, if it can advance, the tb is not empty,
3118     * otherwise it is. */
3119    tb = edje_object_part_object_get(wd->ent, "elm.text");
3120    cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
3121                                                                   actually, ok for the time being, thsese hackish stuff will be removed
3122                                                                   once evas 1.0 is out*/
3123    evas_textblock_cursor_pos_set(cur, 0);
3124    ret = evas_textblock_cursor_char_next(cur);
3125    evas_textblock_cursor_free(cur);
3126
3127    return !ret;
3128 #endif
3129
3130    char *str = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
3131    if (!str) return EINA_TRUE;
3132
3133    ret = (strlen(str) == 0);
3134
3135    return ret;
3136 }
3137
3138 /**
3139  * This returns all selected text within the entry.
3140  *
3141  * @param obj The entry object
3142  * @return The selected text within the entry or NULL on failure
3143  *
3144  * @ingroup Entry
3145  */
3146 EAPI const char *
3147 elm_entry_selection_get(const Evas_Object *obj)
3148 {
3149    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3150    Widget_Data *wd = elm_widget_data_get(obj);
3151    if (!wd) return NULL;
3152    return edje_object_part_text_selection_get(wd->ent, "elm.text");
3153 }
3154
3155 /**
3156  * This inserts text in @p entry where the current cursor position.
3157  *
3158  * This inserts text at the cursor position is as if it was typed
3159  * by the user (note this also allows markup which a user
3160  * can't just "type" as it would be converted to escaped text, so this
3161  * call can be used to insert things like emoticon items or bold push/pop
3162  * tags, other font and color change tags etc.)
3163  *
3164  * @param obj The entry object
3165  * @param entry The text to insert
3166  *
3167  * @ingroup Entry
3168  */
3169 EAPI void
3170 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
3171 {
3172    ELM_CHECK_WIDTYPE(obj, widtype);
3173    Widget_Data *wd = elm_widget_data_get(obj);
3174    if (!wd) return;
3175    edje_object_part_text_insert(wd->ent, "elm.text", entry);
3176    // start for cbhm
3177 #ifdef HAVE_ELEMENTARY_X
3178    if (cnpwidgetdata == obj)
3179       ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
3180 #endif
3181    // end for cbhm
3182    wd->changed = EINA_TRUE;
3183    _sizing_eval(obj);
3184 }
3185
3186 /**
3187  * This enables word line wrapping in the entry object.  It is the opposite
3188  * of elm_entry_single_line_set().  Additionally, setting this disables
3189  * character line wrapping.
3190  *
3191  * @param obj The entry object
3192  * @param wrap If true, the entry will be wrapped once it reaches the end
3193  * of the object. Wrapping will occur at the end of the word before the end of the
3194  * object.
3195  *
3196  * @ingroup Entry
3197  */
3198 EAPI void
3199 elm_entry_line_wrap_set(Evas_Object *obj, Elm_Wrap_Type wrap)
3200 {
3201    ELM_CHECK_WIDTYPE(obj, widtype);
3202    Widget_Data *wd = elm_widget_data_get(obj);
3203    if (!wd) return;
3204    if (wd->linewrap == wrap) return;
3205    wd->lastw = -1;
3206    wd->linewrap = wrap;
3207    _theme_hook(obj);
3208 }
3209
3210 /**
3211  * Get the wrapping behavior of the entry.
3212  * See also elm_entry_line_wrap_set().
3213  *
3214  * @param obj The entry object
3215  * @return Wrap type
3216  *
3217  * @ingroup Entry
3218  */
3219 EAPI Elm_Wrap_Type
3220 elm_entry_line_wrap_get(const Evas_Object *obj)
3221 {
3222    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3223    Widget_Data *wd = elm_widget_data_get(obj);
3224    if (!wd) return EINA_FALSE;
3225    return wd->linewrap;
3226 }
3227
3228 /**
3229  * This sets the editable attribute of the entry.
3230  *
3231  * @param obj The entry object
3232  * @param editable If true, the entry will be editable by the user.
3233  * If false, it will be set to the disabled state.
3234  *
3235  * @ingroup Entry
3236  */
3237 EAPI void
3238 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
3239 {
3240    ELM_CHECK_WIDTYPE(obj, widtype);
3241    Widget_Data *wd = elm_widget_data_get(obj);
3242    if (!wd) return;
3243    if (wd->editable == editable) return;
3244    wd->editable = editable;
3245    _theme_hook(obj);
3246
3247 #ifdef HAVE_ELEMENTARY_X
3248    if (editable)
3249      elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
3250    else
3251      elm_drop_target_del(obj);
3252 #endif
3253 }
3254
3255 /**
3256  * This gets the editable attribute of the entry.
3257  * See also elm_entry_editable_set().
3258  *
3259  * @param obj The entry object
3260  * @return If true, the entry is editable by the user.
3261  * If false, it is not editable by the user
3262  *
3263  * @ingroup Entry
3264  */
3265 EAPI Eina_Bool
3266 elm_entry_editable_get(const Evas_Object *obj)
3267 {
3268    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3269    Widget_Data *wd = elm_widget_data_get(obj);
3270    if (!wd) return EINA_FALSE;
3271    return wd->editable;
3272 }
3273
3274 /**
3275  * This drops any existing text selection within the entry.
3276  *
3277  * @param obj The entry object
3278  *
3279  * @ingroup Entry
3280  */
3281 EAPI void
3282 elm_entry_select_none(Evas_Object *obj)
3283 {
3284    ELM_CHECK_WIDTYPE(obj, widtype);
3285    Widget_Data *wd = elm_widget_data_get(obj);
3286    if (!wd) return;
3287    if (wd->selmode)
3288      {
3289         wd->selmode = EINA_FALSE;
3290         if (!_elm_config->desktop_entry)
3291           edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
3292         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
3293      }
3294    wd->have_selection = EINA_FALSE;
3295    edje_object_part_text_select_none(wd->ent, "elm.text");
3296 }
3297
3298 /**
3299  * This selects all text within the entry.
3300  *
3301  * @param obj The entry object
3302  *
3303  * @ingroup Entry
3304  */
3305 EAPI void
3306 elm_entry_select_all(Evas_Object *obj)
3307 {
3308    ELM_CHECK_WIDTYPE(obj, widtype);
3309    Widget_Data *wd = elm_widget_data_get(obj);
3310    if (!wd) return;
3311    if (wd->selmode)
3312      {
3313         wd->selmode = EINA_FALSE;
3314         if (!_elm_config->desktop_entry)
3315           edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
3316         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
3317      }
3318    wd->have_selection = EINA_TRUE;
3319    edje_object_part_text_select_all(wd->ent, "elm.text");
3320 }
3321
3322 /**
3323  * This function returns the geometry of the cursor.
3324  *
3325  * It's useful if you want to draw something on the cursor (or where it is),
3326  * or for example in the case of scrolled entry where you want to show the
3327  * cursor.
3328  *
3329  * @param obj The entry object
3330  * @param x returned geometry
3331  * @param y returned geometry
3332  * @param w returned geometry
3333  * @param h returned geometry
3334  * @return EINA_TRUE upon success, EINA_FALSE upon failure
3335  *
3336  * @ingroup Entry
3337  */
3338 EAPI Eina_Bool
3339 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
3340 {
3341    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3342    Widget_Data *wd = elm_widget_data_get(obj);
3343    if (!wd) return EINA_FALSE;
3344    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
3345    return EINA_TRUE;
3346 }
3347
3348 /**
3349  * This moves the cursor one place to the right within the entry.
3350  *
3351  * @param obj The entry object
3352  * @return EINA_TRUE upon success, EINA_FALSE upon failure
3353  *
3354  * @ingroup Entry
3355  */
3356 EAPI Eina_Bool
3357 elm_entry_cursor_next(Evas_Object *obj)
3358 {
3359    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3360    Widget_Data *wd = elm_widget_data_get(obj);
3361    if (!wd) return EINA_FALSE;
3362    return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3363 }
3364
3365 /**
3366  * This moves the cursor one place to the left within the entry.
3367  *
3368  * @param obj The entry object
3369  * @return EINA_TRUE upon success, EINA_FALSE upon failure
3370  *
3371  * @ingroup Entry
3372  */
3373 EAPI Eina_Bool
3374 elm_entry_cursor_prev(Evas_Object *obj)
3375 {
3376    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3377    Widget_Data *wd = elm_widget_data_get(obj);
3378    if (!wd) return EINA_FALSE;
3379    return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3380 }
3381
3382 /**
3383  * This moves the cursor one line up within the entry.
3384  *
3385  * @param obj The entry object
3386  * @return EINA_TRUE upon success, EINA_FALSE upon failure
3387  *
3388  * @ingroup Entry
3389  */
3390 EAPI Eina_Bool
3391 elm_entry_cursor_up(Evas_Object *obj)
3392 {
3393    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3394    Widget_Data *wd = elm_widget_data_get(obj);
3395    if (!wd) return EINA_FALSE;
3396    return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3397 }
3398
3399 /**
3400  * This moves the cursor one line down within the entry.
3401  *
3402  * @param obj The entry object
3403  * @return EINA_TRUE upon success, EINA_FALSE upon failure
3404  *
3405  * @ingroup Entry
3406  */
3407 EAPI Eina_Bool
3408 elm_entry_cursor_down(Evas_Object *obj)
3409 {
3410    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3411    Widget_Data *wd = elm_widget_data_get(obj);
3412    if (!wd) return EINA_FALSE;
3413    return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3414 }
3415
3416 /**
3417  * This moves the cursor to the beginning of the entry.
3418  *
3419  * @param obj The entry object
3420  *
3421  * @ingroup Entry
3422  */
3423 EAPI void
3424 elm_entry_cursor_begin_set(Evas_Object *obj)
3425 {
3426    ELM_CHECK_WIDTYPE(obj, widtype);
3427    Widget_Data *wd = elm_widget_data_get(obj);
3428    if (!wd) return;
3429    edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3430 }
3431
3432 /**
3433  * This moves the cursor to the end of the entry.
3434  *
3435  * @param obj The entry object
3436  *
3437  * @ingroup Entry
3438  */
3439 EAPI void
3440 elm_entry_cursor_end_set(Evas_Object *obj)
3441 {
3442    ELM_CHECK_WIDTYPE(obj, widtype);
3443    Widget_Data *wd = elm_widget_data_get(obj);
3444    if (!wd) return;
3445    int x, y, w, h;
3446    edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3447    if (wd->scroll)
3448      {
3449         elm_widget_show_region_get(wd->ent, &x, &y, &w, &h);
3450         elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
3451      }
3452 }
3453
3454 /**
3455  * This moves the cursor to the beginning of the current line.
3456  *
3457  * @param obj The entry object
3458  *
3459  * @ingroup Entry
3460  */
3461 EAPI void
3462 elm_entry_cursor_line_begin_set(Evas_Object *obj)
3463 {
3464    ELM_CHECK_WIDTYPE(obj, widtype);
3465    Widget_Data *wd = elm_widget_data_get(obj);
3466    if (!wd) return;
3467    edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3468 }
3469
3470 /**
3471  * This moves the cursor to the end of the current line.
3472  *
3473  * @param obj The entry object
3474  *
3475  * @ingroup Entry
3476  */
3477 EAPI void
3478 elm_entry_cursor_line_end_set(Evas_Object *obj)
3479 {
3480    ELM_CHECK_WIDTYPE(obj, widtype);
3481    Widget_Data *wd = elm_widget_data_get(obj);
3482    if (!wd) return;
3483    edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3484 }
3485
3486 /**
3487  * This begins a selection within the entry as though
3488  * the user were holding down the mouse button to make a selection.
3489  *
3490  * @param obj The entry object
3491  *
3492  * @ingroup Entry
3493  */
3494 EAPI void
3495 elm_entry_cursor_selection_begin(Evas_Object *obj)
3496 {
3497    ELM_CHECK_WIDTYPE(obj, widtype);
3498    Widget_Data *wd = elm_widget_data_get(obj);
3499    if (!wd) return;
3500    edje_object_part_text_select_begin(wd->ent, "elm.text");
3501 }
3502
3503 /**
3504  * This ends a selection within the entry as though
3505  * the user had just released the mouse button while making a selection.
3506  *
3507  * @param obj The entry object
3508  *
3509  * @ingroup Entry
3510  */
3511 EAPI void
3512 elm_entry_cursor_selection_end(Evas_Object *obj)
3513 {
3514    ELM_CHECK_WIDTYPE(obj, widtype);
3515    Widget_Data *wd = elm_widget_data_get(obj);
3516    if (!wd) return;
3517    edje_object_part_text_select_extend(wd->ent, "elm.text");
3518 }
3519
3520 /**
3521  * TODO: fill this in
3522  *
3523  * @param obj The entry object
3524  * @return TODO: fill this in
3525  *
3526  * @ingroup Entry
3527  */
3528 EAPI Eina_Bool
3529 elm_entry_cursor_is_format_get(const Evas_Object *obj)
3530 {
3531    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3532    Widget_Data *wd = elm_widget_data_get(obj);
3533    if (!wd) return EINA_FALSE;
3534    return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3535 }
3536
3537 /**
3538  * This returns whether the cursor is visible.
3539  *
3540  * @param obj The entry object
3541  * @return If true, the cursor is visible.
3542  *
3543  * @ingroup Entry
3544  */
3545 EAPI Eina_Bool
3546 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
3547 {
3548    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3549    Widget_Data *wd = elm_widget_data_get(obj);
3550    if (!wd) return EINA_FALSE;
3551    return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3552 }
3553
3554 /**
3555  * TODO: fill this in
3556  *
3557  * @param obj The entry object
3558  * @return TODO: fill this in
3559  *
3560  * @ingroup Entry
3561  */
3562 EAPI const char *
3563 elm_entry_cursor_content_get(const Evas_Object *obj)
3564 {
3565    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3566    Widget_Data *wd = elm_widget_data_get(obj);
3567    if (!wd) return NULL;
3568    return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3569 }
3570
3571 /**
3572  * Sets the cursor position in the entry to the given value
3573  *
3574  * @param obj The entry object
3575  * @param pos The position of the cursor
3576  *
3577  * @ingroup Entry
3578  */
3579 EAPI void
3580 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
3581 {
3582    ELM_CHECK_WIDTYPE(obj, widtype);
3583    Widget_Data *wd = elm_widget_data_get(obj);
3584    if (!wd) return;
3585    edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
3586    edje_object_message_signal_process(wd->ent);
3587 }
3588
3589 /**
3590  * Retrieves the current position of the cursor in the entry
3591  *
3592  * @param obj The entry object
3593  * @return The cursor position
3594  *
3595  * @ingroup Entry
3596  */
3597 EAPI int
3598 elm_entry_cursor_pos_get(const Evas_Object *obj)
3599 {
3600    ELM_CHECK_WIDTYPE(obj, widtype) 0;
3601    Widget_Data *wd = elm_widget_data_get(obj);
3602    if (!wd) return 0;
3603    return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3604 }
3605
3606 /**
3607  * This executes a "cut" action on the selected text in the entry.
3608  *
3609  * @param obj The entry object
3610  *
3611  * @ingroup Entry
3612  */
3613 EAPI void
3614 elm_entry_selection_cut(Evas_Object *obj)
3615 {
3616    ELM_CHECK_WIDTYPE(obj, widtype);
3617    Widget_Data *wd = elm_widget_data_get(obj);
3618    if (!wd) return;
3619    _cut(obj, NULL, NULL);
3620 }
3621
3622 /**
3623  * This executes a "copy" action on the selected text in the entry.
3624  *
3625  * @param obj The entry object
3626  *
3627  * @ingroup Entry
3628  */
3629 EAPI void
3630 elm_entry_selection_copy(Evas_Object *obj)
3631 {
3632    ELM_CHECK_WIDTYPE(obj, widtype);
3633    Widget_Data *wd = elm_widget_data_get(obj);
3634    if (!wd) return;
3635    _copy(obj, NULL, NULL);
3636 }
3637
3638 /**
3639  * This executes a "paste" action in the entry.
3640  *
3641  * @param obj The entry object
3642  *
3643  * @ingroup Entry
3644  */
3645 EAPI void
3646 elm_entry_selection_paste(Evas_Object *obj)
3647 {
3648    ELM_CHECK_WIDTYPE(obj, widtype);
3649    Widget_Data *wd = elm_widget_data_get(obj);
3650    if (!wd) return;
3651    _paste(obj, NULL, NULL);
3652 }
3653
3654 /**
3655  * This clears and frees the items in a entry's contextual (right click) menu.
3656  *
3657  * @param obj The entry object
3658  *
3659  * @ingroup Entry
3660  */
3661 EAPI void
3662 elm_entry_context_menu_clear(Evas_Object *obj)
3663 {
3664    ELM_CHECK_WIDTYPE(obj, widtype);
3665    Widget_Data *wd = elm_widget_data_get(obj);
3666    Elm_Entry_Context_Menu_Item *it;
3667    if (!wd) return;
3668    EINA_LIST_FREE(wd->items, it)
3669      {
3670         eina_stringshare_del(it->label);
3671         eina_stringshare_del(it->icon_file);
3672         eina_stringshare_del(it->icon_group);
3673         free(it);
3674      }
3675 }
3676
3677 /**
3678  * This adds an item to the entry's contextual menu.
3679  *
3680  * @param obj The entry object
3681  * @param label The item's text label
3682  * @param icon_file The item's icon file
3683  * @param icon_type The item's icon type
3684  * @param func The callback to execute when the item is clicked
3685  * @param data The data to associate with the item for related functions
3686  *
3687  * @ingroup Entry
3688  */
3689 EAPI void
3690 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)
3691 {
3692    ELM_CHECK_WIDTYPE(obj, widtype);
3693    Widget_Data *wd = elm_widget_data_get(obj);
3694    Elm_Entry_Context_Menu_Item *it;
3695    if (!wd) return;
3696    it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
3697    if (!it) return;
3698    wd->items = eina_list_append(wd->items, it);
3699    it->obj = obj;
3700    it->label = eina_stringshare_add(label);
3701    it->icon_file = eina_stringshare_add(icon_file);
3702    it->icon_type = icon_type;
3703    it->func = func;
3704    it->data = (void *)data;
3705 }
3706
3707 /**
3708  * This disables the entry's contextual (right click) menu.
3709  *
3710  * @param obj The entry object
3711  * @param disabled If true, the menu is disabled
3712  *
3713  * @ingroup Entry
3714  */
3715 EAPI void
3716 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
3717 {
3718    ELM_CHECK_WIDTYPE(obj, widtype);
3719    Widget_Data *wd = elm_widget_data_get(obj);
3720    if (!wd) return;
3721    if (wd->context_menu == !disabled) return;
3722    wd->context_menu = !disabled;
3723 }
3724
3725 /**
3726  * This returns whether the entry's contextual (right click) menu is disabled.
3727  *
3728  * @param obj The entry object
3729  * @return If true, the menu is disabled
3730  *
3731  * @ingroup Entry
3732  */
3733 EAPI Eina_Bool
3734 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
3735 {
3736    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3737    Widget_Data *wd = elm_widget_data_get(obj);
3738    if (!wd) return EINA_FALSE;
3739    return !wd->context_menu;
3740 }
3741
3742 /**
3743  * This appends a custom item provider to the list for that entry
3744  *
3745  * This appends the given callback. The list is walked from beginning to end
3746  * with each function called given the item href string in the text. If the
3747  * function returns an object handle other than NULL (it should create an
3748  * and object to do this), then this object is used to replace that item. If
3749  * not the next provider is called until one provides an item object, or the
3750  * default provider in entry does.
3751  *
3752  * @param obj The entry object
3753  * @param func The function called to provide the item object
3754  * @param data The data passed to @p func
3755  *
3756  * @ingroup Entry
3757  */
3758 EAPI void
3759 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3760 {
3761    ELM_CHECK_WIDTYPE(obj, widtype);
3762    Widget_Data *wd = elm_widget_data_get(obj);
3763    if (!wd) return;
3764    EINA_SAFETY_ON_NULL_RETURN(func);
3765    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3766    if (!ip) return;
3767    ip->func = func;
3768    ip->data = data;
3769    wd->item_providers = eina_list_append(wd->item_providers, ip);
3770 }
3771
3772 /**
3773  * This prepends a custom item provider to the list for that entry
3774  *
3775  * This prepends the given callback. See elm_entry_item_provider_append() for
3776  * more information
3777  *
3778  * @param obj The entry object
3779  * @param func The function called to provide the item object
3780  * @param data The data passed to @p func
3781  *
3782  * @ingroup Entry
3783  */
3784 EAPI void
3785 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3786 {
3787    ELM_CHECK_WIDTYPE(obj, widtype);
3788    Widget_Data *wd = elm_widget_data_get(obj);
3789    if (!wd) return;
3790    EINA_SAFETY_ON_NULL_RETURN(func);
3791    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3792    if (!ip) return;
3793    ip->func = func;
3794    ip->data = data;
3795    wd->item_providers = eina_list_prepend(wd->item_providers, ip);
3796 }
3797
3798 /**
3799  * This removes a custom item provider to the list for that entry
3800  *
3801  * This removes the given callback. See elm_entry_item_provider_append() for
3802  * more information
3803  *
3804  * @param obj The entry object
3805  * @param func The function called to provide the item object
3806  * @param data The data passed to @p func
3807  *
3808  * @ingroup Entry
3809  */
3810 EAPI void
3811 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3812 {
3813    ELM_CHECK_WIDTYPE(obj, widtype);
3814    Widget_Data *wd = elm_widget_data_get(obj);
3815    Eina_List *l;
3816    Elm_Entry_Item_Provider *ip;
3817    if (!wd) return;
3818    EINA_SAFETY_ON_NULL_RETURN(func);
3819    EINA_LIST_FOREACH(wd->item_providers, l, ip)
3820      {
3821         if ((ip->func == func) && ((!data) || (ip->data == data)))
3822           {
3823              wd->item_providers = eina_list_remove_list(wd->item_providers, l);
3824              free(ip);
3825              return;
3826           }
3827      }
3828 }
3829
3830 /**
3831  * Append a filter function for text inserted in the entry
3832  *
3833  * Append the given callback to the list. This functions will be called
3834  * whenever any text is inserted into the entry, with the text to be inserted
3835  * as a parameter. The callback function is free to alter the text in any way
3836  * it wants, but it must remember to free the given pointer and update it.
3837  * If the new text is to be discarded, the function can free it and set it text
3838  * parameter to NULL. This will also prevent any following filters from being
3839  * called.
3840  *
3841  * @param obj The entry object
3842  * @param func The function to use as text filter
3843  * @param data User data to pass to @p func
3844  *
3845  * @ingroup Entry
3846  */
3847 EAPI void
3848 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3849 {
3850    Widget_Data *wd;
3851    Elm_Entry_Text_Filter *tf;
3852    ELM_CHECK_WIDTYPE(obj, widtype);
3853
3854    wd = elm_widget_data_get(obj);
3855
3856    EINA_SAFETY_ON_NULL_RETURN(func);
3857
3858    tf = _filter_new(func, data);
3859    if (!tf) return;
3860
3861    wd->text_filters = eina_list_append(wd->text_filters, tf);
3862 }
3863
3864 /**
3865  * Prepend a filter function for text insdrted in the entry
3866  *
3867  * Prepend the given callback to the list. See elm_entry_text_filter_append()
3868  * for more information
3869  *
3870  * @param obj The entry object
3871  * @param func The function to use as text filter
3872  * @param data User data to pass to @p func
3873  *
3874  * @ingroup Entry
3875  */
3876 EAPI void
3877 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3878 {
3879    Widget_Data *wd;
3880    Elm_Entry_Text_Filter *tf;
3881    ELM_CHECK_WIDTYPE(obj, widtype);
3882
3883    wd = elm_widget_data_get(obj);
3884
3885    EINA_SAFETY_ON_NULL_RETURN(func);
3886
3887    tf = _filter_new(func, data);
3888    if (!tf) return;
3889
3890    wd->text_filters = eina_list_prepend(wd->text_filters, tf);
3891 }
3892
3893 /**
3894  * Remove a filter from the list
3895  *
3896  * Removes the given callback from the filter list. See elm_entry_text_filter_append()
3897  * for more information.
3898  *
3899  * @param obj The entry object
3900  * @param func The filter function to remove
3901  * @param data The user data passed when adding the function
3902  *
3903  * @ingroup Entry
3904  */
3905 EAPI void
3906 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3907 {
3908    Widget_Data *wd;
3909    Eina_List *l;
3910    Elm_Entry_Text_Filter *tf;
3911    ELM_CHECK_WIDTYPE(obj, widtype);
3912
3913    wd = elm_widget_data_get(obj);
3914
3915    EINA_SAFETY_ON_NULL_RETURN(func);
3916
3917    EINA_LIST_FOREACH(wd->text_filters, l, tf)
3918      {
3919         if ((tf->func == func) && ((!data) || (tf->data == data)))
3920           {
3921              wd->text_filters = eina_list_remove_list(wd->text_filters, l);
3922              _filter_free(tf);
3923              return;
3924           }
3925      }
3926 }
3927
3928 /**
3929  * This converts a markup (HTML-like) string into UTF-8.
3930  * Returning string is obtained with malloc.
3931  * After use the returned string, it should be freed.
3932  *
3933  * @param s The string (in markup) to be converted
3934  * @return The converted string (in UTF-8). It should be freed.
3935  *
3936  * @ingroup Entry
3937  */
3938 EAPI char *
3939 elm_entry_markup_to_utf8(const char *s)
3940 {
3941    char *ss = _elm_util_mkup_to_text(s);
3942    if (!ss) ss = strdup("");
3943    return ss;
3944 }
3945
3946 /**
3947  * This converts a UTF-8 string into markup (HTML-like).
3948  * Returning string is obtained with malloc.
3949  * After use the returned string, it should be freed.
3950  *
3951  * @param s The string (in UTF-8) to be converted
3952  * @return The converted string (in markup). It should be freed.
3953  *
3954  * @ingroup Entry
3955  */
3956 EAPI char *
3957 elm_entry_utf8_to_markup(const char *s)
3958 {
3959    char *ss = _elm_util_text_to_mkup(s);
3960    if (!ss) ss = strdup("");
3961    return ss;
3962 }
3963
3964 /**
3965  * Filter inserted text based on user defined character and byte limits
3966  *
3967  * Add this filter to an entry to limit the characters that it will accept
3968  * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
3969  * The funtion works on the UTF-8 representation of the string, converting
3970  * it from the set markup, thus not accounting for any format in it.
3971  *
3972  * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
3973  * it as data when setting the filter. In it it's possible to set limits
3974  * by character count or bytes (any of them is disabled if 0), and both can
3975  * be set at the same time. In that case, it first checks for characters,
3976  * then bytes.
3977  *
3978  * The function will cut the inserted text in order to allow only the first
3979  * number of characters that are still allowed. The cut is made in
3980  * characters, even when limiting by bytes, in order to always contain
3981  * valid ones and avoid half unicode characters making it in.
3982  *
3983  * @ingroup Entry
3984  */
3985 EAPI void
3986 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
3987 {
3988    Elm_Entry_Filter_Limit_Size *lim = data;
3989    char *current;
3990    int len, newlen;
3991    const char *(*text_get)(const Evas_Object *);
3992    const char *widget_type;
3993
3994    EINA_SAFETY_ON_NULL_RETURN(data);
3995    EINA_SAFETY_ON_NULL_RETURN(entry);
3996    EINA_SAFETY_ON_NULL_RETURN(text);
3997
3998    /* hack. I don't want to copy the entire function to work with
3999     * scrolled_entry */
4000    widget_type = elm_widget_type_get(entry);
4001    if (!strcmp(widget_type, "entry"))
4002      text_get = elm_entry_entry_get;
4003    else /* huh? */
4004      return;
4005
4006    current = elm_entry_markup_to_utf8(text_get(entry));
4007
4008    if (lim->max_char_count > 0)
4009      {
4010         len = evas_string_char_len_get(current);
4011         if (len >= lim->max_char_count)
4012           {
4013              evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
4014              free(*text);
4015              free(current);
4016              *text = NULL;
4017              return;
4018           }
4019         newlen = evas_string_char_len_get(elm_entry_markup_to_utf8(*text));
4020         if ((len + newlen) > lim->max_char_count)
4021           _add_chars_till_limit(entry, text, (lim->max_char_count - len), LENGTH_UNIT_CHAR);
4022      }
4023    else if (lim->max_byte_count > 0)
4024      {
4025         len = strlen(current);
4026         if (len >= lim->max_byte_count)
4027           {
4028              evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
4029              free(*text);
4030              free(current);
4031              *text = NULL;
4032              return;
4033           }
4034         newlen = strlen(elm_entry_markup_to_utf8(*text));
4035         if ((len + newlen) > lim->max_byte_count)
4036           _add_chars_till_limit(entry, text, (lim->max_byte_count - len), LENGTH_UNIT_BYTE);
4037      }
4038    free(current);
4039 }
4040
4041 /**
4042  * Filter inserted text based on accepted or rejected sets of characters
4043  *
4044  * Add this filter to an entry to restrict the set of accepted characters
4045  * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
4046  * This structure contains both accepted and rejected sets, but they are
4047  * mutually exclusive. If accepted is set, it will be used, otherwise it
4048  * goes on to the rejected set.
4049  */
4050 EAPI void
4051 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
4052 {
4053    Elm_Entry_Filter_Accept_Set *as = data;
4054    const char *set;
4055    char *insert;
4056    Eina_Bool goes_in;
4057    int read_idx, last_read_idx = 0, read_char;
4058
4059    EINA_SAFETY_ON_NULL_RETURN(data);
4060    EINA_SAFETY_ON_NULL_RETURN(text);
4061
4062    if ((!as->accepted) && (!as->rejected))
4063      return;
4064
4065    if (as->accepted)
4066      {
4067         set = as->accepted;
4068         goes_in = EINA_TRUE;
4069      }
4070    else
4071      {
4072         set = as->rejected;
4073         goes_in = EINA_FALSE;
4074      }
4075
4076    insert = *text;
4077    read_idx = evas_string_char_next_get(*text, 0, &read_char);
4078    while (read_char)
4079      {
4080         int cmp_idx, cmp_char;
4081         Eina_Bool in_set = EINA_FALSE;
4082
4083         cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
4084         while (cmp_char)
4085           {
4086              if (read_char == cmp_char)
4087                {
4088                   in_set = EINA_TRUE;
4089                   break;
4090                }
4091              cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
4092           }
4093         if (in_set == goes_in)
4094           {
4095              int size = read_idx - last_read_idx;
4096              const char *src = (*text) + last_read_idx;
4097              if (src != insert)
4098                memcpy(insert, *text + last_read_idx, size);
4099              insert += size;
4100           }
4101         last_read_idx = read_idx;
4102         read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
4103      }
4104    *insert = 0;
4105 }
4106
4107 /**
4108  * This sets the file (and implicitly loads it) for the text to display and
4109  * then edit. All changes are written back to the file after a short delay if
4110  * the entry object is set to autosave.
4111  *
4112  * @param obj The entry object
4113  * @param file The path to the file to load and save
4114  * @param format The file format
4115  *
4116  * @ingroup Entry
4117  */
4118 EAPI void
4119 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
4120 {
4121    ELM_CHECK_WIDTYPE(obj, widtype);
4122    Widget_Data *wd = elm_widget_data_get(obj);
4123    if (!wd) return;
4124    if (wd->delay_write)
4125      {
4126         ecore_timer_del(wd->delay_write);
4127         wd->delay_write = NULL;
4128      }
4129    if (wd->autosave) _save(obj);
4130    eina_stringshare_replace(&wd->file, file);
4131    wd->format = format;
4132    _load(obj);
4133 }
4134
4135 /**
4136  * Gets the file to load and save and the file format
4137  *
4138  * @param obj The entry object
4139  * @param file The path to the file to load and save
4140  * @param format The file format
4141  *
4142  * @ingroup Entry
4143  */
4144 EAPI void
4145 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
4146 {
4147    ELM_CHECK_WIDTYPE(obj, widtype);
4148    Widget_Data *wd = elm_widget_data_get(obj);
4149    if (!wd) return;
4150    if (file) *file = wd->file;
4151    if (format) *format = wd->format;
4152 }
4153
4154 /**
4155  * This function writes any changes made to the file set with
4156  * elm_entry_file_set()
4157  *
4158  * @param obj The entry object
4159  *
4160  * @ingroup Entry
4161  */
4162 EAPI void
4163 elm_entry_file_save(Evas_Object *obj)
4164 {
4165    ELM_CHECK_WIDTYPE(obj, widtype);
4166    Widget_Data *wd = elm_widget_data_get(obj);
4167    if (!wd) return;
4168    if (wd->delay_write)
4169      {
4170         ecore_timer_del(wd->delay_write);
4171         wd->delay_write = NULL;
4172      }
4173    _save(obj);
4174    wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
4175 }
4176
4177 /**
4178  * This sets the entry object to 'autosave' the loaded text file or not.
4179  *
4180  * @param obj The entry object
4181  * @param autosave Autosave the loaded file or not
4182  *
4183  * @ingroup Entry
4184  */
4185 EAPI void
4186 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
4187 {
4188    ELM_CHECK_WIDTYPE(obj, widtype);
4189    Widget_Data *wd = elm_widget_data_get(obj);
4190    if (!wd) return;
4191    wd->autosave = !!autosave;
4192 }
4193
4194 /**
4195  * This gets the entry object's 'autosave' status.
4196  *
4197  * @param obj The entry object
4198  * @return Autosave the loaded file or not
4199  *
4200  * @ingroup Entry
4201  */
4202 EAPI Eina_Bool
4203 elm_entry_autosave_get(const Evas_Object *obj)
4204 {
4205    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4206    Widget_Data *wd = elm_widget_data_get(obj);
4207    if (!wd) return EINA_FALSE;
4208    return wd->autosave;
4209 }
4210
4211 /**
4212  * Control pasting of text and images for the widget.
4213  *
4214  * Normally the entry allows both text and images to be pasted.  By setting
4215  * textonly to be true, this prevents images from being pasted.
4216  *
4217  * Note this only changes the behaviour of text.
4218  *
4219  * @param obj The entry object
4220  * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is text+image+other.
4221  *
4222  * @ingroup Entry
4223  */
4224 EAPI void
4225 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
4226 {
4227    Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
4228    ELM_CHECK_WIDTYPE(obj, widtype);
4229    Widget_Data *wd = elm_widget_data_get(obj);
4230    if (!wd) return;
4231    textonly = !!textonly;
4232    if (wd->textonly == textonly) return;
4233    wd->textonly = !!textonly;
4234    if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
4235 #ifdef HAVE_ELEMENTARY_X
4236    elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
4237 #endif
4238 }
4239
4240 /**
4241  * Getting elm_entry text paste/drop mode.
4242  *
4243  * In textonly mode, only text may be pasted or dropped into the widget.
4244  *
4245  * @param obj The entry object
4246  * @return If the widget only accepts text from pastes.
4247  *
4248  * @ingroup Entry
4249  */
4250 EAPI Eina_Bool
4251 elm_entry_cnp_textonly_get(const Evas_Object *obj)
4252 {
4253    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4254    Widget_Data *wd = elm_widget_data_get(obj);
4255    if (!wd) return EINA_FALSE;
4256    return wd->textonly;
4257 }
4258
4259 /**
4260  * Enable or disable scrolling in entry
4261  *
4262  * Normally the entry is not scrollable unless you enable it with this call.
4263  *
4264  * @param obj The entry object
4265  * @param scroll EINA_TRUE if it is to be scrollable, EINA_FALSE otherwise
4266  *
4267  * @ingroup Entry
4268  */
4269 EAPI void
4270 elm_entry_scrollable_set(Evas_Object *obj, Eina_Bool scroll)
4271 {
4272    ELM_CHECK_WIDTYPE(obj, widtype);
4273    Widget_Data *wd = elm_widget_data_get(obj);
4274    if (!wd) return;
4275    scroll = !!scroll;
4276    if (wd->scroll == scroll) return;
4277    wd->scroll = scroll;
4278    if (wd->scroll)
4279      {
4280         elm_widget_sub_object_del(obj, wd->scroller);
4281         elm_widget_resize_object_set(obj, wd->scroller);
4282         elm_widget_sub_object_add(obj, wd->ent);
4283         elm_smart_scroller_child_set(wd->scroller, wd->ent);
4284         evas_object_show(wd->scroller);
4285         elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
4286         if (wd->single_line)
4287           {
4288              elm_smart_scroller_policy_set(wd->scroller,
4289                                            ELM_SMART_SCROLLER_POLICY_OFF,
4290                                            ELM_SMART_SCROLLER_POLICY_OFF);
4291              elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
4292           }
4293         else
4294           {
4295              const Elm_Scroller_Policy map[3] =
4296                {
4297                   ELM_SMART_SCROLLER_POLICY_AUTO,
4298                   ELM_SMART_SCROLLER_POLICY_ON,
4299                   ELM_SMART_SCROLLER_POLICY_OFF
4300                };
4301              elm_smart_scroller_policy_set(wd->scroller,
4302                                            map[wd->policy_h],
4303                                            map[wd->policy_v]);
4304              elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
4305           }
4306      }
4307    else
4308      {
4309         elm_smart_scroller_child_set(wd->scroller, NULL);
4310         elm_widget_sub_object_del(obj, wd->ent);
4311         elm_widget_resize_object_set(obj, wd->ent);
4312         evas_object_smart_member_add(wd->scroller, obj);
4313         elm_widget_sub_object_add(obj, wd->scroller);
4314         evas_object_hide(wd->scroller);
4315         elm_widget_on_show_region_hook_set(obj, NULL, NULL);
4316      }
4317    wd->lastw = -1;
4318    _theme_hook(obj);
4319 }
4320
4321 /**
4322  * Get the scrollable state of the entry
4323  *
4324  * Normally the entry is not scrollable. This gets the scrollable state
4325  * of the entry. See elm_entry_scrollable_set() for more information.
4326  *
4327  * @param obj The entry object
4328  * @return The scrollable state
4329  *
4330  * @ingroup Entry
4331  */
4332 EAPI Eina_Bool
4333 elm_entry_scrollable_get(const Evas_Object *obj)
4334 {
4335    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4336    Widget_Data *wd = elm_widget_data_get(obj);
4337    if (!wd) return EINA_FALSE;
4338    return wd->scroll;
4339 }
4340
4341 /**
4342  * This sets a widget to be displayed to the left of a scrolled entry.
4343  *
4344  * @param obj The scrolled entry object
4345  * @param icon The widget to display on the left side of the scrolled
4346  * entry.
4347  *
4348  * @note A previously set widget will be destroyed.
4349  * @note If the object being set does not have minimum size hints set,
4350  * it won't get properly displayed.
4351  *
4352  * @ingroup Entry
4353  * @see elm_entry_end_set
4354  */
4355 EAPI void
4356 elm_entry_icon_set(Evas_Object *obj, Evas_Object *icon)
4357 {
4358    ELM_CHECK_WIDTYPE(obj, widtype);
4359    Widget_Data *wd = elm_widget_data_get(obj);
4360    Evas_Object *edje;
4361    if (!wd) return;
4362    EINA_SAFETY_ON_NULL_RETURN(icon);
4363    if (wd->icon == icon) return;
4364    if (wd->icon) evas_object_del(wd->icon);
4365    wd->icon = icon;
4366    edje = elm_smart_scroller_edje_object_get(wd->scroller);
4367    if (!edje) return;
4368    edje_object_part_swallow(edje, "elm.swallow.icon", wd->icon);
4369    edje_object_signal_emit(edje, "elm,action,show,icon", "elm");
4370    _sizing_eval(obj);
4371 }
4372
4373 /**
4374  * Gets the leftmost widget of the scrolled entry. This object is
4375  * owned by the scrolled entry and should not be modified.
4376  *
4377  * @param obj The scrolled entry object
4378  * @return the left widget inside the scroller
4379  *
4380  * @ingroup Entry
4381  */
4382 EAPI Evas_Object *
4383 elm_entry_icon_get(const Evas_Object *obj)
4384 {
4385    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4386    Widget_Data *wd = elm_widget_data_get(obj);
4387    if (!wd) return NULL;
4388    return wd->icon;
4389 }
4390
4391 /**
4392  * Unset the leftmost widget of the scrolled entry, unparenting and
4393  * returning it.
4394  *
4395  * @param obj The scrolled entry object
4396  * @return the previously set icon sub-object of this entry, on
4397  * success.
4398  *
4399  * @see elm_entry_icon_set()
4400  *
4401  * @ingroup Entry
4402  */
4403 EAPI Evas_Object *
4404 elm_entry_icon_unset(Evas_Object *obj)
4405 {
4406    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4407    Widget_Data *wd = elm_widget_data_get(obj);
4408    Evas_Object *ret = NULL;
4409    if (!wd) return NULL;
4410    if (wd->icon)
4411      {
4412         Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
4413         if (!edje) return NULL;
4414         ret = wd->icon;
4415         edje_object_part_unswallow(edje, wd->icon);
4416         edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
4417         wd->icon = NULL;
4418         _sizing_eval(obj);
4419      }
4420    return ret;
4421 }
4422
4423 /**
4424  * Sets the visibility of the left-side widget of the scrolled entry,
4425  * set by @elm_entry_icon_set().
4426  *
4427  * @param obj The scrolled entry object
4428  * @param setting EINA_TRUE if the object should be displayed,
4429  * EINA_FALSE if not.
4430  *
4431  * @ingroup Entry
4432  */
4433 EAPI void
4434 elm_entry_icon_visible_set(Evas_Object *obj, Eina_Bool setting)
4435 {
4436    ELM_CHECK_WIDTYPE(obj, widtype);
4437    Widget_Data *wd = elm_widget_data_get(obj);
4438    if ((!wd) || (!wd->icon)) return;
4439    if (setting)
4440       evas_object_hide(wd->icon);
4441    else
4442       evas_object_show(wd->icon);
4443    _sizing_eval(obj);
4444 }
4445
4446 /**
4447  * This sets a widget to be displayed to the end of a scrolled entry.
4448  *
4449  * @param obj The scrolled entry object
4450  * @param end The widget to display on the right side of the scrolled
4451  * entry.
4452  *
4453  * @note A previously set widget will be destroyed.
4454  * @note If the object being set does not have minimum size hints set,
4455  * it won't get properly displayed.
4456  *
4457  * @ingroup Entry
4458  * @see elm_entry_icon_set
4459  */
4460 EAPI void
4461 elm_entry_end_set(Evas_Object *obj, Evas_Object *end)
4462 {
4463    ELM_CHECK_WIDTYPE(obj, widtype);
4464    Widget_Data *wd = elm_widget_data_get(obj);
4465    Evas_Object *edje;
4466    if (!wd) return;
4467    EINA_SAFETY_ON_NULL_RETURN(end);
4468    if (wd->end == end) return;
4469    if (wd->end) evas_object_del(wd->end);
4470    wd->end = end;
4471    edje = elm_smart_scroller_edje_object_get(wd->scroller);
4472    if (!edje) return;
4473    edje_object_part_swallow(edje, "elm.swallow.end", wd->end);
4474    edje_object_signal_emit(edje, "elm,action,show,end", "elm");
4475    _sizing_eval(obj);
4476 }
4477
4478 /**
4479  * Gets the endmost widget of the scrolled entry. This object is owned
4480  * by the scrolled entry and should not be modified.
4481  *
4482  * @param obj The scrolled entry object
4483  * @return the right widget inside the scroller
4484  *
4485  * @ingroup Entry
4486  */
4487 EAPI Evas_Object *
4488 elm_entry_end_get(const Evas_Object *obj)
4489 {
4490    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4491    Widget_Data *wd = elm_widget_data_get(obj);
4492    if (!wd) return NULL;
4493    return wd->end;
4494 }
4495
4496 /**
4497  * Unset the endmost widget of the scrolled entry, unparenting and
4498  * returning it.
4499  *
4500  * @param obj The scrolled entry object
4501  * @return the previously set icon sub-object of this entry, on
4502  * success.
4503  *
4504  * @see elm_entry_icon_set()
4505  *
4506  * @ingroup Entry
4507  */
4508 EAPI Evas_Object *
4509 elm_entry_end_unset(Evas_Object *obj)
4510 {
4511    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4512    Widget_Data *wd = elm_widget_data_get(obj);
4513    Evas_Object *ret = NULL;
4514    if (!wd) return NULL;
4515    if (wd->end)
4516      {
4517         Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
4518         if (!edje) return NULL;
4519         ret = wd->end;
4520         edje_object_part_unswallow(edje, wd->end);
4521         edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
4522         wd->end = NULL;
4523         _sizing_eval(obj);
4524      }
4525    return ret;
4526 }
4527
4528 /**
4529  * Sets the visibility of the end widget of the scrolled entry, set by
4530  * @elm_entry_end_set().
4531  *
4532  * @param obj The scrolled entry object
4533  * @param setting EINA_TRUE if the object should be displayed,
4534  * EINA_FALSE if not.
4535  *
4536  * @ingroup Entry
4537  */
4538 EAPI void
4539 elm_entry_end_visible_set(Evas_Object *obj, Eina_Bool setting)
4540 {
4541    ELM_CHECK_WIDTYPE(obj, widtype);
4542    Widget_Data *wd = elm_widget_data_get(obj);
4543    if ((!wd) || (!wd->end)) return;
4544    if (setting)
4545       evas_object_hide(wd->end);
4546    else
4547       evas_object_show(wd->end);
4548    _sizing_eval(obj);
4549 }
4550
4551 /**
4552  * This sets the scrolled entry's scrollbar policy (ie. enabling/disabling them).
4553  *
4554  * @param obj The scrolled entry object
4555  * @param h The horizontal scrollbar policy to apply
4556  * @param v The vertical scrollbar policy to apply
4557  *
4558  * @ingroup Entry
4559  */
4560 EAPI void
4561 elm_entry_scrollbar_policy_set(Evas_Object *obj, Elm_Scroller_Policy h, Elm_Scroller_Policy v)
4562 {
4563    ELM_CHECK_WIDTYPE(obj, widtype);
4564    Widget_Data *wd = elm_widget_data_get(obj);
4565    const Elm_Scroller_Policy map[3] =
4566      {
4567         ELM_SMART_SCROLLER_POLICY_AUTO,
4568         ELM_SMART_SCROLLER_POLICY_ON,
4569         ELM_SMART_SCROLLER_POLICY_OFF
4570      };
4571    if (!wd) return;
4572    wd->policy_h = h;
4573    wd->policy_v = v;
4574    elm_smart_scroller_policy_set(wd->scroller,
4575                                  map[wd->policy_h],
4576                                  map[wd->policy_v]);
4577 }
4578
4579 /**
4580  * This enables/disables bouncing within the entry.
4581  *
4582  * @param obj The scrolled entry object
4583  * @param h The horizontal bounce state
4584  * @param v The vertical bounce state
4585  *
4586  * @ingroup Entry
4587  */
4588 EAPI void
4589 elm_entry_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
4590 {
4591    ELM_CHECK_WIDTYPE(obj, widtype);
4592    Widget_Data *wd = elm_widget_data_get(obj);
4593    if (!wd) return;
4594    elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
4595 }
4596
4597 /**
4598  * Get the bounce mode
4599  *
4600  * @param obj The Entry object
4601  * @param h_bounce Allow bounce horizontally
4602  * @param v_bounce Allow bounce vertically
4603  *
4604  * @ingroup Entry
4605  */
4606 EAPI void
4607 elm_entry_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
4608 {
4609    ELM_CHECK_WIDTYPE(obj, widtype);
4610    Widget_Data *wd = elm_widget_data_get(obj);
4611    if (!wd) return;
4612    elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
4613 }
4614
4615 EINA_DEPRECATED EAPI void
4616 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
4617 {
4618    if (wrap) elm_entry_line_wrap_set(obj, ELM_WRAP_CHAR);
4619 }
4620
4621 /**
4622  * Set background color of the entry
4623  *
4624  * @param obj The entry object
4625  * @param r Red property background color of The entry object
4626  * @param g Green property background color of The entry object
4627  * @param b Blue property background color of The entry object
4628  * @param a Alpha property background alpha of The entry object
4629  * @ingroup Entry
4630  */
4631 EAPI void
4632 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
4633 {
4634    ELM_CHECK_WIDTYPE(obj, widtype);
4635    Widget_Data *wd = elm_widget_data_get(obj);
4636    evas_object_color_set(wd->bg, r, g, b, a);
4637
4638    if (wd->bgcolor == EINA_FALSE)
4639      {
4640        wd->bgcolor = 1;
4641        edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
4642      }
4643 }
4644
4645 /**
4646  * Set whether entry should support auto capitalization
4647  *
4648  * @param obj The entry object
4649  * @param on If true, entry suports auto capitalization.
4650  *
4651  * @ingroup Entry
4652  */
4653 EAPI void
4654 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
4655 {
4656    ELM_CHECK_WIDTYPE(obj, widtype);
4657    Widget_Data *wd = elm_widget_data_get(obj);
4658    if (!wd) return;
4659
4660    if (wd->password)
4661      wd->autocapital = EINA_FALSE;
4662    else
4663      wd->autocapital = autocap;
4664
4665    if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
4666        wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
4667      wd->autocapital = EINA_FALSE;
4668
4669    edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
4670 }
4671
4672 /**
4673  * Set whether entry should support auto period
4674  *
4675  * @param obj The entry object
4676  * @param on If true, entry suports auto period.
4677  *
4678  * @ingroup Entry
4679  */
4680 EAPI void
4681 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
4682 {
4683    ELM_CHECK_WIDTYPE(obj, widtype);
4684    Widget_Data *wd = elm_widget_data_get(obj);
4685    if (!wd) return;
4686
4687    if (wd->password)
4688      wd->autoperiod = EINA_FALSE;
4689    else
4690      wd->autoperiod = autoperiod;
4691
4692    if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
4693        wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
4694      wd->autoperiod = EINA_FALSE;
4695
4696    edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
4697 }
4698
4699 /**
4700  * Set whether entry should enable the return key on soft keyboard automatically
4701  *
4702  * @param obj The entry object
4703  * @param on If true, entry enables the return key on soft keyboard automatically.
4704  *
4705  * @ingroup Entry
4706  */
4707 EAPI void
4708 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
4709 {
4710    ELM_CHECK_WIDTYPE(obj, widtype);
4711    Widget_Data *wd = elm_widget_data_get(obj);
4712    if (!wd) return;
4713
4714    wd->autoreturnkey = on;
4715    _check_enable_returnkey(obj);
4716 }
4717
4718 /**
4719  * This sets the attribute to show the input panel automatically.
4720  *
4721  * @param obj The entry object
4722  * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
4723  *
4724  * @ingroup Entry
4725  */
4726 EAPI void
4727 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
4728 {
4729    ELM_CHECK_WIDTYPE(obj, widtype);
4730    Widget_Data *wd = elm_widget_data_get(obj);
4731    if (!wd) return;
4732
4733    wd->input_panel_enable = enabled;
4734    edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
4735 }
4736
4737 /**
4738  * Set the input panel layout of the entry
4739  *
4740  * @param obj The entry object
4741  * @param layout the layout to set
4742  *
4743  * @ingroup Entry
4744  */
4745 EAPI void
4746 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
4747 {
4748    ELM_CHECK_WIDTYPE(obj, widtype);
4749    Widget_Data *wd = elm_widget_data_get(obj);
4750    if (!wd) return;
4751
4752    Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
4753    if (!ic) return;
4754
4755    wd->input_panel_layout = layout;
4756
4757    ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
4758 }
4759
4760 /**
4761  * Get the input method context in the entry widget
4762  *
4763  * @param obj The entry object
4764  * @return The input method context
4765  *
4766  * @ingroup Entry
4767  */
4768 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
4769 {
4770    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4771    Widget_Data *wd = elm_widget_data_get(obj);
4772    if (!wd || !wd->ent) return NULL;
4773
4774    return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
4775 }
4776
4777 EAPI void
4778 elm_entry_matchlist_set(Evas_Object *obj, Eina_List *match_list, Eina_Bool case_sensitive)
4779 {
4780    Widget_Data *wd = elm_widget_data_get(obj);
4781    if (!wd) return;
4782
4783    if (match_list)
4784      {
4785         Evas_Coord max_w = 9999, max_h = 9999;
4786         const char* key_data = NULL;
4787
4788         wd->matchlist_threshold = 1;
4789         wd->hover = elm_hover_add(elm_widget_parent_get(obj));
4790         elm_hover_parent_set(wd->hover, elm_widget_parent_get(obj));
4791         elm_hover_target_set(wd->hover, obj);
4792         elm_object_style_set(wd->hover, "matchlist");
4793
4794         wd->layout = elm_layout_add(wd->hover);
4795         elm_layout_theme_set(wd->layout, "entry", "matchlist", "default");
4796         wd->list = elm_list_add(wd->layout);
4797         evas_object_size_hint_weight_set(wd->list, EVAS_HINT_EXPAND, 0.0);
4798         evas_object_size_hint_align_set(wd->list, EVAS_HINT_FILL, EVAS_HINT_FILL);
4799         elm_list_mode_set(wd->list, ELM_LIST_EXPAND);
4800         elm_object_style_set(wd->list, "matchlist");
4801
4802         key_data = edje_object_data_get(elm_layout_edje_get(wd->layout), "max_width");
4803         if (key_data) max_w = atoi(key_data);
4804         key_data = edje_object_data_get(elm_layout_edje_get(wd->layout), "max_height");
4805         if (key_data) max_h = atoi(key_data);
4806
4807         elm_list_go(wd->list);
4808         evas_object_size_hint_max_set(wd->list, max_w, max_h);
4809         evas_object_smart_callback_add(wd->list, "selected", _matchlist_list_clicked, obj);
4810         elm_layout_content_set(wd->layout, "elm.swallow.content", wd->list);
4811         elm_hover_content_set(wd->hover, "bottom", wd->layout);
4812
4813         wd->match_list = match_list;
4814      }
4815    else
4816      {
4817         if (wd->hover)
4818           evas_object_del(wd->hover);
4819
4820         wd->match_list = NULL;
4821      }
4822
4823    wd->matchlist_case_sensitive = case_sensitive;
4824 }
4825
4826 /**
4827  * Set the magnifier style of the entry
4828  *
4829  * @param obj The entry object
4830  * @param type the magnifier style to set
4831  *
4832  * @ingroup Entry
4833  */
4834 EAPI void
4835 elm_entry_magnifier_type_set(Evas_Object *obj, int type)
4836 {
4837    ELM_CHECK_WIDTYPE(obj, widtype);
4838    Widget_Data *wd = elm_widget_data_get(obj);
4839    if (!wd) return;
4840
4841    wd->mgf_type = type;
4842    _magnifier_create(obj);
4843 }
4844
4845 /**
4846  * Set wrap width of the entry
4847  *
4848  * @param obj The entry object
4849  * @param w The wrap width in pixels at a minimum where words need to wrap
4850  * @ingroup Entry
4851  */
4852 EAPI void
4853 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
4854 {
4855    Widget_Data *wd = elm_widget_data_get(obj);
4856    if (wd->wrap_w == w) return;
4857    wd->wrap_w = w;
4858    _sizing_eval(obj);
4859 }
4860
4861 /**
4862  * get wrap width of the entry
4863  *
4864  * @param obj The entry object
4865  * @return The wrap width in pixels at a minimum where words need to wrap
4866  * @ingroup Entry
4867  */
4868 EAPI Evas_Coord
4869 elm_entry_wrap_width_get(const Evas_Object *obj)
4870 {
4871    Widget_Data *wd = elm_widget_data_get(obj);
4872    return wd->wrap_w;
4873 }
4874
4875 /**
4876  * Set the font size on the entry object
4877  *
4878  * @param obj The entry object
4879  * @param size font size
4880  *
4881  * @ingroup Entry
4882  */
4883 EAPI void
4884 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
4885 {
4886    ELM_CHECK_WIDTYPE(obj, widtype);
4887    Widget_Data *wd = elm_widget_data_get(obj);
4888    Eina_Strbuf *fontbuf = NULL;
4889    int removeflag = 0;
4890    const char *t;
4891
4892    if (!wd) return;
4893    t = eina_stringshare_add(elm_entry_entry_get(obj));
4894    fontbuf = eina_strbuf_new();
4895    eina_strbuf_append_printf(fontbuf, "%d", fontsize);
4896
4897    if (fontsize == 0) removeflag = 1; // remove fontsize tag
4898
4899    if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
4900      {
4901        elm_entry_entry_set(obj, t);
4902        wd->changed = 1;
4903        _sizing_eval(obj);
4904      }
4905    eina_strbuf_free(fontbuf);
4906    eina_stringshare_del(t);
4907 }
4908
4909 /**
4910  * Set the text color on the entry object
4911  *
4912  * @param obj The entry object
4913  * @param r Red property background color of The entry object
4914  * @param g Green property background color of The entry object
4915  * @param b Blue property background color of The entry object
4916  * @param a Alpha property background alpha of The entry object
4917  *
4918  * @ingroup Entry
4919  */
4920 EAPI void
4921 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
4922 {
4923    ELM_CHECK_WIDTYPE(obj, widtype);
4924    Widget_Data *wd = elm_widget_data_get(obj);
4925    Eina_Strbuf *colorbuf = NULL;
4926    const char *t;
4927    int len;
4928
4929    if (!wd) return;
4930    t = eina_stringshare_add(elm_entry_entry_get(obj));
4931    len = strlen(t);
4932    if (len <= 0) return;
4933    colorbuf = eina_strbuf_new();
4934    eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
4935
4936    if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
4937      {
4938        elm_entry_entry_set(obj, t);
4939        wd->changed = 1;
4940        _sizing_eval(obj);
4941      }
4942    eina_strbuf_free(colorbuf);
4943    eina_stringshare_del(t);
4944 }
4945
4946 /**
4947  * Set the text align on the entry object
4948  *
4949  * @param obj The entry object
4950  * @param align align mode
4951  *
4952  * @ingroup Entry
4953  */
4954 EAPI void
4955 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
4956 {
4957    ELM_CHECK_WIDTYPE(obj, widtype);
4958    Widget_Data *wd = elm_widget_data_get(obj);
4959    int len;
4960    const char *t;
4961
4962    if (!wd) return;
4963    t = eina_stringshare_add(elm_entry_entry_get(obj));
4964    len = strlen(t);
4965    if (len <= 0) return;
4966
4967    if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
4968      elm_entry_entry_set(obj, t);
4969
4970    wd->changed = 1;
4971    _sizing_eval(obj);
4972    eina_stringshare_del(t);
4973 }