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