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