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