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