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