1 #include <Elementary.h>
2 #include <Elementary_Cursor.h>
6 * @defgroup Entry Entry
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
15 * You can also insert "items" in the entry with:
17 * \<item size=16x16 vsize=full href=emoticon/haha\>\</item\>
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:
24 * - emoticon/angry-shout
25 * - emoticon/crazy-laugh
26 * - emoticon/evil-laugh
28 * - emoticon/goggle-smile
30 * - emoticon/grumpy-smile
32 * - emoticon/guilty-smile
34 * - emoticon/half-smile
35 * - emoticon/happy-panting
37 * - emoticon/indifferent
39 * - emoticon/knowing-grin
41 * - emoticon/little-bit-sorry
42 * - emoticon/love-lots
44 * - emoticon/minimal-smile
45 * - emoticon/not-happy
46 * - emoticon/not-impressed
48 * - emoticon/opensmile
51 * - emoticon/squint-laugh
52 * - emoticon/surprised
53 * - emoticon/suspicious
54 * - emoticon/tongue-dangling
55 * - emoticon/tongue-poke
58 * - emoticon/very-sorry
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.
68 * See the entry test for some more examples of use of this.
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().
75 * Signals that you can add callbacks for are:
76 * - "changed" - The text within the entry was changed
77 * - "activated" - The entry has had editing finished and changes are to be committed (generally when enter key is pressed)
78 * - "press" - The entry has been clicked
79 * - "longpressed" - The entry has been clicked for a couple seconds
80 * - "clicked" - The entry has been clicked
81 * - "clicked,double" - The entry has been double clicked
82 * - "focused" - The entry has received focus
83 * - "unfocused" - The entry has lost focus
84 * - "selection,paste" - A paste action has occurred
85 * - "selection,copy" - A copy action has occurred
86 * - "selection,cut" - A cut action has occurred
87 * - "selection,start" - A selection has begun
88 * - "selection,changed" - The selection has changed
89 * - "selection,cleared" - The selection has been cleared
90 * - "cursor,changed" - The cursor has changed
91 * - "anchor,clicked" - The anchor has been clicked
94 typedef struct _Mod_Api Mod_Api;
96 typedef struct _Widget_Data Widget_Data;
97 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
98 typedef struct _Elm_Entry_Item_Provider Elm_Entry_Item_Provider;
99 typedef struct _Elm_Entry_Text_Filter Elm_Entry_Text_Filter;
104 Evas_Object *hoversel;
105 Ecore_Job *deferred_recalc_job;
106 Ecore_Event_Handler *sel_notify_handler;
107 Ecore_Event_Handler *sel_clear_handler;
108 Ecore_Timer *longpress_timer;
109 Ecore_Timer *delay_write;
110 /* Only for clipboard */
114 Elm_Text_Format format;
116 Evas_Coord downx, downy;
117 Evas_Coord cx, cy, cw, ch;
119 Eina_List *item_providers;
120 Eina_List *text_filters;
121 Ecore_Job *hovdeljob;
122 Mod_Api *api; // module api if supplied
123 Eina_Bool changed : 1;
124 Eina_Bool linewrap : 1;
125 Eina_Bool char_linewrap : 1;
126 Eina_Bool single_line : 1;
127 Eina_Bool password : 1;
128 Eina_Bool editable : 1;
129 Eina_Bool selection_asked : 1;
130 Eina_Bool have_selection : 1;
131 Eina_Bool selmode : 1;
132 Eina_Bool deferred_cur : 1;
133 Eina_Bool disabled : 1;
134 Eina_Bool context_menu : 1;
135 Eina_Bool drag_selection_asked : 1;
136 Eina_Bool can_write : 1;
137 Eina_Bool autosave : 1;
138 Eina_Bool textonly : 1;
142 struct _Elm_Entry_Context_Menu_Item
146 const char *icon_file;
147 const char *icon_group;
148 Elm_Icon_Type icon_type;
153 struct _Elm_Entry_Item_Provider
155 Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
159 struct _Elm_Entry_Text_Filter
161 void (*func) (void *data, Evas_Object *entry, char **text);
165 static const char *widtype = NULL;
167 #ifdef HAVE_ELEMENTARY_X
168 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
170 static void _del_hook(Evas_Object *obj);
171 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
172 static void _theme_hook(Evas_Object *obj);
173 static void _disable_hook(Evas_Object *obj);
174 static void _sizing_eval(Evas_Object *obj);
175 static void _on_focus_hook(void *data, Evas_Object *obj);
176 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
177 static const char *_getbase(Evas_Object *obj);
178 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
179 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
180 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
181 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
182 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
183 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
184 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
185 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
187 static const char SIG_CHANGED[] = "changed";
188 static const char SIG_ACTIVATED[] = "activated";
189 static const char SIG_PRESS[] = "press";
190 static const char SIG_LONGPRESSED[] = "longpressed";
191 static const char SIG_CLICKED[] = "clicked";
192 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
193 static const char SIG_FOCUSED[] = "focused";
194 static const char SIG_UNFOCUSED[] = "unfocused";
195 static const char SIG_SELECTION_PASTE[] = "selection,paste";
196 static const char SIG_SELECTION_COPY[] = "selection,copy";
197 static const char SIG_SELECTION_CUT[] = "selection,cut";
198 static const char SIG_SELECTION_START[] = "selection,start";
199 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
200 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
201 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
202 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
203 static const Evas_Smart_Cb_Description _signals[] = {
207 {SIG_LONGPRESSED, ""},
209 {SIG_CLICKED_DOUBLE, ""},
212 {SIG_SELECTION_PASTE, ""},
213 {SIG_SELECTION_COPY, ""},
214 {SIG_SELECTION_CUT, ""},
215 {SIG_SELECTION_START, ""},
216 {SIG_SELECTION_CHANGED, ""},
217 {SIG_SELECTION_CLEARED, ""},
218 {SIG_CURSOR_CHANGED, ""},
219 {SIG_ANCHOR_CLICKED, ""},
223 static Eina_List *entries = NULL;
227 void (*obj_hook) (Evas_Object *obj);
228 void (*obj_unhook) (Evas_Object *obj);
229 void (*obj_longpress) (Evas_Object *obj);
233 _module(Evas_Object *obj __UNUSED__)
235 static Elm_Module *m = NULL;
236 if (m) goto ok; // already found - just use
237 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
239 m->api = malloc(sizeof(Mod_Api));
240 if (!m->api) return NULL;
241 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
242 _elm_module_symbol_get(m, "obj_hook");
243 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
244 _elm_module_symbol_get(m, "obj_unhook");
245 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
246 _elm_module_symbol_get(m, "obj_longpress");
247 ok: // ok - return api
252 _buf_append(char *buf, const char *str, int *len, int *alloc)
254 int len2 = strlen(str);
255 if ((*len + len2) >= *alloc)
257 char *buf2 = realloc(buf, *alloc + len2 + 512);
258 if (!buf2) return NULL;
260 *alloc += (512 + len2);
262 strcpy(buf + *len, str);
268 _load_file(const char *file)
272 int alloc = 0, len = 0;
273 char *text = NULL, buf[16384 + 1];
275 f = fopen(file, "rb");
277 while ((size = fread(buf, 1, sizeof(buf) - 1, f)))
281 tmp_text = _buf_append(text, buf, &len, &alloc);
282 if (!tmp_text) break;
290 _load_plain(const char *file)
294 text = _load_file(file);
299 text2 = elm_entry_utf8_to_markup(text);
307 _load(Evas_Object *obj)
309 Widget_Data *wd = elm_widget_data_get(obj);
314 elm_entry_entry_set(obj, "");
319 case ELM_TEXT_FORMAT_PLAIN_UTF8:
320 text = _load_plain(wd->file);
322 case ELM_TEXT_FORMAT_MARKUP_UTF8:
323 text = _load_file(wd->file);
331 elm_entry_entry_set(obj, text);
335 elm_entry_entry_set(obj, "");
339 _save_markup_utf8(const char *file, const char *text)
343 if ((!text) || (!text[0]))
345 ecore_file_unlink(file);
348 f = fopen(file, "wb");
351 // FIXME: report a write error
354 fputs(text, f); // FIXME: catch error
359 _save_plain_utf8(const char *file, const char *text)
363 text2 = elm_entry_markup_to_utf8(text);
366 _save_markup_utf8(file, text2);
371 _save(Evas_Object *obj)
373 Widget_Data *wd = elm_widget_data_get(obj);
375 if (!wd->file) return;
378 case ELM_TEXT_FORMAT_PLAIN_UTF8:
379 _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
381 case ELM_TEXT_FORMAT_MARKUP_UTF8:
382 _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
390 _delay_write(void *data)
392 Widget_Data *wd = elm_widget_data_get(data);
393 if (!wd) return ECORE_CALLBACK_CANCEL;
395 wd->delay_write = NULL;
396 return ECORE_CALLBACK_CANCEL;
399 static Elm_Entry_Text_Filter *
400 _filter_new(void (*func) (void *data, Evas_Object *entry, char **text), void *data)
402 Elm_Entry_Text_Filter *tf = ELM_NEW(Elm_Entry_Text_Filter);
403 if (!tf) return NULL;
406 if (func == elm_entry_filter_limit_size)
408 Elm_Entry_Filter_Limit_Size *lim = data, *lim2;
415 lim2 = malloc(sizeof(Elm_Entry_Filter_Limit_Size));
421 memcpy(lim2, lim, sizeof(Elm_Entry_Filter_Limit_Size));
424 else if (func == elm_entry_filter_accept_set)
426 Elm_Entry_Filter_Accept_Set *as = data, *as2;
433 as2 = malloc(sizeof(Elm_Entry_Filter_Accept_Set));
440 as2->accepted = eina_stringshare_add(as->accepted);
442 as2->accepted = NULL;
444 as2->rejected = eina_stringshare_add(as->rejected);
446 as2->rejected = NULL;
455 _filter_free(Elm_Entry_Text_Filter *tf)
457 if (tf->func == elm_entry_filter_limit_size)
459 Elm_Entry_Filter_Limit_Size *lim = tf->data;
462 else if (tf->func == elm_entry_filter_accept_set)
464 Elm_Entry_Filter_Accept_Set *as = tf->data;
467 if (as->accepted) eina_stringshare_del(as->accepted);
468 if (as->rejected) eina_stringshare_del(as->rejected);
476 _del_pre_hook(Evas_Object *obj)
478 Widget_Data *wd = elm_widget_data_get(obj);
482 ecore_timer_del(wd->delay_write);
483 wd->delay_write = NULL;
484 if (wd->autosave) _save(obj);
489 _del_hook(Evas_Object *obj)
491 Widget_Data *wd = elm_widget_data_get(obj);
492 Elm_Entry_Context_Menu_Item *it;
493 Elm_Entry_Item_Provider *ip;
494 Elm_Entry_Text_Filter *tf;
496 if (wd->file) eina_stringshare_del(wd->file);
498 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
499 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
501 entries = eina_list_remove(entries, obj);
502 #ifdef HAVE_ELEMENTARY_X
503 ecore_event_handler_del(wd->sel_notify_handler);
504 ecore_event_handler_del(wd->sel_clear_handler);
506 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
507 if (wd->text) eina_stringshare_del(wd->text);
508 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
509 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
510 EINA_LIST_FREE(wd->items, it)
512 eina_stringshare_del(it->label);
513 eina_stringshare_del(it->icon_file);
514 eina_stringshare_del(it->icon_group);
517 EINA_LIST_FREE(wd->item_providers, ip)
521 EINA_LIST_FREE(wd->text_filters, tf)
529 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
531 Widget_Data *wd = elm_widget_data_get(obj);
532 edje_object_mirrored_set(wd->ent, rtl);
536 _theme_hook(Evas_Object *obj)
538 Widget_Data *wd = elm_widget_data_get(obj);
540 _elm_widget_mirrored_reload(obj);
541 _mirrored_set(obj, elm_widget_mirrored_get(obj));
543 t = eina_stringshare_add(elm_entry_entry_get(obj));
544 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
545 elm_entry_entry_set(obj, t);
546 eina_stringshare_del(t);
547 if (elm_widget_disabled_get(obj))
548 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
549 elm_entry_cursor_pos_set(obj, wd->cursor_pos);
550 if (elm_widget_focus_get(obj))
551 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
552 edje_object_message_signal_process(wd->ent);
553 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
558 _disable_hook(Evas_Object *obj)
560 Widget_Data *wd = elm_widget_data_get(obj);
562 if (elm_widget_disabled_get(obj))
564 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
565 wd->disabled = EINA_TRUE;
569 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
570 wd->disabled = EINA_FALSE;
575 _elm_win_recalc_job(void *data)
577 Widget_Data *wd = elm_widget_data_get(data);
578 Evas_Coord minw = -1, minh = -1, maxh = -1;
579 Evas_Coord resw, resh, minminw;
581 wd->deferred_recalc_job = NULL;
582 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
584 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, 0, 0);
585 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
587 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
588 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
589 evas_object_size_hint_min_set(data, minminw, minh);
590 if (wd->single_line) maxh = minh;
591 evas_object_size_hint_max_set(data, -1, maxh);
592 if (wd->deferred_cur)
593 elm_widget_show_region_set(data, wd->cx, wd->cy, wd->cw, wd->ch);
597 _sizing_eval(Evas_Object *obj)
599 Widget_Data *wd = elm_widget_data_get(obj);
600 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
601 Evas_Coord resw, resh;
603 if ((wd->linewrap) || (wd->char_linewrap))
605 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
606 if ((resw == wd->lastw) && (!wd->changed)) return;
607 wd->changed = EINA_FALSE;
609 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
610 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
614 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
615 edje_object_size_min_calc(wd->ent, &minw, &minh);
616 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
617 evas_object_size_hint_min_set(obj, minw, minh);
618 if (wd->single_line) maxh = minh;
619 evas_object_size_hint_max_set(obj, maxw, maxh);
624 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
626 Widget_Data *wd = elm_widget_data_get(obj);
627 Evas_Object *top = elm_widget_top_get(obj);
629 if (!wd->editable) return;
630 if (elm_widget_focus_get(obj))
632 evas_object_focus_set(wd->ent, EINA_TRUE);
633 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
634 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
635 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
639 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
640 evas_object_focus_set(wd->ent, EINA_FALSE);
641 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
642 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
647 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
649 Widget_Data *wd = elm_widget_data_get(obj);
651 edje_object_signal_emit(wd->ent, emission, source);
655 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
657 Widget_Data *wd = elm_widget_data_get(obj);
659 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
663 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
665 Widget_Data *wd = elm_widget_data_get(obj);
666 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
671 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
673 Widget_Data *wd = elm_widget_data_get(obj);
674 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
678 _hoversel_position(Evas_Object *obj)
680 Widget_Data *wd = elm_widget_data_get(obj);
681 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
683 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
684 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
686 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
697 evas_object_move(wd->hoversel, x + cx, y + cy);
698 evas_object_resize(wd->hoversel, cw, ch);
702 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
704 Widget_Data *wd = elm_widget_data_get(data);
706 if (wd->hoversel) _hoversel_position(data);
710 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
712 Widget_Data *wd = elm_widget_data_get(data);
714 if ((wd->linewrap) || (wd->char_linewrap))
718 if (wd->hoversel) _hoversel_position(data);
719 // Evas_Coord ww, hh;
720 // evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
724 _hover_del(void *data)
726 Widget_Data *wd = elm_widget_data_get(data);
731 evas_object_del(wd->hoversel);
734 wd->hovdeljob = NULL;
738 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
740 Widget_Data *wd = elm_widget_data_get(data);
742 if (wd->hoversel) evas_object_hide(wd->hoversel);
746 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
748 elm_widget_scroll_freeze_pop(data);
749 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
750 wd->hovdeljob = ecore_job_add(_hover_del, data);
754 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
756 Widget_Data *wd = elm_widget_data_get(data);
758 wd->selmode = EINA_TRUE;
759 edje_object_part_text_select_none(wd->ent, "elm.text");
761 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
762 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
763 elm_widget_scroll_hold_push(data);
767 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
769 Widget_Data *wd = elm_widget_data_get(data);
771 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
772 if (wd->sel_notify_handler)
774 #ifdef HAVE_ELEMENTARY_X
775 Elm_Sel_Format formats;
776 wd->selection_asked = EINA_TRUE;
777 formats = ELM_SEL_FORMAT_MARKUP;
779 formats |= ELM_SEL_FORMAT_IMAGE;
780 elm_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL);
786 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
788 Widget_Data *wd = elm_widget_data_get(obj);
792 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
793 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
794 if (seltype == ELM_SEL_CLIPBOARD)
795 eina_stringshare_replace(&wd->cut_sel, sel);
799 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
801 Widget_Data *wd = elm_widget_data_get(data);
804 wd->selmode = EINA_FALSE;
805 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
806 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
807 elm_widget_scroll_hold_pop(data);
808 _store_selection(ELM_SEL_CLIPBOARD, data);
809 edje_object_part_text_insert(wd->ent, "elm.text", "");
810 edje_object_part_text_select_none(wd->ent, "elm.text");
814 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
816 Widget_Data *wd = elm_widget_data_get(data);
818 wd->selmode = EINA_FALSE;
819 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
820 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
821 elm_widget_scroll_hold_pop(data);
822 _store_selection(ELM_SEL_CLIPBOARD, data);
823 // edje_object_part_text_select_none(wd->ent, "elm.text");
827 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
829 Widget_Data *wd = elm_widget_data_get(data);
831 wd->selmode = EINA_FALSE;
832 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
833 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
834 elm_widget_scroll_hold_pop(data);
835 edje_object_part_text_select_none(wd->ent, "elm.text");
839 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
841 Elm_Entry_Context_Menu_Item *it = data;
842 Evas_Object *obj2 = it->obj;
843 if (it->func) it->func(it->data, obj2, NULL);
847 _long_press(void *data)
849 Widget_Data *wd = elm_widget_data_get(data);
852 const Elm_Entry_Context_Menu_Item *it;
853 if (!wd) return ECORE_CALLBACK_CANCEL;
854 if ((wd->api) && (wd->api->obj_longpress))
856 wd->api->obj_longpress(data);
858 else if (wd->context_menu)
860 const char *context_menu_orientation;
862 if (wd->hoversel) evas_object_del(wd->hoversel);
863 else elm_widget_scroll_freeze_push(data);
864 wd->hoversel = elm_hoversel_add(data);
865 context_menu_orientation = edje_object_data_get
866 (wd->ent, "context_menu_orientation");
867 if ((context_menu_orientation) &&
868 (!strcmp(context_menu_orientation, "horizontal")))
869 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
870 elm_object_style_set(wd->hoversel, "entry");
871 elm_widget_sub_object_add(data, wd->hoversel);
872 elm_hoversel_label_set(wd->hoversel, "Text");
873 top = elm_widget_top_get(data);
874 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
875 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, data);
879 elm_hoversel_item_add(wd->hoversel, E_("Select"), NULL, ELM_ICON_NONE,
881 if (1) // need way to detect if someone has a selection
884 elm_hoversel_item_add(wd->hoversel, E_("Paste"), NULL, ELM_ICON_NONE,
892 if (wd->have_selection)
894 elm_hoversel_item_add(wd->hoversel, E_("Copy"), NULL, ELM_ICON_NONE,
897 elm_hoversel_item_add(wd->hoversel, E_("Cut"), NULL, ELM_ICON_NONE,
900 elm_hoversel_item_add(wd->hoversel, E_("Cancel"), NULL, ELM_ICON_NONE,
904 EINA_LIST_FOREACH(wd->items, l, it)
906 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
907 it->icon_type, _item_clicked, it);
911 _hoversel_position(data);
912 evas_object_show(wd->hoversel);
913 elm_hoversel_hover_begin(wd->hoversel);
915 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
916 edje_object_part_text_select_abort(wd->ent, "elm.text");
918 wd->longpress_timer = NULL;
919 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
920 return ECORE_CALLBACK_CANCEL;
924 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
926 Widget_Data *wd = elm_widget_data_get(data);
927 Evas_Event_Mouse_Down *ev = event_info;
929 if (wd->disabled) return;
930 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
931 if (ev->button != 1) return;
932 // if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
933 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
934 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
935 wd->downx = ev->canvas.x;
936 wd->downy = ev->canvas.y;
940 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
942 Widget_Data *wd = elm_widget_data_get(data);
943 Evas_Event_Mouse_Up *ev = event_info;
945 if (wd->disabled) return;
946 if (ev->button != 1) return;
947 if (wd->longpress_timer)
949 ecore_timer_del(wd->longpress_timer);
950 wd->longpress_timer = NULL;
955 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
957 Widget_Data *wd = elm_widget_data_get(data);
958 Evas_Event_Mouse_Move *ev = event_info;
960 if (wd->disabled) return;
963 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
965 if (wd->longpress_timer)
967 ecore_timer_del(wd->longpress_timer);
968 wd->longpress_timer = NULL;
971 else if (wd->longpress_timer)
975 dx = wd->downx - ev->cur.canvas.x;
977 dy = wd->downy - ev->cur.canvas.y;
980 ((_elm_config->finger_size / 2) *
981 (_elm_config->finger_size / 2)))
983 ecore_timer_del(wd->longpress_timer);
984 wd->longpress_timer = NULL;
988 else if (wd->longpress_timer)
992 dx = wd->downx - ev->cur.canvas.x;
994 dy = wd->downy - ev->cur.canvas.y;
997 ((_elm_config->finger_size / 2) *
998 (_elm_config->finger_size / 2)))
1000 ecore_timer_del(wd->longpress_timer);
1001 wd->longpress_timer = NULL;
1007 _getbase(Evas_Object *obj)
1009 Widget_Data *wd = elm_widget_data_get(obj);
1010 if (!wd) return "base";
1013 if (wd->password) return "base-password";
1016 if (wd->single_line) return "base-single";
1019 if (wd->linewrap) return "base";
1020 else if (wd->char_linewrap) return "base-charwrap";
1021 else return "base-nowrap";
1027 if (wd->password) return "base-password";
1030 if (wd->single_line) return "base-single-noedit";
1033 if (wd->linewrap) return "base-noedit";
1034 else if (wd->char_linewrap) return "base-noedit-charwrap";
1035 else return "base-nowrap-noedit";
1043 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1045 Widget_Data *wd = elm_widget_data_get(data);
1047 wd->changed = EINA_TRUE;
1049 if (wd->text) eina_stringshare_del(wd->text);
1051 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1052 if (wd->delay_write)
1054 ecore_timer_del(wd->delay_write);
1055 wd->delay_write = NULL;
1057 if ((!wd->autosave) || (!wd->file)) return;
1058 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1062 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1064 Widget_Data *wd = elm_widget_data_get(data);
1068 EINA_LIST_FOREACH(entries, l, entry)
1070 if (entry != data) elm_entry_select_none(entry);
1072 wd->have_selection = EINA_TRUE;
1073 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1074 #ifdef HAVE_ELEMENTARY_X
1075 if (wd->sel_notify_handler)
1077 const char *txt = elm_entry_selection_get(data);
1080 top = elm_widget_top_get(data);
1081 if ((top) && (elm_win_xwindow_get(top)))
1082 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1088 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1090 Widget_Data *wd = elm_widget_data_get(data);
1092 wd->have_selection = EINA_TRUE;
1093 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1094 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1095 elm_entry_selection_get(data));
1099 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1101 Widget_Data *wd = elm_widget_data_get(data);
1103 if (!wd->have_selection) return;
1104 wd->have_selection = EINA_FALSE;
1105 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1106 if (wd->sel_notify_handler)
1110 #ifdef HAVE_ELEMENTARY_X
1113 top = elm_widget_top_get(data);
1114 if ((top) && (elm_win_xwindow_get(top)))
1115 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1118 eina_stringshare_del(wd->cut_sel);
1123 #ifdef HAVE_ELEMENTARY_X
1126 top = elm_widget_top_get(data);
1127 if ((top) && (elm_win_xwindow_get(top)))
1128 elm_selection_clear(ELM_SEL_PRIMARY, data);
1135 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1137 Widget_Data *wd = elm_widget_data_get(data);
1139 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1140 if (wd->sel_notify_handler)
1142 #ifdef HAVE_ELEMENTARY_X
1145 top = elm_widget_top_get(data);
1146 if ((top) && (elm_win_xwindow_get(top)))
1148 wd->selection_asked = EINA_TRUE;
1149 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
1157 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1159 Widget_Data *wd = elm_widget_data_get(data);
1161 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1162 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1163 elm_entry_selection_get(data));
1167 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1169 Widget_Data *wd = elm_widget_data_get(data);
1171 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1172 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1173 elm_entry_selection_get(data));
1174 edje_object_part_text_insert(wd->ent, "elm.text", "");
1175 wd->changed = EINA_TRUE;
1180 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1182 Widget_Data *wd = elm_widget_data_get(data);
1183 Evas_Coord cx, cy, cw, ch;
1185 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1186 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1187 &cx, &cy, &cw, &ch);
1188 wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1189 if (!wd->deferred_recalc_job)
1190 elm_widget_show_region_set(data, cx, cy, cw, ch);
1193 wd->deferred_cur = EINA_TRUE;
1202 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1204 Widget_Data *wd = elm_widget_data_get(data);
1209 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1211 Widget_Data *wd = elm_widget_data_get(data);
1216 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1218 Widget_Data *wd = elm_widget_data_get(data);
1219 Elm_Entry_Anchor_Info ei;
1220 char *buf2, *p, *p2, *n;
1222 p = strrchr(emission, ',');
1225 const Eina_List *geoms;
1229 while (p2 >= emission)
1231 if (*p2 == ',') break;
1235 buf2 = alloca(5 + p - p2);
1236 strncpy(buf2, p2, p - p2);
1239 ei.button = atoi(buf2);
1240 ei.x = ei.y = ei.w = ei.h = 0;
1242 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1245 Evas_Textblock_Rectangle *r;
1247 Evas_Coord px, py, x, y;
1249 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1250 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1251 EINA_LIST_FOREACH(geoms, l, r)
1253 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1254 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1265 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1270 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1272 Widget_Data *wd = elm_widget_data_get(data);
1277 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1279 Widget_Data *wd = elm_widget_data_get(data);
1284 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1286 Widget_Data *wd = elm_widget_data_get(data);
1291 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1293 Widget_Data *wd = elm_widget_data_get(data);
1295 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1299 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1301 Widget_Data *wd = elm_widget_data_get(data);
1303 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1307 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1309 Widget_Data *wd = elm_widget_data_get(data);
1311 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1315 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1317 Widget_Data *wd = elm_widget_data_get(data);
1319 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1322 #ifdef HAVE_ELEMENTARY_X
1324 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1326 Widget_Data *wd = elm_widget_data_get(data);
1327 Ecore_X_Event_Selection_Notify *ev = event;
1328 if (!wd) return ECORE_CALLBACK_PASS_ON;
1329 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1330 return ECORE_CALLBACK_PASS_ON;
1332 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1333 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1335 Ecore_X_Selection_Data_Text *text_data;
1337 text_data = ev->data;
1338 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1340 if (text_data->text)
1342 char *txt = _elm_util_text_to_mkup(text_data->text);
1346 elm_entry_entry_insert(data, txt);
1351 wd->selection_asked = EINA_FALSE;
1353 else if (ev->selection == ECORE_X_SELECTION_XDND)
1355 Ecore_X_Selection_Data_Text *text_data;
1357 text_data = ev->data;
1358 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1360 if (text_data->text)
1362 char *txt = _elm_util_text_to_mkup(text_data->text);
1366 /* Massive FIXME: this should be at the drag point */
1367 elm_entry_entry_insert(data, txt);
1372 wd->drag_selection_asked = EINA_FALSE;
1374 ecore_x_dnd_send_finished();
1377 return ECORE_CALLBACK_PASS_ON;
1381 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1384 Widget_Data *wd = elm_widget_data_get(data);
1385 Ecore_X_Event_Selection_Clear *ev = event;
1386 if (!wd) return ECORE_CALLBACK_PASS_ON;
1387 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1388 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1389 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1391 elm_entry_select_none(data);
1394 return ECORE_CALLBACK_PASS_ON;
1399 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1404 wd = elm_widget_data_get(obj);
1406 if (!wd) return EINA_FALSE;
1407 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1409 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1410 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1411 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1412 EDJE_CURSOR_MAIN,drop->x,drop->y);
1413 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1414 elm_entry_entry_insert(obj, drop->data);
1415 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1416 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1422 static Evas_Object *
1423 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1425 Widget_Data *wd = elm_widget_data_get(data);
1428 Elm_Entry_Item_Provider *ip;
1430 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1432 o = ip->func(ip->data, data, item);
1435 if (!strncmp(item, "file://", 7))
1437 const char *fname = item + 7;
1439 o = evas_object_image_filled_add(evas_object_evas_get(data));
1440 evas_object_image_file_set(o, fname, NULL);
1441 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1443 evas_object_show(o);
1448 o = edje_object_add(evas_object_evas_get(data));
1449 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1453 o = edje_object_add(evas_object_evas_get(data));
1454 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1455 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1460 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
1462 Widget_Data *wd = elm_widget_data_get(data);
1464 Elm_Entry_Text_Filter *tf;
1466 if (type == EDJE_TEXT_FILTER_FORMAT)
1469 EINA_LIST_FOREACH(wd->text_filters, l, tf)
1471 tf->func(tf->data, data, text);
1478 * This adds an entry to @p parent object.
1480 * @param parent The parent object
1481 * @return The new object or NULL if it cannot be created
1486 elm_entry_add(Evas_Object *parent)
1488 Evas_Object *obj, *top;
1492 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1494 ELM_SET_WIDTYPE(widtype, "entry");
1495 elm_widget_type_set(obj, "entry");
1496 elm_widget_sub_object_add(parent, obj);
1497 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1498 elm_widget_data_set(obj, wd);
1499 elm_widget_del_hook_set(obj, _del_hook);
1500 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1501 elm_widget_theme_hook_set(obj, _theme_hook);
1502 elm_widget_disable_hook_set(obj, _disable_hook);
1503 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1504 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
1505 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1506 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1507 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
1508 elm_widget_can_focus_set(obj, EINA_TRUE);
1509 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
1511 wd->linewrap = EINA_TRUE;
1512 wd->char_linewrap= EINA_FALSE;
1513 wd->editable = EINA_TRUE;
1514 wd->disabled = EINA_FALSE;
1515 wd->context_menu = EINA_TRUE;
1516 wd->autosave = EINA_TRUE;
1517 wd->textonly = EINA_FALSE;
1519 wd->ent = edje_object_add(e);
1520 edje_object_item_provider_set(wd->ent, _get_item, obj);
1521 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
1522 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1523 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1524 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1526 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1528 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1531 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1532 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1533 _signal_entry_changed, obj);
1534 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1535 _signal_selection_start, obj);
1536 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1537 _signal_selection_changed, obj);
1538 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1539 _signal_selection_cleared, obj);
1540 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1541 _signal_entry_paste_request, obj);
1542 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1543 _signal_entry_copy_notify, obj);
1544 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1545 _signal_entry_cut_notify, obj);
1546 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1547 _signal_cursor_changed, obj);
1548 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1549 _signal_anchor_down, obj);
1550 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1551 _signal_anchor_up, obj);
1552 edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
1553 _signal_anchor_clicked, obj);
1554 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1555 _signal_anchor_move, obj);
1556 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1557 _signal_anchor_in, obj);
1558 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1559 _signal_anchor_out, obj);
1560 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
1561 _signal_key_enter, obj);
1562 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
1563 _signal_mouse_down, obj);
1564 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
1565 _signal_mouse_clicked, obj);
1566 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
1567 _signal_mouse_double, obj);
1568 edje_object_part_text_set(wd->ent, "elm.text", "");
1569 elm_widget_resize_object_set(obj, wd->ent);
1572 #ifdef HAVE_ELEMENTARY_X
1573 top = elm_widget_top_get(obj);
1574 if ((top) && (elm_win_xwindow_get(top)))
1576 wd->sel_notify_handler =
1577 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
1578 _event_selection_notify, obj);
1579 wd->sel_clear_handler =
1580 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
1581 _event_selection_clear, obj);
1584 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
1585 _drag_drop_cb, NULL);
1588 entries = eina_list_prepend(entries, obj);
1590 // module - find module for entry
1591 wd->api = _module(obj);
1592 // if found - hook in
1593 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
1595 _mirrored_set(obj, elm_widget_mirrored_get(obj));
1596 // TODO: convert Elementary to subclassing of Evas_Smart_Class
1597 // TODO: and save some bytes, making descriptions per-class and not instance!
1598 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1604 * This sets the entry object not to line wrap. All input will
1605 * be on a single line, and the entry box will extend with user input.
1607 * @param obj The entry object
1608 * @param single_line If true, the text in the entry
1609 * will be on a single line.
1614 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
1616 ELM_CHECK_WIDTYPE(obj, widtype);
1617 Widget_Data *wd = elm_widget_data_get(obj);
1619 if (wd->single_line == single_line) return;
1620 wd->single_line = single_line;
1621 wd->linewrap = EINA_FALSE;
1622 wd->char_linewrap = EINA_FALSE;
1623 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
1628 * This returns true if the entry has been set to single line mode.
1629 * See also elm_entry_single_line_set().
1631 * @param obj The entry object
1632 * @return single_line If true, the text in the entry is set to display
1638 elm_entry_single_line_get(const Evas_Object *obj)
1640 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1641 Widget_Data *wd = elm_widget_data_get(obj);
1642 if (!wd) return EINA_FALSE;
1643 return wd->single_line;
1647 * This sets the entry object to password mode. All text entered
1648 * and/or displayed within the widget will be replaced with asterisks (*).
1650 * @param obj The entry object
1651 * @param password If true, password mode is enabled.
1656 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
1658 ELM_CHECK_WIDTYPE(obj, widtype);
1659 Widget_Data *wd = elm_widget_data_get(obj);
1661 if (wd->password == password) return;
1662 wd->password = password;
1663 wd->single_line = EINA_TRUE;
1664 wd->linewrap = EINA_FALSE;
1665 wd->char_linewrap = EINA_FALSE;
1671 * This returns whether password mode is enabled.
1672 * See also elm_entry_password_set().
1674 * @param obj The entry object
1675 * @return If true, the entry is set to display all characters
1681 elm_entry_password_get(const Evas_Object *obj)
1683 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1684 Widget_Data *wd = elm_widget_data_get(obj);
1685 if (!wd) return EINA_FALSE;
1686 return wd->password;
1690 * This sets the text displayed within the entry to @p entry.
1692 * @param obj The entry object
1693 * @param entry The text to be displayed
1698 elm_entry_entry_set(Evas_Object *obj, const char *entry)
1700 ELM_CHECK_WIDTYPE(obj, widtype);
1701 Widget_Data *wd = elm_widget_data_get(obj);
1703 if (!entry) entry = "";
1704 edje_object_part_text_set(wd->ent, "elm.text", entry);
1705 if (wd->text) eina_stringshare_del(wd->text);
1707 wd->changed = EINA_TRUE;
1712 * This returns the text currently shown in object @p entry.
1713 * See also elm_entry_entry_set().
1715 * @param obj The entry object
1716 * @return The currently displayed text or NULL on failure
1721 elm_entry_entry_get(const Evas_Object *obj)
1723 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1724 Widget_Data *wd = elm_widget_data_get(obj);
1726 if (!wd) return NULL;
1727 if (wd->text) return wd->text;
1728 text = edje_object_part_text_get(wd->ent, "elm.text");
1731 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
1734 eina_stringshare_replace(&wd->text, text);
1740 * This returns EINA_TRUE if the entry is empty/there was an error
1741 * and EINA_FALSE if it is not empty.
1743 * @param obj The entry object
1744 * @return If the entry is empty or not.
1749 elm_entry_is_empty(const Evas_Object *obj)
1751 /* FIXME: until there's support for that in textblock, we just check
1752 * to see if the there is text or not. */
1753 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
1754 Widget_Data *wd = elm_widget_data_get(obj);
1755 const Evas_Object *tb;
1756 Evas_Textblock_Cursor *cur;
1758 if (!wd) return EINA_TRUE;
1759 /* It's a hack until we get the support suggested above.
1760 * We just create a cursor, point it to the begining, and then
1761 * try to advance it, if it can advance, the tb is not empty,
1762 * otherwise it is. */
1763 tb = edje_object_part_object_get(wd->ent, "elm.text");
1764 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
1765 actually, ok for the time being, thsese hackish stuff will be removed
1766 once evas 1.0 is out*/
1767 evas_textblock_cursor_pos_set(cur, 0);
1768 ret = evas_textblock_cursor_char_next(cur);
1769 evas_textblock_cursor_free(cur);
1775 * This returns all selected text within the entry.
1777 * @param obj The entry object
1778 * @return The selected text within the entry or NULL on failure
1783 elm_entry_selection_get(const Evas_Object *obj)
1785 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1786 Widget_Data *wd = elm_widget_data_get(obj);
1787 if (!wd) return NULL;
1788 return edje_object_part_text_selection_get(wd->ent, "elm.text");
1792 * This inserts text in @p entry where the current cursor position.
1794 * This inserts text at the cursor position is as if it was typed
1795 * by the user (note this also allows markup which a user
1796 * can't just "type" as it would be converted to escaped text, so this
1797 * call can be used to insert things like emoticon items or bold push/pop
1798 * tags, other font and color change tags etc.)
1800 * @param obj The entry object
1801 * @param entry The text to insert
1806 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
1808 ELM_CHECK_WIDTYPE(obj, widtype);
1809 Widget_Data *wd = elm_widget_data_get(obj);
1811 edje_object_part_text_insert(wd->ent, "elm.text", entry);
1812 wd->changed = EINA_TRUE;
1817 * This enables word line wrapping in the entry object. It is the opposite
1818 * of elm_entry_single_line_set(). Additionally, setting this disables
1819 * character line wrapping.
1820 * See also elm_entry_line_char_wrap_set().
1822 * @param obj The entry object
1823 * @param wrap If true, the entry will be wrapped once it reaches the end
1824 * of the object. Wrapping will occur at the end of the word before the end of the
1830 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
1832 ELM_CHECK_WIDTYPE(obj, widtype);
1833 Widget_Data *wd = elm_widget_data_get(obj);
1835 if (wd->linewrap == wrap) return;
1836 wd->linewrap = wrap;
1838 wd->char_linewrap = EINA_FALSE;
1843 * This enables character line wrapping in the entry object. It is the opposite
1844 * of elm_entry_single_line_set(). Additionally, setting this disables
1845 * word line wrapping.
1846 * See also elm_entry_line_wrap_set().
1848 * @param obj The entry object
1849 * @param wrap If true, the entry will be wrapped once it reaches the end
1850 * of the object. Wrapping will occur immediately upon reaching the end of the object.
1855 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
1857 ELM_CHECK_WIDTYPE(obj, widtype);
1858 Widget_Data *wd = elm_widget_data_get(obj);
1860 if (wd->char_linewrap == wrap) return;
1861 wd->char_linewrap = wrap;
1862 if(wd->char_linewrap)
1863 wd->linewrap = EINA_FALSE;
1868 * This sets the editable attribute of the entry.
1870 * @param obj The entry object
1871 * @param editable If true, the entry will be editable by the user.
1872 * If false, it will be set to the disabled state.
1877 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
1879 ELM_CHECK_WIDTYPE(obj, widtype);
1880 Widget_Data *wd = elm_widget_data_get(obj);
1882 if (wd->editable == editable) return;
1883 wd->editable = editable;
1886 #ifdef HAVE_ELEMENTARY_X
1888 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
1890 elm_drop_target_del(obj);
1895 * This gets the editable attribute of the entry.
1896 * See also elm_entry_editable_set().
1898 * @param obj The entry object
1899 * @return If true, the entry is editable by the user.
1900 * If false, it is not editable by the user
1905 elm_entry_editable_get(const Evas_Object *obj)
1907 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1908 Widget_Data *wd = elm_widget_data_get(obj);
1909 if (!wd) return EINA_FALSE;
1910 return wd->editable;
1914 * This drops any existing text selection within the entry.
1916 * @param obj The entry object
1921 elm_entry_select_none(Evas_Object *obj)
1923 ELM_CHECK_WIDTYPE(obj, widtype);
1924 Widget_Data *wd = elm_widget_data_get(obj);
1928 wd->selmode = EINA_FALSE;
1929 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1930 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1932 wd->have_selection = EINA_FALSE;
1933 edje_object_part_text_select_none(wd->ent, "elm.text");
1937 * This selects all text within the entry.
1939 * @param obj The entry object
1944 elm_entry_select_all(Evas_Object *obj)
1946 ELM_CHECK_WIDTYPE(obj, widtype);
1947 Widget_Data *wd = elm_widget_data_get(obj);
1951 wd->selmode = EINA_FALSE;
1952 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1953 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1955 wd->have_selection = EINA_TRUE;
1956 edje_object_part_text_select_all(wd->ent, "elm.text");
1960 * This function returns the geometry of the cursor.
1962 * It's useful if you want to draw something on the cursor (or where it is),
1963 * or for example in the case of scrolled entry where you want to show the
1966 * @param obj The entry object
1967 * @param x returned geometry
1968 * @param y returned geometry
1969 * @param w returned geometry
1970 * @param h returned geometry
1971 * @return EINA_TRUE upon success, EINA_FALSE upon failure
1976 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1978 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1979 Widget_Data *wd = elm_widget_data_get(obj);
1980 if (!wd) return EINA_FALSE;
1981 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
1986 * This moves the cursor one place to the right within the entry.
1988 * @param obj The entry object
1989 * @return EINA_TRUE upon success, EINA_FALSE upon failure
1994 elm_entry_cursor_next(Evas_Object *obj)
1996 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1997 Widget_Data *wd = elm_widget_data_get(obj);
1998 if (!wd) return EINA_FALSE;
1999 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2003 * This moves the cursor one place to the left within the entry.
2005 * @param obj The entry object
2006 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2011 elm_entry_cursor_prev(Evas_Object *obj)
2013 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2014 Widget_Data *wd = elm_widget_data_get(obj);
2015 if (!wd) return EINA_FALSE;
2016 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2020 * This moves the cursor one line up within the entry.
2022 * @param obj The entry object
2023 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2028 elm_entry_cursor_up(Evas_Object *obj)
2030 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2031 Widget_Data *wd = elm_widget_data_get(obj);
2032 if (!wd) return EINA_FALSE;
2033 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2037 * This moves the cursor one line down within the entry.
2039 * @param obj The entry object
2040 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2045 elm_entry_cursor_down(Evas_Object *obj)
2047 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2048 Widget_Data *wd = elm_widget_data_get(obj);
2049 if (!wd) return EINA_FALSE;
2050 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2054 * This moves the cursor to the beginning of the entry.
2056 * @param obj The entry object
2061 elm_entry_cursor_begin_set(Evas_Object *obj)
2063 ELM_CHECK_WIDTYPE(obj, widtype);
2064 Widget_Data *wd = elm_widget_data_get(obj);
2066 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2070 * This moves the cursor to the end of the entry.
2072 * @param obj The entry object
2077 elm_entry_cursor_end_set(Evas_Object *obj)
2079 ELM_CHECK_WIDTYPE(obj, widtype);
2080 Widget_Data *wd = elm_widget_data_get(obj);
2082 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2086 * This moves the cursor to the beginning of the current line.
2088 * @param obj The entry object
2093 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2095 ELM_CHECK_WIDTYPE(obj, widtype);
2096 Widget_Data *wd = elm_widget_data_get(obj);
2098 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2102 * This moves the cursor to the end of the current line.
2104 * @param obj The entry object
2109 elm_entry_cursor_line_end_set(Evas_Object *obj)
2111 ELM_CHECK_WIDTYPE(obj, widtype);
2112 Widget_Data *wd = elm_widget_data_get(obj);
2114 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2118 * This begins a selection within the entry as though
2119 * the user were holding down the mouse button to make a selection.
2121 * @param obj The entry object
2126 elm_entry_cursor_selection_begin(Evas_Object *obj)
2128 ELM_CHECK_WIDTYPE(obj, widtype);
2129 Widget_Data *wd = elm_widget_data_get(obj);
2131 edje_object_part_text_select_begin(wd->ent, "elm.text");
2135 * This ends a selection within the entry as though
2136 * the user had just released the mouse button while making a selection.
2138 * @param obj The entry object
2143 elm_entry_cursor_selection_end(Evas_Object *obj)
2145 ELM_CHECK_WIDTYPE(obj, widtype);
2146 Widget_Data *wd = elm_widget_data_get(obj);
2148 edje_object_part_text_select_extend(wd->ent, "elm.text");
2152 * TODO: fill this in
2154 * @param obj The entry object
2155 * @return TODO: fill this in
2160 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2162 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2163 Widget_Data *wd = elm_widget_data_get(obj);
2164 if (!wd) return EINA_FALSE;
2165 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2169 * This returns whether the cursor is visible.
2171 * @param obj The entry object
2172 * @return If true, the cursor is visible.
2177 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2179 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2180 Widget_Data *wd = elm_widget_data_get(obj);
2181 if (!wd) return EINA_FALSE;
2182 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2186 * TODO: fill this in
2188 * @param obj The entry object
2189 * @return TODO: fill this in
2194 elm_entry_cursor_content_get(const Evas_Object *obj)
2196 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2197 Widget_Data *wd = elm_widget_data_get(obj);
2198 if (!wd) return NULL;
2199 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2203 * Sets the cursor position in the entry to the given value
2205 * @param obj The entry object
2206 * @param pos The position of the cursor
2211 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
2213 ELM_CHECK_WIDTYPE(obj, widtype);
2214 Widget_Data *wd = elm_widget_data_get(obj);
2216 edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
2217 edje_object_message_signal_process(wd->ent);
2221 * Retrieves the current position of the cursor in the entry
2223 * @param obj The entry object
2224 * @return The cursor position
2229 elm_entry_cursor_pos_get(const Evas_Object *obj)
2231 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2232 Widget_Data *wd = elm_widget_data_get(obj);
2234 return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2238 * This executes a "cut" action on the selected text in the entry.
2240 * @param obj The entry object
2245 elm_entry_selection_cut(Evas_Object *obj)
2247 ELM_CHECK_WIDTYPE(obj, widtype);
2248 Widget_Data *wd = elm_widget_data_get(obj);
2250 _cut(obj, NULL, NULL);
2254 * This executes a "copy" action on the selected text in the entry.
2256 * @param obj The entry object
2261 elm_entry_selection_copy(Evas_Object *obj)
2263 ELM_CHECK_WIDTYPE(obj, widtype);
2264 Widget_Data *wd = elm_widget_data_get(obj);
2266 _copy(obj, NULL, NULL);
2270 * This executes a "paste" action in the entry.
2272 * @param obj The entry object
2277 elm_entry_selection_paste(Evas_Object *obj)
2279 ELM_CHECK_WIDTYPE(obj, widtype);
2280 Widget_Data *wd = elm_widget_data_get(obj);
2282 _paste(obj, NULL, NULL);
2286 * This clears and frees the items in a entry's contextual (right click) menu.
2288 * @param obj The entry object
2293 elm_entry_context_menu_clear(Evas_Object *obj)
2295 ELM_CHECK_WIDTYPE(obj, widtype);
2296 Widget_Data *wd = elm_widget_data_get(obj);
2297 Elm_Entry_Context_Menu_Item *it;
2299 EINA_LIST_FREE(wd->items, it)
2301 eina_stringshare_del(it->label);
2302 eina_stringshare_del(it->icon_file);
2303 eina_stringshare_del(it->icon_group);
2309 * This adds an item to the entry's contextual menu.
2311 * @param obj The entry object
2312 * @param label The item's text label
2313 * @param icon_file The item's icon file
2314 * @param icon_type The item's icon type
2315 * @param func The callback to execute when the item is clicked
2316 * @param data The data to associate with the item for related functions
2321 elm_entry_context_menu_item_add(Evas_Object *obj, const char *label, const char *icon_file, Elm_Icon_Type icon_type, Evas_Smart_Cb func, const void *data)
2323 ELM_CHECK_WIDTYPE(obj, widtype);
2324 Widget_Data *wd = elm_widget_data_get(obj);
2325 Elm_Entry_Context_Menu_Item *it;
2327 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2329 wd->items = eina_list_append(wd->items, it);
2331 it->label = eina_stringshare_add(label);
2332 it->icon_file = eina_stringshare_add(icon_file);
2333 it->icon_type = icon_type;
2335 it->data = (void *)data;
2339 * This disables the entry's contextual (right click) menu.
2341 * @param obj The entry object
2342 * @param disabled If true, the menu is disabled
2347 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2349 ELM_CHECK_WIDTYPE(obj, widtype);
2350 Widget_Data *wd = elm_widget_data_get(obj);
2352 if (wd->context_menu == !disabled) return;
2353 wd->context_menu = !disabled;
2357 * This returns whether the entry's contextual (right click) menu is disabled.
2359 * @param obj The entry object
2360 * @return If true, the menu is disabled
2365 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2367 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2368 Widget_Data *wd = elm_widget_data_get(obj);
2369 if (!wd) return EINA_FALSE;
2370 return !wd->context_menu;
2374 * This appends a custom item provider to the list for that entry
2376 * This appends the given callback. The list is walked from beginning to end
2377 * with each function called given the item href string in the text. If the
2378 * function returns an object handle other than NULL (it should create an
2379 * and object to do this), then this object is used to replace that item. If
2380 * not the next provider is called until one provides an item object, or the
2381 * default provider in entry does.
2383 * @param obj The entry object
2384 * @param func The function called to provide the item object
2385 * @param data The data passed to @p func
2390 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2392 ELM_CHECK_WIDTYPE(obj, widtype);
2393 Widget_Data *wd = elm_widget_data_get(obj);
2395 EINA_SAFETY_ON_NULL_RETURN(func);
2396 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2400 wd->item_providers = eina_list_append(wd->item_providers, ip);
2404 * This prepends a custom item provider to the list for that entry
2406 * This prepends the given callback. See elm_entry_item_provider_append() for
2409 * @param obj The entry object
2410 * @param func The function called to provide the item object
2411 * @param data The data passed to @p func
2416 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2418 ELM_CHECK_WIDTYPE(obj, widtype);
2419 Widget_Data *wd = elm_widget_data_get(obj);
2421 EINA_SAFETY_ON_NULL_RETURN(func);
2422 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2426 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2430 * This removes a custom item provider to the list for that entry
2432 * This removes the given callback. See elm_entry_item_provider_append() for
2435 * @param obj The entry object
2436 * @param func The function called to provide the item object
2437 * @param data The data passed to @p func
2442 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2444 ELM_CHECK_WIDTYPE(obj, widtype);
2445 Widget_Data *wd = elm_widget_data_get(obj);
2447 Elm_Entry_Item_Provider *ip;
2449 EINA_SAFETY_ON_NULL_RETURN(func);
2450 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2452 if ((ip->func == func) && ((!data) || (ip->data == data)))
2454 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2462 * Append a filter function for text inserted in the entry
2464 * Append the given callback to the list. This functions will be called
2465 * whenever any text is inserted into the entry, with the text to be inserted
2466 * as a parameter. The callback function is free to alter the text in any way
2467 * it wants, but it must remember to free the given pointer and update it.
2468 * If the new text is to be discarded, the function can free it and set it text
2469 * parameter to NULL. This will also prevent any following filters from being
2472 * @param obj The entry object
2473 * @param func The function to use as text filter
2474 * @param data User data to pass to @p func
2479 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2482 Elm_Entry_Text_Filter *tf;
2483 ELM_CHECK_WIDTYPE(obj, widtype);
2485 wd = elm_widget_data_get(obj);
2487 EINA_SAFETY_ON_NULL_RETURN(func);
2489 tf = _filter_new(func, data);
2492 wd->text_filters = eina_list_append(wd->text_filters, tf);
2496 * Prepend a filter function for text insdrted in the entry
2498 * Prepend the given callback to the list. See elm_entry_text_filter_append()
2499 * for more information
2501 * @param obj The entry object
2502 * @param func The function to use as text filter
2503 * @param data User data to pass to @p func
2508 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2511 Elm_Entry_Text_Filter *tf;
2512 ELM_CHECK_WIDTYPE(obj, widtype);
2514 wd = elm_widget_data_get(obj);
2516 EINA_SAFETY_ON_NULL_RETURN(func);
2518 tf = _filter_new(func, data);
2521 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
2525 * Remove a filter from the list
2527 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
2528 * for more information.
2530 * @param obj The entry object
2531 * @param func The filter function to remove
2532 * @param data The user data passed when adding the function
2537 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2541 Elm_Entry_Text_Filter *tf;
2542 ELM_CHECK_WIDTYPE(obj, widtype);
2544 wd = elm_widget_data_get(obj);
2546 EINA_SAFETY_ON_NULL_RETURN(func);
2548 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2550 if ((tf->func == func) && ((!data) || (tf->data == data)))
2552 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
2560 * This converts a markup (HTML-like) string into UTF-8.
2561 * Returning string is obtained with malloc.
2562 * After use the returned string, it should be freed.
2564 * @param s The string (in markup) to be converted
2565 * @return The converted string (in UTF-8). It should be freed.
2570 elm_entry_markup_to_utf8(const char *s)
2572 char *ss = _elm_util_mkup_to_text(s);
2573 if (!ss) ss = strdup("");
2578 * This converts a UTF-8 string into markup (HTML-like).
2579 * Returning string is obtained with malloc.
2580 * After use the returned string, it should be freed.
2582 * @param s The string (in UTF-8) to be converted
2583 * @return The converted string (in markup). It should be freed.
2588 elm_entry_utf8_to_markup(const char *s)
2590 char *ss = _elm_util_text_to_mkup(s);
2591 if (!ss) ss = strdup("");
2596 * Filter inserted text based on user defined character and byte limits
2598 * Add this filter to an entry to limit the characters that it will accept
2599 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
2600 * The funtion works on the UTF-8 representation of the string, converting
2601 * it from the set markup, thus not accounting for any format in it.
2603 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
2604 * it as data when setting the filter. In it it's possible to set limits
2605 * by character count or bytes (any of them is disabled if 0), and both can
2606 * be set at the same time. In that case, it first checks for characters,
2609 * The function will cut the inserted text in order to allow only the first
2610 * number of characters that are still allowed. The cut is made in
2611 * characters, even when limiting by bytes, in order to always contain
2612 * valid ones and avoid half unicode characters making it in.
2617 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
2619 Elm_Entry_Filter_Limit_Size *lim = data;
2622 const char *(*text_get)(const Evas_Object *);
2623 const char *widget_type;
2625 EINA_SAFETY_ON_NULL_RETURN(data);
2626 EINA_SAFETY_ON_NULL_RETURN(entry);
2627 EINA_SAFETY_ON_NULL_RETURN(text);
2629 /* hack. I don't want to copy the entire function to work with
2631 widget_type = elm_widget_type_get(entry);
2632 if (!strcmp(widget_type, "entry"))
2633 text_get = elm_entry_entry_get;
2634 else if (!strcmp(widget_type, "scrolled_entry"))
2635 text_get = elm_scrolled_entry_entry_get;
2639 current = elm_entry_markup_to_utf8(text_get(entry));
2641 if (lim->max_char_count > 0)
2644 len = evas_string_char_len_get(current);
2645 if (len >= lim->max_char_count)
2652 newlen = evas_string_char_len_get(*text);
2653 cut = strlen(*text);
2654 while ((len + newlen) > lim->max_char_count)
2656 cut = evas_string_char_prev_get(*text, cut, NULL);
2662 if (lim->max_byte_count > 0)
2664 len = strlen(current);
2665 if (len >= lim->max_byte_count)
2672 newlen = strlen(*text);
2673 while ((len + newlen) > lim->max_byte_count)
2675 int p = evas_string_char_prev_get(*text, newlen, NULL);
2676 newlen -= (newlen - p);
2679 (*text)[newlen] = 0;
2690 * Filter inserted text based on accepted or rejected sets of characters
2692 * Add this filter to an entry to restrict the set of accepted characters
2693 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
2694 * This structure contains both accepted and rejected sets, but they are
2695 * mutually exclusive. If accepted is set, it will be used, otherwise it
2696 * goes on to the rejected set.
2699 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
2701 Elm_Entry_Filter_Accept_Set *as = data;
2705 int read_idx, last_read_idx = 0, read_char;
2707 EINA_SAFETY_ON_NULL_RETURN(data);
2708 EINA_SAFETY_ON_NULL_RETURN(text);
2710 if ((!as->accepted) && (!as->rejected))
2716 goes_in = EINA_TRUE;
2721 goes_in = EINA_FALSE;
2725 read_idx = evas_string_char_next_get(*text, 0, &read_char);
2728 int cmp_idx, cmp_char;
2729 Eina_Bool in_set = EINA_FALSE;
2731 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
2734 if (read_char == cmp_char)
2739 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
2741 if (in_set == goes_in)
2743 int size = read_idx - last_read_idx;
2744 const char *src = (*text) + last_read_idx;
2746 memcpy(insert, *text + last_read_idx, size);
2749 last_read_idx = read_idx;
2750 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
2756 * This sets the file (and implicitly loads it) for the text to display and
2757 * then edit. All changes are written back to the file after a short delay if
2758 * the entry object is set to autosave.
2760 * @param obj The entry object
2761 * @param file The path to the file to load and save
2762 * @param format The file format
2767 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
2769 ELM_CHECK_WIDTYPE(obj, widtype);
2770 Widget_Data *wd = elm_widget_data_get(obj);
2772 if (wd->delay_write)
2774 ecore_timer_del(wd->delay_write);
2775 wd->delay_write = NULL;
2777 if (wd->autosave) _save(obj);
2778 eina_stringshare_replace(&wd->file, file);
2779 wd->format = format;
2784 * Gets the file to load and save and the file format
2786 * @param obj The entry object
2787 * @param file The path to the file to load and save
2788 * @param format The file format
2793 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
2795 ELM_CHECK_WIDTYPE(obj, widtype);
2796 Widget_Data *wd = elm_widget_data_get(obj);
2798 if (file) *file = wd->file;
2799 if (format) *format = wd->format;
2803 * This function writes any changes made to the file set with
2804 * elm_entry_file_set()
2806 * @param obj The entry object
2811 elm_entry_file_save(Evas_Object *obj)
2813 ELM_CHECK_WIDTYPE(obj, widtype);
2814 Widget_Data *wd = elm_widget_data_get(obj);
2816 if (wd->delay_write)
2818 ecore_timer_del(wd->delay_write);
2819 wd->delay_write = NULL;
2822 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
2826 * This sets the entry object to 'autosave' the loaded text file or not.
2828 * @param obj The entry object
2829 * @param autosave Autosave the loaded file or not
2834 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
2836 ELM_CHECK_WIDTYPE(obj, widtype);
2837 Widget_Data *wd = elm_widget_data_get(obj);
2839 wd->autosave = !!autosave;
2843 * This gets the entry object's 'autosave' status.
2845 * @param obj The entry object
2846 * @return Autosave the loaded file or not
2851 elm_entry_autosave_get(const Evas_Object *obj)
2853 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2854 Widget_Data *wd = elm_widget_data_get(obj);
2855 if (!wd) return EINA_FALSE;
2856 return wd->autosave;
2861 * Control pasting of text and images for the widget.
2863 * Normally the entry allows both text and images to be pasted. By setting
2864 * textonly to be true, this prevents images from being pasted.
2866 * Note this only changes the behaviour of text.
2868 * @param obj The entry object
2869 * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is text+image+other.
2874 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
2876 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
2877 ELM_CHECK_WIDTYPE(obj, widtype);
2878 Widget_Data *wd = elm_widget_data_get(obj);
2880 textonly = !!textonly;
2881 if (wd->textonly == textonly) return;
2882 wd->textonly = !!textonly;
2883 if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
2884 #ifdef HAVE_ELEMENTARY_X
2885 elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
2890 * Getting elm_entry text paste/drop mode.
2892 * In textonly mode, only text may be pasted or dropped into the widget.
2894 * @param obj The entry object
2895 * @return If the widget only accepts text from pastes.
2900 elm_entry_cnp_textonly_get(Evas_Object *obj)
2902 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2903 Widget_Data *wd = elm_widget_data_get(obj);
2904 if (!wd) return EINA_FALSE;
2905 return wd->textonly;