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