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