1 #include <Elementary.h>
2 #include <Elementary_Cursor.h>
6 * @defgroup Entry Entry
8 * An entry is a convenience widget which shows
9 * a box that the user can enter text into. Unlike a
10 * @ref Scrolled_Entry widget, entries DO NOT scroll with user
11 * input. Entry widgets are capable of expanding past the
12 * boundaries of the window, thus resizing the window to its
15 * You can also insert "items" in the entry with:
17 * \<item size=16x16 vsize=full href=emoticon/haha\>\</item\>
19 * for example. sizing can be set bu size=WxH, relsize=WxH or absize=WxH with
20 * vsize=ascent or vsize=full. the href=NAME sets the item name. Entry
21 * supports a list of emoticon names by default. These are:
24 * - emoticon/angry-shout
25 * - emoticon/crazy-laugh
26 * - emoticon/evil-laugh
28 * - emoticon/goggle-smile
30 * - emoticon/grumpy-smile
32 * - emoticon/guilty-smile
34 * - emoticon/half-smile
35 * - emoticon/happy-panting
37 * - emoticon/indifferent
39 * - emoticon/knowing-grin
41 * - emoticon/little-bit-sorry
42 * - emoticon/love-lots
44 * - emoticon/minimal-smile
45 * - emoticon/not-happy
46 * - emoticon/not-impressed
48 * - emoticon/opensmile
51 * - emoticon/squint-laugh
52 * - emoticon/surprised
53 * - emoticon/suspicious
54 * - emoticon/tongue-dangling
55 * - emoticon/tongue-poke
58 * - emoticon/very-sorry
64 * These are built-in currently, but you can add your own item provieer that
65 * can create inlined objects in the text and fill the space allocated to the
66 * item with a custom object of your own.
68 * See the entry test for some more examples of use of this.
70 * Entries have functions to load a text file, display it,
71 * allowing editing of it and saving of changes back to the file loaded.
72 * Changes are written back to the original file after a short delay.
73 * The file to load and save to is specified by elm_entry_file_set().
75 * Signals that you can add callbacks for are:
77 * "changed" - The text within the entry was changed
78 * "activated" - The entry has had editing finished and changes are to be committed
79 (generally when enter key is pressed)
80 * "press" - The entry has been clicked
81 * "longpressed" - The entry has been clicked for a couple seconds
82 * "clicked" - The entry has been clicked
83 * "clicked,double" - The entry has been double clicked
84 * "focused" - The entry has received focus
85 * "unfocused" - The entry has lost focus
86 * "selection,paste" - A paste action has occurred
87 * "selection,copy" - A copy action has occurred
88 * "selection,cut" - A cut action has occurred
89 * "selection,start" - A selection has begun
90 * "selection,changed" - The selection has changed
91 * "selection,cleared" - The selection has been cleared
92 * "cursor,changed" - The cursor has changed
93 * "anchor,clicked" - The anchor has been clicked
94 * "preedit,changed" - The preedit string has changed
97 /* Maximum chunk size to be inserted to the entry at once
98 * FIXME: This size is arbitrary, should probably choose a better size.
99 * Possibly also find a way to set it to a low value for weak computers,
100 * and to a big value for better computers. */
101 #define _CHUNK_SIZE 10000
103 typedef struct _Mod_Api Mod_Api;
105 typedef struct _Widget_Data Widget_Data;
106 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
107 typedef struct _Elm_Entry_Item_Provider Elm_Entry_Item_Provider;
108 typedef struct _Elm_Entry_Text_Filter Elm_Entry_Text_Filter;
112 Evas_Object *ent, *scroller, *end, *icon;
113 Evas_Object *hoversel;
114 Ecore_Job *deferred_recalc_job;
115 Ecore_Event_Handler *sel_notify_handler;
116 Ecore_Event_Handler *sel_clear_handler;
117 Ecore_Timer *longpress_timer;
118 Ecore_Timer *delay_write;
119 /* for deferred appending */
120 Ecore_Idler *append_text_idler;
121 char *append_text_left;
122 int append_text_position;
124 /* Only for clipboard */
128 Elm_Text_Format format;
129 Evas_Coord lastw, entmw, entmh;
130 Evas_Coord downx, downy;
132 Eina_List *item_providers;
133 Eina_List *text_filters;
134 Ecore_Job *hovdeljob;
135 Mod_Api *api; // module api if supplied
137 Elm_Scroller_Policy policy_h, policy_v;
138 Elm_Wrap_Type linewrap;
139 Eina_Bool changed : 1;
140 Eina_Bool single_line : 1;
141 Eina_Bool password : 1;
142 Eina_Bool editable : 1;
143 Eina_Bool selection_asked : 1;
144 Eina_Bool have_selection : 1;
145 Eina_Bool selmode : 1;
146 Eina_Bool deferred_cur : 1;
147 Eina_Bool cur_changed : 1;
148 Eina_Bool disabled : 1;
149 Eina_Bool context_menu : 1;
150 Eina_Bool drag_selection_asked : 1;
151 Eina_Bool can_write : 1;
152 Eina_Bool autosave : 1;
153 Eina_Bool textonly : 1;
154 Eina_Bool usedown : 1;
155 Eina_Bool scroll : 1;
158 struct _Elm_Entry_Context_Menu_Item
162 const char *icon_file;
163 const char *icon_group;
164 Elm_Icon_Type icon_type;
169 struct _Elm_Entry_Item_Provider
171 Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
175 struct _Elm_Entry_Text_Filter
177 void (*func) (void *data, Evas_Object *entry, char **text);
181 typedef enum _Length_Unit
188 static const char *widtype = NULL;
190 #ifdef HAVE_ELEMENTARY_X
191 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
193 static void _del_hook(Evas_Object *obj);
194 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
195 static void _theme_hook(Evas_Object *obj);
196 static void _disable_hook(Evas_Object *obj);
197 static void _sizing_eval(Evas_Object *obj);
198 static void _on_focus_hook(void *data, Evas_Object *obj);
199 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
200 static const char *_getbase(Evas_Object *obj);
201 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
202 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
203 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
204 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
205 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
206 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
207 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
208 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
209 static void _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit);
211 static const char SIG_CHANGED[] = "changed";
212 static const char SIG_ACTIVATED[] = "activated";
213 static const char SIG_PRESS[] = "press";
214 static const char SIG_LONGPRESSED[] = "longpressed";
215 static const char SIG_CLICKED[] = "clicked";
216 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
217 static const char SIG_FOCUSED[] = "focused";
218 static const char SIG_UNFOCUSED[] = "unfocused";
219 static const char SIG_SELECTION_PASTE[] = "selection,paste";
220 static const char SIG_SELECTION_COPY[] = "selection,copy";
221 static const char SIG_SELECTION_CUT[] = "selection,cut";
222 static const char SIG_SELECTION_START[] = "selection,start";
223 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
224 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
225 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
226 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
227 static const char SIG_PREEDIT_CHANGED[] = "preedit,changed";
228 static const Evas_Smart_Cb_Description _signals[] = {
232 {SIG_LONGPRESSED, ""},
234 {SIG_CLICKED_DOUBLE, ""},
237 {SIG_SELECTION_PASTE, ""},
238 {SIG_SELECTION_COPY, ""},
239 {SIG_SELECTION_CUT, ""},
240 {SIG_SELECTION_START, ""},
241 {SIG_SELECTION_CHANGED, ""},
242 {SIG_SELECTION_CLEARED, ""},
243 {SIG_CURSOR_CHANGED, ""},
244 {SIG_ANCHOR_CLICKED, ""},
245 {SIG_PREEDIT_CHANGED, ""},
249 static Eina_List *entries = NULL;
253 void (*obj_hook) (Evas_Object *obj);
254 void (*obj_unhook) (Evas_Object *obj);
255 void (*obj_longpress) (Evas_Object *obj);
259 _module(Evas_Object *obj __UNUSED__)
261 static Elm_Module *m = NULL;
262 if (m) goto ok; // already found - just use
263 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
265 m->api = malloc(sizeof(Mod_Api));
266 if (!m->api) return NULL;
267 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
268 _elm_module_symbol_get(m, "obj_hook");
269 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
270 _elm_module_symbol_get(m, "obj_unhook");
271 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
272 _elm_module_symbol_get(m, "obj_longpress");
273 ok: // ok - return api
278 _buf_append(char *buf, const char *str, int *len, int *alloc)
280 int len2 = strlen(str);
281 if ((*len + len2) >= *alloc)
283 char *buf2 = realloc(buf, *alloc + len2 + 512);
284 if (!buf2) return NULL;
286 *alloc += (512 + len2);
288 strcpy(buf + *len, str);
294 _load_file(const char *file)
298 int alloc = 0, len = 0;
299 char *text = NULL, buf[16384 + 1];
301 f = fopen(file, "rb");
303 while ((size = fread(buf, 1, sizeof(buf) - 1, f)))
307 tmp_text = _buf_append(text, buf, &len, &alloc);
308 if (!tmp_text) break;
316 _load_plain(const char *file)
320 text = _load_file(file);
325 text2 = elm_entry_utf8_to_markup(text);
333 _load(Evas_Object *obj)
335 Widget_Data *wd = elm_widget_data_get(obj);
340 elm_entry_entry_set(obj, "");
345 case ELM_TEXT_FORMAT_PLAIN_UTF8:
346 text = _load_plain(wd->file);
348 case ELM_TEXT_FORMAT_MARKUP_UTF8:
349 text = _load_file(wd->file);
357 elm_entry_entry_set(obj, text);
361 elm_entry_entry_set(obj, "");
365 _save_markup_utf8(const char *file, const char *text)
369 if ((!text) || (!text[0]))
371 ecore_file_unlink(file);
374 f = fopen(file, "wb");
377 // FIXME: report a write error
380 fputs(text, f); // FIXME: catch error
385 _save_plain_utf8(const char *file, const char *text)
389 text2 = elm_entry_markup_to_utf8(text);
392 _save_markup_utf8(file, text2);
397 _save(Evas_Object *obj)
399 Widget_Data *wd = elm_widget_data_get(obj);
401 if (!wd->file) return;
404 case ELM_TEXT_FORMAT_PLAIN_UTF8:
405 _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
407 case ELM_TEXT_FORMAT_MARKUP_UTF8:
408 _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
416 _delay_write(void *data)
418 Widget_Data *wd = elm_widget_data_get(data);
419 if (!wd) return ECORE_CALLBACK_CANCEL;
421 wd->delay_write = NULL;
422 return ECORE_CALLBACK_CANCEL;
425 static Elm_Entry_Text_Filter *
426 _filter_new(void (*func) (void *data, Evas_Object *entry, char **text), void *data)
428 Elm_Entry_Text_Filter *tf = ELM_NEW(Elm_Entry_Text_Filter);
429 if (!tf) return NULL;
432 if (func == elm_entry_filter_limit_size)
434 Elm_Entry_Filter_Limit_Size *lim = data, *lim2;
441 lim2 = malloc(sizeof(Elm_Entry_Filter_Limit_Size));
447 memcpy(lim2, lim, sizeof(Elm_Entry_Filter_Limit_Size));
450 else if (func == elm_entry_filter_accept_set)
452 Elm_Entry_Filter_Accept_Set *as = data, *as2;
459 as2 = malloc(sizeof(Elm_Entry_Filter_Accept_Set));
466 as2->accepted = eina_stringshare_add(as->accepted);
468 as2->accepted = NULL;
470 as2->rejected = eina_stringshare_add(as->rejected);
472 as2->rejected = NULL;
481 _filter_free(Elm_Entry_Text_Filter *tf)
483 if (tf->func == elm_entry_filter_limit_size)
485 Elm_Entry_Filter_Limit_Size *lim = tf->data;
488 else if (tf->func == elm_entry_filter_accept_set)
490 Elm_Entry_Filter_Accept_Set *as = tf->data;
493 if (as->accepted) eina_stringshare_del(as->accepted);
494 if (as->rejected) eina_stringshare_del(as->rejected);
502 _del_pre_hook(Evas_Object *obj)
504 Widget_Data *wd = elm_widget_data_get(obj);
508 ecore_timer_del(wd->delay_write);
509 wd->delay_write = NULL;
510 if (wd->autosave) _save(obj);
515 _del_hook(Evas_Object *obj)
517 Widget_Data *wd = elm_widget_data_get(obj);
518 Elm_Entry_Context_Menu_Item *it;
519 Elm_Entry_Item_Provider *ip;
520 Elm_Entry_Text_Filter *tf;
522 if (wd->file) eina_stringshare_del(wd->file);
524 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
525 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
527 entries = eina_list_remove(entries, obj);
528 #ifdef HAVE_ELEMENTARY_X
529 if (wd->sel_notify_handler)
530 ecore_event_handler_del(wd->sel_notify_handler);
531 if (wd->sel_clear_handler)
532 ecore_event_handler_del(wd->sel_clear_handler);
534 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
535 if (wd->text) eina_stringshare_del(wd->text);
536 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
537 if (wd->append_text_idler)
539 ecore_idler_del(wd->append_text_idler);
540 free(wd->append_text_left);
541 wd->append_text_left = NULL;
542 wd->append_text_idler = NULL;
544 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
545 EINA_LIST_FREE(wd->items, it)
547 eina_stringshare_del(it->label);
548 eina_stringshare_del(it->icon_file);
549 eina_stringshare_del(it->icon_group);
552 EINA_LIST_FREE(wd->item_providers, ip)
556 EINA_LIST_FREE(wd->text_filters, tf)
564 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
566 Widget_Data *wd = elm_widget_data_get(obj);
567 edje_object_mirrored_set(wd->ent, rtl);
571 _theme_hook(Evas_Object *obj)
573 Widget_Data *wd = elm_widget_data_get(obj);
575 _elm_widget_mirrored_reload(obj);
576 _mirrored_set(obj, elm_widget_mirrored_get(obj));
578 t = eina_stringshare_add(elm_entry_entry_get(obj));
579 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
580 if (_elm_config->desktop_entry)
581 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
582 elm_entry_entry_set(obj, t);
583 eina_stringshare_del(t);
584 if (elm_widget_disabled_get(obj))
585 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
586 elm_entry_cursor_pos_set(obj, wd->cursor_pos);
587 if (elm_widget_focus_get(obj))
588 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
589 edje_object_message_signal_process(wd->ent);
590 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
591 elm_smart_scroller_mirrored_set(wd->scroller, elm_widget_mirrored_get(obj));
592 elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
593 elm_widget_style_get(obj));
599 edj = elm_smart_scroller_edje_object_get(wd->scroller);
600 str = edje_object_data_get(edj, "focus_highlight");
601 if ((str) && (!strcmp(str, "on")))
602 elm_widget_highlight_in_theme_set(obj, EINA_TRUE);
604 elm_widget_highlight_in_theme_set(obj, EINA_FALSE);
610 _disable_hook(Evas_Object *obj)
612 Widget_Data *wd = elm_widget_data_get(obj);
614 if (elm_widget_disabled_get(obj))
616 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
617 wd->disabled = EINA_TRUE;
621 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
622 wd->disabled = EINA_FALSE;
627 _recalc_cursor_geometry(Evas_Object *obj)
629 Widget_Data *wd = elm_widget_data_get(obj);
631 evas_object_smart_callback_call(obj, SIG_CURSOR_CHANGED, NULL);
632 if (!wd->deferred_recalc_job)
634 Evas_Coord cx, cy, cw, ch;
635 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
639 elm_widget_show_region_set(obj, cx, cy, cw, ch);
640 wd->cur_changed = EINA_FALSE;
644 wd->deferred_cur = EINA_TRUE;
648 _elm_win_recalc_job(void *data)
650 Widget_Data *wd = elm_widget_data_get(data);
651 Evas_Coord minh = -1, resw = -1, minw = -1;
653 wd->deferred_recalc_job = NULL;
655 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, NULL);
656 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
657 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
660 /* This is a hack to workaround the way min size hints are treated.
661 * If the minimum width is smaller than the restricted width, it means
662 * the mininmum doesn't matter. */
665 Evas_Coord ominw = -1;
666 evas_object_size_hint_min_get(data, &ominw, NULL);
669 evas_object_size_hint_min_set(data, minw, minh);
671 evas_object_size_hint_max_set(data, -1, minh);
673 evas_object_size_hint_max_set(data, -1, -1);
675 if (wd->deferred_cur)
677 Evas_Coord cx, cy, cw, ch;
678 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
682 elm_widget_show_region_set(data, cx, cy, cw, ch);
683 wd->cur_changed = EINA_FALSE;
689 _sizing_eval(Evas_Object *obj)
691 Widget_Data *wd = elm_widget_data_get(obj);
692 Evas_Coord minw = -1, minh = -1;
693 Evas_Coord resw, resh;
696 evas_object_geometry_get(obj, NULL, NULL, &resw, &resh);
699 if ((resw == wd->lastw) && (!wd->changed)) return;
700 wd->changed = EINA_FALSE;
704 Evas_Coord vw = 0, vh = 0, vmw = 0, vmh = 0, w = -1, h = -1;
706 evas_object_resize(wd->scroller, resw, resh);
707 edje_object_size_min_calc
708 (elm_smart_scroller_edje_object_get(wd->scroller),
710 elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
711 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, vw, 0);
714 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
716 if ((minw > 0) && (vw < minw)) vw = minw;
717 if (minh > vh) vh = minh;
719 if (wd->single_line) h = vmh + minh;
721 evas_object_resize(wd->ent, vw, vh);
722 evas_object_size_hint_min_set(obj, w, h);
724 evas_object_size_hint_max_set(obj, -1, h);
726 evas_object_size_hint_max_set(obj, -1, -1);
730 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
731 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
736 if (!wd->changed) return;
737 wd->changed = EINA_FALSE;
741 Evas_Coord vw = 0, vh = 0, vmw = 0, vmh = 0, w = -1, h = -1;
743 edje_object_size_min_calc(wd->ent, &minw, &minh);
746 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
748 elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
750 if ((minw > 0) && (vw < minw)) vw = minw;
751 if (minh > 0) vh = minh;
753 evas_object_resize(wd->ent, vw, vh);
754 edje_object_size_min_calc
755 (elm_smart_scroller_edje_object_get(wd->scroller),
757 if (wd->single_line) h = vmh + minh;
759 evas_object_size_hint_min_set(obj, w, h);
761 evas_object_size_hint_max_set(obj, -1, h);
763 evas_object_size_hint_max_set(obj, -1, -1);
767 edje_object_size_min_calc(wd->ent, &minw, &minh);
770 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
771 evas_object_size_hint_min_set(obj, minw, minh);
773 evas_object_size_hint_max_set(obj, -1, minh);
775 evas_object_size_hint_max_set(obj, -1, -1);
779 _recalc_cursor_geometry(obj);
783 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
785 Widget_Data *wd = elm_widget_data_get(obj);
786 Evas_Object *top = elm_widget_top_get(obj);
788 if (!wd->editable) return;
789 if (elm_widget_focus_get(obj))
791 evas_object_focus_set(wd->ent, EINA_TRUE);
792 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
793 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
794 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
798 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
799 evas_object_focus_set(wd->ent, EINA_FALSE);
800 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
801 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
806 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
808 Widget_Data *wd = elm_widget_data_get(obj);
810 edje_object_signal_emit(wd->ent, emission, source);
812 edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scroller),
817 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
819 Widget_Data *wd = elm_widget_data_get(obj);
821 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
823 edje_object_signal_callback_add(elm_smart_scroller_edje_object_get(wd->scroller),
824 emission, source, func_cb, data);
828 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
830 Widget_Data *wd = elm_widget_data_get(obj);
831 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
834 edje_object_signal_callback_del_full(elm_smart_scroller_edje_object_get(wd->scroller),
835 emission, source, func_cb, data);
839 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
841 Widget_Data *wd = elm_widget_data_get(obj);
842 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
846 _focus_region_hook(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
848 Widget_Data *wd = elm_widget_data_get(obj);
850 elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
854 _show_region_hook(void *data, Evas_Object *obj)
856 Widget_Data *wd = elm_widget_data_get(data);
857 Evas_Coord x, y, w, h;
859 elm_widget_show_region_get(obj, &x, &y, &w, &h);
861 elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
865 _hoversel_position(Evas_Object *obj)
867 Widget_Data *wd = elm_widget_data_get(obj);
868 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
873 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
882 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
884 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
895 evas_object_move(wd->hoversel, x + cx, y + cy);
896 evas_object_resize(wd->hoversel, cw, ch);
900 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
902 Widget_Data *wd = elm_widget_data_get(data);
904 if (wd->hoversel) _hoversel_position(data);
908 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
910 Widget_Data *wd = elm_widget_data_get(data);
919 Evas_Coord vw = 0, vh = 0;
921 elm_smart_scroller_child_viewport_size_get(wd->scroller, &vw, &vh);
922 if (vw < wd->entmw) vw = wd->entmw;
923 if (vh < wd->entmh) vh = wd->entmh;
924 evas_object_resize(wd->ent, vw, vh);
926 if (wd->hoversel) _hoversel_position(data);
930 _hover_del(void *data)
932 Widget_Data *wd = elm_widget_data_get(data);
937 evas_object_del(wd->hoversel);
940 wd->hovdeljob = NULL;
944 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
946 Widget_Data *wd = elm_widget_data_get(data);
949 if (wd->hoversel) evas_object_hide(wd->hoversel);
952 if (!_elm_config->desktop_entry)
955 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
958 elm_widget_scroll_freeze_pop(data);
959 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
960 wd->hovdeljob = ecore_job_add(_hover_del, data);
964 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
966 Widget_Data *wd = elm_widget_data_get(data);
968 wd->selmode = EINA_TRUE;
969 edje_object_part_text_select_none(wd->ent, "elm.text");
970 if (!_elm_config->desktop_entry)
973 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
975 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
976 if (!_elm_config->desktop_entry)
977 elm_widget_scroll_hold_push(data);
981 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
983 Widget_Data *wd = elm_widget_data_get(data);
985 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
986 if (wd->sel_notify_handler)
988 #ifdef HAVE_ELEMENTARY_X
989 Elm_Sel_Format formats;
990 wd->selection_asked = EINA_TRUE;
991 formats = ELM_SEL_FORMAT_MARKUP;
993 formats |= ELM_SEL_FORMAT_IMAGE;
994 elm_selection_get(ELM_SEL_CLIPBOARD, formats, data, NULL, NULL);
1000 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
1002 Widget_Data *wd = elm_widget_data_get(obj);
1006 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
1007 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
1008 if (seltype == ELM_SEL_CLIPBOARD)
1009 eina_stringshare_replace(&wd->cut_sel, sel);
1013 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1015 Widget_Data *wd = elm_widget_data_get(data);
1018 wd->selmode = EINA_FALSE;
1019 if (!_elm_config->desktop_entry)
1020 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1021 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1022 if (!_elm_config->desktop_entry)
1023 elm_widget_scroll_hold_pop(data);
1024 _store_selection(ELM_SEL_CLIPBOARD, data);
1025 edje_object_part_text_insert(wd->ent, "elm.text", "");
1026 edje_object_part_text_select_none(wd->ent, "elm.text");
1030 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1032 Widget_Data *wd = elm_widget_data_get(data);
1034 wd->selmode = EINA_FALSE;
1035 if (!_elm_config->desktop_entry)
1037 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1038 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1039 elm_widget_scroll_hold_pop(data);
1041 _store_selection(ELM_SEL_CLIPBOARD, data);
1042 // edje_object_part_text_select_none(wd->ent, "elm.text");
1046 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1048 Widget_Data *wd = elm_widget_data_get(data);
1050 wd->selmode = EINA_FALSE;
1051 if (!_elm_config->desktop_entry)
1052 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1053 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
1054 if (!_elm_config->desktop_entry)
1055 elm_widget_scroll_hold_pop(data);
1056 edje_object_part_text_select_none(wd->ent, "elm.text");
1060 _item_clicked(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
1062 Elm_Entry_Context_Menu_Item *it = data;
1063 Evas_Object *obj2 = it->obj;
1064 if (it->func) it->func(it->data, obj2, NULL);
1068 _menu_press(Evas_Object *obj)
1070 Widget_Data *wd = elm_widget_data_get(obj);
1073 const Elm_Entry_Context_Menu_Item *it;
1075 if ((wd->api) && (wd->api->obj_longpress))
1077 wd->api->obj_longpress(obj);
1079 else if (wd->context_menu)
1081 const char *context_menu_orientation;
1083 if (wd->hoversel) evas_object_del(wd->hoversel);
1084 else elm_widget_scroll_freeze_push(obj);
1085 wd->hoversel = elm_hoversel_add(obj);
1086 context_menu_orientation = edje_object_data_get
1087 (wd->ent, "context_menu_orientation");
1088 if ((context_menu_orientation) &&
1089 (!strcmp(context_menu_orientation, "horizontal")))
1090 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
1091 elm_object_style_set(wd->hoversel, "entry");
1092 elm_widget_sub_object_add(obj, wd->hoversel);
1093 elm_object_text_set(wd->hoversel, "Text");
1094 top = elm_widget_top_get(obj);
1095 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
1096 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, obj);
1097 if (wd->have_selection)
1101 if (wd->have_selection)
1103 elm_hoversel_item_add(wd->hoversel, E_("Copy"), NULL, ELM_ICON_NONE,
1106 elm_hoversel_item_add(wd->hoversel, E_("Cut"), NULL, ELM_ICON_NONE,
1109 elm_hoversel_item_add(wd->hoversel, E_("Cancel"), NULL, ELM_ICON_NONE,
1117 if (!_elm_config->desktop_entry)
1120 elm_hoversel_item_add(wd->hoversel, E_("Select"), NULL, ELM_ICON_NONE,
1123 if (1) // need way to detect if someone has a selection
1126 elm_hoversel_item_add(wd->hoversel, E_("Paste"), NULL, ELM_ICON_NONE,
1131 EINA_LIST_FOREACH(wd->items, l, it)
1133 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
1134 it->icon_type, _item_clicked, it);
1138 _hoversel_position(obj);
1139 evas_object_show(wd->hoversel);
1140 elm_hoversel_hover_begin(wd->hoversel);
1142 if (!_elm_config->desktop_entry)
1144 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
1145 edje_object_part_text_select_abort(wd->ent, "elm.text");
1151 _long_press(void *data)
1153 Widget_Data *wd = elm_widget_data_get(data);
1154 if (!wd) return ECORE_CALLBACK_CANCEL;
1156 wd->longpress_timer = NULL;
1157 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
1158 return ECORE_CALLBACK_CANCEL;
1162 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1164 Widget_Data *wd = elm_widget_data_get(data);
1165 Evas_Event_Mouse_Down *ev = event_info;
1167 if (wd->disabled) return;
1168 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
1169 wd->downx = ev->canvas.x;
1170 wd->downy = ev->canvas.y;
1171 if (ev->button == 1)
1173 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
1174 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
1179 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1181 Widget_Data *wd = elm_widget_data_get(data);
1182 Evas_Event_Mouse_Up *ev = event_info;
1184 if (wd->disabled) return;
1185 if (ev->button == 1)
1187 if (wd->longpress_timer)
1189 ecore_timer_del(wd->longpress_timer);
1190 wd->longpress_timer = NULL;
1193 else if (ev->button == 3)
1201 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1203 Widget_Data *wd = elm_widget_data_get(data);
1204 Evas_Event_Mouse_Move *ev = event_info;
1206 if (wd->disabled) return;
1209 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1211 if (wd->longpress_timer)
1213 ecore_timer_del(wd->longpress_timer);
1214 wd->longpress_timer = NULL;
1217 else if (wd->longpress_timer)
1221 dx = wd->downx - ev->cur.canvas.x;
1223 dy = wd->downy - ev->cur.canvas.y;
1226 ((_elm_config->finger_size / 2) *
1227 (_elm_config->finger_size / 2)))
1229 ecore_timer_del(wd->longpress_timer);
1230 wd->longpress_timer = NULL;
1234 else if (wd->longpress_timer)
1238 dx = wd->downx - ev->cur.canvas.x;
1240 dy = wd->downy - ev->cur.canvas.y;
1243 ((_elm_config->finger_size / 2) *
1244 (_elm_config->finger_size / 2)))
1246 ecore_timer_del(wd->longpress_timer);
1247 wd->longpress_timer = NULL;
1253 _getbase(Evas_Object *obj)
1255 Widget_Data *wd = elm_widget_data_get(obj);
1256 if (!wd) return "base";
1259 if (wd->password) return "base-password";
1262 if (wd->single_line) return "base-single";
1265 switch (wd->linewrap)
1268 return "base-charwrap";
1271 case ELM_WRAP_MIXED:
1272 return "base-mixedwrap";
1275 return "base-nowrap";
1282 if (wd->password) return "base-password";
1285 if (wd->single_line) return "base-single-noedit";
1288 switch (wd->linewrap)
1291 return "base-noedit-charwrap";
1293 return "base-noedit";
1294 case ELM_WRAP_MIXED:
1295 return "base-noedit-mixedwrap";
1298 return "base-nowrap-noedit";
1307 _entry_changed_common_handling(void *data, const char *event)
1309 Widget_Data *wd = elm_widget_data_get(data);
1312 wd->changed = EINA_TRUE;
1313 /* Reset the size hints which are no more relevant.
1314 * Keep the height, this is a hack, but doesn't really matter
1315 * cause we'll re-eval in a moment. */
1316 evas_object_size_hint_min_get(data, NULL, &minh);
1317 evas_object_size_hint_min_set(data, -1, minh);
1319 if (wd->text) eina_stringshare_del(wd->text);
1321 evas_object_smart_callback_call(data, event, NULL);
1322 if (wd->delay_write)
1324 ecore_timer_del(wd->delay_write);
1325 wd->delay_write = NULL;
1327 if ((!wd->autosave) || (!wd->file)) return;
1328 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1332 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1334 _entry_changed_common_handling(data, SIG_CHANGED);
1338 _signal_preedit_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1340 _entry_changed_common_handling(data, SIG_PREEDIT_CHANGED);
1344 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1346 Widget_Data *wd = elm_widget_data_get(data);
1350 EINA_LIST_FOREACH(entries, l, entry)
1352 if (entry != data) elm_entry_select_none(entry);
1354 wd->have_selection = EINA_TRUE;
1355 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1356 #ifdef HAVE_ELEMENTARY_X
1357 if (wd->sel_notify_handler)
1359 const char *txt = elm_entry_selection_get(data);
1362 top = elm_widget_top_get(data);
1363 if ((top) && (elm_win_xwindow_get(top)))
1364 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1370 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1372 Widget_Data *wd = elm_widget_data_get(data);
1374 wd->have_selection = EINA_TRUE;
1375 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1376 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1377 elm_entry_selection_get(data));
1381 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1383 Widget_Data *wd = elm_widget_data_get(data);
1385 if (!wd->have_selection) return;
1386 wd->have_selection = EINA_FALSE;
1387 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1388 if (wd->sel_notify_handler)
1392 #ifdef HAVE_ELEMENTARY_X
1395 top = elm_widget_top_get(data);
1396 if ((top) && (elm_win_xwindow_get(top)))
1397 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1400 eina_stringshare_del(wd->cut_sel);
1405 #ifdef HAVE_ELEMENTARY_X
1408 top = elm_widget_top_get(data);
1409 if ((top) && (elm_win_xwindow_get(top)))
1410 elm_selection_clear(ELM_SEL_PRIMARY, data);
1417 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1419 Widget_Data *wd = elm_widget_data_get(data);
1421 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1422 if (wd->sel_notify_handler)
1424 #ifdef HAVE_ELEMENTARY_X
1427 top = elm_widget_top_get(data);
1428 if ((top) && (elm_win_xwindow_get(top)))
1430 wd->selection_asked = EINA_TRUE;
1431 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
1439 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1441 Widget_Data *wd = elm_widget_data_get(data);
1443 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1444 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1445 elm_entry_selection_get(data));
1449 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1451 Widget_Data *wd = elm_widget_data_get(data);
1453 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1454 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1455 elm_entry_selection_get(data));
1456 edje_object_part_text_insert(wd->ent, "elm.text", "");
1457 wd->changed = EINA_TRUE;
1462 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1464 Widget_Data *wd = elm_widget_data_get(data);
1466 wd->cursor_pos = edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1467 wd->cur_changed = EINA_TRUE;
1468 _recalc_cursor_geometry(data);
1472 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1474 Widget_Data *wd = elm_widget_data_get(data);
1479 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1481 Widget_Data *wd = elm_widget_data_get(data);
1486 _signal_anchor_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1488 Widget_Data *wd = elm_widget_data_get(data);
1489 Elm_Entry_Anchor_Info ei;
1490 char *buf2, *p, *p2, *n;
1492 p = strrchr(emission, ',');
1495 const Eina_List *geoms;
1499 while (p2 >= emission)
1501 if (*p2 == ',') break;
1505 buf2 = alloca(5 + p - p2);
1506 strncpy(buf2, p2, p - p2);
1509 ei.button = atoi(buf2);
1510 ei.x = ei.y = ei.w = ei.h = 0;
1512 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1515 Evas_Textblock_Rectangle *r;
1517 Evas_Coord px, py, x, y;
1519 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1520 evas_pointer_canvas_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1521 EINA_LIST_FOREACH(geoms, l, r)
1523 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1524 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1535 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1540 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1542 Widget_Data *wd = elm_widget_data_get(data);
1547 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1549 Widget_Data *wd = elm_widget_data_get(data);
1554 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1556 Widget_Data *wd = elm_widget_data_get(data);
1561 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1563 Widget_Data *wd = elm_widget_data_get(data);
1565 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1569 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1571 Widget_Data *wd = elm_widget_data_get(data);
1573 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1577 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1579 Widget_Data *wd = elm_widget_data_get(data);
1581 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1585 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1587 Widget_Data *wd = elm_widget_data_get(data);
1589 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1592 #ifdef HAVE_ELEMENTARY_X
1594 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1596 Widget_Data *wd = elm_widget_data_get(data);
1597 Ecore_X_Event_Selection_Notify *ev = event;
1598 if (!wd) return ECORE_CALLBACK_PASS_ON;
1599 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1600 return ECORE_CALLBACK_PASS_ON;
1602 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1603 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1605 Ecore_X_Selection_Data_Text *text_data;
1607 text_data = ev->data;
1608 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1610 if (text_data->text)
1612 char *txt = _elm_util_text_to_mkup(text_data->text);
1616 elm_entry_entry_insert(data, txt);
1621 wd->selection_asked = EINA_FALSE;
1623 else if (ev->selection == ECORE_X_SELECTION_XDND)
1625 Ecore_X_Selection_Data_Text *text_data;
1627 text_data = ev->data;
1628 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1630 if (text_data->text)
1632 char *txt = _elm_util_text_to_mkup(text_data->text);
1636 /* Massive FIXME: this should be at the drag point */
1637 elm_entry_entry_insert(data, txt);
1642 wd->drag_selection_asked = EINA_FALSE;
1644 ecore_x_dnd_send_finished();
1647 return ECORE_CALLBACK_PASS_ON;
1651 _event_selection_clear(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1653 Widget_Data *wd = elm_widget_data_get(data);
1654 Ecore_X_Event_Selection_Clear *ev = event;
1655 if (!wd) return ECORE_CALLBACK_PASS_ON;
1656 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1657 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1658 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1660 elm_entry_select_none(data);
1662 return ECORE_CALLBACK_PASS_ON;
1666 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1671 wd = elm_widget_data_get(obj);
1672 if (!wd) return EINA_FALSE;
1673 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1675 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1676 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1677 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1678 EDJE_CURSOR_MAIN,drop->x,drop->y);
1679 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1680 elm_entry_entry_insert(obj, drop->data);
1681 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1682 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1688 static Evas_Object *
1689 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1691 Widget_Data *wd = elm_widget_data_get(data);
1694 Elm_Entry_Item_Provider *ip;
1696 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1698 o = ip->func(ip->data, data, item);
1701 if (!strncmp(item, "file://", 7))
1703 const char *fname = item + 7;
1705 o = evas_object_image_filled_add(evas_object_evas_get(data));
1706 evas_object_image_file_set(o, fname, NULL);
1707 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1709 evas_object_show(o);
1714 o = edje_object_add(evas_object_evas_get(data));
1715 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1719 o = edje_object_add(evas_object_evas_get(data));
1720 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1721 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1726 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
1728 Widget_Data *wd = elm_widget_data_get(data);
1730 Elm_Entry_Text_Filter *tf;
1732 if (type == EDJE_TEXT_FILTER_FORMAT)
1735 EINA_LIST_FOREACH(wd->text_filters, l, tf)
1737 tf->func(tf->data, data, text);
1743 /* This function is used to insert text by chunks in jobs */
1745 _text_append_idler(void *data)
1749 Evas_Object *obj = (Evas_Object *) data;
1750 Widget_Data *wd = elm_widget_data_get(obj);
1751 if (wd->text) eina_stringshare_del(wd->text);
1753 wd->changed = EINA_TRUE;
1755 start = wd->append_text_position;
1756 if(start + _CHUNK_SIZE < wd->append_text_len)
1758 wd->append_text_position = (start + _CHUNK_SIZE);
1759 /* Go to the start of the nearest codepoint, because we don't want
1760 * to cut it in the middle */
1761 eina_unicode_utf8_get_prev(wd->append_text_left,
1762 &wd->append_text_position);
1766 wd->append_text_position = wd->append_text_len;
1769 backup = wd->append_text_left[wd->append_text_position];
1770 wd->append_text_left[wd->append_text_position] = '\0';
1772 edje_object_part_text_append(wd->ent, "elm.text",
1773 wd->append_text_left + start);
1775 wd->append_text_left[wd->append_text_position] = backup;
1777 /* If there's still more to go, renew the idler, else, cleanup */
1778 if (wd->append_text_position < wd->append_text_len)
1780 return ECORE_CALLBACK_RENEW;
1784 free(wd->append_text_left);
1785 wd->append_text_left = NULL;
1786 wd->append_text_idler = NULL;
1787 return ECORE_CALLBACK_CANCEL;
1792 _add_chars_till_limit(Evas_Object *obj, char **text, int can_add, Length_Unit unit)
1794 int i = 0, unit_size;
1795 int current_len = strlen(*text);
1796 char *new_text = *text;
1797 if (unit >= LENGTH_UNIT_LAST) return;
1800 if (*new_text == '<')
1802 while (*new_text != '>')
1805 if (!*new_text) break;
1812 if (*new_text == '&')
1814 while (*(new_text + index) != ';')
1817 if (!*(new_text + index)) break;
1821 index = evas_string_char_next_get(new_text, index, NULL);
1822 markup = malloc(index + 1);
1823 strncpy(markup, new_text, index);
1825 if (unit == LENGTH_UNIT_BYTE)
1826 unit_size = strlen(elm_entry_markup_to_utf8(markup));
1827 else if (unit == LENGTH_UNIT_CHAR)
1828 unit_size = evas_string_char_len_get(elm_entry_markup_to_utf8(markup));
1834 if (can_add < unit_size)
1838 evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
1844 strncpy(new_text, new_text + index, current_len - ((new_text + index) - *text));
1845 current_len -= index;
1846 (*text)[current_len] = 0;
1851 can_add -= unit_size;
1856 evas_object_smart_callback_call(obj, "maxlength,reached", NULL);
1860 _elm_entry_text_set(Evas_Object *obj, const char *item, const char *entry)
1863 ELM_CHECK_WIDTYPE(obj, widtype);
1865 Widget_Data *wd = elm_widget_data_get(obj);
1867 if (!entry) entry = "";
1868 if (wd->text) eina_stringshare_del(wd->text);
1870 wd->changed = EINA_TRUE;
1872 /* Clear currently pending job if there is one */
1873 if (wd->append_text_idler)
1875 ecore_idler_del(wd->append_text_idler);
1876 free(wd->append_text_left);
1877 wd->append_text_left = NULL;
1878 wd->append_text_idler = NULL;
1881 len = strlen(entry);
1882 /* Split to ~_CHUNK_SIZE chunks */
1883 if (len > _CHUNK_SIZE)
1885 wd->append_text_left = (char *) malloc(len + 1);
1888 /* If we decided to use the idler */
1889 if (wd->append_text_left)
1891 /* Need to clear the entry first */
1892 edje_object_part_text_set(wd->ent, "elm.text", "");
1893 memcpy(wd->append_text_left, entry, len + 1);
1894 wd->append_text_position = 0;
1895 wd->append_text_len = len;
1896 wd->append_text_idler = ecore_idler_add(_text_append_idler, obj);
1900 edje_object_part_text_set(wd->ent, "elm.text", entry);
1905 _elm_entry_text_get(const Evas_Object *obj, const char *item)
1907 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1908 Widget_Data *wd = elm_widget_data_get(obj);
1909 if (item) return NULL;
1911 if (!wd) return NULL;
1912 if (wd->text) return wd->text;
1913 text = edje_object_part_text_get(wd->ent, "elm.text");
1916 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
1919 eina_stringshare_replace(&wd->text, text);
1924 * This adds an entry to @p parent object.
1926 * @param parent The parent object
1927 * @return The new object or NULL if it cannot be created
1932 elm_entry_add(Evas_Object *parent)
1934 Evas_Object *obj, *top;
1938 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1940 ELM_SET_WIDTYPE(widtype, "entry");
1941 elm_widget_type_set(obj, "entry");
1942 elm_widget_sub_object_add(parent, obj);
1943 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
1944 elm_widget_data_set(obj, wd);
1945 elm_widget_del_hook_set(obj, _del_hook);
1946 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1947 elm_widget_theme_hook_set(obj, _theme_hook);
1948 elm_widget_disable_hook_set(obj, _disable_hook);
1949 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
1950 elm_widget_focus_region_hook_set(obj, _focus_region_hook);
1951 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
1952 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
1953 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
1954 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
1955 elm_widget_can_focus_set(obj, EINA_TRUE);
1956 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
1957 elm_widget_text_set_hook_set(obj, _elm_entry_text_set);
1958 elm_widget_text_get_hook_set(obj, _elm_entry_text_get);
1960 wd->scroller = elm_smart_scroller_add(e);
1961 elm_widget_sub_object_add(obj, wd->scroller);
1962 elm_smart_scroller_widget_set(wd->scroller, obj);
1963 elm_smart_scroller_object_theme_set(obj, wd->scroller, "scroller", "entry",
1964 elm_widget_style_get(obj));
1965 evas_object_size_hint_weight_set(wd->scroller, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1966 evas_object_size_hint_align_set(wd->scroller, EVAS_HINT_FILL, EVAS_HINT_FILL);
1967 elm_smart_scroller_bounce_allow_set(wd->scroller, EINA_FALSE, EINA_FALSE);
1968 evas_object_propagate_events_set(wd->scroller, EINA_TRUE);
1970 wd->linewrap = ELM_WRAP_WORD;
1971 wd->editable = EINA_TRUE;
1972 wd->disabled = EINA_FALSE;
1973 wd->context_menu = EINA_TRUE;
1974 wd->autosave = EINA_TRUE;
1975 wd->textonly = EINA_FALSE;
1977 wd->ent = edje_object_add(e);
1978 elm_widget_sub_object_add(obj, wd->ent);
1979 edje_object_item_provider_set(wd->ent, _get_item, obj);
1980 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
1981 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
1982 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
1984 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
1986 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
1988 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, obj);
1990 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
1991 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
1992 _signal_entry_changed, obj);
1993 edje_object_signal_callback_add(wd->ent, "preedit,changed", "elm.text",
1994 _signal_preedit_changed, obj);
1995 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
1996 _signal_selection_start, obj);
1997 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
1998 _signal_selection_changed, obj);
1999 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2000 _signal_selection_cleared, obj);
2001 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
2002 _signal_entry_paste_request, obj);
2003 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2004 _signal_entry_copy_notify, obj);
2005 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2006 _signal_entry_cut_notify, obj);
2007 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2008 _signal_cursor_changed, obj);
2009 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2010 _signal_anchor_down, obj);
2011 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2012 _signal_anchor_up, obj);
2013 edje_object_signal_callback_add(wd->ent, "anchor,mouse,clicked,*", "elm.text",
2014 _signal_anchor_clicked, obj);
2015 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2016 _signal_anchor_move, obj);
2017 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2018 _signal_anchor_in, obj);
2019 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2020 _signal_anchor_out, obj);
2021 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2022 _signal_key_enter, obj);
2023 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2024 _signal_mouse_down, obj);
2025 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2026 _signal_mouse_clicked, obj);
2027 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2028 _signal_mouse_double, obj);
2029 edje_object_part_text_set(wd->ent, "elm.text", "");
2030 if (_elm_config->desktop_entry)
2031 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
2032 elm_widget_resize_object_set(obj, wd->ent);
2035 #ifdef HAVE_ELEMENTARY_X
2036 top = elm_widget_top_get(obj);
2037 if ((top) && (elm_win_xwindow_get(top)))
2039 wd->sel_notify_handler =
2040 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2041 _event_selection_notify, obj);
2042 wd->sel_clear_handler =
2043 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2044 _event_selection_clear, obj);
2047 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP | ELM_SEL_FORMAT_IMAGE,
2048 _drag_drop_cb, NULL);
2051 entries = eina_list_prepend(entries, obj);
2053 // module - find module for entry
2054 wd->api = _module(obj);
2055 // if found - hook in
2056 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2058 _mirrored_set(obj, elm_widget_mirrored_get(obj));
2059 // TODO: convert Elementary to subclassing of Evas_Smart_Class
2060 // TODO: and save some bytes, making descriptions per-class and not instance!
2061 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2066 * This sets the entry object not to line wrap. All input will
2067 * be on a single line, and the entry box will extend with user input.
2069 * @param obj The entry object
2070 * @param single_line If true, the text in the entry
2071 * will be on a single line.
2076 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2078 ELM_CHECK_WIDTYPE(obj, widtype);
2079 Widget_Data *wd = elm_widget_data_get(obj);
2081 if (wd->single_line == single_line) return;
2082 wd->single_line = single_line;
2083 wd->linewrap = ELM_WRAP_NONE;
2084 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
2088 if (wd->single_line)
2089 elm_smart_scroller_policy_set(wd->scroller,
2090 ELM_SMART_SCROLLER_POLICY_OFF,
2091 ELM_SMART_SCROLLER_POLICY_OFF);
2094 const Elm_Scroller_Policy map[3] =
2096 ELM_SMART_SCROLLER_POLICY_AUTO,
2097 ELM_SMART_SCROLLER_POLICY_ON,
2098 ELM_SMART_SCROLLER_POLICY_OFF
2100 elm_smart_scroller_policy_set(wd->scroller,
2109 * This returns true if the entry has been set to single line mode.
2110 * See also elm_entry_single_line_set().
2112 * @param obj The entry object
2113 * @return single_line If true, the text in the entry is set to display
2119 elm_entry_single_line_get(const Evas_Object *obj)
2121 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2122 Widget_Data *wd = elm_widget_data_get(obj);
2123 if (!wd) return EINA_FALSE;
2124 return wd->single_line;
2128 * This sets the entry object to password mode. All text entered
2129 * and/or displayed within the widget will be replaced with asterisks (*).
2131 * @param obj The entry object
2132 * @param password If true, password mode is enabled.
2137 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2139 ELM_CHECK_WIDTYPE(obj, widtype);
2140 Widget_Data *wd = elm_widget_data_get(obj);
2142 if (wd->password == password) return;
2143 wd->password = password;
2144 wd->single_line = EINA_TRUE;
2145 wd->linewrap = ELM_WRAP_NONE;
2150 * This returns whether password mode is enabled.
2151 * See also elm_entry_password_set().
2153 * @param obj The entry object
2154 * @return If true, the entry is set to display all characters
2160 elm_entry_password_get(const Evas_Object *obj)
2162 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2163 Widget_Data *wd = elm_widget_data_get(obj);
2164 if (!wd) return EINA_FALSE;
2165 return wd->password;
2169 * This sets the text displayed within the entry to @p entry.
2171 * @param obj The entry object
2172 * @param entry The text to be displayed
2177 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2179 _elm_entry_text_set(obj, NULL, entry);
2183 * This appends @p entry to the text of the entry.
2185 * @param obj The entry object
2186 * @param entry The text to be displayed
2191 elm_entry_entry_append(Evas_Object *obj, const char *entry)
2194 ELM_CHECK_WIDTYPE(obj, widtype);
2195 Widget_Data *wd = elm_widget_data_get(obj);
2197 if (!entry) entry = "";
2198 wd->changed = EINA_TRUE;
2200 len = strlen(entry);
2201 if (wd->append_text_left)
2204 tmpbuf = realloc(wd->append_text_left, wd->append_text_len + len + 1);
2210 wd->append_text_left = tmpbuf;
2211 memcpy(wd->append_text_left + wd->append_text_len, entry, len + 1);
2212 wd->append_text_len += len;
2216 /* FIXME: Add chunked appending here (like in entry_set) */
2217 edje_object_part_text_append(wd->ent, "elm.text", entry);
2222 * This returns the text currently shown in object @p entry.
2223 * See also elm_entry_entry_set().
2225 * @param obj The entry object
2226 * @return The currently displayed text or NULL on failure
2231 elm_entry_entry_get(const Evas_Object *obj)
2233 return _elm_entry_text_get(obj, NULL);
2237 * This returns EINA_TRUE if the entry is empty/there was an error
2238 * and EINA_FALSE if it is not empty.
2240 * @param obj The entry object
2241 * @return If the entry is empty or not.
2246 elm_entry_is_empty(const Evas_Object *obj)
2248 /* FIXME: until there's support for that in textblock, we just check
2249 * to see if the there is text or not. */
2250 ELM_CHECK_WIDTYPE(obj, widtype) EINA_TRUE;
2251 Widget_Data *wd = elm_widget_data_get(obj);
2252 const Evas_Object *tb;
2253 Evas_Textblock_Cursor *cur;
2255 if (!wd) return EINA_TRUE;
2256 /* It's a hack until we get the support suggested above.
2257 * We just create a cursor, point it to the begining, and then
2258 * try to advance it, if it can advance, the tb is not empty,
2259 * otherwise it is. */
2260 tb = edje_object_part_object_get(wd->ent, "elm.text");
2261 cur = evas_object_textblock_cursor_new((Evas_Object *) tb); /* This is
2262 actually, ok for the time being, thsese hackish stuff will be removed
2263 once evas 1.0 is out*/
2264 evas_textblock_cursor_pos_set(cur, 0);
2265 ret = evas_textblock_cursor_char_next(cur);
2266 evas_textblock_cursor_free(cur);
2272 * This returns all selected text within the entry.
2274 * @param obj The entry object
2275 * @return The selected text within the entry or NULL on failure
2280 elm_entry_selection_get(const Evas_Object *obj)
2282 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2283 Widget_Data *wd = elm_widget_data_get(obj);
2284 if (!wd) return NULL;
2285 return edje_object_part_text_selection_get(wd->ent, "elm.text");
2289 * This inserts text in @p entry where the current cursor position.
2291 * This inserts text at the cursor position is as if it was typed
2292 * by the user (note this also allows markup which a user
2293 * can't just "type" as it would be converted to escaped text, so this
2294 * call can be used to insert things like emoticon items or bold push/pop
2295 * tags, other font and color change tags etc.)
2297 * @param obj The entry object
2298 * @param entry The text to insert
2303 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2305 ELM_CHECK_WIDTYPE(obj, widtype);
2306 Widget_Data *wd = elm_widget_data_get(obj);
2308 edje_object_part_text_insert(wd->ent, "elm.text", entry);
2309 wd->changed = EINA_TRUE;
2314 * This enables word line wrapping in the entry object. It is the opposite
2315 * of elm_entry_single_line_set(). Additionally, setting this disables
2316 * character line wrapping.
2318 * @param obj The entry object
2319 * @param wrap If true, the entry will be wrapped once it reaches the end
2320 * of the object. Wrapping will occur at the end of the word before the end of the
2326 elm_entry_line_wrap_set(Evas_Object *obj, Elm_Wrap_Type wrap)
2328 ELM_CHECK_WIDTYPE(obj, widtype);
2329 Widget_Data *wd = elm_widget_data_get(obj);
2331 if (wd->linewrap == wrap) return;
2333 wd->linewrap = wrap;
2338 * This sets the editable attribute of the entry.
2340 * @param obj The entry object
2341 * @param editable If true, the entry will be editable by the user.
2342 * If false, it will be set to the disabled state.
2347 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2349 ELM_CHECK_WIDTYPE(obj, widtype);
2350 Widget_Data *wd = elm_widget_data_get(obj);
2352 if (wd->editable == editable) return;
2353 wd->editable = editable;
2356 #ifdef HAVE_ELEMENTARY_X
2358 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2360 elm_drop_target_del(obj);
2365 * This gets the editable attribute of the entry.
2366 * See also elm_entry_editable_set().
2368 * @param obj The entry object
2369 * @return If true, the entry is editable by the user.
2370 * If false, it is not editable by the user
2375 elm_entry_editable_get(const Evas_Object *obj)
2377 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2378 Widget_Data *wd = elm_widget_data_get(obj);
2379 if (!wd) return EINA_FALSE;
2380 return wd->editable;
2384 * This drops any existing text selection within the entry.
2386 * @param obj The entry object
2391 elm_entry_select_none(Evas_Object *obj)
2393 ELM_CHECK_WIDTYPE(obj, widtype);
2394 Widget_Data *wd = elm_widget_data_get(obj);
2398 wd->selmode = EINA_FALSE;
2399 if (!_elm_config->desktop_entry)
2400 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2401 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2403 wd->have_selection = EINA_FALSE;
2404 edje_object_part_text_select_none(wd->ent, "elm.text");
2408 * This selects all text within the entry.
2410 * @param obj The entry object
2415 elm_entry_select_all(Evas_Object *obj)
2417 ELM_CHECK_WIDTYPE(obj, widtype);
2418 Widget_Data *wd = elm_widget_data_get(obj);
2422 wd->selmode = EINA_FALSE;
2423 if (!_elm_config->desktop_entry)
2424 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2425 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2427 wd->have_selection = EINA_TRUE;
2428 edje_object_part_text_select_all(wd->ent, "elm.text");
2432 * This function returns the geometry of the cursor.
2434 * It's useful if you want to draw something on the cursor (or where it is),
2435 * or for example in the case of scrolled entry where you want to show the
2438 * @param obj The entry object
2439 * @param x returned geometry
2440 * @param y returned geometry
2441 * @param w returned geometry
2442 * @param h returned geometry
2443 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2448 elm_entry_cursor_geometry_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
2450 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2451 Widget_Data *wd = elm_widget_data_get(obj);
2452 if (!wd) return EINA_FALSE;
2453 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
2458 * This moves the cursor one place to the right within the entry.
2460 * @param obj The entry object
2461 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2466 elm_entry_cursor_next(Evas_Object *obj)
2468 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2469 Widget_Data *wd = elm_widget_data_get(obj);
2470 if (!wd) return EINA_FALSE;
2471 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2475 * This moves the cursor one place to the left within the entry.
2477 * @param obj The entry object
2478 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2483 elm_entry_cursor_prev(Evas_Object *obj)
2485 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2486 Widget_Data *wd = elm_widget_data_get(obj);
2487 if (!wd) return EINA_FALSE;
2488 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2492 * This moves the cursor one line up within the entry.
2494 * @param obj The entry object
2495 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2500 elm_entry_cursor_up(Evas_Object *obj)
2502 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2503 Widget_Data *wd = elm_widget_data_get(obj);
2504 if (!wd) return EINA_FALSE;
2505 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2509 * This moves the cursor one line down within the entry.
2511 * @param obj The entry object
2512 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2517 elm_entry_cursor_down(Evas_Object *obj)
2519 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2520 Widget_Data *wd = elm_widget_data_get(obj);
2521 if (!wd) return EINA_FALSE;
2522 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2526 * This moves the cursor to the beginning of the entry.
2528 * @param obj The entry object
2533 elm_entry_cursor_begin_set(Evas_Object *obj)
2535 ELM_CHECK_WIDTYPE(obj, widtype);
2536 Widget_Data *wd = elm_widget_data_get(obj);
2538 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2542 * This moves the cursor to the end of the entry.
2544 * @param obj The entry object
2549 elm_entry_cursor_end_set(Evas_Object *obj)
2551 ELM_CHECK_WIDTYPE(obj, widtype);
2552 Widget_Data *wd = elm_widget_data_get(obj);
2555 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2558 elm_widget_show_region_get(wd->ent, &x, &y, &w, &h);
2559 elm_smart_scroller_child_region_show(wd->scroller, x, y, w, h);
2564 * This moves the cursor to the beginning of the current line.
2566 * @param obj The entry object
2571 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2573 ELM_CHECK_WIDTYPE(obj, widtype);
2574 Widget_Data *wd = elm_widget_data_get(obj);
2576 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2580 * This moves the cursor to the end of the current line.
2582 * @param obj The entry object
2587 elm_entry_cursor_line_end_set(Evas_Object *obj)
2589 ELM_CHECK_WIDTYPE(obj, widtype);
2590 Widget_Data *wd = elm_widget_data_get(obj);
2592 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2596 * This begins a selection within the entry as though
2597 * the user were holding down the mouse button to make a selection.
2599 * @param obj The entry object
2604 elm_entry_cursor_selection_begin(Evas_Object *obj)
2606 ELM_CHECK_WIDTYPE(obj, widtype);
2607 Widget_Data *wd = elm_widget_data_get(obj);
2609 edje_object_part_text_select_begin(wd->ent, "elm.text");
2613 * This ends a selection within the entry as though
2614 * the user had just released the mouse button while making a selection.
2616 * @param obj The entry object
2621 elm_entry_cursor_selection_end(Evas_Object *obj)
2623 ELM_CHECK_WIDTYPE(obj, widtype);
2624 Widget_Data *wd = elm_widget_data_get(obj);
2626 edje_object_part_text_select_extend(wd->ent, "elm.text");
2630 * TODO: fill this in
2632 * @param obj The entry object
2633 * @return TODO: fill this in
2638 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2640 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2641 Widget_Data *wd = elm_widget_data_get(obj);
2642 if (!wd) return EINA_FALSE;
2643 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2647 * This returns whether the cursor is visible.
2649 * @param obj The entry object
2650 * @return If true, the cursor is visible.
2655 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2657 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2658 Widget_Data *wd = elm_widget_data_get(obj);
2659 if (!wd) return EINA_FALSE;
2660 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2664 * TODO: fill this in
2666 * @param obj The entry object
2667 * @return TODO: fill this in
2672 elm_entry_cursor_content_get(const Evas_Object *obj)
2674 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2675 Widget_Data *wd = elm_widget_data_get(obj);
2676 if (!wd) return NULL;
2677 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2681 * Sets the cursor position in the entry to the given value
2683 * @param obj The entry object
2684 * @param pos The position of the cursor
2689 elm_entry_cursor_pos_set(Evas_Object *obj, int pos)
2691 ELM_CHECK_WIDTYPE(obj, widtype);
2692 Widget_Data *wd = elm_widget_data_get(obj);
2694 edje_object_part_text_cursor_pos_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN, pos);
2695 edje_object_message_signal_process(wd->ent);
2699 * Retrieves the current position of the cursor in the entry
2701 * @param obj The entry object
2702 * @return The cursor position
2707 elm_entry_cursor_pos_get(const Evas_Object *obj)
2709 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2710 Widget_Data *wd = elm_widget_data_get(obj);
2712 return edje_object_part_text_cursor_pos_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2716 * This executes a "cut" action on the selected text in the entry.
2718 * @param obj The entry object
2723 elm_entry_selection_cut(Evas_Object *obj)
2725 ELM_CHECK_WIDTYPE(obj, widtype);
2726 Widget_Data *wd = elm_widget_data_get(obj);
2728 _cut(obj, NULL, NULL);
2732 * This executes a "copy" action on the selected text in the entry.
2734 * @param obj The entry object
2739 elm_entry_selection_copy(Evas_Object *obj)
2741 ELM_CHECK_WIDTYPE(obj, widtype);
2742 Widget_Data *wd = elm_widget_data_get(obj);
2744 _copy(obj, NULL, NULL);
2748 * This executes a "paste" action in the entry.
2750 * @param obj The entry object
2755 elm_entry_selection_paste(Evas_Object *obj)
2757 ELM_CHECK_WIDTYPE(obj, widtype);
2758 Widget_Data *wd = elm_widget_data_get(obj);
2760 _paste(obj, NULL, NULL);
2764 * This clears and frees the items in a entry's contextual (right click) menu.
2766 * @param obj The entry object
2771 elm_entry_context_menu_clear(Evas_Object *obj)
2773 ELM_CHECK_WIDTYPE(obj, widtype);
2774 Widget_Data *wd = elm_widget_data_get(obj);
2775 Elm_Entry_Context_Menu_Item *it;
2777 EINA_LIST_FREE(wd->items, it)
2779 eina_stringshare_del(it->label);
2780 eina_stringshare_del(it->icon_file);
2781 eina_stringshare_del(it->icon_group);
2787 * This adds an item to the entry's contextual menu.
2789 * @param obj The entry object
2790 * @param label The item's text label
2791 * @param icon_file The item's icon file
2792 * @param icon_type The item's icon type
2793 * @param func The callback to execute when the item is clicked
2794 * @param data The data to associate with the item for related functions
2799 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)
2801 ELM_CHECK_WIDTYPE(obj, widtype);
2802 Widget_Data *wd = elm_widget_data_get(obj);
2803 Elm_Entry_Context_Menu_Item *it;
2805 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2807 wd->items = eina_list_append(wd->items, it);
2809 it->label = eina_stringshare_add(label);
2810 it->icon_file = eina_stringshare_add(icon_file);
2811 it->icon_type = icon_type;
2813 it->data = (void *)data;
2817 * This disables the entry's contextual (right click) menu.
2819 * @param obj The entry object
2820 * @param disabled If true, the menu is disabled
2825 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2827 ELM_CHECK_WIDTYPE(obj, widtype);
2828 Widget_Data *wd = elm_widget_data_get(obj);
2830 if (wd->context_menu == !disabled) return;
2831 wd->context_menu = !disabled;
2835 * This returns whether the entry's contextual (right click) menu is disabled.
2837 * @param obj The entry object
2838 * @return If true, the menu is disabled
2843 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2845 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2846 Widget_Data *wd = elm_widget_data_get(obj);
2847 if (!wd) return EINA_FALSE;
2848 return !wd->context_menu;
2852 * This appends a custom item provider to the list for that entry
2854 * This appends the given callback. The list is walked from beginning to end
2855 * with each function called given the item href string in the text. If the
2856 * function returns an object handle other than NULL (it should create an
2857 * and object to do this), then this object is used to replace that item. If
2858 * not the next provider is called until one provides an item object, or the
2859 * default provider in entry does.
2861 * @param obj The entry object
2862 * @param func The function called to provide the item object
2863 * @param data The data passed to @p func
2868 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2870 ELM_CHECK_WIDTYPE(obj, widtype);
2871 Widget_Data *wd = elm_widget_data_get(obj);
2873 EINA_SAFETY_ON_NULL_RETURN(func);
2874 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2878 wd->item_providers = eina_list_append(wd->item_providers, ip);
2882 * This prepends a custom item provider to the list for that entry
2884 * This prepends the given callback. See elm_entry_item_provider_append() for
2887 * @param obj The entry object
2888 * @param func The function called to provide the item object
2889 * @param data The data passed to @p func
2894 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2896 ELM_CHECK_WIDTYPE(obj, widtype);
2897 Widget_Data *wd = elm_widget_data_get(obj);
2899 EINA_SAFETY_ON_NULL_RETURN(func);
2900 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
2904 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
2908 * This removes a custom item provider to the list for that entry
2910 * This removes the given callback. See elm_entry_item_provider_append() for
2913 * @param obj The entry object
2914 * @param func The function called to provide the item object
2915 * @param data The data passed to @p func
2920 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
2922 ELM_CHECK_WIDTYPE(obj, widtype);
2923 Widget_Data *wd = elm_widget_data_get(obj);
2925 Elm_Entry_Item_Provider *ip;
2927 EINA_SAFETY_ON_NULL_RETURN(func);
2928 EINA_LIST_FOREACH(wd->item_providers, l, ip)
2930 if ((ip->func == func) && ((!data) || (ip->data == data)))
2932 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
2940 * Append a filter function for text inserted in the entry
2942 * Append the given callback to the list. This functions will be called
2943 * whenever any text is inserted into the entry, with the text to be inserted
2944 * as a parameter. The callback function is free to alter the text in any way
2945 * it wants, but it must remember to free the given pointer and update it.
2946 * If the new text is to be discarded, the function can free it and set it text
2947 * parameter to NULL. This will also prevent any following filters from being
2950 * @param obj The entry object
2951 * @param func The function to use as text filter
2952 * @param data User data to pass to @p func
2957 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2960 Elm_Entry_Text_Filter *tf;
2961 ELM_CHECK_WIDTYPE(obj, widtype);
2963 wd = elm_widget_data_get(obj);
2965 EINA_SAFETY_ON_NULL_RETURN(func);
2967 tf = _filter_new(func, data);
2970 wd->text_filters = eina_list_append(wd->text_filters, tf);
2974 * Prepend a filter function for text insdrted in the entry
2976 * Prepend the given callback to the list. See elm_entry_text_filter_append()
2977 * for more information
2979 * @param obj The entry object
2980 * @param func The function to use as text filter
2981 * @param data User data to pass to @p func
2986 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
2989 Elm_Entry_Text_Filter *tf;
2990 ELM_CHECK_WIDTYPE(obj, widtype);
2992 wd = elm_widget_data_get(obj);
2994 EINA_SAFETY_ON_NULL_RETURN(func);
2996 tf = _filter_new(func, data);
2999 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
3003 * Remove a filter from the list
3005 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
3006 * for more information.
3008 * @param obj The entry object
3009 * @param func The filter function to remove
3010 * @param data The user data passed when adding the function
3015 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3019 Elm_Entry_Text_Filter *tf;
3020 ELM_CHECK_WIDTYPE(obj, widtype);
3022 wd = elm_widget_data_get(obj);
3024 EINA_SAFETY_ON_NULL_RETURN(func);
3026 EINA_LIST_FOREACH(wd->text_filters, l, tf)
3028 if ((tf->func == func) && ((!data) || (tf->data == data)))
3030 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
3038 * This converts a markup (HTML-like) string into UTF-8.
3039 * Returning string is obtained with malloc.
3040 * After use the returned string, it should be freed.
3042 * @param s The string (in markup) to be converted
3043 * @return The converted string (in UTF-8). It should be freed.
3048 elm_entry_markup_to_utf8(const char *s)
3050 char *ss = _elm_util_mkup_to_text(s);
3051 if (!ss) ss = strdup("");
3056 * This converts a UTF-8 string into markup (HTML-like).
3057 * Returning string is obtained with malloc.
3058 * After use the returned string, it should be freed.
3060 * @param s The string (in UTF-8) to be converted
3061 * @return The converted string (in markup). It should be freed.
3066 elm_entry_utf8_to_markup(const char *s)
3068 char *ss = _elm_util_text_to_mkup(s);
3069 if (!ss) ss = strdup("");
3074 * Filter inserted text based on user defined character and byte limits
3076 * Add this filter to an entry to limit the characters that it will accept
3077 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
3078 * The funtion works on the UTF-8 representation of the string, converting
3079 * it from the set markup, thus not accounting for any format in it.
3081 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
3082 * it as data when setting the filter. In it it's possible to set limits
3083 * by character count or bytes (any of them is disabled if 0), and both can
3084 * be set at the same time. In that case, it first checks for characters,
3087 * The function will cut the inserted text in order to allow only the first
3088 * number of characters that are still allowed. The cut is made in
3089 * characters, even when limiting by bytes, in order to always contain
3090 * valid ones and avoid half unicode characters making it in.
3095 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
3097 Elm_Entry_Filter_Limit_Size *lim = data;
3100 const char *(*text_get)(const Evas_Object *);
3101 const char *widget_type;
3103 EINA_SAFETY_ON_NULL_RETURN(data);
3104 EINA_SAFETY_ON_NULL_RETURN(entry);
3105 EINA_SAFETY_ON_NULL_RETURN(text);
3107 /* hack. I don't want to copy the entire function to work with
3109 widget_type = elm_widget_type_get(entry);
3110 if (!strcmp(widget_type, "entry"))
3111 text_get = elm_entry_entry_get;
3115 current = elm_entry_markup_to_utf8(text_get(entry));
3117 if (lim->max_char_count > 0)
3119 len = evas_string_char_len_get(current);
3120 if (len >= lim->max_char_count)
3122 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3128 newlen = evas_string_char_len_get(elm_entry_markup_to_utf8(*text));
3129 if ((len + newlen) > lim->max_char_count)
3130 _add_chars_till_limit(entry, text, (lim->max_char_count - len), LENGTH_UNIT_CHAR);
3132 else if (lim->max_byte_count > 0)
3134 len = strlen(current);
3135 if (len >= lim->max_byte_count)
3137 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3143 newlen = strlen(elm_entry_markup_to_utf8(*text));
3144 if ((len + newlen) > lim->max_byte_count)
3145 _add_chars_till_limit(entry, text, (lim->max_byte_count - len), LENGTH_UNIT_BYTE);
3151 * Filter inserted text based on accepted or rejected sets of characters
3153 * Add this filter to an entry to restrict the set of accepted characters
3154 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
3155 * This structure contains both accepted and rejected sets, but they are
3156 * mutually exclusive. If accepted is set, it will be used, otherwise it
3157 * goes on to the rejected set.
3160 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
3162 Elm_Entry_Filter_Accept_Set *as = data;
3166 int read_idx, last_read_idx = 0, read_char;
3168 EINA_SAFETY_ON_NULL_RETURN(data);
3169 EINA_SAFETY_ON_NULL_RETURN(text);
3171 if ((!as->accepted) && (!as->rejected))
3177 goes_in = EINA_TRUE;
3182 goes_in = EINA_FALSE;
3186 read_idx = evas_string_char_next_get(*text, 0, &read_char);
3189 int cmp_idx, cmp_char;
3190 Eina_Bool in_set = EINA_FALSE;
3192 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
3195 if (read_char == cmp_char)
3200 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
3202 if (in_set == goes_in)
3204 int size = read_idx - last_read_idx;
3205 const char *src = (*text) + last_read_idx;
3207 memcpy(insert, *text + last_read_idx, size);
3210 last_read_idx = read_idx;
3211 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
3217 * This sets the file (and implicitly loads it) for the text to display and
3218 * then edit. All changes are written back to the file after a short delay if
3219 * the entry object is set to autosave.
3221 * @param obj The entry object
3222 * @param file The path to the file to load and save
3223 * @param format The file format
3228 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
3230 ELM_CHECK_WIDTYPE(obj, widtype);
3231 Widget_Data *wd = elm_widget_data_get(obj);
3233 if (wd->delay_write)
3235 ecore_timer_del(wd->delay_write);
3236 wd->delay_write = NULL;
3238 if (wd->autosave) _save(obj);
3239 eina_stringshare_replace(&wd->file, file);
3240 wd->format = format;
3245 * Gets the file to load and save and the file format
3247 * @param obj The entry object
3248 * @param file The path to the file to load and save
3249 * @param format The file format
3254 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
3256 ELM_CHECK_WIDTYPE(obj, widtype);
3257 Widget_Data *wd = elm_widget_data_get(obj);
3259 if (file) *file = wd->file;
3260 if (format) *format = wd->format;
3264 * This function writes any changes made to the file set with
3265 * elm_entry_file_set()
3267 * @param obj The entry object
3272 elm_entry_file_save(Evas_Object *obj)
3274 ELM_CHECK_WIDTYPE(obj, widtype);
3275 Widget_Data *wd = elm_widget_data_get(obj);
3277 if (wd->delay_write)
3279 ecore_timer_del(wd->delay_write);
3280 wd->delay_write = NULL;
3283 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
3287 * This sets the entry object to 'autosave' the loaded text file or not.
3289 * @param obj The entry object
3290 * @param autosave Autosave the loaded file or not
3295 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
3297 ELM_CHECK_WIDTYPE(obj, widtype);
3298 Widget_Data *wd = elm_widget_data_get(obj);
3300 wd->autosave = !!autosave;
3304 * This gets the entry object's 'autosave' status.
3306 * @param obj The entry object
3307 * @return Autosave the loaded file or not
3312 elm_entry_autosave_get(const Evas_Object *obj)
3314 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3315 Widget_Data *wd = elm_widget_data_get(obj);
3316 if (!wd) return EINA_FALSE;
3317 return wd->autosave;
3321 * Control pasting of text and images for the widget.
3323 * Normally the entry allows both text and images to be pasted. By setting
3324 * textonly to be true, this prevents images from being pasted.
3326 * Note this only changes the behaviour of text.
3328 * @param obj The entry object
3329 * @param textonly paste mode - EINA_TRUE is text only, EINA_FALSE is text+image+other.
3334 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
3336 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
3337 ELM_CHECK_WIDTYPE(obj, widtype);
3338 Widget_Data *wd = elm_widget_data_get(obj);
3340 textonly = !!textonly;
3341 if (wd->textonly == textonly) return;
3342 wd->textonly = !!textonly;
3343 if (!textonly) format |= ELM_SEL_FORMAT_IMAGE;
3344 #ifdef HAVE_ELEMENTARY_X
3345 elm_drop_target_add(obj, format, _drag_drop_cb, NULL);
3350 * Getting elm_entry text paste/drop mode.
3352 * In textonly mode, only text may be pasted or dropped into the widget.
3354 * @param obj The entry object
3355 * @return If the widget only accepts text from pastes.
3360 elm_entry_cnp_textonly_get(const Evas_Object *obj)
3362 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3363 Widget_Data *wd = elm_widget_data_get(obj);
3364 if (!wd) return EINA_FALSE;
3365 return wd->textonly;
3369 * Enable or disable scrolling in entry
3371 * Normally the entry is not scrollable unless you enable it with this call.
3373 * @param obj The entry object
3374 * @param scroll EINA_TRUE if it is to be scrollable, EINA_FALSE otherwise
3379 elm_entry_scrollable_set(Evas_Object *obj, Eina_Bool scroll)
3381 ELM_CHECK_WIDTYPE(obj, widtype);
3382 Widget_Data *wd = elm_widget_data_get(obj);
3385 if (wd->scroll == scroll) return;
3386 wd->scroll = scroll;
3389 elm_widget_sub_object_del(obj, wd->scroller);
3390 elm_widget_resize_object_set(obj, wd->scroller);
3391 elm_widget_sub_object_add(obj, wd->ent);
3392 elm_smart_scroller_child_set(wd->scroller, wd->ent);
3393 evas_object_show(wd->scroller);
3394 elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
3398 elm_smart_scroller_child_set(wd->scroller, NULL);
3399 elm_widget_sub_object_del(obj, wd->ent);
3400 elm_widget_resize_object_set(obj, wd->ent);
3401 evas_object_smart_member_add(wd->scroller, obj);
3402 elm_widget_sub_object_add(obj, wd->scroller);
3403 evas_object_hide(wd->scroller);
3404 elm_widget_on_show_region_hook_set(obj, NULL, NULL);
3411 * Get the scrollable state of the entry
3413 * Normally the entry is not scrollable. This gets the scrollable state
3414 * of the entry. See elm_entry_scrollable_set() for more information.
3416 * @param obj The entry object
3417 * @return The scrollable state
3422 elm_entry_scrollable_get(const Evas_Object *obj)
3424 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3425 Widget_Data *wd = elm_widget_data_get(obj);
3426 if (!wd) return EINA_FALSE;
3431 * This sets a widget to be displayed to the left of a scrolled entry.
3433 * @param obj The scrolled entry object
3434 * @param icon The widget to display on the left side of the scrolled
3437 * @note A previously set widget will be destroyed.
3438 * @note If the object being set does not have minimum size hints set,
3439 * it won't get properly displayed.
3442 * @see elm_entry_end_set
3445 elm_entry_icon_set(Evas_Object *obj, Evas_Object *icon)
3447 ELM_CHECK_WIDTYPE(obj, widtype);
3448 Widget_Data *wd = elm_widget_data_get(obj);
3451 EINA_SAFETY_ON_NULL_RETURN(icon);
3452 if (wd->icon == icon) return;
3453 if (wd->icon) evas_object_del(wd->icon);
3455 edje = elm_smart_scroller_edje_object_get(wd->scroller);
3457 edje_object_part_swallow(edje, "elm.swallow.icon", wd->icon);
3458 edje_object_signal_emit(edje, "elm,action,show,icon", "elm");
3463 * Gets the leftmost widget of the scrolled entry. This object is
3464 * owned by the scrolled entry and should not be modified.
3466 * @param obj The scrolled entry object
3467 * @return the left widget inside the scroller
3472 elm_entry_icon_get(const Evas_Object *obj)
3474 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3475 Widget_Data *wd = elm_widget_data_get(obj);
3476 if (!wd) return NULL;
3481 * Unset the leftmost widget of the scrolled entry, unparenting and
3484 * @param obj The scrolled entry object
3485 * @return the previously set icon sub-object of this entry, on
3488 * @see elm_entry_icon_set()
3493 elm_entry_icon_unset(Evas_Object *obj)
3495 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3496 Widget_Data *wd = elm_widget_data_get(obj);
3497 Evas_Object *ret = NULL;
3498 if (!wd) return NULL;
3501 Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
3502 if (!edje) return NULL;
3504 edje_object_part_unswallow(edje, wd->icon);
3505 edje_object_signal_emit(edje, "elm,action,hide,icon", "elm");
3513 * Sets the visibility of the left-side widget of the scrolled entry,
3514 * set by @elm_entry_icon_set().
3516 * @param obj The scrolled entry object
3517 * @param setting EINA_TRUE if the object should be displayed,
3518 * EINA_FALSE if not.
3523 elm_entry_icon_visible_set(Evas_Object *obj, Eina_Bool setting)
3525 ELM_CHECK_WIDTYPE(obj, widtype);
3526 Widget_Data *wd = elm_widget_data_get(obj);
3527 if ((!wd) || (!wd->icon)) return;
3529 evas_object_hide(wd->icon);
3531 evas_object_show(wd->icon);
3536 * This sets a widget to be displayed to the end of a scrolled entry.
3538 * @param obj The scrolled entry object
3539 * @param end The widget to display on the right side of the scrolled
3542 * @note A previously set widget will be destroyed.
3543 * @note If the object being set does not have minimum size hints set,
3544 * it won't get properly displayed.
3547 * @see elm_entry_icon_set
3550 elm_entry_end_set(Evas_Object *obj, Evas_Object *end)
3552 ELM_CHECK_WIDTYPE(obj, widtype);
3553 Widget_Data *wd = elm_widget_data_get(obj);
3556 EINA_SAFETY_ON_NULL_RETURN(end);
3557 if (wd->end == end) return;
3558 if (wd->end) evas_object_del(wd->end);
3560 edje = elm_smart_scroller_edje_object_get(wd->scroller);
3562 edje_object_part_swallow(edje, "elm.swallow.end", wd->end);
3563 edje_object_signal_emit(edje, "elm,action,show,end", "elm");
3568 * Gets the endmost widget of the scrolled entry. This object is owned
3569 * by the scrolled entry and should not be modified.
3571 * @param obj The scrolled entry object
3572 * @return the right widget inside the scroller
3577 elm_entry_end_get(const Evas_Object *obj)
3579 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3580 Widget_Data *wd = elm_widget_data_get(obj);
3581 if (!wd) return NULL;
3586 * Unset the endmost widget of the scrolled entry, unparenting and
3589 * @param obj The scrolled entry object
3590 * @return the previously set icon sub-object of this entry, on
3593 * @see elm_entry_icon_set()
3598 elm_entry_end_unset(Evas_Object *obj)
3600 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3601 Widget_Data *wd = elm_widget_data_get(obj);
3602 Evas_Object *ret = NULL;
3603 if (!wd) return NULL;
3606 Evas_Object *edje = elm_smart_scroller_edje_object_get(wd->scroller);
3607 if (!edje) return NULL;
3609 edje_object_part_unswallow(edje, wd->end);
3610 edje_object_signal_emit(edje, "elm,action,hide,end", "elm");
3618 * Sets the visibility of the end widget of the scrolled entry, set by
3619 * @elm_entry_end_set().
3621 * @param obj The scrolled entry object
3622 * @param setting EINA_TRUE if the object should be displayed,
3623 * EINA_FALSE if not.
3628 elm_entry_end_visible_set(Evas_Object *obj, Eina_Bool setting)
3630 ELM_CHECK_WIDTYPE(obj, widtype);
3631 Widget_Data *wd = elm_widget_data_get(obj);
3632 if ((!wd) || (!wd->end)) return;
3634 evas_object_hide(wd->end);
3636 evas_object_show(wd->end);
3641 * This sets the scrolled entry's scrollbar policy (ie. enabling/disabling them).
3643 * @param obj The scrolled entry object
3644 * @param h The horizontal scrollbar policy to apply
3645 * @param v The vertical scrollbar policy to apply
3650 elm_entry_scrollbar_policy_set(Evas_Object *obj, Elm_Scroller_Policy h, Elm_Scroller_Policy v)
3652 ELM_CHECK_WIDTYPE(obj, widtype);
3653 Widget_Data *wd = elm_widget_data_get(obj);
3654 const Elm_Scroller_Policy map[3] =
3656 ELM_SMART_SCROLLER_POLICY_AUTO,
3657 ELM_SMART_SCROLLER_POLICY_ON,
3658 ELM_SMART_SCROLLER_POLICY_OFF
3663 elm_smart_scroller_policy_set(wd->scroller,
3669 * This enables/disables bouncing within the entry.
3671 * @param obj The scrolled entry object
3672 * @param h The horizontal bounce state
3673 * @param v The vertical bounce state
3678 elm_entry_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
3680 ELM_CHECK_WIDTYPE(obj, widtype);
3681 Widget_Data *wd = elm_widget_data_get(obj);
3683 elm_smart_scroller_bounce_allow_set(wd->scroller, h_bounce, v_bounce);
3687 * Get the bounce mode
3689 * @param obj The Entry object
3690 * @param h_bounce Allow bounce horizontally
3691 * @param v_bounce Allow bounce vertically
3696 elm_entry_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
3698 ELM_CHECK_WIDTYPE(obj, widtype);
3699 Widget_Data *wd = elm_widget_data_get(obj);
3701 elm_smart_scroller_bounce_allow_get(wd->scroller, h_bounce, v_bounce);