Elementary migration around 2011/04/06
[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    _theme_hook(obj);
2458 }
2459
2460 /**
2461  * This returns whether password mode is enabled.
2462  * See also elm_entry_password_set().
2463  *
2464  * @param obj The entry object
2465  * @return If true, the entry is set to display all characters
2466  * as asterisks (*).
2467  *
2468  * @ingroup Entry
2469  */
2470 EAPI Eina_Bool
2471 elm_entry_password_get(const Evas_Object *obj)
2472 {
2473    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2474    Widget_Data *wd = elm_widget_data_get(obj);
2475    if (!wd) return EINA_FALSE;
2476    return wd->password;
2477 }
2478
2479 /**
2480  * This sets the text displayed within the entry to @p entry.
2481  *
2482  * @param obj The entry object
2483  * @param entry The text to be displayed
2484  *
2485  * @ingroup Entry
2486  */
2487 EAPI void
2488 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2489 {
2490    ELM_CHECK_WIDTYPE(obj, widtype);
2491    Widget_Data *wd = elm_widget_data_get(obj);
2492    if (!wd) return;
2493    if (!entry) entry = "";
2494    if(wd->max_no_of_bytes)
2495      {
2496         int len = strlen(entry);
2497         if(len > wd->max_no_of_bytes)
2498           {
2499              ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2500              return;
2501           }
2502      }
2503    edje_object_part_text_set(wd->ent, "elm.text", entry);
2504    if (wd->text) eina_stringshare_del(wd->text);
2505    wd->text = NULL;
2506    wd->changed = EINA_TRUE;
2507    _sizing_eval(obj);
2508 }
2509
2510 /**
2511  * This returns the text currently shown in object @p entry.
2512  * See also elm_entry_entry_set().
2513  *
2514  * @param obj The entry object
2515  * @return The currently displayed text or NULL on failure
2516  *
2517  * @ingroup Entry
2518  */
2519 EAPI const char *
2520 elm_entry_entry_get(const Evas_Object *obj)
2521 {
2522    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2523    Widget_Data *wd = elm_widget_data_get(obj);
2524    const char *text;
2525    if (!wd) return NULL;
2526
2527    if ((wd->text)&&(wd->password))
2528      return elm_entry_markup_to_utf8(wd->text);
2529
2530    if (wd->text) return wd->text;
2531    text = edje_object_part_text_get(wd->ent, "elm.text");
2532    if (!text)
2533      {
2534         ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2535         return NULL;
2536      }
2537    eina_stringshare_replace(&wd->text, text);
2538    if(wd->password)return elm_entry_markup_to_utf8(wd->text);
2539    return wd->text;
2540 }
2541
2542 /**
2543  * This returns EINA_TRUE if the entry is empty/there was an error
2544  * and EINA_FALSE if it is not empty.
2545  *
2546  * @param obj The entry object
2547  * @return If the entry is empty or not.
2548  *
2549  * @ingroup Entry
2550  */
2551 EAPI Eina_Bool
2552 elm_entry_is_empty(const Evas_Object *obj)
2553 {
2554    /* FIXME: until there's support for that in textblock, we just check
2555     * to see if the there is text or not. */
2556    ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
2557    Widget_Data *wd = elm_widget_data_get(obj);
2558    const Evas_Object *tb;
2559    //Evas_Textblock_Cursor *cur;
2560    Eina_Bool ret;
2561    if (!wd) return EINA_TRUE;
2562
2563 #if 0   
2564    /* It's a hack until we get the support suggested above.
2565     * We just create a cursor, point it to the begining, and then
2566     * try to advance it, if it can advance, the tb is not empty,
2567     * otherwise it is. */
2568    tb = edje_object_part_object_get(wd->ent, "elm.text");
2569    cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
2570                                                                   actually, ok for the time being, thsese hackish stuff will be removed
2571                                                                   once evas 1.0 is out*/
2572    evas_textblock_cursor_pos_set(cur, 0);
2573    ret = evas_textblock_cursor_char_next(cur);
2574    evas_textblock_cursor_free(cur);
2575
2576    return !ret;
2577 #endif
2578
2579    char *str = elm_entry_markup_to_utf8(elm_entry_entry_get(obj));
2580    if (!str) return EINA_TRUE;
2581
2582    ret = (strlen(str) == 0);
2583
2584    return ret;
2585 }
2586
2587 /**
2588  * This returns all selected text within the entry.
2589  *
2590  * @param obj The entry object
2591  * @return The selected text within the entry or NULL on failure
2592  *
2593  * @ingroup Entry
2594  */
2595 EAPI const char *
2596 elm_entry_selection_get(const Evas_Object *obj)
2597 {
2598    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2599    Widget_Data *wd = elm_widget_data_get(obj);
2600    if (!wd) return NULL;
2601    return edje_object_part_text_selection_get(wd->ent, "elm.text");
2602 }
2603
2604 /**
2605  * This inserts text in @p entry where the current cursor position.
2606  *
2607  * This inserts text at the cursor position is as if it was typed
2608  * by the user (note this also allows markup which a user
2609  * can't just "type" as it would be converted to escaped text, so this
2610  * call can be used to insert things like emoticon items or bold push/pop
2611  * tags, other font and color change tags etc.)
2612  *
2613  * @param obj The entry object
2614  * @param entry The text to insert
2615  *
2616  * @ingroup Entry
2617  */
2618 EAPI void
2619 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2620 {
2621    ELM_CHECK_WIDTYPE(obj, widtype);
2622    Widget_Data *wd = elm_widget_data_get(obj);
2623    if (!wd) return;
2624    edje_object_part_text_insert(wd->ent, "elm.text", entry);
2625    // start for cbhm
2626    if (cnpwidgetdata == obj)
2627       ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
2628    // end for cbhm
2629    wd->changed = EINA_TRUE;
2630    _sizing_eval(obj);
2631 }
2632
2633 /**
2634  * This enables word line wrapping in the entry object.  It is the opposite
2635  * of elm_entry_single_line_set().  Additionally, setting this disables
2636  * character line wrapping.
2637  * See also elm_entry_line_char_wrap_set().
2638  *
2639  * @param obj The entry object
2640  * @param wrap If true, the entry will be wrapped once it reaches the end
2641  * of the object. Wrapping will occur at the end of the word before the end of the
2642  * object.
2643  *
2644  * @ingroup Entry
2645  */
2646 EAPI void
2647 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2648 {
2649    ELM_CHECK_WIDTYPE(obj, widtype);
2650    Widget_Data *wd = elm_widget_data_get(obj);
2651    if (!wd) return;
2652    if (wd->linewrap == wrap) return;
2653    wd->linewrap = wrap;
2654    if(wd->linewrap)
2655      wd->char_linewrap = EINA_FALSE;
2656    _theme_hook(obj);
2657 }
2658
2659 /**
2660  * Set wrap width of the entry
2661  *
2662  * @param obj The entry object
2663  * @param w The wrap width in pixels at a minimum where words need to wrap
2664  * @ingroup Entry
2665  */
2666 EAPI void
2667 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2668 {
2669    Widget_Data *wd = elm_widget_data_get(obj);
2670    if (wd->wrap_w == w) return;
2671    wd->wrap_w = w;
2672    _sizing_eval(obj);
2673 }
2674
2675 /**
2676  * get wrap width of the entry
2677  *
2678  * @param obj The entry object
2679  * @return The wrap width in pixels at a minimum where words need to wrap
2680  * @ingroup Entry
2681  */
2682 EAPI Evas_Coord
2683 elm_entry_wrap_width_get(const Evas_Object *obj)
2684 {
2685    Widget_Data *wd = elm_widget_data_get(obj);
2686    return wd->wrap_w;
2687 }
2688
2689 /**
2690  * This enables character line wrapping in the entry object.  It is the opposite
2691  * of elm_entry_single_line_set().  Additionally, setting this disables
2692  * word line wrapping.
2693  * See also elm_entry_line_wrap_set().
2694  *
2695  * @param obj The entry object
2696  * @param wrap If true, the entry will be wrapped once it reaches the end
2697  * of the object. Wrapping will occur immediately upon reaching the end of the object.
2698  *
2699  * @ingroup Entry
2700  */
2701 EAPI void
2702 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2703 {
2704    ELM_CHECK_WIDTYPE(obj, widtype);
2705    Widget_Data *wd = elm_widget_data_get(obj);
2706    if (!wd) return;
2707    if (wd->char_linewrap == wrap) return;
2708    wd->char_linewrap = wrap;
2709    if(wd->char_linewrap)
2710      wd->linewrap = EINA_FALSE;
2711    _theme_hook(obj);
2712 }
2713
2714 /**
2715  * This sets the editable attribute of the entry.
2716  *
2717  * @param obj The entry object
2718  * @param editable If true, the entry will be editable by the user.
2719  * If false, it will be set to the disabled state.
2720  *
2721  * @ingroup Entry
2722  */
2723 EAPI void
2724 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2725 {
2726    ELM_CHECK_WIDTYPE(obj, widtype);
2727    Widget_Data *wd = elm_widget_data_get(obj);
2728    if (!wd) return;
2729    if (wd->editable == editable) return;
2730    wd->editable = editable;
2731    _theme_hook(obj);
2732
2733 #ifdef HAVE_ELEMENTARY_X
2734    if (editable)
2735      elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2736    else
2737      elm_drop_target_del(obj);
2738 #endif
2739 }
2740
2741 /**
2742  * This gets the editable attribute of the entry.
2743  * See also elm_entry_editable_set().
2744  *
2745  * @param obj The entry object
2746  * @return If true, the entry is editable by the user.
2747  * If false, it is not editable by the user
2748  *
2749  * @ingroup Entry
2750  */
2751 EAPI Eina_Bool
2752 elm_entry_editable_get(const Evas_Object *obj)
2753 {
2754    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2755    Widget_Data *wd = elm_widget_data_get(obj);
2756    if (!wd) return EINA_FALSE;
2757    return wd->editable;
2758 }
2759
2760 /**
2761  * This drops any existing text selection within the entry.
2762  *
2763  * @param obj The entry object
2764  *
2765  * @ingroup Entry
2766  */
2767 EAPI void
2768 elm_entry_select_none(Evas_Object *obj)
2769 {
2770    ELM_CHECK_WIDTYPE(obj, widtype);
2771    Widget_Data *wd = elm_widget_data_get(obj);
2772    if (!wd) return;
2773    if (wd->selmode)
2774      {
2775         wd->selmode = EINA_FALSE;
2776         if (!_elm_config->desktop_entry)
2777            edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2778         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2779      }
2780    wd->have_selection = EINA_FALSE;
2781    edje_object_part_text_select_none(wd->ent, "elm.text");
2782 }
2783
2784 /**
2785  * This selects all text within the entry.
2786  *
2787  * @param obj The entry object
2788  *
2789  * @ingroup Entry
2790  */
2791 EAPI void
2792 elm_entry_select_all(Evas_Object *obj)
2793 {
2794    ELM_CHECK_WIDTYPE(obj, widtype);
2795    Widget_Data *wd = elm_widget_data_get(obj);
2796    if (!wd) return;
2797    if (wd->selmode)
2798      {
2799         wd->selmode = EINA_FALSE;
2800         if (!_elm_config->desktop_entry)
2801            edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2802         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2803      }
2804    wd->have_selection = EINA_TRUE;
2805    edje_object_part_text_select_all(wd->ent, "elm.text");
2806 }
2807
2808 /**
2809  * This function returns the geometry of the cursor.
2810  *
2811  * It's useful if you want to draw something on the cursor (or where it is),
2812  * or for example in the case of scrolled entry where you want to show the
2813  * cursor.
2814  *
2815  * @param obj The entry object
2816  * @param x returned geometry
2817  * @param y returned geometry
2818  * @param w returned geometry
2819  * @param h returned geometry
2820  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2821  *
2822  * @ingroup Entry
2823  */
2824 EAPI Eina_Bool
2825 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
2826 {
2827    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2828    Widget_Data *wd = elm_widget_data_get(obj);
2829    if (!wd) return EINA_FALSE;
2830    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
2831    return EINA_TRUE;
2832 }
2833
2834 /**
2835  * This moves the cursor one place to the right within the entry.
2836  *
2837  * @param obj The entry object
2838  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2839  *
2840  * @ingroup Entry
2841  */
2842 EAPI Eina_Bool
2843 elm_entry_cursor_next(Evas_Object *obj)
2844 {
2845    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2846    Widget_Data *wd = elm_widget_data_get(obj);
2847    if (!wd) return EINA_FALSE;
2848    return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2849 }
2850
2851 /**
2852  * This moves the cursor one place to the left within the entry.
2853  *
2854  * @param obj The entry object
2855  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2856  *
2857  * @ingroup Entry
2858  */
2859 EAPI Eina_Bool
2860 elm_entry_cursor_prev(Evas_Object *obj)
2861 {
2862    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2863    Widget_Data *wd = elm_widget_data_get(obj);
2864    if (!wd) return EINA_FALSE;
2865    return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2866 }
2867
2868 /**
2869  * This moves the cursor one line up within the entry.
2870  *
2871  * @param obj The entry object
2872  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2873  *
2874  * @ingroup Entry
2875  */
2876 EAPI Eina_Bool
2877 elm_entry_cursor_up(Evas_Object *obj)
2878 {
2879    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2880    Widget_Data *wd = elm_widget_data_get(obj);
2881    if (!wd) return EINA_FALSE;
2882    return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2883 }
2884
2885 /**
2886  * This moves the cursor one line down within the entry.
2887  *
2888  * @param obj The entry object
2889  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2890  *
2891  * @ingroup Entry
2892  */
2893 EAPI Eina_Bool
2894 elm_entry_cursor_down(Evas_Object *obj)
2895 {
2896    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2897    Widget_Data *wd = elm_widget_data_get(obj);
2898    if (!wd) return EINA_FALSE;
2899    return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2900 }
2901
2902 /**
2903  * This moves the cursor to the beginning of the entry.
2904  *
2905  * @param obj The entry object
2906  *
2907  * @ingroup Entry
2908  */
2909 EAPI void
2910 elm_entry_cursor_begin_set(Evas_Object *obj)
2911 {
2912    ELM_CHECK_WIDTYPE(obj, widtype);
2913    Widget_Data *wd = elm_widget_data_get(obj);
2914    if (!wd) return;
2915    edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2916 }
2917
2918 /**
2919  * This moves the cursor to the end of the entry.
2920  *
2921  * @param obj The entry object
2922  *
2923  * @ingroup Entry
2924  */
2925 EAPI void
2926 elm_entry_cursor_end_set(Evas_Object *obj)
2927 {
2928    ELM_CHECK_WIDTYPE(obj, widtype);
2929    Widget_Data *wd = elm_widget_data_get(obj);
2930    if (!wd) return;
2931    edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2932 }
2933
2934 /**
2935  * This moves the cursor to the beginning of the current line.
2936  *
2937  * @param obj The entry object
2938  *
2939  * @ingroup Entry
2940  */
2941 EAPI void
2942 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2943 {
2944    ELM_CHECK_WIDTYPE(obj, widtype);
2945    Widget_Data *wd = elm_widget_data_get(obj);
2946    if (!wd) return;
2947    edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2948 }
2949
2950 /**
2951  * This moves the cursor to the end of the current line.
2952  *
2953  * @param obj The entry object
2954  *
2955  * @ingroup Entry
2956  */
2957 EAPI void
2958 elm_entry_cursor_line_end_set(Evas_Object *obj)
2959 {
2960    ELM_CHECK_WIDTYPE(obj, widtype);
2961    Widget_Data *wd = elm_widget_data_get(obj);
2962    if (!wd) return;
2963    edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2964 }
2965
2966 /**
2967  * This begins a selection within the entry as though
2968  * the user were holding down the mouse button to make a selection.
2969  *
2970  * @param obj The entry object
2971  *
2972  * @ingroup Entry
2973  */
2974 EAPI void
2975 elm_entry_cursor_selection_begin(Evas_Object *obj)
2976 {
2977    ELM_CHECK_WIDTYPE(obj, widtype);
2978    Widget_Data *wd = elm_widget_data_get(obj);
2979    if (!wd) return;
2980    edje_object_part_text_select_begin(wd->ent, "elm.text");
2981 }
2982
2983 /**
2984  * This ends a selection within the entry as though
2985  * the user had just released the mouse button while making a selection.
2986  *
2987  * @param obj The entry object
2988  *
2989  * @ingroup Entry
2990  */
2991 EAPI void
2992 elm_entry_cursor_selection_end(Evas_Object *obj)
2993 {
2994    ELM_CHECK_WIDTYPE(obj, widtype);
2995    Widget_Data *wd = elm_widget_data_get(obj);
2996    if (!wd) return;
2997    edje_object_part_text_select_extend(wd->ent, "elm.text");
2998 }
2999
3000 /**
3001  * TODO: fill this in
3002  *
3003  * @param obj The entry object
3004  * @return TODO: fill this in
3005  *
3006  * @ingroup Entry
3007  */
3008 EAPI Eina_Bool
3009 elm_entry_cursor_is_format_get(const Evas_Object *obj)
3010 {
3011    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3012    Widget_Data *wd = elm_widget_data_get(obj);
3013    if (!wd) return EINA_FALSE;
3014    return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3015 }
3016
3017 /**
3018  * This returns whether the cursor is visible.
3019  *
3020  * @param obj The entry object
3021  * @return If true, the cursor is visible.
3022  *
3023  * @ingroup Entry
3024  */
3025 EAPI Eina_Bool
3026 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
3027 {
3028    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3029    Widget_Data *wd = elm_widget_data_get(obj);
3030    if (!wd) return EINA_FALSE;
3031    return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3032 }
3033
3034 /**
3035  * TODO: fill this in
3036  *
3037  * @param obj The entry object
3038  * @return TODO: fill this in
3039  *
3040  * @ingroup Entry
3041  */
3042 EAPI const char *
3043 elm_entry_cursor_content_get(const Evas_Object *obj)
3044 {
3045    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3046    Widget_Data *wd = elm_widget_data_get(obj);
3047    if (!wd) return NULL;
3048    return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3049 }
3050
3051 /**
3052  * Sets the cursor position in the entry to the given value
3053  *
3054  * @param obj The entry object
3055  * @param pos The position of the cursor
3056  *
3057  * @ingroup Entry
3058  */
3059 EAPI void
3060 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
3061 {
3062    ELM_CHECK_WIDTYPE(obj, widtype);
3063    Widget_Data *wd = elm_widget_data_get(obj);
3064    if (!wd) return;
3065    edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
3066    edje_object_message_signal_process(wd->ent);
3067 }
3068
3069 /**
3070  * Retrieves the current position of the cursor in the entry
3071  *
3072  * @param obj The entry object
3073  * @return The cursor position
3074  *
3075  * @ingroup Entry
3076  */
3077 EAPI int
3078 elm_entry_cursor_pos_get(const Evas_Object *obj)
3079 {
3080    ELM_CHECK_WIDTYPE(obj, widtype) 0;
3081    Widget_Data *wd = elm_widget_data_get(obj);
3082    if (!wd) return 0;
3083    return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
3084 }
3085
3086 /**
3087  * This executes a "cut" action on the selected text in the entry.
3088  *
3089  * @param obj The entry object
3090  *
3091  * @ingroup Entry
3092  */
3093 EAPI void
3094 elm_entry_selection_cut(Evas_Object *obj)
3095 {
3096    ELM_CHECK_WIDTYPE(obj, widtype);
3097    Widget_Data *wd = elm_widget_data_get(obj);
3098    if (!wd) return;
3099    _cut(obj, NULL, NULL);
3100 }
3101
3102 /**
3103  * This executes a "copy" action on the selected text in the entry.
3104  *
3105  * @param obj The entry object
3106  *
3107  * @ingroup Entry
3108  */
3109 EAPI void
3110 elm_entry_selection_copy(Evas_Object *obj)
3111 {
3112    ELM_CHECK_WIDTYPE(obj, widtype);
3113    Widget_Data *wd = elm_widget_data_get(obj);
3114    if (!wd) return;
3115    _copy(obj, NULL, NULL);
3116 }
3117
3118 /**
3119  * This executes a "paste" action in the entry.
3120  *
3121  * @param obj The entry object
3122  *
3123  * @ingroup Entry
3124  */
3125 EAPI void
3126 elm_entry_selection_paste(Evas_Object *obj)
3127 {
3128    ELM_CHECK_WIDTYPE(obj, widtype);
3129    Widget_Data *wd = elm_widget_data_get(obj);
3130    if (!wd) return;
3131    _paste(obj, NULL, NULL);
3132 }
3133
3134 /**
3135  * This clears and frees the items in a entry's contextual (right click) menu.
3136  *
3137  * @param obj The entry object
3138  *
3139  * @ingroup Entry
3140  */
3141 EAPI void
3142 elm_entry_context_menu_clear(Evas_Object *obj)
3143 {
3144    ELM_CHECK_WIDTYPE(obj, widtype);
3145    Widget_Data *wd = elm_widget_data_get(obj);
3146    Elm_Entry_Context_Menu_Item *it;
3147    if (!wd) return;
3148    EINA_LIST_FREE(wd->items, it)
3149      {
3150         eina_stringshare_del(it->label);
3151         eina_stringshare_del(it->icon_file);
3152         eina_stringshare_del(it->icon_group);
3153         free(it);
3154      }
3155 }
3156
3157 /**
3158  * This adds an item to the entry's contextual menu.
3159  *
3160  * @param obj The entry object
3161  * @param label The item's text label
3162  * @param icon_file The item's icon file
3163  * @param icon_type The item's icon type
3164  * @param func The callback to execute when the item is clicked
3165  * @param data The data to associate with the item for related functions
3166  *
3167  * @ingroup Entry
3168  */
3169 EAPI void
3170 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)
3171 {
3172    ELM_CHECK_WIDTYPE(obj, widtype);
3173    Widget_Data *wd = elm_widget_data_get(obj);
3174    Elm_Entry_Context_Menu_Item *it;
3175    if (!wd) return;
3176    it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
3177    if (!it) return;
3178    wd->items = eina_list_append(wd->items, it);
3179    it->obj = obj;
3180    it->label = eina_stringshare_add(label);
3181    it->icon_file = eina_stringshare_add(icon_file);
3182    it->icon_type = icon_type;
3183    it->func = func;
3184    it->data = (void *)data;
3185 }
3186
3187 /**
3188  * This disables the entry's contextual (right click) menu.
3189  *
3190  * @param obj The entry object
3191  * @param disabled If true, the menu is disabled
3192  *
3193  * @ingroup Entry
3194  */
3195 EAPI void
3196 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
3197 {
3198    ELM_CHECK_WIDTYPE(obj, widtype);
3199    Widget_Data *wd = elm_widget_data_get(obj);
3200    if (!wd) return;
3201    if (wd->context_menu == !disabled) return;
3202    wd->context_menu = !disabled;
3203 }
3204
3205 /**
3206  * This returns whether the entry's contextual (right click) menu is disabled.
3207  *
3208  * @param obj The entry object
3209  * @return If true, the menu is disabled
3210  *
3211  * @ingroup Entry
3212  */
3213 EAPI Eina_Bool
3214 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
3215 {
3216    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3217    Widget_Data *wd = elm_widget_data_get(obj);
3218    if (!wd) return EINA_FALSE;
3219    return !wd->context_menu;
3220 }
3221
3222 /**
3223  * This appends a custom item provider to the list for that entry
3224  *
3225  * This appends the given callback. The list is walked from beginning to end
3226  * with each function called given the item href string in the text. If the
3227  * function returns an object handle other than NULL (it should create an
3228  * and object to do this), then this object is used to replace that item. If
3229  * not the next provider is called until one provides an item object, or the
3230  * default provider in entry does.
3231  *
3232  * @param obj The entry object
3233  * @param func The function called to provide the item object
3234  * @param data The data passed to @p func
3235  *
3236  * @ingroup Entry
3237  */
3238 EAPI void
3239 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3240 {
3241    ELM_CHECK_WIDTYPE(obj, widtype);
3242    Widget_Data *wd = elm_widget_data_get(obj);
3243    if (!wd) return;
3244    EINA_SAFETY_ON_NULL_RETURN(func);
3245    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3246    if (!ip) return;
3247    ip->func = func;
3248    ip->data = data;
3249    wd->item_providers = eina_list_append(wd->item_providers, ip);
3250 }
3251
3252 /**
3253  * This prepends a custom item provider to the list for that entry
3254  *
3255  * This prepends the given callback. See elm_entry_item_provider_append() for
3256  * more information
3257  *
3258  * @param obj The entry object
3259  * @param func The function called to provide the item object
3260  * @param data The data passed to @p func
3261  *
3262  * @ingroup Entry
3263  */
3264 EAPI void
3265 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3266 {
3267    ELM_CHECK_WIDTYPE(obj, widtype);
3268    Widget_Data *wd = elm_widget_data_get(obj);
3269    if (!wd) return;
3270    EINA_SAFETY_ON_NULL_RETURN(func);
3271    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3272    if (!ip) return;
3273    ip->func = func;
3274    ip->data = data;
3275    wd->item_providers = eina_list_prepend(wd->item_providers, ip);
3276 }
3277
3278 /**
3279  * This removes a custom item provider to the list for that entry
3280  *
3281  * This removes the given callback. See elm_entry_item_provider_append() for
3282  * more information
3283  *
3284  * @param obj The entry object
3285  * @param func The function called to provide the item object
3286  * @param data The data passed to @p func
3287  *
3288  * @ingroup Entry
3289  */
3290 EAPI void
3291 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3292 {
3293    ELM_CHECK_WIDTYPE(obj, widtype);
3294    Widget_Data *wd = elm_widget_data_get(obj);
3295    Eina_List *l;
3296    Elm_Entry_Item_Provider *ip;
3297    if (!wd) return;
3298    EINA_SAFETY_ON_NULL_RETURN(func);
3299    EINA_LIST_FOREACH(wd->item_providers, l, ip)
3300      {
3301         if ((ip->func == func) && ((!data) || (ip->data == data)))
3302           {
3303              wd->item_providers = eina_list_remove_list(wd->item_providers, l);
3304              free(ip);
3305              return;
3306           }
3307      }
3308 }
3309
3310 /**
3311  * Append a filter function for text inserted in the entry
3312  *
3313  * Append the given callback to the list. This functions will be called
3314  * whenever any text is inserted into the entry, with the text to be inserted
3315  * as a parameter. The callback function is free to alter the text in any way
3316  * it wants, but it must remember to free the given pointer and update it.
3317  * If the new text is to be discarded, the function can free it and set it text
3318  * parameter to NULL. This will also prevent any following filters from being
3319  * called.
3320  *
3321  * @param obj The entry object
3322  * @param func The function to use as text filter
3323  * @param data User data to pass to @p func
3324  *
3325  * @ingroup Entry
3326  */
3327 EAPI void
3328 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3329 {
3330    Widget_Data *wd;
3331    Elm_Entry_Text_Filter *tf;
3332    ELM_CHECK_WIDTYPE(obj, widtype);
3333
3334    wd = elm_widget_data_get(obj);
3335
3336    EINA_SAFETY_ON_NULL_RETURN(func);
3337
3338    tf = _filter_new(func, data);
3339    if (!tf) return;
3340
3341    wd->text_filters = eina_list_append(wd->text_filters, tf);
3342 }
3343
3344 /**
3345  * Prepend a filter function for text insdrted in the entry
3346  *
3347  * Prepend the given callback to the list. See elm_entry_text_filter_append()
3348  * for more information
3349  *
3350  * @param obj The entry object
3351  * @param func The function to use as text filter
3352  * @param data User data to pass to @p func
3353  *
3354  * @ingroup Entry
3355  */
3356 EAPI void
3357 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3358 {
3359    Widget_Data *wd;
3360    Elm_Entry_Text_Filter *tf;
3361    ELM_CHECK_WIDTYPE(obj, widtype);
3362
3363    wd = elm_widget_data_get(obj);
3364
3365    EINA_SAFETY_ON_NULL_RETURN(func);
3366
3367    tf = _filter_new(func, data);
3368    if (!tf) return;
3369
3370    wd->text_filters = eina_list_prepend(wd->text_filters, tf);
3371 }
3372
3373 /**
3374  * Remove a filter from the list
3375  *
3376  * Removes the given callback from the filter list. See elm_entry_text_filter_append()
3377  * for more information.
3378  *
3379  * @param obj The entry object
3380  * @param func The filter function to remove
3381  * @param data The user data passed when adding the function
3382  *
3383  * @ingroup Entry
3384  */
3385 EAPI void
3386 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3387 {
3388    Widget_Data *wd;
3389    Eina_List *l;
3390    Elm_Entry_Text_Filter *tf;
3391    ELM_CHECK_WIDTYPE(obj, widtype);
3392
3393    wd = elm_widget_data_get(obj);
3394
3395    EINA_SAFETY_ON_NULL_RETURN(func);
3396
3397    EINA_LIST_FOREACH(wd->text_filters, l, tf)
3398      {
3399         if ((tf->func == func) && ((!data) || (tf->data == data)))
3400           {
3401              wd->text_filters = eina_list_remove_list(wd->text_filters, l);
3402              _filter_free(tf);
3403              return;
3404           }
3405      }
3406 }
3407
3408 /**
3409  * This converts a markup (HTML-like) string into UTF-8.
3410  * Returning string is obtained with malloc.
3411  * After use the returned string, it should be freed.
3412  *
3413  * @param s The string (in markup) to be converted
3414  * @return The converted string (in UTF-8). It should be freed.
3415  *
3416  * @ingroup Entry
3417  */
3418 EAPI char *
3419 elm_entry_markup_to_utf8(const char *s)
3420 {
3421    char *ss = _elm_util_mkup_to_text(s);
3422    if (!ss) ss = strdup("");
3423    return ss;
3424 }
3425
3426 /**
3427  * This converts a UTF-8 string into markup (HTML-like).
3428  * Returning string is obtained with malloc.
3429  * After use the returned string, it should be freed.
3430  *
3431  * @param s The string (in UTF-8) to be converted
3432  * @return The converted string (in markup). It should be freed.
3433  *
3434  * @ingroup Entry
3435  */
3436 EAPI char *
3437 elm_entry_utf8_to_markup(const char *s)
3438 {
3439    char *ss = _elm_util_text_to_mkup(s);
3440    if (!ss) ss = strdup("");
3441    return ss;
3442 }
3443
3444 /**
3445  * Get the input method context in the entry widget
3446  *
3447  * @param obj The entry object
3448  * @return The input method context
3449  *
3450  * @ingroup Entry
3451  */
3452 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
3453 {
3454    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3455    Widget_Data *wd = elm_widget_data_get(obj);
3456    if (!wd || !wd->ent) return NULL;
3457
3458    return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
3459 }
3460
3461 /**
3462  * Set whether entry should enable the return key on soft keyboard automatically
3463  *
3464  * @param obj The entry object
3465  * @param on If true, entry enables the return key on soft keyboard automatically.
3466  *
3467  * @ingroup Entry
3468  */
3469 EAPI void
3470 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
3471 {
3472    ELM_CHECK_WIDTYPE(obj, widtype);
3473    Widget_Data *wd = elm_widget_data_get(obj);
3474    if (!wd) return;
3475
3476    wd->autoreturnkey = on;
3477    _check_enable_returnkey(obj);
3478 }
3479
3480 /**
3481  * Set whether entry should support auto capitalization
3482  *
3483  * @param obj The entry object
3484  * @param on If true, entry suports auto capitalization.
3485  *
3486  * @ingroup Entry
3487  */
3488 EAPI void
3489 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
3490 {
3491    ELM_CHECK_WIDTYPE(obj, widtype);
3492    Widget_Data *wd = elm_widget_data_get(obj);
3493    if (!wd) return;
3494
3495    if (wd->password)
3496      wd->autocapital = EINA_FALSE;
3497    else
3498      wd->autocapital = autocap;
3499
3500    if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3501        wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3502      wd->autocapital = EINA_FALSE;
3503
3504    edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
3505 }
3506
3507 /**
3508  * Set whether entry should support auto period
3509  *
3510  * @param obj The entry object
3511  * @param on If true, entry suports auto period.
3512  *
3513  * @ingroup Entry
3514  */
3515 EAPI void
3516 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
3517 {
3518    ELM_CHECK_WIDTYPE(obj, widtype);
3519    Widget_Data *wd = elm_widget_data_get(obj);
3520    if (!wd) return;
3521
3522    if (wd->password)
3523      wd->autoperiod = EINA_FALSE;
3524    else
3525      wd->autoperiod = autoperiod;
3526
3527    if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3528        wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3529      wd->autoperiod = EINA_FALSE;
3530
3531    edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
3532 }
3533
3534 /**
3535  * Set the font size on the entry object
3536  *
3537  * @param obj The entry object
3538  * @param size font size
3539  *
3540  * @ingroup Entry
3541  */
3542 EAPI void
3543 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
3544 {
3545    ELM_CHECK_WIDTYPE(obj, widtype);
3546    Widget_Data *wd = elm_widget_data_get(obj);
3547    Eina_Strbuf *fontbuf = NULL;
3548    int removeflag = 0;
3549    const char *t;
3550
3551    if (!wd) return;
3552    t = eina_stringshare_add(elm_entry_entry_get(obj));
3553    fontbuf = eina_strbuf_new();
3554    eina_strbuf_append_printf(fontbuf, "%d", fontsize);
3555
3556    if (fontsize == 0) removeflag = 1; // remove fontsize tag
3557
3558    if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
3559      {
3560        elm_entry_entry_set(obj, t);
3561        wd->changed = 1;
3562        _sizing_eval(obj);
3563      }
3564    eina_strbuf_free(fontbuf);
3565    eina_stringshare_del(t);
3566 }
3567
3568 /**
3569  * Set the text align on the entry object
3570  *
3571  * @param obj The entry object
3572  * @param align align mode
3573  *
3574  * @ingroup Entry
3575  */
3576 EAPI void
3577 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
3578 {
3579    ELM_CHECK_WIDTYPE(obj, widtype);
3580    Widget_Data *wd = elm_widget_data_get(obj);
3581    int len;
3582    const char *t;
3583
3584    if (!wd) return;
3585    t = eina_stringshare_add(elm_entry_entry_get(obj));
3586    len = strlen(t);
3587    if (len <= 0) return;
3588
3589    if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
3590      elm_entry_entry_set(obj, t);
3591
3592    wd->changed = 1;
3593    _sizing_eval(obj);
3594    eina_stringshare_del(t);
3595 }
3596
3597 /**
3598  * Set the text color on the entry object
3599  *
3600  * @param obj The entry object
3601  * @param r Red property background color of The entry object 
3602  * @param g Green property background color of The entry object 
3603  * @param b Blue property background color of The entry object 
3604  * @param a Alpha property background alpha of The entry object 
3605  *
3606  * @ingroup Entry
3607  */
3608 EAPI void
3609 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3610 {
3611    ELM_CHECK_WIDTYPE(obj, widtype);
3612    Widget_Data *wd = elm_widget_data_get(obj);
3613    Eina_Strbuf *colorbuf = NULL;
3614    const char *t;
3615    int len;
3616
3617    if (!wd) return;
3618    t = eina_stringshare_add(elm_entry_entry_get(obj));
3619    len = strlen(t);
3620    if (len <= 0) return;
3621    colorbuf = eina_strbuf_new();
3622    eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
3623
3624    if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
3625      {
3626        elm_entry_entry_set(obj, t);
3627        wd->changed = 1;
3628        _sizing_eval(obj);
3629      }
3630    eina_strbuf_free(colorbuf);
3631    eina_stringshare_del(t);
3632 }
3633
3634 /**
3635  * Set background color of the entry
3636  *
3637  * @param obj The entry object
3638  * @param r Red property background color of The entry object 
3639  * @param g Green property background color of The entry object 
3640  * @param b Blue property background color of The entry object 
3641  * @param a Alpha property background alpha of The entry object 
3642  * @ingroup Entry
3643  */
3644 EAPI void
3645 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3646 {
3647    ELM_CHECK_WIDTYPE(obj, widtype);
3648    Widget_Data *wd = elm_widget_data_get(obj);
3649    evas_object_color_set(wd->bg, r, g, b, a);
3650
3651    if (wd->bgcolor == EINA_FALSE)
3652      {
3653        wd->bgcolor = 1;
3654        edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3655      }
3656 }
3657
3658 /**
3659  * Filter inserted text based on user defined character and byte limits
3660  *
3661  * Add this filter to an entry to limit the characters that it will accept
3662  * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
3663  * The funtion works on the UTF-8 representation of the string, converting
3664  * it from the set markup, thus not accounting for any format in it.
3665  *
3666  * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
3667  * it as data when setting the filter. In it it's possible to set limits
3668  * by character count or bytes (any of them is disabled if 0), and both can
3669  * be set at the same time. In that case, it first checks for characters,
3670  * then bytes.
3671  *
3672  * The function will cut the inserted text in order to allow only the first
3673  * number of characters that are still allowed. The cut is made in
3674  * characters, even when limiting by bytes, in order to always contain
3675  * valid ones and avoid half unicode characters making it in.
3676  *
3677  * @ingroup Entry
3678  */
3679 EAPI void
3680 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
3681 {
3682    Elm_Entry_Filter_Limit_Size *lim = data;
3683    char *current;
3684    int len, newlen;
3685    const char *(*text_get)(const Evas_Object *);
3686    const char *widget_type;
3687
3688    EINA_SAFETY_ON_NULL_RETURN(data);
3689    EINA_SAFETY_ON_NULL_RETURN(entry);
3690    EINA_SAFETY_ON_NULL_RETURN(text);
3691
3692    /* hack. I don't want to copy the entire function to work with
3693     * scrolled_entry */
3694    widget_type = elm_widget_type_get(entry);
3695    if (!strcmp(widget_type, "entry"))
3696      text_get = elm_entry_entry_get;
3697    else if (!strcmp(widget_type, "scrolled_entry"))
3698      text_get = elm_scrolled_entry_entry_get;
3699    else /* huh? */
3700      return;
3701
3702    current = elm_entry_markup_to_utf8(text_get(entry));
3703
3704    if (lim->max_char_count > 0)
3705      {
3706         int cut;
3707         len = evas_string_char_len_get(current);
3708         if (len >= lim->max_char_count)
3709           {
3710              evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3711              free(*text);
3712              free(current);
3713              *text = NULL;
3714              return;
3715           }
3716         newlen = evas_string_char_len_get(*text);
3717         cut = strlen(*text);
3718         while ((len + newlen) > lim->max_char_count)
3719           {
3720              cut = evas_string_char_prev_get(*text, cut, NULL);
3721              newlen--;
3722           }
3723         (*text)[cut] = 0;
3724      }
3725
3726    if (lim->max_byte_count > 0)
3727      {
3728         len = strlen(current);
3729         if (len >= lim->max_byte_count)
3730           {
3731              evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3732              free(*text);
3733              free(current);
3734              *text = NULL;
3735              return;
3736           }
3737         newlen = strlen(*text);
3738         while ((len + newlen) > lim->max_byte_count)
3739           {
3740              int p = evas_string_char_prev_get(*text, newlen, NULL);
3741              newlen -= (newlen - p);
3742           }
3743         if (newlen)
3744           (*text)[newlen] = 0;
3745         else
3746           {
3747              free(*text);
3748              *text = NULL;
3749           }
3750      }
3751    free(current);
3752 }
3753
3754 /**
3755  * Filter inserted text based on accepted or rejected sets of characters
3756  *
3757  * Add this filter to an entry to restrict the set of accepted characters
3758  * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
3759  * This structure contains both accepted and rejected sets, but they are
3760  * mutually exclusive. If accepted is set, it will be used, otherwise it
3761  * goes on to the rejected set.
3762  */
3763 EAPI void
3764 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
3765 {
3766    Elm_Entry_Filter_Accept_Set *as = data;
3767    const char *set;
3768    char *insert;
3769    Eina_Bool goes_in;
3770    int read_idx, last_read_idx = 0, read_char;
3771
3772    EINA_SAFETY_ON_NULL_RETURN(data);
3773    EINA_SAFETY_ON_NULL_RETURN(text);
3774
3775    if ((!as->accepted) && (!as->rejected))
3776      return;
3777
3778    if (as->accepted)
3779      {
3780         set = as->accepted;
3781         goes_in = EINA_TRUE;
3782      }
3783    else
3784      {
3785         set = as->rejected;
3786         goes_in = EINA_FALSE;
3787      }
3788
3789    insert = *text;
3790    read_idx = evas_string_char_next_get(*text, 0, &read_char);
3791    while (read_char)
3792      {
3793         int cmp_idx, cmp_char;
3794         Eina_Bool in_set = EINA_FALSE;
3795
3796         cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
3797         while (cmp_char)
3798           {
3799              if (read_char == cmp_char)
3800                {
3801                   in_set = EINA_TRUE;
3802                   break;
3803                }
3804              cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
3805           }
3806         if (in_set == goes_in)
3807           {
3808              int size = read_idx - last_read_idx;
3809              const char *src = (*text) + last_read_idx;
3810              if (src != insert)
3811                memcpy(insert, *text + last_read_idx, size);
3812              insert += size;
3813           }
3814         last_read_idx = read_idx;
3815         read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
3816      }
3817    *insert = 0;
3818 }
3819
3820 /**
3821  * This sets the file (and implicitly loads it) for the text to display and
3822  * then edit. All changes are written back to the file after a short delay if
3823  * the entry object is set to autosave.
3824  *
3825  * @param obj The entry object
3826  * @param file The path to the file to load and save
3827  * @param format The file format
3828  *
3829  * @ingroup Entry
3830  */
3831 EAPI void
3832 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
3833 {
3834    ELM_CHECK_WIDTYPE(obj, widtype);
3835    Widget_Data *wd = elm_widget_data_get(obj);
3836    if (!wd) return;
3837    if (wd->delay_write)
3838      {
3839         ecore_timer_del(wd->delay_write);
3840         wd->delay_write = NULL;
3841      }
3842    if (wd->autosave) _save(obj);
3843    eina_stringshare_replace(&wd->file, file);
3844    wd->format = format;
3845    _load(obj);
3846 }
3847
3848 /**
3849  * Gets the file to load and save and the file format
3850  *
3851  * @param obj The entry object
3852  * @param file The path to the file to load and save
3853  * @param format The file format
3854  *
3855  * @ingroup Entry
3856  */
3857 EAPI void
3858 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
3859 {
3860    ELM_CHECK_WIDTYPE(obj, widtype);
3861    Widget_Data *wd = elm_widget_data_get(obj);
3862    if (!wd) return;
3863    if (file) *file = wd->file;
3864    if (format) *format = wd->format;
3865 }
3866
3867 /**
3868  * This function writes any changes made to the file set with
3869  * elm_entry_file_set()
3870  *
3871  * @param obj The entry object
3872  *
3873  * @ingroup Entry
3874  */
3875 EAPI void
3876 elm_entry_file_save(Evas_Object *obj)
3877 {
3878    ELM_CHECK_WIDTYPE(obj, widtype);
3879    Widget_Data *wd = elm_widget_data_get(obj);
3880    if (!wd) return;
3881    if (wd->delay_write)
3882      {
3883         ecore_timer_del(wd->delay_write);
3884         wd->delay_write = NULL;
3885      }
3886    _save(obj);
3887    wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
3888 }
3889
3890 /**
3891  * This sets the entry object to 'autosave' the loaded text file or not.
3892  *
3893  * @param obj The entry object
3894  * @param autosave Autosave the loaded file or not
3895  *
3896  * @ingroup Entry
3897  */
3898 EAPI void
3899 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
3900 {
3901    ELM_CHECK_WIDTYPE(obj, widtype);
3902    Widget_Data *wd = elm_widget_data_get(obj);
3903    if (!wd) return;
3904    wd->autosave = !!autosave;
3905 }
3906
3907 /**
3908  * This gets the entry object's 'autosave' status.
3909  *
3910  * @param obj The entry object
3911  * @return Autosave the loaded file or not
3912  *
3913  * @ingroup Entry
3914  */
3915 EAPI Eina_Bool
3916 elm_entry_autosave_get(const Evas_Object *obj)
3917 {
3918    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3919    Widget_Data *wd = elm_widget_data_get(obj);
3920    if (!wd) return EINA_FALSE;
3921    return wd->autosave;
3922 }
3923
3924 /**
3925  * Control pasting of text and images for the widget.
3926  *
3927  * Normally the entry allows both text and images to be pasted.  By setting
3928  * textonly to be true, this prevents images from being pasted.
3929  *
3930  * Note this only changes the behaviour of text.
3931  *
3932  * @param obj The entry object
3933  * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is text+image+other.
3934  *
3935  * @ingroup Entry
3936  */
3937 EAPI void
3938 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
3939 {
3940    Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
3941    ELM_CHECK_WIDTYPE(obj, widtype);
3942    Widget_Data *wd = elm_widget_data_get(obj);
3943    if (!wd) return;
3944    textonly = !!textonly;
3945    if (wd->textonly == textonly) return;
3946    wd->textonly = !!textonly;
3947    if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
3948 #ifdef HAVE_ELEMENTARY_X
3949    elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
3950 #endif
3951 }
3952
3953 /**
3954  * Getting elm_entry text paste/drop mode.
3955  *
3956  * In textonly mode, only text may be pasted or dropped into the widget.
3957  *
3958  * @param obj The entry object
3959  * @return If the widget only accepts text from pastes.
3960  *
3961  * @ingroup Entry
3962  */
3963 EAPI Eina_Bool
3964 elm_entry_cnp_textonly_get(Evas_Object *obj)
3965 {
3966    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3967    Widget_Data *wd = elm_widget_data_get(obj);
3968    if (!wd) return EINA_FALSE;
3969    return wd->textonly;
3970 }
3971
3972 /**
3973  * This sets the attribute to show the input panel automatically.
3974  *
3975  * @param obj The entry object
3976  * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
3977  *
3978  * @ingroup Entry
3979  */
3980 EAPI void
3981 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
3982 {
3983    ELM_CHECK_WIDTYPE(obj, widtype);
3984    Widget_Data *wd = elm_widget_data_get(obj);
3985    if (!wd) return;
3986
3987    wd->input_panel_enable = enabled;
3988    edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
3989 }
3990
3991 /**
3992  * Set the input panel layout of the entry
3993  *
3994  * @param obj The entry object
3995  * @param layout the layout to set
3996  *
3997  * @ingroup Entry
3998  */
3999 EAPI void
4000 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
4001 {
4002    ELM_CHECK_WIDTYPE(obj, widtype);
4003    Widget_Data *wd = elm_widget_data_get(obj);
4004    if (!wd) return;
4005
4006    Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
4007    if (!ic) return;
4008
4009    wd->input_panel_layout = layout;
4010
4011    ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);
4012 }
4013
4014 /**
4015  * Set the magnifier style of the entry
4016  *
4017  * @param obj The entry object
4018  * @param type the magnifier style to set
4019  *
4020  * @ingroup Entry
4021  */
4022 EAPI void
4023 elm_entry_magnifier_type_set(Evas_Object *obj, int type)
4024 {
4025    ELM_CHECK_WIDTYPE(obj, widtype);
4026    Widget_Data *wd = elm_widget_data_get(obj);
4027    if (!wd) return;
4028
4029    wd->mgf_type = type;
4030    _magnifier_create(obj);
4031 }