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;
141 struct _Elm_Entry_Context_Menu_Item
145 const char *icon_file;
146 const char *icon_group;
147 Elm_Icon_Type icon_type;
152 struct _Elm_Entry_Item_Provider
154 Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
158 struct _Elm_Entry_Text_Filter
160 void (*func) (void *data, Evas_Object *entry, char **text);
164 static const char *widtype = NULL;
166 #ifdef HAVE_ELEMENTARY_X
167 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
169 static void _del_hook(Evas_Object *obj);
170 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
171 static void _theme_hook(Evas_Object *obj);
172 static void _disable_hook(Evas_Object *obj);
173 static void _sizing_eval(Evas_Object *obj);
174 static void _on_focus_hook(void *data, Evas_Object *obj);
175 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
176 static const char *_getbase(Evas_Object *obj);
177 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
178 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
179 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
180 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
181 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
182 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
183 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
184 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
186 static const char SIG_CHANGED[] = "changed";
187 static const char SIG_ACTIVATED[] = "activated";
188 static const char SIG_PRESS[] = "press";
189 static const char SIG_LONGPRESSED[] = "longpressed";
190 static const char SIG_CLICKED[] = "clicked";
191 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
192 static const char SIG_FOCUSED[] = "focused";
193 static const char SIG_UNFOCUSED[] = "unfocused";
194 static const char SIG_SELECTION_PASTE[] = "selection,paste";
195 static const char SIG_SELECTION_COPY[] = "selection,copy";
196 static const char SIG_SELECTION_CUT[] = "selection,cut";
197 static const char SIG_SELECTION_START[] = "selection,start";
198 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
199 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
200 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
201 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
202 static const Evas_Smart_Cb_Description _signals[] = {
206 {SIG_LONGPRESSED, ""},
208 {SIG_CLICKED_DOUBLE, ""},
211 {SIG_SELECTION_PASTE, ""},
212 {SIG_SELECTION_COPY, ""},
213 {SIG_SELECTION_CUT, ""},
214 {SIG_SELECTION_START, ""},
215 {SIG_SELECTION_CHANGED, ""},
216 {SIG_SELECTION_CLEARED, ""},
217 {SIG_CURSOR_CHANGED, ""},
218 {SIG_ANCHOR_CLICKED, ""},
222 static Eina_List *entries = NULL;
226 void (*obj_hook) (Evas_Object *obj);
227 void (*obj_unhook) (Evas_Object *obj);
228 void (*obj_longpress) (Evas_Object *obj);
232 _module(Evas_Object *obj __UNUSED__)
234 static Elm_Module *m = NULL;
235 if (m) goto ok; // already found - just use
236 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
238 m->api = malloc(sizeof(Mod_Api));
239 if (!m->api) return NULL;
240 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
241 _elm_module_symbol_get(m, "obj_hook");
242 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
243 _elm_module_symbol_get(m, "obj_unhook");
244 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
245 _elm_module_symbol_get(m, "obj_longpress");
246 ok: // ok - return api
251 _buf_append(char *buf, const char *str, int *len, int *alloc)
253 int len2 = strlen(str);
254 if ((*len + len2) >= *alloc)
256 char *buf2 = realloc(buf, *alloc + len2 + 512);
257 if (!buf2) return NULL;
259 *alloc += (512 + len2);
261 strcpy(buf + *len, str);
267 _load_file(const char *file)
271 int alloc = 0, len = 0;
272 char *text = NULL, buf[16384 + 1];
274 f = fopen(file, "rb");
276 while ((size = fread(buf, 1, sizeof(buf) - 1, f)))
280 tmp_text = _buf_append(text, buf, &len, &alloc);
281 if (!tmp_text) break;
289 _load_plain(const char *file)
293 text = _load_file(file);
298 text2 = elm_entry_utf8_to_markup(text);
306 _load(Evas_Object *obj)
308 Widget_Data *wd = elm_widget_data_get(obj);
313 elm_entry_entry_set(obj, "");
318 case ELM_TEXT_FORMAT_PLAIN_UTF8:
319 text = _load_plain(wd->file);
321 case ELM_TEXT_FORMAT_MARKUP_UTF8:
322 text = _load_file(wd->file);
330 elm_entry_entry_set(obj, text);
334 elm_entry_entry_set(obj, "");
338 _save_markup_utf8(const char *file, const char *text)
342 if ((!text) || (!text[0]))
344 ecore_file_unlink(file);
347 f = fopen(file, "wb");
350 // FIXME: report a write error
353 fputs(text, f); // FIXME: catch error
358 _save_plain_utf8(const char *file, const char *text)
362 text2 = elm_entry_markup_to_utf8(text);
365 _save_markup_utf8(file, text2);
370 _save(Evas_Object *obj)
372 Widget_Data *wd = elm_widget_data_get(obj);
374 if (!wd->file) return;
377 case ELM_TEXT_FORMAT_PLAIN_UTF8:
378 _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
380 case ELM_TEXT_FORMAT_MARKUP_UTF8:
381 _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
389 _delay_write(void *data)
391 Widget_Data *wd = elm_widget_data_get(data);
392 if (!wd) return ECORE_CALLBACK_CANCEL;
394 wd->delay_write = NULL;
395 return ECORE_CALLBACK_CANCEL;
398 static Elm_Entry_Text_Filter *
399 _filter_new(void (*func) (void *data, Evas_Object *entry, char **text), void *data)
401 Elm_Entry_Text_Filter *tf = ELM_NEW(Elm_Entry_Text_Filter);
402 if (!tf) return NULL;
405 if (func == elm_entry_filter_limit_size)
407 Elm_Entry_Filter_Limit_Size *lim = data, *lim2;
414 lim2 = malloc(sizeof(Elm_Entry_Filter_Limit_Size));
420 memcpy(lim2, lim, sizeof(Elm_Entry_Filter_Limit_Size));
423 else if (func == elm_entry_filter_accept_set)
425 Elm_Entry_Filter_Accept_Set *as = data, *as2;
432 as2 = malloc(sizeof(Elm_Entry_Filter_Accept_Set));
439 as2->accepted = eina_stringshare_add(as->accepted);
441 as2->accepted = NULL;
443 as2->rejected = eina_stringshare_add(as->rejected);
445 as2->rejected = NULL;
454 _filter_free(Elm_Entry_Text_Filter *tf)
456 if (tf->func == elm_entry_filter_limit_size)
458 Elm_Entry_Filter_Limit_Size *lim = tf->data;
461 else if (tf->func == elm_entry_filter_accept_set)
463 Elm_Entry_Filter_Accept_Set *as = tf->data;
466 if (as->accepted) eina_stringshare_del(as->accepted);
467 if (as->rejected) eina_stringshare_del(as->rejected);
475 _del_pre_hook(Evas_Object *obj)
477 Widget_Data *wd = elm_widget_data_get(obj);
481 ecore_timer_del(wd->delay_write);
482 wd->delay_write = NULL;
483 if (wd->autosave) _save(obj);
488 _del_hook(Evas_Object *obj)
490 Widget_Data *wd = elm_widget_data_get(obj);
491 Elm_Entry_Context_Menu_Item *it;
492 Elm_Entry_Item_Provider *ip;
493 Elm_Entry_Text_Filter *tf;
495 if (wd->file) eina_stringshare_del(wd->file);
497 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
498 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
500 entries = eina_list_remove(entries, obj);
501 #ifdef HAVE_ELEMENTARY_X
502 ecore_event_handler_del(wd->sel_notify_handler);
503 ecore_event_handler_del(wd->sel_clear_handler);
505 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
506 if (wd->text) eina_stringshare_del(wd->text);
507 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
508 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
509 EINA_LIST_FREE(wd->items, it)
511 eina_stringshare_del(it->label);
512 eina_stringshare_del(it->icon_file);
513 eina_stringshare_del(it->icon_group);
516 EINA_LIST_FREE(wd->item_providers, ip)
520 EINA_LIST_FREE(wd->text_filters, tf)
528 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
530 Widget_Data *wd = elm_widget_data_get(obj);
531 edje_object_mirrored_set(wd->ent, rtl);
535 _theme_hook(Evas_Object *obj)
537 Widget_Data *wd = elm_widget_data_get(obj);
539 _elm_widget_mirrored_reload(obj);
540 _mirrored_set(obj, elm_widget_mirrored_get(obj));
542 t = eina_stringshare_add(elm_entry_entry_get(obj));
543 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
544 elm_entry_entry_set(obj, t);
545 eina_stringshare_del(t);
546 if (elm_widget_disabled_get(obj))
547 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
548 edje_object_message_signal_process(wd->ent);
549 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
554 _disable_hook(Evas_Object *obj)
556 Widget_Data *wd = elm_widget_data_get(obj);
558 if (elm_widget_disabled_get(obj))
560 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
561 wd->disabled = EINA_TRUE;
565 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
566 wd->disabled = EINA_FALSE;
571 _elm_win_recalc_job(void *data)
573 Widget_Data *wd = elm_widget_data_get(data);
574 Evas_Coord minw = -1, minh = -1, maxh = -1;
575 Evas_Coord resw, resh, minminw;
577 wd->deferred_recalc_job = NULL;
578 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
580 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, 0, 0);
581 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
583 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
584 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
585 evas_object_size_hint_min_set(data, minminw, minh);
586 if (wd->single_line) maxh = minh;
587 evas_object_size_hint_max_set(data, -1, maxh);
588 if (wd->deferred_cur)
589 elm_widget_show_region_set(data, wd->cx, wd->cy, wd->cw, wd->ch);
593 _sizing_eval(Evas_Object *obj)
595 Widget_Data *wd = elm_widget_data_get(obj);
596 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
597 Evas_Coord resw, resh;
599 if ((wd->linewrap) || (wd->char_linewrap))
601 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
602 if ((resw == wd->lastw) && (!wd->changed)) return;
603 wd->changed = EINA_FALSE;
605 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
606 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
610 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
611 edje_object_size_min_calc(wd->ent, &minw, &minh);
612 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
613 evas_object_size_hint_min_set(obj, minw, minh);
614 if (wd->single_line) maxh = minh;
615 evas_object_size_hint_max_set(obj, maxw, maxh);
620 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
622 Widget_Data *wd = elm_widget_data_get(obj);
623 Evas_Object *top = elm_widget_top_get(obj);
625 if (!wd->editable) return;
626 if (elm_widget_focus_get(obj))
628 evas_object_focus_set(wd->ent, EINA_TRUE);
629 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
630 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
631 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
635 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
636 evas_object_focus_set(wd->ent, EINA_FALSE);
637 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
638 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
643 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
645 Widget_Data *wd = elm_widget_data_get(obj);
647 edje_object_signal_emit(wd->ent, emission, source);
651 _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)
653 Widget_Data *wd = elm_widget_data_get(obj);
655 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
659 _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)
661 Widget_Data *wd = elm_widget_data_get(obj);
662 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
667 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
669 Widget_Data *wd = elm_widget_data_get(obj);
670 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
674 _hoversel_position(Evas_Object *obj)
676 Widget_Data *wd = elm_widget_data_get(obj);
677 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
679 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
680 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
682 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
693 evas_object_move(wd->hoversel, x + cx, y + cy);
694 evas_object_resize(wd->hoversel, cw, ch);
698 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
700 Widget_Data *wd = elm_widget_data_get(data);
702 if (wd->hoversel) _hoversel_position(data);
706 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
708 Widget_Data *wd = elm_widget_data_get(data);
710 if ((wd->linewrap) || (wd->char_linewrap))
714 if (wd->hoversel) _hoversel_position(data);
715 // Evas_Coord ww, hh;
716 // evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
720 _hover_del(void *data)
722 Widget_Data *wd = elm_widget_data_get(data);
727 evas_object_del(wd->hoversel);
730 wd->hovdeljob = NULL;
734 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
736 Widget_Data *wd = elm_widget_data_get(data);
738 if (wd->hoversel) evas_object_hide(wd->hoversel);
742 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
744 elm_widget_scroll_freeze_pop(data);
745 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
746 wd->hovdeljob = ecore_job_add(_hover_del, data);
750 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
752 Widget_Data *wd = elm_widget_data_get(data);
754 wd->selmode = EINA_TRUE;
755 edje_object_part_text_select_none(wd->ent, "elm.text");
757 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
758 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
759 elm_widget_scroll_hold_push(data);
763 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
765 Widget_Data *wd = elm_widget_data_get(data);
767 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
768 if (wd->sel_notify_handler)
770 #ifdef HAVE_ELEMENTARY_X
771 Elm_Sel_Format formats;
772 wd->selection_asked = EINA_TRUE;
773 formats = ELM_SEL_FORMAT_MARKUP;
775 formats |= ELM_SEL_FORMAT_IMAGE;
776 elm_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL);
782 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
784 Widget_Data *wd = elm_widget_data_get(obj);
788 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
789 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
790 if (seltype == ELM_SEL_CLIPBOARD)
791 eina_stringshare_replace(&wd->cut_sel, sel);
795 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
797 Widget_Data *wd = elm_widget_data_get(data);
800 wd->selmode = EINA_FALSE;
801 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
802 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
803 elm_widget_scroll_hold_pop(data);
804 _store_selection(ELM_SEL_CLIPBOARD, data);
805 edje_object_part_text_insert(wd->ent, "elm.text", "");
806 edje_object_part_text_select_none(wd->ent, "elm.text");
810 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
812 Widget_Data *wd = elm_widget_data_get(data);
814 wd->selmode = EINA_FALSE;
815 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
816 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
817 elm_widget_scroll_hold_pop(data);
818 _store_selection(ELM_SEL_CLIPBOARD, data);
819 // edje_object_part_text_select_none(wd->ent, "elm.text");
823 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
825 Widget_Data *wd = elm_widget_data_get(data);
827 wd->selmode = EINA_FALSE;
828 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
829 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
830 elm_widget_scroll_hold_pop(data);
831 edje_object_part_text_select_none(wd->ent, "elm.text");
835 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
837 Elm_Entry_Context_Menu_Item *it = data;
838 Evas_Object *obj2 = it->obj;
839 if (it->func) it->func(it->data, obj2, NULL);
843 _long_press(void *data)
845 Widget_Data *wd = elm_widget_data_get(data);
848 const Elm_Entry_Context_Menu_Item *it;
849 if (!wd) return ECORE_CALLBACK_CANCEL;
850 if ((wd->api) && (wd->api->obj_longpress))
852 wd->api->obj_longpress(data);
854 else if (wd->context_menu)
856 const char *context_menu_orientation;
858 if (wd->hoversel) evas_object_del(wd->hoversel);
859 else elm_widget_scroll_freeze_push(data);
860 wd->hoversel = elm_hoversel_add(data);
861 context_menu_orientation = edje_object_data_get
862 (wd->ent, "context_menu_orientation");
863 if ((context_menu_orientation) &&
864 (!strcmp(context_menu_orientation, "horizontal")))
865 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
866 elm_object_style_set(wd->hoversel, "entry");
867 elm_widget_sub_object_add(data, wd->hoversel);
868 elm_hoversel_label_set(wd->hoversel, "Text");
869 top = elm_widget_top_get(data);
870 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
871 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, data);
875 elm_hoversel_item_add(wd->hoversel, _("Select"), NULL, ELM_ICON_NONE,
877 if (1) // need way to detect if someone has a selection
880 elm_hoversel_item_add(wd->hoversel, _("Paste"), NULL, ELM_ICON_NONE,
888 if (wd->have_selection)
890 elm_hoversel_item_add(wd->hoversel, _("Copy"), NULL, ELM_ICON_NONE,
893 elm_hoversel_item_add(wd->hoversel, _("Cut"), NULL, ELM_ICON_NONE,
896 elm_hoversel_item_add(wd->hoversel, _("Cancel"), NULL, ELM_ICON_NONE,
900 EINA_LIST_FOREACH(wd->items, l, it)
902 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
903 it->icon_type, _item_clicked, it);
907 _hoversel_position(data);
908 evas_object_show(wd->hoversel);
909 elm_hoversel_hover_begin(wd->hoversel);
911 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
912 edje_object_part_text_select_abort(wd->ent, "elm.text");
914 wd->longpress_timer = NULL;
915 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
916 return ECORE_CALLBACK_CANCEL;
920 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
922 Widget_Data *wd = elm_widget_data_get(data);
923 Evas_Event_Mouse_Down *ev = event_info;
925 if (wd->disabled) return;
926 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
927 if (ev->button != 1) return;
928 // if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
929 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
930 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
931 wd->downx = ev->canvas.x;
932 wd->downy = ev->canvas.y;
936 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
938 Widget_Data *wd = elm_widget_data_get(data);
939 Evas_Event_Mouse_Up *ev = event_info;
941 if (wd->disabled) return;
942 if (ev->button != 1) return;
943 if (wd->longpress_timer)
945 ecore_timer_del(wd->longpress_timer);
946 wd->longpress_timer = NULL;
951 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
953 Widget_Data *wd = elm_widget_data_get(data);
954 Evas_Event_Mouse_Move *ev = event_info;
956 if (wd->disabled) return;
959 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
961 if (wd->longpress_timer)
963 ecore_timer_del(wd->longpress_timer);
964 wd->longpress_timer = NULL;
967 else if (wd->longpress_timer)
971 dx = wd->downx - ev->cur.canvas.x;
973 dy = wd->downy - ev->cur.canvas.y;
976 ((_elm_config->finger_size / 2) *
977 (_elm_config->finger_size / 2)))
979 ecore_timer_del(wd->longpress_timer);
980 wd->longpress_timer = NULL;
984 else if (wd->longpress_timer)
988 dx = wd->downx - ev->cur.canvas.x;
990 dy = wd->downy - ev->cur.canvas.y;
993 ((_elm_config->finger_size / 2) *
994 (_elm_config->finger_size / 2)))
996 ecore_timer_del(wd->longpress_timer);
997 wd->longpress_timer = NULL;
1003 _getbase(Evas_Object *obj)
1005 Widget_Data *wd = elm_widget_data_get(obj);
1006 if (!wd) return "base";
1009 if (wd->password) return "base-password";
1012 if (wd->single_line) return "base-single";
1015 if (wd->linewrap) return "base";
1016 else if (wd->char_linewrap) return "base-charwrap";
1017 else return "base-nowrap";
1023 if (wd->password) return "base-password";
1026 if (wd->single_line) return "base-single-noedit";
1029 if (wd->linewrap) return "base-noedit";
1030 else if (wd->char_linewrap) return "base-noedit-charwrap";
1031 else return "base-nowrap-noedit";
1039 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1041 Widget_Data *wd = elm_widget_data_get(data);
1043 wd->changed = EINA_TRUE;
1045 if (wd->text) eina_stringshare_del(wd->text);
1047 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1048 if (wd->delay_write)
1050 ecore_timer_del(wd->delay_write);
1051 wd->delay_write = NULL;
1053 if ((!wd->autosave) || (!wd->file)) return;
1054 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1058 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1060 Widget_Data *wd = elm_widget_data_get(data);
1064 EINA_LIST_FOREACH(entries, l, entry)
1066 if (entry != data) elm_entry_select_none(entry);
1068 wd->have_selection = EINA_TRUE;
1069 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1070 #ifdef HAVE_ELEMENTARY_X
1071 if (wd->sel_notify_handler)
1073 const char *txt = elm_entry_selection_get(data);
1076 top = elm_widget_top_get(data);
1077 if ((top) && (elm_win_xwindow_get(top)))
1078 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1084 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1086 Widget_Data *wd = elm_widget_data_get(data);
1088 wd->have_selection = EINA_TRUE;
1089 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1090 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1091 elm_entry_selection_get(data));
1095 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1097 Widget_Data *wd = elm_widget_data_get(data);
1099 if (!wd->have_selection) return;
1100 wd->have_selection = EINA_FALSE;
1101 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1102 if (wd->sel_notify_handler)
1106 #ifdef HAVE_ELEMENTARY_X
1109 top = elm_widget_top_get(data);
1110 if ((top) && (elm_win_xwindow_get(top)))
1111 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1114 eina_stringshare_del(wd->cut_sel);
1119 #ifdef HAVE_ELEMENTARY_X
1122 top = elm_widget_top_get(data);
1123 if ((top) && (elm_win_xwindow_get(top)))
1124 elm_selection_clear(ELM_SEL_PRIMARY, data);
1131 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1133 Widget_Data *wd = elm_widget_data_get(data);
1135 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1136 if (wd->sel_notify_handler)
1138 #ifdef HAVE_ELEMENTARY_X
1141 top = elm_widget_top_get(data);
1142 if ((top) && (elm_win_xwindow_get(top)))
1144 wd->selection_asked = EINA_TRUE;
1145 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
1153 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1155 Widget_Data *wd = elm_widget_data_get(data);
1157 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1158 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1159 elm_entry_selection_get(data));
1163 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1165 Widget_Data *wd = elm_widget_data_get(data);
1167 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1168 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1169 elm_entry_selection_get(data));
1170 edje_object_part_text_insert(wd->ent, "elm.text", "");
1171 wd->changed = EINA_TRUE;
1176 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1178 Widget_Data *wd = elm_widget_data_get(data);
1179 Evas_Coord cx, cy, cw, ch;
1181 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1182 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1183 &cx, &cy, &cw, &ch);
1184 if (!wd->deferred_recalc_job)
1185 elm_widget_show_region_set(data, cx, cy, cw, ch);
1188 wd->deferred_cur = EINA_TRUE;
1197 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1199 Widget_Data *wd = elm_widget_data_get(data);
1204 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1206 Widget_Data *wd = elm_widget_data_get(data);
1207 Elm_Entry_Anchor_Info ei;
1208 char *buf2, *p, *p2, *n;
1210 p = strrchr(emission, ',');
1213 const Eina_List *geoms;
1217 while (p2 >= emission)
1219 if (*p2 == ',') break;
1223 buf2 = alloca(5 + p - p2);
1224 strncpy(buf2, p2, p - p2);
1227 ei.button = atoi(buf2);
1228 ei.x = ei.y = ei.w = ei.h = 0;
1230 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1233 Evas_Textblock_Rectangle *r;
1235 Evas_Coord px, py, x, y;
1237 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1238 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1239 EINA_LIST_FOREACH(geoms, l, r)
1241 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1242 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1253 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1258 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1260 Widget_Data *wd = elm_widget_data_get(data);
1265 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1267 Widget_Data *wd = elm_widget_data_get(data);
1272 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1274 Widget_Data *wd = elm_widget_data_get(data);
1279 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1281 Widget_Data *wd = elm_widget_data_get(data);
1283 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1287 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1289 Widget_Data *wd = elm_widget_data_get(data);
1291 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1295 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1297 Widget_Data *wd = elm_widget_data_get(data);
1299 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1303 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1305 Widget_Data *wd = elm_widget_data_get(data);
1307 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1310 #ifdef HAVE_ELEMENTARY_X
1312 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1314 Widget_Data *wd = elm_widget_data_get(data);
1315 Ecore_X_Event_Selection_Notify *ev = event;
1316 if (!wd) return ECORE_CALLBACK_PASS_ON;
1317 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1318 return ECORE_CALLBACK_PASS_ON;
1320 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1321 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1323 Ecore_X_Selection_Data_Text *text_data;
1325 text_data = ev->data;
1326 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1328 if (text_data->text)
1330 char *txt = _elm_util_text_to_mkup(text_data->text);
1334 elm_entry_entry_insert(data, txt);
1339 wd->selection_asked = EINA_FALSE;
1341 else if (ev->selection == ECORE_X_SELECTION_XDND)
1343 Ecore_X_Selection_Data_Text *text_data;
1345 text_data = ev->data;
1346 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1348 if (text_data->text)
1350 char *txt = _elm_util_text_to_mkup(text_data->text);
1354 /* Massive FIXME: this should be at the drag point */
1355 elm_entry_entry_insert(data, txt);
1360 wd->drag_selection_asked = EINA_FALSE;
1362 ecore_x_dnd_send_finished();
1365 return ECORE_CALLBACK_PASS_ON;
1369 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1372 Widget_Data *wd = elm_widget_data_get(data);
1373 Ecore_X_Event_Selection_Clear *ev = event;
1374 if (!wd) return ECORE_CALLBACK_PASS_ON;
1375 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1376 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1377 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1379 elm_entry_select_none(data);
1382 return ECORE_CALLBACK_PASS_ON;
1387 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1392 wd = elm_widget_data_get(obj);
1394 if (!wd) return EINA_FALSE;
1395 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1397 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1398 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1399 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1400 EDJE_CURSOR_MAIN,drop->x,drop->y);
1401 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1402 elm_entry_entry_insert(obj, drop->data);
1403 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1404 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1410 static Evas_Object *
1411 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1413 Widget_Data *wd = elm_widget_data_get(data);
1416 Elm_Entry_Item_Provider *ip;
1418 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1420 o = ip->func(ip->data, data, item);
1423 if (!strncmp(item, "file://", 7))
1425 const char *fname = item + 7;
1427 o = evas_object_image_filled_add(evas_object_evas_get(data));
1428 evas_object_image_file_set(o, fname, NULL);
1429 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1431 evas_object_show(o);
1436 o = edje_object_add(evas_object_evas_get(data));
1437 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1441 o = edje_object_add(evas_object_evas_get(data));
1442 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1443 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1448 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
1450 Widget_Data *wd = elm_widget_data_get(data);
1452 Elm_Entry_Text_Filter *tf;
1454 if (type == EDJE_TEXT_FILTER_FORMAT)
1457 EINA_LIST_FOREACH(wd->text_filters, l, tf)
1459 tf->func(tf->data, data, text);
1466 * This adds an entry to @p parent object.
1468 * @param parent The parent object
1469 * @return The new object or NULL if it cannot be created
1474 elm_entry_add(Evas_Object *parent)
1476 Evas_Object *obj, *top;
1480 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
1482 wd = ELM_NEW(Widget_Data);
1483 e = evas_object_evas_get(parent);
1484 if (!e) return NULL;
1485 obj = elm_widget_add(e);
1486 ELM_SET_WIDTYPE(widtype, "entry");
1487 elm_widget_type_set(obj, "entry");
1488 elm_widget_sub_object_add(parent, obj);
1489 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1490 elm_widget_data_set(obj, wd);
1491 elm_widget_del_hook_set(obj, _del_hook);
1492 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1493 elm_widget_theme_hook_set(obj, _theme_hook);
1494 elm_widget_disable_hook_set(obj, _disable_hook);
1495 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1496 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
1497 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1498 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1499 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
1500 elm_widget_can_focus_set(obj, EINA_TRUE);
1501 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
1503 wd->linewrap = EINA_TRUE;
1504 wd->char_linewrap= EINA_FALSE;
1505 wd->editable = EINA_TRUE;
1506 wd->disabled = EINA_FALSE;
1507 wd->context_menu = EINA_TRUE;
1508 wd->autosave = EINA_TRUE;
1509 wd->textonly = EINA_FALSE;
1511 wd->ent = edje_object_add(e);
1512 edje_object_item_provider_set(wd->ent, _get_item, obj);
1513 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
1514 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1515 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1516 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1518 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1520 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1523 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1524 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1525 _signal_entry_changed, obj);
1526 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1527 _signal_selection_start, obj);
1528 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1529 _signal_selection_changed, obj);
1530 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1531 _signal_selection_cleared, obj);
1532 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1533 _signal_entry_paste_request, obj);
1534 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1535 _signal_entry_copy_notify, obj);
1536 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1537 _signal_entry_cut_notify, obj);
1538 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1539 _signal_cursor_changed, obj);
1540 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1541 _signal_anchor_down, obj);
1542 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1543 _signal_anchor_up, obj);
1544 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1545 _signal_anchor_move, obj);
1546 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1547 _signal_anchor_in, obj);
1548 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1549 _signal_anchor_out, obj);
1550 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
1551 _signal_key_enter, obj);
1552 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
1553 _signal_mouse_down, obj);
1554 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
1555 _signal_mouse_clicked, obj);
1556 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
1557 _signal_mouse_double, obj);
1558 edje_object_part_text_set(wd->ent, "elm.text", "");
1559 elm_widget_resize_object_set(obj, wd->ent);
1562 #ifdef HAVE_ELEMENTARY_X
1563 top = elm_widget_top_get(obj);
1564 if ((top) && (elm_win_xwindow_get(top)))
1566 wd->sel_notify_handler =
1567 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
1568 _event_selection_notify, obj);
1569 wd->sel_clear_handler =
1570 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
1571 _event_selection_clear, obj);
1574 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
1575 _drag_drop_cb, NULL);
1578 entries = eina_list_prepend(entries, obj);
1580 // module - find module for entry
1581 wd->api = _module(obj);
1582 // if found - hook in
1583 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
1585 _mirrored_set(obj, elm_widget_mirrored_get(obj));
1586 // TODO: convert Elementary to subclassing of Evas_Smart_Class
1587 // TODO: and save some bytes, making descriptions per-class and not instance!
1588 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1594 * This sets the entry object not to line wrap. All input will
1595 * be on a single line, and the entry box will extend with user input.
1597 * @param obj The entry object
1598 * @param single_line If true, the text in the entry
1599 * will be on a single line.
1604 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
1606 ELM_CHECK_WIDTYPE(obj, widtype);
1607 Widget_Data *wd = elm_widget_data_get(obj);
1610 if (wd->single_line == single_line) return;
1611 wd->single_line = single_line;
1612 wd->linewrap = EINA_FALSE;
1613 wd->char_linewrap = EINA_FALSE;
1614 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
1615 t = eina_stringshare_add(elm_entry_entry_get(obj));
1616 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1617 elm_entry_entry_set(obj, t);
1618 eina_stringshare_del(t);
1623 * This returns true if the entry has been set to single line mode.
1624 * See also elm_entry_single_line_set().
1626 * @param obj The entry object
1627 * @return single_line If true, the text in the entry is set to display
1633 elm_entry_single_line_get(const Evas_Object *obj)
1635 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1636 Widget_Data *wd = elm_widget_data_get(obj);
1637 if (!wd) return EINA_FALSE;
1638 return wd->single_line;
1642 * This sets the entry object to password mode. All text entered
1643 * and/or displayed within the widget will be replaced with asterisks (*).
1645 * @param obj The entry object
1646 * @param password If true, password mode is enabled.
1651 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
1653 ELM_CHECK_WIDTYPE(obj, widtype);
1654 Widget_Data *wd = elm_widget_data_get(obj);
1657 if (wd->password == password) return;
1658 wd->password = password;
1659 wd->single_line = EINA_TRUE;
1660 wd->linewrap = EINA_FALSE;
1661 wd->char_linewrap = EINA_FALSE;
1662 t = eina_stringshare_add(elm_entry_entry_get(obj));
1663 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1664 elm_entry_entry_set(obj, t);
1665 eina_stringshare_del(t);
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);
1836 if (wd->linewrap == wrap) return;
1837 wd->linewrap = wrap;
1839 wd->char_linewrap = EINA_FALSE;
1840 t = eina_stringshare_add(elm_entry_entry_get(obj));
1841 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1842 elm_entry_entry_set(obj, t);
1843 eina_stringshare_del(t);
1848 * This enables character line wrapping in the entry object. It is the opposite
1849 * of elm_entry_single_line_set(). Additionally, setting this disables
1850 * word line wrapping.
1851 * See also elm_entry_line_wrap_set().
1853 * @param obj The entry object
1854 * @param wrap If true, the entry will be wrapped once it reaches the end
1855 * of the object. Wrapping will occur immediately upon reaching the end of the object.
1860 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
1862 ELM_CHECK_WIDTYPE(obj, widtype);
1863 Widget_Data *wd = elm_widget_data_get(obj);
1866 if (wd->char_linewrap == wrap) return;
1867 wd->char_linewrap = wrap;
1868 if(wd->char_linewrap)
1869 wd->linewrap = EINA_FALSE;
1870 t = eina_stringshare_add(elm_entry_entry_get(obj));
1871 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1872 elm_entry_entry_set(obj, t);
1873 eina_stringshare_del(t);
1878 * This sets the editable attribute of the entry.
1880 * @param obj The entry object
1881 * @param editable If true, the entry will be editable by the user.
1882 * If false, it will be set to the disabled state.
1887 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
1889 ELM_CHECK_WIDTYPE(obj, widtype);
1890 Widget_Data *wd = elm_widget_data_get(obj);
1893 if (wd->editable == editable) return;
1894 wd->editable = editable;
1895 t = eina_stringshare_add(elm_entry_entry_get(obj));
1896 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1897 elm_entry_entry_set(obj, t);
1898 eina_stringshare_del(t);
1901 #ifdef HAVE_ELEMENTARY_X
1903 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
1905 elm_drop_target_del(obj);
1910 * This gets the editable attribute of the entry.
1911 * See also elm_entry_editable_set().
1913 * @param obj The entry object
1914 * @return If true, the entry is editable by the user.
1915 * If false, it is not editable by the user
1920 elm_entry_editable_get(const Evas_Object *obj)
1922 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1923 Widget_Data *wd = elm_widget_data_get(obj);
1924 if (!wd) return EINA_FALSE;
1925 return wd->editable;
1929 * This drops any existing text selection within the entry.
1931 * @param obj The entry object
1936 elm_entry_select_none(Evas_Object *obj)
1938 ELM_CHECK_WIDTYPE(obj, widtype);
1939 Widget_Data *wd = elm_widget_data_get(obj);
1943 wd->selmode = EINA_FALSE;
1944 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
1945 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1947 wd->have_selection = EINA_FALSE;
1948 edje_object_part_text_select_none(wd->ent, "elm.text");
1952 * This selects all text within the entry.
1954 * @param obj The entry object
1959 elm_entry_select_all(Evas_Object *obj)
1961 ELM_CHECK_WIDTYPE(obj, widtype);
1962 Widget_Data *wd = elm_widget_data_get(obj);
1966 wd->selmode = EINA_FALSE;
1967 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
1968 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1970 wd->have_selection = EINA_TRUE;
1971 edje_object_part_text_select_all(wd->ent, "elm.text");
1975 * This function returns the geometry of the cursor.
1977 * It's useful if you want to draw something on the cursor (or where it is),
1978 * or for example in the case of scrolled entry where you want to show the
1981 * @param obj The entry object
1982 * @param x returned geometry
1983 * @param y returned geometry
1984 * @param w returned geometry
1985 * @param h returned geometry
1986 * @return EINA_TRUE upon success, EINA_FALSE upon failure
1991 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1993 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1994 Widget_Data *wd = elm_widget_data_get(obj);
1995 if (!wd) return EINA_FALSE;
1996 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
2001 * This moves the cursor one place to the right within the entry.
2003 * @param obj The entry object
2004 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2009 elm_entry_cursor_next(Evas_Object *obj)
2011 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2012 Widget_Data *wd = elm_widget_data_get(obj);
2013 if (!wd) return EINA_FALSE;
2014 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2018 * This moves the cursor one place to the left within the entry.
2020 * @param obj The entry object
2021 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2026 elm_entry_cursor_prev(Evas_Object *obj)
2028 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2029 Widget_Data *wd = elm_widget_data_get(obj);
2030 if (!wd) return EINA_FALSE;
2031 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2035 * This moves the cursor one line up within the entry.
2037 * @param obj The entry object
2038 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2043 elm_entry_cursor_up(Evas_Object *obj)
2045 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2046 Widget_Data *wd = elm_widget_data_get(obj);
2047 if (!wd) return EINA_FALSE;
2048 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2052 * This moves the cursor one line down within the entry.
2054 * @param obj The entry object
2055 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2060 elm_entry_cursor_down(Evas_Object *obj)
2062 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2063 Widget_Data *wd = elm_widget_data_get(obj);
2064 if (!wd) return EINA_FALSE;
2065 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2069 * This moves the cursor to the beginning of the entry.
2071 * @param obj The entry object
2076 elm_entry_cursor_begin_set(Evas_Object *obj)
2078 ELM_CHECK_WIDTYPE(obj, widtype);
2079 Widget_Data *wd = elm_widget_data_get(obj);
2081 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2085 * This moves the cursor to the end of the entry.
2087 * @param obj The entry object
2092 elm_entry_cursor_end_set(Evas_Object *obj)
2094 ELM_CHECK_WIDTYPE(obj, widtype);
2095 Widget_Data *wd = elm_widget_data_get(obj);
2097 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2101 * This moves the cursor to the beginning of the current line.
2103 * @param obj The entry object
2108 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2110 ELM_CHECK_WIDTYPE(obj, widtype);
2111 Widget_Data *wd = elm_widget_data_get(obj);
2113 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2117 * This moves the cursor to the end of the current line.
2119 * @param obj The entry object
2124 elm_entry_cursor_line_end_set(Evas_Object *obj)
2126 ELM_CHECK_WIDTYPE(obj, widtype);
2127 Widget_Data *wd = elm_widget_data_get(obj);
2129 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2133 * This begins a selection within the entry as though
2134 * the user were holding down the mouse button to make a selection.
2136 * @param obj The entry object
2141 elm_entry_cursor_selection_begin(Evas_Object *obj)
2143 ELM_CHECK_WIDTYPE(obj, widtype);
2144 Widget_Data *wd = elm_widget_data_get(obj);
2146 edje_object_part_text_select_begin(wd->ent, "elm.text");
2150 * This ends a selection within the entry as though
2151 * the user had just released the mouse button while making a selection.
2153 * @param obj The entry object
2158 elm_entry_cursor_selection_end(Evas_Object *obj)
2160 ELM_CHECK_WIDTYPE(obj, widtype);
2161 Widget_Data *wd = elm_widget_data_get(obj);
2163 edje_object_part_text_select_extend(wd->ent, "elm.text");
2167 * TODO: fill this in
2169 * @param obj The entry object
2170 * @return TODO: fill this in
2175 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2177 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2178 Widget_Data *wd = elm_widget_data_get(obj);
2179 if (!wd) return EINA_FALSE;
2180 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2184 * This returns whether the cursor is visible.
2186 * @param obj The entry object
2187 * @return If true, the cursor is visible.
2192 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2194 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2195 Widget_Data *wd = elm_widget_data_get(obj);
2196 if (!wd) return EINA_FALSE;
2197 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2201 * TODO: fill this in
2203 * @param obj The entry object
2204 * @return TODO: fill this in
2209 elm_entry_cursor_content_get(const Evas_Object *obj)
2211 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2212 Widget_Data *wd = elm_widget_data_get(obj);
2213 if (!wd) return NULL;
2214 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2218 * Sets the cursor position in the entry to the given value
2220 * @param obj The entry object
2221 * @param pos The position of the cursor
2226 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
2228 ELM_CHECK_WIDTYPE(obj, widtype);
2229 Widget_Data *wd = elm_widget_data_get(obj);
2231 edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
2235 * Retrieves the current position of the cursor in the entry
2237 * @param obj The entry object
2238 * @return The cursor position
2243 elm_entry_cursor_pos_get(const Evas_Object *obj)
2245 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2246 Widget_Data *wd = elm_widget_data_get(obj);
2248 return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2252 * This executes a "cut" action on the selected text in the entry.
2254 * @param obj The entry object
2259 elm_entry_selection_cut(Evas_Object *obj)
2261 ELM_CHECK_WIDTYPE(obj, widtype);
2262 Widget_Data *wd = elm_widget_data_get(obj);
2264 _cut(obj, NULL, NULL);
2268 * This executes a "copy" action on the selected text in the entry.
2270 * @param obj The entry object
2275 elm_entry_selection_copy(Evas_Object *obj)
2277 ELM_CHECK_WIDTYPE(obj, widtype);
2278 Widget_Data *wd = elm_widget_data_get(obj);
2280 _copy(obj, NULL, NULL);
2284 * This executes a "paste" action in the entry.
2286 * @param obj The entry object
2291 elm_entry_selection_paste(Evas_Object *obj)
2293 ELM_CHECK_WIDTYPE(obj, widtype);
2294 Widget_Data *wd = elm_widget_data_get(obj);
2296 _paste(obj, NULL, NULL);
2300 * This clears and frees the items in a entry's contextual (right click) menu.
2302 * @param obj The entry object
2307 elm_entry_context_menu_clear(Evas_Object *obj)
2309 ELM_CHECK_WIDTYPE(obj, widtype);
2310 Widget_Data *wd = elm_widget_data_get(obj);
2311 Elm_Entry_Context_Menu_Item *it;
2313 EINA_LIST_FREE(wd->items, it)
2315 eina_stringshare_del(it->label);
2316 eina_stringshare_del(it->icon_file);
2317 eina_stringshare_del(it->icon_group);
2323 * This adds an item to the entry's contextual menu.
2325 * @param obj The entry object
2326 * @param label The item's text label
2327 * @param icon_file The item's icon file
2328 * @param icon_type The item's icon type
2329 * @param func The callback to execute when the item is clicked
2330 * @param data The data to associate with the item for related functions
2335 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)
2337 ELM_CHECK_WIDTYPE(obj, widtype);
2338 Widget_Data *wd = elm_widget_data_get(obj);
2339 Elm_Entry_Context_Menu_Item *it;
2341 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2343 wd->items = eina_list_append(wd->items, it);
2345 it->label = eina_stringshare_add(label);
2346 it->icon_file = eina_stringshare_add(icon_file);
2347 it->icon_type = icon_type;
2349 it->data = (void *)data;
2353 * This disables the entry's contextual (right click) menu.
2355 * @param obj The entry object
2356 * @param disabled If true, the menu is disabled
2361 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2363 ELM_CHECK_WIDTYPE(obj, widtype);
2364 Widget_Data *wd = elm_widget_data_get(obj);
2366 if (wd->context_menu == !disabled) return;
2367 wd->context_menu = !disabled;
2371 * This returns whether the entry's contextual (right click) menu is disabled.
2373 * @param obj The entry object
2374 * @return If true, the menu is disabled
2379 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2381 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2382 Widget_Data *wd = elm_widget_data_get(obj);
2383 if (!wd) return EINA_FALSE;
2384 return !wd->context_menu;
2388 * This appends a custom item provider to the list for that entry
2390 * This appends the given callback. The list is walked from beginning to end
2391 * with each function called given the item href string in the text. If the
2392 * function returns an object handle other than NULL (it should create an
2393 * and object to do this), then this object is used to replace that item. If
2394 * not the next provider is called until one provides an item object, or the
2395 * default provider in entry does.
2397 * @param obj The entry object
2398 * @param func The function called to provide the item object
2399 * @param data The data passed to @p func
2404 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2406 ELM_CHECK_WIDTYPE(obj, widtype);
2407 Widget_Data *wd = elm_widget_data_get(obj);
2409 EINA_SAFETY_ON_NULL_RETURN(func);
2410 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2414 wd->item_providers = eina_list_append(wd->item_providers, ip);
2418 * This prepends a custom item provider to the list for that entry
2420 * This prepends the given callback. See elm_entry_item_provider_append() for
2423 * @param obj The entry object
2424 * @param func The function called to provide the item object
2425 * @param data The data passed to @p func
2430 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2432 ELM_CHECK_WIDTYPE(obj, widtype);
2433 Widget_Data *wd = elm_widget_data_get(obj);
2435 EINA_SAFETY_ON_NULL_RETURN(func);
2436 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2440 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2444 * This removes a custom item provider to the list for that entry
2446 * This removes the given callback. See elm_entry_item_provider_append() for
2449 * @param obj The entry object
2450 * @param func The function called to provide the item object
2451 * @param data The data passed to @p func
2456 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2458 ELM_CHECK_WIDTYPE(obj, widtype);
2459 Widget_Data *wd = elm_widget_data_get(obj);
2461 Elm_Entry_Item_Provider *ip;
2463 EINA_SAFETY_ON_NULL_RETURN(func);
2464 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2466 if ((ip->func == func) && ((!data) || (ip->data == data)))
2468 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2476 * Append a filter function for text inserted in the entry
2478 * Append the given callback to the list. This functions will be called
2479 * whenever any text is inserted into the entry, with the text to be inserted
2480 * as a parameter. The callback function is free to alter the text in any way
2481 * it wants, but it must remember to free the given pointer and update it.
2482 * If the new text is to be discarded, the function can free it and set it text
2483 * parameter to NULL. This will also prevent any following filters from being
2486 * @param obj The entry object
2487 * @param func The function to use as text filter
2488 * @param data User data to pass to @p func
2493 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2496 Elm_Entry_Text_Filter *tf;
2497 ELM_CHECK_WIDTYPE(obj, widtype);
2499 wd = elm_widget_data_get(obj);
2501 EINA_SAFETY_ON_NULL_RETURN(func);
2503 tf = _filter_new(func, data);
2506 wd->text_filters = eina_list_append(wd->text_filters, tf);
2510 * Prepend a filter function for text insdrted in the entry
2512 * Prepend the given callback to the list. See elm_entry_text_filter_append()
2513 * for more information
2515 * @param obj The entry object
2516 * @param func The function to use as text filter
2517 * @param data User data to pass to @p func
2522 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2525 Elm_Entry_Text_Filter *tf;
2526 ELM_CHECK_WIDTYPE(obj, widtype);
2528 wd = elm_widget_data_get(obj);
2530 EINA_SAFETY_ON_NULL_RETURN(func);
2532 tf = _filter_new(func, data);
2535 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
2539 * Remove a filter from the list
2541 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
2542 * for more information.
2544 * @param obj The entry object
2545 * @param func The filter function to remove
2546 * @param data The user data passed when adding the function
2551 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2555 Elm_Entry_Text_Filter *tf;
2556 ELM_CHECK_WIDTYPE(obj, widtype);
2558 wd = elm_widget_data_get(obj);
2560 EINA_SAFETY_ON_NULL_RETURN(func);
2562 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2564 if ((tf->func == func) && ((!data) || (tf->data == data)))
2566 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
2574 * This converts a markup (HTML-like) string into UTF-8.
2576 * @param s The string (in markup) to be converted
2577 * @return The converted string (in UTF-8)
2582 elm_entry_markup_to_utf8(const char *s)
2584 char *ss = _elm_util_mkup_to_text(s);
2585 if (!ss) ss = strdup("");
2590 * This converts a UTF-8 string into markup (HTML-like).
2592 * @param s The string (in UTF-8) to be converted
2593 * @return The converted string (in markup)
2598 elm_entry_utf8_to_markup(const char *s)
2600 char *ss = _elm_util_text_to_mkup(s);
2601 if (!ss) ss = strdup("");
2606 * Filter inserted text based on user defined character and byte limits
2608 * Add this filter to an entry to limit the characters that it will accept
2609 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
2610 * The funtion works on the UTF-8 representation of the string, converting
2611 * it from the set markup, thus not accounting for any format in it.
2613 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
2614 * it as data when setting the filter. In it it's possible to set limits
2615 * by character count or bytes (any of them is disabled if 0), and both can
2616 * be set at the same time. In that case, it first checks for characters,
2619 * The function will cut the inserted text in order to allow only the first
2620 * number of characters that are still allowed. The cut is made in
2621 * characters, even when limiting by bytes, in order to always contain
2622 * valid ones and avoid half unicode characters making it in.
2627 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
2629 Elm_Entry_Filter_Limit_Size *lim = data;
2632 const char *(*text_get)(const Evas_Object *);
2633 const char *widget_type;
2635 EINA_SAFETY_ON_NULL_RETURN(data);
2636 EINA_SAFETY_ON_NULL_RETURN(entry);
2637 EINA_SAFETY_ON_NULL_RETURN(text);
2639 /* hack. I don't want to copy the entire function to work with
2641 widget_type = elm_widget_type_get(entry);
2642 if (!strcmp(widget_type, "entry"))
2643 text_get = elm_entry_entry_get;
2644 else if (!strcmp(widget_type, "scrolled_entry"))
2645 text_get = elm_scrolled_entry_entry_get;
2649 current = elm_entry_markup_to_utf8(text_get(entry));
2651 if (lim->max_char_count > 0)
2654 len = evas_string_char_len_get(current);
2655 if (len >= lim->max_char_count)
2662 newlen = evas_string_char_len_get(*text);
2663 cut = strlen(*text);
2664 while ((len + newlen) > lim->max_char_count)
2666 cut = evas_string_char_prev_get(*text, cut, NULL);
2672 if (lim->max_byte_count > 0)
2674 len = strlen(current);
2675 if (len >= lim->max_byte_count)
2682 newlen = strlen(*text);
2683 while ((len + newlen) > lim->max_byte_count)
2685 int p = evas_string_char_prev_get(*text, newlen, NULL);
2686 newlen -= (newlen - p);
2689 (*text)[newlen] = 0;
2700 * Filter inserted text based on accepted or rejected sets of characters
2702 * Add this filter to an entry to restrict the set of accepted characters
2703 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
2704 * This structure contains both accepted and rejected sets, but they are
2705 * mutually exclusive. If accepted is set, it will be used, otherwise it
2706 * goes on to the rejected set.
2709 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
2711 Elm_Entry_Filter_Accept_Set *as = data;
2715 int read_idx, last_read_idx = 0, read_char;
2717 EINA_SAFETY_ON_NULL_RETURN(data);
2718 EINA_SAFETY_ON_NULL_RETURN(text);
2720 if ((!as->accepted) && (!as->rejected))
2726 goes_in = EINA_TRUE;
2731 goes_in = EINA_FALSE;
2735 read_idx = evas_string_char_next_get(*text, 0, &read_char);
2738 int cmp_idx, cmp_char;
2739 Eina_Bool in_set = EINA_FALSE;
2741 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
2744 if (read_char == cmp_char)
2749 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
2751 if (in_set == goes_in)
2753 int size = read_idx - last_read_idx;
2754 const char *src = (*text) + last_read_idx;
2756 memcpy(insert, *text + last_read_idx, size);
2759 last_read_idx = read_idx;
2760 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
2766 * This sets the file (and implicitly loads it) for the text to display and
2767 * then edit. All changes are written back to the file after a short delay if
2768 * the entry object is set to autosave.
2770 * @param obj The entry object
2771 * @param file The path to the file to load and save
2772 * @param format The file format
2777 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
2779 ELM_CHECK_WIDTYPE(obj, widtype);
2780 Widget_Data *wd = elm_widget_data_get(obj);
2782 if (wd->delay_write)
2784 ecore_timer_del(wd->delay_write);
2785 wd->delay_write = NULL;
2787 if (wd->autosave) _save(obj);
2788 eina_stringshare_replace(&wd->file, file);
2789 wd->format = format;
2794 * Gets the file to load and save and the file format
2796 * @param obj The entry object
2797 * @param file The path to the file to load and save
2798 * @param format The file format
2803 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
2805 ELM_CHECK_WIDTYPE(obj, widtype);
2806 Widget_Data *wd = elm_widget_data_get(obj);
2808 if (file) *file = wd->file;
2809 if (format) *format = wd->format;
2813 * This function writes any changes made to the file set with
2814 * elm_entry_file_set()
2816 * @param obj The entry object
2821 elm_entry_file_save(Evas_Object *obj)
2823 ELM_CHECK_WIDTYPE(obj, widtype);
2824 Widget_Data *wd = elm_widget_data_get(obj);
2826 if (wd->delay_write)
2828 ecore_timer_del(wd->delay_write);
2829 wd->delay_write = NULL;
2832 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
2836 * This sets the entry object to 'autosave' the loaded text file or not.
2838 * @param obj The entry object
2839 * @param autosave Autosave the loaded file or not
2844 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
2846 ELM_CHECK_WIDTYPE(obj, widtype);
2847 Widget_Data *wd = elm_widget_data_get(obj);
2849 wd->autosave = !!autosave;
2853 * This gets the entry object's 'autosave' status.
2855 * @param obj The entry object
2856 * @return Autosave the loaded file or not
2861 elm_entry_autosave_get(const Evas_Object *obj)
2863 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2864 Widget_Data *wd = elm_widget_data_get(obj);
2865 if (!wd) return EINA_FALSE;
2866 return wd->autosave;
2871 * Control pasting of text and images for the widget.
2873 * Normally the entry allows both text and images to be pasted. By setting
2874 * textonly to be true, this prevents images from being pasted.
2876 * Note this only changes the behaviour of text.
2878 * @param obj The entry object
2879 * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is text+image+other.
2884 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
2886 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
2887 ELM_CHECK_WIDTYPE(obj, widtype);
2888 Widget_Data *wd = elm_widget_data_get(obj);
2890 textonly = !!textonly;
2891 if (wd->textonly == textonly) return;
2892 wd->textonly = !!textonly;
2893 if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
2894 #ifdef HAVE_ELEMENTARY_X
2895 elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
2900 * Getting elm_entry text paste/drop mode.
2902 * In textonly mode, only text may be pasted or dropped into the widget.
2904 * @param obj The entry object
2905 * @return If the widget only accepts text from pastes.
2910 elm_entry_cnp_textonly_get(Evas_Object *obj)
2912 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2913 Widget_Data *wd = elm_widget_data_get(obj);
2914 if (!wd) return EINA_FALSE;
2915 return wd->textonly;