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