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 _mirrored_set(obj, elm_widget_mirrored_get(obj));
465 t = eina_stringshare_add(elm_entry_entry_get(obj));
466 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
467 elm_entry_entry_set(obj, t);
468 eina_stringshare_del(t);
469 if (elm_widget_disabled_get(obj))
470 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
471 edje_object_message_signal_process(wd->ent);
472 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
477 _disable_hook(Evas_Object *obj)
479 Widget_Data *wd = elm_widget_data_get(obj);
481 if (elm_widget_disabled_get(obj))
483 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
484 wd->disabled = EINA_TRUE;
488 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
489 wd->disabled = EINA_FALSE;
494 _elm_win_recalc_job(void *data)
496 Widget_Data *wd = elm_widget_data_get(data);
497 Evas_Coord minw = -1, minh = -1, maxh = -1;
498 Evas_Coord resw, resh, minminw;
500 wd->deferred_recalc_job = NULL;
501 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
503 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, 0, 0);
504 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
506 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
507 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
508 evas_object_size_hint_min_set(data, minminw, minh);
509 if (wd->single_line) maxh = minh;
510 evas_object_size_hint_max_set(data, -1, maxh);
511 if (wd->deferred_cur)
512 elm_widget_show_region_set(data, wd->cx, wd->cy, wd->cw, wd->ch);
516 _sizing_eval(Evas_Object *obj)
518 Widget_Data *wd = elm_widget_data_get(obj);
519 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
520 Evas_Coord resw, resh;
522 if ((wd->linewrap) || (wd->char_linewrap))
524 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
525 if ((resw == wd->lastw) && (!wd->changed)) return;
526 wd->changed = EINA_FALSE;
528 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
529 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
533 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
534 edje_object_size_min_calc(wd->ent, &minw, &minh);
535 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
536 evas_object_size_hint_min_set(obj, minw, minh);
537 if (wd->single_line) maxh = minh;
538 evas_object_size_hint_max_set(obj, maxw, maxh);
543 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
545 Widget_Data *wd = elm_widget_data_get(obj);
546 Evas_Object *top = elm_widget_top_get(obj);
548 if (!wd->editable) return;
549 if (elm_widget_focus_get(obj))
551 evas_object_focus_set(wd->ent, EINA_TRUE);
552 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
553 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
554 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
558 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
559 evas_object_focus_set(wd->ent, EINA_FALSE);
560 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
561 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
566 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
568 Widget_Data *wd = elm_widget_data_get(obj);
570 edje_object_signal_emit(wd->ent, emission, source);
574 _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)
576 Widget_Data *wd = elm_widget_data_get(obj);
578 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
582 _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)
584 Widget_Data *wd = elm_widget_data_get(obj);
585 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
590 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
592 Widget_Data *wd = elm_widget_data_get(obj);
593 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
597 _hoversel_position(Evas_Object *obj)
599 Widget_Data *wd = elm_widget_data_get(obj);
600 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
602 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
603 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
605 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
616 evas_object_move(wd->hoversel, x + cx, y + cy);
617 evas_object_resize(wd->hoversel, cw, ch);
621 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
623 Widget_Data *wd = elm_widget_data_get(data);
625 if (wd->hoversel) _hoversel_position(data);
629 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
631 Widget_Data *wd = elm_widget_data_get(data);
633 if ((wd->linewrap) || (wd->char_linewrap))
637 if (wd->hoversel) _hoversel_position(data);
638 // Evas_Coord ww, hh;
639 // evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
643 _hover_del(void *data)
645 Widget_Data *wd = elm_widget_data_get(data);
650 evas_object_del(wd->hoversel);
653 wd->hovdeljob = NULL;
657 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
659 Widget_Data *wd = elm_widget_data_get(data);
661 if (wd->hoversel) evas_object_hide(wd->hoversel);
665 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
667 elm_widget_scroll_freeze_pop(data);
668 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
669 wd->hovdeljob = ecore_job_add(_hover_del, data);
673 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
675 Widget_Data *wd = elm_widget_data_get(data);
677 wd->selmode = EINA_TRUE;
678 edje_object_part_text_select_none(wd->ent, "elm.text");
680 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
681 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
682 elm_widget_scroll_hold_push(data);
686 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
688 Widget_Data *wd = elm_widget_data_get(data);
690 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
691 if (wd->sel_notify_handler)
693 #ifdef HAVE_ELEMENTARY_X
694 Elm_Sel_Format formats;
695 wd->selection_asked = EINA_TRUE;
696 formats = ELM_SEL_FORMAT_MARKUP;
698 formats |= ELM_SEL_FORMAT_IMAGE;
699 elm_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL);
705 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
707 Widget_Data *wd = elm_widget_data_get(obj);
711 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
712 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
713 if (seltype == ELM_SEL_CLIPBOARD)
714 eina_stringshare_replace(&wd->cut_sel, sel);
718 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
720 Widget_Data *wd = elm_widget_data_get(data);
723 wd->selmode = EINA_FALSE;
724 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
725 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
726 elm_widget_scroll_hold_pop(data);
727 _store_selection(ELM_SEL_CLIPBOARD, data);
728 edje_object_part_text_insert(wd->ent, "elm.text", "");
729 edje_object_part_text_select_none(wd->ent, "elm.text");
733 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
735 Widget_Data *wd = elm_widget_data_get(data);
737 wd->selmode = EINA_FALSE;
738 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
739 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
740 elm_widget_scroll_hold_pop(data);
741 _store_selection(ELM_SEL_CLIPBOARD, data);
742 // edje_object_part_text_select_none(wd->ent, "elm.text");
746 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
748 Widget_Data *wd = elm_widget_data_get(data);
750 wd->selmode = EINA_FALSE;
751 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
752 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
753 elm_widget_scroll_hold_pop(data);
754 edje_object_part_text_select_none(wd->ent, "elm.text");
758 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
760 Elm_Entry_Context_Menu_Item *it = data;
761 Evas_Object *obj2 = it->obj;
762 if (it->func) it->func(it->data, obj2, NULL);
766 _long_press(void *data)
768 Widget_Data *wd = elm_widget_data_get(data);
771 const Elm_Entry_Context_Menu_Item *it;
772 if (!wd) return ECORE_CALLBACK_CANCEL;
773 if ((wd->api) && (wd->api->obj_longpress))
775 wd->api->obj_longpress(data);
777 else if (wd->context_menu)
779 const char *context_menu_orientation;
781 if (wd->hoversel) evas_object_del(wd->hoversel);
782 else elm_widget_scroll_freeze_push(data);
783 wd->hoversel = elm_hoversel_add(data);
784 context_menu_orientation = edje_object_data_get
785 (wd->ent, "context_menu_orientation");
786 if ((context_menu_orientation) &&
787 (!strcmp(context_menu_orientation, "horizontal")))
788 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
789 elm_object_style_set(wd->hoversel, "entry");
790 elm_widget_sub_object_add(data, wd->hoversel);
791 elm_hoversel_label_set(wd->hoversel, "Text");
792 top = elm_widget_top_get(data);
793 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
794 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, data);
798 elm_hoversel_item_add(wd->hoversel, "Select", NULL, ELM_ICON_NONE,
800 if (1) // need way to detect if someone has a selection
803 elm_hoversel_item_add(wd->hoversel, "Paste", NULL, ELM_ICON_NONE,
811 if (wd->have_selection)
813 elm_hoversel_item_add(wd->hoversel, "Copy", NULL, ELM_ICON_NONE,
816 elm_hoversel_item_add(wd->hoversel, "Cut", NULL, ELM_ICON_NONE,
819 elm_hoversel_item_add(wd->hoversel, "Cancel", NULL, ELM_ICON_NONE,
823 EINA_LIST_FOREACH(wd->items, l, it)
825 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
826 it->icon_type, _item_clicked, it);
830 _hoversel_position(data);
831 evas_object_show(wd->hoversel);
832 elm_hoversel_hover_begin(wd->hoversel);
834 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
835 edje_object_part_text_select_abort(wd->ent, "elm.text");
837 wd->longpress_timer = NULL;
838 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
839 return ECORE_CALLBACK_CANCEL;
843 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
845 Widget_Data *wd = elm_widget_data_get(data);
846 Evas_Event_Mouse_Down *ev = event_info;
848 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
849 if (ev->button != 1) return;
850 // if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
851 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
852 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
853 wd->downx = ev->canvas.x;
854 wd->downy = ev->canvas.y;
858 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
860 Widget_Data *wd = elm_widget_data_get(data);
861 Evas_Event_Mouse_Up *ev = event_info;
863 if (ev->button != 1) return;
864 if (wd->longpress_timer)
866 ecore_timer_del(wd->longpress_timer);
867 wd->longpress_timer = NULL;
872 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
874 Widget_Data *wd = elm_widget_data_get(data);
875 Evas_Event_Mouse_Move *ev = event_info;
879 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
881 if (wd->longpress_timer)
883 ecore_timer_del(wd->longpress_timer);
884 wd->longpress_timer = NULL;
887 else if (wd->longpress_timer)
891 dx = wd->downx - ev->cur.canvas.x;
893 dy = wd->downy - ev->cur.canvas.y;
896 ((_elm_config->finger_size / 2) *
897 (_elm_config->finger_size / 2)))
899 ecore_timer_del(wd->longpress_timer);
900 wd->longpress_timer = NULL;
904 else if (wd->longpress_timer)
908 dx = wd->downx - ev->cur.canvas.x;
910 dy = wd->downy - ev->cur.canvas.y;
913 ((_elm_config->finger_size / 2) *
914 (_elm_config->finger_size / 2)))
916 ecore_timer_del(wd->longpress_timer);
917 wd->longpress_timer = NULL;
923 _getbase(Evas_Object *obj)
925 Widget_Data *wd = elm_widget_data_get(obj);
926 if (!wd) return "base";
929 if (wd->password) return "base-password";
932 if (wd->single_line) return "base-single";
935 if (wd->linewrap) return "base";
936 else if (wd->char_linewrap) return "base-charwrap";
937 else return "base-nowrap";
943 if (wd->password) return "base-password";
946 if (wd->single_line) return "base-single-noedit";
949 if (wd->linewrap) return "base-noedit";
950 else if (wd->char_linewrap) return "base-noedit-charwrap";
951 else return "base-nowrap-noedit";
959 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
961 Widget_Data *wd = elm_widget_data_get(data);
963 wd->changed = EINA_TRUE;
965 if (wd->text) eina_stringshare_del(wd->text);
967 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
970 ecore_timer_del(wd->delay_write);
971 wd->delay_write = NULL;
973 if ((!wd->autosave) || (!wd->file)) return;
974 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
978 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
980 Widget_Data *wd = elm_widget_data_get(data);
984 EINA_LIST_FOREACH(entries, l, entry)
986 if (entry != data) elm_entry_select_none(entry);
988 wd->have_selection = EINA_TRUE;
989 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
990 #ifdef HAVE_ELEMENTARY_X
991 if (wd->sel_notify_handler)
993 const char *txt = elm_entry_selection_get(data);
996 top = elm_widget_top_get(data);
997 if ((top) && (elm_win_xwindow_get(top)))
998 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1004 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1006 Widget_Data *wd = elm_widget_data_get(data);
1008 wd->have_selection = EINA_TRUE;
1009 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1010 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1011 elm_entry_selection_get(data));
1015 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1017 Widget_Data *wd = elm_widget_data_get(data);
1019 if (!wd->have_selection) return;
1020 wd->have_selection = EINA_FALSE;
1021 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1022 if (wd->sel_notify_handler)
1026 #ifdef HAVE_ELEMENTARY_X
1029 top = elm_widget_top_get(data);
1030 if ((top) && (elm_win_xwindow_get(top)))
1031 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1034 eina_stringshare_del(wd->cut_sel);
1039 #ifdef HAVE_ELEMENTARY_X
1042 top = elm_widget_top_get(data);
1043 if ((top) && (elm_win_xwindow_get(top)))
1044 elm_selection_clear(ELM_SEL_PRIMARY, data);
1051 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1053 Widget_Data *wd = elm_widget_data_get(data);
1055 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1056 if (wd->sel_notify_handler)
1058 #ifdef HAVE_ELEMENTARY_X
1061 top = elm_widget_top_get(data);
1062 if ((top) && (elm_win_xwindow_get(top)))
1064 wd->selection_asked = EINA_TRUE;
1065 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
1073 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1075 Widget_Data *wd = elm_widget_data_get(data);
1077 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1078 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1079 elm_entry_selection_get(data));
1083 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1085 Widget_Data *wd = elm_widget_data_get(data);
1087 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1088 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1089 elm_entry_selection_get(data));
1090 edje_object_part_text_insert(wd->ent, "elm.text", "");
1091 wd->changed = EINA_TRUE;
1096 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1098 Widget_Data *wd = elm_widget_data_get(data);
1099 Evas_Coord cx, cy, cw, ch;
1101 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1102 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1103 &cx, &cy, &cw, &ch);
1104 if (!wd->deferred_recalc_job)
1105 elm_widget_show_region_set(data, cx, cy, cw, ch);
1108 wd->deferred_cur = EINA_TRUE;
1117 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1119 Widget_Data *wd = elm_widget_data_get(data);
1124 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1126 Widget_Data *wd = elm_widget_data_get(data);
1127 Elm_Entry_Anchor_Info ei;
1128 char *buf2, *p, *p2, *n;
1130 p = strrchr(emission, ',');
1133 const Eina_List *geoms;
1137 while (p2 >= emission)
1139 if (*p2 == ',') break;
1143 buf2 = alloca(5 + p - p2);
1144 strncpy(buf2, p2, p - p2);
1147 ei.button = atoi(buf2);
1148 ei.x = ei.y = ei.w = ei.h = 0;
1150 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1153 Evas_Textblock_Rectangle *r;
1155 Evas_Coord px, py, x, y;
1157 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1158 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1159 EINA_LIST_FOREACH(geoms, l, r)
1161 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1162 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1173 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1178 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1180 Widget_Data *wd = elm_widget_data_get(data);
1185 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1187 Widget_Data *wd = elm_widget_data_get(data);
1192 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1194 Widget_Data *wd = elm_widget_data_get(data);
1199 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1201 Widget_Data *wd = elm_widget_data_get(data);
1203 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1207 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1209 Widget_Data *wd = elm_widget_data_get(data);
1211 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1215 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1217 Widget_Data *wd = elm_widget_data_get(data);
1219 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1223 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1225 Widget_Data *wd = elm_widget_data_get(data);
1227 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1230 #ifdef HAVE_ELEMENTARY_X
1232 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1234 Widget_Data *wd = elm_widget_data_get(data);
1235 Ecore_X_Event_Selection_Notify *ev = event;
1236 if (!wd) return ECORE_CALLBACK_PASS_ON;
1237 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1238 return ECORE_CALLBACK_PASS_ON;
1240 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1241 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1243 Ecore_X_Selection_Data_Text *text_data;
1245 text_data = ev->data;
1246 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1248 if (text_data->text)
1250 char *txt = _elm_util_text_to_mkup(text_data->text);
1254 elm_entry_entry_insert(data, txt);
1259 wd->selection_asked = EINA_FALSE;
1261 else if (ev->selection == ECORE_X_SELECTION_XDND)
1263 Ecore_X_Selection_Data_Text *text_data;
1265 text_data = ev->data;
1266 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1268 if (text_data->text)
1270 char *txt = _elm_util_text_to_mkup(text_data->text);
1274 /* Massive FIXME: this should be at the drag point */
1275 elm_entry_entry_insert(data, txt);
1280 wd->drag_selection_asked = EINA_FALSE;
1282 ecore_x_dnd_send_finished();
1285 return ECORE_CALLBACK_PASS_ON;
1289 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1292 Widget_Data *wd = elm_widget_data_get(data);
1293 Ecore_X_Event_Selection_Clear *ev = event;
1294 if (!wd) return ECORE_CALLBACK_PASS_ON;
1295 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1296 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1297 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1299 elm_entry_select_none(data);
1302 return ECORE_CALLBACK_PASS_ON;
1307 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1312 wd = elm_widget_data_get(obj);
1314 if (!wd) return EINA_FALSE;
1315 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1317 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1318 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1319 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1320 EDJE_CURSOR_MAIN,drop->x,drop->y);
1321 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1322 elm_entry_entry_insert(obj, drop->data);
1323 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1324 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1330 static Evas_Object *
1331 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1333 Widget_Data *wd = elm_widget_data_get(data);
1336 Elm_Entry_Item_Provider *ip;
1338 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1340 o = ip->func(ip->data, data, item);
1343 if (!strncmp(item, "file://", 7))
1345 const char *fname = item + 7;
1347 o = evas_object_image_filled_add(evas_object_evas_get(data));
1348 evas_object_image_file_set(o, fname, NULL);
1349 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1351 evas_object_show(o);
1356 o = edje_object_add(evas_object_evas_get(data));
1357 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1361 o = edje_object_add(evas_object_evas_get(data));
1362 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1363 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1368 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
1370 Widget_Data *wd = elm_widget_data_get(data);
1372 Elm_Entry_Text_Filter *tf;
1374 if (type == EDJE_TEXT_FILTER_FORMAT)
1377 EINA_LIST_FOREACH(wd->text_filters, l, tf)
1379 tf->func(tf->data, data, text);
1386 * This adds an entry to @p parent object.
1388 * @param parent The parent object
1389 * @return The new object or NULL if it cannot be created
1394 elm_entry_add(Evas_Object *parent)
1396 Evas_Object *obj, *top;
1400 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
1402 wd = ELM_NEW(Widget_Data);
1403 e = evas_object_evas_get(parent);
1404 if (!e) return NULL;
1405 obj = elm_widget_add(e);
1406 ELM_SET_WIDTYPE(widtype, "entry");
1407 elm_widget_type_set(obj, "entry");
1408 elm_widget_sub_object_add(parent, obj);
1409 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1410 elm_widget_data_set(obj, wd);
1411 elm_widget_del_hook_set(obj, _del_hook);
1412 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1413 elm_widget_theme_hook_set(obj, _theme_hook);
1414 elm_widget_disable_hook_set(obj, _disable_hook);
1415 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1416 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
1417 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1418 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1419 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
1420 elm_widget_can_focus_set(obj, EINA_TRUE);
1421 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
1423 wd->linewrap = EINA_TRUE;
1424 wd->char_linewrap= EINA_FALSE;
1425 wd->editable = EINA_TRUE;
1426 wd->disabled = EINA_FALSE;
1427 wd->context_menu = EINA_TRUE;
1428 wd->autosave = EINA_TRUE;
1429 wd->textonly = EINA_FALSE;
1431 wd->ent = edje_object_add(e);
1432 edje_object_item_provider_set(wd->ent, _get_item, obj);
1433 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
1434 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1435 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
1436 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1438 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1440 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1443 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1444 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1445 _signal_entry_changed, obj);
1446 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1447 _signal_selection_start, obj);
1448 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1449 _signal_selection_changed, obj);
1450 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
1451 _signal_selection_cleared, obj);
1452 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
1453 _signal_entry_paste_request, obj);
1454 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
1455 _signal_entry_copy_notify, obj);
1456 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
1457 _signal_entry_cut_notify, obj);
1458 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
1459 _signal_cursor_changed, obj);
1460 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
1461 _signal_anchor_down, obj);
1462 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
1463 _signal_anchor_up, obj);
1464 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
1465 _signal_anchor_move, obj);
1466 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
1467 _signal_anchor_in, obj);
1468 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
1469 _signal_anchor_out, obj);
1470 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
1471 _signal_key_enter, obj);
1472 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
1473 _signal_mouse_down, obj);
1474 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
1475 _signal_mouse_clicked, obj);
1476 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
1477 _signal_mouse_double, obj);
1478 edje_object_part_text_set(wd->ent, "elm.text", "");
1479 elm_widget_resize_object_set(obj, wd->ent);
1482 #ifdef HAVE_ELEMENTARY_X
1483 top = elm_widget_top_get(obj);
1484 if ((top) && (elm_win_xwindow_get(top)))
1486 wd->sel_notify_handler =
1487 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
1488 _event_selection_notify, obj);
1489 wd->sel_clear_handler =
1490 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
1491 _event_selection_clear, obj);
1494 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
1495 _drag_drop_cb, NULL);
1498 entries = eina_list_prepend(entries, obj);
1500 // module - find module for entry
1501 wd->api = _module(obj);
1502 // if found - hook in
1503 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
1505 _mirrored_set(obj, elm_widget_mirrored_get(obj));
1506 // TODO: convert Elementary to subclassing of Evas_Smart_Class
1507 // TODO: and save some bytes, making descriptions per-class and not instance!
1508 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1514 * This sets the entry object not to line wrap. All input will
1515 * be on a single line, and the entry box will extend with user input.
1517 * @param obj The entry object
1518 * @param single_line If true, the text in the entry
1519 * will be on a single line.
1524 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
1526 ELM_CHECK_WIDTYPE(obj, widtype);
1527 Widget_Data *wd = elm_widget_data_get(obj);
1530 if (wd->single_line == single_line) return;
1531 wd->single_line = single_line;
1532 wd->linewrap = EINA_FALSE;
1533 wd->char_linewrap = EINA_FALSE;
1534 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
1535 t = eina_stringshare_add(elm_entry_entry_get(obj));
1536 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1537 elm_entry_entry_set(obj, t);
1538 eina_stringshare_del(t);
1543 * This returns true if the entry has been set to single line mode.
1544 * See also elm_entry_single_line_set().
1546 * @param obj The entry object
1547 * @return single_line If true, the text in the entry is set to display
1553 elm_entry_single_line_get(const Evas_Object *obj)
1555 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1556 Widget_Data *wd = elm_widget_data_get(obj);
1557 if (!wd) return EINA_FALSE;
1558 return wd->single_line;
1562 * This sets the entry object to password mode. All text entered
1563 * and/or displayed within the widget will be replaced with asterisks (*).
1565 * @param obj The entry object
1566 * @param password If true, password mode is enabled.
1571 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
1573 ELM_CHECK_WIDTYPE(obj, widtype);
1574 Widget_Data *wd = elm_widget_data_get(obj);
1577 if (wd->password == password) return;
1578 wd->password = password;
1579 wd->single_line = EINA_TRUE;
1580 wd->linewrap = EINA_FALSE;
1581 wd->char_linewrap = EINA_FALSE;
1582 t = eina_stringshare_add(elm_entry_entry_get(obj));
1583 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1584 elm_entry_entry_set(obj, t);
1585 eina_stringshare_del(t);
1591 * This returns whether password mode is enabled.
1592 * See also elm_entry_password_set().
1594 * @param obj The entry object
1595 * @return If true, the entry is set to display all characters
1601 elm_entry_password_get(const Evas_Object *obj)
1603 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1604 Widget_Data *wd = elm_widget_data_get(obj);
1605 if (!wd) return EINA_FALSE;
1606 return wd->password;
1610 * This sets the text displayed within the entry to @p entry.
1612 * @param obj The entry object
1613 * @param entry The text to be displayed
1618 elm_entry_entry_set(Evas_Object *obj, const char *entry)
1620 ELM_CHECK_WIDTYPE(obj, widtype);
1621 Widget_Data *wd = elm_widget_data_get(obj);
1623 if (!entry) entry = "";
1624 edje_object_part_text_set(wd->ent, "elm.text", entry);
1625 if (wd->text) eina_stringshare_del(wd->text);
1627 wd->changed = EINA_TRUE;
1632 * This returns the text currently shown in object @p entry.
1633 * See also elm_entry_entry_set().
1635 * @param obj The entry object
1636 * @return The currently displayed text or NULL on failure
1641 elm_entry_entry_get(const Evas_Object *obj)
1643 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1644 Widget_Data *wd = elm_widget_data_get(obj);
1646 if (!wd) return NULL;
1647 if (wd->text) return wd->text;
1648 text = edje_object_part_text_get(wd->ent, "elm.text");
1651 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
1654 eina_stringshare_replace(&wd->text, text);
1660 * This returns EINA_TRUE if the entry is empty/there was an error
1661 * and EINA_FALSE if it is not empty.
1663 * @param obj The entry object
1664 * @return If the entry is empty or not.
1669 elm_entry_is_empty(const Evas_Object *obj)
1671 /* FIXME: until there's support for that in textblock, we just check
1672 * to see if the there is text or not. */
1673 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
1674 Widget_Data *wd = elm_widget_data_get(obj);
1675 const Evas_Object *tb;
1676 Evas_Textblock_Cursor *cur;
1678 if (!wd) return EINA_TRUE;
1679 /* It's a hack until we get the support suggested above.
1680 * We just create a cursor, point it to the begining, and then
1681 * try to advance it, if it can advance, the tb is not empty,
1682 * otherwise it is. */
1683 tb = edje_object_part_object_get(wd->ent, "elm.text");
1684 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
1685 actually, ok for the time being, thsese hackish stuff will be removed
1686 once evas 1.0 is out*/
1687 evas_textblock_cursor_pos_set(cur, 0);
1688 ret = evas_textblock_cursor_char_next(cur);
1689 evas_textblock_cursor_free(cur);
1695 * This returns all selected text within the entry.
1697 * @param obj The entry object
1698 * @return The selected text within the entry or NULL on failure
1703 elm_entry_selection_get(const Evas_Object *obj)
1705 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1706 Widget_Data *wd = elm_widget_data_get(obj);
1707 if (!wd) return NULL;
1708 return edje_object_part_text_selection_get(wd->ent, "elm.text");
1712 * This inserts text in @p entry where the current cursor position.
1714 * This inserts text at the cursor position is as if it was typed
1715 * by the user (note this also allows markup which a user
1716 * can't just "type" as it would be converted to escaped text, so this
1717 * call can be used to insert things like emoticon items or bold push/pop
1718 * tags, other font and color change tags etc.)
1720 * @param obj The entry object
1721 * @param entry The text to insert
1726 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
1728 ELM_CHECK_WIDTYPE(obj, widtype);
1729 Widget_Data *wd = elm_widget_data_get(obj);
1731 edje_object_part_text_insert(wd->ent, "elm.text", entry);
1732 wd->changed = EINA_TRUE;
1737 * This enables word line wrapping in the entry object. It is the opposite
1738 * of elm_entry_single_line_set(). Additionally, setting this disables
1739 * character line wrapping.
1740 * See also elm_entry_line_char_wrap_set().
1742 * @param obj The entry object
1743 * @param wrap If true, the entry will be wrapped once it reaches the end
1744 * of the object. Wrapping will occur at the end of the word before the end of the
1750 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
1752 ELM_CHECK_WIDTYPE(obj, widtype);
1753 Widget_Data *wd = elm_widget_data_get(obj);
1756 if (wd->linewrap == wrap) return;
1757 wd->linewrap = wrap;
1759 wd->char_linewrap = EINA_FALSE;
1760 t = eina_stringshare_add(elm_entry_entry_get(obj));
1761 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1762 elm_entry_entry_set(obj, t);
1763 eina_stringshare_del(t);
1768 * This enables character line wrapping in the entry object. It is the opposite
1769 * of elm_entry_single_line_set(). Additionally, setting this disables
1770 * word line wrapping.
1771 * See also elm_entry_line_wrap_set().
1773 * @param obj The entry object
1774 * @param wrap If true, the entry will be wrapped once it reaches the end
1775 * of the object. Wrapping will occur immediately upon reaching the end of the object.
1780 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
1782 ELM_CHECK_WIDTYPE(obj, widtype);
1783 Widget_Data *wd = elm_widget_data_get(obj);
1786 if (wd->char_linewrap == wrap) return;
1787 wd->char_linewrap = wrap;
1788 if(wd->char_linewrap)
1789 wd->linewrap = EINA_FALSE;
1790 t = eina_stringshare_add(elm_entry_entry_get(obj));
1791 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1792 elm_entry_entry_set(obj, t);
1793 eina_stringshare_del(t);
1798 * This sets the editable attribute of the entry.
1800 * @param obj The entry object
1801 * @param editable If true, the entry will be editable by the user.
1802 * If false, it will be set to the disabled state.
1807 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
1809 ELM_CHECK_WIDTYPE(obj, widtype);
1810 Widget_Data *wd = elm_widget_data_get(obj);
1813 if (wd->editable == editable) return;
1814 wd->editable = editable;
1815 t = eina_stringshare_add(elm_entry_entry_get(obj));
1816 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
1817 elm_entry_entry_set(obj, t);
1818 eina_stringshare_del(t);
1821 #ifdef HAVE_ELEMENTARY_X
1823 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
1825 elm_drop_target_del(obj);
1830 * This gets the editable attribute of the entry.
1831 * See also elm_entry_editable_set().
1833 * @param obj The entry object
1834 * @return If true, the entry is editable by the user.
1835 * If false, it is not editable by the user
1840 elm_entry_editable_get(const Evas_Object *obj)
1842 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1843 Widget_Data *wd = elm_widget_data_get(obj);
1844 if (!wd) return EINA_FALSE;
1845 return wd->editable;
1849 * This drops any existing text selection within the entry.
1851 * @param obj The entry object
1856 elm_entry_select_none(Evas_Object *obj)
1858 ELM_CHECK_WIDTYPE(obj, widtype);
1859 Widget_Data *wd = elm_widget_data_get(obj);
1863 wd->selmode = EINA_FALSE;
1864 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
1865 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1867 wd->have_selection = EINA_FALSE;
1868 edje_object_part_text_select_none(wd->ent, "elm.text");
1872 * This selects all text within the entry.
1874 * @param obj The entry object
1879 elm_entry_select_all(Evas_Object *obj)
1881 ELM_CHECK_WIDTYPE(obj, widtype);
1882 Widget_Data *wd = elm_widget_data_get(obj);
1886 wd->selmode = EINA_FALSE;
1887 edje_object_part_text_select_allow_set(wd->ent, "elm.text", 0);
1888 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1890 wd->have_selection = EINA_TRUE;
1891 edje_object_part_text_select_all(wd->ent, "elm.text");
1895 * This function returns the geometry of the cursor.
1897 * It's useful if you want to draw something on the cursor (or where it is),
1898 * or for example in the case of scrolled entry where you want to show the
1901 * @param obj The entry object
1902 * @param x returned geometry
1903 * @param y returned geometry
1904 * @param w returned geometry
1905 * @param h returned geometry
1906 * @return EINA_TRUE upon success, EINA_FALSE upon failure
1911 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
1913 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1914 Widget_Data *wd = elm_widget_data_get(obj);
1915 if (!wd) return EINA_FALSE;
1916 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
1921 * This moves the cursor one place to the right within the entry.
1923 * @param obj The entry object
1924 * @return EINA_TRUE upon success, EINA_FALSE upon failure
1929 elm_entry_cursor_next(Evas_Object *obj)
1931 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1932 Widget_Data *wd = elm_widget_data_get(obj);
1933 if (!wd) return EINA_FALSE;
1934 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1938 * This moves the cursor one place to the left within the entry.
1940 * @param obj The entry object
1941 * @return EINA_TRUE upon success, EINA_FALSE upon failure
1946 elm_entry_cursor_prev(Evas_Object *obj)
1948 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1949 Widget_Data *wd = elm_widget_data_get(obj);
1950 if (!wd) return EINA_FALSE;
1951 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1955 * This moves the cursor one line up within the entry.
1957 * @param obj The entry object
1958 * @return EINA_TRUE upon success, EINA_FALSE upon failure
1963 elm_entry_cursor_up(Evas_Object *obj)
1965 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1966 Widget_Data *wd = elm_widget_data_get(obj);
1967 if (!wd) return EINA_FALSE;
1968 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1972 * This moves the cursor one line down within the entry.
1974 * @param obj The entry object
1975 * @return EINA_TRUE upon success, EINA_FALSE upon failure
1980 elm_entry_cursor_down(Evas_Object *obj)
1982 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1983 Widget_Data *wd = elm_widget_data_get(obj);
1984 if (!wd) return EINA_FALSE;
1985 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1989 * This moves the cursor to the beginning of the entry.
1991 * @param obj The entry object
1996 elm_entry_cursor_begin_set(Evas_Object *obj)
1998 ELM_CHECK_WIDTYPE(obj, widtype);
1999 Widget_Data *wd = elm_widget_data_get(obj);
2001 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2005 * This moves the cursor to the end of the entry.
2007 * @param obj The entry object
2012 elm_entry_cursor_end_set(Evas_Object *obj)
2014 ELM_CHECK_WIDTYPE(obj, widtype);
2015 Widget_Data *wd = elm_widget_data_get(obj);
2017 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2021 * This moves the cursor to the beginning of the current line.
2023 * @param obj The entry object
2028 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2030 ELM_CHECK_WIDTYPE(obj, widtype);
2031 Widget_Data *wd = elm_widget_data_get(obj);
2033 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2037 * This moves the cursor to the end of the current line.
2039 * @param obj The entry object
2044 elm_entry_cursor_line_end_set(Evas_Object *obj)
2046 ELM_CHECK_WIDTYPE(obj, widtype);
2047 Widget_Data *wd = elm_widget_data_get(obj);
2049 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2053 * This begins a selection within the entry as though
2054 * the user were holding down the mouse button to make a selection.
2056 * @param obj The entry object
2061 elm_entry_cursor_selection_begin(Evas_Object *obj)
2063 ELM_CHECK_WIDTYPE(obj, widtype);
2064 Widget_Data *wd = elm_widget_data_get(obj);
2066 edje_object_part_text_select_begin(wd->ent, "elm.text");
2070 * This ends a selection within the entry as though
2071 * the user had just released the mouse button while making a selection.
2073 * @param obj The entry object
2078 elm_entry_cursor_selection_end(Evas_Object *obj)
2080 ELM_CHECK_WIDTYPE(obj, widtype);
2081 Widget_Data *wd = elm_widget_data_get(obj);
2083 edje_object_part_text_select_extend(wd->ent, "elm.text");
2087 * TODO: fill this in
2089 * @param obj The entry object
2090 * @return TODO: fill this in
2095 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2097 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2098 Widget_Data *wd = elm_widget_data_get(obj);
2099 if (!wd) return EINA_FALSE;
2100 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2104 * This returns whether the cursor is visible.
2106 * @param obj The entry object
2107 * @return If true, the cursor is visible.
2112 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2114 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2115 Widget_Data *wd = elm_widget_data_get(obj);
2116 if (!wd) return EINA_FALSE;
2117 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2121 * TODO: fill this in
2123 * @param obj The entry object
2124 * @return TODO: fill this in
2129 elm_entry_cursor_content_get(const Evas_Object *obj)
2131 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2132 Widget_Data *wd = elm_widget_data_get(obj);
2133 if (!wd) return NULL;
2134 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2138 * This executes a "cut" action on the selected text in the entry.
2140 * @param obj The entry object
2145 elm_entry_selection_cut(Evas_Object *obj)
2147 ELM_CHECK_WIDTYPE(obj, widtype);
2148 Widget_Data *wd = elm_widget_data_get(obj);
2150 _cut(obj, NULL, NULL);
2154 * This executes a "copy" action on the selected text in the entry.
2156 * @param obj The entry object
2161 elm_entry_selection_copy(Evas_Object *obj)
2163 ELM_CHECK_WIDTYPE(obj, widtype);
2164 Widget_Data *wd = elm_widget_data_get(obj);
2166 _copy(obj, NULL, NULL);
2170 * This executes a "paste" action in the entry.
2172 * @param obj The entry object
2177 elm_entry_selection_paste(Evas_Object *obj)
2179 ELM_CHECK_WIDTYPE(obj, widtype);
2180 Widget_Data *wd = elm_widget_data_get(obj);
2182 _paste(obj, NULL, NULL);
2186 * This clears and frees the items in a entry's contextual (right click) menu.
2188 * @param obj The entry object
2193 elm_entry_context_menu_clear(Evas_Object *obj)
2195 ELM_CHECK_WIDTYPE(obj, widtype);
2196 Widget_Data *wd = elm_widget_data_get(obj);
2197 Elm_Entry_Context_Menu_Item *it;
2199 EINA_LIST_FREE(wd->items, it)
2201 eina_stringshare_del(it->label);
2202 eina_stringshare_del(it->icon_file);
2203 eina_stringshare_del(it->icon_group);
2209 * This adds an item to the entry's contextual menu.
2211 * @param obj The entry object
2212 * @param label The item's text label
2213 * @param icon_file The item's icon file
2214 * @param icon_type The item's icon type
2215 * @param func The callback to execute when the item is clicked
2216 * @param data The data to associate with the item for related functions
2221 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)
2223 ELM_CHECK_WIDTYPE(obj, widtype);
2224 Widget_Data *wd = elm_widget_data_get(obj);
2225 Elm_Entry_Context_Menu_Item *it;
2227 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2229 wd->items = eina_list_append(wd->items, it);
2231 it->label = eina_stringshare_add(label);
2232 it->icon_file = eina_stringshare_add(icon_file);
2233 it->icon_type = icon_type;
2235 it->data = (void *)data;
2239 * This disables the entry's contextual (right click) menu.
2241 * @param obj The entry object
2242 * @param disabled If true, the menu is disabled
2247 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2249 ELM_CHECK_WIDTYPE(obj, widtype);
2250 Widget_Data *wd = elm_widget_data_get(obj);
2252 if (wd->context_menu == !disabled) return;
2253 wd->context_menu = !disabled;
2257 * This returns whether the entry's contextual (right click) menu is disabled.
2259 * @param obj The entry object
2260 * @return If true, the menu is disabled
2265 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2267 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2268 Widget_Data *wd = elm_widget_data_get(obj);
2269 if (!wd) return EINA_FALSE;
2270 return !wd->context_menu;
2274 * This appends a custom item provider to the list for that entry
2276 * This appends the given callback. The list is walked from beginning to end
2277 * with each function called given the item href string in the text. If the
2278 * function returns an object handle other than NULL (it should create an
2279 * and object to do this), then this object is used to replace that item. If
2280 * not the next provider is called until one provides an item object, or the
2281 * default provider in entry does.
2283 * @param obj The entry object
2284 * @param func The function called to provide the item object
2285 * @param data The data passed to @p func
2290 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2292 ELM_CHECK_WIDTYPE(obj, widtype);
2293 Widget_Data *wd = elm_widget_data_get(obj);
2295 EINA_SAFETY_ON_NULL_RETURN(func);
2296 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2300 wd->item_providers = eina_list_append(wd->item_providers, ip);
2304 * This prepends a custom item provider to the list for that entry
2306 * This prepends the given callback. See elm_entry_item_provider_append() for
2309 * @param obj The entry object
2310 * @param func The function called to provide the item object
2311 * @param data The data passed to @p func
2316 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2318 ELM_CHECK_WIDTYPE(obj, widtype);
2319 Widget_Data *wd = elm_widget_data_get(obj);
2321 EINA_SAFETY_ON_NULL_RETURN(func);
2322 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2326 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2330 * This removes a custom item provider to the list for that entry
2332 * This removes the given callback. See elm_entry_item_provider_append() for
2335 * @param obj The entry object
2336 * @param func The function called to provide the item object
2337 * @param data The data passed to @p func
2342 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2344 ELM_CHECK_WIDTYPE(obj, widtype);
2345 Widget_Data *wd = elm_widget_data_get(obj);
2347 Elm_Entry_Item_Provider *ip;
2349 EINA_SAFETY_ON_NULL_RETURN(func);
2350 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2352 if ((ip->func == func) && (ip->data == data))
2354 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2362 * Append a filter function for text inserted in the entry
2364 * Append the given callback to the list. This functions will be called
2365 * whenever any text is inserted into the entry, with the text to be inserted
2366 * as a parameter. The callback function is free to alter the text in any way
2367 * it wants, but it must remember to free the given pointer and update it.
2368 * If the new text is to be discarded, the function can free it and set it text
2369 * parameter to NULL. This will also prevent any following filters from being
2372 * @param obj The entry object
2373 * @param func The function to use as text filter
2374 * @param data User data to pass to @p func
2379 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2382 Elm_Entry_Text_Filter *tf;
2383 ELM_CHECK_WIDTYPE(obj, widtype);
2385 wd = elm_widget_data_get(obj);
2387 EINA_SAFETY_ON_NULL_RETURN(func);
2389 tf = ELM_NEW(Elm_Entry_Text_Filter);
2393 wd->text_filters = eina_list_append(wd->text_filters, tf);
2397 * Prepend a filter function for text insdrted in the entry
2399 * Prepend the given callback to the list. See elm_entry_text_filter_append()
2400 * for more information
2402 * @param obj The entry object
2403 * @param func The function to use as text filter
2404 * @param data User data to pass to @p func
2409 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2412 Elm_Entry_Text_Filter *tf;
2413 ELM_CHECK_WIDTYPE(obj, widtype);
2415 wd = elm_widget_data_get(obj);
2417 EINA_SAFETY_ON_NULL_RETURN(func);
2419 tf = ELM_NEW(Elm_Entry_Text_Filter);
2423 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
2427 * Remove a filter from the list
2429 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
2430 * for more information.
2432 * @param obj The entry object
2433 * @param func The filter function to remove
2434 * @param data The user data passed when adding the function
2439 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2443 Elm_Entry_Text_Filter *tf;
2444 ELM_CHECK_WIDTYPE(obj, widtype);
2446 wd = elm_widget_data_get(obj);
2448 EINA_SAFETY_ON_NULL_RETURN(func);
2450 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2452 if ((tf->func == func) && (tf->data == data))
2454 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
2462 * This converts a markup (HTML-like) string into UTF-8.
2464 * @param s The string (in markup) to be converted
2465 * @return The converted string (in UTF-8)
2470 elm_entry_markup_to_utf8(const char *s)
2472 char *ss = _elm_util_mkup_to_text(s);
2473 if (!ss) ss = strdup("");
2478 * This converts a UTF-8 string into markup (HTML-like).
2480 * @param s The string (in UTF-8) to be converted
2481 * @return The converted string (in markup)
2486 elm_entry_utf8_to_markup(const char *s)
2488 char *ss = _elm_util_text_to_mkup(s);
2489 if (!ss) ss = strdup("");
2494 * Filter inserted text based on user defined character and byte limits
2496 * Add this filter to an entry to limit the characters that it will accept
2497 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
2498 * The funtion works on the UTF-8 representation of the string, converting
2499 * it from the set markup, thus not accounting for any format in it.
2501 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
2502 * it as data when setting the filter. In it it's possible to set limits
2503 * by character count or bytes (any of them is disabled if 0), and both can
2504 * be set at the same time. In that case, it first checks for characters,
2507 * The function will cut the inserted text in order to allow only the first
2508 * number of characters that are still allowed. The cut is made in
2509 * characters, even when limiting by bytes, in order to always contain
2510 * valid ones and avoid half unicode characters making it in.
2515 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
2517 Elm_Entry_Filter_Limit_Size *lim = data;
2520 const char *(*text_get)(const Evas_Object *);
2521 const char *widget_type;
2523 EINA_SAFETY_ON_NULL_RETURN(data);
2524 EINA_SAFETY_ON_NULL_RETURN(entry);
2525 EINA_SAFETY_ON_NULL_RETURN(text);
2527 /* hack. I don't want to copy the entire function to work with
2529 widget_type = elm_widget_type_get(entry);
2530 if (!strcmp(widget_type, "entry"))
2531 text_get = elm_entry_entry_get;
2532 else if (!strcmp(widget_type, "scrolled_entry"))
2533 text_get = elm_scrolled_entry_entry_get;
2537 current = elm_entry_markup_to_utf8(text_get(entry));
2539 if (lim->max_char_count > 0)
2542 len = evas_string_char_len_get(current);
2543 if (len >= lim->max_char_count)
2550 newlen = evas_string_char_len_get(*text);
2551 cut = strlen(*text);
2552 while ((len + newlen) > lim->max_char_count)
2554 cut = evas_string_char_prev_get(*text, cut, NULL);
2560 if (lim->max_byte_count > 0)
2562 len = strlen(current);
2563 if (len >= lim->max_byte_count)
2570 newlen = strlen(*text);
2571 while ((len + newlen) > lim->max_byte_count)
2573 int p = evas_string_char_prev_get(*text, newlen, NULL);
2574 newlen -= (newlen - p);
2577 (*text)[newlen] = 0;
2588 * Filter inserted text based on accepted or rejected sets of characters
2590 * Add this filter to an entry to restrict the set of accepted characters
2591 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
2592 * This structure contains both accepted and rejected sets, but they are
2593 * mutually exclusive. If accepted is set, it will be used, otherwise it
2594 * goes on to the rejected set.
2597 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
2599 Elm_Entry_Filter_Accept_Set *as = data;
2603 int read_idx, last_read_idx = 0, read_char;
2605 EINA_SAFETY_ON_NULL_RETURN(data);
2606 EINA_SAFETY_ON_NULL_RETURN(text);
2608 if ((!as->accepted) && (!as->rejected))
2614 goes_in = EINA_TRUE;
2619 goes_in = EINA_FALSE;
2623 read_idx = evas_string_char_next_get(*text, 0, &read_char);
2626 int cmp_idx, cmp_char;
2627 Eina_Bool in_set = EINA_FALSE;
2629 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
2632 if (read_char == cmp_char)
2637 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
2639 if (in_set == goes_in)
2641 int size = read_idx - last_read_idx;
2642 const char *src = (*text) + last_read_idx;
2644 memcpy(insert, *text + last_read_idx, size);
2647 last_read_idx = read_idx;
2648 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
2654 * This sets the file (and implicitly loads it) for the text to display and
2655 * then edit. All changes are written back to the file after a short delay if
2656 * the entry object is set to autosave.
2658 * @param obj The entry object
2659 * @param file The path to the file to load and save
2660 * @param format The file format
2665 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
2667 ELM_CHECK_WIDTYPE(obj, widtype);
2668 Widget_Data *wd = elm_widget_data_get(obj);
2670 if (wd->delay_write)
2672 ecore_timer_del(wd->delay_write);
2673 wd->delay_write = NULL;
2675 if (wd->autosave) _save(obj);
2676 eina_stringshare_replace(&wd->file, file);
2677 wd->format = format;
2682 * Gets the file to load and save and the file format
2684 * @param obj The entry object
2685 * @param file The path to the file to load and save
2686 * @param format The file format
2691 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
2693 ELM_CHECK_WIDTYPE(obj, widtype);
2694 Widget_Data *wd = elm_widget_data_get(obj);
2696 if (file) *file = wd->file;
2697 if (format) *format = wd->format;
2701 * This function writes any changes made to the file set with
2702 * elm_entry_file_set()
2704 * @param obj The entry object
2709 elm_entry_file_save(Evas_Object *obj)
2711 ELM_CHECK_WIDTYPE(obj, widtype);
2712 Widget_Data *wd = elm_widget_data_get(obj);
2714 if (wd->delay_write)
2716 ecore_timer_del(wd->delay_write);
2717 wd->delay_write = NULL;
2720 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
2724 * This sets the entry object to 'autosave' the loaded text file or not.
2726 * @param obj The entry object
2727 * @param autosave Autosave the loaded file or not
2732 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
2734 ELM_CHECK_WIDTYPE(obj, widtype);
2735 Widget_Data *wd = elm_widget_data_get(obj);
2737 wd->autosave = !!autosave;
2741 * This gets the entry object's 'autosave' status.
2743 * @param obj The entry object
2744 * @return Autosave the loaded file or not
2749 elm_entry_autosave_get(const Evas_Object *obj)
2751 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2752 Widget_Data *wd = elm_widget_data_get(obj);
2753 if (!wd) return EINA_FALSE;
2754 return wd->autosave;
2759 * Control pasting of text and images for the widget.
2761 * Normally the entry allows both text and images to be pasted. By setting
2762 * textonly to be true, this prevents images from being pasted.
2764 * Note this only changes the behaviour of text.
2766 * @param obj The entry object
2767 * @param pmode paste mode - 0 is text only, 1 is text+image+other.
2772 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
2774 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
2775 ELM_CHECK_WIDTYPE(obj, widtype);
2776 Widget_Data *wd = elm_widget_data_get(obj);
2778 textonly = !!textonly;
2779 if (wd->textonly == textonly) return;
2780 wd->textonly = !!textonly;
2781 if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
2782 #ifdef HAVE_ELEMENTARY_X
2783 elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
2788 * Getting elm_entry text paste/drop mode.
2790 * In textonly mode, only text may be pasted or dropped into the widget.
2792 * @param obj The entry object
2793 * @return If the widget only accepts text from pastes.
2798 elm_entry_cnp_textonly_get(Evas_Object *obj)
2800 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2801 Widget_Data *wd = elm_widget_data_get(obj);
2802 if (!wd) return EINA_FALSE;
2803 return wd->textonly;