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