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 #ifdef HAVE_ELEMENTARY_X
167 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
169 static void _del_hook(Evas_Object *obj);
170 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
171 static void _theme_hook(Evas_Object *obj);
172 static void _disable_hook(Evas_Object *obj);
173 static void _sizing_eval(Evas_Object *obj);
174 static void _on_focus_hook(void *data, Evas_Object *obj);
175 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
176 static const char *_getbase(Evas_Object *obj);
177 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
178 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
179 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
180 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
181 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
182 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
183 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
184 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
186 static const char SIG_CHANGED[] = "changed";
187 static const char SIG_ACTIVATED[] = "activated";
188 static const char SIG_PRESS[] = "press";
189 static const char SIG_LONGPRESSED[] = "longpressed";
190 static const char SIG_CLICKED[] = "clicked";
191 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
192 static const char SIG_FOCUSED[] = "focused";
193 static const char SIG_UNFOCUSED[] = "unfocused";
194 static const char SIG_SELECTION_PASTE[] = "selection,paste";
195 static const char SIG_SELECTION_COPY[] = "selection,copy";
196 static const char SIG_SELECTION_CUT[] = "selection,cut";
197 static const char SIG_SELECTION_START[] = "selection,start";
198 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
199 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
200 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
201 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
202 static const Evas_Smart_Cb_Description _signals[] = {
206 {SIG_LONGPRESSED, ""},
208 {SIG_CLICKED_DOUBLE, ""},
211 {SIG_SELECTION_PASTE, ""},
212 {SIG_SELECTION_COPY, ""},
213 {SIG_SELECTION_CUT, ""},
214 {SIG_SELECTION_START, ""},
215 {SIG_SELECTION_CHANGED, ""},
216 {SIG_SELECTION_CLEARED, ""},
217 {SIG_CURSOR_CHANGED, ""},
218 {SIG_ANCHOR_CLICKED, ""},
222 static Eina_List *entries = NULL;
226 void (*obj_hook) (Evas_Object *obj);
227 void (*obj_unhook) (Evas_Object *obj);
228 void (*obj_longpress) (Evas_Object *obj);
232 _module(Evas_Object *obj __UNUSED__)
234 static Elm_Module *m = NULL;
235 if (m) goto ok; // already found - just use
236 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
238 m->api = malloc(sizeof(Mod_Api));
239 if (!m->api) return NULL;
240 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
241 _elm_module_symbol_get(m, "obj_hook");
242 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
243 _elm_module_symbol_get(m, "obj_unhook");
244 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
245 _elm_module_symbol_get(m, "obj_longpress");
246 ok: // ok - return api
251 _buf_append(char *buf, const char *str, int *len, int *alloc)
253 int len2 = strlen(str);
254 if ((*len + len2) >= *alloc)
256 char *buf2 = realloc(buf, *alloc + len2 + 512);
257 if (!buf2) return NULL;
259 *alloc += (512 + len2);
261 strcpy(buf + *len, str);
267 _load_file(const char *file)
271 int alloc = 0, len = 0;
272 char *text = NULL, buf[16384 + 1];
274 f = fopen(file, "rb");
276 while ((size = fread(buf, 1, sizeof(buf) - 1, f)))
280 tmp_text = _buf_append(text, buf, &len, &alloc);
281 if (!tmp_text) break;
289 _load_plain(const char *file)
293 text = _load_file(file);
298 text2 = elm_entry_utf8_to_markup(text);
306 _load(Evas_Object *obj)
308 Widget_Data *wd = elm_widget_data_get(obj);
313 elm_entry_entry_set(obj, "");
318 case ELM_TEXT_FORMAT_PLAIN_UTF8:
319 text = _load_plain(wd->file);
321 case ELM_TEXT_FORMAT_MARKUP_UTF8:
322 text = _load_file(wd->file);
330 elm_entry_entry_set(obj, text);
334 elm_entry_entry_set(obj, "");
338 _save_markup_utf8(const char *file, const char *text)
342 if ((!text) || (!text[0]))
344 ecore_file_unlink(file);
347 f = fopen(file, "wb");
350 // FIXME: report a write error
353 fputs(text, f); // FIXME: catch error
358 _save_plain_utf8(const char *file, const char *text)
362 text2 = elm_entry_markup_to_utf8(text);
365 _save_markup_utf8(file, text2);
370 _save(Evas_Object *obj)
372 Widget_Data *wd = elm_widget_data_get(obj);
374 if (!wd->file) return;
377 case ELM_TEXT_FORMAT_PLAIN_UTF8:
378 _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
380 case ELM_TEXT_FORMAT_MARKUP_UTF8:
381 _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
389 _delay_write(void *data)
391 Widget_Data *wd = elm_widget_data_get(data);
392 if (!wd) return ECORE_CALLBACK_CANCEL;
394 wd->delay_write = NULL;
395 return ECORE_CALLBACK_CANCEL;
399 _del_pre_hook(Evas_Object *obj)
401 Widget_Data *wd = elm_widget_data_get(obj);
405 ecore_timer_del(wd->delay_write);
406 wd->delay_write = NULL;
407 if (wd->autosave) _save(obj);
412 _del_hook(Evas_Object *obj)
414 Widget_Data *wd = elm_widget_data_get(obj);
415 Elm_Entry_Context_Menu_Item *it;
416 Elm_Entry_Item_Provider *ip;
417 Elm_Entry_Text_Filter *tf;
419 if (wd->file) eina_stringshare_del(wd->file);
421 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
422 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
424 entries = eina_list_remove(entries, obj);
425 #ifdef HAVE_ELEMENTARY_X
426 ecore_event_handler_del(wd->sel_notify_handler);
427 ecore_event_handler_del(wd->sel_clear_handler);
429 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
430 if (wd->text) eina_stringshare_del(wd->text);
431 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
432 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
433 EINA_LIST_FREE(wd->items, it)
435 eina_stringshare_del(it->label);
436 eina_stringshare_del(it->icon_file);
437 eina_stringshare_del(it->icon_group);
440 EINA_LIST_FREE(wd->item_providers, ip)
444 EINA_LIST_FREE(wd->text_filters, tf)
452 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
454 Widget_Data *wd = elm_widget_data_get(obj);
455 edje_object_mirrored_set(wd->ent, rtl);
459 _theme_hook(Evas_Object *obj)
461 Widget_Data *wd = elm_widget_data_get(obj);
463 _elm_widget_mirrored_reload(obj);
464 _mirrored_set(obj, elm_widget_mirrored_get(obj));
466 t = eina_stringshare_add(elm_entry_entry_get(obj));
467 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
468 elm_entry_entry_set(obj, t);
469 eina_stringshare_del(t);
470 if (elm_widget_disabled_get(obj))
471 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
472 edje_object_message_signal_process(wd->ent);
473 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
478 _disable_hook(Evas_Object *obj)
480 Widget_Data *wd = elm_widget_data_get(obj);
482 if (elm_widget_disabled_get(obj))
484 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
485 wd->disabled = EINA_TRUE;
489 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
490 wd->disabled = EINA_FALSE;
495 _elm_win_recalc_job(void *data)
497 Widget_Data *wd = elm_widget_data_get(data);
498 Evas_Coord minw = -1, minh = -1, maxh = -1;
499 Evas_Coord resw, resh, minminw;
501 wd->deferred_recalc_job = NULL;
502 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
504 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, 0, 0);
505 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
507 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
508 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
509 evas_object_size_hint_min_set(data, minminw, minh);
510 if (wd->single_line) maxh = minh;
511 evas_object_size_hint_max_set(data, -1, maxh);
512 if (wd->deferred_cur)
513 elm_widget_show_region_set(data, wd->cx, wd->cy, wd->cw, wd->ch);
517 _sizing_eval(Evas_Object *obj)
519 Widget_Data *wd = elm_widget_data_get(obj);
520 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
521 Evas_Coord resw, resh;
523 if ((wd->linewrap) || (wd->char_linewrap))
525 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
526 if ((resw == wd->lastw) && (!wd->changed)) return;
527 wd->changed = EINA_FALSE;
529 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
530 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
534 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
535 edje_object_size_min_calc(wd->ent, &minw, &minh);
536 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
537 evas_object_size_hint_min_set(obj, minw, minh);
538 if (wd->single_line) maxh = minh;
539 evas_object_size_hint_max_set(obj, maxw, maxh);
544 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
546 Widget_Data *wd = elm_widget_data_get(obj);
547 Evas_Object *top = elm_widget_top_get(obj);
549 if (!wd->editable) return;
550 if (elm_widget_focus_get(obj))
552 evas_object_focus_set(wd->ent, EINA_TRUE);
553 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
554 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
555 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
559 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
560 evas_object_focus_set(wd->ent, EINA_FALSE);
561 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
562 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
567 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
569 Widget_Data *wd = elm_widget_data_get(obj);
571 edje_object_signal_emit(wd->ent, emission, source);
575 _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)
577 Widget_Data *wd = elm_widget_data_get(obj);
579 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
583 _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)
585 Widget_Data *wd = elm_widget_data_get(obj);
586 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
591 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
593 Widget_Data *wd = elm_widget_data_get(obj);
594 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
598 _hoversel_position(Evas_Object *obj)
600 Widget_Data *wd = elm_widget_data_get(obj);
601 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
603 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
604 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
606 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
617 evas_object_move(wd->hoversel, x + cx, y + cy);
618 evas_object_resize(wd->hoversel, cw, ch);
622 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
624 Widget_Data *wd = elm_widget_data_get(data);
626 if (wd->hoversel) _hoversel_position(data);
630 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
632 Widget_Data *wd = elm_widget_data_get(data);
634 if ((wd->linewrap) || (wd->char_linewrap))
638 if (wd->hoversel) _hoversel_position(data);
639 // Evas_Coord ww, hh;
640 // evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
644 _hover_del(void *data)
646 Widget_Data *wd = elm_widget_data_get(data);
651 evas_object_del(wd->hoversel);
654 wd->hovdeljob = NULL;
658 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
660 Widget_Data *wd = elm_widget_data_get(data);
662 if (wd->hoversel) evas_object_hide(wd->hoversel);
666 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
668 elm_widget_scroll_freeze_pop(data);
669 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
670 wd->hovdeljob = ecore_job_add(_hover_del, data);
674 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
676 Widget_Data *wd = elm_widget_data_get(data);
678 wd->selmode = EINA_TRUE;
679 edje_object_part_text_select_none(wd->ent, "elm.text");
681 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
682 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
683 elm_widget_scroll_hold_push(data);
687 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
689 Widget_Data *wd = elm_widget_data_get(data);
691 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
692 if (wd->sel_notify_handler)
694 #ifdef HAVE_ELEMENTARY_X
695 Elm_Sel_Format formats;
696 wd->selection_asked = EINA_TRUE;
697 formats = ELM_SEL_FORMAT_MARKUP;
699 formats |= ELM_SEL_FORMAT_IMAGE;
700 elm_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL);
706 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
708 Widget_Data *wd = elm_widget_data_get(obj);
712 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
713 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
714 if (seltype == ELM_SEL_CLIPBOARD)
715 eina_stringshare_replace(&wd->cut_sel, sel);
719 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
721 Widget_Data *wd = elm_widget_data_get(data);
724 wd->selmode = EINA_FALSE;
725 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
726 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
727 elm_widget_scroll_hold_pop(data);
728 _store_selection(ELM_SEL_CLIPBOARD, data);
729 edje_object_part_text_insert(wd->ent, "elm.text", "");
730 edje_object_part_text_select_none(wd->ent, "elm.text");
734 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
736 Widget_Data *wd = elm_widget_data_get(data);
738 wd->selmode = EINA_FALSE;
739 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
740 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
741 elm_widget_scroll_hold_pop(data);
742 _store_selection(ELM_SEL_CLIPBOARD, data);
743 // edje_object_part_text_select_none(wd->ent, "elm.text");
747 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
749 Widget_Data *wd = elm_widget_data_get(data);
751 wd->selmode = EINA_FALSE;
752 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
753 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
754 elm_widget_scroll_hold_pop(data);
755 edje_object_part_text_select_none(wd->ent, "elm.text");
759 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
761 Elm_Entry_Context_Menu_Item *it = data;
762 Evas_Object *obj2 = it->obj;
763 if (it->func) it->func(it->data, obj2, NULL);
767 _long_press(void *data)
769 Widget_Data *wd = elm_widget_data_get(data);
772 const Elm_Entry_Context_Menu_Item *it;
773 if (!wd) return ECORE_CALLBACK_CANCEL;
774 if ((wd->api) && (wd->api->obj_longpress))
776 wd->api->obj_longpress(data);
778 else if (wd->context_menu)
780 const char *context_menu_orientation;
782 if (wd->hoversel) evas_object_del(wd->hoversel);
783 else elm_widget_scroll_freeze_push(data);
784 wd->hoversel = elm_hoversel_add(data);
785 context_menu_orientation = edje_object_data_get
786 (wd->ent, "context_menu_orientation");
787 if ((context_menu_orientation) &&
788 (!strcmp(context_menu_orientation, "horizontal")))
789 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
790 elm_object_style_set(wd->hoversel, "entry");
791 elm_widget_sub_object_add(data, wd->hoversel);
792 elm_hoversel_label_set(wd->hoversel, "Text");
793 top = elm_widget_top_get(data);
794 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
795 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, data);
799 elm_hoversel_item_add(wd->hoversel, "Select", NULL, ELM_ICON_NONE,
801 if (1) // need way to detect if someone has a selection
804 elm_hoversel_item_add(wd->hoversel, "Paste", NULL, ELM_ICON_NONE,
812 if (wd->have_selection)
814 elm_hoversel_item_add(wd->hoversel, "Copy", NULL, ELM_ICON_NONE,
817 elm_hoversel_item_add(wd->hoversel, "Cut", NULL, ELM_ICON_NONE,
820 elm_hoversel_item_add(wd->hoversel, "Cancel", NULL, ELM_ICON_NONE,
824 EINA_LIST_FOREACH(wd->items, l, it)
826 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
827 it->icon_type, _item_clicked, it);
831 _hoversel_position(data);
832 evas_object_show(wd->hoversel);
833 elm_hoversel_hover_begin(wd->hoversel);
835 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
836 edje_object_part_text_select_abort(wd->ent, "elm.text");
838 wd->longpress_timer = NULL;
839 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
840 return ECORE_CALLBACK_CANCEL;
844 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
846 Widget_Data *wd = elm_widget_data_get(data);
847 Evas_Event_Mouse_Down *ev = event_info;
849 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
850 if (ev->button != 1) return;
851 // if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
852 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
853 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
854 wd->downx = ev->canvas.x;
855 wd->downy = ev->canvas.y;
859 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
861 Widget_Data *wd = elm_widget_data_get(data);
862 Evas_Event_Mouse_Up *ev = event_info;
864 if (ev->button != 1) return;
865 if (wd->longpress_timer)
867 ecore_timer_del(wd->longpress_timer);
868 wd->longpress_timer = NULL;
873 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
875 Widget_Data *wd = elm_widget_data_get(data);
876 Evas_Event_Mouse_Move *ev = event_info;
880 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
882 if (wd->longpress_timer)
884 ecore_timer_del(wd->longpress_timer);
885 wd->longpress_timer = NULL;
888 else if (wd->longpress_timer)
892 dx = wd->downx - ev->cur.canvas.x;
894 dy = wd->downy - ev->cur.canvas.y;
897 ((_elm_config->finger_size / 2) *
898 (_elm_config->finger_size / 2)))
900 ecore_timer_del(wd->longpress_timer);
901 wd->longpress_timer = NULL;
905 else if (wd->longpress_timer)
909 dx = wd->downx - ev->cur.canvas.x;
911 dy = wd->downy - ev->cur.canvas.y;
914 ((_elm_config->finger_size / 2) *
915 (_elm_config->finger_size / 2)))
917 ecore_timer_del(wd->longpress_timer);
918 wd->longpress_timer = NULL;
924 _getbase(Evas_Object *obj)
926 Widget_Data *wd = elm_widget_data_get(obj);
927 if (!wd) return "base";
930 if (wd->password) return "base-password";
933 if (wd->single_line) return "base-single";
936 if (wd->linewrap) return "base";
937 else if (wd->char_linewrap) return "base-charwrap";
938 else return "base-nowrap";
944 if (wd->password) return "base-password";
947 if (wd->single_line) return "base-single-noedit";
950 if (wd->linewrap) return "base-noedit";
951 else if (wd->char_linewrap) return "base-noedit-charwrap";
952 else return "base-nowrap-noedit";
960 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
962 Widget_Data *wd = elm_widget_data_get(data);
964 wd->changed = EINA_TRUE;
966 if (wd->text) eina_stringshare_del(wd->text);
968 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
971 ecore_timer_del(wd->delay_write);
972 wd->delay_write = NULL;
974 if ((!wd->autosave) || (!wd->file)) return;
975 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
979 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
981 Widget_Data *wd = elm_widget_data_get(data);
985 EINA_LIST_FOREACH(entries, l, entry)
987 if (entry != data) elm_entry_select_none(entry);
989 wd->have_selection = EINA_TRUE;
990 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
991 #ifdef HAVE_ELEMENTARY_X
992 if (wd->sel_notify_handler)
994 const char *txt = elm_entry_selection_get(data);
997 top = elm_widget_top_get(data);
998 if ((top) && (elm_win_xwindow_get(top)))
999 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1005 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1007 Widget_Data *wd = elm_widget_data_get(data);
1009 wd->have_selection = EINA_TRUE;
1010 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1011 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1012 elm_entry_selection_get(data));
1016 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1018 Widget_Data *wd = elm_widget_data_get(data);
1020 if (!wd->have_selection) return;
1021 wd->have_selection = EINA_FALSE;
1022 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1023 if (wd->sel_notify_handler)
1027 #ifdef HAVE_ELEMENTARY_X
1030 top = elm_widget_top_get(data);
1031 if ((top) && (elm_win_xwindow_get(top)))
1032 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1035 eina_stringshare_del(wd->cut_sel);
1040 #ifdef HAVE_ELEMENTARY_X
1043 top = elm_widget_top_get(data);
1044 if ((top) && (elm_win_xwindow_get(top)))
1045 elm_selection_clear(ELM_SEL_PRIMARY, data);
1052 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1054 Widget_Data *wd = elm_widget_data_get(data);
1056 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1057 if (wd->sel_notify_handler)
1059 #ifdef HAVE_ELEMENTARY_X
1062 top = elm_widget_top_get(data);
1063 if ((top) && (elm_win_xwindow_get(top)))
1065 wd->selection_asked = EINA_TRUE;
1066 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
1074 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1076 Widget_Data *wd = elm_widget_data_get(data);
1078 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1079 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1080 elm_entry_selection_get(data));
1084 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1086 Widget_Data *wd = elm_widget_data_get(data);
1088 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1089 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1090 elm_entry_selection_get(data));
1091 edje_object_part_text_insert(wd->ent, "elm.text", "");
1092 wd->changed = EINA_TRUE;
1097 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1099 Widget_Data *wd = elm_widget_data_get(data);
1100 Evas_Coord cx, cy, cw, ch;
1102 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1103 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1104 &cx, &cy, &cw, &ch);
1105 if (!wd->deferred_recalc_job)
1106 elm_widget_show_region_set(data, cx, cy, cw, ch);
1109 wd->deferred_cur = EINA_TRUE;
1118 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1120 Widget_Data *wd = elm_widget_data_get(data);
1125 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1127 Widget_Data *wd = elm_widget_data_get(data);
1128 Elm_Entry_Anchor_Info ei;
1129 char *buf2, *p, *p2, *n;
1131 p = strrchr(emission, ',');
1134 const Eina_List *geoms;
1138 while (p2 >= emission)
1140 if (*p2 == ',') break;
1144 buf2 = alloca(5 + p - p2);
1145 strncpy(buf2, p2, p - p2);
1148 ei.button = atoi(buf2);
1149 ei.x = ei.y = ei.w = ei.h = 0;
1151 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1154 Evas_Textblock_Rectangle *r;
1156 Evas_Coord px, py, x, y;
1158 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1159 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1160 EINA_LIST_FOREACH(geoms, l, r)
1162 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1163 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1174 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1179 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1181 Widget_Data *wd = elm_widget_data_get(data);
1186 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1188 Widget_Data *wd = elm_widget_data_get(data);
1193 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1195 Widget_Data *wd = elm_widget_data_get(data);
1200 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1202 Widget_Data *wd = elm_widget_data_get(data);
1204 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1208 _signal_mouse_down(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_PRESS, NULL);
1216 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1218 Widget_Data *wd = elm_widget_data_get(data);
1220 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1224 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1226 Widget_Data *wd = elm_widget_data_get(data);
1228 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1231 #ifdef HAVE_ELEMENTARY_X
1233 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1235 Widget_Data *wd = elm_widget_data_get(data);
1236 Ecore_X_Event_Selection_Notify *ev = event;
1237 if (!wd) return ECORE_CALLBACK_PASS_ON;
1238 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1239 return ECORE_CALLBACK_PASS_ON;
1241 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1242 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1244 Ecore_X_Selection_Data_Text *text_data;
1246 text_data = ev->data;
1247 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1249 if (text_data->text)
1251 char *txt = _elm_util_text_to_mkup(text_data->text);
1255 elm_entry_entry_insert(data, txt);
1260 wd->selection_asked = EINA_FALSE;
1262 else if (ev->selection == ECORE_X_SELECTION_XDND)
1264 Ecore_X_Selection_Data_Text *text_data;
1266 text_data = ev->data;
1267 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1269 if (text_data->text)
1271 char *txt = _elm_util_text_to_mkup(text_data->text);
1275 /* Massive FIXME: this should be at the drag point */
1276 elm_entry_entry_insert(data, txt);
1281 wd->drag_selection_asked = EINA_FALSE;
1283 ecore_x_dnd_send_finished();
1286 return ECORE_CALLBACK_PASS_ON;
1290 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1293 Widget_Data *wd = elm_widget_data_get(data);
1294 Ecore_X_Event_Selection_Clear *ev = event;
1295 if (!wd) return ECORE_CALLBACK_PASS_ON;
1296 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1297 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1298 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1300 elm_entry_select_none(data);
1303 return ECORE_CALLBACK_PASS_ON;
1308 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1313 wd = elm_widget_data_get(obj);
1315 if (!wd) return EINA_FALSE;
1316 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1318 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1319 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1320 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1321 EDJE_CURSOR_MAIN,drop->x,drop->y);
1322 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1323 elm_entry_entry_insert(obj, drop->data);
1324 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1325 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1331 static Evas_Object *
1332 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1334 Widget_Data *wd = elm_widget_data_get(data);
1337 Elm_Entry_Item_Provider *ip;
1339 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1341 o = ip->func(ip->data, data, item);
1344 if (!strncmp(item, "file://", 7))
1346 const char *fname = item + 7;
1348 o = evas_object_image_filled_add(evas_object_evas_get(data));
1349 evas_object_image_file_set(o, fname, NULL);
1350 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1352 evas_object_show(o);
1357 o = edje_object_add(evas_object_evas_get(data));
1358 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1362 o = edje_object_add(evas_object_evas_get(data));
1363 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1364 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1369 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
1371 Widget_Data *wd = elm_widget_data_get(data);
1373 Elm_Entry_Text_Filter *tf;
1375 if (type == EDJE_TEXT_FILTER_FORMAT)
1378 EINA_LIST_FOREACH(wd->text_filters, l, tf)
1380 tf->func(tf->data, data, text);
1387 * This adds an entry to @p parent object.
1389 * @param parent The parent object
1390 * @return The new object or NULL if it cannot be created
1395 elm_entry_add(Evas_Object *parent)
1397 Evas_Object *obj, *top;
1401 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
1403 wd = ELM_NEW(Widget_Data);
1404 e = evas_object_evas_get(parent);
1405 if (!e) return NULL;
1406 obj = elm_widget_add(e);
1407 ELM_SET_WIDTYPE(widtype, "entry");
1408 elm_widget_type_set(obj, "entry");
1409 elm_widget_sub_object_add(parent, obj);
1410 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1411 elm_widget_data_set(obj, wd);
1412 elm_widget_del_hook_set(obj, _del_hook);
1413 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1414 elm_widget_theme_hook_set(obj, _theme_hook);
1415 elm_widget_disable_hook_set(obj, _disable_hook);
1416 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1417 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
1418 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1419 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1420 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
1421 elm_widget_can_focus_set(obj, EINA_TRUE);
1422 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
1424 wd->linewrap = EINA_TRUE;
1425 wd->char_linewrap= EINA_FALSE;
1426 wd->editable = EINA_TRUE;
1427 wd->disabled = EINA_FALSE;
1428 wd->context_menu = EINA_TRUE;
1429 wd->autosave = EINA_TRUE;
1430 wd->textonly = EINA_FALSE;
1432 wd->ent = edje_object_add(e);
1433 edje_object_item_provider_set(wd->ent, _get_item, obj);
1434 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
1435 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1436 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1437 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1439 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1441 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1444 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1445 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1446 _signal_entry_changed, obj);
1447 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1448 _signal_selection_start, obj);
1449 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1450 _signal_selection_changed, obj);
1451 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1452 _signal_selection_cleared, obj);
1453 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1454 _signal_entry_paste_request, obj);
1455 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1456 _signal_entry_copy_notify, obj);
1457 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1458 _signal_entry_cut_notify, obj);
1459 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1460 _signal_cursor_changed, obj);
1461 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1462 _signal_anchor_down, obj);
1463 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1464 _signal_anchor_up, obj);
1465 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1466 _signal_anchor_move, obj);
1467 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1468 _signal_anchor_in, obj);
1469 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1470 _signal_anchor_out, obj);
1471 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
1472 _signal_key_enter, obj);
1473 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
1474 _signal_mouse_down, obj);
1475 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
1476 _signal_mouse_clicked, obj);
1477 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
1478 _signal_mouse_double, obj);
1479 edje_object_part_text_set(wd->ent, "elm.text", "");
1480 elm_widget_resize_object_set(obj, wd->ent);
1483 #ifdef HAVE_ELEMENTARY_X
1484 top = elm_widget_top_get(obj);
1485 if ((top) && (elm_win_xwindow_get(top)))
1487 wd->sel_notify_handler =
1488 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
1489 _event_selection_notify, obj);
1490 wd->sel_clear_handler =
1491 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
1492 _event_selection_clear, obj);
1495 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
1496 _drag_drop_cb, NULL);
1499 entries = eina_list_prepend(entries, obj);
1501 // module - find module for entry
1502 wd->api = _module(obj);
1503 // if found - hook in
1504 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
1506 _mirrored_set(obj, elm_widget_mirrored_get(obj));
1507 // TODO: convert Elementary to subclassing of Evas_Smart_Class
1508 // TODO: and save some bytes, making descriptions per-class and not instance!
1509 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1515 * This sets the entry object not to line wrap. All input will
1516 * be on a single line, and the entry box will extend with user input.
1518 * @param obj The entry object
1519 * @param single_line If true, the text in the entry
1520 * will be on a single line.
1525 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
1527 ELM_CHECK_WIDTYPE(obj, widtype);
1528 Widget_Data *wd = elm_widget_data_get(obj);
1531 if (wd->single_line == single_line) return;
1532 wd->single_line = single_line;
1533 wd->linewrap = EINA_FALSE;
1534 wd->char_linewrap = EINA_FALSE;
1535 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
1536 t = eina_stringshare_add(elm_entry_entry_get(obj));
1537 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1538 elm_entry_entry_set(obj, t);
1539 eina_stringshare_del(t);
1544 * This returns true if the entry has been set to single line mode.
1545 * See also elm_entry_single_line_set().
1547 * @param obj The entry object
1548 * @return single_line If true, the text in the entry is set to display
1554 elm_entry_single_line_get(const Evas_Object *obj)
1556 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1557 Widget_Data *wd = elm_widget_data_get(obj);
1558 if (!wd) return EINA_FALSE;
1559 return wd->single_line;
1563 * This sets the entry object to password mode. All text entered
1564 * and/or displayed within the widget will be replaced with asterisks (*).
1566 * @param obj The entry object
1567 * @param password If true, password mode is enabled.
1572 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
1574 ELM_CHECK_WIDTYPE(obj, widtype);
1575 Widget_Data *wd = elm_widget_data_get(obj);
1578 if (wd->password == password) return;
1579 wd->password = password;
1580 wd->single_line = EINA_TRUE;
1581 wd->linewrap = EINA_FALSE;
1582 wd->char_linewrap = EINA_FALSE;
1583 t = eina_stringshare_add(elm_entry_entry_get(obj));
1584 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1585 elm_entry_entry_set(obj, t);
1586 eina_stringshare_del(t);
1592 * This returns whether password mode is enabled.
1593 * See also elm_entry_password_set().
1595 * @param obj The entry object
1596 * @return If true, the entry is set to display all characters
1602 elm_entry_password_get(const Evas_Object *obj)
1604 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1605 Widget_Data *wd = elm_widget_data_get(obj);
1606 if (!wd) return EINA_FALSE;
1607 return wd->password;
1611 * This sets the text displayed within the entry to @p entry.
1613 * @param obj The entry object
1614 * @param entry The text to be displayed
1619 elm_entry_entry_set(Evas_Object *obj, const char *entry)
1621 ELM_CHECK_WIDTYPE(obj, widtype);
1622 Widget_Data *wd = elm_widget_data_get(obj);
1624 if (!entry) entry = "";
1625 edje_object_part_text_set(wd->ent, "elm.text", entry);
1626 if (wd->text) eina_stringshare_del(wd->text);
1628 wd->changed = EINA_TRUE;
1633 * This returns the text currently shown in object @p entry.
1634 * See also elm_entry_entry_set().
1636 * @param obj The entry object
1637 * @return The currently displayed text or NULL on failure
1642 elm_entry_entry_get(const Evas_Object *obj)
1644 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1645 Widget_Data *wd = elm_widget_data_get(obj);
1647 if (!wd) return NULL;
1648 if (wd->text) return wd->text;
1649 text = edje_object_part_text_get(wd->ent, "elm.text");
1652 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
1655 eina_stringshare_replace(&wd->text, text);
1661 * This returns EINA_TRUE if the entry is empty/there was an error
1662 * and EINA_FALSE if it is not empty.
1664 * @param obj The entry object
1665 * @return If the entry is empty or not.
1670 elm_entry_is_empty(const Evas_Object *obj)
1672 /* FIXME: until there's support for that in textblock, we just check
1673 * to see if the there is text or not. */
1674 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
1675 Widget_Data *wd = elm_widget_data_get(obj);
1676 const Evas_Object *tb;
1677 Evas_Textblock_Cursor *cur;
1679 if (!wd) return EINA_TRUE;
1680 /* It's a hack until we get the support suggested above.
1681 * We just create a cursor, point it to the begining, and then
1682 * try to advance it, if it can advance, the tb is not empty,
1683 * otherwise it is. */
1684 tb = edje_object_part_object_get(wd->ent, "elm.text");
1685 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
1686 actually, ok for the time being, thsese hackish stuff will be removed
1687 once evas 1.0 is out*/
1688 evas_textblock_cursor_pos_set(cur, 0);
1689 ret = evas_textblock_cursor_char_next(cur);
1690 evas_textblock_cursor_free(cur);
1696 * This returns all selected text within the entry.
1698 * @param obj The entry object
1699 * @return The selected text within the entry or NULL on failure
1704 elm_entry_selection_get(const Evas_Object *obj)
1706 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1707 Widget_Data *wd = elm_widget_data_get(obj);
1708 if (!wd) return NULL;
1709 return edje_object_part_text_selection_get(wd->ent, "elm.text");
1713 * This inserts text in @p entry where the current cursor position.
1715 * This inserts text at the cursor position is as if it was typed
1716 * by the user (note this also allows markup which a user
1717 * can't just "type" as it would be converted to escaped text, so this
1718 * call can be used to insert things like emoticon items or bold push/pop
1719 * tags, other font and color change tags etc.)
1721 * @param obj The entry object
1722 * @param entry The text to insert
1727 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
1729 ELM_CHECK_WIDTYPE(obj, widtype);
1730 Widget_Data *wd = elm_widget_data_get(obj);
1732 edje_object_part_text_insert(wd->ent, "elm.text", entry);
1733 wd->changed = EINA_TRUE;
1738 * This enables word line wrapping in the entry object. It is the opposite
1739 * of elm_entry_single_line_set(). Additionally, setting this disables
1740 * character line wrapping.
1741 * See also elm_entry_line_char_wrap_set().
1743 * @param obj The entry object
1744 * @param wrap If true, the entry will be wrapped once it reaches the end
1745 * of the object. Wrapping will occur at the end of the word before the end of the
1751 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
1753 ELM_CHECK_WIDTYPE(obj, widtype);
1754 Widget_Data *wd = elm_widget_data_get(obj);
1757 if (wd->linewrap == wrap) return;
1758 wd->linewrap = wrap;
1760 wd->char_linewrap = EINA_FALSE;
1761 t = eina_stringshare_add(elm_entry_entry_get(obj));
1762 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1763 elm_entry_entry_set(obj, t);
1764 eina_stringshare_del(t);
1769 * This enables character line wrapping in the entry object. It is the opposite
1770 * of elm_entry_single_line_set(). Additionally, setting this disables
1771 * word line wrapping.
1772 * See also elm_entry_line_wrap_set().
1774 * @param obj The entry object
1775 * @param wrap If true, the entry will be wrapped once it reaches the end
1776 * of the object. Wrapping will occur immediately upon reaching the end of the object.
1781 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
1783 ELM_CHECK_WIDTYPE(obj, widtype);
1784 Widget_Data *wd = elm_widget_data_get(obj);
1787 if (wd->char_linewrap == wrap) return;
1788 wd->char_linewrap = wrap;
1789 if(wd->char_linewrap)
1790 wd->linewrap = EINA_FALSE;
1791 t = eina_stringshare_add(elm_entry_entry_get(obj));
1792 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1793 elm_entry_entry_set(obj, t);
1794 eina_stringshare_del(t);
1799 * This sets the editable attribute of the entry.
1801 * @param obj The entry object
1802 * @param editable If true, the entry will be editable by the user.
1803 * If false, it will be set to the disabled state.
1808 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
1810 ELM_CHECK_WIDTYPE(obj, widtype);
1811 Widget_Data *wd = elm_widget_data_get(obj);
1814 if (wd->editable == editable) return;
1815 wd->editable = editable;
1816 t = eina_stringshare_add(elm_entry_entry_get(obj));
1817 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1818 elm_entry_entry_set(obj, t);
1819 eina_stringshare_del(t);
1822 #ifdef HAVE_ELEMENTARY_X
1824 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
1826 elm_drop_target_del(obj);
1831 * This gets the editable attribute of the entry.
1832 * See also elm_entry_editable_set().
1834 * @param obj The entry object
1835 * @return If true, the entry is editable by the user.
1836 * If false, it is not editable by the user
1841 elm_entry_editable_get(const Evas_Object *obj)
1843 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1844 Widget_Data *wd = elm_widget_data_get(obj);
1845 if (!wd) return EINA_FALSE;
1846 return wd->editable;
1850 * This drops any existing text selection within the entry.
1852 * @param obj The entry object
1857 elm_entry_select_none(Evas_Object *obj)
1859 ELM_CHECK_WIDTYPE(obj, widtype);
1860 Widget_Data *wd = elm_widget_data_get(obj);
1864 wd->selmode = EINA_FALSE;
1865 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
1866 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1868 wd->have_selection = EINA_FALSE;
1869 edje_object_part_text_select_none(wd->ent, "elm.text");
1873 * This selects all text within the entry.
1875 * @param obj The entry object
1880 elm_entry_select_all(Evas_Object *obj)
1882 ELM_CHECK_WIDTYPE(obj, widtype);
1883 Widget_Data *wd = elm_widget_data_get(obj);
1887 wd->selmode = EINA_FALSE;
1888 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
1889 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1891 wd->have_selection = EINA_TRUE;
1892 edje_object_part_text_select_all(wd->ent, "elm.text");
1896 * This function returns the geometry of the cursor.
1898 * It's useful if you want to draw something on the cursor (or where it is),
1899 * or for example in the case of scrolled entry where you want to show the
1902 * @param obj The entry object
1903 * @param x returned geometry
1904 * @param y returned geometry
1905 * @param w returned geometry
1906 * @param h returned geometry
1907 * @return EINA_TRUE upon success, EINA_FALSE upon failure
1912 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1914 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1915 Widget_Data *wd = elm_widget_data_get(obj);
1916 if (!wd) return EINA_FALSE;
1917 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
1922 * This moves the cursor one place to the right within the entry.
1924 * @param obj The entry object
1925 * @return EINA_TRUE upon success, EINA_FALSE upon failure
1930 elm_entry_cursor_next(Evas_Object *obj)
1932 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1933 Widget_Data *wd = elm_widget_data_get(obj);
1934 if (!wd) return EINA_FALSE;
1935 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1939 * This moves the cursor one place to the left within the entry.
1941 * @param obj The entry object
1942 * @return EINA_TRUE upon success, EINA_FALSE upon failure
1947 elm_entry_cursor_prev(Evas_Object *obj)
1949 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1950 Widget_Data *wd = elm_widget_data_get(obj);
1951 if (!wd) return EINA_FALSE;
1952 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1956 * This moves the cursor one line up within the entry.
1958 * @param obj The entry object
1959 * @return EINA_TRUE upon success, EINA_FALSE upon failure
1964 elm_entry_cursor_up(Evas_Object *obj)
1966 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1967 Widget_Data *wd = elm_widget_data_get(obj);
1968 if (!wd) return EINA_FALSE;
1969 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1973 * This moves the cursor one line down within the entry.
1975 * @param obj The entry object
1976 * @return EINA_TRUE upon success, EINA_FALSE upon failure
1981 elm_entry_cursor_down(Evas_Object *obj)
1983 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1984 Widget_Data *wd = elm_widget_data_get(obj);
1985 if (!wd) return EINA_FALSE;
1986 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1990 * This moves the cursor to the beginning of the entry.
1992 * @param obj The entry object
1997 elm_entry_cursor_begin_set(Evas_Object *obj)
1999 ELM_CHECK_WIDTYPE(obj, widtype);
2000 Widget_Data *wd = elm_widget_data_get(obj);
2002 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2006 * This moves the cursor to the end of the entry.
2008 * @param obj The entry object
2013 elm_entry_cursor_end_set(Evas_Object *obj)
2015 ELM_CHECK_WIDTYPE(obj, widtype);
2016 Widget_Data *wd = elm_widget_data_get(obj);
2018 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2022 * This moves the cursor to the beginning of the current line.
2024 * @param obj The entry object
2029 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2031 ELM_CHECK_WIDTYPE(obj, widtype);
2032 Widget_Data *wd = elm_widget_data_get(obj);
2034 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2038 * This moves the cursor to the end of the current line.
2040 * @param obj The entry object
2045 elm_entry_cursor_line_end_set(Evas_Object *obj)
2047 ELM_CHECK_WIDTYPE(obj, widtype);
2048 Widget_Data *wd = elm_widget_data_get(obj);
2050 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2054 * This begins a selection within the entry as though
2055 * the user were holding down the mouse button to make a selection.
2057 * @param obj The entry object
2062 elm_entry_cursor_selection_begin(Evas_Object *obj)
2064 ELM_CHECK_WIDTYPE(obj, widtype);
2065 Widget_Data *wd = elm_widget_data_get(obj);
2067 edje_object_part_text_select_begin(wd->ent, "elm.text");
2071 * This ends a selection within the entry as though
2072 * the user had just released the mouse button while making a selection.
2074 * @param obj The entry object
2079 elm_entry_cursor_selection_end(Evas_Object *obj)
2081 ELM_CHECK_WIDTYPE(obj, widtype);
2082 Widget_Data *wd = elm_widget_data_get(obj);
2084 edje_object_part_text_select_extend(wd->ent, "elm.text");
2088 * TODO: fill this in
2090 * @param obj The entry object
2091 * @return TODO: fill this in
2096 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2098 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2099 Widget_Data *wd = elm_widget_data_get(obj);
2100 if (!wd) return EINA_FALSE;
2101 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2105 * This returns whether the cursor is visible.
2107 * @param obj The entry object
2108 * @return If true, the cursor is visible.
2113 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2115 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2116 Widget_Data *wd = elm_widget_data_get(obj);
2117 if (!wd) return EINA_FALSE;
2118 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2122 * TODO: fill this in
2124 * @param obj The entry object
2125 * @return TODO: fill this in
2130 elm_entry_cursor_content_get(const Evas_Object *obj)
2132 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2133 Widget_Data *wd = elm_widget_data_get(obj);
2134 if (!wd) return NULL;
2135 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2139 * This executes a "cut" action on the selected text in the entry.
2141 * @param obj The entry object
2146 elm_entry_selection_cut(Evas_Object *obj)
2148 ELM_CHECK_WIDTYPE(obj, widtype);
2149 Widget_Data *wd = elm_widget_data_get(obj);
2151 _cut(obj, NULL, NULL);
2155 * This executes a "copy" action on the selected text in the entry.
2157 * @param obj The entry object
2162 elm_entry_selection_copy(Evas_Object *obj)
2164 ELM_CHECK_WIDTYPE(obj, widtype);
2165 Widget_Data *wd = elm_widget_data_get(obj);
2167 _copy(obj, NULL, NULL);
2171 * This executes a "paste" action in the entry.
2173 * @param obj The entry object
2178 elm_entry_selection_paste(Evas_Object *obj)
2180 ELM_CHECK_WIDTYPE(obj, widtype);
2181 Widget_Data *wd = elm_widget_data_get(obj);
2183 _paste(obj, NULL, NULL);
2187 * This clears and frees the items in a entry's contextual (right click) menu.
2189 * @param obj The entry object
2194 elm_entry_context_menu_clear(Evas_Object *obj)
2196 ELM_CHECK_WIDTYPE(obj, widtype);
2197 Widget_Data *wd = elm_widget_data_get(obj);
2198 Elm_Entry_Context_Menu_Item *it;
2200 EINA_LIST_FREE(wd->items, it)
2202 eina_stringshare_del(it->label);
2203 eina_stringshare_del(it->icon_file);
2204 eina_stringshare_del(it->icon_group);
2210 * This adds an item to the entry's contextual menu.
2212 * @param obj The entry object
2213 * @param label The item's text label
2214 * @param icon_file The item's icon file
2215 * @param icon_type The item's icon type
2216 * @param func The callback to execute when the item is clicked
2217 * @param data The data to associate with the item for related functions
2222 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)
2224 ELM_CHECK_WIDTYPE(obj, widtype);
2225 Widget_Data *wd = elm_widget_data_get(obj);
2226 Elm_Entry_Context_Menu_Item *it;
2228 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2230 wd->items = eina_list_append(wd->items, it);
2232 it->label = eina_stringshare_add(label);
2233 it->icon_file = eina_stringshare_add(icon_file);
2234 it->icon_type = icon_type;
2236 it->data = (void *)data;
2240 * This disables the entry's contextual (right click) menu.
2242 * @param obj The entry object
2243 * @param disabled If true, the menu is disabled
2248 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2250 ELM_CHECK_WIDTYPE(obj, widtype);
2251 Widget_Data *wd = elm_widget_data_get(obj);
2253 if (wd->context_menu == !disabled) return;
2254 wd->context_menu = !disabled;
2258 * This returns whether the entry's contextual (right click) menu is disabled.
2260 * @param obj The entry object
2261 * @return If true, the menu is disabled
2266 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2268 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2269 Widget_Data *wd = elm_widget_data_get(obj);
2270 if (!wd) return EINA_FALSE;
2271 return !wd->context_menu;
2275 * This appends a custom item provider to the list for that entry
2277 * This appends the given callback. The list is walked from beginning to end
2278 * with each function called given the item href string in the text. If the
2279 * function returns an object handle other than NULL (it should create an
2280 * and object to do this), then this object is used to replace that item. If
2281 * not the next provider is called until one provides an item object, or the
2282 * default provider in entry does.
2284 * @param obj The entry object
2285 * @param func The function called to provide the item object
2286 * @param data The data passed to @p func
2291 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2293 ELM_CHECK_WIDTYPE(obj, widtype);
2294 Widget_Data *wd = elm_widget_data_get(obj);
2296 EINA_SAFETY_ON_NULL_RETURN(func);
2297 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2301 wd->item_providers = eina_list_append(wd->item_providers, ip);
2305 * This prepends a custom item provider to the list for that entry
2307 * This prepends the given callback. See elm_entry_item_provider_append() for
2310 * @param obj The entry object
2311 * @param func The function called to provide the item object
2312 * @param data The data passed to @p func
2317 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2319 ELM_CHECK_WIDTYPE(obj, widtype);
2320 Widget_Data *wd = elm_widget_data_get(obj);
2322 EINA_SAFETY_ON_NULL_RETURN(func);
2323 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2327 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2331 * This removes a custom item provider to the list for that entry
2333 * This removes the given callback. See elm_entry_item_provider_append() for
2336 * @param obj The entry object
2337 * @param func The function called to provide the item object
2338 * @param data The data passed to @p func
2343 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2345 ELM_CHECK_WIDTYPE(obj, widtype);
2346 Widget_Data *wd = elm_widget_data_get(obj);
2348 Elm_Entry_Item_Provider *ip;
2350 EINA_SAFETY_ON_NULL_RETURN(func);
2351 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2353 if ((ip->func == func) && (ip->data == data))
2355 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2363 * Append a filter function for text inserted in the entry
2365 * Append the given callback to the list. This functions will be called
2366 * whenever any text is inserted into the entry, with the text to be inserted
2367 * as a parameter. The callback function is free to alter the text in any way
2368 * it wants, but it must remember to free the given pointer and update it.
2369 * If the new text is to be discarded, the function can free it and set it text
2370 * parameter to NULL. This will also prevent any following filters from being
2373 * @param obj The entry object
2374 * @param func The function to use as text filter
2375 * @param data User data to pass to @p func
2380 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2383 Elm_Entry_Text_Filter *tf;
2384 ELM_CHECK_WIDTYPE(obj, widtype);
2386 wd = elm_widget_data_get(obj);
2388 EINA_SAFETY_ON_NULL_RETURN(func);
2390 tf = ELM_NEW(Elm_Entry_Text_Filter);
2394 wd->text_filters = eina_list_append(wd->text_filters, tf);
2398 * Prepend a filter function for text insdrted in the entry
2400 * Prepend the given callback to the list. See elm_entry_text_filter_append()
2401 * for more information
2403 * @param obj The entry object
2404 * @param func The function to use as text filter
2405 * @param data User data to pass to @p func
2410 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2413 Elm_Entry_Text_Filter *tf;
2414 ELM_CHECK_WIDTYPE(obj, widtype);
2416 wd = elm_widget_data_get(obj);
2418 EINA_SAFETY_ON_NULL_RETURN(func);
2420 tf = ELM_NEW(Elm_Entry_Text_Filter);
2424 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
2428 * Remove a filter from the list
2430 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
2431 * for more information.
2433 * @param obj The entry object
2434 * @param func The filter function to remove
2435 * @param data The user data passed when adding the function
2440 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2444 Elm_Entry_Text_Filter *tf;
2445 ELM_CHECK_WIDTYPE(obj, widtype);
2447 wd = elm_widget_data_get(obj);
2449 EINA_SAFETY_ON_NULL_RETURN(func);
2451 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2453 if ((tf->func == func) && (tf->data == data))
2455 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
2463 * This converts a markup (HTML-like) string into UTF-8.
2465 * @param s The string (in markup) to be converted
2466 * @return The converted string (in UTF-8)
2471 elm_entry_markup_to_utf8(const char *s)
2473 char *ss = _elm_util_mkup_to_text(s);
2474 if (!ss) ss = strdup("");
2479 * This converts a UTF-8 string into markup (HTML-like).
2481 * @param s The string (in UTF-8) to be converted
2482 * @return The converted string (in markup)
2487 elm_entry_utf8_to_markup(const char *s)
2489 char *ss = _elm_util_text_to_mkup(s);
2490 if (!ss) ss = strdup("");
2495 * Filter inserted text based on user defined character and byte limits
2497 * Add this filter to an entry to limit the characters that it will accept
2498 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
2499 * The funtion works on the UTF-8 representation of the string, converting
2500 * it from the set markup, thus not accounting for any format in it.
2502 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
2503 * it as data when setting the filter. In it it's possible to set limits
2504 * by character count or bytes (any of them is disabled if 0), and both can
2505 * be set at the same time. In that case, it first checks for characters,
2508 * The function will cut the inserted text in order to allow only the first
2509 * number of characters that are still allowed. The cut is made in
2510 * characters, even when limiting by bytes, in order to always contain
2511 * valid ones and avoid half unicode characters making it in.
2516 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
2518 Elm_Entry_Filter_Limit_Size *lim = data;
2521 const char *(*text_get)(const Evas_Object *);
2522 const char *widget_type;
2524 EINA_SAFETY_ON_NULL_RETURN(data);
2525 EINA_SAFETY_ON_NULL_RETURN(entry);
2526 EINA_SAFETY_ON_NULL_RETURN(text);
2528 /* hack. I don't want to copy the entire function to work with
2530 widget_type = elm_widget_type_get(entry);
2531 if (!strcmp(widget_type, "entry"))
2532 text_get = elm_entry_entry_get;
2533 else if (!strcmp(widget_type, "scrolled_entry"))
2534 text_get = elm_scrolled_entry_entry_get;
2538 current = elm_entry_markup_to_utf8(text_get(entry));
2540 if (lim->max_char_count > 0)
2543 len = evas_string_char_len_get(current);
2544 if (len >= lim->max_char_count)
2551 newlen = evas_string_char_len_get(*text);
2552 cut = strlen(*text);
2553 while ((len + newlen) > lim->max_char_count)
2555 cut = evas_string_char_prev_get(*text, cut, NULL);
2561 if (lim->max_byte_count > 0)
2563 len = strlen(current);
2564 if (len >= lim->max_byte_count)
2571 newlen = strlen(*text);
2572 while ((len + newlen) > lim->max_byte_count)
2574 int p = evas_string_char_prev_get(*text, newlen, NULL);
2575 newlen -= (newlen - p);
2578 (*text)[newlen] = 0;
2589 * Filter inserted text based on accepted or rejected sets of characters
2591 * Add this filter to an entry to restrict the set of accepted characters
2592 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
2593 * This structure contains both accepted and rejected sets, but they are
2594 * mutually exclusive. If accepted is set, it will be used, otherwise it
2595 * goes on to the rejected set.
2598 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
2600 Elm_Entry_Filter_Accept_Set *as = data;
2604 int read_idx, last_read_idx = 0, read_char;
2606 EINA_SAFETY_ON_NULL_RETURN(data);
2607 EINA_SAFETY_ON_NULL_RETURN(text);
2609 if ((!as->accepted) && (!as->rejected))
2615 goes_in = EINA_TRUE;
2620 goes_in = EINA_FALSE;
2624 read_idx = evas_string_char_next_get(*text, 0, &read_char);
2627 int cmp_idx, cmp_char;
2628 Eina_Bool in_set = EINA_FALSE;
2630 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
2633 if (read_char == cmp_char)
2638 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
2640 if (in_set == goes_in)
2642 int size = read_idx - last_read_idx;
2643 const char *src = (*text) + last_read_idx;
2645 memcpy(insert, *text + last_read_idx, size);
2648 last_read_idx = read_idx;
2649 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
2655 * This sets the file (and implicitly loads it) for the text to display and
2656 * then edit. All changes are written back to the file after a short delay if
2657 * the entry object is set to autosave.
2659 * @param obj The entry object
2660 * @param file The path to the file to load and save
2661 * @param format The file format
2666 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
2668 ELM_CHECK_WIDTYPE(obj, widtype);
2669 Widget_Data *wd = elm_widget_data_get(obj);
2671 if (wd->delay_write)
2673 ecore_timer_del(wd->delay_write);
2674 wd->delay_write = NULL;
2676 if (wd->autosave) _save(obj);
2677 eina_stringshare_replace(&wd->file, file);
2678 wd->format = format;
2683 * Gets the file to load and save and the file format
2685 * @param obj The entry object
2686 * @param file The path to the file to load and save
2687 * @param format The file format
2692 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
2694 ELM_CHECK_WIDTYPE(obj, widtype);
2695 Widget_Data *wd = elm_widget_data_get(obj);
2697 if (file) *file = wd->file;
2698 if (format) *format = wd->format;
2702 * This function writes any changes made to the file set with
2703 * elm_entry_file_set()
2705 * @param obj The entry object
2710 elm_entry_file_save(Evas_Object *obj)
2712 ELM_CHECK_WIDTYPE(obj, widtype);
2713 Widget_Data *wd = elm_widget_data_get(obj);
2715 if (wd->delay_write)
2717 ecore_timer_del(wd->delay_write);
2718 wd->delay_write = NULL;
2721 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
2725 * This sets the entry object to 'autosave' the loaded text file or not.
2727 * @param obj The entry object
2728 * @param autosave Autosave the loaded file or not
2733 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
2735 ELM_CHECK_WIDTYPE(obj, widtype);
2736 Widget_Data *wd = elm_widget_data_get(obj);
2738 wd->autosave = !!autosave;
2742 * This gets the entry object's 'autosave' status.
2744 * @param obj The entry object
2745 * @return Autosave the loaded file or not
2750 elm_entry_autosave_get(const Evas_Object *obj)
2752 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2753 Widget_Data *wd = elm_widget_data_get(obj);
2754 if (!wd) return EINA_FALSE;
2755 return wd->autosave;
2760 * Control pasting of text and images for the widget.
2762 * Normally the entry allows both text and images to be pasted. By setting
2763 * textonly to be true, this prevents images from being pasted.
2765 * Note this only changes the behaviour of text.
2767 * @param obj The entry object
2768 * @param pmode paste mode - 0 is text only, 1 is text+image+other.
2773 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
2775 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
2776 ELM_CHECK_WIDTYPE(obj, widtype);
2777 Widget_Data *wd = elm_widget_data_get(obj);
2779 textonly = !!textonly;
2780 if (wd->textonly == textonly) return;
2781 wd->textonly = !!textonly;
2782 if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
2783 #ifdef HAVE_ELEMENTARY_X
2784 elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
2789 * Getting elm_entry text paste/drop mode.
2791 * In textonly mode, only text may be pasted or dropped into the widget.
2793 * @param obj The entry object
2794 * @return If the widget only accepts text from pastes.
2799 elm_entry_cnp_textonly_get(Evas_Object *obj)
2801 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2802 Widget_Data *wd = elm_widget_data_get(obj);
2803 if (!wd) return EINA_FALSE;
2804 return wd->textonly;