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(data);
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 elm_cbhm_send_raw_data("show");
874 _cnpinit(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
876 Widget_Data *wd = elm_widget_data_get(data);
878 cnpwidgetdata = data;
884 _item_clicked(void *data, Evas_Object *obj, void *event_info __UNUSED__)
886 Elm_Entry_Context_Menu_Item *it = data;
887 Evas_Object *obj2 = it->obj;
888 if (it->func) it->func(it->data, obj2, NULL);
892 _long_press(void *data)
894 Widget_Data *wd = elm_widget_data_get(data);
897 const Elm_Entry_Context_Menu_Item *it;
898 if (!wd) return ECORE_CALLBACK_CANCEL;
899 if ((wd->api) && (wd->api->obj_longpress))
901 wd->api->obj_longpress(data);
903 else if (wd->context_menu)
905 const char *context_menu_orientation;
907 if (wd->hoversel) evas_object_del(wd->hoversel);
908 else elm_widget_scroll_freeze_push(data);
909 wd->hoversel = elm_hoversel_add(data);
910 context_menu_orientation = edje_object_data_get
911 (wd->ent, "context_menu_orientation");
912 if ((context_menu_orientation) &&
913 (!strcmp(context_menu_orientation, "horizontal")))
914 elm_hoversel_horizontal_set(wd->hoversel, EINA_TRUE);
915 elm_object_style_set(wd->hoversel, "entry");
916 elm_widget_sub_object_add(data, wd->hoversel);
917 elm_hoversel_label_set(wd->hoversel, "Text");
918 top = elm_widget_top_get(data);
919 if (top) elm_hoversel_hover_parent_set(wd->hoversel, top);
920 evas_object_smart_callback_add(wd->hoversel, "dismissed", _dismissed, data);
924 elm_hoversel_item_add(wd->hoversel, "Select", NULL, ELM_ICON_NONE,
926 if (1) // need way to detect if someone has a selection
929 elm_hoversel_item_add(wd->hoversel, "Paste", NULL, ELM_ICON_NONE,
934 elm_hoversel_item_add(wd->hoversel, "More", NULL, ELM_ICON_NONE,
935 _clipboard_menu, data);
942 if (wd->have_selection)
944 elm_hoversel_item_add(wd->hoversel, "Copy", NULL, ELM_ICON_NONE,
947 elm_hoversel_item_add(wd->hoversel, "Cut", NULL, ELM_ICON_NONE,
950 elm_hoversel_item_add(wd->hoversel, "Cancel", NULL, ELM_ICON_NONE,
953 elm_hoversel_item_add(wd->hoversel, "More", NULL, ELM_ICON_NONE,
954 _clipboard_menu, data);
958 EINA_LIST_FOREACH(wd->items, l, it)
960 elm_hoversel_item_add(wd->hoversel, it->label, it->icon_file,
961 it->icon_type, _item_clicked, it);
965 _hoversel_position(data);
966 evas_object_show(wd->hoversel);
967 elm_hoversel_hover_begin(wd->hoversel);
969 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
970 edje_object_part_text_select_abort(wd->ent, "elm.text");
972 wd->longpress_timer = NULL;
973 evas_object_smart_callback_call(data, SIG_LONGPRESSED, NULL);
974 return ECORE_CALLBACK_CANCEL;
978 _mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
980 Widget_Data *wd = elm_widget_data_get(data);
981 Evas_Event_Mouse_Down *ev = event_info;
983 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return;
984 if (ev->button != 1) return;
985 // if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
986 if (wd->longpress_timer) ecore_timer_del(wd->longpress_timer);
987 wd->longpress_timer = ecore_timer_add(_elm_config->longpress_timeout, _long_press, data);
988 wd->downx = ev->canvas.x;
989 wd->downy = ev->canvas.y;
991 wd->long_pressed = EINA_FALSE;
995 _mouse_up(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
997 Widget_Data *wd = elm_widget_data_get(data);
998 Evas_Event_Mouse_Up *ev = event_info;
1000 if (ev->button != 1) return;
1002 if (!wd->double_clicked)
1004 if ((wd->api) && (wd->api->obj_mouseup))
1006 wd->api->obj_mouseup(data);
1009 if (wd->longpress_timer)
1011 ecore_timer_del(wd->longpress_timer);
1012 wd->longpress_timer = NULL;
1015 elm_object_scroll_freeze_pop(data);
1019 _mouse_move(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1021 Widget_Data *wd = elm_widget_data_get(data);
1022 Evas_Event_Mouse_Move *ev = event_info;
1026 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
1028 if (wd->longpress_timer)
1030 ecore_timer_del(wd->longpress_timer);
1031 wd->longpress_timer = NULL;
1034 else if (wd->longpress_timer)
1038 dx = wd->downx - ev->cur.canvas.x;
1040 dy = wd->downy - ev->cur.canvas.y;
1043 ((_elm_config->finger_size / 2) *
1044 (_elm_config->finger_size / 2)))
1046 ecore_timer_del(wd->longpress_timer);
1047 wd->longpress_timer = NULL;
1051 else if (wd->longpress_timer)
1055 dx = wd->downx - ev->cur.canvas.x;
1057 dy = wd->downy - ev->cur.canvas.y;
1060 ((_elm_config->finger_size / 2) *
1061 (_elm_config->finger_size / 2)))
1063 ecore_timer_del(wd->longpress_timer);
1064 wd->longpress_timer = NULL;
1070 _getbase(Evas_Object *obj)
1072 Widget_Data *wd = elm_widget_data_get(obj);
1073 if (!wd) return "base";
1078 if (wd->show_last_character) return "custom-password";
1079 else return "base-password";
1083 if (wd->single_line) return "base-single";
1086 if (wd->linewrap) return "base";
1087 else if (wd->char_linewrap) return "base-charwrap";
1088 else return "base-nowrap";
1096 if (wd->show_last_character) return "custom-password";
1097 else return "base-password";
1101 if (wd->single_line) return "base-single-noedit";
1104 if (wd->linewrap) return "base-noedit";
1105 else if (wd->char_linewrap) return "base-noedit-charwrap";
1106 else return "base-nowrap-noedit";
1114 _entry_length_get(Evas_Object *obj)
1117 const char *str = elm_entry_entry_get(obj);
1120 char *plain_str = _elm_util_mkup_to_text(str);
1121 if (!plain_str) return 0;
1123 len = strlen(plain_str);
1130 _signal_entry_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1132 Widget_Data *wd = elm_widget_data_get(data);
1134 wd->changed = EINA_TRUE;
1136 if (wd->text) eina_stringshare_del(wd->text);
1138 _check_enable_returnkey(data);
1139 evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
1140 if (wd->delay_write)
1142 ecore_timer_del(wd->delay_write);
1143 wd->delay_write = NULL;
1145 if ((!wd->autosave) || (!wd->file)) return;
1146 wd->delay_write = ecore_timer_add(2.0, _delay_write, data);
1150 _signal_handler_move_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1152 Widget_Data *wd = elm_widget_data_get(data);
1153 elm_object_scroll_freeze_push(data);
1155 if ((wd->api) && (wd->api->obj_hidemenu))
1157 wd->api->obj_hidemenu(data);
1162 _signal_handler_move_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1164 Widget_Data *wd = elm_widget_data_get(data);
1165 elm_object_scroll_freeze_pop(data);
1167 if (wd->have_selection)
1172 _signal_selection_end(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1175 Widget_Data *wd = elm_widget_data_get(data);
1183 _signal_selection_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1185 Widget_Data *wd = elm_widget_data_get(data);
1189 EINA_LIST_FOREACH(entries, l, entry)
1191 if (entry != data) elm_entry_select_none(entry);
1193 wd->have_selection = EINA_TRUE;
1194 wd->selmode = EINA_TRUE;
1195 evas_object_smart_callback_call(data, SIG_SELECTION_START, NULL);
1196 #ifdef HAVE_ELEMENTARY_X
1197 if (wd->sel_notify_handler)
1199 const char *txt = elm_entry_selection_get(data);
1202 top = elm_widget_top_get(data);
1203 if ((top) && (elm_win_xwindow_get(top)))
1204 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP, txt);
1210 _signal_selection_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1212 Evas_Coord cx, cy, cw, ch;
1213 Widget_Data *wd = elm_widget_data_get(data);
1215 wd->have_selection = EINA_TRUE;
1216 wd->selmode = EINA_TRUE;
1217 evas_object_smart_callback_call(data, SIG_SELECTION_CHANGED, NULL);
1218 elm_selection_set(ELM_SEL_PRIMARY, obj, ELM_SEL_FORMAT_MARKUP,
1219 elm_entry_selection_get(data));
1221 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text", &cx, &cy, &cw, &ch);
1222 if (!wd->deferred_recalc_job)
1223 elm_widget_show_region_set(data, cx, cy, cw, ch + elm_finger_size_get());
1226 wd->deferred_cur = EINA_TRUE;
1230 wd->ch = ch + elm_finger_size_get();
1235 _signal_selection_cleared(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1237 Widget_Data *wd = elm_widget_data_get(data);
1239 if (!wd->have_selection) return;
1240 wd->have_selection = EINA_FALSE;
1241 wd->selmode = EINA_FALSE;
1242 evas_object_smart_callback_call(data, SIG_SELECTION_CLEARED, NULL);
1243 if (wd->sel_notify_handler)
1247 #ifdef HAVE_ELEMENTARY_X
1250 top = elm_widget_top_get(data);
1251 if ((top) && (elm_win_xwindow_get(top)))
1252 elm_selection_set(ELM_SEL_PRIMARY, data, ELM_SEL_FORMAT_MARKUP,
1255 eina_stringshare_del(wd->cut_sel);
1260 #ifdef HAVE_ELEMENTARY_X
1263 top = elm_widget_top_get(data);
1264 if ((top) && (elm_win_xwindow_get(top)))
1265 elm_selection_clear(ELM_SEL_PRIMARY, data);
1272 _signal_entry_paste_request(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1274 Widget_Data *wd = elm_widget_data_get(data);
1276 evas_object_smart_callback_call(data, SIG_SELECTION_PASTE, NULL);
1277 if (wd->sel_notify_handler)
1279 #ifdef HAVE_ELEMENTARY_X
1282 top = elm_widget_top_get(data);
1283 if ((top) && (elm_win_xwindow_get(top)))
1285 wd->selection_asked = EINA_TRUE;
1286 elm_selection_get(ELM_SEL_CLIPBOARD, ELM_SEL_FORMAT_MARKUP, data,
1294 _signal_entry_copy_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1296 Widget_Data *wd = elm_widget_data_get(data);
1298 evas_object_smart_callback_call(data, SIG_SELECTION_COPY, NULL);
1299 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1300 elm_entry_selection_get(data));
1304 _signal_entry_cut_notify(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1306 Widget_Data *wd = elm_widget_data_get(data);
1308 evas_object_smart_callback_call(data, SIG_SELECTION_CUT, NULL);
1309 elm_selection_set(ELM_SEL_CLIPBOARD, obj, ELM_SEL_FORMAT_MARKUP,
1310 elm_entry_selection_get(data));
1311 edje_object_part_text_insert(wd->ent, "elm.text", "");
1312 wd->changed = EINA_TRUE;
1317 _signal_cursor_changed(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1319 Widget_Data *wd = elm_widget_data_get(data);
1320 Evas_Coord cx, cy, cw, ch;
1322 evas_object_smart_callback_call(data, SIG_CURSOR_CHANGED, NULL);
1323 edje_object_part_text_cursor_geometry_get(wd->ent, "elm.text",
1324 &cx, &cy, &cw, &ch);
1325 if (!wd->deferred_recalc_job)
1326 elm_widget_show_region_set(data, cx, cy, cw, ch);
1329 wd->deferred_cur = EINA_TRUE;
1338 _signal_anchor_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1340 Widget_Data *wd = elm_widget_data_get(data);
1345 _signal_anchor_up(void *data, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
1347 Widget_Data *wd = elm_widget_data_get(data);
1348 Elm_Entry_Anchor_Info ei;
1349 char *buf2, *p, *p2, *n;
1351 p = strrchr(emission, ',');
1354 const Eina_List *geoms;
1358 while (p2 >= emission)
1360 if (*p2 == ',') break;
1364 buf2 = alloca(5 + p - p2);
1365 strncpy(buf2, p2, p - p2);
1368 ei.button = atoi(buf2);
1369 ei.x = ei.y = ei.w = ei.h = 0;
1371 edje_object_part_text_anchor_geometry_get(wd->ent, "elm.text", ei.name);
1374 Evas_Textblock_Rectangle *r;
1376 Evas_Coord px, py, x, y;
1378 evas_object_geometry_get(wd->ent, &x, &y, NULL, NULL);
1379 evas_pointer_output_xy_get(evas_object_evas_get(wd->ent), &px, &py);
1380 EINA_LIST_FOREACH(geoms, l, r)
1382 if (((r->x + x) <= px) && ((r->y + y) <= py) &&
1383 ((r->x + x + r->w) > px) && ((r->y + y + r->h) > py))
1394 evas_object_smart_callback_call(data, SIG_ANCHOR_CLICKED, &ei);
1399 _signal_anchor_move(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1401 Widget_Data *wd = elm_widget_data_get(data);
1406 _signal_anchor_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1408 Widget_Data *wd = elm_widget_data_get(data);
1413 _signal_anchor_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1415 Widget_Data *wd = elm_widget_data_get(data);
1420 _signal_key_enter(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1422 Widget_Data *wd = elm_widget_data_get(data);
1424 evas_object_smart_callback_call(data, SIG_ACTIVATED, NULL);
1428 _signal_mouse_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1430 Widget_Data *wd = elm_widget_data_get(data);
1432 wd->double_clicked = EINA_FALSE;
1433 evas_object_smart_callback_call(data, SIG_PRESS, NULL);
1435 if ((wd->api) && (wd->api->obj_hidemenu))
1437 wd->api->obj_hidemenu(data);
1442 _signal_mouse_clicked(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1444 Widget_Data *wd = elm_widget_data_get(data);
1446 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
1450 _signal_mouse_double(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1452 Widget_Data *wd = elm_widget_data_get(data);
1454 wd->double_clicked = EINA_TRUE;
1455 evas_object_smart_callback_call(data, SIG_CLICKED_DOUBLE, NULL);
1458 #ifdef HAVE_ELEMENTARY_X
1460 _event_selection_notify(void *data, int type __UNUSED__, void *event)
1462 Widget_Data *wd = elm_widget_data_get(data);
1463 Ecore_X_Event_Selection_Notify *ev = event;
1464 if (!wd) return ECORE_CALLBACK_PASS_ON;
1465 if ((!wd->selection_asked) && (!wd->drag_selection_asked))
1466 return ECORE_CALLBACK_PASS_ON;
1468 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1469 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1471 Ecore_X_Selection_Data_Text *text_data;
1473 text_data = ev->data;
1474 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1476 if (text_data->text)
1478 char *txt = _elm_util_text_to_mkup(text_data->text);
1482 elm_entry_entry_insert(data, txt);
1487 wd->selection_asked = EINA_FALSE;
1489 else if (ev->selection == ECORE_X_SELECTION_XDND)
1491 Ecore_X_Selection_Data_Text *text_data;
1493 text_data = ev->data;
1494 if (text_data->data.content == ECORE_X_SELECTION_CONTENT_TEXT)
1496 if (text_data->text)
1498 char *txt = _elm_util_text_to_mkup(text_data->text);
1502 /* Massive FIXME: this should be at the drag point */
1503 elm_entry_entry_insert(data, txt);
1508 wd->drag_selection_asked = EINA_FALSE;
1510 ecore_x_dnd_send_finished();
1513 return ECORE_CALLBACK_PASS_ON;
1517 _event_selection_clear(void *data, int type __UNUSED__, void *event)
1520 Widget_Data *wd = elm_widget_data_get(data);
1521 Ecore_X_Event_Selection_Clear *ev = event;
1522 if (!wd) return ECORE_CALLBACK_PASS_ON;
1523 if (!wd->have_selection) return ECORE_CALLBACK_PASS_ON;
1524 if ((ev->selection == ECORE_X_SELECTION_CLIPBOARD) ||
1525 (ev->selection == ECORE_X_SELECTION_PRIMARY))
1527 elm_entry_select_none(data);
1532 Evas_Object *top = elm_widget_top_get(data);
1533 Ecore_X_Event_Selection_Clear *ev = event;
1536 return ECORE_CALLBACK_PASS_ON;
1538 if (ev->selection != ECORE_X_SELECTION_SECONDARY)
1540 return ECORE_CALLBACK_PASS_ON;
1543 if (cnpwidgetdata == data)
1545 elm_selection_get(ELM_SEL_SECONDARY,ELM_SEL_FORMAT_MARKUP,data,NULL,NULL);
1549 return ECORE_CALLBACK_PASS_ON;
1554 _drag_drop_cb(void *data __UNUSED__, Evas_Object *obj, Elm_Selection_Data *drop)
1559 wd = elm_widget_data_get(obj);
1561 if (!wd) return EINA_FALSE;
1562 printf("Inserting at (%d,%d) %s\n",drop->x,drop->y,(char*)drop->data);
1564 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1565 EDJE_CURSOR_MAIN,/*->*/EDJE_CURSOR_USER);
1566 rv = edje_object_part_text_cursor_coord_set(wd->ent,"elm.text",
1567 EDJE_CURSOR_MAIN,drop->x,drop->y);
1568 if (!rv) printf("Warning: Failed to position cursor: paste anyway\n");
1569 elm_entry_entry_insert(obj, drop->data);
1570 edje_object_part_text_cursor_copy(wd->ent, "elm.text",
1571 EDJE_CURSOR_USER,/*->*/EDJE_CURSOR_MAIN);
1577 static Evas_Object *
1578 _get_item(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, const char *item)
1580 Widget_Data *wd = elm_widget_data_get(data);
1583 Elm_Entry_Item_Provider *ip;
1585 EINA_LIST_FOREACH(wd->item_providers, l, ip)
1587 o = ip->func(ip->data, data, item);
1590 if (!strncmp(item, "file://", 7))
1592 const char *fname = item + 7;
1594 o = evas_object_image_filled_add(evas_object_evas_get(data));
1595 evas_object_image_file_set(o, fname, NULL);
1596 if (evas_object_image_load_error_get(o) == EVAS_LOAD_ERROR_NONE)
1598 evas_object_show(o);
1603 o = edje_object_add(evas_object_evas_get(data));
1604 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1608 o = edje_object_add(evas_object_evas_get(data));
1609 if (!_elm_theme_object_set(data, o, "entry", item, elm_widget_style_get(data)))
1610 _elm_theme_object_set(data, o, "entry/emoticon", "wtf", elm_widget_style_get(data));
1615 _get_value_in_key_string(const char *oldstring, char *key, char **value)
1617 char *curlocater, *starttag, *endtag;
1618 int firstindex = 0, foundflag = -1;
1620 curlocater = strstr(oldstring, key);
1623 starttag = curlocater;
1624 endtag = curlocater + strlen(key);
1625 if (endtag == NULL || *endtag != '=')
1631 firstindex = abs(oldstring - curlocater);
1632 firstindex += strlen(key)+1; // strlen("key") + strlen("=")
1633 *value = (char*)(oldstring + firstindex);
1635 while (oldstring != starttag)
1637 if (*starttag == '>')
1642 if (*starttag == '<')
1646 if (starttag == NULL) break;
1649 while (NULL != endtag)
1660 if (endtag == NULL) break;
1663 if (foundflag != 0 && *starttag == '<' && *endtag == '>')
1673 if (foundflag == 1) return 0;
1679 _strbuf_key_value_replace(Eina_Strbuf *srcbuf, char *key, const char *value, int deleteflag)
1681 const char *srcstring = NULL;
1682 Eina_Strbuf *repbuf = NULL, *diffbuf = NULL;
1683 char *curlocater, *replocater;
1684 char *starttag, *endtag;
1685 int tagtxtlen = 0, insertflag = 0;
1687 srcstring = eina_strbuf_string_get(srcbuf);
1688 curlocater = strstr(srcstring, key);
1690 if (!curlocater || !srcstring)
1698 starttag = strchr(srcstring, '<');
1699 endtag = strchr(srcstring, '>');
1700 tagtxtlen = endtag - starttag;
1701 if (tagtxtlen <= 0) tagtxtlen = 0;
1702 if (starttag < curlocater && curlocater < endtag) break;
1703 if (endtag != NULL && endtag+1 != NULL)
1704 srcstring = endtag+1;
1707 } while (strlen(srcstring) > 1);
1709 if (starttag && endtag && tagtxtlen > strlen(key))
1711 repbuf = eina_strbuf_new();
1712 diffbuf = eina_strbuf_new();
1713 eina_strbuf_append_n(repbuf, starttag, tagtxtlen);
1714 srcstring = eina_strbuf_string_get(repbuf);
1715 curlocater = strstr(srcstring, key);
1717 if (curlocater != NULL)
1719 replocater = curlocater + strlen(key) + 1;
1721 while ((*replocater) && (*replocater != ' ') && (*replocater != '>'))
1724 if (replocater-curlocater > strlen(key)+1)
1726 eina_strbuf_append_n(diffbuf, curlocater, replocater-curlocater+1);
1735 eina_strbuf_reset(repbuf);
1743 if (repbuf == NULL) repbuf = eina_strbuf_new();
1744 if (diffbuf == NULL) diffbuf = eina_strbuf_new();
1748 eina_strbuf_append_printf(repbuf, "<%s=%s>", key, value);
1749 eina_strbuf_prepend(srcbuf, eina_strbuf_string_get(repbuf));
1755 eina_strbuf_prepend(diffbuf, "<");
1756 eina_strbuf_append(diffbuf, ">");
1757 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), "");
1761 eina_strbuf_append_printf(repbuf, "%s=%s", key, value);
1762 eina_strbuf_replace_first(srcbuf, eina_strbuf_string_get(diffbuf), eina_strbuf_string_get(repbuf));
1766 if (repbuf) eina_strbuf_free(repbuf);
1767 if (diffbuf) eina_strbuf_free(diffbuf);
1773 _stringshare_key_value_replace(const char **srcstring, char *key, const char *value, int deleteflag)
1775 Eina_Strbuf *sharebuf = NULL;
1777 sharebuf = eina_strbuf_new();
1778 eina_strbuf_append(sharebuf, *srcstring);
1779 _strbuf_key_value_replace(sharebuf, key, value, deleteflag);
1780 eina_stringshare_del(*srcstring);
1781 *srcstring = eina_stringshare_add(eina_strbuf_string_get(sharebuf));
1782 eina_strbuf_free(sharebuf);
1788 _is_width_over(Evas_Object *obj)
1790 Evas_Coord x, y, w, h;
1791 Evas_Coord vx, vy, vw, vh;
1792 Widget_Data *wd = elm_widget_data_get(obj);
1796 edje_object_part_geometry_get(wd->ent,"elm.text",&x,&y,&w,&h);
1798 evas_object_geometry_get (obj, &vx,&vy,&vw,&vh);
1800 if (x >= 0 && y >= 0)
1803 if (4 < wd->wrap_w && w > wd->wrap_w)
1810 _reverse_ellipsis_entry(Evas_Object *obj)
1812 Widget_Data *wd = elm_widget_data_get(obj);
1813 int cur_fontsize = 0;
1814 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1815 char *kvalue = NULL;
1816 const char *minfont, *deffont, *maxfont;
1817 const char *ellipsis_string = "...";
1818 int minfontsize, maxfontsize, minshowcount;
1820 minshowcount = strlen(ellipsis_string) + 1;
1821 minfont = edje_object_data_get(wd->ent, "min_font_size");
1822 if (minfont) minfontsize = atoi(minfont);
1823 else minfontsize = 1;
1824 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1825 if (maxfont) maxfontsize = atoi(maxfont);
1826 else maxfontsize = 1;
1827 deffont = edje_object_data_get(wd->ent, "default_font_size");
1828 if (deffont) cur_fontsize = atoi(deffont);
1829 else cur_fontsize = 1;
1830 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1831 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1833 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1835 if (kvalue != NULL) cur_fontsize = atoi(kvalue);
1838 txtbuf = eina_strbuf_new();
1839 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1841 if (cur_fontsize >= atoi(deffont))
1843 if (txtbuf) eina_strbuf_free(txtbuf);
1847 if (_is_width_over(obj) != 1)
1849 int rev_fontsize = cur_fontsize;
1853 if (rev_fontsize > atoi(deffont))
1856 if (fontbuf != NULL)
1858 eina_strbuf_free(fontbuf);
1861 fontbuf = eina_strbuf_new();
1862 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1863 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1864 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1866 eina_strbuf_free(fontbuf);
1868 } while (_is_width_over(obj) != 1);
1870 while (_is_width_over(obj))
1873 if (rev_fontsize < atoi(deffont))
1876 if (fontbuf != NULL)
1878 eina_strbuf_free(fontbuf);
1881 fontbuf = eina_strbuf_new();
1882 eina_strbuf_append_printf(fontbuf, "%d", rev_fontsize);
1883 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1884 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1885 eina_strbuf_free(fontbuf);
1890 if (txtbuf) eina_strbuf_free(txtbuf);
1896 _ellipsis_entry_to_width(Evas_Object *obj)
1898 Widget_Data *wd = elm_widget_data_get(obj);
1899 int cur_fontsize = 0, len, jumpcount;
1900 Eina_Strbuf *fontbuf = NULL, *txtbuf = NULL;
1901 char *kvalue = NULL;
1902 const char *minfont, *deffont, *maxfont;
1903 const char *ellipsis_string = "...";
1904 int minfontsize, maxfontsize, minshowcount;
1905 int i, tagend, cur_len;
1908 minshowcount = strlen(ellipsis_string) + 1;
1909 minfont = edje_object_data_get(wd->ent, "min_font_size");
1910 if (minfont) minfontsize = atoi(minfont);
1911 else minfontsize = 1;
1912 maxfont = edje_object_data_get(wd->ent, "max_font_size");
1913 if (maxfont) maxfontsize = atoi(maxfont);
1914 else maxfontsize = 1;
1915 deffont = edje_object_data_get(wd->ent, "default_font_size");
1916 if (deffont) cur_fontsize = atoi(deffont);
1917 else cur_fontsize = 1;
1918 if (minfontsize == maxfontsize || cur_fontsize == 1) return; // theme is not ready for ellipsis
1919 if (strlen(edje_object_part_text_get(wd->ent, "elm.text")) <= 0) return;
1921 if (_get_value_in_key_string(edje_object_part_text_get(wd->ent, "elm.text"), "font_size", &kvalue) == 0)
1923 if (kvalue != NULL) cur_fontsize = atoi(kvalue);
1926 txtbuf = eina_strbuf_new();
1927 eina_strbuf_append(txtbuf, edje_object_part_text_get(wd->ent, "elm.text"));
1929 while (_is_width_over(obj))
1931 if (wd->ellipsis_threshold == 0)
1932 wd->ellipsis_threshold = _entry_length_get(obj);
1933 if (cur_fontsize > minfontsize)
1936 if (fontbuf != NULL)
1938 eina_strbuf_free(fontbuf);
1941 fontbuf = eina_strbuf_new();
1942 eina_strbuf_append_printf(fontbuf, "%d", cur_fontsize);
1943 _strbuf_key_value_replace(txtbuf, "font_size", eina_strbuf_string_get(fontbuf), 0);
1944 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1945 eina_strbuf_free(fontbuf);
1947 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1951 len = _entry_length_get(obj);
1952 cur_str = (char*)edje_object_part_text_get(wd->ent, "elm.text");
1953 cur_len = strlen(cur_str);
1955 for (i = 0; i < len; i++)
1957 if(cur_str[i] == '>' && cur_str[i+1] != '\0' &&
1958 cur_str[i+1] != '<')
1965 while (jumpcount < len-strlen(ellipsis_string))
1967 cur_str = (char*)edje_object_part_text_get(wd->ent, "elm.text");
1971 eina_strbuf_free(txtbuf);
1974 txtbuf = eina_strbuf_new();
1975 eina_strbuf_append_n(txtbuf, cur_str, tagend+1);
1976 eina_strbuf_append(txtbuf, ellipsis_string);
1977 eina_strbuf_append(txtbuf, cur_str+tagend+jumpcount+1);
1978 edje_object_part_text_set(wd->ent, "elm.text", eina_strbuf_string_get(txtbuf));
1979 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
1981 if (_is_width_over(obj))
1989 if (txtbuf) eina_strbuf_free(txtbuf);
1994 static Eina_Bool *_textinput_control_function(void *data,void *input_data)
1996 /* calculate character count */
1997 Evas_Object *entry = (Evas_Object *)data;
1998 Widget_Data *wd = elm_widget_data_get((Evas_Object *)data);
2001 size_t insert_text_len=0;
2002 char *text = (char*)edje_object_part_text_get(wd->ent, "elm.text");
2004 size_t remain_bytes;
2007 byte_len = strlen(text); /* no of bytes */
2008 remain_bytes = wd->max_no_of_bytes - byte_len;
2009 sprintf(buf,"%d",remain_bytes);
2010 //edje_object_part_text_set(wd->ent, "elm_entry_remain_byte_count", buf);
2013 insert_text = (char *)input_data;
2014 insert_text_len = strlen(insert_text);
2015 if (remain_bytes < insert_text_len)
2017 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2020 if (byte_len >= wd->max_no_of_bytes)
2022 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
2032 _text_filter(void *data, Evas_Object *edje __UNUSED__, const char *part __UNUSED__, Edje_Text_Filter_Type type, char **text)
2034 Widget_Data *wd = elm_widget_data_get(data);
2036 Elm_Entry_Text_Filter *tf;
2038 if (type == EDJE_TEXT_FILTER_FORMAT)
2041 EINA_LIST_FOREACH(wd->text_filters, l, tf)
2043 tf->func(tf->data, data, text);
2050 * This adds an entry to @p parent object.
2052 * @param parent The parent object
2053 * @return The new object or NULL if it cannot be created
2058 elm_entry_add(Evas_Object *parent)
2060 Evas_Object *obj, *top;
2064 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
2066 wd = ELM_NEW(Widget_Data);
2067 e = evas_object_evas_get(parent);
2068 if (!e) return NULL;
2069 wd->bgcolor = EINA_FALSE;
2070 wd->bg = evas_object_rectangle_add(e);
2071 evas_object_color_set(wd->bg, 0, 0, 0, 0);
2072 obj = elm_widget_add(e);
2073 ELM_SET_WIDTYPE(widtype, "entry");
2074 elm_widget_type_set(obj, "entry");
2075 elm_widget_sub_object_add(parent, obj);
2076 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
2077 elm_widget_data_set(obj, wd);
2078 elm_widget_del_hook_set(obj, _del_hook);
2079 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
2080 elm_widget_theme_hook_set(obj, _theme_hook);
2081 elm_widget_disable_hook_set(obj, _disable_hook);
2082 elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
2083 elm_widget_on_focus_region_hook_set(obj, _on_focus_region_hook);
2084 elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
2085 elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
2086 elm_object_cursor_set(obj, ELM_CURSOR_XTERM);
2087 elm_widget_can_focus_set(obj, EINA_TRUE);
2088 elm_widget_highlight_ignore_set(obj, EINA_TRUE);
2090 wd->linewrap = EINA_TRUE;
2091 wd->ellipsis = EINA_FALSE;
2092 wd->char_linewrap= EINA_FALSE;
2093 wd->editable = EINA_TRUE;
2094 wd->disabled = EINA_FALSE;
2095 wd->context_menu = EINA_TRUE;
2096 wd->autosave = EINA_TRUE;
2097 wd->textonly = EINA_FALSE;
2098 wd->autoperiod = EINA_TRUE;
2100 wd->ellipsis_threshold = 0;
2102 wd->ent = edje_object_add(e);
2103 edje_object_item_provider_set(wd->ent, _get_item, obj);
2104 edje_object_text_insert_filter_callback_add(wd->ent,"elm.text", _text_filter, obj);
2105 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOVE, _move, obj);
2106 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_RESIZE, _resize, obj);
2107 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_DOWN,
2109 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_UP,
2111 evas_object_event_callback_add(wd->ent, EVAS_CALLBACK_MOUSE_MOVE,
2114 _elm_theme_object_set(obj, wd->ent, "entry", "base", "default");
2115 edje_object_signal_callback_add(wd->ent, "entry,changed", "elm.text",
2116 _signal_entry_changed, obj);
2117 edje_object_signal_callback_add(wd->ent, "handler,move,start", "elm.text",
2118 _signal_handler_move_start, obj);
2119 edje_object_signal_callback_add(wd->ent, "handler,move,end", "elm.text",
2120 _signal_handler_move_end, obj);
2121 edje_object_signal_callback_add(wd->ent, "selection,start", "elm.text",
2122 _signal_selection_start, obj);
2123 edje_object_signal_callback_add(wd->ent, "selection,end", "elm.text",
2124 _signal_selection_end, obj);
2125 edje_object_signal_callback_add(wd->ent, "selection,changed", "elm.text",
2126 _signal_selection_changed, obj);
2127 edje_object_signal_callback_add(wd->ent, "selection,cleared", "elm.text",
2128 _signal_selection_cleared, obj);
2129 edje_object_signal_callback_add(wd->ent, "entry,paste,request", "elm.text",
2130 _signal_entry_paste_request, obj);
2131 edje_object_signal_callback_add(wd->ent, "entry,copy,notify", "elm.text",
2132 _signal_entry_copy_notify, obj);
2133 edje_object_signal_callback_add(wd->ent, "entry,cut,notify", "elm.text",
2134 _signal_entry_cut_notify, obj);
2135 edje_object_signal_callback_add(wd->ent, "cursor,changed", "elm.text",
2136 _signal_cursor_changed, obj);
2137 edje_object_signal_callback_add(wd->ent, "anchor,mouse,down,*", "elm.text",
2138 _signal_anchor_down, obj);
2139 edje_object_signal_callback_add(wd->ent, "anchor,mouse,up,*", "elm.text",
2140 _signal_anchor_up, obj);
2141 edje_object_signal_callback_add(wd->ent, "anchor,mouse,move,*", "elm.text",
2142 _signal_anchor_move, obj);
2143 edje_object_signal_callback_add(wd->ent, "anchor,mouse,in,*", "elm.text",
2144 _signal_anchor_in, obj);
2145 edje_object_signal_callback_add(wd->ent, "anchor,mouse,out,*", "elm.text",
2146 _signal_anchor_out, obj);
2147 edje_object_signal_callback_add(wd->ent, "entry,key,enter", "elm.text",
2148 _signal_key_enter, obj);
2149 edje_object_signal_callback_add(wd->ent, "mouse,down,1", "elm.text",
2150 _signal_mouse_down, obj);
2151 edje_object_signal_callback_add(wd->ent, "mouse,clicked,1", "elm.text",
2152 _signal_mouse_clicked, obj);
2153 edje_object_signal_callback_add(wd->ent, "mouse,down,1,double", "elm.text",
2154 _signal_mouse_double, obj);
2155 edje_object_part_text_set(wd->ent, "elm.text", "");
2156 elm_widget_resize_object_set(obj, wd->ent);
2159 wd->input_panel_enable = edje_object_part_text_input_panel_enabled_get(wd->ent, "elm.text");
2161 #ifdef HAVE_ELEMENTARY_X
2162 top = elm_widget_top_get(obj);
2163 if ((top) && (elm_win_xwindow_get(top)))
2165 wd->sel_notify_handler =
2166 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_NOTIFY,
2167 _event_selection_notify, obj);
2168 wd->sel_clear_handler =
2169 ecore_event_handler_add(ECORE_X_EVENT_SELECTION_CLEAR,
2170 _event_selection_clear, obj);
2173 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP,_drag_drop_cb, NULL);
2176 entries = eina_list_prepend(entries, obj);
2178 // module - find module for entry
2179 wd->api = _module(obj);
2180 // if found - hook in
2181 if ((wd->api) && (wd->api->obj_hook)) wd->api->obj_hook(obj);
2183 // TODO: convert Elementary to subclassing of Evas_Smart_Class
2184 // TODO: and save some bytes, making descriptions per-class and not instance!
2185 evas_object_smart_callbacks_descriptions_set(obj, _signals);
2189 EAPI void elm_entry_extension_module_data_get(Evas_Object *obj,Elm_Entry_Extension_data *ext_mod)
2191 ELM_CHECK_WIDTYPE(obj, widtype);
2192 Widget_Data *wd = elm_widget_data_get(obj);
2194 ext_mod->cancel = _cancel;
2195 ext_mod->copy = _copy;
2196 ext_mod->cut = _cut;
2197 ext_mod->paste = _paste;
2198 ext_mod->select = _select;
2199 ext_mod->selectall = _selectall;
2200 ext_mod->ent = wd->ent;
2201 ext_mod->items = wd->items;
2202 ext_mod->longpress_timer = wd->longpress_timer;
2203 ext_mod->editable = wd->editable;
2204 ext_mod->have_selection = wd->have_selection;
2205 ext_mod->password = wd->password;
2206 ext_mod->selmode = wd->selmode;
2207 ext_mod->cnpinit = _cnpinit;
2208 ext_mod->context_menu = wd->context_menu;
2212 * This sets the entry object not to line wrap. All input will
2213 * be on a single line, and the entry box will extend with user input.
2215 * @param obj The entry object
2216 * @param single_line If true, the text in the entry
2217 * will be on a single line.
2222 elm_entry_single_line_set(Evas_Object *obj, Eina_Bool single_line)
2224 ELM_CHECK_WIDTYPE(obj, widtype);
2225 Widget_Data *wd = elm_widget_data_get(obj);
2227 Ecore_IMF_Context *ic;
2229 if (wd->single_line == single_line) return;
2230 wd->single_line = single_line;
2231 wd->linewrap = EINA_FALSE;
2232 wd->char_linewrap = EINA_FALSE;
2233 elm_entry_cnp_textonly_set(obj, EINA_TRUE);
2234 t = eina_stringshare_add(elm_entry_entry_get(obj));
2235 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2236 elm_entry_entry_set(obj, t);
2237 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
2238 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
2239 ic = elm_entry_imf_context_get(obj);
2242 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2245 eina_stringshare_del(t);
2250 * This returns true if the entry has been set to single line mode.
2251 * See also elm_entry_single_line_set().
2253 * @param obj The entry object
2254 * @return single_line If true, the text in the entry is set to display
2260 elm_entry_single_line_get(const Evas_Object *obj)
2262 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2263 Widget_Data *wd = elm_widget_data_get(obj);
2264 if (!wd) return EINA_FALSE;
2265 return wd->single_line;
2269 * This set's the maximum bytes that can be added in entry.
2271 * @param obj The entry object
2272 * @param max_no_of_bytes Maximum number of bytes entry can have.
2277 elm_entry_maximum_bytes_set(Evas_Object *obj, int max_no_of_bytes)
2279 Widget_Data *wd = elm_widget_data_get(obj);
2281 wd->max_no_of_bytes = max_no_of_bytes;
2282 edje_object_part_textinput_callback_set(wd->ent, "elm.text", _textinput_control_function,obj);
2287 * This sets the entry object to password mode. All text entered
2288 * and/or displayed within the widget will be replaced with asterisks (*).
2290 * @param obj The entry object
2291 * @param password If true, password mode is enabled.
2296 elm_entry_password_set(Evas_Object *obj, Eina_Bool password)
2298 ELM_CHECK_WIDTYPE(obj, widtype);
2299 Widget_Data *wd = elm_widget_data_get(obj);
2300 Ecore_IMF_Context *ic;
2303 if (wd->password == password) return;
2304 wd->password = password;
2305 wd->single_line = EINA_TRUE;
2306 wd->linewrap = EINA_FALSE;
2307 wd->char_linewrap = EINA_FALSE;
2308 if (_elm_config->password_show_last_character)
2309 wd->show_last_character = EINA_TRUE;
2310 t = eina_stringshare_add(elm_entry_entry_get(obj));
2311 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2312 elm_entry_entry_set(obj, t);
2317 elm_entry_autoperiod_set(obj, EINA_FALSE);
2319 if (wd->autocapital)
2320 elm_entry_autocapitalization_set(obj, EINA_FALSE);
2323 ic = elm_entry_imf_context_get(obj);
2325 ecore_imf_context_input_panel_layout_set(ic, wd->input_panel_layout);
2327 eina_stringshare_del(t);
2333 * This returns whether password mode is enabled.
2334 * See also elm_entry_password_set().
2336 * @param obj The entry object
2337 * @return If true, the entry is set to display all characters
2343 elm_entry_password_get(const Evas_Object *obj)
2345 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2346 Widget_Data *wd = elm_widget_data_get(obj);
2347 if (!wd) return EINA_FALSE;
2348 return wd->password;
2352 * This sets the text displayed within the entry to @p entry.
2354 * @param obj The entry object
2355 * @param entry The text to be displayed
2360 elm_entry_entry_set(Evas_Object *obj, const char *entry)
2362 ELM_CHECK_WIDTYPE(obj, widtype);
2363 Widget_Data *wd = elm_widget_data_get(obj);
2365 if (!entry) entry = "";
2366 if(wd->max_no_of_bytes)
2368 int len = strlen(entry);
2369 if(len > wd->max_no_of_bytes)
2371 ERR("[ERROR]the length of the text set is more than max no of bytes, text cannot be set");
2375 edje_object_part_text_set(wd->ent, "elm.text", entry);
2376 if (wd->text) eina_stringshare_del(wd->text);
2378 wd->changed = EINA_TRUE;
2383 * This returns the text currently shown in object @p entry.
2384 * See also elm_entry_entry_set().
2386 * @param obj The entry object
2387 * @return The currently displayed text or NULL on failure
2392 elm_entry_entry_get(const Evas_Object *obj)
2394 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2395 Widget_Data *wd = elm_widget_data_get(obj);
2397 if (!wd) return NULL;
2399 if ((wd->text)&&(wd->password))
2400 return elm_entry_markup_to_utf8(wd->text);
2402 if (wd->text) return wd->text;
2403 text = edje_object_part_text_get(wd->ent, "elm.text");
2406 ERR("text=NULL for edje %p, part 'elm.text'", wd->ent);
2409 eina_stringshare_replace(&wd->text, text);
2410 if(wd->password)return elm_entry_markup_to_utf8(wd->text);
2415 * This returns all selected text within the entry.
2417 * @param obj The entry object
2418 * @return The selected text within the entry or NULL on failure
2423 elm_entry_selection_get(const Evas_Object *obj)
2425 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2426 Widget_Data *wd = elm_widget_data_get(obj);
2427 if (!wd) return NULL;
2428 return edje_object_part_text_selection_get(wd->ent, "elm.text");
2432 * This inserts text in @p entry where the current cursor position.
2434 * This inserts text at the cursor position is as if it was typed
2435 * by the user (note this also allows markup which a user
2436 * can't just "type" as it would be converted to escaped text, so this
2437 * call can be used to insert things like emoticon items or bold push/pop
2438 * tags, other font and color change tags etc.)
2440 * @param obj The entry object
2441 * @param entry The text to insert
2446 elm_entry_entry_insert(Evas_Object *obj, const char *entry)
2448 ELM_CHECK_WIDTYPE(obj, widtype);
2449 Widget_Data *wd = elm_widget_data_get(obj);
2451 edje_object_part_text_insert(wd->ent, "elm.text", entry);
2453 if (cnpwidgetdata == obj)
2454 ecore_x_selection_secondary_set(elm_win_xwindow_get(obj), "",1);
2456 wd->changed = EINA_TRUE;
2461 * This enables word line wrapping in the entry object. It is the opposite
2462 * of elm_entry_single_line_set(). Additionally, setting this disables
2463 * character line wrapping.
2464 * See also elm_entry_line_char_wrap_set().
2466 * @param obj The entry object
2467 * @param wrap If true, the entry will be wrapped once it reaches the end
2468 * of the object. Wrapping will occur at the end of the word before the end of the
2474 elm_entry_line_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2476 ELM_CHECK_WIDTYPE(obj, widtype);
2477 Widget_Data *wd = elm_widget_data_get(obj);
2480 if (wd->linewrap == wrap) return;
2481 wd->linewrap = wrap;
2483 wd->char_linewrap = EINA_FALSE;
2484 t = eina_stringshare_add(elm_entry_entry_get(obj));
2485 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2486 elm_entry_entry_set(obj, t);
2487 eina_stringshare_del(t);
2492 * Set wrap width of the entry
2494 * @param obj The entry object
2495 * @param w The wrap width in pixels at a minimum where words need to wrap
2499 elm_entry_wrap_width_set(Evas_Object *obj, Evas_Coord w)
2501 Widget_Data *wd = elm_widget_data_get(obj);
2502 if (wd->wrap_w == w) return;
2508 * get wrap width of the entry
2510 * @param obj The entry object
2511 * @return The wrap width in pixels at a minimum where words need to wrap
2515 elm_entry_wrap_width_get(const Evas_Object *obj)
2517 Widget_Data *wd = elm_widget_data_get(obj);
2522 * This enables character line wrapping in the entry object. It is the opposite
2523 * of elm_entry_single_line_set(). Additionally, setting this disables
2524 * word line wrapping.
2525 * See also elm_entry_line_wrap_set().
2527 * @param obj The entry object
2528 * @param wrap If true, the entry will be wrapped once it reaches the end
2529 * of the object. Wrapping will occur immediately upon reaching the end of the object.
2534 elm_entry_line_char_wrap_set(Evas_Object *obj, Eina_Bool wrap)
2536 ELM_CHECK_WIDTYPE(obj, widtype);
2537 Widget_Data *wd = elm_widget_data_get(obj);
2540 if (wd->char_linewrap == wrap) return;
2541 wd->char_linewrap = wrap;
2542 if(wd->char_linewrap)
2543 wd->linewrap = EINA_FALSE;
2544 t = eina_stringshare_add(elm_entry_entry_get(obj));
2545 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2546 elm_entry_entry_set(obj, t);
2547 eina_stringshare_del(t);
2552 * This sets the editable attribute of the entry.
2554 * @param obj The entry object
2555 * @param editable If true, the entry will be editable by the user.
2556 * If false, it will be set to the disabled state.
2561 elm_entry_editable_set(Evas_Object *obj, Eina_Bool editable)
2563 ELM_CHECK_WIDTYPE(obj, widtype);
2564 Widget_Data *wd = elm_widget_data_get(obj);
2567 if (wd->editable == editable) return;
2568 wd->editable = editable;
2569 t = eina_stringshare_add(elm_entry_entry_get(obj));
2570 _elm_theme_object_set(obj, wd->ent, "entry", _getbase(obj), elm_widget_style_get(obj));
2571 elm_entry_entry_set(obj, t);
2572 eina_stringshare_del(t);
2575 #ifdef HAVE_ELEMENTARY_X
2577 elm_drop_target_add(obj, ELM_SEL_FORMAT_MARKUP, _drag_drop_cb, NULL);
2579 elm_drop_target_del(obj);
2584 * This gets the editable attribute of the entry.
2585 * See also elm_entry_editable_set().
2587 * @param obj The entry object
2588 * @return If true, the entry is editable by the user.
2589 * If false, it is not editable by the user
2594 elm_entry_editable_get(const Evas_Object *obj)
2596 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2597 Widget_Data *wd = elm_widget_data_get(obj);
2598 if (!wd) return EINA_FALSE;
2599 return wd->editable;
2603 * This drops any existing text selection within the entry.
2605 * @param obj The entry object
2610 elm_entry_select_none(Evas_Object *obj)
2612 ELM_CHECK_WIDTYPE(obj, widtype);
2613 Widget_Data *wd = elm_widget_data_get(obj);
2617 wd->selmode = EINA_FALSE;
2618 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2619 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2621 wd->have_selection = EINA_FALSE;
2622 edje_object_part_text_select_none(wd->ent, "elm.text");
2626 * This selects all text within the entry.
2628 * @param obj The entry object
2633 elm_entry_select_all(Evas_Object *obj)
2635 ELM_CHECK_WIDTYPE(obj, widtype);
2636 Widget_Data *wd = elm_widget_data_get(obj);
2640 wd->selmode = EINA_FALSE;
2641 edje_object_part_text_select_allow_set(wd->ent, "elm.text", EINA_FALSE);
2642 edje_object_signal_emit(wd->ent, "elm,state,select,off", "elm");
2644 wd->have_selection = EINA_TRUE;
2645 edje_object_part_text_select_all(wd->ent, "elm.text");
2649 * This moves the cursor one place to the right within the entry.
2651 * @param obj The entry object
2652 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2657 elm_entry_cursor_next(Evas_Object *obj)
2659 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2660 Widget_Data *wd = elm_widget_data_get(obj);
2661 if (!wd) return EINA_FALSE;
2662 return edje_object_part_text_cursor_next(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2666 * This moves the cursor one place to the left within the entry.
2668 * @param obj The entry object
2669 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2674 elm_entry_cursor_prev(Evas_Object *obj)
2676 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2677 Widget_Data *wd = elm_widget_data_get(obj);
2678 if (!wd) return EINA_FALSE;
2679 return edje_object_part_text_cursor_prev(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2683 * This moves the cursor one line up within the entry.
2685 * @param obj The entry object
2686 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2691 elm_entry_cursor_up(Evas_Object *obj)
2693 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2694 Widget_Data *wd = elm_widget_data_get(obj);
2695 if (!wd) return EINA_FALSE;
2696 return edje_object_part_text_cursor_up(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2700 * This moves the cursor one line down within the entry.
2702 * @param obj The entry object
2703 * @return EINA_TRUE upon success, EINA_FALSE upon failure
2708 elm_entry_cursor_down(Evas_Object *obj)
2710 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2711 Widget_Data *wd = elm_widget_data_get(obj);
2712 if (!wd) return EINA_FALSE;
2713 return edje_object_part_text_cursor_down(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2717 * This moves the cursor to the beginning of the entry.
2719 * @param obj The entry object
2724 elm_entry_cursor_begin_set(Evas_Object *obj)
2726 ELM_CHECK_WIDTYPE(obj, widtype);
2727 Widget_Data *wd = elm_widget_data_get(obj);
2729 edje_object_part_text_cursor_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2733 * This moves the cursor to the end of the entry.
2735 * @param obj The entry object
2740 elm_entry_cursor_end_set(Evas_Object *obj)
2742 ELM_CHECK_WIDTYPE(obj, widtype);
2743 Widget_Data *wd = elm_widget_data_get(obj);
2745 edje_object_part_text_cursor_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2749 * This moves the cursor to the beginning of the current line.
2751 * @param obj The entry object
2756 elm_entry_cursor_line_begin_set(Evas_Object *obj)
2758 ELM_CHECK_WIDTYPE(obj, widtype);
2759 Widget_Data *wd = elm_widget_data_get(obj);
2761 edje_object_part_text_cursor_line_begin_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2765 * This moves the cursor to the end of the current line.
2767 * @param obj The entry object
2772 elm_entry_cursor_line_end_set(Evas_Object *obj)
2774 ELM_CHECK_WIDTYPE(obj, widtype);
2775 Widget_Data *wd = elm_widget_data_get(obj);
2777 edje_object_part_text_cursor_line_end_set(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2781 * This begins a selection within the entry as though
2782 * the user were holding down the mouse button to make a selection.
2784 * @param obj The entry object
2789 elm_entry_cursor_selection_begin(Evas_Object *obj)
2791 ELM_CHECK_WIDTYPE(obj, widtype);
2792 Widget_Data *wd = elm_widget_data_get(obj);
2794 edje_object_part_text_select_begin(wd->ent, "elm.text");
2798 * This ends a selection within the entry as though
2799 * the user had just released the mouse button while making a selection.
2801 * @param obj The entry object
2806 elm_entry_cursor_selection_end(Evas_Object *obj)
2808 ELM_CHECK_WIDTYPE(obj, widtype);
2809 Widget_Data *wd = elm_widget_data_get(obj);
2811 edje_object_part_text_select_extend(wd->ent, "elm.text");
2815 * TODO: fill this in
2817 * @param obj The entry object
2818 * @return TODO: fill this in
2823 elm_entry_cursor_is_format_get(const Evas_Object *obj)
2825 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2826 Widget_Data *wd = elm_widget_data_get(obj);
2827 if (!wd) return EINA_FALSE;
2828 return edje_object_part_text_cursor_is_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2832 * This returns whether the cursor is visible.
2834 * @param obj The entry object
2835 * @return If true, the cursor is visible.
2840 elm_entry_cursor_is_visible_format_get(const Evas_Object *obj)
2842 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2843 Widget_Data *wd = elm_widget_data_get(obj);
2844 if (!wd) return EINA_FALSE;
2845 return edje_object_part_text_cursor_is_visible_format_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2849 * TODO: fill this in
2851 * @param obj The entry object
2852 * @return TODO: fill this in
2857 elm_entry_cursor_content_get(const Evas_Object *obj)
2859 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2860 Widget_Data *wd = elm_widget_data_get(obj);
2861 if (!wd) return NULL;
2862 return edje_object_part_text_cursor_content_get(wd->ent, "elm.text", EDJE_CURSOR_MAIN);
2866 * This executes a "cut" action on the selected text in the entry.
2868 * @param obj The entry object
2873 elm_entry_selection_cut(Evas_Object *obj)
2875 ELM_CHECK_WIDTYPE(obj, widtype);
2876 Widget_Data *wd = elm_widget_data_get(obj);
2878 _cut(obj, NULL, NULL);
2882 * This executes a "copy" action on the selected text in the entry.
2884 * @param obj The entry object
2889 elm_entry_selection_copy(Evas_Object *obj)
2891 ELM_CHECK_WIDTYPE(obj, widtype);
2892 Widget_Data *wd = elm_widget_data_get(obj);
2894 _copy(obj, NULL, NULL);
2898 * This executes a "paste" action in the entry.
2900 * @param obj The entry object
2905 elm_entry_selection_paste(Evas_Object *obj)
2907 ELM_CHECK_WIDTYPE(obj, widtype);
2908 Widget_Data *wd = elm_widget_data_get(obj);
2910 _paste(obj, NULL, NULL);
2914 * This clears and frees the items in a entry's contextual (right click) menu.
2916 * @param obj The entry object
2921 elm_entry_context_menu_clear(Evas_Object *obj)
2923 ELM_CHECK_WIDTYPE(obj, widtype);
2924 Widget_Data *wd = elm_widget_data_get(obj);
2925 Elm_Entry_Context_Menu_Item *it;
2927 EINA_LIST_FREE(wd->items, it)
2929 eina_stringshare_del(it->label);
2930 eina_stringshare_del(it->icon_file);
2931 eina_stringshare_del(it->icon_group);
2937 * This adds an item to the entry's contextual menu.
2939 * @param obj The entry object
2940 * @param label The item's text label
2941 * @param icon_file The item's icon file
2942 * @param icon_type The item's icon type
2943 * @param func The callback to execute when the item is clicked
2944 * @param data The data to associate with the item for related functions
2949 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)
2951 ELM_CHECK_WIDTYPE(obj, widtype);
2952 Widget_Data *wd = elm_widget_data_get(obj);
2953 Elm_Entry_Context_Menu_Item *it;
2955 it = calloc(1, sizeof(Elm_Entry_Context_Menu_Item));
2957 wd->items = eina_list_append(wd->items, it);
2959 it->label = eina_stringshare_add(label);
2960 it->icon_file = eina_stringshare_add(icon_file);
2961 it->icon_type = icon_type;
2963 it->data = (void *)data;
2967 * This disables the entry's contextual (right click) menu.
2969 * @param obj The entry object
2970 * @param disabled If true, the menu is disabled
2975 elm_entry_context_menu_disabled_set(Evas_Object *obj, Eina_Bool disabled)
2977 ELM_CHECK_WIDTYPE(obj, widtype);
2978 Widget_Data *wd = elm_widget_data_get(obj);
2980 if (wd->context_menu == !disabled) return;
2981 wd->context_menu = !disabled;
2985 * This returns whether the entry's contextual (right click) menu is disabled.
2987 * @param obj The entry object
2988 * @return If true, the menu is disabled
2993 elm_entry_context_menu_disabled_get(const Evas_Object *obj)
2995 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2996 Widget_Data *wd = elm_widget_data_get(obj);
2997 if (!wd) return EINA_FALSE;
2998 return !wd->context_menu;
3002 * This appends a custom item provider to the list for that entry
3004 * This appends the given callback. The list is walked from beginning to end
3005 * with each function called given the item href string in the text. If the
3006 * function returns an object handle other than NULL (it should create an
3007 * and object to do this), then this object is used to replace that item. If
3008 * not the next provider is called until one provides an item object, or the
3009 * default provider in entry does.
3011 * @param obj The entry object
3012 * @param func The function called to provide the item object
3013 * @param data The data passed to @p func
3018 elm_entry_item_provider_append(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3020 ELM_CHECK_WIDTYPE(obj, widtype);
3021 Widget_Data *wd = elm_widget_data_get(obj);
3023 EINA_SAFETY_ON_NULL_RETURN(func);
3024 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3028 wd->item_providers = eina_list_append(wd->item_providers, ip);
3032 * This prepends a custom item provider to the list for that entry
3034 * This prepends the given callback. See elm_entry_item_provider_append() for
3037 * @param obj The entry object
3038 * @param func The function called to provide the item object
3039 * @param data The data passed to @p func
3044 elm_entry_item_provider_prepend(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3046 ELM_CHECK_WIDTYPE(obj, widtype);
3047 Widget_Data *wd = elm_widget_data_get(obj);
3049 EINA_SAFETY_ON_NULL_RETURN(func);
3050 Elm_Entry_Item_Provider *ip = calloc(1, sizeof(Elm_Entry_Item_Provider));
3054 wd->item_providers = eina_list_prepend(wd->item_providers, ip);
3058 * This removes a custom item provider to the list for that entry
3060 * This removes the given callback. See elm_entry_item_provider_append() for
3063 * @param obj The entry object
3064 * @param func The function called to provide the item object
3065 * @param data The data passed to @p func
3070 elm_entry_item_provider_remove(Evas_Object *obj, Evas_Object *(*func) (void *data, Evas_Object *entry, const char *item), void *data)
3072 ELM_CHECK_WIDTYPE(obj, widtype);
3073 Widget_Data *wd = elm_widget_data_get(obj);
3075 Elm_Entry_Item_Provider *ip;
3077 EINA_SAFETY_ON_NULL_RETURN(func);
3078 EINA_LIST_FOREACH(wd->item_providers, l, ip)
3080 if ((ip->func == func) && (ip->data == data))
3082 wd->item_providers = eina_list_remove_list(wd->item_providers, l);
3090 * Append a filter function for text inserted in the entry
3092 * Append the given callback to the list. This functions will be called
3093 * whenever any text is inserted into the entry, with the text to be inserted
3094 * as a parameter. The callback function is free to alter the text in any way
3095 * it wants, but it must remember to free the given pointer and update it.
3096 * If the new text is to be discarded, the function can free it and set it text
3097 * parameter to NULL. This will also prevent any following filters from being
3100 * @param obj The entry object
3101 * @param func The function to use as text filter
3102 * @param data User data to pass to @p func
3107 elm_entry_text_filter_append(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3110 Elm_Entry_Text_Filter *tf;
3111 ELM_CHECK_WIDTYPE(obj, widtype);
3113 wd = elm_widget_data_get(obj);
3115 EINA_SAFETY_ON_NULL_RETURN(func);
3117 tf = ELM_NEW(Elm_Entry_Text_Filter);
3121 wd->text_filters = eina_list_append(wd->text_filters, tf);
3125 * Prepend a filter function for text insdrted in the entry
3127 * Prepend the given callback to the list. See elm_entry_text_filter_append()
3128 * for more information
3130 * @param obj The entry object
3131 * @param func The function to use as text filter
3132 * @param data User data to pass to @p func
3137 elm_entry_text_filter_prepend(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3140 Elm_Entry_Text_Filter *tf;
3141 ELM_CHECK_WIDTYPE(obj, widtype);
3143 wd = elm_widget_data_get(obj);
3145 EINA_SAFETY_ON_NULL_RETURN(func);
3147 tf = ELM_NEW(Elm_Entry_Text_Filter);
3151 wd->text_filters = eina_list_prepend(wd->text_filters, tf);
3155 * Remove a filter from the list
3157 * Removes the given callback from the filter list. See elm_entry_text_filter_append()
3158 * for more information.
3160 * @param obj The entry object
3161 * @param func The filter function to remove
3162 * @param data The user data passed when adding the function
3167 elm_entry_text_filter_remove(Evas_Object *obj, void (*func) (void *data, Evas_Object *entry, char **text), void *data)
3171 Elm_Entry_Text_Filter *tf;
3172 ELM_CHECK_WIDTYPE(obj, widtype);
3174 wd = elm_widget_data_get(obj);
3176 EINA_SAFETY_ON_NULL_RETURN(func);
3178 EINA_LIST_FOREACH(wd->text_filters, l, tf)
3180 if ((tf->func == func) && (tf->data == data))
3182 wd->text_filters = eina_list_remove_list(wd->text_filters, l);
3190 * This converts a markup (HTML-like) string into UTF-8.
3192 * @param s The string (in markup) to be converted
3193 * @return The converted string (in UTF-8)
3198 elm_entry_markup_to_utf8(const char *s)
3200 char *ss = _elm_util_mkup_to_text(s);
3201 if (!ss) ss = strdup("");
3206 * This converts a UTF-8 string into markup (HTML-like).
3208 * @param s The string (in UTF-8) to be converted
3209 * @return The converted string (in markup)
3214 elm_entry_utf8_to_markup(const char *s)
3216 char *ss = _elm_util_text_to_mkup(s);
3217 if (!ss) ss = strdup("");
3222 * Get the input method context in the entry widget
3224 * @param obj The entry object
3225 * @return The input method context
3229 EAPI Ecore_IMF_Context *elm_entry_imf_context_get(Evas_Object *obj)
3231 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
3232 Widget_Data *wd = elm_widget_data_get(obj);
3233 if (!wd || !wd->ent) return NULL;
3235 return edje_object_part_text_imf_context_get(wd->ent, "elm.text");
3239 * Set whether entry should enable the return key on soft keyboard automatically
3241 * @param obj The entry object
3242 * @param on If true, entry enables the return key on soft keyboard automatically.
3247 elm_entry_autoenable_returnkey_set(Evas_Object *obj, Eina_Bool on)
3249 ELM_CHECK_WIDTYPE(obj, widtype);
3250 Widget_Data *wd = elm_widget_data_get(obj);
3253 wd->autoreturnkey = on;
3254 _check_enable_returnkey(obj);
3258 * Set whether entry should support auto capitalization
3260 * @param obj The entry object
3261 * @param on If true, entry suports auto capitalization.
3266 elm_entry_autocapitalization_set(Evas_Object *obj, Eina_Bool autocap)
3268 ELM_CHECK_WIDTYPE(obj, widtype);
3269 Widget_Data *wd = elm_widget_data_get(obj);
3273 wd->autocapital = EINA_FALSE;
3275 wd->autocapital = autocap;
3277 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3278 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3279 wd->autocapital = EINA_FALSE;
3281 edje_object_part_text_autocapitalization_set(wd->ent, "elm.text", wd->autocapital);
3285 * Set whether entry should support auto period
3287 * @param obj The entry object
3288 * @param on If true, entry suports auto period.
3293 elm_entry_autoperiod_set(Evas_Object *obj, Eina_Bool autoperiod)
3295 ELM_CHECK_WIDTYPE(obj, widtype);
3296 Widget_Data *wd = elm_widget_data_get(obj);
3300 wd->autoperiod = EINA_FALSE;
3302 wd->autoperiod = autoperiod;
3304 if (wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_URL ||
3305 wd->input_panel_layout == ELM_INPUT_PANEL_LAYOUT_EMAIL)
3306 wd->autoperiod = EINA_FALSE;
3308 edje_object_part_text_autoperiod_set(wd->ent, "elm.text", wd->autoperiod);
3312 * Set the font size on the entry object
3314 * @param obj The entry object
3315 * @param size font size
3320 elm_entry_fontsize_set(Evas_Object *obj, int fontsize)
3322 ELM_CHECK_WIDTYPE(obj, widtype);
3323 Widget_Data *wd = elm_widget_data_get(obj);
3324 Eina_Strbuf *fontbuf = NULL;
3329 t = eina_stringshare_add(elm_entry_entry_get(obj));
3330 fontbuf = eina_strbuf_new();
3331 eina_strbuf_append_printf(fontbuf, "%d", fontsize);
3333 if (fontsize == 0) removeflag = 1; // remove fontsize tag
3335 if (_stringshare_key_value_replace(&t, "font_size", eina_strbuf_string_get(fontbuf), removeflag) == 0)
3337 elm_entry_entry_set(obj, t);
3341 eina_strbuf_free(fontbuf);
3342 eina_stringshare_del(t);
3346 * Set the text align on the entry object
3348 * @param obj The entry object
3349 * @param align align mode
3354 elm_entry_text_align_set(Evas_Object *obj, const char *alignmode)
3356 ELM_CHECK_WIDTYPE(obj, widtype);
3357 Widget_Data *wd = elm_widget_data_get(obj);
3362 t = eina_stringshare_add(elm_entry_entry_get(obj));
3364 if (len <= 0) return;
3366 if (_stringshare_key_value_replace(&t, "align", alignmode, 0) == 0)
3367 elm_entry_entry_set(obj, t);
3371 eina_stringshare_del(t);
3375 * Set the text color on the entry object
3377 * @param obj The entry object
3378 * @param r Red property background color of The entry object
3379 * @param g Green property background color of The entry object
3380 * @param b Blue property background color of The entry object
3381 * @param a Alpha property background alpha of The entry object
3386 elm_entry_text_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3388 ELM_CHECK_WIDTYPE(obj, widtype);
3389 Widget_Data *wd = elm_widget_data_get(obj);
3390 Eina_Strbuf *colorbuf = NULL;
3395 t = eina_stringshare_add(elm_entry_entry_get(obj));
3397 if (len <= 0) return;
3398 colorbuf = eina_strbuf_new();
3399 eina_strbuf_append_printf(colorbuf, "#%02X%02X%02X%02X", r, g, b, a);
3401 if (_stringshare_key_value_replace(&t, "color", eina_strbuf_string_get(colorbuf), 0) == 0)
3403 elm_entry_entry_set(obj, t);
3407 eina_strbuf_free(colorbuf);
3408 eina_stringshare_del(t);
3412 * Set background color of the entry
3414 * @param obj The entry object
3415 * @param r Red property background color of The entry object
3416 * @param g Green property background color of The entry object
3417 * @param b Blue property background color of The entry object
3418 * @param a Alpha property background alpha of The entry object
3422 elm_entry_background_color_set(Evas_Object *obj, unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3424 ELM_CHECK_WIDTYPE(obj, widtype);
3425 Widget_Data *wd = elm_widget_data_get(obj);
3426 evas_object_color_set(wd->bg, r, g, b, a);
3428 if (wd->bgcolor == EINA_FALSE)
3431 edje_object_part_swallow(wd->ent, "entry.swallow.background", wd->bg);
3436 * Set the ellipsis behavior of the entry
3438 * @param obj The entry object
3439 * @param ellipsis To ellipsis text or not
3443 elm_entry_ellipsis_set(Evas_Object *obj, Eina_Bool ellipsis)
3445 ELM_CHECK_WIDTYPE(obj, widtype);
3446 Widget_Data *wd = elm_widget_data_get(obj);
3447 if (wd->ellipsis == ellipsis) return;
3448 wd->ellipsis = ellipsis;
3454 * Filter inserted text based on user defined character and byte limits
3456 * Add this filter to an entry to limit the characters that it will accept
3457 * based the the contents of the provided Elm_Entry_Filter_Limit_Size.
3458 * The funtion works on the UTF-8 representation of the string, converting
3459 * it from the set markup, thus not accounting for any format in it.
3461 * The user must create an Elm_Entry_Filter_Limit_Size structure and pass
3462 * it as data when setting the filter. In it it's possible to set limits
3463 * by character count or bytes (any of them is disabled if 0), and both can
3464 * be set at the same time. In that case, it first checks for characters,
3467 * The function will cut the inserted text in order to allow only the first
3468 * number of characters that are still allowed. The cut is made in
3469 * characters, even when limiting by bytes, in order to always contain
3470 * valid ones and avoid half unicode characters making it in.
3475 elm_entry_filter_limit_size(void *data, Evas_Object *entry, char **text)
3477 Elm_Entry_Filter_Limit_Size *lim = data;
3480 const char *(*text_get)(const Evas_Object *);
3481 const char *widget_type;
3483 EINA_SAFETY_ON_NULL_RETURN(data);
3484 EINA_SAFETY_ON_NULL_RETURN(entry);
3485 EINA_SAFETY_ON_NULL_RETURN(text);
3487 /* hack. I don't want to copy the entire function to work with
3489 widget_type = elm_widget_type_get(entry);
3490 if (!strcmp(widget_type, "entry"))
3491 text_get = elm_entry_entry_get;
3492 else if (!strcmp(widget_type, "scrolled_entry"))
3493 text_get = elm_scrolled_entry_entry_get;
3497 current = elm_entry_markup_to_utf8(text_get(entry));
3499 if (lim->max_char_count > 0)
3502 len = evas_string_char_len_get(current);
3503 if (len >= lim->max_char_count)
3505 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3511 newlen = evas_string_char_len_get(*text);
3512 cut = strlen(*text);
3513 while ((len + newlen) > lim->max_char_count)
3515 cut = evas_string_char_prev_get(*text, cut, NULL);
3521 if (lim->max_byte_count > 0)
3523 len = strlen(current);
3524 if (len >= lim->max_byte_count)
3526 evas_object_smart_callback_call(entry, "maxlength,reached", NULL);
3532 newlen = strlen(*text);
3533 while ((len + newlen) > lim->max_byte_count)
3535 int p = evas_string_char_prev_get(*text, newlen, NULL);
3536 newlen -= (newlen - p);
3539 (*text)[newlen] = 0;
3550 * Filter inserted text based on accepted or rejected sets of characters
3552 * Add this filter to an entry to restrict the set of accepted characters
3553 * based on the sets in the provided Elm_Entry_Filter_Accept_Set.
3554 * This structure contains both accepted and rejected sets, but they are
3555 * mutually exclusive. If accepted is set, it will be used, otherwise it
3556 * goes on to the rejected set.
3559 elm_entry_filter_accept_set(void *data, Evas_Object *entry __UNUSED__, char **text)
3561 Elm_Entry_Filter_Accept_Set *as = data;
3565 int read_idx, last_read_idx = 0, read_char;
3567 EINA_SAFETY_ON_NULL_RETURN(data);
3568 EINA_SAFETY_ON_NULL_RETURN(text);
3570 if ((!as->accepted) && (!as->rejected))
3576 goes_in = EINA_TRUE;
3581 goes_in = EINA_FALSE;
3585 read_idx = evas_string_char_next_get(*text, 0, &read_char);
3588 int cmp_idx, cmp_char;
3589 Eina_Bool in_set = EINA_FALSE;
3591 cmp_idx = evas_string_char_next_get(set, 0, &cmp_char);
3594 if (read_char == cmp_char)
3599 cmp_idx = evas_string_char_next_get(set, cmp_idx, &cmp_char);
3601 if (in_set == goes_in)
3603 int size = read_idx - last_read_idx;
3604 const char *src = (*text) + last_read_idx;
3606 memcpy(insert, *text + last_read_idx, size);
3609 last_read_idx = read_idx;
3610 read_idx = evas_string_char_next_get(*text, read_idx, &read_char);
3616 * This sets the file (and implicitly loads it) for the text to display and
3617 * then edit. All changes are written back to the file after a short delay if
3618 * the entry object is set to autosave.
3620 * @param obj The entry object
3621 * @param file The path to the file to load and save
3622 * @param format The file format
3627 elm_entry_file_set(Evas_Object *obj, const char *file, Elm_Text_Format format)
3629 ELM_CHECK_WIDTYPE(obj, widtype);
3630 Widget_Data *wd = elm_widget_data_get(obj);
3632 if (wd->delay_write)
3634 ecore_timer_del(wd->delay_write);
3635 wd->delay_write = NULL;
3637 if (wd->autosave) _save(obj);
3638 eina_stringshare_replace(&wd->file, file);
3639 wd->format = format;
3644 * Gets the file to load and save and the file format
3646 * @param obj The entry object
3647 * @param file The path to the file to load and save
3648 * @param format The file format
3653 elm_entry_file_get(const Evas_Object *obj, const char **file, Elm_Text_Format *format)
3655 ELM_CHECK_WIDTYPE(obj, widtype);
3656 Widget_Data *wd = elm_widget_data_get(obj);
3658 if (file) *file = wd->file;
3659 if (format) *format = wd->format;
3663 * This function writes any changes made to the file set with
3664 * elm_entry_file_set()
3666 * @param obj The entry object
3671 elm_entry_file_save(Evas_Object *obj)
3673 ELM_CHECK_WIDTYPE(obj, widtype);
3674 Widget_Data *wd = elm_widget_data_get(obj);
3676 if (wd->delay_write)
3678 ecore_timer_del(wd->delay_write);
3679 wd->delay_write = NULL;
3682 wd->delay_write = ecore_timer_add(2.0, _delay_write, obj);
3686 * This sets the entry object to 'autosave' the loaded text file or not.
3688 * @param obj The entry object
3689 * @param autosave Autosave the loaded file or not
3694 elm_entry_autosave_set(Evas_Object *obj, Eina_Bool autosave)
3696 ELM_CHECK_WIDTYPE(obj, widtype);
3697 Widget_Data *wd = elm_widget_data_get(obj);
3699 wd->autosave = !!autosave;
3703 * This gets the entry object's 'autosave' status.
3705 * @param obj The entry object
3706 * @return Autosave the loaded file or not
3711 elm_entry_autosave_get(const Evas_Object *obj)
3713 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3714 Widget_Data *wd = elm_widget_data_get(obj);
3715 if (!wd) return EINA_FALSE;
3716 return wd->autosave;
3721 * Control pasting of text and images for the widget.
3723 * Normally the entry allows both text and images to be pasted. By setting
3724 * textonly to be true, this prevents images from being pasted.
3726 * Note this only changes the behaviour of text.
3728 * @param obj The entry object
3729 * @param pmode paste mode - 0 is text only, 1 is text+image+other.
3734 elm_entry_cnp_textonly_set(Evas_Object *obj, Eina_Bool textonly)
3736 Elm_Sel_Format format = ELM_SEL_FORMAT_MARKUP;
3737 ELM_CHECK_WIDTYPE(obj, widtype);
3738 Widget_Data *wd = elm_widget_data_get(obj);
3740 textonly = !!textonly;
3741 if (wd->textonly == textonly) return;
3742 wd->textonly = !!textonly;
3746 * Getting elm_entry text paste/drop mode.
3748 * In textonly mode, only text may be pasted or dropped into the widget.
3750 * @param obj The entry object
3751 * @return If the widget only accepts text from pastes.
3756 elm_entry_cnp_textonly_get(Evas_Object *obj)
3758 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
3759 Widget_Data *wd = elm_widget_data_get(obj);
3760 if (!wd) return EINA_FALSE;
3761 return wd->textonly;
3765 * This sets the attribute to show the input panel automatically.
3767 * @param obj The entry object
3768 * @param enabled If true, the input panel is appeared when entry is clicked or has a focus
3773 elm_entry_input_panel_enabled_set(Evas_Object *obj, Eina_Bool enabled)
3775 ELM_CHECK_WIDTYPE(obj, widtype);
3776 Widget_Data *wd = elm_widget_data_get(obj);
3779 wd->input_panel_enable = enabled;
3780 edje_object_part_text_input_panel_enabled_set(wd->ent, "elm.text", enabled);
3784 * Set the input panel layout of the entry
3786 * @param obj The entry object
3787 * @param layout the layout to set
3792 elm_entry_input_panel_layout_set(Evas_Object *obj, Elm_Input_Panel_Layout layout)
3794 ELM_CHECK_WIDTYPE(obj, widtype);
3795 Widget_Data *wd = elm_widget_data_get(obj);
3798 Ecore_IMF_Context *ic = elm_entry_imf_context_get(obj);
3801 wd->input_panel_layout = layout;
3803 ecore_imf_context_input_panel_layout_set(ic, (Ecore_IMF_Input_Panel_Layout)layout);