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