elementary - entry, genlist, gengrid, image, icon, hover, frame, diskselector, index...
[framework/uifw/elementary.git] / src / lib / elm_entry.c
1 #include <Elementary.h>
2 #include <Elementary_Cursor.h>
3 #include "elm_priv.h"
4
5 /**
6  * @defgroup Entry Entry
7  *
8  * An entry is a convenience widget which shows
9  * a box that the user can enter text into.  Unlike a
10  * @ref Scrolled_Entry widget, entries DO NOT scroll with user
11  * input.  Entry widgets are capable of expanding past the
12  * boundaries of the window, thus resizing the window to its
13  * own length.
14  *
15  * You can also insert "items" in the entry with:
16  *
17  * \<item size=16x16 vsize=full href=emoticon/haha\>\</item\>
18  *
19  * for example. sizing can be set bu size=WxH, relsize=WxH or absize=WxH with
20  * vsize=ascent or vsize=full. the href=NAME sets the item name. Entry
21  * supports a list of emoticon names by default. These are:
22  *
23  * - emoticon/angry
24  * - emoticon/angry-shout
25  * - emoticon/crazy-laugh
26  * - emoticon/evil-laugh
27  * - emoticon/evil
28  * - emoticon/goggle-smile
29  * - emoticon/grumpy
30  * - emoticon/grumpy-smile
31  * - emoticon/guilty
32  * - emoticon/guilty-smile
33  * - emoticon/haha
34  * - emoticon/half-smile
35  * - emoticon/happy-panting
36  * - emoticon/happy
37  * - emoticon/indifferent
38  * - emoticon/kiss
39  * - emoticon/knowing-grin
40  * - emoticon/laugh
41  * - emoticon/little-bit-sorry
42  * - emoticon/love-lots
43  * - emoticon/love
44  * - emoticon/minimal-smile
45  * - emoticon/not-happy
46  * - emoticon/not-impressed
47  * - emoticon/omg
48  * - emoticon/opensmile
49  * - emoticon/smile
50  * - emoticon/sorry
51  * - emoticon/squint-laugh
52  * - emoticon/surprised
53  * - emoticon/suspicious
54  * - emoticon/tongue-dangling
55  * - emoticon/tongue-poke
56  * - emoticon/uh
57  * - emoticon/unhappy
58  * - emoticon/very-sorry
59  * - emoticon/what
60  * - emoticon/wink
61  * - emoticon/worried
62  * - emoticon/wtf
63  *
64  * These are built-in currently, but you can add your own item provieer that
65  * can create inlined objects in the text and fill the space allocated to the
66  * item with a custom object of your own.
67  *
68  * See the entry test for some more examples of use of this.
69  *
70  * Entries have functions to load a text file, display it,
71  * allowing editing of it and saving of changes back to the file loaded.
72  * Changes are written back to the original file after a short delay.
73  * The file to load and save to is specified by elm_entry_file_set().
74  *
75  * Signals that you can add callbacks for are:
76  * - "changed" - The text within the entry was changed
77  * - "activated" - The entry has had editing finished and changes are to be committed (generally when enter key is pressed)
78  * - "press" - The entry has been clicked
79  * - "longpressed" - The entry has been clicked for a couple seconds
80  * - "clicked" - The entry has been clicked
81  * - "clicked,double" - The entry has been double clicked
82  * - "focused" - The entry has received focus
83  * - "unfocused" - The entry has lost focus
84  * - "selection,paste" - A paste action has occurred
85  * - "selection,copy" - A copy action has occurred
86  * - "selection,cut" - A cut action has occurred
87  * - "selection,start" - A selection has begun
88  * - "selection,changed" - The selection has changed
89  * - "selection,cleared" - The selection has been cleared
90  * - "cursor,changed" - The cursor has changed
91  * - "anchor,clicked" - The anchor has been clicked
92  */
93
94 typedef struct _Mod_Api Mod_Api;
95
96 typedef struct _Widget_Data Widget_Data;
97 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
98 typedef struct _Elm_Entry_Item_Provider Elm_Entry_Item_Provider;
99 typedef struct _Elm_Entry_Text_Filter Elm_Entry_Text_Filter;
100
101 struct _Widget_Data
102 {
103    Evas_Object *ent;
104    Evas_Object *hoversel;
105    Ecore_Job *deferred_recalc_job;
106    Ecore_Event_Handler *sel_notify_handler;
107    Ecore_Event_Handler *sel_clear_handler;
108    Ecore_Timer *longpress_timer;
109    Ecore_Timer *delay_write;
110    /* Only for clipboard */
111    const char *cut_sel;
112    const char *text;
113    const char *file;
114    Elm_Text_Format format;
115    Evas_Coord lastw;
116    Evas_Coord downx, downy;
117    Evas_Coord cx, cy, cw, ch;
118    Eina_List *items;
119    Eina_List *item_providers;
120    Eina_List *text_filters;
121    Ecore_Job *hovdeljob;
122    Mod_Api *api; // module api if supplied
123    Eina_Bool changed : 1;
124    Eina_Bool linewrap : 1;
125    Eina_Bool char_linewrap : 1;
126    Eina_Bool single_line : 1;
127    Eina_Bool password : 1;
128    Eina_Bool editable : 1;
129    Eina_Bool selection_asked : 1;
130    Eina_Bool have_selection : 1;
131    Eina_Bool selmode : 1;
132    Eina_Bool deferred_cur : 1;
133    Eina_Bool disabled : 1;
134    Eina_Bool context_menu : 1;
135    Eina_Bool drag_selection_asked : 1;
136    Eina_Bool can_write : 1;
137    Eina_Bool autosave : 1;
138    Eina_Bool textonly : 1;
139    int cursor_pos;
140 };
141
142 struct _Elm_Entry_Context_Menu_Item
143 {
144    Evas_Object *obj;
145    const char *label;
146    const char *icon_file;
147    const char *icon_group;
148    Elm_Icon_Type icon_type;
149    Evas_Smart_Cb func;
150    void *data;
151 };
152
153 struct _Elm_Entry_Item_Provider
154 {
155    Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
156    void *data;
157 };
158
159 struct _Elm_Entry_Text_Filter
160 {
161    void (*func) (void *data, Evas_Object *entry, char **text);
162    void *data;
163 };
164
165 static const char *widtype = NULL;
166
167 #ifdef HAVE_ELEMENTARY_X
168 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
169 #endif
170 static void _del_hook(Evas_Object *obj);
171 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
172 static void _theme_hook(Evas_Object *obj);
173 static void _disable_hook(Evas_Object *obj);
174 static void _sizing_eval(Evas_Object *obj);
175 static void _on_focus_hook(void *data, Evas_Object *obj);
176 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
177 static const char *_getbase(Evas_Object *obj);
178 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
179 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
180 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
181 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
182 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
183 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
184 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
185 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
186
187 static const char SIG_CHANGED[] = "changed";
188 static const char SIG_ACTIVATED[] = "activated";
189 static const char SIG_PRESS[] = "press";
190 static const char SIG_LONGPRESSED[] = "longpressed";
191 static const char SIG_CLICKED[] = "clicked";
192 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
193 static const char SIG_FOCUSED[] = "focused";
194 static const char SIG_UNFOCUSED[] = "unfocused";
195 static const char SIG_SELECTION_PASTE[] = "selection,paste";
196 static const char SIG_SELECTION_COPY[] = "selection,copy";
197 static const char SIG_SELECTION_CUT[] = "selection,cut";
198 static const char SIG_SELECTION_START[] = "selection,start";
199 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
200 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
201 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
202 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
203 static const Evas_Smart_Cb_Description _signals[] = {
204        {SIG_CHANGED, ""},
205        {SIG_ACTIVATED, ""},
206        {SIG_PRESS, ""},
207        {SIG_LONGPRESSED, ""},
208        {SIG_CLICKED, ""},
209        {SIG_CLICKED_DOUBLE, ""},
210        {SIG_FOCUSED, ""},
211        {SIG_UNFOCUSED, ""},
212        {SIG_SELECTION_PASTE, ""},
213        {SIG_SELECTION_COPY, ""},
214        {SIG_SELECTION_CUT, ""},
215        {SIG_SELECTION_START, ""},
216        {SIG_SELECTION_CHANGED, ""},
217        {SIG_SELECTION_CLEARED, ""},
218        {SIG_CURSOR_CHANGED, ""},
219        {SIG_ANCHOR_CLICKED, ""},
220        {NULL, NULL}
221 };
222
223 static Eina_List *entries = NULL;
224
225 struct _Mod_Api
226 {
227    void (*obj_hook) (Evas_Object *obj);
228    void (*obj_unhook) (Evas_Object *obj);
229    void (*obj_longpress) (Evas_Object *obj);
230 };
231
232 static Mod_Api *
233 _module(Evas_Object *obj __UNUSED__)
234 {
235    static Elm_Module *m = NULL;
236    if (m) goto ok; // already found - just use
237    if (!(m = _elm_module_find_as("entry/api"))) return NULL;
238    // get module api
239    m->api = malloc(sizeof(Mod_Api));
240    if (!m->api) return NULL;
241    ((Mod_Api *)(m->api)      )->obj_hook = // called on creation
242       _elm_module_symbol_get(m, "obj_hook");
243    ((Mod_Api *)(m->api)      )->obj_unhook = // called on deletion
244       _elm_module_symbol_get(m, "obj_unhook");
245    ((Mod_Api *)(m->api)      )->obj_longpress = // called on long press menu
246       _elm_module_symbol_get(m, "obj_longpress");
247 ok: // ok - return api
248    return m->api;
249 }
250
251 static char *
252 _buf_append(char *buf, const char *str, int *len, int *alloc)
253 {
254    int len2 = strlen(str);
255    if ((*len + len2) >= *alloc)
256      {
257         char *buf2 = realloc(buf, *alloc + len2 + 512);
258         if (!buf2) return NULL;
259         buf = buf2;
260         *alloc += (512 + len2);
261      }
262    strcpy(buf + *len, str);
263    *len += len2;
264    return buf;
265 }
266
267 static char *
268 _load_file(const char *file)
269 {
270    FILE *f;
271    size_t size;
272    int alloc = 0, len = 0;
273    char *text = NULL, buf[16384 + 1];
274
275    f = fopen(file, "rb");
276    if (!f) return NULL;
277    while ((size = fread(buf, 1, sizeof(buf) - 1, f)))
278      {
279         char *tmp_text;
280         buf[size] = 0;
281         tmp_text = _buf_append(text, buf, &len, &alloc);
282         if (!tmp_text) break;
283         text = tmp_text;
284      }
285    fclose(f);
286    return text;
287 }
288
289 static char *
290 _load_plain(const char *file)
291 {
292    char *text;
293
294    text = _load_file(file);
295    if (text)
296      {
297         char *text2;
298
299         text2 = elm_entry_utf8_to_markup(text);
300         free(text);
301         return text2;
302      }
303    return NULL;
304 }
305
306 static void
307 _load(Evas_Object *obj)
308 {
309    Widget_Data *wd = elm_widget_data_get(obj);
310    char *text;
311    if (!wd) return;
312    if (!wd->file)
313      {
314         elm_entry_entry_set(obj, "");
315         return;
316      }
317    switch (wd->format)
318      {
319       case ELM_TEXT_FORMAT_PLAIN_UTF8:
320          text = _load_plain(wd->file);
321          break;
322       case ELM_TEXT_FORMAT_MARKUP_UTF8:
323          text = _load_file(wd->file);
324          break;
325       default:
326          text = NULL;
327          break;
328      }
329    if (text)
330      {
331         elm_entry_entry_set(obj, text);
332         free(text);
333      }
334    else
335      elm_entry_entry_set(obj, "");
336 }
337
338 static void
339 _save_markup_utf8(const char *file, const char *text)
340 {
341    FILE *f;
342
343    if ((!text) || (!text[0]))
344      {
345         ecore_file_unlink(file);
346         return;
347      }
348    f = fopen(file, "wb");
349    if (!f)
350      {
351         // FIXME: report a write error
352         return;
353      }
354    fputs(text, f); // FIXME: catch error
355    fclose(f);
356 }
357
358 static void
359 _save_plain_utf8(const char *file, const char *text)
360 {
361    char *text2;
362
363    text2 = elm_entry_markup_to_utf8(text);
364    if (!text2)
365      return;
366    _save_markup_utf8(file, text2);
367    free(text2);
368 }
369
370 static void
371 _save(Evas_Object *obj)
372 {
373    Widget_Data *wd = elm_widget_data_get(obj);
374    if (!wd) return;
375    if (!wd->file) return;
376    switch (wd->format)
377      {
378       case ELM_TEXT_FORMAT_PLAIN_UTF8:
379          _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
380          break;
381       case ELM_TEXT_FORMAT_MARKUP_UTF8:
382          _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
383          break;
384       default:
385          break;
386      }
387 }
388
389 static Eina_Bool
390 _delay_write(void *data)
391 {
392    Widget_Data *wd = elm_widget_data_get(data);
393    if (!wd) return ECORE_CALLBACK_CANCEL;
394    _save(data);
395    wd->delay_write = NULL;
396    return ECORE_CALLBACK_CANCEL;
397 }
398
399 static Elm_Entry_Text_Filter *
400 _filter_new(void (*func) (void *data, Evas_Object *entry, char **text), void *data)
401 {
402    Elm_Entry_Text_Filter *tf = ELM_NEW(Elm_Entry_Text_Filter);
403    if (!tf) return NULL;
404
405    tf->func = func;
406    if (func == elm_entry_filter_limit_size)
407      {
408         Elm_Entry_Filter_Limit_Size *lim = data, *lim2;
409
410         if (!data)
411           {
412              free(tf);
413              return NULL;
414           }
415         lim2 = malloc(sizeof(Elm_Entry_Filter_Limit_Size));
416         if (!lim2)
417           {
418              free(tf);
419              return NULL;
420           }
421         memcpy(lim2, lim, sizeof(Elm_Entry_Filter_Limit_Size));
422         tf->data = lim2;
423      }
424    else if (func == elm_entry_filter_accept_set)
425      {
426         Elm_Entry_Filter_Accept_Set *as = data, *as2;
427
428         if (!data)
429           {
430              free(tf);
431              return NULL;
432           }
433         as2 = malloc(sizeof(Elm_Entry_Filter_Accept_Set));
434         if (!as2)
435           {
436              free(tf);
437              return NULL;
438           }
439         if (as->accepted)
440           as2->accepted = eina_stringshare_add(as->accepted);
441         else
442           as2->accepted = NULL;
443         if (as->rejected)
444           as2->rejected = eina_stringshare_add(as->rejected);
445         else
446           as2->rejected = NULL;
447         tf->data = as2;
448      }
449    else
450      tf->data = data;
451    return tf;
452 }
453
454 static void
455 _filter_free(Elm_Entry_Text_Filter *tf)
456 {
457    if (tf->func == elm_entry_filter_limit_size)
458      {
459         Elm_Entry_Filter_Limit_Size *lim = tf->data;
460         if (lim) free(lim);
461      }
462    else if (tf->func == elm_entry_filter_accept_set)
463      {
464         Elm_Entry_Filter_Accept_Set *as = tf->data;
465         if (as)
466           {
467              if (as->accepted) eina_stringshare_del(as->accepted);
468              if (as->rejected) eina_stringshare_del(as->rejected);
469              free(as);
470           }
471      }
472    free(tf);
473 }
474
475 static void
476 _del_pre_hook(Evas_Object *obj)
477 {
478    Widget_Data *wd = elm_widget_data_get(obj);
479    if (!wd) return;
480    if (wd->delay_write)
481      {
482         ecore_timer_del(wd->delay_write);
483         wd->delay_write = NULL;
484         if (wd->autosave) _save(obj);
485      }
486 }
487
488 static void
489 _del_hook(Evas_Object *obj)
490 {
491    Widget_Data *wd = elm_widget_data_get(obj);
492    Elm_Entry_Context_Menu_Item *it;
493    Elm_Entry_Item_Provider *ip;
494    Elm_Entry_Text_Filter *tf;
495
496    if (wd->file) eina_stringshare_del(wd->file);
497
498    if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
499    if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
500
501    entries = eina_list_remove(entries, obj);
502 #ifdef HAVE_ELEMENTARY_X
503    ecore_event_handler_del(wd->sel_notify_handler);
504    ecore_event_handler_del(wd->sel_clear_handler);
505 #endif
506    if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
507    if (wd->text) eina_stringshare_del(wd->text);
508    if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
509    if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
510    EINA_LIST_FREE(wd->items, it)
511      {
512         eina_stringshare_del(it->label);
513         eina_stringshare_del(it->icon_file);
514         eina_stringshare_del(it->icon_group);
515         free(it);
516      }
517    EINA_LIST_FREE(wd->item_providers, ip)
518      {
519         free(ip);
520      }
521    EINA_LIST_FREE(wd->text_filters, tf)
522      {
523         _filter_free(tf);
524      }
525    free(wd);
526 }
527
528 static void
529 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
530 {
531    Widget_Data *wd = elm_widget_data_get(obj);
532    edje_object_mirrored_set(wd->ent, rtl);
533 }
534
535 static void
536 _theme_hook(Evas_Object *obj)
537 {
538    Widget_Data *wd = elm_widget_data_get(obj);
539    const char *t;
540    _elm_widget_mirrored_reload(obj);
541    _mirrored_set(obj, elm_widget_mirrored_get(obj));
542
543    t = eina_stringshare_add(elm_entry_entry_get(obj));
544    _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
545    elm_entry_entry_set(obj, t);
546    eina_stringshare_del(t);
547    if (elm_widget_disabled_get(obj))
548      edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
549    elm_entry_cursor_pos_set(obj, wd->cursor_pos);
550    if (elm_widget_focus_get(obj))
551      edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
552    edje_object_message_signal_process(wd->ent);
553    edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
554    _sizing_eval(obj);
555 }
556
557 static void
558 _disable_hook(Evas_Object *obj)
559 {
560    Widget_Data *wd = elm_widget_data_get(obj);
561
562    if (elm_widget_disabled_get(obj))
563      {
564         edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
565         wd->disabled = EINA_TRUE;
566      }
567    else
568      {
569         edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
570         wd->disabled = EINA_FALSE;
571      }
572 }
573
574 static void
575 _elm_win_recalc_job(void *data)
576 {
577    Widget_Data *wd = elm_widget_data_get(data);
578    Evas_Coord minw = -1, minh = -1, maxh = -1;
579    Evas_Coord resw, resh, minminw;
580    if (!wd) return;
581    wd->deferred_recalc_job = NULL;
582    evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
583    resh = 0;
584    edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, 0, 0);
585    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
586    minminw = minw;
587    edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
588    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
589    evas_object_size_hint_min_set(data, minminw, minh);
590    if (wd->single_line) maxh = minh;
591    evas_object_size_hint_max_set(data, -1, maxh);
592    if (wd->deferred_cur)
593      elm_widget_show_region_set(data, wd->cx, wd->cy, wd->cw, wd->ch);
594 }
595
596 static void
597 _sizing_eval(Evas_Object *obj)
598 {
599    Widget_Data *wd = elm_widget_data_get(obj);
600    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
601    Evas_Coord resw, resh;
602    if (!wd) return;
603    if ((wd->linewrap) || (wd->char_linewrap))
604      {
605         evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
606         if ((resw == wd->lastw) && (!wd->changed)) return;
607         wd->changed = EINA_FALSE;
608         wd->lastw = resw;
609         if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
610         wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
611      }
612    else
613      {
614         evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
615         edje_object_size_min_calc(wd->ent, &minw, &minh);
616         elm_coords_finger_size_adjust(1, &minw, 1, &minh);
617         evas_object_size_hint_min_set(obj, minw, minh);
618         if (wd->single_line) maxh = minh;
619         evas_object_size_hint_max_set(obj, maxw, maxh);
620      }
621 }
622
623 static void
624 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
625 {
626    Widget_Data *wd = elm_widget_data_get(obj);
627    Evas_Object *top = elm_widget_top_get(obj);
628    if (!wd) return;
629    if (!wd->editable) return;
630    if (elm_widget_focus_get(obj))
631      {
632         evas_object_focus_set(wd->ent, EINA_TRUE);
633         edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
634         if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
635         evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
636      }
637    else
638      {
639         edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
640         evas_object_focus_set(wd->ent, EINA_FALSE);
641         if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
642         evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
643      }
644 }
645
646 static void
647 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
648 {
649    Widget_Data *wd = elm_widget_data_get(obj);
650    if (!wd) return;
651    edje_object_signal_emit(wd->ent, emission, source);
652 }
653
654 static void
655 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
656 {
657    Widget_Data *wd = elm_widget_data_get(obj);
658    if (!wd) return;
659    edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
660 }
661
662 static void
663 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
664 {
665    Widget_Data *wd = elm_widget_data_get(obj);
666    edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
667                                         data);
668 }
669
670 static void
671 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
672 {
673    Widget_Data *wd = elm_widget_data_get(obj);
674    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
675 }
676
677 static void
678 _hoversel_position(Evas_Object *obj)
679 {
680    Widget_Data *wd = elm_widget_data_get(obj);
681    Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
682    if (!wd) return;
683    evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
684    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
685                                              &cx, &cy, &cw, &ch);
686    evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
687    if (cw < mw)
688      {
689         cx += (cw - mw) / 2;
690         cw = mw;
691      }
692    if (ch < mh)
693      {
694         cy += (ch - mh) / 2;
695         ch = mh;
696      }
697    evas_object_move(wd->hoversel, x + cx, y + cy);
698    evas_object_resize(wd->hoversel, cw, ch);
699 }
700
701 static void
702 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
703 {
704    Widget_Data *wd = elm_widget_data_get(data);
705
706    if (wd->hoversel) _hoversel_position(data);
707 }
708
709 static void
710 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
711 {
712    Widget_Data *wd = elm_widget_data_get(data);
713    if (!wd) return;
714    if ((wd->linewrap) || (wd->char_linewrap))
715      {
716         _sizing_eval(data);
717      }
718    if (wd->hoversel) _hoversel_position(data);
719    //   Evas_Coord ww, hh;
720    //   evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
721 }
722
723 static void
724 _hover_del(void *data)
725 {
726    Widget_Data *wd = elm_widget_data_get(data);
727    if (!wd) return;
728
729    if (wd->hoversel)
730      {
731         evas_object_del(wd->hoversel);
732         wd->hoversel = NULL;
733      }
734    wd->hovdeljob = NULL;
735 }
736
737 static void
738 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
739 {
740    Widget_Data *wd = elm_widget_data_get(data);
741    if (!wd) return;
742    if (wd->hoversel) evas_object_hide(wd->hoversel);
743    if (wd->selmode)
744      {
745         if (!wd->password)
746           edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
747      }
748    elm_widget_scroll_freeze_pop(data);
749    if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
750    wd->hovdeljob = ecore_job_add(_hover_del, data);
751 }
752
753 static void
754 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
755 {
756    Widget_Data *wd = elm_widget_data_get(data);
757    if (!wd) return;
758    wd->selmode = EINA_TRUE;
759    edje_object_part_text_select_none(wd->ent, "elm.text");
760    if (!wd->password)
761      edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
762    edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
763    elm_widget_scroll_hold_push(data);
764 }
765
766 static void
767 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
768 {
769    Widget_Data *wd = elm_widget_data_get(data);
770    if (!wd) return;
771    evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
772    if (wd->sel_notify_handler)
773      {
774 #ifdef HAVE_ELEMENTARY_X
775         Elm_Sel_Format formats;
776         wd->selection_asked = EINA_TRUE;
777         formats = ELM_SEL_FORMAT_MARKUP;
778         if (!wd->textonly)
779           formats |= ELM_SEL_FORMAT_IMAGE;
780         elm_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL);
781 #endif
782      }
783 }
784
785 static void
786 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
787 {
788    Widget_Data *wd = elm_widget_data_get(obj);
789    const char *sel;
790
791    if (!wd) return;
792    sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
793    elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
794    if (seltype == ELM_SEL_CLIPBOARD)
795      eina_stringshare_replace(&wd->cut_sel, sel);
796 }
797
798 static void
799 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
800 {
801    Widget_Data *wd = elm_widget_data_get(data);
802
803    /* Store it */
804    wd->selmode = EINA_FALSE;
805    edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
806    edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
807    elm_widget_scroll_hold_pop(data);
808    _store_selection(ELM_SEL_CLIPBOARD, data);
809    edje_object_part_text_insert(wd->ent, "elm.text", "");
810    edje_object_part_text_select_none(wd->ent, "elm.text");
811 }
812
813 static void
814 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
815 {
816    Widget_Data *wd = elm_widget_data_get(data);
817    if (!wd) return;
818    wd->selmode = EINA_FALSE;
819    edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
820    edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
821    elm_widget_scroll_hold_pop(data);
822    _store_selection(ELM_SEL_CLIPBOARD, data);
823    //   edje_object_part_text_select_none(wd->ent, "elm.text");
824 }
825
826 static void
827 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
828 {
829    Widget_Data *wd = elm_widget_data_get(data);
830    if (!wd) return;
831    wd->selmode = EINA_FALSE;
832    edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
833    edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
834    elm_widget_scroll_hold_pop(data);
835    edje_object_part_text_select_none(wd->ent, "elm.text");
836 }
837
838 static void
839 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
840 {
841    Elm_Entry_Context_Menu_Item *it = data;
842    Evas_Object *obj2 = it->obj;
843    if (it->func) it->func(it->data, obj2, NULL);
844 }
845
846 static Eina_Bool
847 _long_press(void *data)
848 {
849    Widget_Data *wd = elm_widget_data_get(data);
850    Evas_Object *top;
851    const Eina_List *l;
852    const Elm_Entry_Context_Menu_Item *it;
853    if (!wd) return ECORE_CALLBACK_CANCEL;
854    if ((wd->api) && (wd->api->obj_longpress))
855      {
856         wd->api->obj_longpress(data);
857      }
858    else if (wd->context_menu)
859      {
860         const char *context_menu_orientation;
861
862         if (wd->hoversel) evas_object_del(wd->hoversel);
863         else elm_widget_scroll_freeze_push(data);
864         wd->hoversel = elm_hoversel_add(data);
865         context_menu_orientation = edje_object_data_get
866            (wd->ent, "context_menu_orientation");
867         if ((context_menu_orientation) &&
868             (!strcmp(context_menu_orientation, "horizontal")))
869           elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
870         elm_object_style_set(wd->hoversel, "entry");
871         elm_widget_sub_object_add(data, wd->hoversel);
872         elm_hoversel_label_set(wd->hoversel, "Text");
873         top = elm_widget_top_get(data);
874         if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
875         evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, data);
876         if (!wd->selmode)
877           {
878              if (!wd->password)
879                elm_hoversel_item_add(wd->hoversel, E_("Select"), NULL, ELM_ICON_NONE,
880                                      _select, data);
881              if (1) // need way to detect if someone has a selection
882                {
883                   if (wd->editable)
884                     elm_hoversel_item_add(wd->hoversel, E_("Paste"), NULL, ELM_ICON_NONE,
885                                           _paste, data);
886                }
887           }
888         else
889           {
890              if (!wd->password)
891                {
892                   if (wd->have_selection)
893                     {
894                        elm_hoversel_item_add(wd->hoversel, E_("Copy"), NULL, ELM_ICON_NONE,
895                                              _copy, data);
896                        if (wd->editable)
897                          elm_hoversel_item_add(wd->hoversel, E_("Cut"), NULL, ELM_ICON_NONE,
898                                                _cut, data);
899                     }
900                   elm_hoversel_item_add(wd->hoversel, E_("Cancel"), NULL, ELM_ICON_NONE,
901                                         _cancel, data);
902                }
903           }
904         EINA_LIST_FOREACH(wd->items, l, it)
905           {
906              elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
907                                    it->icon_type, _item_clicked, it);
908           }
909         if (wd->hoversel)
910           {
911              _hoversel_position(data);
912              evas_object_show(wd->hoversel);
913              elm_hoversel_hover_begin(wd->hoversel);
914           }
915         edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
916         edje_object_part_text_select_abort(wd->ent, "elm.text");
917      }
918    wd->longpress_timer = NULL;
919    evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
920    return ECORE_CALLBACK_CANCEL;
921 }
922
923 static void
924 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
925 {
926    Widget_Data *wd = elm_widget_data_get(data);
927    Evas_Event_Mouse_Down *ev = event_info;
928    if (!wd) return;
929    if (wd->disabled) return;
930    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
931    if (ev->button != 1) return;
932    //   if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
933    if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
934    wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
935    wd->downx = ev->canvas.x;
936    wd->downy = ev->canvas.y;
937 }
938
939 static void
940 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
941 {
942    Widget_Data *wd = elm_widget_data_get(data);
943    Evas_Event_Mouse_Up *ev = event_info;
944    if (!wd) return;
945    if (wd->disabled) return;
946    if (ev->button != 1) return;
947    if (wd->longpress_timer)
948      {
949         ecore_timer_del(wd->longpress_timer);
950         wd->longpress_timer = NULL;
951      }
952 }
953
954 static void
955 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
956 {
957    Widget_Data *wd = elm_widget_data_get(data);
958    Evas_Event_Mouse_Move *ev = event_info;
959    if (!wd) return;
960    if (wd->disabled) return;
961    if (!wd->selmode)
962      {
963         if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
964           {
965              if (wd->longpress_timer)
966                {
967                   ecore_timer_del(wd->longpress_timer);
968                   wd->longpress_timer = NULL;
969                }
970           }
971         else if (wd->longpress_timer)
972           {
973              Evas_Coord dx, dy;
974
975              dx = wd->downx - ev->cur.canvas.x;
976              dx *= dx;
977              dy = wd->downy - ev->cur.canvas.y;
978              dy *= dy;
979              if ((dx + dy) >
980                  ((_elm_config->finger_size / 2) *
981                   (_elm_config->finger_size / 2)))
982                {
983                   ecore_timer_del(wd->longpress_timer);
984                   wd->longpress_timer = NULL;
985                }
986           }
987      }
988    else if (wd->longpress_timer)
989      {
990         Evas_Coord dx, dy;
991
992         dx = wd->downx - ev->cur.canvas.x;
993         dx *= dx;
994         dy = wd->downy - ev->cur.canvas.y;
995         dy *= dy;
996         if ((dx + dy) >
997             ((_elm_config->finger_size / 2) *
998              (_elm_config->finger_size / 2)))
999           {
1000              ecore_timer_del(wd->longpress_timer);
1001              wd->longpress_timer = NULL;
1002           }
1003      }
1004 }
1005
1006 static const char *
1007 _getbase(Evas_Object *obj)
1008 {
1009    Widget_Data *wd = elm_widget_data_get(obj);
1010    if (!wd) return "base";
1011    if (wd->editable)
1012      {
1013         if (wd->password) return "base-password";
1014         else
1015           {
1016              if (wd->single_line) return "base-single";
1017              else
1018                {
1019                   if (wd->linewrap) return "base";
1020                   else if (wd->char_linewrap) return "base-charwrap";
1021                   else  return "base-nowrap";
1022                }
1023           }
1024      }
1025    else
1026      {
1027         if (wd->password) return "base-password";
1028         else
1029           {
1030              if (wd->single_line) return "base-single-noedit";
1031              else
1032                {
1033                   if (wd->linewrap) return "base-noedit";
1034                   else if (wd->char_linewrap) return "base-noedit-charwrap";
1035                   else  return "base-nowrap-noedit";
1036                }
1037           }
1038      }
1039    return "base";
1040 }
1041
1042 static void
1043 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1044 {
1045    Widget_Data *wd = elm_widget_data_get(data);
1046    if (!wd) return;
1047    wd->changed = EINA_TRUE;
1048    _sizing_eval(data);
1049    if (wd->text) eina_stringshare_del(wd->text);
1050    wd->text = NULL;
1051    evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1052    if (wd->delay_write)
1053      {
1054         ecore_timer_del(wd->delay_write);
1055         wd->delay_write = NULL;
1056      }
1057    if ((!wd->autosave) || (!wd->file)) return;
1058    wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1059 }
1060
1061 static void
1062 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1063 {
1064    Widget_Data *wd = elm_widget_data_get(data);
1065    const Eina_List *l;
1066    Evas_Object *entry;
1067    if (!wd) return;
1068    EINA_LIST_FOREACH(entries, l, entry)
1069      {
1070         if (entry != data) elm_entry_select_none(entry);
1071      }
1072    wd->have_selection = EINA_TRUE;
1073    evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1074 #ifdef HAVE_ELEMENTARY_X
1075    if (wd->sel_notify_handler)
1076      {
1077         const char *txt = elm_entry_selection_get(data);
1078         Evas_Object *top;
1079
1080         top = elm_widget_top_get(data);
1081         if ((top) && (elm_win_xwindow_get(top)))
1082           elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1083      }
1084 #endif
1085 }
1086
1087 static void
1088 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1089 {
1090    Widget_Data *wd = elm_widget_data_get(data);
1091    if (!wd) return;
1092    wd->have_selection = EINA_TRUE;
1093    evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1094    elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1095                      elm_entry_selection_get(data));
1096 }
1097
1098 static void
1099 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1100 {
1101    Widget_Data *wd = elm_widget_data_get(data);
1102    if (!wd) return;
1103    if (!wd->have_selection) return;
1104    wd->have_selection = EINA_FALSE;
1105    evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1106    if (wd->sel_notify_handler)
1107      {
1108         if (wd->cut_sel)
1109           {
1110 #ifdef HAVE_ELEMENTARY_X
1111              Evas_Object *top;
1112
1113              top = elm_widget_top_get(data);
1114              if ((top) && (elm_win_xwindow_get(top)))
1115                elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1116                                  wd->cut_sel);
1117 #endif
1118              eina_stringshare_del(wd->cut_sel);
1119              wd->cut_sel = NULL;
1120           }
1121         else
1122           {
1123 #ifdef HAVE_ELEMENTARY_X
1124              Evas_Object *top;
1125
1126              top = elm_widget_top_get(data);
1127              if ((top) && (elm_win_xwindow_get(top)))
1128                elm_selection_clear(ELM_SEL_PRIMARY, data);
1129 #endif
1130           }
1131      }
1132 }
1133
1134 static void
1135 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1136 {
1137    Widget_Data *wd = elm_widget_data_get(data);
1138    if (!wd) return;
1139    evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1140    if (wd->sel_notify_handler)
1141      {
1142 #ifdef HAVE_ELEMENTARY_X
1143         Evas_Object *top;
1144
1145         top = elm_widget_top_get(data);
1146         if ((top) && (elm_win_xwindow_get(top)))
1147           {
1148              wd->selection_asked = EINA_TRUE;
1149              elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
1150                                NULL, NULL);
1151           }
1152 #endif
1153      }
1154 }
1155
1156 static void
1157 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1158 {
1159    Widget_Data *wd = elm_widget_data_get(data);
1160    if (!wd) return;
1161    evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1162    elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1163                      elm_entry_selection_get(data));
1164 }
1165
1166 static void
1167 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1168 {
1169    Widget_Data *wd = elm_widget_data_get(data);
1170    if (!wd) return;
1171    evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1172    elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1173                      elm_entry_selection_get(data));
1174    edje_object_part_text_insert(wd->ent, "elm.text", "");
1175    wd->changed = EINA_TRUE;
1176    _sizing_eval(data);
1177 }
1178
1179 static void
1180 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1181 {
1182    Widget_Data *wd = elm_widget_data_get(data);
1183    Evas_Coord cx, cy, cw, ch;
1184    if (!wd) return;
1185    evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1186    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1187                                              &cx, &cy, &cw, &ch);
1188    wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1189    if (!wd->deferred_recalc_job)
1190      elm_widget_show_region_set(data, cx, cy, cw, ch);
1191    else
1192      {
1193         wd->deferred_cur = EINA_TRUE;
1194         wd->cx = cx;
1195         wd->cy = cy;
1196         wd->cw = cw;
1197         wd->ch = ch;
1198      }
1199 }
1200
1201 static void
1202 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1203 {
1204    Widget_Data *wd = elm_widget_data_get(data);
1205    if (!wd) return;
1206 }
1207
1208 static void
1209 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1210 {
1211    Widget_Data *wd = elm_widget_data_get(data);
1212    if (!wd) return;
1213 }
1214
1215 static void
1216 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1217 {
1218    Widget_Data *wd = elm_widget_data_get(data);
1219    Elm_Entry_Anchor_Info ei;
1220    char *buf2, *p, *p2, *n;
1221    if (!wd) return;
1222    p = strrchr(emission, ',');
1223    if (p)
1224      {
1225         const Eina_List *geoms;
1226
1227         n = p + 1;
1228         p2 = p -1;
1229         while (p2 >= emission)
1230           {
1231              if (*p2 == ',') break;
1232              p2--;
1233           }
1234         p2++;
1235         buf2 = alloca(5 + p - p2);
1236         strncpy(buf2, p2, p - p2);
1237         buf2[p - p2] = 0;
1238         ei.name = n;
1239         ei.button = atoi(buf2);
1240         ei.x = ei.y = ei.w = ei.h = 0;
1241         geoms =
1242            edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1243         if (geoms)
1244           {
1245              Evas_Textblock_Rectangle *r;
1246              const Eina_List *l;
1247              Evas_Coord px, py, x, y;
1248
1249              evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1250              evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1251              EINA_LIST_FOREACH(geoms, l, r)
1252                {
1253                   if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1254                       ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1255                     {
1256                        ei.x = r->x + x;
1257                        ei.y = r->y + y;
1258                        ei.w = r->w;
1259                        ei.h = r->h;
1260                        break;
1261                     }
1262                }
1263           }
1264         if (!wd->disabled)
1265           evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1266      }
1267 }
1268
1269 static void
1270 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1271 {
1272    Widget_Data *wd = elm_widget_data_get(data);
1273    if (!wd) return;
1274 }
1275
1276 static void
1277 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1278 {
1279    Widget_Data *wd = elm_widget_data_get(data);
1280    if (!wd) return;
1281 }
1282
1283 static void
1284 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1285 {
1286    Widget_Data *wd = elm_widget_data_get(data);
1287    if (!wd) return;
1288 }
1289
1290 static void
1291 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1292 {
1293    Widget_Data *wd = elm_widget_data_get(data);
1294    if (!wd) return;
1295    evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1296 }
1297
1298 static void
1299 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1300 {
1301    Widget_Data *wd = elm_widget_data_get(data);
1302    if (!wd) return;
1303    evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1304 }
1305
1306 static void
1307 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1308 {
1309    Widget_Data *wd = elm_widget_data_get(data);
1310    if (!wd) return;
1311    evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1312 }
1313
1314 static void
1315 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1316 {
1317    Widget_Data *wd = elm_widget_data_get(data);
1318    if (!wd) return;
1319    evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1320 }
1321
1322 #ifdef HAVE_ELEMENTARY_X
1323 static Eina_Bool
1324 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1325 {
1326    Widget_Data *wd = elm_widget_data_get(data);
1327    Ecore_X_Event_Selection_Notify *ev = event;
1328    if (!wd) return ECORE_CALLBACK_PASS_ON;
1329    if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1330      return ECORE_CALLBACK_PASS_ON;
1331
1332    if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1333        (ev->selection == ECORE_X_SELECTION_PRIMARY))
1334      {
1335         Ecore_X_Selection_Data_Text *text_data;
1336
1337         text_data = ev->data;
1338         if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1339           {
1340              if (text_data->text)
1341                {
1342                   char *txt = _elm_util_text_to_mkup(text_data->text);
1343
1344                   if (txt)
1345                     {
1346                        elm_entry_entry_insert(data, txt);
1347                        free(txt);
1348                     }
1349                }
1350           }
1351         wd->selection_asked = EINA_FALSE;
1352      }
1353    else if (ev->selection == ECORE_X_SELECTION_XDND)
1354      {
1355         Ecore_X_Selection_Data_Text *text_data;
1356
1357         text_data = ev->data;
1358         if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1359           {
1360              if (text_data->text)
1361                {
1362                   char *txt = _elm_util_text_to_mkup(text_data->text);
1363
1364                   if (txt)
1365                     {
1366                        /* Massive FIXME: this should be at the drag point */
1367                        elm_entry_entry_insert(data, txt);
1368                        free(txt);
1369                     }
1370                }
1371           }
1372         wd->drag_selection_asked = EINA_FALSE;
1373
1374         ecore_x_dnd_send_finished();
1375
1376      }
1377    return ECORE_CALLBACK_PASS_ON;
1378 }
1379
1380 static Eina_Bool
1381 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1382 {
1383    /*
1384       Widget_Data *wd = elm_widget_data_get(data);
1385       Ecore_X_Event_Selection_Clear *ev = event;
1386       if (!wd) return ECORE_CALLBACK_PASS_ON;
1387       if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1388       if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1389       (ev->selection == ECORE_X_SELECTION_PRIMARY))
1390       {
1391       elm_entry_select_none(data);
1392       }
1393       return 1;*/
1394    return ECORE_CALLBACK_PASS_ON;
1395 }
1396
1397
1398 static Eina_Bool
1399 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1400 {
1401    Widget_Data *wd;
1402    Eina_Bool rv;
1403
1404    wd = elm_widget_data_get(obj);
1405
1406    if (!wd) return EINA_FALSE;
1407    printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1408
1409    edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1410                                      EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1411    rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1412                                                EDJE_CURSOR_MAIN,drop->x,drop->y);
1413    if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1414    elm_entry_entry_insert(obj, drop->data);
1415    edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1416                                      EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1417
1418    return EINA_TRUE;
1419 }
1420 #endif
1421
1422 static Evas_Object *
1423 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1424 {
1425    Widget_Data *wd = elm_widget_data_get(data);
1426    Evas_Object *o;
1427    Eina_List *l;
1428    Elm_Entry_Item_Provider *ip;
1429
1430    EINA_LIST_FOREACH(wd->item_providers, l, ip)
1431      {
1432         o = ip->func(ip->data, data, item);
1433         if (o) return o;
1434      }
1435    if (!strncmp(item, "file://", 7))
1436      {
1437         const char *fname = item + 7;
1438
1439         o = evas_object_image_filled_add(evas_object_evas_get(data));
1440         evas_object_image_file_set(o, fname, NULL);
1441         if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1442           {
1443              evas_object_show(o);
1444           }
1445         else
1446           {
1447              evas_object_del(o);
1448              o = edje_object_add(evas_object_evas_get(data));
1449              _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1450           }
1451         return o;
1452      }
1453    o = edje_object_add(evas_object_evas_get(data));
1454    if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1455      _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1456    return o;
1457 }
1458
1459 static void
1460 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
1461 {
1462    Widget_Data *wd = elm_widget_data_get(data);
1463    Eina_List *l;
1464    Elm_Entry_Text_Filter *tf;
1465
1466    if (type == EDJE_TEXT_FILTER_FORMAT)
1467      return;
1468
1469    EINA_LIST_FOREACH(wd->text_filters, l, tf)
1470      {
1471         tf->func(tf->data, data, text);
1472         if (!*text)
1473           break;
1474      }
1475 }
1476
1477 /**
1478  * This adds an entry to @p parent object.
1479  *
1480  * @param parent The parent object
1481  * @return The new object or NULL if it cannot be created
1482  *
1483  * @ingroup Entry
1484  */
1485 EAPI Evas_Object *
1486 elm_entry_add(Evas_Object *parent)
1487 {
1488    Evas_Object *obj, *top;
1489    Evas *e;
1490    Widget_Data *wd;
1491
1492    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1493
1494    ELM_SET_WIDTYPE(widtype, "entry");
1495    elm_widget_type_set(obj, "entry");
1496    elm_widget_sub_object_add(parent, obj);
1497    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1498    elm_widget_data_set(obj, wd);
1499    elm_widget_del_hook_set(obj, _del_hook);
1500    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1501    elm_widget_theme_hook_set(obj, _theme_hook);
1502    elm_widget_disable_hook_set(obj, _disable_hook);
1503    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1504    elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
1505    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1506    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1507    elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
1508    elm_widget_can_focus_set(obj, EINA_TRUE);
1509    elm_widget_highlight_ignore_set(obj, EINA_TRUE);
1510
1511    wd->linewrap     = EINA_TRUE;
1512    wd->char_linewrap= EINA_FALSE;
1513    wd->editable     = EINA_TRUE;
1514    wd->disabled     = EINA_FALSE;
1515    wd->context_menu = EINA_TRUE;
1516    wd->autosave     = EINA_TRUE;
1517    wd->textonly     = EINA_FALSE;
1518
1519    wd->ent = edje_object_add(e);
1520    edje_object_item_provider_set(wd->ent, _get_item, obj);
1521    edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
1522    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1523    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1524    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1525                                   _mouse_down, obj);
1526    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1527                                   _mouse_up, obj);
1528    evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1529                                   _mouse_move, obj);
1530
1531    _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1532    edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1533                                    _signal_entry_changed, obj);
1534    edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1535                                    _signal_selection_start, obj);
1536    edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1537                                    _signal_selection_changed, obj);
1538    edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1539                                    _signal_selection_cleared, obj);
1540    edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1541                                    _signal_entry_paste_request, obj);
1542    edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1543                                    _signal_entry_copy_notify, obj);
1544    edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1545                                    _signal_entry_cut_notify, obj);
1546    edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1547                                    _signal_cursor_changed, obj);
1548    edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1549                                    _signal_anchor_down, obj);
1550    edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1551                                    _signal_anchor_up, obj);
1552    edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
1553                                    _signal_anchor_clicked, obj);
1554    edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1555                                    _signal_anchor_move, obj);
1556    edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1557                                    _signal_anchor_in, obj);
1558    edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1559                                    _signal_anchor_out, obj);
1560    edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
1561                                    _signal_key_enter, obj);
1562    edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
1563                                    _signal_mouse_down, obj);
1564    edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
1565                                    _signal_mouse_clicked, obj);
1566    edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
1567                                    _signal_mouse_double, obj);
1568    edje_object_part_text_set(wd->ent, "elm.text", "");
1569    elm_widget_resize_object_set(obj, wd->ent);
1570    _sizing_eval(obj);
1571
1572 #ifdef HAVE_ELEMENTARY_X
1573    top = elm_widget_top_get(obj);
1574    if ((top) && (elm_win_xwindow_get(top)))
1575      {
1576         wd->sel_notify_handler =
1577            ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
1578                                    _event_selection_notify, obj);
1579         wd->sel_clear_handler =
1580            ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
1581                                    _event_selection_clear, obj);
1582      }
1583
1584    elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
1585                        _drag_drop_cb, NULL);
1586 #endif
1587
1588    entries = eina_list_prepend(entries, obj);
1589
1590    // module - find module for entry
1591    wd->api = _module(obj);
1592    // if found - hook in
1593    if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
1594
1595    _mirrored_set(obj, elm_widget_mirrored_get(obj));
1596    // TODO: convert Elementary to subclassing of Evas_Smart_Class
1597    // TODO: and save some bytes, making descriptions per-class and not instance!
1598    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1599    return obj;
1600 }
1601
1602
1603 /**
1604  * This sets the entry object not to line wrap.  All input will
1605  * be on a single line, and the entry box will extend with user input.
1606  *
1607  * @param obj The entry object
1608  * @param single_line If true, the text in the entry
1609  * will be on a single line.
1610  *
1611  * @ingroup Entry
1612  */
1613 EAPI void
1614 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
1615 {
1616    ELM_CHECK_WIDTYPE(obj, widtype);
1617    Widget_Data *wd = elm_widget_data_get(obj);
1618    if (!wd) return;
1619    if (wd->single_line == single_line) return;
1620    wd->single_line = single_line;
1621    wd->linewrap = EINA_FALSE;
1622    wd->char_linewrap = EINA_FALSE;
1623    elm_entry_cnp_textonly_set(obj, EINA_TRUE);
1624    _theme_hook(obj);
1625 }
1626
1627 /**
1628  * This returns true if the entry has been set to single line mode.
1629  * See also elm_entry_single_line_set().
1630  *
1631  * @param obj The entry object
1632  * @return single_line If true, the text in the entry is set to display
1633  * on a single line.
1634  *
1635  * @ingroup Entry
1636  */
1637 EAPI Eina_Bool
1638 elm_entry_single_line_get(const Evas_Object *obj)
1639 {
1640    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1641    Widget_Data *wd = elm_widget_data_get(obj);
1642    if (!wd) return EINA_FALSE;
1643    return wd->single_line;
1644 }
1645
1646 /**
1647  * This sets the entry object to password mode.  All text entered
1648  * and/or displayed within the widget will be replaced with asterisks (*).
1649  *
1650  * @param obj The entry object
1651  * @param password If true, password mode is enabled.
1652  *
1653  * @ingroup Entry
1654  */
1655 EAPI void
1656 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
1657 {
1658    ELM_CHECK_WIDTYPE(obj, widtype);
1659    Widget_Data *wd = elm_widget_data_get(obj);
1660    if (!wd) return;
1661    if (wd->password == password) return;
1662    wd->password = password;
1663    wd->single_line = EINA_TRUE;
1664    wd->linewrap = EINA_FALSE;
1665    wd->char_linewrap = EINA_FALSE;
1666    _theme_hook(obj);
1667 }
1668
1669
1670 /**
1671  * This returns whether password mode is enabled.
1672  * See also elm_entry_password_set().
1673  *
1674  * @param obj The entry object
1675  * @return If true, the entry is set to display all characters
1676  * as asterisks (*).
1677  *
1678  * @ingroup Entry
1679  */
1680 EAPI Eina_Bool
1681 elm_entry_password_get(const Evas_Object *obj)
1682 {
1683    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1684    Widget_Data *wd = elm_widget_data_get(obj);
1685    if (!wd) return EINA_FALSE;
1686    return wd->password;
1687 }
1688
1689 /**
1690  * This sets the text displayed within the entry to @p entry.
1691  *
1692  * @param obj The entry object
1693  * @param entry The text to be displayed
1694  *
1695  * @ingroup Entry
1696  */
1697 EAPI void
1698 elm_entry_entry_set(Evas_Object *obj, const char *entry)
1699 {
1700    ELM_CHECK_WIDTYPE(obj, widtype);
1701    Widget_Data *wd = elm_widget_data_get(obj);
1702    if (!wd) return;
1703    if (!entry) entry = "";
1704    edje_object_part_text_set(wd->ent, "elm.text", entry);
1705    if (wd->text) eina_stringshare_del(wd->text);
1706    wd->text = NULL;
1707    wd->changed = EINA_TRUE;
1708    _sizing_eval(obj);
1709 }
1710
1711 /**
1712  * This returns the text currently shown in object @p entry.
1713  * See also elm_entry_entry_set().
1714  *
1715  * @param obj The entry object
1716  * @return The currently displayed text or NULL on failure
1717  *
1718  * @ingroup Entry
1719  */
1720 EAPI const char *
1721 elm_entry_entry_get(const Evas_Object *obj)
1722 {
1723    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1724    Widget_Data *wd = elm_widget_data_get(obj);
1725    const char *text;
1726    if (!wd) return NULL;
1727    if (wd->text) return wd->text;
1728    text = edje_object_part_text_get(wd->ent, "elm.text");
1729    if (!text)
1730      {
1731         ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
1732         return NULL;
1733      }
1734    eina_stringshare_replace(&wd->text, text);
1735    return wd->text;
1736 }
1737
1738
1739 /**
1740  * This returns EINA_TRUE if the entry is empty/there was an error
1741  * and EINA_FALSE if it is not empty.
1742  *
1743  * @param obj The entry object
1744  * @return If the entry is empty or not.
1745  *
1746  * @ingroup Entry
1747  */
1748 EAPI Eina_Bool
1749 elm_entry_is_empty(const Evas_Object *obj)
1750 {
1751    /* FIXME: until there's support for that in textblock, we just check
1752     * to see if the there is text or not. */
1753    ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
1754    Widget_Data *wd = elm_widget_data_get(obj);
1755    const Evas_Object *tb;
1756    Evas_Textblock_Cursor *cur;
1757    Eina_Bool ret;
1758    if (!wd) return EINA_TRUE;
1759    /* It's a hack until we get the support suggested above.
1760     * We just create a cursor, point it to the begining, and then
1761     * try to advance it, if it can advance, the tb is not empty,
1762     * otherwise it is. */
1763    tb = edje_object_part_object_get(wd->ent, "elm.text");
1764    cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
1765                                                                   actually, ok for the time being, thsese hackish stuff will be removed
1766                                                                   once evas 1.0 is out*/
1767    evas_textblock_cursor_pos_set(cur, 0);
1768    ret = evas_textblock_cursor_char_next(cur);
1769    evas_textblock_cursor_free(cur);
1770
1771    return !ret;
1772 }
1773
1774 /**
1775  * This returns all selected text within the entry.
1776  *
1777  * @param obj The entry object
1778  * @return The selected text within the entry or NULL on failure
1779  *
1780  * @ingroup Entry
1781  */
1782 EAPI const char *
1783 elm_entry_selection_get(const Evas_Object *obj)
1784 {
1785    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1786    Widget_Data *wd = elm_widget_data_get(obj);
1787    if (!wd) return NULL;
1788    return edje_object_part_text_selection_get(wd->ent, "elm.text");
1789 }
1790
1791 /**
1792  * This inserts text in @p entry where the current cursor position.
1793  *
1794  * This inserts text at the cursor position is as if it was typed
1795  * by the user (note this also allows markup which a user
1796  * can't just "type" as it would be converted to escaped text, so this
1797  * call can be used to insert things like emoticon items or bold push/pop
1798  * tags, other font and color change tags etc.)
1799  *
1800  * @param obj The entry object
1801  * @param entry The text to insert
1802  *
1803  * @ingroup Entry
1804  */
1805 EAPI void
1806 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
1807 {
1808    ELM_CHECK_WIDTYPE(obj, widtype);
1809    Widget_Data *wd = elm_widget_data_get(obj);
1810    if (!wd) return;
1811    edje_object_part_text_insert(wd->ent, "elm.text", entry);
1812    wd->changed = EINA_TRUE;
1813    _sizing_eval(obj);
1814 }
1815
1816 /**
1817  * This enables word line wrapping in the entry object.  It is the opposite
1818  * of elm_entry_single_line_set().  Additionally, setting this disables
1819  * character line wrapping.
1820  * See also elm_entry_line_char_wrap_set().
1821  *
1822  * @param obj The entry object
1823  * @param wrap If true, the entry will be wrapped once it reaches the end
1824  * of the object. Wrapping will occur at the end of the word before the end of the
1825  * object.
1826  *
1827  * @ingroup Entry
1828  */
1829 EAPI void
1830 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
1831 {
1832    ELM_CHECK_WIDTYPE(obj, widtype);
1833    Widget_Data *wd = elm_widget_data_get(obj);
1834    if (!wd) return;
1835    if (wd->linewrap == wrap) return;
1836    wd->linewrap = wrap;
1837    if(wd->linewrap)
1838      wd->char_linewrap = EINA_FALSE;
1839    _theme_hook(obj);
1840 }
1841
1842 /**
1843  * This enables character line wrapping in the entry object.  It is the opposite
1844  * of elm_entry_single_line_set().  Additionally, setting this disables
1845  * word line wrapping.
1846  * See also elm_entry_line_wrap_set().
1847  *
1848  * @param obj The entry object
1849  * @param wrap If true, the entry will be wrapped once it reaches the end
1850  * of the object. Wrapping will occur immediately upon reaching the end of the object.
1851  *
1852  * @ingroup Entry
1853  */
1854 EAPI void
1855 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
1856 {
1857    ELM_CHECK_WIDTYPE(obj, widtype);
1858    Widget_Data *wd = elm_widget_data_get(obj);
1859    if (!wd) return;
1860    if (wd->char_linewrap == wrap) return;
1861    wd->char_linewrap = wrap;
1862    if(wd->char_linewrap)
1863      wd->linewrap = EINA_FALSE;
1864    _theme_hook(obj);
1865 }
1866
1867 /**
1868  * This sets the editable attribute of the entry.
1869  *
1870  * @param obj The entry object
1871  * @param editable If true, the entry will be editable by the user.
1872  * If false, it will be set to the disabled state.
1873  *
1874  * @ingroup Entry
1875  */
1876 EAPI void
1877 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
1878 {
1879    ELM_CHECK_WIDTYPE(obj, widtype);
1880    Widget_Data *wd = elm_widget_data_get(obj);
1881    if (!wd) return;
1882    if (wd->editable == editable) return;
1883    wd->editable = editable;
1884    _theme_hook(obj);
1885
1886 #ifdef HAVE_ELEMENTARY_X
1887    if (editable)
1888      elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
1889    else
1890      elm_drop_target_del(obj);
1891 #endif
1892 }
1893
1894 /**
1895  * This gets the editable attribute of the entry.
1896  * See also elm_entry_editable_set().
1897  *
1898  * @param obj The entry object
1899  * @return If true, the entry is editable by the user.
1900  * If false, it is not editable by the user
1901  *
1902  * @ingroup Entry
1903  */
1904 EAPI Eina_Bool
1905 elm_entry_editable_get(const Evas_Object *obj)
1906 {
1907    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1908    Widget_Data *wd = elm_widget_data_get(obj);
1909    if (!wd) return EINA_FALSE;
1910    return wd->editable;
1911 }
1912
1913 /**
1914  * This drops any existing text selection within the entry.
1915  *
1916  * @param obj The entry object
1917  *
1918  * @ingroup Entry
1919  */
1920 EAPI void
1921 elm_entry_select_none(Evas_Object *obj)
1922 {
1923    ELM_CHECK_WIDTYPE(obj, widtype);
1924    Widget_Data *wd = elm_widget_data_get(obj);
1925    if (!wd) return;
1926    if (wd->selmode)
1927      {
1928         wd->selmode = EINA_FALSE;
1929         edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1930         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1931      }
1932    wd->have_selection = EINA_FALSE;
1933    edje_object_part_text_select_none(wd->ent, "elm.text");
1934 }
1935
1936 /**
1937  * This selects all text within the entry.
1938  *
1939  * @param obj The entry object
1940  *
1941  * @ingroup Entry
1942  */
1943 EAPI void
1944 elm_entry_select_all(Evas_Object *obj)
1945 {
1946    ELM_CHECK_WIDTYPE(obj, widtype);
1947    Widget_Data *wd = elm_widget_data_get(obj);
1948    if (!wd) return;
1949    if (wd->selmode)
1950      {
1951         wd->selmode = EINA_FALSE;
1952         edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1953         edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1954      }
1955    wd->have_selection = EINA_TRUE;
1956    edje_object_part_text_select_all(wd->ent, "elm.text");
1957 }
1958
1959 /**
1960  * This function returns the geometry of the cursor.
1961  *
1962  * It's useful if you want to draw something on the cursor (or where it is),
1963  * or for example in the case of scrolled entry where you want to show the
1964  * cursor.
1965  *
1966  * @param obj The entry object
1967  * @param x returned geometry
1968  * @param y returned geometry
1969  * @param w returned geometry
1970  * @param h returned geometry
1971  * @return EINA_TRUE upon success, EINA_FALSE upon failure
1972  *
1973  * @ingroup Entry
1974  */
1975 EAPI Eina_Bool
1976 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1977 {
1978    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1979    Widget_Data *wd = elm_widget_data_get(obj);
1980    if (!wd) return EINA_FALSE;
1981    edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
1982    return EINA_TRUE;
1983 }
1984
1985 /**
1986  * This moves the cursor one place to the right within the entry.
1987  *
1988  * @param obj The entry object
1989  * @return EINA_TRUE upon success, EINA_FALSE upon failure
1990  *
1991  * @ingroup Entry
1992  */
1993 EAPI Eina_Bool
1994 elm_entry_cursor_next(Evas_Object *obj)
1995 {
1996    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1997    Widget_Data *wd = elm_widget_data_get(obj);
1998    if (!wd) return EINA_FALSE;
1999    return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2000 }
2001
2002 /**
2003  * This moves the cursor one place to the left within the entry.
2004  *
2005  * @param obj The entry object
2006  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2007  *
2008  * @ingroup Entry
2009  */
2010 EAPI Eina_Bool
2011 elm_entry_cursor_prev(Evas_Object *obj)
2012 {
2013    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2014    Widget_Data *wd = elm_widget_data_get(obj);
2015    if (!wd) return EINA_FALSE;
2016    return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2017 }
2018
2019 /**
2020  * This moves the cursor one line up within the entry.
2021  *
2022  * @param obj The entry object
2023  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2024  *
2025  * @ingroup Entry
2026  */
2027 EAPI Eina_Bool
2028 elm_entry_cursor_up(Evas_Object *obj)
2029 {
2030    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2031    Widget_Data *wd = elm_widget_data_get(obj);
2032    if (!wd) return EINA_FALSE;
2033    return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2034 }
2035
2036 /**
2037  * This moves the cursor one line down within the entry.
2038  *
2039  * @param obj The entry object
2040  * @return EINA_TRUE upon success, EINA_FALSE upon failure
2041  *
2042  * @ingroup Entry
2043  */
2044 EAPI Eina_Bool
2045 elm_entry_cursor_down(Evas_Object *obj)
2046 {
2047    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2048    Widget_Data *wd = elm_widget_data_get(obj);
2049    if (!wd) return EINA_FALSE;
2050    return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2051 }
2052
2053 /**
2054  * This moves the cursor to the beginning of the entry.
2055  *
2056  * @param obj The entry object
2057  *
2058  * @ingroup Entry
2059  */
2060 EAPI void
2061 elm_entry_cursor_begin_set(Evas_Object *obj)
2062 {
2063    ELM_CHECK_WIDTYPE(obj, widtype);
2064    Widget_Data *wd = elm_widget_data_get(obj);
2065    if (!wd) return;
2066    edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2067 }
2068
2069 /**
2070  * This moves the cursor to the end of the entry.
2071  *
2072  * @param obj The entry object
2073  *
2074  * @ingroup Entry
2075  */
2076 EAPI void
2077 elm_entry_cursor_end_set(Evas_Object *obj)
2078 {
2079    ELM_CHECK_WIDTYPE(obj, widtype);
2080    Widget_Data *wd = elm_widget_data_get(obj);
2081    if (!wd) return;
2082    edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2083 }
2084
2085 /**
2086  * This moves the cursor to the beginning of the current line.
2087  *
2088  * @param obj The entry object
2089  *
2090  * @ingroup Entry
2091  */
2092 EAPI void
2093 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2094 {
2095    ELM_CHECK_WIDTYPE(obj, widtype);
2096    Widget_Data *wd = elm_widget_data_get(obj);
2097    if (!wd) return;
2098    edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2099 }
2100
2101 /**
2102  * This moves the cursor to the end of the current line.
2103  *
2104  * @param obj The entry object
2105  *
2106  * @ingroup Entry
2107  */
2108 EAPI void
2109 elm_entry_cursor_line_end_set(Evas_Object *obj)
2110 {
2111    ELM_CHECK_WIDTYPE(obj, widtype);
2112    Widget_Data *wd = elm_widget_data_get(obj);
2113    if (!wd) return;
2114    edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2115 }
2116
2117 /**
2118  * This begins a selection within the entry as though
2119  * the user were holding down the mouse button to make a selection.
2120  *
2121  * @param obj The entry object
2122  *
2123  * @ingroup Entry
2124  */
2125 EAPI void
2126 elm_entry_cursor_selection_begin(Evas_Object *obj)
2127 {
2128    ELM_CHECK_WIDTYPE(obj, widtype);
2129    Widget_Data *wd = elm_widget_data_get(obj);
2130    if (!wd) return;
2131    edje_object_part_text_select_begin(wd->ent, "elm.text");
2132 }
2133
2134 /**
2135  * This ends a selection within the entry as though
2136  * the user had just released the mouse button while making a selection.
2137  *
2138  * @param obj The entry object
2139  *
2140  * @ingroup Entry
2141  */
2142 EAPI void
2143 elm_entry_cursor_selection_end(Evas_Object *obj)
2144 {
2145    ELM_CHECK_WIDTYPE(obj, widtype);
2146    Widget_Data *wd = elm_widget_data_get(obj);
2147    if (!wd) return;
2148    edje_object_part_text_select_extend(wd->ent, "elm.text");
2149 }
2150
2151 /**
2152  * TODO: fill this in
2153  *
2154  * @param obj The entry object
2155  * @return TODO: fill this in
2156  *
2157  * @ingroup Entry
2158  */
2159 EAPI Eina_Bool
2160 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2161 {
2162    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2163    Widget_Data *wd = elm_widget_data_get(obj);
2164    if (!wd) return EINA_FALSE;
2165    return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2166 }
2167
2168 /**
2169  * This returns whether the cursor is visible.
2170  *
2171  * @param obj The entry object
2172  * @return If true, the cursor is visible.
2173  *
2174  * @ingroup Entry
2175  */
2176 EAPI Eina_Bool
2177 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2178 {
2179    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2180    Widget_Data *wd = elm_widget_data_get(obj);
2181    if (!wd) return EINA_FALSE;
2182    return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2183 }
2184
2185 /**
2186  * TODO: fill this in
2187  *
2188  * @param obj The entry object
2189  * @return TODO: fill this in
2190  *
2191  * @ingroup Entry
2192  */
2193 EAPI const char *
2194 elm_entry_cursor_content_get(const Evas_Object *obj)
2195 {
2196    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2197    Widget_Data *wd = elm_widget_data_get(obj);
2198    if (!wd) return NULL;
2199    return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2200 }
2201
2202 /**
2203  * Sets the cursor position in the entry to the given value
2204  *
2205  * @param obj The entry object
2206  * @param pos The position of the cursor
2207  *
2208  * @ingroup Entry
2209  */
2210 EAPI void
2211 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
2212 {
2213    ELM_CHECK_WIDTYPE(obj, widtype);
2214    Widget_Data *wd = elm_widget_data_get(obj);
2215    if (!wd) return;
2216    edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
2217    edje_object_message_signal_process(wd->ent);
2218 }
2219
2220 /**
2221  * Retrieves the current position of the cursor in the entry
2222  *
2223  * @param obj The entry object
2224  * @return The cursor position
2225  *
2226  * @ingroup Entry
2227  */
2228 EAPI int
2229 elm_entry_cursor_pos_get(const Evas_Object *obj)
2230 {
2231    ELM_CHECK_WIDTYPE(obj, widtype) 0;
2232    Widget_Data *wd = elm_widget_data_get(obj);
2233    if (!wd) return 0;
2234    return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2235 }
2236
2237 /**
2238  * This executes a "cut" action on the selected text in the entry.
2239  *
2240  * @param obj The entry object
2241  *
2242  * @ingroup Entry
2243  */
2244 EAPI void
2245 elm_entry_selection_cut(Evas_Object *obj)
2246 {
2247    ELM_CHECK_WIDTYPE(obj, widtype);
2248    Widget_Data *wd = elm_widget_data_get(obj);
2249    if (!wd) return;
2250    _cut(obj, NULL, NULL);
2251 }
2252
2253 /**
2254  * This executes a "copy" action on the selected text in the entry.
2255  *
2256  * @param obj The entry object
2257  *
2258  * @ingroup Entry
2259  */
2260 EAPI void
2261 elm_entry_selection_copy(Evas_Object *obj)
2262 {
2263    ELM_CHECK_WIDTYPE(obj, widtype);
2264    Widget_Data *wd = elm_widget_data_get(obj);
2265    if (!wd) return;
2266    _copy(obj, NULL, NULL);
2267 }
2268
2269 /**
2270  * This executes a "paste" action in the entry.
2271  *
2272  * @param obj The entry object
2273  *
2274  * @ingroup Entry
2275  */
2276 EAPI void
2277 elm_entry_selection_paste(Evas_Object *obj)
2278 {
2279    ELM_CHECK_WIDTYPE(obj, widtype);
2280    Widget_Data *wd = elm_widget_data_get(obj);
2281    if (!wd) return;
2282    _paste(obj, NULL, NULL);
2283 }
2284
2285 /**
2286  * This clears and frees the items in a entry's contextual (right click) menu.
2287  *
2288  * @param obj The entry object
2289  *
2290  * @ingroup Entry
2291  */
2292 EAPI void
2293 elm_entry_context_menu_clear(Evas_Object *obj)
2294 {
2295    ELM_CHECK_WIDTYPE(obj, widtype);
2296    Widget_Data *wd = elm_widget_data_get(obj);
2297    Elm_Entry_Context_Menu_Item *it;
2298    if (!wd) return;
2299    EINA_LIST_FREE(wd->items, it)
2300      {
2301         eina_stringshare_del(it->label);
2302         eina_stringshare_del(it->icon_file);
2303         eina_stringshare_del(it->icon_group);
2304         free(it);
2305      }
2306 }
2307
2308 /**
2309  * This adds an item to the entry's contextual menu.
2310  *
2311  * @param obj The entry object
2312  * @param label The item's text label
2313  * @param icon_file The item's icon file
2314  * @param icon_type The item's icon type
2315  * @param func The callback to execute when the item is clicked
2316  * @param data The data to associate with the item for related functions
2317  *
2318  * @ingroup Entry
2319  */
2320 EAPI void
2321 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)
2322 {
2323    ELM_CHECK_WIDTYPE(obj, widtype);
2324    Widget_Data *wd = elm_widget_data_get(obj);
2325    Elm_Entry_Context_Menu_Item *it;
2326    if (!wd) return;
2327    it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2328    if (!it) return;
2329    wd->items = eina_list_append(wd->items, it);
2330    it->obj = obj;
2331    it->label = eina_stringshare_add(label);
2332    it->icon_file = eina_stringshare_add(icon_file);
2333    it->icon_type = icon_type;
2334    it->func = func;
2335    it->data = (void *)data;
2336 }
2337
2338 /**
2339  * This disables the entry's contextual (right click) menu.
2340  *
2341  * @param obj The entry object
2342  * @param disabled If true, the menu is disabled
2343  *
2344  * @ingroup Entry
2345  */
2346 EAPI void
2347 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2348 {
2349    ELM_CHECK_WIDTYPE(obj, widtype);
2350    Widget_Data *wd = elm_widget_data_get(obj);
2351    if (!wd) return;
2352    if (wd->context_menu == !disabled) return;
2353    wd->context_menu = !disabled;
2354 }
2355
2356 /**
2357  * This returns whether the entry's contextual (right click) menu is disabled.
2358  *
2359  * @param obj The entry object
2360  * @return If true, the menu is disabled
2361  *
2362  * @ingroup Entry
2363  */
2364 EAPI Eina_Bool
2365 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2366 {
2367    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2368    Widget_Data *wd = elm_widget_data_get(obj);
2369    if (!wd) return EINA_FALSE;
2370    return !wd->context_menu;
2371 }
2372
2373 /**
2374  * This appends a custom item provider to the list for that entry
2375  *
2376  * This appends the given callback. The list is walked from beginning to end
2377  * with each function called given the item href string in the text. If the
2378  * function returns an object handle other than NULL (it should create an
2379  * and object to do this), then this object is used to replace that item. If
2380  * not the next provider is called until one provides an item object, or the
2381  * default provider in entry does.
2382  *
2383  * @param obj The entry object
2384  * @param func The function called to provide the item object
2385  * @param data The data passed to @p func
2386  *
2387  * @ingroup Entry
2388  */
2389 EAPI void
2390 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2391 {
2392    ELM_CHECK_WIDTYPE(obj, widtype);
2393    Widget_Data *wd = elm_widget_data_get(obj);
2394    if (!wd) return;
2395    EINA_SAFETY_ON_NULL_RETURN(func);
2396    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2397    if (!ip) return;
2398    ip->func = func;
2399    ip->data = data;
2400    wd->item_providers = eina_list_append(wd->item_providers, ip);
2401 }
2402
2403 /**
2404  * This prepends a custom item provider to the list for that entry
2405  *
2406  * This prepends the given callback. See elm_entry_item_provider_append() for
2407  * more information
2408  *
2409  * @param obj The entry object
2410  * @param func The function called to provide the item object
2411  * @param data The data passed to @p func
2412  *
2413  * @ingroup Entry
2414  */
2415 EAPI void
2416 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2417 {
2418    ELM_CHECK_WIDTYPE(obj, widtype);
2419    Widget_Data *wd = elm_widget_data_get(obj);
2420    if (!wd) return;
2421    EINA_SAFETY_ON_NULL_RETURN(func);
2422    Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2423    if (!ip) return;
2424    ip->func = func;
2425    ip->data = data;
2426    wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2427 }
2428
2429 /**
2430  * This removes a custom item provider to the list for that entry
2431  *
2432  * This removes the given callback. See elm_entry_item_provider_append() for
2433  * more information
2434  *
2435  * @param obj The entry object
2436  * @param func The function called to provide the item object
2437  * @param data The data passed to @p func
2438  *
2439  * @ingroup Entry
2440  */
2441 EAPI void
2442 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2443 {
2444    ELM_CHECK_WIDTYPE(obj, widtype);
2445    Widget_Data *wd = elm_widget_data_get(obj);
2446    Eina_List *l;
2447    Elm_Entry_Item_Provider *ip;
2448    if (!wd) return;
2449    EINA_SAFETY_ON_NULL_RETURN(func);
2450    EINA_LIST_FOREACH(wd->item_providers, l, ip)
2451      {
2452         if ((ip->func == func) && ((!data) || (ip->data == data)))
2453           {
2454              wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2455              free(ip);
2456              return;
2457           }
2458      }
2459 }
2460
2461 /**
2462  * Append a filter function for text inserted in the entry
2463  *
2464  * Append the given callback to the list. This functions will be called
2465  * whenever any text is inserted into the entry, with the text to be inserted
2466  * as a parameter. The callback function is free to alter the text in any way
2467  * it wants, but it must remember to free the given pointer and update it.
2468  * If the new text is to be discarded, the function can free it and set it text
2469  * parameter to NULL. This will also prevent any following filters from being
2470  * called.
2471  *
2472  * @param obj The entry object
2473  * @param func The function to use as text filter
2474  * @param data User data to pass to @p func
2475  *
2476  * @ingroup Entry
2477  */
2478 EAPI void
2479 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2480 {
2481    Widget_Data *wd;
2482    Elm_Entry_Text_Filter *tf;
2483    ELM_CHECK_WIDTYPE(obj, widtype);
2484
2485    wd = elm_widget_data_get(obj);
2486
2487    EINA_SAFETY_ON_NULL_RETURN(func);
2488
2489    tf = _filter_new(func, data);
2490    if (!tf) return;
2491
2492    wd->text_filters = eina_list_append(wd->text_filters, tf);
2493 }
2494
2495 /**
2496  * Prepend a filter function for text insdrted in the entry
2497  *
2498  * Prepend the given callback to the list. See elm_entry_text_filter_append()
2499  * for more information
2500  *
2501  * @param obj The entry object
2502  * @param func The function to use as text filter
2503  * @param data User data to pass to @p func
2504  *
2505  * @ingroup Entry
2506  */
2507 EAPI void
2508 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2509 {
2510    Widget_Data *wd;
2511    Elm_Entry_Text_Filter *tf;
2512    ELM_CHECK_WIDTYPE(obj, widtype);
2513
2514    wd = elm_widget_data_get(obj);
2515
2516    EINA_SAFETY_ON_NULL_RETURN(func);
2517
2518    tf = _filter_new(func, data);
2519    if (!tf) return;
2520
2521    wd->text_filters = eina_list_prepend(wd->text_filters, tf);
2522 }
2523
2524 /**
2525  * Remove a filter from the list
2526  *
2527  * Removes the given callback from the filter list. See elm_entry_text_filter_append()
2528  * for more information.
2529  *
2530  * @param obj The entry object
2531  * @param func The filter function to remove
2532  * @param data The user data passed when adding the function
2533  *
2534  * @ingroup Entry
2535  */
2536 EAPI void
2537 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2538 {
2539    Widget_Data *wd;
2540    Eina_List *l;
2541    Elm_Entry_Text_Filter *tf;
2542    ELM_CHECK_WIDTYPE(obj, widtype);
2543
2544    wd = elm_widget_data_get(obj);
2545
2546    EINA_SAFETY_ON_NULL_RETURN(func);
2547
2548    EINA_LIST_FOREACH(wd->text_filters, l, tf)
2549      {
2550         if ((tf->func == func) && ((!data) || (tf->data == data)))
2551           {
2552              wd->text_filters = eina_list_remove_list(wd->text_filters, l);
2553              _filter_free(tf);
2554              return;
2555           }
2556      }
2557 }
2558
2559 /**
2560  * This converts a markup (HTML-like) string into UTF-8.
2561  * Returning string is obtained with malloc.
2562  * After use the returned string, it should be freed.
2563  *
2564  * @param s The string (in markup) to be converted
2565  * @return The converted string (in UTF-8). It should be freed.
2566  *
2567  * @ingroup Entry
2568  */
2569 EAPI char *
2570 elm_entry_markup_to_utf8(const char *s)
2571 {
2572    char *ss = _elm_util_mkup_to_text(s);
2573    if (!ss) ss = strdup("");
2574    return ss;
2575 }
2576
2577 /**
2578  * This converts a UTF-8 string into markup (HTML-like).
2579  * Returning string is obtained with malloc.
2580  * After use the returned string, it should be freed.
2581  *
2582  * @param s The string (in UTF-8) to be converted
2583  * @return The converted string (in markup). It should be freed.
2584  *
2585  * @ingroup Entry
2586  */
2587 EAPI char *
2588 elm_entry_utf8_to_markup(const char *s)
2589 {
2590    char *ss = _elm_util_text_to_mkup(s);
2591    if (!ss) ss = strdup("");
2592    return ss;
2593 }
2594
2595 /**
2596  * Filter inserted text based on user defined character and byte limits
2597  *
2598  * Add this filter to an entry to limit the characters that it will accept
2599  * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
2600  * The funtion works on the UTF-8 representation of the string, converting
2601  * it from the set markup, thus not accounting for any format in it.
2602  *
2603  * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
2604  * it as data when setting the filter. In it it's possible to set limits
2605  * by character count or bytes (any of them is disabled if 0), and both can
2606  * be set at the same time. In that case, it first checks for characters,
2607  * then bytes.
2608  *
2609  * The function will cut the inserted text in order to allow only the first
2610  * number of characters that are still allowed. The cut is made in
2611  * characters, even when limiting by bytes, in order to always contain
2612  * valid ones and avoid half unicode characters making it in.
2613  *
2614  * @ingroup Entry
2615  */
2616 EAPI void
2617 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
2618 {
2619    Elm_Entry_Filter_Limit_Size *lim = data;
2620    char *current;
2621    int len, newlen;
2622    const char *(*text_get)(const Evas_Object *);
2623    const char *widget_type;
2624
2625    EINA_SAFETY_ON_NULL_RETURN(data);
2626    EINA_SAFETY_ON_NULL_RETURN(entry);
2627    EINA_SAFETY_ON_NULL_RETURN(text);
2628
2629    /* hack. I don't want to copy the entire function to work with
2630     * scrolled_entry */
2631    widget_type = elm_widget_type_get(entry);
2632    if (!strcmp(widget_type, "entry"))
2633      text_get = elm_entry_entry_get;
2634    else if (!strcmp(widget_type, "scrolled_entry"))
2635      text_get = elm_scrolled_entry_entry_get;
2636    else /* huh? */
2637      return;
2638
2639    current = elm_entry_markup_to_utf8(text_get(entry));
2640
2641    if (lim->max_char_count > 0)
2642      {
2643         int cut;
2644         len = evas_string_char_len_get(current);
2645         if (len >= lim->max_char_count)
2646           {
2647              free(*text);
2648              free(current);
2649              *text = NULL;
2650              return;
2651           }
2652         newlen = evas_string_char_len_get(*text);
2653         cut = strlen(*text);
2654         while ((len + newlen) > lim->max_char_count)
2655           {
2656              cut = evas_string_char_prev_get(*text, cut, NULL);
2657              newlen--;
2658           }
2659         (*text)[cut] = 0;
2660      }
2661
2662    if (lim->max_byte_count > 0)
2663      {
2664         len = strlen(current);
2665         if (len >= lim->max_byte_count)
2666           {
2667              free(*text);
2668              free(current);
2669              *text = NULL;
2670              return;
2671           }
2672         newlen = strlen(*text);
2673         while ((len + newlen) > lim->max_byte_count)
2674           {
2675              int p = evas_string_char_prev_get(*text, newlen, NULL);
2676              newlen -= (newlen - p);
2677           }
2678         if (newlen)
2679           (*text)[newlen] = 0;
2680         else
2681           {
2682              free(*text);
2683              *text = NULL;
2684           }
2685      }
2686    free(current);
2687 }
2688
2689 /**
2690  * Filter inserted text based on accepted or rejected sets of characters
2691  *
2692  * Add this filter to an entry to restrict the set of accepted characters
2693  * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
2694  * This structure contains both accepted and rejected sets, but they are
2695  * mutually exclusive. If accepted is set, it will be used, otherwise it
2696  * goes on to the rejected set.
2697  */
2698 EAPI void
2699 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
2700 {
2701    Elm_Entry_Filter_Accept_Set *as = data;
2702    const char *set;
2703    char *insert;
2704    Eina_Bool goes_in;
2705    int read_idx, last_read_idx = 0, read_char;
2706
2707    EINA_SAFETY_ON_NULL_RETURN(data);
2708    EINA_SAFETY_ON_NULL_RETURN(text);
2709
2710    if ((!as->accepted) && (!as->rejected))
2711      return;
2712
2713    if (as->accepted)
2714      {
2715         set = as->accepted;
2716         goes_in = EINA_TRUE;
2717      }
2718    else
2719      {
2720         set = as->rejected;
2721         goes_in = EINA_FALSE;
2722      }
2723
2724    insert = *text;
2725    read_idx = evas_string_char_next_get(*text, 0, &read_char);
2726    while (read_char)
2727      {
2728         int cmp_idx, cmp_char;
2729         Eina_Bool in_set = EINA_FALSE;
2730
2731         cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
2732         while (cmp_char)
2733           {
2734              if (read_char == cmp_char)
2735                {
2736                   in_set = EINA_TRUE;
2737                   break;
2738                }
2739              cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
2740           }
2741         if (in_set == goes_in)
2742           {
2743              int size = read_idx - last_read_idx;
2744              const char *src = (*text) + last_read_idx;
2745              if (src != insert)
2746                memcpy(insert, *text + last_read_idx, size);
2747              insert += size;
2748           }
2749         last_read_idx = read_idx;
2750         read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
2751      }
2752    *insert = 0;
2753 }
2754
2755 /**
2756  * This sets the file (and implicitly loads it) for the text to display and
2757  * then edit. All changes are written back to the file after a short delay if
2758  * the entry object is set to autosave.
2759  *
2760  * @param obj The entry object
2761  * @param file The path to the file to load and save
2762  * @param format The file format
2763  *
2764  * @ingroup Entry
2765  */
2766 EAPI void
2767 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
2768 {
2769    ELM_CHECK_WIDTYPE(obj, widtype);
2770    Widget_Data *wd = elm_widget_data_get(obj);
2771    if (!wd) return;
2772    if (wd->delay_write)
2773      {
2774         ecore_timer_del(wd->delay_write);
2775         wd->delay_write = NULL;
2776      }
2777    if (wd->autosave) _save(obj);
2778    eina_stringshare_replace(&wd->file, file);
2779    wd->format = format;
2780    _load(obj);
2781 }
2782
2783 /**
2784  * Gets the file to load and save and the file format
2785  *
2786  * @param obj The entry object
2787  * @param file The path to the file to load and save
2788  * @param format The file format
2789  *
2790  * @ingroup Entry
2791  */
2792 EAPI void
2793 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
2794 {
2795    ELM_CHECK_WIDTYPE(obj, widtype);
2796    Widget_Data *wd = elm_widget_data_get(obj);
2797    if (!wd) return;
2798    if (file) *file = wd->file;
2799    if (format) *format = wd->format;
2800 }
2801
2802 /**
2803  * This function writes any changes made to the file set with
2804  * elm_entry_file_set()
2805  *
2806  * @param obj The entry object
2807  *
2808  * @ingroup Entry
2809  */
2810 EAPI void
2811 elm_entry_file_save(Evas_Object *obj)
2812 {
2813    ELM_CHECK_WIDTYPE(obj, widtype);
2814    Widget_Data *wd = elm_widget_data_get(obj);
2815    if (!wd) return;
2816    if (wd->delay_write)
2817      {
2818         ecore_timer_del(wd->delay_write);
2819         wd->delay_write = NULL;
2820      }
2821    _save(obj);
2822    wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
2823 }
2824
2825 /**
2826  * This sets the entry object to 'autosave' the loaded text file or not.
2827  *
2828  * @param obj The entry object
2829  * @param autosave Autosave the loaded file or not
2830  *
2831  * @ingroup Entry
2832  */
2833 EAPI void
2834 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
2835 {
2836    ELM_CHECK_WIDTYPE(obj, widtype);
2837    Widget_Data *wd = elm_widget_data_get(obj);
2838    if (!wd) return;
2839    wd->autosave = !!autosave;
2840 }
2841
2842 /**
2843  * This gets the entry object's 'autosave' status.
2844  *
2845  * @param obj The entry object
2846  * @return Autosave the loaded file or not
2847  *
2848  * @ingroup Entry
2849  */
2850 EAPI Eina_Bool
2851 elm_entry_autosave_get(const Evas_Object *obj)
2852 {
2853    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2854    Widget_Data *wd = elm_widget_data_get(obj);
2855    if (!wd) return EINA_FALSE;
2856    return wd->autosave;
2857 }
2858
2859
2860 /**
2861  * Control pasting of text and images for the widget.
2862  *
2863  * Normally the entry allows both text and images to be pasted.  By setting
2864  * textonly to be true, this prevents images from being pasted.
2865  *
2866  * Note this only changes the behaviour of text.
2867  *
2868  * @param obj The entry object
2869  * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is text+image+other.
2870  *
2871  * @ingroup Entry
2872  */
2873 EAPI void
2874 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
2875 {
2876    Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
2877    ELM_CHECK_WIDTYPE(obj, widtype);
2878    Widget_Data *wd = elm_widget_data_get(obj);
2879    if (!wd) return;
2880    textonly = !!textonly;
2881    if (wd->textonly == textonly) return;
2882    wd->textonly = !!textonly;
2883    if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
2884 #ifdef HAVE_ELEMENTARY_X
2885    elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
2886 #endif
2887 }
2888
2889 /**
2890  * Getting elm_entry text paste/drop mode.
2891  *
2892  * In textonly mode, only text may be pasted or dropped into the widget.
2893  *
2894  * @param obj The entry object
2895  * @return If the widget only accepts text from pastes.
2896  *
2897  * @ingroup Entry
2898  */
2899 EAPI Eina_Bool
2900 elm_entry_cnp_textonly_get(Evas_Object *obj)
2901 {
2902    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2903    Widget_Data *wd = elm_widget_data_get(obj);
2904    if (!wd) return EINA_FALSE;
2905    return wd->textonly;
2906 }
2907