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