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