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