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