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:
77 * "changed" - The text within the entry was changed
78 * "activated" - The entry has had editing finished and changes are to be committed
79 (generally when enter key is pressed)
80 * "press" - The entry has been clicked
81 * "longpressed" - The entry has been clicked for a couple seconds
82 * "clicked" - The entry has been clicked
83 * "clicked,double" - The entry has been double clicked
84 * "focused" - The entry has received focus
85 * "unfocused" - The entry has lost focus
86 * "selection,paste" - A paste action has occurred
87 * "selection,copy" - A copy action has occurred
88 * "selection,cut" - A cut action has occurred
89 * "selection,start" - A selection has begun
90 * "selection,changed" - The selection has changed
91 * "selection,cleared" - The selection has been cleared
92 * "cursor,changed" - The cursor has changed
93 * "anchor,clicked" - The anchor has been clicked
96 typedef struct _Mod_Api Mod_Api;
98 typedef struct _Widget_Data Widget_Data;
99 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
100 typedef struct _Elm_Entry_Item_Provider Elm_Entry_Item_Provider;
101 typedef struct _Elm_Entry_Text_Filter Elm_Entry_Text_Filter;
106 Evas_Object *hoversel;
107 Ecore_Job *deferred_recalc_job;
108 Ecore_Event_Handler *sel_notify_handler;
109 Ecore_Event_Handler *sel_clear_handler;
110 Ecore_Timer *longpress_timer;
111 Ecore_Timer *delay_write;
112 /* Only for clipboard */
116 Elm_Text_Format format;
118 Evas_Coord downx, downy;
120 Eina_List *item_providers;
121 Eina_List *text_filters;
122 Ecore_Job *hovdeljob;
123 Mod_Api *api; // module api if supplied
125 Eina_Bool changed : 1;
126 Eina_Bool linewrap : 1;
127 Eina_Bool char_linewrap : 1;
128 Eina_Bool single_line : 1;
129 Eina_Bool password : 1;
130 Eina_Bool editable : 1;
131 Eina_Bool selection_asked : 1;
132 Eina_Bool have_selection : 1;
133 Eina_Bool selmode : 1;
134 Eina_Bool deferred_cur : 1;
135 Eina_Bool disabled : 1;
136 Eina_Bool context_menu : 1;
137 Eina_Bool drag_selection_asked : 1;
138 Eina_Bool can_write : 1;
139 Eina_Bool autosave : 1;
140 Eina_Bool textonly : 1;
141 Eina_Bool usedown : 1;
144 struct _Elm_Entry_Context_Menu_Item
148 const char *icon_file;
149 const char *icon_group;
150 Elm_Icon_Type icon_type;
155 struct _Elm_Entry_Item_Provider
157 Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
161 struct _Elm_Entry_Text_Filter
163 void (*func) (void *data, Evas_Object *entry, char **text);
167 static const char *widtype = NULL;
169 #ifdef HAVE_ELEMENTARY_X
170 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
172 static void _del_hook(Evas_Object *obj);
173 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
174 static void _theme_hook(Evas_Object *obj);
175 static void _disable_hook(Evas_Object *obj);
176 static void _sizing_eval(Evas_Object *obj);
177 static void _on_focus_hook(void *data, Evas_Object *obj);
178 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
179 static const char *_getbase(Evas_Object *obj);
180 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
181 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
182 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
183 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
184 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
185 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
186 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
187 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
189 static const char SIG_CHANGED[] = "changed";
190 static const char SIG_ACTIVATED[] = "activated";
191 static const char SIG_PRESS[] = "press";
192 static const char SIG_LONGPRESSED[] = "longpressed";
193 static const char SIG_CLICKED[] = "clicked";
194 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
195 static const char SIG_FOCUSED[] = "focused";
196 static const char SIG_UNFOCUSED[] = "unfocused";
197 static const char SIG_SELECTION_PASTE[] = "selection,paste";
198 static const char SIG_SELECTION_COPY[] = "selection,copy";
199 static const char SIG_SELECTION_CUT[] = "selection,cut";
200 static const char SIG_SELECTION_START[] = "selection,start";
201 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
202 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
203 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
204 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
205 static const Evas_Smart_Cb_Description _signals[] = {
209 {SIG_LONGPRESSED, ""},
211 {SIG_CLICKED_DOUBLE, ""},
214 {SIG_SELECTION_PASTE, ""},
215 {SIG_SELECTION_COPY, ""},
216 {SIG_SELECTION_CUT, ""},
217 {SIG_SELECTION_START, ""},
218 {SIG_SELECTION_CHANGED, ""},
219 {SIG_SELECTION_CLEARED, ""},
220 {SIG_CURSOR_CHANGED, ""},
221 {SIG_ANCHOR_CLICKED, ""},
225 static Eina_List *entries = NULL;
229 void (*obj_hook) (Evas_Object *obj);
230 void (*obj_unhook) (Evas_Object *obj);
231 void (*obj_longpress) (Evas_Object *obj);
235 _module(Evas_Object *obj __UNUSED__)
237 static Elm_Module *m = NULL;
238 if (m) goto ok; // already found - just use
239 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
241 m->api = malloc(sizeof(Mod_Api));
242 if (!m->api) return NULL;
243 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
244 _elm_module_symbol_get(m, "obj_hook");
245 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
246 _elm_module_symbol_get(m, "obj_unhook");
247 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
248 _elm_module_symbol_get(m, "obj_longpress");
249 ok: // ok - return api
254 _buf_append(char *buf, const char *str, int *len, int *alloc)
256 int len2 = strlen(str);
257 if ((*len + len2) >= *alloc)
259 char *buf2 = realloc(buf, *alloc + len2 + 512);
260 if (!buf2) return NULL;
262 *alloc += (512 + len2);
264 strcpy(buf + *len, str);
270 _load_file(const char *file)
274 int alloc = 0, len = 0;
275 char *text = NULL, buf[16384 + 1];
277 f = fopen(file, "rb");
279 while ((size = fread(buf, 1, sizeof(buf) - 1, f)))
283 tmp_text = _buf_append(text, buf, &len, &alloc);
284 if (!tmp_text) break;
292 _load_plain(const char *file)
296 text = _load_file(file);
301 text2 = elm_entry_utf8_to_markup(text);
309 _load(Evas_Object *obj)
311 Widget_Data *wd = elm_widget_data_get(obj);
316 elm_entry_entry_set(obj, "");
321 case ELM_TEXT_FORMAT_PLAIN_UTF8:
322 text = _load_plain(wd->file);
324 case ELM_TEXT_FORMAT_MARKUP_UTF8:
325 text = _load_file(wd->file);
333 elm_entry_entry_set(obj, text);
337 elm_entry_entry_set(obj, "");
341 _save_markup_utf8(const char *file, const char *text)
345 if ((!text) || (!text[0]))
347 ecore_file_unlink(file);
350 f = fopen(file, "wb");
353 // FIXME: report a write error
356 fputs(text, f); // FIXME: catch error
361 _save_plain_utf8(const char *file, const char *text)
365 text2 = elm_entry_markup_to_utf8(text);
368 _save_markup_utf8(file, text2);
373 _save(Evas_Object *obj)
375 Widget_Data *wd = elm_widget_data_get(obj);
377 if (!wd->file) return;
380 case ELM_TEXT_FORMAT_PLAIN_UTF8:
381 _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
383 case ELM_TEXT_FORMAT_MARKUP_UTF8:
384 _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
392 _delay_write(void *data)
394 Widget_Data *wd = elm_widget_data_get(data);
395 if (!wd) return ECORE_CALLBACK_CANCEL;
397 wd->delay_write = NULL;
398 return ECORE_CALLBACK_CANCEL;
401 static Elm_Entry_Text_Filter *
402 _filter_new(void (*func) (void *data, Evas_Object *entry, char **text), void *data)
404 Elm_Entry_Text_Filter *tf = ELM_NEW(Elm_Entry_Text_Filter);
405 if (!tf) return NULL;
408 if (func == elm_entry_filter_limit_size)
410 Elm_Entry_Filter_Limit_Size *lim = data, *lim2;
417 lim2 = malloc(sizeof(Elm_Entry_Filter_Limit_Size));
423 memcpy(lim2, lim, sizeof(Elm_Entry_Filter_Limit_Size));
426 else if (func == elm_entry_filter_accept_set)
428 Elm_Entry_Filter_Accept_Set *as = data, *as2;
435 as2 = malloc(sizeof(Elm_Entry_Filter_Accept_Set));
442 as2->accepted = eina_stringshare_add(as->accepted);
444 as2->accepted = NULL;
446 as2->rejected = eina_stringshare_add(as->rejected);
448 as2->rejected = NULL;
457 _filter_free(Elm_Entry_Text_Filter *tf)
459 if (tf->func == elm_entry_filter_limit_size)
461 Elm_Entry_Filter_Limit_Size *lim = tf->data;
464 else if (tf->func == elm_entry_filter_accept_set)
466 Elm_Entry_Filter_Accept_Set *as = tf->data;
469 if (as->accepted) eina_stringshare_del(as->accepted);
470 if (as->rejected) eina_stringshare_del(as->rejected);
478 _del_pre_hook(Evas_Object *obj)
480 Widget_Data *wd = elm_widget_data_get(obj);
484 ecore_timer_del(wd->delay_write);
485 wd->delay_write = NULL;
486 if (wd->autosave) _save(obj);
491 _del_hook(Evas_Object *obj)
493 Widget_Data *wd = elm_widget_data_get(obj);
494 Elm_Entry_Context_Menu_Item *it;
495 Elm_Entry_Item_Provider *ip;
496 Elm_Entry_Text_Filter *tf;
498 if (wd->file) eina_stringshare_del(wd->file);
500 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
501 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
503 entries = eina_list_remove(entries, obj);
504 #ifdef HAVE_ELEMENTARY_X
505 if (wd->sel_notify_handler)
506 ecore_event_handler_del(wd->sel_notify_handler);
507 if (wd->sel_clear_handler)
508 ecore_event_handler_del(wd->sel_clear_handler);
510 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
511 if (wd->text) eina_stringshare_del(wd->text);
512 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
513 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
514 EINA_LIST_FREE(wd->items, it)
516 eina_stringshare_del(it->label);
517 eina_stringshare_del(it->icon_file);
518 eina_stringshare_del(it->icon_group);
521 EINA_LIST_FREE(wd->item_providers, ip)
525 EINA_LIST_FREE(wd->text_filters, tf)
533 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
535 Widget_Data *wd = elm_widget_data_get(obj);
536 edje_object_mirrored_set(wd->ent, rtl);
540 _theme_hook(Evas_Object *obj)
542 Widget_Data *wd = elm_widget_data_get(obj);
544 _elm_widget_mirrored_reload(obj);
545 _mirrored_set(obj, elm_widget_mirrored_get(obj));
547 t = eina_stringshare_add(elm_entry_entry_get(obj));
548 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
549 if (_elm_config->desktop_entry)
550 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
551 elm_entry_entry_set(obj, t);
552 eina_stringshare_del(t);
553 if (elm_widget_disabled_get(obj))
554 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
555 elm_entry_cursor_pos_set(obj, wd->cursor_pos);
556 if (elm_widget_focus_get(obj))
557 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
558 edje_object_message_signal_process(wd->ent);
559 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
564 _disable_hook(Evas_Object *obj)
566 Widget_Data *wd = elm_widget_data_get(obj);
568 if (elm_widget_disabled_get(obj))
570 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
571 wd->disabled = EINA_TRUE;
575 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
576 wd->disabled = EINA_FALSE;
581 _elm_win_recalc_job(void *data)
583 Widget_Data *wd = elm_widget_data_get(data);
584 Evas_Coord minh = -1, resw = -1, minw = -1;
586 wd->deferred_recalc_job = NULL;
588 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, NULL);
589 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
590 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
591 /* This is a hack to workaround the way min size hints are treated.
592 * If the minimum width is smaller than the restricted width, it means
593 * the mininmum doesn't matter. */
596 Evas_Coord ominw = -1;
597 evas_object_size_hint_min_get(data, &ominw, NULL);
600 evas_object_size_hint_min_set(data, minw, minh);
602 evas_object_size_hint_max_set(data, minw, minh);
604 if (wd->deferred_cur)
606 Evas_Coord cx, cy, cw, ch;
607 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
609 elm_widget_show_region_set(data, cx, cy, cw, ch);
614 _sizing_eval(Evas_Object *obj)
616 Widget_Data *wd = elm_widget_data_get(obj);
617 Evas_Coord minw = -1, minh = -1;
618 Evas_Coord resw, resh;
620 if ((wd->linewrap) || (wd->char_linewrap))
622 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
623 if ((resw == wd->lastw) && (!wd->changed)) return;
624 wd->changed = EINA_FALSE;
626 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
627 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
631 edje_object_size_min_calc(wd->ent, &minw, &minh);
632 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
633 evas_object_size_hint_min_set(obj, minw, minh);
635 evas_object_size_hint_max_set(obj, -1, minh);
640 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
642 Widget_Data *wd = elm_widget_data_get(obj);
643 Evas_Object *top = elm_widget_top_get(obj);
645 if (!wd->editable) return;
646 if (elm_widget_focus_get(obj))
648 evas_object_focus_set(wd->ent, EINA_TRUE);
649 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
650 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
651 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
655 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
656 evas_object_focus_set(wd->ent, EINA_FALSE);
657 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
658 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
663 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
665 Widget_Data *wd = elm_widget_data_get(obj);
667 edje_object_signal_emit(wd->ent, emission, source);
671 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
673 Widget_Data *wd = elm_widget_data_get(obj);
675 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
679 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
681 Widget_Data *wd = elm_widget_data_get(obj);
682 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
687 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
689 Widget_Data *wd = elm_widget_data_get(obj);
690 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
694 _hoversel_position(Evas_Object *obj)
696 Widget_Data *wd = elm_widget_data_get(obj);
697 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
702 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
711 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
713 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
724 evas_object_move(wd->hoversel, x + cx, y + cy);
725 evas_object_resize(wd->hoversel, cw, ch);
729 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
731 Widget_Data *wd = elm_widget_data_get(data);
733 if (wd->hoversel) _hoversel_position(data);
737 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
739 Widget_Data *wd = elm_widget_data_get(data);
741 if ((wd->linewrap) || (wd->char_linewrap))
745 if (wd->hoversel) _hoversel_position(data);
746 // Evas_Coord ww, hh;
747 // evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
751 _hover_del(void *data)
753 Widget_Data *wd = elm_widget_data_get(data);
758 evas_object_del(wd->hoversel);
761 wd->hovdeljob = NULL;
765 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
767 Widget_Data *wd = elm_widget_data_get(data);
770 if (wd->hoversel) evas_object_hide(wd->hoversel);
773 if (!_elm_config->desktop_entry)
776 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
779 elm_widget_scroll_freeze_pop(data);
780 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
781 wd->hovdeljob = ecore_job_add(_hover_del, data);
785 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
787 Widget_Data *wd = elm_widget_data_get(data);
789 wd->selmode = EINA_TRUE;
790 edje_object_part_text_select_none(wd->ent, "elm.text");
791 if (!_elm_config->desktop_entry)
794 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
796 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
797 if (!_elm_config->desktop_entry)
798 elm_widget_scroll_hold_push(data);
802 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
804 Widget_Data *wd = elm_widget_data_get(data);
806 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
807 if (wd->sel_notify_handler)
809 #ifdef HAVE_ELEMENTARY_X
810 Elm_Sel_Format formats;
811 wd->selection_asked = EINA_TRUE;
812 formats = ELM_SEL_FORMAT_MARKUP;
814 formats |= ELM_SEL_FORMAT_IMAGE;
815 elm_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL);
821 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
823 Widget_Data *wd = elm_widget_data_get(obj);
827 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
828 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
829 if (seltype == ELM_SEL_CLIPBOARD)
830 eina_stringshare_replace(&wd->cut_sel, sel);
834 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
836 Widget_Data *wd = elm_widget_data_get(data);
839 wd->selmode = EINA_FALSE;
840 if (!_elm_config->desktop_entry)
841 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
842 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
843 if (!_elm_config->desktop_entry)
844 elm_widget_scroll_hold_pop(data);
845 _store_selection(ELM_SEL_CLIPBOARD, data);
846 edje_object_part_text_insert(wd->ent, "elm.text", "");
847 edje_object_part_text_select_none(wd->ent, "elm.text");
851 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
853 Widget_Data *wd = elm_widget_data_get(data);
855 wd->selmode = EINA_FALSE;
856 if (!_elm_config->desktop_entry)
858 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
859 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
860 elm_widget_scroll_hold_pop(data);
862 _store_selection(ELM_SEL_CLIPBOARD, data);
863 // edje_object_part_text_select_none(wd->ent, "elm.text");
867 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
869 Widget_Data *wd = elm_widget_data_get(data);
871 wd->selmode = EINA_FALSE;
872 if (!_elm_config->desktop_entry)
873 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
874 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
875 if (!_elm_config->desktop_entry)
876 elm_widget_scroll_hold_pop(data);
877 edje_object_part_text_select_none(wd->ent, "elm.text");
881 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
883 Elm_Entry_Context_Menu_Item *it = data;
884 Evas_Object *obj2 = it->obj;
885 if (it->func) it->func(it->data, obj2, NULL);
889 _menu_press(Evas_Object *obj)
891 Widget_Data *wd = elm_widget_data_get(obj);
894 const Elm_Entry_Context_Menu_Item *it;
896 if ((wd->api) && (wd->api->obj_longpress))
898 wd->api->obj_longpress(obj);
900 else if (wd->context_menu)
902 const char *context_menu_orientation;
904 if (wd->hoversel) evas_object_del(wd->hoversel);
905 else elm_widget_scroll_freeze_push(obj);
906 wd->hoversel = elm_hoversel_add(obj);
907 context_menu_orientation = edje_object_data_get
908 (wd->ent, "context_menu_orientation");
909 if ((context_menu_orientation) &&
910 (!strcmp(context_menu_orientation, "horizontal")))
911 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
912 elm_object_style_set(wd->hoversel, "entry");
913 elm_widget_sub_object_add(obj, wd->hoversel);
914 elm_hoversel_label_set(wd->hoversel, "Text");
915 top = elm_widget_top_get(obj);
916 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
917 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, obj);
918 if (wd->have_selection)
922 if (wd->have_selection)
924 elm_hoversel_item_add(wd->hoversel, E_("Copy"), NULL, ELM_ICON_NONE,
927 elm_hoversel_item_add(wd->hoversel, E_("Cut"), NULL, ELM_ICON_NONE,
930 elm_hoversel_item_add(wd->hoversel, E_("Cancel"), NULL, ELM_ICON_NONE,
938 if (!_elm_config->desktop_entry)
941 elm_hoversel_item_add(wd->hoversel, E_("Select"), NULL, ELM_ICON_NONE,
944 if (1) // need way to detect if someone has a selection
947 elm_hoversel_item_add(wd->hoversel, E_("Paste"), NULL, ELM_ICON_NONE,
952 EINA_LIST_FOREACH(wd->items, l, it)
954 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
955 it->icon_type, _item_clicked, it);
959 _hoversel_position(obj);
960 evas_object_show(wd->hoversel);
961 elm_hoversel_hover_begin(wd->hoversel);
963 if (!_elm_config->desktop_entry)
965 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
966 edje_object_part_text_select_abort(wd->ent, "elm.text");
972 _long_press(void *data)
974 Widget_Data *wd = elm_widget_data_get(data);
975 if (!wd) return ECORE_CALLBACK_CANCEL;
977 wd->longpress_timer = NULL;
978 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
979 return ECORE_CALLBACK_CANCEL;
983 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
985 Widget_Data *wd = elm_widget_data_get(data);
986 Evas_Event_Mouse_Down *ev = event_info;
988 if (wd->disabled) return;
989 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
990 wd->downx = ev->canvas.x;
991 wd->downy = ev->canvas.y;
994 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
995 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1000 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1002 Widget_Data *wd = elm_widget_data_get(data);
1003 Evas_Event_Mouse_Up *ev = event_info;
1005 if (wd->disabled) return;
1006 if (ev->button == 1)
1008 if (wd->longpress_timer)
1010 ecore_timer_del(wd->longpress_timer);
1011 wd->longpress_timer = NULL;
1014 else if (ev->button == 3)
1022 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1024 Widget_Data *wd = elm_widget_data_get(data);
1025 Evas_Event_Mouse_Move *ev = event_info;
1027 if (wd->disabled) return;
1030 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1032 if (wd->longpress_timer)
1034 ecore_timer_del(wd->longpress_timer);
1035 wd->longpress_timer = NULL;
1038 else if (wd->longpress_timer)
1042 dx = wd->downx - ev->cur.canvas.x;
1044 dy = wd->downy - ev->cur.canvas.y;
1047 ((_elm_config->finger_size / 2) *
1048 (_elm_config->finger_size / 2)))
1050 ecore_timer_del(wd->longpress_timer);
1051 wd->longpress_timer = NULL;
1055 else if (wd->longpress_timer)
1059 dx = wd->downx - ev->cur.canvas.x;
1061 dy = wd->downy - ev->cur.canvas.y;
1064 ((_elm_config->finger_size / 2) *
1065 (_elm_config->finger_size / 2)))
1067 ecore_timer_del(wd->longpress_timer);
1068 wd->longpress_timer = NULL;
1074 _getbase(Evas_Object *obj)
1076 Widget_Data *wd = elm_widget_data_get(obj);
1077 if (!wd) return "base";
1080 if (wd->password) return "base-password";
1083 if (wd->single_line) return "base-single";
1086 if (wd->linewrap) return "base";
1087 else if (wd->char_linewrap) return "base-charwrap";
1088 else return "base-nowrap";
1094 if (wd->password) return "base-password";
1097 if (wd->single_line) return "base-single-noedit";
1100 if (wd->linewrap) return "base-noedit";
1101 else if (wd->char_linewrap) return "base-noedit-charwrap";
1102 else return "base-nowrap-noedit";
1110 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1112 Widget_Data *wd = elm_widget_data_get(data);
1114 wd->changed = EINA_TRUE;
1115 /* Reset the size hints which are no more relevant. */
1116 evas_object_size_hint_min_set(data, -1, -1);
1118 if (wd->text) eina_stringshare_del(wd->text);
1120 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1121 if (wd->delay_write)
1123 ecore_timer_del(wd->delay_write);
1124 wd->delay_write = NULL;
1126 if ((!wd->autosave) || (!wd->file)) return;
1127 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1131 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1133 Widget_Data *wd = elm_widget_data_get(data);
1137 EINA_LIST_FOREACH(entries, l, entry)
1139 if (entry != data) elm_entry_select_none(entry);
1141 wd->have_selection = EINA_TRUE;
1142 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1143 #ifdef HAVE_ELEMENTARY_X
1144 if (wd->sel_notify_handler)
1146 const char *txt = elm_entry_selection_get(data);
1149 top = elm_widget_top_get(data);
1150 if ((top) && (elm_win_xwindow_get(top)))
1151 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1157 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1159 Widget_Data *wd = elm_widget_data_get(data);
1161 wd->have_selection = EINA_TRUE;
1162 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1163 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1164 elm_entry_selection_get(data));
1168 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1170 Widget_Data *wd = elm_widget_data_get(data);
1172 if (!wd->have_selection) return;
1173 wd->have_selection = EINA_FALSE;
1174 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1175 if (wd->sel_notify_handler)
1179 #ifdef HAVE_ELEMENTARY_X
1182 top = elm_widget_top_get(data);
1183 if ((top) && (elm_win_xwindow_get(top)))
1184 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1187 eina_stringshare_del(wd->cut_sel);
1192 #ifdef HAVE_ELEMENTARY_X
1195 top = elm_widget_top_get(data);
1196 if ((top) && (elm_win_xwindow_get(top)))
1197 elm_selection_clear(ELM_SEL_PRIMARY, data);
1204 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1206 Widget_Data *wd = elm_widget_data_get(data);
1208 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1209 if (wd->sel_notify_handler)
1211 #ifdef HAVE_ELEMENTARY_X
1214 top = elm_widget_top_get(data);
1215 if ((top) && (elm_win_xwindow_get(top)))
1217 wd->selection_asked = EINA_TRUE;
1218 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
1226 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1228 Widget_Data *wd = elm_widget_data_get(data);
1230 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1231 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1232 elm_entry_selection_get(data));
1236 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1238 Widget_Data *wd = elm_widget_data_get(data);
1240 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1241 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1242 elm_entry_selection_get(data));
1243 edje_object_part_text_insert(wd->ent, "elm.text", "");
1244 wd->changed = EINA_TRUE;
1249 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1251 Widget_Data *wd = elm_widget_data_get(data);
1253 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1254 wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1255 if (!wd->deferred_recalc_job)
1257 Evas_Coord cx, cy, cw, ch;
1258 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1259 &cx, &cy, &cw, &ch);
1260 elm_widget_show_region_set(data, cx, cy, cw, ch);
1264 wd->deferred_cur = EINA_TRUE;
1269 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1271 Widget_Data *wd = elm_widget_data_get(data);
1276 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1278 Widget_Data *wd = elm_widget_data_get(data);
1283 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1285 Widget_Data *wd = elm_widget_data_get(data);
1286 Elm_Entry_Anchor_Info ei;
1287 char *buf2, *p, *p2, *n;
1289 p = strrchr(emission, ',');
1292 const Eina_List *geoms;
1296 while (p2 >= emission)
1298 if (*p2 == ',') break;
1302 buf2 = alloca(5 + p - p2);
1303 strncpy(buf2, p2, p - p2);
1306 ei.button = atoi(buf2);
1307 ei.x = ei.y = ei.w = ei.h = 0;
1309 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1312 Evas_Textblock_Rectangle *r;
1314 Evas_Coord px, py, x, y;
1316 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1317 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1318 EINA_LIST_FOREACH(geoms, l, r)
1320 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1321 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1332 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1337 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1339 Widget_Data *wd = elm_widget_data_get(data);
1344 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1346 Widget_Data *wd = elm_widget_data_get(data);
1351 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1353 Widget_Data *wd = elm_widget_data_get(data);
1358 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1360 Widget_Data *wd = elm_widget_data_get(data);
1362 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1366 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1368 Widget_Data *wd = elm_widget_data_get(data);
1370 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1374 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1376 Widget_Data *wd = elm_widget_data_get(data);
1378 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1382 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1384 Widget_Data *wd = elm_widget_data_get(data);
1386 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1389 #ifdef HAVE_ELEMENTARY_X
1391 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1393 Widget_Data *wd = elm_widget_data_get(data);
1394 Ecore_X_Event_Selection_Notify *ev = event;
1395 if (!wd) return ECORE_CALLBACK_PASS_ON;
1396 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1397 return ECORE_CALLBACK_PASS_ON;
1399 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1400 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1402 Ecore_X_Selection_Data_Text *text_data;
1404 text_data = ev->data;
1405 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1407 if (text_data->text)
1409 char *txt = _elm_util_text_to_mkup(text_data->text);
1413 elm_entry_entry_insert(data, txt);
1418 wd->selection_asked = EINA_FALSE;
1420 else if (ev->selection == ECORE_X_SELECTION_XDND)
1422 Ecore_X_Selection_Data_Text *text_data;
1424 text_data = ev->data;
1425 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1427 if (text_data->text)
1429 char *txt = _elm_util_text_to_mkup(text_data->text);
1433 /* Massive FIXME: this should be at the drag point */
1434 elm_entry_entry_insert(data, txt);
1439 wd->drag_selection_asked = EINA_FALSE;
1441 ecore_x_dnd_send_finished();
1444 return ECORE_CALLBACK_PASS_ON;
1448 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1450 Widget_Data *wd = elm_widget_data_get(data);
1451 Ecore_X_Event_Selection_Clear *ev = event;
1452 if (!wd) return ECORE_CALLBACK_PASS_ON;
1453 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1454 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1455 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1457 elm_entry_select_none(data);
1459 return ECORE_CALLBACK_PASS_ON;
1463 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1468 wd = elm_widget_data_get(obj);
1469 if (!wd) return EINA_FALSE;
1470 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1472 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1473 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1474 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1475 EDJE_CURSOR_MAIN,drop->x,drop->y);
1476 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1477 elm_entry_entry_insert(obj, drop->data);
1478 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1479 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1485 static Evas_Object *
1486 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1488 Widget_Data *wd = elm_widget_data_get(data);
1491 Elm_Entry_Item_Provider *ip;
1493 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1495 o = ip->func(ip->data, data, item);
1498 if (!strncmp(item, "file://", 7))
1500 const char *fname = item + 7;
1502 o = evas_object_image_filled_add(evas_object_evas_get(data));
1503 evas_object_image_file_set(o, fname, NULL);
1504 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1506 evas_object_show(o);
1511 o = edje_object_add(evas_object_evas_get(data));
1512 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1516 o = edje_object_add(evas_object_evas_get(data));
1517 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1518 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1523 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
1525 Widget_Data *wd = elm_widget_data_get(data);
1527 Elm_Entry_Text_Filter *tf;
1529 if (type == EDJE_TEXT_FILTER_FORMAT)
1532 EINA_LIST_FOREACH(wd->text_filters, l, tf)
1534 tf->func(tf->data, data, text);
1541 * This adds an entry to @p parent object.
1543 * @param parent The parent object
1544 * @return The new object or NULL if it cannot be created
1549 elm_entry_add(Evas_Object *parent)
1551 Evas_Object *obj, *top;
1555 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1557 ELM_SET_WIDTYPE(widtype, "entry");
1558 elm_widget_type_set(obj, "entry");
1559 elm_widget_sub_object_add(parent, obj);
1560 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1561 elm_widget_data_set(obj, wd);
1562 elm_widget_del_hook_set(obj, _del_hook);
1563 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1564 elm_widget_theme_hook_set(obj, _theme_hook);
1565 elm_widget_disable_hook_set(obj, _disable_hook);
1566 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1567 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
1568 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1569 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1570 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
1571 elm_widget_can_focus_set(obj, EINA_TRUE);
1572 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
1574 wd->linewrap = EINA_TRUE;
1575 wd->char_linewrap= EINA_FALSE;
1576 wd->editable = EINA_TRUE;
1577 wd->disabled = EINA_FALSE;
1578 wd->context_menu = EINA_TRUE;
1579 wd->autosave = EINA_TRUE;
1580 wd->textonly = EINA_FALSE;
1582 wd->ent = edje_object_add(e);
1583 edje_object_item_provider_set(wd->ent, _get_item, obj);
1584 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
1585 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1586 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1587 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1589 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1591 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1594 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1595 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1596 _signal_entry_changed, obj);
1597 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1598 _signal_selection_start, obj);
1599 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1600 _signal_selection_changed, obj);
1601 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1602 _signal_selection_cleared, obj);
1603 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1604 _signal_entry_paste_request, obj);
1605 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1606 _signal_entry_copy_notify, obj);
1607 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1608 _signal_entry_cut_notify, obj);
1609 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1610 _signal_cursor_changed, obj);
1611 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1612 _signal_anchor_down, obj);
1613 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1614 _signal_anchor_up, obj);
1615 edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
1616 _signal_anchor_clicked, obj);
1617 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1618 _signal_anchor_move, obj);
1619 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1620 _signal_anchor_in, obj);
1621 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1622 _signal_anchor_out, obj);
1623 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
1624 _signal_key_enter, obj);
1625 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
1626 _signal_mouse_down, obj);
1627 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
1628 _signal_mouse_clicked, obj);
1629 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
1630 _signal_mouse_double, obj);
1631 edje_object_part_text_set(wd->ent, "elm.text", "");
1632 if (_elm_config->desktop_entry)
1633 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
1634 elm_widget_resize_object_set(obj, wd->ent);
1637 #ifdef HAVE_ELEMENTARY_X
1638 top = elm_widget_top_get(obj);
1639 if ((top) && (elm_win_xwindow_get(top)))
1641 wd->sel_notify_handler =
1642 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
1643 _event_selection_notify, obj);
1644 wd->sel_clear_handler =
1645 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
1646 _event_selection_clear, obj);
1649 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
1650 _drag_drop_cb, NULL);
1653 entries = eina_list_prepend(entries, obj);
1655 // module - find module for entry
1656 wd->api = _module(obj);
1657 // if found - hook in
1658 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
1660 _mirrored_set(obj, elm_widget_mirrored_get(obj));
1661 // TODO: convert Elementary to subclassing of Evas_Smart_Class
1662 // TODO: and save some bytes, making descriptions per-class and not instance!
1663 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1668 * This sets the entry object not to line wrap. All input will
1669 * be on a single line, and the entry box will extend with user input.
1671 * @param obj The entry object
1672 * @param single_line If true, the text in the entry
1673 * will be on a single line.
1678 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
1680 ELM_CHECK_WIDTYPE(obj, widtype);
1681 Widget_Data *wd = elm_widget_data_get(obj);
1683 if (wd->single_line == single_line) return;
1684 wd->single_line = single_line;
1685 wd->linewrap = EINA_FALSE;
1686 wd->char_linewrap = EINA_FALSE;
1687 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
1692 * This returns true if the entry has been set to single line mode.
1693 * See also elm_entry_single_line_set().
1695 * @param obj The entry object
1696 * @return single_line If true, the text in the entry is set to display
1702 elm_entry_single_line_get(const Evas_Object *obj)
1704 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1705 Widget_Data *wd = elm_widget_data_get(obj);
1706 if (!wd) return EINA_FALSE;
1707 return wd->single_line;
1711 * This sets the entry object to password mode. All text entered
1712 * and/or displayed within the widget will be replaced with asterisks (*).
1714 * @param obj The entry object
1715 * @param password If true, password mode is enabled.
1720 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
1722 ELM_CHECK_WIDTYPE(obj, widtype);
1723 Widget_Data *wd = elm_widget_data_get(obj);
1725 if (wd->password == password) return;
1726 wd->password = password;
1727 wd->single_line = EINA_TRUE;
1728 wd->linewrap = EINA_FALSE;
1729 wd->char_linewrap = EINA_FALSE;
1734 * This returns whether password mode is enabled.
1735 * See also elm_entry_password_set().
1737 * @param obj The entry object
1738 * @return If true, the entry is set to display all characters
1744 elm_entry_password_get(const Evas_Object *obj)
1746 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1747 Widget_Data *wd = elm_widget_data_get(obj);
1748 if (!wd) return EINA_FALSE;
1749 return wd->password;
1753 * This sets the text displayed within the entry to @p entry.
1755 * @param obj The entry object
1756 * @param entry The text to be displayed
1761 elm_entry_entry_set(Evas_Object *obj, const char *entry)
1763 ELM_CHECK_WIDTYPE(obj, widtype);
1764 Widget_Data *wd = elm_widget_data_get(obj);
1766 if (!entry) entry = "";
1767 edje_object_part_text_set(wd->ent, "elm.text", entry);
1768 if (wd->text) eina_stringshare_del(wd->text);
1770 wd->changed = EINA_TRUE;
1775 * This returns the text currently shown in object @p entry.
1776 * See also elm_entry_entry_set().
1778 * @param obj The entry object
1779 * @return The currently displayed text or NULL on failure
1784 elm_entry_entry_get(const Evas_Object *obj)
1786 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1787 Widget_Data *wd = elm_widget_data_get(obj);
1789 if (!wd) return NULL;
1790 if (wd->text) return wd->text;
1791 text = edje_object_part_text_get(wd->ent, "elm.text");
1794 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
1797 eina_stringshare_replace(&wd->text, text);
1802 * This returns EINA_TRUE if the entry is empty/there was an error
1803 * and EINA_FALSE if it is not empty.
1805 * @param obj The entry object
1806 * @return If the entry is empty or not.
1811 elm_entry_is_empty(const Evas_Object *obj)
1813 /* FIXME: until there's support for that in textblock, we just check
1814 * to see if the there is text or not. */
1815 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
1816 Widget_Data *wd = elm_widget_data_get(obj);
1817 const Evas_Object *tb;
1818 Evas_Textblock_Cursor *cur;
1820 if (!wd) return EINA_TRUE;
1821 /* It's a hack until we get the support suggested above.
1822 * We just create a cursor, point it to the begining, and then
1823 * try to advance it, if it can advance, the tb is not empty,
1824 * otherwise it is. */
1825 tb = edje_object_part_object_get(wd->ent, "elm.text");
1826 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
1827 actually, ok for the time being, thsese hackish stuff will be removed
1828 once evas 1.0 is out*/
1829 evas_textblock_cursor_pos_set(cur, 0);
1830 ret = evas_textblock_cursor_char_next(cur);
1831 evas_textblock_cursor_free(cur);
1837 * This returns all selected text within the entry.
1839 * @param obj The entry object
1840 * @return The selected text within the entry or NULL on failure
1845 elm_entry_selection_get(const Evas_Object *obj)
1847 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1848 Widget_Data *wd = elm_widget_data_get(obj);
1849 if (!wd) return NULL;
1850 return edje_object_part_text_selection_get(wd->ent, "elm.text");
1854 * This inserts text in @p entry where the current cursor position.
1856 * This inserts text at the cursor position is as if it was typed
1857 * by the user (note this also allows markup which a user
1858 * can't just "type" as it would be converted to escaped text, so this
1859 * call can be used to insert things like emoticon items or bold push/pop
1860 * tags, other font and color change tags etc.)
1862 * @param obj The entry object
1863 * @param entry The text to insert
1868 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
1870 ELM_CHECK_WIDTYPE(obj, widtype);
1871 Widget_Data *wd = elm_widget_data_get(obj);
1873 edje_object_part_text_insert(wd->ent, "elm.text", entry);
1874 wd->changed = EINA_TRUE;
1879 * This enables word line wrapping in the entry object. It is the opposite
1880 * of elm_entry_single_line_set(). Additionally, setting this disables
1881 * character line wrapping.
1882 * See also elm_entry_line_char_wrap_set().
1884 * @param obj The entry object
1885 * @param wrap If true, the entry will be wrapped once it reaches the end
1886 * of the object. Wrapping will occur at the end of the word before the end of the
1892 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
1894 ELM_CHECK_WIDTYPE(obj, widtype);
1895 Widget_Data *wd = elm_widget_data_get(obj);
1897 if (wd->linewrap == wrap) return;
1898 wd->linewrap = wrap;
1900 wd->char_linewrap = EINA_FALSE;
1905 * This enables character line wrapping in the entry object. It is the opposite
1906 * of elm_entry_single_line_set(). Additionally, setting this disables
1907 * word line wrapping.
1908 * See also elm_entry_line_wrap_set().
1910 * @param obj The entry object
1911 * @param wrap If true, the entry will be wrapped once it reaches the end
1912 * of the object. Wrapping will occur immediately upon reaching the end of the object.
1917 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
1919 ELM_CHECK_WIDTYPE(obj, widtype);
1920 Widget_Data *wd = elm_widget_data_get(obj);
1922 if (wd->char_linewrap == wrap) return;
1923 wd->char_linewrap = wrap;
1924 if(wd->char_linewrap)
1925 wd->linewrap = EINA_FALSE;
1930 * This sets the editable attribute of the entry.
1932 * @param obj The entry object
1933 * @param editable If true, the entry will be editable by the user.
1934 * If false, it will be set to the disabled state.
1939 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
1941 ELM_CHECK_WIDTYPE(obj, widtype);
1942 Widget_Data *wd = elm_widget_data_get(obj);
1944 if (wd->editable == editable) return;
1945 wd->editable = editable;
1948 #ifdef HAVE_ELEMENTARY_X
1950 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
1952 elm_drop_target_del(obj);
1957 * This gets the editable attribute of the entry.
1958 * See also elm_entry_editable_set().
1960 * @param obj The entry object
1961 * @return If true, the entry is editable by the user.
1962 * If false, it is not editable by the user
1967 elm_entry_editable_get(const Evas_Object *obj)
1969 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1970 Widget_Data *wd = elm_widget_data_get(obj);
1971 if (!wd) return EINA_FALSE;
1972 return wd->editable;
1976 * This drops any existing text selection within the entry.
1978 * @param obj The entry object
1983 elm_entry_select_none(Evas_Object *obj)
1985 ELM_CHECK_WIDTYPE(obj, widtype);
1986 Widget_Data *wd = elm_widget_data_get(obj);
1990 wd->selmode = EINA_FALSE;
1991 if (!_elm_config->desktop_entry)
1992 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1993 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1995 wd->have_selection = EINA_FALSE;
1996 edje_object_part_text_select_none(wd->ent, "elm.text");
2000 * This selects all text within the entry.
2002 * @param obj The entry object
2007 elm_entry_select_all(Evas_Object *obj)
2009 ELM_CHECK_WIDTYPE(obj, widtype);
2010 Widget_Data *wd = elm_widget_data_get(obj);
2014 wd->selmode = EINA_FALSE;
2015 if (!_elm_config->desktop_entry)
2016 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2017 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2019 wd->have_selection = EINA_TRUE;
2020 edje_object_part_text_select_all(wd->ent, "elm.text");
2024 * This function returns the geometry of the cursor.
2026 * It's useful if you want to draw something on the cursor (or where it is),
2027 * or for example in the case of scrolled entry where you want to show the
2030 * @param obj The entry object
2031 * @param x returned geometry
2032 * @param y returned geometry
2033 * @param w returned geometry
2034 * @param h returned geometry
2035 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2040 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
2042 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2043 Widget_Data *wd = elm_widget_data_get(obj);
2044 if (!wd) return EINA_FALSE;
2045 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
2050 * This moves the cursor one place to the right within the entry.
2052 * @param obj The entry object
2053 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2058 elm_entry_cursor_next(Evas_Object *obj)
2060 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2061 Widget_Data *wd = elm_widget_data_get(obj);
2062 if (!wd) return EINA_FALSE;
2063 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2067 * This moves the cursor one place to the left within the entry.
2069 * @param obj The entry object
2070 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2075 elm_entry_cursor_prev(Evas_Object *obj)
2077 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2078 Widget_Data *wd = elm_widget_data_get(obj);
2079 if (!wd) return EINA_FALSE;
2080 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2084 * This moves the cursor one line up within the entry.
2086 * @param obj The entry object
2087 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2092 elm_entry_cursor_up(Evas_Object *obj)
2094 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2095 Widget_Data *wd = elm_widget_data_get(obj);
2096 if (!wd) return EINA_FALSE;
2097 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2101 * This moves the cursor one line down within the entry.
2103 * @param obj The entry object
2104 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2109 elm_entry_cursor_down(Evas_Object *obj)
2111 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2112 Widget_Data *wd = elm_widget_data_get(obj);
2113 if (!wd) return EINA_FALSE;
2114 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2118 * This moves the cursor to the beginning of the entry.
2120 * @param obj The entry object
2125 elm_entry_cursor_begin_set(Evas_Object *obj)
2127 ELM_CHECK_WIDTYPE(obj, widtype);
2128 Widget_Data *wd = elm_widget_data_get(obj);
2130 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2134 * This moves the cursor to the end of the entry.
2136 * @param obj The entry object
2141 elm_entry_cursor_end_set(Evas_Object *obj)
2143 ELM_CHECK_WIDTYPE(obj, widtype);
2144 Widget_Data *wd = elm_widget_data_get(obj);
2146 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2150 * This moves the cursor to the beginning of the current line.
2152 * @param obj The entry object
2157 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2159 ELM_CHECK_WIDTYPE(obj, widtype);
2160 Widget_Data *wd = elm_widget_data_get(obj);
2162 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2166 * This moves the cursor to the end of the current line.
2168 * @param obj The entry object
2173 elm_entry_cursor_line_end_set(Evas_Object *obj)
2175 ELM_CHECK_WIDTYPE(obj, widtype);
2176 Widget_Data *wd = elm_widget_data_get(obj);
2178 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2182 * This begins a selection within the entry as though
2183 * the user were holding down the mouse button to make a selection.
2185 * @param obj The entry object
2190 elm_entry_cursor_selection_begin(Evas_Object *obj)
2192 ELM_CHECK_WIDTYPE(obj, widtype);
2193 Widget_Data *wd = elm_widget_data_get(obj);
2195 edje_object_part_text_select_begin(wd->ent, "elm.text");
2199 * This ends a selection within the entry as though
2200 * the user had just released the mouse button while making a selection.
2202 * @param obj The entry object
2207 elm_entry_cursor_selection_end(Evas_Object *obj)
2209 ELM_CHECK_WIDTYPE(obj, widtype);
2210 Widget_Data *wd = elm_widget_data_get(obj);
2212 edje_object_part_text_select_extend(wd->ent, "elm.text");
2216 * TODO: fill this in
2218 * @param obj The entry object
2219 * @return TODO: fill this in
2224 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2226 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2227 Widget_Data *wd = elm_widget_data_get(obj);
2228 if (!wd) return EINA_FALSE;
2229 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2233 * This returns whether the cursor is visible.
2235 * @param obj The entry object
2236 * @return If true, the cursor is visible.
2241 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2243 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2244 Widget_Data *wd = elm_widget_data_get(obj);
2245 if (!wd) return EINA_FALSE;
2246 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2250 * TODO: fill this in
2252 * @param obj The entry object
2253 * @return TODO: fill this in
2258 elm_entry_cursor_content_get(const Evas_Object *obj)
2260 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2261 Widget_Data *wd = elm_widget_data_get(obj);
2262 if (!wd) return NULL;
2263 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2267 * Sets the cursor position in the entry to the given value
2269 * @param obj The entry object
2270 * @param pos The position of the cursor
2275 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
2277 ELM_CHECK_WIDTYPE(obj, widtype);
2278 Widget_Data *wd = elm_widget_data_get(obj);
2280 edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
2281 edje_object_message_signal_process(wd->ent);
2285 * Retrieves the current position of the cursor in the entry
2287 * @param obj The entry object
2288 * @return The cursor position
2293 elm_entry_cursor_pos_get(const Evas_Object *obj)
2295 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2296 Widget_Data *wd = elm_widget_data_get(obj);
2298 return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2302 * This executes a "cut" action on the selected text in the entry.
2304 * @param obj The entry object
2309 elm_entry_selection_cut(Evas_Object *obj)
2311 ELM_CHECK_WIDTYPE(obj, widtype);
2312 Widget_Data *wd = elm_widget_data_get(obj);
2314 _cut(obj, NULL, NULL);
2318 * This executes a "copy" action on the selected text in the entry.
2320 * @param obj The entry object
2325 elm_entry_selection_copy(Evas_Object *obj)
2327 ELM_CHECK_WIDTYPE(obj, widtype);
2328 Widget_Data *wd = elm_widget_data_get(obj);
2330 _copy(obj, NULL, NULL);
2334 * This executes a "paste" action in the entry.
2336 * @param obj The entry object
2341 elm_entry_selection_paste(Evas_Object *obj)
2343 ELM_CHECK_WIDTYPE(obj, widtype);
2344 Widget_Data *wd = elm_widget_data_get(obj);
2346 _paste(obj, NULL, NULL);
2350 * This clears and frees the items in a entry's contextual (right click) menu.
2352 * @param obj The entry object
2357 elm_entry_context_menu_clear(Evas_Object *obj)
2359 ELM_CHECK_WIDTYPE(obj, widtype);
2360 Widget_Data *wd = elm_widget_data_get(obj);
2361 Elm_Entry_Context_Menu_Item *it;
2363 EINA_LIST_FREE(wd->items, it)
2365 eina_stringshare_del(it->label);
2366 eina_stringshare_del(it->icon_file);
2367 eina_stringshare_del(it->icon_group);
2373 * This adds an item to the entry's contextual menu.
2375 * @param obj The entry object
2376 * @param label The item's text label
2377 * @param icon_file The item's icon file
2378 * @param icon_type The item's icon type
2379 * @param func The callback to execute when the item is clicked
2380 * @param data The data to associate with the item for related functions
2385 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)
2387 ELM_CHECK_WIDTYPE(obj, widtype);
2388 Widget_Data *wd = elm_widget_data_get(obj);
2389 Elm_Entry_Context_Menu_Item *it;
2391 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2393 wd->items = eina_list_append(wd->items, it);
2395 it->label = eina_stringshare_add(label);
2396 it->icon_file = eina_stringshare_add(icon_file);
2397 it->icon_type = icon_type;
2399 it->data = (void *)data;
2403 * This disables the entry's contextual (right click) menu.
2405 * @param obj The entry object
2406 * @param disabled If true, the menu is disabled
2411 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2413 ELM_CHECK_WIDTYPE(obj, widtype);
2414 Widget_Data *wd = elm_widget_data_get(obj);
2416 if (wd->context_menu == !disabled) return;
2417 wd->context_menu = !disabled;
2421 * This returns whether the entry's contextual (right click) menu is disabled.
2423 * @param obj The entry object
2424 * @return If true, the menu is disabled
2429 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2431 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2432 Widget_Data *wd = elm_widget_data_get(obj);
2433 if (!wd) return EINA_FALSE;
2434 return !wd->context_menu;
2438 * This appends a custom item provider to the list for that entry
2440 * This appends the given callback. The list is walked from beginning to end
2441 * with each function called given the item href string in the text. If the
2442 * function returns an object handle other than NULL (it should create an
2443 * and object to do this), then this object is used to replace that item. If
2444 * not the next provider is called until one provides an item object, or the
2445 * default provider in entry does.
2447 * @param obj The entry object
2448 * @param func The function called to provide the item object
2449 * @param data The data passed to @p func
2454 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2456 ELM_CHECK_WIDTYPE(obj, widtype);
2457 Widget_Data *wd = elm_widget_data_get(obj);
2459 EINA_SAFETY_ON_NULL_RETURN(func);
2460 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2464 wd->item_providers = eina_list_append(wd->item_providers, ip);
2468 * This prepends a custom item provider to the list for that entry
2470 * This prepends the given callback. See elm_entry_item_provider_append() for
2473 * @param obj The entry object
2474 * @param func The function called to provide the item object
2475 * @param data The data passed to @p func
2480 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2482 ELM_CHECK_WIDTYPE(obj, widtype);
2483 Widget_Data *wd = elm_widget_data_get(obj);
2485 EINA_SAFETY_ON_NULL_RETURN(func);
2486 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2490 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2494 * This removes a custom item provider to the list for that entry
2496 * This removes the given callback. See elm_entry_item_provider_append() for
2499 * @param obj The entry object
2500 * @param func The function called to provide the item object
2501 * @param data The data passed to @p func
2506 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2508 ELM_CHECK_WIDTYPE(obj, widtype);
2509 Widget_Data *wd = elm_widget_data_get(obj);
2511 Elm_Entry_Item_Provider *ip;
2513 EINA_SAFETY_ON_NULL_RETURN(func);
2514 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2516 if ((ip->func == func) && ((!data) || (ip->data == data)))
2518 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2526 * Append a filter function for text inserted in the entry
2528 * Append the given callback to the list. This functions will be called
2529 * whenever any text is inserted into the entry, with the text to be inserted
2530 * as a parameter. The callback function is free to alter the text in any way
2531 * it wants, but it must remember to free the given pointer and update it.
2532 * If the new text is to be discarded, the function can free it and set it text
2533 * parameter to NULL. This will also prevent any following filters from being
2536 * @param obj The entry object
2537 * @param func The function to use as text filter
2538 * @param data User data to pass to @p func
2543 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2546 Elm_Entry_Text_Filter *tf;
2547 ELM_CHECK_WIDTYPE(obj, widtype);
2549 wd = elm_widget_data_get(obj);
2551 EINA_SAFETY_ON_NULL_RETURN(func);
2553 tf = _filter_new(func, data);
2556 wd->text_filters = eina_list_append(wd->text_filters, tf);
2560 * Prepend a filter function for text insdrted in the entry
2562 * Prepend the given callback to the list. See elm_entry_text_filter_append()
2563 * for more information
2565 * @param obj The entry object
2566 * @param func The function to use as text filter
2567 * @param data User data to pass to @p func
2572 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2575 Elm_Entry_Text_Filter *tf;
2576 ELM_CHECK_WIDTYPE(obj, widtype);
2578 wd = elm_widget_data_get(obj);
2580 EINA_SAFETY_ON_NULL_RETURN(func);
2582 tf = _filter_new(func, data);
2585 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
2589 * Remove a filter from the list
2591 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
2592 * for more information.
2594 * @param obj The entry object
2595 * @param func The filter function to remove
2596 * @param data The user data passed when adding the function
2601 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2605 Elm_Entry_Text_Filter *tf;
2606 ELM_CHECK_WIDTYPE(obj, widtype);
2608 wd = elm_widget_data_get(obj);
2610 EINA_SAFETY_ON_NULL_RETURN(func);
2612 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2614 if ((tf->func == func) && ((!data) || (tf->data == data)))
2616 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
2624 * This converts a markup (HTML-like) string into UTF-8.
2625 * Returning string is obtained with malloc.
2626 * After use the returned string, it should be freed.
2628 * @param s The string (in markup) to be converted
2629 * @return The converted string (in UTF-8). It should be freed.
2634 elm_entry_markup_to_utf8(const char *s)
2636 char *ss = _elm_util_mkup_to_text(s);
2637 if (!ss) ss = strdup("");
2642 * This converts a UTF-8 string into markup (HTML-like).
2643 * Returning string is obtained with malloc.
2644 * After use the returned string, it should be freed.
2646 * @param s The string (in UTF-8) to be converted
2647 * @return The converted string (in markup). It should be freed.
2652 elm_entry_utf8_to_markup(const char *s)
2654 char *ss = _elm_util_text_to_mkup(s);
2655 if (!ss) ss = strdup("");
2660 * Filter inserted text based on user defined character and byte limits
2662 * Add this filter to an entry to limit the characters that it will accept
2663 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
2664 * The funtion works on the UTF-8 representation of the string, converting
2665 * it from the set markup, thus not accounting for any format in it.
2667 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
2668 * it as data when setting the filter. In it it's possible to set limits
2669 * by character count or bytes (any of them is disabled if 0), and both can
2670 * be set at the same time. In that case, it first checks for characters,
2673 * The function will cut the inserted text in order to allow only the first
2674 * number of characters that are still allowed. The cut is made in
2675 * characters, even when limiting by bytes, in order to always contain
2676 * valid ones and avoid half unicode characters making it in.
2681 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
2683 Elm_Entry_Filter_Limit_Size *lim = data;
2686 const char *(*text_get)(const Evas_Object *);
2687 const char *widget_type;
2689 EINA_SAFETY_ON_NULL_RETURN(data);
2690 EINA_SAFETY_ON_NULL_RETURN(entry);
2691 EINA_SAFETY_ON_NULL_RETURN(text);
2693 /* hack. I don't want to copy the entire function to work with
2695 widget_type = elm_widget_type_get(entry);
2696 if (!strcmp(widget_type, "entry"))
2697 text_get = elm_entry_entry_get;
2698 else if (!strcmp(widget_type, "scrolled_entry"))
2699 text_get = elm_scrolled_entry_entry_get;
2703 current = elm_entry_markup_to_utf8(text_get(entry));
2705 if (lim->max_char_count > 0)
2708 len = evas_string_char_len_get(current);
2709 if (len >= lim->max_char_count)
2716 newlen = evas_string_char_len_get(*text);
2717 cut = strlen(*text);
2718 while ((len + newlen) > lim->max_char_count)
2720 cut = evas_string_char_prev_get(*text, cut, NULL);
2726 if (lim->max_byte_count > 0)
2728 len = strlen(current);
2729 if (len >= lim->max_byte_count)
2736 newlen = strlen(*text);
2737 while ((len + newlen) > lim->max_byte_count)
2739 int p = evas_string_char_prev_get(*text, newlen, NULL);
2740 newlen -= (newlen - p);
2743 (*text)[newlen] = 0;
2754 * Filter inserted text based on accepted or rejected sets of characters
2756 * Add this filter to an entry to restrict the set of accepted characters
2757 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
2758 * This structure contains both accepted and rejected sets, but they are
2759 * mutually exclusive. If accepted is set, it will be used, otherwise it
2760 * goes on to the rejected set.
2763 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
2765 Elm_Entry_Filter_Accept_Set *as = data;
2769 int read_idx, last_read_idx = 0, read_char;
2771 EINA_SAFETY_ON_NULL_RETURN(data);
2772 EINA_SAFETY_ON_NULL_RETURN(text);
2774 if ((!as->accepted) && (!as->rejected))
2780 goes_in = EINA_TRUE;
2785 goes_in = EINA_FALSE;
2789 read_idx = evas_string_char_next_get(*text, 0, &read_char);
2792 int cmp_idx, cmp_char;
2793 Eina_Bool in_set = EINA_FALSE;
2795 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
2798 if (read_char == cmp_char)
2803 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
2805 if (in_set == goes_in)
2807 int size = read_idx - last_read_idx;
2808 const char *src = (*text) + last_read_idx;
2810 memcpy(insert, *text + last_read_idx, size);
2813 last_read_idx = read_idx;
2814 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
2820 * This sets the file (and implicitly loads it) for the text to display and
2821 * then edit. All changes are written back to the file after a short delay if
2822 * the entry object is set to autosave.
2824 * @param obj The entry object
2825 * @param file The path to the file to load and save
2826 * @param format The file format
2831 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
2833 ELM_CHECK_WIDTYPE(obj, widtype);
2834 Widget_Data *wd = elm_widget_data_get(obj);
2836 if (wd->delay_write)
2838 ecore_timer_del(wd->delay_write);
2839 wd->delay_write = NULL;
2841 if (wd->autosave) _save(obj);
2842 eina_stringshare_replace(&wd->file, file);
2843 wd->format = format;
2848 * Gets the file to load and save and the file format
2850 * @param obj The entry object
2851 * @param file The path to the file to load and save
2852 * @param format The file format
2857 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
2859 ELM_CHECK_WIDTYPE(obj, widtype);
2860 Widget_Data *wd = elm_widget_data_get(obj);
2862 if (file) *file = wd->file;
2863 if (format) *format = wd->format;
2867 * This function writes any changes made to the file set with
2868 * elm_entry_file_set()
2870 * @param obj The entry object
2875 elm_entry_file_save(Evas_Object *obj)
2877 ELM_CHECK_WIDTYPE(obj, widtype);
2878 Widget_Data *wd = elm_widget_data_get(obj);
2880 if (wd->delay_write)
2882 ecore_timer_del(wd->delay_write);
2883 wd->delay_write = NULL;
2886 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
2890 * This sets the entry object to 'autosave' the loaded text file or not.
2892 * @param obj The entry object
2893 * @param autosave Autosave the loaded file or not
2898 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
2900 ELM_CHECK_WIDTYPE(obj, widtype);
2901 Widget_Data *wd = elm_widget_data_get(obj);
2903 wd->autosave = !!autosave;
2907 * This gets the entry object's 'autosave' status.
2909 * @param obj The entry object
2910 * @return Autosave the loaded file or not
2915 elm_entry_autosave_get(const Evas_Object *obj)
2917 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2918 Widget_Data *wd = elm_widget_data_get(obj);
2919 if (!wd) return EINA_FALSE;
2920 return wd->autosave;
2924 * Control pasting of text and images for the widget.
2926 * Normally the entry allows both text and images to be pasted. By setting
2927 * textonly to be true, this prevents images from being pasted.
2929 * Note this only changes the behaviour of text.
2931 * @param obj The entry object
2932 * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is text+image+other.
2937 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
2939 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
2940 ELM_CHECK_WIDTYPE(obj, widtype);
2941 Widget_Data *wd = elm_widget_data_get(obj);
2943 textonly = !!textonly;
2944 if (wd->textonly == textonly) return;
2945 wd->textonly = !!textonly;
2946 if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
2947 #ifdef HAVE_ELEMENTARY_X
2948 elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
2953 * Getting elm_entry text paste/drop mode.
2955 * In textonly mode, only text may be pasted or dropped into the widget.
2957 * @param obj The entry object
2958 * @return If the widget only accepts text from pastes.
2963 elm_entry_cnp_textonly_get(Evas_Object *obj)
2965 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2966 Widget_Data *wd = elm_widget_data_get(obj);
2967 if (!wd) return EINA_FALSE;
2968 return wd->textonly;