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