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);
1115 wd->changed = EINA_TRUE;
1116 /* Reset the size hints which are no more relevant.
1117 * Keep the height, this is a hack, but doesn't really matter
1118 * cause we'll re-eval in a moment. */
1119 evas_object_size_hint_min_get(data, NULL, &minh);
1120 evas_object_size_hint_min_set(data, -1, minh);
1122 if (wd->text) eina_stringshare_del(wd->text);
1124 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1125 if (wd->delay_write)
1127 ecore_timer_del(wd->delay_write);
1128 wd->delay_write = NULL;
1130 if ((!wd->autosave) || (!wd->file)) return;
1131 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1135 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1137 Widget_Data *wd = elm_widget_data_get(data);
1141 EINA_LIST_FOREACH(entries, l, entry)
1143 if (entry != data) elm_entry_select_none(entry);
1145 wd->have_selection = EINA_TRUE;
1146 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1147 #ifdef HAVE_ELEMENTARY_X
1148 if (wd->sel_notify_handler)
1150 const char *txt = elm_entry_selection_get(data);
1153 top = elm_widget_top_get(data);
1154 if ((top) && (elm_win_xwindow_get(top)))
1155 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1161 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1163 Widget_Data *wd = elm_widget_data_get(data);
1165 wd->have_selection = EINA_TRUE;
1166 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1167 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1168 elm_entry_selection_get(data));
1172 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1174 Widget_Data *wd = elm_widget_data_get(data);
1176 if (!wd->have_selection) return;
1177 wd->have_selection = EINA_FALSE;
1178 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1179 if (wd->sel_notify_handler)
1183 #ifdef HAVE_ELEMENTARY_X
1186 top = elm_widget_top_get(data);
1187 if ((top) && (elm_win_xwindow_get(top)))
1188 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1191 eina_stringshare_del(wd->cut_sel);
1196 #ifdef HAVE_ELEMENTARY_X
1199 top = elm_widget_top_get(data);
1200 if ((top) && (elm_win_xwindow_get(top)))
1201 elm_selection_clear(ELM_SEL_PRIMARY, data);
1208 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1210 Widget_Data *wd = elm_widget_data_get(data);
1212 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1213 if (wd->sel_notify_handler)
1215 #ifdef HAVE_ELEMENTARY_X
1218 top = elm_widget_top_get(data);
1219 if ((top) && (elm_win_xwindow_get(top)))
1221 wd->selection_asked = EINA_TRUE;
1222 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
1230 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1232 Widget_Data *wd = elm_widget_data_get(data);
1234 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1235 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1236 elm_entry_selection_get(data));
1240 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1242 Widget_Data *wd = elm_widget_data_get(data);
1244 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1245 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1246 elm_entry_selection_get(data));
1247 edje_object_part_text_insert(wd->ent, "elm.text", "");
1248 wd->changed = EINA_TRUE;
1253 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1255 Widget_Data *wd = elm_widget_data_get(data);
1257 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1258 wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1259 if (!wd->deferred_recalc_job)
1261 Evas_Coord cx, cy, cw, ch;
1262 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1263 &cx, &cy, &cw, &ch);
1264 elm_widget_show_region_set(data, cx, cy, cw, ch);
1268 wd->deferred_cur = EINA_TRUE;
1273 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1275 Widget_Data *wd = elm_widget_data_get(data);
1280 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1282 Widget_Data *wd = elm_widget_data_get(data);
1287 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1289 Widget_Data *wd = elm_widget_data_get(data);
1290 Elm_Entry_Anchor_Info ei;
1291 char *buf2, *p, *p2, *n;
1293 p = strrchr(emission, ',');
1296 const Eina_List *geoms;
1300 while (p2 >= emission)
1302 if (*p2 == ',') break;
1306 buf2 = alloca(5 + p - p2);
1307 strncpy(buf2, p2, p - p2);
1310 ei.button = atoi(buf2);
1311 ei.x = ei.y = ei.w = ei.h = 0;
1313 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1316 Evas_Textblock_Rectangle *r;
1318 Evas_Coord px, py, x, y;
1320 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1321 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1322 EINA_LIST_FOREACH(geoms, l, r)
1324 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1325 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1336 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1341 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1343 Widget_Data *wd = elm_widget_data_get(data);
1348 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1350 Widget_Data *wd = elm_widget_data_get(data);
1355 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1357 Widget_Data *wd = elm_widget_data_get(data);
1362 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1364 Widget_Data *wd = elm_widget_data_get(data);
1366 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1370 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1372 Widget_Data *wd = elm_widget_data_get(data);
1374 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1378 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1380 Widget_Data *wd = elm_widget_data_get(data);
1382 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1386 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1388 Widget_Data *wd = elm_widget_data_get(data);
1390 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1393 #ifdef HAVE_ELEMENTARY_X
1395 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1397 Widget_Data *wd = elm_widget_data_get(data);
1398 Ecore_X_Event_Selection_Notify *ev = event;
1399 if (!wd) return ECORE_CALLBACK_PASS_ON;
1400 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1401 return ECORE_CALLBACK_PASS_ON;
1403 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1404 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1406 Ecore_X_Selection_Data_Text *text_data;
1408 text_data = ev->data;
1409 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1411 if (text_data->text)
1413 char *txt = _elm_util_text_to_mkup(text_data->text);
1417 elm_entry_entry_insert(data, txt);
1422 wd->selection_asked = EINA_FALSE;
1424 else if (ev->selection == ECORE_X_SELECTION_XDND)
1426 Ecore_X_Selection_Data_Text *text_data;
1428 text_data = ev->data;
1429 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1431 if (text_data->text)
1433 char *txt = _elm_util_text_to_mkup(text_data->text);
1437 /* Massive FIXME: this should be at the drag point */
1438 elm_entry_entry_insert(data, txt);
1443 wd->drag_selection_asked = EINA_FALSE;
1445 ecore_x_dnd_send_finished();
1448 return ECORE_CALLBACK_PASS_ON;
1452 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1454 Widget_Data *wd = elm_widget_data_get(data);
1455 Ecore_X_Event_Selection_Clear *ev = event;
1456 if (!wd) return ECORE_CALLBACK_PASS_ON;
1457 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1458 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1459 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1461 elm_entry_select_none(data);
1463 return ECORE_CALLBACK_PASS_ON;
1467 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1472 wd = elm_widget_data_get(obj);
1473 if (!wd) return EINA_FALSE;
1474 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1476 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1477 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1478 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1479 EDJE_CURSOR_MAIN,drop->x,drop->y);
1480 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1481 elm_entry_entry_insert(obj, drop->data);
1482 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1483 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1489 static Evas_Object *
1490 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1492 Widget_Data *wd = elm_widget_data_get(data);
1495 Elm_Entry_Item_Provider *ip;
1497 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1499 o = ip->func(ip->data, data, item);
1502 if (!strncmp(item, "file://", 7))
1504 const char *fname = item + 7;
1506 o = evas_object_image_filled_add(evas_object_evas_get(data));
1507 evas_object_image_file_set(o, fname, NULL);
1508 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1510 evas_object_show(o);
1515 o = edje_object_add(evas_object_evas_get(data));
1516 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1520 o = edje_object_add(evas_object_evas_get(data));
1521 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1522 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1527 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
1529 Widget_Data *wd = elm_widget_data_get(data);
1531 Elm_Entry_Text_Filter *tf;
1533 if (type == EDJE_TEXT_FILTER_FORMAT)
1536 EINA_LIST_FOREACH(wd->text_filters, l, tf)
1538 tf->func(tf->data, data, text);
1545 * This adds an entry to @p parent object.
1547 * @param parent The parent object
1548 * @return The new object or NULL if it cannot be created
1553 elm_entry_add(Evas_Object *parent)
1555 Evas_Object *obj, *top;
1559 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1561 ELM_SET_WIDTYPE(widtype, "entry");
1562 elm_widget_type_set(obj, "entry");
1563 elm_widget_sub_object_add(parent, obj);
1564 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1565 elm_widget_data_set(obj, wd);
1566 elm_widget_del_hook_set(obj, _del_hook);
1567 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1568 elm_widget_theme_hook_set(obj, _theme_hook);
1569 elm_widget_disable_hook_set(obj, _disable_hook);
1570 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1571 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
1572 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1573 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1574 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
1575 elm_widget_can_focus_set(obj, EINA_TRUE);
1576 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
1578 wd->linewrap = EINA_TRUE;
1579 wd->char_linewrap= EINA_FALSE;
1580 wd->editable = EINA_TRUE;
1581 wd->disabled = EINA_FALSE;
1582 wd->context_menu = EINA_TRUE;
1583 wd->autosave = EINA_TRUE;
1584 wd->textonly = EINA_FALSE;
1586 wd->ent = edje_object_add(e);
1587 edje_object_item_provider_set(wd->ent, _get_item, obj);
1588 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
1589 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1590 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1591 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1593 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1595 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1598 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1599 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1600 _signal_entry_changed, obj);
1601 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1602 _signal_selection_start, obj);
1603 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1604 _signal_selection_changed, obj);
1605 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1606 _signal_selection_cleared, obj);
1607 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1608 _signal_entry_paste_request, obj);
1609 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1610 _signal_entry_copy_notify, obj);
1611 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1612 _signal_entry_cut_notify, obj);
1613 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1614 _signal_cursor_changed, obj);
1615 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1616 _signal_anchor_down, obj);
1617 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1618 _signal_anchor_up, obj);
1619 edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
1620 _signal_anchor_clicked, obj);
1621 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1622 _signal_anchor_move, obj);
1623 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1624 _signal_anchor_in, obj);
1625 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1626 _signal_anchor_out, obj);
1627 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
1628 _signal_key_enter, obj);
1629 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
1630 _signal_mouse_down, obj);
1631 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
1632 _signal_mouse_clicked, obj);
1633 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
1634 _signal_mouse_double, obj);
1635 edje_object_part_text_set(wd->ent, "elm.text", "");
1636 if (_elm_config->desktop_entry)
1637 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
1638 elm_widget_resize_object_set(obj, wd->ent);
1641 #ifdef HAVE_ELEMENTARY_X
1642 top = elm_widget_top_get(obj);
1643 if ((top) && (elm_win_xwindow_get(top)))
1645 wd->sel_notify_handler =
1646 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
1647 _event_selection_notify, obj);
1648 wd->sel_clear_handler =
1649 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
1650 _event_selection_clear, obj);
1653 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
1654 _drag_drop_cb, NULL);
1657 entries = eina_list_prepend(entries, obj);
1659 // module - find module for entry
1660 wd->api = _module(obj);
1661 // if found - hook in
1662 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
1664 _mirrored_set(obj, elm_widget_mirrored_get(obj));
1665 // TODO: convert Elementary to subclassing of Evas_Smart_Class
1666 // TODO: and save some bytes, making descriptions per-class and not instance!
1667 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1672 * This sets the entry object not to line wrap. All input will
1673 * be on a single line, and the entry box will extend with user input.
1675 * @param obj The entry object
1676 * @param single_line If true, the text in the entry
1677 * will be on a single line.
1682 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
1684 ELM_CHECK_WIDTYPE(obj, widtype);
1685 Widget_Data *wd = elm_widget_data_get(obj);
1687 if (wd->single_line == single_line) return;
1688 wd->single_line = single_line;
1689 wd->linewrap = EINA_FALSE;
1690 wd->char_linewrap = EINA_FALSE;
1691 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
1696 * This returns true if the entry has been set to single line mode.
1697 * See also elm_entry_single_line_set().
1699 * @param obj The entry object
1700 * @return single_line If true, the text in the entry is set to display
1706 elm_entry_single_line_get(const Evas_Object *obj)
1708 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1709 Widget_Data *wd = elm_widget_data_get(obj);
1710 if (!wd) return EINA_FALSE;
1711 return wd->single_line;
1715 * This sets the entry object to password mode. All text entered
1716 * and/or displayed within the widget will be replaced with asterisks (*).
1718 * @param obj The entry object
1719 * @param password If true, password mode is enabled.
1724 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
1726 ELM_CHECK_WIDTYPE(obj, widtype);
1727 Widget_Data *wd = elm_widget_data_get(obj);
1729 if (wd->password == password) return;
1730 wd->password = password;
1731 wd->single_line = EINA_TRUE;
1732 wd->linewrap = EINA_FALSE;
1733 wd->char_linewrap = EINA_FALSE;
1738 * This returns whether password mode is enabled.
1739 * See also elm_entry_password_set().
1741 * @param obj The entry object
1742 * @return If true, the entry is set to display all characters
1748 elm_entry_password_get(const Evas_Object *obj)
1750 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1751 Widget_Data *wd = elm_widget_data_get(obj);
1752 if (!wd) return EINA_FALSE;
1753 return wd->password;
1757 * This sets the text displayed within the entry to @p entry.
1759 * @param obj The entry object
1760 * @param entry The text to be displayed
1765 elm_entry_entry_set(Evas_Object *obj, const char *entry)
1767 ELM_CHECK_WIDTYPE(obj, widtype);
1768 Widget_Data *wd = elm_widget_data_get(obj);
1770 if (!entry) entry = "";
1771 edje_object_part_text_set(wd->ent, "elm.text", entry);
1772 if (wd->text) eina_stringshare_del(wd->text);
1774 wd->changed = EINA_TRUE;
1779 * This returns the text currently shown in object @p entry.
1780 * See also elm_entry_entry_set().
1782 * @param obj The entry object
1783 * @return The currently displayed text or NULL on failure
1788 elm_entry_entry_get(const Evas_Object *obj)
1790 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1791 Widget_Data *wd = elm_widget_data_get(obj);
1793 if (!wd) return NULL;
1794 if (wd->text) return wd->text;
1795 text = edje_object_part_text_get(wd->ent, "elm.text");
1798 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
1801 eina_stringshare_replace(&wd->text, text);
1806 * This returns EINA_TRUE if the entry is empty/there was an error
1807 * and EINA_FALSE if it is not empty.
1809 * @param obj The entry object
1810 * @return If the entry is empty or not.
1815 elm_entry_is_empty(const Evas_Object *obj)
1817 /* FIXME: until there's support for that in textblock, we just check
1818 * to see if the there is text or not. */
1819 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
1820 Widget_Data *wd = elm_widget_data_get(obj);
1821 const Evas_Object *tb;
1822 Evas_Textblock_Cursor *cur;
1824 if (!wd) return EINA_TRUE;
1825 /* It's a hack until we get the support suggested above.
1826 * We just create a cursor, point it to the begining, and then
1827 * try to advance it, if it can advance, the tb is not empty,
1828 * otherwise it is. */
1829 tb = edje_object_part_object_get(wd->ent, "elm.text");
1830 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
1831 actually, ok for the time being, thsese hackish stuff will be removed
1832 once evas 1.0 is out*/
1833 evas_textblock_cursor_pos_set(cur, 0);
1834 ret = evas_textblock_cursor_char_next(cur);
1835 evas_textblock_cursor_free(cur);
1841 * This returns all selected text within the entry.
1843 * @param obj The entry object
1844 * @return The selected text within the entry or NULL on failure
1849 elm_entry_selection_get(const Evas_Object *obj)
1851 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1852 Widget_Data *wd = elm_widget_data_get(obj);
1853 if (!wd) return NULL;
1854 return edje_object_part_text_selection_get(wd->ent, "elm.text");
1858 * This inserts text in @p entry where the current cursor position.
1860 * This inserts text at the cursor position is as if it was typed
1861 * by the user (note this also allows markup which a user
1862 * can't just "type" as it would be converted to escaped text, so this
1863 * call can be used to insert things like emoticon items or bold push/pop
1864 * tags, other font and color change tags etc.)
1866 * @param obj The entry object
1867 * @param entry The text to insert
1872 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
1874 ELM_CHECK_WIDTYPE(obj, widtype);
1875 Widget_Data *wd = elm_widget_data_get(obj);
1877 edje_object_part_text_insert(wd->ent, "elm.text", entry);
1878 wd->changed = EINA_TRUE;
1883 * This enables word line wrapping in the entry object. It is the opposite
1884 * of elm_entry_single_line_set(). Additionally, setting this disables
1885 * character line wrapping.
1886 * See also elm_entry_line_char_wrap_set().
1888 * @param obj The entry object
1889 * @param wrap If true, the entry will be wrapped once it reaches the end
1890 * of the object. Wrapping will occur at the end of the word before the end of the
1896 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
1898 ELM_CHECK_WIDTYPE(obj, widtype);
1899 Widget_Data *wd = elm_widget_data_get(obj);
1901 if (wd->linewrap == wrap) return;
1902 wd->linewrap = wrap;
1904 wd->char_linewrap = EINA_FALSE;
1909 * This enables character line wrapping in the entry object. It is the opposite
1910 * of elm_entry_single_line_set(). Additionally, setting this disables
1911 * word line wrapping.
1912 * See also elm_entry_line_wrap_set().
1914 * @param obj The entry object
1915 * @param wrap If true, the entry will be wrapped once it reaches the end
1916 * of the object. Wrapping will occur immediately upon reaching the end of the object.
1921 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
1923 ELM_CHECK_WIDTYPE(obj, widtype);
1924 Widget_Data *wd = elm_widget_data_get(obj);
1926 if (wd->char_linewrap == wrap) return;
1927 wd->char_linewrap = wrap;
1928 if(wd->char_linewrap)
1929 wd->linewrap = EINA_FALSE;
1934 * This sets the editable attribute of the entry.
1936 * @param obj The entry object
1937 * @param editable If true, the entry will be editable by the user.
1938 * If false, it will be set to the disabled state.
1943 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
1945 ELM_CHECK_WIDTYPE(obj, widtype);
1946 Widget_Data *wd = elm_widget_data_get(obj);
1948 if (wd->editable == editable) return;
1949 wd->editable = editable;
1952 #ifdef HAVE_ELEMENTARY_X
1954 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
1956 elm_drop_target_del(obj);
1961 * This gets the editable attribute of the entry.
1962 * See also elm_entry_editable_set().
1964 * @param obj The entry object
1965 * @return If true, the entry is editable by the user.
1966 * If false, it is not editable by the user
1971 elm_entry_editable_get(const Evas_Object *obj)
1973 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1974 Widget_Data *wd = elm_widget_data_get(obj);
1975 if (!wd) return EINA_FALSE;
1976 return wd->editable;
1980 * This drops any existing text selection within the entry.
1982 * @param obj The entry object
1987 elm_entry_select_none(Evas_Object *obj)
1989 ELM_CHECK_WIDTYPE(obj, widtype);
1990 Widget_Data *wd = elm_widget_data_get(obj);
1994 wd->selmode = EINA_FALSE;
1995 if (!_elm_config->desktop_entry)
1996 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1997 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1999 wd->have_selection = EINA_FALSE;
2000 edje_object_part_text_select_none(wd->ent, "elm.text");
2004 * This selects all text within the entry.
2006 * @param obj The entry object
2011 elm_entry_select_all(Evas_Object *obj)
2013 ELM_CHECK_WIDTYPE(obj, widtype);
2014 Widget_Data *wd = elm_widget_data_get(obj);
2018 wd->selmode = EINA_FALSE;
2019 if (!_elm_config->desktop_entry)
2020 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2021 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2023 wd->have_selection = EINA_TRUE;
2024 edje_object_part_text_select_all(wd->ent, "elm.text");
2028 * This function returns the geometry of the cursor.
2030 * It's useful if you want to draw something on the cursor (or where it is),
2031 * or for example in the case of scrolled entry where you want to show the
2034 * @param obj The entry object
2035 * @param x returned geometry
2036 * @param y returned geometry
2037 * @param w returned geometry
2038 * @param h returned geometry
2039 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2044 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
2046 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2047 Widget_Data *wd = elm_widget_data_get(obj);
2048 if (!wd) return EINA_FALSE;
2049 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
2054 * This moves the cursor one place to the right within the entry.
2056 * @param obj The entry object
2057 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2062 elm_entry_cursor_next(Evas_Object *obj)
2064 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2065 Widget_Data *wd = elm_widget_data_get(obj);
2066 if (!wd) return EINA_FALSE;
2067 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2071 * This moves the cursor one place to the left within the entry.
2073 * @param obj The entry object
2074 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2079 elm_entry_cursor_prev(Evas_Object *obj)
2081 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2082 Widget_Data *wd = elm_widget_data_get(obj);
2083 if (!wd) return EINA_FALSE;
2084 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2088 * This moves the cursor one line up within the entry.
2090 * @param obj The entry object
2091 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2096 elm_entry_cursor_up(Evas_Object *obj)
2098 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2099 Widget_Data *wd = elm_widget_data_get(obj);
2100 if (!wd) return EINA_FALSE;
2101 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2105 * This moves the cursor one line down within the entry.
2107 * @param obj The entry object
2108 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2113 elm_entry_cursor_down(Evas_Object *obj)
2115 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2116 Widget_Data *wd = elm_widget_data_get(obj);
2117 if (!wd) return EINA_FALSE;
2118 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2122 * This moves the cursor to the beginning of the entry.
2124 * @param obj The entry object
2129 elm_entry_cursor_begin_set(Evas_Object *obj)
2131 ELM_CHECK_WIDTYPE(obj, widtype);
2132 Widget_Data *wd = elm_widget_data_get(obj);
2134 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2138 * This moves the cursor to the end of the entry.
2140 * @param obj The entry object
2145 elm_entry_cursor_end_set(Evas_Object *obj)
2147 ELM_CHECK_WIDTYPE(obj, widtype);
2148 Widget_Data *wd = elm_widget_data_get(obj);
2150 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2154 * This moves the cursor to the beginning of the current line.
2156 * @param obj The entry object
2161 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2163 ELM_CHECK_WIDTYPE(obj, widtype);
2164 Widget_Data *wd = elm_widget_data_get(obj);
2166 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2170 * This moves the cursor to the end of the current line.
2172 * @param obj The entry object
2177 elm_entry_cursor_line_end_set(Evas_Object *obj)
2179 ELM_CHECK_WIDTYPE(obj, widtype);
2180 Widget_Data *wd = elm_widget_data_get(obj);
2182 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2186 * This begins a selection within the entry as though
2187 * the user were holding down the mouse button to make a selection.
2189 * @param obj The entry object
2194 elm_entry_cursor_selection_begin(Evas_Object *obj)
2196 ELM_CHECK_WIDTYPE(obj, widtype);
2197 Widget_Data *wd = elm_widget_data_get(obj);
2199 edje_object_part_text_select_begin(wd->ent, "elm.text");
2203 * This ends a selection within the entry as though
2204 * the user had just released the mouse button while making a selection.
2206 * @param obj The entry object
2211 elm_entry_cursor_selection_end(Evas_Object *obj)
2213 ELM_CHECK_WIDTYPE(obj, widtype);
2214 Widget_Data *wd = elm_widget_data_get(obj);
2216 edje_object_part_text_select_extend(wd->ent, "elm.text");
2220 * TODO: fill this in
2222 * @param obj The entry object
2223 * @return TODO: fill this in
2228 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2230 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2231 Widget_Data *wd = elm_widget_data_get(obj);
2232 if (!wd) return EINA_FALSE;
2233 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2237 * This returns whether the cursor is visible.
2239 * @param obj The entry object
2240 * @return If true, the cursor is visible.
2245 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2247 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2248 Widget_Data *wd = elm_widget_data_get(obj);
2249 if (!wd) return EINA_FALSE;
2250 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2254 * TODO: fill this in
2256 * @param obj The entry object
2257 * @return TODO: fill this in
2262 elm_entry_cursor_content_get(const Evas_Object *obj)
2264 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2265 Widget_Data *wd = elm_widget_data_get(obj);
2266 if (!wd) return NULL;
2267 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2271 * Sets the cursor position in the entry to the given value
2273 * @param obj The entry object
2274 * @param pos The position of the cursor
2279 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
2281 ELM_CHECK_WIDTYPE(obj, widtype);
2282 Widget_Data *wd = elm_widget_data_get(obj);
2284 edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
2285 edje_object_message_signal_process(wd->ent);
2289 * Retrieves the current position of the cursor in the entry
2291 * @param obj The entry object
2292 * @return The cursor position
2297 elm_entry_cursor_pos_get(const Evas_Object *obj)
2299 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2300 Widget_Data *wd = elm_widget_data_get(obj);
2302 return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2306 * This executes a "cut" action on the selected text in the entry.
2308 * @param obj The entry object
2313 elm_entry_selection_cut(Evas_Object *obj)
2315 ELM_CHECK_WIDTYPE(obj, widtype);
2316 Widget_Data *wd = elm_widget_data_get(obj);
2318 _cut(obj, NULL, NULL);
2322 * This executes a "copy" action on the selected text in the entry.
2324 * @param obj The entry object
2329 elm_entry_selection_copy(Evas_Object *obj)
2331 ELM_CHECK_WIDTYPE(obj, widtype);
2332 Widget_Data *wd = elm_widget_data_get(obj);
2334 _copy(obj, NULL, NULL);
2338 * This executes a "paste" action in the entry.
2340 * @param obj The entry object
2345 elm_entry_selection_paste(Evas_Object *obj)
2347 ELM_CHECK_WIDTYPE(obj, widtype);
2348 Widget_Data *wd = elm_widget_data_get(obj);
2350 _paste(obj, NULL, NULL);
2354 * This clears and frees the items in a entry's contextual (right click) menu.
2356 * @param obj The entry object
2361 elm_entry_context_menu_clear(Evas_Object *obj)
2363 ELM_CHECK_WIDTYPE(obj, widtype);
2364 Widget_Data *wd = elm_widget_data_get(obj);
2365 Elm_Entry_Context_Menu_Item *it;
2367 EINA_LIST_FREE(wd->items, it)
2369 eina_stringshare_del(it->label);
2370 eina_stringshare_del(it->icon_file);
2371 eina_stringshare_del(it->icon_group);
2377 * This adds an item to the entry's contextual menu.
2379 * @param obj The entry object
2380 * @param label The item's text label
2381 * @param icon_file The item's icon file
2382 * @param icon_type The item's icon type
2383 * @param func The callback to execute when the item is clicked
2384 * @param data The data to associate with the item for related functions
2389 elm_entry_context_menu_item_add(Evas_Object *obj, const char *label, const char *icon_file, Elm_Icon_Type icon_type, Evas_Smart_Cb func, const void *data)
2391 ELM_CHECK_WIDTYPE(obj, widtype);
2392 Widget_Data *wd = elm_widget_data_get(obj);
2393 Elm_Entry_Context_Menu_Item *it;
2395 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2397 wd->items = eina_list_append(wd->items, it);
2399 it->label = eina_stringshare_add(label);
2400 it->icon_file = eina_stringshare_add(icon_file);
2401 it->icon_type = icon_type;
2403 it->data = (void *)data;
2407 * This disables the entry's contextual (right click) menu.
2409 * @param obj The entry object
2410 * @param disabled If true, the menu is disabled
2415 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2417 ELM_CHECK_WIDTYPE(obj, widtype);
2418 Widget_Data *wd = elm_widget_data_get(obj);
2420 if (wd->context_menu == !disabled) return;
2421 wd->context_menu = !disabled;
2425 * This returns whether the entry's contextual (right click) menu is disabled.
2427 * @param obj The entry object
2428 * @return If true, the menu is disabled
2433 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2435 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2436 Widget_Data *wd = elm_widget_data_get(obj);
2437 if (!wd) return EINA_FALSE;
2438 return !wd->context_menu;
2442 * This appends a custom item provider to the list for that entry
2444 * This appends the given callback. The list is walked from beginning to end
2445 * with each function called given the item href string in the text. If the
2446 * function returns an object handle other than NULL (it should create an
2447 * and object to do this), then this object is used to replace that item. If
2448 * not the next provider is called until one provides an item object, or the
2449 * default provider in entry does.
2451 * @param obj The entry object
2452 * @param func The function called to provide the item object
2453 * @param data The data passed to @p func
2458 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2460 ELM_CHECK_WIDTYPE(obj, widtype);
2461 Widget_Data *wd = elm_widget_data_get(obj);
2463 EINA_SAFETY_ON_NULL_RETURN(func);
2464 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2468 wd->item_providers = eina_list_append(wd->item_providers, ip);
2472 * This prepends a custom item provider to the list for that entry
2474 * This prepends the given callback. See elm_entry_item_provider_append() for
2477 * @param obj The entry object
2478 * @param func The function called to provide the item object
2479 * @param data The data passed to @p func
2484 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2486 ELM_CHECK_WIDTYPE(obj, widtype);
2487 Widget_Data *wd = elm_widget_data_get(obj);
2489 EINA_SAFETY_ON_NULL_RETURN(func);
2490 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2494 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2498 * This removes a custom item provider to the list for that entry
2500 * This removes the given callback. See elm_entry_item_provider_append() for
2503 * @param obj The entry object
2504 * @param func The function called to provide the item object
2505 * @param data The data passed to @p func
2510 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2512 ELM_CHECK_WIDTYPE(obj, widtype);
2513 Widget_Data *wd = elm_widget_data_get(obj);
2515 Elm_Entry_Item_Provider *ip;
2517 EINA_SAFETY_ON_NULL_RETURN(func);
2518 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2520 if ((ip->func == func) && ((!data) || (ip->data == data)))
2522 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2530 * Append a filter function for text inserted in the entry
2532 * Append the given callback to the list. This functions will be called
2533 * whenever any text is inserted into the entry, with the text to be inserted
2534 * as a parameter. The callback function is free to alter the text in any way
2535 * it wants, but it must remember to free the given pointer and update it.
2536 * If the new text is to be discarded, the function can free it and set it text
2537 * parameter to NULL. This will also prevent any following filters from being
2540 * @param obj The entry object
2541 * @param func The function to use as text filter
2542 * @param data User data to pass to @p func
2547 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2550 Elm_Entry_Text_Filter *tf;
2551 ELM_CHECK_WIDTYPE(obj, widtype);
2553 wd = elm_widget_data_get(obj);
2555 EINA_SAFETY_ON_NULL_RETURN(func);
2557 tf = _filter_new(func, data);
2560 wd->text_filters = eina_list_append(wd->text_filters, tf);
2564 * Prepend a filter function for text insdrted in the entry
2566 * Prepend the given callback to the list. See elm_entry_text_filter_append()
2567 * for more information
2569 * @param obj The entry object
2570 * @param func The function to use as text filter
2571 * @param data User data to pass to @p func
2576 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2579 Elm_Entry_Text_Filter *tf;
2580 ELM_CHECK_WIDTYPE(obj, widtype);
2582 wd = elm_widget_data_get(obj);
2584 EINA_SAFETY_ON_NULL_RETURN(func);
2586 tf = _filter_new(func, data);
2589 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
2593 * Remove a filter from the list
2595 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
2596 * for more information.
2598 * @param obj The entry object
2599 * @param func The filter function to remove
2600 * @param data The user data passed when adding the function
2605 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2609 Elm_Entry_Text_Filter *tf;
2610 ELM_CHECK_WIDTYPE(obj, widtype);
2612 wd = elm_widget_data_get(obj);
2614 EINA_SAFETY_ON_NULL_RETURN(func);
2616 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2618 if ((tf->func == func) && ((!data) || (tf->data == data)))
2620 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
2628 * This converts a markup (HTML-like) string into UTF-8.
2629 * Returning string is obtained with malloc.
2630 * After use the returned string, it should be freed.
2632 * @param s The string (in markup) to be converted
2633 * @return The converted string (in UTF-8). It should be freed.
2638 elm_entry_markup_to_utf8(const char *s)
2640 char *ss = _elm_util_mkup_to_text(s);
2641 if (!ss) ss = strdup("");
2646 * This converts a UTF-8 string into markup (HTML-like).
2647 * Returning string is obtained with malloc.
2648 * After use the returned string, it should be freed.
2650 * @param s The string (in UTF-8) to be converted
2651 * @return The converted string (in markup). It should be freed.
2656 elm_entry_utf8_to_markup(const char *s)
2658 char *ss = _elm_util_text_to_mkup(s);
2659 if (!ss) ss = strdup("");
2664 * Filter inserted text based on user defined character and byte limits
2666 * Add this filter to an entry to limit the characters that it will accept
2667 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
2668 * The funtion works on the UTF-8 representation of the string, converting
2669 * it from the set markup, thus not accounting for any format in it.
2671 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
2672 * it as data when setting the filter. In it it's possible to set limits
2673 * by character count or bytes (any of them is disabled if 0), and both can
2674 * be set at the same time. In that case, it first checks for characters,
2677 * The function will cut the inserted text in order to allow only the first
2678 * number of characters that are still allowed. The cut is made in
2679 * characters, even when limiting by bytes, in order to always contain
2680 * valid ones and avoid half unicode characters making it in.
2685 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
2687 Elm_Entry_Filter_Limit_Size *lim = data;
2690 const char *(*text_get)(const Evas_Object *);
2691 const char *widget_type;
2693 EINA_SAFETY_ON_NULL_RETURN(data);
2694 EINA_SAFETY_ON_NULL_RETURN(entry);
2695 EINA_SAFETY_ON_NULL_RETURN(text);
2697 /* hack. I don't want to copy the entire function to work with
2699 widget_type = elm_widget_type_get(entry);
2700 if (!strcmp(widget_type, "entry"))
2701 text_get = elm_entry_entry_get;
2702 else if (!strcmp(widget_type, "scrolled_entry"))
2703 text_get = elm_scrolled_entry_entry_get;
2707 current = elm_entry_markup_to_utf8(text_get(entry));
2709 if (lim->max_char_count > 0)
2712 len = evas_string_char_len_get(current);
2713 if (len >= lim->max_char_count)
2720 newlen = evas_string_char_len_get(*text);
2721 cut = strlen(*text);
2722 while ((len + newlen) > lim->max_char_count)
2724 cut = evas_string_char_prev_get(*text, cut, NULL);
2730 if (lim->max_byte_count > 0)
2732 len = strlen(current);
2733 if (len >= lim->max_byte_count)
2740 newlen = strlen(*text);
2741 while ((len + newlen) > lim->max_byte_count)
2743 int p = evas_string_char_prev_get(*text, newlen, NULL);
2744 newlen -= (newlen - p);
2747 (*text)[newlen] = 0;
2758 * Filter inserted text based on accepted or rejected sets of characters
2760 * Add this filter to an entry to restrict the set of accepted characters
2761 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
2762 * This structure contains both accepted and rejected sets, but they are
2763 * mutually exclusive. If accepted is set, it will be used, otherwise it
2764 * goes on to the rejected set.
2767 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
2769 Elm_Entry_Filter_Accept_Set *as = data;
2773 int read_idx, last_read_idx = 0, read_char;
2775 EINA_SAFETY_ON_NULL_RETURN(data);
2776 EINA_SAFETY_ON_NULL_RETURN(text);
2778 if ((!as->accepted) && (!as->rejected))
2784 goes_in = EINA_TRUE;
2789 goes_in = EINA_FALSE;
2793 read_idx = evas_string_char_next_get(*text, 0, &read_char);
2796 int cmp_idx, cmp_char;
2797 Eina_Bool in_set = EINA_FALSE;
2799 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
2802 if (read_char == cmp_char)
2807 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
2809 if (in_set == goes_in)
2811 int size = read_idx - last_read_idx;
2812 const char *src = (*text) + last_read_idx;
2814 memcpy(insert, *text + last_read_idx, size);
2817 last_read_idx = read_idx;
2818 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
2824 * This sets the file (and implicitly loads it) for the text to display and
2825 * then edit. All changes are written back to the file after a short delay if
2826 * the entry object is set to autosave.
2828 * @param obj The entry object
2829 * @param file The path to the file to load and save
2830 * @param format The file format
2835 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
2837 ELM_CHECK_WIDTYPE(obj, widtype);
2838 Widget_Data *wd = elm_widget_data_get(obj);
2840 if (wd->delay_write)
2842 ecore_timer_del(wd->delay_write);
2843 wd->delay_write = NULL;
2845 if (wd->autosave) _save(obj);
2846 eina_stringshare_replace(&wd->file, file);
2847 wd->format = format;
2852 * Gets the file to load and save and the file format
2854 * @param obj The entry object
2855 * @param file The path to the file to load and save
2856 * @param format The file format
2861 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
2863 ELM_CHECK_WIDTYPE(obj, widtype);
2864 Widget_Data *wd = elm_widget_data_get(obj);
2866 if (file) *file = wd->file;
2867 if (format) *format = wd->format;
2871 * This function writes any changes made to the file set with
2872 * elm_entry_file_set()
2874 * @param obj The entry object
2879 elm_entry_file_save(Evas_Object *obj)
2881 ELM_CHECK_WIDTYPE(obj, widtype);
2882 Widget_Data *wd = elm_widget_data_get(obj);
2884 if (wd->delay_write)
2886 ecore_timer_del(wd->delay_write);
2887 wd->delay_write = NULL;
2890 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
2894 * This sets the entry object to 'autosave' the loaded text file or not.
2896 * @param obj The entry object
2897 * @param autosave Autosave the loaded file or not
2902 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
2904 ELM_CHECK_WIDTYPE(obj, widtype);
2905 Widget_Data *wd = elm_widget_data_get(obj);
2907 wd->autosave = !!autosave;
2911 * This gets the entry object's 'autosave' status.
2913 * @param obj The entry object
2914 * @return Autosave the loaded file or not
2919 elm_entry_autosave_get(const Evas_Object *obj)
2921 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2922 Widget_Data *wd = elm_widget_data_get(obj);
2923 if (!wd) return EINA_FALSE;
2924 return wd->autosave;
2928 * Control pasting of text and images for the widget.
2930 * Normally the entry allows both text and images to be pasted. By setting
2931 * textonly to be true, this prevents images from being pasted.
2933 * Note this only changes the behaviour of text.
2935 * @param obj The entry object
2936 * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is text+image+other.
2941 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
2943 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
2944 ELM_CHECK_WIDTYPE(obj, widtype);
2945 Widget_Data *wd = elm_widget_data_get(obj);
2947 textonly = !!textonly;
2948 if (wd->textonly == textonly) return;
2949 wd->textonly = !!textonly;
2950 if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
2951 #ifdef HAVE_ELEMENTARY_X
2952 elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
2957 * Getting elm_entry text paste/drop mode.
2959 * In textonly mode, only text may be pasted or dropped into the widget.
2961 * @param obj The entry object
2962 * @return If the widget only accepts text from pastes.
2967 elm_entry_cnp_textonly_get(Evas_Object *obj)
2969 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2970 Widget_Data *wd = elm_widget_data_get(obj);
2971 if (!wd) return EINA_FALSE;
2972 return wd->textonly;