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