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