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 /* Maximum chunk size to be inserted to the entry at once
97 * FIXME: This size is arbitrary, should probably choose a better size.
98 * Possibly also find a way to set it to a low value for weak computers,
99 * and to a big value for better computers. */
100 #define _CHUNK_SIZE 10000
102 typedef struct _Mod_Api Mod_Api;
104 typedef struct _Widget_Data Widget_Data;
105 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
106 typedef struct _Elm_Entry_Item_Provider Elm_Entry_Item_Provider;
107 typedef struct _Elm_Entry_Text_Filter Elm_Entry_Text_Filter;
112 Evas_Object *hoversel;
113 Ecore_Job *deferred_recalc_job;
114 Ecore_Event_Handler *sel_notify_handler;
115 Ecore_Event_Handler *sel_clear_handler;
116 Ecore_Timer *longpress_timer;
117 Ecore_Timer *delay_write;
118 /* for deferred appending */
119 Ecore_Idler *append_text_idler;
120 char *append_text_left;
121 int append_text_position;
123 /* Only for clipboard */
127 Elm_Text_Format format;
129 Evas_Coord downx, downy;
131 Eina_List *item_providers;
132 Eina_List *text_filters;
133 Ecore_Job *hovdeljob;
134 Mod_Api *api; // module api if supplied
136 Elm_Wrap_Type linewrap;
137 Eina_Bool changed : 1;
138 Eina_Bool single_line : 1;
139 Eina_Bool password : 1;
140 Eina_Bool editable : 1;
141 Eina_Bool selection_asked : 1;
142 Eina_Bool have_selection : 1;
143 Eina_Bool selmode : 1;
144 Eina_Bool deferred_cur : 1;
145 Eina_Bool cur_changed : 1;
146 Eina_Bool disabled : 1;
147 Eina_Bool context_menu : 1;
148 Eina_Bool drag_selection_asked : 1;
149 Eina_Bool can_write : 1;
150 Eina_Bool autosave : 1;
151 Eina_Bool textonly : 1;
152 Eina_Bool usedown : 1;
155 struct _Elm_Entry_Context_Menu_Item
159 const char *icon_file;
160 const char *icon_group;
161 Elm_Icon_Type icon_type;
166 struct _Elm_Entry_Item_Provider
168 Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
172 struct _Elm_Entry_Text_Filter
174 void (*func) (void *data, Evas_Object *entry, char **text);
178 static const char *widtype = NULL;
180 #ifdef HAVE_ELEMENTARY_X
181 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
183 static void _del_hook(Evas_Object *obj);
184 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
185 static void _theme_hook(Evas_Object *obj);
186 static void _disable_hook(Evas_Object *obj);
187 static void _sizing_eval(Evas_Object *obj);
188 static void _on_focus_hook(void *data, Evas_Object *obj);
189 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
190 static const char *_getbase(Evas_Object *obj);
191 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
192 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
193 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
194 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
195 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
196 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
197 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
198 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
200 static const char SIG_CHANGED[] = "changed";
201 static const char SIG_ACTIVATED[] = "activated";
202 static const char SIG_PRESS[] = "press";
203 static const char SIG_LONGPRESSED[] = "longpressed";
204 static const char SIG_CLICKED[] = "clicked";
205 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
206 static const char SIG_FOCUSED[] = "focused";
207 static const char SIG_UNFOCUSED[] = "unfocused";
208 static const char SIG_SELECTION_PASTE[] = "selection,paste";
209 static const char SIG_SELECTION_COPY[] = "selection,copy";
210 static const char SIG_SELECTION_CUT[] = "selection,cut";
211 static const char SIG_SELECTION_START[] = "selection,start";
212 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
213 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
214 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
215 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
216 static const Evas_Smart_Cb_Description _signals[] = {
220 {SIG_LONGPRESSED, ""},
222 {SIG_CLICKED_DOUBLE, ""},
225 {SIG_SELECTION_PASTE, ""},
226 {SIG_SELECTION_COPY, ""},
227 {SIG_SELECTION_CUT, ""},
228 {SIG_SELECTION_START, ""},
229 {SIG_SELECTION_CHANGED, ""},
230 {SIG_SELECTION_CLEARED, ""},
231 {SIG_CURSOR_CHANGED, ""},
232 {SIG_ANCHOR_CLICKED, ""},
236 static Eina_List *entries = NULL;
240 void (*obj_hook) (Evas_Object *obj);
241 void (*obj_unhook) (Evas_Object *obj);
242 void (*obj_longpress) (Evas_Object *obj);
246 _module(Evas_Object *obj __UNUSED__)
248 static Elm_Module *m = NULL;
249 if (m) goto ok; // already found - just use
250 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
252 m->api = malloc(sizeof(Mod_Api));
253 if (!m->api) return NULL;
254 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
255 _elm_module_symbol_get(m, "obj_hook");
256 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
257 _elm_module_symbol_get(m, "obj_unhook");
258 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
259 _elm_module_symbol_get(m, "obj_longpress");
260 ok: // ok - return api
265 _buf_append(char *buf, const char *str, int *len, int *alloc)
267 int len2 = strlen(str);
268 if ((*len + len2) >= *alloc)
270 char *buf2 = realloc(buf, *alloc + len2 + 512);
271 if (!buf2) return NULL;
273 *alloc += (512 + len2);
275 strcpy(buf + *len, str);
281 _load_file(const char *file)
285 int alloc = 0, len = 0;
286 char *text = NULL, buf[16384 + 1];
288 f = fopen(file, "rb");
290 while ((size = fread(buf, 1, sizeof(buf) - 1, f)))
294 tmp_text = _buf_append(text, buf, &len, &alloc);
295 if (!tmp_text) break;
303 _load_plain(const char *file)
307 text = _load_file(file);
312 text2 = elm_entry_utf8_to_markup(text);
320 _load(Evas_Object *obj)
322 Widget_Data *wd = elm_widget_data_get(obj);
327 elm_entry_entry_set(obj, "");
332 case ELM_TEXT_FORMAT_PLAIN_UTF8:
333 text = _load_plain(wd->file);
335 case ELM_TEXT_FORMAT_MARKUP_UTF8:
336 text = _load_file(wd->file);
344 elm_entry_entry_set(obj, text);
348 elm_entry_entry_set(obj, "");
352 _save_markup_utf8(const char *file, const char *text)
356 if ((!text) || (!text[0]))
358 ecore_file_unlink(file);
361 f = fopen(file, "wb");
364 // FIXME: report a write error
367 fputs(text, f); // FIXME: catch error
372 _save_plain_utf8(const char *file, const char *text)
376 text2 = elm_entry_markup_to_utf8(text);
379 _save_markup_utf8(file, text2);
384 _save(Evas_Object *obj)
386 Widget_Data *wd = elm_widget_data_get(obj);
388 if (!wd->file) return;
391 case ELM_TEXT_FORMAT_PLAIN_UTF8:
392 _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
394 case ELM_TEXT_FORMAT_MARKUP_UTF8:
395 _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
403 _delay_write(void *data)
405 Widget_Data *wd = elm_widget_data_get(data);
406 if (!wd) return ECORE_CALLBACK_CANCEL;
408 wd->delay_write = NULL;
409 return ECORE_CALLBACK_CANCEL;
412 static Elm_Entry_Text_Filter *
413 _filter_new(void (*func) (void *data, Evas_Object *entry, char **text), void *data)
415 Elm_Entry_Text_Filter *tf = ELM_NEW(Elm_Entry_Text_Filter);
416 if (!tf) return NULL;
419 if (func == elm_entry_filter_limit_size)
421 Elm_Entry_Filter_Limit_Size *lim = data, *lim2;
428 lim2 = malloc(sizeof(Elm_Entry_Filter_Limit_Size));
434 memcpy(lim2, lim, sizeof(Elm_Entry_Filter_Limit_Size));
437 else if (func == elm_entry_filter_accept_set)
439 Elm_Entry_Filter_Accept_Set *as = data, *as2;
446 as2 = malloc(sizeof(Elm_Entry_Filter_Accept_Set));
453 as2->accepted = eina_stringshare_add(as->accepted);
455 as2->accepted = NULL;
457 as2->rejected = eina_stringshare_add(as->rejected);
459 as2->rejected = NULL;
468 _filter_free(Elm_Entry_Text_Filter *tf)
470 if (tf->func == elm_entry_filter_limit_size)
472 Elm_Entry_Filter_Limit_Size *lim = tf->data;
475 else if (tf->func == elm_entry_filter_accept_set)
477 Elm_Entry_Filter_Accept_Set *as = tf->data;
480 if (as->accepted) eina_stringshare_del(as->accepted);
481 if (as->rejected) eina_stringshare_del(as->rejected);
489 _del_pre_hook(Evas_Object *obj)
491 Widget_Data *wd = elm_widget_data_get(obj);
495 ecore_timer_del(wd->delay_write);
496 wd->delay_write = NULL;
497 if (wd->autosave) _save(obj);
502 _del_hook(Evas_Object *obj)
504 Widget_Data *wd = elm_widget_data_get(obj);
505 Elm_Entry_Context_Menu_Item *it;
506 Elm_Entry_Item_Provider *ip;
507 Elm_Entry_Text_Filter *tf;
509 if (wd->file) eina_stringshare_del(wd->file);
511 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
512 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
514 entries = eina_list_remove(entries, obj);
515 #ifdef HAVE_ELEMENTARY_X
516 if (wd->sel_notify_handler)
517 ecore_event_handler_del(wd->sel_notify_handler);
518 if (wd->sel_clear_handler)
519 ecore_event_handler_del(wd->sel_clear_handler);
521 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
522 if (wd->text) eina_stringshare_del(wd->text);
523 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
524 if (wd->append_text_idler)
526 ecore_idler_del(wd->append_text_idler);
527 free(wd->append_text_left);
528 wd->append_text_left = NULL;
529 wd->append_text_idler = NULL;
531 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
532 EINA_LIST_FREE(wd->items, it)
534 eina_stringshare_del(it->label);
535 eina_stringshare_del(it->icon_file);
536 eina_stringshare_del(it->icon_group);
539 EINA_LIST_FREE(wd->item_providers, ip)
543 EINA_LIST_FREE(wd->text_filters, tf)
551 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
553 Widget_Data *wd = elm_widget_data_get(obj);
554 edje_object_mirrored_set(wd->ent, rtl);
558 _theme_hook(Evas_Object *obj)
560 Widget_Data *wd = elm_widget_data_get(obj);
562 _elm_widget_mirrored_reload(obj);
563 _mirrored_set(obj, elm_widget_mirrored_get(obj));
565 t = eina_stringshare_add(elm_entry_entry_get(obj));
566 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
567 if (_elm_config->desktop_entry)
568 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
569 elm_entry_entry_set(obj, t);
570 eina_stringshare_del(t);
571 if (elm_widget_disabled_get(obj))
572 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
573 elm_entry_cursor_pos_set(obj, wd->cursor_pos);
574 if (elm_widget_focus_get(obj))
575 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
576 edje_object_message_signal_process(wd->ent);
577 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
582 _disable_hook(Evas_Object *obj)
584 Widget_Data *wd = elm_widget_data_get(obj);
586 if (elm_widget_disabled_get(obj))
588 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
589 wd->disabled = EINA_TRUE;
593 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
594 wd->disabled = EINA_FALSE;
599 _elm_win_recalc_job(void *data)
601 Widget_Data *wd = elm_widget_data_get(data);
602 Evas_Coord minh = -1, resw = -1, minw = -1;
604 wd->deferred_recalc_job = NULL;
606 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, NULL);
607 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
608 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
609 /* This is a hack to workaround the way min size hints are treated.
610 * If the minimum width is smaller than the restricted width, it means
611 * the mininmum doesn't matter. */
614 Evas_Coord ominw = -1;
615 evas_object_size_hint_min_get(data, &ominw, NULL);
618 evas_object_size_hint_min_set(data, minw, minh);
620 evas_object_size_hint_max_set(data, -1, minh);
622 if (wd->deferred_cur)
624 Evas_Coord cx, cy, cw, ch;
625 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
629 elm_widget_show_region_set(data, cx, cy, cw, ch);
630 wd->cur_changed = EINA_FALSE;
636 _recalc_cursor_geometry(Evas_Object *obj)
638 Widget_Data *wd = elm_widget_data_get(obj);
640 evas_object_smart_callback_call(obj, SIG_CURSOR_CHANGED, NULL);
641 if (!wd->deferred_recalc_job)
643 Evas_Coord cx, cy, cw, ch;
644 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
648 elm_widget_show_region_set(obj, cx, cy, cw, ch);
649 wd->cur_changed = EINA_FALSE;
654 wd->deferred_cur = EINA_TRUE;
659 _sizing_eval(Evas_Object *obj)
661 Widget_Data *wd = elm_widget_data_get(obj);
662 Evas_Coord minw = -1, minh = -1;
663 Evas_Coord resw, resh;
667 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
668 if ((resw == wd->lastw) && (!wd->changed)) return;
669 wd->changed = EINA_FALSE;
671 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
672 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
676 edje_object_size_min_calc(wd->ent, &minw, &minh);
677 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
678 evas_object_size_hint_min_set(obj, minw, minh);
680 evas_object_size_hint_max_set(obj, -1, minh);
683 _recalc_cursor_geometry(obj);
687 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
689 Widget_Data *wd = elm_widget_data_get(obj);
690 Evas_Object *top = elm_widget_top_get(obj);
692 if (!wd->editable) return;
693 if (elm_widget_focus_get(obj))
695 evas_object_focus_set(wd->ent, EINA_TRUE);
696 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
697 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
698 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
702 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
703 evas_object_focus_set(wd->ent, EINA_FALSE);
704 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
705 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
710 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
712 Widget_Data *wd = elm_widget_data_get(obj);
714 edje_object_signal_emit(wd->ent, emission, source);
718 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
720 Widget_Data *wd = elm_widget_data_get(obj);
722 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
726 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
728 Widget_Data *wd = elm_widget_data_get(obj);
729 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
734 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
736 Widget_Data *wd = elm_widget_data_get(obj);
737 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
741 _hoversel_position(Evas_Object *obj)
743 Widget_Data *wd = elm_widget_data_get(obj);
744 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
749 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
758 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
760 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
771 evas_object_move(wd->hoversel, x + cx, y + cy);
772 evas_object_resize(wd->hoversel, cw, ch);
776 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
778 Widget_Data *wd = elm_widget_data_get(data);
780 if (wd->hoversel) _hoversel_position(data);
784 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
786 Widget_Data *wd = elm_widget_data_get(data);
792 if (wd->hoversel) _hoversel_position(data);
793 // Evas_Coord ww, hh;
794 // evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
798 _hover_del(void *data)
800 Widget_Data *wd = elm_widget_data_get(data);
805 evas_object_del(wd->hoversel);
808 wd->hovdeljob = NULL;
812 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
814 Widget_Data *wd = elm_widget_data_get(data);
817 if (wd->hoversel) evas_object_hide(wd->hoversel);
820 if (!_elm_config->desktop_entry)
823 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
826 elm_widget_scroll_freeze_pop(data);
827 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
828 wd->hovdeljob = ecore_job_add(_hover_del, data);
832 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
834 Widget_Data *wd = elm_widget_data_get(data);
836 wd->selmode = EINA_TRUE;
837 edje_object_part_text_select_none(wd->ent, "elm.text");
838 if (!_elm_config->desktop_entry)
841 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
843 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
844 if (!_elm_config->desktop_entry)
845 elm_widget_scroll_hold_push(data);
849 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
851 Widget_Data *wd = elm_widget_data_get(data);
853 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
854 if (wd->sel_notify_handler)
856 #ifdef HAVE_ELEMENTARY_X
857 Elm_Sel_Format formats;
858 wd->selection_asked = EINA_TRUE;
859 formats = ELM_SEL_FORMAT_MARKUP;
861 formats |= ELM_SEL_FORMAT_IMAGE;
862 elm_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL);
868 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
870 Widget_Data *wd = elm_widget_data_get(obj);
874 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
875 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
876 if (seltype == ELM_SEL_CLIPBOARD)
877 eina_stringshare_replace(&wd->cut_sel, sel);
881 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
883 Widget_Data *wd = elm_widget_data_get(data);
886 wd->selmode = EINA_FALSE;
887 if (!_elm_config->desktop_entry)
888 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
889 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
890 if (!_elm_config->desktop_entry)
891 elm_widget_scroll_hold_pop(data);
892 _store_selection(ELM_SEL_CLIPBOARD, data);
893 edje_object_part_text_insert(wd->ent, "elm.text", "");
894 edje_object_part_text_select_none(wd->ent, "elm.text");
898 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
900 Widget_Data *wd = elm_widget_data_get(data);
902 wd->selmode = EINA_FALSE;
903 if (!_elm_config->desktop_entry)
905 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
906 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
907 elm_widget_scroll_hold_pop(data);
909 _store_selection(ELM_SEL_CLIPBOARD, data);
910 // edje_object_part_text_select_none(wd->ent, "elm.text");
914 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
916 Widget_Data *wd = elm_widget_data_get(data);
918 wd->selmode = EINA_FALSE;
919 if (!_elm_config->desktop_entry)
920 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
921 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
922 if (!_elm_config->desktop_entry)
923 elm_widget_scroll_hold_pop(data);
924 edje_object_part_text_select_none(wd->ent, "elm.text");
928 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
930 Elm_Entry_Context_Menu_Item *it = data;
931 Evas_Object *obj2 = it->obj;
932 if (it->func) it->func(it->data, obj2, NULL);
936 _menu_press(Evas_Object *obj)
938 Widget_Data *wd = elm_widget_data_get(obj);
941 const Elm_Entry_Context_Menu_Item *it;
943 if ((wd->api) && (wd->api->obj_longpress))
945 wd->api->obj_longpress(obj);
947 else if (wd->context_menu)
949 const char *context_menu_orientation;
951 if (wd->hoversel) evas_object_del(wd->hoversel);
952 else elm_widget_scroll_freeze_push(obj);
953 wd->hoversel = elm_hoversel_add(obj);
954 context_menu_orientation = edje_object_data_get
955 (wd->ent, "context_menu_orientation");
956 if ((context_menu_orientation) &&
957 (!strcmp(context_menu_orientation, "horizontal")))
958 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
959 elm_object_style_set(wd->hoversel, "entry");
960 elm_widget_sub_object_add(obj, wd->hoversel);
961 elm_hoversel_label_set(wd->hoversel, "Text");
962 top = elm_widget_top_get(obj);
963 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
964 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, obj);
965 if (wd->have_selection)
969 if (wd->have_selection)
971 elm_hoversel_item_add(wd->hoversel, E_("Copy"), NULL, ELM_ICON_NONE,
974 elm_hoversel_item_add(wd->hoversel, E_("Cut"), NULL, ELM_ICON_NONE,
977 elm_hoversel_item_add(wd->hoversel, E_("Cancel"), NULL, ELM_ICON_NONE,
985 if (!_elm_config->desktop_entry)
988 elm_hoversel_item_add(wd->hoversel, E_("Select"), NULL, ELM_ICON_NONE,
991 if (1) // need way to detect if someone has a selection
994 elm_hoversel_item_add(wd->hoversel, E_("Paste"), NULL, ELM_ICON_NONE,
999 EINA_LIST_FOREACH(wd->items, l, it)
1001 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
1002 it->icon_type, _item_clicked, it);
1006 _hoversel_position(obj);
1007 evas_object_show(wd->hoversel);
1008 elm_hoversel_hover_begin(wd->hoversel);
1010 if (!_elm_config->desktop_entry)
1012 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1013 edje_object_part_text_select_abort(wd->ent, "elm.text");
1019 _long_press(void *data)
1021 Widget_Data *wd = elm_widget_data_get(data);
1022 if (!wd) return ECORE_CALLBACK_CANCEL;
1024 wd->longpress_timer = NULL;
1025 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
1026 return ECORE_CALLBACK_CANCEL;
1030 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1032 Widget_Data *wd = elm_widget_data_get(data);
1033 Evas_Event_Mouse_Down *ev = event_info;
1035 if (wd->disabled) return;
1036 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1037 wd->downx = ev->canvas.x;
1038 wd->downy = ev->canvas.y;
1039 if (ev->button == 1)
1041 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
1042 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1047 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1049 Widget_Data *wd = elm_widget_data_get(data);
1050 Evas_Event_Mouse_Up *ev = event_info;
1052 if (wd->disabled) return;
1053 if (ev->button == 1)
1055 if (wd->longpress_timer)
1057 ecore_timer_del(wd->longpress_timer);
1058 wd->longpress_timer = NULL;
1061 else if (ev->button == 3)
1069 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1071 Widget_Data *wd = elm_widget_data_get(data);
1072 Evas_Event_Mouse_Move *ev = event_info;
1074 if (wd->disabled) return;
1077 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1079 if (wd->longpress_timer)
1081 ecore_timer_del(wd->longpress_timer);
1082 wd->longpress_timer = NULL;
1085 else if (wd->longpress_timer)
1089 dx = wd->downx - ev->cur.canvas.x;
1091 dy = wd->downy - ev->cur.canvas.y;
1094 ((_elm_config->finger_size / 2) *
1095 (_elm_config->finger_size / 2)))
1097 ecore_timer_del(wd->longpress_timer);
1098 wd->longpress_timer = NULL;
1102 else if (wd->longpress_timer)
1106 dx = wd->downx - ev->cur.canvas.x;
1108 dy = wd->downy - ev->cur.canvas.y;
1111 ((_elm_config->finger_size / 2) *
1112 (_elm_config->finger_size / 2)))
1114 ecore_timer_del(wd->longpress_timer);
1115 wd->longpress_timer = NULL;
1121 _getbase(Evas_Object *obj)
1123 Widget_Data *wd = elm_widget_data_get(obj);
1124 if (!wd) return "base";
1127 if (wd->password) return "base-password";
1130 if (wd->single_line) return "base-single";
1133 switch (wd->linewrap)
1136 return "base-charwrap";
1139 case ELM_WRAP_MIXED:
1140 return "base-mixedwrap";
1143 return "base-nowrap";
1150 if (wd->password) return "base-password";
1153 if (wd->single_line) return "base-single-noedit";
1156 switch (wd->linewrap)
1159 return "base-noedit-charwrap";
1161 return "base-noedit";
1162 case ELM_WRAP_MIXED:
1163 return "base-noedit-mixedwrap";
1166 return "base-nowrap-noedit";
1175 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1177 Widget_Data *wd = elm_widget_data_get(data);
1180 wd->changed = EINA_TRUE;
1181 /* Reset the size hints which are no more relevant.
1182 * Keep the height, this is a hack, but doesn't really matter
1183 * cause we'll re-eval in a moment. */
1184 evas_object_size_hint_min_get(data, NULL, &minh);
1185 evas_object_size_hint_min_set(data, -1, minh);
1187 if (wd->text) eina_stringshare_del(wd->text);
1189 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1190 if (wd->delay_write)
1192 ecore_timer_del(wd->delay_write);
1193 wd->delay_write = NULL;
1195 if ((!wd->autosave) || (!wd->file)) return;
1196 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1200 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1202 Widget_Data *wd = elm_widget_data_get(data);
1206 EINA_LIST_FOREACH(entries, l, entry)
1208 if (entry != data) elm_entry_select_none(entry);
1210 wd->have_selection = EINA_TRUE;
1211 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1212 #ifdef HAVE_ELEMENTARY_X
1213 if (wd->sel_notify_handler)
1215 const char *txt = elm_entry_selection_get(data);
1218 top = elm_widget_top_get(data);
1219 if ((top) && (elm_win_xwindow_get(top)))
1220 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1226 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1228 Widget_Data *wd = elm_widget_data_get(data);
1230 wd->have_selection = EINA_TRUE;
1231 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1232 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1233 elm_entry_selection_get(data));
1237 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1239 Widget_Data *wd = elm_widget_data_get(data);
1241 if (!wd->have_selection) return;
1242 wd->have_selection = EINA_FALSE;
1243 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1244 if (wd->sel_notify_handler)
1248 #ifdef HAVE_ELEMENTARY_X
1251 top = elm_widget_top_get(data);
1252 if ((top) && (elm_win_xwindow_get(top)))
1253 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1256 eina_stringshare_del(wd->cut_sel);
1261 #ifdef HAVE_ELEMENTARY_X
1264 top = elm_widget_top_get(data);
1265 if ((top) && (elm_win_xwindow_get(top)))
1266 elm_selection_clear(ELM_SEL_PRIMARY, data);
1273 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1275 Widget_Data *wd = elm_widget_data_get(data);
1277 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1278 if (wd->sel_notify_handler)
1280 #ifdef HAVE_ELEMENTARY_X
1283 top = elm_widget_top_get(data);
1284 if ((top) && (elm_win_xwindow_get(top)))
1286 wd->selection_asked = EINA_TRUE;
1287 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
1295 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1297 Widget_Data *wd = elm_widget_data_get(data);
1299 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1300 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1301 elm_entry_selection_get(data));
1305 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1307 Widget_Data *wd = elm_widget_data_get(data);
1309 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1310 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1311 elm_entry_selection_get(data));
1312 edje_object_part_text_insert(wd->ent, "elm.text", "");
1313 wd->changed = EINA_TRUE;
1318 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1320 Widget_Data *wd = elm_widget_data_get(data);
1322 wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1323 wd->cur_changed = EINA_TRUE;
1324 _recalc_cursor_geometry(data);
1328 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1330 Widget_Data *wd = elm_widget_data_get(data);
1335 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1337 Widget_Data *wd = elm_widget_data_get(data);
1342 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1344 Widget_Data *wd = elm_widget_data_get(data);
1345 Elm_Entry_Anchor_Info ei;
1346 char *buf2, *p, *p2, *n;
1348 p = strrchr(emission, ',');
1351 const Eina_List *geoms;
1355 while (p2 >= emission)
1357 if (*p2 == ',') break;
1361 buf2 = alloca(5 + p - p2);
1362 strncpy(buf2, p2, p - p2);
1365 ei.button = atoi(buf2);
1366 ei.x = ei.y = ei.w = ei.h = 0;
1368 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1371 Evas_Textblock_Rectangle *r;
1373 Evas_Coord px, py, x, y;
1375 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1376 evas_pointer_canvas_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1377 EINA_LIST_FOREACH(geoms, l, r)
1379 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1380 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1391 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1396 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1398 Widget_Data *wd = elm_widget_data_get(data);
1403 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1405 Widget_Data *wd = elm_widget_data_get(data);
1410 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1412 Widget_Data *wd = elm_widget_data_get(data);
1417 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1419 Widget_Data *wd = elm_widget_data_get(data);
1421 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1425 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1427 Widget_Data *wd = elm_widget_data_get(data);
1429 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1433 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1435 Widget_Data *wd = elm_widget_data_get(data);
1437 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1441 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1443 Widget_Data *wd = elm_widget_data_get(data);
1445 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1448 #ifdef HAVE_ELEMENTARY_X
1450 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1452 Widget_Data *wd = elm_widget_data_get(data);
1453 Ecore_X_Event_Selection_Notify *ev = event;
1454 if (!wd) return ECORE_CALLBACK_PASS_ON;
1455 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1456 return ECORE_CALLBACK_PASS_ON;
1458 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1459 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1461 Ecore_X_Selection_Data_Text *text_data;
1463 text_data = ev->data;
1464 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1466 if (text_data->text)
1468 char *txt = _elm_util_text_to_mkup(text_data->text);
1472 elm_entry_entry_insert(data, txt);
1477 wd->selection_asked = EINA_FALSE;
1479 else if (ev->selection == ECORE_X_SELECTION_XDND)
1481 Ecore_X_Selection_Data_Text *text_data;
1483 text_data = ev->data;
1484 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1486 if (text_data->text)
1488 char *txt = _elm_util_text_to_mkup(text_data->text);
1492 /* Massive FIXME: this should be at the drag point */
1493 elm_entry_entry_insert(data, txt);
1498 wd->drag_selection_asked = EINA_FALSE;
1500 ecore_x_dnd_send_finished();
1503 return ECORE_CALLBACK_PASS_ON;
1507 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1509 Widget_Data *wd = elm_widget_data_get(data);
1510 Ecore_X_Event_Selection_Clear *ev = event;
1511 if (!wd) return ECORE_CALLBACK_PASS_ON;
1512 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1513 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1514 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1516 elm_entry_select_none(data);
1518 return ECORE_CALLBACK_PASS_ON;
1522 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1527 wd = elm_widget_data_get(obj);
1528 if (!wd) return EINA_FALSE;
1529 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1531 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1532 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1533 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1534 EDJE_CURSOR_MAIN,drop->x,drop->y);
1535 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1536 elm_entry_entry_insert(obj, drop->data);
1537 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1538 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1544 static Evas_Object *
1545 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1547 Widget_Data *wd = elm_widget_data_get(data);
1550 Elm_Entry_Item_Provider *ip;
1552 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1554 o = ip->func(ip->data, data, item);
1557 if (!strncmp(item, "file://", 7))
1559 const char *fname = item + 7;
1561 o = evas_object_image_filled_add(evas_object_evas_get(data));
1562 evas_object_image_file_set(o, fname, NULL);
1563 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1565 evas_object_show(o);
1570 o = edje_object_add(evas_object_evas_get(data));
1571 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1575 o = edje_object_add(evas_object_evas_get(data));
1576 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1577 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1582 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
1584 Widget_Data *wd = elm_widget_data_get(data);
1586 Elm_Entry_Text_Filter *tf;
1588 if (type == EDJE_TEXT_FILTER_FORMAT)
1591 EINA_LIST_FOREACH(wd->text_filters, l, tf)
1593 tf->func(tf->data, data, text);
1599 /* This function is used to insert text by chunks in jobs */
1601 _text_append_idler(void *data)
1605 Evas_Object *obj = (Evas_Object *) data;
1606 Widget_Data *wd = elm_widget_data_get(obj);
1607 if (wd->text) eina_stringshare_del(wd->text);
1609 wd->changed = EINA_TRUE;
1611 start = wd->append_text_position;
1612 if(start + _CHUNK_SIZE < wd->append_text_len)
1614 wd->append_text_position = (start + _CHUNK_SIZE);
1615 /* Go to the start of the nearest codepoint, because we don't want
1616 * to cut it in the middle */
1617 eina_unicode_utf8_get_prev(wd->append_text_left,
1618 &wd->append_text_position);
1622 wd->append_text_position = wd->append_text_len;
1625 backup = wd->append_text_left[wd->append_text_position];
1626 wd->append_text_left[wd->append_text_position] = '\0';
1628 edje_object_part_text_append(wd->ent, "elm.text",
1629 wd->append_text_left + start);
1631 wd->append_text_left[wd->append_text_position] = backup;
1633 /* If there's still more to go, renew the idler, else, cleanup */
1634 if (wd->append_text_position < wd->append_text_len)
1636 return ECORE_CALLBACK_RENEW;
1640 free(wd->append_text_left);
1641 wd->append_text_left = NULL;
1642 wd->append_text_idler = NULL;
1643 return ECORE_CALLBACK_CANCEL;
1648 * This adds an entry to @p parent object.
1650 * @param parent The parent object
1651 * @return The new object or NULL if it cannot be created
1656 elm_entry_add(Evas_Object *parent)
1658 Evas_Object *obj, *top;
1662 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1664 ELM_SET_WIDTYPE(widtype, "entry");
1665 elm_widget_type_set(obj, "entry");
1666 elm_widget_sub_object_add(parent, obj);
1667 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1668 elm_widget_data_set(obj, wd);
1669 elm_widget_del_hook_set(obj, _del_hook);
1670 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1671 elm_widget_theme_hook_set(obj, _theme_hook);
1672 elm_widget_disable_hook_set(obj, _disable_hook);
1673 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1674 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
1675 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1676 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1677 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
1678 elm_widget_can_focus_set(obj, EINA_TRUE);
1679 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
1681 wd->linewrap = ELM_WRAP_WORD;
1682 wd->editable = EINA_TRUE;
1683 wd->disabled = EINA_FALSE;
1684 wd->context_menu = EINA_TRUE;
1685 wd->autosave = EINA_TRUE;
1686 wd->textonly = EINA_FALSE;
1688 wd->ent = edje_object_add(e);
1689 elm_widget_sub_object_add(obj, wd->ent);
1690 edje_object_item_provider_set(wd->ent, _get_item, obj);
1691 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
1692 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1693 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1694 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1696 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1698 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1701 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1702 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1703 _signal_entry_changed, obj);
1704 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1705 _signal_selection_start, obj);
1706 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1707 _signal_selection_changed, obj);
1708 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1709 _signal_selection_cleared, obj);
1710 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1711 _signal_entry_paste_request, obj);
1712 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1713 _signal_entry_copy_notify, obj);
1714 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1715 _signal_entry_cut_notify, obj);
1716 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1717 _signal_cursor_changed, obj);
1718 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1719 _signal_anchor_down, obj);
1720 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1721 _signal_anchor_up, obj);
1722 edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
1723 _signal_anchor_clicked, obj);
1724 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1725 _signal_anchor_move, obj);
1726 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1727 _signal_anchor_in, obj);
1728 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1729 _signal_anchor_out, obj);
1730 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
1731 _signal_key_enter, obj);
1732 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
1733 _signal_mouse_down, obj);
1734 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
1735 _signal_mouse_clicked, obj);
1736 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
1737 _signal_mouse_double, obj);
1738 edje_object_part_text_set(wd->ent, "elm.text", "");
1739 if (_elm_config->desktop_entry)
1740 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
1741 elm_widget_resize_object_set(obj, wd->ent);
1744 #ifdef HAVE_ELEMENTARY_X
1745 top = elm_widget_top_get(obj);
1746 if ((top) && (elm_win_xwindow_get(top)))
1748 wd->sel_notify_handler =
1749 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
1750 _event_selection_notify, obj);
1751 wd->sel_clear_handler =
1752 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
1753 _event_selection_clear, obj);
1756 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
1757 _drag_drop_cb, NULL);
1760 entries = eina_list_prepend(entries, obj);
1762 // module - find module for entry
1763 wd->api = _module(obj);
1764 // if found - hook in
1765 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
1767 _mirrored_set(obj, elm_widget_mirrored_get(obj));
1768 // TODO: convert Elementary to subclassing of Evas_Smart_Class
1769 // TODO: and save some bytes, making descriptions per-class and not instance!
1770 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1775 * This sets the entry object not to line wrap. All input will
1776 * be on a single line, and the entry box will extend with user input.
1778 * @param obj The entry object
1779 * @param single_line If true, the text in the entry
1780 * will be on a single line.
1785 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
1787 ELM_CHECK_WIDTYPE(obj, widtype);
1788 Widget_Data *wd = elm_widget_data_get(obj);
1790 if (wd->single_line == single_line) return;
1791 wd->single_line = single_line;
1792 wd->linewrap = ELM_WRAP_NONE;
1793 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
1798 * This returns true if the entry has been set to single line mode.
1799 * See also elm_entry_single_line_set().
1801 * @param obj The entry object
1802 * @return single_line If true, the text in the entry is set to display
1808 elm_entry_single_line_get(const Evas_Object *obj)
1810 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1811 Widget_Data *wd = elm_widget_data_get(obj);
1812 if (!wd) return EINA_FALSE;
1813 return wd->single_line;
1817 * This sets the entry object to password mode. All text entered
1818 * and/or displayed within the widget will be replaced with asterisks (*).
1820 * @param obj The entry object
1821 * @param password If true, password mode is enabled.
1826 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
1828 ELM_CHECK_WIDTYPE(obj, widtype);
1829 Widget_Data *wd = elm_widget_data_get(obj);
1831 if (wd->password == password) return;
1832 wd->password = password;
1833 wd->single_line = EINA_TRUE;
1834 wd->linewrap = ELM_WRAP_NONE;
1839 * This returns whether password mode is enabled.
1840 * See also elm_entry_password_set().
1842 * @param obj The entry object
1843 * @return If true, the entry is set to display all characters
1849 elm_entry_password_get(const Evas_Object *obj)
1851 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1852 Widget_Data *wd = elm_widget_data_get(obj);
1853 if (!wd) return EINA_FALSE;
1854 return wd->password;
1858 * This sets the text displayed within the entry to @p entry.
1860 * @param obj The entry object
1861 * @param entry The text to be displayed
1866 elm_entry_entry_set(Evas_Object *obj, const char *entry)
1869 ELM_CHECK_WIDTYPE(obj, widtype);
1870 Widget_Data *wd = elm_widget_data_get(obj);
1872 if (!entry) entry = "";
1873 if (wd->text) eina_stringshare_del(wd->text);
1875 wd->changed = EINA_TRUE;
1877 /* Clear currently pending job if there is one */
1878 if (wd->append_text_idler)
1880 ecore_idler_del(wd->append_text_idler);
1881 free(wd->append_text_left);
1882 wd->append_text_left = NULL;
1883 wd->append_text_idler = NULL;
1886 len = strlen(entry);
1887 /* Split to ~_CHUNK_SIZE chunks */
1888 if (len > _CHUNK_SIZE)
1890 wd->append_text_left = (char *) malloc(len + 1);
1893 /* If we decided to use the idler */
1894 if (wd->append_text_left)
1896 /* Need to clear the entry first */
1897 edje_object_part_text_set(wd->ent, "elm.text", "");
1898 memcpy(wd->append_text_left, entry, len + 1);
1899 wd->append_text_position = 0;
1900 wd->append_text_len = len;
1901 wd->append_text_idler = ecore_idler_add(_text_append_idler, obj);
1905 edje_object_part_text_set(wd->ent, "elm.text", entry);
1910 * This appends @p entry to the text of the entry.
1912 * @param obj The entry object
1913 * @param entry The text to be displayed
1918 elm_entry_entry_append(Evas_Object *obj, const char *entry)
1921 ELM_CHECK_WIDTYPE(obj, widtype);
1922 Widget_Data *wd = elm_widget_data_get(obj);
1924 if (!entry) entry = "";
1925 wd->changed = EINA_TRUE;
1927 len = strlen(entry);
1928 if (wd->append_text_left)
1931 tmpbuf = realloc(wd->append_text_left, wd->append_text_len + len + 1);
1937 wd->append_text_left = tmpbuf;
1938 memcpy(wd->append_text_left + wd->append_text_len, entry, len + 1);
1939 wd->append_text_len += len;
1943 /* FIXME: Add chunked appending here (like in entry_set) */
1944 edje_object_part_text_append(wd->ent, "elm.text", entry);
1949 * This returns the text currently shown in object @p entry.
1950 * See also elm_entry_entry_set().
1952 * @param obj The entry object
1953 * @return The currently displayed text or NULL on failure
1958 elm_entry_entry_get(const Evas_Object *obj)
1960 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1961 Widget_Data *wd = elm_widget_data_get(obj);
1963 if (!wd) return NULL;
1964 if (wd->text) return wd->text;
1965 text = edje_object_part_text_get(wd->ent, "elm.text");
1968 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
1971 eina_stringshare_replace(&wd->text, text);
1976 * This returns EINA_TRUE if the entry is empty/there was an error
1977 * and EINA_FALSE if it is not empty.
1979 * @param obj The entry object
1980 * @return If the entry is empty or not.
1985 elm_entry_is_empty(const Evas_Object *obj)
1987 /* FIXME: until there's support for that in textblock, we just check
1988 * to see if the there is text or not. */
1989 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
1990 Widget_Data *wd = elm_widget_data_get(obj);
1991 const Evas_Object *tb;
1992 Evas_Textblock_Cursor *cur;
1994 if (!wd) return EINA_TRUE;
1995 /* It's a hack until we get the support suggested above.
1996 * We just create a cursor, point it to the begining, and then
1997 * try to advance it, if it can advance, the tb is not empty,
1998 * otherwise it is. */
1999 tb = edje_object_part_object_get(wd->ent, "elm.text");
2000 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
2001 actually, ok for the time being, thsese hackish stuff will be removed
2002 once evas 1.0 is out*/
2003 evas_textblock_cursor_pos_set(cur, 0);
2004 ret = evas_textblock_cursor_char_next(cur);
2005 evas_textblock_cursor_free(cur);
2011 * This returns all selected text within the entry.
2013 * @param obj The entry object
2014 * @return The selected text within the entry or NULL on failure
2019 elm_entry_selection_get(const Evas_Object *obj)
2021 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2022 Widget_Data *wd = elm_widget_data_get(obj);
2023 if (!wd) return NULL;
2024 return edje_object_part_text_selection_get(wd->ent, "elm.text");
2028 * This inserts text in @p entry where the current cursor position.
2030 * This inserts text at the cursor position is as if it was typed
2031 * by the user (note this also allows markup which a user
2032 * can't just "type" as it would be converted to escaped text, so this
2033 * call can be used to insert things like emoticon items or bold push/pop
2034 * tags, other font and color change tags etc.)
2036 * @param obj The entry object
2037 * @param entry The text to insert
2042 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2044 ELM_CHECK_WIDTYPE(obj, widtype);
2045 Widget_Data *wd = elm_widget_data_get(obj);
2047 edje_object_part_text_insert(wd->ent, "elm.text", entry);
2048 wd->changed = EINA_TRUE;
2053 * This enables word line wrapping in the entry object. It is the opposite
2054 * of elm_entry_single_line_set(). Additionally, setting this disables
2055 * character line wrapping.
2057 * @param obj The entry object
2058 * @param wrap If true, the entry will be wrapped once it reaches the end
2059 * of the object. Wrapping will occur at the end of the word before the end of the
2065 elm_entry_line_wrap_set(Evas_Object *obj, Elm_Wrap_Type wrap)
2067 ELM_CHECK_WIDTYPE(obj, widtype);
2068 Widget_Data *wd = elm_widget_data_get(obj);
2070 if (wd->linewrap == wrap) return;
2072 wd->linewrap = wrap;
2077 * This sets the editable attribute of the entry.
2079 * @param obj The entry object
2080 * @param editable If true, the entry will be editable by the user.
2081 * If false, it will be set to the disabled state.
2086 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2088 ELM_CHECK_WIDTYPE(obj, widtype);
2089 Widget_Data *wd = elm_widget_data_get(obj);
2091 if (wd->editable == editable) return;
2092 wd->editable = editable;
2095 #ifdef HAVE_ELEMENTARY_X
2097 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2099 elm_drop_target_del(obj);
2104 * This gets the editable attribute of the entry.
2105 * See also elm_entry_editable_set().
2107 * @param obj The entry object
2108 * @return If true, the entry is editable by the user.
2109 * If false, it is not editable by the user
2114 elm_entry_editable_get(const Evas_Object *obj)
2116 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2117 Widget_Data *wd = elm_widget_data_get(obj);
2118 if (!wd) return EINA_FALSE;
2119 return wd->editable;
2123 * This drops any existing text selection within the entry.
2125 * @param obj The entry object
2130 elm_entry_select_none(Evas_Object *obj)
2132 ELM_CHECK_WIDTYPE(obj, widtype);
2133 Widget_Data *wd = elm_widget_data_get(obj);
2137 wd->selmode = EINA_FALSE;
2138 if (!_elm_config->desktop_entry)
2139 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2140 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2142 wd->have_selection = EINA_FALSE;
2143 edje_object_part_text_select_none(wd->ent, "elm.text");
2147 * This selects all text within the entry.
2149 * @param obj The entry object
2154 elm_entry_select_all(Evas_Object *obj)
2156 ELM_CHECK_WIDTYPE(obj, widtype);
2157 Widget_Data *wd = elm_widget_data_get(obj);
2161 wd->selmode = EINA_FALSE;
2162 if (!_elm_config->desktop_entry)
2163 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2164 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2166 wd->have_selection = EINA_TRUE;
2167 edje_object_part_text_select_all(wd->ent, "elm.text");
2171 * This function returns the geometry of the cursor.
2173 * It's useful if you want to draw something on the cursor (or where it is),
2174 * or for example in the case of scrolled entry where you want to show the
2177 * @param obj The entry object
2178 * @param x returned geometry
2179 * @param y returned geometry
2180 * @param w returned geometry
2181 * @param h returned geometry
2182 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2187 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
2189 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2190 Widget_Data *wd = elm_widget_data_get(obj);
2191 if (!wd) return EINA_FALSE;
2192 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
2197 * This moves the cursor one place to the right within the entry.
2199 * @param obj The entry object
2200 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2205 elm_entry_cursor_next(Evas_Object *obj)
2207 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2208 Widget_Data *wd = elm_widget_data_get(obj);
2209 if (!wd) return EINA_FALSE;
2210 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2214 * This moves the cursor one place to the left within the entry.
2216 * @param obj The entry object
2217 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2222 elm_entry_cursor_prev(Evas_Object *obj)
2224 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2225 Widget_Data *wd = elm_widget_data_get(obj);
2226 if (!wd) return EINA_FALSE;
2227 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2231 * This moves the cursor one line up within the entry.
2233 * @param obj The entry object
2234 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2239 elm_entry_cursor_up(Evas_Object *obj)
2241 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2242 Widget_Data *wd = elm_widget_data_get(obj);
2243 if (!wd) return EINA_FALSE;
2244 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2248 * This moves the cursor one line down within the entry.
2250 * @param obj The entry object
2251 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2256 elm_entry_cursor_down(Evas_Object *obj)
2258 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2259 Widget_Data *wd = elm_widget_data_get(obj);
2260 if (!wd) return EINA_FALSE;
2261 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2265 * This moves the cursor to the beginning of the entry.
2267 * @param obj The entry object
2272 elm_entry_cursor_begin_set(Evas_Object *obj)
2274 ELM_CHECK_WIDTYPE(obj, widtype);
2275 Widget_Data *wd = elm_widget_data_get(obj);
2277 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2281 * This moves the cursor to the end of the entry.
2283 * @param obj The entry object
2288 elm_entry_cursor_end_set(Evas_Object *obj)
2290 ELM_CHECK_WIDTYPE(obj, widtype);
2291 Widget_Data *wd = elm_widget_data_get(obj);
2293 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2297 * This moves the cursor to the beginning of the current line.
2299 * @param obj The entry object
2304 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2306 ELM_CHECK_WIDTYPE(obj, widtype);
2307 Widget_Data *wd = elm_widget_data_get(obj);
2309 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2313 * This moves the cursor to the end of the current line.
2315 * @param obj The entry object
2320 elm_entry_cursor_line_end_set(Evas_Object *obj)
2322 ELM_CHECK_WIDTYPE(obj, widtype);
2323 Widget_Data *wd = elm_widget_data_get(obj);
2325 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2329 * This begins a selection within the entry as though
2330 * the user were holding down the mouse button to make a selection.
2332 * @param obj The entry object
2337 elm_entry_cursor_selection_begin(Evas_Object *obj)
2339 ELM_CHECK_WIDTYPE(obj, widtype);
2340 Widget_Data *wd = elm_widget_data_get(obj);
2342 edje_object_part_text_select_begin(wd->ent, "elm.text");
2346 * This ends a selection within the entry as though
2347 * the user had just released the mouse button while making a selection.
2349 * @param obj The entry object
2354 elm_entry_cursor_selection_end(Evas_Object *obj)
2356 ELM_CHECK_WIDTYPE(obj, widtype);
2357 Widget_Data *wd = elm_widget_data_get(obj);
2359 edje_object_part_text_select_extend(wd->ent, "elm.text");
2363 * TODO: fill this in
2365 * @param obj The entry object
2366 * @return TODO: fill this in
2371 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2373 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2374 Widget_Data *wd = elm_widget_data_get(obj);
2375 if (!wd) return EINA_FALSE;
2376 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2380 * This returns whether the cursor is visible.
2382 * @param obj The entry object
2383 * @return If true, the cursor is visible.
2388 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2390 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2391 Widget_Data *wd = elm_widget_data_get(obj);
2392 if (!wd) return EINA_FALSE;
2393 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2397 * TODO: fill this in
2399 * @param obj The entry object
2400 * @return TODO: fill this in
2405 elm_entry_cursor_content_get(const Evas_Object *obj)
2407 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2408 Widget_Data *wd = elm_widget_data_get(obj);
2409 if (!wd) return NULL;
2410 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2414 * Sets the cursor position in the entry to the given value
2416 * @param obj The entry object
2417 * @param pos The position of the cursor
2422 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
2424 ELM_CHECK_WIDTYPE(obj, widtype);
2425 Widget_Data *wd = elm_widget_data_get(obj);
2427 edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
2428 edje_object_message_signal_process(wd->ent);
2432 * Retrieves the current position of the cursor in the entry
2434 * @param obj The entry object
2435 * @return The cursor position
2440 elm_entry_cursor_pos_get(const Evas_Object *obj)
2442 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2443 Widget_Data *wd = elm_widget_data_get(obj);
2445 return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2449 * This executes a "cut" action on the selected text in the entry.
2451 * @param obj The entry object
2456 elm_entry_selection_cut(Evas_Object *obj)
2458 ELM_CHECK_WIDTYPE(obj, widtype);
2459 Widget_Data *wd = elm_widget_data_get(obj);
2461 _cut(obj, NULL, NULL);
2465 * This executes a "copy" action on the selected text in the entry.
2467 * @param obj The entry object
2472 elm_entry_selection_copy(Evas_Object *obj)
2474 ELM_CHECK_WIDTYPE(obj, widtype);
2475 Widget_Data *wd = elm_widget_data_get(obj);
2477 _copy(obj, NULL, NULL);
2481 * This executes a "paste" action in the entry.
2483 * @param obj The entry object
2488 elm_entry_selection_paste(Evas_Object *obj)
2490 ELM_CHECK_WIDTYPE(obj, widtype);
2491 Widget_Data *wd = elm_widget_data_get(obj);
2493 _paste(obj, NULL, NULL);
2497 * This clears and frees the items in a entry's contextual (right click) menu.
2499 * @param obj The entry object
2504 elm_entry_context_menu_clear(Evas_Object *obj)
2506 ELM_CHECK_WIDTYPE(obj, widtype);
2507 Widget_Data *wd = elm_widget_data_get(obj);
2508 Elm_Entry_Context_Menu_Item *it;
2510 EINA_LIST_FREE(wd->items, it)
2512 eina_stringshare_del(it->label);
2513 eina_stringshare_del(it->icon_file);
2514 eina_stringshare_del(it->icon_group);
2520 * This adds an item to the entry's contextual menu.
2522 * @param obj The entry object
2523 * @param label The item's text label
2524 * @param icon_file The item's icon file
2525 * @param icon_type The item's icon type
2526 * @param func The callback to execute when the item is clicked
2527 * @param data The data to associate with the item for related functions
2532 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)
2534 ELM_CHECK_WIDTYPE(obj, widtype);
2535 Widget_Data *wd = elm_widget_data_get(obj);
2536 Elm_Entry_Context_Menu_Item *it;
2538 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2540 wd->items = eina_list_append(wd->items, it);
2542 it->label = eina_stringshare_add(label);
2543 it->icon_file = eina_stringshare_add(icon_file);
2544 it->icon_type = icon_type;
2546 it->data = (void *)data;
2550 * This disables the entry's contextual (right click) menu.
2552 * @param obj The entry object
2553 * @param disabled If true, the menu is disabled
2558 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2560 ELM_CHECK_WIDTYPE(obj, widtype);
2561 Widget_Data *wd = elm_widget_data_get(obj);
2563 if (wd->context_menu == !disabled) return;
2564 wd->context_menu = !disabled;
2568 * This returns whether the entry's contextual (right click) menu is disabled.
2570 * @param obj The entry object
2571 * @return If true, the menu is disabled
2576 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2578 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2579 Widget_Data *wd = elm_widget_data_get(obj);
2580 if (!wd) return EINA_FALSE;
2581 return !wd->context_menu;
2585 * This appends a custom item provider to the list for that entry
2587 * This appends the given callback. The list is walked from beginning to end
2588 * with each function called given the item href string in the text. If the
2589 * function returns an object handle other than NULL (it should create an
2590 * and object to do this), then this object is used to replace that item. If
2591 * not the next provider is called until one provides an item object, or the
2592 * default provider in entry does.
2594 * @param obj The entry object
2595 * @param func The function called to provide the item object
2596 * @param data The data passed to @p func
2601 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2603 ELM_CHECK_WIDTYPE(obj, widtype);
2604 Widget_Data *wd = elm_widget_data_get(obj);
2606 EINA_SAFETY_ON_NULL_RETURN(func);
2607 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2611 wd->item_providers = eina_list_append(wd->item_providers, ip);
2615 * This prepends a custom item provider to the list for that entry
2617 * This prepends the given callback. See elm_entry_item_provider_append() for
2620 * @param obj The entry object
2621 * @param func The function called to provide the item object
2622 * @param data The data passed to @p func
2627 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2629 ELM_CHECK_WIDTYPE(obj, widtype);
2630 Widget_Data *wd = elm_widget_data_get(obj);
2632 EINA_SAFETY_ON_NULL_RETURN(func);
2633 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2637 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2641 * This removes a custom item provider to the list for that entry
2643 * This removes the given callback. See elm_entry_item_provider_append() for
2646 * @param obj The entry object
2647 * @param func The function called to provide the item object
2648 * @param data The data passed to @p func
2653 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2655 ELM_CHECK_WIDTYPE(obj, widtype);
2656 Widget_Data *wd = elm_widget_data_get(obj);
2658 Elm_Entry_Item_Provider *ip;
2660 EINA_SAFETY_ON_NULL_RETURN(func);
2661 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2663 if ((ip->func == func) && ((!data) || (ip->data == data)))
2665 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2673 * Append a filter function for text inserted in the entry
2675 * Append the given callback to the list. This functions will be called
2676 * whenever any text is inserted into the entry, with the text to be inserted
2677 * as a parameter. The callback function is free to alter the text in any way
2678 * it wants, but it must remember to free the given pointer and update it.
2679 * If the new text is to be discarded, the function can free it and set it text
2680 * parameter to NULL. This will also prevent any following filters from being
2683 * @param obj The entry object
2684 * @param func The function to use as text filter
2685 * @param data User data to pass to @p func
2690 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2693 Elm_Entry_Text_Filter *tf;
2694 ELM_CHECK_WIDTYPE(obj, widtype);
2696 wd = elm_widget_data_get(obj);
2698 EINA_SAFETY_ON_NULL_RETURN(func);
2700 tf = _filter_new(func, data);
2703 wd->text_filters = eina_list_append(wd->text_filters, tf);
2707 * Prepend a filter function for text insdrted in the entry
2709 * Prepend the given callback to the list. See elm_entry_text_filter_append()
2710 * for more information
2712 * @param obj The entry object
2713 * @param func The function to use as text filter
2714 * @param data User data to pass to @p func
2719 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2722 Elm_Entry_Text_Filter *tf;
2723 ELM_CHECK_WIDTYPE(obj, widtype);
2725 wd = elm_widget_data_get(obj);
2727 EINA_SAFETY_ON_NULL_RETURN(func);
2729 tf = _filter_new(func, data);
2732 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
2736 * Remove a filter from the list
2738 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
2739 * for more information.
2741 * @param obj The entry object
2742 * @param func The filter function to remove
2743 * @param data The user data passed when adding the function
2748 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2752 Elm_Entry_Text_Filter *tf;
2753 ELM_CHECK_WIDTYPE(obj, widtype);
2755 wd = elm_widget_data_get(obj);
2757 EINA_SAFETY_ON_NULL_RETURN(func);
2759 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2761 if ((tf->func == func) && ((!data) || (tf->data == data)))
2763 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
2771 * This converts a markup (HTML-like) string into UTF-8.
2772 * Returning string is obtained with malloc.
2773 * After use the returned string, it should be freed.
2775 * @param s The string (in markup) to be converted
2776 * @return The converted string (in UTF-8). It should be freed.
2781 elm_entry_markup_to_utf8(const char *s)
2783 char *ss = _elm_util_mkup_to_text(s);
2784 if (!ss) ss = strdup("");
2789 * This converts a UTF-8 string into markup (HTML-like).
2790 * Returning string is obtained with malloc.
2791 * After use the returned string, it should be freed.
2793 * @param s The string (in UTF-8) to be converted
2794 * @return The converted string (in markup). It should be freed.
2799 elm_entry_utf8_to_markup(const char *s)
2801 char *ss = _elm_util_text_to_mkup(s);
2802 if (!ss) ss = strdup("");
2807 * Filter inserted text based on user defined character and byte limits
2809 * Add this filter to an entry to limit the characters that it will accept
2810 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
2811 * The funtion works on the UTF-8 representation of the string, converting
2812 * it from the set markup, thus not accounting for any format in it.
2814 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
2815 * it as data when setting the filter. In it it's possible to set limits
2816 * by character count or bytes (any of them is disabled if 0), and both can
2817 * be set at the same time. In that case, it first checks for characters,
2820 * The function will cut the inserted text in order to allow only the first
2821 * number of characters that are still allowed. The cut is made in
2822 * characters, even when limiting by bytes, in order to always contain
2823 * valid ones and avoid half unicode characters making it in.
2828 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
2830 Elm_Entry_Filter_Limit_Size *lim = data;
2833 const char *(*text_get)(const Evas_Object *);
2834 const char *widget_type;
2836 EINA_SAFETY_ON_NULL_RETURN(data);
2837 EINA_SAFETY_ON_NULL_RETURN(entry);
2838 EINA_SAFETY_ON_NULL_RETURN(text);
2840 /* hack. I don't want to copy the entire function to work with
2842 widget_type = elm_widget_type_get(entry);
2843 if (!strcmp(widget_type, "entry"))
2844 text_get = elm_entry_entry_get;
2845 else if (!strcmp(widget_type, "scrolled_entry"))
2846 text_get = elm_scrolled_entry_entry_get;
2850 current = elm_entry_markup_to_utf8(text_get(entry));
2852 if (lim->max_char_count > 0)
2855 len = evas_string_char_len_get(current);
2856 if (len >= lim->max_char_count)
2863 newlen = evas_string_char_len_get(*text);
2864 cut = strlen(*text);
2865 while ((len + newlen) > lim->max_char_count)
2867 cut = evas_string_char_prev_get(*text, cut, NULL);
2873 if (lim->max_byte_count > 0)
2875 len = strlen(current);
2876 if (len >= lim->max_byte_count)
2883 newlen = strlen(*text);
2884 while ((len + newlen) > lim->max_byte_count)
2886 int p = evas_string_char_prev_get(*text, newlen, NULL);
2887 newlen -= (newlen - p);
2890 (*text)[newlen] = 0;
2901 * Filter inserted text based on accepted or rejected sets of characters
2903 * Add this filter to an entry to restrict the set of accepted characters
2904 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
2905 * This structure contains both accepted and rejected sets, but they are
2906 * mutually exclusive. If accepted is set, it will be used, otherwise it
2907 * goes on to the rejected set.
2910 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
2912 Elm_Entry_Filter_Accept_Set *as = data;
2916 int read_idx, last_read_idx = 0, read_char;
2918 EINA_SAFETY_ON_NULL_RETURN(data);
2919 EINA_SAFETY_ON_NULL_RETURN(text);
2921 if ((!as->accepted) && (!as->rejected))
2927 goes_in = EINA_TRUE;
2932 goes_in = EINA_FALSE;
2936 read_idx = evas_string_char_next_get(*text, 0, &read_char);
2939 int cmp_idx, cmp_char;
2940 Eina_Bool in_set = EINA_FALSE;
2942 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
2945 if (read_char == cmp_char)
2950 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
2952 if (in_set == goes_in)
2954 int size = read_idx - last_read_idx;
2955 const char *src = (*text) + last_read_idx;
2957 memcpy(insert, *text + last_read_idx, size);
2960 last_read_idx = read_idx;
2961 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
2967 * This sets the file (and implicitly loads it) for the text to display and
2968 * then edit. All changes are written back to the file after a short delay if
2969 * the entry object is set to autosave.
2971 * @param obj The entry object
2972 * @param file The path to the file to load and save
2973 * @param format The file format
2978 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
2980 ELM_CHECK_WIDTYPE(obj, widtype);
2981 Widget_Data *wd = elm_widget_data_get(obj);
2983 if (wd->delay_write)
2985 ecore_timer_del(wd->delay_write);
2986 wd->delay_write = NULL;
2988 if (wd->autosave) _save(obj);
2989 eina_stringshare_replace(&wd->file, file);
2990 wd->format = format;
2995 * Gets the file to load and save and the file format
2997 * @param obj The entry object
2998 * @param file The path to the file to load and save
2999 * @param format The file format
3004 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
3006 ELM_CHECK_WIDTYPE(obj, widtype);
3007 Widget_Data *wd = elm_widget_data_get(obj);
3009 if (file) *file = wd->file;
3010 if (format) *format = wd->format;
3014 * This function writes any changes made to the file set with
3015 * elm_entry_file_set()
3017 * @param obj The entry object
3022 elm_entry_file_save(Evas_Object *obj)
3024 ELM_CHECK_WIDTYPE(obj, widtype);
3025 Widget_Data *wd = elm_widget_data_get(obj);
3027 if (wd->delay_write)
3029 ecore_timer_del(wd->delay_write);
3030 wd->delay_write = NULL;
3033 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
3037 * This sets the entry object to 'autosave' the loaded text file or not.
3039 * @param obj The entry object
3040 * @param autosave Autosave the loaded file or not
3045 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
3047 ELM_CHECK_WIDTYPE(obj, widtype);
3048 Widget_Data *wd = elm_widget_data_get(obj);
3050 wd->autosave = !!autosave;
3054 * This gets the entry object's 'autosave' status.
3056 * @param obj The entry object
3057 * @return Autosave the loaded file or not
3062 elm_entry_autosave_get(const Evas_Object *obj)
3064 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3065 Widget_Data *wd = elm_widget_data_get(obj);
3066 if (!wd) return EINA_FALSE;
3067 return wd->autosave;
3071 * Control pasting of text and images for the widget.
3073 * Normally the entry allows both text and images to be pasted. By setting
3074 * textonly to be true, this prevents images from being pasted.
3076 * Note this only changes the behaviour of text.
3078 * @param obj The entry object
3079 * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is text+image+other.
3084 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
3086 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
3087 ELM_CHECK_WIDTYPE(obj, widtype);
3088 Widget_Data *wd = elm_widget_data_get(obj);
3090 textonly = !!textonly;
3091 if (wd->textonly == textonly) return;
3092 wd->textonly = !!textonly;
3093 if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
3094 #ifdef HAVE_ELEMENTARY_X
3095 elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
3100 * Getting elm_entry text paste/drop mode.
3102 * In textonly mode, only text may be pasted or dropped into the widget.
3104 * @param obj The entry object
3105 * @return If the widget only accepts text from pastes.
3110 elm_entry_cnp_textonly_get(Evas_Object *obj)
3112 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3113 Widget_Data *wd = elm_widget_data_get(obj);
3114 if (!wd) return EINA_FALSE;
3115 return wd->textonly;