1 #include <Elementary.h>
2 #include <Elementary_Cursor.h>
4 #include "elm_module_priv.h"
7 * @defgroup Entry Entry
9 * An entry is a convenience widget which shows
10 * a box that the user can enter text into. Unlike a
11 * @ref Scrolled_Entry widget, entries DO NOT scroll with user
12 * input. Entry widgets are capable of expanding past the
13 * boundaries of the window, thus resizing the window to its
16 * You can also insert "items" in the entry with:
18 * \<item size=16x16 vsize=full href=emoticon/haha\>\</item\>
20 * for example. sizing can be set bu size=WxH, relsize=WxH or absize=WxH with
21 * vsize=ascent or vsize=full. the href=NAME sets the item name. Entry
22 * supports a list of emoticon names by default. These are:
25 * - emoticon/angry-shout
26 * - emoticon/crazy-laugh
27 * - emoticon/evil-laugh
29 * - emoticon/goggle-smile
31 * - emoticon/grumpy-smile
33 * - emoticon/guilty-smile
35 * - emoticon/half-smile
36 * - emoticon/happy-panting
38 * - emoticon/indifferent
40 * - emoticon/knowing-grin
42 * - emoticon/little-bit-sorry
43 * - emoticon/love-lots
45 * - emoticon/minimal-smile
46 * - emoticon/not-happy
47 * - emoticon/not-impressed
49 * - emoticon/opensmile
52 * - emoticon/squint-laugh
53 * - emoticon/surprised
54 * - emoticon/suspicious
55 * - emoticon/tongue-dangling
56 * - emoticon/tongue-poke
59 * - emoticon/very-sorry
65 * These are built-in currently, but you can add your own item provieer that
66 * can create inlined objects in the text and fill the space allocated to the
67 * item with a custom object of your own.
69 * See the entry test for some more examples of use of this.
71 * Entries have functions to load a text file, display it,
72 * allowing editing of it and saving of changes back to the file loaded.
73 * Changes are written back to the original file after a short delay.
74 * The file to load and save to is specified by elm_entry_file_set().
76 * 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 (generally when enter key is pressed)
79 * - "press" - The entry has been clicked
80 * - "longpressed" - The entry has been clicked for a couple seconds
81 * - "clicked" - The entry has been clicked
82 * - "clicked,double" - The entry has been double clicked
83 * - "focused" - The entry has received focus
84 * - "unfocused" - The entry has lost focus
85 * - "selection,paste" - A paste action has occurred
86 * - "selection,copy" - A copy action has occurred
87 * - "selection,cut" - A cut action has occurred
88 * - "selection,start" - A selection has begun
89 * - "selection,changed" - The selection has changed
90 * - "selection,cleared" - The selection has been cleared
91 * - "cursor,changed" - The cursor has changed
92 * - "anchor,clicked" - The anchor has been clicked
95 typedef struct _Mod_Api Mod_Api;
97 typedef struct _Widget_Data Widget_Data;
98 typedef struct _Elm_Entry_Context_Menu_Item Elm_Entry_Context_Menu_Item;
99 typedef struct _Elm_Entry_Item_Provider Elm_Entry_Item_Provider;
100 typedef struct _Elm_Entry_Text_Filter Elm_Entry_Text_Filter;
106 Evas_Object *hoversel;
107 Ecore_Job *deferred_recalc_job;
108 Ecore_Event_Handler *sel_notify_handler;
109 Ecore_Event_Handler *sel_clear_handler;
110 Ecore_Timer *longpress_timer;
111 Ecore_Timer *delay_write;
112 /* Only for clipboard */
116 int ellipsis_threshold;
118 Elm_Text_Format format;
120 Evas_Coord downx, downy;
121 Evas_Coord cx, cy, cw, ch;
123 Eina_List *item_providers;
124 Eina_List *text_filters;
125 Ecore_Job *hovdeljob;
126 Mod_Api *api; // module api if supplied
128 Eina_Bool changed : 1;
129 Eina_Bool linewrap : 1;
130 Eina_Bool char_linewrap : 1;
131 Eina_Bool single_line : 1;
132 Eina_Bool password : 1;
133 Eina_Bool show_last_character : 1;
134 Eina_Bool editable : 1;
135 Eina_Bool selection_asked : 1;
136 Eina_Bool have_selection : 1;
137 Eina_Bool handler_moving : 1;
138 Eina_Bool selmode : 1;
139 Eina_Bool deferred_cur : 1;
140 Eina_Bool disabled : 1;
141 Eina_Bool double_clicked : 1;
142 Eina_Bool long_pressed : 1;
143 Eina_Bool context_menu : 1;
144 Eina_Bool drag_selection_asked : 1;
145 Eina_Bool bgcolor : 1;
146 Eina_Bool ellipsis : 1;
147 Eina_Bool can_write : 1;
148 Eina_Bool autosave : 1;
149 Eina_Bool textonly : 1;
150 Eina_Bool autoreturnkey : 1;
151 Eina_Bool input_panel_enable : 1;
152 Eina_Bool autocapital : 1;
153 Elm_Input_Panel_Layout input_panel_layout;
154 Eina_Bool autoperiod : 1;
157 struct _Elm_Entry_Context_Menu_Item
161 const char *icon_file;
162 const char *icon_group;
163 Elm_Icon_Type icon_type;
168 struct _Elm_Entry_Item_Provider
170 Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item);
174 struct _Elm_Entry_Text_Filter
176 void (*func) (void *data, Evas_Object *entry, char **text);
180 static const char *widtype = NULL;
182 static Evas_Object *cnpwidgetdata = NULL;
185 static Eina_Bool _drag_drop_cb(void *data, Evas_Object *obj, Elm_Selection_Data *);
186 static void _del_hook(Evas_Object *obj);
187 static void _theme_hook(Evas_Object *obj);
188 static void _disable_hook(Evas_Object *obj);
189 static void _sizing_eval(Evas_Object *obj);
190 static void _on_focus_hook(void *data, Evas_Object *obj);
191 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
192 static const char *_getbase(Evas_Object *obj);
193 static void _signal_entry_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
194 static void _signal_selection_start(void *data, Evas_Object *obj, const char *emission, const char *source);
195 static void _signal_selection_end(void *data, Evas_Object *obj, const char *emission, const char *source);
196 static void _signal_selection_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
197 static void _signal_selection_cleared(void *data, Evas_Object *obj, const char *emission, const char *source);
198 static void _signal_handler_move_start(void *data, Evas_Object *obj, const char *emission, const char *source);
199 static void _signal_handler_move_end(void *data, Evas_Object *obj, const char *emission, const char *source);
200 static void _signal_entry_paste_request(void *data, Evas_Object *obj, const char *emission, const char *source);
201 static void _signal_entry_copy_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
202 static void _signal_entry_cut_notify(void *data, Evas_Object *obj, const char *emission, const char *source);
203 static void _signal_cursor_changed(void *data, Evas_Object *obj, const char *emission, const char *source);
204 static int _get_value_in_key_string(const char *oldstring, char *key, char **value);
205 static int _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag);
206 static int _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag);
207 static int _is_width_over(Evas_Object *obj);
208 static void _ellipsis_entry_to_width(Evas_Object *obj);
209 static void _reverse_ellipsis_entry(Evas_Object *obj);
210 static int _entry_length_get(Evas_Object *obj);
212 static const char SIG_CHANGED[] = "changed";
213 static const char SIG_ACTIVATED[] = "activated";
214 static const char SIG_PRESS[] = "press";
215 static const char SIG_LONGPRESSED[] = "longpressed";
216 static const char SIG_CLICKED[] = "clicked";
217 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
218 static const char SIG_FOCUSED[] = "focused";
219 static const char SIG_UNFOCUSED[] = "unfocused";
220 static const char SIG_SELECTION_PASTE[] = "selection,paste";
221 static const char SIG_SELECTION_COPY[] = "selection,copy";
222 static const char SIG_SELECTION_CUT[] = "selection,cut";
223 static const char SIG_SELECTION_START[] = "selection,start";
224 static const char SIG_SELECTION_CHANGED[] = "selection,changed";
225 static const char SIG_SELECTION_CLEARED[] = "selection,cleared";
226 static const char SIG_CURSOR_CHANGED[] = "cursor,changed";
227 static const char SIG_ANCHOR_CLICKED[] = "anchor,clicked";
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, ""},
248 static Eina_List *entries = NULL;
252 void (*obj_hook) (Evas_Object *obj);
253 void (*obj_unhook) (Evas_Object *obj);
254 void (*obj_longpress) (Evas_Object *obj);
255 void (*obj_hidemenu) (Evas_Object *obj);
256 void (*obj_mouseup) (Evas_Object *obj);
260 _module(Evas_Object *obj __UNUSED__)
262 static Elm_Module *m = NULL;
263 if (m) goto ok; // already found - just use
264 if (!(m = _elm_module_find_as("entry/api"))) return NULL;
266 m->api = malloc(sizeof(Mod_Api));
267 if (!m->api) return NULL;
268 ((Mod_Api *)(m->api) )->obj_hook = // called on creation
269 _elm_module_symbol_get(m, "obj_hook");
270 ((Mod_Api *)(m->api) )->obj_unhook = // called on deletion
271 _elm_module_symbol_get(m, "obj_unhook");
272 ((Mod_Api *)(m->api) )->obj_longpress = // called on long press menu
273 _elm_module_symbol_get(m, "obj_longpress");
274 ((Mod_Api *)(m->api) )->obj_hidemenu = // called on hide menu
275 _elm_module_symbol_get(m, "obj_hidemenu");
276 ((Mod_Api *)(m->api) )->obj_mouseup = // called on mouseup
277 _elm_module_symbol_get(m, "obj_mouseup");
278 ok: // ok - return api
283 _buf_append(char *buf, const char *str, int *len, int *alloc)
285 int len2 = strlen(str);
286 if ((*len + len2) >= *alloc)
288 char *buf2 = realloc(buf, *alloc + len2 + 512);
289 if (!buf2) return NULL;
291 *alloc += (512 + len2);
293 strcpy(buf + *len, str);
299 _load_file(const char *file)
303 int alloc = 0, len = 0;
304 char *text = NULL, buf[PATH_MAX];
306 f = fopen(file, "rb");
308 while ((size = fread(buf, 1, sizeof(buf), f)))
312 tmp_text = _buf_append(text, buf, &len, &alloc);
313 if (!tmp_text) break;
321 _load_plain(const char *file)
325 text = _load_file(file);
330 text2 = elm_entry_utf8_to_markup(text);
338 _load(Evas_Object *obj)
340 Widget_Data *wd = elm_widget_data_get(obj);
345 elm_entry_entry_set(obj, "");
350 case ELM_TEXT_FORMAT_PLAIN_UTF8:
351 text = _load_plain(wd->file);
353 case ELM_TEXT_FORMAT_MARKUP_UTF8:
354 text = _load_file(wd->file);
362 elm_entry_entry_set(obj, text);
366 elm_entry_entry_set(obj, "");
370 _save_markup_utf8(const char *file, const char *text)
374 if ((!text) || (!text[0]))
376 ecore_file_unlink(file);
379 f = fopen(file, "wb");
382 // FIXME: report a write error
385 fputs(text, f); // FIXME: catch error
390 _save_plain_utf8(const char *file, const char *text)
394 text2 = elm_entry_markup_to_utf8(text);
397 _save_markup_utf8(file, text2);
402 _save(Evas_Object *obj)
404 Widget_Data *wd = elm_widget_data_get(obj);
406 if (!wd->file) return;
409 case ELM_TEXT_FORMAT_PLAIN_UTF8:
410 _save_plain_utf8(wd->file, elm_entry_entry_get(obj));
412 case ELM_TEXT_FORMAT_MARKUP_UTF8:
413 _save_markup_utf8(wd->file, elm_entry_entry_get(obj));
421 _delay_write(void *data)
423 Widget_Data *wd = elm_widget_data_get(data);
424 if (!wd) return ECORE_CALLBACK_CANCEL;
426 wd->delay_write = NULL;
427 return ECORE_CALLBACK_CANCEL;
431 _del_pre_hook(Evas_Object *obj)
433 Widget_Data *wd = elm_widget_data_get(obj);
437 ecore_timer_del(wd->delay_write);
438 wd->delay_write = NULL;
439 if (wd->autosave) _save(obj);
444 _del_hook(Evas_Object *obj)
446 Widget_Data *wd = elm_widget_data_get(obj);
447 Elm_Entry_Context_Menu_Item *it;
448 Elm_Entry_Item_Provider *ip;
449 Elm_Entry_Text_Filter *tf;
451 if (wd->file) eina_stringshare_del(wd->file);
453 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
454 if ((wd->api) && (wd->api->obj_unhook)) wd->api->obj_unhook(obj); // module - unhook
456 entries = eina_list_remove(entries, obj);
457 #ifdef HAVE_ELEMENTARY_X
458 ecore_event_handler_del(wd->sel_notify_handler);
459 ecore_event_handler_del(wd->sel_clear_handler);
461 if (wd->cut_sel) eina_stringshare_del(wd->cut_sel);
462 if (wd->text) eina_stringshare_del(wd->text);
463 if (wd->bg) evas_object_del(wd->bg);
464 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
465 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
466 EINA_LIST_FREE(wd->items, it)
468 eina_stringshare_del(it->label);
469 eina_stringshare_del(it->icon_file);
470 eina_stringshare_del(it->icon_group);
473 EINA_LIST_FREE(wd->item_providers, ip)
477 EINA_LIST_FREE(wd->text_filters, tf)
485 _theme_hook(Evas_Object *obj)
487 Widget_Data *wd = elm_widget_data_get(obj);
489 Ecore_IMF_Context *ic;
491 t = eina_stringshare_add(elm_entry_entry_get(obj));
492 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
493 elm_entry_entry_set(obj, t);
494 eina_stringshare_del(t);
495 if (elm_widget_disabled_get(obj))
496 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
497 edje_object_message_signal_process(wd->ent);
498 edje_object_scale_set(wd->ent, elm_widget_scale_get(obj) * _elm_config->scale);
499 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
500 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
501 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", wd->input_panel_enable);
503 ic = edje_object_part_text_imf_context_get(wd->ent, "elm.text");
506 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)wd->input_panel_layout);
513 _disable_hook(Evas_Object *obj)
515 Widget_Data *wd = elm_widget_data_get(obj);
517 if (elm_widget_disabled_get(obj))
519 edje_object_signal_emit(wd->ent, "elm,state,disabled", "elm");
520 wd->disabled = EINA_TRUE;
524 edje_object_signal_emit(wd->ent, "elm,state,enabled", "elm");
525 wd->disabled = EINA_FALSE;
530 _elm_win_recalc_job(void *data)
532 Widget_Data *wd = elm_widget_data_get(data);
533 Evas_Coord minw = -1, minh = -1, maxh = -1;
534 Evas_Coord resw, resh, minminw;
536 wd->deferred_recalc_job = NULL;
537 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
539 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, 0, 0);
540 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
542 edje_object_size_min_restricted_calc(wd->ent, &minw, &minh, resw, 0);
543 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
544 evas_object_size_hint_min_set(data, minminw, minh);
545 if (wd->single_line) maxh = minh;
546 evas_object_size_hint_max_set(data, -1, maxh);
547 if (wd->deferred_cur)
548 elm_widget_show_region_set(data, wd->cx, wd->cy, wd->cw, wd->ch);
552 _sizing_eval(Evas_Object *obj)
554 Widget_Data *wd = elm_widget_data_get(obj);
555 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
556 Evas_Coord resw, resh;
558 if ((wd->linewrap) || (wd->char_linewrap))
560 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
561 if ((resw == wd->lastw) && (!wd->changed)) return;
562 wd->changed = EINA_FALSE;
564 if (wd->deferred_recalc_job) ecore_job_del(wd->deferred_recalc_job);
565 wd->deferred_recalc_job = ecore_job_add(_elm_win_recalc_job, obj);
569 evas_object_geometry_get(wd->ent, NULL, NULL, &resw, &resh);
570 edje_object_size_min_calc(wd->ent, &minw, &minh);
571 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
572 evas_object_size_hint_min_set(obj, minw, minh);
573 if (wd->single_line) maxh = minh;
574 evas_object_size_hint_max_set(obj, maxw, maxh);
576 if (wd->ellipsis && wd->single_line)
578 if (_is_width_over(obj))
579 _ellipsis_entry_to_width(obj);
580 else if (wd->ellipsis_threshold > 1 && _entry_length_get(obj) < wd->ellipsis_threshold)
581 _reverse_ellipsis_entry(obj);
587 _check_enable_returnkey(Evas_Object *obj)
589 Widget_Data *wd = elm_widget_data_get(obj);
592 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
595 if (!wd->autoreturnkey) return;
597 if (_entry_length_get(obj) == 0)
599 ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_TRUE);
603 ecore_imf_context_input_panel_key_disabled_set(ic, ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL, ECORE_IMF_INPUT_PANEL_KEY_ENTER, EINA_FALSE);
608 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
610 Widget_Data *wd = elm_widget_data_get(obj);
611 Evas_Object *top = elm_widget_top_get(obj);
612 Evas_Object *parent_obj = obj;
613 Evas_Object *above = NULL;
616 if (!wd->editable) return;
617 if (elm_widget_focus_get(obj))
619 evas_object_focus_set(wd->ent, EINA_TRUE);
620 edje_object_signal_emit(wd->ent, "elm,action,focus", "elm");
621 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_ON);
622 evas_object_smart_callback_call(obj, SIG_FOCUSED, NULL);
623 _check_enable_returnkey(obj);
627 above = evas_object_above_get(parent_obj);
629 evas_object_data_set(parent_obj, "raise", above);
630 evas_object_raise(parent_obj);
631 parent_obj = elm_widget_parent_get(parent_obj);
636 edje_object_signal_emit(wd->ent, "elm,action,unfocus", "elm");
637 evas_object_focus_set(wd->ent, EINA_FALSE);
638 if (top) elm_win_keyboard_mode_set(top, ELM_WIN_KEYBOARD_OFF);
639 evas_object_smart_callback_call(obj, SIG_UNFOCUSED, NULL);
643 above = evas_object_data_get(parent_obj, "raise");
645 evas_object_stack_below(parent_obj, above);
646 parent_obj = elm_widget_parent_get(parent_obj);
648 if ((wd->api) && (wd->api->obj_hidemenu))
650 wd->api->obj_hidemenu(obj);
656 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
658 Widget_Data *wd = elm_widget_data_get(obj);
660 edje_object_signal_emit(wd->ent, emission, source);
664 _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)
666 Widget_Data *wd = elm_widget_data_get(obj);
668 edje_object_signal_callback_add(wd->ent, emission, source, func_cb, data);
672 _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)
674 Widget_Data *wd = elm_widget_data_get(obj);
675 edje_object_signal_callback_del_full(wd->ent, emission, source, func_cb,
680 _on_focus_region_hook(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
682 Widget_Data *wd = elm_widget_data_get(obj);
683 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", x, y, w, h);
687 _hoversel_position(Evas_Object *obj)
689 Widget_Data *wd = elm_widget_data_get(obj);
690 Evas_Coord cx, cy, cw, ch, x, y, mw, mh;
692 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
693 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
695 evas_object_size_hint_min_get(wd->hoversel, &mw, &mh);
706 evas_object_move(wd->hoversel, x + cx, y + cy);
707 evas_object_resize(wd->hoversel, cw, ch);
711 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
713 Widget_Data *wd = elm_widget_data_get(data);
715 if (wd->hoversel) _hoversel_position(data);
719 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
721 Widget_Data *wd = elm_widget_data_get(data);
723 if ((wd->linewrap) || (wd->char_linewrap))
727 if (wd->hoversel) _hoversel_position(data);
728 // Evas_Coord ww, hh;
729 // evas_object_geometry_get(wd->ent, NULL, NULL, &ww, &hh);
733 _hover_del(void *data)
735 Widget_Data *wd = elm_widget_data_get(data);
740 evas_object_del(wd->hoversel);
743 wd->hovdeljob = NULL;
747 _dismissed(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
749 Widget_Data *wd = elm_widget_data_get(data);
751 if (wd->hoversel) evas_object_hide(wd->hoversel);
755 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
757 elm_widget_scroll_freeze_pop(data);
758 if (wd->hovdeljob) ecore_job_del(wd->hovdeljob);
759 wd->hovdeljob = ecore_job_add(_hover_del, data);
763 _selectall(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
765 Widget_Data *wd = elm_widget_data_get(data);
767 wd->selmode = EINA_TRUE;
769 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
770 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
771 edje_object_part_text_select_all(wd->ent, "elm.text");
772 //elm_widget_scroll_hold_push(data);
773 elm_object_scroll_freeze_pop(data);
777 _select(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
779 Widget_Data *wd = elm_widget_data_get(data);
781 wd->selmode = EINA_TRUE;
782 edje_object_part_text_select_none(wd->ent, "elm.text");
784 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_TRUE);
785 edje_object_signal_emit(wd->ent, "elm,state,select,on", "elm");
786 elm_object_scroll_freeze_pop(data);
787 //elm_widget_scroll_hold_push(data);
791 _paste(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
793 Widget_Data *wd = elm_widget_data_get(data);
795 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
796 if (wd->sel_notify_handler)
798 #ifdef HAVE_ELEMENTARY_X
799 wd->selection_asked = EINA_TRUE;
800 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data, NULL, NULL);
806 _store_selection(Elm_Sel_Type seltype, Evas_Object *obj)
808 Widget_Data *wd = elm_widget_data_get(obj);
812 sel = edje_object_part_text_selection_get(wd->ent, "elm.text");
813 elm_selection_set(seltype, obj, ELM_SEL_FORMAT_MARKUP, sel);
814 if (seltype == ELM_SEL_CLIPBOARD)
815 eina_stringshare_replace(&wd->cut_sel, sel);
819 _cut(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
821 Widget_Data *wd = elm_widget_data_get(data);
824 wd->selmode = EINA_FALSE;
825 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
826 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
827 elm_widget_scroll_hold_pop(data);
828 _store_selection(ELM_SEL_CLIPBOARD, data);
829 edje_object_part_text_insert(wd->ent, "elm.text", "");
830 edje_object_part_text_select_none(wd->ent, "elm.text");
834 _copy(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
836 Widget_Data *wd = elm_widget_data_get(data);
838 //wd->selmode = EINA_FALSE;
839 //edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
840 //edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
841 elm_widget_scroll_hold_pop(data);
842 _store_selection(ELM_SEL_CLIPBOARD, data);
843 //edje_object_part_text_select_none(wd->ent, "elm.text");
847 _cancel(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
849 Widget_Data *wd = elm_widget_data_get(data);
851 wd->selmode = EINA_FALSE;
852 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
853 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
854 elm_widget_scroll_hold_pop(data);
855 edje_object_part_text_select_none(wd->ent, "elm.text");
859 _clipboard_menu(void *data, Evas_Object *obj, void *event_info __UNUSED__)
861 Widget_Data *wd = elm_widget_data_get(data);
865 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
866 cnpwidgetdata = data;
867 elm_cbhm_helper_init(obj);
868 if (elm_entry_cnp_textonly_get(obj))
869 elm_cbhm_send_raw_data("show0");
871 elm_cbhm_send_raw_data("show1");
877 _cnpinit(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
879 Widget_Data *wd = elm_widget_data_get(data);
881 cnpwidgetdata = data;
887 _item_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__)
889 Elm_Entry_Context_Menu_Item *it = data;
890 Evas_Object *obj2 = it->obj;
891 if (it->func) it->func(it->data, obj2, NULL);
895 _long_press(void *data)
897 Widget_Data *wd = elm_widget_data_get(data);
900 const Elm_Entry_Context_Menu_Item *it;
901 if (!wd) return ECORE_CALLBACK_CANCEL;
902 if ((wd->api) && (wd->api->obj_longpress))
904 wd->api->obj_longpress(data);
906 else if (wd->context_menu)
908 const char *context_menu_orientation;
910 if (wd->hoversel) evas_object_del(wd->hoversel);
911 else elm_widget_scroll_freeze_push(data);
912 wd->hoversel = elm_hoversel_add(data);
913 context_menu_orientation = edje_object_data_get
914 (wd->ent, "context_menu_orientation");
915 if ((context_menu_orientation) &&
916 (!strcmp(context_menu_orientation, "horizontal")))
917 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
918 elm_object_style_set(wd->hoversel, "entry");
919 elm_widget_sub_object_add(data, wd->hoversel);
920 elm_hoversel_label_set(wd->hoversel, "Text");
921 top = elm_widget_top_get(data);
922 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
923 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, data);
927 elm_hoversel_item_add(wd->hoversel, "Select", NULL, ELM_ICON_NONE,
929 if (1) // need way to detect if someone has a selection
932 elm_hoversel_item_add(wd->hoversel, "Paste", NULL, ELM_ICON_NONE,
937 elm_hoversel_item_add(wd->hoversel, "More", NULL, ELM_ICON_NONE,
938 _clipboard_menu, data);
945 if (wd->have_selection)
947 elm_hoversel_item_add(wd->hoversel, "Copy", NULL, ELM_ICON_NONE,
950 elm_hoversel_item_add(wd->hoversel, "Cut", NULL, ELM_ICON_NONE,
953 elm_hoversel_item_add(wd->hoversel, "Cancel", NULL, ELM_ICON_NONE,
956 elm_hoversel_item_add(wd->hoversel, "More", NULL, ELM_ICON_NONE,
957 _clipboard_menu, data);
961 EINA_LIST_FOREACH(wd->items, l, it)
963 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
964 it->icon_type, _item_clicked, it);
968 _hoversel_position(data);
969 evas_object_show(wd->hoversel);
970 elm_hoversel_hover_begin(wd->hoversel);
972 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
973 edje_object_part_text_select_abort(wd->ent, "elm.text");
975 wd->longpress_timer = NULL;
976 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
977 return ECORE_CALLBACK_CANCEL;
981 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
983 Widget_Data *wd = elm_widget_data_get(data);
984 Evas_Event_Mouse_Down *ev = event_info;
986 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
987 if (ev->button != 1) return;
988 // if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
989 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
990 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
991 wd->downx = ev->canvas.x;
992 wd->downy = ev->canvas.y;
994 wd->long_pressed = EINA_FALSE;
998 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1000 Widget_Data *wd = elm_widget_data_get(data);
1001 Evas_Event_Mouse_Up *ev = event_info;
1003 if (ev->button != 1) return;
1005 if (!wd->double_clicked)
1007 if ((wd->api) && (wd->api->obj_mouseup))
1009 wd->api->obj_mouseup(data);
1012 if (wd->longpress_timer)
1014 ecore_timer_del(wd->longpress_timer);
1015 wd->longpress_timer = NULL;
1018 elm_object_scroll_freeze_pop(data);
1022 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1024 Widget_Data *wd = elm_widget_data_get(data);
1025 Evas_Event_Mouse_Move *ev = event_info;
1029 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1031 if (wd->longpress_timer)
1033 ecore_timer_del(wd->longpress_timer);
1034 wd->longpress_timer = NULL;
1037 else if (wd->longpress_timer)
1041 dx = wd->downx - ev->cur.canvas.x;
1043 dy = wd->downy - ev->cur.canvas.y;
1046 ((_elm_config->finger_size / 2) *
1047 (_elm_config->finger_size / 2)))
1049 ecore_timer_del(wd->longpress_timer);
1050 wd->longpress_timer = NULL;
1054 else if (wd->longpress_timer)
1058 dx = wd->downx - ev->cur.canvas.x;
1060 dy = wd->downy - ev->cur.canvas.y;
1063 ((_elm_config->finger_size / 2) *
1064 (_elm_config->finger_size / 2)))
1066 ecore_timer_del(wd->longpress_timer);
1067 wd->longpress_timer = NULL;
1073 _getbase(Evas_Object *obj)
1075 Widget_Data *wd = elm_widget_data_get(obj);
1076 if (!wd) return "base";
1081 if (wd->show_last_character) return "custom-password";
1082 else return "base-password";
1086 if (wd->single_line) return "base-single";
1089 if (wd->linewrap) return "base";
1090 else if (wd->char_linewrap) return "base-charwrap";
1091 else return "base-nowrap";
1099 if (wd->show_last_character) return "custom-password";
1100 else return "base-password";
1104 if (wd->single_line) return "base-single-noedit";
1107 if (wd->linewrap) return "base-noedit";
1108 else if (wd->char_linewrap) return "base-noedit-charwrap";
1109 else return "base-nowrap-noedit";
1117 _entry_length_get(Evas_Object *obj)
1120 const char *str = elm_entry_entry_get(obj);
1123 char *plain_str = _elm_util_mkup_to_text(str);
1124 if (!plain_str) return 0;
1126 len = strlen(plain_str);
1133 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1135 Widget_Data *wd = elm_widget_data_get(data);
1137 wd->changed = EINA_TRUE;
1139 if (wd->text) eina_stringshare_del(wd->text);
1141 _check_enable_returnkey(data);
1142 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1143 if (wd->delay_write)
1145 ecore_timer_del(wd->delay_write);
1146 wd->delay_write = NULL;
1148 if ((!wd->autosave) || (!wd->file)) return;
1149 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1153 _signal_handler_move_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1155 Widget_Data *wd = elm_widget_data_get(data);
1156 elm_object_scroll_freeze_push(data);
1158 if ((wd->api) && (wd->api->obj_hidemenu))
1160 wd->api->obj_hidemenu(data);
1165 _signal_handler_move_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1167 Widget_Data *wd = elm_widget_data_get(data);
1168 elm_object_scroll_freeze_pop(data);
1170 if (wd->have_selection)
1175 _signal_selection_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1178 Widget_Data *wd = elm_widget_data_get(data);
1186 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1188 Widget_Data *wd = elm_widget_data_get(data);
1192 EINA_LIST_FOREACH(entries, l, entry)
1194 if (entry != data) elm_entry_select_none(entry);
1196 wd->have_selection = EINA_TRUE;
1197 wd->selmode = EINA_TRUE;
1198 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1199 #ifdef HAVE_ELEMENTARY_X
1200 if (wd->sel_notify_handler)
1202 const char *txt = elm_entry_selection_get(data);
1205 top = elm_widget_top_get(data);
1206 if ((top) && (elm_win_xwindow_get(top)))
1207 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1213 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1215 Evas_Coord cx, cy, cw, ch;
1216 Widget_Data *wd = elm_widget_data_get(data);
1218 wd->have_selection = EINA_TRUE;
1219 wd->selmode = EINA_TRUE;
1220 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1221 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1222 elm_entry_selection_get(data));
1224 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1225 if (!wd->deferred_recalc_job)
1226 elm_widget_show_region_set(data, cx, cy, cw, ch + elm_finger_size_get());
1229 wd->deferred_cur = EINA_TRUE;
1233 wd->ch = ch + elm_finger_size_get();
1238 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1240 Widget_Data *wd = elm_widget_data_get(data);
1242 if (!wd->have_selection) return;
1243 wd->have_selection = EINA_FALSE;
1244 wd->selmode = EINA_FALSE;
1245 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1246 if (wd->sel_notify_handler)
1250 #ifdef HAVE_ELEMENTARY_X
1253 top = elm_widget_top_get(data);
1254 if ((top) && (elm_win_xwindow_get(top)))
1255 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1258 eina_stringshare_del(wd->cut_sel);
1263 #ifdef HAVE_ELEMENTARY_X
1266 top = elm_widget_top_get(data);
1267 if ((top) && (elm_win_xwindow_get(top)))
1268 elm_selection_clear(ELM_SEL_PRIMARY, data);
1275 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1277 Widget_Data *wd = elm_widget_data_get(data);
1279 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1280 if (wd->sel_notify_handler)
1282 #ifdef HAVE_ELEMENTARY_X
1285 top = elm_widget_top_get(data);
1286 if ((top) && (elm_win_xwindow_get(top)))
1288 wd->selection_asked = EINA_TRUE;
1289 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
1297 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1299 Widget_Data *wd = elm_widget_data_get(data);
1301 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1302 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1303 elm_entry_selection_get(data));
1307 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1309 Widget_Data *wd = elm_widget_data_get(data);
1311 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1312 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1313 elm_entry_selection_get(data));
1314 edje_object_part_text_insert(wd->ent, "elm.text", "");
1315 wd->changed = EINA_TRUE;
1320 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1322 Widget_Data *wd = elm_widget_data_get(data);
1323 Evas_Coord cx, cy, cw, ch;
1325 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1326 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1327 &cx, &cy, &cw, &ch);
1328 if (!wd->deferred_recalc_job)
1329 elm_widget_show_region_set(data, cx, cy, cw, ch);
1332 wd->deferred_cur = EINA_TRUE;
1341 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1343 Widget_Data *wd = elm_widget_data_get(data);
1348 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1350 Widget_Data *wd = elm_widget_data_get(data);
1351 Elm_Entry_Anchor_Info ei;
1352 char *buf2, *p, *p2, *n;
1354 p = strrchr(emission, ',');
1357 const Eina_List *geoms;
1361 while (p2 >= emission)
1363 if (*p2 == ',') break;
1367 buf2 = alloca(5 + p - p2);
1368 strncpy(buf2, p2, p - p2);
1371 ei.button = atoi(buf2);
1372 ei.x = ei.y = ei.w = ei.h = 0;
1374 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1377 Evas_Textblock_Rectangle *r;
1379 Evas_Coord px, py, x, y;
1381 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1382 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1383 EINA_LIST_FOREACH(geoms, l, r)
1385 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1386 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1397 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1402 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1404 Widget_Data *wd = elm_widget_data_get(data);
1409 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1411 Widget_Data *wd = elm_widget_data_get(data);
1416 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1418 Widget_Data *wd = elm_widget_data_get(data);
1423 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1425 Widget_Data *wd = elm_widget_data_get(data);
1427 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1431 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1433 Widget_Data *wd = elm_widget_data_get(data);
1435 wd->double_clicked = EINA_FALSE;
1436 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1438 if ((wd->api) && (wd->api->obj_hidemenu))
1440 wd->api->obj_hidemenu(data);
1445 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1447 Widget_Data *wd = elm_widget_data_get(data);
1449 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1453 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1455 Widget_Data *wd = elm_widget_data_get(data);
1457 wd->double_clicked = EINA_TRUE;
1458 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1461 #ifdef HAVE_ELEMENTARY_X
1463 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1465 Widget_Data *wd = elm_widget_data_get(data);
1466 Ecore_X_Event_Selection_Notify *ev = event;
1467 if (!wd) return ECORE_CALLBACK_PASS_ON;
1468 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1469 return ECORE_CALLBACK_PASS_ON;
1471 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1472 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1474 Ecore_X_Selection_Data_Text *text_data;
1476 text_data = ev->data;
1477 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1479 if (text_data->text)
1481 char *txt = _elm_util_text_to_mkup(text_data->text);
1485 elm_entry_entry_insert(data, txt);
1490 wd->selection_asked = EINA_FALSE;
1492 else if (ev->selection == ECORE_X_SELECTION_XDND)
1494 Ecore_X_Selection_Data_Text *text_data;
1496 text_data = ev->data;
1497 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1499 if (text_data->text)
1501 char *txt = _elm_util_text_to_mkup(text_data->text);
1505 /* Massive FIXME: this should be at the drag point */
1506 elm_entry_entry_insert(data, txt);
1511 wd->drag_selection_asked = EINA_FALSE;
1513 ecore_x_dnd_send_finished();
1516 return ECORE_CALLBACK_PASS_ON;
1520 _event_selection_clear(void *data, int type __UNUSED__, void *event)
1523 Widget_Data *wd = elm_widget_data_get(data);
1524 Ecore_X_Event_Selection_Clear *ev = event;
1525 if (!wd) return ECORE_CALLBACK_PASS_ON;
1526 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1527 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1528 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1530 elm_entry_select_none(data);
1535 Evas_Object *top = elm_widget_top_get(data);
1536 Ecore_X_Event_Selection_Clear *ev = event;
1539 return ECORE_CALLBACK_PASS_ON;
1541 if (ev->selection != ECORE_X_SELECTION_SECONDARY)
1543 return ECORE_CALLBACK_PASS_ON;
1546 if (cnpwidgetdata == data)
1548 elm_selection_get(ELM_SEL_SECONDARY,ELM_SEL_FORMAT_MARKUP,data,NULL,NULL);
1552 return ECORE_CALLBACK_PASS_ON;
1557 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1562 wd = elm_widget_data_get(obj);
1564 if (!wd) return EINA_FALSE;
1565 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1567 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1568 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1569 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1570 EDJE_CURSOR_MAIN,drop->x,drop->y);
1571 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1572 elm_entry_entry_insert(obj, drop->data);
1573 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1574 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1580 static Evas_Object *
1581 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1583 Widget_Data *wd = elm_widget_data_get(data);
1586 Elm_Entry_Item_Provider *ip;
1588 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1590 o = ip->func(ip->data, data, item);
1593 if (!strncmp(item, "file://", 7))
1595 const char *fname = item + 7;
1597 o = evas_object_image_filled_add(evas_object_evas_get(data));
1598 evas_object_image_file_set(o, fname, NULL);
1599 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1601 evas_object_show(o);
1606 o = edje_object_add(evas_object_evas_get(data));
1607 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1611 o = edje_object_add(evas_object_evas_get(data));
1612 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1613 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1618 _get_value_in_key_string(const char *oldstring, char *key, char **value)
1620 char *curlocater, *starttag, *endtag;
1621 int firstindex = 0, foundflag = -1;
1623 curlocater = strstr(oldstring, key);
1626 starttag = curlocater;
1627 endtag = curlocater + strlen(key);
1628 if (endtag == NULL || *endtag != '=')
1634 firstindex = abs(oldstring - curlocater);
1635 firstindex += strlen(key)+1; // strlen("key") + strlen("=")
1636 *value = (char*)(oldstring + firstindex);
1638 while (oldstring != starttag)
1640 if (*starttag == '>')
1645 if (*starttag == '<')
1649 if (starttag == NULL) break;
1652 while (NULL != endtag)
1663 if (endtag == NULL) break;
1666 if (foundflag != 0 && *starttag == '<' && *endtag == '>')
1676 if (foundflag == 1) return 0;
1682 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
1684 const char *srcstring = NULL;
1685 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
1686 char *curlocater, *replocater;
1687 char *starttag, *endtag;
1688 int tagtxtlen = 0, insertflag = 0;
1690 srcstring = eina_strbuf_string_get(srcbuf);
1691 curlocater = strstr(srcstring, key);
1693 if (!curlocater || !srcstring)
1701 starttag = strchr(srcstring, '<');
1702 endtag = strchr(srcstring, '>');
1703 tagtxtlen = endtag - starttag;
1704 if (tagtxtlen <= 0) tagtxtlen = 0;
1705 if (starttag < curlocater && curlocater < endtag) break;
1706 if (endtag != NULL && endtag+1 != NULL)
1707 srcstring = endtag+1;
1710 } while (strlen(srcstring) > 1);
1712 if (starttag && endtag && tagtxtlen > strlen(key))
1714 repbuf = eina_strbuf_new();
1715 diffbuf = eina_strbuf_new();
1716 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
1717 srcstring = eina_strbuf_string_get(repbuf);
1718 curlocater = strstr(srcstring, key);
1720 if (curlocater != NULL)
1722 replocater = curlocater + strlen(key) + 1;
1724 while ((*replocater) && (*replocater != ' ') && (*replocater != '>'))
1727 if (replocater-curlocater > strlen(key)+1)
1729 eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
1738 eina_strbuf_reset(repbuf);
1746 if (repbuf == NULL) repbuf = eina_strbuf_new();
1747 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
1751 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
1752 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
1758 eina_strbuf_prepend(diffbuf, "<");
1759 eina_strbuf_append(diffbuf, ">");
1760 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
1764 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
1765 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
1769 if (repbuf) eina_strbuf_free(repbuf);
1770 if (diffbuf) eina_strbuf_free(diffbuf);
1776 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
1778 Eina_Strbuf *sharebuf = NULL;
1780 sharebuf = eina_strbuf_new();
1781 eina_strbuf_append(sharebuf, *srcstring);
1782 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
1783 eina_stringshare_del(*srcstring);
1784 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
1785 eina_strbuf_free(sharebuf);
1791 _is_width_over(Evas_Object *obj)
1793 Evas_Coord x, y, w, h;
1794 Evas_Coord vx, vy, vw, vh;
1795 Widget_Data *wd = elm_widget_data_get(obj);
1799 edje_object_part_geometry_get(wd->ent,"elm.text",&x,&y,&w,&h);
1801 evas_object_geometry_get (obj, &vx,&vy,&vw,&vh);
1803 if (x >= 0 && y >= 0)
1806 if (4 < wd->wrap_w && w > wd->wrap_w)
1813 _reverse_ellipsis_entry(Evas_Object *obj)
1815 Widget_Data *wd = elm_widget_data_get(obj);
1816 int cur_fontsize = 0;
1817 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1818 char *kvalue = NULL;
1819 const char *minfont, *deffont, *maxfont;
1820 const char *ellipsis_string = "...";
1821 int minfontsize, maxfontsize, minshowcount;
1823 minshowcount = strlen(ellipsis_string) + 1;
1824 minfont = edje_object_data_get(wd->ent, "min_font_size");
1825 if (minfont) minfontsize = atoi(minfont);
1826 else minfontsize = 1;
1827 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1828 if (maxfont) maxfontsize = atoi(maxfont);
1829 else maxfontsize = 1;
1830 deffont = edje_object_data_get(wd->ent, "default_font_size");
1831 if (deffont) cur_fontsize = atoi(deffont);
1832 else cur_fontsize = 1;
1833 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1834 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1836 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1838 if (kvalue != NULL) cur_fontsize = atoi(kvalue);
1841 txtbuf = eina_strbuf_new();
1842 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1844 if (cur_fontsize >= atoi(deffont))
1846 if (txtbuf) eina_strbuf_free(txtbuf);
1850 if (_is_width_over(obj) != 1)
1852 int rev_fontsize = cur_fontsize;
1856 if (rev_fontsize > atoi(deffont))
1859 if (fontbuf != NULL)
1861 eina_strbuf_free(fontbuf);
1864 fontbuf = eina_strbuf_new();
1865 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1866 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1867 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1869 eina_strbuf_free(fontbuf);
1871 } while (_is_width_over(obj) != 1);
1873 while (_is_width_over(obj))
1876 if (rev_fontsize < atoi(deffont))
1879 if (fontbuf != NULL)
1881 eina_strbuf_free(fontbuf);
1884 fontbuf = eina_strbuf_new();
1885 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1886 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1887 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1888 eina_strbuf_free(fontbuf);
1893 if (txtbuf) eina_strbuf_free(txtbuf);
1899 _ellipsis_entry_to_width(Evas_Object *obj)
1901 Widget_Data *wd = elm_widget_data_get(obj);
1902 int cur_fontsize = 0, len, jumpcount;
1903 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1904 char *kvalue = NULL;
1905 const char *minfont, *deffont, *maxfont;
1906 const char *ellipsis_string = "...";
1907 int minfontsize, maxfontsize, minshowcount;
1908 int i, tagend, cur_len;
1911 minshowcount = strlen(ellipsis_string) + 1;
1912 minfont = edje_object_data_get(wd->ent, "min_font_size");
1913 if (minfont) minfontsize = atoi(minfont);
1914 else minfontsize = 1;
1915 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1916 if (maxfont) maxfontsize = atoi(maxfont);
1917 else maxfontsize = 1;
1918 deffont = edje_object_data_get(wd->ent, "default_font_size");
1919 if (deffont) cur_fontsize = atoi(deffont);
1920 else cur_fontsize = 1;
1921 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1922 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1924 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1926 if (kvalue != NULL) cur_fontsize = atoi(kvalue);
1929 txtbuf = eina_strbuf_new();
1930 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1932 while (_is_width_over(obj))
1934 if (wd->ellipsis_threshold == 0)
1935 wd->ellipsis_threshold = _entry_length_get(obj);
1936 if (cur_fontsize > minfontsize)
1939 if (fontbuf != NULL)
1941 eina_strbuf_free(fontbuf);
1944 fontbuf = eina_strbuf_new();
1945 eina_strbuf_append_printf(fontbuf, "%d", cur_fontsize);
1946 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1947 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1948 eina_strbuf_free(fontbuf);
1950 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1954 len = _entry_length_get(obj);
1955 cur_str = (char*)edje_object_part_text_get(wd->ent, "elm.text");
1956 cur_len = strlen(cur_str);
1958 for (i = 0; i < len; i++)
1960 if(cur_str[i] == '>' && cur_str[i+1] != '\0' &&
1961 cur_str[i+1] != '<')
1968 while (jumpcount < len-strlen(ellipsis_string))
1970 cur_str = (char*)edje_object_part_text_get(wd->ent, "elm.text");
1974 eina_strbuf_free(txtbuf);
1977 txtbuf = eina_strbuf_new();
1978 eina_strbuf_append_n(txtbuf, cur_str, tagend+1);
1979 eina_strbuf_append(txtbuf, ellipsis_string);
1980 eina_strbuf_append(txtbuf, cur_str+tagend+jumpcount+1);
1981 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1982 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1984 if (_is_width_over(obj))
1992 if (txtbuf) eina_strbuf_free(txtbuf);
1997 static Eina_Bool *_textinput_control_function(void *data,void *input_data)
1999 /* calculate character count */
2000 Evas_Object *entry = (Evas_Object *)data;
2001 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
2004 size_t insert_text_len=0;
2005 char *text = (char*)edje_object_part_text_get(wd->ent, "elm.text");
2007 size_t remain_bytes;
2010 byte_len = strlen(text); /* no of bytes */
2011 remain_bytes = wd->max_no_of_bytes - byte_len;
2012 sprintf(buf,"%d",remain_bytes);
2013 //edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", buf);
2016 insert_text = (char *)input_data;
2017 insert_text_len = strlen(insert_text);
2018 if (remain_bytes < insert_text_len)
2020 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2023 if (byte_len >= wd->max_no_of_bytes)
2025 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2035 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
2037 Widget_Data *wd = elm_widget_data_get(data);
2039 Elm_Entry_Text_Filter *tf;
2041 if (type == EDJE_TEXT_FILTER_FORMAT)
2044 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2046 tf->func(tf->data, data, text);
2053 * This adds an entry to @p parent object.
2055 * @param parent The parent object
2056 * @return The new object or NULL if it cannot be created
2061 elm_entry_add(Evas_Object *parent)
2063 Evas_Object *obj, *top;
2067 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
2069 wd = ELM_NEW(Widget_Data);
2070 e = evas_object_evas_get(parent);
2071 if (!e) return NULL;
2072 wd->bgcolor = EINA_FALSE;
2073 wd->bg = evas_object_rectangle_add(e);
2074 evas_object_color_set(wd->bg, 0, 0, 0, 0);
2075 obj = elm_widget_add(e);
2076 ELM_SET_WIDTYPE(widtype, "entry");
2077 elm_widget_type_set(obj, "entry");
2078 elm_widget_sub_object_add(parent, obj);
2079 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2080 elm_widget_data_set(obj, wd);
2081 elm_widget_del_hook_set(obj, _del_hook);
2082 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2083 elm_widget_theme_hook_set(obj, _theme_hook);
2084 elm_widget_disable_hook_set(obj, _disable_hook);
2085 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2086 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
2087 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
2088 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
2089 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
2090 elm_widget_can_focus_set(obj, EINA_TRUE);
2091 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
2093 wd->linewrap = EINA_TRUE;
2094 wd->ellipsis = EINA_FALSE;
2095 wd->char_linewrap= EINA_FALSE;
2096 wd->editable = EINA_TRUE;
2097 wd->disabled = EINA_FALSE;
2098 wd->context_menu = EINA_TRUE;
2099 wd->autosave = EINA_TRUE;
2100 wd->textonly = EINA_FALSE;
2101 wd->autoperiod = EINA_TRUE;
2103 wd->ellipsis_threshold = 0;
2105 wd->ent = edje_object_add(e);
2106 edje_object_item_provider_set(wd->ent, _get_item, obj);
2107 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
2108 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
2109 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
2110 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
2112 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
2114 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
2117 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
2118 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
2119 _signal_entry_changed, obj);
2120 edje_object_signal_callback_add(wd->ent, "handler,move,start", "elm.text",
2121 _signal_handler_move_start, obj);
2122 edje_object_signal_callback_add(wd->ent, "handler,move,end", "elm.text",
2123 _signal_handler_move_end, obj);
2124 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
2125 _signal_selection_start, obj);
2126 edje_object_signal_callback_add(wd->ent, "selection,end", "elm.text",
2127 _signal_selection_end, obj);
2128 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
2129 _signal_selection_changed, obj);
2130 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2131 _signal_selection_cleared, obj);
2132 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
2133 _signal_entry_paste_request, obj);
2134 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2135 _signal_entry_copy_notify, obj);
2136 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2137 _signal_entry_cut_notify, obj);
2138 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2139 _signal_cursor_changed, obj);
2140 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2141 _signal_anchor_down, obj);
2142 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2143 _signal_anchor_up, obj);
2144 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2145 _signal_anchor_move, obj);
2146 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2147 _signal_anchor_in, obj);
2148 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2149 _signal_anchor_out, obj);
2150 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2151 _signal_key_enter, obj);
2152 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2153 _signal_mouse_down, obj);
2154 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2155 _signal_mouse_clicked, obj);
2156 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2157 _signal_mouse_double, obj);
2158 edje_object_part_text_set(wd->ent, "elm.text", "");
2159 elm_widget_resize_object_set(obj, wd->ent);
2162 wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
2164 #ifdef HAVE_ELEMENTARY_X
2165 top = elm_widget_top_get(obj);
2166 if ((top) && (elm_win_xwindow_get(top)))
2168 wd->sel_notify_handler =
2169 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2170 _event_selection_notify, obj);
2171 wd->sel_clear_handler =
2172 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2173 _event_selection_clear, obj);
2176 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP,_drag_drop_cb, NULL);
2179 entries = eina_list_prepend(entries, obj);
2181 // module - find module for entry
2182 wd->api = _module(obj);
2183 // if found - hook in
2184 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2186 // TODO: convert Elementary to subclassing of Evas_Smart_Class
2187 // TODO: and save some bytes, making descriptions per-class and not instance!
2188 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2192 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
2194 ELM_CHECK_WIDTYPE(obj, widtype);
2195 Widget_Data *wd = elm_widget_data_get(obj);
2197 ext_mod->cancel = _cancel;
2198 ext_mod->copy = _copy;
2199 ext_mod->cut = _cut;
2200 ext_mod->paste = _paste;
2201 ext_mod->select = _select;
2202 ext_mod->selectall = _selectall;
2203 ext_mod->ent = wd->ent;
2204 ext_mod->items = wd->items;
2205 ext_mod->longpress_timer = wd->longpress_timer;
2206 ext_mod->editable = wd->editable;
2207 ext_mod->have_selection = wd->have_selection;
2208 ext_mod->password = wd->password;
2209 ext_mod->selmode = wd->selmode;
2210 ext_mod->cnpinit = _cnpinit;
2211 ext_mod->context_menu = wd->context_menu;
2212 ext_mod->textonly = wd->textonly;
2216 * This sets the entry object not to line wrap. All input will
2217 * be on a single line, and the entry box will extend with user input.
2219 * @param obj The entry object
2220 * @param single_line If true, the text in the entry
2221 * will be on a single line.
2226 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2228 ELM_CHECK_WIDTYPE(obj, widtype);
2229 Widget_Data *wd = elm_widget_data_get(obj);
2231 Ecore_IMF_Context *ic;
2233 if (wd->single_line == single_line) return;
2234 wd->single_line = single_line;
2235 wd->linewrap = EINA_FALSE;
2236 wd->char_linewrap = EINA_FALSE;
2237 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
2238 t = eina_stringshare_add(elm_entry_entry_get(obj));
2239 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2240 elm_entry_entry_set(obj, t);
2241 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
2242 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
2243 ic = elm_entry_imf_context_get(obj);
2246 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2249 eina_stringshare_del(t);
2254 * This returns true if the entry has been set to single line mode.
2255 * See also elm_entry_single_line_set().
2257 * @param obj The entry object
2258 * @return single_line If true, the text in the entry is set to display
2264 elm_entry_single_line_get(const Evas_Object *obj)
2266 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2267 Widget_Data *wd = elm_widget_data_get(obj);
2268 if (!wd) return EINA_FALSE;
2269 return wd->single_line;
2273 * This set's the maximum bytes that can be added in entry.
2275 * @param obj The entry object
2276 * @param max_no_of_bytes Maximum number of bytes entry can have.
2281 elm_entry_maximum_bytes_set(Evas_Object *obj, int max_no_of_bytes)
2283 Widget_Data *wd = elm_widget_data_get(obj);
2285 wd->max_no_of_bytes = max_no_of_bytes;
2286 edje_object_part_textinput_callback_set(wd->ent, "elm.text", _textinput_control_function,obj);
2291 * This sets the entry object to password mode. All text entered
2292 * and/or displayed within the widget will be replaced with asterisks (*).
2294 * @param obj The entry object
2295 * @param password If true, password mode is enabled.
2300 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2302 ELM_CHECK_WIDTYPE(obj, widtype);
2303 Widget_Data *wd = elm_widget_data_get(obj);
2304 Ecore_IMF_Context *ic;
2307 if (wd->password == password) return;
2308 wd->password = password;
2309 wd->single_line = EINA_TRUE;
2310 wd->linewrap = EINA_FALSE;
2311 wd->char_linewrap = EINA_FALSE;
2312 if (_elm_config->password_show_last_character)
2313 wd->show_last_character = EINA_TRUE;
2314 t = eina_stringshare_add(elm_entry_entry_get(obj));
2315 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2316 elm_entry_entry_set(obj, t);
2321 elm_entry_autoperiod_set(obj, EINA_FALSE);
2323 if (wd->autocapital)
2324 elm_entry_autocapitalization_set(obj, EINA_FALSE);
2327 ic = elm_entry_imf_context_get(obj);
2329 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2331 eina_stringshare_del(t);
2337 * This returns whether password mode is enabled.
2338 * See also elm_entry_password_set().
2340 * @param obj The entry object
2341 * @return If true, the entry is set to display all characters
2347 elm_entry_password_get(const Evas_Object *obj)
2349 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2350 Widget_Data *wd = elm_widget_data_get(obj);
2351 if (!wd) return EINA_FALSE;
2352 return wd->password;
2356 * This sets the text displayed within the entry to @p entry.
2358 * @param obj The entry object
2359 * @param entry The text to be displayed
2364 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2366 ELM_CHECK_WIDTYPE(obj, widtype);
2367 Widget_Data *wd = elm_widget_data_get(obj);
2369 if (!entry) entry = "";
2370 if(wd->max_no_of_bytes)
2372 int len = strlen(entry);
2373 if(len > wd->max_no_of_bytes)
2375 ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2379 edje_object_part_text_set(wd->ent, "elm.text", entry);
2380 if (wd->text) eina_stringshare_del(wd->text);
2382 wd->changed = EINA_TRUE;
2387 * This returns the text currently shown in object @p entry.
2388 * See also elm_entry_entry_set().
2390 * @param obj The entry object
2391 * @return The currently displayed text or NULL on failure
2396 elm_entry_entry_get(const Evas_Object *obj)
2398 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2399 Widget_Data *wd = elm_widget_data_get(obj);
2401 if (!wd) return NULL;
2403 if ((wd->text)&&(wd->password))
2404 return elm_entry_markup_to_utf8(wd->text);
2406 if (wd->text) return wd->text;
2407 text = edje_object_part_text_get(wd->ent, "elm.text");
2410 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2413 eina_stringshare_replace(&wd->text, text);
2414 if(wd->password)return elm_entry_markup_to_utf8(wd->text);
2419 * This returns all selected text within the entry.
2421 * @param obj The entry object
2422 * @return The selected text within the entry or NULL on failure
2427 elm_entry_selection_get(const Evas_Object *obj)
2429 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2430 Widget_Data *wd = elm_widget_data_get(obj);
2431 if (!wd) return NULL;
2432 return edje_object_part_text_selection_get(wd->ent, "elm.text");
2436 * This inserts text in @p entry where the current cursor position.
2438 * This inserts text at the cursor position is as if it was typed
2439 * by the user (note this also allows markup which a user
2440 * can't just "type" as it would be converted to escaped text, so this
2441 * call can be used to insert things like emoticon items or bold push/pop
2442 * tags, other font and color change tags etc.)
2444 * @param obj The entry object
2445 * @param entry The text to insert
2450 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2452 ELM_CHECK_WIDTYPE(obj, widtype);
2453 Widget_Data *wd = elm_widget_data_get(obj);
2455 edje_object_part_text_insert(wd->ent, "elm.text", entry);
2457 if (cnpwidgetdata == obj)
2458 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
2460 wd->changed = EINA_TRUE;
2465 * This enables word line wrapping in the entry object. It is the opposite
2466 * of elm_entry_single_line_set(). Additionally, setting this disables
2467 * character line wrapping.
2468 * See also elm_entry_line_char_wrap_set().
2470 * @param obj The entry object
2471 * @param wrap If true, the entry will be wrapped once it reaches the end
2472 * of the object. Wrapping will occur at the end of the word before the end of the
2478 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2480 ELM_CHECK_WIDTYPE(obj, widtype);
2481 Widget_Data *wd = elm_widget_data_get(obj);
2484 if (wd->linewrap == wrap) return;
2485 wd->linewrap = wrap;
2487 wd->char_linewrap = EINA_FALSE;
2488 t = eina_stringshare_add(elm_entry_entry_get(obj));
2489 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2490 elm_entry_entry_set(obj, t);
2491 eina_stringshare_del(t);
2496 * Set wrap width of the entry
2498 * @param obj The entry object
2499 * @param w The wrap width in pixels at a minimum where words need to wrap
2503 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2505 Widget_Data *wd = elm_widget_data_get(obj);
2506 if (wd->wrap_w == w) return;
2512 * get wrap width of the entry
2514 * @param obj The entry object
2515 * @return The wrap width in pixels at a minimum where words need to wrap
2519 elm_entry_wrap_width_get(const Evas_Object *obj)
2521 Widget_Data *wd = elm_widget_data_get(obj);
2526 * This enables character line wrapping in the entry object. It is the opposite
2527 * of elm_entry_single_line_set(). Additionally, setting this disables
2528 * word line wrapping.
2529 * See also elm_entry_line_wrap_set().
2531 * @param obj The entry object
2532 * @param wrap If true, the entry will be wrapped once it reaches the end
2533 * of the object. Wrapping will occur immediately upon reaching the end of the object.
2538 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2540 ELM_CHECK_WIDTYPE(obj, widtype);
2541 Widget_Data *wd = elm_widget_data_get(obj);
2544 if (wd->char_linewrap == wrap) return;
2545 wd->char_linewrap = wrap;
2546 if(wd->char_linewrap)
2547 wd->linewrap = EINA_FALSE;
2548 t = eina_stringshare_add(elm_entry_entry_get(obj));
2549 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2550 elm_entry_entry_set(obj, t);
2551 eina_stringshare_del(t);
2556 * This sets the editable attribute of the entry.
2558 * @param obj The entry object
2559 * @param editable If true, the entry will be editable by the user.
2560 * If false, it will be set to the disabled state.
2565 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2567 ELM_CHECK_WIDTYPE(obj, widtype);
2568 Widget_Data *wd = elm_widget_data_get(obj);
2571 if (wd->editable == editable) return;
2572 wd->editable = editable;
2573 t = eina_stringshare_add(elm_entry_entry_get(obj));
2574 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2575 elm_entry_entry_set(obj, t);
2576 eina_stringshare_del(t);
2579 #ifdef HAVE_ELEMENTARY_X
2581 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2583 elm_drop_target_del(obj);
2588 * This gets the editable attribute of the entry.
2589 * See also elm_entry_editable_set().
2591 * @param obj The entry object
2592 * @return If true, the entry is editable by the user.
2593 * If false, it is not editable by the user
2598 elm_entry_editable_get(const Evas_Object *obj)
2600 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2601 Widget_Data *wd = elm_widget_data_get(obj);
2602 if (!wd) return EINA_FALSE;
2603 return wd->editable;
2607 * This drops any existing text selection within the entry.
2609 * @param obj The entry object
2614 elm_entry_select_none(Evas_Object *obj)
2616 ELM_CHECK_WIDTYPE(obj, widtype);
2617 Widget_Data *wd = elm_widget_data_get(obj);
2621 wd->selmode = EINA_FALSE;
2622 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2623 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2625 wd->have_selection = EINA_FALSE;
2626 edje_object_part_text_select_none(wd->ent, "elm.text");
2630 * This selects all text within the entry.
2632 * @param obj The entry object
2637 elm_entry_select_all(Evas_Object *obj)
2639 ELM_CHECK_WIDTYPE(obj, widtype);
2640 Widget_Data *wd = elm_widget_data_get(obj);
2644 wd->selmode = EINA_FALSE;
2645 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2646 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2648 wd->have_selection = EINA_TRUE;
2649 edje_object_part_text_select_all(wd->ent, "elm.text");
2653 * This moves the cursor one place to the right within the entry.
2655 * @param obj The entry object
2656 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2661 elm_entry_cursor_next(Evas_Object *obj)
2663 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2664 Widget_Data *wd = elm_widget_data_get(obj);
2665 if (!wd) return EINA_FALSE;
2666 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2670 * This moves the cursor one place to the left within the entry.
2672 * @param obj The entry object
2673 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2678 elm_entry_cursor_prev(Evas_Object *obj)
2680 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2681 Widget_Data *wd = elm_widget_data_get(obj);
2682 if (!wd) return EINA_FALSE;
2683 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2687 * This moves the cursor one line up within the entry.
2689 * @param obj The entry object
2690 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2695 elm_entry_cursor_up(Evas_Object *obj)
2697 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2698 Widget_Data *wd = elm_widget_data_get(obj);
2699 if (!wd) return EINA_FALSE;
2700 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2704 * This moves the cursor one line down within the entry.
2706 * @param obj The entry object
2707 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2712 elm_entry_cursor_down(Evas_Object *obj)
2714 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2715 Widget_Data *wd = elm_widget_data_get(obj);
2716 if (!wd) return EINA_FALSE;
2717 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2721 * This moves the cursor to the beginning of the entry.
2723 * @param obj The entry object
2728 elm_entry_cursor_begin_set(Evas_Object *obj)
2730 ELM_CHECK_WIDTYPE(obj, widtype);
2731 Widget_Data *wd = elm_widget_data_get(obj);
2733 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2737 * This moves the cursor to the end of the entry.
2739 * @param obj The entry object
2744 elm_entry_cursor_end_set(Evas_Object *obj)
2746 ELM_CHECK_WIDTYPE(obj, widtype);
2747 Widget_Data *wd = elm_widget_data_get(obj);
2749 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2753 * This moves the cursor to the beginning of the current line.
2755 * @param obj The entry object
2760 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2762 ELM_CHECK_WIDTYPE(obj, widtype);
2763 Widget_Data *wd = elm_widget_data_get(obj);
2765 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2769 * This moves the cursor to the end of the current line.
2771 * @param obj The entry object
2776 elm_entry_cursor_line_end_set(Evas_Object *obj)
2778 ELM_CHECK_WIDTYPE(obj, widtype);
2779 Widget_Data *wd = elm_widget_data_get(obj);
2781 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2785 * This begins a selection within the entry as though
2786 * the user were holding down the mouse button to make a selection.
2788 * @param obj The entry object
2793 elm_entry_cursor_selection_begin(Evas_Object *obj)
2795 ELM_CHECK_WIDTYPE(obj, widtype);
2796 Widget_Data *wd = elm_widget_data_get(obj);
2798 edje_object_part_text_select_begin(wd->ent, "elm.text");
2802 * This ends a selection within the entry as though
2803 * the user had just released the mouse button while making a selection.
2805 * @param obj The entry object
2810 elm_entry_cursor_selection_end(Evas_Object *obj)
2812 ELM_CHECK_WIDTYPE(obj, widtype);
2813 Widget_Data *wd = elm_widget_data_get(obj);
2815 edje_object_part_text_select_extend(wd->ent, "elm.text");
2819 * TODO: fill this in
2821 * @param obj The entry object
2822 * @return TODO: fill this in
2827 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2829 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2830 Widget_Data *wd = elm_widget_data_get(obj);
2831 if (!wd) return EINA_FALSE;
2832 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2836 * This returns whether the cursor is visible.
2838 * @param obj The entry object
2839 * @return If true, the cursor is visible.
2844 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2846 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2847 Widget_Data *wd = elm_widget_data_get(obj);
2848 if (!wd) return EINA_FALSE;
2849 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2853 * TODO: fill this in
2855 * @param obj The entry object
2856 * @return TODO: fill this in
2861 elm_entry_cursor_content_get(const Evas_Object *obj)
2863 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2864 Widget_Data *wd = elm_widget_data_get(obj);
2865 if (!wd) return NULL;
2866 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2870 * This executes a "cut" action on the selected text in the entry.
2872 * @param obj The entry object
2877 elm_entry_selection_cut(Evas_Object *obj)
2879 ELM_CHECK_WIDTYPE(obj, widtype);
2880 Widget_Data *wd = elm_widget_data_get(obj);
2882 _cut(obj, NULL, NULL);
2886 * This executes a "copy" action on the selected text in the entry.
2888 * @param obj The entry object
2893 elm_entry_selection_copy(Evas_Object *obj)
2895 ELM_CHECK_WIDTYPE(obj, widtype);
2896 Widget_Data *wd = elm_widget_data_get(obj);
2898 _copy(obj, NULL, NULL);
2902 * This executes a "paste" action in the entry.
2904 * @param obj The entry object
2909 elm_entry_selection_paste(Evas_Object *obj)
2911 ELM_CHECK_WIDTYPE(obj, widtype);
2912 Widget_Data *wd = elm_widget_data_get(obj);
2914 _paste(obj, NULL, NULL);
2918 * This clears and frees the items in a entry's contextual (right click) menu.
2920 * @param obj The entry object
2925 elm_entry_context_menu_clear(Evas_Object *obj)
2927 ELM_CHECK_WIDTYPE(obj, widtype);
2928 Widget_Data *wd = elm_widget_data_get(obj);
2929 Elm_Entry_Context_Menu_Item *it;
2931 EINA_LIST_FREE(wd->items, it)
2933 eina_stringshare_del(it->label);
2934 eina_stringshare_del(it->icon_file);
2935 eina_stringshare_del(it->icon_group);
2941 * This adds an item to the entry's contextual menu.
2943 * @param obj The entry object
2944 * @param label The item's text label
2945 * @param icon_file The item's icon file
2946 * @param icon_type The item's icon type
2947 * @param func The callback to execute when the item is clicked
2948 * @param data The data to associate with the item for related functions
2953 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)
2955 ELM_CHECK_WIDTYPE(obj, widtype);
2956 Widget_Data *wd = elm_widget_data_get(obj);
2957 Elm_Entry_Context_Menu_Item *it;
2959 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2961 wd->items = eina_list_append(wd->items, it);
2963 it->label = eina_stringshare_add(label);
2964 it->icon_file = eina_stringshare_add(icon_file);
2965 it->icon_type = icon_type;
2967 it->data = (void *)data;
2971 * This disables the entry's contextual (right click) menu.
2973 * @param obj The entry object
2974 * @param disabled If true, the menu is disabled
2979 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2981 ELM_CHECK_WIDTYPE(obj, widtype);
2982 Widget_Data *wd = elm_widget_data_get(obj);
2984 if (wd->context_menu == !disabled) return;
2985 wd->context_menu = !disabled;
2989 * This returns whether the entry's contextual (right click) menu is disabled.
2991 * @param obj The entry object
2992 * @return If true, the menu is disabled
2997 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2999 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3000 Widget_Data *wd = elm_widget_data_get(obj);
3001 if (!wd) return EINA_FALSE;
3002 return !wd->context_menu;
3006 * This appends a custom item provider to the list for that entry
3008 * This appends the given callback. The list is walked from beginning to end
3009 * with each function called given the item href string in the text. If the
3010 * function returns an object handle other than NULL (it should create an
3011 * and object to do this), then this object is used to replace that item. If
3012 * not the next provider is called until one provides an item object, or the
3013 * default provider in entry does.
3015 * @param obj The entry object
3016 * @param func The function called to provide the item object
3017 * @param data The data passed to @p func
3022 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3024 ELM_CHECK_WIDTYPE(obj, widtype);
3025 Widget_Data *wd = elm_widget_data_get(obj);
3027 EINA_SAFETY_ON_NULL_RETURN(func);
3028 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3032 wd->item_providers = eina_list_append(wd->item_providers, ip);
3036 * This prepends a custom item provider to the list for that entry
3038 * This prepends the given callback. See elm_entry_item_provider_append() for
3041 * @param obj The entry object
3042 * @param func The function called to provide the item object
3043 * @param data The data passed to @p func
3048 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3050 ELM_CHECK_WIDTYPE(obj, widtype);
3051 Widget_Data *wd = elm_widget_data_get(obj);
3053 EINA_SAFETY_ON_NULL_RETURN(func);
3054 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3058 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
3062 * This removes a custom item provider to the list for that entry
3064 * This removes the given callback. See elm_entry_item_provider_append() for
3067 * @param obj The entry object
3068 * @param func The function called to provide the item object
3069 * @param data The data passed to @p func
3074 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3076 ELM_CHECK_WIDTYPE(obj, widtype);
3077 Widget_Data *wd = elm_widget_data_get(obj);
3079 Elm_Entry_Item_Provider *ip;
3081 EINA_SAFETY_ON_NULL_RETURN(func);
3082 EINA_LIST_FOREACH(wd->item_providers, l, ip)
3084 if ((ip->func == func) && (ip->data == data))
3086 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
3094 * Append a filter function for text inserted in the entry
3096 * Append the given callback to the list. This functions will be called
3097 * whenever any text is inserted into the entry, with the text to be inserted
3098 * as a parameter. The callback function is free to alter the text in any way
3099 * it wants, but it must remember to free the given pointer and update it.
3100 * If the new text is to be discarded, the function can free it and set it text
3101 * parameter to NULL. This will also prevent any following filters from being
3104 * @param obj The entry object
3105 * @param func The function to use as text filter
3106 * @param data User data to pass to @p func
3111 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3114 Elm_Entry_Text_Filter *tf;
3115 ELM_CHECK_WIDTYPE(obj, widtype);
3117 wd = elm_widget_data_get(obj);
3119 EINA_SAFETY_ON_NULL_RETURN(func);
3121 tf = ELM_NEW(Elm_Entry_Text_Filter);
3125 wd->text_filters = eina_list_append(wd->text_filters, tf);
3129 * Prepend a filter function for text insdrted in the entry
3131 * Prepend the given callback to the list. See elm_entry_text_filter_append()
3132 * for more information
3134 * @param obj The entry object
3135 * @param func The function to use as text filter
3136 * @param data User data to pass to @p func
3141 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3144 Elm_Entry_Text_Filter *tf;
3145 ELM_CHECK_WIDTYPE(obj, widtype);
3147 wd = elm_widget_data_get(obj);
3149 EINA_SAFETY_ON_NULL_RETURN(func);
3151 tf = ELM_NEW(Elm_Entry_Text_Filter);
3155 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
3159 * Remove a filter from the list
3161 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
3162 * for more information.
3164 * @param obj The entry object
3165 * @param func The filter function to remove
3166 * @param data The user data passed when adding the function
3171 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3175 Elm_Entry_Text_Filter *tf;
3176 ELM_CHECK_WIDTYPE(obj, widtype);
3178 wd = elm_widget_data_get(obj);
3180 EINA_SAFETY_ON_NULL_RETURN(func);
3182 EINA_LIST_FOREACH(wd->text_filters, l, tf)
3184 if ((tf->func == func) && (tf->data == data))
3186 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
3194 * This converts a markup (HTML-like) string into UTF-8.
3196 * @param s The string (in markup) to be converted
3197 * @return The converted string (in UTF-8)
3202 elm_entry_markup_to_utf8(const char *s)
3204 char *ss = _elm_util_mkup_to_text(s);
3205 if (!ss) ss = strdup("");
3210 * This converts a UTF-8 string into markup (HTML-like).
3212 * @param s The string (in UTF-8) to be converted
3213 * @return The converted string (in markup)
3218 elm_entry_utf8_to_markup(const char *s)
3220 char *ss = _elm_util_text_to_mkup(s);
3221 if (!ss) ss = strdup("");
3226 * Get the input method context in the entry widget
3228 * @param obj The entry object
3229 * @return The input method context
3233 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
3235 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3236 Widget_Data *wd = elm_widget_data_get(obj);
3237 if (!wd || !wd->ent) return NULL;
3239 return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
3243 * Set whether entry should enable the return key on soft keyboard automatically
3245 * @param obj The entry object
3246 * @param on If true, entry enables the return key on soft keyboard automatically.
3251 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
3253 ELM_CHECK_WIDTYPE(obj, widtype);
3254 Widget_Data *wd = elm_widget_data_get(obj);
3257 wd->autoreturnkey = on;
3258 _check_enable_returnkey(obj);
3262 * Set whether entry should support auto capitalization
3264 * @param obj The entry object
3265 * @param on If true, entry suports auto capitalization.
3270 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
3272 ELM_CHECK_WIDTYPE(obj, widtype);
3273 Widget_Data *wd = elm_widget_data_get(obj);
3277 wd->autocapital = EINA_FALSE;
3279 wd->autocapital = autocap;
3281 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3282 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3283 wd->autocapital = EINA_FALSE;
3285 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
3289 * Set whether entry should support auto period
3291 * @param obj The entry object
3292 * @param on If true, entry suports auto period.
3297 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
3299 ELM_CHECK_WIDTYPE(obj, widtype);
3300 Widget_Data *wd = elm_widget_data_get(obj);
3304 wd->autoperiod = EINA_FALSE;
3306 wd->autoperiod = autoperiod;
3308 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3309 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3310 wd->autoperiod = EINA_FALSE;
3312 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
3316 * Set the font size on the entry object
3318 * @param obj The entry object
3319 * @param size font size
3324 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
3326 ELM_CHECK_WIDTYPE(obj, widtype);
3327 Widget_Data *wd = elm_widget_data_get(obj);
3328 Eina_Strbuf *fontbuf = NULL;
3333 t = eina_stringshare_add(elm_entry_entry_get(obj));
3334 fontbuf = eina_strbuf_new();
3335 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
3337 if (fontsize == 0) removeflag = 1; // remove fontsize tag
3339 if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
3341 elm_entry_entry_set(obj, t);
3345 eina_strbuf_free(fontbuf);
3346 eina_stringshare_del(t);
3350 * Set the text align on the entry object
3352 * @param obj The entry object
3353 * @param align align mode
3358 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
3360 ELM_CHECK_WIDTYPE(obj, widtype);
3361 Widget_Data *wd = elm_widget_data_get(obj);
3366 t = eina_stringshare_add(elm_entry_entry_get(obj));
3368 if (len <= 0) return;
3370 if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
3371 elm_entry_entry_set(obj, t);
3375 eina_stringshare_del(t);
3379 * Set the text color on the entry object
3381 * @param obj The entry object
3382 * @param r Red property background color of The entry object
3383 * @param g Green property background color of The entry object
3384 * @param b Blue property background color of The entry object
3385 * @param a Alpha property background alpha of The entry object
3390 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3392 ELM_CHECK_WIDTYPE(obj, widtype);
3393 Widget_Data *wd = elm_widget_data_get(obj);
3394 Eina_Strbuf *colorbuf = NULL;
3399 t = eina_stringshare_add(elm_entry_entry_get(obj));
3401 if (len <= 0) return;
3402 colorbuf = eina_strbuf_new();
3403 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
3405 if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
3407 elm_entry_entry_set(obj, t);
3411 eina_strbuf_free(colorbuf);
3412 eina_stringshare_del(t);
3416 * Set background color of the entry
3418 * @param obj The entry object
3419 * @param r Red property background color of The entry object
3420 * @param g Green property background color of The entry object
3421 * @param b Blue property background color of The entry object
3422 * @param a Alpha property background alpha of The entry object
3426 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3428 ELM_CHECK_WIDTYPE(obj, widtype);
3429 Widget_Data *wd = elm_widget_data_get(obj);
3430 evas_object_color_set(wd->bg, r, g, b, a);
3432 if (wd->bgcolor == EINA_FALSE)
3435 edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3440 * Set the ellipsis behavior of the entry
3442 * @param obj The entry object
3443 * @param ellipsis To ellipsis text or not
3447 elm_entry_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
3449 ELM_CHECK_WIDTYPE(obj, widtype);
3450 Widget_Data *wd = elm_widget_data_get(obj);
3451 if (wd->ellipsis == ellipsis) return;
3452 wd->ellipsis = ellipsis;
3458 * Filter inserted text based on user defined character and byte limits
3460 * Add this filter to an entry to limit the characters that it will accept
3461 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
3462 * The funtion works on the UTF-8 representation of the string, converting
3463 * it from the set markup, thus not accounting for any format in it.
3465 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
3466 * it as data when setting the filter. In it it's possible to set limits
3467 * by character count or bytes (any of them is disabled if 0), and both can
3468 * be set at the same time. In that case, it first checks for characters,
3471 * The function will cut the inserted text in order to allow only the first
3472 * number of characters that are still allowed. The cut is made in
3473 * characters, even when limiting by bytes, in order to always contain
3474 * valid ones and avoid half unicode characters making it in.
3479 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
3481 Elm_Entry_Filter_Limit_Size *lim = data;
3484 const char *(*text_get)(const Evas_Object *);
3485 const char *widget_type;
3487 EINA_SAFETY_ON_NULL_RETURN(data);
3488 EINA_SAFETY_ON_NULL_RETURN(entry);
3489 EINA_SAFETY_ON_NULL_RETURN(text);
3491 /* hack. I don't want to copy the entire function to work with
3493 widget_type = elm_widget_type_get(entry);
3494 if (!strcmp(widget_type, "entry"))
3495 text_get = elm_entry_entry_get;
3496 else if (!strcmp(widget_type, "scrolled_entry"))
3497 text_get = elm_scrolled_entry_entry_get;
3501 current = elm_entry_markup_to_utf8(text_get(entry));
3503 if (lim->max_char_count > 0)
3506 len = evas_string_char_len_get(current);
3507 if (len >= lim->max_char_count)
3509 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3515 newlen = evas_string_char_len_get(*text);
3516 cut = strlen(*text);
3517 while ((len + newlen) > lim->max_char_count)
3519 cut = evas_string_char_prev_get(*text, cut, NULL);
3525 if (lim->max_byte_count > 0)
3527 len = strlen(current);
3528 if (len >= lim->max_byte_count)
3530 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3536 newlen = strlen(*text);
3537 while ((len + newlen) > lim->max_byte_count)
3539 int p = evas_string_char_prev_get(*text, newlen, NULL);
3540 newlen -= (newlen - p);
3543 (*text)[newlen] = 0;
3554 * Filter inserted text based on accepted or rejected sets of characters
3556 * Add this filter to an entry to restrict the set of accepted characters
3557 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
3558 * This structure contains both accepted and rejected sets, but they are
3559 * mutually exclusive. If accepted is set, it will be used, otherwise it
3560 * goes on to the rejected set.
3563 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
3565 Elm_Entry_Filter_Accept_Set *as = data;
3569 int read_idx, last_read_idx = 0, read_char;
3571 EINA_SAFETY_ON_NULL_RETURN(data);
3572 EINA_SAFETY_ON_NULL_RETURN(text);
3574 if ((!as->accepted) && (!as->rejected))
3580 goes_in = EINA_TRUE;
3585 goes_in = EINA_FALSE;
3589 read_idx = evas_string_char_next_get(*text, 0, &read_char);
3592 int cmp_idx, cmp_char;
3593 Eina_Bool in_set = EINA_FALSE;
3595 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
3598 if (read_char == cmp_char)
3603 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
3605 if (in_set == goes_in)
3607 int size = read_idx - last_read_idx;
3608 const char *src = (*text) + last_read_idx;
3610 memcpy(insert, *text + last_read_idx, size);
3613 last_read_idx = read_idx;
3614 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
3620 * This sets the file (and implicitly loads it) for the text to display and
3621 * then edit. All changes are written back to the file after a short delay if
3622 * the entry object is set to autosave.
3624 * @param obj The entry object
3625 * @param file The path to the file to load and save
3626 * @param format The file format
3631 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
3633 ELM_CHECK_WIDTYPE(obj, widtype);
3634 Widget_Data *wd = elm_widget_data_get(obj);
3636 if (wd->delay_write)
3638 ecore_timer_del(wd->delay_write);
3639 wd->delay_write = NULL;
3641 if (wd->autosave) _save(obj);
3642 eina_stringshare_replace(&wd->file, file);
3643 wd->format = format;
3648 * Gets the file to load and save and the file format
3650 * @param obj The entry object
3651 * @param file The path to the file to load and save
3652 * @param format The file format
3657 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
3659 ELM_CHECK_WIDTYPE(obj, widtype);
3660 Widget_Data *wd = elm_widget_data_get(obj);
3662 if (file) *file = wd->file;
3663 if (format) *format = wd->format;
3667 * This function writes any changes made to the file set with
3668 * elm_entry_file_set()
3670 * @param obj The entry object
3675 elm_entry_file_save(Evas_Object *obj)
3677 ELM_CHECK_WIDTYPE(obj, widtype);
3678 Widget_Data *wd = elm_widget_data_get(obj);
3680 if (wd->delay_write)
3682 ecore_timer_del(wd->delay_write);
3683 wd->delay_write = NULL;
3686 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
3690 * This sets the entry object to 'autosave' the loaded text file or not.
3692 * @param obj The entry object
3693 * @param autosave Autosave the loaded file or not
3698 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
3700 ELM_CHECK_WIDTYPE(obj, widtype);
3701 Widget_Data *wd = elm_widget_data_get(obj);
3703 wd->autosave = !!autosave;
3707 * This gets the entry object's 'autosave' status.
3709 * @param obj The entry object
3710 * @return Autosave the loaded file or not
3715 elm_entry_autosave_get(const Evas_Object *obj)
3717 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3718 Widget_Data *wd = elm_widget_data_get(obj);
3719 if (!wd) return EINA_FALSE;
3720 return wd->autosave;
3725 * Control pasting of text and images for the widget.
3727 * Normally the entry allows both text and images to be pasted. By setting
3728 * textonly to be true, this prevents images from being pasted.
3730 * Note this only changes the behaviour of text.
3732 * @param obj The entry object
3733 * @param pmode paste mode - 0 is text only, 1 is text+image+other.
3738 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
3740 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
3741 ELM_CHECK_WIDTYPE(obj, widtype);
3742 Widget_Data *wd = elm_widget_data_get(obj);
3744 textonly = !!textonly;
3745 if (wd->textonly == textonly) return;
3746 wd->textonly = !!textonly;
3750 * Getting elm_entry text paste/drop mode.
3752 * In textonly mode, only text may be pasted or dropped into the widget.
3754 * @param obj The entry object
3755 * @return If the widget only accepts text from pastes.
3760 elm_entry_cnp_textonly_get(Evas_Object *obj)
3762 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3763 Widget_Data *wd = elm_widget_data_get(obj);
3764 if (!wd) return EINA_FALSE;
3765 return wd->textonly;
3769 * This sets the attribute to show the input panel automatically.
3771 * @param obj The entry object
3772 * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
3777 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
3779 ELM_CHECK_WIDTYPE(obj, widtype);
3780 Widget_Data *wd = elm_widget_data_get(obj);
3783 wd->input_panel_enable = enabled;
3784 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
3788 * Set the input panel layout of the entry
3790 * @param obj The entry object
3791 * @param layout the layout to set
3796 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
3798 ELM_CHECK_WIDTYPE(obj, widtype);
3799 Widget_Data *wd = elm_widget_data_get(obj);
3802 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
3805 wd->input_panel_layout = layout;
3807 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);