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