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 disabled : 1;
146 Eina_Bool context_menu : 1;
147 Eina_Bool drag_selection_asked : 1;
148 Eina_Bool can_write : 1;
149 Eina_Bool autosave : 1;
150 Eina_Bool textonly : 1;
151 Eina_Bool usedown : 1;
154 struct _Elm_Entry_Context_Menu_Item
158 const char *icon_file;
159 const char *icon_group;
160 Elm_Icon_Type icon_type;
165 struct _Elm_Entry_Item_Provider
167 Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
171 struct _Elm_Entry_Text_Filter
173 void (*func) (void *data, Evas_Object *entry, char **text);
177 static const char *widtype = NULL;
179 #ifdef HAVE_ELEMENTARY_X
180 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
182 static void _del_hook(Evas_Object *obj);
183 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
184 static void _theme_hook(Evas_Object *obj);
185 static void _disable_hook(Evas_Object *obj);
186 static void _sizing_eval(Evas_Object *obj);
187 static void _on_focus_hook(void *data, Evas_Object *obj);
188 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
189 static const char *_getbase(Evas_Object *obj);
190 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
191 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
192 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
193 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
194 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
195 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
196 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
197 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
199 static const char SIG_CHANGED[] = "changed";
200 static const char SIG_ACTIVATED[] = "activated";
201 static const char SIG_PRESS[] = "press";
202 static const char SIG_LONGPRESSED[] = "longpressed";
203 static const char SIG_CLICKED[] = "clicked";
204 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
205 static const char SIG_FOCUSED[] = "focused";
206 static const char SIG_UNFOCUSED[] = "unfocused";
207 static const char SIG_SELECTION_PASTE[] = "selection,paste";
208 static const char SIG_SELECTION_COPY[] = "selection,copy";
209 static const char SIG_SELECTION_CUT[] = "selection,cut";
210 static const char SIG_SELECTION_START[] = "selection,start";
211 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
212 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
213 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
214 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
215 static const Evas_Smart_Cb_Description _signals[] = {
219 {SIG_LONGPRESSED, ""},
221 {SIG_CLICKED_DOUBLE, ""},
224 {SIG_SELECTION_PASTE, ""},
225 {SIG_SELECTION_COPY, ""},
226 {SIG_SELECTION_CUT, ""},
227 {SIG_SELECTION_START, ""},
228 {SIG_SELECTION_CHANGED, ""},
229 {SIG_SELECTION_CLEARED, ""},
230 {SIG_CURSOR_CHANGED, ""},
231 {SIG_ANCHOR_CLICKED, ""},
235 static Eina_List *entries = NULL;
239 void (*obj_hook) (Evas_Object *obj);
240 void (*obj_unhook) (Evas_Object *obj);
241 void (*obj_longpress) (Evas_Object *obj);
245 _module(Evas_Object *obj __UNUSED__)
247 static Elm_Module *m = NULL;
248 if (m) goto ok; // already found - just use
249 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
251 m->api = malloc(sizeof(Mod_Api));
252 if (!m->api) return NULL;
253 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
254 _elm_module_symbol_get(m, "obj_hook");
255 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
256 _elm_module_symbol_get(m, "obj_unhook");
257 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
258 _elm_module_symbol_get(m, "obj_longpress");
259 ok: // ok - return api
264 _buf_append(char *buf, const char *str, int *len, int *alloc)
266 int len2 = strlen(str);
267 if ((*len + len2) >= *alloc)
269 char *buf2 = realloc(buf, *alloc + len2 + 512);
270 if (!buf2) return NULL;
272 *alloc += (512 + len2);
274 strcpy(buf + *len, str);
280 _load_file(const char *file)
284 int alloc = 0, len = 0;
285 char *text = NULL, buf[16384 + 1];
287 f = fopen(file, "rb");
289 while ((size = fread(buf, 1, sizeof(buf) - 1, f)))
293 tmp_text = _buf_append(text, buf, &len, &alloc);
294 if (!tmp_text) break;
302 _load_plain(const char *file)
306 text = _load_file(file);
311 text2 = elm_entry_utf8_to_markup(text);
319 _load(Evas_Object *obj)
321 Widget_Data *wd = elm_widget_data_get(obj);
326 elm_entry_entry_set(obj, "");
331 case ELM_TEXT_FORMAT_PLAIN_UTF8:
332 text = _load_plain(wd->file);
334 case ELM_TEXT_FORMAT_MARKUP_UTF8:
335 text = _load_file(wd->file);
343 elm_entry_entry_set(obj, text);
347 elm_entry_entry_set(obj, "");
351 _save_markup_utf8(const char *file, const char *text)
355 if ((!text) || (!text[0]))
357 ecore_file_unlink(file);
360 f = fopen(file, "wb");
363 // FIXME: report a write error
366 fputs(text, f); // FIXME: catch error
371 _save_plain_utf8(const char *file, const char *text)
375 text2 = elm_entry_markup_to_utf8(text);
378 _save_markup_utf8(file, text2);
383 _save(Evas_Object *obj)
385 Widget_Data *wd = elm_widget_data_get(obj);
387 if (!wd->file) return;
390 case ELM_TEXT_FORMAT_PLAIN_UTF8:
391 _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
393 case ELM_TEXT_FORMAT_MARKUP_UTF8:
394 _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
402 _delay_write(void *data)
404 Widget_Data *wd = elm_widget_data_get(data);
405 if (!wd) return ECORE_CALLBACK_CANCEL;
407 wd->delay_write = NULL;
408 return ECORE_CALLBACK_CANCEL;
411 static Elm_Entry_Text_Filter *
412 _filter_new(void (*func) (void *data, Evas_Object *entry, char **text), void *data)
414 Elm_Entry_Text_Filter *tf = ELM_NEW(Elm_Entry_Text_Filter);
415 if (!tf) return NULL;
418 if (func == elm_entry_filter_limit_size)
420 Elm_Entry_Filter_Limit_Size *lim = data, *lim2;
427 lim2 = malloc(sizeof(Elm_Entry_Filter_Limit_Size));
433 memcpy(lim2, lim, sizeof(Elm_Entry_Filter_Limit_Size));
436 else if (func == elm_entry_filter_accept_set)
438 Elm_Entry_Filter_Accept_Set *as = data, *as2;
445 as2 = malloc(sizeof(Elm_Entry_Filter_Accept_Set));
452 as2->accepted = eina_stringshare_add(as->accepted);
454 as2->accepted = NULL;
456 as2->rejected = eina_stringshare_add(as->rejected);
458 as2->rejected = NULL;
467 _filter_free(Elm_Entry_Text_Filter *tf)
469 if (tf->func == elm_entry_filter_limit_size)
471 Elm_Entry_Filter_Limit_Size *lim = tf->data;
474 else if (tf->func == elm_entry_filter_accept_set)
476 Elm_Entry_Filter_Accept_Set *as = tf->data;
479 if (as->accepted) eina_stringshare_del(as->accepted);
480 if (as->rejected) eina_stringshare_del(as->rejected);
488 _del_pre_hook(Evas_Object *obj)
490 Widget_Data *wd = elm_widget_data_get(obj);
494 ecore_timer_del(wd->delay_write);
495 wd->delay_write = NULL;
496 if (wd->autosave) _save(obj);
501 _del_hook(Evas_Object *obj)
503 Widget_Data *wd = elm_widget_data_get(obj);
504 Elm_Entry_Context_Menu_Item *it;
505 Elm_Entry_Item_Provider *ip;
506 Elm_Entry_Text_Filter *tf;
508 if (wd->file) eina_stringshare_del(wd->file);
510 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
511 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
513 entries = eina_list_remove(entries, obj);
514 #ifdef HAVE_ELEMENTARY_X
515 if (wd->sel_notify_handler)
516 ecore_event_handler_del(wd->sel_notify_handler);
517 if (wd->sel_clear_handler)
518 ecore_event_handler_del(wd->sel_clear_handler);
520 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
521 if (wd->text) eina_stringshare_del(wd->text);
522 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
523 if (wd->append_text_idler)
525 ecore_idler_del(wd->append_text_idler);
526 free(wd->append_text_left);
527 wd->append_text_left = NULL;
528 wd->append_text_idler = NULL;
530 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
531 EINA_LIST_FREE(wd->items, it)
533 eina_stringshare_del(it->label);
534 eina_stringshare_del(it->icon_file);
535 eina_stringshare_del(it->icon_group);
538 EINA_LIST_FREE(wd->item_providers, ip)
542 EINA_LIST_FREE(wd->text_filters, tf)
550 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
552 Widget_Data *wd = elm_widget_data_get(obj);
553 edje_object_mirrored_set(wd->ent, rtl);
557 _theme_hook(Evas_Object *obj)
559 Widget_Data *wd = elm_widget_data_get(obj);
561 _elm_widget_mirrored_reload(obj);
562 _mirrored_set(obj, elm_widget_mirrored_get(obj));
564 t = eina_stringshare_add(elm_entry_entry_get(obj));
565 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
566 if (_elm_config->desktop_entry)
567 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
568 elm_entry_entry_set(obj, t);
569 eina_stringshare_del(t);
570 if (elm_widget_disabled_get(obj))
571 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
572 elm_entry_cursor_pos_set(obj, wd->cursor_pos);
573 if (elm_widget_focus_get(obj))
574 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
575 edje_object_message_signal_process(wd->ent);
576 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
581 _disable_hook(Evas_Object *obj)
583 Widget_Data *wd = elm_widget_data_get(obj);
585 if (elm_widget_disabled_get(obj))
587 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
588 wd->disabled = EINA_TRUE;
592 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
593 wd->disabled = EINA_FALSE;
598 _elm_win_recalc_job(void *data)
600 Widget_Data *wd = elm_widget_data_get(data);
601 Evas_Coord minh = -1, resw = -1, minw = -1;
603 wd->deferred_recalc_job = NULL;
605 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, NULL);
606 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
607 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
608 /* This is a hack to workaround the way min size hints are treated.
609 * If the minimum width is smaller than the restricted width, it means
610 * the mininmum doesn't matter. */
613 Evas_Coord ominw = -1;
614 evas_object_size_hint_min_get(data, &ominw, NULL);
617 evas_object_size_hint_min_set(data, minw, minh);
619 evas_object_size_hint_max_set(data, -1, minh);
621 if (wd->deferred_cur)
623 Evas_Coord cx, cy, cw, ch;
624 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
626 elm_widget_show_region_set(data, cx, cy, cw, ch);
631 _sizing_eval(Evas_Object *obj)
633 Widget_Data *wd = elm_widget_data_get(obj);
634 Evas_Coord minw = -1, minh = -1;
635 Evas_Coord resw, resh;
639 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
640 if ((resw == wd->lastw) && (!wd->changed)) return;
641 wd->changed = EINA_FALSE;
643 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
644 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
648 edje_object_size_min_calc(wd->ent, &minw, &minh);
649 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
650 evas_object_size_hint_min_set(obj, minw, minh);
652 evas_object_size_hint_max_set(obj, -1, minh);
657 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
659 Widget_Data *wd = elm_widget_data_get(obj);
660 Evas_Object *top = elm_widget_top_get(obj);
662 if (!wd->editable) return;
663 if (elm_widget_focus_get(obj))
665 evas_object_focus_set(wd->ent, EINA_TRUE);
666 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
667 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
668 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
672 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
673 evas_object_focus_set(wd->ent, EINA_FALSE);
674 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
675 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
680 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
682 Widget_Data *wd = elm_widget_data_get(obj);
684 edje_object_signal_emit(wd->ent, emission, source);
688 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
690 Widget_Data *wd = elm_widget_data_get(obj);
692 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
696 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
698 Widget_Data *wd = elm_widget_data_get(obj);
699 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
704 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
706 Widget_Data *wd = elm_widget_data_get(obj);
707 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
711 _hoversel_position(Evas_Object *obj)
713 Widget_Data *wd = elm_widget_data_get(obj);
714 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
719 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
728 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
730 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
741 evas_object_move(wd->hoversel, x + cx, y + cy);
742 evas_object_resize(wd->hoversel, cw, ch);
746 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
748 Widget_Data *wd = elm_widget_data_get(data);
750 if (wd->hoversel) _hoversel_position(data);
754 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
756 Widget_Data *wd = elm_widget_data_get(data);
762 if (wd->hoversel) _hoversel_position(data);
763 // Evas_Coord ww, hh;
764 // evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
768 _hover_del(void *data)
770 Widget_Data *wd = elm_widget_data_get(data);
775 evas_object_del(wd->hoversel);
778 wd->hovdeljob = NULL;
782 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
784 Widget_Data *wd = elm_widget_data_get(data);
787 if (wd->hoversel) evas_object_hide(wd->hoversel);
790 if (!_elm_config->desktop_entry)
793 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
796 elm_widget_scroll_freeze_pop(data);
797 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
798 wd->hovdeljob = ecore_job_add(_hover_del, data);
802 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
804 Widget_Data *wd = elm_widget_data_get(data);
806 wd->selmode = EINA_TRUE;
807 edje_object_part_text_select_none(wd->ent, "elm.text");
808 if (!_elm_config->desktop_entry)
811 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
813 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
814 if (!_elm_config->desktop_entry)
815 elm_widget_scroll_hold_push(data);
819 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
821 Widget_Data *wd = elm_widget_data_get(data);
823 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
824 if (wd->sel_notify_handler)
826 #ifdef HAVE_ELEMENTARY_X
827 Elm_Sel_Format formats;
828 wd->selection_asked = EINA_TRUE;
829 formats = ELM_SEL_FORMAT_MARKUP;
831 formats |= ELM_SEL_FORMAT_IMAGE;
832 elm_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL);
838 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
840 Widget_Data *wd = elm_widget_data_get(obj);
844 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
845 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
846 if (seltype == ELM_SEL_CLIPBOARD)
847 eina_stringshare_replace(&wd->cut_sel, sel);
851 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
853 Widget_Data *wd = elm_widget_data_get(data);
856 wd->selmode = EINA_FALSE;
857 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 if (!_elm_config->desktop_entry)
861 elm_widget_scroll_hold_pop(data);
862 _store_selection(ELM_SEL_CLIPBOARD, data);
863 edje_object_part_text_insert(wd->ent, "elm.text", "");
864 edje_object_part_text_select_none(wd->ent, "elm.text");
868 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
870 Widget_Data *wd = elm_widget_data_get(data);
872 wd->selmode = EINA_FALSE;
873 if (!_elm_config->desktop_entry)
875 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
876 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
877 elm_widget_scroll_hold_pop(data);
879 _store_selection(ELM_SEL_CLIPBOARD, data);
880 // edje_object_part_text_select_none(wd->ent, "elm.text");
884 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
886 Widget_Data *wd = elm_widget_data_get(data);
888 wd->selmode = EINA_FALSE;
889 if (!_elm_config->desktop_entry)
890 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
891 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
892 if (!_elm_config->desktop_entry)
893 elm_widget_scroll_hold_pop(data);
894 edje_object_part_text_select_none(wd->ent, "elm.text");
898 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
900 Elm_Entry_Context_Menu_Item *it = data;
901 Evas_Object *obj2 = it->obj;
902 if (it->func) it->func(it->data, obj2, NULL);
906 _menu_press(Evas_Object *obj)
908 Widget_Data *wd = elm_widget_data_get(obj);
911 const Elm_Entry_Context_Menu_Item *it;
913 if ((wd->api) && (wd->api->obj_longpress))
915 wd->api->obj_longpress(obj);
917 else if (wd->context_menu)
919 const char *context_menu_orientation;
921 if (wd->hoversel) evas_object_del(wd->hoversel);
922 else elm_widget_scroll_freeze_push(obj);
923 wd->hoversel = elm_hoversel_add(obj);
924 context_menu_orientation = edje_object_data_get
925 (wd->ent, "context_menu_orientation");
926 if ((context_menu_orientation) &&
927 (!strcmp(context_menu_orientation, "horizontal")))
928 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
929 elm_object_style_set(wd->hoversel, "entry");
930 elm_widget_sub_object_add(obj, wd->hoversel);
931 elm_hoversel_label_set(wd->hoversel, "Text");
932 top = elm_widget_top_get(obj);
933 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
934 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, obj);
935 if (wd->have_selection)
939 if (wd->have_selection)
941 elm_hoversel_item_add(wd->hoversel, E_("Copy"), NULL, ELM_ICON_NONE,
944 elm_hoversel_item_add(wd->hoversel, E_("Cut"), NULL, ELM_ICON_NONE,
947 elm_hoversel_item_add(wd->hoversel, E_("Cancel"), NULL, ELM_ICON_NONE,
955 if (!_elm_config->desktop_entry)
958 elm_hoversel_item_add(wd->hoversel, E_("Select"), NULL, ELM_ICON_NONE,
961 if (1) // need way to detect if someone has a selection
964 elm_hoversel_item_add(wd->hoversel, E_("Paste"), NULL, ELM_ICON_NONE,
969 EINA_LIST_FOREACH(wd->items, l, it)
971 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
972 it->icon_type, _item_clicked, it);
976 _hoversel_position(obj);
977 evas_object_show(wd->hoversel);
978 elm_hoversel_hover_begin(wd->hoversel);
980 if (!_elm_config->desktop_entry)
982 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
983 edje_object_part_text_select_abort(wd->ent, "elm.text");
989 _long_press(void *data)
991 Widget_Data *wd = elm_widget_data_get(data);
992 if (!wd) return ECORE_CALLBACK_CANCEL;
994 wd->longpress_timer = NULL;
995 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
996 return ECORE_CALLBACK_CANCEL;
1000 _mouse_down(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_Down *ev = event_info;
1005 if (wd->disabled) return;
1006 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1007 wd->downx = ev->canvas.x;
1008 wd->downy = ev->canvas.y;
1009 if (ev->button == 1)
1011 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
1012 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1017 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1019 Widget_Data *wd = elm_widget_data_get(data);
1020 Evas_Event_Mouse_Up *ev = event_info;
1022 if (wd->disabled) return;
1023 if (ev->button == 1)
1025 if (wd->longpress_timer)
1027 ecore_timer_del(wd->longpress_timer);
1028 wd->longpress_timer = NULL;
1031 else if (ev->button == 3)
1039 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1041 Widget_Data *wd = elm_widget_data_get(data);
1042 Evas_Event_Mouse_Move *ev = event_info;
1044 if (wd->disabled) return;
1047 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1049 if (wd->longpress_timer)
1051 ecore_timer_del(wd->longpress_timer);
1052 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;
1072 else if (wd->longpress_timer)
1076 dx = wd->downx - ev->cur.canvas.x;
1078 dy = wd->downy - ev->cur.canvas.y;
1081 ((_elm_config->finger_size / 2) *
1082 (_elm_config->finger_size / 2)))
1084 ecore_timer_del(wd->longpress_timer);
1085 wd->longpress_timer = NULL;
1091 _getbase(Evas_Object *obj)
1093 Widget_Data *wd = elm_widget_data_get(obj);
1094 if (!wd) return "base";
1097 if (wd->password) return "base-password";
1100 if (wd->single_line) return "base-single";
1103 switch (wd->linewrap)
1106 return "base-charwrap";
1109 case ELM_WRAP_MIXED:
1110 return "base-mixedwrap";
1113 return "base-nowrap";
1120 if (wd->password) return "base-password";
1123 if (wd->single_line) return "base-single-noedit";
1126 switch (wd->linewrap)
1129 return "base-noedit-charwrap";
1131 return "base-noedit";
1132 case ELM_WRAP_MIXED:
1133 return "base-noedit-mixedwrap";
1136 return "base-nowrap-noedit";
1145 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1147 Widget_Data *wd = elm_widget_data_get(data);
1150 wd->changed = EINA_TRUE;
1151 /* Reset the size hints which are no more relevant.
1152 * Keep the height, this is a hack, but doesn't really matter
1153 * cause we'll re-eval in a moment. */
1154 evas_object_size_hint_min_get(data, NULL, &minh);
1155 evas_object_size_hint_min_set(data, -1, minh);
1157 if (wd->text) eina_stringshare_del(wd->text);
1159 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1160 if (wd->delay_write)
1162 ecore_timer_del(wd->delay_write);
1163 wd->delay_write = NULL;
1165 if ((!wd->autosave) || (!wd->file)) return;
1166 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1170 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1172 Widget_Data *wd = elm_widget_data_get(data);
1176 EINA_LIST_FOREACH(entries, l, entry)
1178 if (entry != data) elm_entry_select_none(entry);
1180 wd->have_selection = EINA_TRUE;
1181 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1182 #ifdef HAVE_ELEMENTARY_X
1183 if (wd->sel_notify_handler)
1185 const char *txt = elm_entry_selection_get(data);
1188 top = elm_widget_top_get(data);
1189 if ((top) && (elm_win_xwindow_get(top)))
1190 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1196 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1198 Widget_Data *wd = elm_widget_data_get(data);
1200 wd->have_selection = EINA_TRUE;
1201 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1202 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1203 elm_entry_selection_get(data));
1207 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1209 Widget_Data *wd = elm_widget_data_get(data);
1211 if (!wd->have_selection) return;
1212 wd->have_selection = EINA_FALSE;
1213 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1214 if (wd->sel_notify_handler)
1218 #ifdef HAVE_ELEMENTARY_X
1221 top = elm_widget_top_get(data);
1222 if ((top) && (elm_win_xwindow_get(top)))
1223 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1226 eina_stringshare_del(wd->cut_sel);
1231 #ifdef HAVE_ELEMENTARY_X
1234 top = elm_widget_top_get(data);
1235 if ((top) && (elm_win_xwindow_get(top)))
1236 elm_selection_clear(ELM_SEL_PRIMARY, data);
1243 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1245 Widget_Data *wd = elm_widget_data_get(data);
1247 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1248 if (wd->sel_notify_handler)
1250 #ifdef HAVE_ELEMENTARY_X
1253 top = elm_widget_top_get(data);
1254 if ((top) && (elm_win_xwindow_get(top)))
1256 wd->selection_asked = EINA_TRUE;
1257 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
1265 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1267 Widget_Data *wd = elm_widget_data_get(data);
1269 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1270 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1271 elm_entry_selection_get(data));
1275 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1277 Widget_Data *wd = elm_widget_data_get(data);
1279 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1280 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1281 elm_entry_selection_get(data));
1282 edje_object_part_text_insert(wd->ent, "elm.text", "");
1283 wd->changed = EINA_TRUE;
1288 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1290 Widget_Data *wd = elm_widget_data_get(data);
1292 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1293 wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1294 if (!wd->deferred_recalc_job)
1296 Evas_Coord cx, cy, cw, ch;
1297 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1298 &cx, &cy, &cw, &ch);
1299 elm_widget_show_region_set(data, cx, cy, cw, ch);
1303 wd->deferred_cur = EINA_TRUE;
1308 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1310 Widget_Data *wd = elm_widget_data_get(data);
1315 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1317 Widget_Data *wd = elm_widget_data_get(data);
1322 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1324 Widget_Data *wd = elm_widget_data_get(data);
1325 Elm_Entry_Anchor_Info ei;
1326 char *buf2, *p, *p2, *n;
1328 p = strrchr(emission, ',');
1331 const Eina_List *geoms;
1335 while (p2 >= emission)
1337 if (*p2 == ',') break;
1341 buf2 = alloca(5 + p - p2);
1342 strncpy(buf2, p2, p - p2);
1345 ei.button = atoi(buf2);
1346 ei.x = ei.y = ei.w = ei.h = 0;
1348 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1351 Evas_Textblock_Rectangle *r;
1353 Evas_Coord px, py, x, y;
1355 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1356 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1357 EINA_LIST_FOREACH(geoms, l, r)
1359 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1360 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1371 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1376 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1378 Widget_Data *wd = elm_widget_data_get(data);
1383 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1385 Widget_Data *wd = elm_widget_data_get(data);
1390 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1392 Widget_Data *wd = elm_widget_data_get(data);
1397 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1399 Widget_Data *wd = elm_widget_data_get(data);
1401 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1405 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1407 Widget_Data *wd = elm_widget_data_get(data);
1409 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1413 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1415 Widget_Data *wd = elm_widget_data_get(data);
1417 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1421 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1423 Widget_Data *wd = elm_widget_data_get(data);
1425 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1428 #ifdef HAVE_ELEMENTARY_X
1430 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1432 Widget_Data *wd = elm_widget_data_get(data);
1433 Ecore_X_Event_Selection_Notify *ev = event;
1434 if (!wd) return ECORE_CALLBACK_PASS_ON;
1435 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1436 return ECORE_CALLBACK_PASS_ON;
1438 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1439 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1441 Ecore_X_Selection_Data_Text *text_data;
1443 text_data = ev->data;
1444 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1446 if (text_data->text)
1448 char *txt = _elm_util_text_to_mkup(text_data->text);
1452 elm_entry_entry_insert(data, txt);
1457 wd->selection_asked = EINA_FALSE;
1459 else if (ev->selection == ECORE_X_SELECTION_XDND)
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 /* Massive FIXME: this should be at the drag point */
1473 elm_entry_entry_insert(data, txt);
1478 wd->drag_selection_asked = EINA_FALSE;
1480 ecore_x_dnd_send_finished();
1483 return ECORE_CALLBACK_PASS_ON;
1487 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1489 Widget_Data *wd = elm_widget_data_get(data);
1490 Ecore_X_Event_Selection_Clear *ev = event;
1491 if (!wd) return ECORE_CALLBACK_PASS_ON;
1492 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1493 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1494 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1496 elm_entry_select_none(data);
1498 return ECORE_CALLBACK_PASS_ON;
1502 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1507 wd = elm_widget_data_get(obj);
1508 if (!wd) return EINA_FALSE;
1509 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1511 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1512 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1513 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1514 EDJE_CURSOR_MAIN,drop->x,drop->y);
1515 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1516 elm_entry_entry_insert(obj, drop->data);
1517 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1518 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1524 static Evas_Object *
1525 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1527 Widget_Data *wd = elm_widget_data_get(data);
1530 Elm_Entry_Item_Provider *ip;
1532 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1534 o = ip->func(ip->data, data, item);
1537 if (!strncmp(item, "file://", 7))
1539 const char *fname = item + 7;
1541 o = evas_object_image_filled_add(evas_object_evas_get(data));
1542 evas_object_image_file_set(o, fname, NULL);
1543 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1545 evas_object_show(o);
1550 o = edje_object_add(evas_object_evas_get(data));
1551 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1555 o = edje_object_add(evas_object_evas_get(data));
1556 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1557 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1562 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
1564 Widget_Data *wd = elm_widget_data_get(data);
1566 Elm_Entry_Text_Filter *tf;
1568 if (type == EDJE_TEXT_FILTER_FORMAT)
1571 EINA_LIST_FOREACH(wd->text_filters, l, tf)
1573 tf->func(tf->data, data, text);
1579 /* This function is used to insert text by chunks in jobs */
1581 _text_append_idler(void *data)
1585 Evas_Object *obj = (Evas_Object *) data;
1586 Widget_Data *wd = elm_widget_data_get(obj);
1587 if (wd->text) eina_stringshare_del(wd->text);
1589 wd->changed = EINA_TRUE;
1591 start = wd->append_text_position;
1592 if(start + _CHUNK_SIZE < wd->append_text_len)
1594 wd->append_text_position = (start + _CHUNK_SIZE);
1595 /* Go to the start of the nearest codepoint, because we don't want
1596 * to cut it in the middle */
1597 eina_unicode_utf8_get_prev(wd->append_text_left,
1598 &wd->append_text_position);
1602 wd->append_text_position = wd->append_text_len;
1605 backup = wd->append_text_left[wd->append_text_position];
1606 wd->append_text_left[wd->append_text_position] = '\0';
1608 edje_object_part_text_append(wd->ent, "elm.text",
1609 wd->append_text_left + start);
1611 wd->append_text_left[wd->append_text_position] = backup;
1615 /* If there's still more to go, renew the idler, else, cleanup */
1616 if (wd->append_text_position < wd->append_text_len)
1618 return ECORE_CALLBACK_RENEW;
1622 free(wd->append_text_left);
1623 wd->append_text_left = NULL;
1624 wd->append_text_idler = NULL;
1625 return ECORE_CALLBACK_CANCEL;
1630 * This adds an entry to @p parent object.
1632 * @param parent The parent object
1633 * @return The new object or NULL if it cannot be created
1638 elm_entry_add(Evas_Object *parent)
1640 Evas_Object *obj, *top;
1644 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1646 ELM_SET_WIDTYPE(widtype, "entry");
1647 elm_widget_type_set(obj, "entry");
1648 elm_widget_sub_object_add(parent, obj);
1649 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1650 elm_widget_data_set(obj, wd);
1651 elm_widget_del_hook_set(obj, _del_hook);
1652 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1653 elm_widget_theme_hook_set(obj, _theme_hook);
1654 elm_widget_disable_hook_set(obj, _disable_hook);
1655 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1656 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
1657 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1658 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1659 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
1660 elm_widget_can_focus_set(obj, EINA_TRUE);
1661 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
1663 wd->linewrap = ELM_WRAP_WORD;
1664 wd->editable = EINA_TRUE;
1665 wd->disabled = EINA_FALSE;
1666 wd->context_menu = EINA_TRUE;
1667 wd->autosave = EINA_TRUE;
1668 wd->textonly = EINA_FALSE;
1670 wd->ent = edje_object_add(e);
1671 edje_object_item_provider_set(wd->ent, _get_item, obj);
1672 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
1673 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1674 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1675 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1677 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1679 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1682 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1683 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1684 _signal_entry_changed, obj);
1685 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1686 _signal_selection_start, obj);
1687 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1688 _signal_selection_changed, obj);
1689 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1690 _signal_selection_cleared, obj);
1691 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1692 _signal_entry_paste_request, obj);
1693 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1694 _signal_entry_copy_notify, obj);
1695 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1696 _signal_entry_cut_notify, obj);
1697 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1698 _signal_cursor_changed, obj);
1699 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1700 _signal_anchor_down, obj);
1701 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1702 _signal_anchor_up, obj);
1703 edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
1704 _signal_anchor_clicked, obj);
1705 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1706 _signal_anchor_move, obj);
1707 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1708 _signal_anchor_in, obj);
1709 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1710 _signal_anchor_out, obj);
1711 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
1712 _signal_key_enter, obj);
1713 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
1714 _signal_mouse_down, obj);
1715 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
1716 _signal_mouse_clicked, obj);
1717 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
1718 _signal_mouse_double, obj);
1719 edje_object_part_text_set(wd->ent, "elm.text", "");
1720 if (_elm_config->desktop_entry)
1721 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
1722 elm_widget_resize_object_set(obj, wd->ent);
1725 #ifdef HAVE_ELEMENTARY_X
1726 top = elm_widget_top_get(obj);
1727 if ((top) && (elm_win_xwindow_get(top)))
1729 wd->sel_notify_handler =
1730 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
1731 _event_selection_notify, obj);
1732 wd->sel_clear_handler =
1733 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
1734 _event_selection_clear, obj);
1737 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
1738 _drag_drop_cb, NULL);
1741 entries = eina_list_prepend(entries, obj);
1743 // module - find module for entry
1744 wd->api = _module(obj);
1745 // if found - hook in
1746 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
1748 _mirrored_set(obj, elm_widget_mirrored_get(obj));
1749 // TODO: convert Elementary to subclassing of Evas_Smart_Class
1750 // TODO: and save some bytes, making descriptions per-class and not instance!
1751 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1756 * This sets the entry object not to line wrap. All input will
1757 * be on a single line, and the entry box will extend with user input.
1759 * @param obj The entry object
1760 * @param single_line If true, the text in the entry
1761 * will be on a single line.
1766 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
1768 ELM_CHECK_WIDTYPE(obj, widtype);
1769 Widget_Data *wd = elm_widget_data_get(obj);
1771 if (wd->single_line == single_line) return;
1772 wd->single_line = single_line;
1773 wd->linewrap = ELM_WRAP_NONE;
1774 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
1779 * This returns true if the entry has been set to single line mode.
1780 * See also elm_entry_single_line_set().
1782 * @param obj The entry object
1783 * @return single_line If true, the text in the entry is set to display
1789 elm_entry_single_line_get(const Evas_Object *obj)
1791 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1792 Widget_Data *wd = elm_widget_data_get(obj);
1793 if (!wd) return EINA_FALSE;
1794 return wd->single_line;
1798 * This sets the entry object to password mode. All text entered
1799 * and/or displayed within the widget will be replaced with asterisks (*).
1801 * @param obj The entry object
1802 * @param password If true, password mode is enabled.
1807 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
1809 ELM_CHECK_WIDTYPE(obj, widtype);
1810 Widget_Data *wd = elm_widget_data_get(obj);
1812 if (wd->password == password) return;
1813 wd->password = password;
1814 wd->single_line = EINA_TRUE;
1815 wd->linewrap = ELM_WRAP_NONE;
1820 * This returns whether password mode is enabled.
1821 * See also elm_entry_password_set().
1823 * @param obj The entry object
1824 * @return If true, the entry is set to display all characters
1830 elm_entry_password_get(const Evas_Object *obj)
1832 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1833 Widget_Data *wd = elm_widget_data_get(obj);
1834 if (!wd) return EINA_FALSE;
1835 return wd->password;
1839 * This sets the text displayed within the entry to @p entry.
1841 * @param obj The entry object
1842 * @param entry The text to be displayed
1847 elm_entry_entry_set(Evas_Object *obj, const char *entry)
1850 ELM_CHECK_WIDTYPE(obj, widtype);
1851 Widget_Data *wd = elm_widget_data_get(obj);
1853 if (!entry) entry = "";
1854 if (wd->text) eina_stringshare_del(wd->text);
1856 wd->changed = EINA_TRUE;
1858 /* Clear currently pending job if there is one */
1859 if (wd->append_text_idler)
1861 ecore_idler_del(wd->append_text_idler);
1862 free(wd->append_text_left);
1863 wd->append_text_left = NULL;
1864 wd->append_text_idler = NULL;
1867 len = strlen(entry);
1868 /* Split to ~_CHUNK_SIZE chunks */
1869 if (len <= _CHUNK_SIZE)
1871 edje_object_part_text_set(wd->ent, "elm.text", entry);
1876 /* Need to clear the entry first */
1877 edje_object_part_text_set(wd->ent, "elm.text", "");
1878 wd->append_text_left = strndup(entry, len);
1879 wd->append_text_position = 0;
1880 wd->append_text_len = len;
1881 wd->append_text_idler = ecore_idler_add(_text_append_idler, obj);
1886 * This returns the text currently shown in object @p entry.
1887 * See also elm_entry_entry_set().
1889 * @param obj The entry object
1890 * @return The currently displayed text or NULL on failure
1895 elm_entry_entry_get(const Evas_Object *obj)
1897 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1898 Widget_Data *wd = elm_widget_data_get(obj);
1900 if (!wd) return NULL;
1901 if (wd->text) return wd->text;
1902 text = edje_object_part_text_get(wd->ent, "elm.text");
1905 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
1908 eina_stringshare_replace(&wd->text, text);
1913 * This returns EINA_TRUE if the entry is empty/there was an error
1914 * and EINA_FALSE if it is not empty.
1916 * @param obj The entry object
1917 * @return If the entry is empty or not.
1922 elm_entry_is_empty(const Evas_Object *obj)
1924 /* FIXME: until there's support for that in textblock, we just check
1925 * to see if the there is text or not. */
1926 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
1927 Widget_Data *wd = elm_widget_data_get(obj);
1928 const Evas_Object *tb;
1929 Evas_Textblock_Cursor *cur;
1931 if (!wd) return EINA_TRUE;
1932 /* It's a hack until we get the support suggested above.
1933 * We just create a cursor, point it to the begining, and then
1934 * try to advance it, if it can advance, the tb is not empty,
1935 * otherwise it is. */
1936 tb = edje_object_part_object_get(wd->ent, "elm.text");
1937 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
1938 actually, ok for the time being, thsese hackish stuff will be removed
1939 once evas 1.0 is out*/
1940 evas_textblock_cursor_pos_set(cur, 0);
1941 ret = evas_textblock_cursor_char_next(cur);
1942 evas_textblock_cursor_free(cur);
1948 * This returns all selected text within the entry.
1950 * @param obj The entry object
1951 * @return The selected text within the entry or NULL on failure
1956 elm_entry_selection_get(const Evas_Object *obj)
1958 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1959 Widget_Data *wd = elm_widget_data_get(obj);
1960 if (!wd) return NULL;
1961 return edje_object_part_text_selection_get(wd->ent, "elm.text");
1965 * This inserts text in @p entry where the current cursor position.
1967 * This inserts text at the cursor position is as if it was typed
1968 * by the user (note this also allows markup which a user
1969 * can't just "type" as it would be converted to escaped text, so this
1970 * call can be used to insert things like emoticon items or bold push/pop
1971 * tags, other font and color change tags etc.)
1973 * @param obj The entry object
1974 * @param entry The text to insert
1979 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
1981 ELM_CHECK_WIDTYPE(obj, widtype);
1982 Widget_Data *wd = elm_widget_data_get(obj);
1984 edje_object_part_text_insert(wd->ent, "elm.text", entry);
1985 wd->changed = EINA_TRUE;
1990 * This enables word line wrapping in the entry object. It is the opposite
1991 * of elm_entry_single_line_set(). Additionally, setting this disables
1992 * character line wrapping.
1994 * @param obj The entry object
1995 * @param wrap If true, the entry will be wrapped once it reaches the end
1996 * of the object. Wrapping will occur at the end of the word before the end of the
2002 elm_entry_line_wrap_set(Evas_Object *obj, Elm_Wrap_Type wrap)
2004 ELM_CHECK_WIDTYPE(obj, widtype);
2005 Widget_Data *wd = elm_widget_data_get(obj);
2007 if (wd->linewrap == wrap) return;
2009 wd->linewrap = wrap;
2014 * This sets the editable attribute of the entry.
2016 * @param obj The entry object
2017 * @param editable If true, the entry will be editable by the user.
2018 * If false, it will be set to the disabled state.
2023 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2025 ELM_CHECK_WIDTYPE(obj, widtype);
2026 Widget_Data *wd = elm_widget_data_get(obj);
2028 if (wd->editable == editable) return;
2029 wd->editable = editable;
2032 #ifdef HAVE_ELEMENTARY_X
2034 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2036 elm_drop_target_del(obj);
2041 * This gets the editable attribute of the entry.
2042 * See also elm_entry_editable_set().
2044 * @param obj The entry object
2045 * @return If true, the entry is editable by the user.
2046 * If false, it is not editable by the user
2051 elm_entry_editable_get(const Evas_Object *obj)
2053 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2054 Widget_Data *wd = elm_widget_data_get(obj);
2055 if (!wd) return EINA_FALSE;
2056 return wd->editable;
2060 * This drops any existing text selection within the entry.
2062 * @param obj The entry object
2067 elm_entry_select_none(Evas_Object *obj)
2069 ELM_CHECK_WIDTYPE(obj, widtype);
2070 Widget_Data *wd = elm_widget_data_get(obj);
2074 wd->selmode = EINA_FALSE;
2075 if (!_elm_config->desktop_entry)
2076 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2077 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2079 wd->have_selection = EINA_FALSE;
2080 edje_object_part_text_select_none(wd->ent, "elm.text");
2084 * This selects all text within the entry.
2086 * @param obj The entry object
2091 elm_entry_select_all(Evas_Object *obj)
2093 ELM_CHECK_WIDTYPE(obj, widtype);
2094 Widget_Data *wd = elm_widget_data_get(obj);
2098 wd->selmode = EINA_FALSE;
2099 if (!_elm_config->desktop_entry)
2100 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2101 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2103 wd->have_selection = EINA_TRUE;
2104 edje_object_part_text_select_all(wd->ent, "elm.text");
2108 * This function returns the geometry of the cursor.
2110 * It's useful if you want to draw something on the cursor (or where it is),
2111 * or for example in the case of scrolled entry where you want to show the
2114 * @param obj The entry object
2115 * @param x returned geometry
2116 * @param y returned geometry
2117 * @param w returned geometry
2118 * @param h returned geometry
2119 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2124 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
2126 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2127 Widget_Data *wd = elm_widget_data_get(obj);
2128 if (!wd) return EINA_FALSE;
2129 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
2134 * This moves the cursor one place to the right within the entry.
2136 * @param obj The entry object
2137 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2142 elm_entry_cursor_next(Evas_Object *obj)
2144 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2145 Widget_Data *wd = elm_widget_data_get(obj);
2146 if (!wd) return EINA_FALSE;
2147 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2151 * This moves the cursor one place to the left within the entry.
2153 * @param obj The entry object
2154 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2159 elm_entry_cursor_prev(Evas_Object *obj)
2161 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2162 Widget_Data *wd = elm_widget_data_get(obj);
2163 if (!wd) return EINA_FALSE;
2164 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2168 * This moves the cursor one line up within the entry.
2170 * @param obj The entry object
2171 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2176 elm_entry_cursor_up(Evas_Object *obj)
2178 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2179 Widget_Data *wd = elm_widget_data_get(obj);
2180 if (!wd) return EINA_FALSE;
2181 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2185 * This moves the cursor one line down within the entry.
2187 * @param obj The entry object
2188 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2193 elm_entry_cursor_down(Evas_Object *obj)
2195 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2196 Widget_Data *wd = elm_widget_data_get(obj);
2197 if (!wd) return EINA_FALSE;
2198 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2202 * This moves the cursor to the beginning of the entry.
2204 * @param obj The entry object
2209 elm_entry_cursor_begin_set(Evas_Object *obj)
2211 ELM_CHECK_WIDTYPE(obj, widtype);
2212 Widget_Data *wd = elm_widget_data_get(obj);
2214 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2218 * This moves the cursor to the end of the entry.
2220 * @param obj The entry object
2225 elm_entry_cursor_end_set(Evas_Object *obj)
2227 ELM_CHECK_WIDTYPE(obj, widtype);
2228 Widget_Data *wd = elm_widget_data_get(obj);
2230 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2234 * This moves the cursor to the beginning of the current line.
2236 * @param obj The entry object
2241 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2243 ELM_CHECK_WIDTYPE(obj, widtype);
2244 Widget_Data *wd = elm_widget_data_get(obj);
2246 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2250 * This moves the cursor to the end of the current line.
2252 * @param obj The entry object
2257 elm_entry_cursor_line_end_set(Evas_Object *obj)
2259 ELM_CHECK_WIDTYPE(obj, widtype);
2260 Widget_Data *wd = elm_widget_data_get(obj);
2262 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2266 * This begins a selection within the entry as though
2267 * the user were holding down the mouse button to make a selection.
2269 * @param obj The entry object
2274 elm_entry_cursor_selection_begin(Evas_Object *obj)
2276 ELM_CHECK_WIDTYPE(obj, widtype);
2277 Widget_Data *wd = elm_widget_data_get(obj);
2279 edje_object_part_text_select_begin(wd->ent, "elm.text");
2283 * This ends a selection within the entry as though
2284 * the user had just released the mouse button while making a selection.
2286 * @param obj The entry object
2291 elm_entry_cursor_selection_end(Evas_Object *obj)
2293 ELM_CHECK_WIDTYPE(obj, widtype);
2294 Widget_Data *wd = elm_widget_data_get(obj);
2296 edje_object_part_text_select_extend(wd->ent, "elm.text");
2300 * TODO: fill this in
2302 * @param obj The entry object
2303 * @return TODO: fill this in
2308 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2310 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2311 Widget_Data *wd = elm_widget_data_get(obj);
2312 if (!wd) return EINA_FALSE;
2313 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2317 * This returns whether the cursor is visible.
2319 * @param obj The entry object
2320 * @return If true, the cursor is visible.
2325 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2327 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2328 Widget_Data *wd = elm_widget_data_get(obj);
2329 if (!wd) return EINA_FALSE;
2330 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2334 * TODO: fill this in
2336 * @param obj The entry object
2337 * @return TODO: fill this in
2342 elm_entry_cursor_content_get(const Evas_Object *obj)
2344 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2345 Widget_Data *wd = elm_widget_data_get(obj);
2346 if (!wd) return NULL;
2347 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2351 * Sets the cursor position in the entry to the given value
2353 * @param obj The entry object
2354 * @param pos The position of the cursor
2359 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
2361 ELM_CHECK_WIDTYPE(obj, widtype);
2362 Widget_Data *wd = elm_widget_data_get(obj);
2364 edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
2365 edje_object_message_signal_process(wd->ent);
2369 * Retrieves the current position of the cursor in the entry
2371 * @param obj The entry object
2372 * @return The cursor position
2377 elm_entry_cursor_pos_get(const Evas_Object *obj)
2379 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2380 Widget_Data *wd = elm_widget_data_get(obj);
2382 return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2386 * This executes a "cut" action on the selected text in the entry.
2388 * @param obj The entry object
2393 elm_entry_selection_cut(Evas_Object *obj)
2395 ELM_CHECK_WIDTYPE(obj, widtype);
2396 Widget_Data *wd = elm_widget_data_get(obj);
2398 _cut(obj, NULL, NULL);
2402 * This executes a "copy" action on the selected text in the entry.
2404 * @param obj The entry object
2409 elm_entry_selection_copy(Evas_Object *obj)
2411 ELM_CHECK_WIDTYPE(obj, widtype);
2412 Widget_Data *wd = elm_widget_data_get(obj);
2414 _copy(obj, NULL, NULL);
2418 * This executes a "paste" action in the entry.
2420 * @param obj The entry object
2425 elm_entry_selection_paste(Evas_Object *obj)
2427 ELM_CHECK_WIDTYPE(obj, widtype);
2428 Widget_Data *wd = elm_widget_data_get(obj);
2430 _paste(obj, NULL, NULL);
2434 * This clears and frees the items in a entry's contextual (right click) menu.
2436 * @param obj The entry object
2441 elm_entry_context_menu_clear(Evas_Object *obj)
2443 ELM_CHECK_WIDTYPE(obj, widtype);
2444 Widget_Data *wd = elm_widget_data_get(obj);
2445 Elm_Entry_Context_Menu_Item *it;
2447 EINA_LIST_FREE(wd->items, it)
2449 eina_stringshare_del(it->label);
2450 eina_stringshare_del(it->icon_file);
2451 eina_stringshare_del(it->icon_group);
2457 * This adds an item to the entry's contextual menu.
2459 * @param obj The entry object
2460 * @param label The item's text label
2461 * @param icon_file The item's icon file
2462 * @param icon_type The item's icon type
2463 * @param func The callback to execute when the item is clicked
2464 * @param data The data to associate with the item for related functions
2469 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)
2471 ELM_CHECK_WIDTYPE(obj, widtype);
2472 Widget_Data *wd = elm_widget_data_get(obj);
2473 Elm_Entry_Context_Menu_Item *it;
2475 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2477 wd->items = eina_list_append(wd->items, it);
2479 it->label = eina_stringshare_add(label);
2480 it->icon_file = eina_stringshare_add(icon_file);
2481 it->icon_type = icon_type;
2483 it->data = (void *)data;
2487 * This disables the entry's contextual (right click) menu.
2489 * @param obj The entry object
2490 * @param disabled If true, the menu is disabled
2495 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2497 ELM_CHECK_WIDTYPE(obj, widtype);
2498 Widget_Data *wd = elm_widget_data_get(obj);
2500 if (wd->context_menu == !disabled) return;
2501 wd->context_menu = !disabled;
2505 * This returns whether the entry's contextual (right click) menu is disabled.
2507 * @param obj The entry object
2508 * @return If true, the menu is disabled
2513 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2515 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2516 Widget_Data *wd = elm_widget_data_get(obj);
2517 if (!wd) return EINA_FALSE;
2518 return !wd->context_menu;
2522 * This appends a custom item provider to the list for that entry
2524 * This appends the given callback. The list is walked from beginning to end
2525 * with each function called given the item href string in the text. If the
2526 * function returns an object handle other than NULL (it should create an
2527 * and object to do this), then this object is used to replace that item. If
2528 * not the next provider is called until one provides an item object, or the
2529 * default provider in entry does.
2531 * @param obj The entry object
2532 * @param func The function called to provide the item object
2533 * @param data The data passed to @p func
2538 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2540 ELM_CHECK_WIDTYPE(obj, widtype);
2541 Widget_Data *wd = elm_widget_data_get(obj);
2543 EINA_SAFETY_ON_NULL_RETURN(func);
2544 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2548 wd->item_providers = eina_list_append(wd->item_providers, ip);
2552 * This prepends a custom item provider to the list for that entry
2554 * This prepends the given callback. See elm_entry_item_provider_append() for
2557 * @param obj The entry object
2558 * @param func The function called to provide the item object
2559 * @param data The data passed to @p func
2564 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2566 ELM_CHECK_WIDTYPE(obj, widtype);
2567 Widget_Data *wd = elm_widget_data_get(obj);
2569 EINA_SAFETY_ON_NULL_RETURN(func);
2570 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2574 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2578 * This removes a custom item provider to the list for that entry
2580 * This removes the given callback. See elm_entry_item_provider_append() for
2583 * @param obj The entry object
2584 * @param func The function called to provide the item object
2585 * @param data The data passed to @p func
2590 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2592 ELM_CHECK_WIDTYPE(obj, widtype);
2593 Widget_Data *wd = elm_widget_data_get(obj);
2595 Elm_Entry_Item_Provider *ip;
2597 EINA_SAFETY_ON_NULL_RETURN(func);
2598 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2600 if ((ip->func == func) && ((!data) || (ip->data == data)))
2602 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2610 * Append a filter function for text inserted in the entry
2612 * Append the given callback to the list. This functions will be called
2613 * whenever any text is inserted into the entry, with the text to be inserted
2614 * as a parameter. The callback function is free to alter the text in any way
2615 * it wants, but it must remember to free the given pointer and update it.
2616 * If the new text is to be discarded, the function can free it and set it text
2617 * parameter to NULL. This will also prevent any following filters from being
2620 * @param obj The entry object
2621 * @param func The function to use as text filter
2622 * @param data User data to pass to @p func
2627 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2630 Elm_Entry_Text_Filter *tf;
2631 ELM_CHECK_WIDTYPE(obj, widtype);
2633 wd = elm_widget_data_get(obj);
2635 EINA_SAFETY_ON_NULL_RETURN(func);
2637 tf = _filter_new(func, data);
2640 wd->text_filters = eina_list_append(wd->text_filters, tf);
2644 * Prepend a filter function for text insdrted in the entry
2646 * Prepend the given callback to the list. See elm_entry_text_filter_append()
2647 * for more information
2649 * @param obj The entry object
2650 * @param func The function to use as text filter
2651 * @param data User data to pass to @p func
2656 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2659 Elm_Entry_Text_Filter *tf;
2660 ELM_CHECK_WIDTYPE(obj, widtype);
2662 wd = elm_widget_data_get(obj);
2664 EINA_SAFETY_ON_NULL_RETURN(func);
2666 tf = _filter_new(func, data);
2669 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
2673 * Remove a filter from the list
2675 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
2676 * for more information.
2678 * @param obj The entry object
2679 * @param func The filter function to remove
2680 * @param data The user data passed when adding the function
2685 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2689 Elm_Entry_Text_Filter *tf;
2690 ELM_CHECK_WIDTYPE(obj, widtype);
2692 wd = elm_widget_data_get(obj);
2694 EINA_SAFETY_ON_NULL_RETURN(func);
2696 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2698 if ((tf->func == func) && ((!data) || (tf->data == data)))
2700 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
2708 * This converts a markup (HTML-like) string into UTF-8.
2709 * Returning string is obtained with malloc.
2710 * After use the returned string, it should be freed.
2712 * @param s The string (in markup) to be converted
2713 * @return The converted string (in UTF-8). It should be freed.
2718 elm_entry_markup_to_utf8(const char *s)
2720 char *ss = _elm_util_mkup_to_text(s);
2721 if (!ss) ss = strdup("");
2726 * This converts a UTF-8 string into markup (HTML-like).
2727 * Returning string is obtained with malloc.
2728 * After use the returned string, it should be freed.
2730 * @param s The string (in UTF-8) to be converted
2731 * @return The converted string (in markup). It should be freed.
2736 elm_entry_utf8_to_markup(const char *s)
2738 char *ss = _elm_util_text_to_mkup(s);
2739 if (!ss) ss = strdup("");
2744 * Filter inserted text based on user defined character and byte limits
2746 * Add this filter to an entry to limit the characters that it will accept
2747 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
2748 * The funtion works on the UTF-8 representation of the string, converting
2749 * it from the set markup, thus not accounting for any format in it.
2751 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
2752 * it as data when setting the filter. In it it's possible to set limits
2753 * by character count or bytes (any of them is disabled if 0), and both can
2754 * be set at the same time. In that case, it first checks for characters,
2757 * The function will cut the inserted text in order to allow only the first
2758 * number of characters that are still allowed. The cut is made in
2759 * characters, even when limiting by bytes, in order to always contain
2760 * valid ones and avoid half unicode characters making it in.
2765 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
2767 Elm_Entry_Filter_Limit_Size *lim = data;
2770 const char *(*text_get)(const Evas_Object *);
2771 const char *widget_type;
2773 EINA_SAFETY_ON_NULL_RETURN(data);
2774 EINA_SAFETY_ON_NULL_RETURN(entry);
2775 EINA_SAFETY_ON_NULL_RETURN(text);
2777 /* hack. I don't want to copy the entire function to work with
2779 widget_type = elm_widget_type_get(entry);
2780 if (!strcmp(widget_type, "entry"))
2781 text_get = elm_entry_entry_get;
2782 else if (!strcmp(widget_type, "scrolled_entry"))
2783 text_get = elm_scrolled_entry_entry_get;
2787 current = elm_entry_markup_to_utf8(text_get(entry));
2789 if (lim->max_char_count > 0)
2792 len = evas_string_char_len_get(current);
2793 if (len >= lim->max_char_count)
2800 newlen = evas_string_char_len_get(*text);
2801 cut = strlen(*text);
2802 while ((len + newlen) > lim->max_char_count)
2804 cut = evas_string_char_prev_get(*text, cut, NULL);
2810 if (lim->max_byte_count > 0)
2812 len = strlen(current);
2813 if (len >= lim->max_byte_count)
2820 newlen = strlen(*text);
2821 while ((len + newlen) > lim->max_byte_count)
2823 int p = evas_string_char_prev_get(*text, newlen, NULL);
2824 newlen -= (newlen - p);
2827 (*text)[newlen] = 0;
2838 * Filter inserted text based on accepted or rejected sets of characters
2840 * Add this filter to an entry to restrict the set of accepted characters
2841 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
2842 * This structure contains both accepted and rejected sets, but they are
2843 * mutually exclusive. If accepted is set, it will be used, otherwise it
2844 * goes on to the rejected set.
2847 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
2849 Elm_Entry_Filter_Accept_Set *as = data;
2853 int read_idx, last_read_idx = 0, read_char;
2855 EINA_SAFETY_ON_NULL_RETURN(data);
2856 EINA_SAFETY_ON_NULL_RETURN(text);
2858 if ((!as->accepted) && (!as->rejected))
2864 goes_in = EINA_TRUE;
2869 goes_in = EINA_FALSE;
2873 read_idx = evas_string_char_next_get(*text, 0, &read_char);
2876 int cmp_idx, cmp_char;
2877 Eina_Bool in_set = EINA_FALSE;
2879 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
2882 if (read_char == cmp_char)
2887 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
2889 if (in_set == goes_in)
2891 int size = read_idx - last_read_idx;
2892 const char *src = (*text) + last_read_idx;
2894 memcpy(insert, *text + last_read_idx, size);
2897 last_read_idx = read_idx;
2898 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
2904 * This sets the file (and implicitly loads it) for the text to display and
2905 * then edit. All changes are written back to the file after a short delay if
2906 * the entry object is set to autosave.
2908 * @param obj The entry object
2909 * @param file The path to the file to load and save
2910 * @param format The file format
2915 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
2917 ELM_CHECK_WIDTYPE(obj, widtype);
2918 Widget_Data *wd = elm_widget_data_get(obj);
2920 if (wd->delay_write)
2922 ecore_timer_del(wd->delay_write);
2923 wd->delay_write = NULL;
2925 if (wd->autosave) _save(obj);
2926 eina_stringshare_replace(&wd->file, file);
2927 wd->format = format;
2932 * Gets the file to load and save and the file format
2934 * @param obj The entry object
2935 * @param file The path to the file to load and save
2936 * @param format The file format
2941 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
2943 ELM_CHECK_WIDTYPE(obj, widtype);
2944 Widget_Data *wd = elm_widget_data_get(obj);
2946 if (file) *file = wd->file;
2947 if (format) *format = wd->format;
2951 * This function writes any changes made to the file set with
2952 * elm_entry_file_set()
2954 * @param obj The entry object
2959 elm_entry_file_save(Evas_Object *obj)
2961 ELM_CHECK_WIDTYPE(obj, widtype);
2962 Widget_Data *wd = elm_widget_data_get(obj);
2964 if (wd->delay_write)
2966 ecore_timer_del(wd->delay_write);
2967 wd->delay_write = NULL;
2970 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
2974 * This sets the entry object to 'autosave' the loaded text file or not.
2976 * @param obj The entry object
2977 * @param autosave Autosave the loaded file or not
2982 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
2984 ELM_CHECK_WIDTYPE(obj, widtype);
2985 Widget_Data *wd = elm_widget_data_get(obj);
2987 wd->autosave = !!autosave;
2991 * This gets the entry object's 'autosave' status.
2993 * @param obj The entry object
2994 * @return Autosave the loaded file or not
2999 elm_entry_autosave_get(const Evas_Object *obj)
3001 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3002 Widget_Data *wd = elm_widget_data_get(obj);
3003 if (!wd) return EINA_FALSE;
3004 return wd->autosave;
3008 * Control pasting of text and images for the widget.
3010 * Normally the entry allows both text and images to be pasted. By setting
3011 * textonly to be true, this prevents images from being pasted.
3013 * Note this only changes the behaviour of text.
3015 * @param obj The entry object
3016 * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is text+image+other.
3021 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
3023 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
3024 ELM_CHECK_WIDTYPE(obj, widtype);
3025 Widget_Data *wd = elm_widget_data_get(obj);
3027 textonly = !!textonly;
3028 if (wd->textonly == textonly) return;
3029 wd->textonly = !!textonly;
3030 if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
3031 #ifdef HAVE_ELEMENTARY_X
3032 elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
3037 * Getting elm_entry text paste/drop mode.
3039 * In textonly mode, only text may be pasted or dropped into the widget.
3041 * @param obj The entry object
3042 * @return If the widget only accepts text from pastes.
3047 elm_entry_cnp_textonly_get(Evas_Object *obj)
3049 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3050 Widget_Data *wd = elm_widget_data_get(obj);
3051 if (!wd) return EINA_FALSE;
3052 return wd->textonly;