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