Merge "[Password]: New design based changes, a new style removed password mode contro...
[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  */
96
97 typedef struct _Mod_Api Mod_Api;
98
99 typedef struct _Widget_Data Widget_Data;
100 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
101 typedef struct _Elm_Entry_Item_Provider Elm_Entry_Item_Provider;
102 typedef struct _Elm_Entry_Text_Filter Elm_Entry_Text_Filter;
103
104 struct _Widget_Data
105 {
106    Evas_Object *ent;
107    Evas_Object *bg;
108    Evas_Object *hoversel;
109    Evas_Object *hover;
110    Evas_Object *layout;
111    Evas_Object *list;
112    Evas_Object *mgf_proxy;
113    Evas_Object *mgf_clip;
114    Evas_Object *mgf_bg;
115    Evas_Coord mgf_height;
116    float mgf_scale;
117    int mgf_type;
118    Ecore_Job *deferred_recalc_job;
119    Ecore_Event_Handler *sel_notify_handler;
120    Ecore_Event_Handler *sel_clear_handler;
121    Ecore_Timer *longpress_timer;
122    Ecore_Timer *delay_write;
123    /* Only for clipboard */
124    const char *cut_sel;
125    const char *text;
126    Evas_Coord wrap_w;
127    const char *file;
128    Elm_Text_Format format;
129    Evas_Coord lastw;
130    Evas_Coord downx, downy;
131    Evas_Coord cx, cy, cw, ch;
132    Eina_List *items;
133    Eina_List *item_providers;
134    Eina_List *text_filters;
135    Eina_List *match_list;
136    Ecore_Job *matchlist_job;
137    Ecore_Job *hovdeljob;
138    Mod_Api *api; // module api if supplied
139    int cursor_pos;
140    int max_no_of_bytes;
141    Eina_Bool changed : 1;
142    Eina_Bool linewrap : 1;
143    Eina_Bool char_linewrap : 1;
144    Eina_Bool single_line : 1;
145    Eina_Bool password : 1;
146    Eina_Bool editable : 1;
147    Eina_Bool selection_asked : 1;
148    Eina_Bool have_selection : 1;
149    Eina_Bool selmode : 1;
150    Eina_Bool deferred_cur : 1;
151    Eina_Bool disabled : 1;
152    Eina_Bool double_clicked : 1;
153    Eina_Bool long_pressed : 1;
154    Eina_Bool context_menu : 1;
155    Eina_Bool drag_selection_asked : 1;
156    Eina_Bool bgcolor : 1;
157    Eina_Bool can_write : 1;
158    Eina_Bool autosave : 1;
159    Eina_Bool textonly : 1;
160    Eina_Bool usedown : 1;
161    Eina_Bool autoreturnkey : 1;
162    Eina_Bool input_panel_enable : 1;
163    Eina_Bool autocapital : 1;
164    Elm_Input_Panel_Layout input_panel_layout;
165    Eina_Bool autoperiod : 1;
166    Eina_Bool matchlist_list_clicked : 1;
167    Eina_Bool matchlist_case_sensitive : 1;
168    int matchlist_threshold;
169 };
170
171 struct _Elm_Entry_Context_Menu_Item
172 {
173    Evas_Object *obj;
174    const char *label;
175    const char *icon_file;
176    const char *icon_group;
177    Elm_Icon_Type icon_type;
178    Evas_Smart_Cb func;
179    void *data;
180 };
181
182 struct _Elm_Entry_Item_Provider
183 {
184    Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
185    void *data;
186 };
187
188 struct _Elm_Entry_Text_Filter
189 {
190    void (*func) (void *data, Evas_Object *entry, char **text);
191    void *data;
192 };
193
194 typedef enum _Length_Unit
195 {
196    LENGTH_UNIT_CHAR,
197    LENGTH_UNIT_BYTE,
198    LENGTH_UNIT_LAST
199 } Length_Unit;
200
201 static const char *widtype = NULL;
202 // start for cbhm
203 static Evas_Object *cnpwidgetdata = NULL;
204 // end for cbhm
205
206 #ifdef HAVE_ELEMENTARY_X
207 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
208 #endif
209 static void _del_hook(Evas_Object *obj);
210 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
211 static void _theme_hook(Evas_Object *obj);
212 static void _disable_hook(Evas_Object *obj);
213 static void _sizing_eval(Evas_Object *obj);
214 static void _on_focus_hook(void *data, Evas_Object *obj);
215 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
216 static const char *_getbase(Evas_Object *obj);
217 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
218 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
219 static void _signal_selection_end(void *data, Evas_Object *obj, const char *emission, const char *source);
220 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
221 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
222 static void _signal_handler_move_start(void *data, Evas_Object *obj, const char *emission, const char *source);
223 static void _signal_handler_move_end(void *data, Evas_Object *obj, const char *emission, const char *source);
224 static void _signal_handler_moving(void *data, Evas_Object *obj, const char *emission, const char *source);
225 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
226 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
227 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
228 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
229 static void _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit);
230 static int _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag);
231 static int _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag);
232 static int _entry_length_get(Evas_Object *obj);
233 static void _magnifier_create(void *data);
234 static void _magnifier_show(void *data);
235 static void _magnifier_hide(void *data);
236 static void _magnifier_move(void *data);
237
238 static const char SIG_CHANGED[] = "changed";
239 static const char SIG_ACTIVATED[] = "activated";
240 static const char SIG_PRESS[] = "press";
241 static const char SIG_LONGPRESSED[] = "longpressed";
242 static const char SIG_CLICKED[] = "clicked";
243 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
244 static const char SIG_FOCUSED[] = "focused";
245 static const char SIG_UNFOCUSED[] = "unfocused";
246 static const char SIG_SELECTION_PASTE[] = "selection,paste";
247 static const char SIG_SELECTION_COPY[] = "selection,copy";
248 static const char SIG_SELECTION_CUT[] = "selection,cut";
249 static const char SIG_SELECTION_START[] = "selection,start";
250 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
251 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
252 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
253 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
254 static const char SIG_MATCHLIST_CLICKED[] = "matchlist,clicked";
255 static const Evas_Smart_Cb_Description _signals[] = {
256   {SIG_CHANGED, ""},
257   {SIG_ACTIVATED, ""},
258   {SIG_PRESS, ""},
259   {SIG_LONGPRESSED, ""},
260   {SIG_CLICKED, ""},
261   {SIG_CLICKED_DOUBLE, ""},
262   {SIG_FOCUSED, ""},
263   {SIG_UNFOCUSED, ""},
264   {SIG_SELECTION_PASTE, ""},
265   {SIG_SELECTION_COPY, ""},
266   {SIG_SELECTION_CUT, ""},
267   {SIG_SELECTION_START, ""},
268   {SIG_SELECTION_CHANGED, ""},
269   {SIG_SELECTION_CLEARED, ""},
270   {SIG_CURSOR_CHANGED, ""},
271   {SIG_ANCHOR_CLICKED, ""},
272   {SIG_MATCHLIST_CLICKED, ""},
273   {NULL, NULL}
274 };
275
276 typedef enum _Elm_Entry_Magnifier_Type
277 {
278    _ENTRY_MAGNIFIER_FIXEDSIZE = 0,
279    _ENTRY_MAGNIFIER_FILLWIDTH,
280    _ENTRY_MAGNIFIER_CIRCULAR,
281 } Elm_Entry_Magnifier_Type;
282
283
284 static Eina_List *entries = NULL;
285
286 struct _Mod_Api
287 {
288    void (*obj_hook) (Evas_Object *obj);
289    void (*obj_unhook) (Evas_Object *obj);
290    void (*obj_longpress) (Evas_Object *obj);
291    void (*obj_hidemenu) (Evas_Object *obj);
292    void (*obj_mouseup) (Evas_Object *obj);
293 };
294
295 static Mod_Api *
296 _module(Evas_Object *obj __UNUSED__)
297 {
298    static Elm_Module *m = NULL;
299    if (m) goto ok; // already found - just use
300    if (!(m = _elm_module_find_as("entry/api"))) return NULL;
301    // get module api
302    m->api = malloc(sizeof(Mod_Api));
303    if (!m->api) return NULL;
304    ((Mod_Api *)(m->api)      )->obj_hook = // called on creation
305       _elm_module_symbol_get(m, "obj_hook");
306    ((Mod_Api *)(m->api)      )->obj_unhook = // called on deletion
307       _elm_module_symbol_get(m, "obj_unhook");
308    ((Mod_Api *)(m->api)      )->obj_longpress = // called on long press menu
309       _elm_module_symbol_get(m, "obj_longpress");
310    ((Mod_Api *)(m->api)      )->obj_hidemenu = // called on hide menu
311       _elm_module_symbol_get(m, "obj_hidemenu");
312    ((Mod_Api *)(m->api)      )->obj_mouseup = // called on mouseup
313       _elm_module_symbol_get(m, "obj_mouseup");
314 ok: // ok - return api
315    return m->api;
316 }
317
318 static char *
319 _buf_append(char *buf, const char *str, int *len, int *alloc)
320 {
321    int len2 = strlen(str);
322    if ((*len + len2) >= *alloc)
323      {
324         char *buf2 = realloc(buf, *alloc + len2 + 512);
325         if (!buf2) return NULL;
326         buf = buf2;
327         *alloc += (512 + len2);
328      }
329    strcpy(buf + *len, str);
330    *len += len2;
331    return buf;
332 }
333
334 static char *
335 _load_file(const char *file)
336 {
337    FILE *f;
338    size_t size;
339    int alloc = 0, len = 0;
340    char *text = NULL, buf[16384 + 1];
341
342    f = fopen(file, "rb");
343    if (!f) return NULL;
344    while ((size = fread(buf, 1, sizeof(buf) - 1, f)))
345      {
346         char *tmp_text;
347         buf[size] = 0;
348         tmp_text = _buf_append(text, buf, &len, &alloc);
349         if (!tmp_text) break;
350         text = tmp_text;
351      }
352    fclose(f);
353    return text;
354 }
355
356 static char *
357 _load_plain(const char *file)
358 {
359    char *text;
360
361    text = _load_file(file);
362    if (text)
363      {
364         char *text2;
365
366         text2 = elm_entry_utf8_to_markup(text);
367         free(text);
368         return text2;
369      }
370    return NULL;
371 }
372
373 static void
374 _load(Evas_Object *obj)
375 {
376    Widget_Data *wd = elm_widget_data_get(obj);
377    char *text;
378    if (!wd) return;
379    if (!wd->file)
380      {
381         elm_entry_entry_set(obj, "");
382         return;
383      }
384    switch (wd->format)
385      {
386       case ELM_TEXT_FORMAT_PLAIN_UTF8:
387          text = _load_plain(wd->file);
388          break;
389       case ELM_TEXT_FORMAT_MARKUP_UTF8:
390          text = _load_file(wd->file);
391          break;
392       default:
393          text = NULL;
394          break;
395      }
396    if (text)
397      {
398         elm_entry_entry_set(obj, text);
399         free(text);
400      }
401    else
402      elm_entry_entry_set(obj, "");
403 }
404
405 static void
406 _save_markup_utf8(const char *file, const char *text)
407 {
408    FILE *f;
409
410    if ((!text) || (!text[0]))
411      {
412         ecore_file_unlink(file);
413         return;
414      }
415    f = fopen(file, "wb");
416    if (!f)
417      {
418         // FIXME: report a write error
419         return;
420      }
421    fputs(text, f); // FIXME: catch error
422    fclose(f);
423 }
424
425 static void
426 _save_plain_utf8(const char *file, const char *text)
427 {
428    char *text2;
429
430    text2 = elm_entry_markup_to_utf8(text);
431    if (!text2)
432      return;
433    _save_markup_utf8(file, text2);
434    free(text2);
435 }
436
437 static void
438 _save(Evas_Object *obj)
439 {
440    Widget_Data *wd = elm_widget_data_get(obj);
441    if (!wd) return;
442    if (!wd->file) return;
443    switch (wd->format)
444      {
445       case ELM_TEXT_FORMAT_PLAIN_UTF8:
446          _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
447          break;
448       case ELM_TEXT_FORMAT_MARKUP_UTF8:
449          _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
450          break;
451       default:
452          break;
453      }
454 }
455
456 static Eina_Bool
457 _delay_write(void *data)
458 {
459    Widget_Data *wd = elm_widget_data_get(data);
460    if (!wd) return ECORE_CALLBACK_CANCEL;
461    _save(data);
462    wd->delay_write = NULL;
463    return ECORE_CALLBACK_CANCEL;
464 }
465
466 static Elm_Entry_Text_Filter *
467 _filter_new(void (*func) (void *data, Evas_Object *entry, char **text), void *data)
468 {
469    Elm_Entry_Text_Filter *tf = ELM_NEW(Elm_Entry_Text_Filter);
470    if (!tf) return NULL;
471
472    tf->func = func;
473    if (func == elm_entry_filter_limit_size)
474      {
475         Elm_Entry_Filter_Limit_Size *lim = data, *lim2;
476
477         if (!data)
478           {
479              free(tf);
480              return NULL;
481           }
482         lim2 = malloc(sizeof(Elm_Entry_Filter_Limit_Size));
483         if (!lim2)
484           {
485              free(tf);
486              return NULL;
487           }
488         memcpy(lim2, lim, sizeof(Elm_Entry_Filter_Limit_Size));
489         tf->data = lim2;
490      }
491    else if (func == elm_entry_filter_accept_set)
492      {
493         Elm_Entry_Filter_Accept_Set *as = data, *as2;
494
495         if (!data)
496           {
497              free(tf);
498              return NULL;
499           }
500         as2 = malloc(sizeof(Elm_Entry_Filter_Accept_Set));
501         if (!as2)
502           {
503              free(tf);
504              return NULL;
505           }
506         if (as->accepted)
507           as2->accepted = eina_stringshare_add(as->accepted);
508         else
509           as2->accepted = NULL;
510         if (as->rejected)
511           as2->rejected = eina_stringshare_add(as->rejected);
512         else
513           as2->rejected = NULL;
514         tf->data = as2;
515      }
516    else
517      tf->data = data;
518    return tf;
519 }
520
521 static void
522 _filter_free(Elm_Entry_Text_Filter *tf)
523 {
524    if (tf->func == elm_entry_filter_limit_size)
525      {
526         Elm_Entry_Filter_Limit_Size *lim = tf->data;
527         if (lim) free(lim);
528      }
529    else if (tf->func == elm_entry_filter_accept_set)
530      {
531         Elm_Entry_Filter_Accept_Set *as = tf->data;
532         if (as)
533           {
534              if (as->accepted) eina_stringshare_del(as->accepted);
535              if (as->rejected) eina_stringshare_del(as->rejected);
536              free(as);
537           }
538      }
539    free(tf);
540 }
541
542 static void
543 _del_pre_hook(Evas_Object *obj)
544 {
545    Widget_Data *wd = elm_widget_data_get(obj);
546    if (!wd) return;
547    if (wd->delay_write)
548      {
549         ecore_timer_del(wd->delay_write);
550         wd->delay_write = NULL;
551         if (wd->autosave) _save(obj);
552      }
553 }
554
555 static void
556 _del_hook(Evas_Object *obj)
557 {
558    Widget_Data *wd = elm_widget_data_get(obj);
559    Elm_Entry_Context_Menu_Item *it;
560    Elm_Entry_Item_Provider *ip;
561    Elm_Entry_Text_Filter *tf;
562
563    if (wd->file) eina_stringshare_del(wd->file);
564
565    if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
566    if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
567
568    entries = eina_list_remove(entries, obj);
569 #ifdef HAVE_ELEMENTARY_X
570    ecore_event_handler_del(wd->sel_notify_handler);
571    ecore_event_handler_del(wd->sel_clear_handler);
572 #endif
573    if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
574    if (wd->text) eina_stringshare_del(wd->text);
575    if (wd->bg) evas_object_del(wd->bg);
576    if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
577    if (wd->matchlist_job) ecore_job_del(wd->matchlist_job);
578    if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
579    if (wd->mgf_proxy) evas_object_del(wd->mgf_proxy);
580    if (wd->mgf_bg) evas_object_del(wd->mgf_bg);
581    if (wd->mgf_clip) evas_object_del(wd->mgf_clip);
582
583    EINA_LIST_FREE(wd->items, it)
584      {
585         eina_stringshare_del(it->label);
586         eina_stringshare_del(it->icon_file);
587         eina_stringshare_del(it->icon_group);
588         free(it);
589      }
590    EINA_LIST_FREE(wd->item_providers, ip)
591      {
592         free(ip);
593      }
594    EINA_LIST_FREE(wd->text_filters, tf)
595      {
596         _filter_free(tf);
597      }
598    free(wd);
599 }
600
601 static void
602 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
603 {
604    Widget_Data *wd = elm_widget_data_get(obj);
605    edje_object_mirrored_set(wd->ent, rtl);
606 }
607
608 static void
609 _theme_hook(Evas_Object *obj)
610 {
611    Widget_Data *wd = elm_widget_data_get(obj);
612    const char *t;
613    Ecore_IMF_Context *ic;
614    _elm_widget_mirrored_reload(obj);
615    _mirrored_set(obj, elm_widget_mirrored_get(obj));
616
617    t = eina_stringshare_add(elm_entry_entry_get(obj));
618    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
619    if (_elm_config->desktop_entry)
620       edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
621    elm_entry_entry_set(obj, t);
622    eina_stringshare_del(t);
623    if (elm_widget_disabled_get(obj))
624      edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
625    edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", wd->input_panel_enable);
626    elm_entry_cursor_pos_set(obj, wd->cursor_pos);
627    if (elm_widget_focus_get(obj))
628      edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
629    edje_object_message_signal_process(wd->ent);
630    edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
631
632    if (wd->password)
633      {
634         edje_object_part_text_autoperiod_set(wd->ent, "elm.text", EINA_FALSE);
635         edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", EINA_FALSE);
636      }
637    else
638      {
639         edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
640         edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
641      }
642
643    ic = edje_object_part_text_imf_context_get(wd->ent, "elm.text");
644    if (ic)
645      {
646         ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)wd->input_panel_layout);
647      }
648
649    _sizing_eval(obj);
650 }
651
652 static void
653 _disable_hook(Evas_Object *obj)
654 {
655    Widget_Data *wd = elm_widget_data_get(obj);
656
657    if (elm_widget_disabled_get(obj))
658      {
659         edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
660         wd->disabled = EINA_TRUE;
661      }
662    else
663      {
664         edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
665         wd->disabled = EINA_FALSE;
666      }
667 }
668
669 static void
670 _elm_win_recalc_job(void *data)
671 {
672    Widget_Data *wd = elm_widget_data_get(data);
673    Evas_Coord minh = -1, resw = -1;
674    if (!wd) return;
675    wd->deferred_recalc_job = NULL;
676    evas_object_geometry_get(wd->ent, NULL, NULL, &resw, NULL);
677    edje_object_size_min_restricted_calc(wd->ent, NULL, &minh, resw, 0);
678    elm_coords_finger_size_adjust(1, NULL, 1, &minh);
679    evas_object_size_hint_min_set(data, -1, minh);
680    if (wd->single_line)
681       evas_object_size_hint_max_set(data, -1, minh);
682
683    if (wd->deferred_cur)
684      elm_widget_show_region_set(data, wd->cx, wd->cy, wd->cw, wd->ch, EINA_FALSE);
685 }
686
687 static void
688 _sizing_eval(Evas_Object *obj)
689 {
690    Widget_Data *wd = elm_widget_data_get(obj);
691    Evas_Coord minw = -1, minh = -1;
692    Evas_Coord resw, resh;
693    if (!wd) return;
694    if ((wd->linewrap) || (wd->char_linewrap))
695      {
696         evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
697         if ((resw == wd->lastw) && (!wd->changed)) return;
698         wd->changed = EINA_FALSE;
699         wd->lastw = resw;
700         if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
701         wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
702      }
703    else
704      {
705         evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
706         edje_object_size_min_calc(wd->ent, &minw, &minh);
707         elm_coords_finger_size_adjust(1, &minw, 1, &minh);
708         evas_object_size_hint_min_set(obj, minw, minh);
709         if (wd->single_line)
710            evas_object_size_hint_max_set(obj, -1, minh);
711      }
712 }
713
714 static void
715 _check_enable_returnkey(Evas_Object *obj)
716 {
717    Widget_Data *wd = elm_widget_data_get(obj);
718    if (!wd) return;
719
720    Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
721    if (!ic) return;
722
723    if (!wd->autoreturnkey) return;
724
725    if (_entry_length_get(obj) == 0)
726      {
727         ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_TRUE);
728      }
729    else
730      {
731         ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_FALSE);
732      }
733 }
734
735 static void
736 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
737 {
738    Widget_Data *wd = elm_widget_data_get(obj);
739    Evas_Object *top = elm_widget_top_get(obj);
740    if (!wd) return;
741    if (!wd->editable) return;
742    if (elm_widget_focus_get(obj))
743      {
744         printf("[Elm_entry::Focused] obj : %p\n", obj);
745         evas_object_focus_set(wd->ent, EINA_TRUE);
746         edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
747         if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
748         evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
749         _check_enable_returnkey(obj);
750         wd->mgf_type = _ENTRY_MAGNIFIER_FILLWIDTH;
751         _magnifier_create(obj);
752      }
753    else
754      {
755         printf("[Elm_entry::Unfocused] obj : %p\n", obj);
756         edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
757         evas_object_focus_set(wd->ent, EINA_FALSE);
758         if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
759         evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
760
761         if ((wd->api) && (wd->api->obj_hidemenu))
762           {
763              wd->api->obj_hidemenu(obj);
764           }
765      }
766 }
767
768 static void
769 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
770 {
771    Widget_Data *wd = elm_widget_data_get(obj);
772    if (!wd) return;
773    edje_object_signal_emit(wd->ent, emission, source);
774 }
775
776 static void
777 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
778 {
779    Widget_Data *wd = elm_widget_data_get(obj);
780    if (!wd) return;
781    edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
782 }
783
784 static void
785 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
786 {
787    Widget_Data *wd = elm_widget_data_get(obj);
788    edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
789                                         data);
790 }
791
792 static void
793 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
794 {
795    Widget_Data *wd = elm_widget_data_get(obj);
796    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
797 }
798
799 static void
800 _hoversel_position(Evas_Object *obj)
801 {
802    Widget_Data *wd = elm_widget_data_get(obj);
803    Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
804    if (!wd) return;
805
806    cx = cy = 0;
807    cw = ch = 1;
808    evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
809    if (wd->usedown)
810      {
811         cx = wd->downx - x;
812         cy = wd->downy - y;
813         cw = 1;
814         ch = 1;
815      }
816    else
817       edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
818                                                 &cx, &cy, &cw, &ch);
819    evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
820    if (cw < mw)
821      {
822         cx += (cw - mw) / 2;
823         cw = mw;
824      }
825    if (ch < mh)
826      {
827         cy += (ch - mh) / 2;
828         ch = mh;
829      }
830    evas_object_move(wd->hoversel, x + cx, y + cy);
831    evas_object_resize(wd->hoversel, cw, ch);
832 }
833
834 static void
835 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
836 {
837    Widget_Data *wd = elm_widget_data_get(data);
838
839    if (wd->hoversel) _hoversel_position(data);
840 }
841
842 static void
843 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
844 {
845    Widget_Data *wd = elm_widget_data_get(data);
846    if (!wd) return;
847    if ((wd->linewrap) || (wd->char_linewrap))
848      {
849         _sizing_eval(data);
850      }
851    if (wd->hoversel) _hoversel_position(data);
852    //   Evas_Coord ww, hh;
853    //   evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
854 }
855
856 static void
857 _hover_del(void *data)
858 {
859    Widget_Data *wd = elm_widget_data_get(data);
860    if (!wd) return;
861
862    if (wd->hoversel)
863      {
864         evas_object_del(wd->hoversel);
865         wd->hoversel = NULL;
866      }
867    wd->hovdeljob = NULL;
868 }
869
870 static void
871 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
872 {
873    Widget_Data *wd = elm_widget_data_get(data);
874    if (!wd) return;
875    wd->usedown = 0;
876    if (wd->hoversel) evas_object_hide(wd->hoversel);
877    if (wd->selmode)
878      {
879         if (!_elm_config->desktop_entry)
880           {
881              if (!wd->password)
882                 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
883           }
884      }
885    elm_widget_scroll_freeze_pop(data);
886    if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
887    wd->hovdeljob = ecore_job_add(_hover_del, data);
888 }
889
890 static void
891 _selectall(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
892 {
893    Widget_Data *wd = elm_widget_data_get(data);
894    if (!wd) return;
895    wd->selmode = EINA_TRUE;
896    edje_object_part_text_select_none(wd->ent, "elm.text");
897    edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
898    edje_object_part_text_select_all(wd->ent, "elm.text");
899    elm_object_scroll_freeze_pop(data);
900 }
901
902 static void
903 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
904 {
905    Widget_Data *wd = elm_widget_data_get(data);
906    if (!wd) return;
907    wd->selmode = EINA_TRUE;
908    edje_object_part_text_select_none(wd->ent, "elm.text");
909    if (!_elm_config->desktop_entry)
910      {
911         if (!wd->password)
912            edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
913      }
914    edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
915    if (!_elm_config->desktop_entry)
916       elm_object_scroll_freeze_pop(data);
917       //elm_widget_scroll_hold_push(data);
918 }
919
920 static void
921 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
922 {
923    Widget_Data *wd = elm_widget_data_get(data);
924    if (!wd) return;
925    evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
926    if (wd->sel_notify_handler)
927      {
928 #ifdef HAVE_ELEMENTARY_X
929         Elm_Sel_Format formats;
930         wd->selection_asked = EINA_TRUE;
931         formats = ELM_SEL_FORMAT_MARKUP;
932         if (!wd->textonly)
933           formats |= ELM_SEL_FORMAT_IMAGE;
934         elm_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL);
935 #endif
936      }
937 }
938
939 static void
940 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
941 {
942    Widget_Data *wd = elm_widget_data_get(obj);
943    const char *sel;
944
945    if (!wd) return;
946    sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
947    elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
948    if (seltype == ELM_SEL_CLIPBOARD)
949      eina_stringshare_replace(&wd->cut_sel, sel);
950 }
951
952 static void
953 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
954 {
955    Widget_Data *wd = elm_widget_data_get(data);
956
957    /* Store it */
958    wd->selmode = EINA_FALSE;
959    if (!_elm_config->desktop_entry)
960       edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
961    edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
962    if (!_elm_config->desktop_entry)
963       elm_widget_scroll_hold_pop(data);
964    _store_selection(ELM_SEL_CLIPBOARD, data);
965    edje_object_part_text_insert(wd->ent, "elm.text", "");
966    edje_object_part_text_select_none(wd->ent, "elm.text");
967 }
968
969 static void
970 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
971 {
972    Widget_Data *wd = elm_widget_data_get(data);
973    if (!wd) return;
974    //wd->selmode = EINA_FALSE;
975    if (!_elm_config->desktop_entry)
976      {
977         //edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
978         //edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
979         elm_widget_scroll_hold_pop(data);
980      }
981    _store_selection(ELM_SEL_CLIPBOARD, data);
982    //   edje_object_part_text_select_none(wd->ent, "elm.text");
983 }
984
985 static void
986 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
987 {
988    Widget_Data *wd = elm_widget_data_get(data);
989    if (!wd) return;
990    wd->selmode = EINA_FALSE;
991    if (!_elm_config->desktop_entry)
992       edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
993    edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
994    if (!_elm_config->desktop_entry)
995       elm_widget_scroll_hold_pop(data);
996    edje_object_part_text_select_none(wd->ent, "elm.text");
997 }
998
999 static void
1000 _clipboard_menu(void *data, Evas_Object *obj, void *event_info __UNUSED__)
1001 {
1002    Widget_Data *wd = elm_widget_data_get(data);
1003    if (!wd) return;
1004
1005    // start for cbhm
1006 #ifdef HAVE_ELEMENTARY_X
1007    ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
1008 #endif
1009    cnpwidgetdata = data;
1010    elm_cbhm_helper_init(obj);
1011    if (elm_entry_cnp_textonly_get(obj))
1012            elm_cbhm_send_raw_data("show0");
1013    else
1014            elm_cbhm_send_raw_data("show1");
1015    // end for cbhm
1016 }
1017
1018 // start for cbhm
1019 static void
1020 _cnpinit(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1021 {
1022    Widget_Data *wd = elm_widget_data_get(data);
1023    if (!wd) return;
1024    cnpwidgetdata = data;
1025 }
1026 // end for cbhm
1027
1028
1029 static void
1030 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1031 {
1032    Elm_Entry_Context_Menu_Item *it = data;
1033    Evas_Object *obj2 = it->obj;
1034    if (it->func) it->func(it->data, obj2, NULL);
1035 }
1036
1037 static void
1038 _menu_press(Evas_Object *obj)
1039 {
1040    Widget_Data *wd = elm_widget_data_get(obj);
1041    Evas_Object *top;
1042    const Eina_List *l;
1043    const Elm_Entry_Context_Menu_Item *it;
1044    if (!wd) return;
1045    if ((wd->api) && (wd->api->obj_longpress))
1046      {
1047         wd->api->obj_longpress(obj);
1048      }
1049    else if (wd->context_menu)
1050      {
1051         const char *context_menu_orientation;
1052
1053         if (wd->hoversel) evas_object_del(wd->hoversel);
1054         else elm_widget_scroll_freeze_push(obj);
1055         wd->hoversel = elm_hoversel_add(obj);
1056         context_menu_orientation = edje_object_data_get
1057            (wd->ent, "context_menu_orientation");
1058         if ((context_menu_orientation) &&
1059             (!strcmp(context_menu_orientation, "horizontal")))
1060           elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
1061         elm_object_style_set(wd->hoversel, "entry");
1062         elm_widget_sub_object_add(obj, wd->hoversel);
1063         elm_hoversel_label_set(wd->hoversel, "Text");
1064         top = elm_widget_top_get(obj);
1065         if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
1066         evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, obj);
1067         if (!wd->selmode)
1068           {
1069              if (!wd->password)
1070                elm_hoversel_item_add(wd->hoversel, E_("Select"), NULL, ELM_ICON_NONE,
1071                                      _select, obj);
1072              if (1) // need way to detect if someone has a selection
1073                {
1074                   if (wd->editable)
1075                     elm_hoversel_item_add(wd->hoversel, E_("Paste"), NULL, ELM_ICON_NONE,
1076                                           _paste, obj);
1077                }
1078         // start for cbhm
1079              if ((!wd->password) && (wd->editable))
1080                elm_hoversel_item_add(wd->hoversel, E_("More"), NULL, ELM_ICON_NONE,
1081                                      _clipboard_menu, obj);
1082         // end for cbhm
1083           }
1084         else
1085           {
1086              if (!wd->password)
1087                {
1088                   if (wd->have_selection)
1089                     {
1090                        elm_hoversel_item_add(wd->hoversel, E_("Copy"), NULL, ELM_ICON_NONE,
1091                                              _copy, obj);
1092                        if (wd->editable)
1093                          elm_hoversel_item_add(wd->hoversel, E_("Cut"), NULL, ELM_ICON_NONE,
1094                                                _cut, obj);
1095                     }
1096                   elm_hoversel_item_add(wd->hoversel, E_("Cancel"), NULL, ELM_ICON_NONE,
1097                                         _cancel, obj);
1098         // start for cbhm
1099                   if (wd->editable)
1100                     elm_hoversel_item_add(wd->hoversel, E_("More"), NULL, ELM_ICON_NONE,
1101                                           _clipboard_menu, obj);
1102         // end for cbhm
1103                }
1104           }
1105         EINA_LIST_FOREACH(wd->items, l, it)
1106           {
1107              elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
1108                                    it->icon_type, _item_clicked, it);
1109           }
1110         if (wd->hoversel)
1111           {
1112              _hoversel_position(obj);
1113              evas_object_show(wd->hoversel);
1114              elm_hoversel_hover_begin(wd->hoversel);
1115           }
1116         if (!_elm_config->desktop_entry)
1117           {
1118              edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1119              edje_object_part_text_select_abort(wd->ent, "elm.text");
1120           }
1121      }
1122
1123    evas_object_smart_callback_call(obj, SIG_LONGPRESSED, NULL);
1124 }
1125
1126 static void
1127 _magnifier_hide(void *data)
1128 {
1129    Widget_Data *wd = elm_widget_data_get(data);
1130    if (!wd) return;
1131
1132    evas_object_hide(wd->mgf_bg);
1133    evas_object_hide(wd->mgf_clip);
1134 }
1135
1136 static void
1137 _magnifier_show(void *data)
1138 {
1139    Widget_Data *wd = elm_widget_data_get(data);
1140    if (!wd) return;
1141
1142    evas_object_show(wd->mgf_bg);
1143    evas_object_show(wd->mgf_clip);
1144 }
1145
1146 static void
1147 _magnifier_move(void *data)
1148 {
1149    Widget_Data *wd = elm_widget_data_get(data);
1150    if (!wd) return;
1151
1152    Evas_Coord x, y, w, h, fs;
1153    Evas_Coord cx, cy, cw, ch, ox, oy;
1154
1155    evas_object_geometry_get(data, &x, &y, &w, &h);
1156    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1157
1158    ox = oy = 0;
1159    fs = elm_finger_size_get();
1160
1161    if ((cy + y) - wd->mgf_height - fs < 0)
1162         oy = -1 * ((cy + y) - wd->mgf_height - fs);
1163
1164    if (wd->mgf_type == _ENTRY_MAGNIFIER_FIXEDSIZE)
1165         evas_object_move(wd->mgf_bg, (cx + x + cw/2) + ox, (cy + y) - wd->mgf_height - fs + oy);
1166    else if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1167         evas_object_move(wd->mgf_bg, x, (cy + y) - wd->mgf_height - fs + oy);
1168    else
1169         return;
1170
1171    evas_object_move(wd->mgf_proxy, (1 - wd->mgf_scale) * cx + x + ox, (1 - wd->mgf_scale) * cy + y - wd->mgf_height/2 - ch/2 - fs + oy);
1172 }
1173
1174 static void
1175 _magnifier_create(void *data)
1176 {
1177    Widget_Data *wd = elm_widget_data_get(data);
1178    Evas_Coord x, y, w, h;
1179    const char* key_data = NULL;
1180
1181    if (!wd) return;
1182
1183    if (wd->mgf_proxy)
1184      {
1185         evas_object_image_source_unset(wd->mgf_proxy);
1186         evas_object_color_set(wd->mgf_proxy, 255, 255, 255, 0);
1187         evas_object_hide(wd->mgf_proxy);
1188         evas_object_clip_unset(wd->mgf_proxy);
1189         evas_object_del(wd->mgf_proxy);
1190      }
1191    if (wd->mgf_bg) evas_object_del(wd->mgf_bg);
1192    if (wd->mgf_clip) evas_object_del(wd->mgf_clip);
1193
1194    evas_object_geometry_get(data, &x, &y, &w, &h);
1195    wd->mgf_bg = edje_object_add(evas_object_evas_get(data));
1196
1197    if (wd->mgf_type == _ENTRY_MAGNIFIER_FIXEDSIZE)
1198         _elm_theme_object_set(data, wd->mgf_bg, "entry", "magnifier", "fixed-size");
1199    else if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1200         _elm_theme_object_set(data, wd->mgf_bg, "entry", "magnifier", "fill-width");
1201    else
1202         return;
1203
1204    wd->mgf_clip = evas_object_rectangle_add(evas_object_evas_get(data));
1205    evas_object_color_set(wd->mgf_clip, 255, 255, 255, 255);
1206    edje_object_part_swallow(wd->mgf_bg, "swallow", wd->mgf_clip);
1207
1208    key_data = edje_object_data_get(wd->mgf_bg, "height");
1209    if (key_data) wd->mgf_height = atoi(key_data);
1210    key_data = edje_object_data_get(wd->mgf_bg, "scale");
1211    if (key_data) wd->mgf_scale = atof(key_data);
1212
1213    if (wd->mgf_type == _ENTRY_MAGNIFIER_FILLWIDTH)
1214         evas_object_resize(wd->mgf_bg, w, wd->mgf_height);
1215
1216    wd->mgf_proxy = evas_object_image_add(evas_object_evas_get(data));
1217    evas_object_image_source_set(wd->mgf_proxy, data);
1218    evas_object_resize(wd->mgf_proxy, w * wd->mgf_scale, h * wd->mgf_scale);
1219    evas_object_image_fill_set(wd->mgf_proxy, 0, 0, w * wd->mgf_scale, h * wd->mgf_scale);
1220    evas_object_color_set(wd->mgf_proxy, 255, 255, 255, 255);
1221    evas_object_pass_events_set(wd->mgf_proxy, EINA_TRUE);
1222    evas_object_show(wd->mgf_proxy);
1223    evas_object_clip_set(wd->mgf_proxy, wd->mgf_clip);
1224
1225    evas_object_layer_set(wd->mgf_bg, EVAS_LAYER_MAX);
1226    evas_object_layer_set(wd->mgf_proxy, EVAS_LAYER_MAX);
1227 }
1228
1229 static Eina_Bool
1230 _long_press(void *data)
1231 {
1232    Widget_Data *wd = elm_widget_data_get(data);
1233    if (!wd) return ECORE_CALLBACK_CANCEL;
1234
1235    wd->long_pressed = EINA_TRUE;
1236
1237    if (wd->longpress_timer)
1238      {
1239         ecore_timer_del(wd->longpress_timer);
1240         wd->longpress_timer = NULL;
1241      }
1242
1243    _cancel(data, NULL, NULL);
1244
1245    _magnifier_create(data);
1246    _magnifier_move(data);
1247    _magnifier_show(data);
1248    elm_object_scroll_freeze_push(data);
1249
1250    wd->longpress_timer = NULL;
1251    evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
1252    return ECORE_CALLBACK_CANCEL;
1253 }
1254
1255 static void
1256 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1257 {
1258    Widget_Data *wd = elm_widget_data_get(data);
1259    Evas_Event_Mouse_Down *ev = event_info;
1260    if (!wd) return;
1261    if (wd->disabled) return;
1262    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1263    if (ev->button != 1) return;
1264    //   if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
1265    if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
1266    wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1267    wd->downx = ev->canvas.x;
1268    wd->downy = ev->canvas.y;
1269
1270    wd->long_pressed = EINA_FALSE;
1271 }
1272
1273 static void
1274 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1275 {
1276    Widget_Data *wd = elm_widget_data_get(data);
1277    Evas_Event_Mouse_Up *ev = event_info;
1278    if (!wd) return;
1279    if (wd->disabled) return;
1280    if (ev->button != 1) return;
1281
1282    if (!wd->double_clicked)
1283      {
1284         if ((wd->api) && (wd->api->obj_mouseup))
1285           {
1286              wd->api->obj_mouseup(data);
1287           }
1288      }
1289    if (wd->longpress_timer)
1290      {
1291         ecore_timer_del(wd->longpress_timer);
1292         wd->longpress_timer = NULL;
1293      }
1294
1295    _magnifier_hide(data);
1296    elm_object_scroll_freeze_pop(data);
1297
1298    if (wd->long_pressed)
1299      {
1300         _menu_press(data);
1301      }
1302 }
1303
1304 static void
1305 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1306 {
1307    Widget_Data *wd = elm_widget_data_get(data);
1308    Evas_Event_Mouse_Move *ev = event_info;
1309    if (!wd) return;
1310    if (wd->disabled) return;
1311    if (!wd->selmode)
1312      {
1313         if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1314           {
1315              if (wd->longpress_timer)
1316                {
1317                   ecore_timer_del(wd->longpress_timer);
1318                   wd->longpress_timer = NULL;
1319                }
1320           }
1321         else if (wd->longpress_timer)
1322           {
1323              Evas_Coord dx, dy;
1324
1325              dx = wd->downx - ev->cur.canvas.x;
1326              dx *= dx;
1327              dy = wd->downy - ev->cur.canvas.y;
1328              dy *= dy;
1329              if ((dx + dy) >
1330                  ((_elm_config->finger_size / 2) *
1331                   (_elm_config->finger_size / 2)))
1332                {
1333                   ecore_timer_del(wd->longpress_timer);
1334                   wd->longpress_timer = NULL;
1335                }
1336           }
1337      }
1338    else if (wd->longpress_timer)
1339      {
1340         Evas_Coord dx, dy;
1341
1342         dx = wd->downx - ev->cur.canvas.x;
1343         dx *= dx;
1344         dy = wd->downy - ev->cur.canvas.y;
1345         dy *= dy;
1346         if ((dx + dy) >
1347             ((_elm_config->finger_size / 2) *
1348              (_elm_config->finger_size / 2)))
1349           {
1350              ecore_timer_del(wd->longpress_timer);
1351              wd->longpress_timer = NULL;
1352           }
1353      }
1354
1355    if (ev->buttons != 1) return;
1356
1357    if (wd->long_pressed)
1358      {
1359         _magnifier_show(data);
1360         _magnifier_move(data);
1361      }
1362 }
1363
1364 static const char *
1365 _getbase(Evas_Object *obj)
1366 {
1367    Widget_Data *wd = elm_widget_data_get(obj);
1368    if (!wd) return "base";
1369    if (wd->editable)
1370      {
1371         if (wd->password) return "base-password";
1372         else
1373           {
1374              if (wd->single_line) return "base-single";
1375              else
1376                {
1377                   if (wd->linewrap) return "base";
1378                   else if (wd->char_linewrap) return "base-charwrap";
1379                   else  return "base-nowrap";
1380                }
1381           }
1382      }
1383    else
1384      {
1385         if (wd->password) return "base-password";
1386         else
1387           {
1388              if (wd->single_line) return "base-single-noedit";
1389              else
1390                {
1391                   if (wd->linewrap) return "base-noedit";
1392                   else if (wd->char_linewrap) return "base-noedit-charwrap";
1393                   else  return "base-nowrap-noedit";
1394                }
1395           }
1396      }
1397    return "base";
1398 }
1399
1400 static int
1401 _entry_length_get(Evas_Object *obj)
1402 {
1403    int len;
1404    const char *str = elm_entry_entry_get(obj);
1405    if (!str) return 0;
1406
1407    char *plain_str = _elm_util_mkup_to_text(str);
1408    if (!plain_str) return 0;
1409
1410    len = strlen(plain_str);
1411    free(plain_str);
1412
1413    return len;
1414 }
1415
1416 static void
1417 _matchlist_show(void *data)
1418 {
1419    Widget_Data *wd = elm_widget_data_get(data);
1420    const char *text = NULL;
1421    int textlen = 0;
1422    char *str_list = NULL, *str_result = NULL;
1423    char *str_mkup = NULL, *str_front = NULL, *str_mid = NULL;
1424
1425    Eina_List *l;
1426    Eina_Bool textfound = EINA_FALSE;
1427
1428    if (!wd) return;
1429    if (elm_widget_disabled_get(data)) return;
1430
1431    wd->matchlist_job = NULL;
1432
1433    if (wd->matchlist_list_clicked)
1434      {
1435         evas_object_hide(wd->hover);
1436         wd->matchlist_list_clicked = EINA_FALSE;
1437         return;
1438      }
1439    text = elm_entry_entry_get(data);
1440    if (text == NULL)
1441       return;
1442    textlen = strlen(text);
1443
1444    if (textlen < wd->matchlist_threshold)
1445      {
1446         evas_object_hide(wd->hover);
1447         return;
1448      }
1449
1450    evas_object_hide(wd->hover);
1451
1452    if (wd->match_list)
1453      {
1454         elm_list_clear(wd->list);
1455         EINA_LIST_FOREACH(wd->match_list, l, str_list)
1456           {
1457              if (wd->matchlist_case_sensitive)
1458                 str_result = strstr(str_list, text);
1459              else
1460                 str_result = strcasestr(str_list, text);
1461
1462              if (str_result)
1463                {
1464                   str_mkup = malloc(strlen(str_list) + 16);
1465
1466                   textlen = strlen(str_list) - strlen(str_result);
1467                   str_front = malloc(textlen + 1);
1468                   memset(str_front, 0, textlen + 1);
1469                   strncpy(str_front, str_list, textlen);
1470
1471                   textlen = strlen(text);
1472                   str_mid = malloc(textlen + 1);
1473                   memset(str_mid, 0, textlen + 1);
1474                   strncpy(str_mid, str_list + strlen(str_front), textlen);
1475
1476                   sprintf(str_mkup, "%s<match>%s</match>%s", str_front, str_mid, str_result + strlen(text));
1477
1478                   elm_list_item_append(wd->list, str_mkup, NULL, NULL, NULL, NULL);
1479
1480                   if (str_mkup) free(str_mkup);
1481                   if (str_front) free(str_front);
1482                   if (str_mid) free(str_mid);
1483
1484                   textfound=EINA_TRUE;
1485                }
1486           }
1487      }
1488    else
1489       return;
1490
1491    if (textfound)
1492      {
1493         elm_list_go(wd->list);
1494         evas_object_show(wd->hover);
1495         evas_object_raise(wd->hover);
1496      }
1497 }
1498
1499 static void _matchlist_list_clicked( void *data, Evas_Object *obj, void *event_info )
1500 {
1501    Elm_List_Item *it = (Elm_List_Item *) elm_list_selected_item_get(obj);
1502    Widget_Data *wd = elm_widget_data_get(data);
1503    if ((it == NULL) || (wd == NULL))
1504       return;
1505
1506    const char *text = elm_list_item_label_get(it);
1507    evas_object_smart_callback_call((Evas_Object *)data, "selected", (void *)text);
1508    if (wd->match_list)
1509      {
1510         if (text != NULL)
1511           {
1512              elm_entry_entry_set(data, elm_entry_markup_to_utf8(text));
1513              elm_entry_cursor_end_set(data);
1514              wd->matchlist_list_clicked = EINA_TRUE;
1515
1516              evas_object_smart_callback_call(data, SIG_MATCHLIST_CLICKED, elm_entry_markup_to_utf8(text));
1517           }
1518      }
1519    elm_widget_focus_set(data, EINA_TRUE);
1520 }
1521
1522 EAPI void
1523 elm_entry_matchlist_set(Evas_Object *obj, Eina_List *match_list, Eina_Bool case_sensitive)
1524 {
1525    Widget_Data *wd = elm_widget_data_get(obj);
1526    if (!wd) return;
1527
1528    if (match_list)
1529    {
1530            Evas_Coord max_w = 9999, max_h = 9999;
1531            const char* key_data = NULL;
1532
1533            wd->matchlist_threshold = 1;
1534            wd->hover = elm_hover_add(elm_widget_parent_get(obj));
1535            elm_hover_parent_set(wd->hover, elm_widget_parent_get(obj));
1536            elm_hover_target_set(wd->hover, obj);
1537            elm_object_style_set(wd->hover, "matchlist");
1538
1539            wd->layout = elm_layout_add(wd->hover);
1540            elm_layout_theme_set(wd->layout, "entry", "matchlist", "default");
1541            wd->list = elm_list_add(wd->layout);
1542            evas_object_size_hint_weight_set(wd->list, EVAS_HINT_EXPAND, 0.0);
1543            evas_object_size_hint_align_set(wd->list, EVAS_HINT_FILL, EVAS_HINT_FILL);
1544            elm_list_mode_set(wd->list, ELM_LIST_EXPAND);
1545            elm_object_style_set(wd->list, "matchlist");
1546
1547            key_data = edje_object_data_get(elm_layout_edje_get(wd->layout), "max_width");
1548            if (key_data) max_w = atoi(key_data);
1549            key_data = edje_object_data_get(elm_layout_edje_get(wd->layout), "max_height");
1550            if (key_data) max_h = atoi(key_data);
1551
1552            elm_list_go(wd->list);
1553            evas_object_size_hint_max_set(wd->list, max_w, max_h);
1554            evas_object_smart_callback_add(wd->list, "selected", _matchlist_list_clicked, obj);
1555            elm_layout_content_set(wd->layout, "elm.swallow.content", wd->list);
1556            elm_hover_content_set(wd->hover, "bottom", wd->layout);
1557
1558            wd->match_list = match_list;
1559    }
1560    else
1561    {
1562            if (wd->hover)
1563                    evas_object_del(wd->hover);
1564
1565            wd->match_list = NULL;
1566    }
1567
1568    wd->matchlist_case_sensitive = case_sensitive;
1569 }
1570
1571
1572 static void
1573 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1574 {
1575    Widget_Data *wd = elm_widget_data_get(data);
1576    if (!wd) return;
1577    wd->changed = EINA_TRUE;
1578    _sizing_eval(data);
1579    if (wd->text) eina_stringshare_del(wd->text);
1580    wd->text = NULL;
1581    _check_enable_returnkey(data);
1582    evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1583    if (wd->delay_write)
1584      {
1585         ecore_timer_del(wd->delay_write);
1586         wd->delay_write = NULL;
1587      }
1588
1589    if ((wd->single_line) && (wd->match_list))
1590    {
1591         if (wd->matchlist_job) ecore_job_del(wd->matchlist_job);
1592         wd->matchlist_job = ecore_job_add(_matchlist_show, data);
1593    }
1594    if ((!wd->autosave) || (!wd->file)) return;
1595    wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1596 }
1597
1598 static void
1599 _signal_handler_move_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1600 {
1601    Widget_Data *wd = elm_widget_data_get(data);
1602    elm_object_scroll_freeze_push(data);
1603
1604    if ((wd->api) && (wd->api->obj_hidemenu))
1605      {
1606         wd->api->obj_hidemenu(data);
1607      }
1608
1609    _magnifier_create(data);
1610    _magnifier_move(data);
1611    _magnifier_show(data);
1612 }
1613
1614 static void
1615 _signal_handler_move_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1616 {
1617    Widget_Data *wd = elm_widget_data_get(data);
1618    elm_object_scroll_freeze_pop(data);
1619
1620    if (wd->have_selection)
1621      {
1622         _magnifier_hide(data);
1623         _menu_press(data);
1624      }
1625 }
1626
1627 static void
1628 _signal_handler_moving(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1629 {
1630    _magnifier_move(data);
1631    _magnifier_show(data);
1632 }
1633
1634 static void
1635 _signal_selection_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1636 {
1637    _magnifier_hide(data);
1638    _menu_press(data);
1639 }
1640
1641 static void
1642 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1643 {
1644    Widget_Data *wd = elm_widget_data_get(data);
1645    const Eina_List *l;
1646    Evas_Object *entry;
1647    if (!wd) return;
1648    EINA_LIST_FOREACH(entries, l, entry)
1649      {
1650         if (entry != data) elm_entry_select_none(entry);
1651      }
1652    wd->have_selection = EINA_TRUE;
1653    wd->selmode = EINA_TRUE;
1654    evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1655 #ifdef HAVE_ELEMENTARY_X
1656    if (wd->sel_notify_handler)
1657      {
1658         const char *txt = elm_entry_selection_get(data);
1659         Evas_Object *top;
1660
1661         top = elm_widget_top_get(data);
1662         if ((top) && (elm_win_xwindow_get(top)))
1663           elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1664      }
1665 #endif
1666 }
1667
1668 static void
1669 _signal_magnifier_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1670 {
1671    Evas_Coord cx, cy, cw, ch;
1672    Widget_Data *wd = elm_widget_data_get(data);
1673    if (!wd) return;
1674
1675    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1676    if (!wd->deferred_recalc_job)
1677       elm_widget_show_region_set(data, cx, cy, cw, ch, EINA_FALSE);
1678    else
1679      {
1680         wd->deferred_cur = EINA_TRUE;
1681         wd->cx = cx;
1682         wd->cy = cy;
1683         wd->cw = cw;
1684         wd->ch = ch + elm_finger_size_get();
1685      }
1686 }
1687
1688 static void
1689 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1690 {
1691    Evas_Coord cx, cy, cw, ch;
1692    Widget_Data *wd = elm_widget_data_get(data);
1693    if (!wd) return;
1694    wd->have_selection = EINA_TRUE;
1695    wd->selmode = EINA_TRUE;
1696    evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1697    elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1698                      elm_entry_selection_get(data));
1699
1700    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1701    if (!wd->deferred_recalc_job)
1702       elm_widget_show_region_set(data, cx, cy, cw, ch + elm_finger_size_get(), EINA_FALSE);
1703    else
1704      {
1705         wd->deferred_cur = EINA_TRUE;
1706         wd->cx = cx;
1707         wd->cy = cy;
1708         wd->cw = cw;
1709         wd->ch = ch + elm_finger_size_get();
1710      }
1711 }
1712
1713 static void
1714 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1715 {
1716    Widget_Data *wd = elm_widget_data_get(data);
1717    if (!wd) return;
1718    if (!wd->have_selection) return;
1719    wd->have_selection = EINA_FALSE;
1720    wd->selmode = EINA_FALSE;
1721    evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1722    if (wd->sel_notify_handler)
1723      {
1724         if (wd->cut_sel)
1725           {
1726 #ifdef HAVE_ELEMENTARY_X
1727              Evas_Object *top;
1728
1729              top = elm_widget_top_get(data);
1730              if ((top) && (elm_win_xwindow_get(top)))
1731                elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1732                                  wd->cut_sel);
1733 #endif
1734              eina_stringshare_del(wd->cut_sel);
1735              wd->cut_sel = NULL;
1736           }
1737         else
1738           {
1739 #ifdef HAVE_ELEMENTARY_X
1740              Evas_Object *top;
1741
1742              top = elm_widget_top_get(data);
1743              if ((top) && (elm_win_xwindow_get(top)))
1744                elm_selection_clear(ELM_SEL_PRIMARY, data);
1745 #endif
1746           }
1747      }
1748
1749    if ((wd->api) && (wd->api->obj_hidemenu))
1750      {
1751         wd->api->obj_hidemenu(data);
1752      }
1753 }
1754
1755 static void
1756 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1757 {
1758    Widget_Data *wd = elm_widget_data_get(data);
1759    if (!wd) return;
1760    evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1761    if (wd->sel_notify_handler)
1762      {
1763 #ifdef HAVE_ELEMENTARY_X
1764         Evas_Object *top;
1765
1766         top = elm_widget_top_get(data);
1767         if ((top) && (elm_win_xwindow_get(top)))
1768           {
1769              wd->selection_asked = EINA_TRUE;
1770              elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
1771                                NULL, NULL);
1772           }
1773 #endif
1774      }
1775 }
1776
1777 static void
1778 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1779 {
1780    Widget_Data *wd = elm_widget_data_get(data);
1781    if (!wd) return;
1782    evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1783    elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1784                      elm_entry_selection_get(data));
1785 }
1786
1787 static void
1788 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1789 {
1790    Widget_Data *wd = elm_widget_data_get(data);
1791    if (!wd) return;
1792    evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1793    elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1794                      elm_entry_selection_get(data));
1795    edje_object_part_text_insert(wd->ent, "elm.text", "");
1796    wd->changed = EINA_TRUE;
1797    _sizing_eval(data);
1798 }
1799
1800 static void
1801 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1802 {
1803    Widget_Data *wd = elm_widget_data_get(data);
1804    Evas_Coord cx, cy, cw, ch;
1805    if (!wd) return;
1806    evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1807    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1808                                              &cx, &cy, &cw, &ch);
1809    wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1810    if (!wd->deferred_recalc_job)
1811      elm_widget_show_region_set(data, cx, cy, cw, ch, EINA_FALSE);
1812    else
1813      {
1814         wd->deferred_cur = EINA_TRUE;
1815         wd->cx = cx;
1816         wd->cy = cy;
1817         wd->cw = cw;
1818         wd->ch = ch;
1819      }
1820 }
1821
1822 static void
1823 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1824 {
1825    Widget_Data *wd = elm_widget_data_get(data);
1826    if (!wd) return;
1827 }
1828
1829 static void
1830 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1831 {
1832    Widget_Data *wd = elm_widget_data_get(data);
1833    if (!wd) return;
1834 }
1835
1836 static void
1837 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1838 {
1839    Widget_Data *wd = elm_widget_data_get(data);
1840    Elm_Entry_Anchor_Info ei;
1841    char *buf2, *p, *p2, *n;
1842    if (!wd) return;
1843    p = strrchr(emission, ',');
1844    if (p)
1845      {
1846         const Eina_List *geoms;
1847
1848         n = p + 1;
1849         p2 = p - 1;
1850         while (p2 >= emission)
1851           {
1852              if (*p2 == ',') break;
1853              p2--;
1854           }
1855         p2++;
1856         buf2 = alloca(5 + p - p2);
1857         strncpy(buf2, p2, p - p2);
1858         buf2[p - p2] = 0;
1859         ei.name = n;
1860         ei.button = atoi(buf2);
1861         ei.x = ei.y = ei.w = ei.h = 0;
1862         geoms =
1863            edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1864         if (geoms)
1865           {
1866              Evas_Textblock_Rectangle *r;
1867              const Eina_List *l;
1868              Evas_Coord px, py, x, y;
1869
1870              evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1871              evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1872              EINA_LIST_FOREACH(geoms, l, r)
1873                {
1874                   if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1875                       ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1876                     {
1877                        ei.x = r->x + x;
1878                        ei.y = r->y + y;
1879                        ei.w = r->w;
1880                        ei.h = r->h;
1881                        break;
1882                     }
1883                }
1884           }
1885         if (!wd->disabled)
1886           evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1887      }
1888 }
1889
1890 static void
1891 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1892 {
1893    Widget_Data *wd = elm_widget_data_get(data);
1894    if (!wd) return;
1895 }
1896
1897 static void
1898 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1899 {
1900    Widget_Data *wd = elm_widget_data_get(data);
1901    if (!wd) return;
1902 }
1903
1904 static void
1905 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1906 {
1907    Widget_Data *wd = elm_widget_data_get(data);
1908    if (!wd) return;
1909 }
1910
1911 static void
1912 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1913 {
1914    Widget_Data *wd = elm_widget_data_get(data);
1915    if (!wd) return;
1916    evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1917 }
1918
1919 static void
1920 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1921 {
1922    Widget_Data *wd = elm_widget_data_get(data);
1923    if (!wd) return;
1924    wd->double_clicked = EINA_FALSE;
1925    evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1926
1927    if ((wd->api) && (wd->api->obj_hidemenu))
1928      {
1929         wd->api->obj_hidemenu(data);
1930      }
1931 }
1932
1933 static void
1934 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1935 {
1936    Widget_Data *wd = elm_widget_data_get(data);
1937    if (!wd) return;
1938    evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1939 }
1940
1941 static void
1942 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1943 {
1944    Widget_Data *wd = elm_widget_data_get(data);
1945    if (!wd) return;
1946    wd->double_clicked = EINA_TRUE;
1947    evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1948 }
1949
1950 #ifdef HAVE_ELEMENTARY_X
1951 static Eina_Bool
1952 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1953 {
1954    Widget_Data *wd = elm_widget_data_get(data);
1955    Ecore_X_Event_Selection_Notify *ev = event;
1956    if (!wd) return ECORE_CALLBACK_PASS_ON;
1957    if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1958      return ECORE_CALLBACK_PASS_ON;
1959
1960    if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1961        (ev->selection == ECORE_X_SELECTION_PRIMARY))
1962      {
1963         Ecore_X_Selection_Data_Text *text_data;
1964
1965         text_data = ev->data;
1966         if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1967           {
1968              if (text_data->text)
1969                {
1970                   char *txt = _elm_util_text_to_mkup(text_data->text);
1971
1972                   if (txt)
1973                     {
1974                        elm_entry_entry_insert(data, txt);
1975                        free(txt);
1976                     }
1977                }
1978           }
1979         wd->selection_asked = EINA_FALSE;
1980      }
1981    else if (ev->selection == ECORE_X_SELECTION_XDND)
1982      {
1983         Ecore_X_Selection_Data_Text *text_data;
1984
1985         text_data = ev->data;
1986         if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1987           {
1988              if (text_data->text)
1989                {
1990                   char *txt = _elm_util_text_to_mkup(text_data->text);
1991
1992                   if (txt)
1993                     {
1994                        /* Massive FIXME: this should be at the drag point */
1995                        elm_entry_entry_insert(data, txt);
1996                        free(txt);
1997                     }
1998                }
1999           }
2000         wd->drag_selection_asked = EINA_FALSE;
2001
2002         ecore_x_dnd_send_finished();
2003      }
2004    return ECORE_CALLBACK_PASS_ON;
2005 }
2006
2007 static Eina_Bool
2008 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
2009 {
2010 /*
2011    Widget_Data *wd = elm_widget_data_get(data);
2012    Ecore_X_Event_Selection_Clear *ev = event;
2013    if (!wd) return ECORE_CALLBACK_PASS_ON;
2014    if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
2015    if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
2016        (ev->selection == ECORE_X_SELECTION_PRIMARY))
2017      {
2018         elm_entry_select_none(data);
2019      }
2020    return 1; */
2021
2022    // start for cbhm
2023    Evas_Object *top = elm_widget_top_get(data);
2024    Ecore_X_Event_Selection_Clear *ev = event;
2025
2026    if (!top)
2027       return ECORE_CALLBACK_PASS_ON;
2028
2029    if (ev->selection != ECORE_X_SELECTION_SECONDARY)
2030      {
2031         return ECORE_CALLBACK_PASS_ON;
2032      }
2033
2034    if (cnpwidgetdata == data)
2035      {
2036         elm_selection_get(ELM_SEL_SECONDARY,ELM_SEL_FORMAT_MARKUP,data,NULL,NULL);
2037      }
2038
2039    // end for cbhm
2040    return ECORE_CALLBACK_PASS_ON;
2041 }
2042
2043
2044 static Eina_Bool
2045 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
2046 {
2047    Widget_Data *wd;
2048    Eina_Bool rv;
2049
2050    wd = elm_widget_data_get(obj);
2051
2052    if (!wd) return EINA_FALSE;
2053    printf("Inserting at (%d,%d) %s\n", drop->x, drop->y, (char*)drop->data);
2054
2055    edje_object_part_text_cursor_copy(wd->ent, "elm.text",
2056                                      EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
2057    rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
2058                                                EDJE_CURSOR_MAIN,drop->x,drop->y);
2059    if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
2060    elm_entry_entry_insert(obj, drop->data);
2061    edje_object_part_text_cursor_copy(wd->ent, "elm.text",
2062                                      EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
2063
2064    return EINA_TRUE;
2065 }
2066 #endif
2067
2068 static Evas_Object *
2069 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
2070 {
2071    Widget_Data *wd = elm_widget_data_get(data);
2072    Evas_Object *o;
2073    Eina_List *l;
2074    Elm_Entry_Item_Provider *ip;
2075
2076    EINA_LIST_FOREACH(wd->item_providers, l, ip)
2077      {
2078         o = ip->func(ip->data, data, item);
2079         if (o) return o;
2080      }
2081    if (!strncmp(item, "file://", 7))
2082      {
2083         const char *fname = item + 7;
2084
2085         o = evas_object_image_filled_add(evas_object_evas_get(data));
2086         evas_object_image_file_set(o, fname, NULL);
2087         if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
2088           {
2089              evas_object_show(o);
2090           }
2091         else
2092           {
2093              evas_object_del(o);
2094              o = edje_object_add(evas_object_evas_get(data));
2095              _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
2096           }
2097         return o;
2098      }
2099    o = edje_object_add(evas_object_evas_get(data));
2100    if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
2101      _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
2102    return o;
2103 }
2104
2105 static int
2106 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
2107 {
2108    const char *srcstring = NULL;
2109    Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
2110    char *curlocater, *replocater;
2111    char *starttag, *endtag;
2112    int tagtxtlen = 0, insertflag = 0;
2113
2114    srcstring = eina_strbuf_string_get(srcbuf);
2115    curlocater = strstr(srcstring, key);
2116
2117    if (!curlocater || !srcstring)
2118      {
2119        insertflag = 1;
2120      }
2121    else
2122      {
2123        do
2124          {
2125            starttag = strchr(srcstring, '<');
2126            endtag = strchr(srcstring, '>');
2127            tagtxtlen = endtag - starttag;
2128            if (tagtxtlen <= 0) tagtxtlen = 0;
2129            if (starttag < curlocater && curlocater < endtag) break;
2130            if (endtag != NULL && endtag+1 != NULL)
2131              srcstring = endtag+1;
2132            else
2133              break;
2134          } while (strlen(srcstring) > 1);
2135
2136        if (starttag && endtag && tagtxtlen > strlen(key))
2137          {
2138            repbuf = eina_strbuf_new();
2139            diffbuf = eina_strbuf_new();
2140            eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
2141            srcstring = eina_strbuf_string_get(repbuf);
2142            curlocater = strstr(srcstring, key);
2143
2144            if (curlocater != NULL)
2145              {
2146                replocater = curlocater + strlen(key) + 1;
2147
2148                while ((*replocater) && (*replocater != ' ') && (*replocater != '>'))
2149                  replocater++;
2150
2151                if (replocater-curlocater > strlen(key)+1)
2152                  {
2153                    eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
2154                  }
2155                else
2156                  insertflag = 1;
2157              }
2158            else
2159              {
2160                insertflag = 1;
2161              }
2162            eina_strbuf_reset(repbuf);
2163          }
2164        else
2165          {
2166            insertflag = 1;
2167          }
2168      }
2169
2170    if (repbuf == NULL) repbuf = eina_strbuf_new();
2171    if (diffbuf == NULL) diffbuf = eina_strbuf_new();
2172
2173    if (insertflag)
2174      {
2175        eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
2176        eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
2177      }
2178    else
2179      {
2180         if (deleteflag)
2181           {
2182             eina_strbuf_prepend(diffbuf, "<");
2183             eina_strbuf_append(diffbuf, ">");
2184             eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
2185           }
2186         else
2187           {
2188             eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
2189             eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
2190           }
2191      }
2192
2193    if (repbuf) eina_strbuf_free(repbuf);
2194    if (diffbuf) eina_strbuf_free(diffbuf);
2195
2196    return 0;
2197 }
2198
2199 static int
2200 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
2201 {
2202    Eina_Strbuf *sharebuf = NULL;
2203
2204    sharebuf = eina_strbuf_new();
2205    eina_strbuf_append(sharebuf, *srcstring);
2206    _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
2207    eina_stringshare_del(*srcstring);
2208    *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
2209    eina_strbuf_free(sharebuf);
2210
2211    return 0;
2212 }
2213
2214 static void
2215 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
2216 {
2217    Widget_Data *wd = elm_widget_data_get(data);
2218    Eina_List *l;
2219    Elm_Entry_Text_Filter *tf;
2220
2221    if (type == EDJE_TEXT_FILTER_FORMAT)
2222      return;
2223
2224    EINA_LIST_FOREACH(wd->text_filters, l, tf)
2225      {
2226         tf->func(tf->data, data, text);
2227         if (!*text)
2228           break;
2229      }
2230 }
2231
2232 static void
2233 _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit)
2234 {
2235    int i = 0, unit_size;
2236    int current_len = strlen(*text);
2237    char *new_text = *text;
2238    if (unit >= LENGTH_UNIT_LAST) return;
2239    while (*new_text)
2240      {
2241         if (*new_text == '<')
2242           {
2243              while (*new_text != '>')
2244                {
2245                   new_text++;
2246                   if (!*new_text) break;
2247                }
2248              new_text++;
2249           }
2250         else
2251           {
2252              int index = 0;
2253              if (*new_text == '&')
2254                {
2255                   while (*(new_text + index) != ';')
2256                     {
2257                        index++;
2258                        if (!*(new_text + index)) break;
2259                     }
2260                }
2261              char *markup;
2262              index = evas_string_char_next_get(new_text, index, NULL);
2263              markup = malloc(index + 1);
2264              strncpy(markup, new_text, index);
2265              markup[index] = 0;
2266              if (unit == LENGTH_UNIT_BYTE)
2267                unit_size = strlen(elm_entry_markup_to_utf8(markup));
2268              else if (unit == LENGTH_UNIT_CHAR)
2269                unit_size = evas_string_char_len_get(elm_entry_markup_to_utf8(markup));
2270              if (markup)
2271                {
2272                   free(markup);
2273                   markup = NULL;
2274                }
2275              if (can_add < unit_size)
2276                {
2277                   if (!i)
2278                     {
2279                        evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
2280                        free(*text);
2281                        *text = NULL;
2282                        return;
2283                     }
2284                   can_add = 0;
2285                   strncpy(new_text, new_text + index, current_len - ((new_text + index) - *text));
2286                   current_len -= index;
2287                   (*text)[current_len] = 0;
2288                }
2289              else
2290                {
2291                   new_text += index;
2292                   can_add -= unit_size;
2293                }
2294              i++;
2295           }
2296      }
2297    evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
2298 }
2299
2300 /**
2301  * This adds an entry to @p parent object.
2302  *
2303  * @param parent The parent object
2304  * @return The new object or NULL if it cannot be created
2305  *
2306  * @ingroup Entry
2307  */
2308 EAPI Evas_Object *
2309 elm_entry_add(Evas_Object *parent)
2310 {
2311    Evas_Object *obj, *top;
2312    Evas *e;
2313    Widget_Data *wd;
2314
2315    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
2316
2317    ELM_SET_WIDTYPE(widtype, "entry");
2318    elm_widget_type_set(obj, "entry");
2319    elm_widget_sub_object_add(parent, obj);
2320    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2321    elm_widget_data_set(obj, wd);
2322    elm_widget_del_hook_set(obj, _del_hook);
2323    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2324    elm_widget_theme_hook_set(obj, _theme_hook);
2325    elm_widget_disable_hook_set(obj, _disable_hook);
2326    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2327    elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
2328    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
2329    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
2330    elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
2331    elm_widget_can_focus_set(obj, EINA_TRUE);
2332    elm_widget_highlight_ignore_set(obj, EINA_TRUE);
2333
2334    wd->linewrap     = EINA_TRUE;
2335    wd->char_linewrap= EINA_FALSE;
2336    wd->editable     = EINA_TRUE;
2337    wd->disabled     = EINA_FALSE;
2338    wd->context_menu = EINA_TRUE;
2339    wd->autosave     = EINA_TRUE;
2340    wd->textonly     = EINA_FALSE;
2341    wd->autoperiod   = EINA_TRUE;
2342
2343    wd->ent = edje_object_add(e);
2344    edje_object_item_provider_set(wd->ent, _get_item, obj);
2345    edje_object_text_insert_filter_callback_add(wd->ent, "elm.text", _text_filter, obj);
2346    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
2347    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
2348    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
2349                                   _mouse_down, obj);
2350    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
2351                                   _mouse_up, obj);
2352    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
2353                                   _mouse_move, obj);
2354
2355    _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
2356    edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
2357                                    _signal_entry_changed, obj);
2358    edje_object_signal_callback_add(wd->ent, "handler,move,start", "elm.text",
2359                                    _signal_handler_move_start, obj);
2360    edje_object_signal_callback_add(wd->ent, "handler,move,end", "elm.text",
2361                                    _signal_handler_move_end, obj);
2362    edje_object_signal_callback_add(wd->ent, "handler,moving", "elm.text",
2363                                    _signal_handler_moving, obj);
2364    edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
2365                                    _signal_selection_start, obj);
2366    edje_object_signal_callback_add(wd->ent, "selection,end", "elm.text",
2367                                    _signal_selection_end, obj);
2368    edje_object_signal_callback_add(wd->ent, "magnifier,changed", "elm.text",
2369                                    _signal_magnifier_changed, obj);
2370    edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
2371                                    _signal_selection_changed, obj);
2372    edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2373                                    _signal_selection_cleared, obj);
2374    edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
2375                                    _signal_entry_paste_request, obj);
2376    edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2377                                    _signal_entry_copy_notify, obj);
2378    edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2379                                    _signal_entry_cut_notify, obj);
2380    edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2381                                    _signal_cursor_changed, obj);
2382    edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2383                                    _signal_anchor_down, obj);
2384    edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2385                                    _signal_anchor_up, obj);
2386    edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
2387                                    _signal_anchor_clicked, obj);
2388    edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2389                                    _signal_anchor_move, obj);
2390    edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2391                                    _signal_anchor_in, obj);
2392    edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2393                                    _signal_anchor_out, obj);
2394    edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2395                                    _signal_key_enter, obj);
2396    edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2397                                    _signal_mouse_down, obj);
2398    edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2399                                    _signal_mouse_clicked, obj);
2400    edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2401                                    _signal_mouse_double, obj);
2402    edje_object_part_text_set(wd->ent, "elm.text", "");
2403    if (_elm_config->desktop_entry)
2404       edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
2405    elm_widget_resize_object_set(obj, wd->ent);
2406    _sizing_eval(obj);
2407
2408    wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
2409
2410 #ifdef HAVE_ELEMENTARY_X
2411    top = elm_widget_top_get(obj);
2412    if ((top) && (elm_win_xwindow_get(top)))
2413      {
2414         wd->sel_notify_handler =
2415            ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2416                                    _event_selection_notify, obj);
2417         wd->sel_clear_handler =
2418            ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2419                                    _event_selection_clear, obj);
2420      }
2421
2422    elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
2423                        _drag_drop_cb, NULL);
2424 #endif
2425
2426    entries = eina_list_prepend(entries, obj);
2427
2428    // module - find module for entry
2429    wd->api = _module(obj);
2430    // if found - hook in
2431    if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2432
2433    _mirrored_set(obj, elm_widget_mirrored_get(obj));
2434    // TODO: convert Elementary to subclassing of Evas_Smart_Class
2435    // TODO: and save some bytes, making descriptions per-class and not instance!
2436    evas_object_smart_callbacks_descriptions_set(obj, _signals);
2437    return obj;
2438 }
2439
2440 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
2441 {
2442    ELM_CHECK_WIDTYPE(obj, widtype);
2443    Widget_Data *wd = elm_widget_data_get(obj);
2444    if (!wd) return;
2445    ext_mod->cancel = _cancel;
2446    ext_mod->copy = _copy;
2447    ext_mod->cut = _cut;
2448    ext_mod->paste = _paste;
2449    ext_mod->select = _select;
2450    ext_mod->selectall = _selectall;
2451    ext_mod->ent = wd->ent;
2452    ext_mod->items = wd->items;
2453    ext_mod->longpress_timer = wd->longpress_timer;
2454    ext_mod->editable = wd->editable;
2455    ext_mod->have_selection = wd->have_selection;
2456    ext_mod->password = wd->password;
2457    ext_mod->selmode = wd->selmode;
2458    ext_mod->cnpinit = _cnpinit;
2459    ext_mod->context_menu = wd->context_menu;
2460    ext_mod->textonly = wd->textonly;
2461 }
2462
2463 /**
2464  * This sets the entry object not to line wrap.  All input will
2465  * be on a single line, and the entry box will extend with user input.
2466  *
2467  * @param obj The entry object
2468  * @param single_line If true, the text in the entry
2469  * will be on a single line.
2470  *
2471  * @ingroup Entry
2472  */
2473 EAPI void
2474 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2475 {
2476    ELM_CHECK_WIDTYPE(obj, widtype);
2477    Widget_Data *wd = elm_widget_data_get(obj);
2478    if (!wd) return;
2479    if (wd->single_line == single_line) return;
2480    wd->single_line = single_line;
2481    wd->linewrap = EINA_FALSE;
2482    wd->char_linewrap = EINA_FALSE;
2483    elm_entry_cnp_textonly_set(obj, EINA_TRUE);
2484    _theme_hook(obj);
2485 }
2486
2487 /**
2488  * This returns true if the entry has been set to single line mode.
2489  * See also elm_entry_single_line_set().
2490  *
2491  * @param obj The entry object
2492  * @return single_line If true, the text in the entry is set to display
2493  * on a single line.
2494  *
2495  * @ingroup Entry
2496  */
2497 EAPI Eina_Bool
2498 elm_entry_single_line_get(const Evas_Object *obj)
2499 {
2500    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2501    Widget_Data *wd = elm_widget_data_get(obj);
2502    if (!wd) return EINA_FALSE;
2503    return wd->single_line;
2504 }
2505
2506 /**
2507  * This sets the entry object to password mode.  All text entered
2508  * and/or displayed within the widget will be replaced with asterisks (*).
2509  *
2510  * @param obj The entry object
2511  * @param password If true, password mode is enabled.
2512  *
2513  * @ingroup Entry
2514  */
2515 EAPI void
2516 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2517 {
2518    ELM_CHECK_WIDTYPE(obj, widtype);
2519    Widget_Data *wd = elm_widget_data_get(obj);
2520    if (!wd) return;
2521    if (wd->password == password) return;
2522    wd->password = password;
2523    wd->single_line = EINA_TRUE;
2524    wd->linewrap = EINA_FALSE;
2525    wd->char_linewrap = EINA_FALSE;
2526    _theme_hook(obj);
2527 }
2528
2529 /**
2530  * This returns whether password mode is enabled.
2531  * See also elm_entry_password_set().
2532  *
2533  * @param obj The entry object
2534  * @return If true, the entry is set to display all characters
2535  * as asterisks (*).
2536  *
2537  * @ingroup Entry
2538  */
2539 EAPI Eina_Bool
2540 elm_entry_password_get(const Evas_Object *obj)
2541 {
2542    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2543    Widget_Data *wd = elm_widget_data_get(obj);
2544    if (!wd) return EINA_FALSE;
2545    return wd->password;
2546 }
2547
2548 /**
2549  * This sets the text displayed within the entry to @p entry.
2550  *
2551  * @param obj The entry object
2552  * @param entry The text to be displayed
2553  *
2554  * @ingroup Entry
2555  */
2556 EAPI void
2557 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2558 {
2559    ELM_CHECK_WIDTYPE(obj, widtype);
2560    Widget_Data *wd = elm_widget_data_get(obj);
2561    if (!wd) return;
2562    if (!entry) entry = "";
2563    if(wd->max_no_of_bytes)
2564      {
2565         int len = strlen(entry);
2566         if(len > wd->max_no_of_bytes)
2567           {
2568              ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2569              return;
2570           }
2571      }
2572    edje_object_part_text_set(wd->ent, "elm.text", entry);
2573    if (wd->text) eina_stringshare_del(wd->text);
2574    wd->text = NULL;
2575    wd->changed = EINA_TRUE;
2576    _sizing_eval(obj);
2577 }
2578
2579 /**
2580  * This returns the text currently shown in object @p entry.
2581  * See also elm_entry_entry_set().
2582  *
2583  * @param obj The entry object
2584  * @return The currently displayed text or NULL on failure
2585  *
2586  * @ingroup Entry
2587  */
2588 EAPI const char *
2589 elm_entry_entry_get(const Evas_Object *obj)
2590 {
2591    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2592    Widget_Data *wd = elm_widget_data_get(obj);
2593    const char *text;
2594    if (!wd) return NULL;
2595
2596    if ((wd->text)&&(wd->password))
2597      return elm_entry_markup_to_utf8(wd->text);
2598
2599    if (wd->text) return wd->text;
2600    text = edje_object_part_text_get(wd->ent, "elm.text");
2601    if (!text)
2602      {
2603         ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2604         return NULL;
2605      }
2606    eina_stringshare_replace(&wd->text, text);
2607    if(wd->password)return elm_entry_markup_to_utf8(wd->text);
2608    return wd->text;
2609 }
2610
2611 /**
2612  * This returns EINA_TRUE if the entry is empty/there was an error
2613  * and EINA_FALSE if it is not empty.
2614  *
2615  * @param obj The entry object
2616  * @return If the entry is empty or not.
2617  *
2618  * @ingroup Entry
2619  */
2620 EAPI Eina_Bool
2621 elm_entry_is_empty(const Evas_Object *obj)
2622 {
2623    /* FIXME: until there's support for that in textblock, we just check
2624     * to see if the there is text or not. */
2625    ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
2626    Widget_Data *wd = elm_widget_data_get(obj);
2627    const Evas_Object *tb;
2628    //Evas_Textblock_Cursor *cur;
2629    Eina_Bool ret;
2630    if (!wd) return EINA_TRUE;
2631
2632 #if 0   
2633    /* It's a hack until we get the support suggested above.
2634     * We just create a cursor, point it to the begining, and then
2635     * try to advance it, if it can advance, the tb is not empty,
2636     * otherwise it is. */
2637    tb = edje_object_part_object_get(wd->ent, "elm.text");
2638    cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
2639                                                                   actually, ok for the time being, thsese hackish stuff will be removed
2640                                                                   once evas 1.0 is out*/
2641    evas_textblock_cursor_pos_set(cur, 0);
2642    ret = evas_textblock_cursor_char_next(cur);
2643    evas_textblock_cursor_free(cur);
2644
2645    return !ret;
2646 #endif
2647
2648    char *str = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
2649    if (!str) return EINA_TRUE;
2650
2651    ret = (strlen(str) == 0);
2652
2653    return ret;
2654 }
2655
2656 /**
2657  * This returns all selected text within the entry.
2658  *
2659  * @param obj The entry object
2660  * @return The selected text within the entry or NULL on failure
2661  *
2662  * @ingroup Entry
2663  */
2664 EAPI const char *
2665 elm_entry_selection_get(const Evas_Object *obj)
2666 {
2667    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2668    Widget_Data *wd = elm_widget_data_get(obj);
2669    if (!wd) return NULL;
2670    return edje_object_part_text_selection_get(wd->ent, "elm.text");
2671 }
2672
2673 /**
2674  * This inserts text in @p entry where the current cursor position.
2675  *
2676  * This inserts text at the cursor position is as if it was typed
2677  * by the user (note this also allows markup which a user
2678  * can't just "type" as it would be converted to escaped text, so this
2679  * call can be used to insert things like emoticon items or bold push/pop
2680  * tags, other font and color change tags etc.)
2681  *
2682  * @param obj The entry object
2683  * @param entry The text to insert
2684  *
2685  * @ingroup Entry
2686  */
2687 EAPI void
2688 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2689 {
2690    ELM_CHECK_WIDTYPE(obj, widtype);
2691    Widget_Data *wd = elm_widget_data_get(obj);
2692    if (!wd) return;
2693    edje_object_part_text_insert(wd->ent, "elm.text", entry);
2694    // start for cbhm
2695 #ifdef HAVE_ELEMENTARY_X
2696    if (cnpwidgetdata == obj)
2697       ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
2698 #endif
2699    // end for cbhm
2700    wd->changed = EINA_TRUE;
2701    _sizing_eval(obj);
2702 }
2703
2704 /**
2705  * This enables word line wrapping in the entry object.  It is the opposite
2706  * of elm_entry_single_line_set().  Additionally, setting this disables
2707  * character line wrapping.
2708  * See also elm_entry_line_char_wrap_set().
2709  *
2710  * @param obj The entry object
2711  * @param wrap If true, the entry will be wrapped once it reaches the end
2712  * of the object. Wrapping will occur at the end of the word before the end of the
2713  * object.
2714  *
2715  * @ingroup Entry
2716  */
2717 EAPI void
2718 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2719 {
2720    ELM_CHECK_WIDTYPE(obj, widtype);
2721    Widget_Data *wd = elm_widget_data_get(obj);
2722    if (!wd) return;
2723    if (wd->linewrap == wrap) return;
2724    wd->linewrap = wrap;
2725    if(wd->linewrap)
2726      wd->char_linewrap = EINA_FALSE;
2727    _theme_hook(obj);
2728 }
2729
2730 /**
2731  * Set wrap width of the entry
2732  *
2733  * @param obj The entry object
2734  * @param w The wrap width in pixels at a minimum where words need to wrap
2735  * @ingroup Entry
2736  */
2737 EAPI void
2738 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2739 {
2740    Widget_Data *wd = elm_widget_data_get(obj);
2741    if (wd->wrap_w == w) return;
2742    wd->wrap_w = w;
2743    _sizing_eval(obj);
2744 }
2745
2746 /**
2747  * get wrap width of the entry
2748  *
2749  * @param obj The entry object
2750  * @return The wrap width in pixels at a minimum where words need to wrap
2751  * @ingroup Entry
2752  */
2753 EAPI Evas_Coord
2754 elm_entry_wrap_width_get(const Evas_Object *obj)
2755 {
2756    Widget_Data *wd = elm_widget_data_get(obj);
2757    return wd->wrap_w;
2758 }
2759
2760 /**
2761  * This enables character line wrapping in the entry object.  It is the opposite
2762  * of elm_entry_single_line_set().  Additionally, setting this disables
2763  * word line wrapping.
2764  * See also elm_entry_line_wrap_set().
2765  *
2766  * @param obj The entry object
2767  * @param wrap If true, the entry will be wrapped once it reaches the end
2768  * of the object. Wrapping will occur immediately upon reaching the end of the object.
2769  *
2770  * @ingroup Entry
2771  */
2772 EAPI void
2773 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2774 {
2775    ELM_CHECK_WIDTYPE(obj, widtype);
2776    Widget_Data *wd = elm_widget_data_get(obj);
2777    if (!wd) return;
2778    if (wd->char_linewrap == wrap) return;
2779    wd->char_linewrap = wrap;
2780    if(wd->char_linewrap)
2781      wd->linewrap = EINA_FALSE;
2782    _theme_hook(obj);
2783 }
2784
2785 /**
2786  * This sets the editable attribute of the entry.
2787  *
2788  * @param obj The entry object
2789  * @param editable If true, the entry will be editable by the user.
2790  * If false, it will be set to the disabled state.
2791  *
2792  * @ingroup Entry
2793  */
2794 EAPI void
2795 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2796 {
2797    ELM_CHECK_WIDTYPE(obj, widtype);
2798    Widget_Data *wd = elm_widget_data_get(obj);
2799    if (!wd) return;
2800    if (wd->editable == editable) return;
2801    wd->editable = editable;
2802    _theme_hook(obj);
2803
2804 #ifdef HAVE_ELEMENTARY_X
2805    if (editable)
2806      elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2807    else
2808      elm_drop_target_del(obj);
2809 #endif
2810 }
2811
2812 /**
2813  * This gets the editable attribute of the entry.
2814  * See also elm_entry_editable_set().
2815  *
2816  * @param obj The entry object
2817  * @return If true, the entry is editable by the user.
2818  * If false, it is not editable by the user
2819  *
2820  * @ingroup Entry
2821  */
2822 EAPI Eina_Bool
2823 elm_entry_editable_get(const Evas_Object *obj)
2824 {
2825    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2826    Widget_Data *wd = elm_widget_data_get(obj);
2827    if (!wd) return EINA_FALSE;
2828    return wd->editable;
2829 }
2830
2831 /**
2832  * This drops any existing text selection within the entry.
2833  *
2834  * @param obj The entry object
2835  *
2836  * @ingroup Entry
2837  */
2838 EAPI void
2839 elm_entry_select_none(Evas_Object *obj)
2840 {
2841    ELM_CHECK_WIDTYPE(obj, widtype);
2842    Widget_Data *wd = elm_widget_data_get(obj);
2843    if (!wd) return;
2844    if (wd->selmode)
2845      {
2846         wd->selmode = EINA_FALSE;
2847         if (!_elm_config->desktop_entry)
2848            edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2849         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2850      }
2851    wd->have_selection = EINA_FALSE;
2852    edje_object_part_text_select_none(wd->ent, "elm.text");
2853 }
2854
2855 /**
2856  * This selects all text within the entry.
2857  *
2858  * @param obj The entry object
2859  *
2860  * @ingroup Entry
2861  */
2862 EAPI void
2863 elm_entry_select_all(Evas_Object *obj)
2864 {
2865    ELM_CHECK_WIDTYPE(obj, widtype);
2866    Widget_Data *wd = elm_widget_data_get(obj);
2867    if (!wd) return;
2868    if (wd->selmode)
2869      {
2870         wd->selmode = EINA_FALSE;
2871         if (!_elm_config->desktop_entry)
2872            edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2873         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2874      }
2875    wd->have_selection = EINA_TRUE;
2876    edje_object_part_text_select_all(wd->ent, "elm.text");
2877 }
2878
2879 /**
2880  * This function returns the geometry of the cursor.
2881  *
2882  * It's useful if you want to draw something on the cursor (or where it is),
2883  * or for example in the case of scrolled entry where you want to show the
2884  * cursor.
2885  *
2886  * @param obj The entry object
2887  * @param x returned geometry
2888  * @param y returned geometry
2889  * @param w returned geometry
2890  * @param h returned geometry
2891  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2892  *
2893  * @ingroup Entry
2894  */
2895 EAPI Eina_Bool
2896 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
2897 {
2898    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2899    Widget_Data *wd = elm_widget_data_get(obj);
2900    if (!wd) return EINA_FALSE;
2901    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
2902    return EINA_TRUE;
2903 }
2904
2905 /**
2906  * This moves the cursor one place to the right within the entry.
2907  *
2908  * @param obj The entry object
2909  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2910  *
2911  * @ingroup Entry
2912  */
2913 EAPI Eina_Bool
2914 elm_entry_cursor_next(Evas_Object *obj)
2915 {
2916    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2917    Widget_Data *wd = elm_widget_data_get(obj);
2918    if (!wd) return EINA_FALSE;
2919    return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2920 }
2921
2922 /**
2923  * This moves the cursor one place to the left within the entry.
2924  *
2925  * @param obj The entry object
2926  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2927  *
2928  * @ingroup Entry
2929  */
2930 EAPI Eina_Bool
2931 elm_entry_cursor_prev(Evas_Object *obj)
2932 {
2933    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2934    Widget_Data *wd = elm_widget_data_get(obj);
2935    if (!wd) return EINA_FALSE;
2936    return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2937 }
2938
2939 /**
2940  * This moves the cursor one line up within the entry.
2941  *
2942  * @param obj The entry object
2943  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2944  *
2945  * @ingroup Entry
2946  */
2947 EAPI Eina_Bool
2948 elm_entry_cursor_up(Evas_Object *obj)
2949 {
2950    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2951    Widget_Data *wd = elm_widget_data_get(obj);
2952    if (!wd) return EINA_FALSE;
2953    return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2954 }
2955
2956 /**
2957  * This moves the cursor one line down within the entry.
2958  *
2959  * @param obj The entry object
2960  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2961  *
2962  * @ingroup Entry
2963  */
2964 EAPI Eina_Bool
2965 elm_entry_cursor_down(Evas_Object *obj)
2966 {
2967    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2968    Widget_Data *wd = elm_widget_data_get(obj);
2969    if (!wd) return EINA_FALSE;
2970    return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2971 }
2972
2973 /**
2974  * This moves the cursor to the beginning of the entry.
2975  *
2976  * @param obj The entry object
2977  *
2978  * @ingroup Entry
2979  */
2980 EAPI void
2981 elm_entry_cursor_begin_set(Evas_Object *obj)
2982 {
2983    ELM_CHECK_WIDTYPE(obj, widtype);
2984    Widget_Data *wd = elm_widget_data_get(obj);
2985    if (!wd) return;
2986    edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2987 }
2988
2989 /**
2990  * This moves the cursor to the end of the entry.
2991  *
2992  * @param obj The entry object
2993  *
2994  * @ingroup Entry
2995  */
2996 EAPI void
2997 elm_entry_cursor_end_set(Evas_Object *obj)
2998 {
2999    ELM_CHECK_WIDTYPE(obj, widtype);
3000    Widget_Data *wd = elm_widget_data_get(obj);
3001    if (!wd) return;
3002    edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3003 }
3004
3005 /**
3006  * This moves the cursor to the beginning of the current line.
3007  *
3008  * @param obj The entry object
3009  *
3010  * @ingroup Entry
3011  */
3012 EAPI void
3013 elm_entry_cursor_line_begin_set(Evas_Object *obj)
3014 {
3015    ELM_CHECK_WIDTYPE(obj, widtype);
3016    Widget_Data *wd = elm_widget_data_get(obj);
3017    if (!wd) return;
3018    edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3019 }
3020
3021 /**
3022  * This moves the cursor to the end of the current line.
3023  *
3024  * @param obj The entry object
3025  *
3026  * @ingroup Entry
3027  */
3028 EAPI void
3029 elm_entry_cursor_line_end_set(Evas_Object *obj)
3030 {
3031    ELM_CHECK_WIDTYPE(obj, widtype);
3032    Widget_Data *wd = elm_widget_data_get(obj);
3033    if (!wd) return;
3034    edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3035 }
3036
3037 /**
3038  * This begins a selection within the entry as though
3039  * the user were holding down the mouse button to make a selection.
3040  *
3041  * @param obj The entry object
3042  *
3043  * @ingroup Entry
3044  */
3045 EAPI void
3046 elm_entry_cursor_selection_begin(Evas_Object *obj)
3047 {
3048    ELM_CHECK_WIDTYPE(obj, widtype);
3049    Widget_Data *wd = elm_widget_data_get(obj);
3050    if (!wd) return;
3051    edje_object_part_text_select_begin(wd->ent, "elm.text");
3052 }
3053
3054 /**
3055  * This ends a selection within the entry as though
3056  * the user had just released the mouse button while making a selection.
3057  *
3058  * @param obj The entry object
3059  *
3060  * @ingroup Entry
3061  */
3062 EAPI void
3063 elm_entry_cursor_selection_end(Evas_Object *obj)
3064 {
3065    ELM_CHECK_WIDTYPE(obj, widtype);
3066    Widget_Data *wd = elm_widget_data_get(obj);
3067    if (!wd) return;
3068    edje_object_part_text_select_extend(wd->ent, "elm.text");
3069 }
3070
3071 /**
3072  * TODO: fill this in
3073  *
3074  * @param obj The entry object
3075  * @return TODO: fill this in
3076  *
3077  * @ingroup Entry
3078  */
3079 EAPI Eina_Bool
3080 elm_entry_cursor_is_format_get(const Evas_Object *obj)
3081 {
3082    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3083    Widget_Data *wd = elm_widget_data_get(obj);
3084    if (!wd) return EINA_FALSE;
3085    return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3086 }
3087
3088 /**
3089  * This returns whether the cursor is visible.
3090  *
3091  * @param obj The entry object
3092  * @return If true, the cursor is visible.
3093  *
3094  * @ingroup Entry
3095  */
3096 EAPI Eina_Bool
3097 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
3098 {
3099    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3100    Widget_Data *wd = elm_widget_data_get(obj);
3101    if (!wd) return EINA_FALSE;
3102    return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3103 }
3104
3105 /**
3106  * TODO: fill this in
3107  *
3108  * @param obj The entry object
3109  * @return TODO: fill this in
3110  *
3111  * @ingroup Entry
3112  */
3113 EAPI const char *
3114 elm_entry_cursor_content_get(const Evas_Object *obj)
3115 {
3116    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3117    Widget_Data *wd = elm_widget_data_get(obj);
3118    if (!wd) return NULL;
3119    return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3120 }
3121
3122 /**
3123  * Sets the cursor position in the entry to the given value
3124  *
3125  * @param obj The entry object
3126  * @param pos The position of the cursor
3127  *
3128  * @ingroup Entry
3129  */
3130 EAPI void
3131 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
3132 {
3133    ELM_CHECK_WIDTYPE(obj, widtype);
3134    Widget_Data *wd = elm_widget_data_get(obj);
3135    if (!wd) return;
3136    edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
3137    edje_object_message_signal_process(wd->ent);
3138 }
3139
3140 /**
3141  * Retrieves the current position of the cursor in the entry
3142  *
3143  * @param obj The entry object
3144  * @return The cursor position
3145  *
3146  * @ingroup Entry
3147  */
3148 EAPI int
3149 elm_entry_cursor_pos_get(const Evas_Object *obj)
3150 {
3151    ELM_CHECK_WIDTYPE(obj, widtype) 0;
3152    Widget_Data *wd = elm_widget_data_get(obj);
3153    if (!wd) return 0;
3154    return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3155 }
3156
3157 /**
3158  * This executes a "cut" action on the selected text in the entry.
3159  *
3160  * @param obj The entry object
3161  *
3162  * @ingroup Entry
3163  */
3164 EAPI void
3165 elm_entry_selection_cut(Evas_Object *obj)
3166 {
3167    ELM_CHECK_WIDTYPE(obj, widtype);
3168    Widget_Data *wd = elm_widget_data_get(obj);
3169    if (!wd) return;
3170    _cut(obj, NULL, NULL);
3171 }
3172
3173 /**
3174  * This executes a "copy" action on the selected text in the entry.
3175  *
3176  * @param obj The entry object
3177  *
3178  * @ingroup Entry
3179  */
3180 EAPI void
3181 elm_entry_selection_copy(Evas_Object *obj)
3182 {
3183    ELM_CHECK_WIDTYPE(obj, widtype);
3184    Widget_Data *wd = elm_widget_data_get(obj);
3185    if (!wd) return;
3186    _copy(obj, NULL, NULL);
3187 }
3188
3189 /**
3190  * This executes a "paste" action in the entry.
3191  *
3192  * @param obj The entry object
3193  *
3194  * @ingroup Entry
3195  */
3196 EAPI void
3197 elm_entry_selection_paste(Evas_Object *obj)
3198 {
3199    ELM_CHECK_WIDTYPE(obj, widtype);
3200    Widget_Data *wd = elm_widget_data_get(obj);
3201    if (!wd) return;
3202    _paste(obj, NULL, NULL);
3203 }
3204
3205 /**
3206  * This clears and frees the items in a entry's contextual (right click) menu.
3207  *
3208  * @param obj The entry object
3209  *
3210  * @ingroup Entry
3211  */
3212 EAPI void
3213 elm_entry_context_menu_clear(Evas_Object *obj)
3214 {
3215    ELM_CHECK_WIDTYPE(obj, widtype);
3216    Widget_Data *wd = elm_widget_data_get(obj);
3217    Elm_Entry_Context_Menu_Item *it;
3218    if (!wd) return;
3219    EINA_LIST_FREE(wd->items, it)
3220      {
3221         eina_stringshare_del(it->label);
3222         eina_stringshare_del(it->icon_file);
3223         eina_stringshare_del(it->icon_group);
3224         free(it);
3225      }
3226 }
3227
3228 /**
3229  * This adds an item to the entry's contextual menu.
3230  *
3231  * @param obj The entry object
3232  * @param label The item's text label
3233  * @param icon_file The item's icon file
3234  * @param icon_type The item's icon type
3235  * @param func The callback to execute when the item is clicked
3236  * @param data The data to associate with the item for related functions
3237  *
3238  * @ingroup Entry
3239  */
3240 EAPI void
3241 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)
3242 {
3243    ELM_CHECK_WIDTYPE(obj, widtype);
3244    Widget_Data *wd = elm_widget_data_get(obj);
3245    Elm_Entry_Context_Menu_Item *it;
3246    if (!wd) return;
3247    it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
3248    if (!it) return;
3249    wd->items = eina_list_append(wd->items, it);
3250    it->obj = obj;
3251    it->label = eina_stringshare_add(label);
3252    it->icon_file = eina_stringshare_add(icon_file);
3253    it->icon_type = icon_type;
3254    it->func = func;
3255    it->data = (void *)data;
3256 }
3257
3258 /**
3259  * This disables the entry's contextual (right click) menu.
3260  *
3261  * @param obj The entry object
3262  * @param disabled If true, the menu is disabled
3263  *
3264  * @ingroup Entry
3265  */
3266 EAPI void
3267 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
3268 {
3269    ELM_CHECK_WIDTYPE(obj, widtype);
3270    Widget_Data *wd = elm_widget_data_get(obj);
3271    if (!wd) return;
3272    if (wd->context_menu == !disabled) return;
3273    wd->context_menu = !disabled;
3274 }
3275
3276 /**
3277  * This returns whether the entry's contextual (right click) menu is disabled.
3278  *
3279  * @param obj The entry object
3280  * @return If true, the menu is disabled
3281  *
3282  * @ingroup Entry
3283  */
3284 EAPI Eina_Bool
3285 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
3286 {
3287    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3288    Widget_Data *wd = elm_widget_data_get(obj);
3289    if (!wd) return EINA_FALSE;
3290    return !wd->context_menu;
3291 }
3292
3293 /**
3294  * This appends a custom item provider to the list for that entry
3295  *
3296  * This appends the given callback. The list is walked from beginning to end
3297  * with each function called given the item href string in the text. If the
3298  * function returns an object handle other than NULL (it should create an
3299  * and object to do this), then this object is used to replace that item. If
3300  * not the next provider is called until one provides an item object, or the
3301  * default provider in entry does.
3302  *
3303  * @param obj The entry object
3304  * @param func The function called to provide the item object
3305  * @param data The data passed to @p func
3306  *
3307  * @ingroup Entry
3308  */
3309 EAPI void
3310 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3311 {
3312    ELM_CHECK_WIDTYPE(obj, widtype);
3313    Widget_Data *wd = elm_widget_data_get(obj);
3314    if (!wd) return;
3315    EINA_SAFETY_ON_NULL_RETURN(func);
3316    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3317    if (!ip) return;
3318    ip->func = func;
3319    ip->data = data;
3320    wd->item_providers = eina_list_append(wd->item_providers, ip);
3321 }
3322
3323 /**
3324  * This prepends a custom item provider to the list for that entry
3325  *
3326  * This prepends the given callback. See elm_entry_item_provider_append() for
3327  * more information
3328  *
3329  * @param obj The entry object
3330  * @param func The function called to provide the item object
3331  * @param data The data passed to @p func
3332  *
3333  * @ingroup Entry
3334  */
3335 EAPI void
3336 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3337 {
3338    ELM_CHECK_WIDTYPE(obj, widtype);
3339    Widget_Data *wd = elm_widget_data_get(obj);
3340    if (!wd) return;
3341    EINA_SAFETY_ON_NULL_RETURN(func);
3342    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3343    if (!ip) return;
3344    ip->func = func;
3345    ip->data = data;
3346    wd->item_providers = eina_list_prepend(wd->item_providers, ip);
3347 }
3348
3349 /**
3350  * This removes a custom item provider to the list for that entry
3351  *
3352  * This removes the given callback. See elm_entry_item_provider_append() for
3353  * more information
3354  *
3355  * @param obj The entry object
3356  * @param func The function called to provide the item object
3357  * @param data The data passed to @p func
3358  *
3359  * @ingroup Entry
3360  */
3361 EAPI void
3362 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3363 {
3364    ELM_CHECK_WIDTYPE(obj, widtype);
3365    Widget_Data *wd = elm_widget_data_get(obj);
3366    Eina_List *l;
3367    Elm_Entry_Item_Provider *ip;
3368    if (!wd) return;
3369    EINA_SAFETY_ON_NULL_RETURN(func);
3370    EINA_LIST_FOREACH(wd->item_providers, l, ip)
3371      {
3372         if ((ip->func == func) && ((!data) || (ip->data == data)))
3373           {
3374              wd->item_providers = eina_list_remove_list(wd->item_providers, l);
3375              free(ip);
3376              return;
3377           }
3378      }
3379 }
3380
3381 /**
3382  * Append a filter function for text inserted in the entry
3383  *
3384  * Append the given callback to the list. This functions will be called
3385  * whenever any text is inserted into the entry, with the text to be inserted
3386  * as a parameter. The callback function is free to alter the text in any way
3387  * it wants, but it must remember to free the given pointer and update it.
3388  * If the new text is to be discarded, the function can free it and set it text
3389  * parameter to NULL. This will also prevent any following filters from being
3390  * called.
3391  *
3392  * @param obj The entry object
3393  * @param func The function to use as text filter
3394  * @param data User data to pass to @p func
3395  *
3396  * @ingroup Entry
3397  */
3398 EAPI void
3399 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3400 {
3401    Widget_Data *wd;
3402    Elm_Entry_Text_Filter *tf;
3403    ELM_CHECK_WIDTYPE(obj, widtype);
3404
3405    wd = elm_widget_data_get(obj);
3406
3407    EINA_SAFETY_ON_NULL_RETURN(func);
3408
3409    tf = _filter_new(func, data);
3410    if (!tf) return;
3411
3412    wd->text_filters = eina_list_append(wd->text_filters, tf);
3413 }
3414
3415 /**
3416  * Prepend a filter function for text insdrted in the entry
3417  *
3418  * Prepend the given callback to the list. See elm_entry_text_filter_append()
3419  * for more information
3420  *
3421  * @param obj The entry object
3422  * @param func The function to use as text filter
3423  * @param data User data to pass to @p func
3424  *
3425  * @ingroup Entry
3426  */
3427 EAPI void
3428 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3429 {
3430    Widget_Data *wd;
3431    Elm_Entry_Text_Filter *tf;
3432    ELM_CHECK_WIDTYPE(obj, widtype);
3433
3434    wd = elm_widget_data_get(obj);
3435
3436    EINA_SAFETY_ON_NULL_RETURN(func);
3437
3438    tf = _filter_new(func, data);
3439    if (!tf) return;
3440
3441    wd->text_filters = eina_list_prepend(wd->text_filters, tf);
3442 }
3443
3444 /**
3445  * Remove a filter from the list
3446  *
3447  * Removes the given callback from the filter list. See elm_entry_text_filter_append()
3448  * for more information.
3449  *
3450  * @param obj The entry object
3451  * @param func The filter function to remove
3452  * @param data The user data passed when adding the function
3453  *
3454  * @ingroup Entry
3455  */
3456 EAPI void
3457 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3458 {
3459    Widget_Data *wd;
3460    Eina_List *l;
3461    Elm_Entry_Text_Filter *tf;
3462    ELM_CHECK_WIDTYPE(obj, widtype);
3463
3464    wd = elm_widget_data_get(obj);
3465
3466    EINA_SAFETY_ON_NULL_RETURN(func);
3467
3468    EINA_LIST_FOREACH(wd->text_filters, l, tf)
3469      {
3470         if ((tf->func == func) && ((!data) || (tf->data == data)))
3471           {
3472              wd->text_filters = eina_list_remove_list(wd->text_filters, l);
3473              _filter_free(tf);
3474              return;
3475           }
3476      }
3477 }
3478
3479 /**
3480  * This converts a markup (HTML-like) string into UTF-8.
3481  * Returning string is obtained with malloc.
3482  * After use the returned string, it should be freed.
3483  *
3484  * @param s The string (in markup) to be converted
3485  * @return The converted string (in UTF-8). It should be freed.
3486  *
3487  * @ingroup Entry
3488  */
3489 EAPI char *
3490 elm_entry_markup_to_utf8(const char *s)
3491 {
3492    char *ss = _elm_util_mkup_to_text(s);
3493    if (!ss) ss = strdup("");
3494    return ss;
3495 }
3496
3497 /**
3498  * This converts a UTF-8 string into markup (HTML-like).
3499  * Returning string is obtained with malloc.
3500  * After use the returned string, it should be freed.
3501  *
3502  * @param s The string (in UTF-8) to be converted
3503  * @return The converted string (in markup). It should be freed.
3504  *
3505  * @ingroup Entry
3506  */
3507 EAPI char *
3508 elm_entry_utf8_to_markup(const char *s)
3509 {
3510    char *ss = _elm_util_text_to_mkup(s);
3511    if (!ss) ss = strdup("");
3512    return ss;
3513 }
3514
3515 /**
3516  * Get the input method context in the entry widget
3517  *
3518  * @param obj The entry object
3519  * @return The input method context
3520  *
3521  * @ingroup Entry
3522  */
3523 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
3524 {
3525    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3526    Widget_Data *wd = elm_widget_data_get(obj);
3527    if (!wd || !wd->ent) return NULL;
3528
3529    return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
3530 }
3531
3532 /**
3533  * Set whether entry should enable the return key on soft keyboard automatically
3534  *
3535  * @param obj The entry object
3536  * @param on If true, entry enables the return key on soft keyboard automatically.
3537  *
3538  * @ingroup Entry
3539  */
3540 EAPI void
3541 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
3542 {
3543    ELM_CHECK_WIDTYPE(obj, widtype);
3544    Widget_Data *wd = elm_widget_data_get(obj);
3545    if (!wd) return;
3546
3547    wd->autoreturnkey = on;
3548    _check_enable_returnkey(obj);
3549 }
3550
3551 /**
3552  * Set whether entry should support auto capitalization
3553  *
3554  * @param obj The entry object
3555  * @param on If true, entry suports auto capitalization.
3556  *
3557  * @ingroup Entry
3558  */
3559 EAPI void
3560 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
3561 {
3562    ELM_CHECK_WIDTYPE(obj, widtype);
3563    Widget_Data *wd = elm_widget_data_get(obj);
3564    if (!wd) return;
3565
3566    if (wd->password)
3567      wd->autocapital = EINA_FALSE;
3568    else
3569      wd->autocapital = autocap;
3570
3571    if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3572        wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3573      wd->autocapital = EINA_FALSE;
3574
3575    edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
3576 }
3577
3578 /**
3579  * Set whether entry should support auto period
3580  *
3581  * @param obj The entry object
3582  * @param on If true, entry suports auto period.
3583  *
3584  * @ingroup Entry
3585  */
3586 EAPI void
3587 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
3588 {
3589    ELM_CHECK_WIDTYPE(obj, widtype);
3590    Widget_Data *wd = elm_widget_data_get(obj);
3591    if (!wd) return;
3592
3593    if (wd->password)
3594      wd->autoperiod = EINA_FALSE;
3595    else
3596      wd->autoperiod = autoperiod;
3597
3598    if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3599        wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3600      wd->autoperiod = EINA_FALSE;
3601
3602    edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
3603 }
3604
3605 /**
3606  * Set the font size on the entry object
3607  *
3608  * @param obj The entry object
3609  * @param size font size
3610  *
3611  * @ingroup Entry
3612  */
3613 EAPI void
3614 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
3615 {
3616    ELM_CHECK_WIDTYPE(obj, widtype);
3617    Widget_Data *wd = elm_widget_data_get(obj);
3618    Eina_Strbuf *fontbuf = NULL;
3619    int removeflag = 0;
3620    const char *t;
3621
3622    if (!wd) return;
3623    t = eina_stringshare_add(elm_entry_entry_get(obj));
3624    fontbuf = eina_strbuf_new();
3625    eina_strbuf_append_printf(fontbuf, "%d", fontsize);
3626
3627    if (fontsize == 0) removeflag = 1; // remove fontsize tag
3628
3629    if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
3630      {
3631        elm_entry_entry_set(obj, t);
3632        wd->changed = 1;
3633        _sizing_eval(obj);
3634      }
3635    eina_strbuf_free(fontbuf);
3636    eina_stringshare_del(t);
3637 }
3638
3639 /**
3640  * Set the text align on the entry object
3641  *
3642  * @param obj The entry object
3643  * @param align align mode
3644  *
3645  * @ingroup Entry
3646  */
3647 EAPI void
3648 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
3649 {
3650    ELM_CHECK_WIDTYPE(obj, widtype);
3651    Widget_Data *wd = elm_widget_data_get(obj);
3652    int len;
3653    const char *t;
3654
3655    if (!wd) return;
3656    t = eina_stringshare_add(elm_entry_entry_get(obj));
3657    len = strlen(t);
3658    if (len <= 0) return;
3659
3660    if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
3661      elm_entry_entry_set(obj, t);
3662
3663    wd->changed = 1;
3664    _sizing_eval(obj);
3665    eina_stringshare_del(t);
3666 }
3667
3668 /**
3669  * Set the text color on the entry object
3670  *
3671  * @param obj The entry object
3672  * @param r Red property background color of The entry object 
3673  * @param g Green property background color of The entry object 
3674  * @param b Blue property background color of The entry object 
3675  * @param a Alpha property background alpha of The entry object 
3676  *
3677  * @ingroup Entry
3678  */
3679 EAPI void
3680 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3681 {
3682    ELM_CHECK_WIDTYPE(obj, widtype);
3683    Widget_Data *wd = elm_widget_data_get(obj);
3684    Eina_Strbuf *colorbuf = NULL;
3685    const char *t;
3686    int len;
3687
3688    if (!wd) return;
3689    t = eina_stringshare_add(elm_entry_entry_get(obj));
3690    len = strlen(t);
3691    if (len <= 0) return;
3692    colorbuf = eina_strbuf_new();
3693    eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
3694
3695    if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
3696      {
3697        elm_entry_entry_set(obj, t);
3698        wd->changed = 1;
3699        _sizing_eval(obj);
3700      }
3701    eina_strbuf_free(colorbuf);
3702    eina_stringshare_del(t);
3703 }
3704
3705 /**
3706  * Set background color of the entry
3707  *
3708  * @param obj The entry object
3709  * @param r Red property background color of The entry object 
3710  * @param g Green property background color of The entry object 
3711  * @param b Blue property background color of The entry object 
3712  * @param a Alpha property background alpha of The entry object 
3713  * @ingroup Entry
3714  */
3715 EAPI void
3716 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3717 {
3718    ELM_CHECK_WIDTYPE(obj, widtype);
3719    Widget_Data *wd = elm_widget_data_get(obj);
3720    evas_object_color_set(wd->bg, r, g, b, a);
3721
3722    if (wd->bgcolor == EINA_FALSE)
3723      {
3724        wd->bgcolor = 1;
3725        edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3726      }
3727 }
3728
3729 /**
3730  * Filter inserted text based on user defined character and byte limits
3731  *
3732  * Add this filter to an entry to limit the characters that it will accept
3733  * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
3734  * The funtion works on the UTF-8 representation of the string, converting
3735  * it from the set markup, thus not accounting for any format in it.
3736  *
3737  * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
3738  * it as data when setting the filter. In it it's possible to set limits
3739  * by character count or bytes (any of them is disabled if 0), and both can
3740  * be set at the same time. In that case, it first checks for characters,
3741  * then bytes.
3742  *
3743  * The function will cut the inserted text in order to allow only the first
3744  * number of characters that are still allowed. The cut is made in
3745  * characters, even when limiting by bytes, in order to always contain
3746  * valid ones and avoid half unicode characters making it in.
3747  *
3748  * @ingroup Entry
3749  */
3750 EAPI void
3751 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
3752 {
3753    Elm_Entry_Filter_Limit_Size *lim = data;
3754    char *current;
3755    int len, newlen;
3756    const char *(*text_get)(const Evas_Object *);
3757    const char *widget_type;
3758
3759    EINA_SAFETY_ON_NULL_RETURN(data);
3760    EINA_SAFETY_ON_NULL_RETURN(entry);
3761    EINA_SAFETY_ON_NULL_RETURN(text);
3762
3763    /* hack. I don't want to copy the entire function to work with
3764     * scrolled_entry */
3765    widget_type = elm_widget_type_get(entry);
3766    if (!strcmp(widget_type, "entry"))
3767      text_get = elm_entry_entry_get;
3768    else if (!strcmp(widget_type, "scrolled_entry"))
3769      text_get = elm_scrolled_entry_entry_get;
3770    else /* huh? */
3771      return;
3772
3773    current = elm_entry_markup_to_utf8(text_get(entry));
3774
3775    if (lim->max_char_count > 0)
3776      {
3777         len = evas_string_char_len_get(current);
3778         if (len >= lim->max_char_count)
3779           {
3780              evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3781              free(*text);
3782              free(current);
3783              *text = NULL;
3784              return;
3785           }
3786         newlen = evas_string_char_len_get(elm_entry_markup_to_utf8(*text));
3787         if ((len + newlen) > lim->max_char_count)
3788           _add_chars_till_limit(entry, text, (lim->max_char_count - len), LENGTH_UNIT_CHAR);
3789      }
3790    else if (lim->max_byte_count > 0)
3791      {
3792         len = strlen(current);
3793         if (len >= lim->max_byte_count)
3794           {
3795              evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3796              free(*text);
3797              free(current);
3798              *text = NULL;
3799              return;
3800           }
3801         newlen = strlen(elm_entry_markup_to_utf8(*text));
3802         if ((len + newlen) > lim->max_byte_count)
3803           _add_chars_till_limit(entry, text, (lim->max_byte_count - len), LENGTH_UNIT_BYTE);
3804      }
3805    free(current);
3806 }
3807
3808 /**
3809  * Filter inserted text based on accepted or rejected sets of characters
3810  *
3811  * Add this filter to an entry to restrict the set of accepted characters
3812  * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
3813  * This structure contains both accepted and rejected sets, but they are
3814  * mutually exclusive. If accepted is set, it will be used, otherwise it
3815  * goes on to the rejected set.
3816  */
3817 EAPI void
3818 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
3819 {
3820    Elm_Entry_Filter_Accept_Set *as = data;
3821    const char *set;
3822    char *insert;
3823    Eina_Bool goes_in;
3824    int read_idx, last_read_idx = 0, read_char;
3825
3826    EINA_SAFETY_ON_NULL_RETURN(data);
3827    EINA_SAFETY_ON_NULL_RETURN(text);
3828
3829    if ((!as->accepted) && (!as->rejected))
3830      return;
3831
3832    if (as->accepted)
3833      {
3834         set = as->accepted;
3835         goes_in = EINA_TRUE;
3836      }
3837    else
3838      {
3839         set = as->rejected;
3840         goes_in = EINA_FALSE;
3841      }
3842
3843    insert = *text;
3844    read_idx = evas_string_char_next_get(*text, 0, &read_char);
3845    while (read_char)
3846      {
3847         int cmp_idx, cmp_char;
3848         Eina_Bool in_set = EINA_FALSE;
3849
3850         cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
3851         while (cmp_char)
3852           {
3853              if (read_char == cmp_char)
3854                {
3855                   in_set = EINA_TRUE;
3856                   break;
3857                }
3858              cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
3859           }
3860         if (in_set == goes_in)
3861           {
3862              int size = read_idx - last_read_idx;
3863              const char *src = (*text) + last_read_idx;
3864              if (src != insert)
3865                memcpy(insert, *text + last_read_idx, size);
3866              insert += size;
3867           }
3868         last_read_idx = read_idx;
3869         read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
3870      }
3871    *insert = 0;
3872 }
3873
3874 /**
3875  * This sets the file (and implicitly loads it) for the text to display and
3876  * then edit. All changes are written back to the file after a short delay if
3877  * the entry object is set to autosave.
3878  *
3879  * @param obj The entry object
3880  * @param file The path to the file to load and save
3881  * @param format The file format
3882  *
3883  * @ingroup Entry
3884  */
3885 EAPI void
3886 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
3887 {
3888    ELM_CHECK_WIDTYPE(obj, widtype);
3889    Widget_Data *wd = elm_widget_data_get(obj);
3890    if (!wd) return;
3891    if (wd->delay_write)
3892      {
3893         ecore_timer_del(wd->delay_write);
3894         wd->delay_write = NULL;
3895      }
3896    if (wd->autosave) _save(obj);
3897    eina_stringshare_replace(&wd->file, file);
3898    wd->format = format;
3899    _load(obj);
3900 }
3901
3902 /**
3903  * Gets the file to load and save and the file format
3904  *
3905  * @param obj The entry object
3906  * @param file The path to the file to load and save
3907  * @param format The file format
3908  *
3909  * @ingroup Entry
3910  */
3911 EAPI void
3912 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
3913 {
3914    ELM_CHECK_WIDTYPE(obj, widtype);
3915    Widget_Data *wd = elm_widget_data_get(obj);
3916    if (!wd) return;
3917    if (file) *file = wd->file;
3918    if (format) *format = wd->format;
3919 }
3920
3921 /**
3922  * This function writes any changes made to the file set with
3923  * elm_entry_file_set()
3924  *
3925  * @param obj The entry object
3926  *
3927  * @ingroup Entry
3928  */
3929 EAPI void
3930 elm_entry_file_save(Evas_Object *obj)
3931 {
3932    ELM_CHECK_WIDTYPE(obj, widtype);
3933    Widget_Data *wd = elm_widget_data_get(obj);
3934    if (!wd) return;
3935    if (wd->delay_write)
3936      {
3937         ecore_timer_del(wd->delay_write);
3938         wd->delay_write = NULL;
3939      }
3940    _save(obj);
3941    wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
3942 }
3943
3944 /**
3945  * This sets the entry object to 'autosave' the loaded text file or not.
3946  *
3947  * @param obj The entry object
3948  * @param autosave Autosave the loaded file or not
3949  *
3950  * @ingroup Entry
3951  */
3952 EAPI void
3953 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
3954 {
3955    ELM_CHECK_WIDTYPE(obj, widtype);
3956    Widget_Data *wd = elm_widget_data_get(obj);
3957    if (!wd) return;
3958    wd->autosave = !!autosave;
3959 }
3960
3961 /**
3962  * This gets the entry object's 'autosave' status.
3963  *
3964  * @param obj The entry object
3965  * @return Autosave the loaded file or not
3966  *
3967  * @ingroup Entry
3968  */
3969 EAPI Eina_Bool
3970 elm_entry_autosave_get(const Evas_Object *obj)
3971 {
3972    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3973    Widget_Data *wd = elm_widget_data_get(obj);
3974    if (!wd) return EINA_FALSE;
3975    return wd->autosave;
3976 }
3977
3978 /**
3979  * Control pasting of text and images for the widget.
3980  *
3981  * Normally the entry allows both text and images to be pasted.  By setting
3982  * textonly to be true, this prevents images from being pasted.
3983  *
3984  * Note this only changes the behaviour of text.
3985  *
3986  * @param obj The entry object
3987  * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is text+image+other.
3988  *
3989  * @ingroup Entry
3990  */
3991 EAPI void
3992 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
3993 {
3994    Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
3995    ELM_CHECK_WIDTYPE(obj, widtype);
3996    Widget_Data *wd = elm_widget_data_get(obj);
3997    if (!wd) return;
3998    textonly = !!textonly;
3999    if (wd->textonly == textonly) return;
4000    wd->textonly = !!textonly;
4001    if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
4002 #ifdef HAVE_ELEMENTARY_X
4003    elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
4004 #endif
4005 }
4006
4007 /**
4008  * Getting elm_entry text paste/drop mode.
4009  *
4010  * In textonly mode, only text may be pasted or dropped into the widget.
4011  *
4012  * @param obj The entry object
4013  * @return If the widget only accepts text from pastes.
4014  *
4015  * @ingroup Entry
4016  */
4017 EAPI Eina_Bool
4018 elm_entry_cnp_textonly_get(Evas_Object *obj)
4019 {
4020    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
4021    Widget_Data *wd = elm_widget_data_get(obj);
4022    if (!wd) return EINA_FALSE;
4023    return wd->textonly;
4024 }
4025
4026 /**
4027  * This sets the attribute to show the input panel automatically.
4028  *
4029  * @param obj The entry object
4030  * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
4031  *
4032  * @ingroup Entry
4033  */
4034 EAPI void
4035 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
4036 {
4037    ELM_CHECK_WIDTYPE(obj, widtype);
4038    Widget_Data *wd = elm_widget_data_get(obj);
4039    if (!wd) return;
4040
4041    wd->input_panel_enable = enabled;
4042    edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
4043 }
4044
4045 /**
4046  * Set the input panel layout of the entry
4047  *
4048  * @param obj The entry object
4049  * @param layout the layout to set
4050  *
4051  * @ingroup Entry
4052  */
4053 EAPI void
4054 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
4055 {
4056    ELM_CHECK_WIDTYPE(obj, widtype);
4057    Widget_Data *wd = elm_widget_data_get(obj);
4058    if (!wd) return;
4059
4060    Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
4061    if (!ic) return;
4062
4063    wd->input_panel_layout = layout;
4064
4065    ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
4066 }
4067
4068 /**
4069  * Set the magnifier style of the entry
4070  *
4071  * @param obj The entry object
4072  * @param type the magnifier style to set
4073  *
4074  * @ingroup Entry
4075  */
4076 EAPI void
4077 elm_entry_magnifier_type_set(Evas_Object *obj, int type)
4078 {
4079    ELM_CHECK_WIDTYPE(obj, widtype);
4080    Widget_Data *wd = elm_widget_data_get(obj);
4081    if (!wd) return;
4082
4083    wd->mgf_type = type;
4084    _magnifier_create(obj);
4085 }