1 #include <Elementary.h>
2 #include <Elementary_Cursor.h>
6 * @defgroup Entry Entry
8 * An entry is a convenience widget which shows
9 * a box that the user can enter text into. Unlike a
10 * @ref Scrolled_Entry widget, entries DO NOT scroll with user
11 * input. Entry widgets are capable of expanding past the
12 * boundaries of the window, thus resizing the window to its
15 * You can also insert "items" in the entry with:
17 * \<item size=16x16 vsize=full href=emoticon/haha\>\</item\>
19 * for example. sizing can be set bu size=WxH, relsize=WxH or absize=WxH with
20 * vsize=ascent or vsize=full. the href=NAME sets the item name. Entry
21 * supports a list of emoticon names by default. These are:
24 * - emoticon/angry-shout
25 * - emoticon/crazy-laugh
26 * - emoticon/evil-laugh
28 * - emoticon/goggle-smile
30 * - emoticon/grumpy-smile
32 * - emoticon/guilty-smile
34 * - emoticon/half-smile
35 * - emoticon/happy-panting
37 * - emoticon/indifferent
39 * - emoticon/knowing-grin
41 * - emoticon/little-bit-sorry
42 * - emoticon/love-lots
44 * - emoticon/minimal-smile
45 * - emoticon/not-happy
46 * - emoticon/not-impressed
48 * - emoticon/opensmile
51 * - emoticon/squint-laugh
52 * - emoticon/surprised
53 * - emoticon/suspicious
54 * - emoticon/tongue-dangling
55 * - emoticon/tongue-poke
58 * - emoticon/very-sorry
64 * These are built-in currently, but you can add your own item provieer that
65 * can create inlined objects in the text and fill the space allocated to the
66 * item with a custom object of your own.
68 * See the entry test for some more examples of use of this.
70 * Entries have functions to load a text file, display it,
71 * allowing editing of it and saving of changes back to the file loaded.
72 * Changes are written back to the original file after a short delay.
73 * The file to load and save to is specified by elm_entry_file_set().
75 * Signals that you can add callbacks for are:
76 * - "changed" - The text within the entry was changed
77 * - "activated" - The entry has had editing finished and changes are to be committed (generally when enter key is pressed)
78 * - "press" - The entry has been clicked
79 * - "longpressed" - The entry has been clicked for a couple seconds
80 * - "clicked" - The entry has been clicked
81 * - "clicked,double" - The entry has been double clicked
82 * - "focused" - The entry has received focus
83 * - "unfocused" - The entry has lost focus
84 * - "selection,paste" - A paste action has occurred
85 * - "selection,copy" - A copy action has occurred
86 * - "selection,cut" - A cut action has occurred
87 * - "selection,start" - A selection has begun
88 * - "selection,changed" - The selection has changed
89 * - "selection,cleared" - The selection has been cleared
90 * - "cursor,changed" - The cursor has changed
91 * - "anchor,clicked" - The anchor has been clicked
94 typedef struct _Mod_Api Mod_Api;
96 typedef struct _Widget_Data Widget_Data;
97 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
98 typedef struct _Elm_Entry_Item_Provider Elm_Entry_Item_Provider;
99 typedef struct _Elm_Entry_Text_Filter Elm_Entry_Text_Filter;
104 Evas_Object *hoversel;
105 Ecore_Job *deferred_recalc_job;
106 Ecore_Event_Handler *sel_notify_handler;
107 Ecore_Event_Handler *sel_clear_handler;
108 Ecore_Timer *longpress_timer;
109 Ecore_Timer *delay_write;
110 /* Only for clipboard */
114 Elm_Text_Format format;
116 Evas_Coord downx, downy;
117 Evas_Coord cx, cy, cw, ch;
119 Eina_List *item_providers;
120 Eina_List *text_filters;
121 Ecore_Job *hovdeljob;
122 Mod_Api *api; // module api if supplied
124 Eina_Bool changed : 1;
125 Eina_Bool linewrap : 1;
126 Eina_Bool char_linewrap : 1;
127 Eina_Bool single_line : 1;
128 Eina_Bool password : 1;
129 Eina_Bool editable : 1;
130 Eina_Bool selection_asked : 1;
131 Eina_Bool have_selection : 1;
132 Eina_Bool selmode : 1;
133 Eina_Bool deferred_cur : 1;
134 Eina_Bool disabled : 1;
135 Eina_Bool context_menu : 1;
136 Eina_Bool drag_selection_asked : 1;
137 Eina_Bool can_write : 1;
138 Eina_Bool autosave : 1;
139 Eina_Bool textonly : 1;
140 Eina_Bool usedown : 1;
143 struct _Elm_Entry_Context_Menu_Item
147 const char *icon_file;
148 const char *icon_group;
149 Elm_Icon_Type icon_type;
154 struct _Elm_Entry_Item_Provider
156 Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
160 struct _Elm_Entry_Text_Filter
162 void (*func) (void *data, Evas_Object *entry, char **text);
166 static const char *widtype = NULL;
168 #ifdef HAVE_ELEMENTARY_X
169 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
171 static void _del_hook(Evas_Object *obj);
172 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
173 static void _theme_hook(Evas_Object *obj);
174 static void _disable_hook(Evas_Object *obj);
175 static void _sizing_eval(Evas_Object *obj);
176 static void _on_focus_hook(void *data, Evas_Object *obj);
177 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
178 static const char *_getbase(Evas_Object *obj);
179 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
180 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
181 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
182 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
183 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
184 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
185 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
186 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
188 static const char SIG_CHANGED[] = "changed";
189 static const char SIG_ACTIVATED[] = "activated";
190 static const char SIG_PRESS[] = "press";
191 static const char SIG_LONGPRESSED[] = "longpressed";
192 static const char SIG_CLICKED[] = "clicked";
193 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
194 static const char SIG_FOCUSED[] = "focused";
195 static const char SIG_UNFOCUSED[] = "unfocused";
196 static const char SIG_SELECTION_PASTE[] = "selection,paste";
197 static const char SIG_SELECTION_COPY[] = "selection,copy";
198 static const char SIG_SELECTION_CUT[] = "selection,cut";
199 static const char SIG_SELECTION_START[] = "selection,start";
200 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
201 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
202 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
203 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
204 static const Evas_Smart_Cb_Description _signals[] = {
208 {SIG_LONGPRESSED, ""},
210 {SIG_CLICKED_DOUBLE, ""},
213 {SIG_SELECTION_PASTE, ""},
214 {SIG_SELECTION_COPY, ""},
215 {SIG_SELECTION_CUT, ""},
216 {SIG_SELECTION_START, ""},
217 {SIG_SELECTION_CHANGED, ""},
218 {SIG_SELECTION_CLEARED, ""},
219 {SIG_CURSOR_CHANGED, ""},
220 {SIG_ANCHOR_CLICKED, ""},
224 static Eina_List *entries = NULL;
228 void (*obj_hook) (Evas_Object *obj);
229 void (*obj_unhook) (Evas_Object *obj);
230 void (*obj_longpress) (Evas_Object *obj);
234 _module(Evas_Object *obj __UNUSED__)
236 static Elm_Module *m = NULL;
237 if (m) goto ok; // already found - just use
238 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
240 m->api = malloc(sizeof(Mod_Api));
241 if (!m->api) return NULL;
242 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
243 _elm_module_symbol_get(m, "obj_hook");
244 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
245 _elm_module_symbol_get(m, "obj_unhook");
246 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
247 _elm_module_symbol_get(m, "obj_longpress");
248 ok: // ok - return api
253 _buf_append(char *buf, const char *str, int *len, int *alloc)
255 int len2 = strlen(str);
256 if ((*len + len2) >= *alloc)
258 char *buf2 = realloc(buf, *alloc + len2 + 512);
259 if (!buf2) return NULL;
261 *alloc += (512 + len2);
263 strcpy(buf + *len, str);
269 _load_file(const char *file)
273 int alloc = 0, len = 0;
274 char *text = NULL, buf[16384 + 1];
276 f = fopen(file, "rb");
278 while ((size = fread(buf, 1, sizeof(buf) - 1, f)))
282 tmp_text = _buf_append(text, buf, &len, &alloc);
283 if (!tmp_text) break;
291 _load_plain(const char *file)
295 text = _load_file(file);
300 text2 = elm_entry_utf8_to_markup(text);
308 _load(Evas_Object *obj)
310 Widget_Data *wd = elm_widget_data_get(obj);
315 elm_entry_entry_set(obj, "");
320 case ELM_TEXT_FORMAT_PLAIN_UTF8:
321 text = _load_plain(wd->file);
323 case ELM_TEXT_FORMAT_MARKUP_UTF8:
324 text = _load_file(wd->file);
332 elm_entry_entry_set(obj, text);
336 elm_entry_entry_set(obj, "");
340 _save_markup_utf8(const char *file, const char *text)
344 if ((!text) || (!text[0]))
346 ecore_file_unlink(file);
349 f = fopen(file, "wb");
352 // FIXME: report a write error
355 fputs(text, f); // FIXME: catch error
360 _save_plain_utf8(const char *file, const char *text)
364 text2 = elm_entry_markup_to_utf8(text);
367 _save_markup_utf8(file, text2);
372 _save(Evas_Object *obj)
374 Widget_Data *wd = elm_widget_data_get(obj);
376 if (!wd->file) return;
379 case ELM_TEXT_FORMAT_PLAIN_UTF8:
380 _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
382 case ELM_TEXT_FORMAT_MARKUP_UTF8:
383 _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
391 _delay_write(void *data)
393 Widget_Data *wd = elm_widget_data_get(data);
394 if (!wd) return ECORE_CALLBACK_CANCEL;
396 wd->delay_write = NULL;
397 return ECORE_CALLBACK_CANCEL;
400 static Elm_Entry_Text_Filter *
401 _filter_new(void (*func) (void *data, Evas_Object *entry, char **text), void *data)
403 Elm_Entry_Text_Filter *tf = ELM_NEW(Elm_Entry_Text_Filter);
404 if (!tf) return NULL;
407 if (func == elm_entry_filter_limit_size)
409 Elm_Entry_Filter_Limit_Size *lim = data, *lim2;
416 lim2 = malloc(sizeof(Elm_Entry_Filter_Limit_Size));
422 memcpy(lim2, lim, sizeof(Elm_Entry_Filter_Limit_Size));
425 else if (func == elm_entry_filter_accept_set)
427 Elm_Entry_Filter_Accept_Set *as = data, *as2;
434 as2 = malloc(sizeof(Elm_Entry_Filter_Accept_Set));
441 as2->accepted = eina_stringshare_add(as->accepted);
443 as2->accepted = NULL;
445 as2->rejected = eina_stringshare_add(as->rejected);
447 as2->rejected = NULL;
456 _filter_free(Elm_Entry_Text_Filter *tf)
458 if (tf->func == elm_entry_filter_limit_size)
460 Elm_Entry_Filter_Limit_Size *lim = tf->data;
463 else if (tf->func == elm_entry_filter_accept_set)
465 Elm_Entry_Filter_Accept_Set *as = tf->data;
468 if (as->accepted) eina_stringshare_del(as->accepted);
469 if (as->rejected) eina_stringshare_del(as->rejected);
477 _del_pre_hook(Evas_Object *obj)
479 Widget_Data *wd = elm_widget_data_get(obj);
483 ecore_timer_del(wd->delay_write);
484 wd->delay_write = NULL;
485 if (wd->autosave) _save(obj);
490 _del_hook(Evas_Object *obj)
492 Widget_Data *wd = elm_widget_data_get(obj);
493 Elm_Entry_Context_Menu_Item *it;
494 Elm_Entry_Item_Provider *ip;
495 Elm_Entry_Text_Filter *tf;
497 if (wd->file) eina_stringshare_del(wd->file);
499 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
500 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
502 entries = eina_list_remove(entries, obj);
503 #ifdef HAVE_ELEMENTARY_X
504 ecore_event_handler_del(wd->sel_notify_handler);
505 ecore_event_handler_del(wd->sel_clear_handler);
507 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
508 if (wd->text) eina_stringshare_del(wd->text);
509 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
510 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
511 EINA_LIST_FREE(wd->items, it)
513 eina_stringshare_del(it->label);
514 eina_stringshare_del(it->icon_file);
515 eina_stringshare_del(it->icon_group);
518 EINA_LIST_FREE(wd->item_providers, ip)
522 EINA_LIST_FREE(wd->text_filters, tf)
530 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
532 Widget_Data *wd = elm_widget_data_get(obj);
533 edje_object_mirrored_set(wd->ent, rtl);
537 _theme_hook(Evas_Object *obj)
539 Widget_Data *wd = elm_widget_data_get(obj);
541 _elm_widget_mirrored_reload(obj);
542 _mirrored_set(obj, elm_widget_mirrored_get(obj));
544 t = eina_stringshare_add(elm_entry_entry_get(obj));
545 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
546 if (_elm_config->desktop_entry)
547 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
548 elm_entry_entry_set(obj, t);
549 eina_stringshare_del(t);
550 if (elm_widget_disabled_get(obj))
551 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
552 elm_entry_cursor_pos_set(obj, wd->cursor_pos);
553 if (elm_widget_focus_get(obj))
554 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
555 edje_object_message_signal_process(wd->ent);
556 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
561 _disable_hook(Evas_Object *obj)
563 Widget_Data *wd = elm_widget_data_get(obj);
565 if (elm_widget_disabled_get(obj))
567 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
568 wd->disabled = EINA_TRUE;
572 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
573 wd->disabled = EINA_FALSE;
578 _elm_win_recalc_job(void *data)
580 Widget_Data *wd = elm_widget_data_get(data);
581 Evas_Coord minw = -1, minh = -1, maxh = -1;
582 Evas_Coord resw, resh, minminw;
584 wd->deferred_recalc_job = NULL;
585 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
587 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, 0, 0);
588 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
590 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
591 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
592 evas_object_size_hint_min_set(data, minminw, minh);
593 if (wd->single_line) maxh = minh;
594 evas_object_size_hint_max_set(data, -1, maxh);
595 if (wd->deferred_cur)
596 elm_widget_show_region_set(data, wd->cx, wd->cy, wd->cw, wd->ch);
600 _sizing_eval(Evas_Object *obj)
602 Widget_Data *wd = elm_widget_data_get(obj);
603 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
604 Evas_Coord resw, resh;
606 if ((wd->linewrap) || (wd->char_linewrap))
608 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
609 if ((resw == wd->lastw) && (!wd->changed)) return;
610 wd->changed = EINA_FALSE;
612 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
613 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
617 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
618 edje_object_size_min_calc(wd->ent, &minw, &minh);
619 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
620 evas_object_size_hint_min_set(obj, minw, minh);
621 if (wd->single_line) maxh = minh;
622 evas_object_size_hint_max_set(obj, maxw, maxh);
627 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
629 Widget_Data *wd = elm_widget_data_get(obj);
630 Evas_Object *top = elm_widget_top_get(obj);
632 if (!wd->editable) return;
633 if (elm_widget_focus_get(obj))
635 evas_object_focus_set(wd->ent, EINA_TRUE);
636 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
637 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
638 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
642 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
643 evas_object_focus_set(wd->ent, EINA_FALSE);
644 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
645 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
650 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
652 Widget_Data *wd = elm_widget_data_get(obj);
654 edje_object_signal_emit(wd->ent, emission, source);
658 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
660 Widget_Data *wd = elm_widget_data_get(obj);
662 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
666 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, void (*func_cb) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
668 Widget_Data *wd = elm_widget_data_get(obj);
669 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
674 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
676 Widget_Data *wd = elm_widget_data_get(obj);
677 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
681 _hoversel_position(Evas_Object *obj)
683 Widget_Data *wd = elm_widget_data_get(obj);
684 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
689 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
698 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
700 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
711 evas_object_move(wd->hoversel, x + cx, y + cy);
712 evas_object_resize(wd->hoversel, cw, ch);
716 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
718 Widget_Data *wd = elm_widget_data_get(data);
720 if (wd->hoversel) _hoversel_position(data);
724 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
726 Widget_Data *wd = elm_widget_data_get(data);
728 if ((wd->linewrap) || (wd->char_linewrap))
732 if (wd->hoversel) _hoversel_position(data);
733 // Evas_Coord ww, hh;
734 // evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
738 _hover_del(void *data)
740 Widget_Data *wd = elm_widget_data_get(data);
745 evas_object_del(wd->hoversel);
748 wd->hovdeljob = NULL;
752 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
754 Widget_Data *wd = elm_widget_data_get(data);
757 if (wd->hoversel) evas_object_hide(wd->hoversel);
760 if (!_elm_config->desktop_entry)
763 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
766 elm_widget_scroll_freeze_pop(data);
767 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
768 wd->hovdeljob = ecore_job_add(_hover_del, data);
772 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
774 Widget_Data *wd = elm_widget_data_get(data);
776 wd->selmode = EINA_TRUE;
777 edje_object_part_text_select_none(wd->ent, "elm.text");
778 if (!_elm_config->desktop_entry)
781 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
783 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
784 if (!_elm_config->desktop_entry)
785 elm_widget_scroll_hold_push(data);
789 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
791 Widget_Data *wd = elm_widget_data_get(data);
793 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
794 if (wd->sel_notify_handler)
796 #ifdef HAVE_ELEMENTARY_X
797 Elm_Sel_Format formats;
798 wd->selection_asked = EINA_TRUE;
799 formats = ELM_SEL_FORMAT_MARKUP;
801 formats |= ELM_SEL_FORMAT_IMAGE;
802 elm_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL);
808 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
810 Widget_Data *wd = elm_widget_data_get(obj);
814 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
815 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
816 if (seltype == ELM_SEL_CLIPBOARD)
817 eina_stringshare_replace(&wd->cut_sel, sel);
821 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
823 Widget_Data *wd = elm_widget_data_get(data);
826 wd->selmode = EINA_FALSE;
827 if (!_elm_config->desktop_entry)
828 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
829 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
830 if (!_elm_config->desktop_entry)
831 elm_widget_scroll_hold_pop(data);
832 _store_selection(ELM_SEL_CLIPBOARD, data);
833 edje_object_part_text_insert(wd->ent, "elm.text", "");
834 edje_object_part_text_select_none(wd->ent, "elm.text");
838 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
840 Widget_Data *wd = elm_widget_data_get(data);
842 wd->selmode = EINA_FALSE;
843 if (!_elm_config->desktop_entry)
845 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
846 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
847 elm_widget_scroll_hold_pop(data);
849 _store_selection(ELM_SEL_CLIPBOARD, data);
850 // edje_object_part_text_select_none(wd->ent, "elm.text");
854 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
856 Widget_Data *wd = elm_widget_data_get(data);
858 wd->selmode = EINA_FALSE;
859 if (!_elm_config->desktop_entry)
860 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
861 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
862 if (!_elm_config->desktop_entry)
863 elm_widget_scroll_hold_pop(data);
864 edje_object_part_text_select_none(wd->ent, "elm.text");
868 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
870 Elm_Entry_Context_Menu_Item *it = data;
871 Evas_Object *obj2 = it->obj;
872 if (it->func) it->func(it->data, obj2, NULL);
876 _menu_press(Evas_Object *obj)
878 Widget_Data *wd = elm_widget_data_get(obj);
881 const Elm_Entry_Context_Menu_Item *it;
883 if ((wd->api) && (wd->api->obj_longpress))
885 wd->api->obj_longpress(obj);
887 else if (wd->context_menu)
889 const char *context_menu_orientation;
891 if (wd->hoversel) evas_object_del(wd->hoversel);
892 else elm_widget_scroll_freeze_push(obj);
893 wd->hoversel = elm_hoversel_add(obj);
894 context_menu_orientation = edje_object_data_get
895 (wd->ent, "context_menu_orientation");
896 if ((context_menu_orientation) &&
897 (!strcmp(context_menu_orientation, "horizontal")))
898 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
899 elm_object_style_set(wd->hoversel, "entry");
900 elm_widget_sub_object_add(obj, wd->hoversel);
901 elm_hoversel_label_set(wd->hoversel, "Text");
902 top = elm_widget_top_get(obj);
903 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
904 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, obj);
907 if (!_elm_config->desktop_entry)
910 elm_hoversel_item_add(wd->hoversel, E_("Select"), NULL, ELM_ICON_NONE,
913 if (1) // need way to detect if someone has a selection
916 elm_hoversel_item_add(wd->hoversel, E_("Paste"), NULL, ELM_ICON_NONE,
924 if (wd->have_selection)
926 elm_hoversel_item_add(wd->hoversel, E_("Copy"), NULL, ELM_ICON_NONE,
929 elm_hoversel_item_add(wd->hoversel, E_("Cut"), NULL, ELM_ICON_NONE,
932 elm_hoversel_item_add(wd->hoversel, E_("Cancel"), NULL, ELM_ICON_NONE,
936 EINA_LIST_FOREACH(wd->items, l, it)
938 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
939 it->icon_type, _item_clicked, it);
943 _hoversel_position(obj);
944 evas_object_show(wd->hoversel);
945 elm_hoversel_hover_begin(wd->hoversel);
947 if (!_elm_config->desktop_entry)
949 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
950 edje_object_part_text_select_abort(wd->ent, "elm.text");
956 _long_press(void *data)
958 Widget_Data *wd = elm_widget_data_get(data);
959 if (!wd) return ECORE_CALLBACK_CANCEL;
961 wd->longpress_timer = NULL;
962 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
963 return ECORE_CALLBACK_CANCEL;
967 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
969 Widget_Data *wd = elm_widget_data_get(data);
970 Evas_Event_Mouse_Down *ev = event_info;
972 if (wd->disabled) return;
973 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
974 wd->downx = ev->canvas.x;
975 wd->downy = ev->canvas.y;
978 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
979 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
984 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
986 Widget_Data *wd = elm_widget_data_get(data);
987 Evas_Event_Mouse_Up *ev = event_info;
989 if (wd->disabled) return;
992 if (wd->longpress_timer)
994 ecore_timer_del(wd->longpress_timer);
995 wd->longpress_timer = NULL;
998 else if (ev->button == 3)
1006 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1008 Widget_Data *wd = elm_widget_data_get(data);
1009 Evas_Event_Mouse_Move *ev = event_info;
1011 if (wd->disabled) return;
1014 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1016 if (wd->longpress_timer)
1018 ecore_timer_del(wd->longpress_timer);
1019 wd->longpress_timer = NULL;
1022 else if (wd->longpress_timer)
1026 dx = wd->downx - ev->cur.canvas.x;
1028 dy = wd->downy - ev->cur.canvas.y;
1031 ((_elm_config->finger_size / 2) *
1032 (_elm_config->finger_size / 2)))
1034 ecore_timer_del(wd->longpress_timer);
1035 wd->longpress_timer = NULL;
1039 else if (wd->longpress_timer)
1043 dx = wd->downx - ev->cur.canvas.x;
1045 dy = wd->downy - ev->cur.canvas.y;
1048 ((_elm_config->finger_size / 2) *
1049 (_elm_config->finger_size / 2)))
1051 ecore_timer_del(wd->longpress_timer);
1052 wd->longpress_timer = NULL;
1058 _getbase(Evas_Object *obj)
1060 Widget_Data *wd = elm_widget_data_get(obj);
1061 if (!wd) return "base";
1064 if (wd->password) return "base-password";
1067 if (wd->single_line) return "base-single";
1070 if (wd->linewrap) return "base";
1071 else if (wd->char_linewrap) return "base-charwrap";
1072 else return "base-nowrap";
1078 if (wd->password) return "base-password";
1081 if (wd->single_line) return "base-single-noedit";
1084 if (wd->linewrap) return "base-noedit";
1085 else if (wd->char_linewrap) return "base-noedit-charwrap";
1086 else return "base-nowrap-noedit";
1094 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1096 Widget_Data *wd = elm_widget_data_get(data);
1098 wd->changed = EINA_TRUE;
1100 if (wd->text) eina_stringshare_del(wd->text);
1102 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1103 if (wd->delay_write)
1105 ecore_timer_del(wd->delay_write);
1106 wd->delay_write = NULL;
1108 if ((!wd->autosave) || (!wd->file)) return;
1109 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1113 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1115 Widget_Data *wd = elm_widget_data_get(data);
1119 EINA_LIST_FOREACH(entries, l, entry)
1121 if (entry != data) elm_entry_select_none(entry);
1123 wd->have_selection = EINA_TRUE;
1124 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1125 #ifdef HAVE_ELEMENTARY_X
1126 if (wd->sel_notify_handler)
1128 const char *txt = elm_entry_selection_get(data);
1131 top = elm_widget_top_get(data);
1132 if ((top) && (elm_win_xwindow_get(top)))
1133 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1139 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1141 Widget_Data *wd = elm_widget_data_get(data);
1143 wd->have_selection = EINA_TRUE;
1144 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1145 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1146 elm_entry_selection_get(data));
1150 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1152 Widget_Data *wd = elm_widget_data_get(data);
1154 if (!wd->have_selection) return;
1155 wd->have_selection = EINA_FALSE;
1156 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1157 if (wd->sel_notify_handler)
1161 #ifdef HAVE_ELEMENTARY_X
1164 top = elm_widget_top_get(data);
1165 if ((top) && (elm_win_xwindow_get(top)))
1166 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1169 eina_stringshare_del(wd->cut_sel);
1174 #ifdef HAVE_ELEMENTARY_X
1177 top = elm_widget_top_get(data);
1178 if ((top) && (elm_win_xwindow_get(top)))
1179 elm_selection_clear(ELM_SEL_PRIMARY, data);
1186 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1188 Widget_Data *wd = elm_widget_data_get(data);
1190 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1191 if (wd->sel_notify_handler)
1193 #ifdef HAVE_ELEMENTARY_X
1196 top = elm_widget_top_get(data);
1197 if ((top) && (elm_win_xwindow_get(top)))
1199 wd->selection_asked = EINA_TRUE;
1200 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
1208 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1210 Widget_Data *wd = elm_widget_data_get(data);
1212 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1213 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1214 elm_entry_selection_get(data));
1218 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1220 Widget_Data *wd = elm_widget_data_get(data);
1222 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1223 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1224 elm_entry_selection_get(data));
1225 edje_object_part_text_insert(wd->ent, "elm.text", "");
1226 wd->changed = EINA_TRUE;
1231 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1233 Widget_Data *wd = elm_widget_data_get(data);
1234 Evas_Coord cx, cy, cw, ch;
1236 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1237 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1238 &cx, &cy, &cw, &ch);
1239 wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1240 if (!wd->deferred_recalc_job)
1241 elm_widget_show_region_set(data, cx, cy, cw, ch);
1244 wd->deferred_cur = EINA_TRUE;
1253 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1255 Widget_Data *wd = elm_widget_data_get(data);
1260 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1262 Widget_Data *wd = elm_widget_data_get(data);
1267 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1269 Widget_Data *wd = elm_widget_data_get(data);
1270 Elm_Entry_Anchor_Info ei;
1271 char *buf2, *p, *p2, *n;
1273 p = strrchr(emission, ',');
1276 const Eina_List *geoms;
1280 while (p2 >= emission)
1282 if (*p2 == ',') break;
1286 buf2 = alloca(5 + p - p2);
1287 strncpy(buf2, p2, p - p2);
1290 ei.button = atoi(buf2);
1291 ei.x = ei.y = ei.w = ei.h = 0;
1293 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1296 Evas_Textblock_Rectangle *r;
1298 Evas_Coord px, py, x, y;
1300 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1301 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1302 EINA_LIST_FOREACH(geoms, l, r)
1304 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1305 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1316 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1321 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1323 Widget_Data *wd = elm_widget_data_get(data);
1328 _signal_anchor_in(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_out(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_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1344 Widget_Data *wd = elm_widget_data_get(data);
1346 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1350 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1352 Widget_Data *wd = elm_widget_data_get(data);
1354 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1358 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1360 Widget_Data *wd = elm_widget_data_get(data);
1362 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1366 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1368 Widget_Data *wd = elm_widget_data_get(data);
1370 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1373 #ifdef HAVE_ELEMENTARY_X
1375 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1377 Widget_Data *wd = elm_widget_data_get(data);
1378 Ecore_X_Event_Selection_Notify *ev = event;
1379 if (!wd) return ECORE_CALLBACK_PASS_ON;
1380 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1381 return ECORE_CALLBACK_PASS_ON;
1383 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1384 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1386 Ecore_X_Selection_Data_Text *text_data;
1388 text_data = ev->data;
1389 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1391 if (text_data->text)
1393 char *txt = _elm_util_text_to_mkup(text_data->text);
1397 elm_entry_entry_insert(data, txt);
1402 wd->selection_asked = EINA_FALSE;
1404 else if (ev->selection == ECORE_X_SELECTION_XDND)
1406 Ecore_X_Selection_Data_Text *text_data;
1408 text_data = ev->data;
1409 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1411 if (text_data->text)
1413 char *txt = _elm_util_text_to_mkup(text_data->text);
1417 /* Massive FIXME: this should be at the drag point */
1418 elm_entry_entry_insert(data, txt);
1423 wd->drag_selection_asked = EINA_FALSE;
1425 ecore_x_dnd_send_finished();
1428 return ECORE_CALLBACK_PASS_ON;
1432 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1435 Widget_Data *wd = elm_widget_data_get(data);
1436 Ecore_X_Event_Selection_Clear *ev = event;
1437 if (!wd) return ECORE_CALLBACK_PASS_ON;
1438 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1439 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1440 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1442 elm_entry_select_none(data);
1445 return ECORE_CALLBACK_PASS_ON;
1450 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1455 wd = elm_widget_data_get(obj);
1457 if (!wd) return EINA_FALSE;
1458 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1460 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1461 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1462 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1463 EDJE_CURSOR_MAIN,drop->x,drop->y);
1464 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1465 elm_entry_entry_insert(obj, drop->data);
1466 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1467 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1473 static Evas_Object *
1474 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1476 Widget_Data *wd = elm_widget_data_get(data);
1479 Elm_Entry_Item_Provider *ip;
1481 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1483 o = ip->func(ip->data, data, item);
1486 if (!strncmp(item, "file://", 7))
1488 const char *fname = item + 7;
1490 o = evas_object_image_filled_add(evas_object_evas_get(data));
1491 evas_object_image_file_set(o, fname, NULL);
1492 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1494 evas_object_show(o);
1499 o = edje_object_add(evas_object_evas_get(data));
1500 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1504 o = edje_object_add(evas_object_evas_get(data));
1505 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1506 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1511 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
1513 Widget_Data *wd = elm_widget_data_get(data);
1515 Elm_Entry_Text_Filter *tf;
1517 if (type == EDJE_TEXT_FILTER_FORMAT)
1520 EINA_LIST_FOREACH(wd->text_filters, l, tf)
1522 tf->func(tf->data, data, text);
1529 * This adds an entry to @p parent object.
1531 * @param parent The parent object
1532 * @return The new object or NULL if it cannot be created
1537 elm_entry_add(Evas_Object *parent)
1539 Evas_Object *obj, *top;
1543 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1545 ELM_SET_WIDTYPE(widtype, "entry");
1546 elm_widget_type_set(obj, "entry");
1547 elm_widget_sub_object_add(parent, obj);
1548 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1549 elm_widget_data_set(obj, wd);
1550 elm_widget_del_hook_set(obj, _del_hook);
1551 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1552 elm_widget_theme_hook_set(obj, _theme_hook);
1553 elm_widget_disable_hook_set(obj, _disable_hook);
1554 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1555 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
1556 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1557 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1558 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
1559 elm_widget_can_focus_set(obj, EINA_TRUE);
1560 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
1562 wd->linewrap = EINA_TRUE;
1563 wd->char_linewrap= EINA_FALSE;
1564 wd->editable = EINA_TRUE;
1565 wd->disabled = EINA_FALSE;
1566 wd->context_menu = EINA_TRUE;
1567 wd->autosave = EINA_TRUE;
1568 wd->textonly = EINA_FALSE;
1570 wd->ent = edje_object_add(e);
1571 edje_object_item_provider_set(wd->ent, _get_item, obj);
1572 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
1573 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1574 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1575 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1577 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1579 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1582 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1583 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1584 _signal_entry_changed, obj);
1585 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1586 _signal_selection_start, obj);
1587 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1588 _signal_selection_changed, obj);
1589 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1590 _signal_selection_cleared, obj);
1591 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1592 _signal_entry_paste_request, obj);
1593 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1594 _signal_entry_copy_notify, obj);
1595 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1596 _signal_entry_cut_notify, obj);
1597 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1598 _signal_cursor_changed, obj);
1599 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1600 _signal_anchor_down, obj);
1601 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1602 _signal_anchor_up, obj);
1603 edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
1604 _signal_anchor_clicked, obj);
1605 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1606 _signal_anchor_move, obj);
1607 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1608 _signal_anchor_in, obj);
1609 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1610 _signal_anchor_out, obj);
1611 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
1612 _signal_key_enter, obj);
1613 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
1614 _signal_mouse_down, obj);
1615 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
1616 _signal_mouse_clicked, obj);
1617 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
1618 _signal_mouse_double, obj);
1619 edje_object_part_text_set(wd->ent, "elm.text", "");
1620 if (_elm_config->desktop_entry)
1621 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
1622 elm_widget_resize_object_set(obj, wd->ent);
1625 #ifdef HAVE_ELEMENTARY_X
1626 top = elm_widget_top_get(obj);
1627 if ((top) && (elm_win_xwindow_get(top)))
1629 wd->sel_notify_handler =
1630 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
1631 _event_selection_notify, obj);
1632 wd->sel_clear_handler =
1633 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
1634 _event_selection_clear, obj);
1637 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
1638 _drag_drop_cb, NULL);
1641 entries = eina_list_prepend(entries, obj);
1643 // module - find module for entry
1644 wd->api = _module(obj);
1645 // if found - hook in
1646 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
1648 _mirrored_set(obj, elm_widget_mirrored_get(obj));
1649 // TODO: convert Elementary to subclassing of Evas_Smart_Class
1650 // TODO: and save some bytes, making descriptions per-class and not instance!
1651 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1657 * This sets the entry object not to line wrap. All input will
1658 * be on a single line, and the entry box will extend with user input.
1660 * @param obj The entry object
1661 * @param single_line If true, the text in the entry
1662 * will be on a single line.
1667 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
1669 ELM_CHECK_WIDTYPE(obj, widtype);
1670 Widget_Data *wd = elm_widget_data_get(obj);
1672 if (wd->single_line == single_line) return;
1673 wd->single_line = single_line;
1674 wd->linewrap = EINA_FALSE;
1675 wd->char_linewrap = EINA_FALSE;
1676 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
1681 * This returns true if the entry has been set to single line mode.
1682 * See also elm_entry_single_line_set().
1684 * @param obj The entry object
1685 * @return single_line If true, the text in the entry is set to display
1691 elm_entry_single_line_get(const Evas_Object *obj)
1693 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1694 Widget_Data *wd = elm_widget_data_get(obj);
1695 if (!wd) return EINA_FALSE;
1696 return wd->single_line;
1700 * This sets the entry object to password mode. All text entered
1701 * and/or displayed within the widget will be replaced with asterisks (*).
1703 * @param obj The entry object
1704 * @param password If true, password mode is enabled.
1709 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
1711 ELM_CHECK_WIDTYPE(obj, widtype);
1712 Widget_Data *wd = elm_widget_data_get(obj);
1714 if (wd->password == password) return;
1715 wd->password = password;
1716 wd->single_line = EINA_TRUE;
1717 wd->linewrap = EINA_FALSE;
1718 wd->char_linewrap = EINA_FALSE;
1724 * This returns whether password mode is enabled.
1725 * See also elm_entry_password_set().
1727 * @param obj The entry object
1728 * @return If true, the entry is set to display all characters
1734 elm_entry_password_get(const Evas_Object *obj)
1736 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1737 Widget_Data *wd = elm_widget_data_get(obj);
1738 if (!wd) return EINA_FALSE;
1739 return wd->password;
1743 * This sets the text displayed within the entry to @p entry.
1745 * @param obj The entry object
1746 * @param entry The text to be displayed
1751 elm_entry_entry_set(Evas_Object *obj, const char *entry)
1753 ELM_CHECK_WIDTYPE(obj, widtype);
1754 Widget_Data *wd = elm_widget_data_get(obj);
1756 if (!entry) entry = "";
1757 edje_object_part_text_set(wd->ent, "elm.text", entry);
1758 if (wd->text) eina_stringshare_del(wd->text);
1760 wd->changed = EINA_TRUE;
1765 * This returns the text currently shown in object @p entry.
1766 * See also elm_entry_entry_set().
1768 * @param obj The entry object
1769 * @return The currently displayed text or NULL on failure
1774 elm_entry_entry_get(const Evas_Object *obj)
1776 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1777 Widget_Data *wd = elm_widget_data_get(obj);
1779 if (!wd) return NULL;
1780 if (wd->text) return wd->text;
1781 text = edje_object_part_text_get(wd->ent, "elm.text");
1784 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
1787 eina_stringshare_replace(&wd->text, text);
1793 * This returns EINA_TRUE if the entry is empty/there was an error
1794 * and EINA_FALSE if it is not empty.
1796 * @param obj The entry object
1797 * @return If the entry is empty or not.
1802 elm_entry_is_empty(const Evas_Object *obj)
1804 /* FIXME: until there's support for that in textblock, we just check
1805 * to see if the there is text or not. */
1806 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
1807 Widget_Data *wd = elm_widget_data_get(obj);
1808 const Evas_Object *tb;
1809 Evas_Textblock_Cursor *cur;
1811 if (!wd) return EINA_TRUE;
1812 /* It's a hack until we get the support suggested above.
1813 * We just create a cursor, point it to the begining, and then
1814 * try to advance it, if it can advance, the tb is not empty,
1815 * otherwise it is. */
1816 tb = edje_object_part_object_get(wd->ent, "elm.text");
1817 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
1818 actually, ok for the time being, thsese hackish stuff will be removed
1819 once evas 1.0 is out*/
1820 evas_textblock_cursor_pos_set(cur, 0);
1821 ret = evas_textblock_cursor_char_next(cur);
1822 evas_textblock_cursor_free(cur);
1828 * This returns all selected text within the entry.
1830 * @param obj The entry object
1831 * @return The selected text within the entry or NULL on failure
1836 elm_entry_selection_get(const Evas_Object *obj)
1838 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1839 Widget_Data *wd = elm_widget_data_get(obj);
1840 if (!wd) return NULL;
1841 return edje_object_part_text_selection_get(wd->ent, "elm.text");
1845 * This inserts text in @p entry where the current cursor position.
1847 * This inserts text at the cursor position is as if it was typed
1848 * by the user (note this also allows markup which a user
1849 * can't just "type" as it would be converted to escaped text, so this
1850 * call can be used to insert things like emoticon items or bold push/pop
1851 * tags, other font and color change tags etc.)
1853 * @param obj The entry object
1854 * @param entry The text to insert
1859 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
1861 ELM_CHECK_WIDTYPE(obj, widtype);
1862 Widget_Data *wd = elm_widget_data_get(obj);
1864 edje_object_part_text_insert(wd->ent, "elm.text", entry);
1865 wd->changed = EINA_TRUE;
1870 * This enables word line wrapping in the entry object. It is the opposite
1871 * of elm_entry_single_line_set(). Additionally, setting this disables
1872 * character line wrapping.
1873 * See also elm_entry_line_char_wrap_set().
1875 * @param obj The entry object
1876 * @param wrap If true, the entry will be wrapped once it reaches the end
1877 * of the object. Wrapping will occur at the end of the word before the end of the
1883 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
1885 ELM_CHECK_WIDTYPE(obj, widtype);
1886 Widget_Data *wd = elm_widget_data_get(obj);
1888 if (wd->linewrap == wrap) return;
1889 wd->linewrap = wrap;
1891 wd->char_linewrap = EINA_FALSE;
1896 * This enables character line wrapping in the entry object. It is the opposite
1897 * of elm_entry_single_line_set(). Additionally, setting this disables
1898 * word line wrapping.
1899 * See also elm_entry_line_wrap_set().
1901 * @param obj The entry object
1902 * @param wrap If true, the entry will be wrapped once it reaches the end
1903 * of the object. Wrapping will occur immediately upon reaching the end of the object.
1908 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
1910 ELM_CHECK_WIDTYPE(obj, widtype);
1911 Widget_Data *wd = elm_widget_data_get(obj);
1913 if (wd->char_linewrap == wrap) return;
1914 wd->char_linewrap = wrap;
1915 if(wd->char_linewrap)
1916 wd->linewrap = EINA_FALSE;
1921 * This sets the editable attribute of the entry.
1923 * @param obj The entry object
1924 * @param editable If true, the entry will be editable by the user.
1925 * If false, it will be set to the disabled state.
1930 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
1932 ELM_CHECK_WIDTYPE(obj, widtype);
1933 Widget_Data *wd = elm_widget_data_get(obj);
1935 if (wd->editable == editable) return;
1936 wd->editable = editable;
1939 #ifdef HAVE_ELEMENTARY_X
1941 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
1943 elm_drop_target_del(obj);
1948 * This gets the editable attribute of the entry.
1949 * See also elm_entry_editable_set().
1951 * @param obj The entry object
1952 * @return If true, the entry is editable by the user.
1953 * If false, it is not editable by the user
1958 elm_entry_editable_get(const Evas_Object *obj)
1960 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1961 Widget_Data *wd = elm_widget_data_get(obj);
1962 if (!wd) return EINA_FALSE;
1963 return wd->editable;
1967 * This drops any existing text selection within the entry.
1969 * @param obj The entry object
1974 elm_entry_select_none(Evas_Object *obj)
1976 ELM_CHECK_WIDTYPE(obj, widtype);
1977 Widget_Data *wd = elm_widget_data_get(obj);
1981 wd->selmode = EINA_FALSE;
1982 if (!_elm_config->desktop_entry)
1983 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1984 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1986 wd->have_selection = EINA_FALSE;
1987 edje_object_part_text_select_none(wd->ent, "elm.text");
1991 * This selects all text within the entry.
1993 * @param obj The entry object
1998 elm_entry_select_all(Evas_Object *obj)
2000 ELM_CHECK_WIDTYPE(obj, widtype);
2001 Widget_Data *wd = elm_widget_data_get(obj);
2005 wd->selmode = EINA_FALSE;
2006 if (!_elm_config->desktop_entry)
2007 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2008 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2010 wd->have_selection = EINA_TRUE;
2011 edje_object_part_text_select_all(wd->ent, "elm.text");
2015 * This function returns the geometry of the cursor.
2017 * It's useful if you want to draw something on the cursor (or where it is),
2018 * or for example in the case of scrolled entry where you want to show the
2021 * @param obj The entry object
2022 * @param x returned geometry
2023 * @param y returned geometry
2024 * @param w returned geometry
2025 * @param h returned geometry
2026 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2031 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
2033 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2034 Widget_Data *wd = elm_widget_data_get(obj);
2035 if (!wd) return EINA_FALSE;
2036 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
2041 * This moves the cursor one place to the right within the entry.
2043 * @param obj The entry object
2044 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2049 elm_entry_cursor_next(Evas_Object *obj)
2051 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2052 Widget_Data *wd = elm_widget_data_get(obj);
2053 if (!wd) return EINA_FALSE;
2054 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2058 * This moves the cursor one place to the left within the entry.
2060 * @param obj The entry object
2061 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2066 elm_entry_cursor_prev(Evas_Object *obj)
2068 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2069 Widget_Data *wd = elm_widget_data_get(obj);
2070 if (!wd) return EINA_FALSE;
2071 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2075 * This moves the cursor one line up within the entry.
2077 * @param obj The entry object
2078 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2083 elm_entry_cursor_up(Evas_Object *obj)
2085 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2086 Widget_Data *wd = elm_widget_data_get(obj);
2087 if (!wd) return EINA_FALSE;
2088 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2092 * This moves the cursor one line down within the entry.
2094 * @param obj The entry object
2095 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2100 elm_entry_cursor_down(Evas_Object *obj)
2102 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2103 Widget_Data *wd = elm_widget_data_get(obj);
2104 if (!wd) return EINA_FALSE;
2105 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2109 * This moves the cursor to the beginning of the entry.
2111 * @param obj The entry object
2116 elm_entry_cursor_begin_set(Evas_Object *obj)
2118 ELM_CHECK_WIDTYPE(obj, widtype);
2119 Widget_Data *wd = elm_widget_data_get(obj);
2121 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2125 * This moves the cursor to the end of the entry.
2127 * @param obj The entry object
2132 elm_entry_cursor_end_set(Evas_Object *obj)
2134 ELM_CHECK_WIDTYPE(obj, widtype);
2135 Widget_Data *wd = elm_widget_data_get(obj);
2137 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2141 * This moves the cursor to the beginning of the current line.
2143 * @param obj The entry object
2148 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2150 ELM_CHECK_WIDTYPE(obj, widtype);
2151 Widget_Data *wd = elm_widget_data_get(obj);
2153 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2157 * This moves the cursor to the end of the current line.
2159 * @param obj The entry object
2164 elm_entry_cursor_line_end_set(Evas_Object *obj)
2166 ELM_CHECK_WIDTYPE(obj, widtype);
2167 Widget_Data *wd = elm_widget_data_get(obj);
2169 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2173 * This begins a selection within the entry as though
2174 * the user were holding down the mouse button to make a selection.
2176 * @param obj The entry object
2181 elm_entry_cursor_selection_begin(Evas_Object *obj)
2183 ELM_CHECK_WIDTYPE(obj, widtype);
2184 Widget_Data *wd = elm_widget_data_get(obj);
2186 edje_object_part_text_select_begin(wd->ent, "elm.text");
2190 * This ends a selection within the entry as though
2191 * the user had just released the mouse button while making a selection.
2193 * @param obj The entry object
2198 elm_entry_cursor_selection_end(Evas_Object *obj)
2200 ELM_CHECK_WIDTYPE(obj, widtype);
2201 Widget_Data *wd = elm_widget_data_get(obj);
2203 edje_object_part_text_select_extend(wd->ent, "elm.text");
2207 * TODO: fill this in
2209 * @param obj The entry object
2210 * @return TODO: fill this in
2215 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2217 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2218 Widget_Data *wd = elm_widget_data_get(obj);
2219 if (!wd) return EINA_FALSE;
2220 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2224 * This returns whether the cursor is visible.
2226 * @param obj The entry object
2227 * @return If true, the cursor is visible.
2232 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2234 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2235 Widget_Data *wd = elm_widget_data_get(obj);
2236 if (!wd) return EINA_FALSE;
2237 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2241 * TODO: fill this in
2243 * @param obj The entry object
2244 * @return TODO: fill this in
2249 elm_entry_cursor_content_get(const Evas_Object *obj)
2251 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2252 Widget_Data *wd = elm_widget_data_get(obj);
2253 if (!wd) return NULL;
2254 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2258 * Sets the cursor position in the entry to the given value
2260 * @param obj The entry object
2261 * @param pos The position of the cursor
2266 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
2268 ELM_CHECK_WIDTYPE(obj, widtype);
2269 Widget_Data *wd = elm_widget_data_get(obj);
2271 edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
2272 edje_object_message_signal_process(wd->ent);
2276 * Retrieves the current position of the cursor in the entry
2278 * @param obj The entry object
2279 * @return The cursor position
2284 elm_entry_cursor_pos_get(const Evas_Object *obj)
2286 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2287 Widget_Data *wd = elm_widget_data_get(obj);
2289 return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2293 * This executes a "cut" action on the selected text in the entry.
2295 * @param obj The entry object
2300 elm_entry_selection_cut(Evas_Object *obj)
2302 ELM_CHECK_WIDTYPE(obj, widtype);
2303 Widget_Data *wd = elm_widget_data_get(obj);
2305 _cut(obj, NULL, NULL);
2309 * This executes a "copy" action on the selected text in the entry.
2311 * @param obj The entry object
2316 elm_entry_selection_copy(Evas_Object *obj)
2318 ELM_CHECK_WIDTYPE(obj, widtype);
2319 Widget_Data *wd = elm_widget_data_get(obj);
2321 _copy(obj, NULL, NULL);
2325 * This executes a "paste" action in the entry.
2327 * @param obj The entry object
2332 elm_entry_selection_paste(Evas_Object *obj)
2334 ELM_CHECK_WIDTYPE(obj, widtype);
2335 Widget_Data *wd = elm_widget_data_get(obj);
2337 _paste(obj, NULL, NULL);
2341 * This clears and frees the items in a entry's contextual (right click) menu.
2343 * @param obj The entry object
2348 elm_entry_context_menu_clear(Evas_Object *obj)
2350 ELM_CHECK_WIDTYPE(obj, widtype);
2351 Widget_Data *wd = elm_widget_data_get(obj);
2352 Elm_Entry_Context_Menu_Item *it;
2354 EINA_LIST_FREE(wd->items, it)
2356 eina_stringshare_del(it->label);
2357 eina_stringshare_del(it->icon_file);
2358 eina_stringshare_del(it->icon_group);
2364 * This adds an item to the entry's contextual menu.
2366 * @param obj The entry object
2367 * @param label The item's text label
2368 * @param icon_file The item's icon file
2369 * @param icon_type The item's icon type
2370 * @param func The callback to execute when the item is clicked
2371 * @param data The data to associate with the item for related functions
2376 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)
2378 ELM_CHECK_WIDTYPE(obj, widtype);
2379 Widget_Data *wd = elm_widget_data_get(obj);
2380 Elm_Entry_Context_Menu_Item *it;
2382 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2384 wd->items = eina_list_append(wd->items, it);
2386 it->label = eina_stringshare_add(label);
2387 it->icon_file = eina_stringshare_add(icon_file);
2388 it->icon_type = icon_type;
2390 it->data = (void *)data;
2394 * This disables the entry's contextual (right click) menu.
2396 * @param obj The entry object
2397 * @param disabled If true, the menu is disabled
2402 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2404 ELM_CHECK_WIDTYPE(obj, widtype);
2405 Widget_Data *wd = elm_widget_data_get(obj);
2407 if (wd->context_menu == !disabled) return;
2408 wd->context_menu = !disabled;
2412 * This returns whether the entry's contextual (right click) menu is disabled.
2414 * @param obj The entry object
2415 * @return If true, the menu is disabled
2420 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2422 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2423 Widget_Data *wd = elm_widget_data_get(obj);
2424 if (!wd) return EINA_FALSE;
2425 return !wd->context_menu;
2429 * This appends a custom item provider to the list for that entry
2431 * This appends the given callback. The list is walked from beginning to end
2432 * with each function called given the item href string in the text. If the
2433 * function returns an object handle other than NULL (it should create an
2434 * and object to do this), then this object is used to replace that item. If
2435 * not the next provider is called until one provides an item object, or the
2436 * default provider in entry does.
2438 * @param obj The entry object
2439 * @param func The function called to provide the item object
2440 * @param data The data passed to @p func
2445 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2447 ELM_CHECK_WIDTYPE(obj, widtype);
2448 Widget_Data *wd = elm_widget_data_get(obj);
2450 EINA_SAFETY_ON_NULL_RETURN(func);
2451 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2455 wd->item_providers = eina_list_append(wd->item_providers, ip);
2459 * This prepends a custom item provider to the list for that entry
2461 * This prepends the given callback. See elm_entry_item_provider_append() for
2464 * @param obj The entry object
2465 * @param func The function called to provide the item object
2466 * @param data The data passed to @p func
2471 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2473 ELM_CHECK_WIDTYPE(obj, widtype);
2474 Widget_Data *wd = elm_widget_data_get(obj);
2476 EINA_SAFETY_ON_NULL_RETURN(func);
2477 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2481 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2485 * This removes a custom item provider to the list for that entry
2487 * This removes the given callback. See elm_entry_item_provider_append() for
2490 * @param obj The entry object
2491 * @param func The function called to provide the item object
2492 * @param data The data passed to @p func
2497 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2499 ELM_CHECK_WIDTYPE(obj, widtype);
2500 Widget_Data *wd = elm_widget_data_get(obj);
2502 Elm_Entry_Item_Provider *ip;
2504 EINA_SAFETY_ON_NULL_RETURN(func);
2505 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2507 if ((ip->func == func) && ((!data) || (ip->data == data)))
2509 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2517 * Append a filter function for text inserted in the entry
2519 * Append the given callback to the list. This functions will be called
2520 * whenever any text is inserted into the entry, with the text to be inserted
2521 * as a parameter. The callback function is free to alter the text in any way
2522 * it wants, but it must remember to free the given pointer and update it.
2523 * If the new text is to be discarded, the function can free it and set it text
2524 * parameter to NULL. This will also prevent any following filters from being
2527 * @param obj The entry object
2528 * @param func The function to use as text filter
2529 * @param data User data to pass to @p func
2534 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2537 Elm_Entry_Text_Filter *tf;
2538 ELM_CHECK_WIDTYPE(obj, widtype);
2540 wd = elm_widget_data_get(obj);
2542 EINA_SAFETY_ON_NULL_RETURN(func);
2544 tf = _filter_new(func, data);
2547 wd->text_filters = eina_list_append(wd->text_filters, tf);
2551 * Prepend a filter function for text insdrted in the entry
2553 * Prepend the given callback to the list. See elm_entry_text_filter_append()
2554 * for more information
2556 * @param obj The entry object
2557 * @param func The function to use as text filter
2558 * @param data User data to pass to @p func
2563 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2566 Elm_Entry_Text_Filter *tf;
2567 ELM_CHECK_WIDTYPE(obj, widtype);
2569 wd = elm_widget_data_get(obj);
2571 EINA_SAFETY_ON_NULL_RETURN(func);
2573 tf = _filter_new(func, data);
2576 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
2580 * Remove a filter from the list
2582 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
2583 * for more information.
2585 * @param obj The entry object
2586 * @param func The filter function to remove
2587 * @param data The user data passed when adding the function
2592 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2596 Elm_Entry_Text_Filter *tf;
2597 ELM_CHECK_WIDTYPE(obj, widtype);
2599 wd = elm_widget_data_get(obj);
2601 EINA_SAFETY_ON_NULL_RETURN(func);
2603 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2605 if ((tf->func == func) && ((!data) || (tf->data == data)))
2607 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
2615 * This converts a markup (HTML-like) string into UTF-8.
2616 * Returning string is obtained with malloc.
2617 * After use the returned string, it should be freed.
2619 * @param s The string (in markup) to be converted
2620 * @return The converted string (in UTF-8). It should be freed.
2625 elm_entry_markup_to_utf8(const char *s)
2627 char *ss = _elm_util_mkup_to_text(s);
2628 if (!ss) ss = strdup("");
2633 * This converts a UTF-8 string into markup (HTML-like).
2634 * Returning string is obtained with malloc.
2635 * After use the returned string, it should be freed.
2637 * @param s The string (in UTF-8) to be converted
2638 * @return The converted string (in markup). It should be freed.
2643 elm_entry_utf8_to_markup(const char *s)
2645 char *ss = _elm_util_text_to_mkup(s);
2646 if (!ss) ss = strdup("");
2651 * Filter inserted text based on user defined character and byte limits
2653 * Add this filter to an entry to limit the characters that it will accept
2654 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
2655 * The funtion works on the UTF-8 representation of the string, converting
2656 * it from the set markup, thus not accounting for any format in it.
2658 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
2659 * it as data when setting the filter. In it it's possible to set limits
2660 * by character count or bytes (any of them is disabled if 0), and both can
2661 * be set at the same time. In that case, it first checks for characters,
2664 * The function will cut the inserted text in order to allow only the first
2665 * number of characters that are still allowed. The cut is made in
2666 * characters, even when limiting by bytes, in order to always contain
2667 * valid ones and avoid half unicode characters making it in.
2672 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
2674 Elm_Entry_Filter_Limit_Size *lim = data;
2677 const char *(*text_get)(const Evas_Object *);
2678 const char *widget_type;
2680 EINA_SAFETY_ON_NULL_RETURN(data);
2681 EINA_SAFETY_ON_NULL_RETURN(entry);
2682 EINA_SAFETY_ON_NULL_RETURN(text);
2684 /* hack. I don't want to copy the entire function to work with
2686 widget_type = elm_widget_type_get(entry);
2687 if (!strcmp(widget_type, "entry"))
2688 text_get = elm_entry_entry_get;
2689 else if (!strcmp(widget_type, "scrolled_entry"))
2690 text_get = elm_scrolled_entry_entry_get;
2694 current = elm_entry_markup_to_utf8(text_get(entry));
2696 if (lim->max_char_count > 0)
2699 len = evas_string_char_len_get(current);
2700 if (len >= lim->max_char_count)
2707 newlen = evas_string_char_len_get(*text);
2708 cut = strlen(*text);
2709 while ((len + newlen) > lim->max_char_count)
2711 cut = evas_string_char_prev_get(*text, cut, NULL);
2717 if (lim->max_byte_count > 0)
2719 len = strlen(current);
2720 if (len >= lim->max_byte_count)
2727 newlen = strlen(*text);
2728 while ((len + newlen) > lim->max_byte_count)
2730 int p = evas_string_char_prev_get(*text, newlen, NULL);
2731 newlen -= (newlen - p);
2734 (*text)[newlen] = 0;
2745 * Filter inserted text based on accepted or rejected sets of characters
2747 * Add this filter to an entry to restrict the set of accepted characters
2748 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
2749 * This structure contains both accepted and rejected sets, but they are
2750 * mutually exclusive. If accepted is set, it will be used, otherwise it
2751 * goes on to the rejected set.
2754 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
2756 Elm_Entry_Filter_Accept_Set *as = data;
2760 int read_idx, last_read_idx = 0, read_char;
2762 EINA_SAFETY_ON_NULL_RETURN(data);
2763 EINA_SAFETY_ON_NULL_RETURN(text);
2765 if ((!as->accepted) && (!as->rejected))
2771 goes_in = EINA_TRUE;
2776 goes_in = EINA_FALSE;
2780 read_idx = evas_string_char_next_get(*text, 0, &read_char);
2783 int cmp_idx, cmp_char;
2784 Eina_Bool in_set = EINA_FALSE;
2786 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
2789 if (read_char == cmp_char)
2794 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
2796 if (in_set == goes_in)
2798 int size = read_idx - last_read_idx;
2799 const char *src = (*text) + last_read_idx;
2801 memcpy(insert, *text + last_read_idx, size);
2804 last_read_idx = read_idx;
2805 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
2811 * This sets the file (and implicitly loads it) for the text to display and
2812 * then edit. All changes are written back to the file after a short delay if
2813 * the entry object is set to autosave.
2815 * @param obj The entry object
2816 * @param file The path to the file to load and save
2817 * @param format The file format
2822 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
2824 ELM_CHECK_WIDTYPE(obj, widtype);
2825 Widget_Data *wd = elm_widget_data_get(obj);
2827 if (wd->delay_write)
2829 ecore_timer_del(wd->delay_write);
2830 wd->delay_write = NULL;
2832 if (wd->autosave) _save(obj);
2833 eina_stringshare_replace(&wd->file, file);
2834 wd->format = format;
2839 * Gets the file to load and save and the file format
2841 * @param obj The entry object
2842 * @param file The path to the file to load and save
2843 * @param format The file format
2848 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
2850 ELM_CHECK_WIDTYPE(obj, widtype);
2851 Widget_Data *wd = elm_widget_data_get(obj);
2853 if (file) *file = wd->file;
2854 if (format) *format = wd->format;
2858 * This function writes any changes made to the file set with
2859 * elm_entry_file_set()
2861 * @param obj The entry object
2866 elm_entry_file_save(Evas_Object *obj)
2868 ELM_CHECK_WIDTYPE(obj, widtype);
2869 Widget_Data *wd = elm_widget_data_get(obj);
2871 if (wd->delay_write)
2873 ecore_timer_del(wd->delay_write);
2874 wd->delay_write = NULL;
2877 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
2881 * This sets the entry object to 'autosave' the loaded text file or not.
2883 * @param obj The entry object
2884 * @param autosave Autosave the loaded file or not
2889 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
2891 ELM_CHECK_WIDTYPE(obj, widtype);
2892 Widget_Data *wd = elm_widget_data_get(obj);
2894 wd->autosave = !!autosave;
2898 * This gets the entry object's 'autosave' status.
2900 * @param obj The entry object
2901 * @return Autosave the loaded file or not
2906 elm_entry_autosave_get(const Evas_Object *obj)
2908 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2909 Widget_Data *wd = elm_widget_data_get(obj);
2910 if (!wd) return EINA_FALSE;
2911 return wd->autosave;
2916 * Control pasting of text and images for the widget.
2918 * Normally the entry allows both text and images to be pasted. By setting
2919 * textonly to be true, this prevents images from being pasted.
2921 * Note this only changes the behaviour of text.
2923 * @param obj The entry object
2924 * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is text+image+other.
2929 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
2931 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
2932 ELM_CHECK_WIDTYPE(obj, widtype);
2933 Widget_Data *wd = elm_widget_data_get(obj);
2935 textonly = !!textonly;
2936 if (wd->textonly == textonly) return;
2937 wd->textonly = !!textonly;
2938 if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
2939 #ifdef HAVE_ELEMENTARY_X
2940 elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
2945 * Getting elm_entry text paste/drop mode.
2947 * In textonly mode, only text may be pasted or dropped into the widget.
2949 * @param obj The entry object
2950 * @return If the widget only accepts text from pastes.
2955 elm_entry_cnp_textonly_get(Evas_Object *obj)
2957 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2958 Widget_Data *wd = elm_widget_data_get(obj);
2959 if (!wd) return EINA_FALSE;
2960 return wd->textonly;