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