[entry] changed function calling sequence to avoid abnormal access to widget data
[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    if (wd->delay_write)
1949      {
1950         ecore_timer_del(wd->delay_write);
1951         wd->delay_write = NULL;
1952      }
1953
1954    if ((wd->single_line) && (wd->match_list))
1955      {
1956         if (wd->matchlist_job) ecore_job_del(wd->matchlist_job);
1957         wd->matchlist_job = ecore_job_add(_matchlist_show, data);
1958      }
1959
1960    if ((wd->api) && (wd->api->obj_hidemenu))
1961      wd->api->obj_hidemenu(data);
1962
1963    if ((wd->autosave) && (wd->file))
1964      wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1965
1966    /* callback - this could call callbacks that delete the entry... thus...
1967     * any access to wd after this could be invalid */
1968    evas_object_smart_callback_call(data, event, NULL);
1969 }
1970
1971 static void
1972 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1973 {
1974    Widget_Data *wd = elm_widget_data_get(data);
1975    if (!wd) return;
1976
1977    _entry_changed_common_handling(data, SIG_CHANGED);
1978 }
1979
1980 static void
1981 _signal_preedit_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1982 {
1983    Widget_Data *wd = elm_widget_data_get(data);
1984    if (!wd) return;
1985
1986    _entry_changed_common_handling(data, SIG_PREEDIT_CHANGED);
1987 }
1988
1989 static void
1990 _signal_handler_move_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1991 {
1992    Widget_Data *wd = elm_widget_data_get(data);
1993    if (!wd) return;
1994
1995    elm_object_scroll_freeze_push(data);
1996
1997    if ((wd->api) && (wd->api->obj_hidemenu))
1998      wd->api->obj_hidemenu(data);
1999
2000    _magnifier_create(data);
2001    _magnifier_move(data);
2002    _magnifier_show(data);
2003 }
2004
2005 static void
2006 _signal_handler_move_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2007 {
2008    Widget_Data *wd = elm_widget_data_get(data);
2009    if (!wd) return;
2010
2011    elm_object_scroll_freeze_pop(data);
2012
2013    if (wd->have_selection)
2014      {
2015         _magnifier_hide(data);
2016         _menu_press(data);
2017      }
2018 }
2019
2020 static void
2021 _signal_handler_moving(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2022 {
2023    _magnifier_move(data);
2024    _magnifier_show(data);
2025 }
2026
2027 static Evas_Object *
2028 _viewport_obj_get(Evas_Object *data)
2029 {
2030    Widget_Data *wd = elm_widget_data_get(data);
2031    if (!wd) return NULL;
2032
2033    if(!data || !strlen(elm_widget_type_get(data)))
2034      return NULL;
2035
2036    Evas_Coord x, y, w, h;
2037    x = y = w = h = -1;
2038
2039    if (wd->scroll)
2040      {
2041         //evas_object_geometry_get(wd->scroller, &x, &y, &w, &h);
2042         //printf(">>> wd->scroller (%d, %d, %d, %d) \n", x, y, w, h);
2043         return wd->scroller;
2044      }
2045
2046    Evas_Object *parent_obj = data;
2047
2048    while(parent_obj = elm_widget_parent_get(parent_obj))
2049      {
2050         //evas_object_geometry_get(parent_obj, &x, &y, &w, &h);
2051         //printf(">>> %s (%d, %d, %d, %d) \n", elm_widget_type_get(parent_obj), x, y, w, h);
2052         if (!strcmp(elm_widget_type_get(parent_obj), "scroller") ||
2053             !strcmp(elm_widget_type_get(parent_obj), "genlist"))
2054           return parent_obj;
2055      }
2056
2057    return NULL;
2058 }
2059
2060 static void
2061 _signal_selection_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2062 {
2063    _magnifier_hide(data);
2064    _menu_press(data);
2065 }
2066
2067 static void
2068 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2069 {
2070    Widget_Data *wd = elm_widget_data_get(data);
2071    const Eina_List *l;
2072    Evas_Object *entry;
2073    if (!wd) return;
2074    EINA_LIST_FOREACH(entries, l, entry)
2075      {
2076         if (entry != data) elm_entry_select_none(entry);
2077      }
2078    wd->have_selection = EINA_TRUE;
2079    wd->selmode = EINA_TRUE;
2080    evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
2081 #ifdef HAVE_ELEMENTARY_X
2082    if (wd->sel_notify_handler)
2083      {
2084         const char *txt = elm_entry_selection_get(data);
2085         Evas_Object *top;
2086
2087         top = elm_widget_top_get(data);
2088         if ((top) && (elm_win_xwindow_get(top)))
2089           elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
2090      }
2091 #endif
2092
2093    if (!_elm_config->desktop_entry)
2094      edje_object_part_text_viewport_object_set(wd->ent, "elm.text", _viewport_obj_get(data));
2095 }
2096
2097 static void
2098 _signal_magnifier_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2099 {
2100    Evas_Coord cx, cy, cw, ch;
2101    Widget_Data *wd = elm_widget_data_get(data);
2102    if (!wd) return;
2103
2104    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
2105    if (!wd->deferred_recalc_job)
2106      elm_widget_show_region_set(data, cx, cy, cw, ch, EINA_FALSE);
2107    else
2108      {
2109         wd->deferred_cur = EINA_TRUE;
2110         wd->cx = cx;
2111         wd->cy = cy;
2112         wd->cw = cw;
2113         wd->ch = ch;
2114      }
2115 }
2116
2117 static void
2118 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2119 {
2120    Evas_Coord cx, cy, cw, ch;
2121    Widget_Data *wd = elm_widget_data_get(data);
2122    if (!wd) return;
2123    wd->have_selection = EINA_TRUE;
2124    wd->selmode = EINA_TRUE;
2125    evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
2126    elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
2127                      elm_entry_selection_get(data));
2128
2129    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
2130    if (!wd->deferred_recalc_job)
2131      elm_widget_show_region_set(data, cx, cy, cw, ch, EINA_FALSE);
2132    else
2133      {
2134         wd->deferred_cur = EINA_TRUE;
2135         wd->cx = cx;
2136         wd->cy = cy;
2137         wd->cw = cw;
2138         wd->ch = ch;
2139      }
2140 }
2141
2142 static void
2143 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2144 {
2145    Widget_Data *wd = elm_widget_data_get(data);
2146    if (!wd) return;
2147    if (!wd->have_selection) return;
2148    wd->have_selection = EINA_FALSE;
2149    wd->selmode = EINA_FALSE;
2150    evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
2151    if (wd->sel_notify_handler)
2152      {
2153         if (wd->cut_sel)
2154           {
2155 #ifdef HAVE_ELEMENTARY_X
2156              Evas_Object *top;
2157
2158              top = elm_widget_top_get(data);
2159              if ((top) && (elm_win_xwindow_get(top)))
2160                elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
2161                                  wd->cut_sel);
2162 #endif
2163              eina_stringshare_del(wd->cut_sel);
2164              wd->cut_sel = NULL;
2165           }
2166         else
2167           {
2168 #ifdef HAVE_ELEMENTARY_X
2169              Evas_Object *top;
2170
2171              top = elm_widget_top_get(data);
2172              if ((top) && (elm_win_xwindow_get(top)))
2173                elm_selection_clear(ELM_SEL_PRIMARY, data);
2174 #endif
2175           }
2176      }
2177
2178    if ((wd->api) && (wd->api->obj_hidemenu))
2179      {
2180         wd->api->obj_hidemenu(data);
2181      }
2182 }
2183
2184 static void
2185 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2186 {
2187    Widget_Data *wd = elm_widget_data_get(data);
2188    if (!wd) return;
2189    evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
2190    if (wd->sel_notify_handler)
2191      {
2192 #ifdef HAVE_ELEMENTARY_X
2193         Evas_Object *top;
2194
2195         top = elm_widget_top_get(data);
2196         if ((top) && (elm_win_xwindow_get(top)))
2197           {
2198              wd->selection_asked = EINA_TRUE;
2199              elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
2200                                NULL, NULL);
2201           }
2202 #endif
2203      }
2204 }
2205
2206 static void
2207 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2208 {
2209    Widget_Data *wd = elm_widget_data_get(data);
2210    if (!wd) return;
2211    evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
2212    elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
2213                      elm_entry_selection_get(data));
2214 }
2215
2216 static void
2217 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2218 {
2219    Widget_Data *wd = elm_widget_data_get(data);
2220    if (!wd) return;
2221    evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
2222    elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
2223                      elm_entry_selection_get(data));
2224    edje_object_part_text_insert(wd->ent, "elm.text", "");
2225    wd->changed = EINA_TRUE;
2226    _sizing_eval(data);
2227 }
2228
2229 static void
2230 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2231 {
2232    Widget_Data *wd = elm_widget_data_get(data);
2233    if (!wd) return;
2234    wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2235    wd->cur_changed = EINA_TRUE;
2236    _recalc_cursor_geometry(data);
2237 }
2238
2239 static void
2240 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2241 {
2242    Widget_Data *wd = elm_widget_data_get(data);
2243    if (!wd) return;
2244 }
2245
2246 static void
2247 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2248 {
2249    Widget_Data *wd = elm_widget_data_get(data);
2250    if (!wd) return;
2251 }
2252
2253 static void
2254 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
2255 {
2256    Widget_Data *wd = elm_widget_data_get(data);
2257    Elm_Entry_Anchor_Info ei;
2258    char *buf2, *p, *p2, *n;
2259    if (!wd) return;
2260    p = strrchr(emission, ',');
2261    if (p)
2262      {
2263         const Eina_List *geoms;
2264
2265         n = p + 1;
2266         p2 = p -1;
2267         while (p2 >= emission)
2268           {
2269              if (*p2 == ',') break;
2270              p2--;
2271           }
2272         p2++;
2273         buf2 = alloca(5 + p - p2);
2274         strncpy(buf2, p2, p - p2);
2275         buf2[p - p2] = 0;
2276         ei.name = n;
2277         ei.button = atoi(buf2);
2278         ei.x = ei.y = ei.w = ei.h = 0;
2279         geoms =
2280            edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
2281         if (geoms)
2282           {
2283              Evas_Textblock_Rectangle *r;
2284              const Eina_List *l;
2285              Evas_Coord px, py, x, y;
2286
2287              evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
2288              evas_pointer_canvas_xy_get(evas_object_evas_get(wd->ent), &px, &py);
2289              EINA_LIST_FOREACH(geoms, l, r)
2290                {
2291                   if (((r->x + x) <= px) && ((r->y + y) <= py) &&
2292                       ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
2293                     {
2294                        ei.x = r->x + x;
2295                        ei.y = r->y + y;
2296                        ei.w = r->w;
2297                        ei.h = r->h;
2298                        break;
2299                     }
2300                }
2301           }
2302         if (!wd->disabled)
2303           evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
2304      }
2305 }
2306
2307 static void
2308 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2309 {
2310    Widget_Data *wd = elm_widget_data_get(data);
2311    if (!wd) return;
2312 }
2313
2314 static void
2315 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2316 {
2317    Widget_Data *wd = elm_widget_data_get(data);
2318    if (!wd) return;
2319 }
2320
2321 static void
2322 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2323 {
2324    Widget_Data *wd = elm_widget_data_get(data);
2325    if (!wd) return;
2326 }
2327
2328 static void
2329 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2330 {
2331    Widget_Data *wd = elm_widget_data_get(data);
2332    if (!wd) return;
2333    evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
2334 }
2335
2336 static void
2337 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2338 {
2339    Widget_Data *wd = elm_widget_data_get(data);
2340    if (!wd) return;
2341    wd->double_clicked = EINA_FALSE;
2342    evas_object_smart_callback_call(data, SIG_PRESS, NULL);
2343
2344    if ((wd->api) && (wd->api->obj_hidemenu))
2345      wd->api->obj_hidemenu(data);
2346 }
2347
2348 static void
2349 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2350 {
2351    Widget_Data *wd = elm_widget_data_get(data);
2352    if (!wd) return;
2353    evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
2354
2355    if (!_elm_config->desktop_entry && !wd->double_clicked)
2356      _cancel(data, NULL, NULL);
2357 }
2358
2359 static void
2360 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
2361 {
2362    Widget_Data *wd = elm_widget_data_get(data);
2363    if (!wd) return;
2364    wd->double_clicked = EINA_TRUE;
2365    evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
2366 }
2367
2368 #ifdef HAVE_ELEMENTARY_X
2369 static Eina_Bool
2370 _event_selection_notify(void *data, int type __UNUSED__, void *event)
2371 {
2372    Widget_Data *wd = elm_widget_data_get(data);
2373    Ecore_X_Event_Selection_Notify *ev = event;
2374    if (!wd) return ECORE_CALLBACK_PASS_ON;
2375    if ((!wd->selection_asked) && (!wd->drag_selection_asked))
2376      return ECORE_CALLBACK_PASS_ON;
2377
2378    if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
2379        (ev->selection == ECORE_X_SELECTION_PRIMARY))
2380      {
2381         Ecore_X_Selection_Data_Text *text_data;
2382
2383         text_data = ev->data;
2384         if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
2385           {
2386              if (text_data->text)
2387                {
2388                   char *txt = _elm_util_text_to_mkup(text_data->text);
2389
2390                   if (txt)
2391                     {
2392                        elm_entry_entry_insert(data, txt);
2393                        free(txt);
2394                     }
2395                }
2396           }
2397         wd->selection_asked = EINA_FALSE;
2398      }
2399    else if (ev->selection == ECORE_X_SELECTION_XDND)
2400      {
2401         Ecore_X_Selection_Data_Text *text_data;
2402
2403         text_data = ev->data;
2404         if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
2405           {
2406              if (text_data->text)
2407                {
2408                   char *txt = _elm_util_text_to_mkup(text_data->text);
2409
2410                   if (txt)
2411                     {
2412                        /* Massive FIXME: this should be at the drag point */
2413                        elm_entry_entry_insert(data, txt);
2414                        free(txt);
2415                     }
2416                }
2417           }
2418         wd->drag_selection_asked = EINA_FALSE;
2419
2420         ecore_x_dnd_send_finished();
2421
2422      }
2423    return ECORE_CALLBACK_PASS_ON;
2424 }
2425
2426 static Eina_Bool
2427 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
2428 {
2429 /*
2430    Widget_Data *wd = elm_widget_data_get(data);
2431    Ecore_X_Event_Selection_Clear *ev = event;
2432    if (!wd) return ECORE_CALLBACK_PASS_ON;
2433    if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
2434    if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
2435        (ev->selection == ECORE_X_SELECTION_PRIMARY))
2436      {
2437         elm_entry_select_none(data);
2438      }
2439    return 1; */
2440
2441    // start for cbhm
2442    Evas_Object *top = elm_widget_top_get(data);
2443    Ecore_X_Event_Selection_Clear *ev = event;
2444
2445    if (!top)
2446       return ECORE_CALLBACK_PASS_ON;
2447
2448    if (ev->selection != ECORE_X_SELECTION_SECONDARY)
2449      {
2450         return ECORE_CALLBACK_PASS_ON;
2451      }
2452
2453    if (cnpwidgetdata == data)
2454      {
2455         evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
2456         elm_selection_get(ELM_SEL_SECONDARY,ELM_SEL_FORMAT_MARKUP,data,NULL,NULL);
2457      }
2458
2459    // end for cbhm
2460    return ECORE_CALLBACK_PASS_ON;
2461 }
2462
2463 static Eina_Bool
2464 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
2465 {
2466    Widget_Data *wd;
2467    Eina_Bool rv;
2468
2469    wd = elm_widget_data_get(obj);
2470    if (!wd) return EINA_FALSE;
2471    printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
2472
2473    edje_object_part_text_cursor_copy(wd->ent, "elm.text",
2474                                      EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
2475    rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
2476                                                EDJE_CURSOR_MAIN,drop->x,drop->y);
2477    if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
2478    elm_entry_entry_insert(obj, drop->data);
2479    edje_object_part_text_cursor_copy(wd->ent, "elm.text",
2480                                      EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
2481
2482    return EINA_TRUE;
2483 }
2484 #endif
2485
2486 static Evas_Object *
2487 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
2488 {
2489    Widget_Data *wd = elm_widget_data_get(data);
2490    Evas_Object *o;
2491    Eina_List *l;
2492    Elm_Entry_Item_Provider *ip;
2493
2494    EINA_LIST_FOREACH(wd->item_providers, l, ip)
2495      {
2496         o = ip->func(ip->data, data, item);
2497         if (o) return o;
2498      }
2499    if (!strncmp(item, "file://", 7))
2500      {
2501         const char *fname = item + 7;
2502
2503         o = evas_object_image_filled_add(evas_object_evas_get(data));
2504         evas_object_image_file_set(o, fname, NULL);
2505         if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
2506           {
2507              evas_object_show(o);
2508           }
2509         else
2510           {
2511              evas_object_del(o);
2512              o = edje_object_add(evas_object_evas_get(data));
2513              _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
2514           }
2515         return o;
2516      }
2517    o = edje_object_add(evas_object_evas_get(data));
2518    if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
2519      _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
2520    return o;
2521 }
2522
2523 static int
2524 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
2525 {
2526    const char *srcstring = NULL;
2527    Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
2528    char *curlocater, *replocater;
2529    char *starttag, *endtag;
2530    int tagtxtlen = 0, insertflag = 0;
2531
2532    srcstring = eina_strbuf_string_get(srcbuf);
2533    curlocater = strstr(srcstring, key);
2534
2535    if (!curlocater || !srcstring)
2536      {
2537        insertflag = 1;
2538      }
2539    else
2540      {
2541        do
2542          {
2543            starttag = strchr(srcstring, '<');
2544            endtag = strchr(srcstring, '>');
2545            tagtxtlen = endtag - starttag;
2546            if (tagtxtlen <= 0) tagtxtlen = 0;
2547            if (starttag < curlocater && curlocater < endtag) break;
2548            if (endtag != NULL && endtag+1 != NULL)
2549              srcstring = endtag+1;
2550            else
2551              break;
2552          } while (strlen(srcstring) > 1);
2553
2554        if (starttag && endtag && tagtxtlen > strlen(key))
2555          {
2556            repbuf = eina_strbuf_new();
2557            diffbuf = eina_strbuf_new();
2558            eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
2559            srcstring = eina_strbuf_string_get(repbuf);
2560            curlocater = strstr(srcstring, key);
2561
2562            if (curlocater != NULL)
2563              {
2564                replocater = curlocater + strlen(key) + 1;
2565
2566                while ((*replocater) && (*replocater != ' ') && (*replocater != '>'))
2567                  replocater++;
2568
2569                if (replocater-curlocater > strlen(key)+1)
2570                  {
2571                    eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
2572                  }
2573                else
2574                  insertflag = 1;
2575              }
2576            else
2577              {
2578                insertflag = 1;
2579              }
2580            eina_strbuf_reset(repbuf);
2581          }
2582        else
2583          {
2584            insertflag = 1;
2585          }
2586      }
2587
2588    if (repbuf == NULL) repbuf = eina_strbuf_new();
2589    if (diffbuf == NULL) diffbuf = eina_strbuf_new();
2590
2591    if (insertflag)
2592      {
2593        eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
2594        eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
2595      }
2596    else
2597      {
2598         if (deleteflag)
2599           {
2600             eina_strbuf_prepend(diffbuf, "<");
2601             eina_strbuf_append(diffbuf, ">");
2602             eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
2603           }
2604         else
2605           {
2606             eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
2607             eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
2608           }
2609      }
2610
2611    if (repbuf) eina_strbuf_free(repbuf);
2612    if (diffbuf) eina_strbuf_free(diffbuf);
2613
2614    return 0;
2615 }
2616
2617 static int
2618 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
2619 {
2620    Eina_Strbuf *sharebuf = NULL;
2621
2622    sharebuf = eina_strbuf_new();
2623    eina_strbuf_append(sharebuf, *srcstring);
2624    _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
2625    eina_stringshare_del(*srcstring);
2626    *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
2627    eina_strbuf_free(sharebuf);
2628
2629    return 0;
2630 }
2631
2632 static void
2633 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
2634 {
2635    Widget_Data *wd = elm_widget_data_get(data);
2636    Eina_List *l;
2637    Elm_Entry_Text_Filter *tf;
2638
2639    if (type == EDJE_TEXT_FILTER_FORMAT)
2640      return;
2641
2642    EINA_LIST_FOREACH(wd->text_filters, l, tf)
2643      {
2644         tf->func(tf->data, data, text);
2645         if (!*text)
2646           break;
2647      }
2648 }
2649
2650 /* This function is used to insert text by chunks in jobs */
2651 static Eina_Bool
2652 _text_append_idler(void *data)
2653 {
2654    int start;
2655    char backup;
2656    Evas_Object *obj = (Evas_Object *) data;
2657    Widget_Data *wd = elm_widget_data_get(obj);
2658    if (wd->text) eina_stringshare_del(wd->text);
2659    wd->text = NULL;
2660    if (wd->password_text) eina_stringshare_del(wd->password_text);
2661    wd->password_text = NULL;
2662    wd->changed = EINA_TRUE;
2663
2664    start = wd->append_text_position;
2665    if (start + _CHUNK_SIZE < wd->append_text_len)
2666      {
2667         int pos = start;
2668         int tag_start, esc_start;
2669
2670         tag_start = esc_start = -1;
2671         /* Find proper markup cut place */
2672         while (pos - start < _CHUNK_SIZE)
2673           {
2674              int prev_pos = pos;
2675              Eina_Unicode tmp =
2676                 eina_unicode_utf8_get_next(wd->append_text_left, &pos);
2677              if (esc_start == -1)
2678                {
2679                   if (tmp == '<')
2680                      tag_start = prev_pos;
2681                   else if (tmp == '>')
2682                      tag_start = -1;
2683                }
2684              else if (tag_start == -1)
2685                {
2686                   if (tmp == '&')
2687                      esc_start = prev_pos;
2688                   else if (tmp == ';')
2689                      esc_start = -1;
2690                }
2691           }
2692
2693         if (tag_start >= 0)
2694           {
2695              wd->append_text_position = tag_start;
2696           }
2697         else if (esc_start >= 0)
2698           {
2699              wd->append_text_position = esc_start;
2700           }
2701         else
2702           {
2703              wd->append_text_position = pos;
2704           }
2705      }
2706    else
2707      {
2708         wd->append_text_position = wd->append_text_len;
2709      }
2710
2711    backup = wd->append_text_left[wd->append_text_position];
2712    wd->append_text_left[wd->append_text_position] = '\0';
2713
2714    edje_object_part_text_append(wd->ent, "elm.text",
2715          wd->append_text_left + start);
2716
2717    wd->append_text_left[wd->append_text_position] = backup;
2718
2719    /* If there's still more to go, renew the idler, else, cleanup */
2720    if (wd->append_text_position < wd->append_text_len)
2721      {
2722         return ECORE_CALLBACK_RENEW;
2723      }
2724    else
2725      {
2726         free(wd->append_text_left);
2727         wd->append_text_left = NULL;
2728         wd->append_text_idler = NULL;
2729         return ECORE_CALLBACK_CANCEL;
2730      }
2731 }
2732
2733 static void
2734 _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit)
2735 {
2736    int i = 0, unit_size;
2737    int current_len = strlen(*text);
2738    char *new_text = *text;
2739    if (unit >= LENGTH_UNIT_LAST) return;
2740    while (*new_text)
2741      {
2742         if (*new_text == '<')
2743           {
2744              while (*new_text != '>')
2745                {
2746                   new_text++;
2747                   if (!*new_text) break;
2748                }
2749              new_text++;
2750           }
2751         else
2752           {
2753              int index = 0;
2754              if (*new_text == '&')
2755                {
2756                   while (*(new_text + index) != ';')
2757                     {
2758                        index++;
2759                        if (!*(new_text + index)) break;
2760                     }
2761                }
2762              char *markup;
2763              index = evas_string_char_next_get(new_text, index, NULL);
2764              markup = malloc(index + 1);
2765              strncpy(markup, new_text, index);
2766              markup[index] = 0;
2767              if (unit == LENGTH_UNIT_BYTE)
2768                unit_size = strlen(elm_entry_markup_to_utf8(markup));
2769              else if (unit == LENGTH_UNIT_CHAR)
2770                unit_size = evas_string_char_len_get(elm_entry_markup_to_utf8(markup));
2771              if (markup)
2772                {
2773                   free(markup);
2774                   markup = NULL;
2775                }
2776              if (can_add < unit_size)
2777                {
2778                   if (!i)
2779                     {
2780                        evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
2781                        free(*text);
2782                        *text = NULL;
2783                        return;
2784                     }
2785                   can_add = 0;
2786                   strncpy(new_text, new_text + index, current_len - ((new_text + index) - *text));
2787                   current_len -= index;
2788                   (*text)[current_len] = 0;
2789                }
2790              else
2791                {
2792                   new_text += index;
2793                   can_add -= unit_size;
2794                }
2795              i++;
2796           }
2797      }
2798    evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
2799 }
2800
2801 static void
2802 _elm_entry_text_set(Evas_Object *obj, const char *item, const char *entry)
2803 {
2804    int len = 0;
2805    ELM_CHECK_WIDTYPE(obj, widtype);
2806    Widget_Data *wd = elm_widget_data_get(obj);
2807    if (!wd) return;
2808    if (!entry) entry = "";
2809    if (item && strcmp(item, "default"))
2810      {
2811         edje_object_part_text_set(wd->ent, item, entry);
2812         return;
2813      }
2814    if (wd->text) eina_stringshare_del(wd->text);
2815    wd->text = NULL;
2816    if (wd->password_text) eina_stringshare_del(wd->password_text);
2817    wd->password_text = NULL;
2818    wd->changed = EINA_TRUE;
2819
2820    /* Clear currently pending job if there is one */
2821    if (wd->append_text_idler)
2822      {
2823         ecore_idler_del(wd->append_text_idler);
2824         free(wd->append_text_left);
2825         wd->append_text_left = NULL;
2826         wd->append_text_idler = NULL;
2827      }
2828
2829    len = strlen(entry);
2830    /* Split to ~_CHUNK_SIZE chunks */
2831    if (len > _CHUNK_SIZE)
2832      {
2833         wd->append_text_left = (char *) malloc(len + 1);
2834      }
2835
2836    /* If we decided to use the idler */
2837    if (wd->append_text_left)
2838      {
2839         /* Need to clear the entry first */
2840         edje_object_part_text_set(wd->ent, "elm.text", "");
2841         memcpy(wd->append_text_left, entry, len + 1);
2842         wd->append_text_position = 0;
2843         wd->append_text_len = len;
2844         wd->append_text_idler = ecore_idler_add(_text_append_idler, obj);
2845      }
2846    else
2847      {
2848         edje_object_part_text_set(wd->ent, "elm.text", entry);
2849      }
2850 }
2851
2852 static const char *
2853 _elm_entry_text_get(const Evas_Object *obj, const char *item)
2854 {
2855    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2856    Widget_Data *wd = elm_widget_data_get(obj);
2857    if (item && strcmp(item, "default")) return NULL;
2858    const char *text;
2859    if (!wd) return NULL;
2860    if (wd->password)
2861      {
2862         if(wd->password_text) return wd->password_text;
2863      }
2864    else if (wd->text) 
2865      {
2866         return wd->text;
2867      }
2868    text = edje_object_part_text_get(wd->ent, "elm.text");
2869    if (!text)
2870      {
2871         ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2872         return NULL;
2873      }
2874    eina_stringshare_replace(&wd->text, text);
2875    if (wd->password)
2876      {
2877         const char *pw_text;
2878         pw_text = elm_entry_markup_to_utf8(wd->text);
2879         if (pw_text)
2880           {
2881              eina_stringshare_replace(&wd->password_text, pw_text);
2882              free(pw_text);
2883              return wd->password_text;
2884           }
2885      }
2886    return wd->text;
2887 }
2888
2889 /**
2890  * This adds an entry to @p parent object.
2891  *
2892  * @param parent The parent object
2893  * @return The new object or NULL if it cannot be created
2894  *
2895  * @ingroup Entry
2896  */
2897 EAPI Evas_Object *
2898 elm_entry_add(Evas_Object *parent)
2899 {
2900    Evas_Object *obj, *top;
2901    Evas *e;
2902    Widget_Data *wd;
2903
2904    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
2905
2906    ELM_SET_WIDTYPE(widtype, "entry");
2907    elm_widget_type_set(obj, "entry");
2908    elm_widget_sub_object_add(parent, obj);
2909    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2910    elm_widget_data_set(obj, wd);
2911    elm_widget_del_hook_set(obj, _del_hook);
2912    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2913    elm_widget_theme_hook_set(obj, _theme_hook);
2914    elm_widget_disable_hook_set(obj, _disable_hook);
2915    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2916    elm_widget_focus_region_hook_set(obj, _focus_region_hook);
2917    elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
2918    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
2919    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
2920    elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
2921    elm_widget_can_focus_set(obj, EINA_TRUE);
2922    elm_widget_highlight_ignore_set(obj, EINA_TRUE);
2923    elm_widget_text_set_hook_set(obj, _elm_entry_text_set);
2924    elm_widget_text_get_hook_set(obj, _elm_entry_text_get);
2925    elm_widget_content_set_hook_set(obj, _content_set_hook);
2926    elm_widget_content_unset_hook_set(obj, _content_unset_hook);
2927    elm_widget_content_get_hook_set(obj, _content_get_hook);
2928
2929    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, wd);
2930    wd->scroller = elm_smart_scroller_add(e);
2931    elm_widget_sub_object_add(obj, wd->scroller);
2932    elm_smart_scroller_widget_set(wd->scroller, obj);
2933    elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
2934                                        elm_widget_style_get(obj));
2935    evas_object_size_hint_weight_set(wd->scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
2936    evas_object_size_hint_align_set(wd->scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
2937    elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
2938    elm_smart_scroller_propagate_events_set(wd->scroller, EINA_TRUE);
2939
2940    wd->linewrap     = ELM_WRAP_WORD;
2941    wd->editable     = EINA_TRUE;
2942    wd->disabled     = EINA_FALSE;
2943    wd->context_menu = EINA_TRUE;
2944    wd->autosave     = EINA_TRUE;
2945    wd->textonly     = EINA_FALSE;
2946    wd->autoperiod   = EINA_TRUE;
2947
2948    wd->ent = edje_object_add(e);
2949    elm_widget_sub_object_add(obj, wd->ent);
2950    edje_object_item_provider_set(wd->ent, _get_item, obj);
2951    edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
2952    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
2953    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
2954                                   _mouse_down, obj);
2955    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
2956                                   _mouse_up, obj);
2957    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
2958                                   _mouse_move, obj);
2959    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
2960
2961    _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
2962    edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
2963                                    _signal_entry_changed, obj);
2964    edje_object_signal_callback_add(wd->ent, "preedit,changed", "elm.text",
2965                                    _signal_preedit_changed, obj);
2966    edje_object_signal_callback_add(wd->ent, "handler,move,start", "elm.text",
2967                                    _signal_handler_move_start, obj);
2968    edje_object_signal_callback_add(wd->ent, "handler,move,end", "elm.text",
2969                                    _signal_handler_move_end, obj);
2970    edje_object_signal_callback_add(wd->ent, "handler,moving", "elm.text",
2971                                    _signal_handler_moving, obj);
2972    edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
2973                                    _signal_selection_start, obj);
2974    edje_object_signal_callback_add(wd->ent, "selection,end", "elm.text",
2975                                    _signal_selection_end, obj);
2976    edje_object_signal_callback_add(wd->ent, "long,pressed", "elm.text",
2977                                    _signal_long_pressed, obj);
2978    edje_object_signal_callback_add(wd->ent, "magnifier,changed", "elm.text",
2979                                    _signal_magnifier_changed, obj);
2980    edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
2981                                    _signal_selection_changed, obj);
2982    edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2983                                    _signal_selection_cleared, obj);
2984    edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
2985                                    _signal_entry_paste_request, obj);
2986    edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2987                                    _signal_entry_copy_notify, obj);
2988    edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2989                                    _signal_entry_cut_notify, obj);
2990    edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2991                                    _signal_cursor_changed, obj);
2992    edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2993                                    _signal_anchor_down, obj);
2994    edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2995                                    _signal_anchor_up, obj);
2996    edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
2997                                    _signal_anchor_clicked, obj);
2998    edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2999                                    _signal_anchor_move, obj);
3000    edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
3001                                    _signal_anchor_in, obj);
3002    edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
3003                                    _signal_anchor_out, obj);
3004    edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
3005                                    _signal_key_enter, obj);
3006    edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
3007                                    _signal_mouse_down, obj);
3008    edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
3009                                    _signal_mouse_clicked, obj);
3010    edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
3011                                    _signal_mouse_double, obj);
3012    edje_object_part_text_set(wd->ent, "elm.text", "");
3013    if (_elm_config->desktop_entry)
3014      edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
3015    elm_widget_resize_object_set(obj, wd->ent);
3016    _sizing_eval(obj);
3017
3018    wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
3019
3020 #ifdef HAVE_ELEMENTARY_X
3021    top = elm_widget_top_get(obj);
3022    if ((top) && (elm_win_xwindow_get(top)))
3023      {
3024         wd->sel_notify_handler =
3025            ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
3026                                    _event_selection_notify, obj);
3027         wd->sel_clear_handler =
3028            ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
3029                                    _event_selection_clear, obj);
3030      }
3031
3032    elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
3033                        _drag_drop_cb, NULL);
3034 #endif
3035
3036    entries = eina_list_prepend(entries, obj);
3037
3038    // module - find module for entry
3039    wd->api = _module(obj);
3040    // if found - hook in
3041    if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
3042
3043    _mirrored_set(obj, elm_widget_mirrored_get(obj));
3044    // TODO: convert Elementary to subclassing of Evas_Smart_Class
3045    // TODO: and save some bytes, making descriptions per-class and not instance!
3046    evas_object_smart_callbacks_descriptions_set(obj, _signals);
3047    return obj;
3048 }
3049
3050 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
3051 {
3052    ELM_CHECK_WIDTYPE(obj, widtype);
3053    Widget_Data *wd = elm_widget_data_get(obj);
3054    if (!wd) return;
3055    ext_mod->cancel = _cancel;
3056    ext_mod->copy = _copy;
3057    ext_mod->cut = _cut;
3058    ext_mod->paste = _paste;
3059    ext_mod->select = _select;
3060    ext_mod->selectall = _selectall;
3061    ext_mod->ent = wd->ent;
3062    ext_mod->viewport_obj = _viewport_obj_get(obj);
3063    ext_mod->items = wd->items;
3064    ext_mod->editable = wd->editable;
3065    ext_mod->have_selection = wd->have_selection;
3066    ext_mod->password = wd->password;
3067    ext_mod->selmode = wd->selmode;
3068    ext_mod->cnpinit = _cnpinit;
3069    ext_mod->context_menu = wd->context_menu;
3070    ext_mod->textonly = wd->textonly;
3071 }
3072
3073 /**
3074  * This sets the entry object not to line wrap.  All input will
3075  * be on a single line, and the entry box will extend with user input.
3076  *
3077  * @param obj The entry object
3078  * @param single_line If true, the text in the entry
3079  * will be on a single line.
3080  *
3081  * @ingroup Entry
3082  */
3083 EAPI void
3084 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
3085 {
3086    ELM_CHECK_WIDTYPE(obj, widtype);
3087    Widget_Data *wd = elm_widget_data_get(obj);
3088    if (!wd) return;
3089    if (wd->single_line == single_line) return;
3090    wd->single_line = single_line;
3091    wd->linewrap = ELM_WRAP_NONE;
3092    elm_entry_cnp_textonly_set(obj, EINA_TRUE);
3093    _theme_hook(obj);
3094    if (wd->scroller)
3095      {
3096         if (wd->single_line)
3097           {
3098              elm_smart_scroller_policy_set(wd->scroller,
3099                                            ELM_SMART_SCROLLER_POLICY_OFF,
3100                                            ELM_SMART_SCROLLER_POLICY_OFF);
3101              elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
3102           }
3103         else
3104           {
3105              const Elm_Scroller_Policy map[3] =
3106                {
3107                   ELM_SMART_SCROLLER_POLICY_AUTO,
3108                   ELM_SMART_SCROLLER_POLICY_ON,
3109                   ELM_SMART_SCROLLER_POLICY_OFF
3110                };
3111              elm_smart_scroller_policy_set(wd->scroller,
3112                                            map[wd->policy_h],
3113                                            map[wd->policy_v]);
3114              elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
3115           }
3116         _sizing_eval(obj);
3117      }
3118 }
3119
3120 /**
3121  * This returns true if the entry has been set to single line mode.
3122  * See also elm_entry_single_line_set().
3123  *
3124  * @param obj The entry object
3125  * @return single_line If true, the text in the entry is set to display
3126  * on a single line.
3127  *
3128  * @ingroup Entry
3129  */
3130 EAPI Eina_Bool
3131 elm_entry_single_line_get(const Evas_Object *obj)
3132 {
3133    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3134    Widget_Data *wd = elm_widget_data_get(obj);
3135    if (!wd) return EINA_FALSE;
3136    return wd->single_line;
3137 }
3138
3139 /**
3140  * This sets the entry object to password mode.  All text entered
3141  * and/or displayed within the widget will be replaced with asterisks (*).
3142  *
3143  * @param obj The entry object
3144  * @param password If true, password mode is enabled.
3145  *
3146  * @ingroup Entry
3147  */
3148 EAPI void
3149 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
3150 {
3151    ELM_CHECK_WIDTYPE(obj, widtype);
3152    Widget_Data *wd = elm_widget_data_get(obj);
3153    if (!wd) return;
3154    if (wd->password == password) return;
3155    wd->password = password;
3156    wd->single_line = EINA_TRUE;
3157    wd->linewrap = ELM_WRAP_NONE;
3158    _theme_hook(obj);
3159 }
3160
3161 /**
3162  * This returns whether password mode is enabled.
3163  * See also elm_entry_password_set().
3164  *
3165  * @param obj The entry object
3166  * @return If true, the entry is set to display all characters
3167  * as asterisks (*).
3168  *
3169  * @ingroup Entry
3170  */
3171 EAPI Eina_Bool
3172 elm_entry_password_get(const Evas_Object *obj)
3173 {
3174    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3175    Widget_Data *wd = elm_widget_data_get(obj);
3176    if (!wd) return EINA_FALSE;
3177    return wd->password;
3178 }
3179
3180 /**
3181  * This sets the text displayed within the entry to @p entry.
3182  *
3183  * @param obj The entry object
3184  * @param entry The text to be displayed
3185  *
3186  * @ingroup Entry
3187  */
3188 EAPI void
3189 elm_entry_entry_set(Evas_Object *obj, const char *entry)
3190 {
3191    _elm_entry_text_set(obj, NULL, entry);
3192 }
3193
3194 /**
3195  * This appends @p entry to the text of the entry.
3196  *
3197  * @param obj The entry object
3198  * @param entry The text to be displayed
3199  *
3200  * @ingroup Entry
3201  */
3202 EAPI void
3203 elm_entry_entry_append(Evas_Object *obj, const char *entry)
3204 {
3205    int len = 0;
3206    ELM_CHECK_WIDTYPE(obj, widtype);
3207    Widget_Data *wd = elm_widget_data_get(obj);
3208    if (!wd) return;
3209    if (!entry) entry = "";
3210    wd->changed = EINA_TRUE;
3211
3212    len = strlen(entry);
3213    if (wd->append_text_left)
3214      {
3215         char *tmpbuf;
3216         tmpbuf = realloc(wd->append_text_left, wd->append_text_len + len + 1);
3217         if (!tmpbuf)
3218           {
3219              /* Do something */
3220              return;
3221           }
3222         wd->append_text_left = tmpbuf;
3223         memcpy(wd->append_text_left + wd->append_text_len, entry, len + 1);
3224         wd->append_text_len += len;
3225      }
3226    else
3227      {
3228         /* FIXME: Add chunked appending here (like in entry_set) */
3229         edje_object_part_text_append(wd->ent, "elm.text", entry);
3230      }
3231 }
3232
3233 /**
3234  * This returns the text currently shown in object @p entry.
3235  * See also elm_entry_entry_set().
3236  *
3237  * @param obj The entry object
3238  * @return The currently displayed text or NULL on failure
3239  *
3240  * @ingroup Entry
3241  */
3242 EAPI const char *
3243 elm_entry_entry_get(const Evas_Object *obj)
3244 {
3245    return _elm_entry_text_get(obj, NULL);
3246 }
3247
3248 /**
3249  * This returns EINA_TRUE if the entry is empty/there was an error
3250  * and EINA_FALSE if it is not empty.
3251  *
3252  * @param obj The entry object
3253  * @return If the entry is empty or not.
3254  *
3255  * @ingroup Entry
3256  */
3257 EAPI Eina_Bool
3258 elm_entry_is_empty(const Evas_Object *obj)
3259 {
3260    /* FIXME: until there's support for that in textblock, we just check
3261     * to see if the there is text or not. */
3262    ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
3263    Widget_Data *wd = elm_widget_data_get(obj);
3264    const Evas_Object *tb;
3265    //Evas_Textblock_Cursor *cur;
3266    Eina_Bool ret;
3267    if (!wd) return EINA_TRUE;
3268
3269 #if 0
3270    /* It's a hack until we get the support suggested above.
3271     * We just create a cursor, point it to the begining, and then
3272     * try to advance it, if it can advance, the tb is not empty,
3273     * otherwise it is. */
3274    tb = edje_object_part_object_get(wd->ent, "elm.text");
3275    cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
3276                                                                   actually, ok for the time being, thsese hackish stuff will be removed
3277                                                                   once evas 1.0 is out*/
3278    evas_textblock_cursor_pos_set(cur, 0);
3279    ret = evas_textblock_cursor_char_next(cur);
3280    evas_textblock_cursor_free(cur);
3281
3282    return !ret;
3283 #endif
3284
3285    char *str = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
3286    if (!str) return EINA_TRUE;
3287
3288    ret = (strlen(str) == 0);
3289
3290    return ret;
3291 }
3292
3293 /**
3294  * This returns all selected text within the entry.
3295  *
3296  * @param obj The entry object
3297  * @return The selected text within the entry or NULL on failure
3298  *
3299  * @ingroup Entry
3300  */
3301 EAPI const char *
3302 elm_entry_selection_get(const Evas_Object *obj)
3303 {
3304    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3305    Widget_Data *wd = elm_widget_data_get(obj);
3306    if (!wd) return NULL;
3307    return edje_object_part_text_selection_get(wd->ent, "elm.text");
3308 }
3309
3310 /**
3311  * This inserts text in @p entry where the current cursor position.
3312  *
3313  * This inserts text at the cursor position is as if it was typed
3314  * by the user (note this also allows markup which a user
3315  * can't just "type" as it would be converted to escaped text, so this
3316  * call can be used to insert things like emoticon items or bold push/pop
3317  * tags, other font and color change tags etc.)
3318  *
3319  * @param obj The entry object
3320  * @param entry The text to insert
3321  *
3322  * @ingroup Entry
3323  */
3324 EAPI void
3325 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
3326 {
3327    ELM_CHECK_WIDTYPE(obj, widtype);
3328    Widget_Data *wd = elm_widget_data_get(obj);
3329    if (!wd) return;
3330    edje_object_part_text_insert(wd->ent, "elm.text", entry);
3331    // start for cbhm
3332 #ifdef HAVE_ELEMENTARY_X
3333    if (cnpwidgetdata == obj)
3334       ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
3335 #endif
3336    // end for cbhm
3337    wd->changed = EINA_TRUE;
3338    _sizing_eval(obj);
3339 }
3340
3341 /**
3342  * This enables word line wrapping in the entry object.  It is the opposite
3343  * of elm_entry_single_line_set().  Additionally, setting this disables
3344  * character line wrapping.
3345  *
3346  * @param obj The entry object
3347  * @param wrap If true, the entry will be wrapped once it reaches the end
3348  * of the object. Wrapping will occur at the end of the word before the end of the
3349  * object.
3350  *
3351  * @ingroup Entry
3352  */
3353 EAPI void
3354 elm_entry_line_wrap_set(Evas_Object *obj, Elm_Wrap_Type wrap)
3355 {
3356    ELM_CHECK_WIDTYPE(obj, widtype);
3357    Widget_Data *wd = elm_widget_data_get(obj);
3358    if (!wd) return;
3359    if (wd->linewrap == wrap) return;
3360    wd->lastw = -1;
3361    wd->linewrap = wrap;
3362    _theme_hook(obj);
3363 }
3364
3365 /**
3366  * Get the wrapping behavior of the entry.
3367  * See also elm_entry_line_wrap_set().
3368  *
3369  * @param obj The entry object
3370  * @return Wrap type
3371  *
3372  * @ingroup Entry
3373  */
3374 EAPI Elm_Wrap_Type
3375 elm_entry_line_wrap_get(const Evas_Object *obj)
3376 {
3377    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3378    Widget_Data *wd = elm_widget_data_get(obj);
3379    if (!wd) return EINA_FALSE;
3380    return wd->linewrap;
3381 }
3382
3383 /**
3384  * This sets the editable attribute of the entry.
3385  *
3386  * @param obj The entry object
3387  * @param editable If true, the entry will be editable by the user.
3388  * If false, it will be set to the disabled state.
3389  *
3390  * @ingroup Entry
3391  */
3392 EAPI void
3393 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
3394 {
3395    ELM_CHECK_WIDTYPE(obj, widtype);
3396    Widget_Data *wd = elm_widget_data_get(obj);
3397    if (!wd) return;
3398    if (wd->editable == editable) return;
3399    wd->editable = editable;
3400    _theme_hook(obj);
3401
3402 #ifdef HAVE_ELEMENTARY_X
3403    if (editable)
3404      elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
3405    else
3406      elm_drop_target_del(obj);
3407 #endif
3408 }
3409
3410 /**
3411  * This gets the editable attribute of the entry.
3412  * See also elm_entry_editable_set().
3413  *
3414  * @param obj The entry object
3415  * @return If true, the entry is editable by the user.
3416  * If false, it is not editable by the user
3417  *
3418  * @ingroup Entry
3419  */
3420 EAPI Eina_Bool
3421 elm_entry_editable_get(const Evas_Object *obj)
3422 {
3423    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3424    Widget_Data *wd = elm_widget_data_get(obj);
3425    if (!wd) return EINA_FALSE;
3426    return wd->editable;
3427 }
3428
3429 /**
3430  * This drops any existing text selection within the entry.
3431  *
3432  * @param obj The entry object
3433  *
3434  * @ingroup Entry
3435  */
3436 EAPI void
3437 elm_entry_select_none(Evas_Object *obj)
3438 {
3439    ELM_CHECK_WIDTYPE(obj, widtype);
3440    Widget_Data *wd = elm_widget_data_get(obj);
3441    if (!wd) return;
3442    if (wd->selmode)
3443      {
3444         wd->selmode = EINA_FALSE;
3445         if (!_elm_config->desktop_entry)
3446           edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
3447         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
3448      }
3449    wd->have_selection = EINA_FALSE;
3450    edje_object_part_text_select_none(wd->ent, "elm.text");
3451 }
3452
3453 /**
3454  * This selects all text within the entry.
3455  *
3456  * @param obj The entry object
3457  *
3458  * @ingroup Entry
3459  */
3460 EAPI void
3461 elm_entry_select_all(Evas_Object *obj)
3462 {
3463    ELM_CHECK_WIDTYPE(obj, widtype);
3464    Widget_Data *wd = elm_widget_data_get(obj);
3465    if (!wd) return;
3466    if (wd->selmode)
3467      {
3468         wd->selmode = EINA_FALSE;
3469         if (!_elm_config->desktop_entry)
3470           edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
3471         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
3472      }
3473    wd->have_selection = EINA_TRUE;
3474    edje_object_part_text_select_all(wd->ent, "elm.text");
3475 }
3476
3477 /**
3478  * This function returns the geometry of the cursor.
3479  *
3480  * It's useful if you want to draw something on the cursor (or where it is),
3481  * or for example in the case of scrolled entry where you want to show the
3482  * cursor.
3483  *
3484  * @param obj The entry object
3485  * @param x returned geometry
3486  * @param y returned geometry
3487  * @param w returned geometry
3488  * @param h returned geometry
3489  * @return EINA_TRUE upon success, EINA_FALSE upon failure
3490  *
3491  * @ingroup Entry
3492  */
3493 EAPI Eina_Bool
3494 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
3495 {
3496    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3497    Widget_Data *wd = elm_widget_data_get(obj);
3498    if (!wd) return EINA_FALSE;
3499    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
3500    return EINA_TRUE;
3501 }
3502
3503 /**
3504  * This moves the cursor one place to the right within the entry.
3505  *
3506  * @param obj The entry object
3507  * @return EINA_TRUE upon success, EINA_FALSE upon failure
3508  *
3509  * @ingroup Entry
3510  */
3511 EAPI Eina_Bool
3512 elm_entry_cursor_next(Evas_Object *obj)
3513 {
3514    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3515    Widget_Data *wd = elm_widget_data_get(obj);
3516    if (!wd) return EINA_FALSE;
3517    return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3518 }
3519
3520 /**
3521  * This moves the cursor one place to the left within the entry.
3522  *
3523  * @param obj The entry object
3524  * @return EINA_TRUE upon success, EINA_FALSE upon failure
3525  *
3526  * @ingroup Entry
3527  */
3528 EAPI Eina_Bool
3529 elm_entry_cursor_prev(Evas_Object *obj)
3530 {
3531    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3532    Widget_Data *wd = elm_widget_data_get(obj);
3533    if (!wd) return EINA_FALSE;
3534    return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3535 }
3536
3537 /**
3538  * This moves the cursor one line up within the entry.
3539  *
3540  * @param obj The entry object
3541  * @return EINA_TRUE upon success, EINA_FALSE upon failure
3542  *
3543  * @ingroup Entry
3544  */
3545 EAPI Eina_Bool
3546 elm_entry_cursor_up(Evas_Object *obj)
3547 {
3548    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3549    Widget_Data *wd = elm_widget_data_get(obj);
3550    if (!wd) return EINA_FALSE;
3551    return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3552 }
3553
3554 /**
3555  * This moves the cursor one line down within the entry.
3556  *
3557  * @param obj The entry object
3558  * @return EINA_TRUE upon success, EINA_FALSE upon failure
3559  *
3560  * @ingroup Entry
3561  */
3562 EAPI Eina_Bool
3563 elm_entry_cursor_down(Evas_Object *obj)
3564 {
3565    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3566    Widget_Data *wd = elm_widget_data_get(obj);
3567    if (!wd) return EINA_FALSE;
3568    return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3569 }
3570
3571 /**
3572  * This moves the cursor to the beginning of the entry.
3573  *
3574  * @param obj The entry object
3575  *
3576  * @ingroup Entry
3577  */
3578 EAPI void
3579 elm_entry_cursor_begin_set(Evas_Object *obj)
3580 {
3581    ELM_CHECK_WIDTYPE(obj, widtype);
3582    Widget_Data *wd = elm_widget_data_get(obj);
3583    if (!wd) return;
3584    edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3585 }
3586
3587 /**
3588  * This moves the cursor to the end of the entry.
3589  *
3590  * @param obj The entry object
3591  *
3592  * @ingroup Entry
3593  */
3594 EAPI void
3595 elm_entry_cursor_end_set(Evas_Object *obj)
3596 {
3597    ELM_CHECK_WIDTYPE(obj, widtype);
3598    Widget_Data *wd = elm_widget_data_get(obj);
3599    if (!wd) return;
3600    int x, y, w, h;
3601    edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3602    if (wd->scroll)
3603      {
3604         elm_widget_show_region_get(wd->ent, &x, &y, &w, &h);
3605         elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
3606      }
3607 }
3608
3609 /**
3610  * This moves the cursor to the beginning of the current line.
3611  *
3612  * @param obj The entry object
3613  *
3614  * @ingroup Entry
3615  */
3616 EAPI void
3617 elm_entry_cursor_line_begin_set(Evas_Object *obj)
3618 {
3619    ELM_CHECK_WIDTYPE(obj, widtype);
3620    Widget_Data *wd = elm_widget_data_get(obj);
3621    if (!wd) return;
3622    edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3623 }
3624
3625 /**
3626  * This moves the cursor to the end of the current line.
3627  *
3628  * @param obj The entry object
3629  *
3630  * @ingroup Entry
3631  */
3632 EAPI void
3633 elm_entry_cursor_line_end_set(Evas_Object *obj)
3634 {
3635    ELM_CHECK_WIDTYPE(obj, widtype);
3636    Widget_Data *wd = elm_widget_data_get(obj);
3637    if (!wd) return;
3638    edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3639 }
3640
3641 /**
3642  * This begins a selection within the entry as though
3643  * the user were holding down the mouse button to make a selection.
3644  *
3645  * @param obj The entry object
3646  *
3647  * @ingroup Entry
3648  */
3649 EAPI void
3650 elm_entry_cursor_selection_begin(Evas_Object *obj)
3651 {
3652    ELM_CHECK_WIDTYPE(obj, widtype);
3653    Widget_Data *wd = elm_widget_data_get(obj);
3654    if (!wd) return;
3655    edje_object_part_text_select_begin(wd->ent, "elm.text");
3656 }
3657
3658 /**
3659  * This ends a selection within the entry as though
3660  * the user had just released the mouse button while making a selection.
3661  *
3662  * @param obj The entry object
3663  *
3664  * @ingroup Entry
3665  */
3666 EAPI void
3667 elm_entry_cursor_selection_end(Evas_Object *obj)
3668 {
3669    ELM_CHECK_WIDTYPE(obj, widtype);
3670    Widget_Data *wd = elm_widget_data_get(obj);
3671    if (!wd) return;
3672    edje_object_part_text_select_extend(wd->ent, "elm.text");
3673 }
3674
3675 /**
3676  * TODO: fill this in
3677  *
3678  * @param obj The entry object
3679  * @return TODO: fill this in
3680  *
3681  * @ingroup Entry
3682  */
3683 EAPI Eina_Bool
3684 elm_entry_cursor_is_format_get(const Evas_Object *obj)
3685 {
3686    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3687    Widget_Data *wd = elm_widget_data_get(obj);
3688    if (!wd) return EINA_FALSE;
3689    return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3690 }
3691
3692 /**
3693  * This returns whether the cursor is visible.
3694  *
3695  * @param obj The entry object
3696  * @return If true, the cursor is visible.
3697  *
3698  * @ingroup Entry
3699  */
3700 EAPI Eina_Bool
3701 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
3702 {
3703    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3704    Widget_Data *wd = elm_widget_data_get(obj);
3705    if (!wd) return EINA_FALSE;
3706    return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3707 }
3708
3709 /**
3710  * TODO: fill this in
3711  *
3712  * @param obj The entry object
3713  * @return TODO: fill this in
3714  *
3715  * @ingroup Entry
3716  */
3717 EAPI const char *
3718 elm_entry_cursor_content_get(const Evas_Object *obj)
3719 {
3720    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3721    Widget_Data *wd = elm_widget_data_get(obj);
3722    if (!wd) return NULL;
3723    return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3724 }
3725
3726 /**
3727  * Sets the cursor position in the entry to the given value
3728  *
3729  * @param obj The entry object
3730  * @param pos The position of the cursor
3731  *
3732  * @ingroup Entry
3733  */
3734 EAPI void
3735 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
3736 {
3737    ELM_CHECK_WIDTYPE(obj, widtype);
3738    Widget_Data *wd = elm_widget_data_get(obj);
3739    if (!wd) return;
3740    edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
3741    edje_object_message_signal_process(wd->ent);
3742 }
3743
3744 /**
3745  * Retrieves the current position of the cursor in the entry
3746  *
3747  * @param obj The entry object
3748  * @return The cursor position
3749  *
3750  * @ingroup Entry
3751  */
3752 EAPI int
3753 elm_entry_cursor_pos_get(const Evas_Object *obj)
3754 {
3755    ELM_CHECK_WIDTYPE(obj, widtype) 0;
3756    Widget_Data *wd = elm_widget_data_get(obj);
3757    if (!wd) return 0;
3758    return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3759 }
3760
3761 /**
3762  * This executes a "cut" action on the selected text in the entry.
3763  *
3764  * @param obj The entry object
3765  *
3766  * @ingroup Entry
3767  */
3768 EAPI void
3769 elm_entry_selection_cut(Evas_Object *obj)
3770 {
3771    ELM_CHECK_WIDTYPE(obj, widtype);
3772    Widget_Data *wd = elm_widget_data_get(obj);
3773    if (!wd) return;
3774    _cut(obj, NULL, NULL);
3775 }
3776
3777 /**
3778  * This executes a "copy" action on the selected text in the entry.
3779  *
3780  * @param obj The entry object
3781  *
3782  * @ingroup Entry
3783  */
3784 EAPI void
3785 elm_entry_selection_copy(Evas_Object *obj)
3786 {
3787    ELM_CHECK_WIDTYPE(obj, widtype);
3788    Widget_Data *wd = elm_widget_data_get(obj);
3789    if (!wd) return;
3790    _copy(obj, NULL, NULL);
3791 }
3792
3793 /**
3794  * This executes a "paste" action in the entry.
3795  *
3796  * @param obj The entry object
3797  *
3798  * @ingroup Entry
3799  */
3800 EAPI void
3801 elm_entry_selection_paste(Evas_Object *obj)
3802 {
3803    ELM_CHECK_WIDTYPE(obj, widtype);
3804    Widget_Data *wd = elm_widget_data_get(obj);
3805    if (!wd) return;
3806    _paste(obj, NULL, NULL);
3807 }
3808
3809 /**
3810  * This clears and frees the items in a entry's contextual (right click) menu.
3811  *
3812  * @param obj The entry object
3813  *
3814  * @ingroup Entry
3815  */
3816 EAPI void
3817 elm_entry_context_menu_clear(Evas_Object *obj)
3818 {
3819    ELM_CHECK_WIDTYPE(obj, widtype);
3820    Widget_Data *wd = elm_widget_data_get(obj);
3821    Elm_Entry_Context_Menu_Item *it;
3822    if (!wd) return;
3823    EINA_LIST_FREE(wd->items, it)
3824      {
3825         eina_stringshare_del(it->label);
3826         eina_stringshare_del(it->icon_file);
3827         eina_stringshare_del(it->icon_group);
3828         free(it);
3829      }
3830 }
3831
3832 /**
3833  * This adds an item to the entry's contextual menu.
3834  *
3835  * @param obj The entry object
3836  * @param label The item's text label
3837  * @param icon_file The item's icon file
3838  * @param icon_type The item's icon type
3839  * @param func The callback to execute when the item is clicked
3840  * @param data The data to associate with the item for related functions
3841  *
3842  * @ingroup Entry
3843  */
3844 EAPI void
3845 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)
3846 {
3847    ELM_CHECK_WIDTYPE(obj, widtype);
3848    Widget_Data *wd = elm_widget_data_get(obj);
3849    Elm_Entry_Context_Menu_Item *it;
3850    if (!wd) return;
3851    it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
3852    if (!it) return;
3853    wd->items = eina_list_append(wd->items, it);
3854    it->obj = obj;
3855    it->label = eina_stringshare_add(label);
3856    it->icon_file = eina_stringshare_add(icon_file);
3857    it->icon_type = icon_type;
3858    it->func = func;
3859    it->data = (void *)data;
3860 }
3861
3862 /**
3863  * This disables the entry's contextual (right click) menu.
3864  *
3865  * @param obj The entry object
3866  * @param disabled If true, the menu is disabled
3867  *
3868  * @ingroup Entry
3869  */
3870 EAPI void
3871 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
3872 {
3873    ELM_CHECK_WIDTYPE(obj, widtype);
3874    Widget_Data *wd = elm_widget_data_get(obj);
3875    if (!wd) return;
3876    if (wd->context_menu == !disabled) return;
3877    wd->context_menu = !disabled;
3878 }
3879
3880 /**
3881  * This returns whether the entry's contextual (right click) menu is disabled.
3882  *
3883  * @param obj The entry object
3884  * @return If true, the menu is disabled
3885  *
3886  * @ingroup Entry
3887  */
3888 EAPI Eina_Bool
3889 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
3890 {
3891    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3892    Widget_Data *wd = elm_widget_data_get(obj);
3893    if (!wd) return EINA_FALSE;
3894    return !wd->context_menu;
3895 }
3896
3897 /**
3898  * This appends a custom item provider to the list for that entry
3899  *
3900  * This appends the given callback. The list is walked from beginning to end
3901  * with each function called given the item href string in the text. If the
3902  * function returns an object handle other than NULL (it should create an
3903  * and object to do this), then this object is used to replace that item. If
3904  * not the next provider is called until one provides an item object, or the
3905  * default provider in entry does.
3906  *
3907  * @param obj The entry object
3908  * @param func The function called to provide the item object
3909  * @param data The data passed to @p func
3910  *
3911  * @ingroup Entry
3912  */
3913 EAPI void
3914 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3915 {
3916    ELM_CHECK_WIDTYPE(obj, widtype);
3917    Widget_Data *wd = elm_widget_data_get(obj);
3918    if (!wd) return;
3919    EINA_SAFETY_ON_NULL_RETURN(func);
3920    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3921    if (!ip) return;
3922    ip->func = func;
3923    ip->data = data;
3924    wd->item_providers = eina_list_append(wd->item_providers, ip);
3925 }
3926
3927 /**
3928  * This prepends a custom item provider to the list for that entry
3929  *
3930  * This prepends the given callback. See elm_entry_item_provider_append() for
3931  * more information
3932  *
3933  * @param obj The entry object
3934  * @param func The function called to provide the item object
3935  * @param data The data passed to @p func
3936  *
3937  * @ingroup Entry
3938  */
3939 EAPI void
3940 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3941 {
3942    ELM_CHECK_WIDTYPE(obj, widtype);
3943    Widget_Data *wd = elm_widget_data_get(obj);
3944    if (!wd) return;
3945    EINA_SAFETY_ON_NULL_RETURN(func);
3946    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3947    if (!ip) return;
3948    ip->func = func;
3949    ip->data = data;
3950    wd->item_providers = eina_list_prepend(wd->item_providers, ip);
3951 }
3952
3953 /**
3954  * This removes a custom item provider to the list for that entry
3955  *
3956  * This removes the given callback. See elm_entry_item_provider_append() for
3957  * more information
3958  *
3959  * @param obj The entry object
3960  * @param func The function called to provide the item object
3961  * @param data The data passed to @p func
3962  *
3963  * @ingroup Entry
3964  */
3965 EAPI void
3966 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3967 {
3968    ELM_CHECK_WIDTYPE(obj, widtype);
3969    Widget_Data *wd = elm_widget_data_get(obj);
3970    Eina_List *l;
3971    Elm_Entry_Item_Provider *ip;
3972    if (!wd) return;
3973    EINA_SAFETY_ON_NULL_RETURN(func);
3974    EINA_LIST_FOREACH(wd->item_providers, l, ip)
3975      {
3976         if ((ip->func == func) && ((!data) || (ip->data == data)))
3977           {
3978              wd->item_providers = eina_list_remove_list(wd->item_providers, l);
3979              free(ip);
3980              return;
3981           }
3982      }
3983 }
3984
3985 /**
3986  * Append a filter function for text inserted in the entry
3987  *
3988  * Append the given callback to the list. This functions will be called
3989  * whenever any text is inserted into the entry, with the text to be inserted
3990  * as a parameter. The callback function is free to alter the text in any way
3991  * it wants, but it must remember to free the given pointer and update it.
3992  * If the new text is to be discarded, the function can free it and set it text
3993  * parameter to NULL. This will also prevent any following filters from being
3994  * called.
3995  *
3996  * @param obj The entry object
3997  * @param func The function to use as text filter
3998  * @param data User data to pass to @p func
3999  *
4000  * @ingroup Entry
4001  */
4002 EAPI void
4003 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
4004 {
4005    Widget_Data *wd;
4006    Elm_Entry_Text_Filter *tf;
4007    ELM_CHECK_WIDTYPE(obj, widtype);
4008
4009    wd = elm_widget_data_get(obj);
4010
4011    EINA_SAFETY_ON_NULL_RETURN(func);
4012
4013    tf = _filter_new(func, data);
4014    if (!tf) return;
4015
4016    wd->text_filters = eina_list_append(wd->text_filters, tf);
4017 }
4018
4019 /**
4020  * Prepend a filter function for text insdrted in the entry
4021  *
4022  * Prepend the given callback to the list. See elm_entry_text_filter_append()
4023  * for more information
4024  *
4025  * @param obj The entry object
4026  * @param func The function to use as text filter
4027  * @param data User data to pass to @p func
4028  *
4029  * @ingroup Entry
4030  */
4031 EAPI void
4032 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
4033 {
4034    Widget_Data *wd;
4035    Elm_Entry_Text_Filter *tf;
4036    ELM_CHECK_WIDTYPE(obj, widtype);
4037
4038    wd = elm_widget_data_get(obj);
4039
4040    EINA_SAFETY_ON_NULL_RETURN(func);
4041
4042    tf = _filter_new(func, data);
4043    if (!tf) return;
4044
4045    wd->text_filters = eina_list_prepend(wd->text_filters, tf);
4046 }
4047
4048 /**
4049  * Remove a filter from the list
4050  *
4051  * Removes the given callback from the filter list. See elm_entry_text_filter_append()
4052  * for more information.
4053  *
4054  * @param obj The entry object
4055  * @param func The filter function to remove
4056  * @param data The user data passed when adding the function
4057  *
4058  * @ingroup Entry
4059  */
4060 EAPI void
4061 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
4062 {
4063    Widget_Data *wd;
4064    Eina_List *l;
4065    Elm_Entry_Text_Filter *tf;
4066    ELM_CHECK_WIDTYPE(obj, widtype);
4067
4068    wd = elm_widget_data_get(obj);
4069
4070    EINA_SAFETY_ON_NULL_RETURN(func);
4071
4072    EINA_LIST_FOREACH(wd->text_filters, l, tf)
4073      {
4074         if ((tf->func == func) && ((!data) || (tf->data == data)))
4075           {
4076              wd->text_filters = eina_list_remove_list(wd->text_filters, l);
4077              _filter_free(tf);
4078              return;
4079           }
4080      }
4081 }
4082
4083 /**
4084  * This converts a markup (HTML-like) string into UTF-8.
4085  * Returning string is obtained with malloc.
4086  * After use the returned string, it should be freed.
4087  *
4088  * @param s The string (in markup) to be converted
4089  * @return The converted string (in UTF-8). It should be freed.
4090  *
4091  * @ingroup Entry
4092  */
4093 EAPI char *
4094 elm_entry_markup_to_utf8(const char *s)
4095 {
4096    char *ss = _elm_util_mkup_to_text(s);
4097    if (!ss) ss = strdup("");
4098    return ss;
4099 }
4100
4101 /**
4102  * This converts a UTF-8 string into markup (HTML-like).
4103  * Returning string is obtained with malloc.
4104  * After use the returned string, it should be freed.
4105  *
4106  * @param s The string (in UTF-8) to be converted
4107  * @return The converted string (in markup). It should be freed.
4108  *
4109  * @ingroup Entry
4110  */
4111 EAPI char *
4112 elm_entry_utf8_to_markup(const char *s)
4113 {
4114    char *ss = _elm_util_text_to_mkup(s);
4115    if (!ss) ss = strdup("");
4116    return ss;
4117 }
4118
4119 /**
4120  * Filter inserted text based on user defined character and byte limits
4121  *
4122  * Add this filter to an entry to limit the characters that it will accept
4123  * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
4124  * The funtion works on the UTF-8 representation of the string, converting
4125  * it from the set markup, thus not accounting for any format in it.
4126  *
4127  * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
4128  * it as data when setting the filter. In it it's possible to set limits
4129  * by character count or bytes (any of them is disabled if 0), and both can
4130  * be set at the same time. In that case, it first checks for characters,
4131  * then bytes.
4132  *
4133  * The function will cut the inserted text in order to allow only the first
4134  * number of characters that are still allowed. The cut is made in
4135  * characters, even when limiting by bytes, in order to always contain
4136  * valid ones and avoid half unicode characters making it in.
4137  *
4138  * @ingroup Entry
4139  */
4140 EAPI void
4141 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
4142 {
4143    Elm_Entry_Filter_Limit_Size *lim = data;
4144    char *current;
4145    int len, newlen;
4146    const char *(*text_get)(const Evas_Object *);
4147    const char *widget_type;
4148
4149    EINA_SAFETY_ON_NULL_RETURN(data);
4150    EINA_SAFETY_ON_NULL_RETURN(entry);
4151    EINA_SAFETY_ON_NULL_RETURN(text);
4152
4153    /* hack. I don't want to copy the entire function to work with
4154     * scrolled_entry */
4155    widget_type = elm_widget_type_get(entry);
4156    if (!strcmp(widget_type, "entry"))
4157      text_get = elm_entry_entry_get;
4158    else /* huh? */
4159      return;
4160
4161    current = elm_entry_markup_to_utf8(text_get(entry));
4162
4163    if (lim->max_char_count > 0)
4164      {
4165         len = evas_string_char_len_get(current);
4166         if (len >= lim->max_char_count)
4167           {
4168              evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
4169              free(*text);
4170              free(current);
4171              *text = NULL;
4172              return;
4173           }
4174         newlen = evas_string_char_len_get(elm_entry_markup_to_utf8(*text));
4175         if ((len + newlen) > lim->max_char_count)
4176           _add_chars_till_limit(entry, text, (lim->max_char_count - len), LENGTH_UNIT_CHAR);
4177      }
4178    else if (lim->max_byte_count > 0)
4179      {
4180         len = strlen(current);
4181         if (len >= lim->max_byte_count)
4182           {
4183              evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
4184              free(*text);
4185              free(current);
4186              *text = NULL;
4187              return;
4188           }
4189         newlen = strlen(elm_entry_markup_to_utf8(*text));
4190         if ((len + newlen) > lim->max_byte_count)
4191           _add_chars_till_limit(entry, text, (lim->max_byte_count - len), LENGTH_UNIT_BYTE);
4192      }
4193    free(current);
4194 }
4195
4196 /**
4197  * Filter inserted text based on accepted or rejected sets of characters
4198  *
4199  * Add this filter to an entry to restrict the set of accepted characters
4200  * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
4201  * This structure contains both accepted and rejected sets, but they are
4202  * mutually exclusive. If accepted is set, it will be used, otherwise it
4203  * goes on to the rejected set.
4204  */
4205 EAPI void
4206 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
4207 {
4208    Elm_Entry_Filter_Accept_Set *as = data;
4209    const char *set;
4210    char *insert;
4211    Eina_Bool goes_in;
4212    int read_idx, last_read_idx = 0, read_char;
4213
4214    EINA_SAFETY_ON_NULL_RETURN(data);
4215    EINA_SAFETY_ON_NULL_RETURN(text);
4216
4217    if ((!as->accepted) && (!as->rejected))
4218      return;
4219
4220    if (as->accepted)
4221      {
4222         set = as->accepted;
4223         goes_in = EINA_TRUE;
4224      }
4225    else
4226      {
4227         set = as->rejected;
4228         goes_in = EINA_FALSE;
4229      }
4230
4231    insert = *text;
4232    read_idx = evas_string_char_next_get(*text, 0, &read_char);
4233    while (read_char)
4234      {
4235         int cmp_idx, cmp_char;
4236         Eina_Bool in_set = EINA_FALSE;
4237
4238         cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
4239         while (cmp_char)
4240           {
4241              if (read_char == cmp_char)
4242                {
4243                   in_set = EINA_TRUE;
4244                   break;
4245                }
4246              cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
4247           }
4248         if (in_set == goes_in)
4249           {
4250              int size = read_idx - last_read_idx;
4251              const char *src = (*text) + last_read_idx;
4252              if (src != insert)
4253                memcpy(insert, *text + last_read_idx, size);
4254              insert += size;
4255           }
4256         last_read_idx = read_idx;
4257         read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
4258      }
4259    *insert = 0;
4260 }
4261
4262 /**
4263  * This sets the file (and implicitly loads it) for the text to display and
4264  * then edit. All changes are written back to the file after a short delay if
4265  * the entry object is set to autosave.
4266  *
4267  * @param obj The entry object
4268  * @param file The path to the file to load and save
4269  * @param format The file format
4270  *
4271  * @ingroup Entry
4272  */
4273 EAPI void
4274 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
4275 {
4276    ELM_CHECK_WIDTYPE(obj, widtype);
4277    Widget_Data *wd = elm_widget_data_get(obj);
4278    if (!wd) return;
4279    if (wd->delay_write)
4280      {
4281         ecore_timer_del(wd->delay_write);
4282         wd->delay_write = NULL;
4283      }
4284    if (wd->autosave) _save(obj);
4285    eina_stringshare_replace(&wd->file, file);
4286    wd->format = format;
4287    _load(obj);
4288 }
4289
4290 /**
4291  * Gets the file to load and save and the file format
4292  *
4293  * @param obj The entry object
4294  * @param file The path to the file to load and save
4295  * @param format The file format
4296  *
4297  * @ingroup Entry
4298  */
4299 EAPI void
4300 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
4301 {
4302    ELM_CHECK_WIDTYPE(obj, widtype);
4303    Widget_Data *wd = elm_widget_data_get(obj);
4304    if (!wd) return;
4305    if (file) *file = wd->file;
4306    if (format) *format = wd->format;
4307 }
4308
4309 /**
4310  * This function writes any changes made to the file set with
4311  * elm_entry_file_set()
4312  *
4313  * @param obj The entry object
4314  *
4315  * @ingroup Entry
4316  */
4317 EAPI void
4318 elm_entry_file_save(Evas_Object *obj)
4319 {
4320    ELM_CHECK_WIDTYPE(obj, widtype);
4321    Widget_Data *wd = elm_widget_data_get(obj);
4322    if (!wd) return;
4323    if (wd->delay_write)
4324      {
4325         ecore_timer_del(wd->delay_write);
4326         wd->delay_write = NULL;
4327      }
4328    _save(obj);
4329    wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
4330 }
4331
4332 /**
4333  * This sets the entry object to 'autosave' the loaded text file or not.
4334  *
4335  * @param obj The entry object
4336  * @param autosave Autosave the loaded file or not
4337  *
4338  * @ingroup Entry
4339  */
4340 EAPI void
4341 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
4342 {
4343    ELM_CHECK_WIDTYPE(obj, widtype);
4344    Widget_Data *wd = elm_widget_data_get(obj);
4345    if (!wd) return;
4346    wd->autosave = !!autosave;
4347 }
4348
4349 /**
4350  * This gets the entry object's 'autosave' status.
4351  *
4352  * @param obj The entry object
4353  * @return Autosave the loaded file or not
4354  *
4355  * @ingroup Entry
4356  */
4357 EAPI Eina_Bool
4358 elm_entry_autosave_get(const Evas_Object *obj)
4359 {
4360    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4361    Widget_Data *wd = elm_widget_data_get(obj);
4362    if (!wd) return EINA_FALSE;
4363    return wd->autosave;
4364 }
4365
4366 /**
4367  * Control pasting of text and images for the widget.
4368  *
4369  * Normally the entry allows both text and images to be pasted.  By setting
4370  * textonly to be true, this prevents images from being pasted.
4371  *
4372  * Note this only changes the behaviour of text.
4373  *
4374  * @param obj The entry object
4375  * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is text+image+other.
4376  *
4377  * @ingroup Entry
4378  */
4379 EAPI void
4380 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
4381 {
4382    Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
4383    ELM_CHECK_WIDTYPE(obj, widtype);
4384    Widget_Data *wd = elm_widget_data_get(obj);
4385    if (!wd) return;
4386    textonly = !!textonly;
4387    if (wd->textonly == textonly) return;
4388    wd->textonly = !!textonly;
4389    if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
4390 #ifdef HAVE_ELEMENTARY_X
4391    elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
4392 #endif
4393 }
4394
4395 /**
4396  * Getting elm_entry text paste/drop mode.
4397  *
4398  * In textonly mode, only text may be pasted or dropped into the widget.
4399  *
4400  * @param obj The entry object
4401  * @return If the widget only accepts text from pastes.
4402  *
4403  * @ingroup Entry
4404  */
4405 EAPI Eina_Bool
4406 elm_entry_cnp_textonly_get(const Evas_Object *obj)
4407 {
4408    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4409    Widget_Data *wd = elm_widget_data_get(obj);
4410    if (!wd) return EINA_FALSE;
4411    return wd->textonly;
4412 }
4413
4414 /**
4415  * Enable or disable scrolling in entry
4416  *
4417  * Normally the entry is not scrollable unless you enable it with this call.
4418  *
4419  * @param obj The entry object
4420  * @param scroll EINA_TRUE if it is to be scrollable, EINA_FALSE otherwise
4421  *
4422  * @ingroup Entry
4423  */
4424 EAPI void
4425 elm_entry_scrollable_set(Evas_Object *obj, Eina_Bool scroll)
4426 {
4427    ELM_CHECK_WIDTYPE(obj, widtype);
4428    Widget_Data *wd = elm_widget_data_get(obj);
4429    if (!wd) return;
4430    scroll = !!scroll;
4431    if (wd->scroll == scroll) return;
4432    wd->scroll = scroll;
4433    if (wd->scroll)
4434      {
4435         elm_widget_sub_object_del(obj, wd->scroller);
4436         elm_widget_resize_object_set(obj, wd->scroller);
4437         elm_widget_sub_object_add(obj, wd->ent);
4438         elm_smart_scroller_child_set(wd->scroller, wd->ent);
4439         evas_object_show(wd->scroller);
4440         elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
4441         if (wd->single_line)
4442           {
4443              elm_smart_scroller_policy_set(wd->scroller,
4444                                            ELM_SMART_SCROLLER_POLICY_OFF,
4445                                            ELM_SMART_SCROLLER_POLICY_OFF);
4446              elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
4447           }
4448         else
4449           {
4450              const Elm_Scroller_Policy map[3] =
4451                {
4452                   ELM_SMART_SCROLLER_POLICY_AUTO,
4453                   ELM_SMART_SCROLLER_POLICY_ON,
4454                   ELM_SMART_SCROLLER_POLICY_OFF
4455                };
4456              elm_smart_scroller_policy_set(wd->scroller,
4457                                            map[wd->policy_h],
4458                                            map[wd->policy_v]);
4459              elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
4460           }
4461      }
4462    else
4463      {
4464         elm_smart_scroller_child_set(wd->scroller, NULL);
4465         elm_widget_sub_object_del(obj, wd->ent);
4466         elm_widget_resize_object_set(obj, wd->ent);
4467         evas_object_smart_member_add(wd->scroller, obj);
4468         elm_widget_sub_object_add(obj, wd->scroller);
4469         evas_object_hide(wd->scroller);
4470         elm_widget_on_show_region_hook_set(obj, NULL, NULL);
4471      }
4472    wd->lastw = -1;
4473    _theme_hook(obj);
4474 }
4475
4476 /**
4477  * Get the scrollable state of the entry
4478  *
4479  * Normally the entry is not scrollable. This gets the scrollable state
4480  * of the entry. See elm_entry_scrollable_set() for more information.
4481  *
4482  * @param obj The entry object
4483  * @return The scrollable state
4484  *
4485  * @ingroup Entry
4486  */
4487 EAPI Eina_Bool
4488 elm_entry_scrollable_get(const Evas_Object *obj)
4489 {
4490    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4491    Widget_Data *wd = elm_widget_data_get(obj);
4492    if (!wd) return EINA_FALSE;
4493    return wd->scroll;
4494 }
4495
4496 /**
4497  * This sets a widget to be displayed to the left of a scrolled entry.
4498  *
4499  * @param obj The scrolled entry object
4500  * @param icon The widget to display on the left side of the scrolled
4501  * entry.
4502  *
4503  * @note A previously set widget will be destroyed.
4504  * @note If the object being set does not have minimum size hints set,
4505  * it won't get properly displayed.
4506  *
4507  * @ingroup Entry
4508  * @see elm_entry_end_set
4509  */
4510 EAPI void
4511 elm_entry_icon_set(Evas_Object *obj, Evas_Object *icon)
4512 {
4513    ELM_CHECK_WIDTYPE(obj, widtype);
4514    Widget_Data *wd = elm_widget_data_get(obj);
4515    Evas_Object *edje;
4516    if (!wd) return;
4517    EINA_SAFETY_ON_NULL_RETURN(icon);
4518    if (wd->icon == icon) return;
4519    if (wd->icon) evas_object_del(wd->icon);
4520    wd->icon = icon;
4521    edje = elm_smart_scroller_edje_object_get(wd->scroller);
4522    if (!edje) return;
4523    edje_object_part_swallow(edje, "elm.swallow.icon", wd->icon);
4524    edje_object_signal_emit(edje, "elm,action,show,icon", "elm");
4525    _sizing_eval(obj);
4526 }
4527
4528 /**
4529  * Gets the leftmost widget of the scrolled entry. This object is
4530  * owned by the scrolled entry and should not be modified.
4531  *
4532  * @param obj The scrolled entry object
4533  * @return the left widget inside the scroller
4534  *
4535  * @ingroup Entry
4536  */
4537 EAPI Evas_Object *
4538 elm_entry_icon_get(const Evas_Object *obj)
4539 {
4540    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4541    Widget_Data *wd = elm_widget_data_get(obj);
4542    if (!wd) return NULL;
4543    return wd->icon;
4544 }
4545
4546 /**
4547  * Unset the leftmost widget of the scrolled entry, unparenting and
4548  * returning it.
4549  *
4550  * @param obj The scrolled entry object
4551  * @return the previously set icon sub-object of this entry, on
4552  * success.
4553  *
4554  * @see elm_entry_icon_set()
4555  *
4556  * @ingroup Entry
4557  */
4558 EAPI Evas_Object *
4559 elm_entry_icon_unset(Evas_Object *obj)
4560 {
4561    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4562    Widget_Data *wd = elm_widget_data_get(obj);
4563    Evas_Object *ret = NULL;
4564    if (!wd) return NULL;
4565    if (wd->icon)
4566      {
4567         Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
4568         if (!edje) return NULL;
4569         ret = wd->icon;
4570         edje_object_part_unswallow(edje, wd->icon);
4571         edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
4572         wd->icon = NULL;
4573         _sizing_eval(obj);
4574      }
4575    return ret;
4576 }
4577
4578 /**
4579  * Sets the visibility of the left-side widget of the scrolled entry,
4580  * set by @elm_entry_icon_set().
4581  *
4582  * @param obj The scrolled entry object
4583  * @param setting EINA_TRUE if the object should be displayed,
4584  * EINA_FALSE if not.
4585  *
4586  * @ingroup Entry
4587  */
4588 EAPI void
4589 elm_entry_icon_visible_set(Evas_Object *obj, Eina_Bool setting)
4590 {
4591    ELM_CHECK_WIDTYPE(obj, widtype);
4592    Widget_Data *wd = elm_widget_data_get(obj);
4593    if ((!wd) || (!wd->icon)) return;
4594    if (setting)
4595       evas_object_hide(wd->icon);
4596    else
4597       evas_object_show(wd->icon);
4598    _sizing_eval(obj);
4599 }
4600
4601 /**
4602  * This sets a widget to be displayed to the end of a scrolled entry.
4603  *
4604  * @param obj The scrolled entry object
4605  * @param end The widget to display on the right side of the scrolled
4606  * entry.
4607  *
4608  * @note A previously set widget will be destroyed.
4609  * @note If the object being set does not have minimum size hints set,
4610  * it won't get properly displayed.
4611  *
4612  * @ingroup Entry
4613  * @see elm_entry_icon_set
4614  */
4615 EAPI void
4616 elm_entry_end_set(Evas_Object *obj, Evas_Object *end)
4617 {
4618    ELM_CHECK_WIDTYPE(obj, widtype);
4619    Widget_Data *wd = elm_widget_data_get(obj);
4620    Evas_Object *edje;
4621    if (!wd) return;
4622    EINA_SAFETY_ON_NULL_RETURN(end);
4623    if (wd->end == end) return;
4624    if (wd->end) evas_object_del(wd->end);
4625    wd->end = end;
4626    edje = elm_smart_scroller_edje_object_get(wd->scroller);
4627    if (!edje) return;
4628    edje_object_part_swallow(edje, "elm.swallow.end", wd->end);
4629    edje_object_signal_emit(edje, "elm,action,show,end", "elm");
4630    _sizing_eval(obj);
4631 }
4632
4633 /**
4634  * Gets the endmost widget of the scrolled entry. This object is owned
4635  * by the scrolled entry and should not be modified.
4636  *
4637  * @param obj The scrolled entry object
4638  * @return the right widget inside the scroller
4639  *
4640  * @ingroup Entry
4641  */
4642 EAPI Evas_Object *
4643 elm_entry_end_get(const Evas_Object *obj)
4644 {
4645    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4646    Widget_Data *wd = elm_widget_data_get(obj);
4647    if (!wd) return NULL;
4648    return wd->end;
4649 }
4650
4651 /**
4652  * Unset the endmost widget of the scrolled entry, unparenting and
4653  * returning it.
4654  *
4655  * @param obj The scrolled entry object
4656  * @return the previously set icon sub-object of this entry, on
4657  * success.
4658  *
4659  * @see elm_entry_icon_set()
4660  *
4661  * @ingroup Entry
4662  */
4663 EAPI Evas_Object *
4664 elm_entry_end_unset(Evas_Object *obj)
4665 {
4666    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4667    Widget_Data *wd = elm_widget_data_get(obj);
4668    Evas_Object *ret = NULL;
4669    if (!wd) return NULL;
4670    if (wd->end)
4671      {
4672         Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
4673         if (!edje) return NULL;
4674         ret = wd->end;
4675         edje_object_part_unswallow(edje, wd->end);
4676         edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
4677         wd->end = NULL;
4678         _sizing_eval(obj);
4679      }
4680    return ret;
4681 }
4682
4683 /**
4684  * Sets the visibility of the end widget of the scrolled entry, set by
4685  * @elm_entry_end_set().
4686  *
4687  * @param obj The scrolled entry object
4688  * @param setting EINA_TRUE if the object should be displayed,
4689  * EINA_FALSE if not.
4690  *
4691  * @ingroup Entry
4692  */
4693 EAPI void
4694 elm_entry_end_visible_set(Evas_Object *obj, Eina_Bool setting)
4695 {
4696    ELM_CHECK_WIDTYPE(obj, widtype);
4697    Widget_Data *wd = elm_widget_data_get(obj);
4698    if ((!wd) || (!wd->end)) return;
4699    if (setting)
4700       evas_object_hide(wd->end);
4701    else
4702       evas_object_show(wd->end);
4703    _sizing_eval(obj);
4704 }
4705
4706 /**
4707  * This sets the scrolled entry's scrollbar policy (ie. enabling/disabling them).
4708  *
4709  * @param obj The scrolled entry object
4710  * @param h The horizontal scrollbar policy to apply
4711  * @param v The vertical scrollbar policy to apply
4712  *
4713  * @ingroup Entry
4714  */
4715 EAPI void
4716 elm_entry_scrollbar_policy_set(Evas_Object *obj, Elm_Scroller_Policy h, Elm_Scroller_Policy v)
4717 {
4718    ELM_CHECK_WIDTYPE(obj, widtype);
4719    Widget_Data *wd = elm_widget_data_get(obj);
4720    const Elm_Scroller_Policy map[3] =
4721      {
4722         ELM_SMART_SCROLLER_POLICY_AUTO,
4723         ELM_SMART_SCROLLER_POLICY_ON,
4724         ELM_SMART_SCROLLER_POLICY_OFF
4725      };
4726    if (!wd) return;
4727    wd->policy_h = h;
4728    wd->policy_v = v;
4729    elm_smart_scroller_policy_set(wd->scroller,
4730                                  map[wd->policy_h],
4731                                  map[wd->policy_v]);
4732 }
4733
4734 /**
4735  * This enables/disables bouncing within the entry.
4736  *
4737  * @param obj The scrolled entry object
4738  * @param h The horizontal bounce state
4739  * @param v The vertical bounce state
4740  *
4741  * @ingroup Entry
4742  */
4743 EAPI void
4744 elm_entry_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
4745 {
4746    ELM_CHECK_WIDTYPE(obj, widtype);
4747    Widget_Data *wd = elm_widget_data_get(obj);
4748    if (!wd) return;
4749    elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
4750 }
4751
4752 /**
4753  * Get the bounce mode
4754  *
4755  * @param obj The Entry object
4756  * @param h_bounce Allow bounce horizontally
4757  * @param v_bounce Allow bounce vertically
4758  *
4759  * @ingroup Entry
4760  */
4761 EAPI void
4762 elm_entry_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
4763 {
4764    ELM_CHECK_WIDTYPE(obj, widtype);
4765    Widget_Data *wd = elm_widget_data_get(obj);
4766    if (!wd) return;
4767    elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);
4768 }
4769
4770 EINA_DEPRECATED EAPI void
4771 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
4772 {
4773    if (wrap) elm_entry_line_wrap_set(obj, ELM_WRAP_CHAR);
4774 }
4775
4776 /**
4777  * Set background color of the entry
4778  *
4779  * @param obj The entry object
4780  * @param r Red property background color of The entry object
4781  * @param g Green property background color of The entry object
4782  * @param b Blue property background color of The entry object
4783  * @param a Alpha property background alpha of The entry object
4784  * @ingroup Entry
4785  */
4786 EAPI void
4787 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
4788 {
4789    ELM_CHECK_WIDTYPE(obj, widtype);
4790    Widget_Data *wd = elm_widget_data_get(obj);
4791    evas_object_color_set(wd->bg, r, g, b, a);
4792
4793    if (wd->bgcolor == EINA_FALSE)
4794      {
4795        wd->bgcolor = 1;
4796        edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
4797      }
4798 }
4799
4800 /**
4801  * Set whether entry should support auto capitalization
4802  *
4803  * @param obj The entry object
4804  * @param on If true, entry suports auto capitalization.
4805  *
4806  * @ingroup Entry
4807  */
4808 EAPI void
4809 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
4810 {
4811    ELM_CHECK_WIDTYPE(obj, widtype);
4812    Widget_Data *wd = elm_widget_data_get(obj);
4813    if (!wd) return;
4814
4815    if (wd->password)
4816      wd->autocapital = EINA_FALSE;
4817    else
4818      wd->autocapital = autocap;
4819
4820    if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
4821        wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
4822      wd->autocapital = EINA_FALSE;
4823
4824    edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
4825 }
4826
4827 /**
4828  * Set whether entry should support auto period
4829  *
4830  * @param obj The entry object
4831  * @param on If true, entry suports auto period.
4832  *
4833  * @ingroup Entry
4834  */
4835 EAPI void
4836 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
4837 {
4838    ELM_CHECK_WIDTYPE(obj, widtype);
4839    Widget_Data *wd = elm_widget_data_get(obj);
4840    if (!wd) return;
4841
4842    if (wd->password)
4843      wd->autoperiod = EINA_FALSE;
4844    else
4845      wd->autoperiod = autoperiod;
4846
4847    if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
4848        wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
4849      wd->autoperiod = EINA_FALSE;
4850
4851    edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
4852 }
4853
4854 /**
4855  * Set whether entry should enable the return key on soft keyboard automatically
4856  *
4857  * @param obj The entry object
4858  * @param on If true, entry enables the return key on soft keyboard automatically.
4859  *
4860  * @ingroup Entry
4861  */
4862 EAPI void
4863 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
4864 {
4865    ELM_CHECK_WIDTYPE(obj, widtype);
4866    Widget_Data *wd = elm_widget_data_get(obj);
4867    if (!wd) return;
4868
4869    wd->autoreturnkey = on;
4870    _check_enable_returnkey(obj);
4871 }
4872
4873 /**
4874  * This sets the attribute to show the input panel automatically.
4875  *
4876  * @param obj The entry object
4877  * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
4878  *
4879  * @ingroup Entry
4880  */
4881 EAPI void
4882 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
4883 {
4884    ELM_CHECK_WIDTYPE(obj, widtype);
4885    Widget_Data *wd = elm_widget_data_get(obj);
4886    if (!wd) return;
4887
4888    wd->input_panel_enable = enabled;
4889    edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
4890 }
4891
4892 /**
4893  * Set the input panel layout of the entry
4894  *
4895  * @param obj The entry object
4896  * @param layout the layout to set
4897  *
4898  * @ingroup Entry
4899  */
4900 EAPI void
4901 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
4902 {
4903    ELM_CHECK_WIDTYPE(obj, widtype);
4904    Widget_Data *wd = elm_widget_data_get(obj);
4905    if (!wd) return;
4906
4907    Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
4908    if (!ic) return;
4909
4910    wd->input_panel_layout = layout;
4911
4912    ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
4913 }
4914
4915 /**
4916  * Get the input method context in the entry widget
4917  *
4918  * @param obj The entry object
4919  * @return The input method context
4920  *
4921  * @ingroup Entry
4922  */
4923 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
4924 {
4925    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
4926    Widget_Data *wd = elm_widget_data_get(obj);
4927    if (!wd || !wd->ent) return NULL;
4928
4929    return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
4930 }
4931
4932 EAPI void
4933 elm_entry_matchlist_set(Evas_Object *obj, Eina_List *match_list, Eina_Bool case_sensitive)
4934 {
4935    Widget_Data *wd = elm_widget_data_get(obj);
4936    if (!wd) return;
4937
4938    if (match_list)
4939      {
4940         Evas_Coord max_w = 9999, max_h = 9999;
4941         const char* key_data = NULL;
4942
4943         wd->matchlist_threshold = 1;
4944         wd->hover = elm_hover_add(elm_widget_parent_get(obj));
4945         elm_hover_parent_set(wd->hover, elm_widget_parent_get(obj));
4946         elm_hover_target_set(wd->hover, obj);
4947         elm_object_style_set(wd->hover, "matchlist");
4948
4949         wd->layout = elm_layout_add(wd->hover);
4950         elm_layout_theme_set(wd->layout, "entry", "matchlist", "default");
4951         wd->list = elm_list_add(wd->layout);
4952         evas_object_size_hint_weight_set(wd->list, EVAS_HINT_EXPAND, 0.0);
4953         evas_object_size_hint_align_set(wd->list, EVAS_HINT_FILL, EVAS_HINT_FILL);
4954         elm_list_mode_set(wd->list, ELM_LIST_EXPAND);
4955         elm_object_style_set(wd->list, "matchlist");
4956
4957         key_data = edje_object_data_get(elm_layout_edje_get(wd->layout), "max_width");
4958         if (key_data) max_w = atoi(key_data);
4959         key_data = edje_object_data_get(elm_layout_edje_get(wd->layout), "max_height");
4960         if (key_data) max_h = atoi(key_data);
4961
4962         elm_list_go(wd->list);
4963         evas_object_size_hint_max_set(wd->list, max_w, max_h);
4964         evas_object_smart_callback_add(wd->list, "selected", _matchlist_list_clicked, obj);
4965         elm_layout_content_set(wd->layout, "elm.swallow.content", wd->list);
4966         elm_hover_content_set(wd->hover, "bottom", wd->layout);
4967
4968         wd->match_list = match_list;
4969      }
4970    else
4971      {
4972         if (wd->hover)
4973           evas_object_del(wd->hover);
4974
4975         wd->match_list = NULL;
4976      }
4977
4978    wd->matchlist_case_sensitive = case_sensitive;
4979 }
4980
4981 /**
4982  * Set the magnifier style of the entry
4983  *
4984  * @param obj The entry object
4985  * @param type the magnifier style to set
4986  *
4987  * @ingroup Entry
4988  */
4989 EAPI void
4990 elm_entry_magnifier_type_set(Evas_Object *obj, int type)
4991 {
4992    ELM_CHECK_WIDTYPE(obj, widtype);
4993    Widget_Data *wd = elm_widget_data_get(obj);
4994    if (!wd) return;
4995
4996    wd->mgf_type = type;
4997    _magnifier_create(obj);
4998 }
4999
5000 /**
5001  * Set wrap width of the entry
5002  *
5003  * @param obj The entry object
5004  * @param w The wrap width in pixels at a minimum where words need to wrap
5005  * @ingroup Entry
5006  */
5007 EAPI void
5008 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
5009 {
5010    Widget_Data *wd = elm_widget_data_get(obj);
5011    if (!wd) return;
5012    if (wd->wrap_w == w) return;
5013    wd->wrap_w = w;
5014    _sizing_eval(obj);
5015 }
5016
5017 /**
5018  * get wrap width of the entry
5019  *
5020  * @param obj The entry object
5021  * @return The wrap width in pixels at a minimum where words need to wrap
5022  * @ingroup Entry
5023  */
5024 EAPI Evas_Coord
5025 elm_entry_wrap_width_get(const Evas_Object *obj)
5026 {
5027    Widget_Data *wd = elm_widget_data_get(obj);
5028    if (!wd) return;
5029    return wd->wrap_w;
5030 }
5031
5032 /**
5033  * Set the font size on the entry object
5034  *
5035  * @param obj The entry object
5036  * @param size font size
5037  *
5038  * @ingroup Entry
5039  */
5040 EAPI void
5041 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
5042 {
5043    ELM_CHECK_WIDTYPE(obj, widtype);
5044    Widget_Data *wd = elm_widget_data_get(obj);
5045    Eina_Strbuf *fontbuf = NULL;
5046    int removeflag = 0;
5047    const char *t;
5048
5049    if (!wd) return;
5050    t = eina_stringshare_add(elm_entry_entry_get(obj));
5051    fontbuf = eina_strbuf_new();
5052    eina_strbuf_append_printf(fontbuf, "%d", fontsize);
5053
5054    if (fontsize == 0) removeflag = 1; // remove fontsize tag
5055
5056    if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
5057      {
5058        elm_entry_entry_set(obj, t);
5059        wd->changed = 1;
5060        _sizing_eval(obj);
5061      }
5062    eina_strbuf_free(fontbuf);
5063    eina_stringshare_del(t);
5064 }
5065
5066 /**
5067  * Set the text color on the entry object
5068  *
5069  * @param obj The entry object
5070  * @param r Red property background color of The entry object
5071  * @param g Green property background color of The entry object
5072  * @param b Blue property background color of The entry object
5073  * @param a Alpha property background alpha of The entry object
5074  *
5075  * @ingroup Entry
5076  */
5077 EAPI void
5078 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
5079 {
5080    ELM_CHECK_WIDTYPE(obj, widtype);
5081    Widget_Data *wd = elm_widget_data_get(obj);
5082    Eina_Strbuf *colorbuf = NULL;
5083    const char *t;
5084    int len;
5085
5086    if (!wd) return;
5087    t = eina_stringshare_add(elm_entry_entry_get(obj));
5088    len = strlen(t);
5089    if (len <= 0) return;
5090    colorbuf = eina_strbuf_new();
5091    eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
5092
5093    if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
5094      {
5095        elm_entry_entry_set(obj, t);
5096        wd->changed = 1;
5097        _sizing_eval(obj);
5098      }
5099    eina_strbuf_free(colorbuf);
5100    eina_stringshare_del(t);
5101 }
5102
5103 /**
5104  * Set the text align on the entry object
5105  *
5106  * @param obj The entry object
5107  * @param align align mode
5108  *
5109  * @ingroup Entry
5110  */
5111 EAPI void
5112 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
5113 {
5114    ELM_CHECK_WIDTYPE(obj, widtype);
5115    Widget_Data *wd = elm_widget_data_get(obj);
5116    int len;
5117    const char *t;
5118
5119    if (!wd) return;
5120    t = eina_stringshare_add(elm_entry_entry_get(obj));
5121    len = strlen(t);
5122    if (len <= 0) return;
5123
5124    if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
5125      elm_entry_entry_set(obj, t);
5126
5127    wd->changed = 1;
5128    _sizing_eval(obj);
5129    eina_stringshare_del(t);
5130 }