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