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
123 Eina_Bool changed : 1;
124 Eina_Bool linewrap : 1;
125 Eina_Bool char_linewrap : 1;
126 Eina_Bool single_line : 1;
127 Eina_Bool password : 1;
128 Eina_Bool editable : 1;
129 Eina_Bool selection_asked : 1;
130 Eina_Bool have_selection : 1;
131 Eina_Bool selmode : 1;
132 Eina_Bool deferred_cur : 1;
133 Eina_Bool disabled : 1;
134 Eina_Bool context_menu : 1;
135 Eina_Bool drag_selection_asked : 1;
136 Eina_Bool can_write : 1;
137 Eina_Bool autosave : 1;
138 Eina_Bool textonly : 1;
141 struct _Elm_Entry_Context_Menu_Item
145 const char *icon_file;
146 const char *icon_group;
147 Elm_Icon_Type icon_type;
152 struct _Elm_Entry_Item_Provider
154 Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
158 struct _Elm_Entry_Text_Filter
160 void (*func) (void *data, Evas_Object *entry, char **text);
164 static const char *widtype = NULL;
166 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
167 static void _del_hook(Evas_Object *obj);
168 static void _theme_hook(Evas_Object *obj);
169 static void _disable_hook(Evas_Object *obj);
170 static void _sizing_eval(Evas_Object *obj);
171 static void _on_focus_hook(void *data, Evas_Object *obj);
172 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
173 static const char *_getbase(Evas_Object *obj);
174 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
175 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
176 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
177 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
178 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
179 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
180 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
181 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
183 static const char SIG_CHANGED[] = "changed";
184 static const char SIG_ACTIVATED[] = "activated";
185 static const char SIG_PRESS[] = "press";
186 static const char SIG_LONGPRESSED[] = "longpressed";
187 static const char SIG_CLICKED[] = "clicked";
188 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
189 static const char SIG_FOCUSED[] = "focused";
190 static const char SIG_UNFOCUSED[] = "unfocused";
191 static const char SIG_SELECTION_PASTE[] = "selection,paste";
192 static const char SIG_SELECTION_COPY[] = "selection,copy";
193 static const char SIG_SELECTION_CUT[] = "selection,cut";
194 static const char SIG_SELECTION_START[] = "selection,start";
195 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
196 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
197 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
198 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
199 static const Evas_Smart_Cb_Description _signals[] = {
203 {SIG_LONGPRESSED, ""},
205 {SIG_CLICKED_DOUBLE, ""},
208 {SIG_SELECTION_PASTE, ""},
209 {SIG_SELECTION_COPY, ""},
210 {SIG_SELECTION_CUT, ""},
211 {SIG_SELECTION_START, ""},
212 {SIG_SELECTION_CHANGED, ""},
213 {SIG_SELECTION_CLEARED, ""},
214 {SIG_CURSOR_CHANGED, ""},
215 {SIG_ANCHOR_CLICKED, ""},
219 static Eina_List *entries = NULL;
223 void (*obj_hook) (Evas_Object *obj);
224 void (*obj_unhook) (Evas_Object *obj);
225 void (*obj_longpress) (Evas_Object *obj);
229 _module(Evas_Object *obj __UNUSED__)
231 static Elm_Module *m = NULL;
232 if (m) goto ok; // already found - just use
233 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
235 m->api = malloc(sizeof(Mod_Api));
236 if (!m->api) return NULL;
237 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
238 _elm_module_symbol_get(m, "obj_hook");
239 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
240 _elm_module_symbol_get(m, "obj_unhook");
241 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
242 _elm_module_symbol_get(m, "obj_longpress");
243 ok: // ok - return api
248 _buf_append(char *buf, const char *str, int *len, int *alloc)
250 int len2 = strlen(str);
251 if ((*len + len2) >= *alloc)
253 char *buf2 = realloc(buf, *alloc + len2 + 512);
254 if (!buf2) return NULL;
256 *alloc += (512 + len2);
258 strcpy(buf + *len, str);
264 _load_file(const char *file)
268 int alloc = 0, len = 0;
269 char *text = NULL, buf[16384 + 1];
271 f = fopen(file, "rb");
273 while ((size = fread(buf, 1, sizeof(buf) - 1, f)))
277 tmp_text = _buf_append(text, buf, &len, &alloc);
278 if (!tmp_text) break;
286 _load_plain(const char *file)
290 text = _load_file(file);
295 text2 = elm_entry_utf8_to_markup(text);
303 _load(Evas_Object *obj)
305 Widget_Data *wd = elm_widget_data_get(obj);
310 elm_entry_entry_set(obj, "");
315 case ELM_TEXT_FORMAT_PLAIN_UTF8:
316 text = _load_plain(wd->file);
318 case ELM_TEXT_FORMAT_MARKUP_UTF8:
319 text = _load_file(wd->file);
327 elm_entry_entry_set(obj, text);
331 elm_entry_entry_set(obj, "");
335 _save_markup_utf8(const char *file, const char *text)
339 if ((!text) || (!text[0]))
341 ecore_file_unlink(file);
344 f = fopen(file, "wb");
347 // FIXME: report a write error
350 fputs(text, f); // FIXME: catch error
355 _save_plain_utf8(const char *file, const char *text)
359 text2 = elm_entry_markup_to_utf8(text);
362 _save_markup_utf8(file, text2);
367 _save(Evas_Object *obj)
369 Widget_Data *wd = elm_widget_data_get(obj);
371 if (!wd->file) return;
374 case ELM_TEXT_FORMAT_PLAIN_UTF8:
375 _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
377 case ELM_TEXT_FORMAT_MARKUP_UTF8:
378 _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
386 _delay_write(void *data)
388 Widget_Data *wd = elm_widget_data_get(data);
389 if (!wd) return ECORE_CALLBACK_CANCEL;
391 wd->delay_write = NULL;
392 return ECORE_CALLBACK_CANCEL;
396 _del_pre_hook(Evas_Object *obj)
398 Widget_Data *wd = elm_widget_data_get(obj);
402 ecore_timer_del(wd->delay_write);
403 wd->delay_write = NULL;
404 if (wd->autosave) _save(obj);
409 _del_hook(Evas_Object *obj)
411 Widget_Data *wd = elm_widget_data_get(obj);
412 Elm_Entry_Context_Menu_Item *it;
413 Elm_Entry_Item_Provider *ip;
414 Elm_Entry_Text_Filter *tf;
416 if (wd->file) eina_stringshare_del(wd->file);
418 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
419 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
421 entries = eina_list_remove(entries, obj);
422 #ifdef HAVE_ELEMENTARY_X
423 ecore_event_handler_del(wd->sel_notify_handler);
424 ecore_event_handler_del(wd->sel_clear_handler);
426 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
427 if (wd->text) eina_stringshare_del(wd->text);
428 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
429 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
430 EINA_LIST_FREE(wd->items, it)
432 eina_stringshare_del(it->label);
433 eina_stringshare_del(it->icon_file);
434 eina_stringshare_del(it->icon_group);
437 EINA_LIST_FREE(wd->item_providers, ip)
441 EINA_LIST_FREE(wd->text_filters, tf)
449 _theme_hook(Evas_Object *obj)
451 Widget_Data *wd = elm_widget_data_get(obj);
454 t = eina_stringshare_add(elm_entry_entry_get(obj));
455 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
456 elm_entry_entry_set(obj, t);
457 eina_stringshare_del(t);
458 if (elm_widget_disabled_get(obj))
459 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
460 edje_object_message_signal_process(wd->ent);
461 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
466 _disable_hook(Evas_Object *obj)
468 Widget_Data *wd = elm_widget_data_get(obj);
470 if (elm_widget_disabled_get(obj))
472 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
473 wd->disabled = EINA_TRUE;
477 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
478 wd->disabled = EINA_FALSE;
483 _elm_win_recalc_job(void *data)
485 Widget_Data *wd = elm_widget_data_get(data);
486 Evas_Coord minw = -1, minh = -1, maxh = -1;
487 Evas_Coord resw, resh, minminw;
489 wd->deferred_recalc_job = NULL;
490 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
492 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, 0, 0);
493 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
495 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
496 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
497 evas_object_size_hint_min_set(data, minminw, minh);
498 if (wd->single_line) maxh = minh;
499 evas_object_size_hint_max_set(data, -1, maxh);
500 if (wd->deferred_cur)
501 elm_widget_show_region_set(data, wd->cx, wd->cy, wd->cw, wd->ch);
505 _sizing_eval(Evas_Object *obj)
507 Widget_Data *wd = elm_widget_data_get(obj);
508 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
509 Evas_Coord resw, resh;
511 if ((wd->linewrap) || (wd->char_linewrap))
513 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
514 if ((resw == wd->lastw) && (!wd->changed)) return;
515 wd->changed = EINA_FALSE;
517 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
518 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
522 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
523 edje_object_size_min_calc(wd->ent, &minw, &minh);
524 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
525 evas_object_size_hint_min_set(obj, minw, minh);
526 if (wd->single_line) maxh = minh;
527 evas_object_size_hint_max_set(obj, maxw, maxh);
532 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
534 Widget_Data *wd = elm_widget_data_get(obj);
535 Evas_Object *top = elm_widget_top_get(obj);
537 if (!wd->editable) return;
538 if (elm_widget_focus_get(obj))
540 evas_object_focus_set(wd->ent, EINA_TRUE);
541 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
542 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
543 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
547 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
548 evas_object_focus_set(wd->ent, EINA_FALSE);
549 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
550 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
555 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
557 Widget_Data *wd = elm_widget_data_get(obj);
559 edje_object_signal_emit(wd->ent, emission, source);
563 _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)
565 Widget_Data *wd = elm_widget_data_get(obj);
567 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
571 _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)
573 Widget_Data *wd = elm_widget_data_get(obj);
574 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
579 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
581 Widget_Data *wd = elm_widget_data_get(obj);
582 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
586 _hoversel_position(Evas_Object *obj)
588 Widget_Data *wd = elm_widget_data_get(obj);
589 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
591 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
592 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
594 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
605 evas_object_move(wd->hoversel, x + cx, y + cy);
606 evas_object_resize(wd->hoversel, cw, ch);
610 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
612 Widget_Data *wd = elm_widget_data_get(data);
614 if (wd->hoversel) _hoversel_position(data);
618 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
620 Widget_Data *wd = elm_widget_data_get(data);
622 if ((wd->linewrap) || (wd->char_linewrap))
626 if (wd->hoversel) _hoversel_position(data);
627 // Evas_Coord ww, hh;
628 // evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
632 _hover_del(void *data)
634 Widget_Data *wd = elm_widget_data_get(data);
639 evas_object_del(wd->hoversel);
642 wd->hovdeljob = NULL;
646 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
648 Widget_Data *wd = elm_widget_data_get(data);
650 if (wd->hoversel) evas_object_hide(wd->hoversel);
654 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
656 elm_widget_scroll_freeze_pop(data);
657 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
658 wd->hovdeljob = ecore_job_add(_hover_del, data);
662 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
664 Widget_Data *wd = elm_widget_data_get(data);
666 wd->selmode = EINA_TRUE;
667 edje_object_part_text_select_none(wd->ent, "elm.text");
669 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
670 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
671 elm_widget_scroll_hold_push(data);
675 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
677 Widget_Data *wd = elm_widget_data_get(data);
679 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
680 if (wd->sel_notify_handler)
682 #ifdef HAVE_ELEMENTARY_X
683 Elm_Sel_Format formats;
684 wd->selection_asked = EINA_TRUE;
685 formats = ELM_SEL_FORMAT_MARKUP;
687 formats |= ELM_SEL_FORMAT_IMAGE;
688 elm_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL);
694 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
696 Widget_Data *wd = elm_widget_data_get(obj);
700 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
701 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
702 if (seltype == ELM_SEL_CLIPBOARD)
703 eina_stringshare_replace(&wd->cut_sel, sel);
707 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
709 Widget_Data *wd = elm_widget_data_get(data);
712 wd->selmode = EINA_FALSE;
713 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
714 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
715 elm_widget_scroll_hold_pop(data);
716 _store_selection(ELM_SEL_CLIPBOARD, data);
717 edje_object_part_text_insert(wd->ent, "elm.text", "");
718 edje_object_part_text_select_none(wd->ent, "elm.text");
722 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
724 Widget_Data *wd = elm_widget_data_get(data);
726 wd->selmode = EINA_FALSE;
727 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
728 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
729 elm_widget_scroll_hold_pop(data);
730 _store_selection(ELM_SEL_CLIPBOARD, data);
731 // edje_object_part_text_select_none(wd->ent, "elm.text");
735 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
737 Widget_Data *wd = elm_widget_data_get(data);
739 wd->selmode = EINA_FALSE;
740 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
741 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
742 elm_widget_scroll_hold_pop(data);
743 edje_object_part_text_select_none(wd->ent, "elm.text");
747 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
749 Elm_Entry_Context_Menu_Item *it = data;
750 Evas_Object *obj2 = it->obj;
751 if (it->func) it->func(it->data, obj2, NULL);
755 _long_press(void *data)
757 Widget_Data *wd = elm_widget_data_get(data);
760 const Elm_Entry_Context_Menu_Item *it;
761 if (!wd) return ECORE_CALLBACK_CANCEL;
762 if ((wd->api) && (wd->api->obj_longpress))
764 wd->api->obj_longpress(data);
766 else if (wd->context_menu)
768 const char *context_menu_orientation;
770 if (wd->hoversel) evas_object_del(wd->hoversel);
771 else elm_widget_scroll_freeze_push(data);
772 wd->hoversel = elm_hoversel_add(data);
773 context_menu_orientation = edje_object_data_get
774 (wd->ent, "context_menu_orientation");
775 if ((context_menu_orientation) &&
776 (!strcmp(context_menu_orientation, "horizontal")))
777 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
778 elm_object_style_set(wd->hoversel, "entry");
779 elm_widget_sub_object_add(data, wd->hoversel);
780 elm_hoversel_label_set(wd->hoversel, "Text");
781 top = elm_widget_top_get(data);
782 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
783 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, data);
787 elm_hoversel_item_add(wd->hoversel, "Select", NULL, ELM_ICON_NONE,
789 if (1) // need way to detect if someone has a selection
792 elm_hoversel_item_add(wd->hoversel, "Paste", NULL, ELM_ICON_NONE,
800 if (wd->have_selection)
802 elm_hoversel_item_add(wd->hoversel, "Copy", NULL, ELM_ICON_NONE,
805 elm_hoversel_item_add(wd->hoversel, "Cut", NULL, ELM_ICON_NONE,
808 elm_hoversel_item_add(wd->hoversel, "Cancel", NULL, ELM_ICON_NONE,
812 EINA_LIST_FOREACH(wd->items, l, it)
814 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
815 it->icon_type, _item_clicked, it);
819 _hoversel_position(data);
820 evas_object_show(wd->hoversel);
821 elm_hoversel_hover_begin(wd->hoversel);
823 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
824 edje_object_part_text_select_abort(wd->ent, "elm.text");
826 wd->longpress_timer = NULL;
827 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
828 return ECORE_CALLBACK_CANCEL;
832 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
834 Widget_Data *wd = elm_widget_data_get(data);
835 Evas_Event_Mouse_Down *ev = event_info;
837 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
838 if (ev->button != 1) return;
839 // if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
840 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
841 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
842 wd->downx = ev->canvas.x;
843 wd->downy = ev->canvas.y;
847 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
849 Widget_Data *wd = elm_widget_data_get(data);
850 Evas_Event_Mouse_Up *ev = event_info;
852 if (ev->button != 1) return;
853 if (wd->longpress_timer)
855 ecore_timer_del(wd->longpress_timer);
856 wd->longpress_timer = NULL;
861 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
863 Widget_Data *wd = elm_widget_data_get(data);
864 Evas_Event_Mouse_Move *ev = event_info;
868 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
870 if (wd->longpress_timer)
872 ecore_timer_del(wd->longpress_timer);
873 wd->longpress_timer = NULL;
876 else if (wd->longpress_timer)
880 dx = wd->downx - ev->cur.canvas.x;
882 dy = wd->downy - ev->cur.canvas.y;
885 ((_elm_config->finger_size / 2) *
886 (_elm_config->finger_size / 2)))
888 ecore_timer_del(wd->longpress_timer);
889 wd->longpress_timer = NULL;
893 else if (wd->longpress_timer)
897 dx = wd->downx - ev->cur.canvas.x;
899 dy = wd->downy - ev->cur.canvas.y;
902 ((_elm_config->finger_size / 2) *
903 (_elm_config->finger_size / 2)))
905 ecore_timer_del(wd->longpress_timer);
906 wd->longpress_timer = NULL;
912 _getbase(Evas_Object *obj)
914 Widget_Data *wd = elm_widget_data_get(obj);
915 if (!wd) return "base";
918 if (wd->password) return "base-password";
921 if (wd->single_line) return "base-single";
924 if (wd->linewrap) return "base";
925 else if (wd->char_linewrap) return "base-charwrap";
926 else return "base-nowrap";
932 if (wd->password) return "base-password";
935 if (wd->single_line) return "base-single-noedit";
938 if (wd->linewrap) return "base-noedit";
939 else if (wd->char_linewrap) return "base-noedit-charwrap";
940 else return "base-nowrap-noedit";
948 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
950 Widget_Data *wd = elm_widget_data_get(data);
952 wd->changed = EINA_TRUE;
954 if (wd->text) eina_stringshare_del(wd->text);
956 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
959 ecore_timer_del(wd->delay_write);
960 wd->delay_write = NULL;
962 if ((!wd->autosave) || (!wd->file)) return;
963 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
967 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
969 Widget_Data *wd = elm_widget_data_get(data);
973 EINA_LIST_FOREACH(entries, l, entry)
975 if (entry != data) elm_entry_select_none(entry);
977 wd->have_selection = EINA_TRUE;
978 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
979 #ifdef HAVE_ELEMENTARY_X
980 if (wd->sel_notify_handler)
982 const char *txt = elm_entry_selection_get(data);
985 top = elm_widget_top_get(data);
986 if ((top) && (elm_win_xwindow_get(top)))
987 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
993 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
995 Widget_Data *wd = elm_widget_data_get(data);
997 wd->have_selection = EINA_TRUE;
998 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
999 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1000 elm_entry_selection_get(data));
1004 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1006 Widget_Data *wd = elm_widget_data_get(data);
1008 if (!wd->have_selection) return;
1009 wd->have_selection = EINA_FALSE;
1010 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1011 if (wd->sel_notify_handler)
1015 #ifdef HAVE_ELEMENTARY_X
1018 top = elm_widget_top_get(data);
1019 if ((top) && (elm_win_xwindow_get(top)))
1020 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1023 eina_stringshare_del(wd->cut_sel);
1028 #ifdef HAVE_ELEMENTARY_X
1031 top = elm_widget_top_get(data);
1032 if ((top) && (elm_win_xwindow_get(top)))
1033 elm_selection_clear(ELM_SEL_PRIMARY, data);
1040 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1042 Widget_Data *wd = elm_widget_data_get(data);
1044 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1045 if (wd->sel_notify_handler)
1047 #ifdef HAVE_ELEMENTARY_X
1050 top = elm_widget_top_get(data);
1051 if ((top) && (elm_win_xwindow_get(top)))
1053 wd->selection_asked = EINA_TRUE;
1054 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
1062 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1064 Widget_Data *wd = elm_widget_data_get(data);
1066 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1067 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1068 elm_entry_selection_get(data));
1072 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1074 Widget_Data *wd = elm_widget_data_get(data);
1076 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1077 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1078 elm_entry_selection_get(data));
1079 edje_object_part_text_insert(wd->ent, "elm.text", "");
1080 wd->changed = EINA_TRUE;
1085 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1087 Widget_Data *wd = elm_widget_data_get(data);
1088 Evas_Coord cx, cy, cw, ch;
1090 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1091 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1092 &cx, &cy, &cw, &ch);
1093 if (!wd->deferred_recalc_job)
1094 elm_widget_show_region_set(data, cx, cy, cw, ch);
1097 wd->deferred_cur = EINA_TRUE;
1106 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1108 Widget_Data *wd = elm_widget_data_get(data);
1113 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1115 Widget_Data *wd = elm_widget_data_get(data);
1116 Elm_Entry_Anchor_Info ei;
1117 char *buf2, *p, *p2, *n;
1119 p = strrchr(emission, ',');
1122 const Eina_List *geoms;
1126 while (p2 >= emission)
1128 if (*p2 == ',') break;
1132 buf2 = alloca(5 + p - p2);
1133 strncpy(buf2, p2, p - p2);
1136 ei.button = atoi(buf2);
1137 ei.x = ei.y = ei.w = ei.h = 0;
1139 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1142 Evas_Textblock_Rectangle *r;
1144 Evas_Coord px, py, x, y;
1146 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1147 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1148 EINA_LIST_FOREACH(geoms, l, r)
1150 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1151 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1162 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1167 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1169 Widget_Data *wd = elm_widget_data_get(data);
1174 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1176 Widget_Data *wd = elm_widget_data_get(data);
1181 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1183 Widget_Data *wd = elm_widget_data_get(data);
1188 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1190 Widget_Data *wd = elm_widget_data_get(data);
1192 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1196 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1198 Widget_Data *wd = elm_widget_data_get(data);
1200 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1204 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1206 Widget_Data *wd = elm_widget_data_get(data);
1208 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1212 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1214 Widget_Data *wd = elm_widget_data_get(data);
1216 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1219 #ifdef HAVE_ELEMENTARY_X
1221 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1223 Widget_Data *wd = elm_widget_data_get(data);
1224 Ecore_X_Event_Selection_Notify *ev = event;
1225 if (!wd) return ECORE_CALLBACK_PASS_ON;
1226 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1227 return ECORE_CALLBACK_PASS_ON;
1229 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1230 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1232 Ecore_X_Selection_Data_Text *text_data;
1234 text_data = ev->data;
1235 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1237 if (text_data->text)
1239 char *txt = _elm_util_text_to_mkup(text_data->text);
1243 elm_entry_entry_insert(data, txt);
1248 wd->selection_asked = EINA_FALSE;
1250 else if (ev->selection == ECORE_X_SELECTION_XDND)
1252 Ecore_X_Selection_Data_Text *text_data;
1254 text_data = ev->data;
1255 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1257 if (text_data->text)
1259 char *txt = _elm_util_text_to_mkup(text_data->text);
1263 /* Massive FIXME: this should be at the drag point */
1264 elm_entry_entry_insert(data, txt);
1269 wd->drag_selection_asked = EINA_FALSE;
1271 ecore_x_dnd_send_finished();
1274 return ECORE_CALLBACK_PASS_ON;
1278 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1281 Widget_Data *wd = elm_widget_data_get(data);
1282 Ecore_X_Event_Selection_Clear *ev = event;
1283 if (!wd) return ECORE_CALLBACK_PASS_ON;
1284 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1285 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1286 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1288 elm_entry_select_none(data);
1291 return ECORE_CALLBACK_PASS_ON;
1296 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1301 wd = elm_widget_data_get(obj);
1303 if (!wd) return EINA_FALSE;
1304 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1306 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1307 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1308 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1309 EDJE_CURSOR_MAIN,drop->x,drop->y);
1310 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1311 elm_entry_entry_insert(obj, drop->data);
1312 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1313 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1319 static Evas_Object *
1320 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1322 Widget_Data *wd = elm_widget_data_get(data);
1325 Elm_Entry_Item_Provider *ip;
1327 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1329 o = ip->func(ip->data, data, item);
1332 if (!strncmp(item, "file://", 7))
1334 const char *fname = item + 7;
1336 o = evas_object_image_filled_add(evas_object_evas_get(data));
1337 evas_object_image_file_set(o, fname, NULL);
1338 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1340 evas_object_show(o);
1345 o = edje_object_add(evas_object_evas_get(data));
1346 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1350 o = edje_object_add(evas_object_evas_get(data));
1351 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1352 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1357 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
1359 Widget_Data *wd = elm_widget_data_get(data);
1361 Elm_Entry_Text_Filter *tf;
1363 if (type == EDJE_TEXT_FILTER_FORMAT)
1366 EINA_LIST_FOREACH(wd->text_filters, l, tf)
1368 tf->func(tf->data, data, text);
1375 * This adds an entry to @p parent object.
1377 * @param parent The parent object
1378 * @return The new object or NULL if it cannot be created
1383 elm_entry_add(Evas_Object *parent)
1385 Evas_Object *obj, *top;
1389 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
1391 wd = ELM_NEW(Widget_Data);
1392 e = evas_object_evas_get(parent);
1393 if (!e) return NULL;
1394 obj = elm_widget_add(e);
1395 ELM_SET_WIDTYPE(widtype, "entry");
1396 elm_widget_type_set(obj, "entry");
1397 elm_widget_sub_object_add(parent, obj);
1398 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1399 elm_widget_data_set(obj, wd);
1400 elm_widget_del_hook_set(obj, _del_hook);
1401 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1402 elm_widget_theme_hook_set(obj, _theme_hook);
1403 elm_widget_disable_hook_set(obj, _disable_hook);
1404 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1405 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
1406 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1407 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1408 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
1409 elm_widget_can_focus_set(obj, EINA_TRUE);
1410 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
1412 wd->linewrap = EINA_TRUE;
1413 wd->char_linewrap= EINA_FALSE;
1414 wd->editable = EINA_TRUE;
1415 wd->disabled = EINA_FALSE;
1416 wd->context_menu = EINA_TRUE;
1417 wd->autosave = EINA_TRUE;
1418 wd->textonly = EINA_FALSE;
1420 wd->ent = edje_object_add(e);
1421 edje_object_item_provider_set(wd->ent, _get_item, obj);
1422 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
1423 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1424 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1425 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1427 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1429 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1432 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1433 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1434 _signal_entry_changed, obj);
1435 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1436 _signal_selection_start, obj);
1437 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1438 _signal_selection_changed, obj);
1439 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1440 _signal_selection_cleared, obj);
1441 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1442 _signal_entry_paste_request, obj);
1443 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1444 _signal_entry_copy_notify, obj);
1445 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1446 _signal_entry_cut_notify, obj);
1447 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1448 _signal_cursor_changed, obj);
1449 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1450 _signal_anchor_down, obj);
1451 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1452 _signal_anchor_up, obj);
1453 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1454 _signal_anchor_move, obj);
1455 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1456 _signal_anchor_in, obj);
1457 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1458 _signal_anchor_out, obj);
1459 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
1460 _signal_key_enter, obj);
1461 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
1462 _signal_mouse_down, obj);
1463 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
1464 _signal_mouse_clicked, obj);
1465 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
1466 _signal_mouse_double, obj);
1467 edje_object_part_text_set(wd->ent, "elm.text", "");
1468 elm_widget_resize_object_set(obj, wd->ent);
1471 #ifdef HAVE_ELEMENTARY_X
1472 top = elm_widget_top_get(obj);
1473 if ((top) && (elm_win_xwindow_get(top)))
1475 wd->sel_notify_handler =
1476 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
1477 _event_selection_notify, obj);
1478 wd->sel_clear_handler =
1479 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
1480 _event_selection_clear, obj);
1483 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
1484 _drag_drop_cb, NULL);
1487 entries = eina_list_prepend(entries, obj);
1489 // module - find module for entry
1490 wd->api = _module(obj);
1491 // if found - hook in
1492 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
1494 // TODO: convert Elementary to subclassing of Evas_Smart_Class
1495 // TODO: and save some bytes, making descriptions per-class and not instance!
1496 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1502 * This sets the entry object not to line wrap. All input will
1503 * be on a single line, and the entry box will extend with user input.
1505 * @param obj The entry object
1506 * @param single_line If true, the text in the entry
1507 * will be on a single line.
1512 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
1514 ELM_CHECK_WIDTYPE(obj, widtype);
1515 Widget_Data *wd = elm_widget_data_get(obj);
1518 if (wd->single_line == single_line) return;
1519 wd->single_line = single_line;
1520 wd->linewrap = EINA_FALSE;
1521 wd->char_linewrap = EINA_FALSE;
1522 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
1523 t = eina_stringshare_add(elm_entry_entry_get(obj));
1524 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1525 elm_entry_entry_set(obj, t);
1526 eina_stringshare_del(t);
1531 * This returns true if the entry has been set to single line mode.
1532 * See also elm_entry_single_line_set().
1534 * @param obj The entry object
1535 * @return single_line If true, the text in the entry is set to display
1541 elm_entry_single_line_get(const Evas_Object *obj)
1543 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1544 Widget_Data *wd = elm_widget_data_get(obj);
1545 if (!wd) return EINA_FALSE;
1546 return wd->single_line;
1550 * This sets the entry object to password mode. All text entered
1551 * and/or displayed within the widget will be replaced with asterisks (*).
1553 * @param obj The entry object
1554 * @param password If true, password mode is enabled.
1559 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
1561 ELM_CHECK_WIDTYPE(obj, widtype);
1562 Widget_Data *wd = elm_widget_data_get(obj);
1565 if (wd->password == password) return;
1566 wd->password = password;
1567 wd->single_line = EINA_TRUE;
1568 wd->linewrap = EINA_FALSE;
1569 wd->char_linewrap = EINA_FALSE;
1570 t = eina_stringshare_add(elm_entry_entry_get(obj));
1571 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1572 elm_entry_entry_set(obj, t);
1573 eina_stringshare_del(t);
1579 * This returns whether password mode is enabled.
1580 * See also elm_entry_password_set().
1582 * @param obj The entry object
1583 * @return If true, the entry is set to display all characters
1589 elm_entry_password_get(const Evas_Object *obj)
1591 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1592 Widget_Data *wd = elm_widget_data_get(obj);
1593 if (!wd) return EINA_FALSE;
1594 return wd->password;
1598 * This sets the text displayed within the entry to @p entry.
1600 * @param obj The entry object
1601 * @param entry The text to be displayed
1606 elm_entry_entry_set(Evas_Object *obj, const char *entry)
1608 ELM_CHECK_WIDTYPE(obj, widtype);
1609 Widget_Data *wd = elm_widget_data_get(obj);
1611 if (!entry) entry = "";
1612 edje_object_part_text_set(wd->ent, "elm.text", entry);
1613 if (wd->text) eina_stringshare_del(wd->text);
1615 wd->changed = EINA_TRUE;
1620 * This returns the text currently shown in object @p entry.
1621 * See also elm_entry_entry_set().
1623 * @param obj The entry object
1624 * @return The currently displayed text or NULL on failure
1629 elm_entry_entry_get(const Evas_Object *obj)
1631 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1632 Widget_Data *wd = elm_widget_data_get(obj);
1634 if (!wd) return NULL;
1635 if (wd->text) return wd->text;
1636 text = edje_object_part_text_get(wd->ent, "elm.text");
1639 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
1642 eina_stringshare_replace(&wd->text, text);
1648 * This returns EINA_TRUE if the entry is empty/there was an error
1649 * and EINA_FALSE if it is not empty.
1651 * @param obj The entry object
1652 * @return If the entry is empty or not.
1657 elm_entry_is_empty(const Evas_Object *obj)
1659 /* FIXME: until there's support for that in textblock, we just check
1660 * to see if the there is text or not. */
1661 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
1662 Widget_Data *wd = elm_widget_data_get(obj);
1663 const Evas_Object *tb;
1664 Evas_Textblock_Cursor *cur;
1666 if (!wd) return EINA_TRUE;
1667 /* It's a hack until we get the support suggested above.
1668 * We just create a cursor, point it to the begining, and then
1669 * try to advance it, if it can advance, the tb is not empty,
1670 * otherwise it is. */
1671 tb = edje_object_part_object_get(wd->ent, "elm.text");
1672 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
1673 actually, ok for the time being, thsese hackish stuff will be removed
1674 once evas 1.0 is out*/
1675 evas_textblock_cursor_pos_set(cur, 0);
1676 ret = evas_textblock_cursor_char_next(cur);
1677 evas_textblock_cursor_free(cur);
1683 * This returns all selected text within the entry.
1685 * @param obj The entry object
1686 * @return The selected text within the entry or NULL on failure
1691 elm_entry_selection_get(const Evas_Object *obj)
1693 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1694 Widget_Data *wd = elm_widget_data_get(obj);
1695 if (!wd) return NULL;
1696 return edje_object_part_text_selection_get(wd->ent, "elm.text");
1700 * This inserts text in @p entry where the current cursor position.
1702 * This inserts text at the cursor position is as if it was typed
1703 * by the user (note this also allows markup which a user
1704 * can't just "type" as it would be converted to escaped text, so this
1705 * call can be used to insert things like emoticon items or bold push/pop
1706 * tags, other font and color change tags etc.)
1708 * @param obj The entry object
1709 * @param entry The text to insert
1714 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
1716 ELM_CHECK_WIDTYPE(obj, widtype);
1717 Widget_Data *wd = elm_widget_data_get(obj);
1719 edje_object_part_text_insert(wd->ent, "elm.text", entry);
1720 wd->changed = EINA_TRUE;
1725 * This enables word line wrapping in the entry object. It is the opposite
1726 * of elm_entry_single_line_set(). Additionally, setting this disables
1727 * character line wrapping.
1728 * See also elm_entry_line_char_wrap_set().
1730 * @param obj The entry object
1731 * @param wrap If true, the entry will be wrapped once it reaches the end
1732 * of the object. Wrapping will occur at the end of the word before the end of the
1738 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
1740 ELM_CHECK_WIDTYPE(obj, widtype);
1741 Widget_Data *wd = elm_widget_data_get(obj);
1744 if (wd->linewrap == wrap) return;
1745 wd->linewrap = wrap;
1747 wd->char_linewrap = EINA_FALSE;
1748 t = eina_stringshare_add(elm_entry_entry_get(obj));
1749 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1750 elm_entry_entry_set(obj, t);
1751 eina_stringshare_del(t);
1756 * This enables character line wrapping in the entry object. It is the opposite
1757 * of elm_entry_single_line_set(). Additionally, setting this disables
1758 * word line wrapping.
1759 * See also elm_entry_line_wrap_set().
1761 * @param obj The entry object
1762 * @param wrap If true, the entry will be wrapped once it reaches the end
1763 * of the object. Wrapping will occur immediately upon reaching the end of the object.
1768 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
1770 ELM_CHECK_WIDTYPE(obj, widtype);
1771 Widget_Data *wd = elm_widget_data_get(obj);
1774 if (wd->char_linewrap == wrap) return;
1775 wd->char_linewrap = wrap;
1776 if(wd->char_linewrap)
1777 wd->linewrap = EINA_FALSE;
1778 t = eina_stringshare_add(elm_entry_entry_get(obj));
1779 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1780 elm_entry_entry_set(obj, t);
1781 eina_stringshare_del(t);
1786 * This sets the editable attribute of the entry.
1788 * @param obj The entry object
1789 * @param editable If true, the entry will be editable by the user.
1790 * If false, it will be set to the disabled state.
1795 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
1797 ELM_CHECK_WIDTYPE(obj, widtype);
1798 Widget_Data *wd = elm_widget_data_get(obj);
1801 if (wd->editable == editable) return;
1802 wd->editable = editable;
1803 t = eina_stringshare_add(elm_entry_entry_get(obj));
1804 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1805 elm_entry_entry_set(obj, t);
1806 eina_stringshare_del(t);
1809 #ifdef HAVE_ELEMENTARY_X
1811 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
1813 elm_drop_target_del(obj);
1818 * This gets the editable attribute of the entry.
1819 * See also elm_entry_editable_set().
1821 * @param obj The entry object
1822 * @return If true, the entry is editable by the user.
1823 * If false, it is not editable by the user
1828 elm_entry_editable_get(const Evas_Object *obj)
1830 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1831 Widget_Data *wd = elm_widget_data_get(obj);
1832 if (!wd) return EINA_FALSE;
1833 return wd->editable;
1837 * This drops any existing text selection within the entry.
1839 * @param obj The entry object
1844 elm_entry_select_none(Evas_Object *obj)
1846 ELM_CHECK_WIDTYPE(obj, widtype);
1847 Widget_Data *wd = elm_widget_data_get(obj);
1851 wd->selmode = EINA_FALSE;
1852 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
1853 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1855 wd->have_selection = EINA_FALSE;
1856 edje_object_part_text_select_none(wd->ent, "elm.text");
1860 * This selects all text within the entry.
1862 * @param obj The entry object
1867 elm_entry_select_all(Evas_Object *obj)
1869 ELM_CHECK_WIDTYPE(obj, widtype);
1870 Widget_Data *wd = elm_widget_data_get(obj);
1874 wd->selmode = EINA_FALSE;
1875 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
1876 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1878 wd->have_selection = EINA_TRUE;
1879 edje_object_part_text_select_all(wd->ent, "elm.text");
1883 * This function returns the geometry of the cursor.
1885 * It's useful if you want to draw something on the cursor (or where it is),
1886 * or for example in the case of scrolled entry where you want to show the
1889 * @param obj The entry object
1890 * @param x returned geometry
1891 * @param y returned geometry
1892 * @param w returned geometry
1893 * @param h returned geometry
1894 * @return EINA_TRUE upon success, EINA_FALSE upon failure
1899 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1901 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1902 Widget_Data *wd = elm_widget_data_get(obj);
1903 if (!wd) return EINA_FALSE;
1904 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
1909 * This moves the cursor one place to the right within the entry.
1911 * @param obj The entry object
1912 * @return EINA_TRUE upon success, EINA_FALSE upon failure
1917 elm_entry_cursor_next(Evas_Object *obj)
1919 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1920 Widget_Data *wd = elm_widget_data_get(obj);
1921 if (!wd) return EINA_FALSE;
1922 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1926 * This moves the cursor one place to the left within the entry.
1928 * @param obj The entry object
1929 * @return EINA_TRUE upon success, EINA_FALSE upon failure
1934 elm_entry_cursor_prev(Evas_Object *obj)
1936 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1937 Widget_Data *wd = elm_widget_data_get(obj);
1938 if (!wd) return EINA_FALSE;
1939 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1943 * This moves the cursor one line up within the entry.
1945 * @param obj The entry object
1946 * @return EINA_TRUE upon success, EINA_FALSE upon failure
1951 elm_entry_cursor_up(Evas_Object *obj)
1953 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1954 Widget_Data *wd = elm_widget_data_get(obj);
1955 if (!wd) return EINA_FALSE;
1956 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1960 * This moves the cursor one line down within the entry.
1962 * @param obj The entry object
1963 * @return EINA_TRUE upon success, EINA_FALSE upon failure
1968 elm_entry_cursor_down(Evas_Object *obj)
1970 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1971 Widget_Data *wd = elm_widget_data_get(obj);
1972 if (!wd) return EINA_FALSE;
1973 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1977 * This moves the cursor to the beginning of the entry.
1979 * @param obj The entry object
1984 elm_entry_cursor_begin_set(Evas_Object *obj)
1986 ELM_CHECK_WIDTYPE(obj, widtype);
1987 Widget_Data *wd = elm_widget_data_get(obj);
1989 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1993 * This moves the cursor to the end of the entry.
1995 * @param obj The entry object
2000 elm_entry_cursor_end_set(Evas_Object *obj)
2002 ELM_CHECK_WIDTYPE(obj, widtype);
2003 Widget_Data *wd = elm_widget_data_get(obj);
2005 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2009 * This moves the cursor to the beginning of the current line.
2011 * @param obj The entry object
2016 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2018 ELM_CHECK_WIDTYPE(obj, widtype);
2019 Widget_Data *wd = elm_widget_data_get(obj);
2021 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2025 * This moves the cursor to the end of the current line.
2027 * @param obj The entry object
2032 elm_entry_cursor_line_end_set(Evas_Object *obj)
2034 ELM_CHECK_WIDTYPE(obj, widtype);
2035 Widget_Data *wd = elm_widget_data_get(obj);
2037 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2041 * This begins a selection within the entry as though
2042 * the user were holding down the mouse button to make a selection.
2044 * @param obj The entry object
2049 elm_entry_cursor_selection_begin(Evas_Object *obj)
2051 ELM_CHECK_WIDTYPE(obj, widtype);
2052 Widget_Data *wd = elm_widget_data_get(obj);
2054 edje_object_part_text_select_begin(wd->ent, "elm.text");
2058 * This ends a selection within the entry as though
2059 * the user had just released the mouse button while making a selection.
2061 * @param obj The entry object
2066 elm_entry_cursor_selection_end(Evas_Object *obj)
2068 ELM_CHECK_WIDTYPE(obj, widtype);
2069 Widget_Data *wd = elm_widget_data_get(obj);
2071 edje_object_part_text_select_extend(wd->ent, "elm.text");
2075 * TODO: fill this in
2077 * @param obj The entry object
2078 * @return TODO: fill this in
2083 elm_entry_cursor_is_format_get(const 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_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2092 * This returns whether the cursor is visible.
2094 * @param obj The entry object
2095 * @return If true, the cursor is visible.
2100 elm_entry_cursor_is_visible_format_get(const 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_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2109 * TODO: fill this in
2111 * @param obj The entry object
2112 * @return TODO: fill this in
2117 elm_entry_cursor_content_get(const Evas_Object *obj)
2119 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2120 Widget_Data *wd = elm_widget_data_get(obj);
2121 if (!wd) return NULL;
2122 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2126 * This executes a "cut" action on the selected text in the entry.
2128 * @param obj The entry object
2133 elm_entry_selection_cut(Evas_Object *obj)
2135 ELM_CHECK_WIDTYPE(obj, widtype);
2136 Widget_Data *wd = elm_widget_data_get(obj);
2138 _cut(obj, NULL, NULL);
2142 * This executes a "copy" action on the selected text in the entry.
2144 * @param obj The entry object
2149 elm_entry_selection_copy(Evas_Object *obj)
2151 ELM_CHECK_WIDTYPE(obj, widtype);
2152 Widget_Data *wd = elm_widget_data_get(obj);
2154 _copy(obj, NULL, NULL);
2158 * This executes a "paste" action in the entry.
2160 * @param obj The entry object
2165 elm_entry_selection_paste(Evas_Object *obj)
2167 ELM_CHECK_WIDTYPE(obj, widtype);
2168 Widget_Data *wd = elm_widget_data_get(obj);
2170 _paste(obj, NULL, NULL);
2174 * This clears and frees the items in a entry's contextual (right click) menu.
2176 * @param obj The entry object
2181 elm_entry_context_menu_clear(Evas_Object *obj)
2183 ELM_CHECK_WIDTYPE(obj, widtype);
2184 Widget_Data *wd = elm_widget_data_get(obj);
2185 Elm_Entry_Context_Menu_Item *it;
2187 EINA_LIST_FREE(wd->items, it)
2189 eina_stringshare_del(it->label);
2190 eina_stringshare_del(it->icon_file);
2191 eina_stringshare_del(it->icon_group);
2197 * This adds an item to the entry's contextual menu.
2199 * @param obj The entry object
2200 * @param label The item's text label
2201 * @param icon_file The item's icon file
2202 * @param icon_type The item's icon type
2203 * @param func The callback to execute when the item is clicked
2204 * @param data The data to associate with the item for related functions
2209 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)
2211 ELM_CHECK_WIDTYPE(obj, widtype);
2212 Widget_Data *wd = elm_widget_data_get(obj);
2213 Elm_Entry_Context_Menu_Item *it;
2215 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2217 wd->items = eina_list_append(wd->items, it);
2219 it->label = eina_stringshare_add(label);
2220 it->icon_file = eina_stringshare_add(icon_file);
2221 it->icon_type = icon_type;
2223 it->data = (void *)data;
2227 * This disables the entry's contextual (right click) menu.
2229 * @param obj The entry object
2230 * @param disabled If true, the menu is disabled
2235 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2237 ELM_CHECK_WIDTYPE(obj, widtype);
2238 Widget_Data *wd = elm_widget_data_get(obj);
2240 if (wd->context_menu == !disabled) return;
2241 wd->context_menu = !disabled;
2245 * This returns whether the entry's contextual (right click) menu is disabled.
2247 * @param obj The entry object
2248 * @return If true, the menu is disabled
2253 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2255 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2256 Widget_Data *wd = elm_widget_data_get(obj);
2257 if (!wd) return EINA_FALSE;
2258 return !wd->context_menu;
2262 * This appends a custom item provider to the list for that entry
2264 * This appends the given callback. The list is walked from beginning to end
2265 * with each function called given the item href string in the text. If the
2266 * function returns an object handle other than NULL (it should create an
2267 * and object to do this), then this object is used to replace that item. If
2268 * not the next provider is called until one provides an item object, or the
2269 * default provider in entry does.
2271 * @param obj The entry object
2272 * @param func The function called to provide the item object
2273 * @param data The data passed to @p func
2278 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2280 ELM_CHECK_WIDTYPE(obj, widtype);
2281 Widget_Data *wd = elm_widget_data_get(obj);
2283 EINA_SAFETY_ON_NULL_RETURN(func);
2284 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2288 wd->item_providers = eina_list_append(wd->item_providers, ip);
2292 * This prepends a custom item provider to the list for that entry
2294 * This prepends the given callback. See elm_entry_item_provider_append() for
2297 * @param obj The entry object
2298 * @param func The function called to provide the item object
2299 * @param data The data passed to @p func
2304 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2306 ELM_CHECK_WIDTYPE(obj, widtype);
2307 Widget_Data *wd = elm_widget_data_get(obj);
2309 EINA_SAFETY_ON_NULL_RETURN(func);
2310 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2314 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2318 * This removes a custom item provider to the list for that entry
2320 * This removes the given callback. See elm_entry_item_provider_append() for
2323 * @param obj The entry object
2324 * @param func The function called to provide the item object
2325 * @param data The data passed to @p func
2330 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2332 ELM_CHECK_WIDTYPE(obj, widtype);
2333 Widget_Data *wd = elm_widget_data_get(obj);
2335 Elm_Entry_Item_Provider *ip;
2337 EINA_SAFETY_ON_NULL_RETURN(func);
2338 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2340 if ((ip->func == func) && (ip->data == data))
2342 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2350 * Append a filter function for text inserted in the entry
2352 * Append the given callback to the list. This functions will be called
2353 * whenever any text is inserted into the entry, with the text to be inserted
2354 * as a parameter. The callback function is free to alter the text in any way
2355 * it wants, but it must remember to free the given pointer and update it.
2356 * If the new text is to be discarded, the function can free it and set it text
2357 * parameter to NULL. This will also prevent any following filters from being
2360 * @param obj The entry object
2361 * @param func The function to use as text filter
2362 * @param data User data to pass to @p func
2367 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2370 Elm_Entry_Text_Filter *tf;
2371 ELM_CHECK_WIDTYPE(obj, widtype);
2373 wd = elm_widget_data_get(obj);
2375 EINA_SAFETY_ON_NULL_RETURN(func);
2377 tf = ELM_NEW(Elm_Entry_Text_Filter);
2381 wd->text_filters = eina_list_append(wd->text_filters, tf);
2385 * Prepend a filter function for text insdrted in the entry
2387 * Prepend the given callback to the list. See elm_entry_text_filter_append()
2388 * for more information
2390 * @param obj The entry object
2391 * @param func The function to use as text filter
2392 * @param data User data to pass to @p func
2397 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2400 Elm_Entry_Text_Filter *tf;
2401 ELM_CHECK_WIDTYPE(obj, widtype);
2403 wd = elm_widget_data_get(obj);
2405 EINA_SAFETY_ON_NULL_RETURN(func);
2407 tf = ELM_NEW(Elm_Entry_Text_Filter);
2411 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
2415 * Remove a filter from the list
2417 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
2418 * for more information.
2420 * @param obj The entry object
2421 * @param func The filter function to remove
2422 * @param data The user data passed when adding the function
2427 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2431 Elm_Entry_Text_Filter *tf;
2432 ELM_CHECK_WIDTYPE(obj, widtype);
2434 wd = elm_widget_data_get(obj);
2436 EINA_SAFETY_ON_NULL_RETURN(func);
2438 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2440 if ((tf->func == func) && (tf->data == data))
2442 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
2450 * This converts a markup (HTML-like) string into UTF-8.
2452 * @param s The string (in markup) to be converted
2453 * @return The converted string (in UTF-8)
2458 elm_entry_markup_to_utf8(const char *s)
2460 char *ss = _elm_util_mkup_to_text(s);
2461 if (!ss) ss = strdup("");
2466 * This converts a UTF-8 string into markup (HTML-like).
2468 * @param s The string (in UTF-8) to be converted
2469 * @return The converted string (in markup)
2474 elm_entry_utf8_to_markup(const char *s)
2476 char *ss = _elm_util_text_to_mkup(s);
2477 if (!ss) ss = strdup("");
2482 * Filter inserted text based on user defined character and byte limits
2484 * Add this filter to an entry to limit the characters that it will accept
2485 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
2486 * The funtion works on the UTF-8 representation of the string, converting
2487 * it from the set markup, thus not accounting for any format in it.
2489 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
2490 * it as data when setting the filter. In it it's possible to set limits
2491 * by character count or bytes (any of them is disabled if 0), and both can
2492 * be set at the same time. In that case, it first checks for characters,
2495 * The function will cut the inserted text in order to allow only the first
2496 * number of characters that are still allowed. The cut is made in
2497 * characters, even when limiting by bytes, in order to always contain
2498 * valid ones and avoid half unicode characters making it in.
2503 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
2505 Elm_Entry_Filter_Limit_Size *lim = data;
2508 const char *(*text_get)(const Evas_Object *);
2509 const char *widget_type;
2511 EINA_SAFETY_ON_NULL_RETURN(data);
2512 EINA_SAFETY_ON_NULL_RETURN(entry);
2513 EINA_SAFETY_ON_NULL_RETURN(text);
2515 /* hack. I don't want to copy the entire function to work with
2517 widget_type = elm_widget_type_get(entry);
2518 if (!strcmp(widget_type, "entry"))
2519 text_get = elm_entry_entry_get;
2520 else if (!strcmp(widget_type, "scrolled_entry"))
2521 text_get = elm_scrolled_entry_entry_get;
2525 current = elm_entry_markup_to_utf8(text_get(entry));
2527 if (lim->max_char_count > 0)
2530 len = evas_string_char_len_get(current);
2531 if (len >= lim->max_char_count)
2538 newlen = evas_string_char_len_get(*text);
2539 cut = strlen(*text);
2540 while ((len + newlen) > lim->max_char_count)
2542 cut = evas_string_char_prev_get(*text, cut, NULL);
2548 if (lim->max_byte_count > 0)
2550 len = strlen(current);
2551 if (len >= lim->max_byte_count)
2558 newlen = strlen(*text);
2559 while ((len + newlen) > lim->max_byte_count)
2561 int p = evas_string_char_prev_get(*text, newlen, NULL);
2562 newlen -= (newlen - p);
2565 (*text)[newlen] = 0;
2576 * Filter inserted text based on accepted or rejected sets of characters
2578 * Add this filter to an entry to restrict the set of accepted characters
2579 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
2580 * This structure contains both accepted and rejected sets, but they are
2581 * mutually exclusive. If accepted is set, it will be used, otherwise it
2582 * goes on to the rejected set.
2585 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
2587 Elm_Entry_Filter_Accept_Set *as = data;
2591 int read_idx, last_read_idx = 0, read_char;
2593 EINA_SAFETY_ON_NULL_RETURN(data);
2594 EINA_SAFETY_ON_NULL_RETURN(text);
2596 if ((!as->accepted) && (!as->rejected))
2602 goes_in = EINA_TRUE;
2607 goes_in = EINA_FALSE;
2611 read_idx = evas_string_char_next_get(*text, 0, &read_char);
2614 int cmp_idx, cmp_char;
2615 Eina_Bool in_set = EINA_FALSE;
2617 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
2620 if (read_char == cmp_char)
2625 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
2627 if (in_set == goes_in)
2629 int size = read_idx - last_read_idx;
2630 const char *src = (*text) + last_read_idx;
2632 memcpy(insert, *text + last_read_idx, size);
2635 last_read_idx = read_idx;
2636 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
2642 * This sets the file (and implicitly loads it) for the text to display and
2643 * then edit. All changes are written back to the file after a short delay if
2644 * the entry object is set to autosave.
2646 * @param obj The entry object
2647 * @param file The path to the file to load and save
2648 * @param format The file format
2653 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
2655 ELM_CHECK_WIDTYPE(obj, widtype);
2656 Widget_Data *wd = elm_widget_data_get(obj);
2658 if (wd->delay_write)
2660 ecore_timer_del(wd->delay_write);
2661 wd->delay_write = NULL;
2663 if (wd->autosave) _save(obj);
2664 eina_stringshare_replace(&wd->file, file);
2665 wd->format = format;
2670 * Gets the file to load and save and the file format
2672 * @param obj The entry object
2673 * @param file The path to the file to load and save
2674 * @param format The file format
2679 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
2681 ELM_CHECK_WIDTYPE(obj, widtype);
2682 Widget_Data *wd = elm_widget_data_get(obj);
2684 if (file) *file = wd->file;
2685 if (format) *format = wd->format;
2689 * This function writes any changes made to the file set with
2690 * elm_entry_file_set()
2692 * @param obj The entry object
2697 elm_entry_file_save(Evas_Object *obj)
2699 ELM_CHECK_WIDTYPE(obj, widtype);
2700 Widget_Data *wd = elm_widget_data_get(obj);
2702 if (wd->delay_write)
2704 ecore_timer_del(wd->delay_write);
2705 wd->delay_write = NULL;
2708 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
2712 * This sets the entry object to 'autosave' the loaded text file or not.
2714 * @param obj The entry object
2715 * @param autosave Autosave the loaded file or not
2720 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
2722 ELM_CHECK_WIDTYPE(obj, widtype);
2723 Widget_Data *wd = elm_widget_data_get(obj);
2725 wd->autosave = !!autosave;
2729 * This gets the entry object's 'autosave' status.
2731 * @param obj The entry object
2732 * @return Autosave the loaded file or not
2737 elm_entry_autosave_get(const Evas_Object *obj)
2739 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2740 Widget_Data *wd = elm_widget_data_get(obj);
2741 if (!wd) return EINA_FALSE;
2742 return wd->autosave;
2747 * Control pasting of text and images for the widget.
2749 * Normally the entry allows both text and images to be pasted. By setting
2750 * textonly to be true, this prevents images from being pasted.
2752 * Note this only changes the behaviour of text.
2754 * @param obj The entry object
2755 * @param pmode paste mode - 0 is text only, 1 is text+image+other.
2760 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
2762 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
2763 ELM_CHECK_WIDTYPE(obj, widtype);
2764 Widget_Data *wd = elm_widget_data_get(obj);
2766 textonly = !!textonly;
2767 if (wd->textonly == textonly) return;
2768 wd->textonly = !!textonly;
2769 if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
2770 elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
2774 * Getting elm_entry text paste/drop mode.
2776 * In textonly mode, only text may be pasted or dropped into the widget.
2778 * @param obj The entry object
2779 * @return If the widget only accepts text from pastes.
2784 elm_entry_cnp_textonly_get(Evas_Object *obj)
2786 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2787 Widget_Data *wd = elm_widget_data_get(obj);
2788 if (!wd) return EINA_FALSE;
2789 return wd->textonly;